aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatus Fabian <matfabia@cisco.com>2018-10-02 03:22:18 -0700
committerDamjan Marion <dmarion@me.com>2018-10-02 12:32:15 +0000
commit2d3c7b9c4555ea4467253b0590c9aa1a6c644b4d (patch)
treebd48ef5082982c8c30c29ccf8a852bc80c6e36e4
parenta9a0b2ce2daabc5479aa7722e3ec7023f8c6c0d5 (diff)
BFD: add get echo source API (VPP-1367)
Change-Id: I45f540128e038ddb17ba96ce30965e8f7c732067 Signed-off-by: Matus Fabian <matfabia@cisco.com>
-rw-r--r--src/vnet/bfd/bfd.api32
-rw-r--r--src/vnet/bfd/bfd_api.c56
-rw-r--r--test/test_bfd.py45
-rw-r--r--test/vpp_papi_provider.py3
4 files changed, 135 insertions, 1 deletions
diff --git a/src/vnet/bfd/bfd.api b/src/vnet/bfd/bfd.api
index 912c6954407..afbcc731e5a 100644
--- a/src/vnet/bfd/bfd.api
+++ b/src/vnet/bfd/bfd.api
@@ -37,6 +37,38 @@ autoreply define bfd_udp_del_echo_source
u32 context;
};
+/** \brief Get BFD echo source
+ @param client_index - opaque cookie to identify the sender
+ @param context - sender context, to match reply w/ request
+*/
+define bfd_udp_get_echo_source
+{
+ u32 client_index;
+ u32 context;
+};
+
+/** \brief Get BFD echo source reply
+ @param context - sender context, to match reply w/ request
+ @param retval - return code
+ @param sw_if_index - interface to use as echo source
+ @param is_set - non-zero if set
+ @param have_usable_ip4 - non-zero if have usable IPv4 address
+ @param ip4_addr - IPv4 address
+ @param have_usable_ip6 - non-zero if have usable IPv6 address
+ @param ip6_addr - IPv6 address
+*/
+define bfd_udp_get_echo_source_reply
+{
+ u32 context;
+ i32 retval;
+ u32 sw_if_index;
+ u8 is_set;
+ u8 have_usable_ip4;
+ u8 ip4_addr[4];
+ u8 have_usable_ip6;
+ u8 ip6_addr[16];
+};
+
/** \brief Add UDP BFD session on interface
@param client_index - opaque cookie to identify the sender
@param context - sender context, to match reply w/ request
diff --git a/src/vnet/bfd/bfd_api.c b/src/vnet/bfd/bfd_api.c
index 33a7c1d8bf6..fcd66950114 100644
--- a/src/vnet/bfd/bfd_api.c
+++ b/src/vnet/bfd/bfd_api.c
@@ -60,7 +60,8 @@
_ (BFD_UDP_AUTH_ACTIVATE, bfd_udp_auth_activate) \
_ (BFD_UDP_AUTH_DEACTIVATE, bfd_udp_auth_deactivate) \
_ (BFD_UDP_SET_ECHO_SOURCE, bfd_udp_set_echo_source) \
- _ (BFD_UDP_DEL_ECHO_SOURCE, bfd_udp_del_echo_source)
+ _ (BFD_UDP_DEL_ECHO_SOURCE, bfd_udp_del_echo_source) \
+ _ (BFD_UDP_GET_ECHO_SOURCE, bfd_udp_get_echo_source)
pub_sub_handler (bfd_events, BFD_EVENTS);
@@ -359,6 +360,59 @@ vl_api_bfd_udp_del_echo_source_t_handler (vl_api_bfd_udp_del_echo_source_t *
REPLY_MACRO (VL_API_BFD_UDP_DEL_ECHO_SOURCE_REPLY);
}
+static void
+vl_api_bfd_udp_get_echo_source_t_handler (vl_api_bfd_udp_get_echo_source_t *
+ mp)
+{
+ vl_api_bfd_udp_get_echo_source_reply_t *rmp;
+ int rv = 0;
+ int is_set;
+ u32 sw_if_index;
+ int have_usable_ip4;
+ ip4_address_t ip4;
+ int have_usable_ip6;
+ ip6_address_t ip6;
+
+ bfd_udp_get_echo_source (&is_set, &sw_if_index, &have_usable_ip4, &ip4,
+ &have_usable_ip6, &ip6);
+
+ /* *INDENT-OFF* */
+ REPLY_MACRO2 (VL_API_BFD_UDP_GET_ECHO_SOURCE_REPLY,
+ ({
+ rmp->sw_if_index = ntohl (sw_if_index);
+ if (is_set)
+ {
+ rmp->is_set = 1;
+ rmp->sw_if_index = clib_host_to_net_u32 (sw_if_index);
+ if (have_usable_ip4)
+ {
+ rmp->have_usable_ip4 = 1;
+ clib_memcpy (rmp->ip4_addr, &ip4, sizeof (ip4));
+ }
+ else
+ {
+ rmp->have_usable_ip4 = 0;
+ }
+ if (have_usable_ip6)
+ {
+ rmp->have_usable_ip6 = 1;
+ clib_memcpy (rmp->ip6_addr, &ip6, sizeof (ip6));
+ }
+ else
+ {
+ rmp->have_usable_ip6 = 0;
+ }
+ }
+ else
+ {
+ rmp->is_set = 0;
+ rmp->have_usable_ip4 = 0;
+ rmp->have_usable_ip6 = 0;
+ }
+ }))
+ /* *INDENT-ON* */
+}
+
/*
* bfd_api_hookup
* Add vpe's API message handlers to the table.
diff --git a/test/test_bfd.py b/test/test_bfd.py
index f14ff71b341..a7f2b93982b 100644
--- a/test/test_bfd.py
+++ b/test/test_bfd.py
@@ -252,6 +252,51 @@ class BFDAPITestCase(VppTestCase):
session.add_vpp_config()
session.activate_auth(key2)
+ def test_set_del_udp_echo_source(self):
+ """ set/del udp echo source """
+ self.create_loopback_interfaces(1)
+ self.loopback0 = self.lo_interfaces[0]
+ self.loopback0.admin_up()
+ echo_source = self.vapi.bfd_udp_get_echo_source()
+ self.assertFalse(echo_source.is_set)
+ self.assertFalse(echo_source.have_usable_ip4)
+ self.assertFalse(echo_source.have_usable_ip6)
+
+ self.vapi.bfd_udp_set_echo_source(self.loopback0.sw_if_index)
+ echo_source = self.vapi.bfd_udp_get_echo_source()
+ self.assertTrue(echo_source.is_set)
+ self.assertEqual(echo_source.sw_if_index, self.loopback0.sw_if_index)
+ self.assertFalse(echo_source.have_usable_ip4)
+ self.assertFalse(echo_source.have_usable_ip6)
+
+ self.loopback0.config_ip4()
+ unpacked = unpack("!L", self.loopback0.local_ip4n)
+ echo_ip4 = pack("!L", unpacked[0] ^ 1)
+ echo_source = self.vapi.bfd_udp_get_echo_source()
+ self.assertTrue(echo_source.is_set)
+ self.assertEqual(echo_source.sw_if_index, self.loopback0.sw_if_index)
+ self.assertTrue(echo_source.have_usable_ip4)
+ self.assertEqual(echo_source.ip4_addr, echo_ip4)
+ self.assertFalse(echo_source.have_usable_ip6)
+
+ self.loopback0.config_ip6()
+ unpacked = unpack("!LLLL", self.loopback0.local_ip6n)
+ echo_ip6 = pack("!LLLL", unpacked[0], unpacked[1], unpacked[2],
+ unpacked[3] ^ 1)
+ echo_source = self.vapi.bfd_udp_get_echo_source()
+ self.assertTrue(echo_source.is_set)
+ self.assertEqual(echo_source.sw_if_index, self.loopback0.sw_if_index)
+ self.assertTrue(echo_source.have_usable_ip4)
+ self.assertEqual(echo_source.ip4_addr, echo_ip4)
+ self.assertTrue(echo_source.have_usable_ip6)
+ self.assertEqual(echo_source.ip6_addr, echo_ip6)
+
+ self.vapi.bfd_udp_del_echo_source()
+ echo_source = self.vapi.bfd_udp_get_echo_source()
+ self.assertFalse(echo_source.is_set)
+ self.assertFalse(echo_source.have_usable_ip4)
+ self.assertFalse(echo_source.have_usable_ip6)
+
@unittest.skipUnless(running_extended_tests(), "part of extended tests")
class BFDTestSession(object):
diff --git a/test/vpp_papi_provider.py b/test/vpp_papi_provider.py
index 5ef1b309e06..a51dea4685e 100644
--- a/test/vpp_papi_provider.py
+++ b/test/vpp_papi_provider.py
@@ -2272,6 +2272,9 @@ class VppPapiProvider(object):
def bfd_udp_del_echo_source(self):
return self.api(self.papi.bfd_udp_del_echo_source, {})
+ def bfd_udp_get_echo_source(self):
+ return self.api(self.papi.bfd_udp_get_echo_source, {})
+
def classify_add_del_table(
self,
is_add,