api: API trace improvements
[vpp.git] / test / test_bfd.py
index c8bda73..e6a710d 100644 (file)
@@ -5,13 +5,14 @@ from __future__ import division
 
 import binascii
 import hashlib
+import ipaddress
+import reprlib
 import time
 import unittest
 from random import randint, shuffle, getrandbits
 from socket import AF_INET, AF_INET6, inet_ntop
 from struct import pack, unpack
 
-from six import moves
 import scapy.compat
 from scapy.layers.inet import UDP, IP
 from scapy.layers.inet6 import IPv6
@@ -20,7 +21,9 @@ from scapy.packet import Raw
 
 from bfd import VppBFDAuthKey, BFD, BFDAuthType, VppBFDUDPSession, \
     BFDDiagCode, BFDState, BFD_vpp_echo
+from framework import tag_fixme_vpp_workers
 from framework import VppTestCase, VppTestRunner, running_extended_tests
+from framework import tag_run_solo
 from util import ppp
 from vpp_ip import DpoProto
 from vpp_ip_route import VppIpRoute, VppRoutePath
@@ -52,7 +55,6 @@ class AuthKeyFactory(object):
                              conf_key_id=conf_key_id, key=key)
 
 
-@unittest.skipUnless(running_extended_tests, "part of extended tests")
 class BFDAPITestCase(VppTestCase):
     """Bidirectional Forwarding Detection (BFD) - API"""
 
@@ -152,7 +154,7 @@ class BFDAPITestCase(VppTestCase):
         for key in keys:
             self.assertTrue(key.query_vpp_config())
         # remove randomly
-        indexes = range(key_count)
+        indexes = list(range(key_count))
         shuffle(indexes)
         removed = []
         for i in indexes:
@@ -210,7 +212,7 @@ class BFDAPITestCase(VppTestCase):
             session.add_vpp_config()
 
     def test_shared_sha1_key(self):
-        """ share single SHA1 key between multiple BFD sessions """
+        """ single SHA1 key shared by multiple BFD sessions """
         key = self.factory.create_random_key(self)
         key.add_vpp_config()
         sessions = [
@@ -284,8 +286,8 @@ class BFDAPITestCase(VppTestCase):
         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_ip4 = ipaddress.IPv4Address(int(ipaddress.IPv4Address(
+            self.loopback0.local_ip4)) ^ 1).packed
         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)
@@ -294,9 +296,9 @@ class BFDAPITestCase(VppTestCase):
         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_ip6 = ipaddress.IPv6Address(int(ipaddress.IPv6Address(
+            self.loopback0.local_ip6)) ^ 1).packed
+
         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)
@@ -451,7 +453,7 @@ class BFDTestSession(object):
         if self.sha1_key:
             hash_material = scapy.compat.raw(
                 packet[BFD])[:32] + self.sha1_key.key + \
-                "\0" * (20 - len(self.sha1_key.key))
+                b"\0" * (20 - len(self.sha1_key.key))
             self.test.logger.debug("BFD: Calculated SHA1 hash: %s" %
                                    hashlib.sha1(hash_material).hexdigest())
             packet[BFD].auth_key_hash = hashlib.sha1(hash_material).digest()
@@ -510,7 +512,7 @@ class BFDTestSession(object):
             b"\0" * (20 - len(self.sha1_key.key))
         expected_hash = hashlib.sha1(hash_material).hexdigest()
         self.test.assert_equal(binascii.hexlify(bfd.auth_key_hash),
-                               expected_hash, "Auth key hash")
+                               expected_hash.encode(), "Auth key hash")
 
     def verify_bfd(self, packet):
         """ Verify correctness of BFD layer. """
@@ -530,7 +532,7 @@ def bfd_session_up(test):
     old_offset = None
     if hasattr(test, 'vpp_clock_offset'):
         old_offset = test.vpp_clock_offset
-    test.vpp_clock_offset = time.time() - p.time
+    test.vpp_clock_offset = time.time() - float(p.time)
     test.logger.debug("BFD: Calculated vpp clock offset: %s",
                       test.vpp_clock_offset)
     if old_offset:
@@ -547,7 +549,7 @@ def bfd_session_up(test):
         test.test_session.inc_seq_num()
     test.test_session.send_packet()
     test.logger.info("BFD: Waiting for event")
