def verify_prefix( node_list, prefix, prefix_len=64, stable=True, priority='med', on_mesh=False, slaac=False, dhcp=False, configure=False, default_route=False, preferred=False, ): """ This function verifies that the `prefix` is present on all nodes in the `node_list`. """ for node in node_list: prefixes = wpan.parse_on_mesh_prefix_result( node.get(wpan.WPAN_THREAD_ON_MESH_PREFIXES)) for p in prefixes: if p.prefix == prefix: if (int(p.prefix_len) == prefix_len and p.is_stable() == stable and p.is_on_mesh() == on_mesh and p.is_def_route() == default_route and p.is_slaac() == slaac and p.is_dhcp() == dhcp and p.is_config() == configure and p.is_preferred() == preferred and p.priority == priority): break else: raise wpan.VerifyError("Did not find prefix {} on node {}".format( prefix, node))
def verify_prefix(node_list, prefix, rloc16, prefix_len=64, stable=True, priority='med', on_mesh=False, slaac=False, dhcp=False, configure=False, default_route=False, preferred=True): """ This function verifies that the `prefix` is present on all the nodes in the `node_list`. It also verifies that the `prefix` is associated with the given `rloc16` (as an integer). """ for node in node_list: prefixes = wpan.parse_on_mesh_prefix_result( node.get(wpan.WPAN_THREAD_ON_MESH_PREFIXES)) for p in prefixes: if p.prefix == prefix and p.origin == "ncp" and int(p.rloc16(), 0) == rloc16: verify(int(p.prefix_len) == prefix_len) verify(p.is_stable() == stable) verify(p.is_on_mesh() == on_mesh) verify(p.is_def_route() == default_route) verify(p.is_slaac() == slaac) verify(p.is_dhcp() == dhcp) verify(p.is_config() == configure) verify(p.is_preferred() == preferred) verify(p.priority == priority) break else: raise wpan.VerifyError("Did not find prefix {} on node {}".format( prefix, node))
def verify_child_table(parent, children): """ This function verifies that child table on `parent` node contains all the entries in `children` list and the child table entry's mode value matches the children Thread mode. """ child_table = wpan.parse_child_table_result( parent.get(wpan.WPAN_THREAD_CHILD_TABLE)) verify(len(child_table) == len(children)) for child in children: ext_addr = child.get(wpan.WPAN_EXT_ADDRESS)[1:-1] for entry in child_table: if entry.ext_address == ext_addr: break else: raise wpan.VerifyError( 'Failed to find a child entry for extended address {} in table' .format(ext_addr)) exit(1) verify( int(entry.rloc16, 16) == int(child.get(wpan.WPAN_THREAD_RLOC16), 16)) mode = int(child.get(wpan.WPAN_THREAD_DEVICE_MODE), 0) verify(entry.is_rx_on_when_idle() == ( mode & wpan.THREAD_MODE_FLAG_RX_ON_WHEN_IDLE != 0)) verify(entry.is_ftd() == ( mode & wpan.THREAD_MODE_FLAG_FULL_THREAD_DEV != 0)) verify(entry.is_full_net_data() == ( mode & wpan.THREAD_MODE_FLAG_FULL_NETWORK_DATA != 0)) verify(entry.is_sec_data_req() == ( mode & wpan.THREAD_MODE_FLAG_SECURE_DATA_REQUEST != 0))
def check_addresses_and_prefixes(): # Verify that the addresses are present in "IPv6:AllAddresses" wpantund # property on the corresponding node. verify(r2.find_ip6_address_with_prefix(IP6_PREFIX_1) == IP6_ADDR_1) verify(fed1.find_ip6_address_with_prefix(IP6_PREFIX_2) == IP6_ADDR_2) verify(sed2.find_ip6_address_with_prefix(IP6_PREFIX_3) == IP6_ADDR_3) # Verify that all prefixes are present in network data on all nodes (with # correct flags). for prefix in [IP6_PREFIX_1, IP6_PREFIX_2, IP6_PREFIX_3]: for node in all_nodes: prefixes = wpan.parse_on_mesh_prefix_result( node.get(wpan.WPAN_THREAD_ON_MESH_PREFIXES)) for p in prefixes: if p.prefix == prefix: verify(p.prefix_len == '64') verify(p.is_stable()) verify(p.is_on_mesh()) verify(p.is_preferred()) verify(p.is_def_route() is False) verify(p.is_slaac() is False) verify(p.is_dhcp() is False) verify(p.is_config() is False) verify(p.priority == "med") break else: # `for` loop finished without finding the prefix. raise wpan.VerifyError( 'Did not find prefix {} on node {}'.format(prefix, node)) # Verify that IPv6 address of `sed2` is present on `r2` (its parent) # "Thread:ChildTable:Addresses". addr_str = r2.get(wpan.WPAN_THREAD_CHILD_TABLE_ADDRESSES) # search for index on address in the `addr_str` and ensure it is # non-negative. verify(addr_str.find(IP6_ADDR_3) >= 0)
def check_prefix(): for node in [r1, r2]: prefixes = wpan.parse_on_mesh_prefix_result(node.get(wpan.WPAN_THREAD_ON_MESH_PREFIXES)) for p in prefixes: if p.prefix == IP6_PREFIX: if (p.origin == 'ncp' and p.prefix_len == '64' and p.is_stable() and p.is_on_mesh() and p.is_preferred() and not p.is_def_route() and not p.is_slaac() and not p.is_dhcp() and not p.is_config() and p.priority == "med"): break else: # `for` loop finished without finding the prefix. raise wpan.VerifyError('Did not find prefix {} on node {}'.format(IP6_PREFIX, r1))
def verify_neighbor_table(node, neighbors): """ This function verifies that the neighbor table of a given `node` contains the node in the `neighbors` list. """ neighbor_table = wpan.parse_neighbor_table_result(node.get(wpan.WPAN_THREAD_NEIGHBOR_TABLE)) for neighbor in neighbors: ext_addr = neighbor.get(wpan.WPAN_EXT_ADDRESS)[1:-1] for entry in neighbor_table: if entry.ext_address == ext_addr: break else: raise wpan.VerifyError('Failed to find a neighbor entry for extended address {} in table'.format(ext_addr))
def verify_no_prefix(node_list, prefix, rloc16): """ This function verifies that none of the nodes in `node_list` contains the on-mesh `prefix` associated with the given `rloc16`. """ for node in node_list: prefixes = wpan.parse_on_mesh_prefix_result( node.get(wpan.WPAN_THREAD_ON_MESH_PREFIXES)) for p in prefixes: if p.prefix == prefix and p.origin == "ncp" and int(p.rloc16(), 0) == rloc16: raise wpan.VerifyError( "Did find prefix {} with rloc {} on node {}".format( prefix, hex(rloc16), node))
def verify_interface_routes(node, route_list): """ This function verifies that node has the same interface routes as given by `route_list` which is an array of tuples of (route, prefix_len, metric). """ node_routes = wpan.parse_interface_routes_result(node.get(wpan.WPAN_IP6_INTERFACE_ROUTES)) verify(len(route_list) == len(node_routes)) for route in route_list: for node_route in node_routes: if (node_route.route_prefix, node_route.prefix_len, node_route.metric) == route: break else: raise wpan.VerifyError( 'Did not find route {} on node {}'.format(route, node) )
def check_r4_router_table(): router_table = wpan.parse_router_table_result( r4.get(wpan.WPAN_THREAD_ROUTER_TABLE)) verify(len(router_table) == 4) for entry in router_table: if entry.rloc16 == r1_rloc: # r4's next hop towards r1 should be through r3. verify(not entry.is_link_established()) verify(entry.next_hop == r3_id) elif entry.rloc16 == r2_rloc: # r4's next hop towards r2 should be through r3. verify(not entry.is_link_established()) verify(entry.next_hop == r3_id) elif entry.rloc16 == r3_rloc: # r4 should be directly connected to r3. verify(entry.is_link_established()) verify(entry.ext_address == r3_ext_addr) elif entry.rloc16 == r4_rloc: pass else: raise (wpan.VerifyError("unknown entry in the router table of r4"))
def check_r3_router_table(): router_table = wpan.parse_router_table_result( r3.get(wpan.WPAN_THREAD_ROUTER_TABLE)) verify(len(router_table) == 4) for entry in router_table: if entry.rloc16 == r1_rloc: # r3 should be directly connected to r1. verify(entry.is_link_established()) verify(entry.ext_address == r1_ext_addr) elif entry.rloc16 == r2_rloc: # r3 should be directly connected to r2. verify(entry.is_link_established()) verify(entry.ext_address == r2_ext_addr) elif entry.rloc16 == r3_rloc: pass elif entry.rloc16 == r4_rloc: # r3 should be directly connected to r4. verify(entry.is_link_established()) verify(entry.ext_address == r4_ext_addr) else: raise (wpan.VerifyError("unknown entry in the router table of r3"))
# Get and parse the neighbor table on routers[0]. neighbor_table = wpan.parse_neighbor_table_result(routers[0].get( wpan.WPAN_THREAD_NEIGHBOR_TABLE)) verify(len(neighbor_table) == NUM_ROUTERS - 1 + NUM_CHILDREN) # Verify that all children are seen in the neighbor table for child in children: ext_addr = child.get(wpan.WPAN_EXT_ADDRESS)[1:-1] for entry in neighbor_table: if entry.ext_address == ext_addr: break else: raise wpan.VerifyError( 'Failed to find a child entry for extended address {} in table'. format(ext_addr)) verify( int(entry.rloc16, 16) == int(child.get(wpan.WPAN_THREAD_RLOC16), 16)) verify(entry.is_rx_on_when_idle() is False) verify(entry.is_ftd() is False) verify(entry.is_child()) # Verify that all other routers are seen in the neighbor table for router in routers[1:]: ext_addr = router.get(wpan.WPAN_EXT_ADDRESS)[1:-1] for entry in neighbor_table: if entry.ext_address == ext_addr: break else:
# The address cache table on r1 should contain two entries for # c2 and c3 addresses. addr_cache_table = wpan.parse_address_cache_table_result(r1.get(wpan.WPAN_THREAD_ADDRESS_CACHE_TABLE)) verify(len(addr_cache_table) == 2) for entry in addr_cache_table: if entry.address == c2_address: # Entry for c2 should point towards its parent r2. verify(entry.rloc16 == r2_rloc) elif entry.address == c3_address: # Entry for c3 should point towards c3 itself. verify(entry.rloc16 == c3_rloc) else: raise (wpan.VerifyError("Unknown entry in the address cache table")) # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # Force c2 to switch its parent from r2 to r3 CHILD_SUPERVISION_CHECK_TIMEOUT = 2 PARENT_SUPERVISION_INTERVAL = 1 REATTACH_WAIT_TIME = CHILD_SUPERVISION_CHECK_TIMEOUT / speedup + 6 c2.set( wpan.WPAN_CHILD_SUPERVISION_CHECK_TIMEOUT, str(CHILD_SUPERVISION_CHECK_TIMEOUT), ) r3.set(wpan.WPAN_CHILD_SUPERVISION_INTERVAL, str(PARENT_SUPERVISION_INTERVAL))