Add in-message cli_request/cli_reply API
[vpp.git] / vpp-api-test / vat / api_format.c
index c1a472a..b9cfd75 100644 (file)
@@ -893,6 +893,34 @@ vl_api_cli_reply_t_handler_json (vl_api_cli_reply_t * mp)
   vam->result_ready = 1;
 }
 
+static void
+vl_api_cli_inband_reply_t_handler (vl_api_cli_inband_reply_t * mp)
+{
+  vat_main_t *vam = &vat_main;
+  i32 retval = ntohl (mp->retval);
+
+  vam->retval = retval;
+  vam->cmd_reply = mp->reply;
+  vam->result_ready = 1;
+}
+
+static void
+vl_api_cli_inband_reply_t_handler_json (vl_api_cli_inband_reply_t * mp)
+{
+  vat_main_t *vam = &vat_main;
+  vat_json_node_t node;
+
+  vat_json_init_object (&node);
+  vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
+  vat_json_object_add_string_copy (&node, "reply", mp->reply);
+
+  vat_json_print (vam->ofp, &node);
+  vat_json_free (&node);
+
+  vam->retval = ntohl (mp->retval);
+  vam->result_ready = 1;
+}
+
 static void vl_api_classify_add_del_table_reply_t_handler
   (vl_api_classify_add_del_table_reply_t * mp)
 {
@@ -1134,6 +1162,21 @@ vl_api_ip4_arp_event_t_handler_json (vl_api_ip4_arp_event_t * mp)
   /* JSON output not supported */
 }
 
