VPP-448 Fix LISP APIs using binary data
[vpp.git] / vpp-api-test / vat / api_format.c
index e29b47e..4b1d41f 100644 (file)
@@ -35,7 +35,7 @@
 #include <vnet/l2/l2_vtr.h>
 #include <vnet/classify/input_acl.h>
 #include <vnet/classify/policer_classify.h>
-#include <vnet/mpls-gre/mpls.h>
+#include <vnet/mpls/mpls.h>
 #if DPDK > 0
 #include <vnet/ipsec/ipsec.h>
 #include <vnet/ipsec/ikev2.h>
@@ -2711,6 +2711,62 @@ static void
   vam->result_ready = 1;
 }
 
+static u8 *
+format_lisp_map_request_mode (u8 * s, va_list * args)
+{
+  u32 mode = va_arg (*args, u32);
+
+  switch (mode)
+    {
+    case 0:
+      return format (0, "dst-only");
+    case 1:
+      return format (0, "src-dst");
+    }
+  return 0;
+}
+
+static void
+  vl_api_show_lisp_map_request_mode_reply_t_handler
+  (vl_api_show_lisp_map_request_mode_reply_t * mp)
+{
+  vat_main_t *vam = &vat_main;
+  i32 retval = ntohl (mp->retval);
+
+  if (0 <= retval)
+    {
+      u32 mode = mp->mode;
+      fformat (vam->ofp, "map_request_mode: %U\n",
+              format_lisp_map_request_mode, mode);
+    }
+
+  vam->retval = retval;
+  vam->result_ready = 1;
+}
+
+static void
+  vl_api_show_lisp_map_request_mode_reply_t_handler_json
+  (vl_api_show_lisp_map_request_mode_reply_t * mp)
+{
+  vat_main_t *vam = &vat_main;
+  vat_json_node_t node;
+  u8 *s = 0;
+  u32 mode;
+
+  mode = mp->mode;
+  s = format (0, "%U", format_lisp_map_request_mode, mode);
+  vec_add1 (s, 0);
+
+  vat_json_init_object (&node);
+  vat_json_object_add_string_copy (&node, "map_request_mode", s);
+  vat_json_print (vam->ofp, &node);
+  vat_json_free (&node);
+
+  vec_free (s);
+  vam->retval = ntohl (mp->retval);
+  vam->result_ready = 1;
+}
+
 static void
 vl_api_show_lisp_pitr_reply_t_handler (vl_api_show_lisp_pitr_reply_t * mp)
 {
@@ -3407,6 +3463,7 @@ _(lisp_gpe_enable_disable_reply)                        \
 _(lisp_gpe_add_del_iface_reply)                         \
 _(lisp_enable_disable_reply)                            \
 _(lisp_pitr_set_locator_set_reply)                      \
+_(lisp_map_request_mode_reply)                          \
 _(lisp_add_del_map_request_itr_rlocs_reply)             \
 _(lisp_eid_table_add_del_map_reply)                     \
 _(vxlan_gpe_add_del_tunnel_reply)                       \
@@ -3599,6 +3656,7 @@ _(LISP_ADD_DEL_MAP_RESOLVER_REPLY, lisp_add_del_map_resolver_reply)     \
 _(LISP_GPE_ENABLE_DISABLE_REPLY, lisp_gpe_enable_disable_reply)         \
 _(LISP_ENABLE_DISABLE_REPLY, lisp_enable_disable_reply)                 \
 _(LISP_PITR_SET_LOCATOR_SET_REPLY, lisp_pitr_set_locator_set_reply)     \
+_(LISP_MAP_REQUEST_MODE_REPLY, lisp_map_request_mode_reply)             \
 _(LISP_EID_TABLE_ADD_DEL_MAP_REPLY, lisp_eid_table_add_del_map_reply)   \
 _(LISP_GPE_ADD_DEL_IFACE_REPLY, lisp_gpe_add_del_iface_reply)           \
 _(LISP_LOCATOR_SET_DETAILS, lisp_locator_set_details)                   \
@@ -3614,6 +3672,7 @@ _(LISP_ADD_DEL_MAP_REQUEST_ITR_RLOCS_REPLY,                             \
 _(LISP_GET_MAP_REQUEST_ITR_RLOCS_REPLY,                                 \
   lisp_get_map_request_itr_rlocs_reply)                                 \
 _(SHOW_LISP_PITR_REPLY, show_lisp_pitr_reply)                           \
+_(SHOW_LISP_MAP_REQUEST_MODE_REPLY, show_lisp_map_request_mode_reply)   \
 _(AF_PACKET_CREATE_REPLY, af_packet_create_reply)                       \
 _(AF_PACKET_DELETE_REPLY, af_packet_delete_reply)                       \
 _(POLICER_ADD_DEL_REPLY, policer_add_del_reply)                         \
@@ -5346,6 +5405,7 @@ api_ip_add_del_route (vat_main_t * vam)
   u32 random_seed = 0xdeaddabe;
   u32 classify_table_index = ~0;
   u8 is_classify = 0;
+  u8 resolve_host, resolve_attached;
 
   /* Parse args required to build the message */
   while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
@@ -5401,6 +5461,10 @@ api_ip_add_del_route (vat_main_t * vam)
        is_add = 1;
       else if (unformat (i, "not-last"))
        not_last = 1;
+      else if (unformat (i, "resolve-via-host"))
+       resolve_host = 1;
+      else if (unformat (i, "resolve-via-attached"))
+       resolve_attached = 1;
       else if (unformat (i, "multipath"))
        is_multipath = 1;
       else if (unformat (i, "vrf %d", &vrf_id))
@@ -5497,6 +5561,8 @@ api_ip_add_del_route (vat_main_t * vam)
       mp->is_local = is_local;
       mp->is_classify = is_classify;
       mp->is_multipath = is_multipath;
+      mp->is_resolve_host = resolve_host;
+      mp->is_resolve_attached = resolve_attached;
       mp->not_last = not_last;
       mp->next_hop_weight = next_hop_weight;
       mp->dst_address_length = dst_address_length;
@@ -7860,7 +7926,6 @@ out:
 }
 
 #define foreach_ip_next                         \
-_(miss, MISS)                                   \
 _(drop, DROP)                                   \
 _(local, LOCAL)                                 \
 _(rewrite, REWRITE)
@@ -9446,6 +9511,7 @@ api_gre_add_del_tunnel (vat_main_t * vam)
   f64 timeout;
   ip4_address_t src4, dst4;
   u8 is_add = 1;
+  u8 teb = 0;
   u8 src_set = 0;
   u8 dst_set = 0;
   u32 outer_fib_id = 0;
@@ -9460,6 +9526,8 @@ api_gre_add_del_tunnel (vat_main_t * vam)
        dst_set = 1;
       else if (unformat (line_input, "outer-fib-id %d", &outer_fib_id))
        ;
+      else if (unformat (line_input, "teb"))
+       teb = 1;
       else
        {
          errmsg ("parse error '%U'\n", format_unformat_error, line_input);
@@ -9485,6 +9553,7 @@ api_gre_add_del_tunnel (vat_main_t * vam)
   clib_memcpy (&mp->dst_address, &dst4, sizeof (dst4));
   mp->outer_fib_id = ntohl (outer_fib_id);
   mp->is_add = is_add;
+  mp->teb = teb;
 
   S;
   W;
@@ -9497,10 +9566,11 @@ static void vl_api_gre_tunnel_details_t_handler
 {
   vat_main_t *vam = &vat_main;
 
-  fformat (vam->ofp, "%11d%15U%15U%14d\n",
+  fformat (vam->ofp, "%11d%15U%15U%6d%14d\n",
           ntohl (mp->sw_if_index),
           format_ip4_address, &mp->src_address,
-          format_ip4_address, &mp->dst_address, ntohl (mp->outer_fib_id));
+          format_ip4_address, &mp->dst_address,
+          mp->teb, ntohl (mp->outer_fib_id));
 }
 
 static void vl_api_gre_tunnel_details_t_handler_json
@@ -9523,6 +9593,7 @@ static void vl_api_gre_tunnel_details_t_handler_json
   vat_json_object_add_ip4 (node, "src_address", ip4);
   clib_memcpy (&ip4, &mp->dst_address, sizeof (ip4));
   vat_json_object_add_ip4 (node, "dst_address", ip4);
+  vat_json_object_add_uint (node, "teb", mp->teb);
   vat_json_object_add_uint (node, "outer_fib_id", ntohl (mp->outer_fib_id));
 }
 
@@ -9551,8 +9622,9 @@ api_gre_tunnel_dump (vat_main_t * vam)
 
   if (!vam->json_output)
     {
-      fformat (vam->ofp, "%11s%15s%15s%14s\n",
-              "sw_if_index", "src_address", "dst_address", "outer_fib_id");
+      fformat (vam->ofp, "%11s%15s%15s%6s%14s\n",
+              "sw_if_index", "src_address", "dst_address", "teb",
+              "outer_fib_id");
     }
 
   /* Get list of gre-tunnel interfaces */
@@ -11798,6 +11870,7 @@ api_lisp_add_del_locator_set (vat_main_t * vam)
   u8 locator_set_name_set = 0;
   ls_locator_t locator, *locators = 0;
   u32 sw_if_index, priority, weight;
+  u32 data_len = 0;
 
   /* Parse args required to build the message */
   while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
@@ -11846,8 +11919,10 @@ api_lisp_add_del_locator_set (vat_main_t * vam)
     }
   vec_add1 (locator_set_name, 0);
 