-    e = test.vapi.wait_for_event(1, "bfd_udp_session_details")
+    e = test.vapi.wait_for_event(1, "bfd_udp_session_event")
     verify_event(test, e, expected_state=BFDState.up)
     test.logger.info("BFD: Session is Up")
     test.test_session.update(state=BFDState.up)
@@ -567,7 +569,7 @@ def bfd_session_down(test):
         test.test_session.inc_seq_num()
     test.test_session.send_packet()
     test.logger.info("BFD: Waiting for event")
-    e = test.vapi.wait_for_event(1, "bfd_udp_session_details")
+    e = test.vapi.wait_for_event(1, "bfd_udp_session_event")
     verify_event(test, e, expected_state=BFDState.down)
     test.logger.info("BFD: Session is Down")
     test.assert_equal(test.vpp_session.state, BFDState.down, BFDState)
@@ -624,7 +626,7 @@ def verify_udp(test, packet):
 def verify_event(test, event, expected_state):
     """ Verify correctness of event values. """
     e = event
-    test.logger.debug("BFD: Event: %s" % moves.reprlib.repr(e))
+    test.logger.debug("BFD: Event: %s" % reprlib.repr(e))
     test.assert_equal(e.sw_if_index,
                       test.vpp_session.interface.sw_if_index,
                       "BFD interface index")
@@ -677,7 +679,7 @@ def wait_for_bfd_packet(test, timeout=1, pcap_time_min=None, is_tunnel=False):
     return p
 
 
-@unittest.skipUnless(running_extended_tests, "part of extended tests")
+@tag_run_solo
 class BFD4TestCase(VppTestCase):
     """Bidirectional Forwarding Detection (BFD)"""
 
@@ -748,12 +750,12 @@ class BFD4TestCase(VppTestCase):
         self.test_session.update(your_discriminator=p[BFD].my_discriminator,
                                  state=BFDState.up)
         self.logger.info("BFD: Waiting for event")
-        e = self.vapi.wait_for_event(1, "bfd_udp_session_details")
+        e = self.vapi.wait_for_event(1, "bfd_udp_session_event")
         verify_event(self, e, expected_state=BFDState.init)
         self.logger.info("BFD: Sending Up")
         self.test_session.send_packet()
         self.logger.info("BFD: Waiting for event")
-        e = self.vapi.wait_for_event(1, "bfd_udp_session_details")
+        e = self.vapi.wait_for_event(1, "bfd_udp_session_event")
         verify_event(self, e, expected_state=BFDState.up)
         self.logger.info("BFD: Session is Up")
         self.test_session.update(state=BFDState.up)
@@ -765,7 +767,6 @@ class BFD4TestCase(VppTestCase):
         bfd_session_up(self)
         bfd_session_down(self)
 
-    @unittest.skipUnless(running_extended_tests, "part of extended tests")
     def test_hold_up(self):
         """ hold BFD session up """
         bfd_session_up(self)
@@ -775,7 +776,6 @@ class BFD4TestCase(VppTestCase):
         self.assert_equal(len(self.vapi.collect_events()), 0,
                           "number of bfd events")
 
-    @unittest.skipUnless(running_extended_tests, "part of extended tests")
     def test_slow_timer(self):
         """ verify slow periodic control frames while session down """
         packet_count = 3
@@ -790,7 +790,6 @@ class BFD4TestCase(VppTestCase):
                 time_diff, 0.70, 1.05, "time between slow packets")
             prev_packet = next_packet
 
-    @unittest.skipUnless(running_extended_tests, "part of extended tests")
     def test_zero_remote_min_rx(self):
         """ no packets when zero remote required min rx interval """
         bfd_session_up(self)
@@ -815,17 +814,25 @@ class BFD4TestCase(VppTestCase):
         self.assert_equal(
             len(self.vapi.collect_events()), 0, "number of bfd events")
 
-    @unittest.skipUnless(running_extended_tests, "part of extended tests")
     def test_conn_down(self):
         """ verify session goes down after inactivity """
         bfd_session_up(self)
         detection_time = self.test_session.detect_mult *\
             self.vpp_session.required_min_rx / USEC_IN_SEC
         self.sleep(detection_time, "waiting for BFD session time-out")
-        e = self.vapi.wait_for_event(1, "bfd_udp_session_details")
+        e = self.vapi.wait_for_event(1, "bfd_udp_session_event")
         verify_event(self, e, expected_state=BFDState.down)
 
