gbp: update gbp-ext-itf API 08/20508/2
authorBenoît Ganne <bganne@cisco.com>
Thu, 4 Jul 2019 14:43:26 +0000 (16:43 +0200)
committerNeale Ranns <nranns@cisco.com>
Fri, 5 Jul 2019 08:48:39 +0000 (08:48 +0000)
Change gbp-ext-itf API to create anonymous ext-itf through the same API
as non-anonymous instead of a new API

Type: refactor

Change-Id: I381ff2a5bcd55276793df78ca891334c28946cd0
Signed-off-by: Benoît Ganne <bganne@cisco.com>
src/plugins/gbp/gbp.api
src/plugins/gbp/gbp_api.c
src/plugins/gbp/gbp_api_print.h
src/plugins/gbp/gbp_ext_itf.c
src/plugins/gbp/gbp_ext_itf.h

index cf0564c..99be9c4 100644 (file)
@@ -393,11 +393,18 @@ define gbp_vxlan_tunnel_details
   vl_api_gbp_vxlan_tunnel_t tunnel;
 };
 
+enum gbp_ext_itf_flags
+{
+  GBP_API_EXT_ITF_F_NONE = 0,
+  GBP_API_EXT_ITF_F_ANON = 1,
+};
+
 typeonly define gbp_ext_itf
 {
   u32 sw_if_index;
   u32 bd_id;
   u32 rd_id;
+  vl_api_gbp_ext_itf_flags_t flags;
 };
 
 manual_print autoreply define gbp_ext_itf_add_del
@@ -420,14 +427,6 @@ define gbp_ext_itf_details
   vl_api_gbp_ext_itf_t ext_itf;
 };
 
