[thci] register multicast addresses on the host side (#7193)

Make use of the `mcast6.py` application in order to listen to
multicast traffic on the host side when required by the harness.
This commit is contained in:
Eduardo Montoya
2021-12-22 09:51:47 -08:00
committed by GitHub
parent 66dc0c3467
commit 348f0a10a3
2 changed files with 69 additions and 46 deletions
+20 -46
View File
@@ -1583,6 +1583,10 @@ class OpenThreadTHCI(object):
self.IsBackboneRouter = False
self.IsHost = False
# remove stale multicast addresses
if self.IsBorderRouter:
self.stopListeningToAddrAll()
# BBR dataset
self.bbrSeqNum = random.randint(0, 254) # random seqnum except 255, so that BBR-TC-02 never need re-run
self.bbrMlrTimeout = 3600
@@ -3455,20 +3459,14 @@ class OpenThreadTHCI(object):
def stopListeningToAddr(self, sAddr):
print('%s call stopListeningToAddr' % self.port)
# convert to list for single element, for possible extension
# requirements.
if not isinstance(sAddr, list):
sAddr = [sAddr]
for addr in sAddr:
cmd = 'ipmaddr del ' + addr
try:
self.__executeCommand(cmd)
except CommandError as ex:
if ex.code == OT_ERROR_ALREADY:
pass
else:
raise
cmd = 'ipmaddr del ' + sAddr
try:
self.__executeCommand(cmd)
except CommandError as ex:
if ex.code == OT_ERROR_ALREADY:
pass
else:
raise
return True
@@ -3479,40 +3477,16 @@ class OpenThreadTHCI(object):
Args:
sAddr : str : Multicast address to be subscribed and notified OTA.
"""
# convert to list for single element, for possible extension
# requirements.
if not isinstance(sAddr, list):
sAddr = [sAddr]
if self.externalCommissioner is not None:
self.externalCommissioner.MLR(sAddr, timeout)
return True
cmd = 'ipmaddr add ' + str(sAddr)
# subscribe address one by one
for addr in sAddr:
cmd = 'ipmaddr add ' + str(addr)
try:
self.__executeCommand(cmd)
except CommandError as ex:
if ex.code == OT_ERROR_ALREADY:
pass
else:
raise
@API
def deregisterMulticast(self, sAddr):
"""
Unsubscribe to a given IPv6 address.
Only used by External Commissioner.
Args:
sAddr : str : Multicast address to be unsubscribed.
"""
if not isinstance(sAddr, list):
sAddr = [sAddr]
self.externalCommissioner.MLR(sAddr, 0)
return True
try:
self.__executeCommand(cmd)
except CommandError as ex:
if ex.code == OT_ERROR_ALREADY:
pass
else:
raise
@API
def getMlrLogs(self):
+49
View File
@@ -313,6 +313,8 @@ class OpenThread_BR(OpenThreadTHCI, IThci):
self.bash('sudo ip -6 addr del 910b::1 dev eth0 || true')
self.bash('sudo ip -6 addr del fd00:7d03:7d03:7d03::1 dev eth0 || true')
self.stopListeningToAddrAll()
def _deviceAfterReset(self):
self.__dumpSyslog()
self.__truncateSyslog()
@@ -661,3 +663,50 @@ EOF"
def forceSetSlaac(self, slaacAddress):
print('forceSetSlaac %s' % slaacAddress)
self.bash('sudo ip -6 addr add %s/64 dev wpan0' % slaacAddress)
# Override registerMulticast
@API
def registerMulticast(self, sAddr='ff04::1234:777a:1', timeout=300):
"""subscribe to the given ipv6 address (sAddr) in interface and send MLR.req OTA
Args:
sAddr : str : Multicast address to be subscribed and notified OTA.
"""
if self.externalCommissioner is not None:
self.externalCommissioner.MLR([sAddr], timeout)
return True
cmd = 'sudo nohup ~/repo/openthread/tests/scripts/thread-cert/mcast6.py wpan0 %s' % sAddr
cmd = cmd + ' > /dev/null 2>&1 &'
self.bash(cmd)
return True
# Override stopListeningToAddr
@API
def stopListeningToAddr(self, sAddr):
"""
Unsubscribe to a given IPv6 address which was subscribed earlier wiht `registerMulticast`.
Args:
sAddr : str : Multicast address to be unsubscribed. Use an empty string to unsubscribe
all the active multicast addresses.
"""
cmd = 'sudo pkill -f mcast6.*%s' % sAddr
self.bash(cmd)
def stopListeningToAddrAll(self):
return self.stopListeningToAddr('')
@API
def deregisterMulticast(self, sAddr):
"""
Unsubscribe to a given IPv6 address.
Only used by External Commissioner.
Args:
sAddr : str : Multicast address to be unsubscribed.
"""
self.externalCommissioner.MLR([sAddr], 0)
return True