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)
472 # wait for a little bit
476 # remove state, expect the report for the removal
477 # the dump should be empty
479 self.vapi.sw_interface_set_mtu(self.pg0.sw_if_index, [600, 0, 0, 0])
480 self.remove_group(h8)
481 self.remove_group(h9)
482 self.remove_group(h2)
483 self.remove_group(h3)
484 self.remove_group(h4)
485 self.remove_group(h5)
486 self.remove_group(h6)
487 self.remove_group(h7)
488 self.remove_group(h10)
490 self.logger.info(self.vapi.cli("sh igmp config"))
491 self.assertFalse(self.vapi.igmp_dump())
495 # ADD STATE ON MORE INTERFACES
498 self.vapi.igmp_enable_disable(self.pg0.sw_if_index,
502 def test_igmp_router(self):
503 """ IGMP Router Functions """
506 # Drop reports when not enabled
508 p_j = (Ether(dst=self.pg0.local_mac, src=self.pg0.remote_mac) /
509 IP(src=self.pg0.remote_ip4, dst="224.0.0.22", tos=0xc0, ttl=1,
510 options=[IPOption(copy_flag=1, optclass="control",
511 option="router_alert")]) /
512 IGMPv3(type="Version 3 Membership Report") /
514 IGMPv3gr(rtype="Allow New Sources",
515 maddr="239.1.1.1", srcaddrs=["10.1.1.1", "10.1.1.2"]))
516 p_l = (Ether(dst=self.pg0.local_mac, src=self.pg0.remote_mac) /
517 IP(src=self.pg0.remote_ip4, dst="224.0.0.22", tos=0xc0,
518 options=[IPOption(copy_flag=1, optclass="control",
519 option="router_alert")]) /
520 IGMPv3(type="Version 3 Membership Report") /
522 IGMPv3gr(rtype="Block Old Sources",
523 maddr="239.1.1.1", srcaddrs=["10.1.1.1", "10.1.1.2"]))
525 self.send(self.pg0, p_j)
526 self.assertFalse(self.vapi.igmp_dump())
529 # drop the default timer values so these tests execute in a
530 # reasonable time frame
532 self.vapi.cli("test igmp timers query 1 src 3 leave 1")
535 # enable router functions on the interface
537 self.pg_enable_capture(self.pg_interfaces)
539 self.vapi.igmp_enable_disable(self.pg0.sw_if_index,
542 self.vapi.want_igmp_events(1)
545 # wait for router to send general query
548 capture = self.pg0.get_capture(1, timeout=2)
549 self.verify_general_query(capture[0])
550 self.pg_enable_capture(self.pg_interfaces)
554 # re-send the report. VPP should now hold state for the new group
555 # VPP sends a notification that a new group has been joined
557 self.send(self.pg0, p_j)
559 self.assertTrue(wait_for_igmp_event(self, 1, self.pg0,
560 "239.1.1.1", "10.1.1.1", 1))
561 self.assertTrue(wait_for_igmp_event(self, 1, self.pg0,
562 "239.1.1.1", "10.1.1.2", 1))
563 dump = self.vapi.igmp_dump(self.pg0.sw_if_index)
564 self.assertEqual(len(dump), 2)
565 self.assertTrue(find_igmp_state(dump, self.pg0,
566 "239.1.1.1", "10.1.1.1"))
567 self.assertTrue(find_igmp_state(dump, self.pg0,
568 "239.1.1.1", "10.1.1.2"))
571 # wait for the per-source timer to expire
572 # the state should be reaped
573 # VPP sends a notification that the group has been left
575 self.assertTrue(wait_for_igmp_event(self, 4, self.pg0,
576 "239.1.1.1", "10.1.1.1", 0))
577 self.assertTrue(wait_for_igmp_event(self, 1, self.pg0,
578 "239.1.1.1", "10.1.1.2", 0))
579 self.assertFalse(self.vapi.igmp_dump())
582 # resend the join. wait for two queries and then send a current-state
583 # record to include all sources. this should reset the expiry time
584 # on the sources and thus they will still be present in 2 seconds time.
585 # If the source timer was not refreshed, then the state would have
586 # expired in 3 seconds.
588 self.send(self.pg0, p_j)
589 self.assertTrue(wait_for_igmp_event(self, 1, self.pg0,
590 "239.1.1.1", "10.1.1.1", 1))
591 self.assertTrue(wait_for_igmp_event(self, 1, self.pg0,
592 "239.1.1.1", "10.1.1.2", 1))
593 dump = self.vapi.igmp_dump(self.pg0.sw_if_index)
594 self.assertEqual(len(dump), 2)
596 capture = self.pg0.get_capture(2, timeout=3)
597 self.verify_general_query(capture[0])
598 self.verify_general_query(capture[1])
600 p_cs = (Ether(dst=self.pg0.local_mac, src=self.pg0.remote_mac) /
601 IP(src=self.pg0.remote_ip4, dst="224.0.0.22", tos=0xc0,
602 options=[IPOption(copy_flag=1, optclass="control",
603 option="router_alert")]) /
604 IGMPv3(type="Version 3 Membership Report") /
606 IGMPv3gr(rtype="Mode Is Include",
607 maddr="239.1.1.1", srcaddrs=["10.1.1.1", "10.1.1.2"]))
609 self.send(self.pg0, p_cs)
612 dump = self.vapi.igmp_dump(self.pg0.sw_if_index)
613 self.assertEqual(len(dump), 2)
614 self.assertTrue(find_igmp_state(dump, self.pg0,
615 "239.1.1.1", "10.1.1.1"))
616 self.assertTrue(find_igmp_state(dump, self.pg0,
617 "239.1.1.1", "10.1.1.2"))
620 # wait for the per-source timer to expire
621 # the state should be reaped
623 self.assertTrue(wait_for_igmp_event(self, 4, self.pg0,
624 "239.1.1.1", "10.1.1.1", 0))
625 self.assertTrue(wait_for_igmp_event(self, 1, self.pg0,
626 "239.1.1.1", "10.1.1.2", 0))
627 self.assertFalse(self.vapi.igmp_dump())
630 # resend the join, then a leave. Router sends a group+source
631 # specific query containing both sources
633 self.send(self.pg0, p_j)
635 self.assertTrue(wait_for_igmp_event(self, 1, self.pg0,
636 "239.1.1.1", "10.1.1.1", 1))
637 self.assertTrue(wait_for_igmp_event(self, 1, self.pg0,
638 "239.1.1.1", "10.1.1.2", 1))
639 dump = self.vapi.igmp_dump(self.pg0.sw_if_index)
640 self.assertEqual(len(dump), 2)
642 self.send(self.pg0, p_l)
643 capture = self.pg0.get_capture(1, timeout=3)
644 self.verify_group_query(capture[0], "239.1.1.1",
645 ["10.1.1.1", "10.1.1.2"])
648 # the group specific query drops the timeout to leave (=1) seconds
650 self.assertTrue(wait_for_igmp_event(self, 2, self.pg0,
651 "239.1.1.1", "10.1.1.1", 0))
652 self.assertTrue(wait_for_igmp_event(self, 1, self.pg0,
653 "239.1.1.1", "10.1.1.2", 0))
654 self.assertFalse(self.vapi.igmp_dump())
655 self.assertFalse(self.vapi.igmp_dump())
658 # a TO_EX({}) / IN_EX({}) is treated like a (*,G) join
660 p_j = (Ether(dst=self.pg0.local_mac, src=self.pg0.remote_mac) /
661 IP(src=self.pg0.remote_ip4, dst="224.0.0.22", tos=0xc0, ttl=1,
662 options=[IPOption(copy_flag=1, optclass="control",
663 option="router_alert")]) /
664 IGMPv3(type="Version 3 Membership Report") /
666 IGMPv3gr(rtype="Change To Exclude Mode", maddr="239.1.1.2"))
668 self.send(self.pg0, p_j)
670 self.assertTrue(wait_for_igmp_event(self, 1, self.pg0,
671 "239.1.1.2", "0.0.0.0", 1))
673 p_j = (Ether(dst=self.pg0.local_mac, src=self.pg0.remote_mac) /
674 IP(src=self.pg0.remote_ip4, dst="224.0.0.22", tos=0xc0, ttl=1,
675 options=[IPOption(copy_flag=1, optclass="control",
676 option="router_alert")]) /
677 IGMPv3(type="Version 3 Membership Report") /
679 IGMPv3gr(rtype="Mode Is Exclude", maddr="239.1.1.3"))
681 self.send(self.pg0, p_j)
683 self.assertTrue(wait_for_igmp_event(self, 1, self.pg0,
684 "239.1.1.3", "0.0.0.0", 1))
687 # A 'allow sources' for {} should be ignored as it should
690 p_j = (Ether(dst=self.pg0.local_mac, src=self.pg0.remote_mac) /
691 IP(src=self.pg0.remote_ip4, dst="224.0.0.22", tos=0xc0, ttl=1,
692 options=[IPOption(copy_flag=1, optclass="control",
693 option="router_alert")]) /
694 IGMPv3(type="Version 3 Membership Report") /
696 IGMPv3gr(rtype="Allow New Sources", maddr="239.1.1.4"))
698 self.send(self.pg0, p_j)
700 dump = self.vapi.igmp_dump(self.pg0.sw_if_index)
701 self.assertTrue(find_igmp_state(dump, self.pg0,
702 "239.1.1.2", "0.0.0.0"))
703 self.assertTrue(find_igmp_state(dump, self.pg0,
704 "239.1.1.3", "0.0.0.0"))
705 self.assertFalse(find_igmp_state(dump, self.pg0,
706 "239.1.1.4", "0.0.0.0"))
709 # a TO_IN({}) and IS_IN({}) are treated like a (*,G) leave
711 self.vapi.cli("set logging class igmp level debug")
712 p_l = (Ether(dst=self.pg0.local_mac, src=self.pg0.remote_mac) /
713 IP(src=self.pg0.remote_ip4, dst="224.0.0.22", tos=0xc0, ttl=1,
714 options=[IPOption(copy_flag=1, optclass="control",
715 option="router_alert")]) /
716 IGMPv3(type="Version 3 Membership Report") /
718 IGMPv3gr(rtype="Change To Include Mode", maddr="239.1.1.2"))
720 self.send(self.pg0, p_l)
721 self.assertTrue(wait_for_igmp_event(self, 2, self.pg0,
722 "239.1.1.2", "0.0.0.0", 0))
724 p_l = (Ether(dst=self.pg0.local_mac, src=self.pg0.remote_mac) /
725 IP(src=self.pg0.remote_ip4, dst="224.0.0.22", tos=0xc0, ttl=1,
726 options=[IPOption(copy_flag=1, optclass="control",
727 option="router_alert")]) /
728 IGMPv3(type="Version 3 Membership Report") /
730 IGMPv3gr(rtype="Mode Is Include", maddr="239.1.1.3"))
732 self.send(self.pg0, p_l)
734 self.assertTrue(wait_for_igmp_event(self, 2, self.pg0,
735 "239.1.1.3", "0.0.0.0", 0))
736 self.assertFalse(self.vapi.igmp_dump(self.pg0.sw_if_index))
739 # disable router config
741 self.vapi.igmp_enable_disable(self.pg0.sw_if_index,
745 def _create_igmpv3_pck(self, itf, rtype, maddr, srcaddrs):
746 p = (Ether(dst=itf.local_mac, src=itf.remote_mac) /
747 IP(src=itf.remote_ip4, dst="224.0.0.22", tos=0xc0, ttl=1,
748 options=[IPOption(copy_flag=1, optclass="control",
749 option="router_alert")]) /
750 IGMPv3(type="Version 3 Membership Report") /
752 IGMPv3gr(rtype=rtype,
753 maddr=maddr, srcaddrs=srcaddrs))
756 def test_igmp_proxy_device(self):
757 """ IGMP proxy device """
758 self.pg2.admin_down()
759 self.pg2.unconfig_ip4()
760 self.pg2.set_table_ip4(0)
761 self.pg2.config_ip4()
764 self.vapi.cli('test igmp timers query 10 src 3 leave 1')
767 self.vapi.igmp_enable_disable(self.pg0.sw_if_index, 1, IGMP_MODE.HOST)
768 self.vapi.igmp_enable_disable(self.pg1.sw_if_index, 1,
770 self.vapi.igmp_enable_disable(self.pg2.sw_if_index, 1,
773 # create IGMP proxy device
774 self.vapi.igmp_proxy_device_add_del(0, self.pg0.sw_if_index, 1)
775 self.vapi.igmp_proxy_device_add_del_interface(0,
776 self.pg1.sw_if_index, 1)
777 self.vapi.igmp_proxy_device_add_del_interface(0,
778 self.pg2.sw_if_index, 1)
780 # send join on pg1. join should be proxied by pg0
781 p_j = self._create_igmpv3_pck(self.pg1, "Allow New Sources",
782 "239.1.1.1", ["10.1.1.1", "10.1.1.2"])
783 self.send(self.pg1, p_j)
785 capture = self.pg0.get_capture(1, timeout=1)
786 self.verify_report(capture[0], [IgmpRecord(IgmpSG("239.1.1.1",
787 ["10.1.1.1", "10.1.1.2"]), "Allow New Sources")])
788 self.assertTrue(find_mroute(self, "239.1.1.1", "0.0.0.0", 32))
790 # send join on pg2. join should be proxied by pg0.
791 # the group should contain only 10.1.1.3 as
792 # 10.1.1.1 was already reported
793 p_j = self._create_igmpv3_pck(self.pg2, "Allow New Sources",
794 "239.1.1.1", ["10.1.1.1", "10.1.1.3"])
795 self.send(self.pg2, p_j)
797 capture = self.pg0.get_capture(1, timeout=1)
798 self.verify_report(capture[0], [IgmpRecord(IgmpSG("239.1.1.1",
799 ["10.1.1.3"]), "Allow New Sources")])
800 self.assertTrue(find_mroute(self, "239.1.1.1", "0.0.0.0", 32))
802 # send leave on pg2. leave for 10.1.1.3 should be proxyed
803 # as pg2 was the only interface interested in 10.1.1.3
804 p_l = self._create_igmpv3_pck(self.pg2, "Block Old Sources",
805 "239.1.1.1", ["10.1.1.3"])
806 self.send(self.pg2, p_l)
808 capture = self.pg0.get_capture(1, timeout=2)
809 self.verify_report(capture[0], [IgmpRecord(IgmpSG("239.1.1.1",
810 ["10.1.1.3"]), "Block Old Sources")])
811 self.assertTrue(find_mroute(self, "239.1.1.1", "0.0.0.0", 32))
813 # disable igmp on pg1 (also removes interface from proxy device)
814 # proxy leave for 10.1.1.2. pg2 is still interested in 10.1.1.1
815 self.pg_enable_capture(self.pg_interfaces)
816 self.vapi.igmp_enable_disable(self.pg1.sw_if_index, 0,
819 capture = self.pg0.get_capture(1, timeout=1)
820 self.verify_report(capture[0], [IgmpRecord(IgmpSG("239.1.1.1",
821 ["10.1.1.2"]), "Block Old Sources")])
822 self.assertTrue(find_mroute(self, "239.1.1.1", "0.0.0.0", 32))
824 # disable IGMP on pg0 and pg1.
825 # disabling IGMP on pg0 (proxy device upstream interface)
826 # removes this proxy device
827 self.vapi.igmp_enable_disable(self.pg0.sw_if_index, 0, IGMP_MODE.HOST)
828 self.vapi.igmp_enable_disable(self.pg2.sw_if_index, 0,
830 self.assertFalse(find_mroute(self, "239.1.1.1", "0.0.0.0", 32))
833 if __name__ == '__main__':
834 unittest.main(testRunner=VppTestRunner)