+  data_len = sizeof (ls_locator_t) * vec_len (locators);
+
   /* Construct the API message */
-  M (LISP_ADD_DEL_LOCATOR_SET, lisp_add_del_locator_set);
+  M2 (LISP_ADD_DEL_LOCATOR_SET, lisp_add_del_locator_set, data_len);
 
   mp->is_add = is_add;
   clib_memcpy (mp->locator_set_name, locator_set_name,
@@ -11856,8 +11931,7 @@ api_lisp_add_del_locator_set (vat_main_t * vam)
 
   mp->locator_num = clib_host_to_net_u32 (vec_len (locators));
   if (locators)
-    clib_memcpy (mp->locators, locators,
-                (sizeof (ls_locator_t) * vec_len (locators)));
+    clib_memcpy (mp->locators, locators, data_len);
   vec_free (locators);
 
   /* send it... */
@@ -12367,6 +12441,59 @@ api_lisp_enable_disable (vat_main_t * vam)
   return 0;
 }
 
+static int
+api_show_lisp_map_request_mode (vat_main_t * vam)
+{
+  f64 timeout = ~0;
+  vl_api_show_lisp_map_request_mode_t *mp;
+
+  M (SHOW_LISP_MAP_REQUEST_MODE, show_lisp_map_request_mode);
+
+  /* send */
+  S;
+
+  /* wait for reply */
+  W;
+
+  return 0;
+}
+
+static int
+api_lisp_map_request_mode (vat_main_t * vam)
+{
+  f64 timeout = ~0;
+  unformat_input_t *input = vam->input;
+  vl_api_lisp_map_request_mode_t *mp;
+  u8 mode = 0;
+
+  /* Parse args required to build the message */
+  while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
+    {
+      if (unformat (input, "dst-only"))
+       mode = 0;
+      else if (unformat (input, "src-dst"))
+       mode = 1;
+      else
+       {
+         errmsg ("parse error '%U'", format_unformat_error, input);
+         return -99;
+       }
+    }
+
+  M (LISP_MAP_REQUEST_MODE, lisp_map_request_mode);
+
+  mp->mode = mode;
+
+  /* send */
+  S;
+
+  /* wait for reply */
+  W;
+
+  /* notreached */
+  return 0;
+}
+
 /**
  * Enable/disable LISP proxy ITR.
  *
@@ -12542,7 +12669,7 @@ api_lisp_add_del_remote_mapping (vat_main_t * vam)
   lisp_eid_vat_t _eid, *eid = &_eid;
   lisp_eid_vat_t _seid, *seid = &_seid;
   u8 is_add = 1, del_all = 0, eid_set = 0, seid_set = 0;
-  u32 action = ~0, p, w;
+  u32 action = ~0, p, w, data_len;
   ip4_address_t rloc4;
   ip6_address_t rloc6;
   rloc_t *rlocs = 0, rloc, *curr_rloc = 0;
@@ -12624,7 +12751,9 @@ api_lisp_add_del_remote_mapping (vat_main_t * vam)
       return -99;
     }
 
-  M (LISP_ADD_DEL_REMOTE_MAPPING, lisp_add_del_remote_mapping);
+  data_len = vec_len (rlocs) * sizeof (rloc_t);
+
+  M2 (LISP_ADD_DEL_REMOTE_MAPPING, lisp_add_del_remote_mapping, data_len);
   mp->is_add = is_add;
   mp->vni = htonl (vni);
   mp->action = (u8) action;
@@ -12637,7 +12766,7 @@ api_lisp_add_del_remote_mapping (vat_main_t * vam)
   lisp_eid_put_vat (mp->seid, seid->addr, seid->type);
 
   mp->rloc_num = clib_host_to_net_u32 (vec_len (rlocs));
-  clib_memcpy (mp->rlocs, rlocs, (sizeof (rloc_t) * vec_len (rlocs)));
+  clib_memcpy (mp->rlocs, rlocs, data_len);
   vec_free (rlocs);
 
   /* send it... */
