[test] add traffic analysis for Cert_5_2_3_LeaderReject2Hops (#2142)

Also add a method last_mle_message to find the newest mle; Add a method assertAssignedRouterQuantity to confirm if Leader contains the Route64 TLV with 32 assigned router IDs.
This commit is contained in:
hjian2017
2017-08-30 08:41:31 -07:00
committed by Jonathan Hui
parent c57908ce9e
commit ce061e2174
2 changed files with 123 additions and 28 deletions
+54 -1
View File
@@ -156,6 +156,14 @@ class Message(object):
assert(self.mle.command.type == command_type)
def assertMleMessageContainsTlv(self, tlv_class_type):
"""To confirm if Mle message contains the TLV type.
Args:
tlv_class_type: tlv's type.
Returns:
mle.Route64: If contains the TLV, return it.
"""
if self.type != MessageType.MLE:
raise ValueError("Invalid message type. Expected MLE message.")
@@ -166,6 +174,22 @@ class Message(object):
break
assert(contains_tlv == True)
return tlv
def assertAssignedRouterQuantity(self, router_quantity):
"""Confirm if Leader contains the Route64 TLV with router_quantity assigned Router IDs.
Args:
router_quantity: the quantity of router.
"""
tlv = self.assertMleMessageContainsTlv(mle.Route64)
router_id_mask = tlv.router_id_mask
count = 0
for i in range(1, 65):
count += (router_id_mask & 1)
router_id_mask = (router_id_mask >> 1)
assert(count == router_quantity)
def assertMleMessageDoesNotContainTlv(self, tlv_class_type):
if self.type != MessageType.MLE:
@@ -294,8 +318,37 @@ class MessagesSet(object):
return message
def last_mle_message(self, command_type, assert_enabled = True):
"""Get the last Mle Message with specified type from existing capture.
Args:
command_type: the specified mle type.
assert_enabled: interrupt or not when get the mle.
Returns:
message.Message: the last Mle Message with specified type.
"""
message = None
size = len(self.messages)
for i in range(size - 1, -1, -1):
m = self.messages[i]
if m.type != MessageType.MLE:
continue
#for command_type in command_types:
if m.mle.command.type == command_type:
message = m
break
if assert_enabled:
assert message is not None, "Could not find MleMessage with type: {}".format(command_type)
return message
def next_mle_message(self, command_type, assert_enabled=True):
message = self.next_mle_message_of_one_of_command_types(command_type,)
message = self.next_mle_message_of_one_of_command_types(command_type)
if assert_enabled:
assert message is not None, "Could not find MleMessage of the type: {}".format(command_type)