span: add tx functionality and support for multiple mirror ports
[vpp.git] / vpp / vpp-api / api.c
index 004dcb7..ec52f44 100644 (file)
@@ -52,6 +52,7 @@
 #include <vnet/l2tp/l2tp.h>
 #include <vnet/ip/ip.h>
 #include <vnet/ip/ip6.h>
+#include <vnet/ip/ip6_neighbor.h>
 #include <vnet/unix/tuntap.h>
 #include <vnet/unix/tapcli.h>
 #include <vnet/mpls/mpls.h>
@@ -238,12 +239,6 @@ _(IKEV2_PROFILE_SET_TS, ikev2_profile_set_ts)                           \
 _(IKEV2_SET_LOCAL_KEY, ikev2_set_local_key)                             \
 _(DELETE_LOOPBACK, delete_loopback)                                     \
 _(BD_IP_MAC_ADD_DEL, bd_ip_mac_add_del)                                 \
-_(MAP_ADD_DOMAIN, map_add_domain)                                       \
-_(MAP_DEL_DOMAIN, map_del_domain)                                       \
-_(MAP_ADD_DEL_RULE, map_add_del_rule)                                   \
-_(MAP_DOMAIN_DUMP, map_domain_dump)                                     \
-_(MAP_RULE_DUMP, map_rule_dump)                                                \
-_(MAP_SUMMARY_STATS, map_summary_stats)                                        \
 _(COP_INTERFACE_ENABLE_DISABLE, cop_interface_enable_disable)          \
 _(COP_WHITELIST_ENABLE_DISABLE, cop_whitelist_enable_disable)          \
 _(GET_NODE_GRAPH, get_node_graph)                                       \
@@ -306,8 +301,6 @@ _(SET_IPFIX_CLASSIFY_STREAM, set_ipfix_classify_stream)                 \
 _(IPFIX_CLASSIFY_STREAM_DUMP, ipfix_classify_stream_dump)               \
 _(IPFIX_CLASSIFY_TABLE_ADD_DEL, ipfix_classify_table_add_del)           \
 _(IPFIX_CLASSIFY_TABLE_DUMP, ipfix_classify_table_dump)                 \
-_(SW_INTERFACE_SPAN_ENABLE_DISABLE, sw_interface_span_enable_disable)   \
-_(SW_INTERFACE_SPAN_DUMP, sw_interface_span_dump)                       \
 _(GET_NEXT_INDEX, get_next_index)                                       \
 _(PG_CREATE_INTERFACE, pg_create_interface)                             \
 _(PG_CAPTURE, pg_capture)                                               \
@@ -328,7 +321,9 @@ _(IP_FIB_DUMP, ip_fib_dump)                                             \
 _(IP_FIB_DETAILS, ip_fib_details)                                       \
 _(IP6_FIB_DUMP, ip6_fib_dump)                                           \
 _(IP6_FIB_DETAILS, ip6_fib_details)                                     \
-_(FEATURE_ENABLE_DISABLE, feature_enable_disable)                      \
+_(FEATURE_ENABLE_DISABLE, feature_enable_disable)                                        \
+_(IP_NEIGHBOR_DUMP, ip_neighbor_dump)                                   \
+_(IP_NEIGHBOR_DETAILS, ip_neighbor_details)
 
 #define QUOTE_(x) #x
 #define QUOTE(x) QUOTE_(x)
@@ -6177,198 +6172,6 @@ vl_api_ikev2_set_local_key_t_handler (vl_api_ikev2_set_local_key_t * mp)
   REPLY_MACRO (VL_API_IKEV2_SET_LOCAL_KEY_REPLY);
 }
 
