mirror of
https://github.com/espressif/openthread.git
synced 2026-08-15 07:07:46 +00:00
[thread-cert] refactor case 5.5.2 using pktverify (#5330)
This commit is contained in:
@@ -29,7 +29,11 @@
|
||||
|
||||
import unittest
|
||||
|
||||
import config
|
||||
import thread_cert
|
||||
from pktverify.consts import MLE_ADVERTISEMENT, MLE_PARENT_REQUEST, MLE_PARENT_RESPONSE, MLE_CHILD_UPDATE_RESPONSE, MLE_CHILD_ID_REQUEST, MLE_CHILD_ID_RESPONSE, MLE_LINK_REQUEST, MLE_LINK_ACCEPT_AND_REQUEST, ADDR_SOL_URI, SOURCE_ADDRESS_TLV, MODE_TLV, TIMEOUT_TLV, CHALLENGE_TLV, RESPONSE_TLV, LINK_LAYER_FRAME_COUNTER_TLV, MLE_FRAME_COUNTER_TLV, ROUTE64_TLV, ADDRESS16_TLV, LEADER_DATA_TLV, NETWORK_DATA_TLV, TLV_REQUEST_TLV, SCAN_MASK_TLV, CONNECTIVITY_TLV, LINK_MARGIN_TLV, VERSION_TLV, ADDRESS_REGISTRATION_TLV, ACTIVE_TIMESTAMP_TLV
|
||||
from pktverify.packet_verifier import PacketVerifier
|
||||
from pktverify.null_field import nullField
|
||||
|
||||
LEADER = 1
|
||||
ROUTER = 2
|
||||
@@ -39,18 +43,21 @@ ED = 3
|
||||
class Cert_5_5_2_LeaderReboot(thread_cert.TestCase):
|
||||
TOPOLOGY = {
|
||||
LEADER: {
|
||||
'name': 'LEADER',
|
||||
'mode': 'rsdn',
|
||||
'panid': 0xface,
|
||||
'router_selection_jitter': 1,
|
||||
'whitelist': [ROUTER]
|
||||
},
|
||||
ROUTER: {
|
||||
'name': 'ROUTER',
|
||||
'mode': 'rsdn',
|
||||
'panid': 0xface,
|
||||
'router_selection_jitter': 1,
|
||||
'whitelist': [LEADER, ED]
|
||||
},
|
||||
ED: {
|
||||
'name': 'MED',
|
||||
'is_mtd': True,
|
||||
'mode': 'rsn',
|
||||
'panid': 0xface,
|
||||
@@ -89,6 +96,101 @@ class Cert_5_5_2_LeaderReboot(thread_cert.TestCase):
|
||||
for addr in addrs:
|
||||
self.assertTrue(self.nodes[ROUTER].ping(addr))
|
||||
|
||||
def verify(self, pv):
|
||||
pkts = pv.pkts
|
||||
pv.summary.show()
|
||||
|
||||
LEADER = pv.vars['LEADER']
|
||||
ROUTER = pv.vars['ROUTER']
|
||||
MED = pv.vars['MED']
|
||||
leader_pkts = pkts.filter_wpan_src64(LEADER)
|
||||
_rpkts = pkts.filter_wpan_src64(ROUTER)
|
||||
|
||||
# Step 2: The DUT MUST send properly formatted MLE Advertisements
|
||||
_rpkts.filter_mle_cmd(MLE_CHILD_ID_RESPONSE).must_next()
|
||||
_lpkts = leader_pkts.range(_rpkts.index)
|
||||
_lpkts.filter_mle_cmd(MLE_ADVERTISEMENT).must_next().must_verify(
|
||||
lambda p: {SOURCE_ADDRESS_TLV, LEADER_DATA_TLV, ROUTE64_TLV} == set(p.mle.tlv.type))
|
||||
|
||||
_rpkts.filter_mle_cmd(MLE_ADVERTISEMENT).must_next().must_verify(
|
||||
lambda p: {SOURCE_ADDRESS_TLV, LEADER_DATA_TLV, ROUTE64_TLV} == set(p.mle.tlv.type))
|
||||
|
||||
# Step 4: Router_1 MUST attempt to reattach to its original partition by
|
||||
# sending MLE Parent Requests to the All-Routers multicast
|
||||
# address (FFxx::xx) with a hop limit of 255.
|
||||
_rpkts.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))
|
||||
lreset_start = _rpkts.index
|
||||
|
||||
# Step 5: Leader MUST NOT respond to the MLE Parent Requests
|
||||
_lpkts.filter_mle_cmd(MLE_PARENT_RESPONSE).must_not_next()
|
||||
|
||||
# Step 6:Router_1 MUST attempt to attach to any other Partition
|
||||
# within range by sending a MLE Parent Request.
|
||||
_rpkts.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))
|
||||
lreset_stop = _rpkts.index
|
||||
|
||||
# Step 3: The Leader MUST stop sending MLE advertisements.
|
||||
leader_pkts.range(lreset_start, lreset_stop).filter_mle_cmd(MLE_ADVERTISEMENT).must_not_next()
|
||||
|
||||
# Step 7: Take over leader role of a new Partition and
|
||||
# begin transmitting MLE Advertisements
|
||||
with _rpkts.save_index():
|
||||
_rpkts.filter_mle_cmd(MLE_ADVERTISEMENT).must_next().must_verify(
|
||||
lambda p: {SOURCE_ADDRESS_TLV, LEADER_DATA_TLV, ROUTE64_TLV} == set(p.mle.tlv.type))
|
||||
|
||||
# Step 8: Router_1 MUST respond with an MLE Child Update Response,
|
||||
# with the updated TLVs of the new partition
|
||||
_rpkts.filter_mle_cmd(MLE_CHILD_UPDATE_RESPONSE).must_next().must_verify(
|
||||
lambda p: {SOURCE_ADDRESS_TLV, MODE_TLV, LEADER_DATA_TLV, ADDRESS_REGISTRATION_TLV} < set(p.mle.tlv.type))
|
||||
|
||||
# Step 9: The Leader MUST send properly formatted MLE Parent
|
||||
# Requests to the All-Routers multicast address
|
||||
_lpkts.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))
|
||||
|
||||
# Step 10: Router_1 MUST send an MLE Parent Response
|
||||
_rpkts.filter_mle_cmd(MLE_PARENT_RESPONSE).must_next().must_verify(
|
||||
lambda p: {
|
||||
SOURCE_ADDRESS_TLV, LEADER_DATA_TLV, LINK_LAYER_FRAME_COUNTER_TLV, RESPONSE_TLV, CHALLENGE_TLV,
|
||||
LINK_MARGIN_TLV, CONNECTIVITY_TLV, VERSION_TLV
|
||||
} < set(p.mle.tlv.type))
|
||||
|
||||
# Step 11: Leader send MLE Child ID Request
|
||||
_lpkts.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,
|
||||
ADDRESS16_TLV, NETWORK_DATA_TLV, ROUTE64_TLV, ACTIVE_TIMESTAMP_TLV
|
||||
} < set(p.mle.tlv.type))
|
||||
|
||||
#Step 12: Router_1 send MLE Child ID Response
|
||||
_rpkts.filter_mle_cmd(MLE_CHILD_ID_RESPONSE).must_next().must_verify(
|
||||
lambda p: {SOURCE_ADDRESS_TLV, LEADER_DATA_TLV, ADDRESS16_TLV, NETWORK_DATA_TLV, ROUTE64_TLV} < set(
|
||||
p.mle.tlv.type))
|
||||
|
||||
#Step 13: Leader send an Address Solicit Request
|
||||
_lpkts.filter_coap_request(ADDR_SOL_URI).must_next().must_verify(
|
||||
lambda p: p.coap.tlv.ext_mac_addr and p.coap.tlv.rloc16 is not nullField and p.coap.tlv.status != 0)
|
||||
|
||||
#Step 14: Router_1 send an Address Solicit Response
|
||||
_rpkts.filter_coap_ack(
|
||||
ADDR_SOL_URI).must_next().must_verify(lambda p: p.coap.tlv.router_mask_assigned and p.coap.tlv.rloc16 is
|
||||
not nullField and p.coap.tlv.status == 0)
|
||||
|
||||
#Step 15: Leader Send a Multicast Link Request
|
||||
_lpkts.filter_mle_cmd(MLE_LINK_REQUEST).must_next().must_verify(
|
||||
lambda p: {VERSION_TLV, TLV_REQUEST_TLV, SOURCE_ADDRESS_TLV, LEADER_DATA_TLV, CHALLENGE_TLV} < set(
|
||||
p.mle.tlv.type))
|
||||
|
||||
#Step 16: Router_1 send a Unicast Link Accept
|
||||
_rpkts.filter_mle_cmd(MLE_LINK_ACCEPT_AND_REQUEST).must_next().must_verify(lambda p: {
|
||||
VERSION_TLV, SOURCE_ADDRESS_TLV, RESPONSE_TLV, MLE_FRAME_COUNTER_TLV, LINK_MARGIN_TLV, LEADER_DATA_TLV
|
||||
} < set(p.mle.tlv.type))
|
||||
|
||||
#Step 17: Router_1 MUST respond with an ICMPv6 Echo Reply
|
||||
_rpkts.filter_ping_request().filter_wpan_dst64(MED).must_next()
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
||||
@@ -69,6 +69,46 @@ MLE_PARENT_REQUEST = 9
|
||||
MLE_PARENT_RESPONSE = 10
|
||||
MLE_CHILD_ID_REQUEST = 11
|
||||
MLE_CHILD_ID_RESPONSE = 12
|
||||
MLE_CHILD_UPDATE_REQUEST = 13
|
||||
MLE_CHILD_UPDATE_RESPONSE = 14
|
||||
|
||||
# COAP URI
|
||||
ADDR_QRY_URI = '/a/aq'
|
||||
ADDR_NTF_URI = '/a/an'
|
||||
ADDR_ERR_URI = '/a/ae'
|
||||
ADDR_SOL_URI = '/a/as'
|
||||
ADDR_REL_URI = '/a/ar'
|
||||
SVR_DATA_URI = '/a/sd'
|
||||
ND_DATA_URI = '/a/nd'
|
||||
|
||||
# TLV
|
||||
SOURCE_ADDRESS_TLV = 0
|
||||
MODE_TLV = 1
|
||||
TIMEOUT_TLV = 2
|
||||
CHALLENGE_TLV = 3
|
||||
RESPONSE_TLV = 4
|
||||
LINK_LAYER_FRAME_COUNTER_TLV = 5
|
||||
LINK_QUALITY_TLV = 6
|
||||
PARAMETER_TLV = 7
|
||||
MLE_FRAME_COUNTER_TLV = 8
|
||||
ROUTE64_TLV = 9
|
||||
ADDRESS16_TLV = 10
|
||||
LEADER_DATA_TLV = 11
|
||||
NETWORK_DATA_TLV = 12
|
||||
TLV_REQUEST_TLV = 13
|
||||
SCAN_MASK_TLV = 14
|
||||
CONNECTIVITY_TLV = 15
|
||||
LINK_MARGIN_TLV = 16
|
||||
STATUS_TLV = 17
|
||||
VERSION_TLV = 18
|
||||
ADDRESS_REGISTRATION_TLV = 19
|
||||
CHANNEL_TLV = 20
|
||||
PAN_ID_TLV = 21
|
||||
ACTIVE_TIMESTAMP_TLV = 22
|
||||
PENDING_TIMESTAMP_TLV = 23
|
||||
ACTIVE_OPERATION_DATASET_TLV = 24
|
||||
PENDING_OPERATION_DATASET_TLV = 25
|
||||
THREAD_DISCOVERY_TLV = 26
|
||||
|
||||
# DUA related constants
|
||||
|
||||
|
||||
Reference in New Issue
Block a user