]> git.puffer.fish Git - matthieu/frr.git/commitdiff
zebra: Moving afi-safi identity to lib
authorvdhingra <vdhingra@vmware.com>
Thu, 2 Jul 2020 05:36:51 +0000 (22:36 -0700)
committervdhingra <vdhingra@vmware.com>
Thu, 16 Jul 2020 15:40:42 +0000 (08:40 -0700)
afi-safi identity handling should be in the common place.

Signed-off-by: VishalDhingra <vdhingra@vmware.com>
lib/yang_wrappers.c
lib/yang_wrappers.h
yang/frr-routing.yang
yang/frr-zebra.yang
zebra/main.c
zebra/zebra_nb.c
zebra/zebra_nb.h
zebra/zebra_nb_config.c
zebra/zebra_nb_state.c

index c31ba3fcc0080113e539a055021738400a4c63fc..8b0e89d52edcad4368aa5511c4ce671436b935c6 100644 (file)
@@ -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;
+       }
+}
index ba2cf5139c527139fb625f20fc8ed52d0491180c..335ff319d5efb717bbb0491e67ea36355eb870bc 100644 (file)
@@ -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
index 0f64f3f481988a29b197a33ef4433ed54e898e85..d22e12074f6ad7559ef8670cb2e4f3f180f5bb3e 100644 (file)
@@ -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
index 159dd8f791c6bc3c653628384af3546acd4bf4b2..8894eeaa2662e8c129dd9a770e24088ec60557ac 100644 (file)
@@ -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";
@@ -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.";
index 748e43b8d98ed4396b7c9272ec642ee7f3e3019a..9de24c5e41e7bf4cd4a05319eb0d1a149b0562a6 100644 (file)
@@ -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"
@@ -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(
index 53fe8e8e3fe63a1eb3ef93d407656a8c895da7bd..6f01c41d71c0ee0f7f74fb14280fbb6da5918f24 100644 (file)
 #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",
index a9e7fd5fb05976c26fd8063921c25dc283aa1386..defa206d593b52cf1069e0a7005921ce6e93991b 100644 (file)
@@ -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);
index 948ef513203a729cbd1893d7907c4a14cf0c04fd..259b5f1eb2c50dc9f14b1e27ce2456fad5f25b8c 100644 (file)
@@ -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);
 
index 4374da360e130cca7f7dd25c33cd9d60fc1c4891..b5fde5f03eacec54129b992c671c7d908bd67880 100644 (file)
@@ -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);
 
@@ -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)