Skip to content

Commit

Permalink
staticd : northbound backend code
Browse files Browse the repository at this point in the history
basic routing northbound callbacks
vrf northbound callbacks
staticd northbound callbacks
tag, distance, tableid is the property of route

Signed-off-by: VishalDhingra <vdhingra@vmware.com>
  • Loading branch information
vishaldhingra committed Mar 25, 2020
1 parent 2ee1136 commit d3e6d58
Show file tree
Hide file tree
Showing 23 changed files with 2,632 additions and 977 deletions.
65 changes: 65 additions & 0 deletions lib/routing_nb.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
#include "northbound.h"
#include "libfrr.h"
#include "vrf.h"
#include "routing_nb.h"


static int lib_routing_cp_create(enum nb_event event,
const struct lyd_node *dnode,
union nb_resource *resource)
{
struct vrf *vrf;
const char *vrfname;

switch (event) {
case NB_EV_VALIDATE:
vrfname = yang_dnode_get_string(dnode, "./vrf");
vrf = vrf_lookup_by_name(vrfname);
if (!vrf) {
zlog_warn(
"vrf is not configured\n");
return NB_ERR_VALIDATION;
}

break;
case NB_EV_PREPARE:
case NB_EV_ABORT:
break;
case NB_EV_APPLY:
vrfname = yang_dnode_get_string(dnode, "./vrf");
vrf = vrf_lookup_by_name(vrfname);
nb_running_set_entry(dnode, vrf);
break;
};

return NB_OK;
}

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

if (event != NB_EV_APPLY)
return NB_OK;

vrf = nb_running_unset_entry(dnode);
(void)vrf;
return NB_OK;
}

const struct frr_yang_module_info frr_routing_info = {
.name = "frr-routing",
.nodes = {
{
.xpath = FRR_ROUTING_XPATH,
.cbs = {
.create = lib_routing_cp_create,
.destroy = lib_routing_cp_destroy,
},
},
{
.xpath = NULL,
},
}
};
17 changes: 17 additions & 0 deletions lib/routing_nb.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#ifndef _FRR_ROUTING_NB_H_
#define _FRR_ROUTING_NB_H_


#define FRR_ROUTING_XPATH \
"/frr-routing:routing/control-plane-protocols/control-plane-protocol"

#define FRR_ROUTING_KEY_XPATH \
"/frr-routing:routing/control-plane-protocols/control-plane-protocol[type='%s'][name='%s'][vrf='%s']"

extern const struct frr_yang_module_info frr_routing_info;

/* Mandatory callbacks. */



#endif /* _FRR_ROUTING_NB_H_ */
3 changes: 3 additions & 0 deletions lib/subdir.am
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ lib_libfrr_la_SOURCES = \
lib/printf/printf-pos.c \
lib/printf/vfprintf.c \
lib/printf/glue.c \
lib/routing_nb.c \
# end

nodist_lib_libfrr_la_SOURCES = \
Expand All @@ -112,6 +113,7 @@ nodist_lib_libfrr_la_SOURCES = \
yang/frr-route-types.yang.c \
yang/frr-vrf.yang.c \
yang/frr-routing.yang.c \
yang/frr-nexthop.yang.c \
yang/ietf/ietf-routing-types.yang.c \
yang/frr-module-translator.yang.c \
# end
Expand Down Expand Up @@ -257,6 +259,7 @@ pkginclude_HEADERS += \
lib/zclient.h \
lib/zebra.h \
lib/pbr.h \
lib/routing_nb.h \
# end


Expand Down
21 changes: 21 additions & 0 deletions lib/yang.c
Original file line number Diff line number Diff line change
Expand Up @@ -689,3 +689,24 @@ void yang_terminate(void)

ly_ctx_destroy(ly_native_ctx, NULL);
}

const struct lyd_node *yang_dnode_get_pleaf(const struct lyd_node *dnode,
const char *lname)
{
const struct lyd_node *orig_dnode = dnode;

while (orig_dnode) {
switch (orig_dnode->schema->nodetype) {
case LYS_LIST:
if(!strcmp(orig_dnode->schema->name, lname))
return orig_dnode;
break;
default:
break;
}

orig_dnode = orig_dnode->parent;
}

return NULL;
}
5 changes: 4 additions & 1 deletion lib/yang.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ extern "C" {
#endif

/* Maximum XPath length. */
#define XPATH_MAXLEN 256
#define XPATH_MAXLEN 1024

/* Maximum list key length. */
#define LIST_MAXKEYS 8
Expand Down Expand Up @@ -505,6 +505,9 @@ extern void yang_init(void);
*/
extern void yang_terminate(void);

extern const struct lyd_node *yang_dnode_get_pleaf(const struct lyd_node *dnode,
const char *lname);

#ifdef __cplusplus
}
#endif
Expand Down
5 changes: 5 additions & 0 deletions staticd/static_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,14 @@
#include "vrf.h"
#include "nexthop.h"
#include "filter.h"
#include "routing_nb.h"

#include "static_vrf.h"
#include "static_vty.h"
#include "static_routes.h"
#include "static_zebra.h"
#include "static_debug.h"
#include "static_nb.h"

char backup_config_file[256];

Expand Down Expand Up @@ -104,7 +106,10 @@ struct quagga_signal_t static_signals[] = {
};

static const struct frr_yang_module_info *const staticd_yang_modules[] = {
&frr_interface_info,
&frr_vrf_info,
&frr_routing_info,
&frr_staticd_info,
};

#define STATIC_VTY_PORT 2616
Expand Down
2 changes: 2 additions & 0 deletions staticd/static_memory.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,5 @@
DEFINE_MGROUP(STATIC, "staticd")

DEFINE_MTYPE(STATIC, STATIC_ROUTE, "Static Route");

DEFINE_MTYPE(STATIC, STATIC_ROUTE_INFO, "Static Route Info");
1 change: 1 addition & 0 deletions staticd/static_memory.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,6 @@
DECLARE_MGROUP(STATIC)

DECLARE_MTYPE(STATIC_ROUTE);
DECLARE_MTYPE(STATIC_ROUTE_INFO);

#endif
Loading

0 comments on commit d3e6d58

Please sign in to comment.