FIB table add/delete API only
[vpp.git] / src / vnet / ip / ip_api.c
index 9c9cb4a..bba65ab 100644 (file)
@@ -69,6 +69,7 @@ _(IP_ADDRESS_DUMP, ip_address_dump)                                     \
 _(IP_DUMP, ip_dump)                                                     \
 _(IP_NEIGHBOR_ADD_DEL, ip_neighbor_add_del)                             \
 _(IP_ADD_DEL_ROUTE, ip_add_del_route)                                   \
+_(IP_TABLE_ADD_DEL, ip_table_add_del)                                   \
 _(SET_IP_FLOW_HASH,set_ip_flow_hash)                                    \
 _(SW_INTERFACE_IP6ND_RA_CONFIG, sw_interface_ip6nd_ra_config)           \
 _(SW_INTERFACE_IP6ND_RA_PREFIX, sw_interface_ip6nd_ra_prefix)           \
@@ -156,9 +157,9 @@ copy_fib_next_hop (fib_route_path_encode_t * api_rpath, void *fp_arg)
   int is_ip4;
   vl_api_fib_path_t *fp = (vl_api_fib_path_t *) fp_arg;
 
-  if (api_rpath->rpath.frp_proto == FIB_PROTOCOL_IP4)
+  if (api_rpath->rpath.frp_proto == DPO_PROTO_IP4)
     fp->afi = IP46_TYPE_IP4;
-  else if (api_rpath->rpath.frp_proto == FIB_PROTOCOL_IP6)
+  else if (api_rpath->rpath.frp_proto == DPO_PROTO_IP6)
     fp->afi = IP46_TYPE_IP6;
   else
     {
@@ -231,7 +232,8 @@ send_ip_fib_details (vpe_api_main_t * am,
       default:
        break;
       }
-    fp->weight = htonl (api_rpath->rpath.frp_weight);
+    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);
     copy_fib_next_hop (api_rpath, fp);
     fp++;
@@ -357,8 +359,9 @@ send_ip6_fib_details (vpe_api_main_t * am,
       default:
        break;
       }
-    fp->weight = htonl (api_rpath->rpath.frp_weight);
-    fp->sw_if_index = htonl (api_rpath->rpath.frp_sw_if_index);
+    fp->weight = api_rpath->rpath.frp_weight;
+    fp->preference = api_rpath->rpath.frp_preference;
+    fp->sw_if_index = api_rpath->rpath.frp_sw_if_index;
     copy_fib_next_hop (api_rpath, fp);
     fp++;
   }
@@ -696,6 +699,15 @@ vl_api_ip_neighbor_add_del_t_handler (vl_api_ip_neighbor_add_del_t * mp,
   REPLY_MACRO (VL_API_IP_NEIGHBOR_ADD_DEL_REPLY);
 }
 
