tests: Factor out multicast connectivity check
A test may want to check multicast connectivity independent of unicast or check multicast without exercising unicast first. Factor out the multicast connectivity check code into its own function. Signed-off-by: Thomas Pedersen <thomas@adapt-ip.com>
This commit is contained in:
parent
b056275111
commit
1d9d6c2432
3 changed files with 93 additions and 92 deletions
|
@ -179,6 +179,9 @@ class Hostapd:
|
||||||
self.bssid = self.get_status_field('bssid[%d]' % self.bssidx)
|
self.bssid = self.get_status_field('bssid[%d]' % self.bssidx)
|
||||||
return self.bssid
|
return self.bssid
|
||||||
|
|
||||||
|
def get_addr(self, group=False):
|
||||||
|
return self.own_addr()
|
||||||
|
|
||||||
def request(self, cmd):
|
def request(self, cmd):
|
||||||
logger.debug(self.dbg + ": CTRL: " + cmd)
|
logger.debug(self.dbg + ": CTRL: " + cmd)
|
||||||
return self.ctrl.request(cmd)
|
return self.ctrl.request(cmd)
|
||||||
|
|
|
@ -11,32 +11,7 @@ logger = logging.getLogger()
|
||||||
|
|
||||||
from wpasupplicant import WpaSupplicant
|
from wpasupplicant import WpaSupplicant
|
||||||
|
|
||||||
def run_connectivity_test(dev1, dev2, tos, dev1group=False, dev2group=False,
|
def config_data_test(dev1, dev2, dev1group, dev2group, ifname1, ifname2):
|
||||||
ifname1=None, ifname2=None, config=True, timeout=5,
|
|
||||||
multicast_to_unicast=False, broadcast=True,
|
|
||||||
send_len=None):
|
|
||||||
addr1 = dev1.own_addr()
|
|
||||||
if not dev1group and isinstance(dev1, WpaSupplicant):
|
|
||||||
addr = dev1.get_driver_status_field('addr')
|
|
||||||
if addr:
|
|
||||||
addr1 = addr
|
|
||||||
|
|
||||||
addr2 = dev2.own_addr()
|
|
||||||
if not dev2group and isinstance(dev2, WpaSupplicant):
|
|
||||||
addr = dev2.get_driver_status_field('addr')
|
|
||||||
if addr:
|
|
||||||
addr2 = addr
|
|
||||||
|
|
||||||
dev1.dump_monitor()
|
|
||||||
dev2.dump_monitor()
|
|
||||||
|
|
||||||
if dev1.hostname is None and dev2.hostname is None:
|
|
||||||
broadcast_retry_c = 1
|
|
||||||
else:
|
|
||||||
broadcast_retry_c = 10
|
|
||||||
|
|
||||||
try:
|
|
||||||
if config:
|
|
||||||
cmd = "DATA_TEST_CONFIG 1"
|
cmd = "DATA_TEST_CONFIG 1"
|
||||||
if ifname1:
|
if ifname1:
|
||||||
cmd = cmd + " ifname=" + ifname1
|
cmd = cmd + " ifname=" + ifname1
|
||||||
|
@ -57,6 +32,72 @@ def run_connectivity_test(dev1, dev2, tos, dev1group=False, dev2group=False,
|
||||||
if "OK" not in res:
|
if "OK" not in res:
|
||||||
raise Exception("Failed to enable data test functionality")
|
raise Exception("Failed to enable data test functionality")
|
||||||
|
|
||||||
|
def run_multicast_connectivity_test(dev1, dev2, tos=None,
|
||||||
|
dev1group=False, dev2group=False,
|
||||||
|
ifname1=None, ifname2=None,
|
||||||
|
config=True, timeout=5,
|
||||||
|
send_len=None, multicast_to_unicast=False,
|
||||||
|
broadcast_retry_c=1):
|
||||||
|
addr1 = dev1.get_addr(dev1group)
|
||||||
|
addr2 = dev2.get_addr(dev2group)
|
||||||
|
|
||||||
|
if config:
|
||||||
|
config_data_test(dev1, dev2, dev1group, dev2group, ifname1, ifname2)
|
||||||
|
|
||||||
|
cmd = "DATA_TEST_TX ff:ff:ff:ff:ff:ff {} {}".format(addr1, tos)
|
||||||
|
if send_len is not None:
|
||||||
|
cmd += " len=" + str(send_len)
|
||||||
|
for i in range(broadcast_retry_c):
|
||||||
|
try:
|
||||||
|
if dev1group:
|
||||||
|
dev1.group_request(cmd)
|
||||||
|
else:
|
||||||
|
dev1.request(cmd)
|
||||||
|
if dev2group:
|
||||||
|
ev = dev2.wait_group_event(["DATA-TEST-RX"],
|
||||||
|
timeout=timeout)
|
||||||
|
else:
|
||||||
|
ev = dev2.wait_event(["DATA-TEST-RX"], timeout=timeout)
|
||||||
|
if ev is None:
|
||||||
|
raise Exception("dev1->dev2 broadcast data delivery failed")
|
||||||
|
if multicast_to_unicast:
|
||||||
|
if "DATA-TEST-RX ff:ff:ff:ff:ff:ff {}".format(addr1) in ev:
|
||||||
|
raise Exception("Unexpected dev1->dev2 broadcast data result: multicast to unicast conversion missing")
|
||||||
|
if "DATA-TEST-RX {} {}".format(addr2, addr1) not in ev:
|
||||||
|
raise Exception("Unexpected dev1->dev2 broadcast data result (multicast to unicast enabled)")
|
||||||
|
else:
|
||||||
|
if "DATA-TEST-RX ff:ff:ff:ff:ff:ff {}".format(addr1) not in ev:
|
||||||
|
raise Exception("Unexpected dev1->dev2 broadcast data result")
|
||||||
|
if send_len is not None:
|
||||||
|
if " len=" + str(send_len) not in ev:
|
||||||
|
raise Exception("Unexpected dev1->dev2 broadcast data length")
|
||||||
|
else:
|
||||||
|
if " len=" in ev:
|
||||||
|
raise Exception("Unexpected dev1->dev2 broadcast data length")
|
||||||
|
break
|
||||||
|
except Exception as e:
|
||||||
|
if i == broadcast_retry_c - 1:
|
||||||
|
raise
|
||||||
|
|
||||||
|
def run_connectivity_test(dev1, dev2, tos, dev1group=False, dev2group=False,
|
||||||
|
ifname1=None, ifname2=None, config=True, timeout=5,
|
||||||
|
multicast_to_unicast=False, broadcast=True,
|
||||||
|
send_len=None):
|
||||||
|
addr1 = dev1.get_addr(dev1group)
|
||||||
|
addr2 = dev2.get_addr(dev2group)
|
||||||
|
|
||||||
|
dev1.dump_monitor()
|
||||||
|
dev2.dump_monitor()
|
||||||
|
|
||||||
|
if dev1.hostname is None and dev2.hostname is None:
|
||||||
|
broadcast_retry_c = 1
|
||||||
|
else:
|
||||||
|
broadcast_retry_c = 10
|
||||||
|
|
||||||
|
try:
|
||||||
|
if config:
|
||||||
|
config_data_test(dev1, dev2, dev1group, dev2group, ifname1, ifname2)
|
||||||
|
|
||||||
cmd = "DATA_TEST_TX {} {} {}".format(addr2, addr1, tos)
|
cmd = "DATA_TEST_TX {} {} {}".format(addr2, addr1, tos)
|
||||||
if send_len is not None:
|
if send_len is not None:
|
||||||
cmd += " len=" + str(send_len)
|
cmd += " len=" + str(send_len)
|
||||||
|
@ -80,34 +121,10 @@ def run_connectivity_test(dev1, dev2, tos, dev1group=False, dev2group=False,
|
||||||
raise Exception("Unexpected dev1->dev2 unicast data length")
|
raise Exception("Unexpected dev1->dev2 unicast data length")
|
||||||
|
|
||||||
if broadcast:
|
if broadcast:
|
||||||
cmd = "DATA_TEST_TX ff:ff:ff:ff:ff:ff {} {}".format(addr1, tos)
|
run_multicast_connectivity_test(dev1, dev2, tos,
|
||||||
if send_len is not None:
|
dev1group, dev2group,
|
||||||
cmd += " len=" + str(send_len)
|
ifname1, ifname2, False, timeout,
|
||||||
for i in range(broadcast_retry_c):
|
send_len, False, broadcast_retry_c)
|
||||||
try:
|
|
||||||
if dev1group:
|
|
||||||
dev1.group_request(cmd)
|
|
||||||
else:
|
|
||||||
dev1.request(cmd)
|
|
||||||
if dev2group:
|
|
||||||
ev = dev2.wait_group_event(["DATA-TEST-RX"],
|
|
||||||
timeout=timeout)
|
|
||||||
else:
|
|
||||||
ev = dev2.wait_event(["DATA-TEST-RX"], timeout=timeout)
|
|
||||||
if ev is None:
|
|
||||||
raise Exception("dev1->dev2 broadcast data delivery failed")
|
|
||||||
if "DATA-TEST-RX ff:ff:ff:ff:ff:ff {}".format(addr1) not in ev:
|
|
||||||
raise Exception("Unexpected dev1->dev2 broadcast data result")
|
|
||||||
if send_len is not None:
|
|
||||||
if " len=" + str(send_len) not in ev:
|
|
||||||
raise Exception("Unexpected dev1->dev2 broadcast data length")
|
|
||||||
else:
|
|
||||||
if " len=" in ev:
|
|
||||||
raise Exception("Unexpected dev1->dev2 broadcast data length")
|
|
||||||
break
|
|
||||||
except Exception as e:
|
|
||||||
if i == broadcast_retry_c - 1:
|
|
||||||
raise
|
|
||||||
|
|
||||||
cmd = "DATA_TEST_TX {} {} {}".format(addr1, addr2, tos)
|
cmd = "DATA_TEST_TX {} {} {}".format(addr1, addr2, tos)
|
||||||
if send_len is not None:
|
if send_len is not None:
|
||||||
|
@ -132,40 +149,12 @@ def run_connectivity_test(dev1, dev2, tos, dev1group=False, dev2group=False,
|
||||||
raise Exception("Unexpected dev2->dev1 unicast data length")
|
raise Exception("Unexpected dev2->dev1 unicast data length")
|
||||||
|
|
||||||
if broadcast:
|
if broadcast:
|
||||||
cmd = "DATA_TEST_TX ff:ff:ff:ff:ff:ff {} {}".format(addr2, tos)
|
run_multicast_connectivity_test(dev2, dev1, tos,
|
||||||
if send_len is not None:
|
dev2group, dev1group,
|
||||||
cmd += " len=" + str(send_len)
|
ifname2, ifname1, False, timeout,
|
||||||
for i in range(broadcast_retry_c):
|
send_len, multicast_to_unicast,
|
||||||
try:
|
broadcast_retry_c)
|
||||||
if dev2group:
|
|
||||||
dev2.group_request(cmd)
|
|
||||||
else:
|
|
||||||
dev2.request(cmd)
|
|
||||||
if dev1group:
|
|
||||||
ev = dev1.wait_group_event(["DATA-TEST-RX"],
|
|
||||||
timeout=timeout)
|
|
||||||
else:
|
|
||||||
ev = dev1.wait_event(["DATA-TEST-RX"], timeout=timeout)
|
|
||||||
if ev is None:
|
|
||||||
raise Exception("dev2->dev1 broadcast data delivery failed")
|
|
||||||
if multicast_to_unicast:
|
|
||||||
if "DATA-TEST-RX ff:ff:ff:ff:ff:ff {}".format(addr2) in ev:
|
|
||||||
raise Exception("Unexpected dev2->dev1 broadcast data result: multicast to unicast conversion missing")
|
|
||||||
if "DATA-TEST-RX {} {}".format(addr1, addr2) not in ev:
|
|
||||||
raise Exception("Unexpected dev2->dev1 broadcast data result (multicast to unicast enabled)")
|
|
||||||
else:
|
|
||||||
if "DATA-TEST-RX ff:ff:ff:ff:ff:ff {}".format(addr2) not in ev:
|
|
||||||
raise Exception("Unexpected dev2->dev1 broadcast data result")
|
|
||||||
if send_len is not None:
|
|
||||||
if " len=" + str(send_len) not in ev:
|
|
||||||
raise Exception("Unexpected dev2->dev1 broadcast data length")
|
|
||||||
else:
|
|
||||||
if " len=" in ev:
|
|
||||||
raise Exception("Unexpected dev2->dev1 broadcast data length")
|
|
||||||
break
|
|
||||||
except Exception as e:
|
|
||||||
if i == broadcast_retry_c - 1:
|
|
||||||
raise
|
|
||||||
finally:
|
finally:
|
||||||
if config:
|
if config:
|
||||||
if dev1group:
|
if dev1group:
|
||||||
|
|
|
@ -598,6 +598,15 @@ class WpaSupplicant:
|
||||||
res = self.p2p_dev_addr()
|
res = self.p2p_dev_addr()
|
||||||
return res
|
return res
|
||||||
|
|
||||||
|
def get_addr(self, group=False):
|
||||||
|
dev_addr = self.own_addr()
|
||||||
|
if not group:
|
||||||
|
addr = self.get_status_field('address')
|
||||||
|
if addr:
|
||||||
|
dev_addr = addr
|
||||||
|
|
||||||
|
return dev_addr
|
||||||
|
|
||||||
def p2p_listen(self):
|
def p2p_listen(self):
|
||||||
return self.global_request("P2P_LISTEN")
|
return self.global_request("P2P_LISTEN")
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue