def test(self): # 1 - All self.nodes[LEADER].start() self.simulator.go(5) self.assertEqual(self.nodes[LEADER].get_state(), 'leader') self.nodes[ROUTER].start() self.simulator.go(5) self.assertEqual(self.nodes[ROUTER].get_state(), 'router') self.nodes[SED1].start() self.simulator.go(5) self.assertEqual(self.nodes[SED1].get_state(), 'child') self.nodes[MED1].start() self.simulator.go(5) self.assertEqual(self.nodes[MED1].get_state(), 'child') # 2 - N/A # Clear collected messages self.simulator.get_messages_sent_by(LEADER) self.simulator.get_messages_sent_by(MED1) self.simulator.get_messages_sent_by(SED1) self.nodes[LEADER].add_prefix('2001:2:0:1::/64', 'paros') self.nodes[LEADER].add_prefix('2001:2:0:2::/64', 'paro') self.nodes[LEADER].register_netdata() self.simulator.go(5) # Set lowpan context of sniffer self.simulator.set_lowpan_context(1, '2001:2:0:1::/64') self.simulator.set_lowpan_context(2, '2001:2:0:2::/64') leader_messages = self.simulator.get_messages_sent_by(LEADER) med1_messages = self.simulator.get_messages_sent_by(MED1) sed1_messages = self.simulator.get_messages_sent_by(SED1) addrs = self.nodes[SED1].get_addrs() self.assertTrue(any('2001:2:0:1' in addr[0:10] for addr in addrs)) self.assertFalse(any('2001:2:0:2' in addr[0:10] for addr in addrs)) for addr in addrs: if addr[0:10] == '2001:2:0:1' or addr[0:10] == '2001:2:0:2': self.assertTrue(self.nodes[LEADER].ping(addr)) addrs = self.nodes[MED1].get_addrs() self.assertTrue(any('2001:2:0:1' in addr[0:10] for addr in addrs)) self.assertTrue(any('2001:2:0:2' in addr[0:10] for addr in addrs)) for addr in addrs: if addr[0:10] == '2001:2:0:1' or addr[0:10] == '2001:2:0:2': self.assertTrue(self.nodes[LEADER].ping(addr)) # 3 - Leader msg = leader_messages.next_mle_message(mle.CommandType.DATA_RESPONSE) check_data_response( msg, network_data_check=NetworkDataCheck(prefixes_check=PrefixesCheck( prefix_check_list=[ SinglePrefixCheck(b'2001000200000001'), SinglePrefixCheck(b'2001000200000002'), ])), ) # 4 - N/A # Get addresses registered by MED1 msg = med1_messages.next_mle_message( mle.CommandType.CHILD_UPDATE_REQUEST) check_child_update_request_from_child( msg, address_registration=CheckType.CONTAIN, CIDs=[0, 1, 2]) # 5 - Leader # Make a copy of leader's messages to ensure that we don't miss # messages to SED1 leader_messages_copy = leader_messages.clone() msg = leader_messages_copy.next_mle_message( mle.CommandType.CHILD_UPDATE_RESPONSE, sent_to_node=self.nodes[MED1], ) check_child_update_response(msg, address_registration=CheckType.CONTAIN, CIDs=[1, 2]) # 6A & 6B - Leader if config.LEADER_NOTIFY_SED_BY_CHILD_UPDATE_REQUEST: msg = leader_messages.next_mle_message( mle.CommandType.CHILD_UPDATE_REQUEST, sent_to_node=self.nodes[SED1], ) check_child_update_request_from_parent( msg, leader_data=CheckType.CONTAIN, network_data=CheckType.CONTAIN, active_timestamp=CheckType.CONTAIN, ) else: msg = leader_messages.next_mle_message( mle.CommandType.DATA_RESPONSE, sent_to_node=self.nodes[SED1]) check_data_response(msg, network_data_check=NetworkDataCheck()) # 7 - N/A # Get addresses registered by SED1 msg = sed1_messages.next_mle_message( mle.CommandType.CHILD_UPDATE_REQUEST) check_child_update_request_from_child( msg, address_registration=CheckType.CONTAIN, CIDs=[0, 1]) # 8 - Leader msg = leader_messages.next_mle_message( mle.CommandType.CHILD_UPDATE_RESPONSE, sent_to_node=self.nodes[SED1], ) check_child_update_response(msg, address_registration=CheckType.CONTAIN, CIDs=[1])
def test(self): # 1 - All self.nodes[LEADER].start() self.simulator.go(5) self.assertEqual(self.nodes[LEADER].get_state(), 'leader') self.nodes[ROUTER].start() self.simulator.go(5) self.assertEqual(self.nodes[ROUTER].get_state(), 'router') self.nodes[SED1].start() self.simulator.go(5) self.assertEqual(self.nodes[SED1].get_state(), 'child') self.nodes[MED1].start() self.simulator.go(5) self.assertEqual(self.nodes[MED1].get_state(), 'child') # 2 - N/A # Clear collected messages self.simulator.get_messages_sent_by(LEADER) self.simulator.get_messages_sent_by(MED1) self.simulator.get_messages_sent_by(SED1) self.nodes[LEADER].add_prefix('2001:2:0:1::/64', 'paros') self.nodes[LEADER].add_prefix('2001:2:0:2::/64', 'paro') self.nodes[LEADER].register_netdata() self.simulator.go(5) leader_messages = self.simulator.get_messages_sent_by(LEADER) med1_messages = self.simulator.get_messages_sent_by(MED1) sed1_messages = self.simulator.get_messages_sent_by(SED1) addrs = self.nodes[SED1].get_addrs() self.assertTrue(any('2001:2:0:1' in addr[0:10] for addr in addrs)) self.assertFalse(any('2001:2:0:2' in addr[0:10] for addr in addrs)) for addr in addrs: if addr[0:10] == '2001:2:0:1' or addr[0:10] == '2001:2:0:2': self.assertTrue(self.nodes[LEADER].ping(addr)) addrs = self.nodes[MED1].get_addrs() self.assertTrue(any('2001:2:0:1' in addr[0:10] for addr in addrs)) self.assertTrue(any('2001:2:0:2' in addr[0:10] for addr in addrs)) for addr in addrs: if addr[0:10] == '2001:2:0:1' or addr[0:10] == '2001:2:0:2': self.assertTrue(self.nodes[LEADER].ping(addr)) # 3 - Leader msg = leader_messages.next_mle_message(mle.CommandType.DATA_RESPONSE) command.check_data_response(msg, network_data=CheckType.CONTAIN, prefixes=[('2001:2:0:1::/64', 'paros'), ('2001:2:0:2::/64', 'paro')]) # 4 - N/A # Get addresses registered by MED1 msg = med1_messages.next_mle_message(mle.CommandType.CHILD_UPDATE_REQUEST) med1_addresses = msg.get_mle_message_tlv(mle.AddressRegistration).addresses # 5 - Leader # Make a copy of leader's messages to ensure that we don't miss messages to SED1 leader_messages_copy = leader_messages.clone() msg = leader_messages_copy.next_mle_message(mle.CommandType.CHILD_UPDATE_RESPONSE, sent_to_node=self.nodes[MED1]) command.check_child_update_response_from_parent(msg, address_registration=CheckType.CONTAIN) leader_addresses = msg.get_mle_message_tlv(mle.AddressRegistration).addresses self.assertTrue(all(addr in leader_addresses for addr in med1_addresses)) # 6A & 6B - Leader if config.LEADER_NOTIFY_SED_BY_CHILD_UPDATE_REQUEST: msg = leader_messages.next_mle_message(mle.CommandType.CHILD_UPDATE_REQUEST, sent_to_node=self.nodes[SED1]) command.check_child_update_request_from_parent(msg, leader_data=CheckType.CONTAIN, network_data=CheckType.CONTAIN, active_timestamp=CheckType.CONTAIN) else: msg = leader_messages.next_mle_message(mle.CommandType.DATA_RESPONSE, sent_to_node=self.nodes[SED1]) command.check_data_response(msg, network_data=CheckType.CONTAIN, active_timestamp=CheckType.CONTAIN) # 7 - N/A # Get addresses registered by SED1 msg = sed1_messages.next_mle_message(mle.CommandType.CHILD_UPDATE_REQUEST) sed1_addresses = msg.get_mle_message_tlv(mle.AddressRegistration).addresses # 8 - Leader msg = leader_messages.next_mle_message(mle.CommandType.CHILD_UPDATE_RESPONSE, sent_to_node=self.nodes[SED1]) command.check_child_update_response_from_parent(msg, address_registration=CheckType.CONTAIN) leader_addresses = msg.get_mle_message_tlv(mle.AddressRegistration).addresses self.assertTrue(all(addr in leader_addresses for addr in sed1_addresses))
def test(self): # 1 - All self.nodes[LEADER].start() self.simulator.go(5) self.assertEqual(self.nodes[LEADER].get_state(), 'leader') self.nodes[ROUTER].start() self.simulator.go(5) self.assertEqual(self.nodes[ROUTER].get_state(), 'router') self.nodes[SED1].start() self.simulator.go(5) self.assertEqual(self.nodes[SED1].get_state(), 'child') self.nodes[MED1].start() self.simulator.go(5) self.assertEqual(self.nodes[MED1].get_state(), 'child') # 2 - N/A # Clear collected messages self.simulator.get_messages_sent_by(LEADER) self.simulator.get_messages_sent_by(MED1) self.simulator.get_messages_sent_by(SED1) self.nodes[LEADER].add_prefix('2001:2:0:1::/64', 'paros') self.nodes[LEADER].add_prefix('2001:2:0:2::/64', 'paro') self.nodes[LEADER].register_netdata() self.simulator.go(5) leader_messages = self.simulator.get_messages_sent_by(LEADER) med1_messages = self.simulator.get_messages_sent_by(MED1) sed1_messages = self.simulator.get_messages_sent_by(SED1) addrs = self.nodes[SED1].get_addrs() self.assertTrue(any('2001:2:0:1' in addr[0:10] for addr in addrs)) self.assertFalse(any('2001:2:0:2' in addr[0:10] for addr in addrs)) for addr in addrs: if addr[0:10] == '2001:2:0:1' or addr[0:10] == '2001:2:0:2': self.assertTrue(self.nodes[LEADER].ping(addr)) addrs = self.nodes[MED1].get_addrs() self.assertTrue(any('2001:2:0:1' in addr[0:10] for addr in addrs)) self.assertTrue(any('2001:2:0:2' in addr[0:10] for addr in addrs)) for addr in addrs: if addr[0:10] == '2001:2:0:1' or addr[0:10] == '2001:2:0:2': self.assertTrue(self.nodes[LEADER].ping(addr)) # 3 - Leader msg = leader_messages.next_mle_message(mle.CommandType.DATA_RESPONSE) command.check_data_response(msg, network_data=CheckType.CONTAIN, prefixes=[('2001:2:0:1::/64', 'paros'), ('2001:2:0:2::/64', 'paro')]) # 4 - N/A # Get addresses registered by MED1 msg = med1_messages.next_mle_message( mle.CommandType.CHILD_UPDATE_REQUEST) med1_addresses = msg.get_mle_message_tlv( mle.AddressRegistration).addresses # 5 - Leader # Make a copy of leader's messages to ensure that we don't miss messages to SED1 leader_messages_copy = leader_messages.clone() msg = leader_messages_copy.next_mle_message( mle.CommandType.CHILD_UPDATE_RESPONSE, sent_to_node=self.nodes[MED1]) command.check_child_update_response_from_parent( msg, address_registration=CheckType.CONTAIN) leader_addresses = msg.get_mle_message_tlv( mle.AddressRegistration).addresses self.assertTrue( all(addr in leader_addresses for addr in med1_addresses)) # 6A & 6B - Leader if config.LEADER_NOTIFY_SED_BY_CHILD_UPDATE_REQUEST: msg = leader_messages.next_mle_message( mle.CommandType.CHILD_UPDATE_REQUEST, sent_to_node=self.nodes[SED1]) command.check_child_update_request_from_parent( msg, leader_data=CheckType.CONTAIN, network_data=CheckType.CONTAIN, active_timestamp=CheckType.CONTAIN) else: msg = leader_messages.next_mle_message( mle.CommandType.DATA_RESPONSE, sent_to_node=self.nodes[SED1]) command.check_data_response(msg, network_data=CheckType.CONTAIN, active_timestamp=CheckType.CONTAIN) # 7 - N/A # Get addresses registered by SED1 msg = sed1_messages.next_mle_message( mle.CommandType.CHILD_UPDATE_REQUEST) sed1_addresses = msg.get_mle_message_tlv( mle.AddressRegistration).addresses # 8 - Leader msg = leader_messages.next_mle_message( mle.CommandType.CHILD_UPDATE_RESPONSE, sent_to_node=self.nodes[SED1]) command.check_child_update_response_from_parent( msg, address_registration=CheckType.CONTAIN) leader_addresses = msg.get_mle_message_tlv( mle.AddressRegistration).addresses self.assertTrue( all(addr in leader_addresses for addr in sed1_addresses))
def test(self): # 1 - All self.nodes[LEADER].start() self.simulator.go(5) self.assertEqual(self.nodes[LEADER].get_state(), 'leader') self.nodes[ROUTER].start() self.simulator.go(5) self.assertEqual(self.nodes[ROUTER].get_state(), 'router') self.nodes[SED1].start() self.simulator.go(5) self.assertEqual(self.nodes[SED1].get_state(), 'child') self.nodes[MED1].start() self.simulator.go(5) self.assertEqual(self.nodes[MED1].get_state(), 'child') # 2 - N/A # Clear collected messages self.simulator.get_messages_sent_by(LEADER) self.simulator.get_messages_sent_by(MED1) self.simulator.get_messages_sent_by(SED1) self.nodes[LEADER].add_prefix('2001:2:0:1::/64', 'paros') self.nodes[LEADER].add_prefix('2001:2:0:2::/64', 'paro') self.nodes[LEADER].register_netdata() self.simulator.go(5) # Set lowpan context of sniffer self.simulator.set_lowpan_context(1, '2001:2:0:1::/64') self.simulator.set_lowpan_context(2, '2001:2:0:2::/64') leader_messages = self.simulator.get_messages_sent_by(LEADER) med1_messages = self.simulator.get_messages_sent_by(MED1) sed1_messages = self.simulator.get_messages_sent_by(SED1) addrs = self.nodes[SED1].get_addrs() self.assertTrue(any('2001:2:0:1' in addr[0:10] for addr in addrs)) self.assertFalse(any('2001:2:0:2' in addr[0:10] for addr in addrs)) for addr in addrs: if addr[0:10] == '2001:2:0:1' or addr[0:10] == '2001:2:0:2': self.assertTrue(self.nodes[LEADER].ping(addr)) addrs = self.nodes[MED1].get_addrs() self.assertTrue(any('2001:2:0:1' in addr[0:10] for addr in addrs)) self.assertTrue(any('2001:2:0:2' in addr[0:10] for addr in addrs)) for addr in addrs: if addr[0:10] == '2001:2:0:1' or addr[0:10] == '2001:2:0:2': self.assertTrue(self.nodes[LEADER].ping(addr)) # 3 - Leader msg = leader_messages.next_mle_message(mle.CommandType.DATA_RESPONSE) check_data_response(msg, network_data_check=NetworkDataCheck( prefixes_check=PrefixesCheck(prefix_check_list=[ SinglePrefixCheck(b'2001000200000001'), SinglePrefixCheck(b'2001000200000002')]) ) ) # 4 - N/A # Get addresses registered by MED1 msg = med1_messages.next_mle_message(mle.CommandType.CHILD_UPDATE_REQUEST) check_child_update_request_from_child(msg, address_registration=CheckType.CONTAIN, CIDs=[0, 1, 2]) # 5 - Leader # Make a copy of leader's messages to ensure that we don't miss messages to SED1 leader_messages_copy = leader_messages.clone() msg = leader_messages_copy.next_mle_message(mle.CommandType.CHILD_UPDATE_RESPONSE, sent_to_node=self.nodes[MED1]) check_child_update_response(msg, address_registration=CheckType.CONTAIN, CIDs=[1, 2]) # 6A & 6B - Leader if config.LEADER_NOTIFY_SED_BY_CHILD_UPDATE_REQUEST: msg = leader_messages.next_mle_message(mle.CommandType.CHILD_UPDATE_REQUEST, sent_to_node=self.nodes[SED1]) check_child_update_request_from_parent(msg, leader_data=CheckType.CONTAIN, network_data=CheckType.CONTAIN, active_timestamp=CheckType.CONTAIN) else: msg = leader_messages.next_mle_message(mle.CommandType.DATA_RESPONSE, sent_to_node=self.nodes[SED1]) check_data_response(msg, network_data_check=command.NetworkDataCheck()) # 7 - N/A # Get addresses registered by SED1 msg = sed1_messages.next_mle_message(mle.CommandType.CHILD_UPDATE_REQUEST) check_child_update_request_from_child(msg, address_registration=CheckType.CONTAIN, CIDs=[0, 1]) # 8 - Leader msg = leader_messages.next_mle_message(mle.CommandType.CHILD_UPDATE_RESPONSE, sent_to_node=self.nodes[SED1]) check_child_update_response(msg, address_registration=CheckType.CONTAIN, CIDs=[1])