aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorOle Troan <ot@cisco.com>2019-12-08 14:14:37 +0100
committerAndrew Yourtchenko <ayourtch@gmail.com>2019-12-09 12:43:47 +0000
commit55636cb623d3161da34120c01a666e36f3be7302 (patch)
treec2f950b2757bf2fb51f7a46cdfe981224c91bf4b /src
parent60f5108a99cca759668aa8efbac11dcd17cba983 (diff)
gtpu: use explicit types in api
Type: fix Signed-off-by: Ole Troan <ot@cisco.com> Change-Id: I16fcbd5e63526dbf062a3032701479324fe2a4f5
Diffstat (limited to 'src')
-rw-r--r--src/plugins/gtpu/gtpu.api34
-rw-r--r--src/plugins/gtpu/gtpu.c3
-rw-r--r--src/plugins/gtpu/gtpu.h1
-rw-r--r--src/plugins/gtpu/gtpu_api.c30
-rw-r--r--src/plugins/gtpu/gtpu_test.c24
-rw-r--r--src/plugins/gtpu/test/test_gtpu.py69
6 files changed, 83 insertions, 78 deletions
diff --git a/src/plugins/gtpu/gtpu.api b/src/plugins/gtpu/gtpu.api
index b5f4f029c53..052e6a292d7 100644
--- a/src/plugins/gtpu/gtpu.api
+++ b/src/plugins/gtpu/gtpu.api
@@ -13,13 +13,14 @@
* limitations under the License.
*/
-option version = "1.0.0";
+option version = "2.0.0";
+import "vnet/interface_types.api";
+import "vnet/ip/ip_types.api";
/** \brief Set or delete an GTPU tunnel
@param client_index - opaque cookie to identify the sender
@param context - sender context, to match reply w/ request
@param is_add - add address if non-zero, else delete
- @param is_ipv6 - src_address and dst_address is ipv6 or not
@param src_address - GTPU tunnel's source address.
@param dst_address - GTPU tunnel's destination address.
@param mcast_sw_if_index - version, O-bit and C-bit (see nsh_packet.h)
@@ -31,11 +32,10 @@ define gtpu_add_del_tunnel
{
u32 client_index;
u32 context;
- u8 is_add;
- u8 is_ipv6;
- u8 src_address[16];
- u8 dst_address[16];
- u32 mcast_sw_if_index;
+ bool is_add;
+ vl_api_address_t src_address;
+ vl_api_address_t dst_address;
+ vl_api_interface_index_t mcast_sw_if_index;
u32 encap_vrf_id;
u32 decap_next_index;
u32 teid;
@@ -51,7 +51,7 @@ define gtpu_add_del_tunnel_reply
{
u32 context;
i32 retval;
- u32 sw_if_index;
+ vl_api_interface_index_t sw_if_index;
};
/** \brief Dump GTPU tunnel
@@ -63,14 +63,13 @@ define gtpu_tunnel_dump
{
u32 client_index;
u32 context;
- u32 sw_if_index;
+ vl_api_interface_index_t sw_if_index;
option vat_help = "[<intfc> | sw_if_index <nn>]";
};
/** \brief dump details of an GTPU tunnel
@param context - sender context, to match reply w/ request
@param sw_if_index - software index of the interface
- @param is_ipv6 - src_address and dst_address is ipv6 or not
@param src_address - GTPU tunnel's source address.
@param dst_address - GTPU tunnel's destination address.
@param mcast_sw_if_index - version, O-bit and C-bit (see nsh_packet.h)
@@ -81,11 +80,10 @@ define gtpu_tunnel_dump
define gtpu_tunnel_details
{
u32 context;
- u32 sw_if_index;
- u8 is_ipv6;
- u8 src_address[16];
- u8 dst_address[16];
- u32 mcast_sw_if_index;
+ vl_api_interface_index_t sw_if_index;
+ vl_api_address_t src_address;
+ vl_api_address_t dst_address;
+ vl_api_interface_index_t mcast_sw_if_index;
u32 encap_vrf_id;
u32 decap_next_index;
u32 teid;
@@ -102,9 +100,9 @@ autoreply define sw_interface_set_gtpu_bypass
{
u32 client_index;
u32 context;
- u32 sw_if_index;
- u8 is_ipv6;
- u8 enable;
+ vl_api_interface_index_t sw_if_index;
+ bool is_ipv6;
+ bool enable;
option vat_help = "<intfc> | sw_if_index <id> [ip4 | ip6] [enable | disable]";
};
diff --git a/src/plugins/gtpu/gtpu.c b/src/plugins/gtpu/gtpu.c
index dc5c689f5d3..8a1610c97e7 100644
--- a/src/plugins/gtpu/gtpu.c
+++ b/src/plugins/gtpu/gtpu.c
@@ -379,7 +379,7 @@ int vnet_gtpu_add_del_tunnel
u32 sw_if_index = ~0;
gtpu4_tunnel_key_t key4;
gtpu6_tunnel_key_t key6;
- u32 is_ip6 = a->is_ip6;
+ bool is_ip6 = !ip46_address_is_ip4 (&a->dst);
if (!is_ip6)
{
@@ -820,7 +820,6 @@ gtpu_add_del_tunnel_command_fn (vlib_main_t * vm,
clib_memset (a, 0, sizeof (*a));
a->is_add = is_add;
- a->is_ip6 = ipv6_set;
#define _(x) a->x = x;
foreach_copy_field;
diff --git a/src/plugins/gtpu/gtpu.h b/src/plugins/gtpu/gtpu.h
index 7296ece5b7c..dc36308d8a8 100644
--- a/src/plugins/gtpu/gtpu.h
+++ b/src/plugins/gtpu/gtpu.h
@@ -245,7 +245,6 @@ u8 *format_gtpu_encap_trace (u8 * s, va_list * args);
typedef struct
{
u8 is_add;
- u8 is_ip6;
ip46_address_t src, dst;
u32 mcast_sw_if_index;
u32 encap_fib_index;
diff --git a/src/plugins/gtpu/gtpu_api.c b/src/plugins/gtpu/gtpu_api.c
index 77ae3349721..0c4a31521bb 100644
--- a/src/plugins/gtpu/gtpu_api.c
+++ b/src/plugins/gtpu/gtpu_api.c
@@ -24,9 +24,10 @@
#include <vppinfra/byte_order.h>
#include <vlibmemory/api.h>
-
+#include <vnet/ip/ip_types_api.h>
#include <gtpu/gtpu.h>
+#include <vnet/format_fns.h>
#include <gtpu/gtpu.api_enum.h>
#include <gtpu/gtpu.api_types.h>
@@ -67,14 +68,13 @@ static void vl_api_gtpu_add_del_tunnel_t_handler
vnet_gtpu_add_del_tunnel_args_t a = {
.is_add = mp->is_add,
- .is_ip6 = mp->is_ipv6,
.mcast_sw_if_index = ntohl (mp->mcast_sw_if_index),
.encap_fib_index = p[0],
.decap_next_index = ntohl (mp->decap_next_index),
.teid = ntohl (mp->teid),
- .dst = to_ip46 (mp->is_ipv6, mp->dst_address),
- .src = to_ip46 (mp->is_ipv6, mp->src_address),
};
+ ip_address_decode (&mp->dst_address, &a.dst);
+ ip_address_decode (&mp->src_address, &a.src);
/* Check src & dst are different */
if (ip46_address_cmp (&a.dst, &a.src) == 0)
@@ -113,23 +113,19 @@ static void send_gtpu_tunnel_details
rmp = vl_msg_api_alloc (sizeof (*rmp));
clib_memset (rmp, 0, sizeof (*rmp));
rmp->_vl_msg_id = ntohs (VL_API_GTPU_TUNNEL_DETAILS + gtm->msg_id_base);
- if (is_ipv6)
- {
- memcpy (rmp->src_address, t->src.ip6.as_u8, 16);
- memcpy (rmp->dst_address, t->dst.ip6.as_u8, 16);
- rmp->encap_vrf_id = htonl (im6->fibs[t->encap_fib_index].ft_table_id);
- }
- else
- {
- memcpy (rmp->src_address, t->src.ip4.as_u8, 4);
- memcpy (rmp->dst_address, t->dst.ip4.as_u8, 4);
- rmp->encap_vrf_id = htonl (im4->fibs[t->encap_fib_index].ft_table_id);
- }
+
+ ip_address_encode (&t->src, is_ipv6 ? IP46_TYPE_IP6 : IP46_TYPE_IP4,
+ &rmp->src_address);
+ ip_address_encode (&t->dst, is_ipv6 ? IP46_TYPE_IP6 : IP46_TYPE_IP4,
+ &rmp->dst_address);
+
+ rmp->encap_vrf_id =
+ is_ipv6 ? htonl (im6->fibs[t->encap_fib_index].ft_table_id) :
+ htonl (im4->fibs[t->encap_fib_index].ft_table_id);
rmp->mcast_sw_if_index = htonl (t->mcast_sw_if_index);
rmp->teid = htonl (t->teid);
rmp->decap_next_index = htonl (t->decap_next_index);
rmp->sw_if_index = htonl (t->sw_if_index);
- rmp->is_ipv6 = is_ipv6;
rmp->context = context;
vl_api_send_msg (reg, (u8 *) rmp);
diff --git a/src/plugins/gtpu/gtpu_test.c b/src/plugins/gtpu/gtpu_test.c
index 36f4a8e1e49..55c5363becc 100644
--- a/src/plugins/gtpu/gtpu_test.c
+++ b/src/plugins/gtpu/gtpu_test.c
@@ -18,10 +18,12 @@
#include <vlibmemory/api.h>
#include <vppinfra/error.h>
#include <gtpu/gtpu.h>
+#include <vnet/ip/ip_types_api.h>
#define __plugin_msg_base gtpu_test_main.msg_id_base
#include <vlibapi/vat_helper_macros.h>
+#include <vnet/format_fns.h>
#include <gtpu/gtpu.api_enum.h>
#include <gtpu/gtpu.api_types.h>
@@ -299,22 +301,15 @@ api_gtpu_add_del_tunnel (vat_main_t * vam)
M (GTPU_ADD_DEL_TUNNEL, mp);
- if (ipv6_set)
- {
- clib_memcpy (mp->src_address, &src.ip6, sizeof (src.ip6));
- clib_memcpy (mp->dst_address, &dst.ip6, sizeof (dst.ip6));
- }
- else
- {
- clib_memcpy (mp->src_address, &src.ip4, sizeof (src.ip4));
- clib_memcpy (mp->dst_address, &dst.ip4, sizeof (dst.ip4));
- }
+ ip_address_encode(&src, ipv6_set ? IP46_TYPE_IP6 : IP46_TYPE_IP4,
+ &mp->src_address);
+ ip_address_encode(&dst, ipv6_set ? IP46_TYPE_IP6 : IP46_TYPE_IP4,
+ &mp->dst_address);
mp->encap_vrf_id = ntohl (encap_vrf_id);
mp->decap_next_index = ntohl (decap_next_index);
mp->mcast_sw_if_index = ntohl (mcast_sw_if_index);
mp->teid = ntohl (teid);
mp->is_add = is_add;
- mp->is_ipv6 = ipv6_set;
S (mp);
W (ret);
@@ -325,9 +320,10 @@ static void vl_api_gtpu_tunnel_details_t_handler
(vl_api_gtpu_tunnel_details_t * mp)
{
vat_main_t *vam = &vat_main;
- ip46_address_t src = to_ip46 (mp->is_ipv6, mp->dst_address);
- ip46_address_t dst = to_ip46 (mp->is_ipv6, mp->src_address);
-
+ ip46_address_t src;
+ ip46_address_t dst;
+ ip_address_decode(&mp->dst_address, &dst);
+ ip_address_decode(&mp->src_address, &src);
print (vam->ofp, "%11d%24U%24U%14d%18d%13d%19d",
ntohl (mp->sw_if_index),
format_ip46_address, &src, IP46_TYPE_ANY,
diff --git a/src/plugins/gtpu/test/test_gtpu.py b/src/plugins/gtpu/test/test_gtpu.py
index b6a7012966a..e6d9c9e0598 100644
--- a/src/plugins/gtpu/test/test_gtpu.py
+++ b/src/plugins/gtpu/test/test_gtpu.py
@@ -74,31 +74,39 @@ class TestGtpuUDP(VppTestCase):
""" test UDP ports
Check if there are no udp listeners before gtpu is enabled
"""
-
# UDP ports should be disabled unless a tunnel is configured
self._check_udp_port_ip4(False)
self._check_udp_port_ip6(False)
- r = self.vapi.gtpu_add_del_tunnel(src_addr=self.pg0.local_ip4n,
- dst_addr=self.pg0.remote_ip4n)
+ r = self.vapi.gtpu_add_del_tunnel(is_add=True,
+ mcast_sw_if_index=0xFFFFFFFF,
+ decap_next_index=0xFFFFFFFF,
+ src_address=self.pg0.local_ip4,
+ dst_address=self.pg0.remote_ip4)
# UDP port 2152 enabled for ip4
self._check_udp_port_ip4()
- r = self.vapi.gtpu_add_del_tunnel(is_ipv6=1,
- src_addr=self.pg0.local_ip6n,
- dst_addr=self.pg0.remote_ip6n)
+ r = self.vapi.gtpu_add_del_tunnel(is_add=True,
+ mcast_sw_if_index=0xFFFFFFFF,
+ decap_next_index=0xFFFFFFFF,
+ src_address=self.pg0.local_ip6,
+ dst_address=self.pg0.remote_ip6)
# UDP port 2152 enabled for ip6
self._check_udp_port_ip6()
- r = self.vapi.gtpu_add_del_tunnel(is_add=0,
- src_addr=self.pg0.local_ip4n,
- dst_addr=self.pg0.remote_ip4n)
+ r = self.vapi.gtpu_add_del_tunnel(is_add=False,
+ mcast_sw_if_index=0xFFFFFFFF,
+ decap_next_index=0xFFFFFFFF,
+ src_address=self.pg0.local_ip4,
+ dst_address=self.pg0.remote_ip4)
- r = self.vapi.gtpu_add_del_tunnel(is_add=0, is_ipv6=1,
- src_addr=self.pg0.local_ip6n,
- dst_addr=self.pg0.remote_ip6n)
+ r = self.vapi.gtpu_add_del_tunnel(is_add=False,
+ mcast_sw_if_index=0xFFFFFFFF,
+ decap_next_index=0xFFFFFFFF,
+ src_address=self.pg0.local_ip6,
+ dst_address=self.pg0.remote_ip6)
class TestGtpu(BridgeDomain, VppTestCase):
@@ -235,10 +243,12 @@ class TestGtpu(BridgeDomain, VppTestCase):
INVALID_INDEX)],
register=False)
rip.add_vpp_config()
- dest_ip4n = socket.inet_pton(socket.AF_INET, dest_ip4)
r = cls.vapi.gtpu_add_del_tunnel(
- src_addr=cls.pg0.local_ip4n,
- dst_addr=dest_ip4n,
+ is_add=True,
+ mcast_sw_if_index=0xFFFFFFFF,
+ decap_next_index=0xFFFFFFFF,
+ src_address=cls.pg0.local_ip4,
+ dst_address=dest_ip4,
teid=teid)
cls.vapi.sw_interface_set_l2_bridge(rx_sw_if_index=r.sw_if_index,
bd_id=teid)
@@ -254,8 +264,9 @@ class TestGtpu(BridgeDomain, VppTestCase):
teid_end = teid_start + n_shared_dst_tunnels
for teid in range(teid_start, teid_end):
r = cls.vapi.gtpu_add_del_tunnel(
- src_addr=cls.pg0.local_ip4n,
- dst_addr=cls.mcast_ip4n,
+ decap_next_index=0xFFFFFFFF,
+ src_address=cls.pg0.local_ip4,
+ dst_address=cls.mcast_ip4,
mcast_sw_if_index=1,
teid=teid,
is_add=is_add)
@@ -278,12 +289,13 @@ class TestGtpu(BridgeDomain, VppTestCase):
n_distinct_dst_tunnels = 20
ip_range_start = 10
ip_range_end = ip_range_start + n_distinct_dst_tunnels
- for dest_ip4n in ip4n_range(cls.mcast_ip4n, ip_range_start,
- ip_range_end):
- teid = bytearray(dest_ip4n)[3]
+ for dest_ip4 in ip4_range(cls.mcast_ip4, ip_range_start,
+ ip_range_end):
+ teid = int(dest_ip4.split('.')[3])
cls.vapi.gtpu_add_del_tunnel(
- src_addr=cls.pg0.local_ip4n,
- dst_addr=dest_ip4n,
+ decap_next_index=0xFFFFFFFF,
+ src_address=cls.pg0.local_ip4,
+ dst_address=dest_ip4,
mcast_sw_if_index=1,
teid=teid,
is_add=is_add)
@@ -331,8 +343,11 @@ class TestGtpu(BridgeDomain, VppTestCase):
# into BD.
cls.single_tunnel_bd = 11
r = cls.vapi.gtpu_add_del_tunnel(
- src_addr=cls.pg0.local_ip4n,
- dst_addr=cls.pg0.remote_ip4n,
+ is_add=True,
+ mcast_sw_if_index=0xFFFFFFFF,
+ decap_next_index=0xFFFFFFFF,
+ src_address=cls.pg0.local_ip4,
+ dst_address=cls.pg0.remote_ip4,
teid=cls.single_tunnel_bd)
cls.vapi.sw_interface_set_l2_bridge(rx_sw_if_index=r.sw_if_index,
bd_id=cls.single_tunnel_bd)
@@ -345,9 +360,11 @@ class TestGtpu(BridgeDomain, VppTestCase):
cls.create_gtpu_flood_test_bd(cls.mcast_flood_bd,
cls.n_ucast_tunnels)
r = cls.vapi.gtpu_add_del_tunnel(
- src_addr=cls.pg0.local_ip4n,
- dst_addr=cls.mcast_ip4n,
+ is_add=True,
+ src_address=cls.pg0.local_ip4,
+ dst_address=cls.mcast_ip4,
mcast_sw_if_index=1,
+ decap_next_index=0xFFFFFFFF,
teid=cls.mcast_flood_bd)
cls.vapi.sw_interface_set_l2_bridge(rx_sw_if_index=r.sw_if_index,
bd_id=cls.mcast_flood_bd)