mirror of
https://github.com/espressif/openthread.git
synced 2026-08-30 22:09:54 +00:00
[mlr] send BMLR.ntf on Backbone link (#5388)
This commit enhances Backbone Router to send BMLR.ntf on the backbone link for Multicast Listeners. - Send BMLR.ntf to the Backbone link - Add Backbone test with packet verification - Includes some revision to the Thread 1.2 Backbone CI scripts to make it more stable
This commit is contained in:
@@ -0,0 +1,197 @@
|
||||
#!/usr/bin/env python3
|
||||
#
|
||||
# Copyright (c) 2020, The OpenThread Authors.
|
||||
# All rights reserved.
|
||||
#
|
||||
# Redistribution and use in source and binary forms, with or without
|
||||
# modification, are permitted provided that the following conditions are met:
|
||||
# 1. Redistributions of source code must retain the above copyright
|
||||
# notice, this list of conditions and the following disclaimer.
|
||||
# 2. Redistributions in binary form must reproduce the above copyright
|
||||
# notice, this list of conditions and the following disclaimer in the
|
||||
# documentation and/or other materials provided with the distribution.
|
||||
# 3. Neither the name of the copyright holder nor the
|
||||
# names of its contributors may be used to endorse or promote products
|
||||
# derived from this software without specific prior written permission.
|
||||
#
|
||||
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 'AS IS'
|
||||
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
||||
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
# POSSIBILITY OF SUCH DAMAGE.
|
||||
#
|
||||
# This test verifies that PBBR sends BMLR.ntf correctly when multicast addresses are registered.
|
||||
#
|
||||
# Topology:
|
||||
# ---- -(eth)-------
|
||||
# | |
|
||||
# PBBR----SBBR
|
||||
# \ /
|
||||
# Router1---Commissioner
|
||||
#
|
||||
|
||||
import unittest
|
||||
|
||||
import thread_cert
|
||||
from pktverify.packet_verifier import PacketVerifier
|
||||
|
||||
PBBR = 1
|
||||
SBBR = 2
|
||||
ROUTER1 = 3
|
||||
COMMISSIONER = 4
|
||||
|
||||
REREG_DELAY = 4 # Seconds
|
||||
MLR_TIMEOUT = 300 # Seconds
|
||||
CUSTOM_MLR_TIMEOUT = 1000 # Seconds
|
||||
|
||||
MA1 = 'ff04::1'
|
||||
MA2 = 'ff04::2'
|
||||
MA3 = 'ff04::3'
|
||||
MA4 = 'ff04::4'
|
||||
MA5 = 'ff04::5'
|
||||
|
||||
|
||||
class BBR_5_11_01(thread_cert.TestCase):
|
||||
USE_MESSAGE_FACTORY = False
|
||||
|
||||
TOPOLOGY = {
|
||||
PBBR: {
|
||||
'name': 'PBBR',
|
||||
'allowlist': [SBBR, ROUTER1],
|
||||
'is_otbr': True,
|
||||
'version': '1.2',
|
||||
'router_selection_jitter': 1,
|
||||
},
|
||||
SBBR: {
|
||||
'name': 'SBBR',
|
||||
'allowlist': [PBBR, ROUTER1],
|
||||
'is_otbr': True,
|
||||
'version': '1.2',
|
||||
'router_selection_jitter': 1,
|
||||
},
|
||||
ROUTER1: {
|
||||
'name': 'ROUTER1',
|
||||
'allowlist': [PBBR, SBBR, COMMISSIONER],
|
||||
'version': '1.2',
|
||||
'router_selection_jitter': 1,
|
||||
},
|
||||
COMMISSIONER: {
|
||||
'name': 'COMMISSIONER',
|
||||
'allowlist': [ROUTER1],
|
||||
'version': '1.2',
|
||||
'router_selection_jitter': 1,
|
||||
}
|
||||
}
|
||||
|
||||
def test(self):
|
||||
self.nodes[PBBR].start()
|
||||
self.wait_node_state(PBBR, 'leader', 5)
|
||||
self.nodes[PBBR].set_backbone_router(reg_delay=REREG_DELAY, mlr_timeout=MLR_TIMEOUT)
|
||||
self.nodes[PBBR].enable_backbone_router()
|
||||
self.wait_until(lambda: self.nodes[PBBR].is_primary_backbone_router, 5)
|
||||
|
||||
self.nodes[SBBR].start()
|
||||
self.wait_node_state(SBBR, 'router', 5)
|
||||
self.nodes[SBBR].set_backbone_router(reg_delay=REREG_DELAY, mlr_timeout=MLR_TIMEOUT)
|
||||
self.nodes[SBBR].enable_backbone_router()
|
||||
self.simulator.go(5)
|
||||
self.assertFalse(self.nodes[SBBR].is_primary_backbone_router)
|
||||
|
||||
self.nodes[ROUTER1].start()
|
||||
self.wait_node_state(ROUTER1, 'router', 5)
|
||||
|
||||
self.nodes[COMMISSIONER].start()
|
||||
self.wait_node_state(COMMISSIONER, 'router', 5)
|
||||
|
||||
self.nodes[COMMISSIONER].commissioner_start()
|
||||
self.simulator.go(10)
|
||||
self.assertEqual('active', self.nodes[COMMISSIONER].commissioner_state())
|
||||
|
||||
self.nodes[PBBR].add_ipmaddr(MA1)
|
||||
self.simulator.go(REREG_DELAY)
|
||||
self.nodes[ROUTER1].add_ipmaddr(MA2)
|
||||
self.simulator.go(REREG_DELAY)
|
||||
|
||||
# Commissioner registers MA3 with default timeout
|
||||
self.assertEqual((0, []), self.nodes[COMMISSIONER].register_multicast_listener(MA3, timeout=None))
|
||||
# Commissioner registers MA4 with a custom timeout
|
||||
self.assertEqual((0, []), self.nodes[COMMISSIONER].register_multicast_listener(MA4,
|
||||
timeout=CUSTOM_MLR_TIMEOUT))
|
||||
# Commissioner unregisters MA5
|
||||
self.assertEqual((0, []), self.nodes[COMMISSIONER].register_multicast_listener(MA5, timeout=0))
|
||||
|
||||
self.collect_ipaddrs()
|
||||
self.collect_rloc16s()
|
||||
|
||||
def verify(self, pv: PacketVerifier):
|
||||
pkts = pv.pkts
|
||||
pv.add_common_vars()
|
||||
pv.summary.show()
|
||||
pv.verify_attached('ROUTER1')
|
||||
|
||||
ROUTER1 = pv.vars['ROUTER1']
|
||||
COMMISSIONER = pv.vars['COMMISSIONER']
|
||||
PBBR_ETH = pv.vars['PBBR_ETH']
|
||||
SBBR_ETH = pv.vars['SBBR_ETH']
|
||||
|
||||
# Verify SBBR must not send `/b/bmr` during the test.
|
||||
pkts.filter_eth_src(SBBR_ETH).filter_coap_request('/b/bmr').must_not_next()
|
||||
|
||||
# Verify PBBR sends `/b/bmr` on the Backbone link for MA1 with default timeout.
|
||||
pkts.filter_eth_src(PBBR_ETH).filter_coap_request('/b/bmr').must_next().must_verify(f"""
|
||||
thread_meshcop.tlv.ipv6_addr == ['{MA1}']
|
||||
and thread_bl.tlv.timeout == {MLR_TIMEOUT}
|
||||
""")
|
||||
|
||||
# Router registers MA2 with default timeout
|
||||
pkts.filter_wpan_src64(ROUTER1).filter_coap_request('/n/mr').must_next().must_verify(f"""
|
||||
thread_meshcop.tlv.ipv6_addr == ['{MA2}']
|
||||
and thread_bl.tlv.timeout is null
|
||||
""")
|
||||
# Verify PBBR sends `/b/bmr` on the Backbone link for MA2 with default timeout.
|
||||
pkts.filter_eth_src(PBBR_ETH).filter_coap_request('/b/bmr').must_next().must_verify(f"""
|
||||
thread_meshcop.tlv.ipv6_addr == ['{MA2}']
|
||||
and thread_bl.tlv.timeout == {MLR_TIMEOUT}
|
||||
""")
|
||||
|
||||
# Commissioner registers MA3 with deafult timeout
|
||||
pkts.filter_wpan_src64(COMMISSIONER).filter_coap_request('/n/mr').must_next().must_verify(f"""
|
||||
thread_meshcop.tlv.ipv6_addr == ['{MA3}']
|
||||
and thread_bl.tlv.timeout is null
|
||||
""")
|
||||
# Verify PBBR sends `/b/bmr` on the Backbone link for MA3 with default timeout.
|
||||
pkts.filter_eth_src(PBBR_ETH).filter_coap_request('/b/bmr').must_next().must_verify(f"""
|
||||
thread_meshcop.tlv.ipv6_addr == ['{MA3}']
|
||||
and thread_bl.tlv.timeout == {MLR_TIMEOUT}
|
||||
""")
|
||||
|
||||
# Commissioner registers MA4 with custom timeout
|
||||
pkts.filter_wpan_src64(COMMISSIONER).filter_coap_request('/n/mr').must_next().must_verify(f"""
|
||||
thread_meshcop.tlv.ipv6_addr == ['{MA4}']
|
||||
and thread_nm.tlv.timeout == {CUSTOM_MLR_TIMEOUT}
|
||||
""")
|
||||
# Verify PBBR sends `/b/bmr` on the Backbone link for MA4 with custom timeout.
|
||||
pkts.filter_eth_src(PBBR_ETH).filter_coap_request('/b/bmr').must_next().must_verify(f"""
|
||||
thread_meshcop.tlv.ipv6_addr == ['{MA4}']
|
||||
and thread_bl.tlv.timeout == {CUSTOM_MLR_TIMEOUT}
|
||||
""")
|
||||
|
||||
# Commissioner unregisters MA5
|
||||
pkts.filter_wpan_src64(COMMISSIONER).filter_coap_request('/n/mr').must_next().must_verify(f"""
|
||||
thread_meshcop.tlv.ipv6_addr == ['{MA5}']
|
||||
and thread_nm.tlv.timeout == 0
|
||||
""")
|
||||
# Verify PBBR not sends `/b/bmr` on the Backbone link for MA5.
|
||||
pkts.filter_eth_src(PBBR_ETH).filter_coap_request('/b/bmr').filter(f"""
|
||||
thread_meshcop.tlv.ipv6_addr == ['{MA5}']
|
||||
""").must_not_next()
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
@@ -67,6 +67,7 @@ PORT_OFFSET = int(os.getenv('PORT_OFFSET', '0'))
|
||||
BACKBONE_PREFIX = f'{0x9100 + PORT_OFFSET:04x}::/64'
|
||||
BACKBONE_PREFIX_REGEX_PATTERN = f'^{0x9100 + PORT_OFFSET:04x}:'
|
||||
BACKBONE_DOCKER_NETWORK_NAME = f'backbone{PORT_OFFSET}'
|
||||
BACKBONE_IFNAME = 'eth0'
|
||||
|
||||
OTBR_DOCKER_IMAGE = os.getenv('OTBR_DOCKER_IMAGE', 'otbr-ot12-backbone-ci')
|
||||
OTBR_DOCKER_NAME_PREFIX = f'otbr_{PORT_OFFSET}_'
|
||||
|
||||
@@ -105,13 +105,17 @@ class OtbrDocker:
|
||||
'--cap-add=NET_ADMIN',
|
||||
'--volume',
|
||||
f'{self._rcp_device}:/dev/ttyUSB0',
|
||||
'-v',
|
||||
'/tmp/codecov.bash:/tmp/codecov.bash',
|
||||
config.OTBR_DOCKER_IMAGE,
|
||||
'-B',
|
||||
config.BACKBONE_IFNAME,
|
||||
],
|
||||
stdin=subprocess.DEVNULL,
|
||||
stdout=sys.stdout,
|
||||
stderr=sys.stderr)
|
||||
|
||||
launch_docker_deadline = time.time() + 60
|
||||
launch_docker_deadline = time.time() + 300
|
||||
launch_ok = False
|
||||
|
||||
while time.time() < launch_docker_deadline:
|
||||
@@ -121,7 +125,7 @@ class OtbrDocker:
|
||||
logging.info("OTBR Docker %s Is Ready!", self._docker_name)
|
||||
break
|
||||
except subprocess.CalledProcessError:
|
||||
time.sleep(0.2)
|
||||
time.sleep(5)
|
||||
continue
|
||||
|
||||
assert launch_ok
|
||||
@@ -155,8 +159,7 @@ class OtbrDocker:
|
||||
if COVERAGE or OTBR_COVERAGE:
|
||||
self.bash('service otbr-agent stop')
|
||||
|
||||
self.bash('curl https://codecov.io/bash -o codecov_bash --retry 5')
|
||||
codecov_cmd = 'bash codecov_bash -Z'
|
||||
codecov_cmd = 'bash /tmp/codecov.bash -Z'
|
||||
# Upload OTBR code coverage if OTBR_COVERAGE=1, otherwise OpenThread code coverage.
|
||||
if not OTBR_COVERAGE:
|
||||
codecov_cmd += ' -R third_party/openthread/repo'
|
||||
@@ -381,9 +384,6 @@ class OtCli:
|
||||
serialPort = '/dev/ttyUSB%d' % ((nodeid - 1) * 2)
|
||||
self.pexpect = fdpexpect.fdspawn(os.open(serialPort, os.O_RDWR | os.O_NONBLOCK | os.O_NOCTTY))
|
||||
|
||||
def __del__(self):
|
||||
self.destroy()
|
||||
|
||||
def destroy(self):
|
||||
if not self._initialized:
|
||||
return
|
||||
@@ -609,6 +609,11 @@ class NodeImpl:
|
||||
self.send_command(cmd)
|
||||
self._expect('Done')
|
||||
|
||||
def commissioner_state(self):
|
||||
states = [r'disabled', r'petitioning', r'active']
|
||||
self.send_command('commissioner state')
|
||||
return self._expect_result(states)
|
||||
|
||||
def commissioner_add_joiner(self, addr, psk):
|
||||
cmd = 'commissioner joiner add %s %s' % (addr, psk)
|
||||
self.send_command(cmd)
|
||||
@@ -1904,7 +1909,7 @@ class Node(NodeImpl, OtCli):
|
||||
|
||||
class LinuxHost():
|
||||
PING_RESPONSE_PATTERN = re.compile(r'\d+ bytes from .*:.*')
|
||||
ETH_DEV = 'eth0'
|
||||
ETH_DEV = config.BACKBONE_IFNAME
|
||||
|
||||
def get_ether_addrs(self):
|
||||
output = self.bash(f'ip -6 addr list dev {self.ETH_DEV}')
|
||||
|
||||
@@ -43,7 +43,6 @@ class PcapCodec(object):
|
||||
def __init__(self, filename):
|
||||
self._pcap_file = open('%s.pcap' % filename, 'wb')
|
||||
self._pcap_file.write(self.encode_header())
|
||||
self._epoch = time.time()
|
||||
|
||||
def encode_header(self):
|
||||
""" Returns a pcap file header. """
|
||||
@@ -68,7 +67,7 @@ class PcapCodec(object):
|
||||
|
||||
def _get_timestamp(self):
|
||||
""" Returns the internal timestamp. """
|
||||
timestamp = time.time() - self._epoch
|
||||
timestamp = time.time()
|
||||
timestamp_sec = int(timestamp)
|
||||
timestamp_usec = int((timestamp - timestamp_sec) * 1000000)
|
||||
return timestamp_sec, timestamp_usec
|
||||
|
||||
@@ -510,11 +510,13 @@ _LAYER_FIELDS = {
|
||||
'thread_bl.tlv.target_eid': _ipv6_addr,
|
||||
'thread_bl.tlv.ml_eid': _ext_addr,
|
||||
'thread_bl.tlv.last_transaction_time': _auto,
|
||||
'thread_bl.tlv.timeout': _auto,
|
||||
# THEAD NM
|
||||
'thread_nm.tlv.type': _list(_auto),
|
||||
'thread_nm.tlv.ml_eid': _ext_addr,
|
||||
'thread_nm.tlv.target_eid': _ipv6_addr,
|
||||
'thread_nm.tlv.status': _auto,
|
||||
'thread_nm.tlv.timeout': _auto,
|
||||
# thread_meshcop is not a real layer
|
||||
'thread_meshcop.len_size_mismatch': _str,
|
||||
'thread_meshcop.tlv.type': _list(_auto),
|
||||
@@ -544,6 +546,7 @@ _LAYER_FIELDS = {
|
||||
'thread_meshcop.tlv.unknown': _bytes,
|
||||
'thread_meshcop.tlv.ba_locator': _auto,
|
||||
'thread_meshcop.tlv.active_tstamp': _auto,
|
||||
'thread_meshcop.tlv.ipv6_addr': _list(_ipv6_addr),
|
||||
|
||||
# THREAD NWD
|
||||
'thread_nwd.tlv.type': _list(_auto),
|
||||
@@ -668,7 +671,7 @@ def check_layer_field_exists(packet, field_uri):
|
||||
|
||||
def _get_candidate_layers(packet, layer_name):
|
||||
if layer_name == 'thread_meshcop':
|
||||
candidate_layer_names = ['thread_meshcop', 'mle', 'coap', 'thread_bl']
|
||||
candidate_layer_names = ['thread_meshcop', 'mle', 'coap', 'thread_bl', 'thread_nm']
|
||||
elif layer_name == 'thread_nwd':
|
||||
candidate_layer_names = ['mle', 'thread_address']
|
||||
elif layer_name == 'wpan':
|
||||
|
||||
@@ -86,7 +86,8 @@ def cleanup_env():
|
||||
|
||||
def setup_env():
|
||||
bash(f'docker image inspect {config.OTBR_DOCKER_IMAGE} >/dev/null')
|
||||
bash('mkdir build || true')
|
||||
# Download codecov bash to be used for OTBR Dockers
|
||||
bash('curl -L https://codecov.io/bash -o /tmp/codecov.bash --retry 5')
|
||||
|
||||
|
||||
def parse_args():
|
||||
|
||||
@@ -36,7 +36,7 @@ import sys
|
||||
import time
|
||||
import traceback
|
||||
import unittest
|
||||
from typing import Optional
|
||||
from typing import Optional, Callable
|
||||
|
||||
import config
|
||||
import debug
|
||||
@@ -474,3 +474,17 @@ class TestCase(NcpSupportMixin, unittest.TestCase):
|
||||
mergecap = pvutils.which_mergecap()
|
||||
self.assure_run_ok(f'{mergecap} -w {merged_pcap} {thread_pcap} {backbone_pcap}', shell=True)
|
||||
return merged_pcap
|
||||
|
||||
def wait_until(self, cond: Callable[[], bool], timeout: int, go_interval: int = 1):
|
||||
while True:
|
||||
self.simulator.go(go_interval)
|
||||
|
||||
if cond():
|
||||
break
|
||||
|
||||
timeout -= go_interval
|
||||
if timeout <= 0:
|
||||
raise RuntimeError(f'wait failed after {timeout} seconds')
|
||||
|
||||
def wait_node_state(self, nodeid: int, state: str, timeout: int):
|
||||
self.wait_until(lambda: self.nodes[nodeid].get_state() == state, timeout)
|
||||
|
||||
Reference in New Issue
Block a user