-    @unittest.skipUnless(running_extended_tests, "part of extended tests")
+    def test_peer_discr_reset_sess_down(self):
+        """ peer discriminator reset after session goes down """
+        bfd_session_up(self)
+        detection_time = self.test_session.detect_mult *\
+            self.vpp_session.required_min_rx / USEC_IN_SEC
+        self.sleep(detection_time, "waiting for BFD session time-out")
+        self.test_session.my_discriminator = 0
+        wait_for_bfd_packet(self,
+                            pcap_time_min=time.time() - self.vpp_clock_offset)
+
     def test_large_required_min_rx(self):
         """ large remote required min rx interval """
         bfd_session_up(self)
@@ -855,7 +862,6 @@ class BFD4TestCase(VppTestCase):
                 break
         self.assert_equal(count, 0, "number of packets received")
 
-    @unittest.skipUnless(running_extended_tests, "part of extended tests")
     def test_immediate_remote_min_rx_reduction(self):
         """ immediately honor remote required min rx reduction """
         self.vpp_session.remove_vpp_config()
@@ -888,7 +894,6 @@ class BFD4TestCase(VppTestCase):
                                  "time between BFD packets")
             reference_packet = p
 
-    @unittest.skipUnless(running_extended_tests, "part of extended tests")
     def test_modify_req_min_rx_double(self):
         """ modify session - double required min rx """
         bfd_session_up(self)
@@ -912,13 +917,12 @@ class BFD4TestCase(VppTestCase):
                 self.vpp_session.required_min_rx) / USEC_IN_SEC
         self.test_session.send_packet(final)
         time_mark = time.time()
-        e = self.vapi.wait_for_event(2 * timeout, "bfd_udp_session_details")
+        e = self.vapi.wait_for_event(2 * timeout, "bfd_udp_session_event")
         verify_event(self, e, expected_state=BFDState.down)
         time_to_event = time.time() - time_mark
         self.assert_in_range(time_to_event, .9 * timeout,
                              1.1 * timeout, "session timeout")
 
-    @unittest.skipUnless(running_extended_tests, "part of extended tests")
     def test_modify_req_min_rx_halve(self):
         """ modify session - halve required min rx """
         self.vpp_session.modify_parameters(
@@ -953,7 +957,7 @@ class BFD4TestCase(VppTestCase):
             self.vpp_session.required_min_rx / USEC_IN_SEC
         before = time.time()
         e = self.vapi.wait_for_event(
-            2 * detection_time, "bfd_udp_session_details")
+            2 * detection_time, "bfd_udp_session_event")
         after = time.time()
         self.assert_in_range(after - before,
                              0.9 * detection_time,
@@ -961,7 +965,6 @@ class BFD4TestCase(VppTestCase):
                              "time before bfd session goes down")
         verify_event(self, e, expected_state=BFDState.down)
 
-    @unittest.skipUnless(running_extended_tests, "part of extended tests")
     def test_modify_detect_mult(self):
         """ modify detect multiplier """
         bfd_session_up(self)
@@ -985,7 +988,6 @@ class BFD4TestCase(VppTestCase):
         self.assertNotIn("P", p.sprintf("%BFD.flags%"),
                          "Poll bit not set in BFD packet")
 
-    @unittest.skipUnless(running_extended_tests, "part of extended tests")
     def test_queued_poll(self):
         """ test poll sequence queueing """
         bfd_session_up(self)
@@ -1051,6 +1053,7 @@ class BFD4TestCase(VppTestCase):
         self.assertNotIn("P", p.sprintf("%BFD.flags%"),
                          "Poll bit set in BFD packet")
 
+    # returning inconsistent results requiring retries in per-patch tests
     @unittest.skipUnless(running_extended_tests, "part of extended tests")
     def test_poll_response(self):
         """ test correct response to control frame with poll bit set """
@@ -1062,7 +1065,6 @@ class BFD4TestCase(VppTestCase):
             self, pcap_time_min=time.time() - self.vpp_clock_offset)
         self.assertIn("F", final.sprintf("%BFD.flags%"))
 
-    @unittest.skipUnless(running_extended_tests, "part of extended tests")
     def test_no_periodic_if_remote_demand(self):
         """ no periodic frames outside poll sequence if remote demand set """
         bfd_session_up(self)
