blob: 276555d6267c82bca464e3939297eb7e4720294e [file] [log] [blame]
Neale Ranns32e1c012016-11-22 17:07:28 +00001#!/usr/bin/env python
2
3import unittest
4
5from framework import VppTestCase, VppTestRunner
6from vpp_sub_interface import VppSubInterface, VppDot1QSubint, VppDot1ADSubint
Neale Ranns180279b2017-03-16 15:49:09 -04007from vpp_ip_route import VppIpMRoute, VppMRoutePath, VppMFibSignal, \
8 MRouteItfFlags, MRouteEntryFlags
Neale Ranns32e1c012016-11-22 17:07:28 +00009
10from scapy.packet import Raw
11from scapy.layers.l2 import Ether
Neale Ranns9d676af2017-03-15 01:28:31 -070012from scapy.layers.inet import IP, UDP, getmacbyip, ICMP
Neale Ranns32e1c012016-11-22 17:07:28 +000013from scapy.layers.inet6 import IPv6, getmacbyip6
14from util import ppp
15
Neale Ranns9bea8fb2017-02-03 04:34:01 -080016#
17# The number of packets sent is set to 90 so that when we replicate more than 3
18# times, which we do for some entries, we will generate more than 256 packets
Neale Rannsaaa396a2017-02-05 09:12:02 -080019# to the next node in the VLIB graph. Thus we are testing the code's
20# correctness handling this over-flow
Neale Ranns9bea8fb2017-02-03 04:34:01 -080021#
22N_PKTS_IN_STREAM = 90
23
Neale Ranns32e1c012016-11-22 17:07:28 +000024
Neale Ranns5a8123b2017-01-26 01:18:23 -080025class TestMFIB(VppTestCase):
26 """ MFIB Test Case """
27
28 def setUp(self):
29 super(TestMFIB, self).setUp()
30
31 def test_mfib(self):
32 """ MFIB Unit Tests """
33 error = self.vapi.cli("test mfib")
34
35 if error:
36 self.logger.critical(error)
37 self.assertEqual(error.find("Failed"), -1)
38
39
Neale Ranns32e1c012016-11-22 17:07:28 +000040class TestIPMcast(VppTestCase):
41 """ IP Multicast Test Case """
42
43 def setUp(self):
44 super(TestIPMcast, self).setUp()
45
Neale Ranns37be7362017-02-21 17:30:26 -080046 # create 8 pg interfaces
47 self.create_pg_interfaces(range(8))
Neale Ranns32e1c012016-11-22 17:07:28 +000048
49 # setup interfaces
50 for i in self.pg_interfaces:
51 i.admin_up()
52 i.config_ip4()
53 i.config_ip6()
54 i.resolve_arp()
55 i.resolve_ndp()
56
Neale Ranns9d676af2017-03-15 01:28:31 -070057 def create_stream_ip4(self, src_if, src_ip, dst_ip, payload_size=0):
Neale Ranns32e1c012016-11-22 17:07:28 +000058 pkts = []
Neale Ranns9d676af2017-03-15 01:28:31 -070059 # default to small packet sizes
60 p = (Ether(dst=src_if.local_mac, src=src_if.remote_mac) /
61 IP(src=src_ip, dst=dst_ip) /
62 UDP(sport=1234, dport=1234))
63 if not payload_size:
64 payload_size = 64 - len(p)
65 p = p / Raw('\xa5' * payload_size)
66
Neale Ranns9bea8fb2017-02-03 04:34:01 -080067 for i in range(0, N_PKTS_IN_STREAM):
Neale Ranns32e1c012016-11-22 17:07:28 +000068 pkts.append(p)
69 return pkts
70
71 def create_stream_ip6(self, src_if, src_ip, dst_ip):
72 pkts = []
Neale Ranns9bea8fb2017-02-03 04:34:01 -080073 for i in range(0, N_PKTS_IN_STREAM):
Neale Ranns32e1c012016-11-22 17:07:28 +000074 info = self.create_packet_info(src_if, src_if)
75 payload = self.info_to_payload(info)
76 p = (Ether(dst=src_if.local_mac, src=src_if.remote_mac) /
77 IPv6(src=src_ip, dst=dst_ip) /
78 UDP(sport=1234, dport=1234) /
79 Raw(payload))
80 info.data = p.copy()
81 pkts.append(p)
82 return pkts
83
84 def verify_filter(self, capture, sent):
85 if not len(capture) == len(sent):
86 # filter out any IPv6 RAs from the captur
87 for p in capture:
88 if (p.haslayer(IPv6)):
89 capture.remove(p)
90 return capture
91
Neale Rannsc2aad532017-05-30 09:53:52 -070092 def verify_capture_ip4(self, rx_if, sent):
93 rxd = rx_if.get_capture(len(sent))
Neale Ranns32e1c012016-11-22 17:07:28 +000094
95 try:
96 capture = self.verify_filter(rxd, sent)
97
98 self.assertEqual(len(capture), len(sent))
99
100 for i in range(len(capture)):
101 tx = sent[i]
102 rx = capture[i]
103
Neale Ranns32e1c012016-11-22 17:07:28 +0000104 eth = rx[Ether]
105 self.assertEqual(eth.type, 0x800)
106
107 tx_ip = tx[IP]
108 rx_ip = rx[IP]
109
110 # check the MAC address on the RX'd packet is correctly formed
111 self.assertEqual(eth.dst, getmacbyip(rx_ip.dst))
112
113 self.assertEqual(rx_ip.src, tx_ip.src)
114 self.assertEqual(rx_ip.dst, tx_ip.dst)
115 # IP processing post pop has decremented the TTL
116 self.assertEqual(rx_ip.ttl + 1, tx_ip.ttl)
117
118 except:
119 raise
120
Neale Rannsc2aad532017-05-30 09:53:52 -0700121 def verify_capture_ip6(self, rx_if, sent):
122 capture = rx_if.get_capture(len(sent))
Neale Ranns32e1c012016-11-22 17:07:28 +0000123
124 self.assertEqual(len(capture), len(sent))
125
126 for i in range(len(capture)):
127 tx = sent[i]
128 rx = capture[i]
129
Neale Ranns32e1c012016-11-22 17:07:28 +0000130 eth = rx[Ether]
131 self.assertEqual(eth.type, 0x86DD)
132
133 tx_ip = tx[IPv6]
134 rx_ip = rx[IPv6]
135
136 # check the MAC address on the RX'd packet is correctly formed
137 self.assertEqual(eth.dst, getmacbyip6(rx_ip.dst))
138
139 self.assertEqual(rx_ip.src, tx_ip.src)
140 self.assertEqual(rx_ip.dst, tx_ip.dst)
141 # IP processing post pop has decremented the TTL
142 self.assertEqual(rx_ip.hlim + 1, tx_ip.hlim)
143
144 def test_ip_mcast(self):
145 """ IP Multicast Replication """
146
147 #
148 # a stream that matches the default route. gets dropped.
149 #
150 self.vapi.cli("clear trace")
151 tx = self.create_stream_ip4(self.pg0, "1.1.1.1", "232.1.1.1")
152 self.pg0.add_stream(tx)
153
154 self.pg_enable_capture(self.pg_interfaces)
155 self.pg_start()
156
157 self.pg0.assert_nothing_captured(
158 remark="IP multicast packets forwarded on default route")
159
160 #
161 # A (*,G).
Neale Ranns37be7362017-02-21 17:30:26 -0800162 # one accepting interface, pg0, 7 forwarding interfaces
163 # many forwarding interfaces test the case where the replicare DPO
164 # needs to use extra cache lines for the buckets.
Neale Ranns32e1c012016-11-22 17:07:28 +0000165 #
Neale Ranns5a8123b2017-01-26 01:18:23 -0800166 route_232_1_1_1 = VppIpMRoute(
Neale Ranns32e1c012016-11-22 17:07:28 +0000167 self,
168 "0.0.0.0",
169 "232.1.1.1", 32,
170 MRouteEntryFlags.MFIB_ENTRY_FLAG_NONE,
Neale Ranns5a8123b2017-01-26 01:18:23 -0800171 [VppMRoutePath(self.pg0.sw_if_index,
172 MRouteItfFlags.MFIB_ITF_FLAG_ACCEPT),
173 VppMRoutePath(self.pg1.sw_if_index,
174 MRouteItfFlags.MFIB_ITF_FLAG_FORWARD),
175 VppMRoutePath(self.pg2.sw_if_index,
176 MRouteItfFlags.MFIB_ITF_FLAG_FORWARD),
177 VppMRoutePath(self.pg3.sw_if_index,
Neale Ranns37be7362017-02-21 17:30:26 -0800178 MRouteItfFlags.MFIB_ITF_FLAG_FORWARD),
179 VppMRoutePath(self.pg4.sw_if_index,
180 MRouteItfFlags.MFIB_ITF_FLAG_FORWARD),
181 VppMRoutePath(self.pg5.sw_if_index,
182 MRouteItfFlags.MFIB_ITF_FLAG_FORWARD),
183 VppMRoutePath(self.pg6.sw_if_index,
184 MRouteItfFlags.MFIB_ITF_FLAG_FORWARD),
185 VppMRoutePath(self.pg7.sw_if_index,
Neale Ranns5a8123b2017-01-26 01:18:23 -0800186 MRouteItfFlags.MFIB_ITF_FLAG_FORWARD)])
Neale Ranns32e1c012016-11-22 17:07:28 +0000187 route_232_1_1_1.add_vpp_config()
188
189 #
190 # An (S,G).
191 # one accepting interface, pg0, 2 forwarding interfaces
192 #
Neale Ranns5a8123b2017-01-26 01:18:23 -0800193 route_1_1_1_1_232_1_1_1 = VppIpMRoute(
Neale Ranns32e1c012016-11-22 17:07:28 +0000194 self,
195 "1.1.1.1",
196 "232.1.1.1", 64,
197 MRouteEntryFlags.MFIB_ENTRY_FLAG_NONE,
Neale Ranns5a8123b2017-01-26 01:18:23 -0800198 [VppMRoutePath(self.pg0.sw_if_index,
199 MRouteItfFlags.MFIB_ITF_FLAG_ACCEPT),
200 VppMRoutePath(self.pg1.sw_if_index,
201 MRouteItfFlags.MFIB_ITF_FLAG_FORWARD),
202 VppMRoutePath(self.pg2.sw_if_index,
203 MRouteItfFlags.MFIB_ITF_FLAG_FORWARD)])
Neale Ranns32e1c012016-11-22 17:07:28 +0000204 route_1_1_1_1_232_1_1_1.add_vpp_config()
205
206 #
207 # An (*,G/m).
208 # one accepting interface, pg0, 1 forwarding interfaces
209 #
Neale Ranns5a8123b2017-01-26 01:18:23 -0800210 route_232 = VppIpMRoute(
Neale Ranns32e1c012016-11-22 17:07:28 +0000211 self,
212 "0.0.0.0",
213 "232.0.0.0", 8,
214 MRouteEntryFlags.MFIB_ENTRY_FLAG_NONE,
Neale Ranns5a8123b2017-01-26 01:18:23 -0800215 [VppMRoutePath(self.pg0.sw_if_index,
216 MRouteItfFlags.MFIB_ITF_FLAG_ACCEPT),
217 VppMRoutePath(self.pg1.sw_if_index,
218 MRouteItfFlags.MFIB_ITF_FLAG_FORWARD)])
Neale Ranns32e1c012016-11-22 17:07:28 +0000219 route_232.add_vpp_config()
220
221 #
222 # a stream that matches the route for (1.1.1.1,232.1.1.1)
Neale Ranns9d676af2017-03-15 01:28:31 -0700223 # small packets
Neale Ranns32e1c012016-11-22 17:07:28 +0000224 #
225 self.vapi.cli("clear trace")
226 tx = self.create_stream_ip4(self.pg0, "1.1.1.1", "232.1.1.1")
227 self.pg0.add_stream(tx)
228
229 self.pg_enable_capture(self.pg_interfaces)
230 self.pg_start()
231
Neale Ranns37be7362017-02-21 17:30:26 -0800232 # We expect replications on Pg1->7
Neale Ranns32e1c012016-11-22 17:07:28 +0000233 self.verify_capture_ip4(self.pg1, tx)
234 self.verify_capture_ip4(self.pg2, tx)
235
236 # no replications on Pg0
237 self.pg0.assert_nothing_captured(
238 remark="IP multicast packets forwarded on PG0")
239 self.pg3.assert_nothing_captured(
240 remark="IP multicast packets forwarded on PG3")
241
242 #
Neale Ranns9d676af2017-03-15 01:28:31 -0700243 # a stream that matches the route for (1.1.1.1,232.1.1.1)
244 # large packets
245 #
246 self.vapi.cli("clear trace")
247 tx = self.create_stream_ip4(self.pg0, "1.1.1.1", "232.1.1.1",
248 payload_size=1024)
249 self.pg0.add_stream(tx)
250
251 self.pg_enable_capture(self.pg_interfaces)
252 self.pg_start()
253
254 # We expect replications on Pg1->7
255 self.verify_capture_ip4(self.pg1, tx)
256 self.verify_capture_ip4(self.pg2, tx)
Neale Ranns9d676af2017-03-15 01:28:31 -0700257
258 # no replications on Pg0
259 self.pg0.assert_nothing_captured(
260 remark="IP multicast packets forwarded on PG0")
261 self.pg3.assert_nothing_captured(
262 remark="IP multicast packets forwarded on PG3")
263
264 #
Neale Ranns32e1c012016-11-22 17:07:28 +0000265 # a stream that matches the route for (*,232.0.0.0/8)
266 # Send packets with the 9th bit set so we test the correct clearing
267 # of that bit in the mac rewrite
268 #
269 self.vapi.cli("clear trace")
270 tx = self.create_stream_ip4(self.pg0, "1.1.1.1", "232.255.255.255")
271 self.pg0.add_stream(tx)
272
273 self.pg_enable_capture(self.pg_interfaces)
274 self.pg_start()
275
276 # We expect replications on Pg1 only
277 self.verify_capture_ip4(self.pg1, tx)
278
279 # no replications on Pg0, Pg2 not Pg3
280 self.pg0.assert_nothing_captured(
281 remark="IP multicast packets forwarded on PG0")
282 self.pg2.assert_nothing_captured(
283 remark="IP multicast packets forwarded on PG2")
284 self.pg3.assert_nothing_captured(
285 remark="IP multicast packets forwarded on PG3")
286
287 #
288 # a stream that matches the route for (*,232.1.1.1)
289 #
290 self.vapi.cli("clear trace")
291 tx = self.create_stream_ip4(self.pg0, "1.1.1.2", "232.1.1.1")
292 self.pg0.add_stream(tx)
293
294 self.pg_enable_capture(self.pg_interfaces)
295 self.pg_start()
296
297 # We expect replications on Pg1, 2, 3.
298 self.verify_capture_ip4(self.pg1, tx)
299 self.verify_capture_ip4(self.pg2, tx)
300 self.verify_capture_ip4(self.pg3, tx)
Neale Rannsc2aad532017-05-30 09:53:52 -0700301 self.verify_capture_ip4(self.pg4, tx)
302 self.verify_capture_ip4(self.pg5, tx)
303 self.verify_capture_ip4(self.pg6, tx)
304 self.verify_capture_ip4(self.pg7, tx)
Neale Ranns32e1c012016-11-22 17:07:28 +0000305
306 route_232_1_1_1.remove_vpp_config()
307 route_1_1_1_1_232_1_1_1.remove_vpp_config()
308 route_232.remove_vpp_config()
309
310 def test_ip6_mcast(self):
311 """ IPv6 Multicast Replication """
312
313 #
314 # a stream that matches the default route. gets dropped.
315 #
316 self.vapi.cli("clear trace")
317 tx = self.create_stream_ip6(self.pg0, "2001::1", "ff01::1")
318 self.pg0.add_stream(tx)
319
320 self.pg_enable_capture(self.pg_interfaces)
321 self.pg_start()
322
323 self.pg0.assert_nothing_captured(
324 remark="IPv6 multicast packets forwarded on default route")
325
326 #
327 # A (*,G).
328 # one accepting interface, pg0, 3 forwarding interfaces
329 #
Neale Ranns5a8123b2017-01-26 01:18:23 -0800330 route_ff01_1 = VppIpMRoute(
Neale Ranns32e1c012016-11-22 17:07:28 +0000331 self,
332 "::",
333 "ff01::1", 128,
334 MRouteEntryFlags.MFIB_ENTRY_FLAG_NONE,
Neale Ranns5a8123b2017-01-26 01:18:23 -0800335 [VppMRoutePath(self.pg0.sw_if_index,
336 MRouteItfFlags.MFIB_ITF_FLAG_ACCEPT),
337 VppMRoutePath(self.pg1.sw_if_index,
338 MRouteItfFlags.MFIB_ITF_FLAG_FORWARD),
339 VppMRoutePath(self.pg2.sw_if_index,
340 MRouteItfFlags.MFIB_ITF_FLAG_FORWARD),
341 VppMRoutePath(self.pg3.sw_if_index,
342 MRouteItfFlags.MFIB_ITF_FLAG_FORWARD)],
Neale Ranns32e1c012016-11-22 17:07:28 +0000343 is_ip6=1)
344 route_ff01_1.add_vpp_config()
345
346 #
347 # An (S,G).
348 # one accepting interface, pg0, 2 forwarding interfaces
349 #
Neale Ranns5a8123b2017-01-26 01:18:23 -0800350 route_2001_ff01_1 = VppIpMRoute(
Neale Ranns32e1c012016-11-22 17:07:28 +0000351 self,
352 "2001::1",
353 "ff01::1", 256,
354 MRouteEntryFlags.MFIB_ENTRY_FLAG_NONE,
Neale Ranns5a8123b2017-01-26 01:18:23 -0800355 [VppMRoutePath(self.pg0.sw_if_index,
356 MRouteItfFlags.MFIB_ITF_FLAG_ACCEPT),
357 VppMRoutePath(self.pg1.sw_if_index,
358 MRouteItfFlags.MFIB_ITF_FLAG_FORWARD),
359 VppMRoutePath(self.pg2.sw_if_index,
360 MRouteItfFlags.MFIB_ITF_FLAG_FORWARD)],
Neale Ranns32e1c012016-11-22 17:07:28 +0000361 is_ip6=1)
362 route_2001_ff01_1.add_vpp_config()
363
364 #
365 # An (*,G/m).
366 # one accepting interface, pg0, 1 forwarding interface
367 #
Neale Ranns5a8123b2017-01-26 01:18:23 -0800368 route_ff01 = VppIpMRoute(
Neale Ranns32e1c012016-11-22 17:07:28 +0000369 self,
370 "::",
371 "ff01::", 16,
372 MRouteEntryFlags.MFIB_ENTRY_FLAG_NONE,
Neale Ranns5a8123b2017-01-26 01:18:23 -0800373 [VppMRoutePath(self.pg0.sw_if_index,
374 MRouteItfFlags.MFIB_ITF_FLAG_ACCEPT),
375 VppMRoutePath(self.pg1.sw_if_index,
376 MRouteItfFlags.MFIB_ITF_FLAG_FORWARD)],
Neale Ranns32e1c012016-11-22 17:07:28 +0000377 is_ip6=1)
378 route_ff01.add_vpp_config()
379
380 #
381 # a stream that matches the route for (*, ff01::/16)
382 #
383 self.vapi.cli("clear trace")
384 tx = self.create_stream_ip6(self.pg0, "2002::1", "ff01:2::255")
385 self.pg0.add_stream(tx)
386
387 self.pg_enable_capture(self.pg_interfaces)
388 self.pg_start()
389
390 # We expect replications on Pg1
391 self.verify_capture_ip6(self.pg1, tx)
392
393 # no replications on Pg0, Pg3
394 self.pg0.assert_nothing_captured(
395 remark="IP multicast packets forwarded on PG0")
396 self.pg2.assert_nothing_captured(
397 remark="IP multicast packets forwarded on PG2")
398 self.pg3.assert_nothing_captured(
399 remark="IP multicast packets forwarded on PG3")
400
401 #
Neale Rannsc2aad532017-05-30 09:53:52 -0700402 # Bounce the interface and it should still work
403 #
404 self.pg1.admin_down()
405 self.pg0.add_stream(tx)
406 self.pg_enable_capture(self.pg_interfaces)
407 self.pg_start()
408 self.pg1.assert_nothing_captured(
409 remark="IP multicast packets forwarded on down PG1")
410
411 self.pg1.admin_up()
412 self.pg0.add_stream(tx)
413 self.pg_enable_capture(self.pg_interfaces)
414 self.pg_start()
415 self.verify_capture_ip6(self.pg1, tx)
416
417 #
Neale Ranns32e1c012016-11-22 17:07:28 +0000418 # a stream that matches the route for (*,ff01::1)
419 #
420 self.vapi.cli("clear trace")
421 tx = self.create_stream_ip6(self.pg0, "2002::2", "ff01::1")
422 self.pg0.add_stream(tx)
423
424 self.pg_enable_capture(self.pg_interfaces)
425 self.pg_start()
426
427 # We expect replications on Pg1, 2, 3.
428 self.verify_capture_ip6(self.pg1, tx)
429 self.verify_capture_ip6(self.pg2, tx)
430 self.verify_capture_ip6(self.pg3, tx)
431
432 # no replications on Pg0
433 self.pg0.assert_nothing_captured(
434 remark="IPv6 multicast packets forwarded on PG0")
435
436 #
437 # a stream that matches the route for (2001::1, ff00::1)
438 #
439 self.vapi.cli("clear trace")
440 tx = self.create_stream_ip6(self.pg0, "2001::1", "ff01::1")
441 self.pg0.add_stream(tx)
442
443 self.pg_enable_capture(self.pg_interfaces)
444 self.pg_start()
445
446 # We expect replications on Pg1, 2,
447 self.verify_capture_ip6(self.pg1, tx)
448 self.verify_capture_ip6(self.pg2, tx)
449
450 # no replications on Pg0, Pg3
451 self.pg0.assert_nothing_captured(
452 remark="IP multicast packets forwarded on PG0")
453 self.pg3.assert_nothing_captured(
454 remark="IP multicast packets forwarded on PG3")
455
456 route_ff01.remove_vpp_config()
457 route_ff01_1.remove_vpp_config()
458 route_2001_ff01_1.remove_vpp_config()
459
460 def _mcast_connected_send_stream(self, dst_ip):
461 self.vapi.cli("clear trace")
462 tx = self.create_stream_ip4(self.pg0,
463 self.pg0.remote_ip4,
464 dst_ip)
465 self.pg0.add_stream(tx)
466
467 self.pg_enable_capture(self.pg_interfaces)
468 self.pg_start()
469
470 # We expect replications on Pg1.
471 self.verify_capture_ip4(self.pg1, tx)
472
473 return tx
474
475 def test_ip_mcast_connected(self):
476 """ IP Multicast Connected Source check """
477
478 #
479 # A (*,G).
480 # one accepting interface, pg0, 1 forwarding interfaces
481 #
Neale Ranns5a8123b2017-01-26 01:18:23 -0800482 route_232_1_1_1 = VppIpMRoute(
Neale Ranns32e1c012016-11-22 17:07:28 +0000483 self,
484 "0.0.0.0",
485 "232.1.1.1", 32,
486 MRouteEntryFlags.MFIB_ENTRY_FLAG_NONE,
Neale Ranns5a8123b2017-01-26 01:18:23 -0800487 [VppMRoutePath(self.pg0.sw_if_index,
488 MRouteItfFlags.MFIB_ITF_FLAG_ACCEPT),
489 VppMRoutePath(self.pg1.sw_if_index,
490 MRouteItfFlags.MFIB_ITF_FLAG_FORWARD)])
Neale Ranns32e1c012016-11-22 17:07:28 +0000491
492 route_232_1_1_1.add_vpp_config()
493 route_232_1_1_1.update_entry_flags(
494 MRouteEntryFlags.MFIB_ENTRY_FLAG_CONNECTED)
495
496 #
497 # Now the (*,G) is present, send from connected source
498 #
499 tx = self._mcast_connected_send_stream("232.1.1.1")
500
501 #
502 # Constrct a representation of the signal we expect on pg0
503 #
Neale Ranns5a8123b2017-01-26 01:18:23 -0800504 signal_232_1_1_1_itf_0 = VppMFibSignal(self,
505 route_232_1_1_1,
506 self.pg0.sw_if_index,
507 tx[0])
Neale Ranns32e1c012016-11-22 17:07:28 +0000508
509 #
510 # read the only expected signal
511 #
512 signals = self.vapi.mfib_signal_dump()
513
514 self.assertEqual(1, len(signals))
515
516 signal_232_1_1_1_itf_0.compare(signals[0])
517
518 #
519 # reading the signal allows for the generation of another
520 # so send more packets and expect the next signal
521 #
522 tx = self._mcast_connected_send_stream("232.1.1.1")
523
524 signals = self.vapi.mfib_signal_dump()
525 self.assertEqual(1, len(signals))
526 signal_232_1_1_1_itf_0.compare(signals[0])
527
528 #
529 # A Second entry with connected check
530 # one accepting interface, pg0, 1 forwarding interfaces
531 #
Neale Ranns5a8123b2017-01-26 01:18:23 -0800532 route_232_1_1_2 = VppIpMRoute(
Neale Ranns32e1c012016-11-22 17:07:28 +0000533 self,
534 "0.0.0.0",
535 "232.1.1.2", 32,
536 MRouteEntryFlags.MFIB_ENTRY_FLAG_NONE,
Neale Ranns5a8123b2017-01-26 01:18:23 -0800537 [VppMRoutePath(self.pg0.sw_if_index,
538 MRouteItfFlags.MFIB_ITF_FLAG_ACCEPT),
539 VppMRoutePath(self.pg1.sw_if_index,
540 MRouteItfFlags.MFIB_ITF_FLAG_FORWARD)])
Neale Ranns32e1c012016-11-22 17:07:28 +0000541
542 route_232_1_1_2.add_vpp_config()
543 route_232_1_1_2.update_entry_flags(
544 MRouteEntryFlags.MFIB_ENTRY_FLAG_CONNECTED)
545
546 #
547 # Send traffic to both entries. One read should net us two signals
548 #
Neale Ranns5a8123b2017-01-26 01:18:23 -0800549 signal_232_1_1_2_itf_0 = VppMFibSignal(self,
550 route_232_1_1_2,
551 self.pg0.sw_if_index,
552 tx[0])
Neale Ranns32e1c012016-11-22 17:07:28 +0000553 tx = self._mcast_connected_send_stream("232.1.1.1")
554 tx2 = self._mcast_connected_send_stream("232.1.1.2")
555
556 #
557 # read the only expected signal
558 #
559 signals = self.vapi.mfib_signal_dump()
560
561 self.assertEqual(2, len(signals))
562
563 signal_232_1_1_1_itf_0.compare(signals[1])
564 signal_232_1_1_2_itf_0.compare(signals[0])
565
566 route_232_1_1_1.remove_vpp_config()
567 route_232_1_1_2.remove_vpp_config()
568
569 def test_ip_mcast_signal(self):
570 """ IP Multicast Signal """
571
572 #
573 # A (*,G).
574 # one accepting interface, pg0, 1 forwarding interfaces
575 #
Neale Ranns5a8123b2017-01-26 01:18:23 -0800576 route_232_1_1_1 = VppIpMRoute(
Neale Ranns32e1c012016-11-22 17:07:28 +0000577 self,
578 "0.0.0.0",
579 "232.1.1.1", 32,
580 MRouteEntryFlags.MFIB_ENTRY_FLAG_NONE,
Neale Ranns5a8123b2017-01-26 01:18:23 -0800581 [VppMRoutePath(self.pg0.sw_if_index,
582 MRouteItfFlags.MFIB_ITF_FLAG_ACCEPT),
583 VppMRoutePath(self.pg1.sw_if_index,
584 MRouteItfFlags.MFIB_ITF_FLAG_FORWARD)])
Neale Ranns32e1c012016-11-22 17:07:28 +0000585
586 route_232_1_1_1.add_vpp_config()
587 route_232_1_1_1.update_entry_flags(
588 MRouteEntryFlags.MFIB_ENTRY_FLAG_SIGNAL)
589
590 #
591 # Now the (*,G) is present, send from connected source
592 #
593 tx = self._mcast_connected_send_stream("232.1.1.1")
594
595 #
596 # Constrct a representation of the signal we expect on pg0
597 #
Neale Ranns5a8123b2017-01-26 01:18:23 -0800598 signal_232_1_1_1_itf_0 = VppMFibSignal(self,
599 route_232_1_1_1,
600 self.pg0.sw_if_index,
601 tx[0])
Neale Ranns32e1c012016-11-22 17:07:28 +0000602
603 #
604 # read the only expected signal
605 #
606 signals = self.vapi.mfib_signal_dump()
607
608 self.assertEqual(1, len(signals))
609
610 signal_232_1_1_1_itf_0.compare(signals[0])
611
612 #
613 # reading the signal allows for the generation of another
614 # so send more packets and expect the next signal
615 #
616 tx = self._mcast_connected_send_stream("232.1.1.1")
617
618 signals = self.vapi.mfib_signal_dump()
619 self.assertEqual(1, len(signals))
620 signal_232_1_1_1_itf_0.compare(signals[0])
621
622 #
623 # Set the negate-signal on the accepting interval - the signals
624 # should stop
625 #
626 route_232_1_1_1.update_path_flags(
627 self.pg0.sw_if_index,
628 (MRouteItfFlags.MFIB_ITF_FLAG_ACCEPT |
629 MRouteItfFlags.MFIB_ITF_FLAG_NEGATE_SIGNAL))
630
Neale Ranns0f26c5a2017-03-01 15:12:11 -0800631 self.vapi.cli("clear trace")
Neale Ranns32e1c012016-11-22 17:07:28 +0000632 tx = self._mcast_connected_send_stream("232.1.1.1")
633
634 signals = self.vapi.mfib_signal_dump()
635 self.assertEqual(0, len(signals))
636
637 #
638 # Clear the SIGNAL flag on the entry and the signals should
639 # come back since the interface is still NEGATE-SIGNAL
640 #
641 route_232_1_1_1.update_entry_flags(
642 MRouteEntryFlags.MFIB_ENTRY_FLAG_NONE)
643
644 tx = self._mcast_connected_send_stream("232.1.1.1")
645
646 signals = self.vapi.mfib_signal_dump()
647 self.assertEqual(1, len(signals))
648 signal_232_1_1_1_itf_0.compare(signals[0])
649
650 #
651 # Lastly remove the NEGATE-SIGNAL from the interface and the
652 # signals should stop
653 #
654 route_232_1_1_1.update_path_flags(self.pg0.sw_if_index,
655 MRouteItfFlags.MFIB_ITF_FLAG_ACCEPT)
656
657 tx = self._mcast_connected_send_stream("232.1.1.1")
658 signals = self.vapi.mfib_signal_dump()
659 self.assertEqual(0, len(signals))
660
661 #
662 # Cleanup
663 #
664 route_232_1_1_1.remove_vpp_config()
665
666
667if __name__ == '__main__':
668 unittest.main(testRunner=VppTestRunner)