Skip to content

Commit

Permalink
zebra: Moving afi-safi identity to lib
Browse files Browse the repository at this point in the history
afi-safi identity handling should be in the common place.

Signed-off-by: VishalDhingra <vdhingra@vmware.com>
  • Loading branch information
vishaldhingra committed Jul 16, 2020
1 parent 88fa510 commit 755100a
Show file tree
Hide file tree
Showing 9 changed files with 74 additions and 73 deletions.
35 changes: 35 additions & 0 deletions lib/yang_wrappers.c
Original file line number Diff line number Diff line change
Expand Up @@ -1191,3 +1191,38 @@ const char *yang_nexthop_type2str(uint32_t ntype)
break;
}
}


const char *yang_afi_safi_value2identity(afi_t afi, safi_t safi)
{
if (afi == AFI_IP && safi == SAFI_UNICAST)
return "frr-routing:ipv4-unicast";
if (afi == AFI_IP6 && safi == SAFI_UNICAST)
return "frr-routing:ipv6-unicast";
if (afi == AFI_IP && safi == SAFI_MULTICAST)
return "frr-routing:ipv4-multicast";
if (afi == AFI_IP6 && safi == SAFI_MULTICAST)
return "frr-routing:ipv6-multicast";

return NULL;
}

void yang_afi_safi_identity2value(const char *key, afi_t *afi, safi_t *safi)
{
if (strmatch(key, "frr-routing:ipv4-unicast")) {
*afi = AFI_IP;
*safi = SAFI_UNICAST;
} else if (strmatch(key, "frr-routing:ipv6-unicast")) {
*afi = AFI_IP6;
*safi = SAFI_UNICAST;
} else if (strmatch(key, "frr-routing:ipv4-multicast")) {
*afi = AFI_IP;
*safi = SAFI_MULTICAST;
} else if (strmatch(key, "frr-routing:ipv6-multicast")) {
*afi = AFI_IP6;
*safi = SAFI_MULTICAST;
} else {
*afi = AFI_UNSPEC;
*safi = SAFI_UNSPEC;
}
}
3 changes: 3 additions & 0 deletions lib/yang_wrappers.h
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,9 @@ extern struct yang_data *yang_data_new_date_and_time(const char *xpath,
/* nexthop enum2str */
extern const char *yang_nexthop_type2str(uint32_t ntype);

const char *yang_afi_safi_value2identity(afi_t afi, safi_t safi);
void yang_afi_safi_identity2value(const char *key, afi_t *afi, safi_t *safi);

#ifdef __cplusplus
}
#endif
Expand Down
29 changes: 29 additions & 0 deletions yang/frr-routing.yang
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,35 @@ module frr-routing {
"This identity represents an IPv6 address family.";
}

identity afi-safi-type {
description
"Base identity type (AFI,SAFI) tuples for RIB";
}

identity ipv4-unicast {
base afi-safi-type;
description
"This identity represents the IPv4 unicast address family.";
}

identity ipv6-unicast {
base afi-safi-type;
description
"This identity represents the IPv6 unicast address family.";
}

identity ipv4-multicast {
base afi-safi-type;
description
"This identity represents the IPv4 multicast address family.";
}

identity ipv6-multicast {
base afi-safi-type;
description
"This identity represents the IPv6 multicast address family.";
}