+static void
+vl_api_ip6_nd_event_t_handler (vl_api_ip6_nd_event_t * mp)
+{
+  vat_main_t *vam = &vat_main;
+  errmsg ("ip6 nd event: address %U new mac %U sw_if_index %d\n",
+         format_ip6_address, mp->address,
+         format_ethernet_address, mp->new_mac, mp->sw_if_index);
+}
+
+static void
+vl_api_ip6_nd_event_t_handler_json (vl_api_ip6_nd_event_t * mp)
+{
+  /* JSON output not supported */
+}
+
 /*
  * Special-case: build the bridge domain table, maintain
  * the next bd id vbl.
@@ -3341,6 +3384,7 @@ _(l2_interface_vlan_tag_rewrite_reply)                  \
 _(modify_vhost_user_if_reply)                           \
 _(delete_vhost_user_if_reply)                           \
 _(want_ip4_arp_events_reply)                            \
+_(want_ip6_nd_events_reply)                             \
 _(input_acl_set_interface_reply)                        \
 _(ipsec_spd_add_del_reply)                              \
 _(ipsec_interface_add_del_spd_reply)                    \
@@ -3432,6 +3476,7 @@ _(SW_INTERFACE_SET_FLAGS_REPLY, sw_interface_set_flags_reply)           \
 _(CONTROL_PING_REPLY, control_ping_reply)                               \
 _(NOPRINT_CONTROL_PING_REPLY, noprint_control_ping_reply)               \
 _(CLI_REPLY, cli_reply)                                                 \
+_(CLI_INBAND_REPLY, cli_inband_reply)                                   \
 _(SW_INTERFACE_ADD_DEL_ADDRESS_REPLY,                                   \
   sw_interface_add_del_address_reply)                                   \
 _(SW_INTERFACE_SET_TABLE_REPLY, sw_interface_set_table_reply)          \
@@ -3519,6 +3564,8 @@ _(VXLAN_GPE_TUNNEL_DETAILS, vxlan_gpe_tunnel_details)                   \
 _(INTERFACE_NAME_RENUMBER_REPLY, interface_name_renumber_reply)                \
 _(WANT_IP4_ARP_EVENTS_REPLY, want_ip4_arp_events_reply)                        \
 _(IP4_ARP_EVENT, ip4_arp_event)                                         \
+_(WANT_IP6_ND_EVENTS_REPLY, want_ip6_nd_events_reply)                  \
+_(IP6_ND_EVENT, ip6_nd_event)                                          \
 _(INPUT_ACL_SET_INTERFACE_REPLY, input_acl_set_interface_reply)         \
 _(IP_ADDRESS_DETAILS, ip_address_details)                               \
 _(IP_DETAILS, ip_details)                                               \
@@ -4069,6 +4116,45 @@ exec (vat_main_t * vam)
   return -99;
 }
 
+/*
+ * Future replacement of exec() that passes CLI buffers directly in
+ * the API messages instead of an additional shared memory area.
+ */
+static int
+exec_inband (vat_main_t * vam)
+{
+  vl_api_cli_inband_t *mp;
+  f64 timeout;
+  unformat_input_t *i = vam->input;
+
+  if (vec_len (i->buffer) == 0)
+    return -1;
+
+  if (vam->exec_mode == 0 && unformat (i, "mode"))
+    {
+      vam->exec_mode = 1;
+      return 0;
+    }
+  if (vam->exec_mode == 1 && (unformat (i, "exit") || unformat (i, "quit")))
+    {
+      vam->exec_mode = 0;
+      return 0;
+    }
+
+  /*
+   * In order for the CLI command to work, it
+   * must be a vector ending in \n, not a C-string ending
+   * in \n\0.
+   */
+  u32 len = vec_len (vam->input->buffer);
+  M2 (CLI_INBAND, cli_inband, len);
+  clib_memcpy (mp->cmd, vam->input->buffer, len);
+  mp->length = htonl (len);
+
+  S;
+  W2 (fformat (vam->ofp, "%s", vam->cmd_reply));
+}
+
 static int
 api_create_loopback (vat_main_t * vam)
 {
@@ -7837,7 +7923,7 @@ unformat_l2_next_index (unformat_input_t * input, va_list * args)
   u32 tmp;
 
 #define _(n,N) \
-  if (unformat (input, #n)) { next_index = L2_CLASSIFY_NEXT_##N; goto out;}
+  if (unformat (input, #n)) { next_index = L2_INPUT_CLASSIFY_NEXT_##N; goto out;}
   foreach_l2_next;
 #undef _
 
@@ -8552,6 +8638,7 @@ api_classify_set_interface_l2_tables (vat_main_t * vam)
   u32 ip4_table_index = ~0;
   u32 ip6_table_index = ~0;
   u32 other_table_index = ~0;
+  u32 is_input = 1;
 
   while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
     {
@@ -8565,6 +8652,8 @@ api_classify_set_interface_l2_tables (vat_main_t * vam)
        ;
       else if (unformat (i, "other-table %d", &other_table_index))
        ;
+      else if (unformat (i, "is-input %d", &is_input))
+       ;
       else
        {
          clib_warning ("parse error '%U'", format_unformat_error, i);
@@ -8585,7 +8674,7 @@ api_classify_set_interface_l2_tables (vat_main_t * vam)
   mp->ip4_table_index = ntohl (ip4_table_index);
   mp->ip6_table_index = ntohl (ip6_table_index);
   mp->other_table_index = ntohl (other_table_index);
-
+  mp->is_input = (u8) is_input;
 
   S;
   W;
@@ -10212,6 +10301,41 @@ api_want_ip4_arp_events (vat_main_t * vam)
   W;
 }
 
+static int
+api_want_ip6_nd_events (vat_main_t * vam)
+{
+  unformat_input_t *line_input = vam->input;
+  vl_api_want_ip6_nd_events_t *mp;
+  f64 timeout;
+  ip6_address_t address;
+  int address_set = 0;
+  u32 enable_disable = 1;
+
+  while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
+    {
+      if (unformat (line_input, "address %U", unformat_ip6_address, &address))
+       address_set = 1;
+      else if (unformat (line_input, "del"))
+       enable_disable = 0;
+      else
+       break;
+    }
+
+  if (address_set == 0)
+    {
+      errmsg ("missing addresses\n");
+      return -99;
+    }
+
+  M (WANT_IP6_ND_EVENTS, want_ip6_nd_events);
+  mp->enable_disable = enable_disable;
+  mp->pid = getpid ();
+  clib_memcpy (mp->address, &address, sizeof (ip6_address_t));
+
+  S;
+  W;
+}
+
 static int
 api_input_acl_set_interface (vat_main_t * vam)
 {
@@ -15704,6 +15828,7 @@ _(input_acl_set_interface,                                              \
   "<intfc> | sw_if_index <nn> [ip4-table <nn>] [ip6-table <nn>]\n"      \
   "  [l2-table <nn>] [del]")                                            \
 _(want_ip4_arp_events, "address <ip4-address> [del]")                   \
+_(want_ip6_nd_events, "address <ip6-address> [del]")                    \
 _(ip_address_dump, "(ipv4 | ipv6) (<intfc> | sw_if_index <id>)")        \
 _(ip_dump, "ipv4 | ipv6")                                               \
 _(ipsec_spd_add_del, "spd_id <n> [del]")                                \
@@ -15836,6 +15961,7 @@ _(dump_macro_table, "usage: dump_macro_table ")                 \
 _(dump_node_table, "usage: dump_node_table")                   \
 _(echo, "usage: echo <message>")                               \
 _(exec, "usage: exec <vpe-debug-CLI-command>")                  \
+_(exec_inband, "usage: exec_inband <vpe-debug-CLI-command>")    \
 _(help, "usage: help")                                          \
 _(q, "usage: quit")                                             \
 _(quit, "usage: quit")                                          \