From a2580e8346e3c462567b253b230e97d829f8a050 Mon Sep 17 00:00:00 2001 From: Xiao Ma Date: Sat, 20 Aug 2016 01:13:45 +0800 Subject: [PATCH] THCI: update openthread thci with new fix and support. (#427) * Add new Device Role MED/FED support in joinNetwork() * Set default data poll rate for sleepy end device to 10s * Add forceSetSlaac() method support * Add 'int' type parameter support in removeRouter() for AUTO DUT * Update README.md with 'pexpect' dependency module --- tools/harness-thci/ARM.py | 66 ++++++++++++++++++++++++++++-------- tools/harness-thci/README.md | 31 +++++++++++------ 2 files changed, 71 insertions(+), 26 deletions(-) diff --git a/tools/harness-thci/ARM.py b/tools/harness-thci/ARM.py index cce04e1e7..3074d779b 100644 --- a/tools/harness-thci/ARM.py +++ b/tools/harness-thci/ARM.py @@ -324,7 +324,7 @@ class ARM(IThci): print 'call isOpenThreadRunning' return self.__sendCommand('state')[0] == 'disabled' - # rloc16 might be hex, need to return actual allocated router id + # rloc16 might be hex string or integer, need to return actual allocated router id def __convertRlocToRouterId(self, xRloc16): """mapping Rloc16 to router id @@ -337,11 +337,11 @@ class ARM(IThci): routerList = [] routerList = self.__sendCommand('router list')[0].split() print routerList + print xRloc16 for index in routerList: router = [] cmd = 'router %s' % index - print cmd router = self.__sendCommand(cmd) for line in router: @@ -351,11 +351,20 @@ class ARM(IThci): routerid = line.split()[2] elif 'Rloc' in line: rloc16 = line.split()[1] - rloc16 = '0x' + rloc16 - if rloc16 == str(xRloc16): - return routerid else: pass + + # process input rloc16 + if isinstance(xRloc16, str): + rloc16 = '0x' + rloc16 + if rloc16 == xRloc16: + return routerid + elif isinstance(xRloc16, int): + if int(rloc16, 16) == xRloc16: + return routerid + else: + pass + return None def __convertIp6PrefixStringToIp6Address(self, strIp6Prefix): @@ -699,9 +708,9 @@ class ARM(IThci): Returns: True: ready to set Thread Network parameter for joining desired Network """ - role = '' print '%s call joinNetwork' % self.port print eRoleId + role = '' try: if ModuleHelper.LeaderDutChannelFound: self.channel = ModuleHelper.Default_Channel @@ -717,6 +726,8 @@ class ARM(IThci): elif eRoleId == Thread_Device_Role.SED: print 'join as sleepy end device' role = 's' + # set data polling rate to 10s for SED + self.setPollingRate(10) elif eRoleId == Thread_Device_Role.EndDevice: print 'join as end device' role = 'rsn' @@ -725,6 +736,15 @@ class ARM(IThci): role = 'rsdn' # set ROUTER_UPGRADE_THRESHOLD self.__setRouterUpgradeThreshold(0) + elif eRoleId == Thread_Device_Role.EndDevice_FED: + # always remain an ED, never request to be a router + print 'join as FED' + role = 'rsdn' + # set ROUTER_UPGRADE_THRESHOLD + self.__setRouterUpgradeThreshold(0) + elif eRoleId == Thread_Device_Role.EndDevice_MED: + print 'join as MED' + role = 'rsn' else: pass @@ -825,11 +845,14 @@ class ARM(IThci): length: the size of ICMPv6 echo request payload """ print '%s call ping' % self.port - print destination + print 'destination: %s' %destination try: cmd = 'ping %s %s' % (destination, str(length)) print cmd self.serial.sendline(cmd) + self.serial.expect(cmd + self.serial.linesep) + # wait echo reply + time.sleep(1) except Exception, e: ModuleHelper.WriteIntoDebugLogger("ping() Error: " + str(e)) @@ -842,11 +865,14 @@ class ARM(IThci): length: the size of ICMPv6 echo request payload """ print '%s call multicast_Ping' % self.port - print destination + print 'destination: %s' % destination try: cmd = 'ping %s %s' % (destination, str(length)) print cmd self.serial.sendline(cmd) + self.serial.expect(cmd + self.serial.linesep) + # wait echo reply + time.sleep(1) except Exception, e: ModuleHelper.WriteIntoDebugLogger("multicast_ping() Error: " + str(e)) @@ -1327,7 +1353,6 @@ class ARM(IThci): return None for index in childrenList: - print index cmd = 'child %s' % index child = [] child = self.__sendCommand(cmd) @@ -1411,7 +1436,7 @@ class ARM(IThci): for entry in childNeighbours: neighbourList.append(entry) - # get neighbouring routers + # get neighbouring routers info routerNeighbours = self.getNeighbouringRouters() if routerNeighbours != None and len(routerNeighbours) > 0: for entry in routerNeighbours: @@ -1435,7 +1460,7 @@ class ARM(IThci): cmd = 'leaderpartitionid %s' %(str(hex(partationId)).rstrip('L')) print cmd - return self.__sendCommand(cmd) == 'Done' + return self.__sendCommand(cmd)[0] == 'Done' def getGUA(self, filterByPrefix=None): """get expected global unicast IPv6 address of Thread device @@ -1489,22 +1514,33 @@ class ARM(IThci): pass def forceSetSlaac(self, slaacAddress): + """force to set a slaac IPv6 address to Thread interface + + Args: + slaacAddress: a slaac IPv6 address to be set + + Returns: + True: successful to set slaac address to Thread interface + False: fail to set slaac address to Thread interface + """ print '%s call forceSetSlaac' % self.port print slaacAddress + try: + cmd = 'ipaddr add %s' % str(slaacAddress) + print cmd + return self.__sendCommand(cmd)[0] == 'Done' + except Exception, e: + ModuleHelper.WriteIntoDebugLogger("forceSetSlaac() Error: " + str(e)) def setSleepyNodePollTime(self): pass - -# diagnostic THCI def diagnosticGet(self, strDestinationAddr, TLV_ids=0): pass def diagnosticReset(self, strDestinationAddr, iTLV_id): pass - -# commissioning THCI def startNativeCommissioner(self, strPSKc='GRLpassWord'): pass diff --git a/tools/harness-thci/README.md b/tools/harness-thci/README.md index 170236780..59d9fab6f 100644 --- a/tools/harness-thci/README.md +++ b/tools/harness-thci/README.md @@ -11,21 +11,25 @@ unit behavior. Currently Test Harness Software only supports three kinds of reference unit officially: ARM, NXP(Freescale) and SiLabs. We make OpenThread THCI be able to interact with Test Harness Software with the aid of the official THCI class -name of our partner ARM. And We are using TI CC2538DK as a target hardware platform +name of our partner ARM. And we are using TI CC2538DK as a target hardware platform for reference unit. OpenThread THCI works along with Thread Test Harness Software on Windows OS. ## Environment Setup ## -1. install or update essential module `pexpect_serial` with pip command. - Used pexpect_serial module version is 0.4.4 +1. install or update essential modules `pexpect` and `pexpect_serial` with pip command. + current `pexpect_serial` module version is 0.4.4; `pexpect` module version is 4.1.0 - > pip install pexpect_serial + * pip install pexpect - If there is already `pexpect_serial` installed, just need to upgrade it. + * pip install pexpect_serial - > pip install pexpect_serial --upgrade + If there is already `pexpect` and `pexpect_serial` installed, just need to upgrade them. + + * pip install pexpect --upgrade + + * pip install pexpect_serial --upgrade If there is no 'pip' command installed before, please follow the below instructions to install 'pip' on Windows OS first. @@ -34,16 +38,21 @@ OpenThread THCI works along with Thread Test Harness Software on Windows OS. 2). Unzip the source package and go to the pip directory then install. - > python setup.py install + * python setup.py install 3). Add "pip" executable file path in the Environment Variables. - # add "C\:Python27\Scripts" to environment variable "Path". + * add "C\:Python27\Scripts" to environment variable "Path". -2. Copy the new installed or upgraded `pexpect_serial` packages to Harness' Python2.7 directory. +2. Copy the new installed or upgraded `pexpect` and `pexpect_serial` packages to Harness' Python27 directory. - > copy C:\Python27\Lib\site-packages\pexpect_serial C:\GRL\Thread1.1\Python27\Lib\site-packages\ - > copy C:\Python27\Lib\site-packages\pexpect_serial-0.4.4-py2.7.egg-info C:\GRL\Thread1.1\Python27\Lib\site-packages\ + * copy C:\Python27\Lib\site-packages\pexpect C:\GRL\Thread1.1\Python27\Lib\site-packages\ + + * copy C:\Python27\Lib\site-packages\pexpect-4.1.0.dist-info C:\GRL\Thread1.1\Python27\Lib\site-packages\ + + * copy C:\Python27\Lib\site-packages\pexpect_serial C:\GRL\Thread1.1\Python27\Lib\site-packages\ + + * copy C:\Python27\Lib\site-packages\pexpect_serial-0.4.4-py2.7.egg-info C:\GRL\Thread1.1\Python27\Lib\site-packages\ 3. Replace the origin "ARM.py" in Harness THCI directory with OpenThread THCI python script in /tools/harness-thci (the same name "ARM.py").