mirror of
https://github.com/espressif/openthread.git
synced 2026-08-19 00:49:53 +00:00
[thread-cert] support to get link-local address of the infra interface (#10603)
This commit targets to support getting infra link-local address of a OtbrNode in docker test, which is usefully for future test cases. The test_multi_ail.py is also updated to test the new method added.
This commit is contained in:
@@ -33,6 +33,8 @@ import ipaddress
|
||||
import config
|
||||
import thread_cert
|
||||
|
||||
from node import OtbrNode
|
||||
|
||||
IPV4_CIDR_ADDR_CMD = f'ip addr show {config.BACKBONE_IFNAME} | grep -w inet | grep -Eo "[0-9.]+/[0-9]+"'
|
||||
|
||||
|
||||
@@ -70,8 +72,8 @@ class TwoBorderRoutersOnTwoInfrastructures(thread_cert.TestCase):
|
||||
}
|
||||
|
||||
def test(self):
|
||||
br1 = self.nodes[self.BR1]
|
||||
br2 = self.nodes[self.BR2]
|
||||
br1: OtbrNode = self.nodes[self.BR1]
|
||||
br2: OtbrNode = self.nodes[self.BR2]
|
||||
|
||||
# start nodes
|
||||
br1.start()
|
||||
@@ -92,9 +94,19 @@ class TwoBorderRoutersOnTwoInfrastructures(thread_cert.TestCase):
|
||||
self.assertNotEqual(ipaddress.ip_network(br1_infra_ip_addr[0].strip(), strict=False),
|
||||
ipaddress.ip_network(br2_infra_ip_addr[0].strip(), strict=False))
|
||||
|
||||
# ping each other
|
||||
self.assertTrue(br1.ping(br2.get_ip6_address(config.ADDRESS_TYPE.ML_EID)))
|
||||
self.assertTrue(br2.ping(br1.get_ip6_address(config.ADDRESS_TYPE.ML_EID)))
|
||||
# Ping test
|
||||
br1_thread_link_local = br1.get_ip6_address(config.ADDRESS_TYPE.LINK_LOCAL)
|
||||
br2_thread_link_local = br2.get_ip6_address(config.ADDRESS_TYPE.LINK_LOCAL)
|
||||
br1_infra_link_local = br1.get_ip6_address(config.ADDRESS_TYPE.BACKBONE_LINK_LOCAL)
|
||||
br2_infra_link_local = br2.get_ip6_address(config.ADDRESS_TYPE.BACKBONE_LINK_LOCAL)
|
||||
|
||||
# ping each other using Thread link-local address
|
||||
self.assertTrue(br1.ping(br2_thread_link_local))
|
||||
self.assertTrue(br2.ping(br1_thread_link_local))
|
||||
|
||||
# ping each other using Infra link-local address
|
||||
self.assertFalse(br1.ping(br2_infra_link_local, interface=br1_infra_link_local))
|
||||
self.assertFalse(br2.ping(br1_infra_link_local, interface=br2_infra_link_local))
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
||||
@@ -106,13 +106,14 @@ DEFAULT_NETWORK_KEY = bytearray([
|
||||
|
||||
|
||||
class ADDRESS_TYPE(Enum):
|
||||
LINK_LOCAL = 'LINK_LOCAL'
|
||||
LINK_LOCAL = 'LINK_LOCAL' # For Thread interface link-local only
|
||||
GLOBAL = 'GLOBAL'
|
||||
RLOC = 'RLOC'
|
||||
ALOC = 'ALOC'
|
||||
ML_EID = 'ML_EID'
|
||||
DUA = 'DUA'
|
||||
BACKBONE_GUA = 'BACKBONE_GUA'
|
||||
BACKBONE_LINK_LOCAL = 'BACKBONE_LINK_LOCAL'
|
||||
OMR = 'OMR'
|
||||
ONLINK_ULA = 'ONLINK_ULA'
|
||||
ONLINK_GUA = 'ONLINK_GUA'
|
||||
|
||||
@@ -3804,6 +3804,8 @@ class LinuxHost():
|
||||
"""
|
||||
if address_type == config.ADDRESS_TYPE.BACKBONE_GUA:
|
||||
return self._getBackboneGua()
|
||||
elif address_type == config.ADDRESS_TYPE.BACKBONE_LINK_LOCAL:
|
||||
return self._getInfraLinkLocalAddress()
|
||||
elif address_type == config.ADDRESS_TYPE.ONLINK_ULA:
|
||||
return self._getInfraUla()
|
||||
elif address_type == config.ADDRESS_TYPE.ONLINK_GUA:
|
||||
@@ -3835,6 +3837,15 @@ class LinuxHost():
|
||||
gua_prefix = config.ONLINK_GUA_PREFIX.split('::/')[0]
|
||||
return [addr for addr in self.get_ether_addrs() if addr.startswith(gua_prefix)]
|
||||
|
||||
def _getInfraLinkLocalAddress(self) -> Optional[str]:
|
||||
""" Returns the link-local address autoconfigured on the infra link, which is started with "fe80".
|
||||
"""
|
||||
for addr in self.get_ether_addrs():
|
||||
if re.match(config.LINK_LOCAL_REGEX_PATTERN, addr, re.I):
|
||||
return addr
|
||||
|
||||
return None
|
||||
|
||||
def ping(self, *args, **kwargs):
|
||||
backbone = kwargs.pop('backbone', False)
|
||||
if backbone:
|
||||
|
||||
Reference in New Issue
Block a user