diff --git a/tests/topotests/lib/mcast-tester.py b/tests/topotests/lib/mcast-tester.py index 5efbecd5e5..3645eef25e 100755 --- a/tests/topotests/lib/mcast-tester.py +++ b/tests/topotests/lib/mcast-tester.py @@ -34,16 +34,64 @@ def interface_name_to_index(name): return None -def multicast_join(sock, ifindex, group, port): +def interface_index_to_address(index, iptype="inet"): + "Gets the interface main address using its name. Returns None on failure." + interfaces = json.loads(subprocess.check_output("ip -j addr show", shell=True)) + + for interface in interfaces: + if interface["ifindex"] == index: + break + + for address in interface["addr_info"]: + if address["family"] == iptype: + break + + local_address = ipaddress.ip_address(address["local"]) + + return local_address.packed + + +def group_source_req(ifindex, group, source): + "Packs the information into 'struct group_source_req' format." + mreq = struct.pack(" 0: # Block to ensure packet send. msock.setblocking(True) else: - multicast_join(msock, ifindex, args.group, args.port) + multicast_join(msock, ifindex, args.group, args.port, args.source) def should_exit():