5 from scapy.layers.l2 import Ether, Raw
6 from scapy.layers.inet import IP, IPOption
7 from scapy.contrib.igmpv3 import IGMPv3, IGMPv3gr, IGMPv3mq, IGMPv3mr
9 from framework import VppTestCase, VppTestRunner, running_extended_tests
10 from vpp_igmp import find_igmp_state, IGMP_FILTER, IgmpRecord, IGMP_MODE, \
11 IgmpSG, VppHostState, wait_for_igmp_event
12 from vpp_ip_route import find_mroute, VppIpTable
20 class TestIgmp(VppTestCase):
21 """ IGMP Test Case """
25 super(TestIgmp, cls).setUpClass()
28 def tearDownClass(cls):
29 super(TestIgmp, cls).tearDownClass()
32 super(TestIgmp, self).setUp()
34 self.create_pg_interfaces(range(4))
39 self.ip_table = VppIpTable(self, 1)
40 self.ip_table.add_vpp_config()
42 for pg in self.pg_interfaces[2:]:
44 for pg in self.pg_interfaces:
50 for pg in self.pg_interfaces:
51 self.vapi.igmp_clear_interface(pg.sw_if_index)
55 super(TestIgmp, self).tearDown()
57 def send(self, ti, pkts):
59 self.pg_enable_capture(self.pg_interfaces)
62 def test_igmp_flush(self):
63 """ IGMP Link Up/down and Flush """
66 # FIX THIS. Link down.
69 def test_igmp_enable(self):
70 """ IGMP enable/disable on an interface
72 check for the addition/removal of the IGMP mroutes """
74 self.vapi.igmp_enable_disable(self.pg0.sw_if_index, 1, IGMP_MODE.HOST)
75 self.vapi.igmp_enable_disable(self.pg1.sw_if_index, 1, IGMP_MODE.HOST)
77 self.assertTrue(find_mroute(self, "224.0.0.1", "0.0.0.0", 32))
78 self.assertTrue(find_mroute(self, "224.0.0.22", "0.0.0.0", 32))
80 self.vapi.igmp_enable_disable(self.pg2.sw_if_index, 1, IGMP_MODE.HOST)
81 self.vapi.igmp_enable_disable(self.pg3.sw_if_index, 1, IGMP_MODE.HOST)
83 self.assertTrue(find_mroute(self, "224.0.0.1", "0.0.0.0", 32,
85 self.assertTrue(find_mroute(self, "224.0.0.22", "0.0.0.0", 32,
87 self.vapi.igmp_enable_disable(self.pg0.sw_if_index, 0, IGMP_MODE.HOST)
88 self.vapi.igmp_enable_disable(self.pg1.sw_if_index, 0, IGMP_MODE.HOST)
89 self.vapi.igmp_enable_disable(self.pg2.sw_if_index, 0, IGMP_MODE.HOST)
90 self.vapi.igmp_enable_disable(self.pg3.sw_if_index, 0, IGMP_MODE.HOST)
92 self.assertFalse(find_mroute(self, "224.0.0.1", "0.0.0.0", 32))
93 self.assertFalse(find_mroute(self, "224.0.0.22", "0.0.0.0", 32))
94 self.assertFalse(find_mroute(self, "224.0.0.1", "0.0.0.0", 32,
96 self.assertFalse(find_mroute(self, "224.0.0.22", "0.0.0.0", 32,
99 def verify_general_query(self, p):
101 self.assertEqual(len(ip.options), 1)
102 self.assertEqual(ip.options[0].option, 20)
103 self.assertEqual(ip.dst, "224.0.0.1")
104 self.assertEqual(ip.proto, 2)
106 self.assertEqual(igmp.type, 0x11)
107 self.assertEqual(igmp.gaddr, "0.0.0.0")
109 def verify_group_query(self, p, grp, srcs):
111 self.assertEqual(ip.dst, grp)
112 self.assertEqual(ip.proto, 2)
113 self.assertEqual(len(ip.options), 1)
114 self.assertEqual(ip.options[0].option, 20)
115 self.assertEqual(ip.proto, 2)
117 self.assertEqual(igmp.type, 0x11)
118 self.assertEqual(igmp.gaddr, grp)
120 def verify_report(self, rx, records):
122 self.assertEqual(rx[IP].dst, "224.0.0.22")
123 self.assertEqual(len(ip.options), 1)
124 self.assertEqual(ip.options[0].option, 20)
125 self.assertEqual(ip.proto, 2)
126 self.assertEqual(IGMPv3.igmpv3types[rx[IGMPv3].type],
127 "Version 3 Membership Report")
128 self.assertEqual(rx[IGMPv3mr].numgrp, len(records))
130 received = rx[IGMPv3mr].records
132 for ii in range(len(records)):
135 self.assertEqual(IGMPv3gr.igmpv3grtypes[gr.rtype], r.type)
136 self.assertEqual(gr.numsrc, len(r.sg.saddrs))
137 self.assertEqual(gr.maddr, r.sg.gaddr)
138 self.assertEqual(len(gr.srcaddrs), len(r.sg.saddrs))
140 self.assertEqual(sorted(gr.srcaddrs),
143 def add_group(self, itf, sg, n_pkts=2):
144 self.pg_enable_capture(self.pg_interfaces)
147 hs = VppHostState(self,
153 capture = itf.get_capture(n_pkts, timeout=10)
155 # reports are transmitted twice due to default rebostness value=2
156 self.verify_report(capture[0],
157 [IgmpRecord(sg, "Allow New Sources")]),
158 self.verify_report(capture[1],
159 [IgmpRecord(sg, "Allow New Sources")]),
163 def remove_group(self, hs):
164 self.pg_enable_capture(self.pg_interfaces)
166 hs.remove_vpp_config()
168 capture = self.pg0.get_capture(1, timeout=10)
170 self.verify_report(capture[0],
171 [IgmpRecord(hs.sg, "Block Old Sources")])
173 def test_igmp_host(self):
174 """ IGMP Host functions """
177 # Enable interface for host functions
179 self.vapi.igmp_enable_disable(self.pg0.sw_if_index,
184 # Add one S,G of state and expect a state-change event report
185 # indicating the addition of the S,G
187 h1 = self.add_group(self.pg0, IgmpSG("239.1.1.1", ["1.1.1.1"]))
189 # search for the corresponding state created in VPP
190 dump = self.vapi.igmp_dump(self.pg0.sw_if_index)
191 self.assertEqual(len(dump), 1)
192 self.assertTrue(find_igmp_state(dump, self.pg0,
193 "239.1.1.1", "1.1.1.1"))
196 # Send a general query (to the all router's address)
197 # expect VPP to respond with a membership report.
198 # Pad the query with 0 - some devices in the big wild
199 # internet are prone to this.
201 p_g = (Ether(dst=self.pg0.local_mac, src=self.pg0.remote_mac) /
202 IP(src=self.pg0.remote_ip4, dst='224.0.0.1', tos=0xc0) /
203 IGMPv3(type="Membership Query", mrcode=100) /
204 IGMPv3mq(gaddr="0.0.0.0") /
207 self.send(self.pg0, p_g)
209 capture = self.pg0.get_capture(1, timeout=10)
210 self.verify_report(capture[0],
211 [IgmpRecord(h1.sg, "Mode Is Include")])
214 # Group specific query
216 p_gs = (Ether(dst=self.pg0.local_mac, src=self.pg0.remote_mac) /
217 IP(src=self.pg0.remote_ip4, dst='239.1.1.1', tos=0xc0,
218 options=[IPOption(copy_flag=1, optclass="control",
219 option="router_alert")]) /
220 IGMPv3(type="Membership Query", mrcode=100) /
221 IGMPv3mq(gaddr="239.1.1.1"))
223 self.send(self.pg0, p_gs)
225 capture = self.pg0.get_capture(1, timeout=10)
226 self.verify_report(capture[0],
227 [IgmpRecord(h1.sg, "Mode Is Include")])
230 # A group and source specific query, with the source matching
233 p_gs1 = (Ether(dst=self.pg0.local_mac, src=self.pg0.remote_mac) /
234 IP(src=self.pg0.remote_ip4, dst='239.1.1.1', tos=0xc0,
235 options=[IPOption(copy_flag=1, optclass="control",
236 option="router_alert")]) /
237 IGMPv3(type="Membership Query", mrcode=100) /
238 IGMPv3mq(gaddr="239.1.1.1", srcaddrs=["1.1.1.1"]))
240 self.send(self.pg0, p_gs1)
242 capture = self.pg0.get_capture(1, timeout=10)
243 self.verify_report(capture[0],
244 [IgmpRecord(h1.sg, "Mode Is Include")])
247 # A group and source specific query that reports more sources
248 # than the packet actually has.
250 p_gs2 = (Ether(dst=self.pg0.local_mac, src=self.pg0.remote_mac) /
251 IP(src=self.pg0.remote_ip4, dst='239.1.1.1', tos=0xc0,
252 options=[IPOption(copy_flag=1, optclass="control",
253 option="router_alert")]) /
254 IGMPv3(type="Membership Query", mrcode=100) /
255 IGMPv3mq(gaddr="239.1.1.1", numsrc=4, srcaddrs=["1.1.1.1"]))
257 self.send_and_assert_no_replies(self.pg0, p_gs2, timeout=10)
260 # A group and source specific query, with the source NOT matching
261 # the source VPP has. There should be no response.
263 p_gs2 = (Ether(dst=self.pg0.local_mac, src=self.pg0.remote_mac) /
264 IP(src=self.pg0.remote_ip4, dst='239.1.1.1', tos=0xc0,
265 options=[IPOption(copy_flag=1, optclass="control",
266 option="router_alert")]) /
267 IGMPv3(type="Membership Query", mrcode=100) /
268 IGMPv3mq(gaddr="239.1.1.1", srcaddrs=["1.1.1.2"]))
270 self.send_and_assert_no_replies(self.pg0, p_gs2, timeout=10)
273 # A group and source specific query, with the multiple sources
274 # one of which matches the source VPP has.
275 # The report should contain only the source VPP has.
277 p_gs3 = (Ether(dst=self.pg0.local_mac, src=self.pg0.remote_mac) /
278 IP(src=self.pg0.remote_ip4, dst='239.1.1.1', tos=0xc0,
279 options=[IPOption(copy_flag=1, optclass="control",
280 option="router_alert")]) /
281 IGMPv3(type="Membership Query", mrcode=100) /
282 IGMPv3mq(gaddr="239.1.1.1",
283 srcaddrs=["1.1.1.1", "1.1.1.2", "1.1.1.3"]))
285 self.send(self.pg0, p_gs3)
287 capture = self.pg0.get_capture(1, timeout=10)
288 self.verify_report(capture[0],
289 [IgmpRecord(h1.sg, "Mode Is Include")])
292 # Two source and group specific queries in quick succession, the
293 # first does not have VPPs source the second does. then vice-versa
295 self.send(self.pg0, [p_gs2, p_gs1])
296 capture = self.pg0.get_capture(1, timeout=10)
297 self.verify_report(capture[0],
298 [IgmpRecord(h1.sg, "Mode Is Include")])
300 self.send(self.pg0, [p_gs1, p_gs2])
301 capture = self.pg0.get_capture(1, timeout=10)
302 self.verify_report(capture[0],
303 [IgmpRecord(h1.sg, "Mode Is Include")])
306 # remove state, expect the report for the removal
308 self.remove_group(h1)
310 dump = self.vapi.igmp_dump()
311 self.assertFalse(dump)
314 # A group with multiple sources
316 h2 = self.add_group(self.pg0,
318 ["1.1.1.1", "1.1.1.2", "1.1.1.3"]))
320 # search for the corresponding state created in VPP
321 dump = self.vapi.igmp_dump(self.pg0.sw_if_index)
322 self.assertEqual(len(dump), 3)
323 for s in h2.sg.saddrs:
324 self.assertTrue(find_igmp_state(dump, self.pg0,
327 # Send a general query (to the all router's address)
328 # expect VPP to respond with a membership report will all sources
330 self.send(self.pg0, p_g)
332 capture = self.pg0.get_capture(1, timeout=10)
333 self.verify_report(capture[0],
334 [IgmpRecord(h2.sg, "Mode Is Include")])
337 # Group and source specific query; some present some not
339 p_gs = (Ether(dst=self.pg0.local_mac, src=self.pg0.remote_mac) /
340 IP(src=self.pg0.remote_ip4, dst='239.1.1.1', tos=0xc0,
341 options=[IPOption(copy_flag=1, optclass="control",
342 option="router_alert")]) /
343 IGMPv3(type="Membership Query", mrcode=100) /
344 IGMPv3mq(gaddr="239.1.1.1",
345 srcaddrs=["1.1.1.1", "1.1.1.2", "1.1.1.4"]))
347 self.send(self.pg0, p_gs)
349 capture = self.pg0.get_capture(1, timeout=10)
350 self.verify_report(capture[0],
352 IgmpSG('239.1.1.1', ["1.1.1.1", "1.1.1.2"]),
356 # add loads more groups
358 h3 = self.add_group(self.pg0,
360 ["2.1.1.1", "2.1.1.2", "2.1.1.3"]))
361 h4 = self.add_group(self.pg0,
363 ["3.1.1.1", "3.1.1.2", "3.1.1.3"]))
364 h5 = self.add_group(self.pg0,
366 ["4.1.1.1", "4.1.1.2", "4.1.1.3"]))
367 h6 = self.add_group(self.pg0,
369 ["5.1.1.1", "5.1.1.2", "5.1.1.3"]))
370 h7 = self.add_group(self.pg0,
372 ["6.1.1.1", "6.1.1.2",
373 "6.1.1.3", "6.1.1.4",
374 "6.1.1.5", "6.1.1.6",
375 "6.1.1.7", "6.1.1.8",
376 "6.1.1.9", "6.1.1.10",
377 "6.1.1.11", "6.1.1.12",
378 "6.1.1.13", "6.1.1.14",
379 "6.1.1.15", "6.1.1.16"]))
383 # the order the groups come in is not important, so what is
384 # checked for is what VPP is sending today.
386 self.send(self.pg0, p_g)
388 capture = self.pg0.get_capture(1, timeout=10)
390 self.verify_report(capture[0],
391 [IgmpRecord(h3.sg, "Mode Is Include"),
392 IgmpRecord(h2.sg, "Mode Is Include"),
393 IgmpRecord(h6.sg, "Mode Is Include"),
394 IgmpRecord(h4.sg, "Mode Is Include"),
395 IgmpRecord(h5.sg, "Mode Is Include"),
396 IgmpRecord(h7.sg, "Mode Is Include")])
399 # modify a group to add and remove some sources
401 h7.sg = IgmpSG("239.1.1.6",
402 ["6.1.1.1", "6.1.1.2",
403 "6.1.1.5", "6.1.1.6",
404 "6.1.1.7", "6.1.1.8",
405 "6.1.1.9", "6.1.1.10",
406 "6.1.1.11", "6.1.1.12",
407 "6.1.1.13", "6.1.1.14",
408 "6.1.1.15", "6.1.1.16",
409 "6.1.1.17", "6.1.1.18"])
411 self.pg_enable_capture(self.pg_interfaces)
415 capture = self.pg0.get_capture(1, timeout=10)
416 self.verify_report(capture[0],
417 [IgmpRecord(IgmpSG("239.1.1.6",
418 ["6.1.1.17", "6.1.1.18"]),
419 "Allow New Sources"),
420 IgmpRecord(IgmpSG("239.1.1.6",
421 ["6.1.1.3", "6.1.1.4"]),
422 "Block Old Sources")])
425 # add an additional groups with many sources so that each group
426 # consumes the link MTU. We should therefore see multiple state
427 # state reports when queried.
429 self.vapi.sw_interface_set_mtu(self.pg0.sw_if_index, [560, 0, 0, 0])
433 src_list.append("10.1.1.%d" % i)
435 h8 = self.add_group(self.pg0,
436 IgmpSG("238.1.1.1", src_list))
437 h9 = self.add_group(self.pg0,
438 IgmpSG("238.1.1.2", src_list))
440 self.send(self.pg0, p_g)
442 capture = self.pg0.get_capture(4, timeout=10)
444 self.verify_report(capture[0],
445 [IgmpRecord(h3.sg, "Mode Is Include"),
446 IgmpRecord(h2.sg, "Mode Is Include"),
447 IgmpRecord(h6.sg, "Mode Is Include"),
448 IgmpRecord(h4.sg, "Mode Is Include"),
449 IgmpRecord(h5.sg, "Mode Is Include")])
450 self.verify_report(capture[1],
451 [IgmpRecord(h8.sg, "Mode Is Include")])
452 self.verify_report(capture[2],
453 [IgmpRecord(h7.sg, "Mode Is Include")])
454 self.verify_report(capture[3],
455 [IgmpRecord(h9.sg, "Mode Is Include")])
458 # drop the MTU further (so a 128 sized group won't fit)
460 self.vapi.sw_interface_set_mtu(self.pg0.sw_if_index, [512, 0, 0, 0])
462 self.pg_enable_capture(self.pg_interfaces)
465 h10 = VppHostState(self,
467 self.pg0.sw_if_index,
468 IgmpSG("238.1.1.3", src_list))
471 capture = self.pg0.get_capture(2, timeout=10)
474 # remove state, expect the report for the removal
475 # the dump should be empty
477 self.vapi.sw_interface_set_mtu(self.pg0.sw_if_index, [600, 0, 0, 0])
478 self.remove_group(h8)
479 self.remove_group(h9)
480 self.remove_group(h2)
481 self.remove_group(h3)
482 self.remove_group(h4)
483 self.remove_group(h5)
484 self.remove_group(h6)
485 self.remove_group(h7)
486 self.remove_group(h10)
488 self.logger.info(self.vapi.cli("sh igmp config"))
489 self.assertFalse(self.vapi.igmp_dump())
493 # ADD STATE ON MORE INTERFACES
496 self.vapi.igmp_enable_disable(self.pg0.sw_if_index,
500 def test_igmp_router(self):
501 """ IGMP Router Functions """
504 # Drop reports when not enabled
506 p_j = (Ether(dst=self.pg0.local_mac, src=self.pg0.remote_mac) /
507 IP(src=self.pg0.remote_ip4, dst="224.0.0.22", tos=0xc0, ttl=1,
508 options=[IPOption(copy_flag=1, optclass="control",
509 option="router_alert")]) /
510 IGMPv3(type="Version 3 Membership Report") /
512 IGMPv3gr(rtype="Allow New Sources",
513 maddr="239.1.1.1", srcaddrs=["10.1.1.1", "10.1.1.2"]))
514 p_l = (Ether(dst=self.pg0.local_mac, src=self.pg0.remote_mac) /
515 IP(src=self.pg0.remote_ip4, dst="224.0.0.22", tos=0xc0,
516 options=[IPOption(copy_flag=1, optclass="control",
517 option="router_alert")]) /
518 IGMPv3(type="Version 3 Membership Report") /
520 IGMPv3gr(rtype="Block Old Sources",
521 maddr="239.1.1.1", srcaddrs=["10.1.1.1", "10.1.1.2"]))
523 self.send(self.pg0, p_j)
524 self.assertFalse(self.vapi.igmp_dump())
527 # drop the default timer values so these tests execute in a
528 # reasonable time frame
530 self.vapi.cli("test igmp timers query 1 src 3 leave 1")
533 # enable router functions on the interface
535 self.pg_enable_capture(self.pg_interfaces)
537 self.vapi.igmp_enable_disable(self.pg0.sw_if_index,
540 self.vapi.want_igmp_events(1)
543 # wait for router to send general query
546 capture = self.pg0.get_capture(1, timeout=2)
547 self.verify_general_query(capture[0])
548 self.pg_enable_capture(self.pg_interfaces)
552 # re-send the report. VPP should now hold state for the new group
553 # VPP sends a notification that a new group has been joined
555 self.send(self.pg0, p_j)
557 self.assertTrue(wait_for_igmp_event(self, 1, self.pg0,
558 "239.1.1.1", "10.1.1.1", 1))
559 self.assertTrue(wait_for_igmp_event(self, 1, self.pg0,
560 "239.1.1.1", "10.1.1.2", 1))
561 dump = self.vapi.igmp_dump(self.pg0.sw_if_index)
562 self.assertEqual(len(dump), 2)
563 self.assertTrue(find_igmp_state(dump, self.pg0,
564 "239.1.1.1", "10.1.1.1"))
565 self.assertTrue(find_igmp_state(dump, self.pg0,
566 "239.1.1.1", "10.1.1.2"))
569 # wait for the per-source timer to expire
570 # the state should be reaped
571 # VPP sends a notification that the group has been left
573 self.assertTrue(wait_for_igmp_event(self, 4, self.pg0,
574 "239.1.1.1", "10.1.1.1", 0))
575 self.assertTrue(wait_for_igmp_event(self, 1, self.pg0,
576 "239.1.1.1", "10.1.1.2", 0))
577 self.assertFalse(self.vapi.igmp_dump())
580 # resend the join. wait for two queries and then send a current-state
581 # record to include all sources. this should reset the expiry time
582 # on the sources and thus they will still be present in 2 seconds time.
583 # If the source timer was not refreshed, then the state would have
584 # expired in 3 seconds.
586 self.send(self.pg0, p_j)
587 self.assertTrue(wait_for_igmp_event(self, 1, self.pg0,
588 "239.1.1.1", "10.1.1.1", 1))
589 self.assertTrue(wait_for_igmp_event(self, 1, self.pg0,
590 "239.1.1.1", "10.1.1.2", 1))
591 dump = self.vapi.igmp_dump(self.pg0.sw_if_index)
592 self.assertEqual(len(dump), 2)
594 capture = self.pg0.get_capture(2, timeout=3)
595 self.verify_general_query(capture[0])
596 self.verify_general_query(capture[1])
598 p_cs = (Ether(dst=self.pg0.local_mac, src=self.pg0.remote_mac) /
599 IP(src=self.pg0.remote_ip4, dst="224.0.0.22", tos=0xc0,
600 options=[IPOption(copy_flag=1, optclass="control",
601 option="router_alert")]) /
602 IGMPv3(type="Version 3 Membership Report") /
604 IGMPv3gr(rtype="Mode Is Include",
605 maddr="239.1.1.1", srcaddrs=["10.1.1.1", "10.1.1.2"]))
607 self.send(self.pg0, p_cs)
610 dump = self.vapi.igmp_dump(self.pg0.sw_if_index)
611 self.assertEqual(len(dump), 2)
612 self.assertTrue(find_igmp_state(dump, self.pg0,
613 "239.1.1.1", "10.1.1.1"))
614 self.assertTrue(find_igmp_state(dump, self.pg0,
615 "239.1.1.1", "10.1.1.2"))
618 # wait for the per-source timer to expire
619 # the state should be reaped
621 self.assertTrue(wait_for_igmp_event(self, 4, self.pg0,
622 "239.1.1.1", "10.1.1.1", 0))
623 self.assertTrue(wait_for_igmp_event(self, 1, self.pg0,
624 "239.1.1.1", "10.1.1.2", 0))
625 self.assertFalse(self.vapi.igmp_dump())
628 # resend the join, then a leave. Router sends a group+source
629 # specific query containing both sources
631 self.send(self.pg0, p_j)
633 self.assertTrue(wait_for_igmp_event(self, 1, self.pg0,
634 "239.1.1.1", "10.1.1.1", 1))
635 self.assertTrue(wait_for_igmp_event(self, 1, self.pg0,
636 "239.1.1.1", "10.1.1.2", 1))
637 dump = self.vapi.igmp_dump(self.pg0.sw_if_index)
638 self.assertEqual(len(dump), 2)
640 self.send(self.pg0, p_l)
641 capture = self.pg0.get_capture(1, timeout=3)
642 self.verify_group_query(capture[0], "239.1.1.1",
643 ["10.1.1.1", "10.1.1.2"])
646 # the group specific query drops the timeout to leave (=1) seconds
648 self.assertTrue(wait_for_igmp_event(self, 2, self.pg0,
649 "239.1.1.1", "10.1.1.1", 0))
650 self.assertTrue(wait_for_igmp_event(self, 1, self.pg0,
651 "239.1.1.1", "10.1.1.2", 0))
652 self.assertFalse(self.vapi.igmp_dump())
653 self.assertFalse(self.vapi.igmp_dump())
656 # a TO_EX({}) / IN_EX({}) is treated like a (*,G) join
658 p_j = (Ether(dst=self.pg0.local_mac, src=self.pg0.remote_mac) /
659 IP(src=self.pg0.remote_ip4, dst="224.0.0.22", tos=0xc0, ttl=1,
660 options=[IPOption(copy_flag=1, optclass="control",
661 option="router_alert")]) /
662 IGMPv3(type="Version 3 Membership Report") /
664 IGMPv3gr(rtype="Change To Exclude Mode", maddr="239.1.1.2"))
666 self.send(self.pg0, p_j)
668 self.assertTrue(wait_for_igmp_event(self, 1, self.pg0,
669 "239.1.1.2", "0.0.0.0", 1))
671 p_j = (Ether(dst=self.pg0.local_mac, src=self.pg0.remote_mac) /
672 IP(src=self.pg0.remote_ip4, dst="224.0.0.22", tos=0xc0, ttl=1,
673 options=[IPOption(copy_flag=1, optclass="control",
674 option="router_alert")]) /
675 IGMPv3(type="Version 3 Membership Report") /
677 IGMPv3gr(rtype="Mode Is Exclude", maddr="239.1.1.3"))
679 self.send(self.pg0, p_j)
681 self.assertTrue(wait_for_igmp_event(self, 1, self.pg0,
682 "239.1.1.3", "0.0.0.0", 1))
685 # A 'allow sources' for {} should be ignored as it should
688 p_j = (Ether(dst=self.pg0.local_mac, src=self.pg0.remote_mac) /
689 IP(src=self.pg0.remote_ip4, dst="224.0.0.22", tos=0xc0, ttl=1,
690 options=[IPOption(copy_flag=1, optclass="control",
691 option="router_alert")]) /
692 IGMPv3(type="Version 3 Membership Report") /
694 IGMPv3gr(rtype="Allow New Sources", maddr="239.1.1.4"))
696 self.send(self.pg0, p_j)
698 dump = self.vapi.igmp_dump(self.pg0.sw_if_index)
699 self.assertTrue(find_igmp_state(dump, self.pg0,
700 "239.1.1.2", "0.0.0.0"))
701 self.assertTrue(find_igmp_state(dump, self.pg0,
702 "239.1.1.3", "0.0.0.0"))
703 self.assertFalse(find_igmp_state(dump, self.pg0,
704 "239.1.1.4", "0.0.0.0"))
707 # a TO_IN({}) and IS_IN({}) are treated like a (*,G) leave
709 self.vapi.cli("set logging class igmp level debug")
710 p_l = (Ether(dst=self.pg0.local_mac, src=self.pg0.remote_mac) /
711 IP(src=self.pg0.remote_ip4, dst="224.0.0.22", tos=0xc0, ttl=1,
712 options=[IPOption(copy_flag=1, optclass="control",
713 option="router_alert")]) /
714 IGMPv3(type="Version 3 Membership Report") /
716 IGMPv3gr(rtype="Change To Include Mode", maddr="239.1.1.2"))
718 self.send(self.pg0, p_l)
719 self.assertTrue(wait_for_igmp_event(self, 2, self.pg0,
720 "239.1.1.2", "0.0.0.0", 0))
722 p_l = (Ether(dst=self.pg0.local_mac, src=self.pg0.remote_mac) /
723 IP(src=self.pg0.remote_ip4, dst="224.0.0.22", tos=0xc0, ttl=1,
724 options=[IPOption(copy_flag=1, optclass="control",
725 option="router_alert")]) /
726 IGMPv3(type="Version 3 Membership Report") /
728 IGMPv3gr(rtype="Mode Is Include", maddr="239.1.1.3"))
730 self.send(self.pg0, p_l)
732 self.assertTrue(wait_for_igmp_event(self, 2, self.pg0,
733 "239.1.1.3", "0.0.0.0", 0))
734 self.assertFalse(self.vapi.igmp_dump(self.pg0.sw_if_index))
737 # disable router config
739 self.vapi.igmp_enable_disable(self.pg0.sw_if_index,
743 def _create_igmpv3_pck(self, itf, rtype, maddr, srcaddrs):
744 p = (Ether(dst=itf.local_mac, src=itf.remote_mac) /
745 IP(src=itf.remote_ip4, dst="224.0.0.22", tos=0xc0, ttl=1,
746 options=[IPOption(copy_flag=1, optclass="control",
747 option="router_alert")]) /
748 IGMPv3(type="Version 3 Membership Report") /
750 IGMPv3gr(rtype=rtype,
751 maddr=maddr, srcaddrs=srcaddrs))
754 def test_igmp_proxy_device(self):
755 """ IGMP proxy device """
756 self.pg2.admin_down()
757 self.pg2.unconfig_ip4()
758 self.pg2.set_table_ip4(0)
759 self.pg2.config_ip4()
762 self.vapi.cli('test igmp timers query 10 src 3 leave 1')
765 self.vapi.igmp_enable_disable(self.pg0.sw_if_index, 1, IGMP_MODE.HOST)
766 self.vapi.igmp_enable_disable(self.pg1.sw_if_index, 1,
768 self.vapi.igmp_enable_disable(self.pg2.sw_if_index, 1,
771 # create IGMP proxy device
772 self.vapi.igmp_proxy_device_add_del(0, self.pg0.sw_if_index, 1)
773 self.vapi.igmp_proxy_device_add_del_interface(0,
774 self.pg1.sw_if_index, 1)
775 self.vapi.igmp_proxy_device_add_del_interface(0,
776 self.pg2.sw_if_index, 1)
778 # send join on pg1. join should be proxied by pg0
779 p_j = self._create_igmpv3_pck(self.pg1, "Allow New Sources",
780 "239.1.1.1", ["10.1.1.1", "10.1.1.2"])
781 self.send(self.pg1, p_j)
783 capture = self.pg0.get_capture(1, timeout=1)
784 self.verify_report(capture[0], [IgmpRecord(IgmpSG("239.1.1.1",
785 ["10.1.1.1", "10.1.1.2"]), "Allow New Sources")])
786 self.assertTrue(find_mroute(self, "239.1.1.1", "0.0.0.0", 32))
788 # send join on pg2. join should be proxied by pg0.
789 # the group should contain only 10.1.1.3 as
790 # 10.1.1.1 was already reported
791 p_j = self._create_igmpv3_pck(self.pg2, "Allow New Sources",
792 "239.1.1.1", ["10.1.1.1", "10.1.1.3"])
793 self.send(self.pg2, p_j)
795 capture = self.pg0.get_capture(1, timeout=1)
796 self.verify_report(capture[0], [IgmpRecord(IgmpSG("239.1.1.1",
797 ["10.1.1.3"]), "Allow New Sources")])
798 self.assertTrue(find_mroute(self, "239.1.1.1", "0.0.0.0", 32))
800 # send leave on pg2. leave for 10.1.1.3 should be proxyed
801 # as pg2 was the only interface interested in 10.1.1.3
802 p_l = self._create_igmpv3_pck(self.pg2, "Block Old Sources",
803 "239.1.1.1", ["10.1.1.3"])
804 self.send(self.pg2, p_l)
806 capture = self.pg0.get_capture(1, timeout=2)
807 self.verify_report(capture[0], [IgmpRecord(IgmpSG("239.1.1.1",
808 ["10.1.1.3"]), "Block Old Sources")])
809 self.assertTrue(find_mroute(self, "239.1.1.1", "0.0.0.0", 32))
811 # disable igmp on pg1 (also removes interface from proxy device)
812 # proxy leave for 10.1.1.2. pg2 is still interested in 10.1.1.1
813 self.pg_enable_capture(self.pg_interfaces)
814 self.vapi.igmp_enable_disable(self.pg1.sw_if_index, 0,
817 capture = self.pg0.get_capture(1, timeout=1)
818 self.verify_report(capture[0], [IgmpRecord(IgmpSG("239.1.1.1",
819 ["10.1.1.2"]), "Block Old Sources")])
820 self.assertTrue(find_mroute(self, "239.1.1.1", "0.0.0.0", 32))
822 # disable IGMP on pg0 and pg1.
823 # disabling IGMP on pg0 (proxy device upstream interface)
824 # removes this proxy device
825 self.vapi.igmp_enable_disable(self.pg0.sw_if_index, 0, IGMP_MODE.HOST)
826 self.vapi.igmp_enable_disable(self.pg2.sw_if_index, 0,
828 self.assertFalse(find_mroute(self, "239.1.1.1", "0.0.0.0", 32))
831 if __name__ == '__main__':
832 unittest.main(testRunner=VppTestRunner)