@@ -1190,7 +1192,6 @@ class BFD4TestCase(VppTestCase):
             self.test_session.send_packet()
         self.assertTrue(echo_seen, "No echo packets received")
 
-    @unittest.skipUnless(running_extended_tests, "part of extended tests")
     def test_echo_fail(self):
         """ session goes down if echo function fails """
         bfd_session_up(self)
@@ -1231,7 +1232,6 @@ class BFD4TestCase(VppTestCase):
         self.assert_equal(events[0].state, BFDState.down, BFDState)
         self.assertTrue(verified_diag, "Incorrect diagnostics code received")
 
-    @unittest.skipUnless(running_extended_tests, "part of extended tests")
     def test_echo_stop(self):
         """ echo function stops if peer sets required min echo rx zero """
         bfd_session_up(self)
@@ -1264,7 +1264,6 @@ class BFD4TestCase(VppTestCase):
             events = self.vapi.collect_events()
             self.assert_equal(len(events), 0, "number of bfd events")
 
-    @unittest.skipUnless(running_extended_tests, "part of extended tests")
     def test_echo_source_removed(self):
         """ echo function stops if echo source is removed """
         bfd_session_up(self)
@@ -1297,7 +1296,6 @@ class BFD4TestCase(VppTestCase):
             events = self.vapi.collect_events()
             self.assert_equal(len(events), 0, "number of bfd events")
 
-    @unittest.skipUnless(running_extended_tests, "part of extended tests")
     def test_stale_echo(self):
         """ stale echo packets don't keep a session up """
         bfd_session_up(self)
@@ -1351,7 +1349,6 @@ class BFD4TestCase(VppTestCase):
             self.test_session.send_packet()
         self.assertTrue(timeout_ok, "Expected timeout event didn't occur")
 
-    @unittest.skipUnless(running_extended_tests, "part of extended tests")
     def test_invalid_echo_checksum(self):
         """ echo packets with invalid checksum don't keep a session up """
         bfd_session_up(self)
@@ -1402,13 +1399,12 @@ class BFD4TestCase(VppTestCase):
             self.test_session.send_packet()
         self.assertTrue(timeout_ok, "Expected timeout event didn't occur")
 
-    @unittest.skipUnless(running_extended_tests, "part of extended tests")
     def test_admin_up_down(self):
         """ put session admin-up and admin-down """
         bfd_session_up(self)
         self.vpp_session.admin_down()
         self.pg0.enable_capture()
-        e = self.vapi.wait_for_event(1, "bfd_udp_session_details")
+        e = self.vapi.wait_for_event(1, "bfd_udp_session_event")
         verify_event(self, e, expected_state=BFDState.admin_down)
         for dummy in range(2):
             p = wait_for_bfd_packet(self)
@@ -1421,7 +1417,7 @@ class BFD4TestCase(VppTestCase):
             self.assert_equal(p[BFD].state, BFDState.admin_down, BFDState)
         self.vpp_session.admin_up()
         self.test_session.update(state=BFDState.down)
-        e = self.vapi.wait_for_event(1, "bfd_udp_session_details")
+        e = self.vapi.wait_for_event(1, "bfd_udp_session_event")
         verify_event(self, e, expected_state=BFDState.down)
         p = wait_for_bfd_packet(
             self, pcap_time_min=time.time() - self.vpp_clock_offset)
@@ -1430,17 +1426,16 @@ class BFD4TestCase(VppTestCase):
         p = wait_for_bfd_packet(
             self, pcap_time_min=time.time() - self.vpp_clock_offset)
         self.assert_equal(p[BFD].state, BFDState.init, BFDState)
-        e = self.vapi.wait_for_event(1, "bfd_udp_session_details")
+        e = self.vapi.wait_for_event(1, "bfd_udp_session_event")
         verify_event(self, e, expected_state=BFDState.init)
         self.test_session.update(state=BFDState.up)
         self.test_session.send_packet()
         p = wait_for_bfd_packet(
             self, pcap_time_min=time.time() - self.vpp_clock_offset)
         self.assert_equal(p[BFD].state, BFDState.up, BFDState)
-        e = self.vapi.wait_for_event(1, "bfd_udp_session_details")
+        e = self.vapi.wait_for_event(1, "bfd_udp_session_event")
         verify_event(self, e, expected_state=BFDState.up)
 