-manual_print autoreply define gbp_ext_itf_anon_add_del
-{
-  u32 client_index;
-  u32 context;
-  u8  is_add;
-  vl_api_gbp_ext_itf_t ext_itf;
-};
-
 /*
  * Local Variables:
  * eval: (c-set-style "gnu")
index 3a3ce32..fca85a7 100644 (file)
@@ -82,8 +82,7 @@
   _(GBP_CONTRACT_DUMP, gbp_contract_dump)                   \
   _(GBP_VXLAN_TUNNEL_ADD, gbp_vxlan_tunnel_add)             \
   _(GBP_VXLAN_TUNNEL_DEL, gbp_vxlan_tunnel_del)             \
-  _(GBP_VXLAN_TUNNEL_DUMP, gbp_vxlan_tunnel_dump)           \
-  _(GBP_EXT_ITF_ANON_ADD_DEL, gbp_ext_itf_anon_add_del)
+  _(GBP_VXLAN_TUNNEL_DUMP, gbp_vxlan_tunnel_dump)
 
 gbp_main_t gbp_main;
 
@@ -733,7 +732,8 @@ vl_api_gbp_ext_itf_add_del_t_handler (vl_api_gbp_ext_itf_add_del_t * mp)
 
   if (mp->is_add)
     rv = gbp_ext_itf_add (sw_if_index,
-                         ntohl (ext_itf->bd_id), ntohl (ext_itf->rd_id));
+                         ntohl (ext_itf->bd_id), ntohl (ext_itf->rd_id),
+                         ntohl (ext_itf->flags));
   else
     rv = gbp_ext_itf_delete (sw_if_index);
 
@@ -757,6 +757,7 @@ gbp_ext_itf_send_details (gbp_ext_itf_t * gx, void *args)
   mp->_vl_msg_id = ntohs (VL_API_GBP_EXT_ITF_DETAILS + GBP_MSG_BASE);
   mp->context = ctx->context;
 
+  mp->ext_itf.flags = ntohl (gx->gx_flags);
   mp->ext_itf.bd_id = ntohl (gbp_bridge_domain_get_bd_id (gx->gx_bd));
   mp->ext_itf.rd_id = ntohl (gbp_route_domain_get_rd_id (gx->gx_rd));
   mp->ext_itf.sw_if_index = ntohl (gx->gx_itf);
@@ -1153,34 +1154,6 @@ vl_api_gbp_vxlan_tunnel_dump_t_handler (vl_api_gbp_vxlan_tunnel_dump_t * mp)
   gbp_vxlan_walk (gbp_vxlan_tunnel_send_details, &ctx);
 }
 
-static void
-vl_api_gbp_ext_itf_anon_add_del_t_handler (vl_api_gbp_ext_itf_anon_add_del_t *
-                                          mp)
-{
-  vl_api_gbp_ext_itf_anon_add_del_reply_t *rmp;
-  u32 sw_if_index = ~0;
-  vl_api_gbp_ext_itf_t *ext_itf;
-  int rv = 0;
-
-  ext_itf = &mp->ext_itf;
-  if (ext_itf)
-    sw_if_index = ntohl (ext_itf->sw_if_index);
-
-  if (!vnet_sw_if_index_is_api_valid (sw_if_index))
-    goto bad_sw_if_index;
-
-  if (mp->is_add)
-    rv = gbp_ext_itf_anon_add (sw_if_index,
-                              ntohl (ext_itf->bd_id),
-                              ntohl (ext_itf->rd_id));
-  else
-    rv = gbp_ext_itf_anon_delete (sw_if_index);
-
-  BAD_SW_IF_INDEX_LABEL;
-
-  REPLY_MACRO (VL_API_GBP_EXT_ITF_ANON_ADD_DEL_REPLY + GBP_MSG_BASE);
-}
-
 /*
  * gbp_api_hookup
  * Add vpe's API message handlers to the table.
index b3afc94..39c25b6 100644 (file)
@@ -332,29 +332,7 @@ vl_api_gbp_ext_itf_add_del_t_print (vl_api_gbp_ext_itf_add_del_t * a,
   s = format (s, "sw_if_index %d ", ntohl (a->ext_itf.sw_if_index));
   s = format (s, "bd_id %d ", ntohl (a->ext_itf.bd_id));
   s = format (s, "rd_id %d ", ntohl (a->ext_itf.rd_id));
-
-  s = format (s, "\n");
-
-  PRINT_S;
-
-  return handle;
-}
-
-static inline void *
-vl_api_gbp_ext_itf_anon_add_del_t_print (vl_api_gbp_ext_itf_anon_add_del_t *
-                                        a, void *handle)
-{
-  u8 *s = 0;
-
-  s = format (s, "SCRIPT: gbp_ext_itf_anon_add_del ");
-  if (a->is_add)
-    s = format (s, "add ");
-  else
-    s = format (s, "del ");
-
-  s = format (s, "sw_if_index %d ", ntohl (a->ext_itf.sw_if_index));
-  s = format (s, "bd_id %d ", ntohl (a->ext_itf.bd_id));
-  s = format (s, "rd_id %d ", ntohl (a->ext_itf.rd_id));
+  s = format (s, "flags %x ", ntohl (a->ext_itf.flags));
 
   s = format (s, "\n");
 
index 89bcb3d..6462eca 100644 (file)
@@ -43,13 +43,14 @@ format_gbp_ext_itf (u8 * s, va_list * args)
 {
   gbp_ext_itf_t *gx = va_arg (*args, gbp_ext_itf_t *);
 
-  return (format (s, "%U in %U",
+  return (format (s, "%U%s in %U",
                  format_gbp_itf, gx->gx_itf,
+                 (gx->gx_flags & GBP_EXT_ITF_F_ANON) ? " [anon]" : "",
                  format_gbp_bridge_domain, gx->gx_bd));
 }
 
 int
-gbp_ext_itf_add (u32 sw_if_index, u32 bd_id, u32 rd_id)
+gbp_ext_itf_add (u32 sw_if_index, u32 bd_id, u32 rd_id, u32 flags)
 {
   gbp_ext_itf_t *gx;
   index_t gxi;
@@ -92,6 +93,20 @@ gbp_ext_itf_add (u32 sw_if_index, u32 bd_id, u32 rd_id)
          gr->grd_fib_index[fib_proto_to_dpo (fproto)];
       }
 
+      if (flags & GBP_EXT_ITF_F_ANON)
+       {
+         /* add interface to the BD */
+         index_t itf = gbp_itf_add_and_lock (sw_if_index, bd_id);
+         /* setup GBP L2 features on this interface */
+         gbp_itf_set_l2_input_feature (itf, 0,
+                                       L2INPUT_FEAT_GBP_LPM_ANON_CLASSIFY |
+                                       L2INPUT_FEAT_LEARN);
+         gbp_itf_set_l2_output_feature (itf, 0,
+                                        L2OUTPUT_FEAT_GBP_POLICY_LPM);
+       }
+
+      gx->gx_flags = flags;
+
       gbp_ext_itf_db[sw_if_index] = gxi;
 
       GBP_EXT_ITF_DBG ("add: %U", format_gbp_ext_itf, gx);
@@ -119,6 +134,9 @@ gbp_ext_itf_delete (u32 sw_if_index)
 
       GBP_EXT_ITF_DBG ("del: %U", format_gbp_ext_itf, gx);
 
+      if (gx->gx_flags & GBP_EXT_ITF_F_ANON)
+       gbp_itf_unlock (gx->gx_itf);
+
       gbp_route_domain_unlock (gx->gx_rd);
       gbp_bridge_domain_unlock (gx->gx_bd);
 