-static void
-vl_api_map_add_domain_t_handler (vl_api_map_add_domain_t * mp)
-{
-  vl_api_map_add_domain_reply_t *rmp;
-  int rv = 0;
-  u32 index;
-  u8 flags = mp->is_translation ? MAP_DOMAIN_TRANSLATION : 0;
-  rv =
-    map_create_domain ((ip4_address_t *) & mp->ip4_prefix, mp->ip4_prefix_len,
-                      (ip6_address_t *) & mp->ip6_prefix, mp->ip6_prefix_len,
-                      (ip6_address_t *) & mp->ip6_src,
-                      mp->ip6_src_prefix_len, mp->ea_bits_len,
-                      mp->psid_offset, mp->psid_length, &index,
-                      ntohs (mp->mtu), flags);
-
-  /* *INDENT-OFF* */
-  REPLY_MACRO2(VL_API_MAP_ADD_DOMAIN_REPLY,
-  ({
-    rmp->index = ntohl(index);
-  }));
-  /* *INDENT-ON* */
-}
-
-static void
-vl_api_map_del_domain_t_handler (vl_api_map_del_domain_t * mp)
-{
-  vl_api_map_del_domain_reply_t *rmp;
-  int rv = 0;
-
-  rv = map_delete_domain (ntohl (mp->index));
-
-  REPLY_MACRO (VL_API_MAP_DEL_DOMAIN_REPLY);
-}
-
-static void
-vl_api_map_add_del_rule_t_handler (vl_api_map_add_del_rule_t * mp)
-{
-  vl_api_map_del_domain_reply_t *rmp;
-  int rv = 0;
-
-  rv =
-    map_add_del_psid (ntohl (mp->index), ntohs (mp->psid),
-                     (ip6_address_t *) mp->ip6_dst, mp->is_add);
-
-  REPLY_MACRO (VL_API_MAP_ADD_DEL_RULE_REPLY);
-}
-
-static void
-vl_api_map_domain_dump_t_handler (vl_api_map_domain_dump_t * mp)
-{
-  vl_api_map_domain_details_t *rmp;
-  map_main_t *mm = &map_main;
-  map_domain_t *d;
-  unix_shared_memory_queue_t *q;
-
-  if (pool_elts (mm->domains) == 0)
-    return;
-
-  q = vl_api_client_index_to_input_queue (mp->client_index);
-  if (q == 0)
-    {
-      return;
-    }
-
-  /* *INDENT-OFF* */
-  pool_foreach(d, mm->domains,
-  ({
-    /* Make sure every field is initiated (or don't skip the memset()) */
-    rmp = vl_msg_api_alloc (sizeof (*rmp));
-    rmp->_vl_msg_id = ntohs(VL_API_MAP_DOMAIN_DETAILS);
-    rmp->domain_index = htonl(d - mm->domains);
-    rmp->ea_bits_len = d->ea_bits_len;
-    rmp->psid_offset = d->psid_offset;
-    rmp->psid_length = d->psid_length;
-    clib_memcpy(rmp->ip4_prefix, &d->ip4_prefix, sizeof(rmp->ip4_prefix));
-    rmp->ip4_prefix_len = d->ip4_prefix_len;
-    clib_memcpy(rmp->ip6_prefix, &d->ip6_prefix, sizeof(rmp->ip6_prefix));
-    rmp->ip6_prefix_len = d->ip6_prefix_len;
-    clib_memcpy(rmp->ip6_src, &d->ip6_src, sizeof(rmp->ip6_src));
-    rmp->ip6_src_len = d->ip6_src_len;
-    rmp->mtu = htons(d->mtu);
-    rmp->is_translation = (d->flags & MAP_DOMAIN_TRANSLATION);
-    rmp->context = mp->context;
-
-    vl_msg_api_send_shmem (q, (u8 *)&rmp);
-  }));
-  /* *INDENT-ON* */
-}
-
-static void
-vl_api_map_rule_dump_t_handler (vl_api_map_rule_dump_t * mp)
-{
-  unix_shared_memory_queue_t *q;
-  u16 i;
-  ip6_address_t dst;
-  vl_api_map_rule_details_t *rmp;
-  map_main_t *mm = &map_main;
-  u32 domain_index = ntohl (mp->domain_index);
-  map_domain_t *d;
-
-  if (pool_elts (mm->domains) == 0)
-    return;
-
-  d = pool_elt_at_index (mm->domains, domain_index);
-  if (!d || !d->rules)
-    {
-      return;
-    }
-
-  q = vl_api_client_index_to_input_queue (mp->client_index);
-  if (q == 0)
-    {
-      return;
-    }
-
-  for (i = 0; i < (0x1 << d->psid_length); i++)
-    {
-      dst = d->rules[i];
-      if (dst.as_u64[0] == 0 && dst.as_u64[1] == 0)
-       {
-         continue;
-       }
-      rmp = vl_msg_api_alloc (sizeof (*rmp));
-      memset (rmp, 0, sizeof (*rmp));
-      rmp->_vl_msg_id = ntohs (VL_API_MAP_RULE_DETAILS);
-      rmp->psid = htons (i);
-      clib_memcpy (rmp->ip6_dst, &dst, sizeof (rmp->ip6_dst));
-      rmp->context = mp->context;
-      vl_msg_api_send_shmem (q, (u8 *) & rmp);
-    }
-}
-
-static void
-vl_api_map_summary_stats_t_handler (vl_api_map_summary_stats_t * mp)
-{
-  vl_api_map_summary_stats_reply_t *rmp;
-  vlib_combined_counter_main_t *cm;
-  vlib_counter_t v;
-  int i, which;
-  u64 total_pkts[VLIB_N_RX_TX];
-  u64 total_bytes[VLIB_N_RX_TX];
-  map_main_t *mm = &map_main;
-  unix_shared_memory_queue_t *q =
-    vl_api_client_index_to_input_queue (mp->client_index);
-
-  if (!q)
-    return;
-
-  rmp = vl_msg_api_alloc (sizeof (*rmp));
-  rmp->_vl_msg_id = ntohs (VL_API_MAP_SUMMARY_STATS_REPLY);
-  rmp->context = mp->context;
-  rmp->retval = 0;
-
-  memset (total_pkts, 0, sizeof (total_pkts));
-  memset (total_bytes, 0, sizeof (total_bytes));
-
-  map_domain_counter_lock (mm);
-  vec_foreach (cm, mm->domain_counters)
-  {
-    which = cm - mm->domain_counters;
-
-    for (i = 0; i < vec_len (cm->maxi); i++)
-      {
-       vlib_get_combined_counter (cm, i, &v);
-       total_pkts[which] += v.packets;
-       total_bytes[which] += v.bytes;
-      }
-  }
-
-  map_domain_counter_unlock (mm);
-
-  /* Note: in network byte order! */
-  rmp->total_pkts[MAP_DOMAIN_COUNTER_RX] =
-    clib_host_to_net_u64 (total_pkts[MAP_DOMAIN_COUNTER_RX]);
-  rmp->total_bytes[MAP_DOMAIN_COUNTER_RX] =
-    clib_host_to_net_u64 (total_bytes[MAP_DOMAIN_COUNTER_RX]);
-  rmp->total_pkts[MAP_DOMAIN_COUNTER_TX] =
-    clib_host_to_net_u64 (total_pkts[MAP_DOMAIN_COUNTER_TX]);
-  rmp->total_bytes[MAP_DOMAIN_COUNTER_TX] =
-    clib_host_to_net_u64 (total_bytes[MAP_DOMAIN_COUNTER_TX]);
-  rmp->total_bindings = clib_host_to_net_u64 (pool_elts (mm->domains));
-  rmp->total_ip4_fragments = 0;        // Not yet implemented. Should be a simple counter.
-  rmp->total_security_check[MAP_DOMAIN_COUNTER_TX] =
-    clib_host_to_net_u64 (map_error_counter_get
-                         (ip4_map_node.index, MAP_ERROR_ENCAP_SEC_CHECK));
-  rmp->total_security_check[MAP_DOMAIN_COUNTER_RX] =
-    clib_host_to_net_u64 (map_error_counter_get
-                         (ip4_map_node.index, MAP_ERROR_DECAP_SEC_CHECK));
-
-  vl_msg_api_send_shmem (q, (u8 *) & rmp);
-}
-
 static void
 vl_api_ipsec_sa_set_key_t_handler (vl_api_ipsec_sa_set_key_t * mp)
 {
@@ -7772,52 +7575,6 @@ static void
       send_ipfix_classify_table_details (i, q, mp->context);
 }
 