@@ -12956,6 +13085,12 @@ api_lisp_locator_dump (vat_main_t * vam)
       return -99;
     }
 
+  if (vec_len (ls_name) > 62)
+    {
+      errmsg ("error: locator set name too long!");
+      return -99;
+    }
+
   if (!vam->json_output)
     {
       fformat (vam->ofp, "%=16s%=16s%=16s\n", "locator", "priority",
@@ -12970,7 +13105,8 @@ api_lisp_locator_dump (vat_main_t * vam)
   else
     {
       vec_add1 (ls_name, 0);
-      strcpy ((char *) mp->ls_name, (char *) ls_name);
+      strncpy ((char *) mp->ls_name, (char *) ls_name,
+              sizeof (mp->ls_name) - 1);
     }
 
   /* send it... */
@@ -15281,7 +15417,7 @@ _(vxlan_add_del_tunnel,                                                 \
   " [decap-next l2|ip4|ip6] [del]")                                     \
 _(vxlan_tunnel_dump, "[<intfc> | sw_if_index <nn>]")                    \
 _(gre_add_del_tunnel,                                                   \
-  "src <ip4-addr> dst <ip4-addr> [outer-fib-id <nn>] [del]\n")          \
+  "src <ip4-addr> dst <ip4-addr> [outer-fib-id <nn>] [teb] [del]\n")    \
 _(gre_tunnel_dump, "[<intfc> | sw_if_index <nn>]")                      \
 _(l2_fib_clear_table, "")                                               \
 _(l2_interface_efp_filter, "sw_if_index <nn> enable | disable")         \
@@ -15378,6 +15514,7 @@ _(lisp_add_del_adjacency, "add|del vni <vni> deid <dest-eid> seid "     \
                           "<src-eid> rloc <locator> p <prio> w <weight>"\
                           "[rloc <loc> ... ] action <action>")          \
 _(lisp_pitr_set_locator_set, "locator-set <loc-set-name> | del")        \
+_(lisp_map_request_mode, "src-dst|dst-only")                            \
 _(lisp_add_del_map_request_itr_rlocs, "<loc-set-name> [del]")           \
 _(lisp_eid_table_add_del_map, "[del] vni <vni> vrf <vrf>")              \
 _(lisp_locator_set_dump, "[local | remote]")                            \
@@ -15391,6 +15528,7 @@ _(lisp_map_resolver_dump, "")                                           \
 _(show_lisp_status, "")                                                 \
 _(lisp_get_map_request_itr_rlocs, "")                                   \
 _(show_lisp_pitr, "")                                                   \
+_(show_lisp_map_request_mode, "")                                       \
 _(af_packet_create, "name <host interface name> [hw_addr <mac>]")       \
 _(af_packet_delete, "name <host interface name>")                       \
 _(policer_add_del, "name <policer name> <params> [del]")                \