[tests] add tests for Border Routing Counters (#8341)

This commit adds tests for verifying the functionality of the D-BUS
API `GetBorderRoutingCounters`.
This commit is contained in:
whd
2022-11-12 04:42:58 +01:00
committed by GitHub
parent 902ce1ca7f
commit caec27dcf1
4 changed files with 110 additions and 0 deletions
@@ -146,10 +146,14 @@ class TestMlr(thread_cert.TestCase):
# ping MA1 from Host could generate a reply from R1 and R2
self.assertTrue(self.nodes[HOST].ping(MA1, backbone=True, ttl=5))
self.simulator.go(WAIT_REDUNDANCE)
self.verify_border_routing_counters(self.nodes[PBBR1], {'inbound_multicast': 1, 'outbound_unicast': 1})
self.verify_border_routing_counters(self.nodes[PBBR2], {'inbound_multicast': 1, 'outbound_unicast': 1})
# ping MA2 from R1 could generate a reply from Host and R2
self.assertTrue(self.nodes[ROUTER1].ping(MA2))
self.simulator.go(WAIT_REDUNDANCE)
self.verify_border_routing_counters(self.nodes[PBBR1], {'inbound_unicast': 2, 'outbound_multicast': 1})
self.verify_border_routing_counters(self.nodes[PBBR2], {'inbound_multicast': 1, 'outbound_unicast': 1})
# ping MA2 from R1's MLE-ID shouldn't generate a reply from Host or R2
self.assertFalse(self.nodes[ROUTER1].ping(MA2, interface=self.nodes[ROUTER1].get_mleid()))
@@ -241,6 +245,13 @@ class TestMlr(thread_cert.TestCase):
# PBBR1 shouldn't forward the multicast ping request to the Backbone link
pkts.filter_eth_src(PBBR1_ETH).filter_ping_request(ping_ma2_3.icmpv6.echo.identifier).must_not_next()
def verify_border_routing_counters(self, br, expect_delta):
delta_counters = br.read_border_routing_counters_delta()
self.assertEqual(set(delta_counters.keys()), set(expect_delta.keys()))
for key in delta_counters:
self.assertGreaterEqual(delta_counters[key][0], expect_delta[key])
self.assertGreater(delta_counters[key][1], 0)
if __name__ == '__main__':
unittest.main()
@@ -146,7 +146,18 @@ class MultiThreadNetworks(thread_cert.TestCase):
self.assertTrue(len(router2.get_ip6_address(config.ADDRESS_TYPE.OMR)) == 1)
self.assertTrue(router1.ping(router2.get_ip6_address(config.ADDRESS_TYPE.OMR)[0]))
self.verify_border_routing_counters(br1, {'inbound_unicast': 1, 'outbound_unicast': 1})
self.verify_border_routing_counters(br2, {'inbound_unicast': 1, 'outbound_unicast': 1})
self.assertTrue(router2.ping(router1.get_ip6_address(config.ADDRESS_TYPE.OMR)[0]))
self.verify_border_routing_counters(br1, {'inbound_unicast': 1, 'outbound_unicast': 1})
self.verify_border_routing_counters(br2, {'inbound_unicast': 1, 'outbound_unicast': 1})
def verify_border_routing_counters(self, br, expect_delta):
delta_counters = br.read_border_routing_counters_delta()
self.assertEqual(set(delta_counters.keys()), set(expect_delta.keys()))
for key in delta_counters:
self.assertEqual(delta_counters[key][0], expect_delta[key])
self.assertGreater(delta_counters[key][1], 0)
if __name__ == '__main__':
@@ -0,0 +1,46 @@
#!/usr/bin/env python3
#
# Copyright (c) 2022, 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.
#
import dbus
import json
import sys
def main():
args = sys.argv[1:]
bus = dbus.SystemBus()
interface, method_name, arguments = args[0], args[1], args[2:]
obj = bus.get_object('io.openthread.BorderRouter.wpan0', '/io/openthread/BorderRouter/wpan0')
iface = dbus.Interface(obj, interface)
method = getattr(iface, method_name)
res = method(*arguments)
print(json.dumps(res))
if __name__ == '__main__':
main()
+42
View File
@@ -27,6 +27,7 @@
# POSSIBILITY OF SUCH DAMAGE.
#
import json
import binascii
import ipaddress
import logging
@@ -60,6 +61,7 @@ class OtbrDocker:
_socat_proc = None
_ot_rcp_proc = None
_docker_proc = None
_border_routing_counters = None
def __init__(self, nodeid: int, **kwargs):
self.verbose = int(float(os.getenv('VERBOSE', 0)))
@@ -363,6 +365,46 @@ class OtbrDocker:
return dig_result
def call_dbus_method(self, *args):
args = ' '.join(args)
return json.loads(
self.bash(f'python3 /app/third_party/openthread/repo/tests/scripts/thread-cert/call_dbus_method.py {args}')
[0])
def get_dbus_property(self, property_name):
return self.call_dbus_method('org.freedesktop.DBus.Properties', 'Get', 'io.openthread.BorderRouter',
property_name)
def get_border_routing_counters(self):
counters = self.get_dbus_property('BorderRoutingCounters')
counters = {
'inbound_unicast': counters[0],
'inbound_multicast': counters[1],
'outbound_unicast': counters[2],
'outbound_multicast': counters[3]
}
logging.info(f'counters = {counters} ')
return counters
def read_border_routing_counters_delta(self):
old_counters = self._border_routing_counters
new_counters = self.get_border_routing_counters()
self._border_routing_counters = new_counters
delta_counters = {}
if old_counters is None:
delta_counters = new_counters
else:
for i in ('inbound', 'outbound'):
for j in ('unicast', 'multicast'):
key = f'{i}_{j}'
assert (key in old_counters)
assert (key in new_counters)
value = [new_counters[key][0] - old_counters[key][0], new_counters[key][1] - old_counters[key][1]]
delta_counters[key] = value
delta_counters = {key: value for key, value in delta_counters.items() if value[0] and value[1]}
return delta_counters
@staticmethod
def __unescape_dns_instance_name(name: str) -> str:
new_name = []