From c3d2b1f8b937860fbdb00e8d92ef48ac3db6aa3a Mon Sep 17 00:00:00 2001 From: Jing Ma Date: Thu, 27 Aug 2020 09:23:33 +0800 Subject: [PATCH] [thread-cert] refactor case 9.2.17 using pktverify (#5443) --- .../scripts/thread-cert/Cert_9_2_17_Orphan.py | 46 +++++++++++++++++++ tests/scripts/thread-cert/pktverify/consts.py | 1 + .../thread-cert/pktverify/layer_fields.py | 1 + 3 files changed, 48 insertions(+) diff --git a/tests/scripts/thread-cert/Cert_9_2_17_Orphan.py b/tests/scripts/thread-cert/Cert_9_2_17_Orphan.py index ac1bd1834..765e89539 100755 --- a/tests/scripts/thread-cert/Cert_9_2_17_Orphan.py +++ b/tests/scripts/thread-cert/Cert_9_2_17_Orphan.py @@ -31,6 +31,8 @@ import unittest import config import thread_cert +from pktverify.consts import MLE_ADVERTISEMENT, MLE_PARENT_REQUEST, MLE_CHILD_ID_RESPONSE, MLE_ANNOUNCE, CHANNEL_TLV, PAN_ID_TLV, ACTIVE_TIMESTAMP_TLV +from pktverify.packet_verifier import PacketVerifier CHANNEL1 = 11 CHANNEL2 = 18 @@ -47,6 +49,7 @@ class Cert_9_2_17_Orphan(thread_cert.TestCase): TOPOLOGY = { LEADER1: { + 'name': 'LEADER_1', 'active_dataset': { 'timestamp': 10, 'panid': PANID_INIT, @@ -58,6 +61,7 @@ class Cert_9_2_17_Orphan(thread_cert.TestCase): 'whitelist': [ED1] }, LEADER2: { + 'name': 'LEADER_2', 'active_dataset': { 'timestamp': 20, 'panid': PANID_INIT, @@ -68,6 +72,7 @@ class Cert_9_2_17_Orphan(thread_cert.TestCase): 'router_selection_jitter': 1 }, ED1: { + 'name': 'ED', 'channel': CHANNEL1, 'is_mtd': True, 'mode': 'rsn', @@ -98,6 +103,47 @@ class Cert_9_2_17_Orphan(thread_cert.TestCase): self.assertEqual(self.nodes[ED1].get_state(), 'child') self.assertEqual(self.nodes[ED1].get_channel(), CHANNEL2) + self.collect_ipaddrs() + ipaddrs = self.nodes[ED1].get_addrs() + for ipaddr in ipaddrs: + self.assertTrue(self.nodes[LEADER2].ping(ipaddr)) + + def verify(self, pv): + pkts = pv.pkts + pv.summary.show() + + LEADER_1 = pv.vars['LEADER_1'] + LEADER_2 = pv.vars['LEADER_2'] + ED = pv.vars['ED'] + + # Step 1: Ensure the topology is formed correctly + # Verify that Leader_1 & Leader_2 are sending MLE Advertisements on separate channels. + pkts.filter_wpan_src64(LEADER_1).filter_mle_cmd(MLE_CHILD_ID_RESPONSE).must_next().must_verify( + lambda p: p.wpan.dst64 == ED and p.thread_meshcop.tlv.channel == CHANNEL1) + pkts.filter_wpan_src64(LEADER_1).filter_mle_cmd(MLE_ADVERTISEMENT).must_next() + pkts.copy().filter_wpan_src64(LEADER_2).filter_mle_cmd(MLE_ADVERTISEMENT).must_next() + + # Step 4: powers-down Leader_1 and enables connectivity between the ED and Leader_2 + # ED MUST send a MLE Parent Request + _epkts = pkts.filter_wpan_src64(ED) + _epkts.filter_mle_cmd(MLE_PARENT_REQUEST).must_next() + + # Step 6: ED MUST send a MLE Announce Message + # The Destination PAN ID (0xFFFF) in the IEEE 802.15.4 MAC and MUST be secured using Key ID Mode 2. + _epkts.filter_mle_cmd(MLE_ANNOUNCE).must_next().must_verify( + lambda p: {CHANNEL_TLV, PAN_ID_TLV, ACTIVE_TIMESTAMP_TLV} == set( + p.mle.tlv.type) and p.wpan.dst_pan == 0xffff and p.wpan.aux_sec.key_id_mode == 0x2) + + # Step 8: ED MUST attempt to attach on the Secondary channel, + # with the new PAN ID it received in the MLE Announce message from Leader_2 + pkts.range(_epkts.index).filter_mle_cmd(MLE_ANNOUNCE).filter_wpan_src64(LEADER_2).filter_wpan_dst64( + ED).must_next().must_verify(lambda p: p.mle.tlv.channel == CHANNEL2) + _epkts.range(pkts.index).filter_mle_cmd(MLE_PARENT_REQUEST).must_next() + + # Step 9: ED MUST respond with an ICMPv6 Echo Reply + _epkts.filter('ipv6.dst == {LEADER_2_MLEID} and ipv6.src == {ED_MLEID}', + **pv.vars).filter_ping_reply().must_next() + if __name__ == '__main__': unittest.main() diff --git a/tests/scripts/thread-cert/pktverify/consts.py b/tests/scripts/thread-cert/pktverify/consts.py index c35cd797e..a6808491d 100644 --- a/tests/scripts/thread-cert/pktverify/consts.py +++ b/tests/scripts/thread-cert/pktverify/consts.py @@ -72,6 +72,7 @@ MLE_CHILD_ID_REQUEST = 11 MLE_CHILD_ID_RESPONSE = 12 MLE_CHILD_UPDATE_REQUEST = 13 MLE_CHILD_UPDATE_RESPONSE = 14 +MLE_ANNOUNCE = 15 # COAP URIs ADDR_QRY_URI = '/a/aq' diff --git a/tests/scripts/thread-cert/pktverify/layer_fields.py b/tests/scripts/thread-cert/pktverify/layer_fields.py index 35b426916..ccc307e8a 100644 --- a/tests/scripts/thread-cert/pktverify/layer_fields.py +++ b/tests/scripts/thread-cert/pktverify/layer_fields.py @@ -281,6 +281,7 @@ _LAYER_FIELDS = { 'mle.tlv.conn.active_rtrs': _auto, 'mle.tlv.timeout': _auto, 'mle.tlv.addr16': _auto, + 'mle.tlv.channel': _auto, # IP 'ip.version': _auto,