mirror of
https://github.com/espressif/openthread.git
synced 2026-07-25 05:24:08 +00:00
[tests] add traffic analysis for Cert_5_2_05_AddressQuery.py (#2173)
Add a fuction in node.py node_cli.py to node's address. Add a module command to verify commands. Spinel-cli.py doesn't request address for dhcp prefix now, so put Cert_5_2_05_AddressQuery.py in XFAIL on ncp.
This commit is contained in:
@@ -31,6 +31,9 @@ import os
|
||||
import sys
|
||||
import time
|
||||
import pexpect
|
||||
import re
|
||||
|
||||
import config
|
||||
|
||||
class otCli:
|
||||
def __init__(self, nodeid, is_mtd):
|
||||
@@ -83,7 +86,7 @@ class otCli:
|
||||
time.sleep(0.2)
|
||||
self.pexpect.expect('spinel-cli >')
|
||||
self.debug(int(os.getenv('DEBUG', '0')))
|
||||
|
||||
|
||||
def __init_soc(self, nodeid):
|
||||
""" Initialize a System-on-a-chip node connected via UART. """
|
||||
import fdpexpect
|
||||
@@ -98,7 +101,7 @@ class otCli:
|
||||
self.pexpect.close(force=True)
|
||||
|
||||
def send_command(self, cmd):
|
||||
print ("%d: %s" % (self.nodeid, cmd))
|
||||
print("%d: %s" % (self.nodeid, cmd))
|
||||
self.pexpect.sendline(cmd)
|
||||
|
||||
def get_commands(self):
|
||||
@@ -136,7 +139,7 @@ class otCli:
|
||||
def thread_stop(self):
|
||||
self.send_command('thread stop')
|
||||
self.pexpect.expect('Done')
|
||||
|
||||
|
||||
def commissioner_start(self):
|
||||
cmd = 'commissioner start'
|
||||
self.send_command(cmd)
|
||||
@@ -372,6 +375,67 @@ class otCli:
|
||||
|
||||
return addrs
|
||||
|
||||
def __getLinkLocalAddress(self):
|
||||
for ip6Addr in self.get_addrs():
|
||||
if re.match(config.LINK_LOCAL_REGEX_PATTERN, ip6Addr, re.I):
|
||||
return ip6Addr
|
||||
|
||||
return None
|
||||
|
||||
def __getGlobalAddress(self):
|
||||
global_address = []
|
||||
for ip6Addr in self.get_addrs():
|
||||
if (not re.match(config.LINK_LOCAL_REGEX_PATTERN, ip6Addr, re.I)) and \
|
||||
(not re.match(config.MESH_LOCAL_PREFIX_REGEX_PATTERN, ip6Addr, re.I)) and \
|
||||
(not re.match(config.ROUTING_LOCATOR_REGEX_PATTERN, ip6Addr, re.I)):
|
||||
global_address.append(ip6Addr)
|
||||
|
||||
return global_address
|
||||
|
||||
def __getRloc(self):
|
||||
for ip6Addr in self.get_addrs():
|
||||
if re.match(config.MESH_LOCAL_PREFIX_REGEX_PATTERN, ip6Addr, re.I) and \
|
||||
re.match(config.ROUTING_LOCATOR_REGEX_PATTERN, ip6Addr, re.I) and \
|
||||
not(re.match(config.ALOC_FLAG_REGEX_PATTERN, ip6Addr, re.I)):
|
||||
return ip6Addr
|
||||
return None
|
||||
|
||||
def __getAloc(self):
|
||||
aloc = []
|
||||
for ip6Addr in self.get_addrs():
|
||||
if re.match(config.MESH_LOCAL_PREFIX_REGEX_PATTERN, ip6Addr, re.I) and \
|
||||
re.match(config.ROUTING_LOCATOR_REGEX_PATTERN, ip6Addr, re.I) and \
|
||||
re.match(config.ALOC_FLAG_REGEX_PATTERN, ip6Addr, re.I):
|
||||
aloc.append(ip6Addr)
|
||||
|
||||
return aloc
|
||||
|
||||
def __getMleid(self):
|
||||
for ip6Addr in self.get_addrs():
|
||||
if re.match(config.MESH_LOCAL_PREFIX_REGEX_PATTERN, ip6Addr, re.I) and \
|
||||
not(re.match(config.ROUTING_LOCATOR_REGEX_PATTERN, ip6Addr, re.I)):
|
||||
return ip6Addr
|
||||
|
||||
return None
|
||||
|
||||
def get_ip6_address(self, address_type):
|
||||
"""Get specific type of IPv6 address configured on thread device.
|
||||
|
||||
Args:
|
||||
address_type: the config.ADDRESS_TYPE type of IPv6 address.
|
||||
|
||||
Returns:
|
||||
IPv6 address string.
|
||||
"""
|
||||
switcher = {
|
||||
config.ADDRESS_TYPE.LINK_LOCAL: self.__getLinkLocalAddress(),
|
||||
config.ADDRESS_TYPE.GLOBAL: self.__getGlobalAddress(),
|
||||
config.ADDRESS_TYPE.RLOC: self.__getRloc(),
|
||||
config.ADDRESS_TYPE.ALOC: self.__getAloc(),
|
||||
config.ADDRESS_TYPE.ML_EID: self.__getMleid()
|
||||
}
|
||||
return switcher.get(address_type, None)
|
||||
|
||||
def get_context_reuse_delay(self):
|
||||
self.send_command('contextreusedelay')
|
||||
i = self.pexpect.expect('(\d+)\r\n')
|
||||
|
||||
Reference in New Issue
Block a user