summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHongjun Ni <hongjun.ni@intel.com>2016-05-30 19:45:51 +0800
committerHongjun Ni <hongjun.ni@intel.com>2016-05-30 03:31:13 +0000
commit0e06e2b1420bca9b2bddd43e9642e56c81768fc2 (patch)
tree8969cb6ac5aa1ce50b3f546621ef8b633ff865b3
parent4b46c84901b6ea393a5118d7835d77aa6b3cef58 (diff)
Add Dump API for VxLAN-GPE tunnel
Change-Id: I4913fe6c4b1280939147887896aea9b79a9f7f10 Signed-off-by: Hongjun Ni <hongjun.ni@intel.com>
-rw-r--r--vnet/vnet/vxlan-gpe/vxlan_gpe.c37
-rw-r--r--vnet/vnet/vxlan-gpe/vxlan_gpe.h4
-rw-r--r--vpp-api-test/vat/api_format.c103
-rw-r--r--vpp/api/api.c64
-rw-r--r--vpp/api/custom_dump.c15
-rw-r--r--vpp/api/vpe.api17
6 files changed, 202 insertions, 38 deletions
diff --git a/vnet/vnet/vxlan-gpe/vxlan_gpe.c b/vnet/vnet/vxlan-gpe/vxlan_gpe.c
index bf1623af372..e6565f4379b 100644
--- a/vnet/vnet/vxlan-gpe/vxlan_gpe.c
+++ b/vnet/vnet/vxlan-gpe/vxlan_gpe.c
@@ -56,30 +56,10 @@ u8 * format_vxlan_gpe_tunnel (u8 * s, va_list * args)
static u8 * format_vxlan_gpe_name (u8 * s, va_list * args)
{
- vxlan_gpe_main_t * gm = &vxlan_gpe_main;
- u32 i = va_arg (*args, u32);
- u32 show_dev_instance = ~0;
-
- if (i < vec_len (gm->dev_inst_by_real))
- show_dev_instance = gm->dev_inst_by_real[i];
-
- if (show_dev_instance != ~0)
- i = show_dev_instance;
-
- return format (s, "vxlan_gpe_tunnel%d", i);
+ u32 dev_instance = va_arg (*args, u32);
+ return format (s, "vxlan_gpe_tunnel%d", dev_instance);
}
-static int vxlan_gpe_name_renumber (vnet_hw_interface_t * hi,
- u32 new_dev_instance)
-{
- vxlan_gpe_main_t * gm = &vxlan_gpe_main;
-
- vec_validate_init_empty (gm->dev_inst_by_real, hi->dev_instance, ~0);
-
- gm->dev_inst_by_real [hi->dev_instance] = new_dev_instance;
-
- return 0;
-}
static uword dummy_interface_tx (vlib_main_t * vm,
vlib_node_runtime_t * node,
@@ -88,6 +68,12 @@ static uword dummy_interface_tx (vlib_main_t * vm,
clib_warning ("you shouldn't be here, leaking buffers...");
return frame->n_vectors;
}
+VNET_DEVICE_CLASS (vxlan_gpe_device_class,static) = {
+ .name = "VXLAN_GPE",
+ .format_device_name = format_vxlan_gpe_name,
+ .format_tx_trace = format_vxlan_gpe_encap_trace,
+ .tx_function = dummy_interface_tx,
+};
static uword dummy_set_rewrite (vnet_main_t * vnm,
u32 sw_if_index,
@@ -99,13 +85,6 @@ static uword dummy_set_rewrite (vnet_main_t * vnm,
return 0;
}
-VNET_DEVICE_CLASS (vxlan_gpe_device_class,static) = {
- .name = "VXLAN_GPE",
- .format_device_name = format_vxlan_gpe_name,
- .format_tx_trace = format_vxlan_gpe_encap_trace,
- .tx_function = dummy_interface_tx,
- .name_renumber = vxlan_gpe_name_renumber,
-};
static u8 * format_vxlan_gpe_header_with_length (u8 * s, va_list * args)
{
diff --git a/vnet/vnet/vxlan-gpe/vxlan_gpe.h b/vnet/vnet/vxlan-gpe/vxlan_gpe.h
index 730abe70253..be420b54f6d 100644
--- a/vnet/vnet/vxlan-gpe/vxlan_gpe.h
+++ b/vnet/vnet/vxlan-gpe/vxlan_gpe.h
@@ -133,8 +133,8 @@ typedef struct {
/* Free vlib hw_if_indices */
u32 * free_vxlan_gpe_tunnel_hw_if_indices;
- /* show device instance by real device instance */
- u32 * dev_inst_by_real;
+ /* Mapping from sw_if_index to tunnel index */
+ u32 * tunnel_index_by_sw_if_index;
/* convenience */
vlib_main_t * vlib_main;
diff --git a/vpp-api-test/vat/api_format.c b/vpp-api-test/vat/api_format.c
index 258e314bab2..c342bcdc2dc 100644
--- a/vpp-api-test/vat/api_format.c
+++ b/vpp-api-test/vat/api_format.c
@@ -2484,7 +2484,8 @@ _(MODIFY_VHOST_USER_IF_REPLY, modify_vhost_user_if_reply) \
_(DELETE_VHOST_USER_IF_REPLY, delete_vhost_user_if_reply) \
_(SHOW_VERSION_REPLY, show_version_reply) \
_(L2_FIB_TABLE_ENTRY, l2_fib_table_entry) \
-_(VXLAN_GPE_ADD_DEL_TUNNEL_REPLY, vxlan_gpe_add_del_tunnel_reply) \
+_(VXLAN_GPE_ADD_DEL_TUNNEL_REPLY, vxlan_gpe_add_del_tunnel_reply) \
+_(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) \
@@ -8162,6 +8163,97 @@ static int api_vxlan_gpe_add_del_tunnel (vat_main_t * vam)
return 0;
}
+static void vl_api_vxlan_gpe_tunnel_details_t_handler
+(vl_api_vxlan_gpe_tunnel_details_t * mp)
+{
+ vat_main_t * vam = &vat_main;
+
+ fformat(vam->ofp, "%11d%24U%24U%13d%12d%14d%14d\n",
+ ntohl(mp->sw_if_index),
+ format_ip46_address, &(mp->local[0]),
+ format_ip46_address, &(mp->remote[0]),
+ ntohl(mp->vni),
+ ntohl(mp->protocol),
+ ntohl(mp->encap_vrf_id),
+ ntohl(mp->decap_vrf_id));
+}
+
+static void vl_api_vxlan_gpe_tunnel_details_t_handler_json
+(vl_api_vxlan_gpe_tunnel_details_t * mp)
+{
+ vat_main_t * vam = &vat_main;
+ vat_json_node_t *node = NULL;
+ struct in_addr ip4;
+ struct in6_addr ip6;
+
+ if (VAT_JSON_ARRAY != vam->json_tree.type) {
+ ASSERT(VAT_JSON_NONE == vam->json_tree.type);
+ vat_json_init_array(&vam->json_tree);
+ }
+ node = vat_json_array_add(&vam->json_tree);
+
+ vat_json_init_object(node);
+ vat_json_object_add_uint(node, "sw_if_index", ntohl(mp->sw_if_index));
+ if (mp->is_ipv6) {
+ clib_memcpy(&ip6, &(mp->local[0]), sizeof(ip6));
+ vat_json_object_add_ip6(node, "local", ip6);
+ clib_memcpy(&ip6, &(mp->remote[0]), sizeof(ip6));
+ vat_json_object_add_ip6(node, "remote", ip6);
+ } else {
+ clib_memcpy(&ip4, &(mp->local[0]), sizeof(ip4));
+ vat_json_object_add_ip4(node, "local", ip4);
+ clib_memcpy(&ip4, &(mp->remote[0]), sizeof(ip4));
+ vat_json_object_add_ip4(node, "remote", ip4);
+ }
+ vat_json_object_add_uint(node, "vni", ntohl(mp->vni));
+ vat_json_object_add_uint(node, "protocol", ntohl(mp->protocol));
+ vat_json_object_add_uint(node, "encap_vrf_id", ntohl(mp->encap_vrf_id));
+ vat_json_object_add_uint(node, "decap_vrf_id", ntohl(mp->decap_vrf_id));
+ vat_json_object_add_uint(node, "is_ipv6", mp->is_ipv6 ? 1 : 0);
+}
+
+static int api_vxlan_gpe_tunnel_dump (vat_main_t * vam)
+{
+ unformat_input_t * i = vam->input;
+ vl_api_vxlan_gpe_tunnel_dump_t *mp;
+ f64 timeout;
+ u32 sw_if_index;
+ u8 sw_if_index_set = 0;
+
+ /* Parse args required to build the message */
+ while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
+ if (unformat (i, "sw_if_index %d", &sw_if_index))
+ sw_if_index_set = 1;
+ else
+ break;
+ }
+
+ if (sw_if_index_set == 0) {
+ sw_if_index = ~0;
+ }
+
+ if (!vam->json_output) {
+ fformat(vam->ofp, "%11s%24s%24s%13s%15s%14s%14s\n",
+ "sw_if_index", "local", "remote", "vni",
+ "protocol","encap_vrf_id", "decap_vrf_id");
+ }
+
+ /* Get list of vxlan-tunnel interfaces */
+ M(VXLAN_GPE_TUNNEL_DUMP, vxlan_gpe_tunnel_dump);
+
+ mp->sw_if_index = htonl(sw_if_index);
+
+ S;
+
+ /* Use a control ping for synchronization */
+ {
+ vl_api_control_ping_t * mp;
+ M(CONTROL_PING, control_ping);
+ S;
+ }
+ W;
+}
+
u8 * format_l2_fib_mac_address (u8 * s, va_list * args)
{
u8 * a = va_arg (*args, u8 *);
@@ -11072,10 +11164,11 @@ _(modify_vhost_user_if, \
_(delete_vhost_user_if, "<intfc> | sw_if_index <nn>") \
_(sw_interface_vhost_user_dump, "") \
_(show_version, "") \
-_(vxlan_gpe_add_del_tunnel, \
- "local <ip4-addr> remote <ip4-addr> vni <nn>\n" \
- "[encap-vrf-id <nn>] [decap-vrf-id <nn>] [next-ip4][next-ip6]" \
- "[next-ethernet] [next-nsh]\n") \
+_(vxlan_gpe_add_del_tunnel, \
+ "local <addr> remote <addr> vni <nn>\n" \
+ "[encap-vrf-id <nn>] [decap-vrf-id <nn>] [next-ip4][next-ip6]" \
+ "[next-ethernet] [next-nsh]\n") \
+_(vxlan_gpe_tunnel_dump, "[<intfc> | sw_if_index <nn>]") \
_(l2_fib_table_dump, "bd_id <bridge-domain-id>") \
_(interface_name_renumber, \
"<intfc> | sw_if_index <nn> new_show_dev_instance <nn>") \
diff --git a/vpp/api/api.c b/vpp/api/api.c
index 6033dc4d34c..f54ef01dd20 100644
--- a/vpp/api/api.c
+++ b/vpp/api/api.c
@@ -291,7 +291,8 @@ _(SW_INTERFACE_VHOST_USER_DETAILS, sw_interface_vhost_user_details) \
_(SHOW_VERSION, show_version) \
_(L2_FIB_TABLE_DUMP, l2_fib_table_dump) \
_(L2_FIB_TABLE_ENTRY, l2_fib_table_entry) \
-_(VXLAN_GPE_ADD_DEL_TUNNEL, vxlan_gpe_add_del_tunnel) \
+_(VXLAN_GPE_ADD_DEL_TUNNEL, vxlan_gpe_add_del_tunnel) \
+_(VXLAN_GPE_TUNNEL_DUMP, vxlan_gpe_tunnel_dump) \
_(INTERFACE_NAME_RENUMBER, interface_name_renumber) \
_(WANT_IP4_ARP_EVENTS, want_ip4_arp_events) \
_(INPUT_ACL_SET_INTERFACE, input_acl_set_interface) \
@@ -4599,6 +4600,67 @@ out:
}));
}
+static void send_vxlan_gpe_tunnel_details
+(vxlan_gpe_tunnel_t * t, unix_shared_memory_queue_t * q, u32 context)
+{
+ vl_api_vxlan_gpe_tunnel_details_t * rmp;
+ ip4_main_t * im4 = &ip4_main;
+ ip6_main_t * im6 = &ip6_main;
+ u8 is_ipv6 = !(t->flags & VXLAN_GPE_TUNNEL_IS_IPV4);
+
+ rmp = vl_msg_api_alloc (sizeof (*rmp));
+ memset (rmp, 0, sizeof (*rmp));
+ rmp->_vl_msg_id = ntohs(VL_API_VXLAN_GPE_TUNNEL_DETAILS);
+ if (is_ipv6) {
+ memcpy(rmp->local, &(t->local.ip6), 16);
+ memcpy(rmp->remote, &(t->remote.ip6), 16);
+ rmp->encap_vrf_id = htonl(im6->fibs[t->encap_fib_index].table_id);
+ rmp->decap_vrf_id = htonl(im6->fibs[t->decap_fib_index].table_id);
+ } else {
+ memcpy(rmp->local, &(t->local.ip4), 4);
+ memcpy(rmp->remote, &(t->remote.ip4), 4);
+ rmp->encap_vrf_id = htonl(im4->fibs[t->encap_fib_index].table_id);
+ rmp->decap_vrf_id = htonl(im4->fibs[t->decap_fib_index].table_id);
+ }
+ rmp->vni = htonl(t->vni);
+ rmp->protocol = t->protocol;
+ rmp->sw_if_index = htonl(t->sw_if_index);
+ rmp->is_ipv6 = is_ipv6;
+ rmp->context = context;
+
+ vl_msg_api_send_shmem (q, (u8 *)&rmp);
+}
+
+static void vl_api_vxlan_gpe_tunnel_dump_t_handler
+(vl_api_vxlan_gpe_tunnel_dump_t * mp)
+{
+ unix_shared_memory_queue_t * q;
+ vxlan_gpe_main_t * vgm = &vxlan_gpe_main;
+ vxlan_gpe_tunnel_t * t;
+ u32 sw_if_index;
+
+ q = vl_api_client_index_to_input_queue (mp->client_index);
+ if (q == 0) {
+ return;
+ }
+
+ sw_if_index = ntohl(mp->sw_if_index);
+
+ if (~0 == sw_if_index) {
+ pool_foreach (t, vgm->tunnels,
+ ({
+ send_vxlan_gpe_tunnel_details(t, q, mp->context);
+ }));
+ } else {
+ if ((sw_if_index >= vec_len(vgm->tunnel_index_by_sw_if_index)) ||
+ (~0 == vgm->tunnel_index_by_sw_if_index[sw_if_index])) {
+ return;
+ }
+ t = &vgm->tunnels[vgm->tunnel_index_by_sw_if_index[sw_if_index]];
+ send_vxlan_gpe_tunnel_details(t, q, mp->context);
+ }
+}
+
static void
vl_api_lisp_add_del_locator_set_t_handler(vl_api_lisp_add_del_locator_set_t *mp)
{
diff --git a/vpp/api/custom_dump.c b/vpp/api/custom_dump.c
index ba4cf538d2f..638c4a78b6e 100644
--- a/vpp/api/custom_dump.c
+++ b/vpp/api/custom_dump.c
@@ -1600,6 +1600,18 @@ static void *vl_api_vxlan_gpe_add_del_tunnel_t_print
FINISH;
}
+static void * vl_api_vxlan_gpe_tunnel_dump_t_print
+(vl_api_vxlan_gpe_tunnel_dump_t * mp, void *handle)
+{
+ u8 * s;
+
+ s = format (0, "SCRIPT: vxlan_gpe_tunnel_dump ");
+
+ s = format (s, "sw_if_index %d ", ntohl(mp->sw_if_index));
+
+ FINISH;
+}
+
static void *vl_api_interface_name_renumber_t_print
(vl_api_interface_name_renumber_t * mp, void * handle)
{
@@ -1789,7 +1801,8 @@ _(MEMCLNT_CREATE, memclnt_create) \
_(SW_INTERFACE_VHOST_USER_DUMP, sw_interface_vhost_user_dump) \
_(SHOW_VERSION, show_version) \
_(L2_FIB_TABLE_DUMP, l2_fib_table_dump) \
-_(VXLAN_GPE_ADD_DEL_TUNNEL, vxlan_gpe_add_del_tunnel) \
+_(VXLAN_GPE_ADD_DEL_TUNNEL, vxlan_gpe_add_del_tunnel) \
+_(VXLAN_GPE_TUNNEL_DUMP, vxlan_gpe_tunnel_dump) \
_(INTERFACE_NAME_RENUMBER, interface_name_renumber) \
_(WANT_IP4_ARP_EVENTS, want_ip4_arp_events) \
_(INPUT_ACL_SET_INTERFACE, input_acl_set_interface) \
diff --git a/vpp/api/vpe.api b/vpp/api/vpe.api
index 9c90c338e73..9ae4987fd53 100644
--- a/vpp/api/vpe.api
+++ b/vpp/api/vpe.api
@@ -2129,6 +2129,23 @@ define vxlan_gpe_add_del_tunnel_reply {
u32 sw_if_index;
};
+manual_java define vxlan_gpe_tunnel_dump {
+ u32 client_index;
+ u32 context;
+ u32 sw_if_index;
+};
+
+manual_java define vxlan_gpe_tunnel_details {
+ u32 context;
+ u32 sw_if_index;
+ u8 local[16];
+ u8 remote[16];
+ u32 vni;
+ u8 protocol;
+ u32 encap_vrf_id;
+ u32 decap_vrf_id;
+ u8 is_ipv6;
+};
/** \brief add or delete locator_set
@param client_index - opaque cookie to identify the sender