mirror of
https://github.com/espressif/openthread.git
synced 2026-07-29 23:27:46 +00:00
[thread-cert] refactor case 5.1.11 using pktverify (#5756)
This commit is contained in:
@@ -31,33 +31,60 @@ import unittest
|
||||
|
||||
import mle
|
||||
import thread_cert
|
||||
from pktverify.consts import MLE_ADVERTISEMENT, MLE_PARENT_REQUEST, MLE_PARENT_RESPONSE, MLE_CHILD_ID_REQUEST, SOURCE_ADDRESS_TLV, MODE_TLV, TIMEOUT_TLV, CHALLENGE_TLV, RESPONSE_TLV, LINK_LAYER_FRAME_COUNTER_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
|
||||
from pktverify.packet_verifier import PacketVerifier
|
||||
from pktverify.null_field import nullField
|
||||
|
||||
LEADER = 1
|
||||
REED = 2
|
||||
ROUTER2 = 3
|
||||
ROUTER1 = 4
|
||||
|
||||
# Test Purpose and Description:
|
||||
# -----------------------------
|
||||
# The purpose of this test case is to validate that DUT will
|
||||
# attach to a REED with the highest link quality, when routers
|
||||
# with the highest link quality are not available.
|
||||
#
|
||||
# Test Topology:
|
||||
# -------------
|
||||
# Leader
|
||||
# / \
|
||||
# Router2 REED1
|
||||
# \ /(better link_quality)
|
||||
# Router1[DUT]
|
||||
#
|
||||
# DUT Types:
|
||||
# ----------
|
||||
# Router
|
||||
|
||||
|
||||
class Cert_5_1_11_REEDAttachLinkQuality(thread_cert.TestCase):
|
||||
USE_MESSAGE_FACTORY = False
|
||||
|
||||
TOPOLOGY = {
|
||||
LEADER: {
|
||||
'name': 'LEADER',
|
||||
'mode': 'rdn',
|
||||
'panid': 0xface,
|
||||
'allowlist': [REED, ROUTER2]
|
||||
},
|
||||
REED: {
|
||||
'name': 'REED_1',
|
||||
'mode': 'rdn',
|
||||
'panid': 0xface,
|
||||
'router_upgrade_threshold': 0,
|
||||
'allowlist': [LEADER, ROUTER1]
|
||||
},
|
||||
ROUTER2: {
|
||||
'name': 'ROUTER_2',
|
||||
'mode': 'rdn',
|
||||
'panid': 0xface,
|
||||
'router_selection_jitter': 1,
|
||||
'allowlist': [LEADER, (ROUTER1, -85)]
|
||||
},
|
||||
ROUTER1: {
|
||||
'name': 'ROUTER_1',
|
||||
'mode': 'rdn',
|
||||
'panid': 0xface,
|
||||
'router_selection_jitter': 1,
|
||||
@@ -83,77 +110,108 @@ class Cert_5_1_11_REEDAttachLinkQuality(thread_cert.TestCase):
|
||||
self.assertEqual(self.nodes[ROUTER1].get_state(), 'router')
|
||||
self.assertEqual(self.nodes[REED].get_state(), 'router')
|
||||
|
||||
leader_messages = self.simulator.get_messages_sent_by(LEADER)
|
||||
reed_messages = self.simulator.get_messages_sent_by(REED)
|
||||
router1_messages = self.simulator.get_messages_sent_by(ROUTER1)
|
||||
router2_messages = self.simulator.get_messages_sent_by(ROUTER2)
|
||||
def verify(self, pv):
|
||||
pkts = pv.pkts
|
||||
pv.summary.show()
|
||||
|
||||
# 1 - Leader. REED1, Router2
|
||||
leader_messages.next_mle_message(mle.CommandType.ADVERTISEMENT)
|
||||
LEADER = pv.vars['LEADER']
|
||||
REED_1 = pv.vars['REED_1']
|
||||
ROUTER_1 = pv.vars['ROUTER_1']
|
||||
ROUTER_2 = pv.vars['ROUTER_2']
|
||||
|
||||
reed_messages.next_mle_message(mle.CommandType.PARENT_REQUEST)
|
||||
leader_messages.next_mle_message(mle.CommandType.PARENT_RESPONSE)
|
||||
# Step 1: Verify ROUTER_2 and Leader are sending MLE advertisements.
|
||||
pkts.filter_wpan_src64(LEADER).\
|
||||
filter_mle_cmd(MLE_ADVERTISEMENT).\
|
||||
must_next()
|
||||
pv.verify_attached('ROUTER_2')
|
||||
|
||||
reed_messages.next_mle_message(mle.CommandType.CHILD_ID_REQUEST)
|
||||
leader_messages.next_mle_message(mle.CommandType.CHILD_ID_RESPONSE)
|
||||
# Step 3: The DUT sends a MLE Parent Request with an IP hop limit of
|
||||
# 255 to the Link-Local All Routers multicast address (FF02::2).
|
||||
# The following TLVs MUST be present in the MLE Parent Request:
|
||||
# - Challenge TLV
|
||||
# - Mode TLV
|
||||
# - Scan Mask TLV
|
||||
# If the DUT sends multiple MLE Parent Requests
|
||||
# - The first one MUST be sent only to all Routers
|
||||
# - Subsequent ones MAY be sent to all Routers and REEDS
|
||||
# - Version TLV
|
||||
# If the first MLE Parent Request was sent to all Routers and
|
||||
# REEDS, the test fails.
|
||||
|
||||
router2_messages.next_mle_message(mle.CommandType.PARENT_REQUEST)
|
||||
leader_messages.next_mle_message(mle.CommandType.PARENT_RESPONSE)
|
||||
pkts.filter_wpan_src64(ROUTER_1).\
|
||||
filter_LLARMA().\
|
||||
filter_mle_cmd(MLE_PARENT_REQUEST).\
|
||||
filter(lambda p: {
|
||||
CHALLENGE_TLV,
|
||||
MODE_TLV,
|
||||
SCAN_MASK_TLV,
|
||||
VERSION_TLV
|
||||
} <= set(p.mle.tlv.type) and\
|
||||
p.ipv6.hlim == 255 and\
|
||||
p.mle.tlv.scan_mask.r == 1 and\
|
||||
p.mle.tlv.scan_mask.e == 0
|
||||
).\
|
||||
must_next()
|
||||
|
||||
router2_messages.next_mle_message(mle.CommandType.CHILD_ID_REQUEST)
|
||||
leader_messages.next_mle_message(mle.CommandType.CHILD_ID_RESPONSE)
|
||||
# Step 5: The DUT MUST send a MLE Parent Request with an IP hop limit of
|
||||
# 255 to the Link-Local All Routers multicast address (FF02::2).
|
||||
# The following TLVs MUST be present in the MLE Parent Request:
|
||||
# - Challenge TLV
|
||||
# - Mode TLV
|
||||
# - Scan Mask TLV
|
||||
# - The Scan Mask TLV MUST be sent to Routers And REEDs
|
||||
# - Version TLV
|
||||
#
|
||||
|
||||
msg = router2_messages.next_coap_message("0.02")
|
||||
msg.assertCoapMessageRequestUriPath("/a/as")
|
||||
pkts.filter_wpan_src64(ROUTER_1).\
|
||||
filter_LLARMA().\
|
||||
filter_mle_cmd(MLE_PARENT_REQUEST).\
|
||||
filter(lambda p: {
|
||||
CHALLENGE_TLV,
|
||||
MODE_TLV,
|
||||
SCAN_MASK_TLV,
|
||||
VERSION_TLV
|
||||
} <= set(p.mle.tlv.type) and\
|
||||
p.ipv6.hlim == 255 and\
|
||||
p.mle.tlv.scan_mask.r == 1 and\
|
||||
p.mle.tlv.scan_mask.e == 1
|
||||
).\
|
||||
must_next()
|
||||
|
||||
msg = leader_messages.next_coap_message("2.04")
|
||||
# Step 6: The DUT MUST initiate the attach process with REED_1 by
|
||||
# sending an MLE Child ID Request; if not, the test fails.
|
||||
# The following TLVs MUST be present in the MLE Child ID Request:
|
||||
# - Link-layer Frame Counter TLV
|
||||
# - Mode TLV
|
||||
# - Response TLV
|
||||
# - Timeout TLV
|
||||
# - TLV Request TLV
|
||||
# - Address16 TLV
|
||||
# - Network Data TLV
|
||||
# - Route64 TLV (optional)
|
||||
# - Version TLV
|
||||
# - MLE Frame Counter TLV (optional)
|
||||
# The following TLV MUST NOT be present in the MLE Child ID Request:
|
||||
# - Address Registration TLV
|
||||
|
||||
router2_messages.next_mle_message(mle.CommandType.ADVERTISEMENT)
|
||||
|
||||
# 3 - Router1
|
||||
msg = router1_messages.next_mle_message(mle.CommandType.PARENT_REQUEST)
|
||||
msg.assertSentWithHopLimit(255)
|
||||
msg.assertSentToDestinationAddress("ff02::2")
|
||||
msg.assertMleMessageContainsTlv(mle.Mode)
|
||||
msg.assertMleMessageContainsTlv(mle.Challenge)
|
||||
msg.assertMleMessageContainsTlv(mle.ScanMask)
|
||||
msg.assertMleMessageContainsTlv(mle.Version)
|
||||
|
||||
scan_mask_tlv = msg.get_mle_message_tlv(mle.ScanMask)
|
||||
self.assertEqual(1, scan_mask_tlv.router)
|
||||
self.assertEqual(0, scan_mask_tlv.end_device)
|
||||
|
||||
# 4 - Router2
|
||||
msg = router2_messages.next_mle_message(mle.CommandType.PARENT_RESPONSE)
|
||||
msg.assertSentToNode(self.nodes[ROUTER1])
|
||||
|
||||
# 5 - Router1
|
||||
msg = router1_messages.next_mle_message(mle.CommandType.PARENT_REQUEST)
|
||||
msg.assertSentWithHopLimit(255)
|
||||
msg.assertSentToDestinationAddress("ff02::2")
|
||||
msg.assertMleMessageContainsTlv(mle.Mode)
|
||||
msg.assertMleMessageContainsTlv(mle.Challenge)
|
||||
msg.assertMleMessageContainsTlv(mle.ScanMask)
|
||||
msg.assertMleMessageContainsTlv(mle.Version)
|
||||
|
||||
scan_mask_tlv = msg.get_mle_message_tlv(mle.ScanMask)
|
||||
self.assertEqual(1, scan_mask_tlv.router)
|
||||
self.assertEqual(1, scan_mask_tlv.end_device)
|
||||
|
||||
# 6 - Router1
|
||||
msg = router1_messages.next_mle_message(mle.CommandType.CHILD_ID_REQUEST)
|
||||
msg.assertMleMessageContainsTlv(mle.LinkLayerFrameCounter)
|
||||
msg.assertMleMessageContainsTlv(mle.Mode)
|
||||
msg.assertMleMessageContainsTlv(mle.Response)
|
||||
msg.assertMleMessageContainsTlv(mle.Timeout)
|
||||
msg.assertMleMessageContainsTlv(mle.TlvRequest)
|
||||
msg.assertMleMessageContainsTlv(mle.Version)
|
||||
msg.assertMleMessageContainsOptionalTlv(mle.MleFrameCounter)
|
||||
msg.assertMleMessageDoesNotContainTlv(mle.AddressRegistration)
|
||||
msg.assertSentToNode(self.nodes[REED])
|
||||
|
||||
msg = reed_messages.next_mle_message(mle.CommandType.CHILD_ID_RESPONSE)
|
||||
msg.assertSentToNode(self.nodes[ROUTER1])
|
||||
_pkt = pkts.filter_wpan_src64(ROUTER_1).\
|
||||
filter_wpan_dst64(REED_1).\
|
||||
filter_mle_cmd(MLE_CHILD_ID_REQUEST).\
|
||||
filter(lambda p: {
|
||||
LINK_LAYER_FRAME_COUNTER_TLV,
|
||||
MODE_TLV,
|
||||
RESPONSE_TLV,
|
||||
TIMEOUT_TLV,
|
||||
TLV_REQUEST_TLV,
|
||||
ADDRESS16_TLV,
|
||||
NETWORK_DATA_TLV,
|
||||
VERSION_TLV
|
||||
} <= set(p.mle.tlv.type) and\
|
||||
p.mle.tlv.addr16 is nullField and\
|
||||
p.thread_nwd.tlv.type is nullField
|
||||
).\
|
||||
must_next()
|
||||
_pkt.must_not_verify(lambda p: (ADDRESS_REGISTRATION_TLV) in p.mle.tlv.type)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
||||
Reference in New Issue
Block a user