mirror of
https://github.com/espressif/openthread.git
synced 2026-09-03 15:50:06 +00:00
[thread-cert] refactor case 9.2.15 and 9.2.16 using pktverify (#5439)
This commit is contained in:
@@ -30,6 +30,8 @@
|
||||
import unittest
|
||||
|
||||
import thread_cert
|
||||
from pktverify.consts import MLE_ADVERTISEMENT, MLE_PARENT_REQUEST, MLE_CHILD_ID_RESPONSE, MLE_CHILD_ID_REQUEST, MGMT_ACTIVE_SET_URI, MGMT_ACTIVE_GET_URI, RESPONSE_TLV, LINK_LAYER_FRAME_COUNTER_TLV, MODE_TLV, TIMEOUT_TLV, VERSION_TLV, TLV_REQUEST_TLV, CHALLENGE_TLV, SCAN_MASK_TLV, ADDRESS_REGISTRATION_TLV
|
||||
from pktverify.packet_verifier import PacketVerifier
|
||||
|
||||
CHANNEL_INIT = 19
|
||||
PANID_INIT = 0xface
|
||||
@@ -47,6 +49,7 @@ class Cert_9_2_15_PendingPartition(thread_cert.TestCase):
|
||||
|
||||
TOPOLOGY = {
|
||||
COMMISSIONER: {
|
||||
'name': 'COMMISSIONER',
|
||||
'active_dataset': {
|
||||
'timestamp': 15,
|
||||
'panid': PANID_INIT,
|
||||
@@ -57,6 +60,7 @@ class Cert_9_2_15_PendingPartition(thread_cert.TestCase):
|
||||
'whitelist': [LEADER]
|
||||
},
|
||||
LEADER: {
|
||||
'name': 'LEADER',
|
||||
'active_dataset': {
|
||||
'timestamp': 15,
|
||||
'panid': PANID_INIT,
|
||||
@@ -68,6 +72,7 @@ class Cert_9_2_15_PendingPartition(thread_cert.TestCase):
|
||||
'whitelist': [COMMISSIONER, ROUTER1]
|
||||
},
|
||||
ROUTER1: {
|
||||
'name': 'ROUTER_1',
|
||||
'active_dataset': {
|
||||
'timestamp': 15,
|
||||
'panid': PANID_INIT,
|
||||
@@ -78,6 +83,7 @@ class Cert_9_2_15_PendingPartition(thread_cert.TestCase):
|
||||
'whitelist': [LEADER, ROUTER2]
|
||||
},
|
||||
ROUTER2: {
|
||||
'name': 'ROUTER_2',
|
||||
'active_dataset': {
|
||||
'timestamp': 15,
|
||||
'panid': PANID_INIT,
|
||||
@@ -131,7 +137,7 @@ class Cert_9_2_15_PendingPartition(thread_cert.TestCase):
|
||||
mesh_local='fd00:0db7::',
|
||||
panid=PANID_FINAL,
|
||||
)
|
||||
self.simulator.go(100)
|
||||
self.simulator.go(101)
|
||||
|
||||
self.nodes[ROUTER2].start()
|
||||
self.simulator.go(5)
|
||||
@@ -149,6 +155,46 @@ class Cert_9_2_15_PendingPartition(thread_cert.TestCase):
|
||||
break
|
||||
self.assertTrue(self.nodes[LEADER].ping(ipaddr))
|
||||
|
||||
def verify(self, pv):
|
||||
pkts = pv.pkts
|
||||
pv.summary.show()
|
||||
|
||||
LEADER = pv.vars['LEADER']
|
||||
COMMISSIONER = pv.vars['COMMISSIONER']
|
||||
ROUTER_1 = pv.vars['ROUTER_1']
|
||||
ROUTER_2 = pv.vars['ROUTER_2']
|
||||
_router2_pkts = pkts.filter_wpan_src64(ROUTER_2)
|
||||
|
||||
# Step 1: Ensure the topology is formed correctly
|
||||
# Verify Commissioner, Leader and Router_1 are sending MLE advertisements
|
||||
pkts.copy().filter_wpan_src64(LEADER).filter_mle_cmd(MLE_ADVERTISEMENT).must_next()
|
||||
pkts.filter_wpan_dst64(COMMISSIONER).filter_mle_cmd(MLE_CHILD_ID_RESPONSE).must_next()
|
||||
pkts.copy().filter_wpan_src64(COMMISSIONER).filter_mle_cmd(MLE_ADVERTISEMENT).must_next()
|
||||
pkts.filter_wpan_dst64(ROUTER_1).filter_mle_cmd(MLE_CHILD_ID_RESPONSE).must_next()
|
||||
pkts.copy().filter_wpan_src64(ROUTER_1).filter_mle_cmd(MLE_ADVERTISEMENT).must_next()
|
||||
|
||||
# Step 5: Router_2 begins attach process by sending a multicast MLE Parent Request
|
||||
# The first MLE Parent Request sent MUST NOT be sent to all routers and REEDS
|
||||
_router2_pkts.range(pkts.index).filter_mle_cmd(MLE_PARENT_REQUEST).must_next().must_verify(
|
||||
lambda p: {MODE_TLV, CHALLENGE_TLV, SCAN_MASK_TLV, VERSION_TLV} == set(
|
||||
p.mle.tlv.type) and p.mle.tlv.scan_mask.r == 1 and p.mle.tlv.scan_mask.e == 0)
|
||||
|
||||
# Step 7: Router_2 MUST send a MLE Child ID Request to Router_1
|
||||
_router2_pkts.filter_mle_cmd(MLE_CHILD_ID_REQUEST).must_next().must_verify(lambda p: {
|
||||
RESPONSE_TLV, LINK_LAYER_FRAME_COUNTER_TLV, MODE_TLV, TIMEOUT_TLV, VERSION_TLV, TLV_REQUEST_TLV
|
||||
} < set(p.mle.tlv.type) and ADDRESS_REGISTRATION_TLV not in p.mle.tlv.type)
|
||||
|
||||
# Step 14: Router_2 begins attach process by sending a multicast MLE Parent Request
|
||||
# The first MLE Parent Request sent MUST NOT be sent to all routers and REEDS
|
||||
_router2_pkts.filter_mle_cmd(MLE_PARENT_REQUEST).must_next().must_verify(
|
||||
lambda p: {MODE_TLV, CHALLENGE_TLV, SCAN_MASK_TLV, VERSION_TLV} == set(
|
||||
p.mle.tlv.type) and p.mle.tlv.scan_mask.r == 1 and p.mle.tlv.scan_mask.e == 0)
|
||||
|
||||
# Step 16: Router_2 MUST send a MLE Child ID Request to Router_1
|
||||
_router2_pkts.filter_mle_cmd(MLE_CHILD_ID_REQUEST).must_next().must_verify(lambda p: {
|
||||
RESPONSE_TLV, LINK_LAYER_FRAME_COUNTER_TLV, MODE_TLV, TIMEOUT_TLV, VERSION_TLV, TLV_REQUEST_TLV
|
||||
} < set(p.mle.tlv.type) and ADDRESS_REGISTRATION_TLV not in p.mle.tlv.type)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
||||
@@ -30,6 +30,8 @@
|
||||
import unittest
|
||||
|
||||
import thread_cert
|
||||
from pktverify.consts import MLE_ADVERTISEMENT, MLE_PARENT_REQUEST, MLE_CHILD_ID_RESPONSE, MLE_CHILD_ID_REQUEST, MGMT_ACTIVE_SET_URI, MGMT_ACTIVE_GET_URI, RESPONSE_TLV, LINK_LAYER_FRAME_COUNTER_TLV, MODE_TLV, TIMEOUT_TLV, VERSION_TLV, TLV_REQUEST_TLV, CHALLENGE_TLV, SCAN_MASK_TLV, ADDRESS_REGISTRATION_TLV
|
||||
from pktverify.packet_verifier import PacketVerifier
|
||||
|
||||
CHANNEL_INIT = 19
|
||||
PANID_INIT = 0xface
|
||||
@@ -48,6 +50,7 @@ class Cert_9_2_16_ActivePendingPartition(thread_cert.TestCase):
|
||||
|
||||
TOPOLOGY = {
|
||||
COMMISSIONER: {
|
||||
'name': 'COMMISSIONER',
|
||||
'active_dataset': {
|
||||
'timestamp': 1,
|
||||
'panid': PANID_INIT,
|
||||
@@ -58,6 +61,7 @@ class Cert_9_2_16_ActivePendingPartition(thread_cert.TestCase):
|
||||
'whitelist': [LEADER]
|
||||
},
|
||||
LEADER: {
|
||||
'name': 'LEADER',
|
||||
'active_dataset': {
|
||||
'timestamp': 1,
|
||||
'panid': PANID_INIT,
|
||||
@@ -69,6 +73,7 @@ class Cert_9_2_16_ActivePendingPartition(thread_cert.TestCase):
|
||||
'whitelist': [COMMISSIONER, ROUTER1]
|
||||
},
|
||||
ROUTER1: {
|
||||
'name': 'ROUTER_1',
|
||||
'active_dataset': {
|
||||
'timestamp': 1,
|
||||
'panid': PANID_INIT,
|
||||
@@ -79,6 +84,7 @@ class Cert_9_2_16_ActivePendingPartition(thread_cert.TestCase):
|
||||
'whitelist': [LEADER, ROUTER2]
|
||||
},
|
||||
ROUTER2: {
|
||||
'name': 'ROUTER_2',
|
||||
'active_dataset': {
|
||||
'timestamp': 1,
|
||||
'panid': PANID_INIT,
|
||||
@@ -159,6 +165,46 @@ class Cert_9_2_16_ActivePendingPartition(thread_cert.TestCase):
|
||||
break
|
||||
self.assertTrue(self.nodes[LEADER].ping(ipaddr))
|
||||
|
||||
def verify(self, pv):
|
||||
pkts = pv.pkts
|
||||
pv.summary.show()
|
||||
|
||||
LEADER = pv.vars['LEADER']
|
||||
COMMISSIONER = pv.vars['COMMISSIONER']
|
||||
ROUTER_1 = pv.vars['ROUTER_1']
|
||||
ROUTER_2 = pv.vars['ROUTER_2']
|
||||
_router2_pkts = pkts.filter_wpan_src64(ROUTER_2)
|
||||
|
||||
# Step 1: Ensure the topology is formed correctly
|
||||
# Verify Commissioner, Leader and Router_1 are sending MLE advertisements
|
||||
pkts.copy().filter_wpan_src64(LEADER).filter_mle_cmd(MLE_ADVERTISEMENT).must_next()
|
||||
pkts.filter_wpan_dst64(COMMISSIONER).filter_mle_cmd(MLE_CHILD_ID_RESPONSE).must_next()
|
||||
pkts.copy().filter_wpan_src64(COMMISSIONER).filter_mle_cmd(MLE_ADVERTISEMENT).must_next()
|
||||
pkts.filter_wpan_dst64(ROUTER_1).filter_mle_cmd(MLE_CHILD_ID_RESPONSE).must_next()
|
||||
pkts.copy().filter_wpan_src64(ROUTER_1).filter_mle_cmd(MLE_ADVERTISEMENT).must_next()
|
||||
|
||||
# Step 5: Router_2 begins attach process by sending a multicast MLE Parent Request
|
||||
# The first MLE Parent Request sent MUST NOT be sent to all routers and REEDS
|
||||
_router2_pkts.range(pkts.index).filter_mle_cmd(MLE_PARENT_REQUEST).must_next().must_verify(
|
||||
lambda p: {MODE_TLV, CHALLENGE_TLV, SCAN_MASK_TLV, VERSION_TLV} == set(
|
||||
p.mle.tlv.type) and p.mle.tlv.scan_mask.r == 1 and p.mle.tlv.scan_mask.e == 0)
|
||||
|
||||
# Step 7: Router_2 MUST send a MLE Child ID Request to Router_1
|
||||
_router2_pkts.filter_mle_cmd(MLE_CHILD_ID_REQUEST).must_next().must_verify(lambda p: {
|
||||
RESPONSE_TLV, LINK_LAYER_FRAME_COUNTER_TLV, MODE_TLV, TIMEOUT_TLV, VERSION_TLV, TLV_REQUEST_TLV
|
||||
} < set(p.mle.tlv.type) and ADDRESS_REGISTRATION_TLV not in p.mle.tlv.type)
|
||||
|
||||
# Step 14: Router_2 begins attach process by sending a multicast MLE Parent Request
|
||||
# The first MLE Parent Request sent MUST NOT be sent to all routers and REEDS
|
||||
_router2_pkts.filter_mle_cmd(MLE_PARENT_REQUEST).must_next().must_verify(
|
||||
lambda p: {MODE_TLV, CHALLENGE_TLV, SCAN_MASK_TLV, VERSION_TLV} == set(
|
||||
p.mle.tlv.type) and p.mle.tlv.scan_mask.r == 1 and p.mle.tlv.scan_mask.e == 0)
|
||||
|
||||
# Step 16: Router_2 MUST send a MLE Child ID Request to Router_1
|
||||
_router2_pkts.filter_mle_cmd(MLE_CHILD_ID_REQUEST).must_next().must_verify(lambda p: {
|
||||
RESPONSE_TLV, LINK_LAYER_FRAME_COUNTER_TLV, MODE_TLV, TIMEOUT_TLV, VERSION_TLV, TLV_REQUEST_TLV
|
||||
} < set(p.mle.tlv.type) and ADDRESS_REGISTRATION_TLV not in p.mle.tlv.type)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
||||
@@ -86,6 +86,8 @@ SVR_DATA_URI = '/a/sd'
|
||||
ND_DATA_URI = '/a/nd'
|
||||
RLY_RX_URI = '/c/rx'
|
||||
RLY_TX_URI = '/c/tx'
|
||||
MGMT_ACTIVE_SET_URI = '/c/as'
|
||||
MGMT_ACTIVE_GET_URI = '/c/ag'
|
||||
|
||||
# MLE TLVs
|
||||
SOURCE_ADDRESS_TLV = 0
|
||||
|
||||
Reference in New Issue
Block a user