Renato Botelho do Couto | ead1e53 | 2019-10-31 13:31:07 -0500 | [diff] [blame] | 1 | #!/usr/bin/env python3 |
Klement Sekera | d3ba515 | 2017-02-14 03:09:17 +0100 | [diff] [blame] | 2 | """ BFD tests """ |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 3 | |
Klement Sekera | a57a970 | 2017-02-02 06:58:07 +0100 | [diff] [blame] | 4 | from __future__ import division |
Paul Vinciguerra | 00671cf | 2018-11-25 12:47:04 -0800 | [diff] [blame] | 5 | |
Klement Sekera | b17dd96 | 2017-01-09 07:43:48 +0100 | [diff] [blame] | 6 | import binascii |
Klement Sekera | cdaf0d8 | 2022-02-14 20:20:22 +0000 | [diff] [blame] | 7 | from collections import namedtuple |
Paul Vinciguerra | 00671cf | 2018-11-25 12:47:04 -0800 | [diff] [blame] | 8 | import hashlib |
Paul Vinciguerra | 2f15631 | 2020-05-02 22:34:40 -0400 | [diff] [blame] | 9 | import ipaddress |
Paul Vinciguerra | 090096b | 2020-12-03 00:42:46 -0500 | [diff] [blame] | 10 | import reprlib |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 11 | import time |
Paul Vinciguerra | 00671cf | 2018-11-25 12:47:04 -0800 | [diff] [blame] | 12 | import unittest |
Klement Sekera | 239790f | 2017-02-16 10:53:53 +0100 | [diff] [blame] | 13 | from random import randint, shuffle, getrandbits |
Dave Wallace | 8800f73 | 2023-08-31 00:47:44 -0400 | [diff] [blame] | 14 | from socket import AF_INET, AF_INET6 |
Abdel Baig | 17a9181 | 2024-09-03 11:52:20 -0400 | [diff] [blame] | 15 | from parameterized import parameterized, parameterized_class |
Paul Vinciguerra | 00671cf | 2018-11-25 12:47:04 -0800 | [diff] [blame] | 16 | |
Paul Vinciguerra | a7427ec | 2019-03-10 10:04:23 -0700 | [diff] [blame] | 17 | import scapy.compat |
Klement Sekera | d3ba515 | 2017-02-14 03:09:17 +0100 | [diff] [blame] | 18 | from scapy.layers.inet import UDP, IP |
| 19 | from scapy.layers.inet6 import IPv6 |
Neale Ranns | 52cd496 | 2019-06-05 10:28:17 +0000 | [diff] [blame] | 20 | from scapy.layers.l2 import Ether, GRE |
Paul Vinciguerra | 00671cf | 2018-11-25 12:47:04 -0800 | [diff] [blame] | 21 | from scapy.packet import Raw |
| 22 | |
Klement Sekera | b23ffd7 | 2021-05-31 16:08:53 +0200 | [diff] [blame] | 23 | from config import config |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 24 | from bfd import ( |
| 25 | VppBFDAuthKey, |
| 26 | BFD, |
| 27 | BFDAuthType, |
| 28 | VppBFDUDPSession, |
| 29 | BFDDiagCode, |
| 30 | BFDState, |
| 31 | BFD_vpp_echo, |
Abdel Baig | 17a9181 | 2024-09-03 11:52:20 -0400 | [diff] [blame] | 32 | BFD_UDP_SH_PORT, |
| 33 | BFD_UDP_MH_PORT, |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 34 | ) |
Dave Wallace | 8800f73 | 2023-08-31 00:47:44 -0400 | [diff] [blame] | 35 | from framework import VppTestCase |
| 36 | from asfframework import ( |
| 37 | tag_fixme_vpp_workers, |
| 38 | tag_fixme_debian11, |
| 39 | tag_run_solo, |
| 40 | VppTestRunner, |
| 41 | ) |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 42 | from util import ppp |
Neale Ranns | c0a9314 | 2018-09-05 15:42:26 -0700 | [diff] [blame] | 43 | from vpp_ip import DpoProto |
| 44 | from vpp_ip_route import VppIpRoute, VppRoutePath |
Paul Vinciguerra | 00671cf | 2018-11-25 12:47:04 -0800 | [diff] [blame] | 45 | from vpp_lo_interface import VppLoInterface |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 46 | from vpp_papi_provider import UnexpectedApiReturnValueError, CliFailedCommandError |
Paul Vinciguerra | 00671cf | 2018-11-25 12:47:04 -0800 | [diff] [blame] | 47 | from vpp_pg_interface import CaptureTimeoutError, is_ipv6_misc |
Neale Ranns | 52cd496 | 2019-06-05 10:28:17 +0000 | [diff] [blame] | 48 | from vpp_gre_interface import VppGreInterface |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 49 | |
Klement Sekera | d3ba515 | 2017-02-14 03:09:17 +0100 | [diff] [blame] | 50 | USEC_IN_SEC = 1000000 |
Abdel Baig | 17a9181 | 2024-09-03 11:52:20 -0400 | [diff] [blame] | 51 | BFD_STATS_V4_SH_PATH = "/bfd/udp4/sessions" |
| 52 | BFD_STATS_V6_SH_PATH = "/bfd/udp6/sessions" |
| 53 | BFD_STATS_V4_MH_PATH = "/bfd/udp4/sessions_mh" |
| 54 | BFD_STATS_V6_MH_PATH = "/bfd/udp6/sessions_mh" |
| 55 | BFD_IPV4_REMOTE_ADDR = "2.2.2.2" |
| 56 | BFD_IPV6_REMOTE_ADDR = "2::2" |
| 57 | BFD_IPV4_REMOTE_ADDR2 = "3.3.3.3" |
| 58 | BFD_IPV6_REMOTE_ADDR2 = "3::3" |
| 59 | |
| 60 | |
| 61 | def set_ipv4_pfx_route_info(cls, pg_if, dst_ip, set_src): |
| 62 | try: |
| 63 | if cls.multihop: |
| 64 | paths = [] |
| 65 | # Get list of all the next hops |
| 66 | for nh_host in pg_if.remote_hosts: |
| 67 | nh_host_ip = nh_host.ip4 |
| 68 | paths.append(VppRoutePath(nh_host_ip, pg_if.sw_if_index)) |
| 69 | cls.dst_ip_net = dst_ip |
| 70 | # Create a route pointing to list of next hops |
| 71 | if paths: |
| 72 | rip = VppIpRoute(cls, cls.dst_ip_net, 32, paths) |
| 73 | rip.add_vpp_config() |
| 74 | cls.logger.info("Route via %s on %s created" % (paths, pg_if.name)) |
| 75 | if set_src: |
| 76 | cls.src_ip_net = cls.loopback0.local_ip4 |
| 77 | else: |
| 78 | cls.dst_ip_net = pg_if.remote_ip4 |
| 79 | if set_src: |
| 80 | cls.src_ip_net = pg_if.local_ip4 |
| 81 | except BaseException: |
| 82 | cls.vapi.want_bfd_events(enable_disable=0) |
| 83 | raise |
| 84 | |
| 85 | |
| 86 | def set_ipv6_pfx_route_info(cls, pg_if, dst_ip, set_src): |
| 87 | try: |
| 88 | if cls.multihop: |
| 89 | paths = [] |
| 90 | # Get list of all the next hops |
| 91 | for nh_host in pg_if.remote_hosts: |
| 92 | nh_host_ip = nh_host.ip6 |
| 93 | paths.append(VppRoutePath(nh_host_ip, pg_if.sw_if_index)) |
| 94 | cls.dst_ip6_net = dst_ip |
| 95 | # Create a route pointing to list of next hops |
| 96 | if paths: |
| 97 | rip = VppIpRoute(cls, cls.dst_ip6_net, 128, paths) |
| 98 | rip.add_vpp_config() |
| 99 | cls.logger.info("Route via %s on %s created" % (paths, pg_if.name)) |
| 100 | if set_src: |
| 101 | cls.src_ip6_net = cls.loopback0.local_ip6 |
| 102 | else: |
| 103 | cls.dst_ip6_net = cls.pg0.remote_ip6 |
| 104 | if set_src: |
| 105 | cls.src_ip6_net = cls.pg0.local_ip6 |
| 106 | except BaseException: |
| 107 | cls.vapi.want_bfd_events(enable_disable=0) |
| 108 | raise |
Klement Sekera | 3e0a356 | 2016-12-19 09:05:21 +0100 | [diff] [blame] | 109 | |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 110 | |
Klement Sekera | b17dd96 | 2017-01-09 07:43:48 +0100 | [diff] [blame] | 111 | class AuthKeyFactory(object): |
| 112 | """Factory class for creating auth keys with unique conf key ID""" |
| 113 | |
| 114 | def __init__(self): |
| 115 | self._conf_key_ids = {} |
| 116 | |
| 117 | def create_random_key(self, test, auth_type=BFDAuthType.keyed_sha1): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 118 | """create a random key with unique conf key id""" |
Klement Sekera | b17dd96 | 2017-01-09 07:43:48 +0100 | [diff] [blame] | 119 | conf_key_id = randint(0, 0xFFFFFFFF) |
| 120 | while conf_key_id in self._conf_key_ids: |
| 121 | conf_key_id = randint(0, 0xFFFFFFFF) |
| 122 | self._conf_key_ids[conf_key_id] = 1 |
Paul Vinciguerra | a7427ec | 2019-03-10 10:04:23 -0700 | [diff] [blame] | 123 | key = scapy.compat.raw( |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 124 | bytearray([randint(0, 255) for _ in range(randint(1, 20))]) |
| 125 | ) |
| 126 | return VppBFDAuthKey( |
| 127 | test=test, auth_type=auth_type, conf_key_id=conf_key_id, key=key |
| 128 | ) |
Klement Sekera | b17dd96 | 2017-01-09 07:43:48 +0100 | [diff] [blame] | 129 | |
| 130 | |
Abdel Baig | 17a9181 | 2024-09-03 11:52:20 -0400 | [diff] [blame] | 131 | @parameterized_class( |
| 132 | [ |
| 133 | {"multihop": False}, |
| 134 | {"multihop": True}, |
| 135 | ] |
| 136 | ) |
Klement Sekera | e4504c6 | 2016-12-08 10:16:41 +0100 | [diff] [blame] | 137 | class BFDAPITestCase(VppTestCase): |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 138 | |
Klement Sekera | d3ba515 | 2017-02-14 03:09:17 +0100 | [diff] [blame] | 139 | pg0 = None |
| 140 | pg1 = None |
Abdel Baig | 17a9181 | 2024-09-03 11:52:20 -0400 | [diff] [blame] | 141 | interface0 = None |
| 142 | interface1 = None |
| 143 | src_ip_net = "" |
| 144 | dst_ip_net = "" |
| 145 | src_ip_net2 = "" |
| 146 | dst_ip_net2 = "" |
| 147 | src_ip6_net = "" |
| 148 | dst_ip6_net = "" |
| 149 | src_ip6_net2 = "" |
| 150 | dst_ip6_net2 = "" |
Klement Sekera | d3ba515 | 2017-02-14 03:09:17 +0100 | [diff] [blame] | 151 | |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 152 | @classmethod |
| 153 | def setUpClass(cls): |
Klement Sekera | e4504c6 | 2016-12-08 10:16:41 +0100 | [diff] [blame] | 154 | super(BFDAPITestCase, cls).setUpClass() |
Abdel Baig | 17a9181 | 2024-09-03 11:52:20 -0400 | [diff] [blame] | 155 | hoptype_str = "MultiHop" if cls.multihop else "SingleHop" |
| 156 | cls.__doc__ = ( |
| 157 | f"""""Bidirectional Forwarding Detection (BFD) - API, {hoptype_str}""" |
| 158 | ) |
Damjan Marion | 07a3857 | 2018-01-21 06:44:18 -0800 | [diff] [blame] | 159 | cls.vapi.cli("set log class bfd level debug") |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 160 | try: |
Klement Sekera | 10db26f | 2017-01-11 08:16:53 +0100 | [diff] [blame] | 161 | cls.create_pg_interfaces(range(2)) |
Abdel Baig | 17a9181 | 2024-09-03 11:52:20 -0400 | [diff] [blame] | 162 | cls.create_loopback_interfaces(2) |
| 163 | cls.loopback0 = cls.lo_interfaces[0] |
| 164 | cls.loopback0.config_ip4() |
| 165 | cls.loopback0.admin_up() |
| 166 | cls.loopback1 = cls.lo_interfaces[1] |
| 167 | cls.loopback1.config_ip4() |
| 168 | cls.loopback1.admin_up() |
Klement Sekera | 10db26f | 2017-01-11 08:16:53 +0100 | [diff] [blame] | 169 | for i in cls.pg_interfaces: |
| 170 | i.config_ip4() |
Klement Sekera | b17dd96 | 2017-01-09 07:43:48 +0100 | [diff] [blame] | 171 | i.config_ip6() |
Klement Sekera | 10db26f | 2017-01-11 08:16:53 +0100 | [diff] [blame] | 172 | i.resolve_arp() |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 173 | |
| 174 | except Exception: |
Klement Sekera | e4504c6 | 2016-12-08 10:16:41 +0100 | [diff] [blame] | 175 | super(BFDAPITestCase, cls).tearDownClass() |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 176 | raise |
| 177 | |
Paul Vinciguerra | 8d991d9 | 2019-01-25 14:05:48 -0800 | [diff] [blame] | 178 | @classmethod |
| 179 | def tearDownClass(cls): |
| 180 | super(BFDAPITestCase, cls).tearDownClass() |
| 181 | |
Klement Sekera | b17dd96 | 2017-01-09 07:43:48 +0100 | [diff] [blame] | 182 | def setUp(self): |
| 183 | super(BFDAPITestCase, self).setUp() |
| 184 | self.factory = AuthKeyFactory() |
| 185 | |
Abdel Baig | 17a9181 | 2024-09-03 11:52:20 -0400 | [diff] [blame] | 186 | if self.multihop: |
| 187 | self.interface0 = None |
| 188 | self.interface1 = None |
| 189 | self.src_ip_net = self.loopback0.local_ip4 |
| 190 | self.src_ip6_net = self.loopback0.local_ip6 |
| 191 | self.dst_ip_net = BFD_IPV4_REMOTE_ADDR |
| 192 | self.dst_ip6_net = BFD_IPV6_REMOTE_ADDR |
| 193 | self.src_ip_net2 = self.loopback1.local_ip4 |
| 194 | self.src_ip6_net2 = self.loopback1.local_ip6 |
| 195 | self.dst_ip_net2 = BFD_IPV4_REMOTE_ADDR2 |
| 196 | self.dst_ip6_net2 = BFD_IPV6_REMOTE_ADDR2 |
| 197 | else: |
| 198 | self.interface0 = self.pg0 |
| 199 | self.interface1 = self.pg1 |
| 200 | self.src_ip_net = self.pg0.local_ip4 |
| 201 | self.src_ip6_net = self.pg0.local_ip6 |
| 202 | self.dst_ip_net = self.pg0.remote_ip4 |
| 203 | self.dst_ip6_net = self.pg0.remote_ip6 |
| 204 | self.src_ip_net2 = self.pg1.local_ip4 |
| 205 | self.src_ip6_net2 = self.pg1.local_ip6 |
| 206 | self.dst_ip_net2 = BFD_IPV4_REMOTE_ADDR2 |
| 207 | self.dst_ip6_net2 = BFD_IPV6_REMOTE_ADDR2 |
| 208 | |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 209 | def test_add_bfd(self): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 210 | """create a BFD session""" |
Abdel Baig | 17a9181 | 2024-09-03 11:52:20 -0400 | [diff] [blame] | 211 | session = VppBFDUDPSession( |
| 212 | self, |
| 213 | self.interface0, |
| 214 | self.dst_ip_net, |
| 215 | local_addr=self.src_ip_net, |
| 216 | multihop=self.multihop, |
| 217 | ) |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 218 | session.add_vpp_config() |
Klement Sekera | d3ba515 | 2017-02-14 03:09:17 +0100 | [diff] [blame] | 219 | self.logger.debug("Session state is %s", session.state) |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 220 | session.remove_vpp_config() |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 221 | session.add_vpp_config() |
Klement Sekera | d3ba515 | 2017-02-14 03:09:17 +0100 | [diff] [blame] | 222 | self.logger.debug("Session state is %s", session.state) |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 223 | session.remove_vpp_config() |
| 224 | |
| 225 | def test_double_add(self): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 226 | """create the same BFD session twice (negative case)""" |
Abdel Baig | 17a9181 | 2024-09-03 11:52:20 -0400 | [diff] [blame] | 227 | session = VppBFDUDPSession( |
| 228 | self, |
| 229 | self.interface0, |
| 230 | self.dst_ip_net, |
| 231 | local_addr=self.src_ip_net, |
| 232 | multihop=self.multihop, |
| 233 | ) |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 234 | session.add_vpp_config() |
Klement Sekera | e0545ef | 2017-01-25 08:00:40 +0100 | [diff] [blame] | 235 | |
Klement Sekera | 7d6afb3 | 2018-11-08 11:52:04 +0100 | [diff] [blame] | 236 | with self.vapi.assert_negative_api_retval(): |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 237 | session.add_vpp_config() |
Klement Sekera | e0545ef | 2017-01-25 08:00:40 +0100 | [diff] [blame] | 238 | |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 239 | session.remove_vpp_config() |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 240 | |
Klement Sekera | b17dd96 | 2017-01-09 07:43:48 +0100 | [diff] [blame] | 241 | def test_add_bfd6(self): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 242 | """create IPv6 BFD session""" |
Abdel Baig | 17a9181 | 2024-09-03 11:52:20 -0400 | [diff] [blame] | 243 | session = VppBFDUDPSession( |
| 244 | self, |
| 245 | self.interface0, |
| 246 | self.dst_ip6_net, |
| 247 | local_addr=self.src_ip6_net, |
| 248 | af=AF_INET6, |
| 249 | multihop=self.multihop, |
| 250 | ) |
Klement Sekera | b17dd96 | 2017-01-09 07:43:48 +0100 | [diff] [blame] | 251 | session.add_vpp_config() |
Klement Sekera | d3ba515 | 2017-02-14 03:09:17 +0100 | [diff] [blame] | 252 | self.logger.debug("Session state is %s", session.state) |
Klement Sekera | b17dd96 | 2017-01-09 07:43:48 +0100 | [diff] [blame] | 253 | session.remove_vpp_config() |
| 254 | session.add_vpp_config() |
Klement Sekera | d3ba515 | 2017-02-14 03:09:17 +0100 | [diff] [blame] | 255 | self.logger.debug("Session state is %s", session.state) |
Klement Sekera | b17dd96 | 2017-01-09 07:43:48 +0100 | [diff] [blame] | 256 | session.remove_vpp_config() |
| 257 | |
Klement Sekera | a57a970 | 2017-02-02 06:58:07 +0100 | [diff] [blame] | 258 | def test_mod_bfd(self): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 259 | """modify BFD session parameters""" |
| 260 | session = VppBFDUDPSession( |
| 261 | self, |
Abdel Baig | 17a9181 | 2024-09-03 11:52:20 -0400 | [diff] [blame] | 262 | self.interface0, |
| 263 | self.dst_ip_net, |
| 264 | local_addr=self.src_ip_net, |
| 265 | multihop=self.multihop, |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 266 | desired_min_tx=50000, |
| 267 | required_min_rx=10000, |
| 268 | detect_mult=1, |
| 269 | ) |
Klement Sekera | a57a970 | 2017-02-02 06:58:07 +0100 | [diff] [blame] | 270 | session.add_vpp_config() |
Klement Sekera | d3ba515 | 2017-02-14 03:09:17 +0100 | [diff] [blame] | 271 | s = session.get_bfd_udp_session_dump_entry() |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 272 | self.assert_equal( |
| 273 | session.desired_min_tx, s.desired_min_tx, "desired min transmit interval" |
| 274 | ) |
| 275 | self.assert_equal( |
| 276 | session.required_min_rx, s.required_min_rx, "required min receive interval" |
| 277 | ) |
Klement Sekera | d3ba515 | 2017-02-14 03:09:17 +0100 | [diff] [blame] | 278 | self.assert_equal(session.detect_mult, s.detect_mult, "detect mult") |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 279 | session.modify_parameters( |
| 280 | desired_min_tx=session.desired_min_tx * 2, |
| 281 | required_min_rx=session.required_min_rx * 2, |
| 282 | detect_mult=session.detect_mult * 2, |
| 283 | ) |
Klement Sekera | d3ba515 | 2017-02-14 03:09:17 +0100 | [diff] [blame] | 284 | s = session.get_bfd_udp_session_dump_entry() |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 285 | self.assert_equal( |
| 286 | session.desired_min_tx, s.desired_min_tx, "desired min transmit interval" |
| 287 | ) |
| 288 | self.assert_equal( |
| 289 | session.required_min_rx, s.required_min_rx, "required min receive interval" |
| 290 | ) |
Klement Sekera | d3ba515 | 2017-02-14 03:09:17 +0100 | [diff] [blame] | 291 | self.assert_equal(session.detect_mult, s.detect_mult, "detect mult") |
Klement Sekera | a57a970 | 2017-02-02 06:58:07 +0100 | [diff] [blame] | 292 | |
Neale Ranns | 63f2c7d | 2022-02-09 13:47:29 +0000 | [diff] [blame] | 293 | def test_upd_bfd(self): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 294 | """Create/Modify w/ Update BFD session parameters""" |
| 295 | session = VppBFDUDPSession( |
| 296 | self, |
Abdel Baig | 17a9181 | 2024-09-03 11:52:20 -0400 | [diff] [blame] | 297 | self.interface0, |
| 298 | self.dst_ip_net, |
| 299 | local_addr=self.src_ip_net, |
| 300 | multihop=self.multihop, |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 301 | desired_min_tx=50000, |
| 302 | required_min_rx=10000, |
| 303 | detect_mult=1, |
| 304 | ) |
Neale Ranns | 63f2c7d | 2022-02-09 13:47:29 +0000 | [diff] [blame] | 305 | session.upd_vpp_config() |
| 306 | s = session.get_bfd_udp_session_dump_entry() |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 307 | self.assert_equal( |
| 308 | session.desired_min_tx, s.desired_min_tx, "desired min transmit interval" |
| 309 | ) |
| 310 | self.assert_equal( |
| 311 | session.required_min_rx, s.required_min_rx, "required min receive interval" |
| 312 | ) |
Neale Ranns | 63f2c7d | 2022-02-09 13:47:29 +0000 | [diff] [blame] | 313 | |
| 314 | self.assert_equal(session.detect_mult, s.detect_mult, "detect mult") |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 315 | session.upd_vpp_config( |
| 316 | desired_min_tx=session.desired_min_tx * 2, |
| 317 | required_min_rx=session.required_min_rx * 2, |
| 318 | detect_mult=session.detect_mult * 2, |
| 319 | ) |
Neale Ranns | 63f2c7d | 2022-02-09 13:47:29 +0000 | [diff] [blame] | 320 | s = session.get_bfd_udp_session_dump_entry() |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 321 | self.assert_equal( |
| 322 | session.desired_min_tx, s.desired_min_tx, "desired min transmit interval" |
| 323 | ) |
| 324 | self.assert_equal( |
| 325 | session.required_min_rx, s.required_min_rx, "required min receive interval" |
| 326 | ) |
Neale Ranns | 63f2c7d | 2022-02-09 13:47:29 +0000 | [diff] [blame] | 327 | self.assert_equal(session.detect_mult, s.detect_mult, "detect mult") |
| 328 | |
Klement Sekera | b17dd96 | 2017-01-09 07:43:48 +0100 | [diff] [blame] | 329 | def test_add_sha1_keys(self): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 330 | """add SHA1 keys""" |
Klement Sekera | b17dd96 | 2017-01-09 07:43:48 +0100 | [diff] [blame] | 331 | key_count = 10 |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 332 | keys = [self.factory.create_random_key(self) for i in range(0, key_count)] |
Klement Sekera | b17dd96 | 2017-01-09 07:43:48 +0100 | [diff] [blame] | 333 | for key in keys: |
| 334 | self.assertFalse(key.query_vpp_config()) |
| 335 | for key in keys: |
| 336 | key.add_vpp_config() |
| 337 | for key in keys: |
| 338 | self.assertTrue(key.query_vpp_config()) |
| 339 | # remove randomly |
snaramre | 73aff47 | 2019-12-02 05:49:28 +0000 | [diff] [blame] | 340 | indexes = list(range(key_count)) |
Klement Sekera | d3ba515 | 2017-02-14 03:09:17 +0100 | [diff] [blame] | 341 | shuffle(indexes) |
Klement Sekera | b17dd96 | 2017-01-09 07:43:48 +0100 | [diff] [blame] | 342 | removed = [] |
| 343 | for i in indexes: |
| 344 | key = keys[i] |
| 345 | key.remove_vpp_config() |
| 346 | removed.append(i) |
| 347 | for j in range(key_count): |
| 348 | key = keys[j] |
| 349 | if j in removed: |
| 350 | self.assertFalse(key.query_vpp_config()) |
| 351 | else: |
| 352 | self.assertTrue(key.query_vpp_config()) |
| 353 | # should be removed now |
| 354 | for key in keys: |
| 355 | self.assertFalse(key.query_vpp_config()) |
| 356 | # add back and remove again |
| 357 | for key in keys: |
| 358 | key.add_vpp_config() |
| 359 | for key in keys: |
| 360 | self.assertTrue(key.query_vpp_config()) |
| 361 | for key in keys: |
| 362 | key.remove_vpp_config() |
| 363 | for key in keys: |
| 364 | self.assertFalse(key.query_vpp_config()) |
| 365 | |
| 366 | def test_add_bfd_sha1(self): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 367 | """create a BFD session (SHA1)""" |
Klement Sekera | b17dd96 | 2017-01-09 07:43:48 +0100 | [diff] [blame] | 368 | key = self.factory.create_random_key(self) |
| 369 | key.add_vpp_config() |
Abdel Baig | 17a9181 | 2024-09-03 11:52:20 -0400 | [diff] [blame] | 370 | session = VppBFDUDPSession( |
| 371 | self, |
| 372 | self.interface0, |
| 373 | self.dst_ip_net, |
| 374 | local_addr=self.src_ip_net, |
| 375 | multihop=self.multihop, |
| 376 | sha1_key=key, |
| 377 | ) |
Klement Sekera | b17dd96 | 2017-01-09 07:43:48 +0100 | [diff] [blame] | 378 | session.add_vpp_config() |
Klement Sekera | d3ba515 | 2017-02-14 03:09:17 +0100 | [diff] [blame] | 379 | self.logger.debug("Session state is %s", session.state) |
Klement Sekera | b17dd96 | 2017-01-09 07:43:48 +0100 | [diff] [blame] | 380 | session.remove_vpp_config() |
| 381 | session.add_vpp_config() |
Klement Sekera | d3ba515 | 2017-02-14 03:09:17 +0100 | [diff] [blame] | 382 | self.logger.debug("Session state is %s", session.state) |
Klement Sekera | b17dd96 | 2017-01-09 07:43:48 +0100 | [diff] [blame] | 383 | session.remove_vpp_config() |
| 384 | |
| 385 | def test_double_add_sha1(self): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 386 | """create the same BFD session twice (negative case) (SHA1)""" |
Klement Sekera | b17dd96 | 2017-01-09 07:43:48 +0100 | [diff] [blame] | 387 | key = self.factory.create_random_key(self) |
| 388 | key.add_vpp_config() |
Abdel Baig | 17a9181 | 2024-09-03 11:52:20 -0400 | [diff] [blame] | 389 | session = VppBFDUDPSession( |
| 390 | self, |
| 391 | self.interface0, |
| 392 | self.dst_ip_net, |
| 393 | local_addr=self.src_ip_net, |
| 394 | multihop=self.multihop, |
| 395 | sha1_key=key, |
| 396 | ) |
Klement Sekera | b17dd96 | 2017-01-09 07:43:48 +0100 | [diff] [blame] | 397 | session.add_vpp_config() |
| 398 | with self.assertRaises(Exception): |
| 399 | session.add_vpp_config() |
| 400 | |
Klement Sekera | d3ba515 | 2017-02-14 03:09:17 +0100 | [diff] [blame] | 401 | def test_add_auth_nonexistent_key(self): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 402 | """create BFD session using non-existent SHA1 (negative case)""" |
Klement Sekera | b17dd96 | 2017-01-09 07:43:48 +0100 | [diff] [blame] | 403 | session = VppBFDUDPSession( |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 404 | self, |
Abdel Baig | 17a9181 | 2024-09-03 11:52:20 -0400 | [diff] [blame] | 405 | self.interface0, |
| 406 | self.dst_ip_net, |
| 407 | local_addr=self.src_ip_net, |
| 408 | multihop=self.multihop, |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 409 | sha1_key=self.factory.create_random_key(self), |
| 410 | ) |
Abdel Baig | 17a9181 | 2024-09-03 11:52:20 -0400 | [diff] [blame] | 411 | self.session = VppBFDUDPSession( |
| 412 | self, |
| 413 | self.interface0, |
| 414 | self.dst_ip_net, |
| 415 | local_addr=self.src_ip_net, |
| 416 | multihop=self.multihop, |
| 417 | ) |
Klement Sekera | b17dd96 | 2017-01-09 07:43:48 +0100 | [diff] [blame] | 418 | with self.assertRaises(Exception): |
| 419 | session.add_vpp_config() |
| 420 | |
| 421 | def test_shared_sha1_key(self): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 422 | """single SHA1 key shared by multiple BFD sessions""" |
Klement Sekera | b17dd96 | 2017-01-09 07:43:48 +0100 | [diff] [blame] | 423 | key = self.factory.create_random_key(self) |
| 424 | key.add_vpp_config() |
| 425 | sessions = [ |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 426 | VppBFDUDPSession( |
Abdel Baig | 17a9181 | 2024-09-03 11:52:20 -0400 | [diff] [blame] | 427 | self, |
| 428 | self.interface0, |
| 429 | self.dst_ip_net, |
| 430 | local_addr=self.src_ip_net, |
| 431 | multihop=self.multihop, |
| 432 | sha1_key=key, |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 433 | ), |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 434 | VppBFDUDPSession( |
Abdel Baig | 17a9181 | 2024-09-03 11:52:20 -0400 | [diff] [blame] | 435 | self, |
| 436 | self.interface0, |
| 437 | self.dst_ip6_net, |
| 438 | local_addr=self.src_ip6_net, |
| 439 | af=AF_INET6, |
| 440 | multihop=self.multihop, |
| 441 | sha1_key=key, |
| 442 | ), |
| 443 | VppBFDUDPSession( |
| 444 | self, |
| 445 | self.interface1, |
| 446 | self.dst_ip_net2, |
| 447 | local_addr=self.src_ip_net2, |
| 448 | multihop=self.multihop, |
| 449 | sha1_key=key, |
| 450 | ), |
| 451 | VppBFDUDPSession( |
| 452 | self, |
| 453 | self.interface1, |
| 454 | self.dst_ip6_net2, |
| 455 | local_addr=self.src_ip6_net2, |
| 456 | af=AF_INET6, |
| 457 | multihop=self.multihop, |
| 458 | sha1_key=key, |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 459 | ), |
| 460 | ] |
Klement Sekera | b17dd96 | 2017-01-09 07:43:48 +0100 | [diff] [blame] | 461 | for s in sessions: |
| 462 | s.add_vpp_config() |
| 463 | removed = 0 |
| 464 | for s in sessions: |
| 465 | e = key.get_bfd_auth_keys_dump_entry() |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 466 | self.assert_equal( |
| 467 | e.use_count, len(sessions) - removed, "Use count for shared key" |
| 468 | ) |
Klement Sekera | b17dd96 | 2017-01-09 07:43:48 +0100 | [diff] [blame] | 469 | s.remove_vpp_config() |
| 470 | removed += 1 |
| 471 | e = key.get_bfd_auth_keys_dump_entry() |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 472 | self.assert_equal( |
| 473 | e.use_count, len(sessions) - removed, "Use count for shared key" |
| 474 | ) |
Klement Sekera | b17dd96 | 2017-01-09 07:43:48 +0100 | [diff] [blame] | 475 | |
| 476 | def test_activate_auth(self): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 477 | """activate SHA1 authentication""" |
Klement Sekera | b17dd96 | 2017-01-09 07:43:48 +0100 | [diff] [blame] | 478 | key = self.factory.create_random_key(self) |
| 479 | key.add_vpp_config() |
Abdel Baig | 17a9181 | 2024-09-03 11:52:20 -0400 | [diff] [blame] | 480 | session = VppBFDUDPSession( |
| 481 | self, |
| 482 | self.interface0, |
| 483 | self.dst_ip_net, |
| 484 | local_addr=self.src_ip_net, |
| 485 | multihop=self.multihop, |
| 486 | ) |
Klement Sekera | b17dd96 | 2017-01-09 07:43:48 +0100 | [diff] [blame] | 487 | session.add_vpp_config() |
| 488 | session.activate_auth(key) |
| 489 | |
| 490 | def test_deactivate_auth(self): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 491 | """deactivate SHA1 authentication""" |
Klement Sekera | b17dd96 | 2017-01-09 07:43:48 +0100 | [diff] [blame] | 492 | key = self.factory.create_random_key(self) |
| 493 | key.add_vpp_config() |
Abdel Baig | 17a9181 | 2024-09-03 11:52:20 -0400 | [diff] [blame] | 494 | session = VppBFDUDPSession( |
| 495 | self, |
| 496 | self.interface0, |
| 497 | self.dst_ip_net, |
| 498 | local_addr=self.src_ip_net, |
| 499 | multihop=self.multihop, |
| 500 | ) |
Klement Sekera | b17dd96 | 2017-01-09 07:43:48 +0100 | [diff] [blame] | 501 | session.add_vpp_config() |
| 502 | session.activate_auth(key) |
| 503 | session.deactivate_auth() |
| 504 | |
| 505 | def test_change_key(self): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 506 | """change SHA1 key""" |
Klement Sekera | b17dd96 | 2017-01-09 07:43:48 +0100 | [diff] [blame] | 507 | key1 = self.factory.create_random_key(self) |
| 508 | key2 = self.factory.create_random_key(self) |
| 509 | while key2.conf_key_id == key1.conf_key_id: |
| 510 | key2 = self.factory.create_random_key(self) |
| 511 | key1.add_vpp_config() |
| 512 | key2.add_vpp_config() |
Abdel Baig | 17a9181 | 2024-09-03 11:52:20 -0400 | [diff] [blame] | 513 | session = VppBFDUDPSession( |
| 514 | self, |
| 515 | self.interface0, |
| 516 | self.dst_ip_net, |
| 517 | local_addr=self.src_ip_net, |
| 518 | multihop=self.multihop, |
| 519 | sha1_key=key1, |
| 520 | ) |
Klement Sekera | b17dd96 | 2017-01-09 07:43:48 +0100 | [diff] [blame] | 521 | session.add_vpp_config() |
| 522 | session.activate_auth(key2) |
Klement Sekera | 10db26f | 2017-01-11 08:16:53 +0100 | [diff] [blame] | 523 | |
Matus Fabian | 2d3c7b9 | 2018-10-02 03:22:18 -0700 | [diff] [blame] | 524 | def test_set_del_udp_echo_source(self): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 525 | """set/del udp echo source""" |
Abdel Baig | 17a9181 | 2024-09-03 11:52:20 -0400 | [diff] [blame] | 526 | |
| 527 | if self.multihop: |
| 528 | self.skipTest( |
| 529 | f"Skipping because echo functionality is not supported with multihop" |
| 530 | ) |
| 531 | |
Matus Fabian | 2d3c7b9 | 2018-10-02 03:22:18 -0700 | [diff] [blame] | 532 | self.create_loopback_interfaces(1) |
| 533 | self.loopback0 = self.lo_interfaces[0] |
| 534 | self.loopback0.admin_up() |
| 535 | echo_source = self.vapi.bfd_udp_get_echo_source() |
| 536 | self.assertFalse(echo_source.is_set) |
| 537 | self.assertFalse(echo_source.have_usable_ip4) |
| 538 | self.assertFalse(echo_source.have_usable_ip6) |
| 539 | |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 540 | self.vapi.bfd_udp_set_echo_source(sw_if_index=self.loopback0.sw_if_index) |
Matus Fabian | 2d3c7b9 | 2018-10-02 03:22:18 -0700 | [diff] [blame] | 541 | echo_source = self.vapi.bfd_udp_get_echo_source() |
| 542 | self.assertTrue(echo_source.is_set) |
| 543 | self.assertEqual(echo_source.sw_if_index, self.loopback0.sw_if_index) |
| 544 | self.assertFalse(echo_source.have_usable_ip4) |
| 545 | self.assertFalse(echo_source.have_usable_ip6) |
| 546 | |
| 547 | self.loopback0.config_ip4() |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 548 | echo_ip4 = ipaddress.IPv4Address( |
| 549 | int(ipaddress.IPv4Address(self.loopback0.local_ip4)) ^ 1 |
| 550 | ).packed |
Matus Fabian | 2d3c7b9 | 2018-10-02 03:22:18 -0700 | [diff] [blame] | 551 | echo_source = self.vapi.bfd_udp_get_echo_source() |
| 552 | self.assertTrue(echo_source.is_set) |
| 553 | self.assertEqual(echo_source.sw_if_index, self.loopback0.sw_if_index) |
| 554 | self.assertTrue(echo_source.have_usable_ip4) |
Jakub Grajciar | 4682feb | 2019-09-02 13:28:52 +0200 | [diff] [blame] | 555 | self.assertEqual(echo_source.ip4_addr.packed, echo_ip4) |
Matus Fabian | 2d3c7b9 | 2018-10-02 03:22:18 -0700 | [diff] [blame] | 556 | self.assertFalse(echo_source.have_usable_ip6) |
| 557 | |
| 558 | self.loopback0.config_ip6() |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 559 | echo_ip6 = ipaddress.IPv6Address( |
| 560 | int(ipaddress.IPv6Address(self.loopback0.local_ip6)) ^ 1 |
| 561 | ).packed |
Paul Vinciguerra | 2f15631 | 2020-05-02 22:34:40 -0400 | [diff] [blame] | 562 | |
Matus Fabian | 2d3c7b9 | 2018-10-02 03:22:18 -0700 | [diff] [blame] | 563 | echo_source = self.vapi.bfd_udp_get_echo_source() |
| 564 | self.assertTrue(echo_source.is_set) |
| 565 | self.assertEqual(echo_source.sw_if_index, self.loopback0.sw_if_index) |
| 566 | self.assertTrue(echo_source.have_usable_ip4) |
Jakub Grajciar | 4682feb | 2019-09-02 13:28:52 +0200 | [diff] [blame] | 567 | self.assertEqual(echo_source.ip4_addr.packed, echo_ip4) |
Matus Fabian | 2d3c7b9 | 2018-10-02 03:22:18 -0700 | [diff] [blame] | 568 | self.assertTrue(echo_source.have_usable_ip6) |
Jakub Grajciar | 4682feb | 2019-09-02 13:28:52 +0200 | [diff] [blame] | 569 | self.assertEqual(echo_source.ip6_addr.packed, echo_ip6) |
Matus Fabian | 2d3c7b9 | 2018-10-02 03:22:18 -0700 | [diff] [blame] | 570 | |
| 571 | self.vapi.bfd_udp_del_echo_source() |
| 572 | echo_source = self.vapi.bfd_udp_get_echo_source() |
| 573 | self.assertFalse(echo_source.is_set) |
| 574 | self.assertFalse(echo_source.have_usable_ip4) |
| 575 | self.assertFalse(echo_source.have_usable_ip6) |
| 576 | |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 577 | |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 578 | class BFDTestSession(object): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 579 | """BFD session as seen from test framework side""" |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 580 | |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 581 | def __init__( |
| 582 | self, |
| 583 | test, |
| 584 | interface, |
| 585 | af, |
| 586 | detect_mult=3, |
| 587 | sha1_key=None, |
| 588 | bfd_key_id=None, |
| 589 | our_seq_number=None, |
| 590 | tunnel_header=None, |
| 591 | phy_interface=None, |
Abdel Baig | 17a9181 | 2024-09-03 11:52:20 -0400 | [diff] [blame] | 592 | multihop=False, |
| 593 | local_addr=None, |
| 594 | peer_addr=None, |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 595 | ): |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 596 | self.test = test |
Klement Sekera | 46a87ad | 2017-01-02 08:22:23 +0100 | [diff] [blame] | 597 | self.af = af |
Klement Sekera | b17dd96 | 2017-01-09 07:43:48 +0100 | [diff] [blame] | 598 | self.sha1_key = sha1_key |
| 599 | self.bfd_key_id = bfd_key_id |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 600 | self.interface = interface |
Neale Ranns | 52cd496 | 2019-06-05 10:28:17 +0000 | [diff] [blame] | 601 | if phy_interface: |
| 602 | self.phy_interface = phy_interface |
| 603 | else: |
| 604 | self.phy_interface = self.interface |
Klement Sekera | d3ba515 | 2017-02-14 03:09:17 +0100 | [diff] [blame] | 605 | self.udp_sport = randint(49152, 65535) |
| 606 | if our_seq_number is None: |
| 607 | self.our_seq_number = randint(0, 40000000) |
| 608 | else: |
| 609 | self.our_seq_number = our_seq_number |
Klement Sekera | b17dd96 | 2017-01-09 07:43:48 +0100 | [diff] [blame] | 610 | self.vpp_seq_number = None |
Klement Sekera | d3ba515 | 2017-02-14 03:09:17 +0100 | [diff] [blame] | 611 | self.my_discriminator = 0 |
Klement Sekera | 2e01dfa | 2017-04-03 08:10:08 +0200 | [diff] [blame] | 612 | self.desired_min_tx = 300000 |
| 613 | self.required_min_rx = 300000 |
Klement Sekera | 239790f | 2017-02-16 10:53:53 +0100 | [diff] [blame] | 614 | self.required_min_echo_rx = None |
Klement Sekera | d3ba515 | 2017-02-14 03:09:17 +0100 | [diff] [blame] | 615 | self.detect_mult = detect_mult |
| 616 | self.diag = BFDDiagCode.no_diagnostic |
| 617 | self.your_discriminator = None |
| 618 | self.state = BFDState.down |
| 619 | self.auth_type = BFDAuthType.no_auth |
Neale Ranns | 52cd496 | 2019-06-05 10:28:17 +0000 | [diff] [blame] | 620 | self.tunnel_header = tunnel_header |
Klement Sekera | cdaf0d8 | 2022-02-14 20:20:22 +0000 | [diff] [blame] | 621 | self.tx_packets = 0 |
| 622 | self.rx_packets = 0 |
| 623 | self.tx_packets_echo = 0 |
| 624 | self.rx_packets_echo = 0 |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 625 | |
Abdel Baig | 17a9181 | 2024-09-03 11:52:20 -0400 | [diff] [blame] | 626 | if multihop: |
| 627 | self.sw_if_index = 0 |
| 628 | BFD.udp_dport = BFD_UDP_MH_PORT |
| 629 | else: |
| 630 | BFD.udp_dport = BFD_UDP_SH_PORT |
| 631 | self.sw_if_index = self.interface.sw_if_index |
| 632 | |
| 633 | if local_addr: |
| 634 | self.local_addr = local_addr |
| 635 | else: |
| 636 | if self.af == AF_INET: |
| 637 | self.local_addr = self.interface.local_ip4 |
| 638 | else: |
| 639 | self.local_addr = self.interface.local_ip6 |
| 640 | |
| 641 | if peer_addr: |
| 642 | self.peer_addr = peer_addr |
| 643 | else: |
| 644 | if self.af == AF_INET: |
| 645 | self.peer_addr = self.interface.remote_ip4 |
| 646 | else: |
| 647 | self.peer_addr = self.interface.remote_ip6 |
| 648 | |
Klement Sekera | b17dd96 | 2017-01-09 07:43:48 +0100 | [diff] [blame] | 649 | def inc_seq_num(self): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 650 | """increment sequence number, wrapping if needed""" |
Klement Sekera | b17dd96 | 2017-01-09 07:43:48 +0100 | [diff] [blame] | 651 | if self.our_seq_number == 0xFFFFFFFF: |
| 652 | self.our_seq_number = 0 |
| 653 | else: |
| 654 | self.our_seq_number += 1 |
| 655 | |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 656 | def update( |
| 657 | self, |
| 658 | my_discriminator=None, |
| 659 | your_discriminator=None, |
| 660 | desired_min_tx=None, |
| 661 | required_min_rx=None, |
| 662 | required_min_echo_rx=None, |
| 663 | detect_mult=None, |
| 664 | diag=None, |
| 665 | state=None, |
| 666 | auth_type=None, |
| 667 | ): |
| 668 | """update BFD parameters associated with session""" |
Klement Sekera | 239790f | 2017-02-16 10:53:53 +0100 | [diff] [blame] | 669 | if my_discriminator is not None: |
Klement Sekera | d3ba515 | 2017-02-14 03:09:17 +0100 | [diff] [blame] | 670 | self.my_discriminator = my_discriminator |
Klement Sekera | 239790f | 2017-02-16 10:53:53 +0100 | [diff] [blame] | 671 | if your_discriminator is not None: |
Klement Sekera | d3ba515 | 2017-02-14 03:09:17 +0100 | [diff] [blame] | 672 | self.your_discriminator = your_discriminator |
Klement Sekera | 239790f | 2017-02-16 10:53:53 +0100 | [diff] [blame] | 673 | if required_min_rx is not None: |
Klement Sekera | d3ba515 | 2017-02-14 03:09:17 +0100 | [diff] [blame] | 674 | self.required_min_rx = required_min_rx |
Klement Sekera | 239790f | 2017-02-16 10:53:53 +0100 | [diff] [blame] | 675 | if required_min_echo_rx is not None: |
| 676 | self.required_min_echo_rx = required_min_echo_rx |
| 677 | if desired_min_tx is not None: |
Klement Sekera | d3ba515 | 2017-02-14 03:09:17 +0100 | [diff] [blame] | 678 | self.desired_min_tx = desired_min_tx |
Klement Sekera | 239790f | 2017-02-16 10:53:53 +0100 | [diff] [blame] | 679 | if detect_mult is not None: |
Klement Sekera | d3ba515 | 2017-02-14 03:09:17 +0100 | [diff] [blame] | 680 | self.detect_mult = detect_mult |
Klement Sekera | 239790f | 2017-02-16 10:53:53 +0100 | [diff] [blame] | 681 | if diag is not None: |
Klement Sekera | d3ba515 | 2017-02-14 03:09:17 +0100 | [diff] [blame] | 682 | self.diag = diag |
Klement Sekera | 239790f | 2017-02-16 10:53:53 +0100 | [diff] [blame] | 683 | if state is not None: |
Klement Sekera | d3ba515 | 2017-02-14 03:09:17 +0100 | [diff] [blame] | 684 | self.state = state |
Klement Sekera | 239790f | 2017-02-16 10:53:53 +0100 | [diff] [blame] | 685 | if auth_type is not None: |
Klement Sekera | d3ba515 | 2017-02-14 03:09:17 +0100 | [diff] [blame] | 686 | self.auth_type = auth_type |
| 687 | |
| 688 | def fill_packet_fields(self, packet): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 689 | """set packet fields with known values in packet""" |
Klement Sekera | d3ba515 | 2017-02-14 03:09:17 +0100 | [diff] [blame] | 690 | bfd = packet[BFD] |
| 691 | if self.my_discriminator: |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 692 | self.test.logger.debug( |
| 693 | "BFD: setting packet.my_discriminator=%s", self.my_discriminator |
| 694 | ) |
Klement Sekera | d3ba515 | 2017-02-14 03:09:17 +0100 | [diff] [blame] | 695 | bfd.my_discriminator = self.my_discriminator |
| 696 | if self.your_discriminator: |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 697 | self.test.logger.debug( |
| 698 | "BFD: setting packet.your_discriminator=%s", self.your_discriminator |
| 699 | ) |
Klement Sekera | d3ba515 | 2017-02-14 03:09:17 +0100 | [diff] [blame] | 700 | bfd.your_discriminator = self.your_discriminator |
| 701 | if self.required_min_rx: |
| 702 | self.test.logger.debug( |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 703 | "BFD: setting packet.required_min_rx_interval=%s", self.required_min_rx |
| 704 | ) |
Klement Sekera | d3ba515 | 2017-02-14 03:09:17 +0100 | [diff] [blame] | 705 | bfd.required_min_rx_interval = self.required_min_rx |
Klement Sekera | 239790f | 2017-02-16 10:53:53 +0100 | [diff] [blame] | 706 | if self.required_min_echo_rx: |
| 707 | self.test.logger.debug( |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 708 | "BFD: setting packet.required_min_echo_rx=%s", self.required_min_echo_rx |
| 709 | ) |
Klement Sekera | 239790f | 2017-02-16 10:53:53 +0100 | [diff] [blame] | 710 | bfd.required_min_echo_rx_interval = self.required_min_echo_rx |
Klement Sekera | d3ba515 | 2017-02-14 03:09:17 +0100 | [diff] [blame] | 711 | if self.desired_min_tx: |
| 712 | self.test.logger.debug( |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 713 | "BFD: setting packet.desired_min_tx_interval=%s", self.desired_min_tx |
| 714 | ) |
Klement Sekera | d3ba515 | 2017-02-14 03:09:17 +0100 | [diff] [blame] | 715 | bfd.desired_min_tx_interval = self.desired_min_tx |
| 716 | if self.detect_mult: |
| 717 | self.test.logger.debug( |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 718 | "BFD: setting packet.detect_mult=%s", self.detect_mult |
| 719 | ) |
Klement Sekera | d3ba515 | 2017-02-14 03:09:17 +0100 | [diff] [blame] | 720 | bfd.detect_mult = self.detect_mult |
| 721 | if self.diag: |
| 722 | self.test.logger.debug("BFD: setting packet.diag=%s", self.diag) |
| 723 | bfd.diag = self.diag |
| 724 | if self.state: |
| 725 | self.test.logger.debug("BFD: setting packet.state=%s", self.state) |
| 726 | bfd.state = self.state |
| 727 | if self.auth_type: |
| 728 | # this is used by a negative test-case |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 729 | self.test.logger.debug("BFD: setting packet.auth_type=%s", self.auth_type) |
Klement Sekera | d3ba515 | 2017-02-14 03:09:17 +0100 | [diff] [blame] | 730 | bfd.auth_type = self.auth_type |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 731 | |
| 732 | def create_packet(self): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 733 | """create a BFD packet, reflecting the current state of session""" |
Klement Sekera | b17dd96 | 2017-01-09 07:43:48 +0100 | [diff] [blame] | 734 | if self.sha1_key: |
| 735 | bfd = BFD(flags="A") |
| 736 | bfd.auth_type = self.sha1_key.auth_type |
| 737 | bfd.auth_len = BFD.sha1_auth_len |
| 738 | bfd.auth_key_id = self.bfd_key_id |
| 739 | bfd.auth_seq_num = self.our_seq_number |
| 740 | bfd.length = BFD.sha1_auth_len + BFD.bfd_pkt_len |
| 741 | else: |
| 742 | bfd = BFD() |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 743 | packet = Ether( |
| 744 | src=self.phy_interface.remote_mac, dst=self.phy_interface.local_mac |
| 745 | ) |
Neale Ranns | 52cd496 | 2019-06-05 10:28:17 +0000 | [diff] [blame] | 746 | if self.tunnel_header: |
| 747 | packet = packet / self.tunnel_header |
Klement Sekera | 46a87ad | 2017-01-02 08:22:23 +0100 | [diff] [blame] | 748 | if self.af == AF_INET6: |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 749 | packet = ( |
| 750 | packet |
| 751 | / IPv6( |
Abdel Baig | 17a9181 | 2024-09-03 11:52:20 -0400 | [diff] [blame] | 752 | src=self.peer_addr, |
| 753 | dst=self.local_addr, |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 754 | hlim=255, |
| 755 | ) |
| 756 | / UDP(sport=self.udp_sport, dport=BFD.udp_dport) |
| 757 | / bfd |
| 758 | ) |
Klement Sekera | 46a87ad | 2017-01-02 08:22:23 +0100 | [diff] [blame] | 759 | else: |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 760 | packet = ( |
| 761 | packet |
Abdel Baig | 17a9181 | 2024-09-03 11:52:20 -0400 | [diff] [blame] | 762 | / IP(src=self.peer_addr, dst=self.local_addr, ttl=255) |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 763 | / UDP(sport=self.udp_sport, dport=BFD.udp_dport) |
| 764 | / bfd |
| 765 | ) |
Klement Sekera | 3e0a356 | 2016-12-19 09:05:21 +0100 | [diff] [blame] | 766 | self.test.logger.debug("BFD: Creating packet") |
Klement Sekera | d3ba515 | 2017-02-14 03:09:17 +0100 | [diff] [blame] | 767 | self.fill_packet_fields(packet) |
Klement Sekera | b17dd96 | 2017-01-09 07:43:48 +0100 | [diff] [blame] | 768 | if self.sha1_key: |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 769 | hash_material = ( |
| 770 | scapy.compat.raw(packet[BFD])[:32] |
| 771 | + self.sha1_key.key |
| 772 | + b"\0" * (20 - len(self.sha1_key.key)) |
| 773 | ) |
| 774 | self.test.logger.debug( |
| 775 | "BFD: Calculated SHA1 hash: %s" |
| 776 | % hashlib.sha1(hash_material).hexdigest() |
| 777 | ) |
Klement Sekera | b17dd96 | 2017-01-09 07:43:48 +0100 | [diff] [blame] | 778 | packet[BFD].auth_key_hash = hashlib.sha1(hash_material).digest() |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 779 | return packet |
| 780 | |
Klement Sekera | d3ba515 | 2017-02-14 03:09:17 +0100 | [diff] [blame] | 781 | def send_packet(self, packet=None, interface=None): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 782 | """send packet on interface, creating the packet if needed""" |
Klement Sekera | a57a970 | 2017-02-02 06:58:07 +0100 | [diff] [blame] | 783 | if packet is None: |
| 784 | packet = self.create_packet() |
Klement Sekera | d3ba515 | 2017-02-14 03:09:17 +0100 | [diff] [blame] | 785 | if interface is None: |
Neale Ranns | 52cd496 | 2019-06-05 10:28:17 +0000 | [diff] [blame] | 786 | interface = self.phy_interface |
Klement Sekera | a57a970 | 2017-02-02 06:58:07 +0100 | [diff] [blame] | 787 | self.test.logger.debug(ppp("Sending packet:", packet)) |
Klement Sekera | d3ba515 | 2017-02-14 03:09:17 +0100 | [diff] [blame] | 788 | interface.add_stream(packet) |
Klement Sekera | cdaf0d8 | 2022-02-14 20:20:22 +0000 | [diff] [blame] | 789 | self.tx_packets += 1 |
Klement Sekera | 9225dee | 2016-12-12 08:36:58 +0100 | [diff] [blame] | 790 | self.test.pg_start() |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 791 | |
Klement Sekera | b17dd96 | 2017-01-09 07:43:48 +0100 | [diff] [blame] | 792 | def verify_sha1_auth(self, packet): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 793 | """Verify correctness of authentication in BFD layer.""" |
Klement Sekera | b17dd96 | 2017-01-09 07:43:48 +0100 | [diff] [blame] | 794 | bfd = packet[BFD] |
| 795 | self.test.assert_equal(bfd.auth_len, 28, "Auth section length") |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 796 | self.test.assert_equal(bfd.auth_type, self.sha1_key.auth_type, BFDAuthType) |
Klement Sekera | b17dd96 | 2017-01-09 07:43:48 +0100 | [diff] [blame] | 797 | self.test.assert_equal(bfd.auth_key_id, self.bfd_key_id, "Key ID") |
| 798 | self.test.assert_equal(bfd.auth_reserved, 0, "Reserved") |
| 799 | if self.vpp_seq_number is None: |
| 800 | self.vpp_seq_number = bfd.auth_seq_num |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 801 | self.test.logger.debug( |
| 802 | "Received initial sequence number: %s" % self.vpp_seq_number |
| 803 | ) |
Klement Sekera | b17dd96 | 2017-01-09 07:43:48 +0100 | [diff] [blame] | 804 | else: |
| 805 | recvd_seq_num = bfd.auth_seq_num |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 806 | self.test.logger.debug( |
| 807 | "Received followup sequence number: %s" % recvd_seq_num |
| 808 | ) |
| 809 | if self.vpp_seq_number < 0xFFFFFFFF: |
| 810 | if self.sha1_key.auth_type == BFDAuthType.meticulous_keyed_sha1: |
| 811 | self.test.assert_equal( |
| 812 | recvd_seq_num, self.vpp_seq_number + 1, "BFD sequence number" |
| 813 | ) |
Klement Sekera | b17dd96 | 2017-01-09 07:43:48 +0100 | [diff] [blame] | 814 | else: |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 815 | self.test.assert_in_range( |
| 816 | recvd_seq_num, |
| 817 | self.vpp_seq_number, |
| 818 | self.vpp_seq_number + 1, |
| 819 | "BFD sequence number", |
| 820 | ) |
Klement Sekera | b17dd96 | 2017-01-09 07:43:48 +0100 | [diff] [blame] | 821 | else: |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 822 | if self.sha1_key.auth_type == BFDAuthType.meticulous_keyed_sha1: |
| 823 | self.test.assert_equal(recvd_seq_num, 0, "BFD sequence number") |
Klement Sekera | b17dd96 | 2017-01-09 07:43:48 +0100 | [diff] [blame] | 824 | else: |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 825 | self.test.assertIn( |
| 826 | recvd_seq_num, |
| 827 | (self.vpp_seq_number, 0), |
| 828 | "BFD sequence number not one of " |
| 829 | "(%s, 0)" % self.vpp_seq_number, |
| 830 | ) |
Klement Sekera | b17dd96 | 2017-01-09 07:43:48 +0100 | [diff] [blame] | 831 | self.vpp_seq_number = recvd_seq_num |
| 832 | # last 20 bytes represent the hash - so replace them with the key, |
| 833 | # pad the result with zeros and hash the result |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 834 | hash_material = ( |
| 835 | bfd.original[:-20] |
| 836 | + self.sha1_key.key |
| 837 | + b"\0" * (20 - len(self.sha1_key.key)) |
| 838 | ) |
Klement Sekera | b17dd96 | 2017-01-09 07:43:48 +0100 | [diff] [blame] | 839 | expected_hash = hashlib.sha1(hash_material).hexdigest() |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 840 | self.test.assert_equal( |
| 841 | binascii.hexlify(bfd.auth_key_hash), expected_hash.encode(), "Auth key hash" |
| 842 | ) |
Klement Sekera | b17dd96 | 2017-01-09 07:43:48 +0100 | [diff] [blame] | 843 | |
| 844 | def verify_bfd(self, packet): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 845 | """Verify correctness of BFD layer.""" |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 846 | bfd = packet[BFD] |
| 847 | self.test.assert_equal(bfd.version, 1, "BFD version") |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 848 | self.test.assert_equal( |
| 849 | bfd.your_discriminator, self.my_discriminator, "BFD - your discriminator" |
| 850 | ) |
Klement Sekera | b17dd96 | 2017-01-09 07:43:48 +0100 | [diff] [blame] | 851 | if self.sha1_key: |
| 852 | self.verify_sha1_auth(packet) |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 853 | |
| 854 | |
Klement Sekera | d3ba515 | 2017-02-14 03:09:17 +0100 | [diff] [blame] | 855 | def bfd_session_up(test): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 856 | """Bring BFD session up""" |
Klement Sekera | d3ba515 | 2017-02-14 03:09:17 +0100 | [diff] [blame] | 857 | test.logger.info("BFD: Waiting for slow hello") |
Neale Ranns | 52cd496 | 2019-06-05 10:28:17 +0000 | [diff] [blame] | 858 | p = wait_for_bfd_packet(test, 2, is_tunnel=test.vpp_session.is_tunnel) |
Klement Sekera | d3ba515 | 2017-02-14 03:09:17 +0100 | [diff] [blame] | 859 | old_offset = None |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 860 | if hasattr(test, "vpp_clock_offset"): |
Klement Sekera | d3ba515 | 2017-02-14 03:09:17 +0100 | [diff] [blame] | 861 | old_offset = test.vpp_clock_offset |
snaramre | 73aff47 | 2019-12-02 05:49:28 +0000 | [diff] [blame] | 862 | test.vpp_clock_offset = time.time() - float(p.time) |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 863 | test.logger.debug("BFD: Calculated vpp clock offset: %s", test.vpp_clock_offset) |
Klement Sekera | d3ba515 | 2017-02-14 03:09:17 +0100 | [diff] [blame] | 864 | if old_offset: |
| 865 | test.assertAlmostEqual( |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 866 | old_offset, |
| 867 | test.vpp_clock_offset, |
| 868 | delta=0.5, |
| 869 | msg="vpp clock offset not stable (new: %s, old: %s)" |
| 870 | % (test.vpp_clock_offset, old_offset), |
| 871 | ) |
Klement Sekera | d3ba515 | 2017-02-14 03:09:17 +0100 | [diff] [blame] | 872 | test.logger.info("BFD: Sending Init") |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 873 | test.test_session.update( |
| 874 | my_discriminator=randint(0, 40000000), |
| 875 | your_discriminator=p[BFD].my_discriminator, |
| 876 | state=BFDState.init, |
| 877 | ) |
| 878 | if ( |
| 879 | test.test_session.sha1_key |
| 880 | and test.test_session.sha1_key.auth_type == BFDAuthType.meticulous_keyed_sha1 |
| 881 | ): |
Klement Sekera | 7388448 | 2017-02-23 09:26:30 +0100 | [diff] [blame] | 882 | test.test_session.inc_seq_num() |
Klement Sekera | d3ba515 | 2017-02-14 03:09:17 +0100 | [diff] [blame] | 883 | test.test_session.send_packet() |
| 884 | test.logger.info("BFD: Waiting for event") |
Ole Troan | 4376ab2 | 2021-03-03 10:40:05 +0100 | [diff] [blame] | 885 | e = test.vapi.wait_for_event(1, "bfd_udp_session_event") |
Klement Sekera | d3ba515 | 2017-02-14 03:09:17 +0100 | [diff] [blame] | 886 | verify_event(test, e, expected_state=BFDState.up) |
| 887 | test.logger.info("BFD: Session is Up") |
| 888 | test.test_session.update(state=BFDState.up) |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 889 | if ( |
| 890 | test.test_session.sha1_key |
| 891 | and test.test_session.sha1_key.auth_type == BFDAuthType.meticulous_keyed_sha1 |
| 892 | ): |
Klement Sekera | 7388448 | 2017-02-23 09:26:30 +0100 | [diff] [blame] | 893 | test.test_session.inc_seq_num() |
Klement Sekera | d3ba515 | 2017-02-14 03:09:17 +0100 | [diff] [blame] | 894 | test.test_session.send_packet() |
| 895 | test.assert_equal(test.vpp_session.state, BFDState.up, BFDState) |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 896 | |
Klement Sekera | 46a87ad | 2017-01-02 08:22:23 +0100 | [diff] [blame] | 897 | |
Klement Sekera | d3ba515 | 2017-02-14 03:09:17 +0100 | [diff] [blame] | 898 | def bfd_session_down(test): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 899 | """Bring BFD session down""" |
Klement Sekera | d3ba515 | 2017-02-14 03:09:17 +0100 | [diff] [blame] | 900 | test.assert_equal(test.vpp_session.state, BFDState.up, BFDState) |
| 901 | test.test_session.update(state=BFDState.down) |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 902 | if ( |
| 903 | test.test_session.sha1_key |
| 904 | and test.test_session.sha1_key.auth_type == BFDAuthType.meticulous_keyed_sha1 |
| 905 | ): |
Klement Sekera | 7388448 | 2017-02-23 09:26:30 +0100 | [diff] [blame] | 906 | test.test_session.inc_seq_num() |
Klement Sekera | d3ba515 | 2017-02-14 03:09:17 +0100 | [diff] [blame] | 907 | test.test_session.send_packet() |
| 908 | test.logger.info("BFD: Waiting for event") |
Ole Troan | 4376ab2 | 2021-03-03 10:40:05 +0100 | [diff] [blame] | 909 | e = test.vapi.wait_for_event(1, "bfd_udp_session_event") |
Klement Sekera | d3ba515 | 2017-02-14 03:09:17 +0100 | [diff] [blame] | 910 | verify_event(test, e, expected_state=BFDState.down) |
| 911 | test.logger.info("BFD: Session is Down") |
| 912 | test.assert_equal(test.vpp_session.state, BFDState.down, BFDState) |
Klement Sekera | b17dd96 | 2017-01-09 07:43:48 +0100 | [diff] [blame] | 913 | |
Klement Sekera | 46a87ad | 2017-01-02 08:22:23 +0100 | [diff] [blame] | 914 | |
Klement Sekera | 7388448 | 2017-02-23 09:26:30 +0100 | [diff] [blame] | 915 | def verify_bfd_session_config(test, session, state=None): |
| 916 | dump = session.get_bfd_udp_session_dump_entry() |
| 917 | test.assertIsNotNone(dump) |
| 918 | # since dump is not none, we have verified that sw_if_index and addresses |
| 919 | # are valid (in get_bfd_udp_session_dump_entry) |
| 920 | if state: |
| 921 | test.assert_equal(dump.state, state, "session state") |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 922 | test.assert_equal( |
| 923 | dump.required_min_rx, session.required_min_rx, "required min rx interval" |
| 924 | ) |
| 925 | test.assert_equal( |
| 926 | dump.desired_min_tx, session.desired_min_tx, "desired min tx interval" |
| 927 | ) |
| 928 | test.assert_equal(dump.detect_mult, session.detect_mult, "detect multiplier") |
Klement Sekera | 7388448 | 2017-02-23 09:26:30 +0100 | [diff] [blame] | 929 | if session.sha1_key is None: |
| 930 | test.assert_equal(dump.is_authenticated, 0, "is_authenticated flag") |
| 931 | else: |
| 932 | test.assert_equal(dump.is_authenticated, 1, "is_authenticated flag") |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 933 | test.assert_equal(dump.bfd_key_id, session.bfd_key_id, "bfd key id") |
| 934 | test.assert_equal( |
| 935 | dump.conf_key_id, session.sha1_key.conf_key_id, "config key id" |
| 936 | ) |
Klement Sekera | 7388448 | 2017-02-23 09:26:30 +0100 | [diff] [blame] | 937 | |
| 938 | |
Klement Sekera | d3ba515 | 2017-02-14 03:09:17 +0100 | [diff] [blame] | 939 | def verify_ip(test, packet): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 940 | """Verify correctness of IP layer.""" |
Klement Sekera | d3ba515 | 2017-02-14 03:09:17 +0100 | [diff] [blame] | 941 | if test.vpp_session.af == AF_INET6: |
| 942 | ip = packet[IPv6] |
Abdel Baig | 17a9181 | 2024-09-03 11:52:20 -0400 | [diff] [blame] | 943 | local_ip = test.vpp_session.local_addr |
| 944 | remote_ip = test.vpp_session.peer_addr |
Klement Sekera | d3ba515 | 2017-02-14 03:09:17 +0100 | [diff] [blame] | 945 | test.assert_equal(ip.hlim, 255, "IPv6 hop limit") |
| 946 | else: |
| 947 | ip = packet[IP] |
Abdel Baig | 17a9181 | 2024-09-03 11:52:20 -0400 | [diff] [blame] | 948 | local_ip = test.vpp_session.local_addr |
| 949 | remote_ip = test.vpp_session.peer_addr |
Klement Sekera | d3ba515 | 2017-02-14 03:09:17 +0100 | [diff] [blame] | 950 | test.assert_equal(ip.ttl, 255, "IPv4 TTL") |
| 951 | test.assert_equal(ip.src, local_ip, "IP source address") |
| 952 | test.assert_equal(ip.dst, remote_ip, "IP destination address") |
| 953 | |
| 954 | |
| 955 | def verify_udp(test, packet): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 956 | """Verify correctness of UDP layer.""" |
Klement Sekera | d3ba515 | 2017-02-14 03:09:17 +0100 | [diff] [blame] | 957 | udp = packet[UDP] |
| 958 | test.assert_equal(udp.dport, BFD.udp_dport, "UDP destination port") |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 959 | test.assert_in_range( |
| 960 | udp.sport, BFD.udp_sport_min, BFD.udp_sport_max, "UDP source port" |
| 961 | ) |
Klement Sekera | d3ba515 | 2017-02-14 03:09:17 +0100 | [diff] [blame] | 962 | |
| 963 | |
| 964 | def verify_event(test, event, expected_state): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 965 | """Verify correctness of event values.""" |
Klement Sekera | d3ba515 | 2017-02-14 03:09:17 +0100 | [diff] [blame] | 966 | e = event |
Paul Vinciguerra | 090096b | 2020-12-03 00:42:46 -0500 | [diff] [blame] | 967 | test.logger.debug("BFD: Event: %s" % reprlib.repr(e)) |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 968 | test.assert_equal( |
Abdel Baig | 17a9181 | 2024-09-03 11:52:20 -0400 | [diff] [blame] | 969 | e.sw_if_index, test.vpp_session._sw_if_index, "BFD interface index" |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 970 | ) |
Jakub Grajciar | 4682feb | 2019-09-02 13:28:52 +0200 | [diff] [blame] | 971 | |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 972 | test.assert_equal( |
| 973 | str(e.local_addr), test.vpp_session.local_addr, "Local IPv6 address" |
| 974 | ) |
| 975 | test.assert_equal(str(e.peer_addr), test.vpp_session.peer_addr, "Peer IPv6 address") |
Klement Sekera | d3ba515 | 2017-02-14 03:09:17 +0100 | [diff] [blame] | 976 | test.assert_equal(e.state, expected_state, BFDState) |
| 977 | |
| 978 | |
Neale Ranns | 52cd496 | 2019-06-05 10:28:17 +0000 | [diff] [blame] | 979 | def wait_for_bfd_packet(test, timeout=1, pcap_time_min=None, is_tunnel=False): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 980 | """wait for BFD packet and verify its correctness |
Klement Sekera | d3ba515 | 2017-02-14 03:09:17 +0100 | [diff] [blame] | 981 | |
| 982 | :param timeout: how long to wait |
| 983 | :param pcap_time_min: ignore packets with pcap timestamp lower than this |
| 984 | |
| 985 | :returns: tuple (packet, time spent waiting for packet) |
| 986 | """ |
| 987 | test.logger.info("BFD: Waiting for BFD packet") |
| 988 | deadline = time.time() + timeout |
| 989 | counter = 0 |
| 990 | while True: |
| 991 | counter += 1 |
| 992 | # sanity check |
| 993 | test.assert_in_range(counter, 0, 100, "number of packets ignored") |
| 994 | time_left = deadline - time.time() |
| 995 | if time_left < 0: |
| 996 | raise CaptureTimeoutError("Packet did not arrive within timeout") |
| 997 | p = test.pg0.wait_for_packet(timeout=time_left) |
Klement Sekera | cdaf0d8 | 2022-02-14 20:20:22 +0000 | [diff] [blame] | 998 | test.test_session.rx_packets += 1 |
Klement Sekera | d3ba515 | 2017-02-14 03:09:17 +0100 | [diff] [blame] | 999 | test.logger.debug(ppp("BFD: Got packet:", p)) |
| 1000 | if pcap_time_min is not None and p.time < pcap_time_min: |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 1001 | test.logger.debug( |
| 1002 | ppp( |
| 1003 | "BFD: ignoring packet (pcap time %s < " |
| 1004 | "pcap time min %s):" % (p.time, pcap_time_min), |
| 1005 | p, |
| 1006 | ) |
| 1007 | ) |
Klement Sekera | 46a87ad | 2017-01-02 08:22:23 +0100 | [diff] [blame] | 1008 | else: |
Klement Sekera | d3ba515 | 2017-02-14 03:09:17 +0100 | [diff] [blame] | 1009 | break |
Klement Sekera | 617d429 | 2022-09-20 15:10:10 +0200 | [diff] [blame] | 1010 | test.logger.debug(test.vapi.ppcli("show trace")) |
Neale Ranns | 52cd496 | 2019-06-05 10:28:17 +0000 | [diff] [blame] | 1011 | if is_tunnel: |
| 1012 | # strip an IP layer and move to the next |
| 1013 | p = p[IP].payload |
| 1014 | |
Klement Sekera | d3ba515 | 2017-02-14 03:09:17 +0100 | [diff] [blame] | 1015 | bfd = p[BFD] |
| 1016 | if bfd is None: |
| 1017 | raise Exception(ppp("Unexpected or invalid BFD packet:", p)) |
| 1018 | if bfd.payload: |
| 1019 | raise Exception(ppp("Unexpected payload in BFD packet:", bfd)) |
| 1020 | verify_ip(test, p) |
| 1021 | verify_udp(test, p) |
| 1022 | test.test_session.verify_bfd(p) |
| 1023 | return p |
Klement Sekera | 3e0a356 | 2016-12-19 09:05:21 +0100 | [diff] [blame] | 1024 | |
Klement Sekera | 46a87ad | 2017-01-02 08:22:23 +0100 | [diff] [blame] | 1025 | |
Klement Sekera | cdaf0d8 | 2022-02-14 20:20:22 +0000 | [diff] [blame] | 1026 | BFDStats = namedtuple("BFDStats", "rx rx_echo tx tx_echo") |
| 1027 | |
| 1028 | |
| 1029 | def bfd_grab_stats_snapshot(test, bs_idx=0, thread_index=None): |
| 1030 | s = test.statistics |
| 1031 | ti = thread_index |
| 1032 | if ti is None: |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 1033 | rx = s["/bfd/rx-session-counters"][:, bs_idx].sum_packets() |
| 1034 | rx_echo = s["/bfd/rx-session-echo-counters"][:, bs_idx].sum_packets() |
| 1035 | tx = s["/bfd/tx-session-counters"][:, bs_idx].sum_packets() |
| 1036 | tx_echo = s["/bfd/tx-session-echo-counters"][:, bs_idx].sum_packets() |
Klement Sekera | cdaf0d8 | 2022-02-14 20:20:22 +0000 | [diff] [blame] | 1037 | else: |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 1038 | rx = s["/bfd/rx-session-counters"][ti, bs_idx].sum_packets() |
| 1039 | rx_echo = s["/bfd/rx-session-echo-counters"][ti, bs_idx].sum_packets() |
| 1040 | tx = s["/bfd/tx-session-counters"][ti, bs_idx].sum_packets() |
| 1041 | tx_echo = s["/bfd/tx-session-echo-counters"][ti, bs_idx].sum_packets() |
Klement Sekera | cdaf0d8 | 2022-02-14 20:20:22 +0000 | [diff] [blame] | 1042 | return BFDStats(rx, rx_echo, tx, tx_echo) |
| 1043 | |
| 1044 | |
| 1045 | def bfd_stats_diff(stats_before, stats_after): |
| 1046 | rx = stats_after.rx - stats_before.rx |
| 1047 | rx_echo = stats_after.rx_echo - stats_before.rx_echo |
| 1048 | tx = stats_after.tx - stats_before.tx |
| 1049 | tx_echo = stats_after.tx_echo - stats_before.tx_echo |
| 1050 | return BFDStats(rx, rx_echo, tx, tx_echo) |
| 1051 | |
| 1052 | |
Abdel Baig | 17a9181 | 2024-09-03 11:52:20 -0400 | [diff] [blame] | 1053 | @parameterized_class( |
| 1054 | [ |
| 1055 | {"multihop": False}, |
| 1056 | {"multihop": True}, |
| 1057 | ] |
| 1058 | ) |
Andrew Yourtchenko | 06f3281 | 2021-01-14 10:19:08 +0000 | [diff] [blame] | 1059 | @tag_run_solo |
Dave Wallace | 670724c | 2022-09-20 21:52:18 -0400 | [diff] [blame] | 1060 | @tag_fixme_debian11 |
Klement Sekera | d3ba515 | 2017-02-14 03:09:17 +0100 | [diff] [blame] | 1061 | class BFD4TestCase(VppTestCase): |
Klement Sekera | d3ba515 | 2017-02-14 03:09:17 +0100 | [diff] [blame] | 1062 | pg0 = None |
Abdel Baig | 17a9181 | 2024-09-03 11:52:20 -0400 | [diff] [blame] | 1063 | interface0 = None |
Klement Sekera | d3ba515 | 2017-02-14 03:09:17 +0100 | [diff] [blame] | 1064 | vpp_clock_offset = None |
| 1065 | vpp_session = None |
| 1066 | test_session = None |
Abdel Baig | 17a9181 | 2024-09-03 11:52:20 -0400 | [diff] [blame] | 1067 | src_ip_net = "" |
| 1068 | dst_ip_net = "" |
Klement Sekera | d3ba515 | 2017-02-14 03:09:17 +0100 | [diff] [blame] | 1069 | |
Klement Sekera | 46a87ad | 2017-01-02 08:22:23 +0100 | [diff] [blame] | 1070 | @classmethod |
| 1071 | def setUpClass(cls): |
| 1072 | super(BFD4TestCase, cls).setUpClass() |
Abdel Baig | 17a9181 | 2024-09-03 11:52:20 -0400 | [diff] [blame] | 1073 | hoptype_str = "MultiHop" if cls.multihop else "SingleHop" |
| 1074 | cls.__doc__ = ( |
| 1075 | f"""""Bidirectional Forwarding Detection (BFD) - IPv4, {hoptype_str}""" |
| 1076 | ) |
Damjan Marion | 07a3857 | 2018-01-21 06:44:18 -0800 | [diff] [blame] | 1077 | cls.vapi.cli("set log class bfd level debug") |
Klement Sekera | 46a87ad | 2017-01-02 08:22:23 +0100 | [diff] [blame] | 1078 | try: |
| 1079 | cls.create_pg_interfaces([0]) |
Klement Sekera | b9ef273 | 2018-06-24 22:49:33 +0200 | [diff] [blame] | 1080 | cls.create_loopback_interfaces(1) |
Klement Sekera | 239790f | 2017-02-16 10:53:53 +0100 | [diff] [blame] | 1081 | cls.loopback0 = cls.lo_interfaces[0] |
| 1082 | cls.loopback0.config_ip4() |
| 1083 | cls.loopback0.admin_up() |
Klement Sekera | 46a87ad | 2017-01-02 08:22:23 +0100 | [diff] [blame] | 1084 | cls.pg0.config_ip4() |
Klement Sekera | 46a87ad | 2017-01-02 08:22:23 +0100 | [diff] [blame] | 1085 | cls.pg0.configure_ipv4_neighbors() |
| 1086 | cls.pg0.admin_up() |
| 1087 | cls.pg0.resolve_arp() |
| 1088 | |
| 1089 | except Exception: |
| 1090 | super(BFD4TestCase, cls).tearDownClass() |
| 1091 | raise |
| 1092 | |
Paul Vinciguerra | 8d991d9 | 2019-01-25 14:05:48 -0800 | [diff] [blame] | 1093 | @classmethod |
| 1094 | def tearDownClass(cls): |
| 1095 | super(BFD4TestCase, cls).tearDownClass() |
| 1096 | |
Klement Sekera | 46a87ad | 2017-01-02 08:22:23 +0100 | [diff] [blame] | 1097 | def setUp(self): |
| 1098 | super(BFD4TestCase, self).setUp() |
Klement Sekera | b17dd96 | 2017-01-09 07:43:48 +0100 | [diff] [blame] | 1099 | self.factory = AuthKeyFactory() |
Klement Sekera | 46a87ad | 2017-01-02 08:22:23 +0100 | [diff] [blame] | 1100 | self.vapi.want_bfd_events() |
Klement Sekera | d3ba515 | 2017-02-14 03:09:17 +0100 | [diff] [blame] | 1101 | self.pg0.enable_capture() |
Abdel Baig | 17a9181 | 2024-09-03 11:52:20 -0400 | [diff] [blame] | 1102 | set_ipv4_pfx_route_info(self, self.pg0, BFD_IPV4_REMOTE_ADDR, True) |
| 1103 | |
Klement Sekera | 46a87ad | 2017-01-02 08:22:23 +0100 | [diff] [blame] | 1104 | try: |
Abdel Baig | 17a9181 | 2024-09-03 11:52:20 -0400 | [diff] [blame] | 1105 | if self.multihop: |
| 1106 | self.interface0 = None |
| 1107 | self.bfd_udp4_sessions = self.statistics[BFD_STATS_V4_MH_PATH] |
| 1108 | self.bfd_udp6_sessions = self.statistics[BFD_STATS_V6_MH_PATH] |
| 1109 | else: |
| 1110 | self.interface0 = self.pg0 |
| 1111 | self.bfd_udp4_sessions = self.statistics[BFD_STATS_V4_SH_PATH] |
| 1112 | self.bfd_udp6_sessions = self.statistics[BFD_STATS_V6_SH_PATH] |
| 1113 | |
Klement Sekera | 617d429 | 2022-09-20 15:10:10 +0200 | [diff] [blame] | 1114 | self.vapi.cli("trace add bfd-process 500") |
Abdel Baig | 17a9181 | 2024-09-03 11:52:20 -0400 | [diff] [blame] | 1115 | self.vpp_session = VppBFDUDPSession( |
| 1116 | self, |
| 1117 | self.interface0, |
| 1118 | self.dst_ip_net, |
| 1119 | local_addr=self.src_ip_net, |
| 1120 | multihop=self.multihop, |
| 1121 | ) |
Klement Sekera | 46a87ad | 2017-01-02 08:22:23 +0100 | [diff] [blame] | 1122 | self.vpp_session.add_vpp_config() |
| 1123 | self.vpp_session.admin_up() |
Abdel Baig | 17a9181 | 2024-09-03 11:52:20 -0400 | [diff] [blame] | 1124 | self.test_session = BFDTestSession( |
| 1125 | self, |
| 1126 | self.pg0, |
| 1127 | AF_INET, |
| 1128 | local_addr=self.src_ip_net, |
| 1129 | peer_addr=self.dst_ip_net, |
| 1130 | multihop=self.multihop, |
| 1131 | ) |
Jakub Grajciar | 4682feb | 2019-09-02 13:28:52 +0200 | [diff] [blame] | 1132 | except BaseException: |
Klement Sekera | 46a87ad | 2017-01-02 08:22:23 +0100 | [diff] [blame] | 1133 | self.vapi.want_bfd_events(enable_disable=0) |
| 1134 | raise |
| 1135 | |
| 1136 | def tearDown(self): |
Klement Sekera | d3ba515 | 2017-02-14 03:09:17 +0100 | [diff] [blame] | 1137 | if not self.vpp_dead: |
| 1138 | self.vapi.want_bfd_events(enable_disable=0) |
| 1139 | self.vapi.collect_events() # clear the event queue |
| 1140 | super(BFD4TestCase, self).tearDown() |
Klement Sekera | b17dd96 | 2017-01-09 07:43:48 +0100 | [diff] [blame] | 1141 | |
| 1142 | def test_session_up(self): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 1143 | """bring BFD session up""" |
Klement Sekera | d3ba515 | 2017-02-14 03:09:17 +0100 | [diff] [blame] | 1144 | bfd_session_up(self) |
Abdel Baig | 17a9181 | 2024-09-03 11:52:20 -0400 | [diff] [blame] | 1145 | if self.multihop: |
| 1146 | bfd_udp4_sessions = self.statistics[BFD_STATS_V4_MH_PATH] |
| 1147 | bfd_udp6_sessions = self.statistics[BFD_STATS_V6_MH_PATH] |
| 1148 | else: |
| 1149 | bfd_udp4_sessions = self.statistics[BFD_STATS_V4_SH_PATH] |
| 1150 | bfd_udp6_sessions = self.statistics[BFD_STATS_V6_SH_PATH] |
| 1151 | |
Klement Sekera | cdaf0d8 | 2022-02-14 20:20:22 +0000 | [diff] [blame] | 1152 | self.assert_equal(bfd_udp4_sessions - self.bfd_udp4_sessions, 1) |
| 1153 | self.assert_equal(bfd_udp6_sessions, self.bfd_udp6_sessions) |
Klement Sekera | b17dd96 | 2017-01-09 07:43:48 +0100 | [diff] [blame] | 1154 | |
Klement Sekera | 7388448 | 2017-02-23 09:26:30 +0100 | [diff] [blame] | 1155 | def test_session_up_by_ip(self): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 1156 | """bring BFD session up - first frame looked up by address pair""" |
Klement Sekera | 7388448 | 2017-02-23 09:26:30 +0100 | [diff] [blame] | 1157 | self.logger.info("BFD: Sending Slow control frame") |
| 1158 | self.test_session.update(my_discriminator=randint(0, 40000000)) |
| 1159 | self.test_session.send_packet() |
| 1160 | self.pg0.enable_capture() |
| 1161 | p = self.pg0.wait_for_packet(1) |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 1162 | self.assert_equal( |
| 1163 | p[BFD].your_discriminator, |
| 1164 | self.test_session.my_discriminator, |
| 1165 | "BFD - your discriminator", |
| 1166 | ) |
Klement Sekera | 7388448 | 2017-02-23 09:26:30 +0100 | [diff] [blame] | 1167 | self.assert_equal(p[BFD].state, BFDState.init, BFDState) |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 1168 | self.test_session.update( |
| 1169 | your_discriminator=p[BFD].my_discriminator, state=BFDState.up |
| 1170 | ) |
Klement Sekera | 7388448 | 2017-02-23 09:26:30 +0100 | [diff] [blame] | 1171 | self.logger.info("BFD: Waiting for event") |
Ole Troan | 4376ab2 | 2021-03-03 10:40:05 +0100 | [diff] [blame] | 1172 | e = self.vapi.wait_for_event(1, "bfd_udp_session_event") |
Klement Sekera | 7388448 | 2017-02-23 09:26:30 +0100 | [diff] [blame] | 1173 | verify_event(self, e, expected_state=BFDState.init) |
| 1174 | self.logger.info("BFD: Sending Up") |
| 1175 | self.test_session.send_packet() |
| 1176 | self.logger.info("BFD: Waiting for event") |
Ole Troan | 4376ab2 | 2021-03-03 10:40:05 +0100 | [diff] [blame] | 1177 | e = self.vapi.wait_for_event(1, "bfd_udp_session_event") |
Klement Sekera | 7388448 | 2017-02-23 09:26:30 +0100 | [diff] [blame] | 1178 | verify_event(self, e, expected_state=BFDState.up) |
| 1179 | self.logger.info("BFD: Session is Up") |
| 1180 | self.test_session.update(state=BFDState.up) |
| 1181 | self.test_session.send_packet() |
| 1182 | self.assert_equal(self.vpp_session.state, BFDState.up, BFDState) |
| 1183 | |
Klement Sekera | b17dd96 | 2017-01-09 07:43:48 +0100 | [diff] [blame] | 1184 | def test_session_down(self): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 1185 | """bring BFD session down""" |
Klement Sekera | d3ba515 | 2017-02-14 03:09:17 +0100 | [diff] [blame] | 1186 | bfd_session_up(self) |
| 1187 | bfd_session_down(self) |
Klement Sekera | b17dd96 | 2017-01-09 07:43:48 +0100 | [diff] [blame] | 1188 | |
| 1189 | def test_hold_up(self): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 1190 | """hold BFD session up""" |
Klement Sekera | d3ba515 | 2017-02-14 03:09:17 +0100 | [diff] [blame] | 1191 | bfd_session_up(self) |
| 1192 | for dummy in range(self.test_session.detect_mult * 2): |
| 1193 | wait_for_bfd_packet(self) |
Klement Sekera | b17dd96 | 2017-01-09 07:43:48 +0100 | [diff] [blame] | 1194 | self.test_session.send_packet() |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 1195 | self.assert_equal(len(self.vapi.collect_events()), 0, "number of bfd events") |
Klement Sekera | 46a87ad | 2017-01-02 08:22:23 +0100 | [diff] [blame] | 1196 | |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 1197 | def test_slow_timer(self): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 1198 | """verify slow periodic control frames while session down""" |
Klement Sekera | d3ba515 | 2017-02-14 03:09:17 +0100 | [diff] [blame] | 1199 | packet_count = 3 |
| 1200 | self.logger.info("BFD: Waiting for %d BFD packets", packet_count) |
| 1201 | prev_packet = wait_for_bfd_packet(self, 2) |
| 1202 | for dummy in range(packet_count): |
| 1203 | next_packet = wait_for_bfd_packet(self, 2) |
| 1204 | time_diff = next_packet.time - prev_packet.time |
Klement Sekera | e4504c6 | 2016-12-08 10:16:41 +0100 | [diff] [blame] | 1205 | # spec says the range should be <0.75, 1>, allow extra 0.05 margin |
| 1206 | # to work around timing issues |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 1207 | self.assert_in_range(time_diff, 0.70, 1.05, "time between slow packets") |
Klement Sekera | d3ba515 | 2017-02-14 03:09:17 +0100 | [diff] [blame] | 1208 | prev_packet = next_packet |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 1209 | |
| 1210 | def test_zero_remote_min_rx(self): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 1211 | """no packets when zero remote required min rx interval""" |
Klement Sekera | d3ba515 | 2017-02-14 03:09:17 +0100 | [diff] [blame] | 1212 | bfd_session_up(self) |
| 1213 | self.test_session.update(required_min_rx=0) |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 1214 | self.test_session.send_packet() |
Klement Sekera | 239790f | 2017-02-16 10:53:53 +0100 | [diff] [blame] | 1215 | for dummy in range(self.test_session.detect_mult): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 1216 | self.sleep( |
| 1217 | self.vpp_session.required_min_rx / USEC_IN_SEC, |
| 1218 | "sleep before transmitting bfd packet", |
| 1219 | ) |
Klement Sekera | 239790f | 2017-02-16 10:53:53 +0100 | [diff] [blame] | 1220 | self.test_session.send_packet() |
Klement Sekera | a57a970 | 2017-02-02 06:58:07 +0100 | [diff] [blame] | 1221 | try: |
Klement Sekera | 239790f | 2017-02-16 10:53:53 +0100 | [diff] [blame] | 1222 | p = wait_for_bfd_packet(self, timeout=0) |
Klement Sekera | a57a970 | 2017-02-02 06:58:07 +0100 | [diff] [blame] | 1223 | self.logger.error(ppp("Received unexpected packet:", p)) |
Klement Sekera | d3ba515 | 2017-02-14 03:09:17 +0100 | [diff] [blame] | 1224 | except CaptureTimeoutError: |
Klement Sekera | a57a970 | 2017-02-02 06:58:07 +0100 | [diff] [blame] | 1225 | pass |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 1226 | self.assert_equal(len(self.vapi.collect_events()), 0, "number of bfd events") |
Klement Sekera | 2e01dfa | 2017-04-03 08:10:08 +0200 | [diff] [blame] | 1227 | self.test_session.update(required_min_rx=300000) |
Klement Sekera | 239790f | 2017-02-16 10:53:53 +0100 | [diff] [blame] | 1228 | for dummy in range(3): |
| 1229 | self.test_session.send_packet() |
| 1230 | wait_for_bfd_packet( |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 1231 | self, timeout=self.test_session.required_min_rx / USEC_IN_SEC |
| 1232 | ) |
| 1233 | self.assert_equal(len(self.vapi.collect_events()), 0, "number of bfd events") |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 1234 | |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 1235 | def test_conn_down(self): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 1236 | """verify session goes down after inactivity""" |
Klement Sekera | d3ba515 | 2017-02-14 03:09:17 +0100 | [diff] [blame] | 1237 | bfd_session_up(self) |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 1238 | detection_time = ( |
| 1239 | self.test_session.detect_mult |
| 1240 | * self.vpp_session.required_min_rx |
| 1241 | / USEC_IN_SEC |
| 1242 | ) |
Klement Sekera | c48829b | 2017-02-14 07:55:57 +0100 | [diff] [blame] | 1243 | self.sleep(detection_time, "waiting for BFD session time-out") |
Ole Troan | 4376ab2 | 2021-03-03 10:40:05 +0100 | [diff] [blame] | 1244 | e = self.vapi.wait_for_event(1, "bfd_udp_session_event") |
Klement Sekera | d3ba515 | 2017-02-14 03:09:17 +0100 | [diff] [blame] | 1245 | verify_event(self, e, expected_state=BFDState.down) |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 1246 | |
Klement Sekera | 4d39f9c | 2020-01-17 10:01:52 +0000 | [diff] [blame] | 1247 | def test_peer_discr_reset_sess_down(self): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 1248 | """peer discriminator reset after session goes down""" |
Klement Sekera | 4d39f9c | 2020-01-17 10:01:52 +0000 | [diff] [blame] | 1249 | bfd_session_up(self) |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 1250 | detection_time = ( |
| 1251 | self.test_session.detect_mult |
| 1252 | * self.vpp_session.required_min_rx |
| 1253 | / USEC_IN_SEC |
| 1254 | ) |
Klement Sekera | 4d39f9c | 2020-01-17 10:01:52 +0000 | [diff] [blame] | 1255 | self.sleep(detection_time, "waiting for BFD session time-out") |
| 1256 | self.test_session.my_discriminator = 0 |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 1257 | wait_for_bfd_packet(self, pcap_time_min=time.time() - self.vpp_clock_offset) |
Klement Sekera | 4d39f9c | 2020-01-17 10:01:52 +0000 | [diff] [blame] | 1258 | |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 1259 | def test_large_required_min_rx(self): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 1260 | """large remote required min rx interval""" |
Klement Sekera | d3ba515 | 2017-02-14 03:09:17 +0100 | [diff] [blame] | 1261 | bfd_session_up(self) |
| 1262 | p = wait_for_bfd_packet(self) |
Klement Sekera | 637b9c4 | 2016-12-08 05:19:14 +0100 | [diff] [blame] | 1263 | interval = 3000000 |
Klement Sekera | d3ba515 | 2017-02-14 03:09:17 +0100 | [diff] [blame] | 1264 | self.test_session.update(required_min_rx=interval) |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 1265 | self.test_session.send_packet() |
Klement Sekera | d3ba515 | 2017-02-14 03:09:17 +0100 | [diff] [blame] | 1266 | time_mark = time.time() |
Klement Sekera | 637b9c4 | 2016-12-08 05:19:14 +0100 | [diff] [blame] | 1267 | count = 0 |
Klement Sekera | a57a970 | 2017-02-02 06:58:07 +0100 | [diff] [blame] | 1268 | # busy wait here, trying to collect a packet or event, vpp is not |
| 1269 | # allowed to send packets and the session will timeout first - so the |
| 1270 | # Up->Down event must arrive before any packets do |
Klement Sekera | d3ba515 | 2017-02-14 03:09:17 +0100 | [diff] [blame] | 1271 | while time.time() < time_mark + interval / USEC_IN_SEC: |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 1272 | try: |
Klement Sekera | d3ba515 | 2017-02-14 03:09:17 +0100 | [diff] [blame] | 1273 | p = wait_for_bfd_packet(self, timeout=0) |
| 1274 | # if vpp managed to send a packet before we did the session |
| 1275 | # session update, then that's fine, ignore it |
| 1276 | if p.time < time_mark - self.vpp_clock_offset: |
| 1277 | continue |
Klement Sekera | a57a970 | 2017-02-02 06:58:07 +0100 | [diff] [blame] | 1278 | self.logger.error(ppp("Received unexpected packet:", p)) |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 1279 | count += 1 |
Klement Sekera | d3ba515 | 2017-02-14 03:09:17 +0100 | [diff] [blame] | 1280 | except CaptureTimeoutError: |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 1281 | pass |
Klement Sekera | a57a970 | 2017-02-02 06:58:07 +0100 | [diff] [blame] | 1282 | events = self.vapi.collect_events() |
| 1283 | if len(events) > 0: |
Klement Sekera | d3ba515 | 2017-02-14 03:09:17 +0100 | [diff] [blame] | 1284 | verify_event(self, events[0], BFDState.down) |
Klement Sekera | a57a970 | 2017-02-02 06:58:07 +0100 | [diff] [blame] | 1285 | break |
| 1286 | self.assert_equal(count, 0, "number of packets received") |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 1287 | |
Klement Sekera | d3ba515 | 2017-02-14 03:09:17 +0100 | [diff] [blame] | 1288 | def test_immediate_remote_min_rx_reduction(self): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 1289 | """immediately honor remote required min rx reduction""" |
Klement Sekera | 3e0a356 | 2016-12-19 09:05:21 +0100 | [diff] [blame] | 1290 | self.vpp_session.remove_vpp_config() |
Klement Sekera | 10db26f | 2017-01-11 08:16:53 +0100 | [diff] [blame] | 1291 | self.vpp_session = VppBFDUDPSession( |
Abdel Baig | 17a9181 | 2024-09-03 11:52:20 -0400 | [diff] [blame] | 1292 | self, |
| 1293 | self.interface0, |
| 1294 | self.dst_ip_net, |
| 1295 | local_addr=self.src_ip_net, |
| 1296 | multihop=self.multihop, |
| 1297 | desired_min_tx=10000, |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 1298 | ) |
Klement Sekera | d3ba515 | 2017-02-14 03:09:17 +0100 | [diff] [blame] | 1299 | self.pg0.enable_capture() |
Klement Sekera | 3e0a356 | 2016-12-19 09:05:21 +0100 | [diff] [blame] | 1300 | self.vpp_session.add_vpp_config() |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 1301 | self.test_session.update(desired_min_tx=1000000, required_min_rx=1000000) |
Klement Sekera | d3ba515 | 2017-02-14 03:09:17 +0100 | [diff] [blame] | 1302 | bfd_session_up(self) |
| 1303 | reference_packet = wait_for_bfd_packet(self) |
| 1304 | time_mark = time.time() |
| 1305 | interval = 300000 |
| 1306 | self.test_session.update(required_min_rx=interval) |
Klement Sekera | 3e0a356 | 2016-12-19 09:05:21 +0100 | [diff] [blame] | 1307 | self.test_session.send_packet() |
Klement Sekera | d3ba515 | 2017-02-14 03:09:17 +0100 | [diff] [blame] | 1308 | extra_time = time.time() - time_mark |
| 1309 | p = wait_for_bfd_packet(self) |
| 1310 | # first packet is allowed to be late by time we spent doing the update |
| 1311 | # calculated in extra_time |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 1312 | self.assert_in_range( |
| 1313 | p.time - reference_packet.time, |
| 1314 | 0.95 * 0.75 * interval / USEC_IN_SEC, |
| 1315 | 1.05 * interval / USEC_IN_SEC + extra_time, |
| 1316 | "time between BFD packets", |
| 1317 | ) |
Klement Sekera | d3ba515 | 2017-02-14 03:09:17 +0100 | [diff] [blame] | 1318 | reference_packet = p |
| 1319 | for dummy in range(3): |
| 1320 | p = wait_for_bfd_packet(self) |
| 1321 | diff = p.time - reference_packet.time |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 1322 | self.assert_in_range( |
| 1323 | diff, |
| 1324 | 0.95 * 0.75 * interval / USEC_IN_SEC, |
| 1325 | 1.05 * interval / USEC_IN_SEC, |
| 1326 | "time between BFD packets", |
| 1327 | ) |
Klement Sekera | d3ba515 | 2017-02-14 03:09:17 +0100 | [diff] [blame] | 1328 | reference_packet = p |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 1329 | |
Klement Sekera | a57a970 | 2017-02-02 06:58:07 +0100 | [diff] [blame] | 1330 | def test_modify_req_min_rx_double(self): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 1331 | """modify session - double required min rx""" |
Klement Sekera | d3ba515 | 2017-02-14 03:09:17 +0100 | [diff] [blame] | 1332 | bfd_session_up(self) |
| 1333 | p = wait_for_bfd_packet(self) |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 1334 | self.test_session.update(desired_min_tx=10000, required_min_rx=10000) |
Klement Sekera | a57a970 | 2017-02-02 06:58:07 +0100 | [diff] [blame] | 1335 | self.test_session.send_packet() |
Klement Sekera | d3ba515 | 2017-02-14 03:09:17 +0100 | [diff] [blame] | 1336 | # double required min rx |
Klement Sekera | a57a970 | 2017-02-02 06:58:07 +0100 | [diff] [blame] | 1337 | self.vpp_session.modify_parameters( |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 1338 | required_min_rx=2 * self.vpp_session.required_min_rx |
| 1339 | ) |
| 1340 | p = wait_for_bfd_packet(self, pcap_time_min=time.time() - self.vpp_clock_offset) |
Klement Sekera | a57a970 | 2017-02-02 06:58:07 +0100 | [diff] [blame] | 1341 | # poll bit needs to be set |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 1342 | self.assertIn("P", p.sprintf("%BFD.flags%"), "Poll bit not set in BFD packet") |
Klement Sekera | a57a970 | 2017-02-02 06:58:07 +0100 | [diff] [blame] | 1343 | # finish poll sequence with final packet |
| 1344 | final = self.test_session.create_packet() |
| 1345 | final[BFD].flags = "F" |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 1346 | timeout = ( |
| 1347 | self.test_session.detect_mult |
| 1348 | * max(self.test_session.desired_min_tx, self.vpp_session.required_min_rx) |
| 1349 | / USEC_IN_SEC |
| 1350 | ) |
Klement Sekera | a57a970 | 2017-02-02 06:58:07 +0100 | [diff] [blame] | 1351 | self.test_session.send_packet(final) |
Klement Sekera | d3ba515 | 2017-02-14 03:09:17 +0100 | [diff] [blame] | 1352 | time_mark = time.time() |
Ole Troan | 4376ab2 | 2021-03-03 10:40:05 +0100 | [diff] [blame] | 1353 | e = self.vapi.wait_for_event(2 * timeout, "bfd_udp_session_event") |
Klement Sekera | d3ba515 | 2017-02-14 03:09:17 +0100 | [diff] [blame] | 1354 | verify_event(self, e, expected_state=BFDState.down) |
| 1355 | time_to_event = time.time() - time_mark |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 1356 | self.assert_in_range( |
| 1357 | time_to_event, 0.9 * timeout, 1.1 * timeout, "session timeout" |
| 1358 | ) |
Klement Sekera | a57a970 | 2017-02-02 06:58:07 +0100 | [diff] [blame] | 1359 | |
| 1360 | def test_modify_req_min_rx_halve(self): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 1361 | """modify session - halve required min rx""" |
Klement Sekera | a57a970 | 2017-02-02 06:58:07 +0100 | [diff] [blame] | 1362 | self.vpp_session.modify_parameters( |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 1363 | required_min_rx=2 * self.vpp_session.required_min_rx |
| 1364 | ) |
Klement Sekera | d3ba515 | 2017-02-14 03:09:17 +0100 | [diff] [blame] | 1365 | bfd_session_up(self) |
| 1366 | p = wait_for_bfd_packet(self) |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 1367 | self.test_session.update(desired_min_tx=10000, required_min_rx=10000) |
Klement Sekera | a57a970 | 2017-02-02 06:58:07 +0100 | [diff] [blame] | 1368 | self.test_session.send_packet() |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 1369 | p = wait_for_bfd_packet(self, pcap_time_min=time.time() - self.vpp_clock_offset) |
Klement Sekera | a57a970 | 2017-02-02 06:58:07 +0100 | [diff] [blame] | 1370 | # halve required min rx |
| 1371 | old_required_min_rx = self.vpp_session.required_min_rx |
| 1372 | self.vpp_session.modify_parameters( |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 1373 | required_min_rx=self.vpp_session.required_min_rx // 2 |
| 1374 | ) |
Klement Sekera | a57a970 | 2017-02-02 06:58:07 +0100 | [diff] [blame] | 1375 | # now we wait 0.8*3*old-req-min-rx and the session should still be up |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 1376 | self.sleep( |
| 1377 | 0.8 * self.vpp_session.detect_mult * old_required_min_rx / USEC_IN_SEC, |
| 1378 | "wait before finishing poll sequence", |
| 1379 | ) |
| 1380 | self.assert_equal(len(self.vapi.collect_events()), 0, "number of bfd events") |
Klement Sekera | d3ba515 | 2017-02-14 03:09:17 +0100 | [diff] [blame] | 1381 | p = wait_for_bfd_packet(self) |
Klement Sekera | a57a970 | 2017-02-02 06:58:07 +0100 | [diff] [blame] | 1382 | # poll bit needs to be set |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 1383 | self.assertIn("P", p.sprintf("%BFD.flags%"), "Poll bit not set in BFD packet") |
Klement Sekera | a57a970 | 2017-02-02 06:58:07 +0100 | [diff] [blame] | 1384 | # finish poll sequence with final packet |
| 1385 | final = self.test_session.create_packet() |
| 1386 | final[BFD].flags = "F" |
| 1387 | self.test_session.send_packet(final) |
| 1388 | # now the session should time out under new conditions |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 1389 | detection_time = ( |
| 1390 | self.test_session.detect_mult |
| 1391 | * self.vpp_session.required_min_rx |
| 1392 | / USEC_IN_SEC |
| 1393 | ) |
Klement Sekera | 2e01dfa | 2017-04-03 08:10:08 +0200 | [diff] [blame] | 1394 | before = time.time() |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 1395 | e = self.vapi.wait_for_event(2 * detection_time, "bfd_udp_session_event") |
Klement Sekera | 2e01dfa | 2017-04-03 08:10:08 +0200 | [diff] [blame] | 1396 | after = time.time() |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 1397 | self.assert_in_range( |
| 1398 | after - before, |
| 1399 | 0.9 * detection_time, |
| 1400 | 1.1 * detection_time, |
| 1401 | "time before bfd session goes down", |
| 1402 | ) |
Klement Sekera | d3ba515 | 2017-02-14 03:09:17 +0100 | [diff] [blame] | 1403 | verify_event(self, e, expected_state=BFDState.down) |
Klement Sekera | a57a970 | 2017-02-02 06:58:07 +0100 | [diff] [blame] | 1404 | |
Klement Sekera | a57a970 | 2017-02-02 06:58:07 +0100 | [diff] [blame] | 1405 | def test_modify_detect_mult(self): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 1406 | """modify detect multiplier""" |
Klement Sekera | d3ba515 | 2017-02-14 03:09:17 +0100 | [diff] [blame] | 1407 | bfd_session_up(self) |
| 1408 | p = wait_for_bfd_packet(self) |
Klement Sekera | a57a970 | 2017-02-02 06:58:07 +0100 | [diff] [blame] | 1409 | self.vpp_session.modify_parameters(detect_mult=1) |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 1410 | p = wait_for_bfd_packet(self, pcap_time_min=time.time() - self.vpp_clock_offset) |
| 1411 | self.assert_equal( |
| 1412 | self.vpp_session.detect_mult, p[BFD].detect_mult, "detect mult" |
| 1413 | ) |
Klement Sekera | a57a970 | 2017-02-02 06:58:07 +0100 | [diff] [blame] | 1414 | # poll bit must not be set |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 1415 | self.assertNotIn( |
| 1416 | "P", p.sprintf("%BFD.flags%"), "Poll bit not set in BFD packet" |
| 1417 | ) |
Klement Sekera | a57a970 | 2017-02-02 06:58:07 +0100 | [diff] [blame] | 1418 | self.vpp_session.modify_parameters(detect_mult=10) |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 1419 | p = wait_for_bfd_packet(self, pcap_time_min=time.time() - self.vpp_clock_offset) |
| 1420 | self.assert_equal( |
| 1421 | self.vpp_session.detect_mult, p[BFD].detect_mult, "detect mult" |
| 1422 | ) |
Klement Sekera | a57a970 | 2017-02-02 06:58:07 +0100 | [diff] [blame] | 1423 | # poll bit must not be set |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 1424 | self.assertNotIn( |
| 1425 | "P", p.sprintf("%BFD.flags%"), "Poll bit not set in BFD packet" |
| 1426 | ) |
Klement Sekera | a57a970 | 2017-02-02 06:58:07 +0100 | [diff] [blame] | 1427 | |
Klement Sekera | 239790f | 2017-02-16 10:53:53 +0100 | [diff] [blame] | 1428 | def test_queued_poll(self): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 1429 | """test poll sequence queueing""" |
Klement Sekera | 239790f | 2017-02-16 10:53:53 +0100 | [diff] [blame] | 1430 | bfd_session_up(self) |
| 1431 | p = wait_for_bfd_packet(self) |
| 1432 | self.vpp_session.modify_parameters( |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 1433 | required_min_rx=2 * self.vpp_session.required_min_rx |
| 1434 | ) |
Klement Sekera | 239790f | 2017-02-16 10:53:53 +0100 | [diff] [blame] | 1435 | p = wait_for_bfd_packet(self) |
| 1436 | poll_sequence_start = time.time() |
| 1437 | poll_sequence_length_min = 0.5 |
| 1438 | send_final_after = time.time() + poll_sequence_length_min |
| 1439 | # poll bit needs to be set |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 1440 | self.assertIn("P", p.sprintf("%BFD.flags%"), "Poll bit not set in BFD packet") |
| 1441 | self.assert_equal( |
| 1442 | p[BFD].required_min_rx_interval, |
| 1443 | self.vpp_session.required_min_rx, |
| 1444 | "BFD required min rx interval", |
| 1445 | ) |
Klement Sekera | 239790f | 2017-02-16 10:53:53 +0100 | [diff] [blame] | 1446 | self.vpp_session.modify_parameters( |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 1447 | required_min_rx=2 * self.vpp_session.required_min_rx |
| 1448 | ) |
Klement Sekera | 239790f | 2017-02-16 10:53:53 +0100 | [diff] [blame] | 1449 | # 2nd poll sequence should be queued now |
| 1450 | # don't send the reply back yet, wait for some time to emulate |
| 1451 | # longer round-trip time |
| 1452 | packet_count = 0 |
| 1453 | while time.time() < send_final_after: |
| 1454 | self.test_session.send_packet() |
| 1455 | p = wait_for_bfd_packet(self) |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 1456 | self.assert_equal( |
| 1457 | len(self.vapi.collect_events()), 0, "number of bfd events" |
| 1458 | ) |
| 1459 | self.assert_equal( |
| 1460 | p[BFD].required_min_rx_interval, |
| 1461 | self.vpp_session.required_min_rx, |
| 1462 | "BFD required min rx interval", |
| 1463 | ) |
Klement Sekera | 239790f | 2017-02-16 10:53:53 +0100 | [diff] [blame] | 1464 | packet_count += 1 |
| 1465 | # poll bit must be set |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 1466 | self.assertIn( |
| 1467 | "P", p.sprintf("%BFD.flags%"), "Poll bit not set in BFD packet" |
| 1468 | ) |
Klement Sekera | 239790f | 2017-02-16 10:53:53 +0100 | [diff] [blame] | 1469 | final = self.test_session.create_packet() |
| 1470 | final[BFD].flags = "F" |
| 1471 | self.test_session.send_packet(final) |
| 1472 | # finish 1st with final |
| 1473 | poll_sequence_length = time.time() - poll_sequence_start |
| 1474 | # vpp must wait for some time before starting new poll sequence |
| 1475 | poll_no_2_started = False |
| 1476 | for dummy in range(2 * packet_count): |
| 1477 | p = wait_for_bfd_packet(self) |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 1478 | self.assert_equal( |
| 1479 | len(self.vapi.collect_events()), 0, "number of bfd events" |
| 1480 | ) |
Klement Sekera | 239790f | 2017-02-16 10:53:53 +0100 | [diff] [blame] | 1481 | if "P" in p.sprintf("%BFD.flags%"): |
| 1482 | poll_no_2_started = True |
| 1483 | if time.time() < poll_sequence_start + poll_sequence_length: |
| 1484 | raise Exception("VPP started 2nd poll sequence too soon") |
| 1485 | final = self.test_session.create_packet() |
| 1486 | final[BFD].flags = "F" |
| 1487 | self.test_session.send_packet(final) |
| 1488 | break |
| 1489 | else: |
| 1490 | self.test_session.send_packet() |
| 1491 | self.assertTrue(poll_no_2_started, "2nd poll sequence not performed") |
| 1492 | # finish 2nd with final |
| 1493 | final = self.test_session.create_packet() |
| 1494 | final[BFD].flags = "F" |
| 1495 | self.test_session.send_packet(final) |
| 1496 | p = wait_for_bfd_packet(self) |
| 1497 | # poll bit must not be set |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 1498 | self.assertNotIn("P", p.sprintf("%BFD.flags%"), "Poll bit set in BFD packet") |
Klement Sekera | 239790f | 2017-02-16 10:53:53 +0100 | [diff] [blame] | 1499 | |
Paul Vinciguerra | 7ade2f5 | 2019-12-06 11:06:02 -0500 | [diff] [blame] | 1500 | # returning inconsistent results requiring retries in per-patch tests |
Klement Sekera | b23ffd7 | 2021-05-31 16:08:53 +0200 | [diff] [blame] | 1501 | @unittest.skipUnless(config.extended, "part of extended tests") |
Klement Sekera | 7388448 | 2017-02-23 09:26:30 +0100 | [diff] [blame] | 1502 | def test_poll_response(self): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 1503 | """test correct response to control frame with poll bit set""" |
Klement Sekera | 7388448 | 2017-02-23 09:26:30 +0100 | [diff] [blame] | 1504 | bfd_session_up(self) |
| 1505 | poll = self.test_session.create_packet() |
| 1506 | poll[BFD].flags = "P" |
| 1507 | self.test_session.send_packet(poll) |
| 1508 | final = wait_for_bfd_packet( |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 1509 | self, pcap_time_min=time.time() - self.vpp_clock_offset |
| 1510 | ) |
Klement Sekera | 7388448 | 2017-02-23 09:26:30 +0100 | [diff] [blame] | 1511 | self.assertIn("F", final.sprintf("%BFD.flags%")) |
| 1512 | |
Klement Sekera | d3ba515 | 2017-02-14 03:09:17 +0100 | [diff] [blame] | 1513 | def test_no_periodic_if_remote_demand(self): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 1514 | """no periodic frames outside poll sequence if remote demand set""" |
Klement Sekera | d3ba515 | 2017-02-14 03:09:17 +0100 | [diff] [blame] | 1515 | bfd_session_up(self) |
| 1516 | demand = self.test_session.create_packet() |
| 1517 | demand[BFD].flags = "D" |
| 1518 | self.test_session.send_packet(demand) |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 1519 | transmit_time = ( |
| 1520 | 0.9 |
| 1521 | * max(self.vpp_session.required_min_rx, self.test_session.desired_min_tx) |
Klement Sekera | d3ba515 | 2017-02-14 03:09:17 +0100 | [diff] [blame] | 1522 | / USEC_IN_SEC |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 1523 | ) |
Klement Sekera | d3ba515 | 2017-02-14 03:09:17 +0100 | [diff] [blame] | 1524 | count = 0 |
Klement Sekera | aeeac3b | 2017-02-14 07:11:52 +0100 | [diff] [blame] | 1525 | for dummy in range(self.test_session.detect_mult * 2): |
Paul Vinciguerra | 0f6602c | 2019-03-10 09:10:54 -0700 | [diff] [blame] | 1526 | self.sleep(transmit_time) |
Klement Sekera | d3ba515 | 2017-02-14 03:09:17 +0100 | [diff] [blame] | 1527 | self.test_session.send_packet(demand) |
| 1528 | try: |
| 1529 | p = wait_for_bfd_packet(self, timeout=0) |
| 1530 | self.logger.error(ppp("Received unexpected packet:", p)) |
| 1531 | count += 1 |
| 1532 | except CaptureTimeoutError: |
| 1533 | pass |
| 1534 | events = self.vapi.collect_events() |
| 1535 | for e in events: |
| 1536 | self.logger.error("Received unexpected event: %s", e) |
| 1537 | self.assert_equal(count, 0, "number of packets received") |
| 1538 | self.assert_equal(len(events), 0, "number of events received") |
Klement Sekera | 46a87ad | 2017-01-02 08:22:23 +0100 | [diff] [blame] | 1539 | |
Klement Sekera | aeeac3b | 2017-02-14 07:11:52 +0100 | [diff] [blame] | 1540 | def test_echo_looped_back(self): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 1541 | """echo packets looped back""" |
Abdel Baig | 17a9181 | 2024-09-03 11:52:20 -0400 | [diff] [blame] | 1542 | |
| 1543 | if self.multihop: |
| 1544 | self.skipTest( |
| 1545 | f"Skipping because echo functionality is not supported with multihop" |
| 1546 | ) |
| 1547 | |
Klement Sekera | cdaf0d8 | 2022-02-14 20:20:22 +0000 | [diff] [blame] | 1548 | bfd_session_up(self) |
| 1549 | stats_before = bfd_grab_stats_snapshot(self) |
Klement Sekera | aeeac3b | 2017-02-14 07:11:52 +0100 | [diff] [blame] | 1550 | self.pg0.enable_capture() |
| 1551 | echo_packet_count = 10 |
| 1552 | # random source port low enough to increment a few times.. |
| 1553 | udp_sport_tx = randint(1, 50000) |
| 1554 | udp_sport_rx = udp_sport_tx |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 1555 | echo_packet = ( |
| 1556 | Ether(src=self.pg0.remote_mac, dst=self.pg0.local_mac) |
| 1557 | / IP(src=self.pg0.remote_ip4, dst=self.pg0.remote_ip4) |
| 1558 | / UDP(dport=BFD.udp_dport_echo) |
| 1559 | / Raw("this should be looped back") |
| 1560 | ) |
Klement Sekera | aeeac3b | 2017-02-14 07:11:52 +0100 | [diff] [blame] | 1561 | for dummy in range(echo_packet_count): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 1562 | self.sleep(0.01, "delay between echo packets") |
Klement Sekera | aeeac3b | 2017-02-14 07:11:52 +0100 | [diff] [blame] | 1563 | echo_packet[UDP].sport = udp_sport_tx |
| 1564 | udp_sport_tx += 1 |
| 1565 | self.logger.debug(ppp("Sending packet:", echo_packet)) |
| 1566 | self.pg0.add_stream(echo_packet) |
| 1567 | self.pg_start() |
Klement Sekera | cdaf0d8 | 2022-02-14 20:20:22 +0000 | [diff] [blame] | 1568 | self.logger.debug(self.vapi.ppcli("show trace")) |
| 1569 | counter = 0 |
| 1570 | bfd_control_packets_rx = 0 |
| 1571 | while counter < echo_packet_count: |
Klement Sekera | aeeac3b | 2017-02-14 07:11:52 +0100 | [diff] [blame] | 1572 | p = self.pg0.wait_for_packet(1) |
| 1573 | self.logger.debug(ppp("Got packet:", p)) |
| 1574 | ether = p[Ether] |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 1575 | self.assert_equal(self.pg0.remote_mac, ether.dst, "Destination MAC") |
Klement Sekera | aeeac3b | 2017-02-14 07:11:52 +0100 | [diff] [blame] | 1576 | self.assert_equal(self.pg0.local_mac, ether.src, "Source MAC") |
| 1577 | ip = p[IP] |
| 1578 | self.assert_equal(self.pg0.remote_ip4, ip.dst, "Destination IP") |
Klement Sekera | aeeac3b | 2017-02-14 07:11:52 +0100 | [diff] [blame] | 1579 | udp = p[UDP] |
Klement Sekera | cdaf0d8 | 2022-02-14 20:20:22 +0000 | [diff] [blame] | 1580 | if udp.dport == BFD.udp_dport: |
| 1581 | bfd_control_packets_rx += 1 |
| 1582 | continue |
| 1583 | self.assert_equal(self.pg0.remote_ip4, ip.src, "Source IP") |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 1584 | self.assert_equal(udp.dport, BFD.udp_dport_echo, "UDP destination port") |
Klement Sekera | aeeac3b | 2017-02-14 07:11:52 +0100 | [diff] [blame] | 1585 | self.assert_equal(udp.sport, udp_sport_rx, "UDP source port") |
| 1586 | udp_sport_rx += 1 |
Klement Sekera | 239790f | 2017-02-16 10:53:53 +0100 | [diff] [blame] | 1587 | # need to compare the hex payload here, otherwise BFD_vpp_echo |
| 1588 | # gets in way |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 1589 | self.assertEqual( |
| 1590 | scapy.compat.raw(p[UDP].payload), |
| 1591 | scapy.compat.raw(echo_packet[UDP].payload), |
| 1592 | "Received packet is not the echo packet sent", |
| 1593 | ) |
Klement Sekera | cdaf0d8 | 2022-02-14 20:20:22 +0000 | [diff] [blame] | 1594 | counter += 1 |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 1595 | self.assert_equal( |
| 1596 | udp_sport_tx, |
| 1597 | udp_sport_rx, |
| 1598 | "UDP source port (== ECHO packet identifier for test purposes)", |
| 1599 | ) |
Klement Sekera | cdaf0d8 | 2022-02-14 20:20:22 +0000 | [diff] [blame] | 1600 | stats_after = bfd_grab_stats_snapshot(self) |
| 1601 | diff = bfd_stats_diff(stats_before, stats_after) |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 1602 | self.assertEqual(0, diff.rx, "RX counter bumped but no BFD packets sent") |
Klement Sekera | cdaf0d8 | 2022-02-14 20:20:22 +0000 | [diff] [blame] | 1603 | self.assertEqual( |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 1604 | 0, diff.rx_echo, "RX echo counter bumped but no BFD session exists" |
| 1605 | ) |
Klement Sekera | cdaf0d8 | 2022-02-14 20:20:22 +0000 | [diff] [blame] | 1606 | self.assertEqual( |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 1607 | 0, diff.tx_echo, "TX echo counter bumped but no BFD session exists" |
| 1608 | ) |
Klement Sekera | aeeac3b | 2017-02-14 07:11:52 +0100 | [diff] [blame] | 1609 | |
Klement Sekera | 239790f | 2017-02-16 10:53:53 +0100 | [diff] [blame] | 1610 | def test_echo(self): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 1611 | """echo function""" |
Abdel Baig | 17a9181 | 2024-09-03 11:52:20 -0400 | [diff] [blame] | 1612 | |
| 1613 | if self.multihop: |
| 1614 | self.skipTest( |
| 1615 | f"Skipping because echo functionality is not supported with multihop" |
| 1616 | ) |
| 1617 | |
Klement Sekera | cdaf0d8 | 2022-02-14 20:20:22 +0000 | [diff] [blame] | 1618 | stats_before = bfd_grab_stats_snapshot(self) |
Klement Sekera | 239790f | 2017-02-16 10:53:53 +0100 | [diff] [blame] | 1619 | bfd_session_up(self) |
Klement Sekera | 3cfa558 | 2017-04-19 07:10:58 +0000 | [diff] [blame] | 1620 | self.test_session.update(required_min_echo_rx=150000) |
Klement Sekera | 239790f | 2017-02-16 10:53:53 +0100 | [diff] [blame] | 1621 | self.test_session.send_packet() |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 1622 | detection_time = ( |
| 1623 | self.test_session.detect_mult |
| 1624 | * self.vpp_session.required_min_rx |
| 1625 | / USEC_IN_SEC |
| 1626 | ) |
Klement Sekera | 239790f | 2017-02-16 10:53:53 +0100 | [diff] [blame] | 1627 | # echo shouldn't work without echo source set |
Klement Sekera | 3cfa558 | 2017-04-19 07:10:58 +0000 | [diff] [blame] | 1628 | for dummy in range(10): |
| 1629 | sleep = self.vpp_session.required_min_rx / USEC_IN_SEC |
Klement Sekera | 239790f | 2017-02-16 10:53:53 +0100 | [diff] [blame] | 1630 | self.sleep(sleep, "delay before sending bfd packet") |
| 1631 | self.test_session.send_packet() |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 1632 | p = wait_for_bfd_packet(self, pcap_time_min=time.time() - self.vpp_clock_offset) |
| 1633 | self.assert_equal( |
| 1634 | p[BFD].required_min_rx_interval, |
| 1635 | self.vpp_session.required_min_rx, |
| 1636 | "BFD required min rx interval", |
| 1637 | ) |
Klement Sekera | 3cfa558 | 2017-04-19 07:10:58 +0000 | [diff] [blame] | 1638 | self.test_session.send_packet() |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 1639 | self.vapi.bfd_udp_set_echo_source(sw_if_index=self.loopback0.sw_if_index) |
Klement Sekera | 3cfa558 | 2017-04-19 07:10:58 +0000 | [diff] [blame] | 1640 | echo_seen = False |
Klement Sekera | 239790f | 2017-02-16 10:53:53 +0100 | [diff] [blame] | 1641 | # should be turned on - loopback echo packets |
| 1642 | for dummy in range(3): |
| 1643 | loop_until = time.time() + 0.75 * detection_time |
| 1644 | while time.time() < loop_until: |
| 1645 | p = self.pg0.wait_for_packet(1) |
| 1646 | self.logger.debug(ppp("Got packet:", p)) |
| 1647 | if p[UDP].dport == BFD.udp_dport_echo: |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 1648 | self.assert_equal(p[IP].dst, self.pg0.local_ip4, "BFD ECHO dst IP") |
| 1649 | self.assertNotEqual( |
| 1650 | p[IP].src, |
| 1651 | self.loopback0.local_ip4, |
| 1652 | "BFD ECHO src IP equal to loopback IP", |
| 1653 | ) |
Klement Sekera | 239790f | 2017-02-16 10:53:53 +0100 | [diff] [blame] | 1654 | self.logger.debug(ppp("Looping back packet:", p)) |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 1655 | self.assert_equal( |
| 1656 | p[Ether].dst, |
| 1657 | self.pg0.remote_mac, |
| 1658 | "ECHO packet destination MAC address", |
| 1659 | ) |
John Lo | 1904c47 | 2017-03-10 17:15:22 -0500 | [diff] [blame] | 1660 | p[Ether].dst = self.pg0.local_mac |
Klement Sekera | 239790f | 2017-02-16 10:53:53 +0100 | [diff] [blame] | 1661 | self.pg0.add_stream(p) |
Klement Sekera | cdaf0d8 | 2022-02-14 20:20:22 +0000 | [diff] [blame] | 1662 | self.test_session.rx_packets_echo += 1 |
| 1663 | self.test_session.tx_packets_echo += 1 |
Klement Sekera | 239790f | 2017-02-16 10:53:53 +0100 | [diff] [blame] | 1664 | self.pg_start() |
Klement Sekera | 3cfa558 | 2017-04-19 07:10:58 +0000 | [diff] [blame] | 1665 | echo_seen = True |
Klement Sekera | 239790f | 2017-02-16 10:53:53 +0100 | [diff] [blame] | 1666 | elif p.haslayer(BFD): |
Klement Sekera | cdaf0d8 | 2022-02-14 20:20:22 +0000 | [diff] [blame] | 1667 | self.test_session.rx_packets += 1 |
Klement Sekera | 3cfa558 | 2017-04-19 07:10:58 +0000 | [diff] [blame] | 1668 | if echo_seen: |
| 1669 | self.assertGreaterEqual( |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 1670 | p[BFD].required_min_rx_interval, 1000000 |
| 1671 | ) |
Klement Sekera | 239790f | 2017-02-16 10:53:53 +0100 | [diff] [blame] | 1672 | if "P" in p.sprintf("%BFD.flags%"): |
| 1673 | final = self.test_session.create_packet() |
| 1674 | final[BFD].flags = "F" |
| 1675 | self.test_session.send_packet(final) |
| 1676 | else: |
| 1677 | raise Exception(ppp("Received unknown packet:", p)) |
| 1678 | |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 1679 | self.assert_equal( |
| 1680 | len(self.vapi.collect_events()), 0, "number of bfd events" |
| 1681 | ) |
Klement Sekera | 239790f | 2017-02-16 10:53:53 +0100 | [diff] [blame] | 1682 | self.test_session.send_packet() |
Klement Sekera | 3cfa558 | 2017-04-19 07:10:58 +0000 | [diff] [blame] | 1683 | self.assertTrue(echo_seen, "No echo packets received") |
Klement Sekera | 239790f | 2017-02-16 10:53:53 +0100 | [diff] [blame] | 1684 | |
Klement Sekera | cdaf0d8 | 2022-02-14 20:20:22 +0000 | [diff] [blame] | 1685 | stats_after = bfd_grab_stats_snapshot(self) |
| 1686 | diff = bfd_stats_diff(stats_before, stats_after) |
| 1687 | # our rx is vpp tx and vice versa, also tolerate one packet off |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 1688 | self.assert_in_range( |
| 1689 | self.test_session.tx_packets, diff.rx - 1, diff.rx + 1, "RX counter" |
| 1690 | ) |
| 1691 | self.assert_in_range( |
| 1692 | self.test_session.rx_packets, diff.tx - 1, diff.tx + 1, "TX counter" |
| 1693 | ) |
| 1694 | self.assert_in_range( |
| 1695 | self.test_session.tx_packets_echo, |
| 1696 | diff.rx_echo - 1, |
| 1697 | diff.rx_echo + 1, |
| 1698 | "RX echo counter", |
| 1699 | ) |
| 1700 | self.assert_in_range( |
| 1701 | self.test_session.rx_packets_echo, |
| 1702 | diff.tx_echo - 1, |
| 1703 | diff.tx_echo + 1, |
| 1704 | "TX echo counter", |
| 1705 | ) |
Klement Sekera | cdaf0d8 | 2022-02-14 20:20:22 +0000 | [diff] [blame] | 1706 | |
Klement Sekera | 239790f | 2017-02-16 10:53:53 +0100 | [diff] [blame] | 1707 | def test_echo_fail(self): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 1708 | """session goes down if echo function fails""" |
Abdel Baig | 17a9181 | 2024-09-03 11:52:20 -0400 | [diff] [blame] | 1709 | |
| 1710 | if self.multihop: |
| 1711 | self.skipTest( |
| 1712 | f"Skipping because echo functionality is not supported with multihop" |
| 1713 | ) |
| 1714 | |
Klement Sekera | 239790f | 2017-02-16 10:53:53 +0100 | [diff] [blame] | 1715 | bfd_session_up(self) |
Klement Sekera | 3cfa558 | 2017-04-19 07:10:58 +0000 | [diff] [blame] | 1716 | self.test_session.update(required_min_echo_rx=150000) |
Klement Sekera | 239790f | 2017-02-16 10:53:53 +0100 | [diff] [blame] | 1717 | self.test_session.send_packet() |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 1718 | detection_time = ( |
| 1719 | self.test_session.detect_mult |
| 1720 | * self.vpp_session.required_min_rx |
| 1721 | / USEC_IN_SEC |
| 1722 | ) |
| 1723 | self.vapi.bfd_udp_set_echo_source(sw_if_index=self.loopback0.sw_if_index) |
Klement Sekera | 239790f | 2017-02-16 10:53:53 +0100 | [diff] [blame] | 1724 | # echo function should be used now, but we will drop the echo packets |
| 1725 | verified_diag = False |
| 1726 | for dummy in range(3): |
| 1727 | loop_until = time.time() + 0.75 * detection_time |
| 1728 | while time.time() < loop_until: |
| 1729 | p = self.pg0.wait_for_packet(1) |
| 1730 | self.logger.debug(ppp("Got packet:", p)) |
| 1731 | if p[UDP].dport == BFD.udp_dport_echo: |
| 1732 | # dropped |
| 1733 | pass |
| 1734 | elif p.haslayer(BFD): |
| 1735 | if "P" in p.sprintf("%BFD.flags%"): |
| 1736 | self.assertGreaterEqual( |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 1737 | p[BFD].required_min_rx_interval, 1000000 |
| 1738 | ) |
Klement Sekera | 239790f | 2017-02-16 10:53:53 +0100 | [diff] [blame] | 1739 | final = self.test_session.create_packet() |
| 1740 | final[BFD].flags = "F" |
| 1741 | self.test_session.send_packet(final) |
| 1742 | if p[BFD].state == BFDState.down: |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 1743 | self.assert_equal( |
| 1744 | p[BFD].diag, BFDDiagCode.echo_function_failed, BFDDiagCode |
| 1745 | ) |
Klement Sekera | 239790f | 2017-02-16 10:53:53 +0100 | [diff] [blame] | 1746 | verified_diag = True |
| 1747 | else: |
| 1748 | raise Exception(ppp("Received unknown packet:", p)) |
| 1749 | self.test_session.send_packet() |
| 1750 | events = self.vapi.collect_events() |
| 1751 | self.assert_equal(len(events), 1, "number of bfd events") |
| 1752 | self.assert_equal(events[0].state, BFDState.down, BFDState) |
| 1753 | self.assertTrue(verified_diag, "Incorrect diagnostics code received") |
| 1754 | |
| 1755 | def test_echo_stop(self): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 1756 | """echo function stops if peer sets required min echo rx zero""" |
Abdel Baig | 17a9181 | 2024-09-03 11:52:20 -0400 | [diff] [blame] | 1757 | |
| 1758 | if self.multihop: |
| 1759 | self.skipTest( |
| 1760 | f"Skipping because echo functionality is not supported with multihop" |
| 1761 | ) |
| 1762 | |
Klement Sekera | 239790f | 2017-02-16 10:53:53 +0100 | [diff] [blame] | 1763 | bfd_session_up(self) |
Klement Sekera | 3cfa558 | 2017-04-19 07:10:58 +0000 | [diff] [blame] | 1764 | self.test_session.update(required_min_echo_rx=150000) |
Klement Sekera | 239790f | 2017-02-16 10:53:53 +0100 | [diff] [blame] | 1765 | self.test_session.send_packet() |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 1766 | self.vapi.bfd_udp_set_echo_source(sw_if_index=self.loopback0.sw_if_index) |
Klement Sekera | 239790f | 2017-02-16 10:53:53 +0100 | [diff] [blame] | 1767 | # wait for first echo packet |
| 1768 | while True: |
| 1769 | p = self.pg0.wait_for_packet(1) |
| 1770 | self.logger.debug(ppp("Got packet:", p)) |
| 1771 | if p[UDP].dport == BFD.udp_dport_echo: |
| 1772 | self.logger.debug(ppp("Looping back packet:", p)) |
John Lo | 1904c47 | 2017-03-10 17:15:22 -0500 | [diff] [blame] | 1773 | p[Ether].dst = self.pg0.local_mac |
Klement Sekera | 239790f | 2017-02-16 10:53:53 +0100 | [diff] [blame] | 1774 | self.pg0.add_stream(p) |
| 1775 | self.pg_start() |
| 1776 | break |
| 1777 | elif p.haslayer(BFD): |
| 1778 | # ignore BFD |
| 1779 | pass |
| 1780 | else: |
| 1781 | raise Exception(ppp("Received unknown packet:", p)) |
| 1782 | self.test_session.update(required_min_echo_rx=0) |
| 1783 | self.test_session.send_packet() |
| 1784 | # echo packets shouldn't arrive anymore |
| 1785 | for dummy in range(5): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 1786 | wait_for_bfd_packet(self, pcap_time_min=time.time() - self.vpp_clock_offset) |
Klement Sekera | 239790f | 2017-02-16 10:53:53 +0100 | [diff] [blame] | 1787 | self.test_session.send_packet() |
| 1788 | events = self.vapi.collect_events() |
| 1789 | self.assert_equal(len(events), 0, "number of bfd events") |
| 1790 | |
Klement Sekera | 7388448 | 2017-02-23 09:26:30 +0100 | [diff] [blame] | 1791 | def test_echo_source_removed(self): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 1792 | """echo function stops if echo source is removed""" |
Abdel Baig | 17a9181 | 2024-09-03 11:52:20 -0400 | [diff] [blame] | 1793 | |
| 1794 | if self.multihop: |
| 1795 | self.skipTest( |
| 1796 | f"Skipping because echo functionality is not supported with multihop" |
| 1797 | ) |
| 1798 | |
Klement Sekera | 7388448 | 2017-02-23 09:26:30 +0100 | [diff] [blame] | 1799 | bfd_session_up(self) |
Klement Sekera | 3cfa558 | 2017-04-19 07:10:58 +0000 | [diff] [blame] | 1800 | self.test_session.update(required_min_echo_rx=150000) |
Klement Sekera | 7388448 | 2017-02-23 09:26:30 +0100 | [diff] [blame] | 1801 | self.test_session.send_packet() |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 1802 | self.vapi.bfd_udp_set_echo_source(sw_if_index=self.loopback0.sw_if_index) |
Klement Sekera | 7388448 | 2017-02-23 09:26:30 +0100 | [diff] [blame] | 1803 | # wait for first echo packet |
| 1804 | while True: |
| 1805 | p = self.pg0.wait_for_packet(1) |
| 1806 | self.logger.debug(ppp("Got packet:", p)) |
| 1807 | if p[UDP].dport == BFD.udp_dport_echo: |
| 1808 | self.logger.debug(ppp("Looping back packet:", p)) |
John Lo | 1904c47 | 2017-03-10 17:15:22 -0500 | [diff] [blame] | 1809 | p[Ether].dst = self.pg0.local_mac |
Klement Sekera | 7388448 | 2017-02-23 09:26:30 +0100 | [diff] [blame] | 1810 | self.pg0.add_stream(p) |
| 1811 | self.pg_start() |
| 1812 | break |
| 1813 | elif p.haslayer(BFD): |
| 1814 | # ignore BFD |
| 1815 | pass |
| 1816 | else: |
| 1817 | raise Exception(ppp("Received unknown packet:", p)) |
| 1818 | self.vapi.bfd_udp_del_echo_source() |
| 1819 | self.test_session.send_packet() |
| 1820 | # echo packets shouldn't arrive anymore |
| 1821 | for dummy in range(5): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 1822 | wait_for_bfd_packet(self, pcap_time_min=time.time() - self.vpp_clock_offset) |
Klement Sekera | 7388448 | 2017-02-23 09:26:30 +0100 | [diff] [blame] | 1823 | self.test_session.send_packet() |
| 1824 | events = self.vapi.collect_events() |
| 1825 | self.assert_equal(len(events), 0, "number of bfd events") |
| 1826 | |
Klement Sekera | 239790f | 2017-02-16 10:53:53 +0100 | [diff] [blame] | 1827 | def test_stale_echo(self): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 1828 | """stale echo packets don't keep a session up""" |
Abdel Baig | 17a9181 | 2024-09-03 11:52:20 -0400 | [diff] [blame] | 1829 | |
| 1830 | if self.multihop: |
| 1831 | self.skipTest( |
| 1832 | f"Skipping because echo functionality is not supported with multihop" |
| 1833 | ) |
| 1834 | |
Klement Sekera | 239790f | 2017-02-16 10:53:53 +0100 | [diff] [blame] | 1835 | bfd_session_up(self) |
Klement Sekera | 3cfa558 | 2017-04-19 07:10:58 +0000 | [diff] [blame] | 1836 | self.test_session.update(required_min_echo_rx=150000) |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 1837 | self.vapi.bfd_udp_set_echo_source(sw_if_index=self.loopback0.sw_if_index) |
Klement Sekera | 239790f | 2017-02-16 10:53:53 +0100 | [diff] [blame] | 1838 | self.test_session.send_packet() |
| 1839 | # should be turned on - loopback echo packets |
| 1840 | echo_packet = None |
| 1841 | timeout_at = None |
| 1842 | timeout_ok = False |
| 1843 | for dummy in range(10 * self.vpp_session.detect_mult): |
| 1844 | p = self.pg0.wait_for_packet(1) |
| 1845 | if p[UDP].dport == BFD.udp_dport_echo: |
| 1846 | if echo_packet is None: |
| 1847 | self.logger.debug(ppp("Got first echo packet:", p)) |
| 1848 | echo_packet = p |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 1849 | timeout_at = ( |
| 1850 | time.time() |
| 1851 | + self.vpp_session.detect_mult |
| 1852 | * self.test_session.required_min_echo_rx |
| 1853 | / USEC_IN_SEC |
| 1854 | ) |
Klement Sekera | 239790f | 2017-02-16 10:53:53 +0100 | [diff] [blame] | 1855 | else: |
| 1856 | self.logger.debug(ppp("Got followup echo packet:", p)) |
| 1857 | self.logger.debug(ppp("Looping back first echo packet:", p)) |
John Lo | 1904c47 | 2017-03-10 17:15:22 -0500 | [diff] [blame] | 1858 | echo_packet[Ether].dst = self.pg0.local_mac |
Klement Sekera | 239790f | 2017-02-16 10:53:53 +0100 | [diff] [blame] | 1859 | self.pg0.add_stream(echo_packet) |
| 1860 | self.pg_start() |
| 1861 | elif p.haslayer(BFD): |
| 1862 | self.logger.debug(ppp("Got packet:", p)) |
| 1863 | if "P" in p.sprintf("%BFD.flags%"): |
| 1864 | final = self.test_session.create_packet() |
| 1865 | final[BFD].flags = "F" |
| 1866 | self.test_session.send_packet(final) |
| 1867 | if p[BFD].state == BFDState.down: |
| 1868 | self.assertIsNotNone( |
| 1869 | timeout_at, |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 1870 | "Session went down before first echo packet received", |
| 1871 | ) |
Klement Sekera | 239790f | 2017-02-16 10:53:53 +0100 | [diff] [blame] | 1872 | now = time.time() |
| 1873 | self.assertGreaterEqual( |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 1874 | now, |
| 1875 | timeout_at, |
| 1876 | "Session timeout at %s, but is expected at %s" |
| 1877 | % (now, timeout_at), |
| 1878 | ) |
| 1879 | self.assert_equal( |
| 1880 | p[BFD].diag, BFDDiagCode.echo_function_failed, BFDDiagCode |
| 1881 | ) |
Klement Sekera | 239790f | 2017-02-16 10:53:53 +0100 | [diff] [blame] | 1882 | events = self.vapi.collect_events() |
| 1883 | self.assert_equal(len(events), 1, "number of bfd events") |
| 1884 | self.assert_equal(events[0].state, BFDState.down, BFDState) |
| 1885 | timeout_ok = True |
| 1886 | break |
| 1887 | else: |
| 1888 | raise Exception(ppp("Received unknown packet:", p)) |
| 1889 | self.test_session.send_packet() |
| 1890 | self.assertTrue(timeout_ok, "Expected timeout event didn't occur") |
| 1891 | |
| 1892 | def test_invalid_echo_checksum(self): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 1893 | """echo packets with invalid checksum don't keep a session up""" |
Abdel Baig | 17a9181 | 2024-09-03 11:52:20 -0400 | [diff] [blame] | 1894 | |
| 1895 | if self.multihop: |
| 1896 | self.skipTest( |
| 1897 | f"Skipping because echo functionality is not supported with multihop" |
| 1898 | ) |
| 1899 | |
Klement Sekera | 239790f | 2017-02-16 10:53:53 +0100 | [diff] [blame] | 1900 | bfd_session_up(self) |
Klement Sekera | 3cfa558 | 2017-04-19 07:10:58 +0000 | [diff] [blame] | 1901 | self.test_session.update(required_min_echo_rx=150000) |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 1902 | self.vapi.bfd_udp_set_echo_source(sw_if_index=self.loopback0.sw_if_index) |
Klement Sekera | 239790f | 2017-02-16 10:53:53 +0100 | [diff] [blame] | 1903 | self.test_session.send_packet() |
| 1904 | # should be turned on - loopback echo packets |
| 1905 | timeout_at = None |
| 1906 | timeout_ok = False |
| 1907 | for dummy in range(10 * self.vpp_session.detect_mult): |
| 1908 | p = self.pg0.wait_for_packet(1) |
| 1909 | if p[UDP].dport == BFD.udp_dport_echo: |
| 1910 | self.logger.debug(ppp("Got echo packet:", p)) |
| 1911 | if timeout_at is None: |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 1912 | timeout_at = ( |
| 1913 | time.time() |
| 1914 | + self.vpp_session.detect_mult |
| 1915 | * self.test_session.required_min_echo_rx |
| 1916 | / USEC_IN_SEC |
| 1917 | ) |
Klement Sekera | 239790f | 2017-02-16 10:53:53 +0100 | [diff] [blame] | 1918 | p[BFD_vpp_echo].checksum = getrandbits(64) |
John Lo | 1904c47 | 2017-03-10 17:15:22 -0500 | [diff] [blame] | 1919 | p[Ether].dst = self.pg0.local_mac |
Klement Sekera | 239790f | 2017-02-16 10:53:53 +0100 | [diff] [blame] | 1920 | self.logger.debug(ppp("Looping back modified echo packet:", p)) |
| 1921 | self.pg0.add_stream(p) |
| 1922 | self.pg_start() |
| 1923 | elif p.haslayer(BFD): |
| 1924 | self.logger.debug(ppp("Got packet:", p)) |
| 1925 | if "P" in p.sprintf("%BFD.flags%"): |
| 1926 | final = self.test_session.create_packet() |
| 1927 | final[BFD].flags = "F" |
| 1928 | self.test_session.send_packet(final) |
| 1929 | if p[BFD].state == BFDState.down: |
| 1930 | self.assertIsNotNone( |
| 1931 | timeout_at, |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 1932 | "Session went down before first echo packet received", |
| 1933 | ) |
Klement Sekera | 239790f | 2017-02-16 10:53:53 +0100 | [diff] [blame] | 1934 | now = time.time() |
| 1935 | self.assertGreaterEqual( |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 1936 | now, |
| 1937 | timeout_at, |
| 1938 | "Session timeout at %s, but is expected at %s" |
| 1939 | % (now, timeout_at), |
| 1940 | ) |
| 1941 | self.assert_equal( |
| 1942 | p[BFD].diag, BFDDiagCode.echo_function_failed, BFDDiagCode |
| 1943 | ) |
Klement Sekera | 239790f | 2017-02-16 10:53:53 +0100 | [diff] [blame] | 1944 | events = self.vapi.collect_events() |
| 1945 | self.assert_equal(len(events), 1, "number of bfd events") |
| 1946 | self.assert_equal(events[0].state, BFDState.down, BFDState) |
| 1947 | timeout_ok = True |
| 1948 | break |
| 1949 | else: |
| 1950 | raise Exception(ppp("Received unknown packet:", p)) |
| 1951 | self.test_session.send_packet() |
| 1952 | self.assertTrue(timeout_ok, "Expected timeout event didn't occur") |
| 1953 | |
Klement Sekera | c48829b | 2017-02-14 07:55:57 +0100 | [diff] [blame] | 1954 | def test_admin_up_down(self): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 1955 | """put session admin-up and admin-down""" |
Klement Sekera | c48829b | 2017-02-14 07:55:57 +0100 | [diff] [blame] | 1956 | bfd_session_up(self) |
| 1957 | self.vpp_session.admin_down() |
| 1958 | self.pg0.enable_capture() |
Ole Troan | 4376ab2 | 2021-03-03 10:40:05 +0100 | [diff] [blame] | 1959 | e = self.vapi.wait_for_event(1, "bfd_udp_session_event") |
Klement Sekera | c48829b | 2017-02-14 07:55:57 +0100 | [diff] [blame] | 1960 | verify_event(self, e, expected_state=BFDState.admin_down) |
| 1961 | for dummy in range(2): |
| 1962 | p = wait_for_bfd_packet(self) |
Klement Sekera | 7388448 | 2017-02-23 09:26:30 +0100 | [diff] [blame] | 1963 | self.assert_equal(p[BFD].state, BFDState.admin_down, BFDState) |
Klement Sekera | c48829b | 2017-02-14 07:55:57 +0100 | [diff] [blame] | 1964 | # try to bring session up - shouldn't be possible |
| 1965 | self.test_session.update(state=BFDState.init) |
| 1966 | self.test_session.send_packet() |
| 1967 | for dummy in range(2): |
| 1968 | p = wait_for_bfd_packet(self) |
Klement Sekera | 7388448 | 2017-02-23 09:26:30 +0100 | [diff] [blame] | 1969 | self.assert_equal(p[BFD].state, BFDState.admin_down, BFDState) |
Klement Sekera | c48829b | 2017-02-14 07:55:57 +0100 | [diff] [blame] | 1970 | self.vpp_session.admin_up() |
| 1971 | self.test_session.update(state=BFDState.down) |
Ole Troan | 4376ab2 | 2021-03-03 10:40:05 +0100 | [diff] [blame] | 1972 | e = self.vapi.wait_for_event(1, "bfd_udp_session_event") |
Klement Sekera | c48829b | 2017-02-14 07:55:57 +0100 | [diff] [blame] | 1973 | verify_event(self, e, expected_state=BFDState.down) |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 1974 | p = wait_for_bfd_packet(self, pcap_time_min=time.time() - self.vpp_clock_offset) |
Klement Sekera | 7388448 | 2017-02-23 09:26:30 +0100 | [diff] [blame] | 1975 | self.assert_equal(p[BFD].state, BFDState.down, BFDState) |
Klement Sekera | c48829b | 2017-02-14 07:55:57 +0100 | [diff] [blame] | 1976 | self.test_session.send_packet() |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 1977 | p = wait_for_bfd_packet(self, pcap_time_min=time.time() - self.vpp_clock_offset) |
Klement Sekera | 7388448 | 2017-02-23 09:26:30 +0100 | [diff] [blame] | 1978 | self.assert_equal(p[BFD].state, BFDState.init, BFDState) |
Ole Troan | 4376ab2 | 2021-03-03 10:40:05 +0100 | [diff] [blame] | 1979 | e = self.vapi.wait_for_event(1, "bfd_udp_session_event") |
Klement Sekera | c48829b | 2017-02-14 07:55:57 +0100 | [diff] [blame] | 1980 | verify_event(self, e, expected_state=BFDState.init) |
| 1981 | self.test_session.update(state=BFDState.up) |
| 1982 | self.test_session.send_packet() |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 1983 | p = wait_for_bfd_packet(self, pcap_time_min=time.time() - self.vpp_clock_offset) |
Klement Sekera | 7388448 | 2017-02-23 09:26:30 +0100 | [diff] [blame] | 1984 | self.assert_equal(p[BFD].state, BFDState.up, BFDState) |
Ole Troan | 4376ab2 | 2021-03-03 10:40:05 +0100 | [diff] [blame] | 1985 | e = self.vapi.wait_for_event(1, "bfd_udp_session_event") |
Klement Sekera | c48829b | 2017-02-14 07:55:57 +0100 | [diff] [blame] | 1986 | verify_event(self, e, expected_state=BFDState.up) |
| 1987 | |
Klement Sekera | 239790f | 2017-02-16 10:53:53 +0100 | [diff] [blame] | 1988 | def test_config_change_remote_demand(self): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 1989 | """configuration change while peer in demand mode""" |
Klement Sekera | 239790f | 2017-02-16 10:53:53 +0100 | [diff] [blame] | 1990 | bfd_session_up(self) |
| 1991 | demand = self.test_session.create_packet() |
| 1992 | demand[BFD].flags = "D" |
| 1993 | self.test_session.send_packet(demand) |
| 1994 | self.vpp_session.modify_parameters( |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 1995 | required_min_rx=2 * self.vpp_session.required_min_rx |
| 1996 | ) |
| 1997 | p = wait_for_bfd_packet(self, pcap_time_min=time.time() - self.vpp_clock_offset) |
Klement Sekera | 239790f | 2017-02-16 10:53:53 +0100 | [diff] [blame] | 1998 | # poll bit must be set |
| 1999 | self.assertIn("P", p.sprintf("%BFD.flags%"), "Poll bit not set") |
| 2000 | # terminate poll sequence |
| 2001 | final = self.test_session.create_packet() |
| 2002 | final[BFD].flags = "D+F" |
| 2003 | self.test_session.send_packet(final) |
| 2004 | # vpp should be quiet now again |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 2005 | transmit_time = ( |
| 2006 | 0.9 |
| 2007 | * max(self.vpp_session.required_min_rx, self.test_session.desired_min_tx) |
Klement Sekera | 239790f | 2017-02-16 10:53:53 +0100 | [diff] [blame] | 2008 | / USEC_IN_SEC |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 2009 | ) |
Klement Sekera | 239790f | 2017-02-16 10:53:53 +0100 | [diff] [blame] | 2010 | count = 0 |
| 2011 | for dummy in range(self.test_session.detect_mult * 2): |
Paul Vinciguerra | 0f6602c | 2019-03-10 09:10:54 -0700 | [diff] [blame] | 2012 | self.sleep(transmit_time) |
Klement Sekera | 239790f | 2017-02-16 10:53:53 +0100 | [diff] [blame] | 2013 | self.test_session.send_packet(demand) |
| 2014 | try: |
| 2015 | p = wait_for_bfd_packet(self, timeout=0) |
| 2016 | self.logger.error(ppp("Received unexpected packet:", p)) |
| 2017 | count += 1 |
| 2018 | except CaptureTimeoutError: |
| 2019 | pass |
| 2020 | events = self.vapi.collect_events() |
| 2021 | for e in events: |
| 2022 | self.logger.error("Received unexpected event: %s", e) |
| 2023 | self.assert_equal(count, 0, "number of packets received") |
| 2024 | self.assert_equal(len(events), 0, "number of events received") |
| 2025 | |
Klement Sekera | f3bcdbf | 2017-05-02 07:38:01 +0200 | [diff] [blame] | 2026 | def test_intf_deleted(self): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 2027 | """interface with bfd session deleted""" |
Klement Sekera | beaded5 | 2018-06-24 10:30:37 +0200 | [diff] [blame] | 2028 | intf = VppLoInterface(self) |
Klement Sekera | f3bcdbf | 2017-05-02 07:38:01 +0200 | [diff] [blame] | 2029 | intf.config_ip4() |
| 2030 | intf.admin_up() |
| 2031 | sw_if_index = intf.sw_if_index |
Abdel Baig | 17a9181 | 2024-09-03 11:52:20 -0400 | [diff] [blame] | 2032 | |
| 2033 | # Setup routing info for multihop |
| 2034 | set_ipv4_pfx_route_info(self, intf, BFD_IPV4_REMOTE_ADDR2, False) |
| 2035 | |
| 2036 | vpp_session = VppBFDUDPSession( |
| 2037 | self, |
| 2038 | intf, |
| 2039 | self.dst_ip_net, |
| 2040 | local_addr=self.src_ip_net, |
| 2041 | multihop=self.multihop, |
| 2042 | ) |
| 2043 | |
Klement Sekera | f3bcdbf | 2017-05-02 07:38:01 +0200 | [diff] [blame] | 2044 | vpp_session.add_vpp_config() |
| 2045 | vpp_session.admin_up() |
| 2046 | intf.remove_vpp_config() |
Abdel Baig | 17a9181 | 2024-09-03 11:52:20 -0400 | [diff] [blame] | 2047 | |
| 2048 | # BFD session is removed only for single-hop session |
| 2049 | if self.multihop: |
| 2050 | self.assertTrue(vpp_session.query_vpp_config()) |
| 2051 | else: |
| 2052 | e = self.vapi.wait_for_event(1, "bfd_udp_session_event") |
| 2053 | self.assert_equal(e.sw_if_index, sw_if_index, "sw_if_index") |
| 2054 | self.assertFalse(vpp_session.query_vpp_config()) |
Klement Sekera | f3bcdbf | 2017-05-02 07:38:01 +0200 | [diff] [blame] | 2055 | |
Klement Sekera | d3ba515 | 2017-02-14 03:09:17 +0100 | [diff] [blame] | 2056 | |
Abdel Baig | 17a9181 | 2024-09-03 11:52:20 -0400 | [diff] [blame] | 2057 | @parameterized_class( |
| 2058 | [ |
| 2059 | {"multihop": False}, |
| 2060 | {"multihop": True}, |
| 2061 | ] |
| 2062 | ) |
Andrew Yourtchenko | 06f3281 | 2021-01-14 10:19:08 +0000 | [diff] [blame] | 2063 | @tag_run_solo |
Andrew Yourtchenko | 8dc0d48 | 2021-01-29 13:17:19 +0000 | [diff] [blame] | 2064 | @tag_fixme_vpp_workers |
Klement Sekera | d3ba515 | 2017-02-14 03:09:17 +0100 | [diff] [blame] | 2065 | class BFD6TestCase(VppTestCase): |
Klement Sekera | d3ba515 | 2017-02-14 03:09:17 +0100 | [diff] [blame] | 2066 | pg0 = None |
Abdel Baig | 17a9181 | 2024-09-03 11:52:20 -0400 | [diff] [blame] | 2067 | interface0 = None |
Klement Sekera | d3ba515 | 2017-02-14 03:09:17 +0100 | [diff] [blame] | 2068 | vpp_clock_offset = None |
| 2069 | vpp_session = None |
| 2070 | test_session = None |
Abdel Baig | 17a9181 | 2024-09-03 11:52:20 -0400 | [diff] [blame] | 2071 | src_ip6_net = "" |
| 2072 | dst_ip6_net = "" |
Klement Sekera | d3ba515 | 2017-02-14 03:09:17 +0100 | [diff] [blame] | 2073 | |
Klement Sekera | 46a87ad | 2017-01-02 08:22:23 +0100 | [diff] [blame] | 2074 | @classmethod |
| 2075 | def setUpClass(cls): |
| 2076 | super(BFD6TestCase, cls).setUpClass() |
Abdel Baig | 17a9181 | 2024-09-03 11:52:20 -0400 | [diff] [blame] | 2077 | hoptype_str = "MultiHop" if cls.multihop else "SingleHop" |
| 2078 | cls.__doc__ = ( |
| 2079 | f"""""Bidirectional Forwarding Detection (BFD) - IPv6, {hoptype_str}""" |
| 2080 | ) |
Damjan Marion | 07a3857 | 2018-01-21 06:44:18 -0800 | [diff] [blame] | 2081 | cls.vapi.cli("set log class bfd level debug") |
Klement Sekera | 46a87ad | 2017-01-02 08:22:23 +0100 | [diff] [blame] | 2082 | try: |
| 2083 | cls.create_pg_interfaces([0]) |
| 2084 | cls.pg0.config_ip6() |
| 2085 | cls.pg0.configure_ipv6_neighbors() |
| 2086 | cls.pg0.admin_up() |
| 2087 | cls.pg0.resolve_ndp() |
Klement Sekera | b9ef273 | 2018-06-24 22:49:33 +0200 | [diff] [blame] | 2088 | cls.create_loopback_interfaces(1) |
Klement Sekera | 239790f | 2017-02-16 10:53:53 +0100 | [diff] [blame] | 2089 | cls.loopback0 = cls.lo_interfaces[0] |
| 2090 | cls.loopback0.config_ip6() |
| 2091 | cls.loopback0.admin_up() |
Klement Sekera | 46a87ad | 2017-01-02 08:22:23 +0100 | [diff] [blame] | 2092 | |
| 2093 | except Exception: |
| 2094 | super(BFD6TestCase, cls).tearDownClass() |
| 2095 | raise |
| 2096 | |
Paul Vinciguerra | 8d991d9 | 2019-01-25 14:05:48 -0800 | [diff] [blame] | 2097 | @classmethod |
| 2098 | def tearDownClass(cls): |
| 2099 | super(BFD6TestCase, cls).tearDownClass() |
| 2100 | |
Klement Sekera | 46a87ad | 2017-01-02 08:22:23 +0100 | [diff] [blame] | 2101 | def setUp(self): |
| 2102 | super(BFD6TestCase, self).setUp() |
Klement Sekera | b17dd96 | 2017-01-09 07:43:48 +0100 | [diff] [blame] | 2103 | self.factory = AuthKeyFactory() |
Klement Sekera | 46a87ad | 2017-01-02 08:22:23 +0100 | [diff] [blame] | 2104 | self.vapi.want_bfd_events() |
Klement Sekera | d3ba515 | 2017-02-14 03:09:17 +0100 | [diff] [blame] | 2105 | self.pg0.enable_capture() |
Abdel Baig | 17a9181 | 2024-09-03 11:52:20 -0400 | [diff] [blame] | 2106 | set_ipv6_pfx_route_info(self, self.pg0, BFD_IPV6_REMOTE_ADDR, True) |
| 2107 | |
Klement Sekera | 46a87ad | 2017-01-02 08:22:23 +0100 | [diff] [blame] | 2108 | try: |
Abdel Baig | 17a9181 | 2024-09-03 11:52:20 -0400 | [diff] [blame] | 2109 | if self.multihop: |
| 2110 | self.interface0 = None |
| 2111 | self.bfd_udp4_sessions = self.statistics[BFD_STATS_V4_MH_PATH] |
| 2112 | self.bfd_udp6_sessions = self.statistics[BFD_STATS_V6_MH_PATH] |
| 2113 | else: |
| 2114 | self.interface0 = self.pg0 |
| 2115 | self.bfd_udp4_sessions = self.statistics[BFD_STATS_V4_SH_PATH] |
| 2116 | self.bfd_udp6_sessions = self.statistics[BFD_STATS_V6_SH_PATH] |
| 2117 | |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 2118 | self.vpp_session = VppBFDUDPSession( |
Abdel Baig | 17a9181 | 2024-09-03 11:52:20 -0400 | [diff] [blame] | 2119 | self, |
| 2120 | self.interface0, |
| 2121 | self.dst_ip6_net, |
| 2122 | local_addr=self.src_ip6_net, |
| 2123 | af=AF_INET6, |
| 2124 | multihop=self.multihop, |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 2125 | ) |
Klement Sekera | 46a87ad | 2017-01-02 08:22:23 +0100 | [diff] [blame] | 2126 | self.vpp_session.add_vpp_config() |
| 2127 | self.vpp_session.admin_up() |
Abdel Baig | 17a9181 | 2024-09-03 11:52:20 -0400 | [diff] [blame] | 2128 | self.test_session = BFDTestSession( |
| 2129 | self, |
| 2130 | self.pg0, |
| 2131 | AF_INET6, |
| 2132 | local_addr=self.src_ip6_net, |
| 2133 | peer_addr=self.dst_ip6_net, |
| 2134 | multihop=self.multihop, |
| 2135 | ) |
Klement Sekera | 46a87ad | 2017-01-02 08:22:23 +0100 | [diff] [blame] | 2136 | self.logger.debug(self.vapi.cli("show adj nbr")) |
Jakub Grajciar | 4682feb | 2019-09-02 13:28:52 +0200 | [diff] [blame] | 2137 | except BaseException: |
Klement Sekera | 46a87ad | 2017-01-02 08:22:23 +0100 | [diff] [blame] | 2138 | self.vapi.want_bfd_events(enable_disable=0) |
| 2139 | raise |
| 2140 | |
| 2141 | def tearDown(self): |
Abdel Baig | 17a9181 | 2024-09-03 11:52:20 -0400 | [diff] [blame] | 2142 | self.vpp_session.remove_vpp_config() |
Klement Sekera | d3ba515 | 2017-02-14 03:09:17 +0100 | [diff] [blame] | 2143 | if not self.vpp_dead: |
| 2144 | self.vapi.want_bfd_events(enable_disable=0) |
| 2145 | self.vapi.collect_events() # clear the event queue |
| 2146 | super(BFD6TestCase, self).tearDown() |
Klement Sekera | b17dd96 | 2017-01-09 07:43:48 +0100 | [diff] [blame] | 2147 | |
| 2148 | def test_session_up(self): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 2149 | """bring BFD session up""" |
Klement Sekera | d3ba515 | 2017-02-14 03:09:17 +0100 | [diff] [blame] | 2150 | bfd_session_up(self) |
Abdel Baig | 17a9181 | 2024-09-03 11:52:20 -0400 | [diff] [blame] | 2151 | if self.multihop: |
| 2152 | bfd_udp4_sessions = self.statistics[BFD_STATS_V4_MH_PATH] |
| 2153 | bfd_udp6_sessions = self.statistics[BFD_STATS_V6_MH_PATH] |
| 2154 | else: |
| 2155 | bfd_udp4_sessions = self.statistics[BFD_STATS_V4_SH_PATH] |
| 2156 | bfd_udp6_sessions = self.statistics[BFD_STATS_V6_SH_PATH] |
| 2157 | |
Klement Sekera | cdaf0d8 | 2022-02-14 20:20:22 +0000 | [diff] [blame] | 2158 | self.assert_equal(bfd_udp4_sessions, self.bfd_udp4_sessions) |
| 2159 | self.assert_equal(bfd_udp6_sessions - self.bfd_udp6_sessions, 1) |
Klement Sekera | b17dd96 | 2017-01-09 07:43:48 +0100 | [diff] [blame] | 2160 | |
Klement Sekera | 7388448 | 2017-02-23 09:26:30 +0100 | [diff] [blame] | 2161 | def test_session_up_by_ip(self): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 2162 | """bring BFD session up - first frame looked up by address pair""" |
Klement Sekera | 7388448 | 2017-02-23 09:26:30 +0100 | [diff] [blame] | 2163 | self.logger.info("BFD: Sending Slow control frame") |
| 2164 | self.test_session.update(my_discriminator=randint(0, 40000000)) |
| 2165 | self.test_session.send_packet() |
| 2166 | self.pg0.enable_capture() |
| 2167 | p = self.pg0.wait_for_packet(1) |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 2168 | self.assert_equal( |
| 2169 | p[BFD].your_discriminator, |
| 2170 | self.test_session.my_discriminator, |
| 2171 | "BFD - your discriminator", |
| 2172 | ) |
Klement Sekera | 7388448 | 2017-02-23 09:26:30 +0100 | [diff] [blame] | 2173 | self.assert_equal(p[BFD].state, BFDState.init, BFDState) |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 2174 | self.test_session.update( |
| 2175 | your_discriminator=p[BFD].my_discriminator, state=BFDState.up |
| 2176 | ) |
Klement Sekera | 7388448 | 2017-02-23 09:26:30 +0100 | [diff] [blame] | 2177 | self.logger.info("BFD: Waiting for event") |
Ole Troan | 4376ab2 | 2021-03-03 10:40:05 +0100 | [diff] [blame] | 2178 | e = self.vapi.wait_for_event(1, "bfd_udp_session_event") |
Klement Sekera | 7388448 | 2017-02-23 09:26:30 +0100 | [diff] [blame] | 2179 | verify_event(self, e, expected_state=BFDState.init) |
| 2180 | self.logger.info("BFD: Sending Up") |
| 2181 | self.test_session.send_packet() |
| 2182 | self.logger.info("BFD: Waiting for event") |
Ole Troan | 4376ab2 | 2021-03-03 10:40:05 +0100 | [diff] [blame] | 2183 | e = self.vapi.wait_for_event(1, "bfd_udp_session_event") |
Klement Sekera | 7388448 | 2017-02-23 09:26:30 +0100 | [diff] [blame] | 2184 | verify_event(self, e, expected_state=BFDState.up) |
| 2185 | self.logger.info("BFD: Session is Up") |
| 2186 | self.test_session.update(state=BFDState.up) |
| 2187 | self.test_session.send_packet() |
| 2188 | self.assert_equal(self.vpp_session.state, BFDState.up, BFDState) |
| 2189 | |
Klement Sekera | b17dd96 | 2017-01-09 07:43:48 +0100 | [diff] [blame] | 2190 | def test_hold_up(self): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 2191 | """hold BFD session up""" |
Klement Sekera | d3ba515 | 2017-02-14 03:09:17 +0100 | [diff] [blame] | 2192 | bfd_session_up(self) |
Klement Sekera | aeeac3b | 2017-02-14 07:11:52 +0100 | [diff] [blame] | 2193 | for dummy in range(self.test_session.detect_mult * 2): |
Klement Sekera | d3ba515 | 2017-02-14 03:09:17 +0100 | [diff] [blame] | 2194 | wait_for_bfd_packet(self) |
Klement Sekera | b17dd96 | 2017-01-09 07:43:48 +0100 | [diff] [blame] | 2195 | self.test_session.send_packet() |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 2196 | self.assert_equal(len(self.vapi.collect_events()), 0, "number of bfd events") |
Klement Sekera | b17dd96 | 2017-01-09 07:43:48 +0100 | [diff] [blame] | 2197 | self.assert_equal(self.vpp_session.state, BFDState.up, BFDState) |
| 2198 | |
Klement Sekera | aeeac3b | 2017-02-14 07:11:52 +0100 | [diff] [blame] | 2199 | def test_echo_looped_back(self): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 2200 | """echo packets looped back""" |
Abdel Baig | 17a9181 | 2024-09-03 11:52:20 -0400 | [diff] [blame] | 2201 | |
| 2202 | if self.multihop: |
| 2203 | self.skipTest( |
| 2204 | f"Skipping because echo functionality is not supported with multihop" |
| 2205 | ) |
| 2206 | |
Klement Sekera | cdaf0d8 | 2022-02-14 20:20:22 +0000 | [diff] [blame] | 2207 | bfd_session_up(self) |
| 2208 | stats_before = bfd_grab_stats_snapshot(self) |
Klement Sekera | aeeac3b | 2017-02-14 07:11:52 +0100 | [diff] [blame] | 2209 | self.pg0.enable_capture() |
| 2210 | echo_packet_count = 10 |
| 2211 | # random source port low enough to increment a few times.. |
| 2212 | udp_sport_tx = randint(1, 50000) |
| 2213 | udp_sport_rx = udp_sport_tx |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 2214 | echo_packet = ( |
| 2215 | Ether(src=self.pg0.remote_mac, dst=self.pg0.local_mac) |
| 2216 | / IPv6(src=self.pg0.remote_ip6, dst=self.pg0.remote_ip6) |
| 2217 | / UDP(dport=BFD.udp_dport_echo) |
| 2218 | / Raw("this should be looped back") |
| 2219 | ) |
Klement Sekera | aeeac3b | 2017-02-14 07:11:52 +0100 | [diff] [blame] | 2220 | for dummy in range(echo_packet_count): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 2221 | self.sleep(0.01, "delay between echo packets") |
Klement Sekera | aeeac3b | 2017-02-14 07:11:52 +0100 | [diff] [blame] | 2222 | echo_packet[UDP].sport = udp_sport_tx |
| 2223 | udp_sport_tx += 1 |
| 2224 | self.logger.debug(ppp("Sending packet:", echo_packet)) |
| 2225 | self.pg0.add_stream(echo_packet) |
| 2226 | self.pg_start() |
Klement Sekera | cdaf0d8 | 2022-02-14 20:20:22 +0000 | [diff] [blame] | 2227 | counter = 0 |
| 2228 | bfd_control_packets_rx = 0 |
| 2229 | while counter < echo_packet_count: |
Klement Sekera | aeeac3b | 2017-02-14 07:11:52 +0100 | [diff] [blame] | 2230 | p = self.pg0.wait_for_packet(1) |
| 2231 | self.logger.debug(ppp("Got packet:", p)) |
| 2232 | ether = p[Ether] |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 2233 | self.assert_equal(self.pg0.remote_mac, ether.dst, "Destination MAC") |
Klement Sekera | aeeac3b | 2017-02-14 07:11:52 +0100 | [diff] [blame] | 2234 | self.assert_equal(self.pg0.local_mac, ether.src, "Source MAC") |
| 2235 | ip = p[IPv6] |
| 2236 | self.assert_equal(self.pg0.remote_ip6, ip.dst, "Destination IP") |
Klement Sekera | aeeac3b | 2017-02-14 07:11:52 +0100 | [diff] [blame] | 2237 | udp = p[UDP] |
Klement Sekera | cdaf0d8 | 2022-02-14 20:20:22 +0000 | [diff] [blame] | 2238 | if udp.dport == BFD.udp_dport: |
| 2239 | bfd_control_packets_rx += 1 |
| 2240 | continue |
| 2241 | self.assert_equal(self.pg0.remote_ip6, ip.src, "Source IP") |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 2242 | self.assert_equal(udp.dport, BFD.udp_dport_echo, "UDP destination port") |
Klement Sekera | aeeac3b | 2017-02-14 07:11:52 +0100 | [diff] [blame] | 2243 | self.assert_equal(udp.sport, udp_sport_rx, "UDP source port") |
| 2244 | udp_sport_rx += 1 |
Klement Sekera | 239790f | 2017-02-16 10:53:53 +0100 | [diff] [blame] | 2245 | # need to compare the hex payload here, otherwise BFD_vpp_echo |
| 2246 | # gets in way |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 2247 | self.assertEqual( |
| 2248 | scapy.compat.raw(p[UDP].payload), |
| 2249 | scapy.compat.raw(echo_packet[UDP].payload), |
| 2250 | "Received packet is not the echo packet sent", |
| 2251 | ) |
Klement Sekera | cdaf0d8 | 2022-02-14 20:20:22 +0000 | [diff] [blame] | 2252 | counter += 1 |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 2253 | self.assert_equal( |
| 2254 | udp_sport_tx, |
| 2255 | udp_sport_rx, |
| 2256 | "UDP source port (== ECHO packet identifier for test purposes)", |
| 2257 | ) |
Klement Sekera | cdaf0d8 | 2022-02-14 20:20:22 +0000 | [diff] [blame] | 2258 | stats_after = bfd_grab_stats_snapshot(self) |
| 2259 | diff = bfd_stats_diff(stats_before, stats_after) |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 2260 | self.assertEqual(0, diff.rx, "RX counter bumped but no BFD packets sent") |
Klement Sekera | cdaf0d8 | 2022-02-14 20:20:22 +0000 | [diff] [blame] | 2261 | self.assertEqual( |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 2262 | 0, diff.rx_echo, "RX echo counter bumped but no BFD session exists" |
| 2263 | ) |
| 2264 | self.assertEqual( |
| 2265 | 0, diff.tx_echo, "TX echo counter bumped but no BFD session exists" |
| 2266 | ) |
Klement Sekera | 239790f | 2017-02-16 10:53:53 +0100 | [diff] [blame] | 2267 | |
| 2268 | def test_echo(self): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 2269 | """echo function""" |
Abdel Baig | 17a9181 | 2024-09-03 11:52:20 -0400 | [diff] [blame] | 2270 | |
| 2271 | if self.multihop: |
| 2272 | self.skipTest( |
| 2273 | f"Skipping because echo functionality is not supported with multihop" |
| 2274 | ) |
| 2275 | |
Klement Sekera | cdaf0d8 | 2022-02-14 20:20:22 +0000 | [diff] [blame] | 2276 | stats_before = bfd_grab_stats_snapshot(self) |
Klement Sekera | 239790f | 2017-02-16 10:53:53 +0100 | [diff] [blame] | 2277 | bfd_session_up(self) |
Klement Sekera | 3cfa558 | 2017-04-19 07:10:58 +0000 | [diff] [blame] | 2278 | self.test_session.update(required_min_echo_rx=150000) |
Klement Sekera | 239790f | 2017-02-16 10:53:53 +0100 | [diff] [blame] | 2279 | self.test_session.send_packet() |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 2280 | detection_time = ( |
| 2281 | self.test_session.detect_mult |
| 2282 | * self.vpp_session.required_min_rx |
| 2283 | / USEC_IN_SEC |
| 2284 | ) |
Klement Sekera | 239790f | 2017-02-16 10:53:53 +0100 | [diff] [blame] | 2285 | # echo shouldn't work without echo source set |
Klement Sekera | 3cfa558 | 2017-04-19 07:10:58 +0000 | [diff] [blame] | 2286 | for dummy in range(10): |
| 2287 | sleep = self.vpp_session.required_min_rx / USEC_IN_SEC |
Klement Sekera | 239790f | 2017-02-16 10:53:53 +0100 | [diff] [blame] | 2288 | self.sleep(sleep, "delay before sending bfd packet") |
| 2289 | self.test_session.send_packet() |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 2290 | p = wait_for_bfd_packet(self, pcap_time_min=time.time() - self.vpp_clock_offset) |
| 2291 | self.assert_equal( |
| 2292 | p[BFD].required_min_rx_interval, |
| 2293 | self.vpp_session.required_min_rx, |
| 2294 | "BFD required min rx interval", |
| 2295 | ) |
Klement Sekera | 3cfa558 | 2017-04-19 07:10:58 +0000 | [diff] [blame] | 2296 | self.test_session.send_packet() |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 2297 | self.vapi.bfd_udp_set_echo_source(sw_if_index=self.loopback0.sw_if_index) |
Klement Sekera | 3cfa558 | 2017-04-19 07:10:58 +0000 | [diff] [blame] | 2298 | echo_seen = False |
Klement Sekera | 239790f | 2017-02-16 10:53:53 +0100 | [diff] [blame] | 2299 | # should be turned on - loopback echo packets |
| 2300 | for dummy in range(3): |
| 2301 | loop_until = time.time() + 0.75 * detection_time |
| 2302 | while time.time() < loop_until: |
| 2303 | p = self.pg0.wait_for_packet(1) |
| 2304 | self.logger.debug(ppp("Got packet:", p)) |
| 2305 | if p[UDP].dport == BFD.udp_dport_echo: |
| 2306 | self.assert_equal( |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 2307 | p[IPv6].dst, self.pg0.local_ip6, "BFD ECHO dst IP" |
| 2308 | ) |
| 2309 | self.assertNotEqual( |
| 2310 | p[IPv6].src, |
| 2311 | self.loopback0.local_ip6, |
| 2312 | "BFD ECHO src IP equal to loopback IP", |
| 2313 | ) |
Klement Sekera | 239790f | 2017-02-16 10:53:53 +0100 | [diff] [blame] | 2314 | self.logger.debug(ppp("Looping back packet:", p)) |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 2315 | self.assert_equal( |
| 2316 | p[Ether].dst, |
| 2317 | self.pg0.remote_mac, |
| 2318 | "ECHO packet destination MAC address", |
| 2319 | ) |
Klement Sekera | cdaf0d8 | 2022-02-14 20:20:22 +0000 | [diff] [blame] | 2320 | self.test_session.rx_packets_echo += 1 |
| 2321 | self.test_session.tx_packets_echo += 1 |
John Lo | 1904c47 | 2017-03-10 17:15:22 -0500 | [diff] [blame] | 2322 | p[Ether].dst = self.pg0.local_mac |
Klement Sekera | 239790f | 2017-02-16 10:53:53 +0100 | [diff] [blame] | 2323 | self.pg0.add_stream(p) |
| 2324 | self.pg_start() |
Klement Sekera | 3cfa558 | 2017-04-19 07:10:58 +0000 | [diff] [blame] | 2325 | echo_seen = True |
Klement Sekera | 239790f | 2017-02-16 10:53:53 +0100 | [diff] [blame] | 2326 | elif p.haslayer(BFD): |
Klement Sekera | cdaf0d8 | 2022-02-14 20:20:22 +0000 | [diff] [blame] | 2327 | self.test_session.rx_packets += 1 |
Klement Sekera | 3cfa558 | 2017-04-19 07:10:58 +0000 | [diff] [blame] | 2328 | if echo_seen: |
| 2329 | self.assertGreaterEqual( |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 2330 | p[BFD].required_min_rx_interval, 1000000 |
| 2331 | ) |
Klement Sekera | 239790f | 2017-02-16 10:53:53 +0100 | [diff] [blame] | 2332 | if "P" in p.sprintf("%BFD.flags%"): |
| 2333 | final = self.test_session.create_packet() |
| 2334 | final[BFD].flags = "F" |
| 2335 | self.test_session.send_packet(final) |
| 2336 | else: |
| 2337 | raise Exception(ppp("Received unknown packet:", p)) |
| 2338 | |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 2339 | self.assert_equal( |
| 2340 | len(self.vapi.collect_events()), 0, "number of bfd events" |
| 2341 | ) |
Klement Sekera | 239790f | 2017-02-16 10:53:53 +0100 | [diff] [blame] | 2342 | self.test_session.send_packet() |
Klement Sekera | 3cfa558 | 2017-04-19 07:10:58 +0000 | [diff] [blame] | 2343 | self.assertTrue(echo_seen, "No echo packets received") |
Klement Sekera | aeeac3b | 2017-02-14 07:11:52 +0100 | [diff] [blame] | 2344 | |
Klement Sekera | cdaf0d8 | 2022-02-14 20:20:22 +0000 | [diff] [blame] | 2345 | stats_after = bfd_grab_stats_snapshot(self) |
| 2346 | diff = bfd_stats_diff(stats_before, stats_after) |
| 2347 | # our rx is vpp tx and vice versa, also tolerate one packet off |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 2348 | self.assert_in_range( |
| 2349 | self.test_session.tx_packets, diff.rx - 1, diff.rx + 1, "RX counter" |
| 2350 | ) |
| 2351 | self.assert_in_range( |
| 2352 | self.test_session.rx_packets, diff.tx - 1, diff.tx + 1, "TX counter" |
| 2353 | ) |
| 2354 | self.assert_in_range( |
| 2355 | self.test_session.tx_packets_echo, |
| 2356 | diff.rx_echo - 1, |
| 2357 | diff.rx_echo + 1, |
| 2358 | "RX echo counter", |
| 2359 | ) |
| 2360 | self.assert_in_range( |
| 2361 | self.test_session.rx_packets_echo, |
| 2362 | diff.tx_echo - 1, |
| 2363 | diff.tx_echo + 1, |
| 2364 | "TX echo counter", |
| 2365 | ) |
Klement Sekera | cdaf0d8 | 2022-02-14 20:20:22 +0000 | [diff] [blame] | 2366 | |
Klement Sekera | f3bcdbf | 2017-05-02 07:38:01 +0200 | [diff] [blame] | 2367 | def test_intf_deleted(self): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 2368 | """interface with bfd session deleted""" |
Klement Sekera | beaded5 | 2018-06-24 10:30:37 +0200 | [diff] [blame] | 2369 | intf = VppLoInterface(self) |
Klement Sekera | f3bcdbf | 2017-05-02 07:38:01 +0200 | [diff] [blame] | 2370 | intf.config_ip6() |
| 2371 | intf.admin_up() |
| 2372 | sw_if_index = intf.sw_if_index |
Abdel Baig | 17a9181 | 2024-09-03 11:52:20 -0400 | [diff] [blame] | 2373 | |
| 2374 | # Setup routing info for multihop |
| 2375 | set_ipv6_pfx_route_info(self, intf, BFD_IPV6_REMOTE_ADDR2, False) |
| 2376 | |
| 2377 | vpp_session = VppBFDUDPSession( |
| 2378 | self, |
| 2379 | intf, |
| 2380 | self.dst_ip6_net, |
| 2381 | local_addr=self.src_ip6_net, |
| 2382 | af=AF_INET6, |
| 2383 | multihop=self.multihop, |
| 2384 | ) |
| 2385 | |
Klement Sekera | f3bcdbf | 2017-05-02 07:38:01 +0200 | [diff] [blame] | 2386 | vpp_session.add_vpp_config() |
| 2387 | vpp_session.admin_up() |
| 2388 | intf.remove_vpp_config() |
Abdel Baig | 17a9181 | 2024-09-03 11:52:20 -0400 | [diff] [blame] | 2389 | |
| 2390 | # BFD session is removed only for single-hop session |
| 2391 | if self.multihop: |
| 2392 | self.assertTrue(vpp_session.query_vpp_config()) |
| 2393 | else: |
| 2394 | e = self.vapi.wait_for_event(1, "bfd_udp_session_event") |
| 2395 | self.assert_equal(e.sw_if_index, sw_if_index, "sw_if_index") |
| 2396 | self.assertFalse(vpp_session.query_vpp_config()) |
Klement Sekera | f3bcdbf | 2017-05-02 07:38:01 +0200 | [diff] [blame] | 2397 | |
Klement Sekera | b17dd96 | 2017-01-09 07:43:48 +0100 | [diff] [blame] | 2398 | |
Abdel Baig | 17a9181 | 2024-09-03 11:52:20 -0400 | [diff] [blame] | 2399 | @parameterized_class( |
| 2400 | [ |
| 2401 | {"multihop": False}, |
| 2402 | {"multihop": True}, |
| 2403 | ] |
| 2404 | ) |
Andrew Yourtchenko | 06f3281 | 2021-01-14 10:19:08 +0000 | [diff] [blame] | 2405 | @tag_run_solo |
Neale Ranns | 88fc83e | 2017-04-05 08:11:14 -0700 | [diff] [blame] | 2406 | class BFDFIBTestCase(VppTestCase): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 2407 | """BFD-FIB interactions (IPv6)""" |
Neale Ranns | 88fc83e | 2017-04-05 08:11:14 -0700 | [diff] [blame] | 2408 | |
| 2409 | vpp_session = None |
| 2410 | test_session = None |
Abdel Baig | 17a9181 | 2024-09-03 11:52:20 -0400 | [diff] [blame] | 2411 | src_ip6_net = "" |
| 2412 | dst_ip6_net = "" |
Neale Ranns | 88fc83e | 2017-04-05 08:11:14 -0700 | [diff] [blame] | 2413 | |
Paul Vinciguerra | 8d991d9 | 2019-01-25 14:05:48 -0800 | [diff] [blame] | 2414 | @classmethod |
| 2415 | def setUpClass(cls): |
| 2416 | super(BFDFIBTestCase, cls).setUpClass() |
Abdel Baig | 17a9181 | 2024-09-03 11:52:20 -0400 | [diff] [blame] | 2417 | hoptype_str = "MultiHop" if cls.multihop else "SingleHop" |
| 2418 | cls.__doc__ = f"""""BFD-FIB interactions (IPv6) - {hoptype_str}""" |
| 2419 | cls.vapi.cli("set log class bfd level debug") |
Paul Vinciguerra | 8d991d9 | 2019-01-25 14:05:48 -0800 | [diff] [blame] | 2420 | |
| 2421 | @classmethod |
| 2422 | def tearDownClass(cls): |
| 2423 | super(BFDFIBTestCase, cls).tearDownClass() |
| 2424 | |
Neale Ranns | 88fc83e | 2017-04-05 08:11:14 -0700 | [diff] [blame] | 2425 | def setUp(self): |
| 2426 | super(BFDFIBTestCase, self).setUp() |
| 2427 | self.create_pg_interfaces(range(1)) |
Abdel Baig | 17a9181 | 2024-09-03 11:52:20 -0400 | [diff] [blame] | 2428 | self.create_loopback_interfaces(1) |
| 2429 | self.loopback0 = self.lo_interfaces[0] |
| 2430 | self.loopback0.config_ip6() |
| 2431 | self.loopback0.admin_up() |
Neale Ranns | 88fc83e | 2017-04-05 08:11:14 -0700 | [diff] [blame] | 2432 | |
| 2433 | self.vapi.want_bfd_events() |
| 2434 | self.pg0.enable_capture() |
| 2435 | |
| 2436 | for i in self.pg_interfaces: |
| 2437 | i.admin_up() |
| 2438 | i.config_ip6() |
| 2439 | i.configure_ipv6_neighbors() |
| 2440 | |
Abdel Baig | 17a9181 | 2024-09-03 11:52:20 -0400 | [diff] [blame] | 2441 | set_ipv6_pfx_route_info(self, self.pg0, BFD_IPV6_REMOTE_ADDR, True) |
| 2442 | |
Neale Ranns | 88fc83e | 2017-04-05 08:11:14 -0700 | [diff] [blame] | 2443 | def tearDown(self): |
| 2444 | if not self.vpp_dead: |
Jakub Grajciar | 4682feb | 2019-09-02 13:28:52 +0200 | [diff] [blame] | 2445 | self.vapi.want_bfd_events(enable_disable=False) |
Neale Ranns | 88fc83e | 2017-04-05 08:11:14 -0700 | [diff] [blame] | 2446 | |
| 2447 | super(BFDFIBTestCase, self).tearDown() |
| 2448 | |
| 2449 | @staticmethod |
| 2450 | def pkt_is_not_data_traffic(p): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 2451 | """not data traffic implies BFD or the usual IPv6 ND/RA""" |
Neale Ranns | 88fc83e | 2017-04-05 08:11:14 -0700 | [diff] [blame] | 2452 | if p.haslayer(BFD) or is_ipv6_misc(p): |
| 2453 | return True |
| 2454 | return False |
| 2455 | |
| 2456 | def test_session_with_fib(self): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 2457 | """BFD-FIB interactions""" |
Neale Ranns | 88fc83e | 2017-04-05 08:11:14 -0700 | [diff] [blame] | 2458 | |
| 2459 | # packets to match against both of the routes |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 2460 | p = [ |
| 2461 | ( |
| 2462 | Ether(dst=self.pg0.local_mac, src=self.pg0.remote_mac) |
| 2463 | / IPv6(src="3001::1", dst="2001::1") |
| 2464 | / UDP(sport=1234, dport=1234) |
| 2465 | / Raw(b"\xa5" * 100) |
| 2466 | ), |
| 2467 | ( |
| 2468 | Ether(dst=self.pg0.local_mac, src=self.pg0.remote_mac) |
| 2469 | / IPv6(src="3001::1", dst="2002::1") |
| 2470 | / UDP(sport=1234, dport=1234) |
| 2471 | / Raw(b"\xa5" * 100) |
| 2472 | ), |
| 2473 | ] |
Neale Ranns | 88fc83e | 2017-04-05 08:11:14 -0700 | [diff] [blame] | 2474 | |
Abdel Baig | 17a9181 | 2024-09-03 11:52:20 -0400 | [diff] [blame] | 2475 | # Two different routes via a next-hop that will have a BFD session. |
| 2476 | # One of the routes is non-recursive route only for single-hop. |
| 2477 | if self.multihop: |
| 2478 | intf_index = 0xFFFFFFFF |
| 2479 | else: |
| 2480 | intf_index = self.pg0.sw_if_index |
| 2481 | |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 2482 | ip_2001_s_64 = VppIpRoute( |
| 2483 | self, |
| 2484 | "2001::", |
| 2485 | 64, |
Abdel Baig | 17a9181 | 2024-09-03 11:52:20 -0400 | [diff] [blame] | 2486 | [VppRoutePath(self.dst_ip6_net, intf_index)], |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 2487 | ) |
| 2488 | ip_2002_s_64 = VppIpRoute( |
Abdel Baig | 17a9181 | 2024-09-03 11:52:20 -0400 | [diff] [blame] | 2489 | self, "2002::", 64, [VppRoutePath(self.dst_ip6_net, 0xFFFFFFFF)] |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 2490 | ) |
Neale Ranns | 88fc83e | 2017-04-05 08:11:14 -0700 | [diff] [blame] | 2491 | ip_2001_s_64.add_vpp_config() |
| 2492 | ip_2002_s_64.add_vpp_config() |
| 2493 | |
| 2494 | # bring the session up now the routes are present |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 2495 | self.vpp_session = VppBFDUDPSession( |
Abdel Baig | 17a9181 | 2024-09-03 11:52:20 -0400 | [diff] [blame] | 2496 | self, |
| 2497 | self.pg0, |
| 2498 | self.dst_ip6_net, |
| 2499 | local_addr=self.src_ip6_net, |
| 2500 | af=AF_INET6, |
| 2501 | multihop=self.multihop, |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 2502 | ) |
Neale Ranns | 88fc83e | 2017-04-05 08:11:14 -0700 | [diff] [blame] | 2503 | self.vpp_session.add_vpp_config() |
| 2504 | self.vpp_session.admin_up() |
Abdel Baig | 17a9181 | 2024-09-03 11:52:20 -0400 | [diff] [blame] | 2505 | self.test_session = BFDTestSession( |
| 2506 | self, |
| 2507 | self.pg0, |
| 2508 | AF_INET6, |
| 2509 | local_addr=self.src_ip6_net, |
| 2510 | peer_addr=self.dst_ip6_net, |
| 2511 | multihop=self.multihop, |
| 2512 | ) |
Neale Ranns | 88fc83e | 2017-04-05 08:11:14 -0700 | [diff] [blame] | 2513 | |
| 2514 | # session is up - traffic passes |
| 2515 | bfd_session_up(self) |
| 2516 | |
| 2517 | self.pg0.add_stream(p) |
| 2518 | self.pg_start() |
| 2519 | for packet in p: |
| 2520 | captured = self.pg0.wait_for_packet( |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 2521 | 1, filter_out_fn=self.pkt_is_not_data_traffic |
| 2522 | ) |
| 2523 | self.assertEqual(captured[IPv6].dst, packet[IPv6].dst) |
Neale Ranns | 88fc83e | 2017-04-05 08:11:14 -0700 | [diff] [blame] | 2524 | |
Abdel Baig | 17a9181 | 2024-09-03 11:52:20 -0400 | [diff] [blame] | 2525 | # session is down - traffic is dropped |
Neale Ranns | 88fc83e | 2017-04-05 08:11:14 -0700 | [diff] [blame] | 2526 | bfd_session_down(self) |
| 2527 | |
| 2528 | self.pg0.add_stream(p) |
| 2529 | self.pg_start() |
| 2530 | with self.assertRaises(CaptureTimeoutError): |
| 2531 | self.pg0.wait_for_packet(1, self.pkt_is_not_data_traffic) |
| 2532 | |
| 2533 | # session is up - traffic passes |
| 2534 | bfd_session_up(self) |
| 2535 | |
| 2536 | self.pg0.add_stream(p) |
| 2537 | self.pg_start() |
| 2538 | for packet in p: |
| 2539 | captured = self.pg0.wait_for_packet( |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 2540 | 1, filter_out_fn=self.pkt_is_not_data_traffic |
| 2541 | ) |
| 2542 | self.assertEqual(captured[IPv6].dst, packet[IPv6].dst) |
Neale Ranns | 88fc83e | 2017-04-05 08:11:14 -0700 | [diff] [blame] | 2543 | |
| 2544 | |
Klement Sekera | b23ffd7 | 2021-05-31 16:08:53 +0200 | [diff] [blame] | 2545 | @unittest.skipUnless(config.extended, "part of extended tests") |
Neale Ranns | 52cd496 | 2019-06-05 10:28:17 +0000 | [diff] [blame] | 2546 | class BFDTunTestCase(VppTestCase): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 2547 | """BFD over GRE tunnel""" |
Neale Ranns | 52cd496 | 2019-06-05 10:28:17 +0000 | [diff] [blame] | 2548 | |
| 2549 | vpp_session = None |
| 2550 | test_session = None |
| 2551 | |
| 2552 | @classmethod |
| 2553 | def setUpClass(cls): |
| 2554 | super(BFDTunTestCase, cls).setUpClass() |
| 2555 | |
| 2556 | @classmethod |
| 2557 | def tearDownClass(cls): |
| 2558 | super(BFDTunTestCase, cls).tearDownClass() |
| 2559 | |
| 2560 | def setUp(self): |
| 2561 | super(BFDTunTestCase, self).setUp() |
| 2562 | self.create_pg_interfaces(range(1)) |
| 2563 | |
| 2564 | self.vapi.want_bfd_events() |
| 2565 | self.pg0.enable_capture() |
| 2566 | |
| 2567 | for i in self.pg_interfaces: |
| 2568 | i.admin_up() |
| 2569 | i.config_ip4() |
| 2570 | i.resolve_arp() |
| 2571 | |
| 2572 | def tearDown(self): |
| 2573 | if not self.vpp_dead: |
| 2574 | self.vapi.want_bfd_events(enable_disable=0) |
| 2575 | |
| 2576 | super(BFDTunTestCase, self).tearDown() |
| 2577 | |
| 2578 | @staticmethod |
| 2579 | def pkt_is_not_data_traffic(p): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 2580 | """not data traffic implies BFD or the usual IPv6 ND/RA""" |
Neale Ranns | 52cd496 | 2019-06-05 10:28:17 +0000 | [diff] [blame] | 2581 | if p.haslayer(BFD) or is_ipv6_misc(p): |
| 2582 | return True |
| 2583 | return False |
| 2584 | |
| 2585 | def test_bfd_o_gre(self): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 2586 | """BFD-o-GRE""" |
Neale Ranns | 52cd496 | 2019-06-05 10:28:17 +0000 | [diff] [blame] | 2587 | |
| 2588 | # A GRE interface over which to run a BFD session |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 2589 | gre_if = VppGreInterface(self, self.pg0.local_ip4, self.pg0.remote_ip4) |
Neale Ranns | 52cd496 | 2019-06-05 10:28:17 +0000 | [diff] [blame] | 2590 | gre_if.add_vpp_config() |
| 2591 | gre_if.admin_up() |
| 2592 | gre_if.config_ip4() |
| 2593 | |
| 2594 | # bring the session up now the routes are present |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 2595 | self.vpp_session = VppBFDUDPSession( |
| 2596 | self, gre_if, gre_if.remote_ip4, is_tunnel=True |
| 2597 | ) |
Neale Ranns | 52cd496 | 2019-06-05 10:28:17 +0000 | [diff] [blame] | 2598 | self.vpp_session.add_vpp_config() |
| 2599 | self.vpp_session.admin_up() |
| 2600 | |
| 2601 | self.test_session = BFDTestSession( |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 2602 | self, |
| 2603 | gre_if, |
| 2604 | AF_INET, |
| 2605 | tunnel_header=(IP(src=self.pg0.remote_ip4, dst=self.pg0.local_ip4) / GRE()), |
| 2606 | phy_interface=self.pg0, |
| 2607 | ) |
Neale Ranns | 52cd496 | 2019-06-05 10:28:17 +0000 | [diff] [blame] | 2608 | |
| 2609 | # packets to match against both of the routes |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 2610 | p = [ |
| 2611 | ( |
| 2612 | Ether(dst=self.pg0.local_mac, src=self.pg0.remote_mac) |
| 2613 | / IP(src=self.pg0.remote_ip4, dst=gre_if.remote_ip4) |
| 2614 | / UDP(sport=1234, dport=1234) |
| 2615 | / Raw(b"\xa5" * 100) |
| 2616 | ) |
| 2617 | ] |
Neale Ranns | 52cd496 | 2019-06-05 10:28:17 +0000 | [diff] [blame] | 2618 | |
| 2619 | # session is up - traffic passes |
| 2620 | bfd_session_up(self) |
| 2621 | |
| 2622 | self.send_and_expect(self.pg0, p, self.pg0) |
| 2623 | |
| 2624 | # bring session down |
| 2625 | bfd_session_down(self) |
| 2626 | |
| 2627 | |
Abdel Baig | 17a9181 | 2024-09-03 11:52:20 -0400 | [diff] [blame] | 2628 | @parameterized_class( |
| 2629 | [ |
| 2630 | {"multihop": False}, |
| 2631 | {"multihop": True}, |
| 2632 | ] |
| 2633 | ) |
Andrew Yourtchenko | 06f3281 | 2021-01-14 10:19:08 +0000 | [diff] [blame] | 2634 | @tag_run_solo |
Klement Sekera | d3ba515 | 2017-02-14 03:09:17 +0100 | [diff] [blame] | 2635 | class BFDSHA1TestCase(VppTestCase): |
Klement Sekera | d3ba515 | 2017-02-14 03:09:17 +0100 | [diff] [blame] | 2636 | pg0 = None |
| 2637 | vpp_clock_offset = None |
| 2638 | vpp_session = None |
| 2639 | test_session = None |
Abdel Baig | 17a9181 | 2024-09-03 11:52:20 -0400 | [diff] [blame] | 2640 | src_ip_net = "" |
| 2641 | dst_ip_net = "" |
Klement Sekera | d3ba515 | 2017-02-14 03:09:17 +0100 | [diff] [blame] | 2642 | |
Klement Sekera | b17dd96 | 2017-01-09 07:43:48 +0100 | [diff] [blame] | 2643 | @classmethod |
| 2644 | def setUpClass(cls): |
| 2645 | super(BFDSHA1TestCase, cls).setUpClass() |
Abdel Baig | 17a9181 | 2024-09-03 11:52:20 -0400 | [diff] [blame] | 2646 | hoptype_str = "MultiHop" if cls.multihop else "SingleHop" |
| 2647 | cls.__doc__ = f"""""Bidirectional Forwarding Detection (BFD) - SHA1 auth - {hoptype_str}""" |
Damjan Marion | 07a3857 | 2018-01-21 06:44:18 -0800 | [diff] [blame] | 2648 | cls.vapi.cli("set log class bfd level debug") |
Klement Sekera | b17dd96 | 2017-01-09 07:43:48 +0100 | [diff] [blame] | 2649 | try: |
| 2650 | cls.create_pg_interfaces([0]) |
Abdel Baig | 17a9181 | 2024-09-03 11:52:20 -0400 | [diff] [blame] | 2651 | cls.create_loopback_interfaces(1) |
| 2652 | cls.loopback0 = cls.lo_interfaces[0] |
| 2653 | cls.loopback0.config_ip4() |
| 2654 | cls.loopback0.admin_up() |
Klement Sekera | b17dd96 | 2017-01-09 07:43:48 +0100 | [diff] [blame] | 2655 | cls.pg0.config_ip4() |
Abdel Baig | 17a9181 | 2024-09-03 11:52:20 -0400 | [diff] [blame] | 2656 | cls.pg0.configure_ipv4_neighbors() |
Klement Sekera | b17dd96 | 2017-01-09 07:43:48 +0100 | [diff] [blame] | 2657 | cls.pg0.admin_up() |
| 2658 | cls.pg0.resolve_arp() |
| 2659 | |
| 2660 | except Exception: |
| 2661 | super(BFDSHA1TestCase, cls).tearDownClass() |
| 2662 | raise |
| 2663 | |
Paul Vinciguerra | 8d991d9 | 2019-01-25 14:05:48 -0800 | [diff] [blame] | 2664 | @classmethod |
| 2665 | def tearDownClass(cls): |
| 2666 | super(BFDSHA1TestCase, cls).tearDownClass() |
| 2667 | |
Klement Sekera | b17dd96 | 2017-01-09 07:43:48 +0100 | [diff] [blame] | 2668 | def setUp(self): |
| 2669 | super(BFDSHA1TestCase, self).setUp() |
| 2670 | self.factory = AuthKeyFactory() |
| 2671 | self.vapi.want_bfd_events() |
Klement Sekera | d3ba515 | 2017-02-14 03:09:17 +0100 | [diff] [blame] | 2672 | self.pg0.enable_capture() |
Abdel Baig | 17a9181 | 2024-09-03 11:52:20 -0400 | [diff] [blame] | 2673 | set_ipv4_pfx_route_info(self, self.pg0, BFD_IPV4_REMOTE_ADDR, True) |
Klement Sekera | b17dd96 | 2017-01-09 07:43:48 +0100 | [diff] [blame] | 2674 | |
| 2675 | def tearDown(self): |
Klement Sekera | d3ba515 | 2017-02-14 03:09:17 +0100 | [diff] [blame] | 2676 | if not self.vpp_dead: |
Jakub Grajciar | 4682feb | 2019-09-02 13:28:52 +0200 | [diff] [blame] | 2677 | self.vapi.want_bfd_events(enable_disable=False) |
Klement Sekera | d3ba515 | 2017-02-14 03:09:17 +0100 | [diff] [blame] | 2678 | self.vapi.collect_events() # clear the event queue |
| 2679 | super(BFDSHA1TestCase, self).tearDown() |
Klement Sekera | b17dd96 | 2017-01-09 07:43:48 +0100 | [diff] [blame] | 2680 | |
| 2681 | def test_session_up(self): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 2682 | """bring BFD session up""" |
Klement Sekera | b17dd96 | 2017-01-09 07:43:48 +0100 | [diff] [blame] | 2683 | key = self.factory.create_random_key(self) |
| 2684 | key.add_vpp_config() |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 2685 | self.vpp_session = VppBFDUDPSession( |
Abdel Baig | 17a9181 | 2024-09-03 11:52:20 -0400 | [diff] [blame] | 2686 | self, |
| 2687 | self.pg0, |
| 2688 | self.dst_ip_net, |
| 2689 | local_addr=self.src_ip_net, |
| 2690 | multihop=self.multihop, |
| 2691 | sha1_key=key, |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 2692 | ) |
Klement Sekera | b17dd96 | 2017-01-09 07:43:48 +0100 | [diff] [blame] | 2693 | self.vpp_session.add_vpp_config() |
| 2694 | self.vpp_session.admin_up() |
| 2695 | self.test_session = BFDTestSession( |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 2696 | self, |
| 2697 | self.pg0, |
| 2698 | AF_INET, |
Abdel Baig | 17a9181 | 2024-09-03 11:52:20 -0400 | [diff] [blame] | 2699 | local_addr=self.src_ip_net, |
| 2700 | peer_addr=self.dst_ip_net, |
| 2701 | multihop=self.multihop, |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 2702 | sha1_key=key, |
| 2703 | bfd_key_id=self.vpp_session.bfd_key_id, |
| 2704 | ) |
Klement Sekera | d3ba515 | 2017-02-14 03:09:17 +0100 | [diff] [blame] | 2705 | bfd_session_up(self) |
Klement Sekera | b17dd96 | 2017-01-09 07:43:48 +0100 | [diff] [blame] | 2706 | |
| 2707 | def test_hold_up(self): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 2708 | """hold BFD session up""" |
Klement Sekera | b17dd96 | 2017-01-09 07:43:48 +0100 | [diff] [blame] | 2709 | key = self.factory.create_random_key(self) |
| 2710 | key.add_vpp_config() |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 2711 | self.vpp_session = VppBFDUDPSession( |
Abdel Baig | 17a9181 | 2024-09-03 11:52:20 -0400 | [diff] [blame] | 2712 | self, |
| 2713 | self.pg0, |
| 2714 | self.dst_ip_net, |
| 2715 | local_addr=self.src_ip_net, |
| 2716 | multihop=self.multihop, |
| 2717 | sha1_key=key, |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 2718 | ) |
Klement Sekera | b17dd96 | 2017-01-09 07:43:48 +0100 | [diff] [blame] | 2719 | self.vpp_session.add_vpp_config() |
| 2720 | self.vpp_session.admin_up() |
| 2721 | self.test_session = BFDTestSession( |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 2722 | self, |
| 2723 | self.pg0, |
| 2724 | AF_INET, |
Abdel Baig | 17a9181 | 2024-09-03 11:52:20 -0400 | [diff] [blame] | 2725 | local_addr=self.src_ip_net, |
| 2726 | peer_addr=self.dst_ip_net, |
| 2727 | multihop=self.multihop, |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 2728 | sha1_key=key, |
| 2729 | bfd_key_id=self.vpp_session.bfd_key_id, |
| 2730 | ) |
Klement Sekera | d3ba515 | 2017-02-14 03:09:17 +0100 | [diff] [blame] | 2731 | bfd_session_up(self) |
Klement Sekera | aeeac3b | 2017-02-14 07:11:52 +0100 | [diff] [blame] | 2732 | for dummy in range(self.test_session.detect_mult * 2): |
Klement Sekera | d3ba515 | 2017-02-14 03:09:17 +0100 | [diff] [blame] | 2733 | wait_for_bfd_packet(self) |
Klement Sekera | b17dd96 | 2017-01-09 07:43:48 +0100 | [diff] [blame] | 2734 | self.test_session.send_packet() |
| 2735 | self.assert_equal(self.vpp_session.state, BFDState.up, BFDState) |
| 2736 | |
| 2737 | def test_hold_up_meticulous(self): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 2738 | """hold BFD session up - meticulous auth""" |
| 2739 | key = self.factory.create_random_key(self, BFDAuthType.meticulous_keyed_sha1) |
Klement Sekera | b17dd96 | 2017-01-09 07:43:48 +0100 | [diff] [blame] | 2740 | key.add_vpp_config() |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 2741 | self.vpp_session = VppBFDUDPSession( |
Abdel Baig | 17a9181 | 2024-09-03 11:52:20 -0400 | [diff] [blame] | 2742 | self, |
| 2743 | self.pg0, |
| 2744 | self.dst_ip_net, |
| 2745 | local_addr=self.src_ip_net, |
| 2746 | multihop=self.multihop, |
| 2747 | sha1_key=key, |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 2748 | ) |
Klement Sekera | b17dd96 | 2017-01-09 07:43:48 +0100 | [diff] [blame] | 2749 | self.vpp_session.add_vpp_config() |
| 2750 | self.vpp_session.admin_up() |
Klement Sekera | d3ba515 | 2017-02-14 03:09:17 +0100 | [diff] [blame] | 2751 | # specify sequence number so that it wraps |
Klement Sekera | b17dd96 | 2017-01-09 07:43:48 +0100 | [diff] [blame] | 2752 | self.test_session = BFDTestSession( |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 2753 | self, |
| 2754 | self.pg0, |
| 2755 | AF_INET, |
Abdel Baig | 17a9181 | 2024-09-03 11:52:20 -0400 | [diff] [blame] | 2756 | local_addr=self.src_ip_net, |
| 2757 | peer_addr=self.dst_ip_net, |
| 2758 | multihop=self.multihop, |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 2759 | sha1_key=key, |
Klement Sekera | d3ba515 | 2017-02-14 03:09:17 +0100 | [diff] [blame] | 2760 | bfd_key_id=self.vpp_session.bfd_key_id, |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 2761 | our_seq_number=0xFFFFFFFF - 4, |
| 2762 | ) |
Klement Sekera | d3ba515 | 2017-02-14 03:09:17 +0100 | [diff] [blame] | 2763 | bfd_session_up(self) |
| 2764 | for dummy in range(30): |
| 2765 | wait_for_bfd_packet(self) |
Klement Sekera | b17dd96 | 2017-01-09 07:43:48 +0100 | [diff] [blame] | 2766 | self.test_session.inc_seq_num() |
| 2767 | self.test_session.send_packet() |
| 2768 | self.assert_equal(self.vpp_session.state, BFDState.up, BFDState) |
| 2769 | |
| 2770 | def test_send_bad_seq_number(self): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 2771 | """session is not kept alive by msgs with bad sequence numbers""" |
| 2772 | key = self.factory.create_random_key(self, BFDAuthType.meticulous_keyed_sha1) |
Klement Sekera | b17dd96 | 2017-01-09 07:43:48 +0100 | [diff] [blame] | 2773 | key.add_vpp_config() |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 2774 | self.vpp_session = VppBFDUDPSession( |
Abdel Baig | 17a9181 | 2024-09-03 11:52:20 -0400 | [diff] [blame] | 2775 | self, |
| 2776 | self.pg0, |
| 2777 | self.dst_ip_net, |
| 2778 | local_addr=self.src_ip_net, |
| 2779 | multihop=self.multihop, |
| 2780 | sha1_key=key, |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 2781 | ) |
Klement Sekera | b17dd96 | 2017-01-09 07:43:48 +0100 | [diff] [blame] | 2782 | self.vpp_session.add_vpp_config() |
Klement Sekera | b17dd96 | 2017-01-09 07:43:48 +0100 | [diff] [blame] | 2783 | self.test_session = BFDTestSession( |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 2784 | self, |
| 2785 | self.pg0, |
| 2786 | AF_INET, |
Abdel Baig | 17a9181 | 2024-09-03 11:52:20 -0400 | [diff] [blame] | 2787 | local_addr=self.src_ip_net, |
| 2788 | peer_addr=self.dst_ip_net, |
| 2789 | multihop=self.multihop, |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 2790 | sha1_key=key, |
| 2791 | bfd_key_id=self.vpp_session.bfd_key_id, |
| 2792 | ) |
Klement Sekera | d3ba515 | 2017-02-14 03:09:17 +0100 | [diff] [blame] | 2793 | bfd_session_up(self) |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 2794 | detection_time = ( |
| 2795 | self.test_session.detect_mult |
| 2796 | * self.vpp_session.required_min_rx |
| 2797 | / USEC_IN_SEC |
| 2798 | ) |
Klement Sekera | 239790f | 2017-02-16 10:53:53 +0100 | [diff] [blame] | 2799 | send_until = time.time() + 2 * detection_time |
| 2800 | while time.time() < send_until: |
Klement Sekera | d3ba515 | 2017-02-14 03:09:17 +0100 | [diff] [blame] | 2801 | self.test_session.send_packet() |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 2802 | self.sleep( |
| 2803 | 0.7 * self.vpp_session.required_min_rx / USEC_IN_SEC, |
| 2804 | "time between bfd packets", |
| 2805 | ) |
Klement Sekera | b17dd96 | 2017-01-09 07:43:48 +0100 | [diff] [blame] | 2806 | e = self.vapi.collect_events() |
| 2807 | # session should be down now, because the sequence numbers weren't |
| 2808 | # updated |
| 2809 | self.assert_equal(len(e), 1, "number of bfd events") |
Klement Sekera | d3ba515 | 2017-02-14 03:09:17 +0100 | [diff] [blame] | 2810 | verify_event(self, e[0], expected_state=BFDState.down) |
Klement Sekera | b17dd96 | 2017-01-09 07:43:48 +0100 | [diff] [blame] | 2811 | |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 2812 | def execute_rogue_session_scenario( |
| 2813 | self, |
| 2814 | vpp_bfd_udp_session, |
| 2815 | legitimate_test_session, |
| 2816 | rogue_test_session, |
| 2817 | rogue_bfd_values=None, |
| 2818 | ): |
| 2819 | """execute a rogue session interaction scenario |
Klement Sekera | b17dd96 | 2017-01-09 07:43:48 +0100 | [diff] [blame] | 2820 | |
| 2821 | 1. create vpp session, add config |
| 2822 | 2. bring the legitimate session up |
| 2823 | 3. copy the bfd values from legitimate session to rogue session |
| 2824 | 4. apply rogue_bfd_values to rogue session |
| 2825 | 5. set rogue session state to down |
| 2826 | 6. send message to take the session down from the rogue session |
| 2827 | 7. assert that the legitimate session is unaffected |
| 2828 | """ |
| 2829 | |
| 2830 | self.vpp_session = vpp_bfd_udp_session |
| 2831 | self.vpp_session.add_vpp_config() |
Klement Sekera | b17dd96 | 2017-01-09 07:43:48 +0100 | [diff] [blame] | 2832 | self.test_session = legitimate_test_session |
| 2833 | # bring vpp session up |
Klement Sekera | d3ba515 | 2017-02-14 03:09:17 +0100 | [diff] [blame] | 2834 | bfd_session_up(self) |
Klement Sekera | b17dd96 | 2017-01-09 07:43:48 +0100 | [diff] [blame] | 2835 | # send packet from rogue session |
Klement Sekera | d3ba515 | 2017-02-14 03:09:17 +0100 | [diff] [blame] | 2836 | rogue_test_session.update( |
| 2837 | my_discriminator=self.test_session.my_discriminator, |
| 2838 | your_discriminator=self.test_session.your_discriminator, |
| 2839 | desired_min_tx=self.test_session.desired_min_tx, |
| 2840 | required_min_rx=self.test_session.required_min_rx, |
| 2841 | detect_mult=self.test_session.detect_mult, |
| 2842 | diag=self.test_session.diag, |
| 2843 | state=self.test_session.state, |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 2844 | auth_type=self.test_session.auth_type, |
| 2845 | ) |
Klement Sekera | b17dd96 | 2017-01-09 07:43:48 +0100 | [diff] [blame] | 2846 | if rogue_bfd_values: |
| 2847 | rogue_test_session.update(**rogue_bfd_values) |
| 2848 | rogue_test_session.update(state=BFDState.down) |
| 2849 | rogue_test_session.send_packet() |
Klement Sekera | d3ba515 | 2017-02-14 03:09:17 +0100 | [diff] [blame] | 2850 | wait_for_bfd_packet(self) |
Klement Sekera | b17dd96 | 2017-01-09 07:43:48 +0100 | [diff] [blame] | 2851 | self.assert_equal(self.vpp_session.state, BFDState.up, BFDState) |
| 2852 | |
| 2853 | def test_mismatch_auth(self): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 2854 | """session is not brought down by unauthenticated msg""" |
Klement Sekera | b17dd96 | 2017-01-09 07:43:48 +0100 | [diff] [blame] | 2855 | key = self.factory.create_random_key(self) |
| 2856 | key.add_vpp_config() |
| 2857 | vpp_session = VppBFDUDPSession( |
Abdel Baig | 17a9181 | 2024-09-03 11:52:20 -0400 | [diff] [blame] | 2858 | self, |
| 2859 | self.pg0, |
| 2860 | self.dst_ip_net, |
| 2861 | local_addr=self.src_ip_net, |
| 2862 | multihop=self.multihop, |
| 2863 | sha1_key=key, |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 2864 | ) |
Klement Sekera | b17dd96 | 2017-01-09 07:43:48 +0100 | [diff] [blame] | 2865 | legitimate_test_session = BFDTestSession( |
Abdel Baig | 17a9181 | 2024-09-03 11:52:20 -0400 | [diff] [blame] | 2866 | self, |
| 2867 | self.pg0, |
| 2868 | AF_INET, |
| 2869 | local_addr=self.src_ip_net, |
| 2870 | peer_addr=self.dst_ip_net, |
| 2871 | multihop=self.multihop, |
| 2872 | sha1_key=key, |
| 2873 | bfd_key_id=vpp_session.bfd_key_id, |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 2874 | ) |
Abdel Baig | 17a9181 | 2024-09-03 11:52:20 -0400 | [diff] [blame] | 2875 | rogue_test_session = BFDTestSession( |
| 2876 | self, |
| 2877 | self.pg0, |
| 2878 | AF_INET, |
| 2879 | local_addr=self.src_ip_net, |
| 2880 | peer_addr=self.dst_ip_net, |
| 2881 | multihop=self.multihop, |
| 2882 | ) |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 2883 | self.execute_rogue_session_scenario( |
| 2884 | vpp_session, legitimate_test_session, rogue_test_session |
| 2885 | ) |
Klement Sekera | b17dd96 | 2017-01-09 07:43:48 +0100 | [diff] [blame] | 2886 | |
| 2887 | def test_mismatch_bfd_key_id(self): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 2888 | """session is not brought down by msg with non-existent key-id""" |
Klement Sekera | b17dd96 | 2017-01-09 07:43:48 +0100 | [diff] [blame] | 2889 | key = self.factory.create_random_key(self) |
| 2890 | key.add_vpp_config() |
| 2891 | vpp_session = VppBFDUDPSession( |
Abdel Baig | 17a9181 | 2024-09-03 11:52:20 -0400 | [diff] [blame] | 2892 | self, |
| 2893 | self.pg0, |
| 2894 | self.dst_ip_net, |
| 2895 | local_addr=self.src_ip_net, |
| 2896 | multihop=self.multihop, |
| 2897 | sha1_key=key, |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 2898 | ) |
Klement Sekera | b17dd96 | 2017-01-09 07:43:48 +0100 | [diff] [blame] | 2899 | # pick a different random bfd key id |
| 2900 | x = randint(0, 255) |
| 2901 | while x == vpp_session.bfd_key_id: |
| 2902 | x = randint(0, 255) |
| 2903 | legitimate_test_session = BFDTestSession( |
Abdel Baig | 17a9181 | 2024-09-03 11:52:20 -0400 | [diff] [blame] | 2904 | self, |
| 2905 | self.pg0, |
| 2906 | AF_INET, |
| 2907 | local_addr=self.src_ip_net, |
| 2908 | peer_addr=self.dst_ip_net, |
| 2909 | multihop=self.multihop, |
| 2910 | sha1_key=key, |
| 2911 | bfd_key_id=vpp_session.bfd_key_id, |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 2912 | ) |
Klement Sekera | b17dd96 | 2017-01-09 07:43:48 +0100 | [diff] [blame] | 2913 | rogue_test_session = BFDTestSession( |
Abdel Baig | 17a9181 | 2024-09-03 11:52:20 -0400 | [diff] [blame] | 2914 | self, |
| 2915 | self.pg0, |
| 2916 | AF_INET, |
| 2917 | local_addr=self.src_ip_net, |
| 2918 | peer_addr=self.dst_ip_net, |
| 2919 | multihop=self.multihop, |
| 2920 | sha1_key=key, |
| 2921 | bfd_key_id=x, |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 2922 | ) |
| 2923 | self.execute_rogue_session_scenario( |
| 2924 | vpp_session, legitimate_test_session, rogue_test_session |
| 2925 | ) |
Klement Sekera | b17dd96 | 2017-01-09 07:43:48 +0100 | [diff] [blame] | 2926 | |
| 2927 | def test_mismatched_auth_type(self): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 2928 | """session is not brought down by msg with wrong auth type""" |
Klement Sekera | b17dd96 | 2017-01-09 07:43:48 +0100 | [diff] [blame] | 2929 | key = self.factory.create_random_key(self) |
| 2930 | key.add_vpp_config() |
| 2931 | vpp_session = VppBFDUDPSession( |
Abdel Baig | 17a9181 | 2024-09-03 11:52:20 -0400 | [diff] [blame] | 2932 | self, |
| 2933 | self.pg0, |
| 2934 | self.dst_ip_net, |
| 2935 | local_addr=self.src_ip_net, |
| 2936 | multihop=self.multihop, |
| 2937 | sha1_key=key, |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 2938 | ) |
Klement Sekera | b17dd96 | 2017-01-09 07:43:48 +0100 | [diff] [blame] | 2939 | legitimate_test_session = BFDTestSession( |
Abdel Baig | 17a9181 | 2024-09-03 11:52:20 -0400 | [diff] [blame] | 2940 | self, |
| 2941 | self.pg0, |
| 2942 | AF_INET, |
| 2943 | local_addr=self.src_ip_net, |
| 2944 | peer_addr=self.dst_ip_net, |
| 2945 | multihop=self.multihop, |
| 2946 | sha1_key=key, |
| 2947 | bfd_key_id=vpp_session.bfd_key_id, |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 2948 | ) |
Klement Sekera | b17dd96 | 2017-01-09 07:43:48 +0100 | [diff] [blame] | 2949 | rogue_test_session = BFDTestSession( |
Abdel Baig | 17a9181 | 2024-09-03 11:52:20 -0400 | [diff] [blame] | 2950 | self, |
| 2951 | self.pg0, |
| 2952 | AF_INET, |
| 2953 | local_addr=self.src_ip_net, |
| 2954 | peer_addr=self.dst_ip_net, |
| 2955 | multihop=self.multihop, |
| 2956 | sha1_key=key, |
| 2957 | bfd_key_id=vpp_session.bfd_key_id, |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 2958 | ) |
Klement Sekera | b17dd96 | 2017-01-09 07:43:48 +0100 | [diff] [blame] | 2959 | self.execute_rogue_session_scenario( |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 2960 | vpp_session, |
| 2961 | legitimate_test_session, |
| 2962 | rogue_test_session, |
| 2963 | {"auth_type": BFDAuthType.keyed_md5}, |
| 2964 | ) |
Klement Sekera | b17dd96 | 2017-01-09 07:43:48 +0100 | [diff] [blame] | 2965 | |
| 2966 | def test_restart(self): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 2967 | """simulate remote peer restart and resynchronization""" |
| 2968 | key = self.factory.create_random_key(self, BFDAuthType.meticulous_keyed_sha1) |
Klement Sekera | b17dd96 | 2017-01-09 07:43:48 +0100 | [diff] [blame] | 2969 | key.add_vpp_config() |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 2970 | self.vpp_session = VppBFDUDPSession( |
Abdel Baig | 17a9181 | 2024-09-03 11:52:20 -0400 | [diff] [blame] | 2971 | self, |
| 2972 | self.pg0, |
| 2973 | self.dst_ip_net, |
| 2974 | local_addr=self.src_ip_net, |
| 2975 | multihop=self.multihop, |
| 2976 | sha1_key=key, |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 2977 | ) |
Klement Sekera | b17dd96 | 2017-01-09 07:43:48 +0100 | [diff] [blame] | 2978 | self.vpp_session.add_vpp_config() |
Klement Sekera | b17dd96 | 2017-01-09 07:43:48 +0100 | [diff] [blame] | 2979 | self.test_session = BFDTestSession( |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 2980 | self, |
| 2981 | self.pg0, |
| 2982 | AF_INET, |
Abdel Baig | 17a9181 | 2024-09-03 11:52:20 -0400 | [diff] [blame] | 2983 | local_addr=self.src_ip_net, |
| 2984 | peer_addr=self.dst_ip_net, |
| 2985 | multihop=self.multihop, |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 2986 | sha1_key=key, |
| 2987 | bfd_key_id=self.vpp_session.bfd_key_id, |
| 2988 | our_seq_number=0, |
| 2989 | ) |
Klement Sekera | d3ba515 | 2017-02-14 03:09:17 +0100 | [diff] [blame] | 2990 | bfd_session_up(self) |
| 2991 | # don't send any packets for 2*detection_time |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 2992 | detection_time = ( |
| 2993 | self.test_session.detect_mult |
| 2994 | * self.vpp_session.required_min_rx |
| 2995 | / USEC_IN_SEC |
| 2996 | ) |
Klement Sekera | 8713493 | 2017-03-07 11:39:27 +0100 | [diff] [blame] | 2997 | self.sleep(2 * detection_time, "simulating peer restart") |
Klement Sekera | d3ba515 | 2017-02-14 03:09:17 +0100 | [diff] [blame] | 2998 | events = self.vapi.collect_events() |
| 2999 | self.assert_equal(len(events), 1, "number of bfd events") |
| 3000 | verify_event(self, events[0], expected_state=BFDState.down) |
Klement Sekera | b17dd96 | 2017-01-09 07:43:48 +0100 | [diff] [blame] | 3001 | self.test_session.update(state=BFDState.down) |
Klement Sekera | b17dd96 | 2017-01-09 07:43:48 +0100 | [diff] [blame] | 3002 | # reset sequence number |
| 3003 | self.test_session.our_seq_number = 0 |
Klement Sekera | d3ba515 | 2017-02-14 03:09:17 +0100 | [diff] [blame] | 3004 | self.test_session.vpp_seq_number = None |
| 3005 | # now throw away any pending packets |
| 3006 | self.pg0.enable_capture() |
Klement Sekera | 4d39f9c | 2020-01-17 10:01:52 +0000 | [diff] [blame] | 3007 | self.test_session.my_discriminator = 0 |
Klement Sekera | d3ba515 | 2017-02-14 03:09:17 +0100 | [diff] [blame] | 3008 | bfd_session_up(self) |
Klement Sekera | b17dd96 | 2017-01-09 07:43:48 +0100 | [diff] [blame] | 3009 | |
| 3010 | |
Abdel Baig | 17a9181 | 2024-09-03 11:52:20 -0400 | [diff] [blame] | 3011 | @parameterized_class( |
| 3012 | [ |
| 3013 | {"multihop": False}, |
| 3014 | {"multihop": True}, |
| 3015 | ] |
| 3016 | ) |
Andrew Yourtchenko | 06f3281 | 2021-01-14 10:19:08 +0000 | [diff] [blame] | 3017 | @tag_run_solo |
Klement Sekera | d3ba515 | 2017-02-14 03:09:17 +0100 | [diff] [blame] | 3018 | class BFDAuthOnOffTestCase(VppTestCase): |
Klement Sekera | d3ba515 | 2017-02-14 03:09:17 +0100 | [diff] [blame] | 3019 | pg0 = None |
| 3020 | vpp_session = None |
| 3021 | test_session = None |
| 3022 | |
Klement Sekera | b17dd96 | 2017-01-09 07:43:48 +0100 | [diff] [blame] | 3023 | @classmethod |
| 3024 | def setUpClass(cls): |
| 3025 | super(BFDAuthOnOffTestCase, cls).setUpClass() |
Abdel Baig | 17a9181 | 2024-09-03 11:52:20 -0400 | [diff] [blame] | 3026 | hoptype_str = "MultiHop" if cls.multihop else "SingleHop" |
| 3027 | cls.__doc__ = f"""""Bidirectional Forwarding Detection (BFD) - changing auth - {hoptype_str}""" |
Damjan Marion | 07a3857 | 2018-01-21 06:44:18 -0800 | [diff] [blame] | 3028 | cls.vapi.cli("set log class bfd level debug") |
Klement Sekera | b17dd96 | 2017-01-09 07:43:48 +0100 | [diff] [blame] | 3029 | try: |
| 3030 | cls.create_pg_interfaces([0]) |
Abdel Baig | 17a9181 | 2024-09-03 11:52:20 -0400 | [diff] [blame] | 3031 | cls.create_loopback_interfaces(1) |
| 3032 | cls.loopback0 = cls.lo_interfaces[0] |
| 3033 | cls.loopback0.config_ip4() |
| 3034 | cls.loopback0.admin_up() |
Klement Sekera | b17dd96 | 2017-01-09 07:43:48 +0100 | [diff] [blame] | 3035 | cls.pg0.config_ip4() |
Abdel Baig | 17a9181 | 2024-09-03 11:52:20 -0400 | [diff] [blame] | 3036 | cls.pg0.configure_ipv4_neighbors() |
Klement Sekera | b17dd96 | 2017-01-09 07:43:48 +0100 | [diff] [blame] | 3037 | cls.pg0.admin_up() |
| 3038 | cls.pg0.resolve_arp() |
| 3039 | |
| 3040 | except Exception: |
| 3041 | super(BFDAuthOnOffTestCase, cls).tearDownClass() |
| 3042 | raise |
| 3043 | |
Paul Vinciguerra | 8d991d9 | 2019-01-25 14:05:48 -0800 | [diff] [blame] | 3044 | @classmethod |
| 3045 | def tearDownClass(cls): |
| 3046 | super(BFDAuthOnOffTestCase, cls).tearDownClass() |
| 3047 | |
Klement Sekera | b17dd96 | 2017-01-09 07:43:48 +0100 | [diff] [blame] | 3048 | def setUp(self): |
| 3049 | super(BFDAuthOnOffTestCase, self).setUp() |
| 3050 | self.factory = AuthKeyFactory() |
| 3051 | self.vapi.want_bfd_events() |
Klement Sekera | d3ba515 | 2017-02-14 03:09:17 +0100 | [diff] [blame] | 3052 | self.pg0.enable_capture() |
Abdel Baig | 17a9181 | 2024-09-03 11:52:20 -0400 | [diff] [blame] | 3053 | set_ipv4_pfx_route_info(self, self.pg0, BFD_IPV4_REMOTE_ADDR, True) |
Klement Sekera | b17dd96 | 2017-01-09 07:43:48 +0100 | [diff] [blame] | 3054 | |
| 3055 | def tearDown(self): |
Klement Sekera | d3ba515 | 2017-02-14 03:09:17 +0100 | [diff] [blame] | 3056 | if not self.vpp_dead: |
Jakub Grajciar | 4682feb | 2019-09-02 13:28:52 +0200 | [diff] [blame] | 3057 | self.vapi.want_bfd_events(enable_disable=False) |
Klement Sekera | d3ba515 | 2017-02-14 03:09:17 +0100 | [diff] [blame] | 3058 | self.vapi.collect_events() # clear the event queue |
| 3059 | super(BFDAuthOnOffTestCase, self).tearDown() |
Klement Sekera | b17dd96 | 2017-01-09 07:43:48 +0100 | [diff] [blame] | 3060 | |
| 3061 | def test_auth_on_immediate(self): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 3062 | """turn auth on without disturbing session state (immediate)""" |
Klement Sekera | b17dd96 | 2017-01-09 07:43:48 +0100 | [diff] [blame] | 3063 | key = self.factory.create_random_key(self) |
| 3064 | key.add_vpp_config() |
Abdel Baig | 17a9181 | 2024-09-03 11:52:20 -0400 | [diff] [blame] | 3065 | self.vpp_session = VppBFDUDPSession( |
| 3066 | self, |
| 3067 | self.pg0, |
| 3068 | self.dst_ip_net, |
| 3069 | local_addr=self.src_ip_net, |
| 3070 | multihop=self.multihop, |
| 3071 | ) |
Klement Sekera | b17dd96 | 2017-01-09 07:43:48 +0100 | [diff] [blame] | 3072 | self.vpp_session.add_vpp_config() |
Abdel Baig | 17a9181 | 2024-09-03 11:52:20 -0400 | [diff] [blame] | 3073 | self.test_session = BFDTestSession( |
| 3074 | self, |
| 3075 | self.pg0, |
| 3076 | AF_INET, |
| 3077 | local_addr=self.src_ip_net, |
| 3078 | peer_addr=self.dst_ip_net, |
| 3079 | multihop=self.multihop, |
| 3080 | ) |
Klement Sekera | d3ba515 | 2017-02-14 03:09:17 +0100 | [diff] [blame] | 3081 | bfd_session_up(self) |
Klement Sekera | aeeac3b | 2017-02-14 07:11:52 +0100 | [diff] [blame] | 3082 | for dummy in range(self.test_session.detect_mult * 2): |
Klement Sekera | d3ba515 | 2017-02-14 03:09:17 +0100 | [diff] [blame] | 3083 | p = wait_for_bfd_packet(self) |
| 3084 | self.assert_equal(p[BFD].state, BFDState.up, BFDState) |
Klement Sekera | b17dd96 | 2017-01-09 07:43:48 +0100 | [diff] [blame] | 3085 | self.test_session.send_packet() |
| 3086 | self.vpp_session.activate_auth(key) |
| 3087 | self.test_session.bfd_key_id = self.vpp_session.bfd_key_id |
| 3088 | self.test_session.sha1_key = key |
Klement Sekera | aeeac3b | 2017-02-14 07:11:52 +0100 | [diff] [blame] | 3089 | for dummy in range(self.test_session.detect_mult * 2): |
Klement Sekera | d3ba515 | 2017-02-14 03:09:17 +0100 | [diff] [blame] | 3090 | p = wait_for_bfd_packet(self) |
| 3091 | self.assert_equal(p[BFD].state, BFDState.up, BFDState) |
Klement Sekera | b17dd96 | 2017-01-09 07:43:48 +0100 | [diff] [blame] | 3092 | self.test_session.send_packet() |
| 3093 | self.assert_equal(self.vpp_session.state, BFDState.up, BFDState) |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 3094 | self.assert_equal(len(self.vapi.collect_events()), 0, "number of bfd events") |
Klement Sekera | b17dd96 | 2017-01-09 07:43:48 +0100 | [diff] [blame] | 3095 | |
| 3096 | def test_auth_off_immediate(self): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 3097 | """turn auth off without disturbing session state (immediate)""" |
Klement Sekera | b17dd96 | 2017-01-09 07:43:48 +0100 | [diff] [blame] | 3098 | key = self.factory.create_random_key(self) |
| 3099 | key.add_vpp_config() |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 3100 | self.vpp_session = VppBFDUDPSession( |
Abdel Baig | 17a9181 | 2024-09-03 11:52:20 -0400 | [diff] [blame] | 3101 | self, |
| 3102 | self.pg0, |
| 3103 | self.dst_ip_net, |
| 3104 | local_addr=self.src_ip_net, |
| 3105 | multihop=self.multihop, |
| 3106 | sha1_key=key, |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 3107 | ) |
Klement Sekera | b17dd96 | 2017-01-09 07:43:48 +0100 | [diff] [blame] | 3108 | self.vpp_session.add_vpp_config() |
Klement Sekera | b17dd96 | 2017-01-09 07:43:48 +0100 | [diff] [blame] | 3109 | self.test_session = BFDTestSession( |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 3110 | self, |
| 3111 | self.pg0, |
| 3112 | AF_INET, |
Abdel Baig | 17a9181 | 2024-09-03 11:52:20 -0400 | [diff] [blame] | 3113 | local_addr=self.src_ip_net, |
| 3114 | peer_addr=self.dst_ip_net, |
| 3115 | multihop=self.multihop, |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 3116 | sha1_key=key, |
| 3117 | bfd_key_id=self.vpp_session.bfd_key_id, |
| 3118 | ) |
Klement Sekera | d3ba515 | 2017-02-14 03:09:17 +0100 | [diff] [blame] | 3119 | bfd_session_up(self) |
| 3120 | # self.vapi.want_bfd_events(enable_disable=0) |
Klement Sekera | aeeac3b | 2017-02-14 07:11:52 +0100 | [diff] [blame] | 3121 | for dummy in range(self.test_session.detect_mult * 2): |
Klement Sekera | d3ba515 | 2017-02-14 03:09:17 +0100 | [diff] [blame] | 3122 | p = wait_for_bfd_packet(self) |
| 3123 | self.assert_equal(p[BFD].state, BFDState.up, BFDState) |
| 3124 | self.test_session.inc_seq_num() |
Klement Sekera | b17dd96 | 2017-01-09 07:43:48 +0100 | [diff] [blame] | 3125 | self.test_session.send_packet() |
| 3126 | self.vpp_session.deactivate_auth() |
| 3127 | self.test_session.bfd_key_id = None |
| 3128 | self.test_session.sha1_key = None |
Klement Sekera | aeeac3b | 2017-02-14 07:11:52 +0100 | [diff] [blame] | 3129 | for dummy in range(self.test_session.detect_mult * 2): |
Klement Sekera | d3ba515 | 2017-02-14 03:09:17 +0100 | [diff] [blame] | 3130 | p = wait_for_bfd_packet(self) |
| 3131 | self.assert_equal(p[BFD].state, BFDState.up, BFDState) |
| 3132 | self.test_session.inc_seq_num() |
Klement Sekera | b17dd96 | 2017-01-09 07:43:48 +0100 | [diff] [blame] | 3133 | self.test_session.send_packet() |
| 3134 | self.assert_equal(self.vpp_session.state, BFDState.up, BFDState) |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 3135 | self.assert_equal(len(self.vapi.collect_events()), 0, "number of bfd events") |
Klement Sekera | b17dd96 | 2017-01-09 07:43:48 +0100 | [diff] [blame] | 3136 | |
| 3137 | def test_auth_change_key_immediate(self): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 3138 | """change auth key without disturbing session state (immediate)""" |
Klement Sekera | b17dd96 | 2017-01-09 07:43:48 +0100 | [diff] [blame] | 3139 | key1 = self.factory.create_random_key(self) |
| 3140 | key1.add_vpp_config() |
| 3141 | key2 = self.factory.create_random_key(self) |
| 3142 | key2.add_vpp_config() |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 3143 | self.vpp_session = VppBFDUDPSession( |
Abdel Baig | 17a9181 | 2024-09-03 11:52:20 -0400 | [diff] [blame] | 3144 | self, |
| 3145 | self.pg0, |
| 3146 | self.dst_ip_net, |
| 3147 | local_addr=self.src_ip_net, |
| 3148 | multihop=self.multihop, |
| 3149 | sha1_key=key1, |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 3150 | ) |
Klement Sekera | b17dd96 | 2017-01-09 07:43:48 +0100 | [diff] [blame] | 3151 | self.vpp_session.add_vpp_config() |
Klement Sekera | b17dd96 | 2017-01-09 07:43:48 +0100 | [diff] [blame] | 3152 | self.test_session = BFDTestSession( |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 3153 | self, |
| 3154 | self.pg0, |
| 3155 | AF_INET, |
Abdel Baig | 17a9181 | 2024-09-03 11:52:20 -0400 | [diff] [blame] | 3156 | local_addr=self.src_ip_net, |
| 3157 | peer_addr=self.dst_ip_net, |
| 3158 | multihop=self.multihop, |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 3159 | sha1_key=key1, |
| 3160 | bfd_key_id=self.vpp_session.bfd_key_id, |
| 3161 | ) |
Klement Sekera | d3ba515 | 2017-02-14 03:09:17 +0100 | [diff] [blame] | 3162 | bfd_session_up(self) |
Klement Sekera | aeeac3b | 2017-02-14 07:11:52 +0100 | [diff] [blame] | 3163 | for dummy in range(self.test_session.detect_mult * 2): |
Klement Sekera | d3ba515 | 2017-02-14 03:09:17 +0100 | [diff] [blame] | 3164 | p = wait_for_bfd_packet(self) |
| 3165 | self.assert_equal(p[BFD].state, BFDState.up, BFDState) |
Klement Sekera | b17dd96 | 2017-01-09 07:43:48 +0100 | [diff] [blame] | 3166 | self.test_session.send_packet() |
| 3167 | self.vpp_session.activate_auth(key2) |
| 3168 | self.test_session.bfd_key_id = self.vpp_session.bfd_key_id |
| 3169 | self.test_session.sha1_key = key2 |
Klement Sekera | aeeac3b | 2017-02-14 07:11:52 +0100 | [diff] [blame] | 3170 | for dummy in range(self.test_session.detect_mult * 2): |
Klement Sekera | d3ba515 | 2017-02-14 03:09:17 +0100 | [diff] [blame] | 3171 | p = wait_for_bfd_packet(self) |
| 3172 | self.assert_equal(p[BFD].state, BFDState.up, BFDState) |
Klement Sekera | b17dd96 | 2017-01-09 07:43:48 +0100 | [diff] [blame] | 3173 | self.test_session.send_packet() |
| 3174 | self.assert_equal(self.vpp_session.state, BFDState.up, BFDState) |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 3175 | self.assert_equal(len(self.vapi.collect_events()), 0, "number of bfd events") |
Klement Sekera | b17dd96 | 2017-01-09 07:43:48 +0100 | [diff] [blame] | 3176 | |
| 3177 | def test_auth_on_delayed(self): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 3178 | """turn auth on without disturbing session state (delayed)""" |
Klement Sekera | b17dd96 | 2017-01-09 07:43:48 +0100 | [diff] [blame] | 3179 | key = self.factory.create_random_key(self) |
| 3180 | key.add_vpp_config() |
Abdel Baig | 17a9181 | 2024-09-03 11:52:20 -0400 | [diff] [blame] | 3181 | self.vpp_session = VppBFDUDPSession( |
| 3182 | self, |
| 3183 | self.pg0, |
| 3184 | self.dst_ip_net, |
| 3185 | local_addr=self.src_ip_net, |
| 3186 | multihop=self.multihop, |
| 3187 | ) |
Klement Sekera | b17dd96 | 2017-01-09 07:43:48 +0100 | [diff] [blame] | 3188 | self.vpp_session.add_vpp_config() |
Abdel Baig | 17a9181 | 2024-09-03 11:52:20 -0400 | [diff] [blame] | 3189 | self.test_session = BFDTestSession( |
| 3190 | self, |
| 3191 | self.pg0, |
| 3192 | AF_INET, |
| 3193 | local_addr=self.src_ip_net, |
| 3194 | peer_addr=self.dst_ip_net, |
| 3195 | multihop=self.multihop, |
| 3196 | ) |
Klement Sekera | d3ba515 | 2017-02-14 03:09:17 +0100 | [diff] [blame] | 3197 | bfd_session_up(self) |
Klement Sekera | aeeac3b | 2017-02-14 07:11:52 +0100 | [diff] [blame] | 3198 | for dummy in range(self.test_session.detect_mult * 2): |
Klement Sekera | d3ba515 | 2017-02-14 03:09:17 +0100 | [diff] [blame] | 3199 | wait_for_bfd_packet(self) |
Klement Sekera | b17dd96 | 2017-01-09 07:43:48 +0100 | [diff] [blame] | 3200 | self.test_session.send_packet() |
| 3201 | self.vpp_session.activate_auth(key, delayed=True) |
Klement Sekera | aeeac3b | 2017-02-14 07:11:52 +0100 | [diff] [blame] | 3202 | for dummy in range(self.test_session.detect_mult * 2): |
Klement Sekera | d3ba515 | 2017-02-14 03:09:17 +0100 | [diff] [blame] | 3203 | p = wait_for_bfd_packet(self) |
| 3204 | self.assert_equal(p[BFD].state, BFDState.up, BFDState) |
Klement Sekera | b17dd96 | 2017-01-09 07:43:48 +0100 | [diff] [blame] | 3205 | self.test_session.send_packet() |
| 3206 | self.test_session.bfd_key_id = self.vpp_session.bfd_key_id |
| 3207 | self.test_session.sha1_key = key |
| 3208 | self.test_session.send_packet() |
Klement Sekera | aeeac3b | 2017-02-14 07:11:52 +0100 | [diff] [blame] | 3209 | for dummy in range(self.test_session.detect_mult * 2): |
Klement Sekera | d3ba515 | 2017-02-14 03:09:17 +0100 | [diff] [blame] | 3210 | p = wait_for_bfd_packet(self) |
| 3211 | self.assert_equal(p[BFD].state, BFDState.up, BFDState) |
Klement Sekera | b17dd96 | 2017-01-09 07:43:48 +0100 | [diff] [blame] | 3212 | self.test_session.send_packet() |
| 3213 | self.assert_equal(self.vpp_session.state, BFDState.up, BFDState) |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 3214 | self.assert_equal(len(self.vapi.collect_events()), 0, "number of bfd events") |
Klement Sekera | b17dd96 | 2017-01-09 07:43:48 +0100 | [diff] [blame] | 3215 | |
| 3216 | def test_auth_off_delayed(self): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 3217 | """turn auth off without disturbing session state (delayed)""" |
Klement Sekera | b17dd96 | 2017-01-09 07:43:48 +0100 | [diff] [blame] | 3218 | key = self.factory.create_random_key(self) |
| 3219 | key.add_vpp_config() |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 3220 | self.vpp_session = VppBFDUDPSession( |
Abdel Baig | 17a9181 | 2024-09-03 11:52:20 -0400 | [diff] [blame] | 3221 | self, |
| 3222 | self.pg0, |
| 3223 | self.dst_ip_net, |
| 3224 | local_addr=self.src_ip_net, |
| 3225 | multihop=self.multihop, |
| 3226 | sha1_key=key, |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 3227 | ) |
Klement Sekera | b17dd96 | 2017-01-09 07:43:48 +0100 | [diff] [blame] | 3228 | self.vpp_session.add_vpp_config() |
Klement Sekera | b17dd96 | 2017-01-09 07:43:48 +0100 | [diff] [blame] | 3229 | self.test_session = BFDTestSession( |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 3230 | self, |
| 3231 | self.pg0, |
| 3232 | AF_INET, |
Abdel Baig | 17a9181 | 2024-09-03 11:52:20 -0400 | [diff] [blame] | 3233 | local_addr=self.src_ip_net, |
| 3234 | peer_addr=self.dst_ip_net, |
| 3235 | multihop=self.multihop, |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 3236 | sha1_key=key, |
| 3237 | bfd_key_id=self.vpp_session.bfd_key_id, |
| 3238 | ) |
Klement Sekera | d3ba515 | 2017-02-14 03:09:17 +0100 | [diff] [blame] | 3239 | bfd_session_up(self) |
Klement Sekera | aeeac3b | 2017-02-14 07:11:52 +0100 | [diff] [blame] | 3240 | for dummy in range(self.test_session.detect_mult * 2): |
Klement Sekera | d3ba515 | 2017-02-14 03:09:17 +0100 | [diff] [blame] | 3241 | p = wait_for_bfd_packet(self) |
| 3242 | self.assert_equal(p[BFD].state, BFDState.up, BFDState) |
Klement Sekera | b17dd96 | 2017-01-09 07:43:48 +0100 | [diff] [blame] | 3243 | self.test_session.send_packet() |
| 3244 | self.vpp_session.deactivate_auth(delayed=True) |
Klement Sekera | aeeac3b | 2017-02-14 07:11:52 +0100 | [diff] [blame] | 3245 | for dummy in range(self.test_session.detect_mult * 2): |
Klement Sekera | d3ba515 | 2017-02-14 03:09:17 +0100 | [diff] [blame] | 3246 | p = wait_for_bfd_packet(self) |
| 3247 | self.assert_equal(p[BFD].state, BFDState.up, BFDState) |
Klement Sekera | b17dd96 | 2017-01-09 07:43:48 +0100 | [diff] [blame] | 3248 | self.test_session.send_packet() |
| 3249 | self.test_session.bfd_key_id = None |
| 3250 | self.test_session.sha1_key = None |
| 3251 | self.test_session.send_packet() |
Klement Sekera | aeeac3b | 2017-02-14 07:11:52 +0100 | [diff] [blame] | 3252 | for dummy in range(self.test_session.detect_mult * 2): |
Klement Sekera | d3ba515 | 2017-02-14 03:09:17 +0100 | [diff] [blame] | 3253 | p = wait_for_bfd_packet(self) |
| 3254 | self.assert_equal(p[BFD].state, BFDState.up, BFDState) |
Klement Sekera | b17dd96 | 2017-01-09 07:43:48 +0100 | [diff] [blame] | 3255 | self.test_session.send_packet() |
| 3256 | self.assert_equal(self.vpp_session.state, BFDState.up, BFDState) |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 3257 | self.assert_equal(len(self.vapi.collect_events()), 0, "number of bfd events") |
Klement Sekera | b17dd96 | 2017-01-09 07:43:48 +0100 | [diff] [blame] | 3258 | |
| 3259 | def test_auth_change_key_delayed(self): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 3260 | """change auth key without disturbing session state (delayed)""" |
Klement Sekera | b17dd96 | 2017-01-09 07:43:48 +0100 | [diff] [blame] | 3261 | key1 = self.factory.create_random_key(self) |
| 3262 | key1.add_vpp_config() |
| 3263 | key2 = self.factory.create_random_key(self) |
| 3264 | key2.add_vpp_config() |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 3265 | self.vpp_session = VppBFDUDPSession( |
Abdel Baig | 17a9181 | 2024-09-03 11:52:20 -0400 | [diff] [blame] | 3266 | self, |
| 3267 | self.pg0, |
| 3268 | self.dst_ip_net, |
| 3269 | local_addr=self.src_ip_net, |
| 3270 | multihop=self.multihop, |
| 3271 | sha1_key=key1, |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 3272 | ) |
Klement Sekera | b17dd96 | 2017-01-09 07:43:48 +0100 | [diff] [blame] | 3273 | self.vpp_session.add_vpp_config() |
| 3274 | self.vpp_session.admin_up() |
| 3275 | self.test_session = BFDTestSession( |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 3276 | self, |
| 3277 | self.pg0, |
| 3278 | AF_INET, |
Abdel Baig | 17a9181 | 2024-09-03 11:52:20 -0400 | [diff] [blame] | 3279 | local_addr=self.src_ip_net, |
| 3280 | peer_addr=self.dst_ip_net, |
| 3281 | multihop=self.multihop, |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 3282 | sha1_key=key1, |
| 3283 | bfd_key_id=self.vpp_session.bfd_key_id, |
| 3284 | ) |
Klement Sekera | d3ba515 | 2017-02-14 03:09:17 +0100 | [diff] [blame] | 3285 | bfd_session_up(self) |
Klement Sekera | aeeac3b | 2017-02-14 07:11:52 +0100 | [diff] [blame] | 3286 | for dummy in range(self.test_session.detect_mult * 2): |
Klement Sekera | d3ba515 | 2017-02-14 03:09:17 +0100 | [diff] [blame] | 3287 | p = wait_for_bfd_packet(self) |
| 3288 | self.assert_equal(p[BFD].state, BFDState.up, BFDState) |
Klement Sekera | b17dd96 | 2017-01-09 07:43:48 +0100 | [diff] [blame] | 3289 | self.test_session.send_packet() |
| 3290 | self.vpp_session.activate_auth(key2, delayed=True) |
Klement Sekera | aeeac3b | 2017-02-14 07:11:52 +0100 | [diff] [blame] | 3291 | for dummy in range(self.test_session.detect_mult * 2): |
Klement Sekera | d3ba515 | 2017-02-14 03:09:17 +0100 | [diff] [blame] | 3292 | p = wait_for_bfd_packet(self) |
| 3293 | self.assert_equal(p[BFD].state, BFDState.up, BFDState) |
Klement Sekera | b17dd96 | 2017-01-09 07:43:48 +0100 | [diff] [blame] | 3294 | self.test_session.send_packet() |
| 3295 | self.test_session.bfd_key_id = self.vpp_session.bfd_key_id |
| 3296 | self.test_session.sha1_key = key2 |
| 3297 | self.test_session.send_packet() |
Klement Sekera | aeeac3b | 2017-02-14 07:11:52 +0100 | [diff] [blame] | 3298 | for dummy in range(self.test_session.detect_mult * 2): |
Klement Sekera | d3ba515 | 2017-02-14 03:09:17 +0100 | [diff] [blame] | 3299 | p = wait_for_bfd_packet(self) |
| 3300 | self.assert_equal(p[BFD].state, BFDState.up, BFDState) |
Klement Sekera | b17dd96 | 2017-01-09 07:43:48 +0100 | [diff] [blame] | 3301 | self.test_session.send_packet() |
| 3302 | self.assert_equal(self.vpp_session.state, BFDState.up, BFDState) |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 3303 | self.assert_equal(len(self.vapi.collect_events()), 0, "number of bfd events") |
Klement Sekera | 46a87ad | 2017-01-02 08:22:23 +0100 | [diff] [blame] | 3304 | |
Klement Sekera | 7388448 | 2017-02-23 09:26:30 +0100 | [diff] [blame] | 3305 | |
Abdel Baig | 17a9181 | 2024-09-03 11:52:20 -0400 | [diff] [blame] | 3306 | @parameterized_class( |
| 3307 | [ |
| 3308 | {"multihop": False}, |
| 3309 | {"multihop": True}, |
| 3310 | ] |
| 3311 | ) |
Andrew Yourtchenko | 06f3281 | 2021-01-14 10:19:08 +0000 | [diff] [blame] | 3312 | @tag_run_solo |
Klement Sekera | 7388448 | 2017-02-23 09:26:30 +0100 | [diff] [blame] | 3313 | class BFDCLITestCase(VppTestCase): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 3314 | """Bidirectional Forwarding Detection (BFD) (CLI)""" |
| 3315 | |
Klement Sekera | 7388448 | 2017-02-23 09:26:30 +0100 | [diff] [blame] | 3316 | pg0 = None |
| 3317 | |
| 3318 | @classmethod |
| 3319 | def setUpClass(cls): |
| 3320 | super(BFDCLITestCase, cls).setUpClass() |
Abdel Baig | 17a9181 | 2024-09-03 11:52:20 -0400 | [diff] [blame] | 3321 | hoptype_str = "MultiHop" if cls.multihop else "SingleHop" |
| 3322 | cls.__doc__ = ( |
| 3323 | f"""""Bidirectional Forwarding Detection (BFD) - CLI - {hoptype_str}""" |
| 3324 | ) |
Damjan Marion | 07a3857 | 2018-01-21 06:44:18 -0800 | [diff] [blame] | 3325 | cls.vapi.cli("set log class bfd level debug") |
Klement Sekera | 7388448 | 2017-02-23 09:26:30 +0100 | [diff] [blame] | 3326 | try: |
Abdel Baig | 17a9181 | 2024-09-03 11:52:20 -0400 | [diff] [blame] | 3327 | cls.create_pg_interfaces([0]) |
| 3328 | cls.create_loopback_interfaces(1) |
| 3329 | cls.loopback0 = cls.lo_interfaces[0] |
| 3330 | cls.loopback0.config_ip4() |
| 3331 | cls.loopback0.config_ip6() |
| 3332 | cls.loopback0.admin_up() |
Klement Sekera | 7388448 | 2017-02-23 09:26:30 +0100 | [diff] [blame] | 3333 | cls.pg0.config_ip4() |
| 3334 | cls.pg0.config_ip6() |
Abdel Baig | 17a9181 | 2024-09-03 11:52:20 -0400 | [diff] [blame] | 3335 | cls.pg0.configure_ipv4_neighbors() |
| 3336 | cls.pg0.admin_up() |
Klement Sekera | 7388448 | 2017-02-23 09:26:30 +0100 | [diff] [blame] | 3337 | cls.pg0.resolve_arp() |
| 3338 | cls.pg0.resolve_ndp() |
| 3339 | |
| 3340 | except Exception: |
| 3341 | super(BFDCLITestCase, cls).tearDownClass() |
| 3342 | raise |
| 3343 | |
Paul Vinciguerra | 8d991d9 | 2019-01-25 14:05:48 -0800 | [diff] [blame] | 3344 | @classmethod |
| 3345 | def tearDownClass(cls): |
| 3346 | super(BFDCLITestCase, cls).tearDownClass() |
| 3347 | |
Klement Sekera | 7388448 | 2017-02-23 09:26:30 +0100 | [diff] [blame] | 3348 | def setUp(self): |
| 3349 | super(BFDCLITestCase, self).setUp() |
| 3350 | self.factory = AuthKeyFactory() |
| 3351 | self.pg0.enable_capture() |
Abdel Baig | 17a9181 | 2024-09-03 11:52:20 -0400 | [diff] [blame] | 3352 | set_ipv4_pfx_route_info(self, self.pg0, BFD_IPV4_REMOTE_ADDR, True) |
| 3353 | set_ipv6_pfx_route_info(self, self.pg0, BFD_IPV6_REMOTE_ADDR, True) |
| 3354 | |
| 3355 | if self.multihop: |
| 3356 | self.cli_str = "multihop" |
| 3357 | else: |
| 3358 | self.cli_str = "interface %s" % self.pg0.name |
Klement Sekera | 7388448 | 2017-02-23 09:26:30 +0100 | [diff] [blame] | 3359 | |
| 3360 | def tearDown(self): |
| 3361 | try: |
Jakub Grajciar | 4682feb | 2019-09-02 13:28:52 +0200 | [diff] [blame] | 3362 | self.vapi.want_bfd_events(enable_disable=False) |
Klement Sekera | 7388448 | 2017-02-23 09:26:30 +0100 | [diff] [blame] | 3363 | except UnexpectedApiReturnValueError: |
| 3364 | # some tests aren't subscribed, so this is not an issue |
| 3365 | pass |
| 3366 | self.vapi.collect_events() # clear the event queue |
| 3367 | super(BFDCLITestCase, self).tearDown() |
| 3368 | |
| 3369 | def cli_verify_no_response(self, cli): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 3370 | """execute a CLI, asserting that the response is empty""" |
| 3371 | self.assert_equal(self.vapi.cli(cli), "", "CLI command response") |
Klement Sekera | 7388448 | 2017-02-23 09:26:30 +0100 | [diff] [blame] | 3372 | |
| 3373 | def cli_verify_response(self, cli, expected): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 3374 | """execute a CLI, asserting that the response matches expectation""" |
Jakub Grajciar | 4682feb | 2019-09-02 13:28:52 +0200 | [diff] [blame] | 3375 | try: |
| 3376 | reply = self.vapi.cli(cli) |
| 3377 | except CliFailedCommandError as cli_error: |
| 3378 | reply = str(cli_error) |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 3379 | self.assert_equal(reply.strip(), expected, "CLI command response") |
Klement Sekera | 7388448 | 2017-02-23 09:26:30 +0100 | [diff] [blame] | 3380 | |
| 3381 | def test_show(self): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 3382 | """show commands""" |
Klement Sekera | 7388448 | 2017-02-23 09:26:30 +0100 | [diff] [blame] | 3383 | k1 = self.factory.create_random_key(self) |
| 3384 | k1.add_vpp_config() |
| 3385 | k2 = self.factory.create_random_key( |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 3386 | self, auth_type=BFDAuthType.meticulous_keyed_sha1 |
| 3387 | ) |
Klement Sekera | 7388448 | 2017-02-23 09:26:30 +0100 | [diff] [blame] | 3388 | k2.add_vpp_config() |
Abdel Baig | 17a9181 | 2024-09-03 11:52:20 -0400 | [diff] [blame] | 3389 | s1 = VppBFDUDPSession( |
| 3390 | self, |
| 3391 | self.pg0, |
| 3392 | self.dst_ip_net, |
| 3393 | local_addr=self.src_ip_net, |
| 3394 | multihop=self.multihop, |
| 3395 | ) |
Klement Sekera | 7388448 | 2017-02-23 09:26:30 +0100 | [diff] [blame] | 3396 | s1.add_vpp_config() |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 3397 | s2 = VppBFDUDPSession( |
Abdel Baig | 17a9181 | 2024-09-03 11:52:20 -0400 | [diff] [blame] | 3398 | self, |
| 3399 | self.pg0, |
| 3400 | self.dst_ip6_net, |
| 3401 | local_addr=self.src_ip6_net, |
| 3402 | af=AF_INET6, |
| 3403 | multihop=self.multihop, |
| 3404 | sha1_key=k2, |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 3405 | ) |
Klement Sekera | 7388448 | 2017-02-23 09:26:30 +0100 | [diff] [blame] | 3406 | s2.add_vpp_config() |
| 3407 | self.logger.info(self.vapi.ppcli("show bfd keys")) |
| 3408 | self.logger.info(self.vapi.ppcli("show bfd sessions")) |
| 3409 | self.logger.info(self.vapi.ppcli("show bfd")) |
| 3410 | |
| 3411 | def test_set_del_sha1_key(self): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 3412 | """set/delete SHA1 auth key""" |
Klement Sekera | 7388448 | 2017-02-23 09:26:30 +0100 | [diff] [blame] | 3413 | k = self.factory.create_random_key(self) |
| 3414 | self.registry.register(k, self.logger) |
| 3415 | self.cli_verify_no_response( |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 3416 | "bfd key set conf-key-id %s type keyed-sha1 secret %s" |
| 3417 | % ( |
| 3418 | k.conf_key_id, |
| 3419 | "".join("{:02x}".format(scapy.compat.orb(c)) for c in k.key), |
| 3420 | ) |
| 3421 | ) |
Klement Sekera | 7388448 | 2017-02-23 09:26:30 +0100 | [diff] [blame] | 3422 | self.assertTrue(k.query_vpp_config()) |
| 3423 | self.vpp_session = VppBFDUDPSession( |
Abdel Baig | 17a9181 | 2024-09-03 11:52:20 -0400 | [diff] [blame] | 3424 | self, |
| 3425 | self.pg0, |
| 3426 | self.dst_ip_net, |
| 3427 | local_addr=self.src_ip_net, |
| 3428 | multihop=self.multihop, |
| 3429 | sha1_key=k, |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 3430 | ) |
Klement Sekera | 7388448 | 2017-02-23 09:26:30 +0100 | [diff] [blame] | 3431 | self.vpp_session.add_vpp_config() |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 3432 | self.test_session = BFDTestSession( |
Abdel Baig | 17a9181 | 2024-09-03 11:52:20 -0400 | [diff] [blame] | 3433 | self, |
| 3434 | self.pg0, |
| 3435 | AF_INET, |
| 3436 | local_addr=self.src_ip_net, |
| 3437 | peer_addr=self.dst_ip_net, |
| 3438 | multihop=self.multihop, |
| 3439 | sha1_key=k, |
| 3440 | bfd_key_id=self.vpp_session.bfd_key_id, |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 3441 | ) |
Klement Sekera | 7388448 | 2017-02-23 09:26:30 +0100 | [diff] [blame] | 3442 | self.vapi.want_bfd_events() |
| 3443 | bfd_session_up(self) |
| 3444 | bfd_session_down(self) |
| 3445 | # try to replace the secret for the key - should fail because the key |
| 3446 | # is in-use |
| 3447 | k2 = self.factory.create_random_key(self) |
| 3448 | self.cli_verify_response( |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 3449 | "bfd key set conf-key-id %s type keyed-sha1 secret %s" |
| 3450 | % ( |
| 3451 | k.conf_key_id, |
| 3452 | "".join("{:02x}".format(scapy.compat.orb(c)) for c in k2.key), |
| 3453 | ), |
Klement Sekera | 7388448 | 2017-02-23 09:26:30 +0100 | [diff] [blame] | 3454 | "bfd key set: `bfd_auth_set_key' API call failed, " |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 3455 | "rv=-103:BFD object in use", |
| 3456 | ) |
Klement Sekera | 7388448 | 2017-02-23 09:26:30 +0100 | [diff] [blame] | 3457 | # manipulating the session using old secret should still work |
| 3458 | bfd_session_up(self) |
| 3459 | bfd_session_down(self) |
| 3460 | self.vpp_session.remove_vpp_config() |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 3461 | self.cli_verify_no_response("bfd key del conf-key-id %s" % k.conf_key_id) |
Klement Sekera | 7388448 | 2017-02-23 09:26:30 +0100 | [diff] [blame] | 3462 | self.assertFalse(k.query_vpp_config()) |
| 3463 | |
| 3464 | def test_set_del_meticulous_sha1_key(self): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 3465 | """set/delete meticulous SHA1 auth key""" |
Klement Sekera | 7388448 | 2017-02-23 09:26:30 +0100 | [diff] [blame] | 3466 | k = self.factory.create_random_key( |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 3467 | self, auth_type=BFDAuthType.meticulous_keyed_sha1 |
| 3468 | ) |
Klement Sekera | 7388448 | 2017-02-23 09:26:30 +0100 | [diff] [blame] | 3469 | self.registry.register(k, self.logger) |
| 3470 | self.cli_verify_no_response( |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 3471 | "bfd key set conf-key-id %s type meticulous-keyed-sha1 secret %s" |
| 3472 | % ( |
| 3473 | k.conf_key_id, |
| 3474 | "".join("{:02x}".format(scapy.compat.orb(c)) for c in k.key), |
| 3475 | ) |
| 3476 | ) |
Klement Sekera | 7388448 | 2017-02-23 09:26:30 +0100 | [diff] [blame] | 3477 | self.assertTrue(k.query_vpp_config()) |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 3478 | self.vpp_session = VppBFDUDPSession( |
Abdel Baig | 17a9181 | 2024-09-03 11:52:20 -0400 | [diff] [blame] | 3479 | self, |
| 3480 | self.pg0, |
| 3481 | self.dst_ip6_net, |
| 3482 | local_addr=self.src_ip6_net, |
| 3483 | af=AF_INET6, |
| 3484 | multihop=self.multihop, |
| 3485 | sha1_key=k, |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 3486 | ) |
Klement Sekera | 7388448 | 2017-02-23 09:26:30 +0100 | [diff] [blame] | 3487 | self.vpp_session.add_vpp_config() |
| 3488 | self.vpp_session.admin_up() |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 3489 | self.test_session = BFDTestSession( |
Abdel Baig | 17a9181 | 2024-09-03 11:52:20 -0400 | [diff] [blame] | 3490 | self, |
| 3491 | self.pg0, |
| 3492 | AF_INET6, |
| 3493 | local_addr=self.src_ip6_net, |
| 3494 | peer_addr=self.dst_ip6_net, |
| 3495 | multihop=self.multihop, |
| 3496 | sha1_key=k, |
| 3497 | bfd_key_id=self.vpp_session.bfd_key_id, |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 3498 | ) |
Klement Sekera | 7388448 | 2017-02-23 09:26:30 +0100 | [diff] [blame] | 3499 | self.vapi.want_bfd_events() |
| 3500 | bfd_session_up(self) |
| 3501 | bfd_session_down(self) |
| 3502 | # try to replace the secret for the key - should fail because the key |
| 3503 | # is in-use |
| 3504 | k2 = self.factory.create_random_key(self) |
| 3505 | self.cli_verify_response( |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 3506 | "bfd key set conf-key-id %s type keyed-sha1 secret %s" |
| 3507 | % ( |
| 3508 | k.conf_key_id, |
| 3509 | "".join("{:02x}".format(scapy.compat.orb(c)) for c in k2.key), |
| 3510 | ), |
Klement Sekera | 7388448 | 2017-02-23 09:26:30 +0100 | [diff] [blame] | 3511 | "bfd key set: `bfd_auth_set_key' API call failed, " |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 3512 | "rv=-103:BFD object in use", |
| 3513 | ) |
Klement Sekera | 7388448 | 2017-02-23 09:26:30 +0100 | [diff] [blame] | 3514 | # manipulating the session using old secret should still work |
| 3515 | bfd_session_up(self) |
| 3516 | bfd_session_down(self) |
| 3517 | self.vpp_session.remove_vpp_config() |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 3518 | self.cli_verify_no_response("bfd key del conf-key-id %s" % k.conf_key_id) |
Klement Sekera | 7388448 | 2017-02-23 09:26:30 +0100 | [diff] [blame] | 3519 | self.assertFalse(k.query_vpp_config()) |
| 3520 | |
| 3521 | def test_add_mod_del_bfd_udp(self): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 3522 | """create/modify/delete IPv4 BFD UDP session""" |
Abdel Baig | 17a9181 | 2024-09-03 11:52:20 -0400 | [diff] [blame] | 3523 | vpp_session = VppBFDUDPSession( |
| 3524 | self, |
| 3525 | self.pg0, |
| 3526 | self.dst_ip_net, |
| 3527 | local_addr=self.src_ip_net, |
| 3528 | multihop=self.multihop, |
| 3529 | ) |
Klement Sekera | 7388448 | 2017-02-23 09:26:30 +0100 | [diff] [blame] | 3530 | self.registry.register(vpp_session, self.logger) |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 3531 | cli_add_cmd = ( |
Abdel Baig | 17a9181 | 2024-09-03 11:52:20 -0400 | [diff] [blame] | 3532 | "bfd udp session add %s local-addr %s " |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 3533 | "peer-addr %s desired-min-tx %s required-min-rx %s " |
| 3534 | "detect-mult %s" |
| 3535 | % ( |
Abdel Baig | 17a9181 | 2024-09-03 11:52:20 -0400 | [diff] [blame] | 3536 | self.cli_str, |
| 3537 | self.src_ip_net, |
| 3538 | self.dst_ip_net, |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 3539 | vpp_session.desired_min_tx, |
| 3540 | vpp_session.required_min_rx, |
| 3541 | vpp_session.detect_mult, |
| 3542 | ) |
| 3543 | ) |
Klement Sekera | 7388448 | 2017-02-23 09:26:30 +0100 | [diff] [blame] | 3544 | self.cli_verify_no_response(cli_add_cmd) |
| 3545 | # 2nd add should fail |
| 3546 | self.cli_verify_response( |
| 3547 | cli_add_cmd, |
| 3548 | "bfd udp session add: `bfd_add_add_session' API call" |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 3549 | " failed, rv=-101:Duplicate BFD object", |
| 3550 | ) |
Klement Sekera | 7388448 | 2017-02-23 09:26:30 +0100 | [diff] [blame] | 3551 | verify_bfd_session_config(self, vpp_session) |
Abdel Baig | 17a9181 | 2024-09-03 11:52:20 -0400 | [diff] [blame] | 3552 | |
Klement Sekera | 7388448 | 2017-02-23 09:26:30 +0100 | [diff] [blame] | 3553 | mod_session = VppBFDUDPSession( |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 3554 | self, |
| 3555 | self.pg0, |
Abdel Baig | 17a9181 | 2024-09-03 11:52:20 -0400 | [diff] [blame] | 3556 | self.dst_ip_net, |
| 3557 | local_addr=self.src_ip_net, |
| 3558 | multihop=self.multihop, |
Klement Sekera | 7388448 | 2017-02-23 09:26:30 +0100 | [diff] [blame] | 3559 | required_min_rx=2 * vpp_session.required_min_rx, |
| 3560 | desired_min_tx=3 * vpp_session.desired_min_tx, |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 3561 | detect_mult=4 * vpp_session.detect_mult, |
| 3562 | ) |
Klement Sekera | 7388448 | 2017-02-23 09:26:30 +0100 | [diff] [blame] | 3563 | self.cli_verify_no_response( |
Abdel Baig | 17a9181 | 2024-09-03 11:52:20 -0400 | [diff] [blame] | 3564 | "bfd udp session mod %s local-addr %s peer-addr %s " |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 3565 | "desired-min-tx %s required-min-rx %s detect-mult %s" |
| 3566 | % ( |
Abdel Baig | 17a9181 | 2024-09-03 11:52:20 -0400 | [diff] [blame] | 3567 | self.cli_str, |
| 3568 | self.src_ip_net, |
| 3569 | self.dst_ip_net, |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 3570 | mod_session.desired_min_tx, |
| 3571 | mod_session.required_min_rx, |
| 3572 | mod_session.detect_mult, |
| 3573 | ) |
| 3574 | ) |
Klement Sekera | 7388448 | 2017-02-23 09:26:30 +0100 | [diff] [blame] | 3575 | verify_bfd_session_config(self, mod_session) |
Abdel Baig | 17a9181 | 2024-09-03 11:52:20 -0400 | [diff] [blame] | 3576 | cli_del_cmd = "bfd udp session del %s local-addr %s peer-addr %s" % ( |
| 3577 | self.cli_str, |
| 3578 | self.src_ip_net, |
| 3579 | self.dst_ip_net, |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 3580 | ) |
Klement Sekera | 7388448 | 2017-02-23 09:26:30 +0100 | [diff] [blame] | 3581 | self.cli_verify_no_response(cli_del_cmd) |
| 3582 | # 2nd del is expected to fail |
| 3583 | self.cli_verify_response( |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 3584 | cli_del_cmd, |
| 3585 | "bfd udp session del: `bfd_udp_del_session' API call" |
| 3586 | " failed, rv=-102:No such BFD object", |
| 3587 | ) |
Klement Sekera | 7388448 | 2017-02-23 09:26:30 +0100 | [diff] [blame] | 3588 | self.assertFalse(vpp_session.query_vpp_config()) |
| 3589 | |
Abdel Baig | 17a9181 | 2024-09-03 11:52:20 -0400 | [diff] [blame] | 3590 | if self.multihop: |
| 3591 | # specifying multihop and interface should fail |
| 3592 | cli_add_cmd = ( |
| 3593 | "bfd udp session add multihop interface %s local-addr 1.1.1.1 " |
| 3594 | "peer-addr 2.2.2.2 desired-min-tx 50000 required-min-rx 1000 " |
| 3595 | "detect-mult 3" % (self.pg0.name) |
| 3596 | ) |
| 3597 | self.cli_verify_response( |
| 3598 | cli_add_cmd, |
| 3599 | "bfd udp session add: Incompatible parameter combination, " |
| 3600 | "interface cannot be specified when multihop is enabled", |
| 3601 | ) |
| 3602 | cli_mod_cmd = ( |
| 3603 | "bfd udp session mod multihop interface %s local-addr 1.1.1.1 " |
| 3604 | "peer-addr 2.2.2.2 desired-min-tx 50000 required-min-rx 1000 " |
| 3605 | "detect-mult 3" % (self.pg0.name) |
| 3606 | ) |
| 3607 | self.cli_verify_response( |
| 3608 | cli_mod_cmd, |
| 3609 | "bfd udp session mod: Incompatible parameter combination, " |
| 3610 | "interface cannot be specified when multihop is enabled", |
| 3611 | ) |
| 3612 | cli_del_cmd = ( |
| 3613 | "bfd udp session del multihop interface %s local-addr 1.1.1.1 " |
| 3614 | "peer-addr 2.2.2.2" % (self.pg0.name) |
| 3615 | ) |
| 3616 | self.cli_verify_response( |
| 3617 | cli_del_cmd, |
| 3618 | "bfd udp session del: Incompatible parameter combination, " |
| 3619 | "interface cannot be specified when multihop is enabled", |
| 3620 | ) |
| 3621 | |
| 3622 | # Not specifying multihop or interface should fail |
| 3623 | cli_add_cmd = ( |
| 3624 | "bfd udp session add local-addr 1.1.1.1 peer-addr 2.2.2.2 " |
| 3625 | "desired-min-tx 50000 required-min-rx 1000 detect-mult 3" |
| 3626 | ) |
| 3627 | self.cli_verify_response( |
| 3628 | cli_add_cmd, |
| 3629 | "bfd udp session add: Incompatible parameter combination, " |
| 3630 | "interface must be set if not multihop", |
| 3631 | ) |
| 3632 | cli_mod_cmd = ( |
| 3633 | "bfd udp session mod local-addr 1.1.1.1 peer-addr 2.2.2.2 " |
| 3634 | "desired-min-tx 50000 required-min-rx 1000 detect-mult 3" |
| 3635 | ) |
| 3636 | self.cli_verify_response( |
| 3637 | cli_mod_cmd, |
| 3638 | "bfd udp session mod: Incompatible parameter combination, " |
| 3639 | "interface must be set if not multihop", |
| 3640 | ) |
| 3641 | cli_del_cmd = "bfd udp session del local-addr 1.1.1.1 peer-addr 2.2.2.2 " |
| 3642 | self.cli_verify_response( |
| 3643 | cli_del_cmd, |
| 3644 | "bfd udp session del: Incompatible parameter combination, " |
| 3645 | "interface must be set if not multihop", |
| 3646 | ) |
| 3647 | |
Klement Sekera | 7388448 | 2017-02-23 09:26:30 +0100 | [diff] [blame] | 3648 | def test_add_mod_del_bfd_udp6(self): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 3649 | """create/modify/delete IPv6 BFD UDP session""" |
Abdel Baig | 17a9181 | 2024-09-03 11:52:20 -0400 | [diff] [blame] | 3650 | vpp_session = VppBFDUDPSession( |
| 3651 | self, |
| 3652 | self.pg0, |
| 3653 | self.dst_ip6_net, |
| 3654 | local_addr=self.src_ip6_net, |
| 3655 | af=AF_INET6, |
| 3656 | multihop=self.multihop, |
| 3657 | ) |
Klement Sekera | 7388448 | 2017-02-23 09:26:30 +0100 | [diff] [blame] | 3658 | self.registry.register(vpp_session, self.logger) |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 3659 | cli_add_cmd = ( |
Abdel Baig | 17a9181 | 2024-09-03 11:52:20 -0400 | [diff] [blame] | 3660 | "bfd udp session add %s local-addr %s " |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 3661 | "peer-addr %s desired-min-tx %s required-min-rx %s " |
| 3662 | "detect-mult %s" |
| 3663 | % ( |
Abdel Baig | 17a9181 | 2024-09-03 11:52:20 -0400 | [diff] [blame] | 3664 | self.cli_str, |
| 3665 | self.src_ip6_net, |
| 3666 | self.dst_ip6_net, |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 3667 | vpp_session.desired_min_tx, |
| 3668 | vpp_session.required_min_rx, |
| 3669 | vpp_session.detect_mult, |
| 3670 | ) |
| 3671 | ) |
Klement Sekera | 7388448 | 2017-02-23 09:26:30 +0100 | [diff] [blame] | 3672 | self.cli_verify_no_response(cli_add_cmd) |
| 3673 | # 2nd add should fail |
| 3674 | self.cli_verify_response( |
| 3675 | cli_add_cmd, |
| 3676 | "bfd udp session add: `bfd_add_add_session' API call" |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 3677 | " failed, rv=-101:Duplicate BFD object", |
| 3678 | ) |
Klement Sekera | 7388448 | 2017-02-23 09:26:30 +0100 | [diff] [blame] | 3679 | verify_bfd_session_config(self, vpp_session) |
| 3680 | mod_session = VppBFDUDPSession( |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 3681 | self, |
| 3682 | self.pg0, |
Abdel Baig | 17a9181 | 2024-09-03 11:52:20 -0400 | [diff] [blame] | 3683 | self.dst_ip6_net, |
| 3684 | local_addr=self.src_ip6_net, |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 3685 | af=AF_INET6, |
Abdel Baig | 17a9181 | 2024-09-03 11:52:20 -0400 | [diff] [blame] | 3686 | multihop=self.multihop, |
Klement Sekera | 7388448 | 2017-02-23 09:26:30 +0100 | [diff] [blame] | 3687 | required_min_rx=2 * vpp_session.required_min_rx, |
| 3688 | desired_min_tx=3 * vpp_session.desired_min_tx, |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 3689 | detect_mult=4 * vpp_session.detect_mult, |
| 3690 | ) |
Klement Sekera | 7388448 | 2017-02-23 09:26:30 +0100 | [diff] [blame] | 3691 | self.cli_verify_no_response( |
Abdel Baig | 17a9181 | 2024-09-03 11:52:20 -0400 | [diff] [blame] | 3692 | "bfd udp session mod %s local-addr %s peer-addr %s " |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 3693 | "desired-min-tx %s required-min-rx %s detect-mult %s" |
| 3694 | % ( |
Abdel Baig | 17a9181 | 2024-09-03 11:52:20 -0400 | [diff] [blame] | 3695 | self.cli_str, |
| 3696 | self.src_ip6_net, |
| 3697 | self.dst_ip6_net, |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 3698 | mod_session.desired_min_tx, |
| 3699 | mod_session.required_min_rx, |
| 3700 | mod_session.detect_mult, |
| 3701 | ) |
| 3702 | ) |
Klement Sekera | 7388448 | 2017-02-23 09:26:30 +0100 | [diff] [blame] | 3703 | verify_bfd_session_config(self, mod_session) |
Abdel Baig | 17a9181 | 2024-09-03 11:52:20 -0400 | [diff] [blame] | 3704 | cli_del_cmd = "bfd udp session del %s local-addr %s peer-addr %s" % ( |
| 3705 | self.cli_str, |
| 3706 | self.src_ip6_net, |
| 3707 | self.dst_ip6_net, |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 3708 | ) |
Klement Sekera | 7388448 | 2017-02-23 09:26:30 +0100 | [diff] [blame] | 3709 | self.cli_verify_no_response(cli_del_cmd) |
| 3710 | # 2nd del is expected to fail |
| 3711 | self.cli_verify_response( |
| 3712 | cli_del_cmd, |
| 3713 | "bfd udp session del: `bfd_udp_del_session' API call" |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 3714 | " failed, rv=-102:No such BFD object", |
| 3715 | ) |
Klement Sekera | 7388448 | 2017-02-23 09:26:30 +0100 | [diff] [blame] | 3716 | self.assertFalse(vpp_session.query_vpp_config()) |
| 3717 | |
| 3718 | def test_add_mod_del_bfd_udp_auth(self): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 3719 | """create/modify/delete IPv4 BFD UDP session (authenticated)""" |
Klement Sekera | 7388448 | 2017-02-23 09:26:30 +0100 | [diff] [blame] | 3720 | key = self.factory.create_random_key(self) |
| 3721 | key.add_vpp_config() |
| 3722 | vpp_session = VppBFDUDPSession( |
Abdel Baig | 17a9181 | 2024-09-03 11:52:20 -0400 | [diff] [blame] | 3723 | self, |
| 3724 | self.pg0, |
| 3725 | self.dst_ip_net, |
| 3726 | local_addr=self.src_ip_net, |
| 3727 | multihop=self.multihop, |
| 3728 | sha1_key=key, |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 3729 | ) |
Klement Sekera | 7388448 | 2017-02-23 09:26:30 +0100 | [diff] [blame] | 3730 | self.registry.register(vpp_session, self.logger) |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 3731 | cli_add_cmd = ( |
Abdel Baig | 17a9181 | 2024-09-03 11:52:20 -0400 | [diff] [blame] | 3732 | "bfd udp session add %s local-addr %s " |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 3733 | "peer-addr %s desired-min-tx %s required-min-rx %s " |
| 3734 | "detect-mult %s conf-key-id %s bfd-key-id %s" |
| 3735 | % ( |
Abdel Baig | 17a9181 | 2024-09-03 11:52:20 -0400 | [diff] [blame] | 3736 | self.cli_str, |
| 3737 | self.src_ip_net, |
| 3738 | self.dst_ip_net, |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 3739 | vpp_session.desired_min_tx, |
| 3740 | vpp_session.required_min_rx, |
| 3741 | vpp_session.detect_mult, |
| 3742 | key.conf_key_id, |
| 3743 | vpp_session.bfd_key_id, |
| 3744 | ) |
| 3745 | ) |
Klement Sekera | 7388448 | 2017-02-23 09:26:30 +0100 | [diff] [blame] | 3746 | self.cli_verify_no_response(cli_add_cmd) |
| 3747 | # 2nd add should fail |
| 3748 | self.cli_verify_response( |
| 3749 | cli_add_cmd, |
| 3750 | "bfd udp session add: `bfd_add_add_session' API call" |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 3751 | " failed, rv=-101:Duplicate BFD object", |
| 3752 | ) |
Klement Sekera | 7388448 | 2017-02-23 09:26:30 +0100 | [diff] [blame] | 3753 | verify_bfd_session_config(self, vpp_session) |
| 3754 | mod_session = VppBFDUDPSession( |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 3755 | self, |
| 3756 | self.pg0, |
Abdel Baig | 17a9181 | 2024-09-03 11:52:20 -0400 | [diff] [blame] | 3757 | self.dst_ip_net, |
| 3758 | local_addr=self.src_ip_net, |
| 3759 | multihop=self.multihop, |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 3760 | sha1_key=key, |
Klement Sekera | 7388448 | 2017-02-23 09:26:30 +0100 | [diff] [blame] | 3761 | bfd_key_id=vpp_session.bfd_key_id, |
| 3762 | required_min_rx=2 * vpp_session.required_min_rx, |
| 3763 | desired_min_tx=3 * vpp_session.desired_min_tx, |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 3764 | detect_mult=4 * vpp_session.detect_mult, |
| 3765 | ) |
Klement Sekera | 7388448 | 2017-02-23 09:26:30 +0100 | [diff] [blame] | 3766 | self.cli_verify_no_response( |
Abdel Baig | 17a9181 | 2024-09-03 11:52:20 -0400 | [diff] [blame] | 3767 | "bfd udp session mod %s local-addr %s peer-addr %s " |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 3768 | "desired-min-tx %s required-min-rx %s detect-mult %s" |
| 3769 | % ( |
Abdel Baig | 17a9181 | 2024-09-03 11:52:20 -0400 | [diff] [blame] | 3770 | self.cli_str, |
| 3771 | self.src_ip_net, |
| 3772 | self.dst_ip_net, |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 3773 | mod_session.desired_min_tx, |
| 3774 | mod_session.required_min_rx, |
| 3775 | mod_session.detect_mult, |
| 3776 | ) |
| 3777 | ) |
Klement Sekera | 7388448 | 2017-02-23 09:26:30 +0100 | [diff] [blame] | 3778 | verify_bfd_session_config(self, mod_session) |
Abdel Baig | 17a9181 | 2024-09-03 11:52:20 -0400 | [diff] [blame] | 3779 | cli_del_cmd = "bfd udp session del %s local-addr %s peer-addr %s" % ( |
| 3780 | self.cli_str, |
| 3781 | self.src_ip_net, |
| 3782 | self.dst_ip_net, |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 3783 | ) |
Klement Sekera | 7388448 | 2017-02-23 09:26:30 +0100 | [diff] [blame] | 3784 | self.cli_verify_no_response(cli_del_cmd) |
| 3785 | # 2nd del is expected to fail |
| 3786 | self.cli_verify_response( |
| 3787 | cli_del_cmd, |
| 3788 | "bfd udp session del: `bfd_udp_del_session' API call" |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 3789 | " failed, rv=-102:No such BFD object", |
| 3790 | ) |
Klement Sekera | 7388448 | 2017-02-23 09:26:30 +0100 | [diff] [blame] | 3791 | self.assertFalse(vpp_session.query_vpp_config()) |
| 3792 | |
| 3793 | def test_add_mod_del_bfd_udp6_auth(self): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 3794 | """create/modify/delete IPv6 BFD UDP session (authenticated)""" |
Klement Sekera | 7388448 | 2017-02-23 09:26:30 +0100 | [diff] [blame] | 3795 | key = self.factory.create_random_key( |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 3796 | self, auth_type=BFDAuthType.meticulous_keyed_sha1 |
| 3797 | ) |
Klement Sekera | 7388448 | 2017-02-23 09:26:30 +0100 | [diff] [blame] | 3798 | key.add_vpp_config() |
| 3799 | vpp_session = VppBFDUDPSession( |
Abdel Baig | 17a9181 | 2024-09-03 11:52:20 -0400 | [diff] [blame] | 3800 | self, |
| 3801 | self.pg0, |
| 3802 | self.dst_ip6_net, |
| 3803 | local_addr=self.src_ip6_net, |
| 3804 | af=AF_INET6, |
| 3805 | multihop=self.multihop, |
| 3806 | sha1_key=key, |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 3807 | ) |
Klement Sekera | 7388448 | 2017-02-23 09:26:30 +0100 | [diff] [blame] | 3808 | self.registry.register(vpp_session, self.logger) |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 3809 | cli_add_cmd = ( |
Abdel Baig | 17a9181 | 2024-09-03 11:52:20 -0400 | [diff] [blame] | 3810 | "bfd udp session add %s local-addr %s " |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 3811 | "peer-addr %s desired-min-tx %s required-min-rx %s " |
| 3812 | "detect-mult %s conf-key-id %s bfd-key-id %s" |
| 3813 | % ( |
Abdel Baig | 17a9181 | 2024-09-03 11:52:20 -0400 | [diff] [blame] | 3814 | self.cli_str, |
| 3815 | self.src_ip6_net, |
| 3816 | self.dst_ip6_net, |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 3817 | vpp_session.desired_min_tx, |
| 3818 | vpp_session.required_min_rx, |
| 3819 | vpp_session.detect_mult, |
| 3820 | key.conf_key_id, |
| 3821 | vpp_session.bfd_key_id, |
| 3822 | ) |
| 3823 | ) |
Klement Sekera | 7388448 | 2017-02-23 09:26:30 +0100 | [diff] [blame] | 3824 | self.cli_verify_no_response(cli_add_cmd) |
| 3825 | # 2nd add should fail |
| 3826 | self.cli_verify_response( |
| 3827 | cli_add_cmd, |
| 3828 | "bfd udp session add: `bfd_add_add_session' API call" |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 3829 | " failed, rv=-101:Duplicate BFD object", |
| 3830 | ) |
Klement Sekera | 7388448 | 2017-02-23 09:26:30 +0100 | [diff] [blame] | 3831 | verify_bfd_session_config(self, vpp_session) |
| 3832 | mod_session = VppBFDUDPSession( |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 3833 | self, |
| 3834 | self.pg0, |
Abdel Baig | 17a9181 | 2024-09-03 11:52:20 -0400 | [diff] [blame] | 3835 | self.dst_ip6_net, |
| 3836 | local_addr=self.src_ip6_net, |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 3837 | af=AF_INET6, |
Abdel Baig | 17a9181 | 2024-09-03 11:52:20 -0400 | [diff] [blame] | 3838 | multihop=self.multihop, |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 3839 | sha1_key=key, |
Klement Sekera | 7388448 | 2017-02-23 09:26:30 +0100 | [diff] [blame] | 3840 | bfd_key_id=vpp_session.bfd_key_id, |
| 3841 | required_min_rx=2 * vpp_session.required_min_rx, |
| 3842 | desired_min_tx=3 * vpp_session.desired_min_tx, |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 3843 | detect_mult=4 * vpp_session.detect_mult, |
| 3844 | ) |
Klement Sekera | 7388448 | 2017-02-23 09:26:30 +0100 | [diff] [blame] | 3845 | self.cli_verify_no_response( |
Abdel Baig | 17a9181 | 2024-09-03 11:52:20 -0400 | [diff] [blame] | 3846 | "bfd udp session mod %s local-addr %s peer-addr %s " |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 3847 | "desired-min-tx %s required-min-rx %s detect-mult %s" |
| 3848 | % ( |
Abdel Baig | 17a9181 | 2024-09-03 11:52:20 -0400 | [diff] [blame] | 3849 | self.cli_str, |
| 3850 | self.src_ip6_net, |
| 3851 | self.dst_ip6_net, |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 3852 | mod_session.desired_min_tx, |
| 3853 | mod_session.required_min_rx, |
| 3854 | mod_session.detect_mult, |
| 3855 | ) |
| 3856 | ) |
Klement Sekera | 7388448 | 2017-02-23 09:26:30 +0100 | [diff] [blame] | 3857 | verify_bfd_session_config(self, mod_session) |
Abdel Baig | 17a9181 | 2024-09-03 11:52:20 -0400 | [diff] [blame] | 3858 | cli_del_cmd = "bfd udp session del %s local-addr %s peer-addr %s" % ( |
| 3859 | self.cli_str, |
| 3860 | self.src_ip6_net, |
| 3861 | self.dst_ip6_net, |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 3862 | ) |
Klement Sekera | 7388448 | 2017-02-23 09:26:30 +0100 | [diff] [blame] | 3863 | self.cli_verify_no_response(cli_del_cmd) |
| 3864 | # 2nd del is expected to fail |
| 3865 | self.cli_verify_response( |
| 3866 | cli_del_cmd, |
| 3867 | "bfd udp session del: `bfd_udp_del_session' API call" |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 3868 | " failed, rv=-102:No such BFD object", |
| 3869 | ) |
Klement Sekera | 7388448 | 2017-02-23 09:26:30 +0100 | [diff] [blame] | 3870 | self.assertFalse(vpp_session.query_vpp_config()) |
| 3871 | |
| 3872 | def test_auth_on_off(self): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 3873 | """turn authentication on and off""" |
Klement Sekera | 7388448 | 2017-02-23 09:26:30 +0100 | [diff] [blame] | 3874 | key = self.factory.create_random_key( |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 3875 | self, auth_type=BFDAuthType.meticulous_keyed_sha1 |
| 3876 | ) |
Klement Sekera | 7388448 | 2017-02-23 09:26:30 +0100 | [diff] [blame] | 3877 | key.add_vpp_config() |
Abdel Baig | 17a9181 | 2024-09-03 11:52:20 -0400 | [diff] [blame] | 3878 | session = VppBFDUDPSession( |
| 3879 | self, |
| 3880 | self.pg0, |
| 3881 | self.dst_ip_net, |
| 3882 | local_addr=self.src_ip_net, |
| 3883 | multihop=self.multihop, |
| 3884 | ) |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 3885 | auth_session = VppBFDUDPSession( |
Abdel Baig | 17a9181 | 2024-09-03 11:52:20 -0400 | [diff] [blame] | 3886 | self, |
| 3887 | self.pg0, |
| 3888 | self.dst_ip_net, |
| 3889 | local_addr=self.src_ip_net, |
| 3890 | multihop=self.multihop, |
| 3891 | sha1_key=key, |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 3892 | ) |
Klement Sekera | 7388448 | 2017-02-23 09:26:30 +0100 | [diff] [blame] | 3893 | session.add_vpp_config() |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 3894 | cli_activate = ( |
Abdel Baig | 17a9181 | 2024-09-03 11:52:20 -0400 | [diff] [blame] | 3895 | "bfd udp session auth activate %s local-addr %s " |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 3896 | "peer-addr %s conf-key-id %s bfd-key-id %s" |
| 3897 | % ( |
Abdel Baig | 17a9181 | 2024-09-03 11:52:20 -0400 | [diff] [blame] | 3898 | self.cli_str, |
| 3899 | self.src_ip_net, |
| 3900 | self.dst_ip_net, |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 3901 | key.conf_key_id, |
| 3902 | auth_session.bfd_key_id, |
| 3903 | ) |
| 3904 | ) |
Klement Sekera | 7388448 | 2017-02-23 09:26:30 +0100 | [diff] [blame] | 3905 | self.cli_verify_no_response(cli_activate) |
| 3906 | verify_bfd_session_config(self, auth_session) |
| 3907 | self.cli_verify_no_response(cli_activate) |
| 3908 | verify_bfd_session_config(self, auth_session) |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 3909 | cli_deactivate = ( |
Abdel Baig | 17a9181 | 2024-09-03 11:52:20 -0400 | [diff] [blame] | 3910 | "bfd udp session auth deactivate %s local-addr %s " |
| 3911 | "peer-addr %s" % (self.cli_str, self.src_ip_net, self.dst_ip_net) |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 3912 | ) |
Klement Sekera | 7388448 | 2017-02-23 09:26:30 +0100 | [diff] [blame] | 3913 | self.cli_verify_no_response(cli_deactivate) |
| 3914 | verify_bfd_session_config(self, session) |
| 3915 | self.cli_verify_no_response(cli_deactivate) |
| 3916 | verify_bfd_session_config(self, session) |
| 3917 | |
Abdel Baig | 17a9181 | 2024-09-03 11:52:20 -0400 | [diff] [blame] | 3918 | if self.multihop: |
| 3919 | # specifying multihop and interface should fail |
| 3920 | cli_activate = ( |
| 3921 | "bfd udp session auth activate multihop interface %s " |
| 3922 | "local-addr %s peer-addr %s conf-key-id %s bfd-key-id %s" |
| 3923 | % ( |
| 3924 | self.pg0.name, |
| 3925 | self.src_ip_net, |
| 3926 | self.dst_ip_net, |
| 3927 | key.conf_key_id, |
| 3928 | auth_session.bfd_key_id, |
| 3929 | ) |
| 3930 | ) |
| 3931 | self.cli_verify_response( |
| 3932 | cli_activate, |
| 3933 | "bfd udp session auth activate: Incompatible parameter " |
| 3934 | "combination, interface cannot be specified when multihop " |
| 3935 | "is enabled", |
| 3936 | ) |
| 3937 | cli_deactivate = ( |
| 3938 | "bfd udp session auth deactivate multihop interface %s " |
| 3939 | "local-addr %s peer-addr %s" |
| 3940 | % ( |
| 3941 | self.pg0.name, |
| 3942 | self.src_ip_net, |
| 3943 | self.dst_ip_net, |
| 3944 | ) |
| 3945 | ) |
| 3946 | self.cli_verify_response( |
| 3947 | cli_deactivate, |
| 3948 | "bfd udp session auth deactivate: Incompatible parameter " |
| 3949 | "combination, interface cannot be specified when multihop " |
| 3950 | "is enabled", |
| 3951 | ) |
| 3952 | # Not specifying multihop or interface should fail |
| 3953 | cli_activate = ( |
| 3954 | "bfd udp session auth activate local-addr %s peer-addr %s " |
| 3955 | "conf-key-id %s bfd-key-id %s" |
| 3956 | % ( |
| 3957 | self.src_ip_net, |
| 3958 | self.dst_ip_net, |
| 3959 | key.conf_key_id, |
| 3960 | auth_session.bfd_key_id, |
| 3961 | ) |
| 3962 | ) |
| 3963 | self.cli_verify_response( |
| 3964 | cli_activate, |
| 3965 | "bfd udp session auth activate: Incompatible parameter " |
| 3966 | "combination, interface must be set if not multihop", |
| 3967 | ) |
| 3968 | cli_deactivate = ( |
| 3969 | "bfd udp session auth deactivate local-addr %s peer-addr %s " |
| 3970 | % ( |
| 3971 | self.src_ip_net, |
| 3972 | self.dst_ip_net, |
| 3973 | ) |
| 3974 | ) |
| 3975 | self.cli_verify_response( |
| 3976 | cli_deactivate, |
| 3977 | "bfd udp session auth deactivate: Incompatible parameter " |
| 3978 | "combination, interface must be set if not multihop", |
| 3979 | ) |
| 3980 | |
Klement Sekera | 7388448 | 2017-02-23 09:26:30 +0100 | [diff] [blame] | 3981 | def test_auth_on_off_delayed(self): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 3982 | """turn authentication on and off (delayed)""" |
Klement Sekera | 7388448 | 2017-02-23 09:26:30 +0100 | [diff] [blame] | 3983 | key = self.factory.create_random_key( |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 3984 | self, auth_type=BFDAuthType.meticulous_keyed_sha1 |
| 3985 | ) |
Klement Sekera | 7388448 | 2017-02-23 09:26:30 +0100 | [diff] [blame] | 3986 | key.add_vpp_config() |
Abdel Baig | 17a9181 | 2024-09-03 11:52:20 -0400 | [diff] [blame] | 3987 | session = VppBFDUDPSession( |
| 3988 | self, |
| 3989 | self.pg0, |
| 3990 | self.dst_ip_net, |
| 3991 | local_addr=self.src_ip_net, |
| 3992 | multihop=self.multihop, |
| 3993 | ) |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 3994 | auth_session = VppBFDUDPSession( |
Abdel Baig | 17a9181 | 2024-09-03 11:52:20 -0400 | [diff] [blame] | 3995 | self, |
| 3996 | self.pg0, |
| 3997 | self.dst_ip_net, |
| 3998 | local_addr=self.src_ip_net, |
| 3999 | multihop=self.multihop, |
| 4000 | sha1_key=key, |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 4001 | ) |
Klement Sekera | 7388448 | 2017-02-23 09:26:30 +0100 | [diff] [blame] | 4002 | session.add_vpp_config() |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 4003 | cli_activate = ( |
Abdel Baig | 17a9181 | 2024-09-03 11:52:20 -0400 | [diff] [blame] | 4004 | "bfd udp session auth activate %s local-addr %s " |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 4005 | "peer-addr %s conf-key-id %s bfd-key-id %s delayed yes" |
| 4006 | % ( |
Abdel Baig | 17a9181 | 2024-09-03 11:52:20 -0400 | [diff] [blame] | 4007 | self.cli_str, |
| 4008 | self.src_ip_net, |
| 4009 | self.dst_ip_net, |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 4010 | key.conf_key_id, |
| 4011 | auth_session.bfd_key_id, |
| 4012 | ) |
| 4013 | ) |
Klement Sekera | 7388448 | 2017-02-23 09:26:30 +0100 | [diff] [blame] | 4014 | self.cli_verify_no_response(cli_activate) |
| 4015 | verify_bfd_session_config(self, auth_session) |
| 4016 | self.cli_verify_no_response(cli_activate) |
| 4017 | verify_bfd_session_config(self, auth_session) |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 4018 | cli_deactivate = ( |
Abdel Baig | 17a9181 | 2024-09-03 11:52:20 -0400 | [diff] [blame] | 4019 | "bfd udp session auth deactivate %s local-addr %s " |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 4020 | "peer-addr %s delayed yes" |
Abdel Baig | 17a9181 | 2024-09-03 11:52:20 -0400 | [diff] [blame] | 4021 | % (self.cli_str, self.src_ip_net, self.dst_ip_net) |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 4022 | ) |
Klement Sekera | 7388448 | 2017-02-23 09:26:30 +0100 | [diff] [blame] | 4023 | self.cli_verify_no_response(cli_deactivate) |
| 4024 | verify_bfd_session_config(self, session) |
| 4025 | self.cli_verify_no_response(cli_deactivate) |
| 4026 | verify_bfd_session_config(self, session) |
| 4027 | |
| 4028 | def test_admin_up_down(self): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 4029 | """put session admin-up and admin-down""" |
Abdel Baig | 17a9181 | 2024-09-03 11:52:20 -0400 | [diff] [blame] | 4030 | session = VppBFDUDPSession( |
| 4031 | self, |
| 4032 | self.pg0, |
| 4033 | self.dst_ip_net, |
| 4034 | local_addr=self.src_ip_net, |
| 4035 | multihop=self.multihop, |
| 4036 | ) |
Klement Sekera | 7388448 | 2017-02-23 09:26:30 +0100 | [diff] [blame] | 4037 | session.add_vpp_config() |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 4038 | cli_down = ( |
Abdel Baig | 17a9181 | 2024-09-03 11:52:20 -0400 | [diff] [blame] | 4039 | "bfd udp session set-flags admin down %s local-addr %s " |
| 4040 | "peer-addr %s " % (self.cli_str, self.src_ip_net, self.dst_ip_net) |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 4041 | ) |
| 4042 | cli_up = ( |
Abdel Baig | 17a9181 | 2024-09-03 11:52:20 -0400 | [diff] [blame] | 4043 | "bfd udp session set-flags admin up %s local-addr %s " |
| 4044 | "peer-addr %s " % (self.cli_str, self.src_ip_net, self.dst_ip_net) |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 4045 | ) |
Klement Sekera | 7388448 | 2017-02-23 09:26:30 +0100 | [diff] [blame] | 4046 | self.cli_verify_no_response(cli_down) |
| 4047 | verify_bfd_session_config(self, session, state=BFDState.admin_down) |
| 4048 | self.cli_verify_no_response(cli_up) |
| 4049 | verify_bfd_session_config(self, session, state=BFDState.down) |
| 4050 | |
Abdel Baig | 17a9181 | 2024-09-03 11:52:20 -0400 | [diff] [blame] | 4051 | if self.multihop: |
| 4052 | # specifying multihop and interface should fail |
| 4053 | cli_up = ( |
| 4054 | "bfd udp session set-flags admin up multihop interface %s " |
| 4055 | "local-addr %s peer-addr %s" |
| 4056 | % ( |
| 4057 | self.pg0.name, |
| 4058 | self.src_ip_net, |
| 4059 | self.dst_ip_net, |
| 4060 | ) |
| 4061 | ) |
| 4062 | self.cli_verify_response( |
| 4063 | cli_up, |
| 4064 | "bfd udp session set-flags: Incompatible parameter " |
| 4065 | "combination, interface cannot be specified when multihop " |
| 4066 | "is enabled", |
| 4067 | ) |
| 4068 | # Not specifying multihop or interface should fail |
| 4069 | cli_up = ( |
| 4070 | "bfd udp session set-flags admin up local-addr %s peer-addr %s " |
| 4071 | % ( |
| 4072 | self.src_ip_net, |
| 4073 | self.dst_ip_net, |
| 4074 | ) |
| 4075 | ) |
| 4076 | self.cli_verify_response( |
| 4077 | cli_up, |
| 4078 | "bfd udp session set-flags: Incompatible parameter " |
| 4079 | "combination, interface must be set if not multihop", |
| 4080 | ) |
| 4081 | |
Klement Sekera | 7388448 | 2017-02-23 09:26:30 +0100 | [diff] [blame] | 4082 | def test_set_del_udp_echo_source(self): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 4083 | """set/del udp echo source""" |
Abdel Baig | 17a9181 | 2024-09-03 11:52:20 -0400 | [diff] [blame] | 4084 | |
| 4085 | if self.multihop: |
| 4086 | self.skipTest( |
| 4087 | f"Skipping because echo functionality is not supported with multihop" |
| 4088 | ) |
| 4089 | |
Klement Sekera | b9ef273 | 2018-06-24 22:49:33 +0200 | [diff] [blame] | 4090 | self.create_loopback_interfaces(1) |
Klement Sekera | 7388448 | 2017-02-23 09:26:30 +0100 | [diff] [blame] | 4091 | self.loopback0 = self.lo_interfaces[0] |
| 4092 | self.loopback0.admin_up() |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 4093 | self.cli_verify_response("show bfd echo-source", "UDP echo source is not set.") |
Klement Sekera | 7388448 | 2017-02-23 09:26:30 +0100 | [diff] [blame] | 4094 | cli_set = "bfd udp echo-source set interface %s" % self.loopback0.name |
| 4095 | self.cli_verify_no_response(cli_set) |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 4096 | self.cli_verify_response( |
| 4097 | "show bfd echo-source", |
| 4098 | "UDP echo source is: %s\n" |
| 4099 | "IPv4 address usable as echo source: none\n" |
| 4100 | "IPv6 address usable as echo source: none" % self.loopback0.name, |
| 4101 | ) |
Klement Sekera | 7388448 | 2017-02-23 09:26:30 +0100 | [diff] [blame] | 4102 | self.loopback0.config_ip4() |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 4103 | echo_ip4 = str( |
| 4104 | ipaddress.IPv4Address( |
| 4105 | int(ipaddress.IPv4Address(self.loopback0.local_ip4)) ^ 1 |
| 4106 | ) |
| 4107 | ) |
| 4108 | self.cli_verify_response( |
| 4109 | "show bfd echo-source", |
| 4110 | "UDP echo source is: %s\n" |
| 4111 | "IPv4 address usable as echo source: %s\n" |
| 4112 | "IPv6 address usable as echo source: none" |
| 4113 | % (self.loopback0.name, echo_ip4), |
| 4114 | ) |
| 4115 | echo_ip6 = str( |
| 4116 | ipaddress.IPv6Address( |
| 4117 | int(ipaddress.IPv6Address(self.loopback0.local_ip6)) ^ 1 |
| 4118 | ) |
| 4119 | ) |
Klement Sekera | 7388448 | 2017-02-23 09:26:30 +0100 | [diff] [blame] | 4120 | self.loopback0.config_ip6() |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 4121 | self.cli_verify_response( |
| 4122 | "show bfd echo-source", |
| 4123 | "UDP echo source is: %s\n" |
| 4124 | "IPv4 address usable as echo source: %s\n" |
| 4125 | "IPv6 address usable as echo source: %s" |
| 4126 | % (self.loopback0.name, echo_ip4, echo_ip6), |
| 4127 | ) |
Klement Sekera | 7388448 | 2017-02-23 09:26:30 +0100 | [diff] [blame] | 4128 | cli_del = "bfd udp echo-source del" |
| 4129 | self.cli_verify_no_response(cli_del) |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 4130 | self.cli_verify_response("show bfd echo-source", "UDP echo source is not set.") |
Klement Sekera | 7388448 | 2017-02-23 09:26:30 +0100 | [diff] [blame] | 4131 | |
Jakub Grajciar | 4682feb | 2019-09-02 13:28:52 +0200 | [diff] [blame] | 4132 | |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 4133 | if __name__ == "__main__": |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 4134 | unittest.main(testRunner=VppTestRunner) |