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