Steven Luong | a77ae47 | 2021-02-14 11:37:02 -0800 | [diff] [blame] | 1 | from scapy.layers.l2 import ARP |
| 2 | from scapy.layers.inet6 import ICMPv6ND_NS, ICMPv6ND_NA, IPv6 |
| 3 | |
| 4 | from framework import VppTestCase |
Dmitry Valter | 34fa0ce | 2024-03-11 10:38:46 +0000 | [diff] [blame] | 5 | from config import config |
| 6 | |
| 7 | import unittest |
Steven Luong | a77ae47 | 2021-02-14 11:37:02 -0800 | [diff] [blame] | 8 | |
| 9 | """ TestArping is a subclass of VPPTestCase classes. |
| 10 | |
| 11 | Basic test for sanity check of arping. |
| 12 | |
| 13 | """ |
| 14 | |
| 15 | |
Dmitry Valter | 34fa0ce | 2024-03-11 10:38:46 +0000 | [diff] [blame] | 16 | @unittest.skipIf("arping" in config.excluded_plugins, "Exclude Arping plugin tests") |
Steven Luong | a77ae47 | 2021-02-14 11:37:02 -0800 | [diff] [blame] | 17 | class TestArping(VppTestCase): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 18 | """Arping Test Case""" |
Steven Luong | a77ae47 | 2021-02-14 11:37:02 -0800 | [diff] [blame] | 19 | |
| 20 | @classmethod |
| 21 | def setUpClass(cls): |
| 22 | super(TestArping, cls).setUpClass() |
| 23 | try: |
| 24 | cls.create_pg_interfaces(range(2)) |
| 25 | cls.interfaces = list(cls.pg_interfaces) |
| 26 | |
| 27 | for i in cls.interfaces: |
| 28 | i.admin_up() |
| 29 | i.config_ip4() |
| 30 | i.config_ip6() |
| 31 | i.disable_ipv6_ra() |
| 32 | i.resolve_arp() |
| 33 | i.resolve_ndp() |
| 34 | except Exception: |
| 35 | super(TestArping, cls).tearDownClass() |
| 36 | raise |
| 37 | |
| 38 | @classmethod |
| 39 | def tearDownClass(cls): |
| 40 | super(TestArping, cls).tearDownClass() |
| 41 | |
| 42 | def tearDown(self): |
| 43 | super(TestArping, self).tearDown() |
| 44 | |
| 45 | def show_commands_at_teardown(self): |
| 46 | self.logger.info(self.vapi.cli("show hardware")) |
| 47 | |
| 48 | def verify_arping_request(self, p, src, dst): |
| 49 | arp = p[ARP] |
| 50 | self.assertEqual(arp.hwtype, 0x0001) |
| 51 | self.assertEqual(arp.ptype, 0x0800) |
| 52 | self.assertEqual(arp.hwlen, 6) |
| 53 | self.assertEqual(arp.op, 1) |
| 54 | self.assertEqual(arp.psrc, src) |
| 55 | self.assertEqual(arp.pdst, dst) |
| 56 | |
| 57 | def verify_arping_ip6_ns(self, p, src, dst): |
| 58 | icmpv6 = p[ICMPv6ND_NS] |
| 59 | self.assertEqual(icmpv6.type, 135) |
| 60 | self.assertEqual(icmpv6.tgt, dst) |
| 61 | ipv6 = p[IPv6] |
| 62 | self.assertEqual(src, ipv6.src) |
| 63 | |
| 64 | def verify_arping_ip6_na(self, p, src, dst): |
| 65 | icmpv6 = p[ICMPv6ND_NA] |
| 66 | self.assertEqual(icmpv6.type, 136) |
| 67 | self.assertEqual(icmpv6.tgt, dst) |
| 68 | ipv6 = p[IPv6] |
| 69 | self.assertEqual(src, ipv6.src) |
| 70 | |
| 71 | def test_arping_ip4_arp_request_cli(self): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 72 | """arping IP4 arp request CLI test""" |
Steven Luong | a77ae47 | 2021-02-14 11:37:02 -0800 | [diff] [blame] | 73 | try: |
| 74 | self.pg_enable_capture(self.pg_interfaces) |
| 75 | self.pg_start() |
| 76 | remote_ip4 = self.pg1.remote_ip4 |
| 77 | |
| 78 | ping_cmd = "arping " + remote_ip4 + "pg1 repeat 5 interval 0.1" |
| 79 | ret = self.vapi.cli(ping_cmd) |
| 80 | self.logger.info(ret) |
| 81 | |
| 82 | ping_cmd = "arping " + remote_ip4 + "pg1" |
| 83 | ret = self.vapi.cli(ping_cmd) |
| 84 | self.logger.info(ret) |
| 85 | |
| 86 | out = self.pg1.get_capture(6) |
| 87 | for p in out: |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 88 | self.verify_arping_request(p, self.pg1.local_ip4, self.pg1.remote_ip4) |
Steven Luong | a77ae47 | 2021-02-14 11:37:02 -0800 | [diff] [blame] | 89 | finally: |
| 90 | self.vapi.cli("show error") |
| 91 | |
| 92 | def test_arping_ip4_garp_cli(self): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 93 | """arping ip4 gratuitous arp CLI test""" |
Steven Luong | a77ae47 | 2021-02-14 11:37:02 -0800 | [diff] [blame] | 94 | try: |
| 95 | self.pg_enable_capture(self.pg_interfaces) |
| 96 | self.pg_start() |
| 97 | |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 98 | ping_cmd = ( |
| 99 | "arping gratuitous" + self.pg1.local_ip4 + "pg1 repeat 5 interval 0.1" |
| 100 | ) |
Steven Luong | a77ae47 | 2021-02-14 11:37:02 -0800 | [diff] [blame] | 101 | ret = self.vapi.cli(ping_cmd) |
| 102 | self.logger.info(ret) |
| 103 | |
| 104 | ping_cmd = "arping gratuitous" + self.pg1.local_ip4 + "pg1" |
| 105 | ret = self.vapi.cli(ping_cmd) |
| 106 | self.logger.info(ret) |
| 107 | |
| 108 | out = self.pg1.get_capture(6) |
| 109 | for p in out: |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 110 | self.verify_arping_request(p, self.pg1.local_ip4, self.pg1.local_ip4) |
Steven Luong | a77ae47 | 2021-02-14 11:37:02 -0800 | [diff] [blame] | 111 | finally: |
| 112 | self.vapi.cli("show error") |
| 113 | |
| 114 | def test_arping_ip4_arp_request_api(self): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 115 | """arping ip4 arp request API test""" |
Steven Luong | a77ae47 | 2021-02-14 11:37:02 -0800 | [diff] [blame] | 116 | try: |
| 117 | self.pg_enable_capture(self.pg_interfaces) |
| 118 | self.pg_start() |
| 119 | remote_ip4 = self.pg1.remote_ip4 |
| 120 | |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 121 | ret = self.vapi.arping( |
| 122 | address=remote_ip4, |
| 123 | sw_if_index=self.pg1.sw_if_index, |
| 124 | is_garp=0, |
| 125 | repeat=5, |
| 126 | interval=0.1, |
| 127 | ) |
Steven Luong | a77ae47 | 2021-02-14 11:37:02 -0800 | [diff] [blame] | 128 | self.logger.info(ret) |
| 129 | |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 130 | ret = self.vapi.arping( |
| 131 | address=remote_ip4, sw_if_index=self.pg1.sw_if_index, is_garp=0 |
| 132 | ) |
Steven Luong | a77ae47 | 2021-02-14 11:37:02 -0800 | [diff] [blame] | 133 | self.logger.info(ret) |
| 134 | |
| 135 | out = self.pg1.get_capture(6) |
| 136 | for p in out: |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 137 | self.verify_arping_request(p, self.pg1.local_ip4, self.pg1.remote_ip4) |
Steven Luong | a77ae47 | 2021-02-14 11:37:02 -0800 | [diff] [blame] | 138 | finally: |
| 139 | self.vapi.cli("show error") |
| 140 | |
| 141 | def test_arping_ip4_garp_api(self): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 142 | """arping ip4 gratuitous arp API test""" |
Steven Luong | a77ae47 | 2021-02-14 11:37:02 -0800 | [diff] [blame] | 143 | try: |
| 144 | self.pg_enable_capture(self.pg_interfaces) |
| 145 | self.pg_start() |
| 146 | |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 147 | ret = self.vapi.arping( |
| 148 | address=self.pg1.local_ip4, |
| 149 | sw_if_index=self.pg1.sw_if_index, |
| 150 | is_garp=1, |
| 151 | repeat=5, |
| 152 | interval=0.1, |
| 153 | ) |
Steven Luong | a77ae47 | 2021-02-14 11:37:02 -0800 | [diff] [blame] | 154 | self.logger.info(ret) |
| 155 | |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 156 | ret = self.vapi.arping( |
| 157 | address=self.pg1.local_ip4, sw_if_index=self.pg1.sw_if_index, is_garp=1 |
| 158 | ) |
Steven Luong | a77ae47 | 2021-02-14 11:37:02 -0800 | [diff] [blame] | 159 | self.logger.info(ret) |
| 160 | |
| 161 | out = self.pg1.get_capture(6) |
| 162 | for p in out: |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 163 | self.verify_arping_request(p, self.pg1.local_ip4, self.pg1.local_ip4) |
Steven Luong | a77ae47 | 2021-02-14 11:37:02 -0800 | [diff] [blame] | 164 | finally: |
| 165 | self.vapi.cli("show error") |
| 166 | |
| 167 | def test_arping_ip6_ns_cli(self): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 168 | """arping IP6 neighbor solicitation CLI test""" |
Steven Luong | a77ae47 | 2021-02-14 11:37:02 -0800 | [diff] [blame] | 169 | try: |
| 170 | self.pg_enable_capture(self.pg_interfaces) |
| 171 | self.pg_start() |
| 172 | remote_ip6 = self.pg1.remote_ip6 |
| 173 | |
| 174 | ping_cmd = "arping " + remote_ip6 + "pg1 repeat 5 interval 0.1" |
| 175 | ret = self.vapi.cli(ping_cmd) |
| 176 | self.logger.info(ret) |
| 177 | |
| 178 | ping_cmd = "arping " + remote_ip6 + "pg1" |
| 179 | ret = self.vapi.cli(ping_cmd) |
| 180 | self.logger.info(ret) |
| 181 | |
| 182 | out = self.pg1.get_capture(6) |
| 183 | for p in out: |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 184 | self.verify_arping_ip6_ns(p, self.pg1.local_ip6, self.pg1.remote_ip6) |
Steven Luong | a77ae47 | 2021-02-14 11:37:02 -0800 | [diff] [blame] | 185 | finally: |
| 186 | self.vapi.cli("show error") |
| 187 | |
| 188 | def test_arping_ip6_ns_api(self): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 189 | """arping ip6 neighbor solicitation API test""" |
Steven Luong | a77ae47 | 2021-02-14 11:37:02 -0800 | [diff] [blame] | 190 | try: |
| 191 | self.pg_enable_capture(self.pg_interfaces) |
| 192 | self.pg_start() |
| 193 | remote_ip6 = self.pg1.remote_ip6 |
| 194 | |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 195 | ret = self.vapi.arping( |
| 196 | address=remote_ip6, |
| 197 | sw_if_index=self.pg1.sw_if_index, |
| 198 | is_garp=0, |
| 199 | repeat=5, |
| 200 | interval=0.1, |
| 201 | ) |
Steven Luong | a77ae47 | 2021-02-14 11:37:02 -0800 | [diff] [blame] | 202 | self.logger.info(ret) |
| 203 | |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 204 | ret = self.vapi.arping( |
| 205 | address=remote_ip6, sw_if_index=self.pg1.sw_if_index, is_garp=0 |
| 206 | ) |
Steven Luong | a77ae47 | 2021-02-14 11:37:02 -0800 | [diff] [blame] | 207 | self.logger.info(ret) |
| 208 | |
| 209 | out = self.pg1.get_capture(6) |
| 210 | for p in out: |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 211 | self.verify_arping_ip6_ns(p, self.pg1.local_ip6, self.pg1.remote_ip6) |
Steven Luong | a77ae47 | 2021-02-14 11:37:02 -0800 | [diff] [blame] | 212 | finally: |
| 213 | self.vapi.cli("show error") |
| 214 | |
| 215 | def test_arping_ip6_na_cli(self): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 216 | """arping ip6 neighbor advertisement CLI test""" |
Steven Luong | a77ae47 | 2021-02-14 11:37:02 -0800 | [diff] [blame] | 217 | try: |
| 218 | self.pg_enable_capture(self.pg_interfaces) |
| 219 | self.pg_start() |
| 220 | |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 221 | ping_cmd = ( |
| 222 | "arping gratuitous" + self.pg1.local_ip6 + "pg1 repeat 5 interval 0.1" |
| 223 | ) |
Steven Luong | a77ae47 | 2021-02-14 11:37:02 -0800 | [diff] [blame] | 224 | ret = self.vapi.cli(ping_cmd) |
| 225 | self.logger.info(ret) |
| 226 | |
| 227 | ping_cmd = "arping gratuitous" + self.pg1.local_ip6 + "pg1" |
| 228 | ret = self.vapi.cli(ping_cmd) |
| 229 | self.logger.info(ret) |
| 230 | |
| 231 | out = self.pg1.get_capture(6) |
| 232 | for p in out: |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 233 | self.verify_arping_ip6_na(p, self.pg1.local_ip6, self.pg1.local_ip6) |
Steven Luong | a77ae47 | 2021-02-14 11:37:02 -0800 | [diff] [blame] | 234 | finally: |
| 235 | self.vapi.cli("show error") |
| 236 | |
| 237 | def test_arping_ip6_na_api(self): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 238 | """arping ip6 neighbor advertisement API test""" |
Steven Luong | a77ae47 | 2021-02-14 11:37:02 -0800 | [diff] [blame] | 239 | try: |
| 240 | self.pg_enable_capture(self.pg_interfaces) |
| 241 | self.pg_start() |
| 242 | |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 243 | ret = self.vapi.arping( |
| 244 | address=self.pg1.local_ip6, |
| 245 | sw_if_index=self.pg1.sw_if_index, |
| 246 | is_garp=1, |
| 247 | repeat=5, |
| 248 | interval=0.1, |
| 249 | ) |
Steven Luong | a77ae47 | 2021-02-14 11:37:02 -0800 | [diff] [blame] | 250 | self.logger.info(ret) |
| 251 | |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 252 | ret = self.vapi.arping( |
| 253 | address=self.pg1.local_ip6, sw_if_index=self.pg1.sw_if_index, is_garp=1 |
| 254 | ) |
Steven Luong | a77ae47 | 2021-02-14 11:37:02 -0800 | [diff] [blame] | 255 | self.logger.info(ret) |
| 256 | |
| 257 | out = self.pg1.get_capture(6) |
| 258 | for p in out: |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 259 | self.verify_arping_ip6_na(p, self.pg1.local_ip6, self.pg1.local_ip6) |
Steven Luong | a77ae47 | 2021-02-14 11:37:02 -0800 | [diff] [blame] | 260 | finally: |
| 261 | self.vapi.cli("show error") |
| 262 | |
| 263 | |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 264 | if __name__ == "__main__": |
Steven Luong | a77ae47 | 2021-02-14 11:37:02 -0800 | [diff] [blame] | 265 | unittest.main(testRunner=VppTestRunner) |