aboutsummaryrefslogtreecommitdiffstats
path: root/src/plugins/ioam/lib-vxlan-gpe
diff options
context:
space:
mode:
authorOle Troan <ot@cisco.com>2019-12-09 14:25:09 +0100
committerPaul Vinciguerra <pvinci@vinciconsulting.com>2019-12-10 04:11:04 +0000
commit0fa66d618e7d839782a896f75bc8b0337cc2a2b8 (patch)
tree9a9b8593063d59dbf66cc6d09914df072c6663e6 /src/plugins/ioam/lib-vxlan-gpe
parent668605fc873a6409f38df712106f4b1290d87648 (diff)
ioam: use explicit api types
Also remove API boilerplate. Type: fix Signed-off-by: Ole Troan <ot@cisco.com> Change-Id: I62e795f5af3843af7912707ade4ba178ff326942
Diffstat (limited to 'src/plugins/ioam/lib-vxlan-gpe')
-rw-r--r--src/plugins/ioam/lib-vxlan-gpe/ioam_vxlan_gpe.api21
-rw-r--r--src/plugins/ioam/lib-vxlan-gpe/vxlan_gpe_api.c36
-rw-r--r--src/plugins/ioam/lib-vxlan-gpe/vxlan_gpe_test.c262
3 files changed, 60 insertions, 259 deletions
diff --git a/src/plugins/ioam/lib-vxlan-gpe/ioam_vxlan_gpe.api b/src/plugins/ioam/lib-vxlan-gpe/ioam_vxlan_gpe.api
index 0cbdf6dc41a..36dc1a4e114 100644
--- a/src/plugins/ioam/lib-vxlan-gpe/ioam_vxlan_gpe.api
+++ b/src/plugins/ioam/lib-vxlan-gpe/ioam_vxlan_gpe.api
@@ -15,6 +15,7 @@
*/
option version = "1.0.0";
+import "vnet/ip/ip_types.api";
/** \brief iOAM Over VxLAN-GPE - Set iOAM transport for VxLAN-GPE
@param client_index - opaque cookie to identify the sender
@@ -30,8 +31,8 @@ autoreply define vxlan_gpe_ioam_enable {
u32 context;
u16 id;
u8 trace_ppc;
- u8 pow_enable;
- u8 trace_enable;
+ bool pow_enable;
+ bool trace_enable;
};
/** \brief iOAM for VxLAN-GPE disable
@@ -58,9 +59,8 @@ autoreply define vxlan_gpe_ioam_vni_enable {
u32 client_index;
u32 context;
u32 vni;
- u8 local[16];
- u8 remote[16];
- u8 is_ipv6;
+ vl_api_address_t local;
+ vl_api_address_t remote;
};
/** \brief Disable iOAM for a VNI (VXLAN-GPE)
@@ -75,9 +75,8 @@ autoreply define vxlan_gpe_ioam_vni_disable {
u32 client_index;
u32 context;
u32 vni;
- u8 local[16];
- u8 remote[16];
- u8 is_ipv6;
+ vl_api_address_t local;
+ vl_api_address_t remote;
};
/** \brief Enable iOAM for a VXLAN-GPE transit
@@ -91,8 +90,7 @@ autoreply define vxlan_gpe_ioam_transit_enable {
u32 client_index;
u32 context;
u32 outer_fib_index;
- u8 dst_addr[16];
- u8 is_ipv6;
+ vl_api_address_t dst_addr;
};
/** \brief Disable iOAM for VXLAN-GPE transit
@@ -106,7 +104,6 @@ autoreply define vxlan_gpe_ioam_transit_disable {
u32 client_index;
u32 context;
u32 outer_fib_index;
- u8 dst_addr[16];
- u8 is_ipv6;
+ vl_api_address_t dst_addr;
};
diff --git a/src/plugins/ioam/lib-vxlan-gpe/vxlan_gpe_api.c b/src/plugins/ioam/lib-vxlan-gpe/vxlan_gpe_api.c
index 77484341add..6255ce53be5 100644
--- a/src/plugins/ioam/lib-vxlan-gpe/vxlan_gpe_api.c
+++ b/src/plugins/ioam/lib-vxlan-gpe/vxlan_gpe_api.c
@@ -25,7 +25,8 @@
#include <vlibapi/api_helper_macros.h>
#include <vlibapi/api.h>
#include <vlibmemory/api.h>
-
+#include <vnet/format_fns.h>
+#include <vnet/ip/ip_types_api.h>
/* define message IDs */
#include <ioam/lib-vxlan-gpe/ioam_vxlan_gpe.api_enum.h>
@@ -84,10 +85,11 @@ static void vl_api_vxlan_gpe_ioam_vni_enable_t_handler
u32 vni;
- if (!mp->is_ipv6)
+ if (clib_net_to_host_u32 (mp->local.af) == ADDRESS_IP4 &&
+ clib_net_to_host_u32 (mp->remote.af) == ADDRESS_IP4)
{
- clib_memcpy (&key4.local, &mp->local, sizeof (key4.local));
- clib_memcpy (&key4.remote, &mp->remote, sizeof (key4.remote));
+ clib_memcpy (&key4.local, &mp->local.un.ip4, sizeof (key4.local));
+ clib_memcpy (&key4.remote, &mp->remote.un.ip4, sizeof (key4.remote));
vni = clib_net_to_host_u32 (mp->vni);
key4.vni = clib_host_to_net_u32 (vni << 8);
key4.pad = 0;
@@ -106,7 +108,7 @@ static void vl_api_vxlan_gpe_ioam_vni_enable_t_handler
error = vxlan_gpe_ioam_set (t, hm->has_trace_option,
hm->has_pot_option,
- hm->has_ppc_option, mp->is_ipv6);
+ hm->has_ppc_option, 0 /* is_ipv6 */ );
if (error)
@@ -132,7 +134,8 @@ static void vl_api_vxlan_gpe_ioam_vni_disable_t_handler
u32 vni;
- if (!mp->is_ipv6)
+ if (clib_net_to_host_u32 (mp->local.af) == ADDRESS_IP4 &&
+ clib_net_to_host_u32 (mp->remote.af) == ADDRESS_IP4)
{
clib_memcpy (&key4.local, &mp->local, sizeof (key4.local));
clib_memcpy (&key4.remote, &mp->remote, sizeof (key4.remote));
@@ -173,16 +176,12 @@ static void vl_api_vxlan_gpe_ioam_transit_enable_t_handler
vxlan_gpe_ioam_main_t *sm = &vxlan_gpe_ioam_main;
ip46_address_t dst_addr;
- clib_memset (&dst_addr.ip4, 0, sizeof (dst_addr.ip4));
- if (!mp->is_ipv6)
- {
- clib_memcpy (&dst_addr.ip4, &mp->dst_addr, sizeof (dst_addr.ip4));
- }
+ ip_address_decode (&mp->dst_addr, &dst_addr);
+ bool is_ip6 = clib_net_to_host_u32 (mp->dst_addr.af) == ADDRESS_IP6;
rv = vxlan_gpe_enable_disable_ioam_for_dest (sm->vlib_main,
dst_addr,
ntohl (mp->outer_fib_index),
- mp->is_ipv6 ? 0 : 1,
- 1 /* is_add */ );
+ is_ip6, 1 /* is_add */ );
REPLY_MACRO (VL_API_VXLAN_GPE_IOAM_TRANSIT_ENABLE_REPLY);
}
@@ -195,16 +194,11 @@ static void vl_api_vxlan_gpe_ioam_transit_disable_t_handler
vxlan_gpe_ioam_main_t *sm = &vxlan_gpe_ioam_main;
ip46_address_t dst_addr;
- clib_memset (&dst_addr.ip4, 0, sizeof (dst_addr.ip4));
- if (!mp->is_ipv6)
- {
- clib_memcpy (&dst_addr.ip4, &mp->dst_addr, sizeof (dst_addr.ip4));
- }
-
+ ip_address_decode (&mp->dst_addr, &dst_addr);
+ bool is_ip6 = clib_net_to_host_u32 (mp->dst_addr.af) == ADDRESS_IP6;
rv = vxlan_gpe_ioam_disable_for_dest (sm->vlib_main,
dst_addr,
- ntohl (mp->outer_fib_index),
- mp->is_ipv6 ? 0 : 1);
+ ntohl (mp->outer_fib_index), is_ip6);
REPLY_MACRO (VL_API_VXLAN_GPE_IOAM_TRANSIT_DISABLE_REPLY);
}
diff --git a/src/plugins/ioam/lib-vxlan-gpe/vxlan_gpe_test.c b/src/plugins/ioam/lib-vxlan-gpe/vxlan_gpe_test.c
index c7eea8b64b8..dad39f20c32 100644
--- a/src/plugins/ioam/lib-vxlan-gpe/vxlan_gpe_test.c
+++ b/src/plugins/ioam/lib-vxlan-gpe/vxlan_gpe_test.c
@@ -23,23 +23,16 @@
#include <vlibmemory/api.h>
#include <vppinfra/error.h>
+#include <vnet/format_fns.h>
+#include <vnet/ip/ip_types_api.h>
-#define __plugin_msg_base vxlan_gpe_test_main.msg_id_base
+#define __plugin_msg_base ioam_vxlan_gpe_test_main.msg_id_base
#include <vlibapi/vat_helper_macros.h>
/* Declare message IDs */
#include <ioam/lib-vxlan-gpe/ioam_vxlan_gpe.api_enum.h>
#include <ioam/lib-vxlan-gpe/ioam_vxlan_gpe.api_types.h>
-#define vl_endianfun /* define message structures */
-#define vl_printfun
-#define vl_api_version(n,v) static u32 api_version=(v);
-#define vl_print(handle, ...)
-#include <ioam/lib-vxlan-gpe/ioam_vxlan_gpe.api.h>
-#undef vl_endianfun
-#undef vl_printfun
-#undef vl_api_version
-
#include <ioam/lib-vxlan-gpe/vxlan_gpe_ioam_packet.h>
#include <ioam/lib-vxlan-gpe/vxlan_gpe_ioam.h>
@@ -48,45 +41,9 @@ typedef struct
/* API message ID base */
u16 msg_id_base;
vat_main_t *vat_main;
-} vxlan_gpe_test_main_t;
-
-vxlan_gpe_test_main_t vxlan_gpe_test_main;
-
-#define foreach_standard_reply_retval_handler \
-_(vxlan_gpe_ioam_enable_reply) \
-_(vxlan_gpe_ioam_disable_reply) \
-_(vxlan_gpe_ioam_vni_enable_reply) \
-_(vxlan_gpe_ioam_vni_disable_reply) \
-_(vxlan_gpe_ioam_transit_enable_reply) \
-_(vxlan_gpe_ioam_transit_disable_reply)
-
-#define _(n) \
- static void vl_api_##n##_t_handler \
- (vl_api_##n##_t * mp) \
- { \
- vat_main_t * vam = vxlan_gpe_test_main.vat_main; \
- i32 retval = ntohl(mp->retval); \
- if (vam->async_mode) { \
- vam->async_errors += (retval < 0); \
- } else { \
- vam->retval = retval; \
- vam->result_ready = 1; \
- } \
- }
-foreach_standard_reply_retval_handler;
-#undef _
+} ioam_vxlan_gpe_test_main_t;
-/*
- * Table of message reply handlers, must include boilerplate handlers
- * we just generated
- */
-#define foreach_vpe_api_reply_msg \
-_(VXLAN_GPE_IOAM_ENABLE_REPLY, vxlan_gpe_ioam_enable_reply) \
-_(VXLAN_GPE_IOAM_DISABLE_REPLY, vxlan_gpe_ioam_disable_reply) \
-_(VXLAN_GPE_IOAM_VNI_ENABLE_REPLY, vxlan_gpe_ioam_vni_enable_reply) \
-_(VXLAN_GPE_IOAM_VNI_DISABLE_REPLY, vxlan_gpe_ioam_vni_disable_reply) \
-_(VXLAN_GPE_IOAM_TRANSIT_ENABLE_REPLY, vxlan_gpe_ioam_transit_enable_reply) \
-_(VXLAN_GPE_IOAM_TRANSIT_DISABLE_REPLY, vxlan_gpe_ioam_transit_disable_reply) \
+ioam_vxlan_gpe_test_main_t ioam_vxlan_gpe_test_main;
static int
api_vxlan_gpe_ioam_enable (vat_main_t * vam)
@@ -144,9 +101,7 @@ api_vxlan_gpe_ioam_vni_enable (vat_main_t * vam)
{
unformat_input_t *line_input = vam->input;
vl_api_vxlan_gpe_ioam_vni_enable_t *mp;
- ip4_address_t local4, remote4;
- ip6_address_t local6, remote6;
- u8 ipv4_set = 0, ipv6_set = 0;
+ ip46_address_t local, remote;
u8 local_set = 0;
u8 remote_set = 0;
u32 vni;
@@ -156,30 +111,15 @@ api_vxlan_gpe_ioam_vni_enable (vat_main_t * vam)
while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
{
- if (unformat (line_input, "local %U", unformat_ip4_address, &local4))
+ if (unformat (line_input, "local %U", unformat_ip46_address, &local))
{
local_set = 1;
- ipv4_set = 1;
}
else if (unformat (line_input, "remote %U",
- unformat_ip4_address, &remote4))
+ unformat_ip46_address, &remote))
{
remote_set = 1;
- ipv4_set = 1;
}
- else if (unformat (line_input, "local %U",
- unformat_ip6_address, &local6))
- {
- local_set = 1;
- ipv6_set = 1;
- }
- else if (unformat (line_input, "remote %U",
- unformat_ip6_address, &remote6))
- {
- remote_set = 1;
- ipv6_set = 1;
- }
-
else if (unformat (line_input, "vni %d", &vni))
vni_set = 1;
else
@@ -199,7 +139,7 @@ api_vxlan_gpe_ioam_vni_enable (vat_main_t * vam)
errmsg ("tunnel remote address not specified\n");
return -99;
}
- if (ipv4_set && ipv6_set)
+ if (ip46_address_is_ip4 (&local) != ip46_address_is_ip4 (&remote))
{
errmsg ("both IPv4 and IPv6 addresses specified");
return -99;
@@ -213,20 +153,14 @@ api_vxlan_gpe_ioam_vni_enable (vat_main_t * vam)
M (VXLAN_GPE_IOAM_VNI_ENABLE, mp);
-
- if (ipv6_set)
- {
- clib_memcpy (&mp->local, &local6, sizeof (local6));
- clib_memcpy (&mp->remote, &remote6, sizeof (remote6));
- }
- else
- {
- clib_memcpy (&mp->local, &local4, sizeof (local4));
- clib_memcpy (&mp->remote, &remote4, sizeof (remote4));
- }
+ ip_address_encode (&local,
+ ip46_address_is_ip4 (&local) ? IP46_TYPE_IP4 :
+ IP46_TYPE_IP6, &mp->local);
+ ip_address_encode (&local,
+ ip46_address_is_ip4 (&remote) ? IP46_TYPE_IP4 :
+ IP46_TYPE_IP6, &mp->remote);
mp->vni = ntohl (vni);
- mp->is_ipv6 = ipv6_set;
S (mp);
W (ret);
@@ -238,9 +172,7 @@ api_vxlan_gpe_ioam_vni_disable (vat_main_t * vam)
{
unformat_input_t *line_input = vam->input;
vl_api_vxlan_gpe_ioam_vni_disable_t *mp;
- ip4_address_t local4, remote4;
- ip6_address_t local6, remote6;
- u8 ipv4_set = 0, ipv6_set = 0;
+ ip46_address_t local, remote;
u8 local_set = 0;
u8 remote_set = 0;
u32 vni;
@@ -250,30 +182,15 @@ api_vxlan_gpe_ioam_vni_disable (vat_main_t * vam)
while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
{
- if (unformat (line_input, "local %U", unformat_ip4_address, &local4))
+ if (unformat (line_input, "local %U", unformat_ip46_address, &local))
{
local_set = 1;
- ipv4_set = 1;
}
else if (unformat (line_input, "remote %U",
- unformat_ip4_address, &remote4))
+ unformat_ip46_address, &remote))
{
remote_set = 1;
- ipv4_set = 1;
}
- else if (unformat (line_input, "local %U",
- unformat_ip6_address, &local6))
- {
- local_set = 1;
- ipv6_set = 1;
- }
- else if (unformat (line_input, "remote %U",
- unformat_ip6_address, &remote6))
- {
- remote_set = 1;
- ipv6_set = 1;
- }
-
else if (unformat (line_input, "vni %d", &vni))
vni_set = 1;
else
@@ -293,7 +210,7 @@ api_vxlan_gpe_ioam_vni_disable (vat_main_t * vam)
errmsg ("tunnel remote address not specified\n");
return -99;
}
- if (ipv4_set && ipv6_set)
+ if (ip46_address_is_ip4 (&local) != ip46_address_is_ip4 (&remote))
{
errmsg ("both IPv4 and IPv6 addresses specified");
return -99;
@@ -307,20 +224,14 @@ api_vxlan_gpe_ioam_vni_disable (vat_main_t * vam)
M (VXLAN_GPE_IOAM_VNI_DISABLE, mp);
-
- if (ipv6_set)
- {
- clib_memcpy (&mp->local, &local6, sizeof (local6));
- clib_memcpy (&mp->remote, &remote6, sizeof (remote6));
- }
- else
- {
- clib_memcpy (&mp->local, &local4, sizeof (local4));
- clib_memcpy (&mp->remote, &remote4, sizeof (remote4));
- }
+ ip_address_encode (&local,
+ ip46_address_is_ip4 (&local) ? IP46_TYPE_IP4 :
+ IP46_TYPE_IP6, &mp->local);
+ ip_address_encode (&local,
+ ip46_address_is_ip4 (&remote) ? IP46_TYPE_IP4 :
+ IP46_TYPE_IP6, &mp->remote);
mp->vni = ntohl (vni);
- mp->is_ipv6 = ipv6_set;
S (mp);
W (ret);
@@ -332,9 +243,7 @@ api_vxlan_gpe_ioam_transit_enable (vat_main_t * vam)
{
unformat_input_t *line_input = vam->input;
vl_api_vxlan_gpe_ioam_transit_enable_t *mp;
- ip4_address_t local4;
- ip6_address_t local6;
- u8 ipv4_set = 0, ipv6_set = 0;
+ ip46_address_t local;
u8 local_set = 0;
u32 outer_fib_index = 0;
int ret;
@@ -342,18 +251,10 @@ api_vxlan_gpe_ioam_transit_enable (vat_main_t * vam)
while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
{
- if (unformat (line_input, "dst-ip %U", unformat_ip4_address, &local4))
- {
- local_set = 1;
- ipv4_set = 1;
- }
- else if (unformat (line_input, "dst-ip %U",
- unformat_ip6_address, &local6))
+ if (unformat (line_input, "dst-ip %U", unformat_ip46_address, &local))
{
local_set = 1;
- ipv6_set = 1;
}
-
else if (unformat (line_input, "outer-fib-index %d", &outer_fib_index))
;
else
@@ -368,28 +269,17 @@ api_vxlan_gpe_ioam_transit_enable (vat_main_t * vam)
errmsg ("destination address not specified\n");
return -99;
}
- if (ipv4_set && ipv6_set)
- {
- errmsg ("both IPv4 and IPv6 addresses specified");
- return -99;
- }
-
M (VXLAN_GPE_IOAM_TRANSIT_ENABLE, mp);
- if (ipv6_set)
+ if (!ip46_address_is_ip4 (&local))
{
errmsg ("IPv6 currently unsupported");
return -1;
}
- else
- {
- clib_memcpy (&mp->dst_addr, &local4, sizeof (local4));
- }
-
+ ip_address_encode (&local, IP46_TYPE_IP4, &mp->dst_addr);
mp->outer_fib_index = htonl (outer_fib_index);
- mp->is_ipv6 = ipv6_set;
S (mp);
W (ret);
@@ -401,9 +291,7 @@ api_vxlan_gpe_ioam_transit_disable (vat_main_t * vam)
{
unformat_input_t *line_input = vam->input;
vl_api_vxlan_gpe_ioam_transit_disable_t *mp;
- ip4_address_t local4;
- ip6_address_t local6;
- u8 ipv4_set = 0, ipv6_set = 0;
+ ip46_address_t local;
u8 local_set = 0;
u32 outer_fib_index = 0;
int ret;
@@ -411,18 +299,10 @@ api_vxlan_gpe_ioam_transit_disable (vat_main_t * vam)
while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
{
- if (unformat (line_input, "dst-ip %U", unformat_ip4_address, &local4))
- {
- local_set = 1;
- ipv4_set = 1;
- }
- else if (unformat (line_input, "dst-ip %U",
- unformat_ip6_address, &local6))
+ if (unformat (line_input, "dst-ip %U", unformat_ip46_address, &local))
{
local_set = 1;
- ipv6_set = 1;
}
-
else if (unformat (line_input, "outer-fib-index %d", &outer_fib_index))
;
else
@@ -437,96 +317,26 @@ api_vxlan_gpe_ioam_transit_disable (vat_main_t * vam)
errmsg ("destination address not specified\n");
return -99;
}
- if (ipv4_set && ipv6_set)
- {
- errmsg ("both IPv4 and IPv6 addresses specified");
- return -99;
- }
-
M (VXLAN_GPE_IOAM_TRANSIT_DISABLE, mp);
- if (ipv6_set)
+ if (!ip46_address_is_ip4 (&local))
{
return -1;
}
- else
- {
- clib_memcpy (&mp->dst_addr, &local4, sizeof (local4));
- }
+ ip_address_encode (&local, IP46_TYPE_IP4, &mp->dst_addr);
mp->outer_fib_index = htonl (outer_fib_index);
- mp->is_ipv6 = ipv6_set;
S (mp);
W (ret);
return ret;
}
-/*
- * List of messages that the api test plugin sends,
- * and that the data plane plugin processes
- */
-#define foreach_vpe_api_msg \
-_(vxlan_gpe_ioam_enable, ""\
- "[trace] [pow] [ppc <encap|ppc decap>]") \
-_(vxlan_gpe_ioam_disable, "") \
-_(vxlan_gpe_ioam_vni_enable, ""\
- "local <local_vtep_ip> remote <remote_vtep_ip> vni <vnid>") \
-_(vxlan_gpe_ioam_vni_disable, ""\
- "local <local_vtep_ip> remote <remote_vtep_ip> vni <vnid>") \
-_(vxlan_gpe_ioam_transit_enable, ""\
- "dst-ip <dst_ip> [outer-fib-index <outer_fib_index>]") \
-_(vxlan_gpe_ioam_transit_disable, ""\
- "dst-ip <dst_ip> [outer-fib-index <outer_fib_index>]") \
-
-
-static void
-vxlan_gpe_vat_api_hookup (vat_main_t * vam)
-{
- vxlan_gpe_test_main_t *sm = &vxlan_gpe_test_main;
- /* Hook up handlers for replies from the data plane plug-in */
-#define _(N,n) \
- vl_msg_api_set_handlers((VL_API_##N + sm->msg_id_base), \
- #n, \
- vl_api_##n##_t_handler, \
- vl_noop_handler, \
- vl_api_##n##_t_endian, \
- vl_api_##n##_t_print, \
- sizeof(vl_api_##n##_t), 1);
- foreach_vpe_api_reply_msg;
-#undef _
-
- /* API messages we can send */
-#define _(n,h) hash_set_mem (vam->function_by_name, #n, api_##n);
- foreach_vpe_api_msg;
-#undef _
-
- /* Help strings */
-#define _(n,h) hash_set_mem (vam->help_by_name, #n, h);
- foreach_vpe_api_msg;
-#undef _
-}
-
-clib_error_t *
-vxlan_gpe_vat_plugin_register (vat_main_t * vam)
-{
- vxlan_gpe_test_main_t *sm = &vxlan_gpe_test_main;
- u8 *name;
-
- sm->vat_main = vam;
-
- name = format (0, "ioam_vxlan_gpe_%08x%c", api_version, 0);
- sm->msg_id_base = vl_client_get_first_plugin_msg_id ((char *) name);
-
- if (sm->msg_id_base != (u16) ~ 0)
- vxlan_gpe_vat_api_hookup (vam);
-
- vec_free (name);
-
- return 0;
-}
+/* Override generated plugin register symbol */
+#define vat_plugin_register vxlan_gpe_vat_plugin_register
+#include <ioam/lib-vxlan-gpe/ioam_vxlan_gpe.api_test.c>
/*
* fd.io coding-style-patch-verification: ON