[tests] enhance Cert_6_1_02_REEDAttach_MED/SED (#3387)

This commit is contained in:
Irving-cl
2018-12-29 09:50:12 -08:00
committed by Jonathan Hui
parent 08247dc92f
commit d34f279e5a
7 changed files with 245 additions and 22 deletions
+27 -4
View File
@@ -223,7 +223,7 @@ def get_routing_cost(command_msg, router_id):
assert router_id_mask_str[router_id - prefix_len] == '1', "Error: The router isn't in the topology. \n" \
+ "route64 tlv is: %s. \nrouter_id is: %s. \nrouting_entry_pos is: %s. \nrouter_id_mask_str is: %s." \
%(tlv, router_id, routing_entry_pos, router_id_mask_str)
return tlv.link_quality_and_route_data[routing_entry_pos].route
def check_mle_optional_tlv(command_msg, type, tlv):
@@ -246,10 +246,14 @@ def check_mle_advertisement(command_msg):
def check_parent_request(command_msg, is_first_request):
"""Verify a properly formatted Parent Request command message.
"""
if command_msg.mle.aux_sec_hdr.key_id_mode != 0x2:
raise ValueError("The Key Identifier Mode of the Security Control Field SHALL be set to 0x02")
command_msg.assertSentWithHopLimit(255)
command_msg.assertSentToDestinationAddress(config.LINK_LOCAL_ALL_ROUTERS_ADDRESS)
command_msg.assertMleMessageContainsTlv(mle.Mode)
command_msg.assertMleMessageContainsTlv(mle.Challenge)
command_msg.assertMleMessageContainsTlv(mle.Version)
scan_mask = command_msg.assertMleMessageContainsTlv(mle.ScanMask)
if not scan_mask.router:
raise ValueError("Parent request without R bit set")
@@ -259,8 +263,6 @@ def check_parent_request(command_msg, is_first_request):
elif not scan_mask.end_device:
raise ValueError("Second parent request without E bit set")
command_msg.assertMleMessageContainsTlv(mle.Version)
def check_parent_response(command_msg, mle_frame_counter = CheckType.OPTIONAL):
"""Verify a properly formatted Parent Response command message.
"""
@@ -277,9 +279,13 @@ def check_parent_response(command_msg, mle_frame_counter = CheckType.OPTIONAL):
def check_child_id_request(command_msg, tlv_request = CheckType.OPTIONAL, \
mle_frame_counter = CheckType.OPTIONAL, address_registration = CheckType.OPTIONAL, \
active_timestamp = CheckType.OPTIONAL, pending_timestamp = CheckType.OPTIONAL):
active_timestamp = CheckType.OPTIONAL, pending_timestamp = CheckType.OPTIONAL,
route64 = CheckType.OPTIONAL):
"""Verify a properly formatted Child Id Request command message.
"""
if command_msg.mle.aux_sec_hdr.key_id_mode != 0x2:
raise ValueError("The Key Identifier Mode of the Security Control Field SHALL be set to 0x02")
command_msg.assertMleMessageContainsTlv(mle.LinkLayerFrameCounter)
command_msg.assertMleMessageContainsTlv(mle.Mode)
command_msg.assertMleMessageContainsTlv(mle.Response)
@@ -291,6 +297,10 @@ def check_child_id_request(command_msg, tlv_request = CheckType.OPTIONAL, \
check_mle_optional_tlv(command_msg, address_registration, mle.AddressRegistration)
check_mle_optional_tlv(command_msg, active_timestamp, mle.ActiveTimestamp)
check_mle_optional_tlv(command_msg, pending_timestamp, mle.PendingTimestamp)
check_mle_optional_tlv(command_msg, route64, mle.Route64)
check_tlv_request_tlv(command_msg, CheckType.CONTAIN, mle.TlvType.ADDRESS16)
check_tlv_request_tlv(command_msg, CheckType.CONTAIN, mle.TlvType.NETWORK_DATA)
def check_child_id_response(command_msg, route64 = CheckType.OPTIONAL, network_data = CheckType.OPTIONAL, \
address_registration = CheckType.OPTIONAL, active_timestamp = CheckType.OPTIONAL, \
@@ -310,6 +320,11 @@ def check_child_id_response(command_msg, route64 = CheckType.OPTIONAL, network_d
check_mle_optional_tlv(command_msg, active_operational_dataset, mle.ActiveOperationalDataset)
check_mle_optional_tlv(command_msg, pending_operational_dataset, mle.PendingOperationalDataset)
def check_child_update_request_by_child(command_msg):
command_msg.assertMleMessageContainsTlv(mle.LeaderData)
command_msg.assertMleMessageContainsTlv(mle.Mode)
command_msg.assertMleMessageContainsTlv(mle.SourceAddress)
def check_coap_optional_tlv(coap_msg, type, tlv):
if (type == CheckType.CONTAIN):
coap_msg.assertCoapMessageContainsTlv(tlv)
@@ -328,3 +343,11 @@ def check_router_id_cached(node, router_id, cached = True):
assert any(router_id == (int(rloc, 16) >> 10) for (_, rloc) in eidcaches)
else:
assert any(router_id == (int(rloc, 16) >> 10) for (_, rloc) in eidcaches) is False
def contains_tlv(sub_tlvs, tlv_type):
return any(isinstance(sub_tlv, tlv_type) for sub_tlv in sub_tlvs)
def get_sub_tlv(tlvs, tlv_type):
for sub_tlv in tlvs:
if isinstance(sub_tlv, tlv_type):
return sub_tlv