From 348f0a10a3dd735ac1e83e9df6209f7a2a61fd6a Mon Sep 17 00:00:00 2001 From: Eduardo Montoya Date: Wed, 22 Dec 2021 18:51:47 +0100 Subject: [PATCH] [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. --- tools/harness-thci/OpenThread.py | 66 +++++++++-------------------- tools/harness-thci/OpenThread_BR.py | 49 +++++++++++++++++++++ 2 files changed, 69 insertions(+), 46 deletions(-) diff --git a/tools/harness-thci/OpenThread.py b/tools/harness-thci/OpenThread.py index fa278dcbc..7f5001f26 100644 --- a/tools/harness-thci/OpenThread.py +++ b/tools/harness-thci/OpenThread.py @@ -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): diff --git a/tools/harness-thci/OpenThread_BR.py b/tools/harness-thci/OpenThread_BR.py index 2e1a006c8..9da819933 100644 --- a/tools/harness-thci/OpenThread_BR.py +++ b/tools/harness-thci/OpenThread_BR.py @@ -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