Renato Botelho do Couto | ead1e53 | 2019-10-31 13:31:07 -0500 | [diff] [blame] | 1 | #!/usr/bin/env python3 |
Steven | 9cd2d7a | 2017-12-20 12:43:01 -0800 | [diff] [blame] | 2 | |
Steven | 9cd2d7a | 2017-12-20 12:43:01 -0800 | [diff] [blame] | 3 | import unittest |
| 4 | |
Steven | 9cd2d7a | 2017-12-20 12:43:01 -0800 | [diff] [blame] | 5 | from scapy.packet import Raw |
| 6 | from scapy.layers.l2 import Ether |
| 7 | from scapy.layers.inet import IP, UDP |
Steven Luong | dc2abbe | 2020-07-28 12:28:03 -0700 | [diff] [blame] | 8 | |
Dave Wallace | 8800f73 | 2023-08-31 00:47:44 -0400 | [diff] [blame] | 9 | from framework import VppTestCase |
| 10 | from asfframework import VppTestRunner |
Steven | 9cd2d7a | 2017-12-20 12:43:01 -0800 | [diff] [blame] | 11 | from vpp_bond_interface import VppBondInterface |
Steven Luong | dc2abbe | 2020-07-28 12:28:03 -0700 | [diff] [blame] | 12 | from vpp_papi import MACAddress, VppEnum |
Dmitry Valter | 34fa0ce | 2024-03-11 10:38:46 +0000 | [diff] [blame] | 13 | from config import config |
Steven | 9cd2d7a | 2017-12-20 12:43:01 -0800 | [diff] [blame] | 14 | |
| 15 | |
| 16 | class TestBondInterface(VppTestCase): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 17 | """Bond Test Case""" |
Steven | 9cd2d7a | 2017-12-20 12:43:01 -0800 | [diff] [blame] | 18 | |
| 19 | @classmethod |
| 20 | def setUpClass(cls): |
| 21 | super(TestBondInterface, cls).setUpClass() |
| 22 | # Test variables |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 23 | cls.pkts_per_burst = 257 # Number of packets per burst |
Steven | 9cd2d7a | 2017-12-20 12:43:01 -0800 | [diff] [blame] | 24 | # create 3 pg interfaces |
| 25 | cls.create_pg_interfaces(range(4)) |
| 26 | |
| 27 | # packet sizes |
| 28 | cls.pg_if_packet_sizes = [64, 512, 1518] # , 9018] |
| 29 | |
| 30 | # setup all interfaces |
| 31 | for i in cls.pg_interfaces: |
| 32 | i.admin_up() |
| 33 | |
Paul Vinciguerra | 7f9b7f9 | 2019-03-12 19:23:27 -0700 | [diff] [blame] | 34 | @classmethod |
| 35 | def tearDownClass(cls): |
| 36 | super(TestBondInterface, cls).tearDownClass() |
| 37 | |
Steven | 9cd2d7a | 2017-12-20 12:43:01 -0800 | [diff] [blame] | 38 | def setUp(self): |
| 39 | super(TestBondInterface, self).setUp() |
| 40 | |
| 41 | def tearDown(self): |
| 42 | super(TestBondInterface, self).tearDown() |
Paul Vinciguerra | 90cf21b | 2019-03-13 09:23:05 -0700 | [diff] [blame] | 43 | |
| 44 | def show_commands_at_teardown(self): |
| 45 | self.logger.info(self.vapi.ppcli("show interface")) |
Steven | 9cd2d7a | 2017-12-20 12:43:01 -0800 | [diff] [blame] | 46 | |
| 47 | def test_bond_traffic(self): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 48 | """Bond traffic test""" |
Steven | 9cd2d7a | 2017-12-20 12:43:01 -0800 | [diff] [blame] | 49 | |
| 50 | # topology |
| 51 | # |
| 52 | # RX-> TX-> |
| 53 | # |
Steven Luong | 4c4223e | 2020-07-15 08:44:54 -0700 | [diff] [blame] | 54 | # pg2 ------+ +------pg0 (member) |
Steven | 9cd2d7a | 2017-12-20 12:43:01 -0800 | [diff] [blame] | 55 | # | | |
| 56 | # BondEthernet0 (10.10.10.1) |
| 57 | # | | |
Steven Luong | 4c4223e | 2020-07-15 08:44:54 -0700 | [diff] [blame] | 58 | # pg3 ------+ +------pg1 (memberx) |
Steven | 9cd2d7a | 2017-12-20 12:43:01 -0800 | [diff] [blame] | 59 | # |
| 60 | |
| 61 | # create interface (BondEthernet0) |
| 62 | # self.logger.info("create bond") |
| 63 | bond0_mac = "02:fe:38:30:59:3c" |
Ole Troan | 8006c6a | 2018-12-17 12:02:26 +0100 | [diff] [blame] | 64 | mac = MACAddress(bond0_mac).packed |
Steven Luong | ea71786 | 2020-07-30 07:31:40 -0700 | [diff] [blame] | 65 | bond0 = VppBondInterface( |
| 66 | self, |
| 67 | mode=VppEnum.vl_api_bond_mode_t.BOND_API_MODE_XOR, |
| 68 | lb=VppEnum.vl_api_bond_lb_algo_t.BOND_API_LB_ALGO_L34, |
| 69 | numa_only=0, |
| 70 | use_custom_mac=1, |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 71 | mac_address=mac, |
| 72 | ) |
Steven | 9cd2d7a | 2017-12-20 12:43:01 -0800 | [diff] [blame] | 73 | bond0.add_vpp_config() |
| 74 | bond0.admin_up() |
Jakub Grajciar | 053204a | 2019-03-18 13:17:53 +0100 | [diff] [blame] | 75 | self.vapi.sw_interface_add_del_address( |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 76 | sw_if_index=bond0.sw_if_index, prefix="10.10.10.1/24" |
| 77 | ) |
Steven | 9cd2d7a | 2017-12-20 12:43:01 -0800 | [diff] [blame] | 78 | |
| 79 | self.pg2.config_ip4() |
| 80 | self.pg2.resolve_arp() |
| 81 | self.pg3.config_ip4() |
| 82 | self.pg3.resolve_arp() |
| 83 | |
| 84 | self.logger.info(self.vapi.cli("show interface")) |
| 85 | self.logger.info(self.vapi.cli("show interface address")) |
Neale Ranns | cbe25aa | 2019-09-30 10:53:31 +0000 | [diff] [blame] | 86 | self.logger.info(self.vapi.cli("show ip neighbors")) |
Steven | 9cd2d7a | 2017-12-20 12:43:01 -0800 | [diff] [blame] | 87 | |
Steven Luong | 4c4223e | 2020-07-15 08:44:54 -0700 | [diff] [blame] | 88 | # add member pg0 and pg1 to BondEthernet0 |
| 89 | self.logger.info("bond add member interface pg0 to BondEthernet0") |
| 90 | bond0.add_member_vpp_bond_interface(sw_if_index=self.pg0.sw_if_index) |
| 91 | self.logger.info("bond add_member interface pg1 to BondEthernet0") |
| 92 | bond0.add_member_vpp_bond_interface(sw_if_index=self.pg1.sw_if_index) |
Steven | 9cd2d7a | 2017-12-20 12:43:01 -0800 | [diff] [blame] | 93 | |
Steven Luong | 4c4223e | 2020-07-15 08:44:54 -0700 | [diff] [blame] | 94 | # verify both members in BondEthernet0 |
| 95 | if_dump = self.vapi.sw_member_interface_dump(bond0.sw_if_index) |
Steven | 9cd2d7a | 2017-12-20 12:43:01 -0800 | [diff] [blame] | 96 | self.assertTrue(self.pg0.is_interface_config_in_dump(if_dump)) |
| 97 | self.assertTrue(self.pg1.is_interface_config_in_dump(if_dump)) |
| 98 | |
| 99 | # generate a packet from pg2 -> BondEthernet0 -> pg1 |
| 100 | # BondEthernet0 TX hashes this packet to pg1 |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 101 | p2 = ( |
| 102 | Ether(src=bond0_mac, dst=self.pg2.local_mac) |
| 103 | / IP(src=self.pg2.local_ip4, dst="10.10.10.12") |
| 104 | / UDP(sport=1235, dport=1235) |
| 105 | / Raw(b"\xa5" * 100) |
| 106 | ) |
Steven | 9cd2d7a | 2017-12-20 12:43:01 -0800 | [diff] [blame] | 107 | self.pg2.add_stream(p2) |
| 108 | |
| 109 | # generate a packet from pg3 -> BondEthernet0 -> pg0 |
| 110 | # BondEthernet0 TX hashes this packet to pg0 |
| 111 | # notice the ip address and ports are different than p2 packet |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 112 | p3 = ( |
| 113 | Ether(src=bond0_mac, dst=self.pg3.local_mac) |
| 114 | / IP(src=self.pg3.local_ip4, dst="10.10.10.11") |
| 115 | / UDP(sport=1234, dport=1234) |
| 116 | / Raw(b"\xa5" * 100) |
| 117 | ) |
Steven | 9cd2d7a | 2017-12-20 12:43:01 -0800 | [diff] [blame] | 118 | self.pg3.add_stream(p3) |
| 119 | |
| 120 | self.pg_enable_capture(self.pg_interfaces) |
| 121 | |
| 122 | # set up the static arp entries pointing to the BondEthernet0 interface |
| 123 | # so that it does not try to resolve the ip address |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 124 | self.logger.info( |
| 125 | self.vapi.cli( |
| 126 | "set ip neighbor static BondEthernet0 10.10.10.12 abcd.abcd.0002" |
| 127 | ) |
| 128 | ) |
| 129 | self.logger.info( |
| 130 | self.vapi.cli( |
| 131 | "set ip neighbor static BondEthernet0 10.10.10.11 abcd.abcd.0004" |
| 132 | ) |
| 133 | ) |
Steven | 9cd2d7a | 2017-12-20 12:43:01 -0800 | [diff] [blame] | 134 | |
| 135 | # clear the interface counters |
| 136 | self.logger.info(self.vapi.cli("clear interfaces")) |
| 137 | |
| 138 | self.pg_start() |
| 139 | |
| 140 | self.logger.info("check the interface counters") |
| 141 | |
| 142 | # verify counters |
| 143 | |
| 144 | # BondEthernet0 tx bytes = 284 |
| 145 | intfs = self.vapi.cli("show interface BondEthernet0").split("\n") |
| 146 | found = 0 |
| 147 | for intf in intfs: |
| 148 | if "tx bytes" in intf and "284" in intf: |
| 149 | found = 1 |
| 150 | self.assertEqual(found, 1) |
| 151 | |
Steven | 0d88301 | 2018-05-11 11:06:23 -0700 | [diff] [blame] | 152 | # BondEthernet0 tx bytes = 284 |
| 153 | intfs = self.vapi.cli("show interface BondEthernet0").split("\n") |
Steven | 9cd2d7a | 2017-12-20 12:43:01 -0800 | [diff] [blame] | 154 | found = 0 |
| 155 | for intf in intfs: |
Steven | 0d88301 | 2018-05-11 11:06:23 -0700 | [diff] [blame] | 156 | if "tx bytes" in intf and "284" in intf: |
Steven | 9cd2d7a | 2017-12-20 12:43:01 -0800 | [diff] [blame] | 157 | found = 1 |
| 158 | self.assertEqual(found, 1) |
| 159 | |
| 160 | # pg2 rx bytes = 142 |
| 161 | intfs = self.vapi.cli("show interface pg2").split("\n") |
| 162 | found = 0 |
| 163 | for intf in intfs: |
| 164 | if "rx bytes" in intf and "142" in intf: |
| 165 | found = 1 |
| 166 | self.assertEqual(found, 1) |
| 167 | |
| 168 | # pg3 rx bytes = 142 |
| 169 | intfs = self.vapi.cli("show interface pg3").split("\n") |
| 170 | found = 0 |
| 171 | for intf in intfs: |
| 172 | if "rx bytes" in intf and "142" in intf: |
| 173 | found = 1 |
| 174 | self.assertEqual(found, 1) |
| 175 | |
| 176 | bond0.remove_vpp_config() |
| 177 | |
Dmitry Valter | 34fa0ce | 2024-03-11 10:38:46 +0000 | [diff] [blame] | 178 | @unittest.skipIf( |
| 179 | "lacp" in config.excluded_plugins, "Exclude tests requiring LACP plugin" |
| 180 | ) |
Steven Luong | 4c4223e | 2020-07-15 08:44:54 -0700 | [diff] [blame] | 181 | def test_bond_add_member(self): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 182 | """Bond add_member/detach member test""" |
Steven | 9cd2d7a | 2017-12-20 12:43:01 -0800 | [diff] [blame] | 183 | |
Vladimir Isaev | 72e31bc | 2020-02-04 11:54:27 +0300 | [diff] [blame] | 184 | # create interface (BondEthernet0) and set bond mode to LACP |
Steven | 9cd2d7a | 2017-12-20 12:43:01 -0800 | [diff] [blame] | 185 | self.logger.info("create bond") |
Steven Luong | ea71786 | 2020-07-30 07:31:40 -0700 | [diff] [blame] | 186 | bond0 = VppBondInterface( |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 187 | self, mode=VppEnum.vl_api_bond_mode_t.BOND_API_MODE_LACP, enable_gso=0 |
| 188 | ) |
Steven | 9cd2d7a | 2017-12-20 12:43:01 -0800 | [diff] [blame] | 189 | bond0.add_vpp_config() |
| 190 | bond0.admin_up() |
| 191 | |
Steven Luong | 4c4223e | 2020-07-15 08:44:54 -0700 | [diff] [blame] | 192 | # verify that interfaces can be added as_member and detached two times |
Vladimir Isaev | 72e31bc | 2020-02-04 11:54:27 +0300 | [diff] [blame] | 193 | for i in range(2): |
| 194 | # verify pg0 and pg1 not in BondEthernet0 |
Steven Luong | 4c4223e | 2020-07-15 08:44:54 -0700 | [diff] [blame] | 195 | if_dump = self.vapi.sw_member_interface_dump(bond0.sw_if_index) |
Vladimir Isaev | 72e31bc | 2020-02-04 11:54:27 +0300 | [diff] [blame] | 196 | self.assertFalse(self.pg0.is_interface_config_in_dump(if_dump)) |
| 197 | self.assertFalse(self.pg1.is_interface_config_in_dump(if_dump)) |
Steven | 9cd2d7a | 2017-12-20 12:43:01 -0800 | [diff] [blame] | 198 | |
Steven Luong | 4c4223e | 2020-07-15 08:44:54 -0700 | [diff] [blame] | 199 | # add_member pg0 and pg1 to BondEthernet0 |
| 200 | self.logger.info("bond add_member interface pg0 to BondEthernet0") |
| 201 | bond0.add_member_vpp_bond_interface( |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 202 | sw_if_index=self.pg0.sw_if_index, is_passive=0, is_long_timeout=0 |
| 203 | ) |
Steven | 9cd2d7a | 2017-12-20 12:43:01 -0800 | [diff] [blame] | 204 | |
Steven Luong | 4c4223e | 2020-07-15 08:44:54 -0700 | [diff] [blame] | 205 | self.logger.info("bond add_member interface pg1 to BondEthernet0") |
| 206 | bond0.add_member_vpp_bond_interface( |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 207 | sw_if_index=self.pg1.sw_if_index, is_passive=0, is_long_timeout=0 |
| 208 | ) |
Steven Luong | 4c4223e | 2020-07-15 08:44:54 -0700 | [diff] [blame] | 209 | # verify both members in BondEthernet0 |
| 210 | if_dump = self.vapi.sw_member_interface_dump(bond0.sw_if_index) |
Vladimir Isaev | 72e31bc | 2020-02-04 11:54:27 +0300 | [diff] [blame] | 211 | self.assertTrue(self.pg0.is_interface_config_in_dump(if_dump)) |
| 212 | self.assertTrue(self.pg1.is_interface_config_in_dump(if_dump)) |
Steven | 9cd2d7a | 2017-12-20 12:43:01 -0800 | [diff] [blame] | 213 | |
Vladimir Isaev | 72e31bc | 2020-02-04 11:54:27 +0300 | [diff] [blame] | 214 | # detach interface pg0 |
| 215 | self.logger.info("detach interface pg0") |
| 216 | bond0.detach_vpp_bond_interface(sw_if_index=self.pg0.sw_if_index) |
Steven | 9cd2d7a | 2017-12-20 12:43:01 -0800 | [diff] [blame] | 217 | |
Vladimir Isaev | 72e31bc | 2020-02-04 11:54:27 +0300 | [diff] [blame] | 218 | # verify pg0 is not in BondEthernet0, but pg1 is |
Steven Luong | 4c4223e | 2020-07-15 08:44:54 -0700 | [diff] [blame] | 219 | if_dump = self.vapi.sw_member_interface_dump(bond0.sw_if_index) |
Vladimir Isaev | 72e31bc | 2020-02-04 11:54:27 +0300 | [diff] [blame] | 220 | self.assertFalse(self.pg0.is_interface_config_in_dump(if_dump)) |
| 221 | self.assertTrue(self.pg1.is_interface_config_in_dump(if_dump)) |
Steven | 9cd2d7a | 2017-12-20 12:43:01 -0800 | [diff] [blame] | 222 | |
Vladimir Isaev | 72e31bc | 2020-02-04 11:54:27 +0300 | [diff] [blame] | 223 | # detach interface pg1 |
| 224 | self.logger.info("detach interface pg1") |
| 225 | bond0.detach_vpp_bond_interface(sw_if_index=self.pg1.sw_if_index) |
Steven | 9cd2d7a | 2017-12-20 12:43:01 -0800 | [diff] [blame] | 226 | |
Vladimir Isaev | 72e31bc | 2020-02-04 11:54:27 +0300 | [diff] [blame] | 227 | # verify pg0 and pg1 not in BondEthernet0 |
Steven Luong | 4c4223e | 2020-07-15 08:44:54 -0700 | [diff] [blame] | 228 | if_dump = self.vapi.sw_member_interface_dump(bond0.sw_if_index) |
Vladimir Isaev | 72e31bc | 2020-02-04 11:54:27 +0300 | [diff] [blame] | 229 | self.assertFalse(self.pg0.is_interface_config_in_dump(if_dump)) |
| 230 | self.assertFalse(self.pg1.is_interface_config_in_dump(if_dump)) |
Steven | 9cd2d7a | 2017-12-20 12:43:01 -0800 | [diff] [blame] | 231 | |
| 232 | bond0.remove_vpp_config() |
| 233 | |
Dmitry Valter | 34fa0ce | 2024-03-11 10:38:46 +0000 | [diff] [blame] | 234 | @unittest.skipIf( |
| 235 | "lacp" in config.excluded_plugins, "Exclude tests requiring LACP plugin" |
| 236 | ) |
Steven | 9cd2d7a | 2017-12-20 12:43:01 -0800 | [diff] [blame] | 237 | def test_bond(self): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 238 | """Bond add/delete interface test""" |
Steven | 9cd2d7a | 2017-12-20 12:43:01 -0800 | [diff] [blame] | 239 | self.logger.info("Bond add interfaces") |
| 240 | |
| 241 | # create interface 1 (BondEthernet0) |
Steven Luong | ea71786 | 2020-07-30 07:31:40 -0700 | [diff] [blame] | 242 | bond0 = VppBondInterface( |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 243 | self, mode=VppEnum.vl_api_bond_mode_t.BOND_API_MODE_LACP |
| 244 | ) |
Steven | 9cd2d7a | 2017-12-20 12:43:01 -0800 | [diff] [blame] | 245 | bond0.add_vpp_config() |
| 246 | bond0.admin_up() |
| 247 | |
| 248 | # create interface 2 (BondEthernet1) |
Steven Luong | ea71786 | 2020-07-30 07:31:40 -0700 | [diff] [blame] | 249 | bond1 = VppBondInterface( |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 250 | self, mode=VppEnum.vl_api_bond_mode_t.BOND_API_MODE_XOR |
| 251 | ) |
Steven | 9cd2d7a | 2017-12-20 12:43:01 -0800 | [diff] [blame] | 252 | bond1.add_vpp_config() |
| 253 | bond1.admin_up() |
| 254 | |
| 255 | # verify both interfaces in the show |
| 256 | ifs = self.vapi.cli("show interface") |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 257 | self.assertIn("BondEthernet0", ifs) |
| 258 | self.assertIn("BondEthernet1", ifs) |
Steven | 9cd2d7a | 2017-12-20 12:43:01 -0800 | [diff] [blame] | 259 | |
| 260 | # verify they are in the dump also |
Steven Luong | 4c4223e | 2020-07-15 08:44:54 -0700 | [diff] [blame] | 261 | if_dump = self.vapi.sw_bond_interface_dump(sw_if_index=0xFFFFFFFF) |
Steven | 9cd2d7a | 2017-12-20 12:43:01 -0800 | [diff] [blame] | 262 | self.assertTrue(bond0.is_interface_config_in_dump(if_dump)) |
| 263 | self.assertTrue(bond1.is_interface_config_in_dump(if_dump)) |
| 264 | |
| 265 | # delete BondEthernet1 |
| 266 | self.logger.info("Deleting BondEthernet1") |
| 267 | bond1.remove_vpp_config() |
| 268 | |
| 269 | self.logger.info("Verifying BondEthernet1 is deleted") |
| 270 | |
| 271 | ifs = self.vapi.cli("show interface") |
| 272 | # verify BondEthernet0 still in the show |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 273 | self.assertIn("BondEthernet0", ifs) |
Steven | 9cd2d7a | 2017-12-20 12:43:01 -0800 | [diff] [blame] | 274 | |
| 275 | # verify BondEthernet1 not in the show |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 276 | self.assertNotIn("BondEthernet1", ifs) |
Steven | 9cd2d7a | 2017-12-20 12:43:01 -0800 | [diff] [blame] | 277 | |
| 278 | # verify BondEthernet1 is not in the dump |
Steven Luong | 4c4223e | 2020-07-15 08:44:54 -0700 | [diff] [blame] | 279 | if_dump = self.vapi.sw_bond_interface_dump(sw_if_index=0xFFFFFFFF) |
Steven | 9cd2d7a | 2017-12-20 12:43:01 -0800 | [diff] [blame] | 280 | self.assertFalse(bond1.is_interface_config_in_dump(if_dump)) |
| 281 | |
| 282 | # verify BondEthernet0 is still in the dump |
| 283 | self.assertTrue(bond0.is_interface_config_in_dump(if_dump)) |
| 284 | |
| 285 | # delete BondEthernet0 |
| 286 | self.logger.info("Deleting BondEthernet0") |
| 287 | bond0.remove_vpp_config() |
| 288 | |
| 289 | self.logger.info("Verifying BondEthernet0 is deleted") |
| 290 | |
| 291 | # verify BondEthernet0 not in the show |
| 292 | ifs = self.vapi.cli("show interface") |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 293 | self.assertNotIn("BondEthernet0", ifs) |
Steven | 9cd2d7a | 2017-12-20 12:43:01 -0800 | [diff] [blame] | 294 | |
| 295 | # verify BondEthernet0 is not in the dump |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 296 | if_dump = self.vapi.sw_bond_interface_dump(sw_if_index=bond0.sw_if_index) |
Steven | 9cd2d7a | 2017-12-20 12:43:01 -0800 | [diff] [blame] | 297 | self.assertFalse(bond0.is_interface_config_in_dump(if_dump)) |
| 298 | |
Steven Luong | dc2abbe | 2020-07-28 12:28:03 -0700 | [diff] [blame] | 299 | def test_bond_link(self): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 300 | """Bond hw interface link state test""" |
Steven Luong | dc2abbe | 2020-07-28 12:28:03 -0700 | [diff] [blame] | 301 | |
| 302 | # for convenience |
| 303 | bond_modes = VppEnum.vl_api_bond_mode_t |
| 304 | intf_flags = VppEnum.vl_api_if_status_flags_t |
| 305 | |
| 306 | # create interface 1 (BondEthernet0) |
| 307 | self.logger.info("Create bond interface") |
| 308 | # use round-robin mode to avoid negotiation required by LACP |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 309 | bond0 = VppBondInterface(self, mode=bond_modes.BOND_API_MODE_ROUND_ROBIN) |
Steven Luong | dc2abbe | 2020-07-28 12:28:03 -0700 | [diff] [blame] | 310 | bond0.add_vpp_config() |
| 311 | |
| 312 | # set bond admin up. |
| 313 | self.logger.info("set interface BondEthernet0 admin up") |
| 314 | bond0.admin_up() |
| 315 | # confirm link up |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 316 | bond0.assert_interface_state( |
| 317 | intf_flags.IF_STATUS_API_FLAG_ADMIN_UP, |
| 318 | intf_flags.IF_STATUS_API_FLAG_LINK_UP, |
| 319 | ) |
Steven Luong | dc2abbe | 2020-07-28 12:28:03 -0700 | [diff] [blame] | 320 | |
| 321 | # toggle bond admin state |
| 322 | self.logger.info("toggle interface BondEthernet0") |
| 323 | bond0.admin_down() |
| 324 | bond0.admin_up() |
| 325 | |
| 326 | # confirm link is still up |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 327 | bond0.assert_interface_state( |
| 328 | intf_flags.IF_STATUS_API_FLAG_ADMIN_UP, |
| 329 | intf_flags.IF_STATUS_API_FLAG_LINK_UP, |
| 330 | ) |
Steven Luong | dc2abbe | 2020-07-28 12:28:03 -0700 | [diff] [blame] | 331 | |
| 332 | # delete BondEthernet0 |
| 333 | self.logger.info("Deleting BondEthernet0") |
| 334 | bond0.remove_vpp_config() |
| 335 | |
Steven Luong | a1876b8 | 2019-08-20 16:58:00 -0700 | [diff] [blame] | 336 | |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 337 | if __name__ == "__main__": |
Steven | 9cd2d7a | 2017-12-20 12:43:01 -0800 | [diff] [blame] | 338 | unittest.main(testRunner=VppTestRunner) |