-    @unittest.skipUnless(running_extended_tests, "part of extended tests")
     def test_config_change_remote_demand(self):
         """ configuration change while peer in demand mode """
         bfd_session_up(self)
@@ -1488,12 +1483,13 @@ class BFD4TestCase(VppTestCase):
         vpp_session.add_vpp_config()
         vpp_session.admin_up()
         intf.remove_vpp_config()
-        e = self.vapi.wait_for_event(1, "bfd_udp_session_details")
+        e = self.vapi.wait_for_event(1, "bfd_udp_session_event")
         self.assert_equal(e.sw_if_index, sw_if_index, "sw_if_index")
         self.assertFalse(vpp_session.query_vpp_config())
 
 
-@unittest.skipUnless(running_extended_tests, "part of extended tests")
+@tag_run_solo
+@tag_fixme_vpp_workers
 class BFD6TestCase(VppTestCase):
     """Bidirectional Forwarding Detection (BFD) (IPv6) """
 
@@ -1566,19 +1562,18 @@ class BFD6TestCase(VppTestCase):
         self.test_session.update(your_discriminator=p[BFD].my_discriminator,
                                  state=BFDState.up)
         self.logger.info("BFD: Waiting for event")
-        e = self.vapi.wait_for_event(1, "bfd_udp_session_details")
+        e = self.vapi.wait_for_event(1, "bfd_udp_session_event")
         verify_event(self, e, expected_state=BFDState.init)
         self.logger.info("BFD: Sending Up")
         self.test_session.send_packet()
         self.logger.info("BFD: Waiting for event")
-        e = self.vapi.wait_for_event(1, "bfd_udp_session_details")
+        e = self.vapi.wait_for_event(1, "bfd_udp_session_event")
         verify_event(self, e, expected_state=BFDState.up)
         self.logger.info("BFD: Session is Up")
         self.test_session.update(state=BFDState.up)
         self.test_session.send_packet()
         self.assert_equal(self.vpp_session.state, BFDState.up, BFDState)
 
-    @unittest.skipUnless(running_extended_tests, "part of extended tests")
     def test_hold_up(self):
         """ hold BFD session up """
         bfd_session_up(self)
@@ -1703,12 +1698,12 @@ class BFD6TestCase(VppTestCase):
         vpp_session.add_vpp_config()
         vpp_session.admin_up()
         intf.remove_vpp_config()
-        e = self.vapi.wait_for_event(1, "bfd_udp_session_details")
+        e = self.vapi.wait_for_event(1, "bfd_udp_session_event")
         self.assert_equal(e.sw_if_index, sw_if_index, "sw_if_index")
         self.assertFalse(vpp_session.query_vpp_config())
 
 
-@unittest.skipUnless(running_extended_tests, "part of extended tests")
+@tag_run_solo
 class BFDFIBTestCase(VppTestCase):
     """ BFD-FIB interactions (IPv6) """
 
@@ -1895,7 +1890,7 @@ class BFDTunTestCase(VppTestCase):
         bfd_session_down(self)
 
 
-@unittest.skipUnless(running_extended_tests, "part of extended tests")
+@tag_run_solo
 class BFDSHA1TestCase(VppTestCase):
     """Bidirectional Forwarding Detection (BFD) (SHA1 auth) """
 
@@ -1948,7 +1943,6 @@ class BFDSHA1TestCase(VppTestCase):
             bfd_key_id=self.vpp_session.bfd_key_id)
         bfd_session_up(self)
 
-    @unittest.skipUnless(running_extended_tests, "part of extended tests")
     def test_hold_up(self):
         """ hold BFD session up """
         key = self.factory.create_random_key(self)
@@ -1967,7 +1961,6 @@ class BFDSHA1TestCase(VppTestCase):
             self.test_session.send_packet()
         self.assert_equal(self.vpp_session.state, BFDState.up, BFDState)
 
