blob: ec0165a03383da79dfd7fb54af052ab5442caf06 [file] [log] [blame]
Renato Botelho do Coutoead1e532019-10-31 13:31:07 -05001#!/usr/bin/env python3
Eyal Baric86e5922017-07-02 18:33:16 +03002""" L2BD ARP term Test """
3
4import unittest
5import random
6import copy
7
snaramre5d4b8912019-12-13 23:39:35 +00008from socket import AF_INET, AF_INET6, inet_pton, inet_ntop
Eyal Bari758137a2017-07-05 14:31:30 +03009
Eyal Baric86e5922017-07-02 18:33:16 +030010from scapy.packet import Raw
11from scapy.layers.l2 import Ether, ARP
12from scapy.layers.inet import IP
Klement Sekerad9b0c6f2022-04-26 19:02:15 +020013from scapy.utils6 import (
14 in6_getnsma,
15 in6_getnsmac,
16 in6_ptop,
17 in6_islladdr,
18 in6_mactoifaceid,
19 in6_ismaddr,
20)
21from scapy.layers.inet6 import (
22 IPv6,
23 UDP,
24 ICMPv6ND_NS,
25 ICMPv6ND_RS,
26 ICMPv6ND_RA,
27 ICMPv6NDOptSrcLLAddr,
28 getmacbyip6,
29 ICMPv6MRD_Solicitation,
30 ICMPv6NDOptMTU,
31 ICMPv6NDOptSrcLLAddr,
32 ICMPv6NDOptPrefixInfo,
33 ICMPv6ND_NA,
34 ICMPv6NDOptDstLLAddr,
35 ICMPv6DestUnreach,
36 icmp6types,
37)
Eyal Baric86e5922017-07-02 18:33:16 +030038
39from framework import VppTestCase, VppTestRunner
Ole Troan7f991832018-12-06 17:35:12 +010040from util import Host, ppp
Eyal Baric86e5922017-07-02 18:33:16 +030041
42
43class TestL2bdArpTerm(VppTestCase):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +020044 """L2BD arp termination Test Case"""
Eyal Baric86e5922017-07-02 18:33:16 +030045
46 @classmethod
47 def setUpClass(cls):
48 """
49 Perform standard class setup (defined by class method setUpClass in
50 class VppTestCase) before running the test case, set test case related
51 variables and configure VPP.
52 """
53 super(TestL2bdArpTerm, cls).setUpClass()
54
55 try:
56 # Create pg interfaces
57 n_bd = 1
58 cls.ifs_per_bd = ifs_per_bd = 3
59 n_ifs = n_bd * ifs_per_bd
60 cls.create_pg_interfaces(range(n_ifs))
61
62 # Set up all interfaces
63 for i in cls.pg_interfaces:
64 i.admin_up()
65
66 cls.hosts = set()
67
68 except Exception:
69 super(TestL2bdArpTerm, cls).tearDownClass()
70 raise
71
Paul Vinciguerra7f9b7f92019-03-12 19:23:27 -070072 @classmethod
73 def tearDownClass(cls):
74 super(TestL2bdArpTerm, cls).tearDownClass()
75
Eyal Baric86e5922017-07-02 18:33:16 +030076 def setUp(self):
77 """
78 Clear trace and packet infos before running each test.
79 """
80 self.reset_packet_infos()
81 super(TestL2bdArpTerm, self).setUp()
82
83 def tearDown(self):
84 """
85 Show various debug prints after each test.
86 """
87 super(TestL2bdArpTerm, self).tearDown()
Paul Vinciguerra90cf21b2019-03-13 09:23:05 -070088
89 def show_commands_at_teardown(self):
90 self.logger.info(self.vapi.ppcli("show l2fib verbose"))
Paul Vinciguerra9673e3e2019-05-10 20:41:08 -040091 # many tests delete bridge-domain 1 as the last task. don't output
92 # the details of a non-existent bridge-domain.
93 if self.vapi.l2_fib_table_dump(bd_id=1):
94 self.logger.info(self.vapi.ppcli("show bridge-domain 1 detail"))
Eyal Baric86e5922017-07-02 18:33:16 +030095
Eyal Bari758137a2017-07-05 14:31:30 +030096 def add_del_arp_term_hosts(self, entries, bd_id=1, is_add=1, is_ipv6=0):
Eyal Baric86e5922017-07-02 18:33:16 +030097 for e in entries:
Neale Ranns4d5b9172018-10-24 02:57:49 -070098 ip = e.ip4 if is_ipv6 == 0 else e.ip6
Klement Sekerad9b0c6f2022-04-26 19:02:15 +020099 self.vapi.bd_ip_mac_add_del(
100 is_add=is_add, entry={"bd_id": bd_id, "ip": ip, "mac": e.mac}
101 )
Eyal Baric86e5922017-07-02 18:33:16 +0300102
103 @classmethod
104 def mac_list(cls, b6_range):
105 return ["00:00:ca:fe:00:%02x" % b6 for b6 in b6_range]
106
107 @classmethod
108 def ip4_host(cls, subnet, host, mac):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200109 return Host(mac=mac, ip4="172.17.1%02u.%u" % (subnet, host))
Eyal Baric86e5922017-07-02 18:33:16 +0300110
111 @classmethod
112 def ip4_hosts(cls, subnet, start, mac_list):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200113 return {
114 cls.ip4_host(subnet, start + j, mac_list[j]) for j in range(len(mac_list))
115 }
Eyal Baric86e5922017-07-02 18:33:16 +0300116
117 @classmethod
Eyal Bari758137a2017-07-05 14:31:30 +0300118 def ip6_host(cls, subnet, host, mac):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200119 return Host(mac=mac, ip6="fd01:%x::%x" % (subnet, host))
Eyal Bari758137a2017-07-05 14:31:30 +0300120
121 @classmethod
122 def ip6_hosts(cls, subnet, start, mac_list):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200123 return {
124 cls.ip6_host(subnet, start + j, mac_list[j]) for j in range(len(mac_list))
125 }
Eyal Bari758137a2017-07-05 14:31:30 +0300126
127 @classmethod
Eyal Baric86e5922017-07-02 18:33:16 +0300128 def bd_swifs(cls, b):
129 n = cls.ifs_per_bd
130 start = (b - 1) * n
131 return [cls.pg_interfaces[j] for j in range(start, start + n)]
132
133 def bd_add_del(self, bd_id=1, is_add=1):
134 if is_add:
Laszlo Kiraly0f8f4352022-09-16 13:20:07 +0200135 self.vapi.bridge_domain_add_del_v2(
136 bd_id=bd_id, is_add=is_add, flood=1, uu_flood=1, forward=1, learn=1
137 )
Eyal Baric86e5922017-07-02 18:33:16 +0300138 for swif in self.bd_swifs(bd_id):
139 swif_idx = swif.sw_if_index
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200140 self.vapi.sw_interface_set_l2_bridge(
141 rx_sw_if_index=swif_idx, bd_id=bd_id, enable=is_add
142 )
Eyal Baric86e5922017-07-02 18:33:16 +0300143 if not is_add:
Laszlo Kiraly0f8f4352022-09-16 13:20:07 +0200144 self.vapi.bridge_domain_add_del_v2(bd_id=bd_id, is_add=is_add)
Eyal Baric86e5922017-07-02 18:33:16 +0300145
146 @classmethod
Eyal Bari20197482017-09-13 12:29:08 +0300147 def arp_req(cls, src_host, host):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200148 return Ether(dst="ff:ff:ff:ff:ff:ff", src=src_host.mac) / ARP(
149 op="who-has", hwsrc=src_host.bin_mac, pdst=host.ip4, psrc=src_host.ip4
150 )
Eyal Baric86e5922017-07-02 18:33:16 +0300151
152 @classmethod
153 def arp_reqs(cls, src_host, entries):
Eyal Bari20197482017-09-13 12:29:08 +0300154 return [cls.arp_req(src_host, e) for e in entries]
155
156 @classmethod
157 def garp_req(cls, host):
158 return cls.arp_req(host, host)
159
160 @classmethod
161 def garp_reqs(cls, entries):
162 return [cls.garp_req(e) for e in entries]
Eyal Baric86e5922017-07-02 18:33:16 +0300163
Eyal Bari758137a2017-07-05 14:31:30 +0300164 def arp_resp_host(self, src_host, arp_resp):
Eyal Baric86e5922017-07-02 18:33:16 +0300165 ether = arp_resp[Ether]
166 self.assertEqual(ether.dst, src_host.mac)
167
168 arp = arp_resp[ARP]
169 self.assertEqual(arp.hwtype, 1)
170 self.assertEqual(arp.ptype, 0x800)
171 self.assertEqual(arp.hwlen, 6)
172 self.assertEqual(arp.plen, 4)
173 arp_opts = {"who-has": 1, "is-at": 2}
174 self.assertEqual(arp.op, arp_opts["is-at"])
175 self.assertEqual(arp.hwdst, src_host.mac)
176 self.assertEqual(arp.pdst, src_host.ip4)
Eyal Bari758137a2017-07-05 14:31:30 +0300177 return Host(mac=arp.hwsrc, ip4=arp.psrc)
Eyal Baric86e5922017-07-02 18:33:16 +0300178
179 def arp_resp_hosts(self, src_host, pkts):
Eyal Bari758137a2017-07-05 14:31:30 +0300180 return {self.arp_resp_host(src_host, p) for p in pkts}
181
Paul Vinciguerra9db94452018-11-25 10:46:44 -0800182 @staticmethod
183 def inttoip4(ip):
Eyal Bari20197482017-09-13 12:29:08 +0300184 o1 = int(ip / 16777216) % 256
185 o2 = int(ip / 65536) % 256
186 o3 = int(ip / 256) % 256
187 o4 = int(ip) % 256
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200188 return "%s.%s.%s.%s" % (o1, o2, o3, o4)
Eyal Bari20197482017-09-13 12:29:08 +0300189
190 def arp_event_host(self, e):
Neale Ranns37029302018-08-10 05:30:06 -0700191 return Host(str(e.mac), ip4=str(e.ip))
Eyal Bari20197482017-09-13 12:29:08 +0300192
193 def arp_event_hosts(self, evs):
194 return {self.arp_event_host(e) for e in evs}
195
Eyal Baric125ecc2017-09-20 11:29:17 +0300196 def nd_event_host(self, e):
Neale Ranns37029302018-08-10 05:30:06 -0700197 return Host(str(e.mac), ip6=str(e.ip))
Eyal Baric125ecc2017-09-20 11:29:17 +0300198
199 def nd_event_hosts(self, evs):
200 return {self.nd_event_host(e) for e in evs}
201
Eyal Bari758137a2017-07-05 14:31:30 +0300202 @classmethod
203 def ns_req(cls, src_host, host):
204 nsma = in6_getnsma(inet_pton(AF_INET6, "fd10::ffff"))
205 d = inet_ntop(AF_INET6, nsma)
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200206 return (
207 Ether(dst="ff:ff:ff:ff:ff:ff", src=src_host.mac)
208 / IPv6(dst=d, src=src_host.ip6)
209 / ICMPv6ND_NS(tgt=host.ip6)
210 / ICMPv6NDOptSrcLLAddr(lladdr=src_host.mac)
211 )
Eyal Bari758137a2017-07-05 14:31:30 +0300212
213 @classmethod
Eyal Baric125ecc2017-09-20 11:29:17 +0300214 def ns_reqs_dst(cls, entries, dst_host):
215 return [cls.ns_req(e, dst_host) for e in entries]
216
217 @classmethod
218 def ns_reqs_src(cls, src_host, entries):
Eyal Bari758137a2017-07-05 14:31:30 +0300219 return [cls.ns_req(src_host, e) for e in entries]
220
221 def na_resp_host(self, src_host, rx):
222 self.assertEqual(rx[Ether].dst, src_host.mac)
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200223 self.assertEqual(in6_ptop(rx[IPv6].dst), in6_ptop(src_host.ip6))
Eyal Bari758137a2017-07-05 14:31:30 +0300224
225 self.assertTrue(rx.haslayer(ICMPv6ND_NA))
226 self.assertTrue(rx.haslayer(ICMPv6NDOptDstLLAddr))
227
228 na = rx[ICMPv6ND_NA]
229 return Host(mac=na.lladdr, ip6=na.tgt)
230
231 def na_resp_hosts(self, src_host, pkts):
232 return {self.na_resp_host(src_host, p) for p in pkts}
Eyal Baric86e5922017-07-02 18:33:16 +0300233
234 def set_bd_flags(self, bd_id, **args):
235 """
236 Enable/disable defined feature(s) of the bridge domain.
237
238 :param int bd_id: Bridge domain ID.
239 :param list args: List of feature/status pairs. Allowed features: \
240 learn, forward, flood, uu_flood and arp_term. Status False means \
241 disable, status True means enable the feature.
242 :raise: ValueError in case of unknown feature in the input.
243 """
244 for flag in args:
245 if flag == "learn":
246 feature_bitmap = 1 << 0
247 elif flag == "forward":
248 feature_bitmap = 1 << 1
249 elif flag == "flood":
250 feature_bitmap = 1 << 2
251 elif flag == "uu_flood":
252 feature_bitmap = 1 << 3
253 elif flag == "arp_term":
254 feature_bitmap = 1 << 4
255 else:
256 raise ValueError("Unknown feature used: %s" % flag)
257 is_set = 1 if args[flag] else 0
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200258 self.vapi.bridge_flags(bd_id=bd_id, is_set=is_set, flags=feature_bitmap)
Eyal Baric86e5922017-07-02 18:33:16 +0300259 self.logger.info("Bridge domain ID %d updated" % bd_id)
260
261 def verify_arp(self, src_host, req_hosts, resp_hosts, bd_id=1):
262 reqs = self.arp_reqs(src_host, req_hosts)
263
264 for swif in self.bd_swifs(bd_id):
265 swif.add_stream(reqs)
266
267 self.pg_enable_capture(self.pg_interfaces)
268 self.pg_start()
269
270 for swif in self.bd_swifs(bd_id):
271 resp_pkts = swif.get_capture(len(resp_hosts))
272 resps = self.arp_resp_hosts(src_host, resp_pkts)
273 self.assertEqual(len(resps ^ resp_hosts), 0)
274
Eyal Bari758137a2017-07-05 14:31:30 +0300275 def verify_nd(self, src_host, req_hosts, resp_hosts, bd_id=1):
Eyal Baric125ecc2017-09-20 11:29:17 +0300276 reqs = self.ns_reqs_src(src_host, req_hosts)
Eyal Bari758137a2017-07-05 14:31:30 +0300277
278 for swif in self.bd_swifs(bd_id):
279 swif.add_stream(reqs)
280
281 self.pg_enable_capture(self.pg_interfaces)
282 self.pg_start()
283
284 for swif in self.bd_swifs(bd_id):
285 resp_pkts = swif.get_capture(len(resp_hosts))
286 resps = self.na_resp_hosts(src_host, resp_pkts)
287 self.assertEqual(len(resps ^ resp_hosts), 0)
288
Eyal Baric86e5922017-07-02 18:33:16 +0300289 def test_l2bd_arp_term_01(self):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200290 """L2BD arp term - add 5 hosts, verify arp responses"""
Eyal Baric86e5922017-07-02 18:33:16 +0300291 src_host = self.ip4_host(50, 50, "00:00:11:22:33:44")
292 self.bd_add_del(1, is_add=1)
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200293 self.set_bd_flags(1, arp_term=True, flood=False, uu_flood=False, learn=False)
Eyal Baric86e5922017-07-02 18:33:16 +0300294 macs = self.mac_list(range(1, 5))
295 hosts = self.ip4_hosts(4, 1, macs)
296 self.add_del_arp_term_hosts(hosts, is_add=1)
Neale Ranns4d5b9172018-10-24 02:57:49 -0700297
Eyal Baric86e5922017-07-02 18:33:16 +0300298 self.verify_arp(src_host, hosts, hosts)
299 type(self).hosts = hosts
300
301 def test_l2bd_arp_term_02(self):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200302 """L2BD arp term - delete 3 hosts, verify arp responses"""
Eyal Baric86e5922017-07-02 18:33:16 +0300303 src_host = self.ip4_host(50, 50, "00:00:11:22:33:44")
304 macs = self.mac_list(range(1, 3))
305 deleted = self.ip4_hosts(4, 1, macs)
306 self.add_del_arp_term_hosts(deleted, is_add=0)
307 remaining = self.hosts - deleted
308 self.verify_arp(src_host, self.hosts, remaining)
309 type(self).hosts = remaining
310 self.bd_add_del(1, is_add=0)
311
312 def test_l2bd_arp_term_03(self):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200313 """L2BD arp term - recreate BD1, readd 3 hosts, verify arp responses"""
Eyal Baric86e5922017-07-02 18:33:16 +0300314 src_host = self.ip4_host(50, 50, "00:00:11:22:33:44")
315 self.bd_add_del(1, is_add=1)
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200316 self.set_bd_flags(1, arp_term=True, flood=False, uu_flood=False, learn=False)
Eyal Baric86e5922017-07-02 18:33:16 +0300317 macs = self.mac_list(range(1, 3))
318 readded = self.ip4_hosts(4, 1, macs)
319 self.add_del_arp_term_hosts(readded, is_add=1)
320 self.verify_arp(src_host, self.hosts | readded, readded)
321 type(self).hosts = readded
322
323 def test_l2bd_arp_term_04(self):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200324 """L2BD arp term - 2 IP4 addrs per host"""
Eyal Baric86e5922017-07-02 18:33:16 +0300325 src_host = self.ip4_host(50, 50, "00:00:11:22:33:44")
326 macs = self.mac_list(range(1, 3))
327 sub5_hosts = self.ip4_hosts(5, 1, macs)
328 self.add_del_arp_term_hosts(sub5_hosts, is_add=1)
329 hosts = self.hosts | sub5_hosts
330 self.verify_arp(src_host, hosts, hosts)
331 type(self).hosts = hosts
332 self.bd_add_del(1, is_add=0)
333
334 def test_l2bd_arp_term_05(self):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200335 """L2BD arp term - create and update 10 IP4-mac pairs"""
Eyal Baric86e5922017-07-02 18:33:16 +0300336 src_host = self.ip4_host(50, 50, "00:00:11:22:33:44")
337 self.bd_add_del(1, is_add=1)
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200338 self.set_bd_flags(1, arp_term=True, flood=False, uu_flood=False, learn=False)
Eyal Baric86e5922017-07-02 18:33:16 +0300339 macs1 = self.mac_list(range(10, 20))
340 hosts1 = self.ip4_hosts(5, 1, macs1)
341 self.add_del_arp_term_hosts(hosts1, is_add=1)
342 self.verify_arp(src_host, hosts1, hosts1)
343 macs2 = self.mac_list(range(20, 30))
344 hosts2 = self.ip4_hosts(5, 1, macs2)
345 self.add_del_arp_term_hosts(hosts2, is_add=1)
346 self.verify_arp(src_host, hosts1, hosts2)
347 self.bd_add_del(1, is_add=0)
348
Eyal Bari758137a2017-07-05 14:31:30 +0300349 def test_l2bd_arp_term_06(self):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200350 """L2BD arp/ND term - hosts with both ip4/ip6"""
Eyal Bari758137a2017-07-05 14:31:30 +0300351 src_host4 = self.ip4_host(50, 50, "00:00:11:22:33:44")
352 src_host6 = self.ip6_host(50, 50, "00:00:11:22:33:44")
353 self.bd_add_del(1, is_add=1)
354 # enable flood to make sure requests are not flooded
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200355 self.set_bd_flags(1, arp_term=True, flood=True, uu_flood=False, learn=False)
Eyal Bari758137a2017-07-05 14:31:30 +0300356 macs = self.mac_list(range(10, 20))
357 hosts6 = self.ip6_hosts(5, 1, macs)
358 hosts4 = self.ip4_hosts(5, 1, macs)
359 self.add_del_arp_term_hosts(hosts4, is_add=1)
360 self.add_del_arp_term_hosts(hosts6, is_add=1, is_ipv6=1)
361 self.verify_arp(src_host4, hosts4, hosts4)
362 self.verify_nd(src_host6, hosts6, hosts6)
363 self.bd_add_del(1, is_add=0)
364
365 def test_l2bd_arp_term_07(self):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200366 """L2BD ND term - Add and Del hosts, verify ND replies"""
Eyal Bari758137a2017-07-05 14:31:30 +0300367 src_host6 = self.ip6_host(50, 50, "00:00:11:22:33:44")
368 self.bd_add_del(1, is_add=1)
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200369 self.set_bd_flags(1, arp_term=True, flood=False, uu_flood=False, learn=False)
Eyal Bari758137a2017-07-05 14:31:30 +0300370 macs = self.mac_list(range(10, 20))
371 hosts6 = self.ip6_hosts(5, 1, macs)
372 self.add_del_arp_term_hosts(hosts6, is_add=1, is_ipv6=1)
373 self.verify_nd(src_host6, hosts6, hosts6)
374 del_macs = self.mac_list(range(10, 15))
375 deleted = self.ip6_hosts(5, 1, del_macs)
376 self.add_del_arp_term_hosts(deleted, is_add=0, is_ipv6=1)
377 self.verify_nd(src_host6, hosts6, hosts6 - deleted)
378 self.bd_add_del(1, is_add=0)
379
380 def test_l2bd_arp_term_08(self):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200381 """L2BD ND term - Add and update IP+mac, verify ND replies"""
Eyal Bari758137a2017-07-05 14:31:30 +0300382 src_host = self.ip6_host(50, 50, "00:00:11:22:33:44")
383 self.bd_add_del(1, is_add=1)
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200384 self.set_bd_flags(1, arp_term=True, flood=False, uu_flood=False, learn=False)
Eyal Bari758137a2017-07-05 14:31:30 +0300385 macs1 = self.mac_list(range(10, 20))
386 hosts = self.ip6_hosts(5, 1, macs1)
387 self.add_del_arp_term_hosts(hosts, is_add=1, is_ipv6=1)
388 self.verify_nd(src_host, hosts, hosts)
389 macs2 = self.mac_list(range(20, 30))
390 updated = self.ip6_hosts(5, 1, macs2)
391 self.add_del_arp_term_hosts(updated, is_add=1, is_ipv6=1)
392 self.verify_nd(src_host, hosts, updated)
393 self.bd_add_del(1, is_add=0)
394
Eyal Bari20197482017-09-13 12:29:08 +0300395 def test_l2bd_arp_term_09(self):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200396 """L2BD arp term - send garps, verify arp event reports"""
Neale Rannscbe25aa2019-09-30 10:53:31 +0000397 self.vapi.want_l2_arp_term_events(enable=1)
Eyal Bari20197482017-09-13 12:29:08 +0300398 self.bd_add_del(1, is_add=1)
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200399 self.set_bd_flags(1, arp_term=True, flood=False, uu_flood=False, learn=False)
Eyal Bari20197482017-09-13 12:29:08 +0300400 macs = self.mac_list(range(90, 95))
401 hosts = self.ip4_hosts(5, 1, macs)
402
403 garps = self.garp_reqs(hosts)
404 self.bd_swifs(1)[0].add_stream(garps)
405
406 self.pg_enable_capture(self.pg_interfaces)
407 self.pg_start()
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200408 evs = [
409 self.vapi.wait_for_event(1, "l2_arp_term_event") for i in range(len(hosts))
410 ]
Eyal Bari20197482017-09-13 12:29:08 +0300411 ev_hosts = self.arp_event_hosts(evs)
412 self.assertEqual(len(ev_hosts ^ hosts), 0)
413
414 def test_l2bd_arp_term_10(self):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200415 """L2BD arp term - send duplicate garps, verify suppression"""
Eyal Bari20197482017-09-13 12:29:08 +0300416 macs = self.mac_list(range(70, 71))
417 hosts = self.ip4_hosts(6, 1, macs)
418
419 """ send the packet 5 times expect one event
420 """
421 garps = self.garp_reqs(hosts) * 5
422 self.bd_swifs(1)[0].add_stream(garps)
423
424 self.pg_enable_capture(self.pg_interfaces)
425 self.pg_start()
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200426 evs = [
427 self.vapi.wait_for_event(1, "l2_arp_term_event") for i in range(len(hosts))
428 ]
Eyal Bari20197482017-09-13 12:29:08 +0300429 ev_hosts = self.arp_event_hosts(evs)
430 self.assertEqual(len(ev_hosts ^ hosts), 0)
431
432 def test_l2bd_arp_term_11(self):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200433 """L2BD arp term - disable ip4 arp events,send garps, verify no events"""
Neale Rannscbe25aa2019-09-30 10:53:31 +0000434 self.vapi.want_l2_arp_term_events(enable=0)
Eyal Bari20197482017-09-13 12:29:08 +0300435 macs = self.mac_list(range(90, 95))
436 hosts = self.ip4_hosts(5, 1, macs)
437
438 garps = self.garp_reqs(hosts)
439 self.bd_swifs(1)[0].add_stream(garps)
440
441 self.pg_enable_capture(self.pg_interfaces)
442 self.pg_start()
443 self.sleep(1)
444 self.assertEqual(len(self.vapi.collect_events()), 0)
445 self.bd_add_del(1, is_add=0)
446
Eyal Baric125ecc2017-09-20 11:29:17 +0300447 def test_l2bd_arp_term_12(self):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200448 """L2BD ND term - send NS packets verify reports"""
Neale Rannscbe25aa2019-09-30 10:53:31 +0000449 self.vapi.want_l2_arp_term_events(enable=1)
Eyal Baric125ecc2017-09-20 11:29:17 +0300450 dst_host = self.ip6_host(50, 50, "00:00:11:22:33:44")
451 self.bd_add_del(1, is_add=1)
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200452 self.set_bd_flags(1, arp_term=True, flood=False, uu_flood=False, learn=False)
Eyal Baric125ecc2017-09-20 11:29:17 +0300453 macs = self.mac_list(range(10, 15))
454 hosts = self.ip6_hosts(5, 1, macs)
455 reqs = self.ns_reqs_dst(hosts, dst_host)
456 self.bd_swifs(1)[0].add_stream(reqs)
457
458 self.pg_enable_capture(self.pg_interfaces)
459 self.pg_start()
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200460 evs = [
461 self.vapi.wait_for_event(2, "l2_arp_term_event") for i in range(len(hosts))
462 ]
Eyal Baric125ecc2017-09-20 11:29:17 +0300463 ev_hosts = self.nd_event_hosts(evs)
464 self.assertEqual(len(ev_hosts ^ hosts), 0)
465
466 def test_l2bd_arp_term_13(self):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200467 """L2BD ND term - send duplicate ns, verify suppression"""
Eyal Baric125ecc2017-09-20 11:29:17 +0300468 dst_host = self.ip6_host(50, 50, "00:00:11:22:33:44")
Ole Troandf0191e2019-10-25 17:03:54 +0200469 macs = self.mac_list(range(16, 17))
Eyal Baric125ecc2017-09-20 11:29:17 +0300470 hosts = self.ip6_hosts(5, 1, macs)
471 reqs = self.ns_reqs_dst(hosts, dst_host) * 5
472 self.bd_swifs(1)[0].add_stream(reqs)
473
474 self.pg_enable_capture(self.pg_interfaces)
475 self.pg_start()
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200476 evs = [
477 self.vapi.wait_for_event(2, "l2_arp_term_event") for i in range(len(hosts))
478 ]
Eyal Baric125ecc2017-09-20 11:29:17 +0300479 ev_hosts = self.nd_event_hosts(evs)
480 self.assertEqual(len(ev_hosts ^ hosts), 0)
481
482 def test_l2bd_arp_term_14(self):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200483 """L2BD ND term - disable ip4 arp events,send ns, verify no events"""
Neale Rannscbe25aa2019-09-30 10:53:31 +0000484 self.vapi.want_l2_arp_term_events(enable=0)
Eyal Baric125ecc2017-09-20 11:29:17 +0300485 dst_host = self.ip6_host(50, 50, "00:00:11:22:33:44")
486 macs = self.mac_list(range(10, 15))
487 hosts = self.ip6_hosts(5, 1, macs)
488 reqs = self.ns_reqs_dst(hosts, dst_host)
489 self.bd_swifs(1)[0].add_stream(reqs)
490
491 self.pg_enable_capture(self.pg_interfaces)
492 self.pg_start()
493 self.sleep(1)
494 self.assertEqual(len(self.vapi.collect_events()), 0)
495 self.bd_add_del(1, is_add=0)
496
Eyal Baric86e5922017-07-02 18:33:16 +0300497
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200498if __name__ == "__main__":
Eyal Baric86e5922017-07-02 18:33:16 +0300499 unittest.main(testRunner=VppTestRunner)