-static void
-  vl_api_sw_interface_span_enable_disable_t_handler
-  (vl_api_sw_interface_span_enable_disable_t * mp)
-{
-  vl_api_sw_interface_span_enable_disable_reply_t *rmp;
-  int rv;
-
-  vlib_main_t *vm = vlib_get_main ();
-
-  rv = span_add_delete_entry (vm, ntohl (mp->sw_if_index_from),
-                             ntohl (mp->sw_if_index_to), mp->enable);
-
-  REPLY_MACRO (VL_API_SW_INTERFACE_SPAN_ENABLE_DISABLE_REPLY);
-}
-
-static void
-vl_api_sw_interface_span_dump_t_handler (vl_api_sw_interface_span_dump_t * mp)
-{
-
-  unix_shared_memory_queue_t *q;
-  vl_api_sw_interface_span_details_t *rmp;
-  span_main_t *sm = &span_main;
-  u32 src_sw_if_index = 0, *dst_sw_if_index;
-
-  q = vl_api_client_index_to_input_queue (mp->client_index);
-  if (!q)
-    return;
-
-  vec_foreach (dst_sw_if_index, sm->dst_by_src_sw_if_index)
-  {
-    if (*dst_sw_if_index > 0)
-      {
-       rmp = vl_msg_api_alloc (sizeof (*rmp));
-       memset (rmp, 0, sizeof (*rmp));
-       rmp->_vl_msg_id = ntohs (VL_API_SW_INTERFACE_SPAN_DETAILS);
-       rmp->context = mp->context;
-
-       rmp->sw_if_index_from = htonl (src_sw_if_index);
-       rmp->sw_if_index_to = htonl (*dst_sw_if_index);
-
-       vl_msg_api_send_shmem (q, (u8 *) & rmp);
-      }
-    src_sw_if_index++;
-  }
-}
-
 static void
 vl_api_pg_create_interface_t_handler (vl_api_pg_create_interface_t * mp)
 {
@@ -8393,6 +8150,80 @@ vl_api_feature_enable_disable_t_handler (vl_api_feature_enable_disable_t * mp)
   REPLY_MACRO (VL_API_FEATURE_ENABLE_DISABLE_REPLY);
 }
 
