5 from framework import VppTestCase, VppTestRunner, running_extended_tests
8 from scapy.layers.l2 import Ether
9 from scapy.layers.inet import IP
10 from scapy.contrib.igmpv3 import *
11 from scapy.contrib.igmp import *
12 from vpp_ip_route import find_mroute, VppIpTable
20 class TestIgmp(VppTestCase):
21 """ IGMP Test Case """
24 super(TestIgmp, self).setUp()
26 self.create_pg_interfaces(range(4))
31 self.ip_table = VppIpTable(self, 1)
32 self.ip_table.add_vpp_config()
34 for pg in self.pg_interfaces[2:]:
36 for pg in self.pg_interfaces:
42 for pg in self.pg_interfaces:
43 self.vapi.igmp_clear_interface(pg.sw_if_index)
47 super(TestIgmp, self).tearDown()
49 def send(self, ti, pkts):
51 self.pg_enable_capture(self.pg_interfaces)
54 def test_igmp_flush(self):
55 """ IGMP Link Up/down and Flush """
58 # FIX THIS. Link down.
61 def test_igmp_enable(self):
62 """ IGMP enable/disable on an interface
64 check for the addition/removal of the IGMP mroutes """
66 self.vapi.igmp_enable_disable(self.pg0.sw_if_index, 1, IGMP_MODE.HOST)
67 self.vapi.igmp_enable_disable(self.pg1.sw_if_index, 1, IGMP_MODE.HOST)
69 self.assertTrue(find_mroute(self, "224.0.0.1", "0.0.0.0", 32))
70 self.assertTrue(find_mroute(self, "224.0.0.22", "0.0.0.0", 32))
72 self.vapi.igmp_enable_disable(self.pg2.sw_if_index, 1, IGMP_MODE.HOST)
73 self.vapi.igmp_enable_disable(self.pg3.sw_if_index, 1, IGMP_MODE.HOST)
75 self.assertTrue(find_mroute(self, "224.0.0.1", "0.0.0.0", 32,
77 self.assertTrue(find_mroute(self, "224.0.0.22", "0.0.0.0", 32,
79 self.vapi.igmp_enable_disable(self.pg0.sw_if_index, 0, IGMP_MODE.HOST)
80 self.vapi.igmp_enable_disable(self.pg1.sw_if_index, 0, IGMP_MODE.HOST)
81 self.vapi.igmp_enable_disable(self.pg2.sw_if_index, 0, IGMP_MODE.HOST)
82 self.vapi.igmp_enable_disable(self.pg3.sw_if_index, 0, IGMP_MODE.HOST)
84 self.assertFalse(find_mroute(self, "224.0.0.1", "0.0.0.0", 32))
85 self.assertFalse(find_mroute(self, "224.0.0.22", "0.0.0.0", 32))
86 self.assertFalse(find_mroute(self, "224.0.0.1", "0.0.0.0", 32,
88 self.assertFalse(find_mroute(self, "224.0.0.22", "0.0.0.0", 32,
91 def verify_general_query(self, p):
93 self.assertEqual(len(ip.options), 1)
94 self.assertEqual(ip.options[0].option, 20)
95 self.assertEqual(ip.dst, "224.0.0.1")
96 self.assertEqual(ip.proto, 2)
98 self.assertEqual(igmp.type, 0x11)
99 self.assertEqual(igmp.gaddr, "0.0.0.0")
101 def verify_group_query(self, p, grp, srcs):
103 self.assertEqual(ip.dst, grp)
104 self.assertEqual(ip.proto, 2)
105 self.assertEqual(len(ip.options), 1)
106 self.assertEqual(ip.options[0].option, 20)
107 self.assertEqual(ip.proto, 2)
109 self.assertEqual(igmp.type, 0x11)
110 self.assertEqual(igmp.gaddr, grp)
112 def verify_report(self, rx, records):
114 self.assertEqual(rx[IP].dst, "224.0.0.22")
115 self.assertEqual(len(ip.options), 1)
116 self.assertEqual(ip.options[0].option, 20)
117 self.assertEqual(ip.proto, 2)
118 self.assertEqual(IGMPv3.igmpv3types[rx[IGMPv3].type],
119 "Version 3 Membership Report")
120 self.assertEqual(rx[IGMPv3mr].numgrp, len(records))
122 received = rx[IGMPv3mr].records
124 for ii in range(len(records)):
127 self.assertEqual(IGMPv3gr.igmpv3grtypes[gr.rtype], r.type)
128 self.assertEqual(gr.numsrc, len(r.sg.saddrs))
129 self.assertEqual(gr.maddr, r.sg.gaddr)
130 self.assertEqual(len(gr.srcaddrs), len(r.sg.saddrs))
132 self.assertEqual(sorted(gr.srcaddrs),
135 def add_group(self, itf, sg, n_pkts=2):
136 self.pg_enable_capture(self.pg_interfaces)
139 hs = VppHostState(self,
145 capture = itf.get_capture(n_pkts, timeout=10)
147 # reports are transmitted twice due to default rebostness value=2
148 self.verify_report(capture[0],
149 [IgmpRecord(sg, "Allow New Sources")]),
150 self.verify_report(capture[1],
151 [IgmpRecord(sg, "Allow New Sources")]),
155 def remove_group(self, hs):
156 self.pg_enable_capture(self.pg_interfaces)
158 hs.remove_vpp_config()
160 capture = self.pg0.get_capture(1, timeout=10)
162 self.verify_report(capture[0],
163 [IgmpRecord(hs.sg, "Block Old Sources")])
165 def test_igmp_host(self):
166 """ IGMP Host functions """
169 # Enable interface for host functions
171 self.vapi.igmp_enable_disable(self.pg0.sw_if_index,
176 # Add one S,G of state and expect a state-change event report
177 # indicating the addition of the S,G
179 h1 = self.add_group(self.pg0, IgmpSG("239.1.1.1", ["1.1.1.1"]))
181 # search for the corresponding state created in VPP
182 dump = self.vapi.igmp_dump(self.pg0.sw_if_index)
183 self.assertEqual(len(dump), 1)
184 self.assertTrue(find_igmp_state(dump, self.pg0,
185 "239.1.1.1", "1.1.1.1"))
188 # Send a general query (to the all router's address)
189 # expect VPP to respond with a membership report
191 p_g = (Ether(dst=self.pg0.local_mac, src=self.pg0.remote_mac) /
192 IP(src=self.pg0.remote_ip4, dst='224.0.0.1', tos=0xc0) /
193 IGMPv3(type="Membership Query", mrcode=100) /
194 IGMPv3mq(gaddr="0.0.0.0"))
196 self.send(self.pg0, p_g)
198 capture = self.pg0.get_capture(1, timeout=10)
199 self.verify_report(capture[0],
200 [IgmpRecord(h1.sg, "Mode Is Include")])
203 # Group specific query
205 p_gs = (Ether(dst=self.pg0.local_mac, src=self.pg0.remote_mac) /
206 IP(src=self.pg0.remote_ip4, dst='239.1.1.1', tos=0xc0,
207 options=[IPOption(copy_flag=1, optclass="control",
208 option="router_alert")]) /
209 IGMPv3(type="Membership Query", mrcode=100) /
210 IGMPv3mq(gaddr="239.1.1.1"))
212 self.send(self.pg0, p_gs)
214 capture = self.pg0.get_capture(1, timeout=10)
215 self.verify_report(capture[0],
216 [IgmpRecord(h1.sg, "Mode Is Include")])
219 # A group and source specific query, with the source matching
222 p_gs1 = (Ether(dst=self.pg0.local_mac, src=self.pg0.remote_mac) /
223 IP(src=self.pg0.remote_ip4, dst='239.1.1.1', tos=0xc0,
224 options=[IPOption(copy_flag=1, optclass="control",
225 option="router_alert")]) /
226 IGMPv3(type="Membership Query", mrcode=100) /
227 IGMPv3mq(gaddr="239.1.1.1", srcaddrs=["1.1.1.1"]))
229 self.send(self.pg0, p_gs1)
231 capture = self.pg0.get_capture(1, timeout=10)
232 self.verify_report(capture[0],
233 [IgmpRecord(h1.sg, "Mode Is Include")])
236 # A group and source specific query, with the source NOT matching
237 # the source VPP has. There should be no response.
239 p_gs2 = (Ether(dst=self.pg0.local_mac, src=self.pg0.remote_mac) /
240 IP(src=self.pg0.remote_ip4, dst='239.1.1.1', tos=0xc0,
241 options=[IPOption(copy_flag=1, optclass="control",
242 option="router_alert")]) /
243 IGMPv3(type="Membership Query", mrcode=100) /
244 IGMPv3mq(gaddr="239.1.1.1", srcaddrs=["1.1.1.2"]))
246 self.send_and_assert_no_replies(self.pg0, p_gs2, timeout=10)
249 # A group and source specific query, with the multiple sources
250 # one of which matches the source VPP has.
251 # The report should contain only the source VPP has.
253 p_gs3 = (Ether(dst=self.pg0.local_mac, src=self.pg0.remote_mac) /
254 IP(src=self.pg0.remote_ip4, dst='239.1.1.1', tos=0xc0,
255 options=[IPOption(copy_flag=1, optclass="control",
256 option="router_alert")]) /
257 IGMPv3(type="Membership Query", mrcode=100) /
258 IGMPv3mq(gaddr="239.1.1.1",
259 srcaddrs=["1.1.1.1", "1.1.1.2", "1.1.1.3"]))
261 self.send(self.pg0, p_gs3)
263 capture = self.pg0.get_capture(1, timeout=10)
264 self.verify_report(capture[0],
265 [IgmpRecord(h1.sg, "Mode Is Include")])
268 # Two source and group specific queires in qucik sucession, the
269 # first does not have VPPs source the second does. then vice-versa
271 self.send(self.pg0, [p_gs2, p_gs1])
272 capture = self.pg0.get_capture(1, timeout=10)
273 self.verify_report(capture[0],
274 [IgmpRecord(h1.sg, "Mode Is Include")])
276 self.send(self.pg0, [p_gs1, p_gs2])
277 capture = self.pg0.get_capture(1, timeout=10)
278 self.verify_report(capture[0],
279 [IgmpRecord(h1.sg, "Mode Is Include")])
282 # remove state, expect the report for the removal
284 self.remove_group(h1)
286 dump = self.vapi.igmp_dump()
287 self.assertFalse(dump)
290 # A group with multiple sources
292 h2 = self.add_group(self.pg0,
294 ["1.1.1.1", "1.1.1.2", "1.1.1.3"]))
296 # search for the corresponding state created in VPP
297 dump = self.vapi.igmp_dump(self.pg0.sw_if_index)
298 self.assertEqual(len(dump), 3)
299 for s in h2.sg.saddrs:
300 self.assertTrue(find_igmp_state(dump, self.pg0,
303 # Send a general query (to the all router's address)
304 # expect VPP to respond with a membership report will all sources
306 self.send(self.pg0, p_g)
308 capture = self.pg0.get_capture(1, timeout=10)
309 self.verify_report(capture[0],
310 [IgmpRecord(h2.sg, "Mode Is Include")])
313 # Group and source specific query; some present some not
315 p_gs = (Ether(dst=self.pg0.local_mac, src=self.pg0.remote_mac) /
316 IP(src=self.pg0.remote_ip4, dst='239.1.1.1', tos=0xc0,
317 options=[IPOption(copy_flag=1, optclass="control",
318 option="router_alert")]) /
319 IGMPv3(type="Membership Query", mrcode=100) /
320 IGMPv3mq(gaddr="239.1.1.1",
321 srcaddrs=["1.1.1.1", "1.1.1.2", "1.1.1.4"]))
323 self.send(self.pg0, p_gs)
325 capture = self.pg0.get_capture(1, timeout=10)
326 self.verify_report(capture[0],
328 IgmpSG('239.1.1.1', ["1.1.1.1", "1.1.1.2"]),
332 # add loads more groups
334 h3 = self.add_group(self.pg0,
336 ["2.1.1.1", "2.1.1.2", "2.1.1.3"]))
337 h4 = self.add_group(self.pg0,
339 ["3.1.1.1", "3.1.1.2", "3.1.1.3"]))
340 h5 = self.add_group(self.pg0,
342 ["4.1.1.1", "4.1.1.2", "4.1.1.3"]))
343 h6 = self.add_group(self.pg0,
345 ["5.1.1.1", "5.1.1.2", "5.1.1.3"]))
346 h7 = self.add_group(self.pg0,
348 ["6.1.1.1", "6.1.1.2",
349 "6.1.1.3", "6.1.1.4",
350 "6.1.1.5", "6.1.1.6",
351 "6.1.1.7", "6.1.1.8",
352 "6.1.1.9", "6.1.1.10",
353 "6.1.1.11", "6.1.1.12",
354 "6.1.1.13", "6.1.1.14",
355 "6.1.1.15", "6.1.1.16"]))
359 # the order the groups come in is not important, so what is
360 # checked for is what VPP is sending today.
362 self.send(self.pg0, p_g)
364 capture = self.pg0.get_capture(1, timeout=10)
366 self.verify_report(capture[0],
367 [IgmpRecord(h3.sg, "Mode Is Include"),
368 IgmpRecord(h2.sg, "Mode Is Include"),
369 IgmpRecord(h6.sg, "Mode Is Include"),
370 IgmpRecord(h4.sg, "Mode Is Include"),
371 IgmpRecord(h5.sg, "Mode Is Include"),
372 IgmpRecord(h7.sg, "Mode Is Include")])
375 # modify a group to add and remove some sources
377 h7.sg = IgmpSG("239.1.1.6",
378 ["6.1.1.1", "6.1.1.2",
379 "6.1.1.5", "6.1.1.6",
380 "6.1.1.7", "6.1.1.8",
381 "6.1.1.9", "6.1.1.10",
382 "6.1.1.11", "6.1.1.12",
383 "6.1.1.13", "6.1.1.14",
384 "6.1.1.15", "6.1.1.16",
385 "6.1.1.17", "6.1.1.18"])
387 self.pg_enable_capture(self.pg_interfaces)
391 capture = self.pg0.get_capture(1, timeout=10)
392 self.verify_report(capture[0],
393 [IgmpRecord(IgmpSG("239.1.1.6",
394 ["6.1.1.17", "6.1.1.18"]),
395 "Allow New Sources"),
396 IgmpRecord(IgmpSG("239.1.1.6",
397 ["6.1.1.3", "6.1.1.4"]),
398 "Block Old Sources")])
401 # add an additional groups with many sources so that each group
402 # consumes the link MTU. We should therefore see multiple state
403 # state reports when queried.
405 self.vapi.sw_interface_set_mtu(self.pg0.sw_if_index, [560, 0, 0, 0])
409 src_list.append("10.1.1.%d" % i)
411 h8 = self.add_group(self.pg0,
412 IgmpSG("238.1.1.1", src_list))
413 h9 = self.add_group(self.pg0,
414 IgmpSG("238.1.1.2", src_list))
416 self.send(self.pg0, p_g)
418 capture = self.pg0.get_capture(4, timeout=10)
420 self.verify_report(capture[0],
421 [IgmpRecord(h3.sg, "Mode Is Include"),
422 IgmpRecord(h2.sg, "Mode Is Include"),
423 IgmpRecord(h6.sg, "Mode Is Include"),
424 IgmpRecord(h4.sg, "Mode Is Include"),
425 IgmpRecord(h5.sg, "Mode Is Include")])
426 self.verify_report(capture[1],
427 [IgmpRecord(h8.sg, "Mode Is Include")])
428 self.verify_report(capture[2],
429 [IgmpRecord(h7.sg, "Mode Is Include")])
430 self.verify_report(capture[3],
431 [IgmpRecord(h9.sg, "Mode Is Include")])
434 # drop the MTU further (so a 128 sized group won't fit)
436 self.vapi.sw_interface_set_mtu(self.pg0.sw_if_index, [512, 0, 0, 0])
438 self.pg_enable_capture(self.pg_interfaces)
441 h10 = VppHostState(self,
443 self.pg0.sw_if_index,
444 IgmpSG("238.1.1.3", src_list))
447 capture = self.pg0.get_capture(2, timeout=10)
450 # remove state, expect the report for the removal
451 # the dump should be empty
453 self.vapi.sw_interface_set_mtu(self.pg0.sw_if_index, [600, 0, 0, 0])
454 self.remove_group(h8)
455 self.remove_group(h9)
456 self.remove_group(h2)
457 self.remove_group(h3)
458 self.remove_group(h4)
459 self.remove_group(h5)
460 self.remove_group(h6)
461 self.remove_group(h7)
462 self.remove_group(h10)
464 self.logger.info(self.vapi.cli("sh igmp config"))
465 self.assertFalse(self.vapi.igmp_dump())
469 # ADD STATE ON MORE INTERFACES
472 self.vapi.igmp_enable_disable(self.pg0.sw_if_index,
476 def test_igmp_router(self):
477 """ IGMP Router Functions """
480 # Drop reports when not enabled
482 p_j = (Ether(dst=self.pg0.local_mac, src=self.pg0.remote_mac) /
483 IP(src=self.pg0.remote_ip4, dst="224.0.0.22", tos=0xc0, ttl=1,
484 options=[IPOption(copy_flag=1, optclass="control",
485 option="router_alert")]) /
486 IGMPv3(type="Version 3 Membership Report") /
488 IGMPv3gr(rtype="Allow New Sources",
489 maddr="239.1.1.1", srcaddrs=["10.1.1.1", "10.1.1.2"]))
490 p_l = (Ether(dst=self.pg0.local_mac, src=self.pg0.remote_mac) /
491 IP(src=self.pg0.remote_ip4, dst="224.0.0.22", tos=0xc0,
492 options=[IPOption(copy_flag=1, optclass="control",
493 option="router_alert")]) /
494 IGMPv3(type="Version 3 Membership Report") /
496 IGMPv3gr(rtype="Block Old Sources",
497 maddr="239.1.1.1", srcaddrs=["10.1.1.1", "10.1.1.2"]))
499 self.send(self.pg0, p_j)
500 self.assertFalse(self.vapi.igmp_dump())
503 # drop the default timer values so these tests execute in a
504 # reasonable time frame
506 self.vapi.cli("test igmp timers query 1 src 3 leave 1")
509 # enable router functions on the interface
511 self.pg_enable_capture(self.pg_interfaces)
513 self.vapi.igmp_enable_disable(self.pg0.sw_if_index,
516 self.vapi.want_igmp_events(1)
519 # wait for router to send general query
522 capture = self.pg0.get_capture(1, timeout=2)
523 self.verify_general_query(capture[0])
524 self.pg_enable_capture(self.pg_interfaces)
528 # re-send the report. VPP should now hold state for the new group
529 # VPP sends a notification that a new group has been joined
531 self.send(self.pg0, p_j)
533 self.assertTrue(wait_for_igmp_event(self, 1, self.pg0,
534 "239.1.1.1", "10.1.1.1", 1))
535 self.assertTrue(wait_for_igmp_event(self, 1, self.pg0,
536 "239.1.1.1", "10.1.1.2", 1))
537 dump = self.vapi.igmp_dump(self.pg0.sw_if_index)
538 self.assertEqual(len(dump), 2)
539 self.assertTrue(find_igmp_state(dump, self.pg0,
540 "239.1.1.1", "10.1.1.1"))
541 self.assertTrue(find_igmp_state(dump, self.pg0,
542 "239.1.1.1", "10.1.1.2"))
545 # wait for the per-source timer to expire
546 # the state should be reaped
547 # VPP sends a notification that the group has been left
549 self.assertTrue(wait_for_igmp_event(self, 4, self.pg0,
550 "239.1.1.1", "10.1.1.1", 0))
551 self.assertTrue(wait_for_igmp_event(self, 1, self.pg0,
552 "239.1.1.1", "10.1.1.2", 0))
553 self.assertFalse(self.vapi.igmp_dump())
556 # resend the join. wait for two queries and then send a current-state
557 # record to include all sources. this should reset the exiry time
558 # on the sources and thus they will still be present in 2 seconds time.
559 # If the source timer was not refreshed, then the state would have
560 # expired in 3 seconds.
562 self.send(self.pg0, p_j)
563 self.assertTrue(wait_for_igmp_event(self, 1, self.pg0,
564 "239.1.1.1", "10.1.1.1", 1))
565 self.assertTrue(wait_for_igmp_event(self, 1, self.pg0,
566 "239.1.1.1", "10.1.1.2", 1))
567 dump = self.vapi.igmp_dump(self.pg0.sw_if_index)
568 self.assertEqual(len(dump), 2)
570 capture = self.pg0.get_capture(2, timeout=3)
571 self.verify_general_query(capture[0])
572 self.verify_general_query(capture[1])
574 p_cs = (Ether(dst=self.pg0.local_mac, src=self.pg0.remote_mac) /
575 IP(src=self.pg0.remote_ip4, dst="224.0.0.22", tos=0xc0,
576 options=[IPOption(copy_flag=1, optclass="control",
577 option="router_alert")]) /
578 IGMPv3(type="Version 3 Membership Report") /
580 IGMPv3gr(rtype="Mode Is Include",
581 maddr="239.1.1.1", srcaddrs=["10.1.1.1", "10.1.1.2"]))
583 self.send(self.pg0, p_cs)
586 dump = self.vapi.igmp_dump(self.pg0.sw_if_index)
587 self.assertEqual(len(dump), 2)
588 self.assertTrue(find_igmp_state(dump, self.pg0,
589 "239.1.1.1", "10.1.1.1"))
590 self.assertTrue(find_igmp_state(dump, self.pg0,
591 "239.1.1.1", "10.1.1.2"))
594 # wait for the per-source timer to expire
595 # the state should be reaped
597 self.assertTrue(wait_for_igmp_event(self, 4, self.pg0,
598 "239.1.1.1", "10.1.1.1", 0))
599 self.assertTrue(wait_for_igmp_event(self, 1, self.pg0,
600 "239.1.1.1", "10.1.1.2", 0))
601 self.assertFalse(self.vapi.igmp_dump())
604 # resend the join, then a leave. Router sends a gruop+source
605 # specific query containing both sources
607 self.send(self.pg0, p_j)
609 self.assertTrue(wait_for_igmp_event(self, 1, self.pg0,
610 "239.1.1.1", "10.1.1.1", 1))
611 self.assertTrue(wait_for_igmp_event(self, 1, self.pg0,
612 "239.1.1.1", "10.1.1.2", 1))
613 dump = self.vapi.igmp_dump(self.pg0.sw_if_index)
614 self.assertEqual(len(dump), 2)
616 self.send(self.pg0, p_l)
617 capture = self.pg0.get_capture(1, timeout=3)
618 self.verify_group_query(capture[0], "239.1.1.1",
619 ["10.1.1.1", "10.1.1.2"])
622 # the group specific query drops the timeout to leave (=1) seconds
624 self.assertTrue(wait_for_igmp_event(self, 2, self.pg0,
625 "239.1.1.1", "10.1.1.1", 0))
626 self.assertTrue(wait_for_igmp_event(self, 1, self.pg0,
627 "239.1.1.1", "10.1.1.2", 0))
628 self.assertFalse(self.vapi.igmp_dump())
629 self.assertFalse(self.vapi.igmp_dump())
632 # A (*,G) host report
634 p_j = (Ether(dst=self.pg0.local_mac, src=self.pg0.remote_mac) /
635 IP(src=self.pg0.remote_ip4, dst="224.0.0.22", tos=0xc0, ttl=1,
636 options=[IPOption(copy_flag=1, optclass="control",
637 option="router_alert")]) /
638 IGMPv3(type="Version 3 Membership Report") /
640 IGMPv3gr(rtype="Allow New Sources", maddr="239.1.1.2"))
642 self.send(self.pg0, p_j)
644 self.assertTrue(wait_for_igmp_event(self, 1, self.pg0,
645 "239.1.1.2", "0.0.0.0", 1))
648 # disable router config
650 self.vapi.igmp_enable_disable(self.pg0.sw_if_index,
654 def _create_igmpv3_pck(self, itf, rtype, maddr, srcaddrs):
655 p = (Ether(dst=itf.local_mac, src=itf.remote_mac) /
656 IP(src=itf.remote_ip4, dst="224.0.0.22", tos=0xc0, ttl=1,
657 options=[IPOption(copy_flag=1, optclass="control",
658 option="router_alert")]) /
659 IGMPv3(type="Version 3 Membership Report") /
661 IGMPv3gr(rtype=rtype,
662 maddr=maddr, srcaddrs=srcaddrs))
665 def test_igmp_proxy_device(self):
666 """ IGMP proxy device """
667 self.pg2.admin_down()
668 self.pg2.unconfig_ip4()
669 self.pg2.set_table_ip4(0)
670 self.pg2.config_ip4()
673 self.vapi.cli('test igmp timers query 10 src 3 leave 1')
676 self.vapi.igmp_enable_disable(self.pg0.sw_if_index, 1, IGMP_MODE.HOST)
677 self.vapi.igmp_enable_disable(self.pg1.sw_if_index, 1,
679 self.vapi.igmp_enable_disable(self.pg2.sw_if_index, 1,
682 # create IGMP proxy device
683 self.vapi.igmp_proxy_device_add_del(0, self.pg0.sw_if_index, 1)
684 self.vapi.igmp_proxy_device_add_del_interface(0,
685 self.pg1.sw_if_index, 1)
686 self.vapi.igmp_proxy_device_add_del_interface(0,
687 self.pg2.sw_if_index, 1)
689 # send join on pg1. join should be proxied by pg0
690 p_j = self._create_igmpv3_pck(self.pg1, "Allow New Sources",
691 "239.1.1.1", ["10.1.1.1", "10.1.1.2"])
692 self.send(self.pg1, p_j)
694 capture = self.pg0.get_capture(1, timeout=1)
695 self.verify_report(capture[0], [IgmpRecord(IgmpSG("239.1.1.1",
696 ["10.1.1.1", "10.1.1.2"]), "Allow New Sources")])
697 self.assertTrue(find_mroute(self, "239.1.1.1", "0.0.0.0", 32))
699 # send join on pg2. join should be proxied by pg0.
700 # the group should contain only 10.1.1.3 as
701 # 10.1.1.1 was already reported
702 p_j = self._create_igmpv3_pck(self.pg2, "Allow New Sources",
703 "239.1.1.1", ["10.1.1.1", "10.1.1.3"])
704 self.send(self.pg2, p_j)
706 capture = self.pg0.get_capture(1, timeout=1)
707 self.verify_report(capture[0], [IgmpRecord(IgmpSG("239.1.1.1",
708 ["10.1.1.3"]), "Allow New Sources")])
709 self.assertTrue(find_mroute(self, "239.1.1.1", "0.0.0.0", 32))
711 # send leave on pg2. leave for 10.1.1.3 should be proxyed
712 # as pg2 was the only interface interested in 10.1.1.3
713 p_l = self._create_igmpv3_pck(self.pg2, "Block Old Sources",
714 "239.1.1.1", ["10.1.1.3"])
715 self.send(self.pg2, p_l)
717 capture = self.pg0.get_capture(1, timeout=2)
718 self.verify_report(capture[0], [IgmpRecord(IgmpSG("239.1.1.1",
719 ["10.1.1.3"]), "Block Old Sources")])
720 self.assertTrue(find_mroute(self, "239.1.1.1", "0.0.0.0", 32))
722 # disable igmp on pg1 (also removes interface from proxy device)
723 # proxy leave for 10.1.1.2. pg2 is still interested in 10.1.1.1
724 self.pg_enable_capture(self.pg_interfaces)
725 self.vapi.igmp_enable_disable(self.pg1.sw_if_index, 0,
728 capture = self.pg0.get_capture(1, timeout=1)
729 self.verify_report(capture[0], [IgmpRecord(IgmpSG("239.1.1.1",
730 ["10.1.1.2"]), "Block Old Sources")])
731 self.assertTrue(find_mroute(self, "239.1.1.1", "0.0.0.0", 32))
733 # disable IGMP on pg0 and pg1.
734 # disabling IGMP on pg0 (proxy device upstream interface)
735 # removes this proxy device
736 self.vapi.igmp_enable_disable(self.pg0.sw_if_index, 0, IGMP_MODE.HOST)
737 self.vapi.igmp_enable_disable(self.pg2.sw_if_index, 0,
739 self.assertFalse(find_mroute(self, "239.1.1.1", "0.0.0.0", 32))
742 if __name__ == '__main__':
743 unittest.main(testRunner=VppTestRunner)