+void
+vl_api_ip_table_add_del_t_handler (vl_api_ip_table_add_del_t * mp)
+{
+  vl_api_ip_table_add_del_reply_t *rmp;
+  int rv = 0;
+
+  REPLY_MACRO (VL_API_IP_TABLE_ADD_DEL_REPLY);
+}
+
 int
 add_del_route_t_handler (u8 is_multipath,
                         u8 is_add,
@@ -712,23 +724,24 @@ add_del_route_t_handler (u8 is_multipath,
                         u8 is_rpf_id,
                         u32 fib_index,
                         const fib_prefix_t * prefix,
-                        u8 next_hop_proto_is_ip4,
+                        dpo_proto_t next_hop_proto,
                         const ip46_address_t * next_hop,
                         u32 next_hop_sw_if_index,
                         u8 next_hop_fib_index,
-                        u32 next_hop_weight,
+                        u16 next_hop_weight,
+                        u16 next_hop_preference,
                         mpls_label_t next_hop_via_label,
                         mpls_label_t * next_hop_out_label_stack)
 {
   vnet_classify_main_t *cm = &vnet_classify_main;
   fib_route_path_flags_t path_flags = FIB_ROUTE_PATH_FLAG_NONE;
   fib_route_path_t path = {
-    .frp_proto = (next_hop_proto_is_ip4 ?
-                 FIB_PROTOCOL_IP4 : FIB_PROTOCOL_IP6),
+    .frp_proto = next_hop_proto,
     .frp_addr = (NULL == next_hop ? zero_addr : *next_hop),
     .frp_sw_if_index = next_hop_sw_if_index,
     .frp_fib_index = next_hop_fib_index,
     .frp_weight = next_hop_weight,
+    .frp_preference = next_hop_preference,
     .frp_label_stack = next_hop_out_label_stack,
   };
   fib_route_path_t *paths = NULL;
@@ -736,7 +749,7 @@ add_del_route_t_handler (u8 is_multipath,
 
   if (MPLS_LABEL_INVALID != next_hop_via_label)
     {
-      path.frp_proto = FIB_PROTOCOL_MPLS;
+      path.frp_proto = DPO_PROTO_MPLS;
       path.frp_local_label = next_hop_via_label;
       path.frp_eos = MPLS_NON_EOS;
     }
@@ -851,7 +864,7 @@ int
 add_del_route_check (fib_protocol_t table_proto,
                     u32 table_id,
                     u32 next_hop_sw_if_index,
-                    fib_protocol_t next_hop_table_proto,
+                    dpo_proto_t next_hop_table_proto,
                     u32 next_hop_table_id,
                     u8 create_missing_tables,
                     u8 is_rpf_id, u32 * fib_index, u32 * next_hop_fib_index)
@@ -883,11 +896,18 @@ add_del_route_check (fib_protocol_t table_proto,
     }
   else
     {
+      fib_protocol_t fib_nh_proto;
+
+      if (next_hop_table_proto > DPO_PROTO_MPLS)
+       return (0);
+
+      fib_nh_proto = dpo_proto_to_fib (next_hop_table_proto);
+
       if (is_rpf_id)
-       *next_hop_fib_index = mfib_table_find (next_hop_table_proto,
+       *next_hop_fib_index = mfib_table_find (fib_nh_proto,
                                               ntohl (next_hop_table_id));
       else
-       *next_hop_fib_index = fib_table_find (next_hop_table_proto,
+       *next_hop_fib_index = fib_table_find (fib_nh_proto,
                                              ntohl (next_hop_table_id));
 
       if (~0 == *next_hop_fib_index)
@@ -896,12 +916,12 @@ add_del_route_check (fib_protocol_t table_proto,
            {
              if (is_rpf_id)
                *next_hop_fib_index =
-                 mfib_table_find_or_create_and_lock (next_hop_table_proto,
+                 mfib_table_find_or_create_and_lock (fib_nh_proto,
                                                      ntohl
                                                      (next_hop_table_id));
              else
                *next_hop_fib_index =
-                 fib_table_find_or_create_and_lock (next_hop_table_proto,
+                 fib_table_find_or_create_and_lock (fib_nh_proto,
                                                     ntohl
                                                     (next_hop_table_id));
            }
@@ -926,7 +946,7 @@ ip4_add_del_route_t_handler (vl_api_ip_add_del_route_t * mp)
   rv = add_del_route_check (FIB_PROTOCOL_IP4,
                            mp->table_id,
                            mp->next_hop_sw_if_index,
-                           FIB_PROTOCOL_IP4,
+                           DPO_PROTO_IP4,
                            mp->next_hop_table_id,
                            mp->create_vrf_if_needed, 0,
                            &fib_index, &next_hop_fib_index);
@@ -966,11 +986,12 @@ ip4_add_del_route_t_handler (vl_api_ip_add_del_route_t * mp)
                                   mp->classify_table_index,
                                   mp->is_resolve_host,
                                   mp->is_resolve_attached, 0, 0,
-                                  fib_index, &pfx, 1,
+                                  fib_index, &pfx, DPO_PROTO_IP4,
                                   &nh,
                                   ntohl (mp->next_hop_sw_if_index),
                                   next_hop_fib_index,
                                   mp->next_hop_weight,
+                                  mp->next_hop_preference,
                                   ntohl (mp->next_hop_via_label),
                                   label_stack));
 }
@@ -985,7 +1006,7 @@ ip6_add_del_route_t_handler (vl_api_ip_add_del_route_t * mp)
   rv = add_del_route_check (FIB_PROTOCOL_IP6,
                            mp->table_id,
                            mp->next_hop_sw_if_index,
-                           FIB_PROTOCOL_IP6,
+                           DPO_PROTO_IP6,
                            mp->next_hop_table_id,
                            mp->create_vrf_if_needed, 0,
                            &fib_index, &next_hop_fib_index);
@@ -1025,10 +1046,11 @@ ip6_add_del_route_t_handler (vl_api_ip_add_del_route_t * mp)
                                   mp->classify_table_index,
                                   mp->is_resolve_host,
                                   mp->is_resolve_attached, 0, 0,
-                                  fib_index, &pfx, 0,
+                                  fib_index, &pfx, DPO_PROTO_IP6,
                                   &nh, ntohl (mp->next_hop_sw_if_index),
                                   next_hop_fib_index,
                                   mp->next_hop_weight,
+                                  mp->next_hop_preference,
                                   ntohl (mp->next_hop_via_label),
                                   label_stack));
 }
@@ -1100,7 +1122,7 @@ mroute_add_del_handler (u8 is_add,
 
   fib_route_path_t path = {
     .frp_sw_if_index = next_hop_sw_if_index,
-    .frp_proto = prefix->fp_proto,
+    .frp_proto = fib_proto_to_dpo (prefix->fp_proto),
   };
 
   if (is_local)
@@ -1336,9 +1358,17 @@ static void
 set_ip6_flow_hash (vl_api_set_ip_flow_hash_t * mp)
 {
   vl_api_set_ip_flow_hash_reply_t *rmp;
-  int rv = VNET_API_ERROR_UNIMPLEMENTED;
+  int rv;
+  u32 table_id;
+  flow_hash_config_t flow_hash_config = 0;
+
+  table_id = ntohl (mp->vrf_id);
+
+#define _(a,b) if (mp->a) flow_hash_config |= b;
+  foreach_flow_hash_bit;
+#undef _
 
-  clib_warning ("unimplemented...");
+  rv = vnet_set_ip6_flow_hash (table_id, flow_hash_config);
 
   REPLY_MACRO (VL_API_SET_IP_FLOW_HASH_REPLY);
 }