FIB Interpose Source
[vpp.git] / src / vnet / bier / bier_api.c
index 77b2cab..7263ec6 100644 (file)
@@ -49,6 +49,7 @@
 #undef vl_printfun
 
 #include <vlibapi/api_helper_macros.h>
+#include <vnet/fib/fib_api.h>
 
 #define foreach_bier_api_msg                            \
     _(BIER_TABLE_ADD_DEL, bier_table_add_del)           \
@@ -164,7 +165,7 @@ vl_api_bier_route_add_del_t_handler (vl_api_bier_route_add_del_t * mp)
     vnet_main_t *vnm;
     bier_bp_t bp;
     int rv = 0;
-    u8 ii, jj;
+    u8 ii;
 
     vnm = vnet_get_main ();
     vnm->api_errno = 0;
@@ -195,61 +196,11 @@ vl_api_bier_route_add_del_t_handler (vl_api_bier_route_add_del_t * mp)
     vec_foreach_index(ii, brpaths)
     {
         brpath = &brpaths[ii];
-        memset(brpath, 0, sizeof(*brpath));
-        brpath->frp_sw_if_index = ~0;
-
-        vec_validate(brpath->frp_label_stack,
-                     mp->br_paths[ii].n_labels - 1);
-        for (jj = 0; jj < mp->br_paths[ii].n_labels; jj++)
-        {
-            brpath->frp_label_stack[jj].fml_value =
-                ntohl(mp->br_paths[ii].label_stack[jj].label);
-            brpath->frp_label_stack[jj].fml_ttl =
-                mp->br_paths[ii].label_stack[jj].ttl;
-            brpath->frp_label_stack[jj].fml_exp =
-                mp->br_paths[ii].label_stack[jj].exp;
-            brpath->frp_label_stack[jj].fml_mode =
-                (mp->br_paths[ii].label_stack[jj].is_uniform ?
-                 FIB_MPLS_LSP_MODE_UNIFORM :
-                 FIB_MPLS_LSP_MODE_PIPE);
-        }
+        rv = fib_path_api_parse(&mp->br_paths[ii], brpath);
 
-        if (mp->br_paths[ii].is_udp_encap)
+        if (0 != rv)
         {
-            brpath->frp_flags |= FIB_ROUTE_PATH_UDP_ENCAP;
-            brpath->frp_udp_encap_id = ntohl(mp->br_paths[ii].next_hop_id);
-        }
-        else
-        {
-            if (0 == mp->br_paths[ii].afi)
-            {
-                clib_memcpy (&brpath->frp_addr.ip4,
-                             mp->br_paths[ii].next_hop,
-                             sizeof (brpath->frp_addr.ip4));
-            }
-            else
-            {
-                clib_memcpy (&brpath->frp_addr.ip6,
-                             mp->br_paths[ii].next_hop,
-                             sizeof (brpath->frp_addr.ip6));
-            }
-            if (ip46_address_is_zero(&brpath->frp_addr))
-            {
-                index_t bdti;
-
-                bdti = bier_disp_table_find(ntohl(mp->br_paths[ii].table_id));
-
-                if (INDEX_INVALID != bdti)
-                {
-                    brpath->frp_fib_index = bdti;
-                    brpath->frp_proto = DPO_PROTO_BIER;
-                }
-                else
-                {
-                    rv = VNET_API_ERROR_NO_SUCH_FIB;
-                    goto done;
-                }
-            }
+            goto done;
         }
     }
 
@@ -307,11 +258,7 @@ send_bier_route_details (const bier_table_t *bt,
     fp = mp->br_paths;
     vec_foreach (api_rpath, api_rpaths)
     {
-        fp->weight = api_rpath->rpath.frp_weight;
-        fp->preference = api_rpath->rpath.frp_preference;
-        fp->sw_if_index = htonl (api_rpath->rpath.frp_sw_if_index);
-        fp->n_labels = 0;
-        copy_fib_next_hop (api_rpath, fp);
+        fib_api_path_encode(api_rpath, fp);
         fp++;
     }
 
@@ -672,11 +619,7 @@ send_bier_disp_entry_details (const bier_disp_table_t *bdt,
             fp = mp->bde_paths;
             vec_foreach (api_rpath, api_rpaths)
             {
-                fp->weight = api_rpath->rpath.frp_weight;
-                fp->preference = api_rpath->rpath.frp_preference;
-                fp->sw_if_index = htonl (api_rpath->rpath.frp_sw_if_index);
-                fp->n_labels = 0;
-                copy_fib_next_hop (api_rpath, fp);
+                fib_api_path_encode(api_rpath, fp);
                 fp++;
             }