identity control-plane-protocol {
description
"Base identity from which control-plane protocol identities are
Expand Down
31 changes: 1 addition & 30 deletions yang/frr-zebra.yang
Original file line number Diff line number Diff line change
Expand Up @@ -77,35 +77,6 @@ module frr-zebra {
"Initial revision.";
}

identity afi-safi-type {
description
"Base identity type (AFI,SAFI) tuples for RIB";
}

identity ipv4-unicast {
base afi-safi-type;
description
"This identity represents the IPv4 unicast address family.";
}

identity ipv6-unicast {
base afi-safi-type;
description
"This identity represents the IPv6 unicast address family.";
}

identity ipv4-multicast {
base afi-safi-type;
description
"This identity represents the IPv4 multicast address family.";
}

identity ipv6-multicast {
base afi-safi-type;
description
"This identity represents the IPv6 multicast address family.";
}

typedef unix-timestamp {
type uint32;
units "seconds";
Expand Down Expand Up @@ -634,7 +605,7 @@ module frr-zebra {
key "afi-safi-name table-id";
leaf afi-safi-name {
type identityref {
base afi-safi-type;
base frr-rt:afi-safi-type;
}
description
"AFI, SAFI name.";
Expand Down
2 changes: 2 additions & 0 deletions zebra/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
#include "vrf.h"
#include "libfrr.h"
#include "routemap.h"
#include "routing_nb.h"

#include "zebra/zebra_router.h"
#include "zebra/zebra_errors.h"
Expand Down Expand Up @@ -258,6 +259,7 @@ static const struct frr_yang_module_info *const zebra_yang_modules[] = {
&frr_route_map_info,
&frr_zebra_info,
&frr_vrf_info,
&frr_routing_info,
};

FRR_DAEMON_INFO(
Expand Down
34 changes: 0 additions & 34 deletions zebra/zebra_nb.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,40 +22,6 @@
#include "libfrr.h"
#include "zebra_nb.h"

const char *zebra_afi_safi_value2identity(afi_t afi, safi_t safi)
{
if (afi == AFI_IP && safi == SAFI_UNICAST)
return "ipv4-unicast";
if (afi == AFI_IP6 && safi == SAFI_UNICAST)
return "ipv6-unicast";
if (afi == AFI_IP && safi == SAFI_MULTICAST)
return "ipv4-multicast";
if (afi == AFI_IP6 && safi == SAFI_MULTICAST)
return "ipv6-multicast";

return " ";
}

void zebra_afi_safi_identity2value(const char *key, afi_t *afi, safi_t *safi)
{
if (strmatch(key, "frr-zebra:ipv4-unicast")) {
*afi = AFI_IP;
*safi = SAFI_UNICAST;
} else if (strmatch(key, "frr-zebra:ipv6-unicast")) {
*afi = AFI_IP6;
*safi = SAFI_UNICAST;
} else if (strmatch(key, "frr-zebra:ipv4-multicast")) {
*afi = AFI_IP;
*safi = SAFI_MULTICAST;
} else if (strmatch(key, "frr-zebra:ipv6-multicast")) {
*afi = AFI_IP6;
*safi = SAFI_MULTICAST;
} else {
*afi = AFI_UNSPEC;
*safi = SAFI_UNSPEC;
}
}

/* clang-format off */
const struct frr_yang_module_info frr_zebra_info = {
.name = "frr-zebra",
Expand Down
4 changes: 0 additions & 4 deletions zebra/zebra_nb.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,6 @@ extern "C" {

extern const struct frr_yang_module_info frr_zebra_info;

/* helper functions */
const char *zebra_afi_safi_value2identity(afi_t afi, safi_t safi);
void zebra_afi_safi_identity2value(const char *key, afi_t *afi, safi_t *safi);

/* prototypes */
int get_route_information_rpc(struct nb_cb_rpc_args *args);
int get_v6_mroute_info_rpc(struct nb_cb_rpc_args *args);
Expand Down
2 changes: 1 addition & 1 deletion zebra/zebra_nb_config.c
Original file line number Diff line number Diff line change
Expand Up @@ -1242,7 +1242,7 @@ int lib_vrf_zebra_ribs_rib_create(struct nb_cb_create_args *args)
table_id = zvrf->table_id;

afi_safi_name = yang_dnode_get_string(args->dnode, "./afi-safi-name");
zebra_afi_safi_identity2value(afi_safi_name, &afi, &safi);
yang_afi_safi_identity2value(afi_safi_name, &afi, &safi);

zrt = zebra_router_find_zrt(zvrf, table_id, afi, safi);

Expand Down
7 changes: 3 additions & 4 deletions zebra/zebra_nb_state.c
Original file line number Diff line number Diff line change
Expand Up @@ -185,9 +185,8 @@ int lib_vrf_zebra_ribs_rib_get_keys(struct nb_cb_get_keys_args *args)

args->keys->num = 2;

snprintfrr(args->keys->key[0], sizeof(args->keys->key[0]), "%s:%s",
"frr-zebra",
zebra_afi_safi_value2identity(zrt->afi, zrt->safi));
snprintfrr(args->keys->key[0], sizeof(args->keys->key[0]), "%s",
yang_afi_safi_value2identity(zrt->afi, zrt->safi));
snprintfrr(args->keys->key[1], sizeof(args->keys->key[1]), "%u",
zrt->tableid);

Expand All @@ -205,7 +204,7 @@ lib_vrf_zebra_ribs_rib_lookup_entry(struct nb_cb_lookup_entry_args *args)

zvrf = zebra_vrf_lookup_by_id(vrf->vrf_id);

zebra_afi_safi_identity2value(args->keys->key[0], &afi, &safi);
yang_afi_safi_identity2value(args->keys->key[0], &afi, &safi);
table_id = yang_str2uint32(args->keys->key[1]);
/* table_id 0 assume vrf's table_id. */
if (!table_id)
Expand Down

0 comments on commit 755100a

Please sign in to comment.