+static void
+send_ip_neighbor_details (u8 is_ipv6,
+                         u8 is_static,
+                         u8 * mac_address,
+                         u8 * ip_address,
+                         unix_shared_memory_queue_t * q, u32 context)
+{
+  vl_api_ip_neighbor_details_t *mp;
+
+  mp = vl_msg_api_alloc (sizeof (*mp));
+  memset (mp, 0, sizeof (*mp));
+  mp->_vl_msg_id = ntohs (VL_API_IP_NEIGHBOR_DETAILS);
+  mp->context = context;
+  mp->is_ipv6 = is_ipv6;
+  mp->is_static = is_static;
+  memcpy (mp->mac_address, mac_address, 6);
+  memcpy (mp->ip_address, ip_address, (is_ipv6) ? 16 : 4);
+
+  vl_msg_api_send_shmem (q, (u8 *) & mp);
+}
+
+static void
+vl_api_ip_neighbor_details_t_handler (vl_api_ip_neighbor_details_t * mp)
+{
+  clib_warning ("BUG");
+}
+
+static void
+vl_api_ip_neighbor_dump_t_handler (vl_api_ip_neighbor_dump_t * mp)
+{
+  unix_shared_memory_queue_t *q;
+
+  q = vl_api_client_index_to_input_queue (mp->client_index);
+  if (q == 0)
+    return;
+
+  u32 sw_if_index = ntohl (mp->sw_if_index);
+
+  if (mp->is_ipv6)
+    {
+      ip6_neighbor_t *n, *ns;
+
+      ns = ip6_neighbors_entries (sw_if_index);
+      /* *INDENT-OFF* */
+      vec_foreach (n, ns)
+      {
+        send_ip_neighbor_details (mp->is_ipv6,
+                                 ((n->flags & IP6_NEIGHBOR_FLAG_STATIC) ? 1 : 0),
+                                 (u8 *) n->link_layer_address,
+                                 (u8 *) & (n->key.ip6_address.as_u8),
+                                 q, mp->context);
+      }
+      /* *INDENT-ON* */
+      vec_free (ns);
+    }
+  else
+    {
+      ethernet_arp_ip4_entry_t *n, *ns;
+
+      ns = ip4_neighbor_entries (sw_if_index);
+      /* *INDENT-OFF* */
+      vec_foreach (n, ns)
+      {
+        send_ip_neighbor_details (mp->is_ipv6,
+          ((n->flags & ETHERNET_ARP_IP4_ENTRY_FLAG_STATIC) ? 1 : 0),
+          (u8*) n->ethernet_address,
+          (u8*) & (n->ip4_address.as_u8),
+          q, mp->context);
+      }
+      /* *INDENT-ON* */
+      vec_free (ns);
+    }
+}
+
 #define BOUNCE_HANDLER(nn)                                              \
 static void vl_api_##nn##_t_handler (                                   \
     vl_api_##nn##_t *mp)                                                \