@@ -130,39 +148,13 @@ gbp_ext_itf_delete (u32 sw_if_index)
   return (VNET_API_ERROR_NO_SUCH_ENTRY);
 }
 
-int
-gbp_ext_itf_anon_add (u32 sw_if_index, u32 bd_id, u32 rd_id)
-{
-  int rv = gbp_ext_itf_add (sw_if_index, bd_id, rd_id);
-  if (rv)
-    return rv;
-  /* add interface to the BD */
-  index_t itf = gbp_itf_add_and_lock (sw_if_index, bd_id);
-  /* setup GBP L2 features on this interface */
-  gbp_itf_set_l2_input_feature (itf, 0,
-                               L2INPUT_FEAT_GBP_LPM_ANON_CLASSIFY |
-                               L2INPUT_FEAT_LEARN);
-  gbp_itf_set_l2_output_feature (itf, 0, L2OUTPUT_FEAT_GBP_POLICY_LPM);
-  return 0;
-}
-
-int
-gbp_ext_itf_anon_delete (u32 sw_if_index)
-{
-  int rv = gbp_ext_itf_delete (sw_if_index);
-  if (rv)
-    return rv;
-  gbp_itf_unlock (sw_if_index);
-  return 0;
-}
-
 static clib_error_t *
 gbp_ext_itf_add_del_cli (vlib_main_t * vm,
                         unformat_input_t * input, vlib_cli_command_t * cmd)
 {
   unformat_input_t _line_input, *line_input = &_line_input;
-  u32 sw_if_index = ~0, bd_id = ~0, rd_id = ~0;
-  int add = 1, anon = 0;
+  u32 sw_if_index = ~0, bd_id = ~0, rd_id = ~0, flags = 0;
+  int add = 1;
   int rv;
 
   /* Get a line of input. */
@@ -183,7 +175,7 @@ gbp_ext_itf_add_del_cli (vlib_main_t * vm,
       else if (unformat (line_input, "rd %d", &rd_id))
        ;
       else if (unformat (line_input, "anon-l3-out"))
-       anon = 1;
+       flags |= GBP_EXT_ITF_F_ANON;
       else
        return clib_error_return (0, "unknown input `%U'",
                                  format_unformat_error, line_input);
@@ -199,18 +191,10 @@ gbp_ext_itf_add_del_cli (vlib_main_t * vm,
        return clib_error_return (0, "BD-ID must be specified");
       if (~0 == rd_id)
        return clib_error_return (0, "RD-ID must be specified");
-      if (anon)
-       rv = gbp_ext_itf_anon_add (sw_if_index, bd_id, rd_id);
-      else
-       rv = gbp_ext_itf_add (sw_if_index, bd_id, rd_id);
+      rv = gbp_ext_itf_add (sw_if_index, bd_id, rd_id, flags);
     }
   else
-    {
-      if (anon)
-       rv = gbp_ext_itf_anon_delete (sw_if_index);
-      else
-       rv = gbp_ext_itf_delete (sw_if_index);
-    }
+    rv = gbp_ext_itf_delete (sw_if_index);
 
   switch (rv)
     {
index d1b0f98..f3829ca 100644 (file)
 
 #include <gbp/gbp.h>
 
+enum
+{
+  GBP_EXT_ITF_F_NONE = 0,
+  GBP_EXT_ITF_F_ANON = 1 << 0,
+};
+
 /**
  * An external interface maps directly to an oflex L3ExternalInterface.
  * The special characteristics of an external interface is the way the source
@@ -46,15 +52,17 @@ typedef struct gpb_ext_itf_t_
    */
   u32 gx_fib_index[DPO_PROTO_NUM];
 
+  /**
+   * The associated flags
+   */
+  u32 gx_flags;
+
 } gbp_ext_itf_t;
 
 
-extern int gbp_ext_itf_add (u32 sw_if_index, u32 bd_id, u32 rd_id);
+extern int gbp_ext_itf_add (u32 sw_if_index, u32 bd_id, u32 rd_id, u32 flags);
 extern int gbp_ext_itf_delete (u32 sw_if_index);
 
-extern int gbp_ext_itf_anon_add (u32 sw_if_index, u32 bd_id, u32 rd_id);
-extern int gbp_ext_itf_anon_delete (u32 sw_if_index);
-
 extern u8 *format_gbp_ext_itf (u8 * s, va_list * args);
 
 typedef walk_rc_t (*gbp_ext_itf_cb_t) (gbp_ext_itf_t * gbpe, void *ctx);