mirror of
https://github.com/espressif/openthread.git
synced 2026-06-05 21:14:49 +00:00
[tests] enhance Cert_7_1_03_BorderRouterAsLeader (#3399)
This commit is contained in:
@@ -30,6 +30,7 @@
|
||||
import sys
|
||||
|
||||
import ipv6
|
||||
from network_data import Prefix, BorderRouter, LowpanId
|
||||
import network_layer
|
||||
import config
|
||||
import mle
|
||||
@@ -345,8 +346,68 @@ def check_router_id_cached(node, router_id, cached = True):
|
||||
assert any(router_id == (int(rloc, 16) >> 10) for (_, rloc) in eidcaches) is False
|
||||
|
||||
def contains_tlv(sub_tlvs, tlv_type):
|
||||
"""Verify if a specific type of tlv is included in a sub-tlv list.
|
||||
"""
|
||||
return any(isinstance(sub_tlv, tlv_type) for sub_tlv in sub_tlvs)
|
||||
|
||||
def check_secure_mle_key_id_mode(command_msg, key_id_mode):
|
||||
"""Verify if the mle command message sets the right key id mode.
|
||||
"""
|
||||
assert isinstance(command_msg.mle, mle.MleMessageSecured)
|
||||
assert command_msg.mle.aux_sec_hdr.key_id_mode == key_id_mode
|
||||
|
||||
def check_data_response(command_msg, network_data=CheckType.OPTIONAL, prefixes=[],
|
||||
active_timestamp=CheckType.OPTIONAL):
|
||||
"""Verify a properly formatted Data Response command message.
|
||||
"""
|
||||
check_secure_mle_key_id_mode(command_msg, 0x02)
|
||||
|
||||
command_msg.assertMleMessageContainsTlv(mle.SourceAddress)
|
||||
command_msg.assertMleMessageContainsTlv(mle.LeaderData)
|
||||
check_mle_optional_tlv(command_msg, network_data, mle.NetworkData)
|
||||
check_mle_optional_tlv(command_msg, active_timestamp, mle.ActiveTimestamp)
|
||||
|
||||
if network_data == CheckType.CONTAIN and len(prefixes) > 0:
|
||||
network_data_tlv = command_msg.get_mle_message_tlv(mle.NetworkData)
|
||||
prefix_tlvs = [tlv for tlv in network_data_tlv.tlvs if isinstance(tlv, Prefix)]
|
||||
assert len(prefix_tlvs) >= len(prefixes)
|
||||
for prefix in prefix_tlvs:
|
||||
assert contains_tlv(prefix.sub_tlvs, BorderRouter)
|
||||
assert contains_tlv(prefix.sub_tlvs, LowpanId)
|
||||
|
||||
def check_child_update_request_from_parent(command_msg, leader_data=CheckType.OPTIONAL,
|
||||
network_data=CheckType.OPTIONAL, challenge=CheckType.OPTIONAL,
|
||||
tlv_request=CheckType.OPTIONAL, active_timestamp=CheckType.OPTIONAL):
|
||||
"""Verify a properly formatted Child Update Request(from parent) command message.
|
||||
"""
|
||||
check_secure_mle_key_id_mode(command_msg, 0x02)
|
||||
|
||||
command_msg.assertMleMessageContainsTlv(mle.SourceAddress)
|
||||
check_mle_optional_tlv(command_msg, leader_data, mle.LeaderData)
|
||||
check_mle_optional_tlv(command_msg, network_data, mle.NetworkData)
|
||||
check_mle_optional_tlv(command_msg, challenge, mle.Challenge)
|
||||
check_mle_optional_tlv(command_msg, tlv_request, mle.TlvRequest)
|
||||
check_mle_optional_tlv(command_msg, active_timestamp, mle.ActiveTimestamp)
|
||||
|
||||
def check_child_update_response_from_parent(command_msg, timeout=CheckType.OPTIONAL,
|
||||
address_registration=CheckType.OPTIONAL, address16=CheckType.OPTIONAL,
|
||||
leader_data=CheckType.OPTIONAL, network_data=CheckType.OPTIONAL, response=CheckType.OPTIONAL,
|
||||
link_layer_frame_counter=CheckType.OPTIONAL, mle_frame_counter=CheckType.OPTIONAL):
|
||||
"""Verify a properly formatted Child Update Response from parent
|
||||
"""
|
||||
check_secure_mle_key_id_mode(command_msg, 0x02)
|
||||
|
||||
command_msg.assertMleMessageContainsTlv(mle.SourceAddress)
|
||||
command_msg.assertMleMessageContainsTlv(mle.Mode)
|
||||
check_mle_optional_tlv(command_msg, timeout, mle.Timeout)
|
||||
check_mle_optional_tlv(command_msg, address_registration, mle.AddressRegistration)
|
||||
check_mle_optional_tlv(command_msg, address16, mle.Address16)
|
||||
check_mle_optional_tlv(command_msg, leader_data, mle.LeaderData)
|
||||
check_mle_optional_tlv(command_msg, network_data, mle.NetworkData)
|
||||
check_mle_optional_tlv(command_msg, response, mle.Response)
|
||||
check_mle_optional_tlv(command_msg, link_layer_frame_counter, mle.LinkLayerFrameCounter)
|
||||
check_mle_optional_tlv(command_msg, mle_frame_counter, mle.MleFrameCounter)
|
||||
|
||||
def get_sub_tlv(tlvs, tlv_type):
|
||||
for sub_tlv in tlvs:
|
||||
if isinstance(sub_tlv, tlv_type):
|
||||
|
||||
Reference in New Issue
Block a user