-    @unittest.skipUnless(running_extended_tests, "part of extended tests")
     def test_hold_up_meticulous(self):
         """ hold BFD session up - meticulous auth """
         key = self.factory.create_random_key(
@@ -1989,7 +1982,6 @@ class BFDSHA1TestCase(VppTestCase):
             self.test_session.send_packet()
         self.assert_equal(self.vpp_session.state, BFDState.up, BFDState)
 
-    @unittest.skipUnless(running_extended_tests, "part of extended tests")
     def test_send_bad_seq_number(self):
         """ session is not kept alive by msgs with bad sequence numbers"""
         key = self.factory.create_random_key(
@@ -2052,7 +2044,6 @@ class BFDSHA1TestCase(VppTestCase):
         wait_for_bfd_packet(self)
         self.assert_equal(self.vpp_session.state, BFDState.up, BFDState)
 
-    @unittest.skipUnless(running_extended_tests, "part of extended tests")
     def test_mismatch_auth(self):
         """ session is not brought down by unauthenticated msg """
         key = self.factory.create_random_key(self)
@@ -2067,7 +2058,6 @@ class BFDSHA1TestCase(VppTestCase):
                                             legitimate_test_session,
                                             rogue_test_session)
 
-    @unittest.skipUnless(running_extended_tests, "part of extended tests")
     def test_mismatch_bfd_key_id(self):
         """ session is not brought down by msg with non-existent key-id """
         key = self.factory.create_random_key(self)
@@ -2087,7 +2077,6 @@ class BFDSHA1TestCase(VppTestCase):
                                             legitimate_test_session,
                                             rogue_test_session)
 
-    @unittest.skipUnless(running_extended_tests, "part of extended tests")
     def test_mismatched_auth_type(self):
         """ session is not brought down by msg with wrong auth type """
         key = self.factory.create_random_key(self)
@@ -2104,7 +2093,6 @@ class BFDSHA1TestCase(VppTestCase):
             vpp_session, legitimate_test_session, rogue_test_session,
             {'auth_type': BFDAuthType.keyed_md5})
 
-    @unittest.skipUnless(running_extended_tests, "part of extended tests")
     def test_restart(self):
         """ simulate remote peer restart and resynchronization """
         key = self.factory.create_random_key(
@@ -2130,10 +2118,11 @@ class BFDSHA1TestCase(VppTestCase):
         self.test_session.vpp_seq_number = None
         # now throw away any pending packets
         self.pg0.enable_capture()
+        self.test_session.my_discriminator = 0
         bfd_session_up(self)
 
 
-@unittest.skipUnless(running_extended_tests, "part of extended tests")
+@tag_run_solo
 class BFDAuthOnOffTestCase(VppTestCase):
     """Bidirectional Forwarding Detection (BFD) (changing auth) """
 
@@ -2346,7 +2335,7 @@ class BFDAuthOnOffTestCase(VppTestCase):
                           "number of bfd events")
 
 
-@unittest.skipUnless(running_extended_tests, "part of extended tests")
+@tag_run_solo
 class BFDCLITestCase(VppTestCase):
     """Bidirectional Forwarding Detection (BFD) (CLI) """
     pg0 = None
@@ -2387,7 +2376,7 @@ class BFDCLITestCase(VppTestCase):
     def cli_verify_no_response(self, cli):
         """ execute a CLI, asserting that the response is empty """
         self.assert_equal(self.vapi.cli(cli),
-                          b"",
+                          "",
                           "CLI command response")
 
     def cli_verify_response(self, cli, expected):
@@ -2749,16 +2738,15 @@ class BFDCLITestCase(VppTestCase):
                                  "IPv6 address usable as echo source: none" %
                                  self.loopback0.name)
         self.loopback0.config_ip4()
-        unpacked = unpack("!L", self.loopback0.local_ip4n)
-        echo_ip4 = inet_ntop(AF_INET, pack("!L", unpacked[0] ^ 1))
+        echo_ip4 = str(ipaddress.IPv4Address(int(ipaddress.IPv4Address(
+            self.loopback0.local_ip4)) ^ 1))
         self.cli_verify_response("show bfd echo-source",
                                  "UDP echo source is: %s\n"
                                  "IPv4 address usable as echo source: %s\n"
                                  "IPv6 address usable as echo source: none" %
                                  (self.loopback0.name, echo_ip4))
-        unpacked = unpack("!LLLL", self.loopback0.local_ip6n)
-        echo_ip6 = inet_ntop(AF_INET6, pack("!LLLL", unpacked[0], unpacked[1],
-                                            unpacked[2], unpacked[3] ^ 1))
+        echo_ip6 = str(ipaddress.IPv6Address(int(ipaddress.IPv6Address(
+            self.loopback0.local_ip6)) ^ 1))
         self.loopback0.config_ip6()
         self.cli_verify_response("show bfd echo-source",
                                  "UDP echo source is: %s\n"