Skip to content

Commit

Permalink
lib: convert vrf cmd to northbound config callback
Browse files Browse the repository at this point in the history
Signed-off-by: Chirag Shah <chirag@cumulusnetworks.com>
  • Loading branch information
chiragshah6 committed Mar 23, 2020
1 parent fc8569a commit 200be70
Showing 1 changed file with 32 additions and 8 deletions.
40 changes: 32 additions & 8 deletions lib/vrf.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
#include "nexthop_group.h"
#include "lib_errors.h"
#include "northbound.h"
#include "northbound_cli.h"

/* default VRF ID value used when VRF backend is not NETNS */
#define VRF_DEFAULT_INTERNAL 0
Expand Down Expand Up @@ -604,6 +605,8 @@ int vrf_handler_create(struct vty *vty, const char *vrfname,
struct vrf **vrf)
{
struct vrf *vrfp;
char xpath_list[XPATH_MAXLEN];
int ret;

if (strlen(vrfname) > VRF_NAMSIZ) {
if (vty)
Expand All @@ -618,13 +621,24 @@ int vrf_handler_create(struct vty *vty, const char *vrfname,
return CMD_WARNING_CONFIG_FAILED;
}

vrfp = vrf_get(VRF_UNKNOWN, vrfname);

if (vty)
VTY_PUSH_CONTEXT(VRF_NODE, vrfp);
if (vty) {
snprintf(xpath_list, sizeof(xpath_list),
"/frr-vrf:lib/vrf[name='%s']", vrfname);

nb_cli_enqueue_change(vty, xpath_list, NB_OP_CREATE, NULL);
ret = nb_cli_apply_changes(vty, xpath_list);
if (ret == CMD_SUCCESS) {
VTY_PUSH_XPATH(VRF_NODE, xpath_list);
vrfp = vrf_lookup_by_name(vrfname);
if (vrfp)
VTY_PUSH_CONTEXT(VRF_NODE, vrfp);
}
} else {
vrfp = vrf_get(VRF_UNKNOWN, vrfname);

if (vrf)
*vrf = vrfp;
if (vrf)
*vrf = vrfp;
}
return CMD_SUCCESS;
}

Expand Down Expand Up @@ -727,6 +741,7 @@ DEFUN (no_vrf,
"VRF's name\n")
{
const char *vrfname = argv[2]->arg;
char xpath_list[XPATH_MAXLEN];

struct vrf *vrfp;

Expand All @@ -742,11 +757,18 @@ DEFUN (no_vrf,
return CMD_WARNING_CONFIG_FAILED;
}

/* Clear configured flag and invoke delete. */
snprintf(xpath_list, sizeof(xpath_list), "/frr-vrf:lib/vrf[name='%s']",
vrfname);

nb_cli_enqueue_change(vty, xpath_list, NB_OP_DESTROY, NULL);
return nb_cli_apply_changes(vty, xpath_list);
#if 0
/* Clear configured flag and invoke delete. */
UNSET_FLAG(vrfp->status, VRF_CONFIGURED);
vrf_delete(vrfp);

return CMD_SUCCESS;
#endif
}


Expand Down Expand Up @@ -1032,14 +1054,15 @@ static int lib_vrf_create(enum nb_event event, const struct lyd_node *dnode,

nb_running_set_entry(dnode, vrfp);

zlog_debug("%s: vrf %s ", __func__, vrfp->name);

return NB_OK;
}

static int lib_vrf_destroy(enum nb_event event, const struct lyd_node *dnode)
{
struct vrf *vrfp;


switch (event) {
case NB_EV_VALIDATE:
vrfp = nb_running_get_entry(dnode, NULL, true);
Expand All @@ -1054,6 +1077,7 @@ static int lib_vrf_destroy(enum nb_event event, const struct lyd_node *dnode)
break;
case NB_EV_APPLY:
vrfp = nb_running_unset_entry(dnode);
zlog_debug("%s: vrf %s", __func__, vrfp->name);
/* Clear configured flag and invoke delete. */
UNSET_FLAG(vrfp->status, VRF_CONFIGURED);
vrf_delete(vrfp);
Expand Down

0 comments on commit 200be70

Please sign in to comment.