]>
git.proxmox.com Git - mirror_frr.git/blob - tests/topotests/pim-basic/mcast-rx.py
5 # Copyright (c) 2018 Cumulus Networks, Inc.
7 # Permission to use, copy, modify, and/or distribute this software
8 # for any purpose with or without fee is hereby granted, provided
9 # that the above copyright notice and this permission notice appear
12 # THE SOFTWARE IS PROVIDED "AS IS" AND Cumulus Networks DISCLAIMS ALL WARRANTIES
13 # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
14 # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL NETDEF BE LIABLE FOR
15 # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY
16 # DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
17 # WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
18 # ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
22 Subscribe to a multicast group so that the kernel sends an IGMP JOIN
23 for the multicast group we subscribed to.
37 def ifname_to_ifindex(ifname
):
38 output
= subprocess
.check_output("ip link show %s" % ifname
, shell
=True)
39 first_line
= output
.split('\n')[0]
40 re_index
= re
.search('^(\d+):', first_line
)
43 return int(re_index
.group(1))
45 log
.error("Could not parse the ifindex for %s out of\n%s" % (ifname
, first_line
))
51 sys
.stderr
.write('ERROR: You must have root privileges\n')
55 logging
.basicConfig(level
=logging
.DEBUG
, format
='%(asctime)s %(levelname)5s: %(message)s')
57 # Color the errors and warnings in red
58 logging
.addLevelName(logging
.ERROR
, "\033[91m %s\033[0m" % logging
.getLevelName(logging
.ERROR
))
59 logging
.addLevelName(logging
.WARNING
, "\033[91m%s\033[0m" % logging
.getLevelName(logging
.WARNING
))
60 log
= logging
.getLogger(__name__
)
62 parser
= argparse
.ArgumentParser(description
='Multicast RX utility',
64 parser
.add_argument('group', help='Multicast IP')
65 parser
.add_argument('ifname', help='Interface name')
66 parser
.add_argument('--port', help='UDP port', default
=1000)
67 parser
.add_argument('--sleep', help='Time to sleep before we stop waiting',
69 args
= parser
.parse_args()
71 # Create the datagram socket
72 sock
= socket
.socket(socket
.AF_INET
, socket
.SOCK_DGRAM
)
73 sock
.setsockopt(socket
.SOL_SOCKET
, socket
.SO_REUSEADDR
, 1)
74 sock
.bind((args
.group
, args
.port
))
79 ifindex
= ifname_to_ifindex(args
.ifname
)
80 mreq
= struct
.pack("=4sLL", socket
.inet_aton(args
.group
), socket
.INADDR_ANY
, ifindex
)
81 sock
.setsockopt(socket
.IPPROTO_IP
, socket
.IP_ADD_MEMBERSHIP
, mreq
)
82 time
.sleep(float(args
.sleep
))