diff --git a/.travis/check-pretty b/.travis/check-pretty index 30a9a2b9f..3e862e09c 100755 --- a/.travis/check-pretty +++ b/.travis/check-pretty @@ -31,12 +31,12 @@ set -e -x -o pipefail setup_python() { - python -m pip install flake8 + python3 -m pip install yapf } check_python() { - flake8 --config=script/pystyle.cfg tests tools + python3 -m yapf --style google -dpr tests tools } check_clang() diff --git a/STYLE_GUIDE.md b/STYLE_GUIDE.md index c9887527c..233e8de91 100644 --- a/STYLE_GUIDE.md +++ b/STYLE_GUIDE.md @@ -185,4 +185,4 @@ ## Format and Style -- All code should adhere to [PEP 8](https://www.python.org/dev/peps/pep-0008/). +- All code should adhere to [Google Python Style Guide](http://google.github.io/styleguide/pyguide.html). diff --git a/script/bootstrap b/script/bootstrap index 1106e395b..c535361c4 100755 --- a/script/bootstrap +++ b/script/bootstrap @@ -56,6 +56,10 @@ install_packages_apt() # add clang-format for pretty sudo apt-get -y install clang-format-6.0 + + # add yapf for pretty + python3 -m pip install yapf || echo 'Failed to install python code formatter yapf. Install it manually if you need.' + } install_packages_opkg() @@ -89,6 +93,9 @@ install_packages_brew() brew install llvm@6 sudo ln -s "$(brew --prefix llvm@6)/bin/clang-format" /usr/local/bin/clang-format-6.0 } + + # add yapf for pretty + python3 -m pip install yapf || echo 'Failed to install python code formatter yapf. Install it manually if you need.' } install_packages_source() diff --git a/script/make-pretty b/script/make-pretty index f254ee18c..6db40cf2e 100755 --- a/script/make-pretty +++ b/script/make-pretty @@ -53,6 +53,7 @@ main() { trap at_exit INT TERM EXIT make_pretty + python3 -m yapf --style google -ipr "${SRC_DIR}/tests" "${SRC_DIR}/tools" } main "$@" diff --git a/script/pystyle.cfg b/script/pystyle.cfg deleted file mode 100644 index dd64ac17a..000000000 --- a/script/pystyle.cfg +++ /dev/null @@ -1,16 +0,0 @@ -[flake8] -# it's not a bug that we aren't using all of hacking, ignore: -# E203: White space before ':' (see #python#black#315). -# W503: Line break occurred before a binary operator (see #python#black#README.md). -ignore = E203, W503 - -# relax the length limitation for now. -max-line-length = 119 -max-doc-length = 119 - -# Print the source code generating the error/warning in question. -show_source = True -show-source = True - -# print the total number of errors. -count = True diff --git a/tests/scripts/thread-cert/Cert_5_1_01_RouterAttach.py b/tests/scripts/thread-cert/Cert_5_1_01_RouterAttach.py index 48d0aeac2..dafb2dd6e 100755 --- a/tests/scripts/thread-cert/Cert_5_1_01_RouterAttach.py +++ b/tests/scripts/thread-cert/Cert_5_1_01_RouterAttach.py @@ -39,6 +39,7 @@ ROUTER = 2 class Cert_5_1_01_RouterAttach(unittest.TestCase): + def setUp(self): self.simulator = config.create_default_simulator() @@ -110,9 +111,7 @@ class Cert_5_1_01_RouterAttach(unittest.TestCase): msg.assertMleMessageContainsTlv(mle.Version) # 4 - Router - msg = router_messages.next_mle_message( - mle.CommandType.CHILD_ID_REQUEST - ) + msg = router_messages.next_mle_message(mle.CommandType.CHILD_ID_REQUEST) msg.assertSentToNode(self.nodes[LEADER]) msg.assertMleMessageContainsTlv(mle.Response) msg.assertMleMessageContainsTlv(mle.LinkLayerFrameCounter) @@ -125,8 +124,7 @@ class Cert_5_1_01_RouterAttach(unittest.TestCase): # 5 - Leader msg = leader_messages.next_mle_message( - mle.CommandType.CHILD_ID_RESPONSE - ) + mle.CommandType.CHILD_ID_RESPONSE) msg.assertSentToNode(self.nodes[ROUTER]) msg.assertMleMessageContainsTlv(mle.SourceAddress) msg.assertMleMessageContainsTlv(mle.LeaderData) @@ -162,8 +160,7 @@ class Cert_5_1_01_RouterAttach(unittest.TestCase): # 9 - Leader msg = leader_messages.next_mle_message( - mle.CommandType.LINK_ACCEPT_AND_REQUEST - ) + mle.CommandType.LINK_ACCEPT_AND_REQUEST) msg.assertMleMessageContainsTlv(mle.SourceAddress) msg.assertMleMessageContainsTlv(mle.LeaderData) msg.assertMleMessageContainsTlv(mle.Response) diff --git a/tests/scripts/thread-cert/Cert_5_1_02_ChildAddressTimeout.py b/tests/scripts/thread-cert/Cert_5_1_02_ChildAddressTimeout.py index 27adb96c8..03734b218 100755 --- a/tests/scripts/thread-cert/Cert_5_1_02_ChildAddressTimeout.py +++ b/tests/scripts/thread-cert/Cert_5_1_02_ChildAddressTimeout.py @@ -42,6 +42,7 @@ MTDS = [ED, SED] class Cert_5_1_02_ChildAddressTimeout(unittest.TestCase): + def setUp(self): self.simulator = config.create_default_simulator() diff --git a/tests/scripts/thread-cert/Cert_5_1_03_RouterAddressReallocation.py b/tests/scripts/thread-cert/Cert_5_1_03_RouterAddressReallocation.py index 8dbb5b540..2ce8c0c6b 100755 --- a/tests/scripts/thread-cert/Cert_5_1_03_RouterAddressReallocation.py +++ b/tests/scripts/thread-cert/Cert_5_1_03_RouterAddressReallocation.py @@ -40,6 +40,7 @@ ROUTER2 = 3 class Cert_5_1_03_RouterAddressReallocation(unittest.TestCase): + def setUp(self): self.simulator = config.create_default_simulator() @@ -124,8 +125,7 @@ class Cert_5_1_03_RouterAddressReallocation(unittest.TestCase): # Leader or Router1 can be parent of Router2 if leader_messages.contains_mle_message( - mle.CommandType.CHILD_ID_RESPONSE - ): + mle.CommandType.CHILD_ID_RESPONSE): leader_messages.next_mle_message(mle.CommandType.CHILD_ID_RESPONSE) msg = router2_messages.next_coap_message("0.02") @@ -134,11 +134,8 @@ class Cert_5_1_03_RouterAddressReallocation(unittest.TestCase): msg = leader_messages.next_coap_message("2.04") elif router1_messages.contains_mle_message( - mle.CommandType.CHILD_ID_RESPONSE - ): - router1_messages.next_mle_message( - mle.CommandType.CHILD_ID_RESPONSE - ) + mle.CommandType.CHILD_ID_RESPONSE): + router1_messages.next_mle_message(mle.CommandType.CHILD_ID_RESPONSE) msg = router2_messages.next_coap_message("0.02") msg.assertCoapMessageRequestUriPath("/a/as") @@ -154,8 +151,7 @@ class Cert_5_1_03_RouterAddressReallocation(unittest.TestCase): # Router1 make two attempts to reconnect to its current Partition. for _ in range(4): msg = router1_messages.next_mle_message( - mle.CommandType.PARENT_REQUEST - ) + mle.CommandType.PARENT_REQUEST) msg.assertSentWithHopLimit(255) msg.assertSentToDestinationAddress("ff02::2") msg.assertMleMessageContainsTlv(mle.Mode) @@ -182,8 +178,7 @@ class Cert_5_1_03_RouterAddressReallocation(unittest.TestCase): # 7 - Router1 msg = router1_messages.next_mle_message( - mle.CommandType.CHILD_ID_REQUEST - ) + mle.CommandType.CHILD_ID_REQUEST) msg.assertSentToNode(self.nodes[ROUTER2]) msg.assertMleMessageContainsTlv(mle.Response) msg.assertMleMessageContainsTlv(mle.LinkLayerFrameCounter) diff --git a/tests/scripts/thread-cert/Cert_5_1_04_RouterAddressReallocation.py b/tests/scripts/thread-cert/Cert_5_1_04_RouterAddressReallocation.py index a94b3f2fc..605f55b45 100755 --- a/tests/scripts/thread-cert/Cert_5_1_04_RouterAddressReallocation.py +++ b/tests/scripts/thread-cert/Cert_5_1_04_RouterAddressReallocation.py @@ -40,6 +40,7 @@ ROUTER2 = 3 class Cert_5_1_04_RouterAddressReallocation(unittest.TestCase): + def setUp(self): self.simulator = config.create_default_simulator() @@ -123,8 +124,7 @@ class Cert_5_1_04_RouterAddressReallocation(unittest.TestCase): # Leader or Router1 can be parent of Router2 if leader_messages.contains_mle_message( - mle.CommandType.CHILD_ID_RESPONSE - ): + mle.CommandType.CHILD_ID_RESPONSE): leader_messages.next_mle_message(mle.CommandType.CHILD_ID_RESPONSE) msg = router2_messages.next_coap_message("0.02") @@ -133,11 +133,8 @@ class Cert_5_1_04_RouterAddressReallocation(unittest.TestCase): msg = leader_messages.next_coap_message("2.04") elif router1_messages.contains_mle_message( - mle.CommandType.CHILD_ID_RESPONSE - ): - router1_messages.next_mle_message( - mle.CommandType.CHILD_ID_RESPONSE - ) + mle.CommandType.CHILD_ID_RESPONSE): + router1_messages.next_mle_message(mle.CommandType.CHILD_ID_RESPONSE) msg = router2_messages.next_coap_message("0.02") msg.assertCoapMessageRequestUriPath("/a/as") @@ -153,8 +150,7 @@ class Cert_5_1_04_RouterAddressReallocation(unittest.TestCase): # Router1 make two attempts to reconnect to its current Partition. for _ in range(4): msg = router1_messages.next_mle_message( - mle.CommandType.PARENT_REQUEST - ) + mle.CommandType.PARENT_REQUEST) msg.assertSentWithHopLimit(255) msg.assertSentToDestinationAddress("ff02::2") msg.assertMleMessageContainsTlv(mle.Mode) @@ -184,9 +180,7 @@ class Cert_5_1_04_RouterAddressReallocation(unittest.TestCase): router2_messages.next_mle_message(mle.CommandType.CHILD_ID_REQUEST) # 9 - Router1 - msg = router1_messages.next_mle_message( - mle.CommandType.PARENT_RESPONSE - ) + msg = router1_messages.next_mle_message(mle.CommandType.PARENT_RESPONSE) msg.assertSentToNode(self.nodes[ROUTER2]) msg.assertMleMessageContainsTlv(mle.SourceAddress) msg.assertMleMessageContainsTlv(mle.LeaderData) @@ -199,8 +193,7 @@ class Cert_5_1_04_RouterAddressReallocation(unittest.TestCase): msg.assertMleMessageContainsTlv(mle.Version) msg = router1_messages.next_mle_message( - mle.CommandType.CHILD_ID_RESPONSE - ) + mle.CommandType.CHILD_ID_RESPONSE) msg.assertSentToNode(self.nodes[ROUTER2]) msg.assertMleMessageContainsTlv(mle.SourceAddress) msg.assertMleMessageContainsTlv(mle.LeaderData) diff --git a/tests/scripts/thread-cert/Cert_5_1_05_RouterAddressTimeout.py b/tests/scripts/thread-cert/Cert_5_1_05_RouterAddressTimeout.py index 8d85b4bab..c61abbf1a 100755 --- a/tests/scripts/thread-cert/Cert_5_1_05_RouterAddressTimeout.py +++ b/tests/scripts/thread-cert/Cert_5_1_05_RouterAddressTimeout.py @@ -39,6 +39,7 @@ ROUTER1 = 2 class Cert_5_1_05_RouterAddressTimeout(unittest.TestCase): + def setUp(self): self.simulator = config.create_default_simulator() diff --git a/tests/scripts/thread-cert/Cert_5_1_06_RemoveRouterId.py b/tests/scripts/thread-cert/Cert_5_1_06_RemoveRouterId.py index afd7b3de4..9b642abb1 100755 --- a/tests/scripts/thread-cert/Cert_5_1_06_RemoveRouterId.py +++ b/tests/scripts/thread-cert/Cert_5_1_06_RemoveRouterId.py @@ -40,6 +40,7 @@ ROUTER1 = 2 class Cert_5_1_06_RemoveRouterId(unittest.TestCase): + def setUp(self): self.simulator = config.create_default_simulator() @@ -105,8 +106,7 @@ class Cert_5_1_06_RemoveRouterId(unittest.TestCase): command.check_parent_request(msg, is_first_request=True) msg = router1_messages.next_mle_message( - mle.CommandType.CHILD_ID_REQUEST, sent_to_node=self.nodes[LEADER] - ) + mle.CommandType.CHILD_ID_REQUEST, sent_to_node=self.nodes[LEADER]) command.check_child_id_request( msg, tlv_request=CheckType.CONTAIN, diff --git a/tests/scripts/thread-cert/Cert_5_1_07_MaxChildCount.py b/tests/scripts/thread-cert/Cert_5_1_07_MaxChildCount.py index 20c8e8629..d87c3bb63 100755 --- a/tests/scripts/thread-cert/Cert_5_1_07_MaxChildCount.py +++ b/tests/scripts/thread-cert/Cert_5_1_07_MaxChildCount.py @@ -38,6 +38,7 @@ SED1 = 7 class Cert_5_1_07_MaxChildCount(unittest.TestCase): + def setUp(self): self.simulator = config.create_default_simulator() diff --git a/tests/scripts/thread-cert/Cert_5_1_08_RouterAttachConnectivity.py b/tests/scripts/thread-cert/Cert_5_1_08_RouterAttachConnectivity.py index 08d8627e9..4c3fa25f3 100755 --- a/tests/scripts/thread-cert/Cert_5_1_08_RouterAttachConnectivity.py +++ b/tests/scripts/thread-cert/Cert_5_1_08_RouterAttachConnectivity.py @@ -41,6 +41,7 @@ ROUTER4 = 5 class Cert_5_1_08_RouterAttachConnectivity(unittest.TestCase): + def setUp(self): self.simulator = config.create_default_simulator() @@ -135,20 +136,15 @@ class Cert_5_1_08_RouterAttachConnectivity(unittest.TestCase): self.assertEqual(0, scan_mask_tlv.end_device) # 3 - Router2, Router3 - msg = router2_messages.next_mle_message( - mle.CommandType.PARENT_RESPONSE - ) + msg = router2_messages.next_mle_message(mle.CommandType.PARENT_RESPONSE) msg.assertSentToNode(self.nodes[ROUTER4]) - msg = router3_messages.next_mle_message( - mle.CommandType.PARENT_RESPONSE - ) + msg = router3_messages.next_mle_message(mle.CommandType.PARENT_RESPONSE) msg.assertSentToNode(self.nodes[ROUTER4]) # 4 - Router4 msg = router4_messages.next_mle_message( - mle.CommandType.CHILD_ID_REQUEST - ) + mle.CommandType.CHILD_ID_REQUEST) msg.assertSentToNode(self.nodes[ROUTER3]) msg.assertMleMessageContainsTlv(mle.Response) msg.assertMleMessageContainsTlv(mle.LinkLayerFrameCounter) diff --git a/tests/scripts/thread-cert/Cert_5_1_09_REEDAttachConnectivity.py b/tests/scripts/thread-cert/Cert_5_1_09_REEDAttachConnectivity.py index 5c1398c77..b1fd33124 100755 --- a/tests/scripts/thread-cert/Cert_5_1_09_REEDAttachConnectivity.py +++ b/tests/scripts/thread-cert/Cert_5_1_09_REEDAttachConnectivity.py @@ -41,6 +41,7 @@ ROUTER2 = 5 class Cert_5_1_09_REEDAttachConnectivity(unittest.TestCase): + def setUp(self): self.simulator = config.create_default_simulator() @@ -161,8 +162,7 @@ class Cert_5_1_09_REEDAttachConnectivity(unittest.TestCase): # 6 - Router2 msg = router2_messages.next_mle_message( - mle.CommandType.CHILD_ID_REQUEST - ) + mle.CommandType.CHILD_ID_REQUEST) msg.assertSentToNode(self.nodes[REED1]) msg.assertMleMessageContainsTlv(mle.Response) msg.assertMleMessageContainsTlv(mle.LinkLayerFrameCounter) diff --git a/tests/scripts/thread-cert/Cert_5_1_10_RouterAttachLinkQuality.py b/tests/scripts/thread-cert/Cert_5_1_10_RouterAttachLinkQuality.py index 5f09e2176..6a32821cd 100755 --- a/tests/scripts/thread-cert/Cert_5_1_10_RouterAttachLinkQuality.py +++ b/tests/scripts/thread-cert/Cert_5_1_10_RouterAttachLinkQuality.py @@ -40,6 +40,7 @@ ROUTER3 = 4 class Cert_5_1_10_RouterAttachLinkQuality(unittest.TestCase): + def setUp(self): self.simulator = config.create_default_simulator() @@ -63,9 +64,8 @@ class Cert_5_1_10_RouterAttachLinkQuality(unittest.TestCase): self.nodes[ROUTER2].set_panid(0xface) self.nodes[ROUTER2].set_mode('rsdn') self.nodes[ROUTER2].add_whitelist(self.nodes[LEADER].get_addr64()) - self.nodes[ROUTER2].add_whitelist( - self.nodes[ROUTER3].get_addr64(), rssi=-85 - ) + self.nodes[ROUTER2].add_whitelist(self.nodes[ROUTER3].get_addr64(), + rssi=-85) self.nodes[ROUTER2].enable_whitelist() self.nodes[ROUTER2].set_router_selection_jitter(1) @@ -142,20 +142,15 @@ class Cert_5_1_10_RouterAttachLinkQuality(unittest.TestCase): msg.assertMleMessageContainsTlv(mle.Version) # 4 - Router1, Router2 - msg = router1_messages.next_mle_message( - mle.CommandType.PARENT_RESPONSE - ) + msg = router1_messages.next_mle_message(mle.CommandType.PARENT_RESPONSE) msg.assertSentToNode(self.nodes[ROUTER3]) - msg = router2_messages.next_mle_message( - mle.CommandType.PARENT_RESPONSE - ) + msg = router2_messages.next_mle_message(mle.CommandType.PARENT_RESPONSE) msg.assertSentToNode(self.nodes[ROUTER3]) # 5 - Router3 msg = router3_messages.next_mle_message( - mle.CommandType.CHILD_ID_REQUEST - ) + mle.CommandType.CHILD_ID_REQUEST) msg.assertSentToNode(self.nodes[ROUTER1]) msg.assertMleMessageContainsTlv(mle.Response) msg.assertMleMessageContainsTlv(mle.LinkLayerFrameCounter) diff --git a/tests/scripts/thread-cert/Cert_5_1_11_REEDAttachLinkQuality.py b/tests/scripts/thread-cert/Cert_5_1_11_REEDAttachLinkQuality.py index be6195dd9..412dada4d 100755 --- a/tests/scripts/thread-cert/Cert_5_1_11_REEDAttachLinkQuality.py +++ b/tests/scripts/thread-cert/Cert_5_1_11_REEDAttachLinkQuality.py @@ -40,6 +40,7 @@ ROUTER1 = 4 class Cert_5_1_11_REEDAttachLinkQuality(unittest.TestCase): + def setUp(self): self.simulator = config.create_default_simulator() @@ -63,9 +64,8 @@ class Cert_5_1_11_REEDAttachLinkQuality(unittest.TestCase): self.nodes[ROUTER2].set_panid(0xface) self.nodes[ROUTER2].set_mode('rsdn') self.nodes[ROUTER2].add_whitelist(self.nodes[LEADER].get_addr64()) - self.nodes[ROUTER2].add_whitelist( - self.nodes[ROUTER1].get_addr64(), rssi=-85 - ) + self.nodes[ROUTER2].add_whitelist(self.nodes[ROUTER1].get_addr64(), + rssi=-85) self.nodes[ROUTER2].enable_whitelist() self.nodes[ROUTER2].set_router_selection_jitter(1) @@ -141,9 +141,7 @@ class Cert_5_1_11_REEDAttachLinkQuality(unittest.TestCase): self.assertEqual(0, scan_mask_tlv.end_device) # 4 - Router2 - msg = router2_messages.next_mle_message( - mle.CommandType.PARENT_RESPONSE - ) + msg = router2_messages.next_mle_message(mle.CommandType.PARENT_RESPONSE) msg.assertSentToNode(self.nodes[ROUTER1]) # 5 - Router1 @@ -161,8 +159,7 @@ class Cert_5_1_11_REEDAttachLinkQuality(unittest.TestCase): # 6 - Router1 msg = router1_messages.next_mle_message( - mle.CommandType.CHILD_ID_REQUEST - ) + mle.CommandType.CHILD_ID_REQUEST) msg.assertMleMessageContainsTlv(mle.LinkLayerFrameCounter) msg.assertMleMessageContainsTlv(mle.Mode) msg.assertMleMessageContainsTlv(mle.Response) diff --git a/tests/scripts/thread-cert/Cert_5_1_12_NewRouterNeighborSync.py b/tests/scripts/thread-cert/Cert_5_1_12_NewRouterNeighborSync.py index 738ebd219..f8ccdaa24 100755 --- a/tests/scripts/thread-cert/Cert_5_1_12_NewRouterNeighborSync.py +++ b/tests/scripts/thread-cert/Cert_5_1_12_NewRouterNeighborSync.py @@ -39,6 +39,7 @@ ROUTER2 = 3 class Cert_5_1_12_NewRouterSync(unittest.TestCase): + def setUp(self): self.simulator = config.create_default_simulator() @@ -70,21 +71,17 @@ class Cert_5_1_12_NewRouterSync(unittest.TestCase): n.destroy() self.simulator.stop() - def verify_step_4( - self, router1_messages, router2_messages, req_receiver, accept_receiver - ): + def verify_step_4(self, router1_messages, router2_messages, req_receiver, + accept_receiver): if router2_messages.contains_mle_message( - mle.CommandType.LINK_REQUEST - ) and ( - router1_messages.contains_mle_message(mle.CommandType.LINK_ACCEPT) - or router1_messages.contains_mle_message( - mle.CommandType.LINK_ACCEPT_AND_REQUEST - ) - ): + mle.CommandType.LINK_REQUEST) and ( + router1_messages.contains_mle_message( + mle.CommandType.LINK_ACCEPT) or + router1_messages.contains_mle_message( + mle.CommandType.LINK_ACCEPT_AND_REQUEST)): msg = router2_messages.next_mle_message( - mle.CommandType.LINK_REQUEST - ) + mle.CommandType.LINK_REQUEST) msg.assertSentToNode(self.nodes[req_receiver]) msg.assertMleMessageContainsTlv(mle.SourceAddress) @@ -154,13 +151,10 @@ class Cert_5_1_12_NewRouterSync(unittest.TestCase): # 4 - Router1, Router2 self.assertTrue( - self.verify_step_4( - router1_messages, router2_messages, ROUTER1, ROUTER2 - ) - or self.verify_step_4( - router2_messages, router1_messages, ROUTER2, ROUTER1 - ) - ) + self.verify_step_4(router1_messages, router2_messages, ROUTER1, + ROUTER2) or + self.verify_step_4(router2_messages, router1_messages, ROUTER2, + ROUTER1)) if __name__ == '__main__': diff --git a/tests/scripts/thread-cert/Cert_5_1_13_RouterReset.py b/tests/scripts/thread-cert/Cert_5_1_13_RouterReset.py index 1c5a7a71e..ed94bd7f3 100755 --- a/tests/scripts/thread-cert/Cert_5_1_13_RouterReset.py +++ b/tests/scripts/thread-cert/Cert_5_1_13_RouterReset.py @@ -38,6 +38,7 @@ ROUTER = 2 class Cert_5_1_13_RouterReset(unittest.TestCase): + def setUp(self): self.simulator = config.create_default_simulator() diff --git a/tests/scripts/thread-cert/Cert_5_2_01_REEDAttach.py b/tests/scripts/thread-cert/Cert_5_2_01_REEDAttach.py index 3461095cd..a1d2682cf 100755 --- a/tests/scripts/thread-cert/Cert_5_2_01_REEDAttach.py +++ b/tests/scripts/thread-cert/Cert_5_2_01_REEDAttach.py @@ -34,7 +34,6 @@ import mle import config import command - LEADER = 1 DUT_ROUTER1 = 2 REED1 = 3 @@ -42,6 +41,7 @@ MED1 = 4 class Cert_5_2_01_REEDAttach(unittest.TestCase): + def setUp(self): self.simulator = config.create_default_simulator() @@ -102,16 +102,13 @@ class Cert_5_2_01_REEDAttach(unittest.TestCase): # 3 DUT_ROUTER1: Verify MLE Parent Response router1_messages = self.simulator.get_messages_sent_by(DUT_ROUTER1) - msg = router1_messages.next_mle_message( - mle.CommandType.PARENT_RESPONSE - ) + msg = router1_messages.next_mle_message(mle.CommandType.PARENT_RESPONSE) msg.assertSentToNode(self.nodes[REED1]) command.check_parent_response(msg) # 4 DUT_ROUTER1: Verify MLE Child ID Response msg = router1_messages.next_mle_message( - mle.CommandType.CHILD_ID_RESPONSE - ) + mle.CommandType.CHILD_ID_RESPONSE) msg.assertSentToNode(self.nodes[REED1]) command.check_child_id_response(msg) @@ -126,8 +123,7 @@ class Cert_5_2_01_REEDAttach(unittest.TestCase): reed1_messages = self.simulator.get_messages_sent_by(REED1) msg = reed1_messages.next_coap_message('0.02') reed1_ipv6_address = ( - msg.ipv6_packet.ipv6_header.source_address.compressed - ) + msg.ipv6_packet.ipv6_header.source_address.compressed) msg.assertSentToNode(self.nodes[DUT_ROUTER1]) msg.assertCoapMessageRequestUriPath('/a/as') diff --git a/tests/scripts/thread-cert/Cert_5_2_03_LeaderReject2Hops.py b/tests/scripts/thread-cert/Cert_5_2_03_LeaderReject2Hops.py index df084f830..5bee43bd6 100755 --- a/tests/scripts/thread-cert/Cert_5_2_03_LeaderReject2Hops.py +++ b/tests/scripts/thread-cert/Cert_5_2_03_LeaderReject2Hops.py @@ -41,14 +41,13 @@ ROUTER_32 = 33 class Cert_5_2_3_LeaderReject2Hops(unittest.TestCase): + def setUp(self): self.simulator = config.create_default_simulator() self.nodes = {} - self.nodes[DUT_LEADER] = node.Node( - DUT_LEADER, simulator=self.simulator - ) + self.nodes[DUT_LEADER] = node.Node(DUT_LEADER, simulator=self.simulator) self.nodes[DUT_LEADER].set_panid(0xface) self.nodes[DUT_LEADER].set_mode('rsdn') self.nodes[DUT_LEADER].enable_whitelist() @@ -126,9 +125,8 @@ class Cert_5_2_3_LeaderReject2Hops(unittest.TestCase): msg.assertCoapMessageContainsTlv(network_layer.Status) status_tlv = msg.get_coap_message_tlv(network_layer.Status) - self.assertEqual( - network_layer.StatusValues.NO_ADDRESS_AVAILABLE, status_tlv.status - ) + self.assertEqual(network_layer.StatusValues.NO_ADDRESS_AVAILABLE, + status_tlv.status) if __name__ == '__main__': diff --git a/tests/scripts/thread-cert/Cert_5_2_04_REEDUpgrade.py b/tests/scripts/thread-cert/Cert_5_2_04_REEDUpgrade.py index 062e97702..58971cf9a 100755 --- a/tests/scripts/thread-cert/Cert_5_2_04_REEDUpgrade.py +++ b/tests/scripts/thread-cert/Cert_5_2_04_REEDUpgrade.py @@ -46,6 +46,7 @@ ROUTER_SELECTION_JITTER = 1 class Cert_5_2_4_REEDUpgrade(unittest.TestCase): + def setUp(self): self.simulator = config.create_default_simulator() @@ -115,9 +116,8 @@ class Cert_5_2_4_REEDUpgrade(unittest.TestCase): msg.assertMleMessageDoesNotContainTlv(mle.Route64) # 4 Wait for DUT_REED to send the second packet. - self.simulator.go( - REED_ADVERTISEMENT_INTERVAL + REED_ADVERTISEMENT_MAX_JITTER - ) + self.simulator.go(REED_ADVERTISEMENT_INTERVAL + + REED_ADVERTISEMENT_MAX_JITTER) # 5 DUT_REED: Verify the second MLE Advertisement. reed_messages = self.simulator.get_messages_sent_by(DUT_REED) @@ -166,10 +166,8 @@ class Cert_5_2_4_REEDUpgrade(unittest.TestCase): # Leader. mleid = None for addr in self.nodes[LEADER].get_addrs(): - if ( - addr.find(MESH_LOCAL_PREFIX) != -1 - and addr.find(ROUTING_LACATOR) == -1 - ): + if (addr.find(MESH_LOCAL_PREFIX) != -1 and + addr.find(ROUTING_LACATOR) == -1): mleid = addr break diff --git a/tests/scripts/thread-cert/Cert_5_2_05_AddressQuery.py b/tests/scripts/thread-cert/Cert_5_2_05_AddressQuery.py index e4a9e3b38..393659e01 100755 --- a/tests/scripts/thread-cert/Cert_5_2_05_AddressQuery.py +++ b/tests/scripts/thread-cert/Cert_5_2_05_AddressQuery.py @@ -42,6 +42,7 @@ ROUTER_SELECTION_JITTER = 1 class Cert_5_2_5_AddressQuery(unittest.TestCase): + def setUp(self): self.simulator = config.create_default_simulator() @@ -126,9 +127,7 @@ class Cert_5_2_5_AddressQuery(unittest.TestCase): # 6. Verify DUT_REED would send Address Notification when ping to its # ML-EID. - mleid = self.nodes[DUT_REED].get_ip6_address( - config.ADDRESS_TYPE.ML_EID - ) + mleid = self.nodes[DUT_REED].get_ip6_address(config.ADDRESS_TYPE.ML_EID) self.assertTrue(self.nodes[ED1].ping(mleid)) # Wait for sniffer collecting packets @@ -136,17 +135,15 @@ class Cert_5_2_5_AddressQuery(unittest.TestCase): reed_messages = self.simulator.get_messages_sent_by(DUT_REED) msg = reed_messages.next_coap_message('0.02', '/a/an') - command.check_address_notification( - msg, self.nodes[DUT_REED], self.nodes[LEADER] - ) + command.check_address_notification(msg, self.nodes[DUT_REED], + self.nodes[LEADER]) # 7 & 8. Verify DUT_REED would send Address Notification when ping to # its 2001::EID and 2002::EID. flag2001 = 0 flag2002 = 0 for global_address in self.nodes[DUT_REED].get_ip6_address( - config.ADDRESS_TYPE.GLOBAL - ): + config.ADDRESS_TYPE.GLOBAL): if global_address[0:4] == '2001': flag2001 += 1 elif global_address[0:4] == '2002': @@ -160,9 +157,8 @@ class Cert_5_2_5_AddressQuery(unittest.TestCase): reed_messages = self.simulator.get_messages_sent_by(DUT_REED) msg = reed_messages.next_coap_message('0.02', '/a/an') - command.check_address_notification( - msg, self.nodes[DUT_REED], self.nodes[LEADER] - ) + command.check_address_notification(msg, self.nodes[DUT_REED], + self.nodes[LEADER]) assert flag2001 == 1, "Error: Expecting address 2001::EID not appear." assert flag2002 == 1, "Error: Expecting address 2002::EID not appear." diff --git a/tests/scripts/thread-cert/Cert_5_2_06_RouterDowngrade.py b/tests/scripts/thread-cert/Cert_5_2_06_RouterDowngrade.py index 963ad7f0c..2ef104cb7 100755 --- a/tests/scripts/thread-cert/Cert_5_2_06_RouterDowngrade.py +++ b/tests/scripts/thread-cert/Cert_5_2_06_RouterDowngrade.py @@ -41,6 +41,7 @@ ROUTER24 = 24 class Cert_5_2_06_RouterDowngrade(unittest.TestCase): + def setUp(self): self.simulator = config.create_default_simulator() @@ -99,8 +100,7 @@ class Cert_5_2_06_RouterDowngrade(unittest.TestCase): # 4 & 5 router1_rloc = self.nodes[DUT_ROUTER1].get_ip6_address( - config.ADDRESS_TYPE.RLOC - ) + config.ADDRESS_TYPE.RLOC) self.assertTrue(self.nodes[LEADER].ping(router1_rloc)) diff --git a/tests/scripts/thread-cert/Cert_5_2_07_REEDSynchronization.py b/tests/scripts/thread-cert/Cert_5_2_07_REEDSynchronization.py index d642e964d..8752ab66e 100755 --- a/tests/scripts/thread-cert/Cert_5_2_07_REEDSynchronization.py +++ b/tests/scripts/thread-cert/Cert_5_2_07_REEDSynchronization.py @@ -43,6 +43,7 @@ MLE_MIN_LINKS = 3 class Cert_5_2_7_REEDSynchronization(unittest.TestCase): + def setUp(self): self.simulator = config.create_default_simulator() @@ -74,9 +75,8 @@ class Cert_5_2_7_REEDSynchronization(unittest.TestCase): # 2. DUT_REED: Attach to network. Verify it didn't send an Address Solicit Request. # Avoid DUT_REED attach to DUT_ROUTER1. - self.nodes[DUT_REED].add_whitelist( - self.nodes[DUT_ROUTER1].get_addr64(), config.RSSI['LINK_QULITY_1'] - ) + self.nodes[DUT_REED].add_whitelist(self.nodes[DUT_ROUTER1].get_addr64(), + config.RSSI['LINK_QULITY_1']) self.nodes[DUT_REED].start() self.simulator.go(config.MAX_ADVERTISEMENT_INTERVAL) @@ -85,9 +85,8 @@ class Cert_5_2_7_REEDSynchronization(unittest.TestCase): # The DUT_REED must not send a coap message here. reed_messages = self.simulator.get_messages_sent_by(DUT_REED) msg = reed_messages.does_not_contain_coap_message() - assert ( - msg is True - ), "Error: The DUT_REED sent an Address Solicit Request" + assert (msg is + True), "Error: The DUT_REED sent an Address Solicit Request" # 3. DUT_REED: Verify sent a Link Request to at least 3 neighboring # Routers. @@ -104,29 +103,24 @@ class Cert_5_2_7_REEDSynchronization(unittest.TestCase): link_accept_count = 0 destination_link_local = self.nodes[DUT_REED].get_ip6_address( - config.ADDRESS_TYPE.LINK_LOCAL - ) + config.ADDRESS_TYPE.LINK_LOCAL) for i in range(1, DUT_REED): dut_messages = self.simulator.get_messages_sent_by(i) while True: - msg = dut_messages.next_mle_message( - mle.CommandType.LINK_ACCEPT, False - ) + msg = dut_messages.next_mle_message(mle.CommandType.LINK_ACCEPT, + False) if msg is None: break - if ( - ipv6.ip_address(destination_link_local) - == msg.ipv6_packet.ipv6_header.destination_address - ): + if (ipv6.ip_address(destination_link_local) == + msg.ipv6_packet.ipv6_header.destination_address): command.check_link_accept(msg, self.nodes[DUT_REED]) link_accept_count += 1 break - assert ( - link_accept_count >= MLE_MIN_LINKS - ) is True, "Error: too few Link Accept sent to DUT_REED" + assert (link_accept_count >= MLE_MIN_LINKS + ) is True, "Error: too few Link Accept sent to DUT_REED" if __name__ == '__main__': diff --git a/tests/scripts/thread-cert/Cert_5_3_01_LinkLocal.py b/tests/scripts/thread-cert/Cert_5_3_01_LinkLocal.py index e7f9bd712..5a2df87ad 100755 --- a/tests/scripts/thread-cert/Cert_5_3_01_LinkLocal.py +++ b/tests/scripts/thread-cert/Cert_5_3_01_LinkLocal.py @@ -37,6 +37,7 @@ DUT_ROUTER1 = 2 class Cert_5_3_1_LinkLocal(unittest.TestCase): + def setUp(self): self.simulator = config.create_default_simulator() @@ -69,8 +70,7 @@ class Cert_5_3_1_LinkLocal(unittest.TestCase): # 2 & 3 link_local = self.nodes[DUT_ROUTER1].get_ip6_address( - config.ADDRESS_TYPE.LINK_LOCAL - ) + config.ADDRESS_TYPE.LINK_LOCAL) self.assertTrue(self.nodes[LEADER].ping(link_local, size=256)) self.assertTrue(self.nodes[LEADER].ping(link_local)) @@ -83,11 +83,8 @@ class Cert_5_3_1_LinkLocal(unittest.TestCase): self.assertTrue(self.nodes[LEADER].ping('ff02::2')) # 8 - self.assertTrue( - self.nodes[LEADER].ping( - config.LINK_LOCAL_All_THREAD_NODES_MULTICAST_ADDRESS - ) - ) + self.assertTrue(self.nodes[LEADER].ping( + config.LINK_LOCAL_All_THREAD_NODES_MULTICAST_ADDRESS)) if __name__ == '__main__': diff --git a/tests/scripts/thread-cert/Cert_5_3_02_RealmLocal.py b/tests/scripts/thread-cert/Cert_5_3_02_RealmLocal.py index f5fd3a103..bb7e9aafd 100755 --- a/tests/scripts/thread-cert/Cert_5_3_02_RealmLocal.py +++ b/tests/scripts/thread-cert/Cert_5_3_02_RealmLocal.py @@ -39,6 +39,7 @@ SED1 = 4 class Cert_5_3_2_RealmLocal(unittest.TestCase): + def setUp(self): self.simulator = config.create_default_simulator() @@ -97,15 +98,14 @@ class Cert_5_3_2_RealmLocal(unittest.TestCase): # 2 & 3 mleid = self.nodes[DUT_ROUTER2].get_ip6_address( - config.ADDRESS_TYPE.ML_EID - ) + config.ADDRESS_TYPE.ML_EID) self.assertTrue(self.nodes[LEADER].ping(mleid, size=256)) self.assertTrue(self.nodes[LEADER].ping(mleid)) # 4 & 5 - self.assertTrue( - self.nodes[LEADER].ping('ff03::1', num_responses=2, size=256) - ) + self.assertTrue(self.nodes[LEADER].ping('ff03::1', + num_responses=2, + size=256)) sed_messages = self.simulator.get_messages_sent_by(SED1) self.assertFalse(sed_messages.contains_icmp_message()) @@ -114,9 +114,9 @@ class Cert_5_3_2_RealmLocal(unittest.TestCase): self.assertFalse(sed_messages.contains_icmp_message()) # 6 & 7 - self.assertTrue( - self.nodes[LEADER].ping('ff03::2', num_responses=2, size=256) - ) + self.assertTrue(self.nodes[LEADER].ping('ff03::2', + num_responses=2, + size=256)) sed_messages = self.simulator.get_messages_sent_by(SED1) self.assertFalse(sed_messages.contains_icmp_message()) @@ -125,23 +125,19 @@ class Cert_5_3_2_RealmLocal(unittest.TestCase): self.assertFalse(sed_messages.contains_icmp_message()) # 8 - self.assertTrue( - self.nodes[LEADER].ping( - config.REALM_LOCAL_All_THREAD_NODES_MULTICAST_ADDRESS, - num_responses=3, - size=256, - ) - ) + self.assertTrue(self.nodes[LEADER].ping( + config.REALM_LOCAL_All_THREAD_NODES_MULTICAST_ADDRESS, + num_responses=3, + size=256, + )) self.simulator.go(2) sed_messages = self.simulator.get_messages_sent_by(SED1) self.assertTrue(sed_messages.contains_icmp_message()) - self.assertTrue( - self.nodes[LEADER].ping( - config.REALM_LOCAL_All_THREAD_NODES_MULTICAST_ADDRESS, - num_responses=3, - ) - ) + self.assertTrue(self.nodes[LEADER].ping( + config.REALM_LOCAL_All_THREAD_NODES_MULTICAST_ADDRESS, + num_responses=3, + )) self.simulator.go(2) sed_messages = self.simulator.get_messages_sent_by(SED1) self.assertTrue(sed_messages.contains_icmp_message()) diff --git a/tests/scripts/thread-cert/Cert_5_3_03_AddressQuery.py b/tests/scripts/thread-cert/Cert_5_3_03_AddressQuery.py index ea6e0f4fc..3403a702f 100755 --- a/tests/scripts/thread-cert/Cert_5_3_03_AddressQuery.py +++ b/tests/scripts/thread-cert/Cert_5_3_03_AddressQuery.py @@ -42,6 +42,7 @@ MED1_TIMEOUT = 3 class Cert_5_3_3_AddressQuery(unittest.TestCase): + def setUp(self): self.simulator = config.create_default_simulator() @@ -112,8 +113,7 @@ class Cert_5_3_3_AddressQuery(unittest.TestCase): dut_messages = self.simulator.get_messages_sent_by(DUT_ROUTER2) router3_mleid = self.nodes[ROUTER3].get_ip6_address( - config.ADDRESS_TYPE.ML_EID - ) + config.ADDRESS_TYPE.ML_EID) self.assertTrue(self.nodes[MED1].ping(router3_mleid)) # Verify DUT_ROUTER2 sent an Address Query Request to the Realm local @@ -136,16 +136,14 @@ class Cert_5_3_3_AddressQuery(unittest.TestCase): dut_messages = self.simulator.get_messages_sent_by(DUT_ROUTER2) med1_mleid = self.nodes[MED1].get_ip6_address( - config.ADDRESS_TYPE.ML_EID - ) + config.ADDRESS_TYPE.ML_EID) self.assertTrue(self.nodes[ROUTER1].ping(med1_mleid)) # Verify DUT_ROUTER2 responded with an Address Notification. dut_messages = self.simulator.get_messages_sent_by(DUT_ROUTER2) msg = dut_messages.next_coap_message('0.02', '/a/an') - command.check_address_notification( - msg, self.nodes[DUT_ROUTER2], self.nodes[ROUTER1] - ) + command.check_address_notification(msg, self.nodes[DUT_ROUTER2], + self.nodes[ROUTER1]) # 4 # Wait the finish of address resolution traffic triggerred by previous diff --git a/tests/scripts/thread-cert/Cert_5_3_04_AddressMapCache.py b/tests/scripts/thread-cert/Cert_5_3_04_AddressMapCache.py index 722ef645e..277ec4772 100755 --- a/tests/scripts/thread-cert/Cert_5_3_04_AddressMapCache.py +++ b/tests/scripts/thread-cert/Cert_5_3_04_AddressMapCache.py @@ -45,6 +45,7 @@ MTDS = [SED1, ED1, ED2, ED3, ED4] class Cert_5_3_4_AddressMapCache(unittest.TestCase): + def setUp(self): self.simulator = config.create_default_simulator() @@ -112,8 +113,7 @@ class Cert_5_3_4_AddressMapCache(unittest.TestCase): # 2 for ED in [ED1, ED2, ED3, ED4]: ed_mleid = self.nodes[ED].get_ip6_address( - config.ADDRESS_TYPE.ML_EID - ) + config.ADDRESS_TYPE.ML_EID) self.assertTrue(self.nodes[SED1].ping(ed_mleid)) self.simulator.go(5) @@ -134,17 +134,15 @@ class Cert_5_3_4_AddressMapCache(unittest.TestCase): for ED in [ED1, ED2, ED3, ED4]: ed_mleid = self.nodes[ED].get_ip6_address( - config.ADDRESS_TYPE.ML_EID - ) + config.ADDRESS_TYPE.ML_EID) self.assertTrue(self.nodes[SED1].ping(ed_mleid)) self.simulator.go(5) # Verify DUT_ROUTER1 didn't generate an Address Query Request. dut_messages = self.simulator.get_messages_sent_by(DUT_ROUTER1) msg = dut_messages.next_coap_message('0.02', '/a/aq', False) - assert ( - msg is None - ), "Error: The DUT sent an unexpected Address Query Request" + assert (msg is None + ), "Error: The DUT sent an unexpected Address Query Request" if __name__ == '__main__': diff --git a/tests/scripts/thread-cert/Cert_5_3_05_RoutingLinkQuality.py b/tests/scripts/thread-cert/Cert_5_3_05_RoutingLinkQuality.py index af6a1dc0c..fcbc7f263 100755 --- a/tests/scripts/thread-cert/Cert_5_3_05_RoutingLinkQuality.py +++ b/tests/scripts/thread-cert/Cert_5_3_05_RoutingLinkQuality.py @@ -40,6 +40,7 @@ ROUTER3 = 4 class Cert_5_3_5_RoutingLinkQuality(unittest.TestCase): + def setUp(self): self.simulator = config.create_default_simulator() @@ -95,8 +96,7 @@ class Cert_5_3_5_RoutingLinkQuality(unittest.TestCase): # 2 & 3 leader_rloc = self.nodes[LEADER].get_ip6_address( - config.ADDRESS_TYPE.RLOC - ) + config.ADDRESS_TYPE.RLOC) # Verify the ICMPv6 Echo Request took the least cost path. self.assertTrue(self.nodes[ROUTER3].ping(leader_rloc)) @@ -104,12 +104,10 @@ class Cert_5_3_5_RoutingLinkQuality(unittest.TestCase): command.check_icmp_path(self.simulator, path, self.nodes) # 4 & 5 - self.nodes[LEADER].add_whitelist( - self.nodes[DUT_ROUTER1].get_addr64(), config.RSSI['LINK_QULITY_1'] - ) - self.nodes[DUT_ROUTER1].add_whitelist( - self.nodes[LEADER].get_addr64(), config.RSSI['LINK_QULITY_1'] - ) + self.nodes[LEADER].add_whitelist(self.nodes[DUT_ROUTER1].get_addr64(), + config.RSSI['LINK_QULITY_1']) + self.nodes[DUT_ROUTER1].add_whitelist(self.nodes[LEADER].get_addr64(), + config.RSSI['LINK_QULITY_1']) self.simulator.go(3 * config.MAX_ADVERTISEMENT_INTERVAL) # Verify the ICMPv6 Echo Request took the longer path because it cost @@ -119,12 +117,10 @@ class Cert_5_3_5_RoutingLinkQuality(unittest.TestCase): command.check_icmp_path(self.simulator, path, self.nodes) # 6 & 7 - self.nodes[LEADER].add_whitelist( - self.nodes[DUT_ROUTER1].get_addr64(), config.RSSI['LINK_QULITY_2'] - ) - self.nodes[DUT_ROUTER1].add_whitelist( - self.nodes[LEADER].get_addr64(), config.RSSI['LINK_QULITY_2'] - ) + self.nodes[LEADER].add_whitelist(self.nodes[DUT_ROUTER1].get_addr64(), + config.RSSI['LINK_QULITY_2']) + self.nodes[DUT_ROUTER1].add_whitelist(self.nodes[LEADER].get_addr64(), + config.RSSI['LINK_QULITY_2']) self.simulator.go(3 * config.MAX_ADVERTISEMENT_INTERVAL) # Verify the direct neighbor would be prioritized when there are two @@ -134,18 +130,15 @@ class Cert_5_3_5_RoutingLinkQuality(unittest.TestCase): command.check_icmp_path(self.simulator, path, self.nodes) # 8 & 9 - self.nodes[LEADER].add_whitelist( - self.nodes[DUT_ROUTER1].get_addr64(), config.RSSI['LINK_QULITY_0'] - ) - self.nodes[DUT_ROUTER1].add_whitelist( - self.nodes[LEADER].get_addr64(), config.RSSI['LINK_QULITY_0'] - ) + self.nodes[LEADER].add_whitelist(self.nodes[DUT_ROUTER1].get_addr64(), + config.RSSI['LINK_QULITY_0']) + self.nodes[DUT_ROUTER1].add_whitelist(self.nodes[LEADER].get_addr64(), + config.RSSI['LINK_QULITY_0']) self.simulator.go(3 * config.MAX_ADVERTISEMENT_INTERVAL) # Verify the ICMPv6 Echo Request took the longer path. leader_rloc = self.nodes[LEADER].get_ip6_address( - config.ADDRESS_TYPE.RLOC - ) + config.ADDRESS_TYPE.RLOC) self.assertTrue(self.nodes[ROUTER3].ping(leader_rloc)) path = [ROUTER3, DUT_ROUTER1, ROUTER2, LEADER] command.check_icmp_path(self.simulator, path, self.nodes) diff --git a/tests/scripts/thread-cert/Cert_5_3_06_RouterIdMask.py b/tests/scripts/thread-cert/Cert_5_3_06_RouterIdMask.py index d20379b77..66fd8d4a5 100755 --- a/tests/scripts/thread-cert/Cert_5_3_06_RouterIdMask.py +++ b/tests/scripts/thread-cert/Cert_5_3_06_RouterIdMask.py @@ -40,6 +40,7 @@ ROUTER2 = 3 class Cert_5_3_6_RouterIdMask(unittest.TestCase): + def setUp(self): self.simulator = config.create_default_simulator() @@ -111,8 +112,7 @@ class Cert_5_3_6_RouterIdMask(unittest.TestCase): leader_messages = self.simulator.get_messages_sent_by(DUT_LEADER) msg = leader_messages.last_mle_message( - mle.CommandType.ADVERTISEMENT, False - ) + mle.CommandType.ADVERTISEMENT, False) if msg is None: continue @@ -123,9 +123,8 @@ class Cert_5_3_6_RouterIdMask(unittest.TestCase): break self.assertTrue(routing_cost == 0) - self.simulator.go( - config.INFINITE_COST_TIMEOUT + config.MAX_ADVERTISEMENT_INTERVAL - ) + self.simulator.go(config.INFINITE_COST_TIMEOUT + + config.MAX_ADVERTISEMENT_INTERVAL) leader_messages = self.simulator.get_messages_sent_by(DUT_LEADER) msg = leader_messages.last_mle_message(mle.CommandType.ADVERTISEMENT) self.assertFalse(command.check_id_set(msg, router2_id)) @@ -150,16 +149,14 @@ class Cert_5_3_6_RouterIdMask(unittest.TestCase): router1_id = self.nodes[ROUTER1].get_router_id() router2_id = self.nodes[ROUTER2].get_router_id() - self.simulator.go( - config.MAX_NEIGHBOR_AGE + config.MAX_ADVERTISEMENT_INTERVAL - ) + self.simulator.go(config.MAX_NEIGHBOR_AGE + + config.MAX_ADVERTISEMENT_INTERVAL) leader_messages = self.simulator.get_messages_sent_by(DUT_LEADER) msg = leader_messages.last_mle_message(mle.CommandType.ADVERTISEMENT) self.assertEqual(command.get_routing_cost(msg, router1_id), 0) - self.simulator.go( - config.INFINITE_COST_TIMEOUT + config.MAX_ADVERTISEMENT_INTERVAL - ) + self.simulator.go(config.INFINITE_COST_TIMEOUT + + config.MAX_ADVERTISEMENT_INTERVAL) leader_messages = self.simulator.get_messages_sent_by(DUT_LEADER) msg = leader_messages.last_mle_message(mle.CommandType.ADVERTISEMENT) self.assertFalse(command.check_id_set(msg, router1_id)) diff --git a/tests/scripts/thread-cert/Cert_5_3_06b_RouterIdMask.py b/tests/scripts/thread-cert/Cert_5_3_06b_RouterIdMask.py index 0403e978f..892a2f037 100755 --- a/tests/scripts/thread-cert/Cert_5_3_06b_RouterIdMask.py +++ b/tests/scripts/thread-cert/Cert_5_3_06b_RouterIdMask.py @@ -38,6 +38,7 @@ ROUTER2 = 3 class Cert_5_3_6_RouterIdMask(unittest.TestCase): + def setUp(self): self.simulator = config.create_default_simulator() diff --git a/tests/scripts/thread-cert/Cert_5_3_07_DuplicateAddress.py b/tests/scripts/thread-cert/Cert_5_3_07_DuplicateAddress.py index 3f65a3766..14b63c027 100755 --- a/tests/scripts/thread-cert/Cert_5_3_07_DuplicateAddress.py +++ b/tests/scripts/thread-cert/Cert_5_3_07_DuplicateAddress.py @@ -45,6 +45,7 @@ MTDS = [MED1, SED1, MED3] class Cert_5_3_7_DuplicateAddress(unittest.TestCase): + def setUp(self): self.simulator = config.create_default_simulator() @@ -139,9 +140,8 @@ class Cert_5_3_7_DuplicateAddress(unittest.TestCase): # address. dut_messages = self.simulator.get_messages_sent_by(DUT_LEADER) msg = dut_messages.next_coap_message('0.02', '/a/aq') - command.check_address_query( - msg, self.nodes[DUT_LEADER], config.REALM_LOCAL_ALL_ROUTERS_ADDRESS - ) + command.check_address_query(msg, self.nodes[DUT_LEADER], + config.REALM_LOCAL_ALL_ROUTERS_ADDRESS) # 5 & 6 # Verify DUT_LEADER sent an Address Error Notification to the Realm @@ -150,8 +150,7 @@ class Cert_5_3_7_DuplicateAddress(unittest.TestCase): dut_messages = self.simulator.get_messages_sent_by(DUT_LEADER) msg = dut_messages.next_coap_message('0.02', '/a/ae') command.check_address_error_notification( - msg, self.nodes[DUT_LEADER], config.REALM_LOCAL_ALL_ROUTERS_ADDRESS - ) + msg, self.nodes[DUT_LEADER], config.REALM_LOCAL_ALL_ROUTERS_ADDRESS) if __name__ == '__main__': diff --git a/tests/scripts/thread-cert/Cert_5_3_08_ChildAddressSet.py b/tests/scripts/thread-cert/Cert_5_3_08_ChildAddressSet.py index 4e6b7c4a0..f8370fffa 100755 --- a/tests/scripts/thread-cert/Cert_5_3_08_ChildAddressSet.py +++ b/tests/scripts/thread-cert/Cert_5_3_08_ChildAddressSet.py @@ -44,6 +44,7 @@ MTDS = [MED1, MED2] class Cert_5_3_8_ChildAddressSet(unittest.TestCase): + def setUp(self): self.simulator = config.create_default_simulator() @@ -109,8 +110,7 @@ class Cert_5_3_8_ChildAddressSet(unittest.TestCase): # 4 MED1: MED1 send an ICMPv6 Echo Request to the MED2 ML-EID med2_ml_eid = self.nodes[MED2].get_ip6_address( - config.ADDRESS_TYPE.ML_EID - ) + config.ADDRESS_TYPE.ML_EID) self.assertTrue(med2_ml_eid is not None) self.assertTrue(self.nodes[MED1].ping(med2_ml_eid)) @@ -127,9 +127,8 @@ class Cert_5_3_8_ChildAddressSet(unittest.TestCase): # Verify MED2 sent an ICMPv6 Echo Reply med2_messages = self.simulator.get_messages_sent_by(MED2) msg = med2_messages.get_icmp_message(ipv6.ICMP_ECHO_RESPONSE) - assert ( - msg is not None - ), "Error: The MED2 didn't send ICMPv6 Echo Reply to MED1" + assert (msg is not None + ), "Error: The MED2 didn't send ICMPv6 Echo Reply to MED1" # 5 MED1: MED1 send an ICMPv6 Echo Request to the MED2 2001::GUA addr = self.nodes[MED2].get_addr("2001::/64") @@ -149,9 +148,8 @@ class Cert_5_3_8_ChildAddressSet(unittest.TestCase): # Verify MED2 sent an ICMPv6 Echo Reply med2_messages = self.simulator.get_messages_sent_by(MED2) msg = med2_messages.get_icmp_message(ipv6.ICMP_ECHO_RESPONSE) - assert ( - msg is not None - ), "Error: The MED2 didn't send ICMPv6 Echo Reply to MED1" + assert (msg is not None + ), "Error: The MED2 didn't send ICMPv6 Echo Reply to MED1" # 6 MED1: MED1 send an ICMPv6 Echo Request to the MED2 2002::GUA addr = self.nodes[MED2].get_addr("2002::/64") @@ -171,9 +169,8 @@ class Cert_5_3_8_ChildAddressSet(unittest.TestCase): # Verify MED2 sent an ICMPv6 Echo Reply med2_messages = self.simulator.get_messages_sent_by(MED2) msg = med2_messages.get_icmp_message(ipv6.ICMP_ECHO_RESPONSE) - assert ( - msg is not None - ), "Error: The MED2 didn't send ICMPv6 Echo Reply to MED1" + assert (msg is not None + ), "Error: The MED2 didn't send ICMPv6 Echo Reply to MED1" # 7 MED1: MED1 send an ICMPv6 Echo Request to the MED2 2003::GUA addr = self.nodes[MED2].get_addr("2003::/64") @@ -193,9 +190,8 @@ class Cert_5_3_8_ChildAddressSet(unittest.TestCase): # Verify MED2 sent an ICMPv6 Echo Reply med2_messages = self.simulator.get_messages_sent_by(MED2) msg = med2_messages.get_icmp_message(ipv6.ICMP_ECHO_RESPONSE) - assert ( - msg is not None - ), "Error: The MED2 didn't send ICMPv6 Echo Reply to MED1" + assert (msg is not None + ), "Error: The MED2 didn't send ICMPv6 Echo Reply to MED1" if __name__ == '__main__': diff --git a/tests/scripts/thread-cert/Cert_5_3_09_AddressQuery.py b/tests/scripts/thread-cert/Cert_5_3_09_AddressQuery.py index d5b856ccb..d898c6de2 100755 --- a/tests/scripts/thread-cert/Cert_5_3_09_AddressQuery.py +++ b/tests/scripts/thread-cert/Cert_5_3_09_AddressQuery.py @@ -43,6 +43,7 @@ SED1 = 5 class Cert_5_3_09_AddressQuery(unittest.TestCase): + def setUp(self): self.simulator = config.create_default_simulator() @@ -130,8 +131,7 @@ class Cert_5_3_09_AddressQuery(unittest.TestCase): dut_router2_messages = self.simulator.get_messages_sent_by(DUT_ROUTER2) msg = dut_router2_messages.next_coap_message('0.02', '/a/aq') msg.assertSentToDestinationAddress( - config.REALM_LOCAL_ALL_ROUTERS_ADDRESS - ) + config.REALM_LOCAL_ALL_ROUTERS_ADDRESS) command.check_address_query( msg, self.nodes[DUT_ROUTER2], @@ -157,9 +157,8 @@ class Cert_5_3_09_AddressQuery(unittest.TestCase): # Verify DUT_ROUTER2 sent an Address Notification message dut_router2_messages = self.simulator.get_messages_sent_by(DUT_ROUTER2) msg = dut_router2_messages.next_coap_message('0.02', '/a/an') - command.check_address_notification( - msg, self.nodes[DUT_ROUTER2], self.nodes[ROUTER1] - ) + command.check_address_notification(msg, self.nodes[DUT_ROUTER2], + self.nodes[ROUTER1]) # 5 SED1: SED1 sends an ICMPv6 Echo Request to the ROUTER3 using GUA # 2001:: address @@ -178,8 +177,7 @@ class Cert_5_3_09_AddressQuery(unittest.TestCase): # Verify DUT_ROUTER2 forwarded the ICMPv6 Echo Reply to SED1 msg = dut_router2_messages_temp.get_icmp_message( - ipv6.ICMP_ECHO_RESPONSE - ) + ipv6.ICMP_ECHO_RESPONSE) assert ( msg is not None ), "Error: The DUT_ROUTER2 didn't forward ICMPv6 Echo Reply to SED1" @@ -197,8 +195,7 @@ class Cert_5_3_09_AddressQuery(unittest.TestCase): dut_router2_messages = self.simulator.get_messages_sent_by(DUT_ROUTER2) msg = dut_router2_messages.next_coap_message('0.02', '/a/aq') msg.assertSentToDestinationAddress( - config.REALM_LOCAL_ALL_ROUTERS_ADDRESS - ) + config.REALM_LOCAL_ALL_ROUTERS_ADDRESS) # 7 SED1: Power off SED1 and wait to allow DUT_ROUTER2 to timeout the # child diff --git a/tests/scripts/thread-cert/Cert_5_3_10_AddressQuery.py b/tests/scripts/thread-cert/Cert_5_3_10_AddressQuery.py index de8fa3a47..7aee11511 100755 --- a/tests/scripts/thread-cert/Cert_5_3_10_AddressQuery.py +++ b/tests/scripts/thread-cert/Cert_5_3_10_AddressQuery.py @@ -43,6 +43,7 @@ MED1 = 5 class Cert_5_3_10_AddressQuery(unittest.TestCase): + def setUp(self): self.simulator = config.create_default_simulator() @@ -158,9 +159,8 @@ class Cert_5_3_10_AddressQuery(unittest.TestCase): # Verify DUT_ROUTER2 sent an Address Notification message dut_router2_messages = self.simulator.get_messages_sent_by(DUT_ROUTER2) msg = dut_router2_messages.next_coap_message('0.02', '/a/an') - command.check_address_notification( - msg, self.nodes[DUT_ROUTER2], self.nodes[BR] - ) + command.check_address_notification(msg, self.nodes[DUT_ROUTER2], + self.nodes[BR]) # 5 MED1: MED1 sends an ICMPv6 Echo Request to ROUTER1 using GUA 2003:: # address @@ -181,8 +181,7 @@ class Cert_5_3_10_AddressQuery(unittest.TestCase): # Verify DUT_ROUTER2 forwarded ICMPv6 Echo Reply to MED1 msg = dut_router2_messages_temp.get_icmp_message( - ipv6.ICMP_ECHO_RESPONSE - ) + ipv6.ICMP_ECHO_RESPONSE) assert ( msg is not None ), "Error: The DUT_ROUTER2 didn't forward ICMPv6 Echo Reply to MED1" @@ -199,16 +198,14 @@ class Cert_5_3_10_AddressQuery(unittest.TestCase): # Verify the DUT_ROUTER2 has removed all entries based on ROUTER1's # Router ID - command.check_router_id_cached( - self.nodes[DUT_ROUTER2], router1_id, False - ) + command.check_router_id_cached(self.nodes[DUT_ROUTER2], router1_id, + False) # Verify DUT_ROUTER2 sent an Address Query Request dut_router2_messages = self.simulator.get_messages_sent_by(DUT_ROUTER2) msg = dut_router2_messages.next_coap_message('0.02', '/a/aq') msg.assertSentToDestinationAddress( - config.REALM_LOCAL_ALL_ROUTERS_ADDRESS - ) + config.REALM_LOCAL_ALL_ROUTERS_ADDRESS) # 7 MED1: Power off MED1 and wait to allow DUT_ROUTER2 to timeout the # child diff --git a/tests/scripts/thread-cert/Cert_5_3_11_AddressQueryTimeoutIntervals.py b/tests/scripts/thread-cert/Cert_5_3_11_AddressQueryTimeoutIntervals.py index eb161534b..8f7e45d91 100755 --- a/tests/scripts/thread-cert/Cert_5_3_11_AddressQueryTimeoutIntervals.py +++ b/tests/scripts/thread-cert/Cert_5_3_11_AddressQueryTimeoutIntervals.py @@ -39,6 +39,7 @@ MED1 = 3 class Cert_5_3_11_AddressQueryTimeoutIntervals(unittest.TestCase): + def setUp(self): self.simulator = config.create_default_simulator() diff --git a/tests/scripts/thread-cert/Cert_5_5_01_LeaderReboot.py b/tests/scripts/thread-cert/Cert_5_5_01_LeaderReboot.py index eddb05d10..a287f89cb 100755 --- a/tests/scripts/thread-cert/Cert_5_5_01_LeaderReboot.py +++ b/tests/scripts/thread-cert/Cert_5_5_01_LeaderReboot.py @@ -40,6 +40,7 @@ DUT_ROUTER1 = 2 class Cert_5_5_1_LeaderReboot(unittest.TestCase): + def setUp(self): self.simulator = config.create_default_simulator() @@ -54,15 +55,13 @@ class Cert_5_5_1_LeaderReboot(unittest.TestCase): self.nodes[DUT_ROUTER1].set_panid(0xface) self.nodes[DUT_ROUTER1].set_mode('rsdn') self.nodes[DUT_ROUTER1].add_whitelist( - self.nodes[DUT_LEADER].get_addr64() - ) + self.nodes[DUT_LEADER].get_addr64()) self.nodes[DUT_ROUTER1].enable_whitelist() self.nodes[DUT_ROUTER1].set_router_selection_jitter(1) def _setUpLeader(self): self.nodes[DUT_LEADER].add_whitelist( - self.nodes[DUT_ROUTER1].get_addr64() - ) + self.nodes[DUT_ROUTER1].get_addr64()) self.nodes[DUT_LEADER].enable_whitelist() def tearDown(self): @@ -93,13 +92,11 @@ class Cert_5_5_1_LeaderReboot(unittest.TestCase): # Send a harness helper ping to the DUT router1_rloc = self.nodes[DUT_ROUTER1].get_ip6_address( - config.ADDRESS_TYPE.RLOC - ) + config.ADDRESS_TYPE.RLOC) self.assertTrue(self.nodes[DUT_LEADER].ping(router1_rloc)) leader_rloc = self.nodes[DUT_LEADER].get_ip6_address( - config.ADDRESS_TYPE.RLOC - ) + config.ADDRESS_TYPE.RLOC) self.assertTrue(self.nodes[DUT_ROUTER1].ping(leader_rloc)) # 3 DUT_LEADER: Reset DUT_LEADER @@ -116,9 +113,8 @@ class Cert_5_5_1_LeaderReboot(unittest.TestCase): # Verify DUT_LEADER didn't send MLE Advertisement messages leader_messages = self.simulator.get_messages_sent_by(DUT_LEADER) - msg = leader_messages.next_mle_message( - mle.CommandType.ADVERTISEMENT, False - ) + msg = leader_messages.next_mle_message(mle.CommandType.ADVERTISEMENT, + False) self.assertTrue(msg is None) self.nodes[DUT_LEADER].start() @@ -153,8 +149,7 @@ class Cert_5_5_1_LeaderReboot(unittest.TestCase): ) else: msg = router1_messages_temp.next_mle_message( - mle.CommandType.LINK_ACCEPT_AND_REQUEST - ) + mle.CommandType.LINK_ACCEPT_AND_REQUEST) self.assertTrue(msg is not None) command.check_link_accept( msg, @@ -167,18 +162,14 @@ class Cert_5_5_1_LeaderReboot(unittest.TestCase): # 6 DUT_LEADER: Verify DUT_LEADER didn't send a Parent Request message msg = leader_messages_temp.next_mle_message( - mle.CommandType.PARENT_REQUEST, False - ) + mle.CommandType.PARENT_REQUEST, False) self.assertTrue(msg is None) # 7 ALL: Verify connectivity by sending an ICMPv6 Echo Request from # DUT_LEADER to DUT_ROUTER1 link local address router1_link_local_address = self.nodes[DUT_ROUTER1].get_ip6_address( - config.ADDRESS_TYPE.LINK_LOCAL - ) - self.assertTrue( - self.nodes[DUT_LEADER].ping(router1_link_local_address) - ) + config.ADDRESS_TYPE.LINK_LOCAL) + self.assertTrue(self.nodes[DUT_LEADER].ping(router1_link_local_address)) if __name__ == '__main__': diff --git a/tests/scripts/thread-cert/Cert_5_5_02_LeaderReboot.py b/tests/scripts/thread-cert/Cert_5_5_02_LeaderReboot.py index c911fc55d..047cff40b 100755 --- a/tests/scripts/thread-cert/Cert_5_5_02_LeaderReboot.py +++ b/tests/scripts/thread-cert/Cert_5_5_02_LeaderReboot.py @@ -38,6 +38,7 @@ ED = 3 class Cert_5_5_2_LeaderReboot(unittest.TestCase): + def setUp(self): self.simulator = config.create_default_simulator() diff --git a/tests/scripts/thread-cert/Cert_5_5_03_SplitMergeChildren.py b/tests/scripts/thread-cert/Cert_5_5_03_SplitMergeChildren.py index c5c92f42c..653858f27 100755 --- a/tests/scripts/thread-cert/Cert_5_5_03_SplitMergeChildren.py +++ b/tests/scripts/thread-cert/Cert_5_5_03_SplitMergeChildren.py @@ -43,6 +43,7 @@ MTDS = [ED1, ED2, ED3] class Cert_5_5_3_SplitMergeChildren(unittest.TestCase): + def setUp(self): self.simulator = config.create_default_simulator() diff --git a/tests/scripts/thread-cert/Cert_5_5_04_SplitMergeRouters.py b/tests/scripts/thread-cert/Cert_5_5_04_SplitMergeRouters.py index a9c8aa3a8..d4b0cf7d5 100755 --- a/tests/scripts/thread-cert/Cert_5_5_04_SplitMergeRouters.py +++ b/tests/scripts/thread-cert/Cert_5_5_04_SplitMergeRouters.py @@ -40,6 +40,7 @@ ROUTER4 = 5 class Cert_5_5_4_SplitMergeRouters(unittest.TestCase): + def setUp(self): self.simulator = config.create_default_simulator() diff --git a/tests/scripts/thread-cert/Cert_5_5_05_SplitMergeREED.py b/tests/scripts/thread-cert/Cert_5_5_05_SplitMergeREED.py index d0930a112..7b3cc2108 100755 --- a/tests/scripts/thread-cert/Cert_5_5_05_SplitMergeREED.py +++ b/tests/scripts/thread-cert/Cert_5_5_05_SplitMergeREED.py @@ -41,6 +41,7 @@ REED1 = 17 class Cert_5_5_5_SplitMergeREED(unittest.TestCase): + def setUp(self): self.simulator = config.create_default_simulator() diff --git a/tests/scripts/thread-cert/Cert_5_5_07_SplitMergeThreeWay.py b/tests/scripts/thread-cert/Cert_5_5_07_SplitMergeThreeWay.py index 08ee6a9ec..47cc480cb 100755 --- a/tests/scripts/thread-cert/Cert_5_5_07_SplitMergeThreeWay.py +++ b/tests/scripts/thread-cert/Cert_5_5_07_SplitMergeThreeWay.py @@ -39,6 +39,7 @@ ROUTER3 = 4 class Cert_5_5_7_SplitMergeThreeWay(unittest.TestCase): + def setUp(self): self.simulator = config.create_default_simulator() diff --git a/tests/scripts/thread-cert/Cert_5_5_08_SplitRoutersLostLeader.py b/tests/scripts/thread-cert/Cert_5_5_08_SplitRoutersLostLeader.py index 6da034bcd..df2c8505b 100755 --- a/tests/scripts/thread-cert/Cert_5_5_08_SplitRoutersLostLeader.py +++ b/tests/scripts/thread-cert/Cert_5_5_08_SplitRoutersLostLeader.py @@ -40,6 +40,7 @@ ED1 = 5 class Cert_5_5_8_SplitRoutersLostLeader(unittest.TestCase): + def setUp(self): self.simulator = config.create_default_simulator() diff --git a/tests/scripts/thread-cert/Cert_5_6_01_NetworkDataRegisterBeforeAttachLeader.py b/tests/scripts/thread-cert/Cert_5_6_01_NetworkDataRegisterBeforeAttachLeader.py index 5e172e7fe..701a38656 100755 --- a/tests/scripts/thread-cert/Cert_5_6_01_NetworkDataRegisterBeforeAttachLeader.py +++ b/tests/scripts/thread-cert/Cert_5_6_01_NetworkDataRegisterBeforeAttachLeader.py @@ -41,6 +41,7 @@ MTDS = [ED1, SED1] class Cert_5_6_1_NetworkDataLeaderAsBr(unittest.TestCase): + def setUp(self): self.simulator = config.create_default_simulator() diff --git a/tests/scripts/thread-cert/Cert_5_6_02_NetworkDataRegisterBeforeAttachRouter.py b/tests/scripts/thread-cert/Cert_5_6_02_NetworkDataRegisterBeforeAttachRouter.py index c4eb66e65..6b332f5f8 100755 --- a/tests/scripts/thread-cert/Cert_5_6_02_NetworkDataRegisterBeforeAttachRouter.py +++ b/tests/scripts/thread-cert/Cert_5_6_02_NetworkDataRegisterBeforeAttachRouter.py @@ -41,6 +41,7 @@ MTDS = [ED1, SED1] class Cert_5_6_2_NetworkDataRouterAsBr(unittest.TestCase): + def setUp(self): self.simulator = config.create_default_simulator() diff --git a/tests/scripts/thread-cert/Cert_5_6_03_NetworkDataRegisterAfterAttachLeader.py b/tests/scripts/thread-cert/Cert_5_6_03_NetworkDataRegisterAfterAttachLeader.py index cbbfe7b65..c8979bfed 100755 --- a/tests/scripts/thread-cert/Cert_5_6_03_NetworkDataRegisterAfterAttachLeader.py +++ b/tests/scripts/thread-cert/Cert_5_6_03_NetworkDataRegisterAfterAttachLeader.py @@ -41,6 +41,7 @@ MTDS = [ED1, SED1] class Cert_5_6_3_NetworkDataRegisterAfterAttachLeader(unittest.TestCase): + def setUp(self): self.simulator = config.create_default_simulator() diff --git a/tests/scripts/thread-cert/Cert_5_6_04_NetworkDataRegisterAfterAttachRouter.py b/tests/scripts/thread-cert/Cert_5_6_04_NetworkDataRegisterAfterAttachRouter.py index d7ad91e47..f083f22c0 100755 --- a/tests/scripts/thread-cert/Cert_5_6_04_NetworkDataRegisterAfterAttachRouter.py +++ b/tests/scripts/thread-cert/Cert_5_6_04_NetworkDataRegisterAfterAttachRouter.py @@ -41,6 +41,7 @@ MTDS = [ED1, SED1] class Cert_5_6_4_NetworkDataRegisterAfterAttachRouter(unittest.TestCase): + def setUp(self): self.simulator = config.create_default_simulator() diff --git a/tests/scripts/thread-cert/Cert_5_6_05_NetworkDataRegisterAfterAttachRouter.py b/tests/scripts/thread-cert/Cert_5_6_05_NetworkDataRegisterAfterAttachRouter.py index 18af5ae82..2a42f95ef 100755 --- a/tests/scripts/thread-cert/Cert_5_6_05_NetworkDataRegisterAfterAttachRouter.py +++ b/tests/scripts/thread-cert/Cert_5_6_05_NetworkDataRegisterAfterAttachRouter.py @@ -41,6 +41,7 @@ MTDS = [ED1, SED1] class Cert_5_6_5_NetworkDataRegisterAfterAttachRouter(unittest.TestCase): + def setUp(self): self.simulator = config.create_default_simulator() diff --git a/tests/scripts/thread-cert/Cert_5_6_06_NetworkDataExpiration.py b/tests/scripts/thread-cert/Cert_5_6_06_NetworkDataExpiration.py index 0c4de82ae..fbae55c72 100755 --- a/tests/scripts/thread-cert/Cert_5_6_06_NetworkDataExpiration.py +++ b/tests/scripts/thread-cert/Cert_5_6_06_NetworkDataExpiration.py @@ -41,6 +41,7 @@ MTDS = [ED1, SED1] class Cert_5_6_6_NetworkDataExpiration(unittest.TestCase): + def setUp(self): self.simulator = config.create_default_simulator() diff --git a/tests/scripts/thread-cert/Cert_5_6_07_NetworkDataRequestREED.py b/tests/scripts/thread-cert/Cert_5_6_07_NetworkDataRequestREED.py index feb89ad53..9fc2a5ecd 100755 --- a/tests/scripts/thread-cert/Cert_5_6_07_NetworkDataRequestREED.py +++ b/tests/scripts/thread-cert/Cert_5_6_07_NetworkDataRequestREED.py @@ -38,6 +38,7 @@ REED = 3 class Cert_5_6_7_NetworkDataRequestREED(unittest.TestCase): + def setUp(self): self.simulator = config.create_default_simulator() diff --git a/tests/scripts/thread-cert/Cert_5_6_08_ContextManagement.py b/tests/scripts/thread-cert/Cert_5_6_08_ContextManagement.py index ff82c7c32..247696348 100755 --- a/tests/scripts/thread-cert/Cert_5_6_08_ContextManagement.py +++ b/tests/scripts/thread-cert/Cert_5_6_08_ContextManagement.py @@ -38,6 +38,7 @@ ED = 3 class Cert_5_6_8_ContextManagement(unittest.TestCase): + def setUp(self): self.simulator = config.create_default_simulator() diff --git a/tests/scripts/thread-cert/Cert_5_6_09_NetworkDataForwarding.py b/tests/scripts/thread-cert/Cert_5_6_09_NetworkDataForwarding.py index bf8b4916d..ae6b48bcf 100755 --- a/tests/scripts/thread-cert/Cert_5_6_09_NetworkDataForwarding.py +++ b/tests/scripts/thread-cert/Cert_5_6_09_NetworkDataForwarding.py @@ -42,6 +42,7 @@ MTDS = [ED, SED] class Cert_5_6_9_NetworkDataForwarding(unittest.TestCase): + def setUp(self): self.simulator = config.create_default_simulator() diff --git a/tests/scripts/thread-cert/Cert_5_8_01_KeySynchronization.py b/tests/scripts/thread-cert/Cert_5_8_01_KeySynchronization.py index 41adbbc01..703ce865e 100755 --- a/tests/scripts/thread-cert/Cert_5_8_01_KeySynchronization.py +++ b/tests/scripts/thread-cert/Cert_5_8_01_KeySynchronization.py @@ -37,6 +37,7 @@ ED = 2 class Cert_5_8_1_KeySynchronization(unittest.TestCase): + def setUp(self): self.simulator = config.create_default_simulator() diff --git a/tests/scripts/thread-cert/Cert_5_8_02_KeyIncrement.py b/tests/scripts/thread-cert/Cert_5_8_02_KeyIncrement.py index 27a4c52bc..d45973edc 100755 --- a/tests/scripts/thread-cert/Cert_5_8_02_KeyIncrement.py +++ b/tests/scripts/thread-cert/Cert_5_8_02_KeyIncrement.py @@ -37,6 +37,7 @@ ROUTER = 2 class Cert_5_8_2_KeyIncrement(unittest.TestCase): + def setUp(self): self.simulator = config.create_default_simulator() diff --git a/tests/scripts/thread-cert/Cert_5_8_03_KeyIncrementRollOver.py b/tests/scripts/thread-cert/Cert_5_8_03_KeyIncrementRollOver.py index b70eeb77c..ac75a97f4 100755 --- a/tests/scripts/thread-cert/Cert_5_8_03_KeyIncrementRollOver.py +++ b/tests/scripts/thread-cert/Cert_5_8_03_KeyIncrementRollOver.py @@ -37,6 +37,7 @@ ROUTER = 2 class Cert_5_8_3_KeyIncrementRollOver(unittest.TestCase): + def setUp(self): self.simulator = config.create_default_simulator() diff --git a/tests/scripts/thread-cert/Cert_6_1_01_RouterAttach.py b/tests/scripts/thread-cert/Cert_6_1_01_RouterAttach.py index a812277e6..e19f06b17 100755 --- a/tests/scripts/thread-cert/Cert_6_1_01_RouterAttach.py +++ b/tests/scripts/thread-cert/Cert_6_1_01_RouterAttach.py @@ -38,6 +38,7 @@ ED = 2 class Cert_6_1_1_RouterAttach(unittest.TestCase): + def setUp(self): self.simulator = config.create_default_simulator() @@ -109,8 +110,7 @@ class Cert_6_1_1_RouterAttach(unittest.TestCase): # 5 - leader msg = leader_messages.next_mle_message( - mle.CommandType.CHILD_ID_RESPONSE - ) + mle.CommandType.CHILD_ID_RESPONSE) msg.assertSentToNode(self.nodes[ED]) # 6 - leader diff --git a/tests/scripts/thread-cert/Cert_6_1_02_REEDAttach_MED.py b/tests/scripts/thread-cert/Cert_6_1_02_REEDAttach_MED.py index 62440f73d..40d229a2f 100755 --- a/tests/scripts/thread-cert/Cert_6_1_02_REEDAttach_MED.py +++ b/tests/scripts/thread-cert/Cert_6_1_02_REEDAttach_MED.py @@ -43,6 +43,7 @@ MED = 3 class Cert_6_1_2_REEDAttach_MED(unittest.TestCase): + def setUp(self): self.simulator = config.create_default_simulator() @@ -99,9 +100,8 @@ class Cert_6_1_2_REEDAttach_MED(unittest.TestCase): check_parent_request(msg, is_first_request=False) # Step 6 - DUT sends Child ID Request - msg = med_messages.next_mle_message( - mle.CommandType.CHILD_ID_REQUEST, sent_to_node=self.nodes[REED] - ) + msg = med_messages.next_mle_message(mle.CommandType.CHILD_ID_REQUEST, + sent_to_node=self.nodes[REED]) check_child_id_request( msg, address_registration=CheckType.CONTAIN, @@ -117,8 +117,7 @@ class Cert_6_1_2_REEDAttach_MED(unittest.TestCase): # Step 8 - DUT sends Child Update messages msg = med_messages.next_mle_message( - mle.CommandType.CHILD_UPDATE_REQUEST - ) + mle.CommandType.CHILD_UPDATE_REQUEST) check_child_update_request_from_child( msg, source_address=CheckType.CONTAIN, diff --git a/tests/scripts/thread-cert/Cert_6_1_02_REEDAttach_SED.py b/tests/scripts/thread-cert/Cert_6_1_02_REEDAttach_SED.py index 41d588206..a9cc61cb7 100755 --- a/tests/scripts/thread-cert/Cert_6_1_02_REEDAttach_SED.py +++ b/tests/scripts/thread-cert/Cert_6_1_02_REEDAttach_SED.py @@ -44,6 +44,7 @@ SED = 3 class Cert_6_1_2_REEDAttach_SED(unittest.TestCase): + def setUp(self): self.simulator = config.create_default_simulator() @@ -100,9 +101,8 @@ class Cert_6_1_2_REEDAttach_SED(unittest.TestCase): check_parent_request(msg, is_first_request=False) # Step 6 - DUT sends Child ID Request - msg = sed_messages.next_mle_message( - mle.CommandType.CHILD_ID_REQUEST, sent_to_node=self.nodes[REED] - ) + msg = sed_messages.next_mle_message(mle.CommandType.CHILD_ID_REQUEST, + sent_to_node=self.nodes[REED]) check_child_id_request( msg, address_registration=CheckType.CONTAIN, @@ -119,9 +119,8 @@ class Cert_6_1_2_REEDAttach_SED(unittest.TestCase): # Step 11 - SED sends periodic 802.15.4 Data Request messages msg = sed_messages.next_message() - self.assertEqual( - False, msg.isMacAddressTypeLong() - ) # Extra check, keep-alive messages are of short types of mac address + self.assertEqual(False, msg.isMacAddressTypeLong( + )) # Extra check, keep-alive messages are of short types of mac address self.assertEqual(msg.type, message.MessageType.COMMAND) self.assertEqual( msg.mac_header.command_type, diff --git a/tests/scripts/thread-cert/Cert_6_1_03_RouterAttachConnectivity.py b/tests/scripts/thread-cert/Cert_6_1_03_RouterAttachConnectivity.py index eebb4e312..18eadf0a2 100755 --- a/tests/scripts/thread-cert/Cert_6_1_03_RouterAttachConnectivity.py +++ b/tests/scripts/thread-cert/Cert_6_1_03_RouterAttachConnectivity.py @@ -40,6 +40,7 @@ ED = 5 class Cert_6_1_3_RouterAttachConnectivity(unittest.TestCase): + def setUp(self): self.simulator = config.create_default_simulator() diff --git a/tests/scripts/thread-cert/Cert_6_1_04_REEDAttachConnectivity.py b/tests/scripts/thread-cert/Cert_6_1_04_REEDAttachConnectivity.py index c2ee061ae..d046a9235 100755 --- a/tests/scripts/thread-cert/Cert_6_1_04_REEDAttachConnectivity.py +++ b/tests/scripts/thread-cert/Cert_6_1_04_REEDAttachConnectivity.py @@ -40,6 +40,7 @@ ED = 5 class Cert_6_1_4_REEDAttachConnectivity(unittest.TestCase): + def setUp(self): self.simulator = config.create_default_simulator() diff --git a/tests/scripts/thread-cert/Cert_6_1_05_RouterAttachLinkQuality.py b/tests/scripts/thread-cert/Cert_6_1_05_RouterAttachLinkQuality.py index 7f3311832..92587647c 100755 --- a/tests/scripts/thread-cert/Cert_6_1_05_RouterAttachLinkQuality.py +++ b/tests/scripts/thread-cert/Cert_6_1_05_RouterAttachLinkQuality.py @@ -39,6 +39,7 @@ ED = 4 class Cert_6_1_5_RouterAttachLinkQuality(unittest.TestCase): + def setUp(self): self.simulator = config.create_default_simulator() @@ -62,9 +63,7 @@ class Cert_6_1_5_RouterAttachLinkQuality(unittest.TestCase): self.nodes[ROUTER2].set_panid(0xface) self.nodes[ROUTER2].set_mode('rsdn') self.nodes[ROUTER2].add_whitelist(self.nodes[LEADER].get_addr64()) - self.nodes[ROUTER2].add_whitelist( - self.nodes[ED].get_addr64(), rssi=-85 - ) + self.nodes[ROUTER2].add_whitelist(self.nodes[ED].get_addr64(), rssi=-85) self.nodes[ROUTER2].enable_whitelist() self.nodes[ROUTER2].set_router_selection_jitter(1) diff --git a/tests/scripts/thread-cert/Cert_6_1_06_REEDAttachLinkQuality_ED.py b/tests/scripts/thread-cert/Cert_6_1_06_REEDAttachLinkQuality_ED.py index 90661e6a1..e71e254d7 100755 --- a/tests/scripts/thread-cert/Cert_6_1_06_REEDAttachLinkQuality_ED.py +++ b/tests/scripts/thread-cert/Cert_6_1_06_REEDAttachLinkQuality_ED.py @@ -40,6 +40,7 @@ ED = 4 class Cert_6_1_6_REEDAttachLinkQuality_ED(unittest.TestCase): + def setUp(self): self.simulator = config.create_default_simulator() @@ -63,9 +64,7 @@ class Cert_6_1_6_REEDAttachLinkQuality_ED(unittest.TestCase): self.nodes[ROUTER2].set_panid(0xface) self.nodes[ROUTER2].set_mode('rsdn') self.nodes[ROUTER2].add_whitelist(self.nodes[LEADER].get_addr64()) - self.nodes[ROUTER2].add_whitelist( - self.nodes[ED].get_addr64(), rssi=-85 - ) + self.nodes[ROUTER2].add_whitelist(self.nodes[ED].get_addr64(), rssi=-85) self.nodes[ROUTER2].enable_whitelist() self.nodes[ROUTER2].set_router_selection_jitter(1) @@ -140,9 +139,7 @@ class Cert_6_1_6_REEDAttachLinkQuality_ED(unittest.TestCase): self.assertEqual(0, scan_mask_tlv.end_device) # 4 - Router2 - msg = router2_messages.next_mle_message( - mle.CommandType.PARENT_RESPONSE - ) + msg = router2_messages.next_mle_message(mle.CommandType.PARENT_RESPONSE) msg.assertSentToNode(self.nodes[ED]) # 5 - ED @@ -159,9 +156,7 @@ class Cert_6_1_6_REEDAttachLinkQuality_ED(unittest.TestCase): self.assertEqual(1, scan_mask_tlv.end_device) # 6 - REED - msg = router2_messages.next_mle_message( - mle.CommandType.PARENT_RESPONSE - ) + msg = router2_messages.next_mle_message(mle.CommandType.PARENT_RESPONSE) msg.assertSentToNode(self.nodes[ED]) msg = reed_messages.next_mle_message(mle.CommandType.PARENT_RESPONSE) diff --git a/tests/scripts/thread-cert/Cert_6_1_06_REEDAttachLinkQuality_SED.py b/tests/scripts/thread-cert/Cert_6_1_06_REEDAttachLinkQuality_SED.py index 8ed653305..ab43e8cef 100755 --- a/tests/scripts/thread-cert/Cert_6_1_06_REEDAttachLinkQuality_SED.py +++ b/tests/scripts/thread-cert/Cert_6_1_06_REEDAttachLinkQuality_SED.py @@ -40,6 +40,7 @@ SED = 4 class Cert_6_1_6_REEDAttachLinkQuality_SED(unittest.TestCase): + def setUp(self): self.simulator = config.create_default_simulator() @@ -63,9 +64,8 @@ class Cert_6_1_6_REEDAttachLinkQuality_SED(unittest.TestCase): self.nodes[ROUTER2].set_panid(0xface) self.nodes[ROUTER2].set_mode('rsdn') self.nodes[ROUTER2].add_whitelist(self.nodes[LEADER].get_addr64()) - self.nodes[ROUTER2].add_whitelist( - self.nodes[SED].get_addr64(), rssi=-85 - ) + self.nodes[ROUTER2].add_whitelist(self.nodes[SED].get_addr64(), + rssi=-85) self.nodes[ROUTER2].enable_whitelist() self.nodes[ROUTER2].set_router_selection_jitter(1) @@ -141,9 +141,7 @@ class Cert_6_1_6_REEDAttachLinkQuality_SED(unittest.TestCase): self.assertEqual(0, scan_mask_tlv.end_device) # 4 - Router2 - msg = router2_messages.next_mle_message( - mle.CommandType.PARENT_RESPONSE - ) + msg = router2_messages.next_mle_message(mle.CommandType.PARENT_RESPONSE) msg.assertSentToNode(self.nodes[SED]) # 5 - SED @@ -160,9 +158,7 @@ class Cert_6_1_6_REEDAttachLinkQuality_SED(unittest.TestCase): self.assertEqual(1, scan_mask_tlv.end_device) # 6 - REED - msg = router2_messages.next_mle_message( - mle.CommandType.PARENT_RESPONSE - ) + msg = router2_messages.next_mle_message(mle.CommandType.PARENT_RESPONSE) msg.assertSentToNode(self.nodes[SED]) msg = reed_messages.next_mle_message(mle.CommandType.PARENT_RESPONSE) diff --git a/tests/scripts/thread-cert/Cert_6_1_07_EDSynchronization.py b/tests/scripts/thread-cert/Cert_6_1_07_EDSynchronization.py index 6af3b3332..e0e82c1e5 100755 --- a/tests/scripts/thread-cert/Cert_6_1_07_EDSynchronization.py +++ b/tests/scripts/thread-cert/Cert_6_1_07_EDSynchronization.py @@ -40,6 +40,7 @@ ROUTER3 = 5 class Cert_6_1_7_EDSynchronization(unittest.TestCase): + def setUp(self): self.simulator = config.create_default_simulator() diff --git a/tests/scripts/thread-cert/Cert_6_2_01_NewPartition.py b/tests/scripts/thread-cert/Cert_6_2_01_NewPartition.py index 0bfafa6b2..7ddc94dc1 100755 --- a/tests/scripts/thread-cert/Cert_6_2_01_NewPartition.py +++ b/tests/scripts/thread-cert/Cert_6_2_01_NewPartition.py @@ -38,6 +38,7 @@ ED = 3 class Cert_6_2_1_NewPartition(unittest.TestCase): + def setUp(self): self.simulator = config.create_default_simulator() diff --git a/tests/scripts/thread-cert/Cert_6_2_02_NewPartition.py b/tests/scripts/thread-cert/Cert_6_2_02_NewPartition.py index d2c7cfccf..c6fb19370 100755 --- a/tests/scripts/thread-cert/Cert_6_2_02_NewPartition.py +++ b/tests/scripts/thread-cert/Cert_6_2_02_NewPartition.py @@ -39,6 +39,7 @@ ED = 4 class Cert_6_2_2_NewPartition(unittest.TestCase): + def setUp(self): self.simulator = config.create_default_simulator() diff --git a/tests/scripts/thread-cert/Cert_6_3_01_OrphanReattach.py b/tests/scripts/thread-cert/Cert_6_3_01_OrphanReattach.py index 0e7743f23..d838d1aca 100755 --- a/tests/scripts/thread-cert/Cert_6_3_01_OrphanReattach.py +++ b/tests/scripts/thread-cert/Cert_6_3_01_OrphanReattach.py @@ -38,6 +38,7 @@ ED = 3 class Cert_6_3_1_OrphanReattach(unittest.TestCase): + def setUp(self): self.simulator = config.create_default_simulator() diff --git a/tests/scripts/thread-cert/Cert_6_3_02_NetworkDataUpdate.py b/tests/scripts/thread-cert/Cert_6_3_02_NetworkDataUpdate.py index 02b34eae6..745c0b609 100755 --- a/tests/scripts/thread-cert/Cert_6_3_02_NetworkDataUpdate.py +++ b/tests/scripts/thread-cert/Cert_6_3_02_NetworkDataUpdate.py @@ -37,6 +37,7 @@ ED = 2 class Cert_6_3_2_NetworkDataUpdate(unittest.TestCase): + def setUp(self): self.simulator = config.create_default_simulator() diff --git a/tests/scripts/thread-cert/Cert_6_4_01_LinkLocal.py b/tests/scripts/thread-cert/Cert_6_4_01_LinkLocal.py index 1448293cd..84eca5057 100755 --- a/tests/scripts/thread-cert/Cert_6_4_01_LinkLocal.py +++ b/tests/scripts/thread-cert/Cert_6_4_01_LinkLocal.py @@ -37,6 +37,7 @@ ED = 2 class Cert_6_4_1_LinkLocal(unittest.TestCase): + def setUp(self): self.simulator = config.create_default_simulator() diff --git a/tests/scripts/thread-cert/Cert_6_4_02_RealmLocal.py b/tests/scripts/thread-cert/Cert_6_4_02_RealmLocal.py index a8bf7a5b7..022c4cebc 100755 --- a/tests/scripts/thread-cert/Cert_6_4_02_RealmLocal.py +++ b/tests/scripts/thread-cert/Cert_6_4_02_RealmLocal.py @@ -38,6 +38,7 @@ ED = 3 class Cert_5_3_2_RealmLocal(unittest.TestCase): + def setUp(self): self.simulator = config.create_default_simulator() @@ -87,21 +88,15 @@ class Cert_5_3_2_RealmLocal(unittest.TestCase): self.assertTrue(self.nodes[LEADER].ping(addr, size=256)) self.assertTrue(self.nodes[LEADER].ping(addr)) - self.assertTrue( - self.nodes[LEADER].ping('ff03::1', num_responses=2, size=256) - ) + self.assertTrue(self.nodes[LEADER].ping('ff03::1', + num_responses=2, + size=256)) self.assertTrue(self.nodes[LEADER].ping('ff03::1', num_responses=2)) - self.assertTrue( - self.nodes[LEADER].ping( - 'ff33:0040:fdde:ad00:beef:0:0:1', num_responses=2, size=256 - ) - ) - self.assertTrue( - self.nodes[LEADER].ping( - 'ff33:0040:fdde:ad00:beef:0:0:1', num_responses=2 - ) - ) + self.assertTrue(self.nodes[LEADER].ping( + 'ff33:0040:fdde:ad00:beef:0:0:1', num_responses=2, size=256)) + self.assertTrue(self.nodes[LEADER].ping( + 'ff33:0040:fdde:ad00:beef:0:0:1', num_responses=2)) if __name__ == '__main__': diff --git a/tests/scripts/thread-cert/Cert_6_5_01_ChildResetSynchronize.py b/tests/scripts/thread-cert/Cert_6_5_01_ChildResetSynchronize.py index fbf9d8aa2..02fc98620 100755 --- a/tests/scripts/thread-cert/Cert_6_5_01_ChildResetSynchronize.py +++ b/tests/scripts/thread-cert/Cert_6_5_01_ChildResetSynchronize.py @@ -37,6 +37,7 @@ ED = 2 class Cert_6_5_1_ChildResetSynchronize(unittest.TestCase): + def setUp(self): self.simulator = config.create_default_simulator() diff --git a/tests/scripts/thread-cert/Cert_6_5_02_ChildResetReattach.py b/tests/scripts/thread-cert/Cert_6_5_02_ChildResetReattach.py index 846f6ae6e..3e11840e3 100755 --- a/tests/scripts/thread-cert/Cert_6_5_02_ChildResetReattach.py +++ b/tests/scripts/thread-cert/Cert_6_5_02_ChildResetReattach.py @@ -37,6 +37,7 @@ ED = 2 class Cert_6_5_2_ChildResetReattach(unittest.TestCase): + def setUp(self): self.simulator = config.create_default_simulator() diff --git a/tests/scripts/thread-cert/Cert_6_6_01_KeyIncrement.py b/tests/scripts/thread-cert/Cert_6_6_01_KeyIncrement.py index 77967a0d9..1e6664c4b 100755 --- a/tests/scripts/thread-cert/Cert_6_6_01_KeyIncrement.py +++ b/tests/scripts/thread-cert/Cert_6_6_01_KeyIncrement.py @@ -37,6 +37,7 @@ ED = 2 class Cert_6_6_1_KeyIncrement(unittest.TestCase): + def setUp(self): self.simulator = config.create_default_simulator() diff --git a/tests/scripts/thread-cert/Cert_6_6_02_KeyIncrementRollOver.py b/tests/scripts/thread-cert/Cert_6_6_02_KeyIncrementRollOver.py index 766b42b50..25637a145 100755 --- a/tests/scripts/thread-cert/Cert_6_6_02_KeyIncrementRollOver.py +++ b/tests/scripts/thread-cert/Cert_6_6_02_KeyIncrementRollOver.py @@ -37,6 +37,7 @@ ED = 2 class Cert_6_6_2_KeyIncrement1(unittest.TestCase): + def setUp(self): self.simulator = config.create_default_simulator() diff --git a/tests/scripts/thread-cert/Cert_7_1_01_BorderRouterAsLeader.py b/tests/scripts/thread-cert/Cert_7_1_01_BorderRouterAsLeader.py index 4f02528a7..1118ab7a9 100755 --- a/tests/scripts/thread-cert/Cert_7_1_01_BorderRouterAsLeader.py +++ b/tests/scripts/thread-cert/Cert_7_1_01_BorderRouterAsLeader.py @@ -51,6 +51,7 @@ MTDS = [SED1, MED1] class Cert_7_1_1_BorderRouterAsLeader(unittest.TestCase): + def setUp(self): self.simulator = config.create_default_simulator() @@ -138,68 +139,52 @@ class Cert_7_1_1_BorderRouterAsLeader(unittest.TestCase): 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(prefix=b'2001000200000001'), - SinglePrefixCheck(prefix=b'2001000200000002'), - ] - ) - ), + network_data_check=NetworkDataCheck(prefixes_check=PrefixesCheck( + prefix_check_list=[ + SinglePrefixCheck(prefix=b'2001000200000001'), + SinglePrefixCheck(prefix=b'2001000200000002'), + ])), ) # Step 4 - DUT sends a MLE Child ID Response to Router1 msg = leader_messages.next_mle_message( - mle.CommandType.CHILD_ID_RESPONSE - ) + mle.CommandType.CHILD_ID_RESPONSE) check_child_id_response( msg, - network_data_check=NetworkDataCheck( - prefixes_check=PrefixesCheck(prefix_cnt=2) - ), + network_data_check=NetworkDataCheck(prefixes_check=PrefixesCheck( + prefix_cnt=2)), ) # Step 6 - DUT sends a MLE Child ID Response to SED1 msg = leader_messages.next_mle_message( - mle.CommandType.CHILD_ID_RESPONSE - ) + mle.CommandType.CHILD_ID_RESPONSE) check_child_id_response( msg, - network_data_check=NetworkDataCheck( - prefixes_check=PrefixesCheck( - prefix_check_list=[ - SinglePrefixCheck(border_router_16=0xfffe) - ] - ) - ), + network_data_check=NetworkDataCheck(prefixes_check=PrefixesCheck( + prefix_check_list=[SinglePrefixCheck( + border_router_16=0xfffe)])), ) # For Step 10 msg_chd_upd_res_to_sed = leader_messages.next_mle_message( - mle.CommandType.CHILD_UPDATE_RESPONSE - ) + mle.CommandType.CHILD_UPDATE_RESPONSE) # Step 8 - DUT sends a MLE Child ID Response to MED1 msg = leader_messages.next_mle_message( - mle.CommandType.CHILD_ID_RESPONSE - ) + mle.CommandType.CHILD_ID_RESPONSE) check_child_id_response( msg, - network_data_check=NetworkDataCheck( - prefixes_check=PrefixesCheck(prefix_cnt=2) - ), + network_data_check=NetworkDataCheck(prefixes_check=PrefixesCheck( + prefix_cnt=2)), ) # Step 10 - DUT sends Child Update Response msg_chd_upd_res_to_med = leader_messages.next_mle_message( - mle.CommandType.CHILD_UPDATE_RESPONSE - ) + mle.CommandType.CHILD_UPDATE_RESPONSE) msg = med1_messages.next_mle_message( - mle.CommandType.CHILD_UPDATE_REQUEST - ) + mle.CommandType.CHILD_UPDATE_REQUEST) check_child_update_request_from_child( - msg, address_registration=CheckType.CONTAIN, CIDs=[0, 1, 2] - ) + msg, address_registration=CheckType.CONTAIN, CIDs=[0, 1, 2]) check_child_update_response( msg_chd_upd_res_to_med, @@ -208,11 +193,9 @@ class Cert_7_1_1_BorderRouterAsLeader(unittest.TestCase): ) msg = sed1_messages.next_mle_message( - mle.CommandType.CHILD_UPDATE_REQUEST - ) + mle.CommandType.CHILD_UPDATE_REQUEST) check_child_update_request_from_child( - msg, address_registration=CheckType.CONTAIN, CIDs=[0, 1] - ) + msg, address_registration=CheckType.CONTAIN, CIDs=[0, 1]) check_child_update_response( msg_chd_upd_res_to_sed, address_registration=CheckType.CONTAIN, diff --git a/tests/scripts/thread-cert/Cert_7_1_02_BorderRouterAsRouter.py b/tests/scripts/thread-cert/Cert_7_1_02_BorderRouterAsRouter.py index 22eb0c8ef..c6098b276 100755 --- a/tests/scripts/thread-cert/Cert_7_1_02_BorderRouterAsRouter.py +++ b/tests/scripts/thread-cert/Cert_7_1_02_BorderRouterAsRouter.py @@ -41,6 +41,7 @@ MTDS = [ED2, SED2] class Cert_7_1_2_BorderRouterAsRouter(unittest.TestCase): + def setUp(self): self.simulator = config.create_default_simulator() diff --git a/tests/scripts/thread-cert/Cert_7_1_03_BorderRouterAsLeader.py b/tests/scripts/thread-cert/Cert_7_1_03_BorderRouterAsLeader.py index 018cb04ac..8a6543791 100755 --- a/tests/scripts/thread-cert/Cert_7_1_03_BorderRouterAsLeader.py +++ b/tests/scripts/thread-cert/Cert_7_1_03_BorderRouterAsLeader.py @@ -51,6 +51,7 @@ MTDS = [SED1, MED1] class Cert_7_1_3_BorderRouterAsLeader(unittest.TestCase): + def setUp(self): self.simulator = config.create_default_simulator() @@ -143,24 +144,19 @@ class Cert_7_1_3_BorderRouterAsLeader(unittest.TestCase): 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'), - ] - ) - ), + 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 - ) + mle.CommandType.CHILD_UPDATE_REQUEST) check_child_update_request_from_child( - msg, address_registration=CheckType.CONTAIN, CIDs=[0, 1, 2] - ) + 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 @@ -170,9 +166,9 @@ class Cert_7_1_3_BorderRouterAsLeader(unittest.TestCase): mle.CommandType.CHILD_UPDATE_RESPONSE, sent_to_node=self.nodes[MED1], ) - check_child_update_response( - msg, address_registration=CheckType.CONTAIN, CIDs=[1, 2] - ) + check_child_update_response(msg, + address_registration=CheckType.CONTAIN, + CIDs=[1, 2]) # 6A & 6B - Leader if config.LEADER_NOTIFY_SED_BY_CHILD_UPDATE_REQUEST: @@ -188,27 +184,24 @@ class Cert_7_1_3_BorderRouterAsLeader(unittest.TestCase): ) else: msg = leader_messages.next_mle_message( - mle.CommandType.DATA_RESPONSE, sent_to_node=self.nodes[SED1] - ) + 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 - ) + mle.CommandType.CHILD_UPDATE_REQUEST) check_child_update_request_from_child( - msg, address_registration=CheckType.CONTAIN, CIDs=[0, 1] - ) + 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] - ) + check_child_update_response(msg, + address_registration=CheckType.CONTAIN, + CIDs=[1]) if __name__ == '__main__': diff --git a/tests/scripts/thread-cert/Cert_7_1_04_BorderRouterAsRouter.py b/tests/scripts/thread-cert/Cert_7_1_04_BorderRouterAsRouter.py index 7ffb393e7..6f9c1441e 100755 --- a/tests/scripts/thread-cert/Cert_7_1_04_BorderRouterAsRouter.py +++ b/tests/scripts/thread-cert/Cert_7_1_04_BorderRouterAsRouter.py @@ -41,6 +41,7 @@ MTDS = [SED2, ED2] class Cert_7_1_4_BorderRouterAsRouter(unittest.TestCase): + def setUp(self): self.simulator = config.create_default_simulator() diff --git a/tests/scripts/thread-cert/Cert_7_1_05_BorderRouterAsRouter.py b/tests/scripts/thread-cert/Cert_7_1_05_BorderRouterAsRouter.py index f048369b5..431cc2303 100755 --- a/tests/scripts/thread-cert/Cert_7_1_05_BorderRouterAsRouter.py +++ b/tests/scripts/thread-cert/Cert_7_1_05_BorderRouterAsRouter.py @@ -41,6 +41,7 @@ MTDS = [ED2, SED2] class Cert_7_1_5_BorderRouterAsRouter(unittest.TestCase): + def setUp(self): self.simulator = config.create_default_simulator() @@ -127,11 +128,8 @@ class Cert_7_1_5_BorderRouterAsRouter(unittest.TestCase): self.assertTrue(any('2001:2:0:2' in addr[0:10] for addr in addrs)) self.assertTrue(any('2001:2:0:3' 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' - or addr[0:10] == '2001:2:0:3' - ): + if (addr[0:10] == '2001:2:0:1' or addr[0:10] == '2001:2:0:2' or + addr[0:10] == '2001:2:0:3'): self.assertTrue(self.nodes[LEADER].ping(addr)) addrs = self.nodes[SED2].get_addrs() @@ -139,11 +137,8 @@ class Cert_7_1_5_BorderRouterAsRouter(unittest.TestCase): self.assertFalse(any('2001:2:0:2' in addr[0:10] for addr in addrs)) self.assertTrue(any('2001:2:0:3' 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' - or addr[0:10] == '2001:2:0:3' - ): + if (addr[0:10] == '2001:2:0:1' or addr[0:10] == '2001:2:0:2' or + addr[0:10] == '2001:2:0:3'): self.assertTrue(self.nodes[LEADER].ping(addr)) diff --git a/tests/scripts/thread-cert/Cert_8_1_01_Commissioning.py b/tests/scripts/thread-cert/Cert_8_1_01_Commissioning.py index e5ee37434..aaa9b83a7 100755 --- a/tests/scripts/thread-cert/Cert_8_1_01_Commissioning.py +++ b/tests/scripts/thread-cert/Cert_8_1_01_Commissioning.py @@ -42,6 +42,7 @@ JOINER = 2 class Cert_8_1_01_Commissioning(unittest.TestCase): + def setUp(self): self.simulator = config.create_default_simulator() @@ -52,8 +53,7 @@ class Cert_8_1_01_Commissioning(unittest.TestCase): self.nodes[COMMISSIONER].set_panid(0xface) self.nodes[COMMISSIONER].set_mode('rsdn') self.nodes[COMMISSIONER].set_masterkey( - '00112233445566778899aabbccddeeff' - ) + '00112233445566778899aabbccddeeff') self.nodes[JOINER].set_mode('rsdn') self.nodes[JOINER].set_masterkey('deadbeefdeadbeefdeadbeefdeadbeef') @@ -73,15 +73,13 @@ class Cert_8_1_01_Commissioning(unittest.TestCase): self.nodes[COMMISSIONER].commissioner_start() self.simulator.go(3) self.nodes[COMMISSIONER].commissioner_add_joiner( - self.nodes[JOINER].get_eui64(), 'OPENTHREAD' - ) + self.nodes[JOINER].get_eui64(), 'OPENTHREAD') self.nodes[JOINER].interface_up() self.nodes[JOINER].joiner_start('OPENTHREAD') self.simulator.go(10) self.simulator.read_cert_messages_in_commissioning_log( - [COMMISSIONER, JOINER] - ) + [COMMISSIONER, JOINER]) self.assertEqual( self.nodes[JOINER].get_masterkey(), self.nodes[COMMISSIONER].get_masterkey(), @@ -89,66 +87,55 @@ class Cert_8_1_01_Commissioning(unittest.TestCase): joiner_messages = self.simulator.get_messages_sent_by(JOINER) commissioner_messages = self.simulator.get_messages_sent_by( - COMMISSIONER - ) + COMMISSIONER) # 2 - N/A # 3 - Joiner_1 msg = joiner_messages.next_mle_message( - mle.CommandType.DISCOVERY_REQUEST - ) + mle.CommandType.DISCOVERY_REQUEST) command.check_discovery_request(msg) request_src_addr = msg.mac_header.src_address # 4 - Commissioner msg = commissioner_messages.next_mle_message( - mle.CommandType.DISCOVERY_RESPONSE - ) - command.check_discovery_response( - msg, request_src_addr, steering_data=CheckType.CONTAIN - ) + mle.CommandType.DISCOVERY_RESPONSE) + command.check_discovery_response(msg, + request_src_addr, + steering_data=CheckType.CONTAIN) udp_port_set_by_commissioner = command.get_joiner_udp_port_in_discovery_response( msg) # 5.2 - Joiner_1 - msg = joiner_messages.next_dtls_message( - dtls.ContentType.HANDSHAKE, dtls.HandshakeType.CLIENT_HELLO - ) + msg = joiner_messages.next_dtls_message(dtls.ContentType.HANDSHAKE, + dtls.HandshakeType.CLIENT_HELLO) self.assertEqual(msg.get_dst_udp_port(), udp_port_set_by_commissioner) # 5.3 - Commissioner msg = commissioner_messages.next_dtls_message( - dtls.ContentType.HANDSHAKE, dtls.HandshakeType.HELLO_VERIFY_REQUEST - ) + dtls.ContentType.HANDSHAKE, dtls.HandshakeType.HELLO_VERIFY_REQUEST) commissioner_cookie = msg.dtls.body.cookie # 5.4 - Joiner_1 - msg = joiner_messages.next_dtls_message( - dtls.ContentType.HANDSHAKE, dtls.HandshakeType.CLIENT_HELLO - ) + msg = joiner_messages.next_dtls_message(dtls.ContentType.HANDSHAKE, + dtls.HandshakeType.CLIENT_HELLO) self.assertEqual(commissioner_cookie, msg.dtls.body.cookie) self.assertEqual(msg.get_dst_udp_port(), udp_port_set_by_commissioner) # 5.5 - Commissioner + commissioner_messages.next_dtls_message(dtls.ContentType.HANDSHAKE, + dtls.HandshakeType.SERVER_HELLO) commissioner_messages.next_dtls_message( - dtls.ContentType.HANDSHAKE, dtls.HandshakeType.SERVER_HELLO - ) + dtls.ContentType.HANDSHAKE, dtls.HandshakeType.SERVER_KEY_EXCHANGE) commissioner_messages.next_dtls_message( - dtls.ContentType.HANDSHAKE, dtls.HandshakeType.SERVER_KEY_EXCHANGE - ) - commissioner_messages.next_dtls_message( - dtls.ContentType.HANDSHAKE, dtls.HandshakeType.SERVER_HELLO_DONE - ) + dtls.ContentType.HANDSHAKE, dtls.HandshakeType.SERVER_HELLO_DONE) # 5.6 - Joiner_1 msg = joiner_messages.next_dtls_message( - dtls.ContentType.HANDSHAKE, dtls.HandshakeType.CLIENT_KEY_EXCHANGE - ) + dtls.ContentType.HANDSHAKE, dtls.HandshakeType.CLIENT_KEY_EXCHANGE) self.assertEqual(msg.get_dst_udp_port(), udp_port_set_by_commissioner) msg = joiner_messages.next_dtls_message( - dtls.ContentType.CHANGE_CIPHER_SPEC - ) + dtls.ContentType.CHANGE_CIPHER_SPEC) self.assertEqual(msg.get_dst_udp_port(), udp_port_set_by_commissioner) # TODO(wgtdkp): It's required to verify DTLS FINISHED message here. @@ -156,8 +143,7 @@ class Cert_8_1_01_Commissioning(unittest.TestCase): # 5.7 - Commissioner commissioner_messages.next_dtls_message( - dtls.ContentType.CHANGE_CIPHER_SPEC - ) + dtls.ContentType.CHANGE_CIPHER_SPEC) # TODO(wgtdkp): It's required to verify DTLS FINISHED message here. # Currently not handled as it is encrypted. @@ -165,16 +151,13 @@ class Cert_8_1_01_Commissioning(unittest.TestCase): # 5.8,9,10,11 # - Joiner_1 command.check_joiner_commissioning_messages( - joiner_messages.commissioning_messages - ) + joiner_messages.commissioning_messages) # - Commissioner command.check_commissioner_commissioning_messages( - commissioner_messages.commissioning_messages - ) + commissioner_messages.commissioning_messages) # As commissioner is also joiner router command.check_joiner_router_commissioning_messages( - commissioner_messages.commissioning_messages - ) + commissioner_messages.commissioning_messages) self.nodes[JOINER].thread_start() self.simulator.go(5) diff --git a/tests/scripts/thread-cert/Cert_8_1_02_Commissioning.py b/tests/scripts/thread-cert/Cert_8_1_02_Commissioning.py index 01c60a204..017f2aa6b 100755 --- a/tests/scripts/thread-cert/Cert_8_1_02_Commissioning.py +++ b/tests/scripts/thread-cert/Cert_8_1_02_Commissioning.py @@ -37,6 +37,7 @@ JOINER = 2 class Cert_8_1_02_Commissioning(unittest.TestCase): + def setUp(self): self.simulator = config.create_default_simulator() @@ -47,8 +48,7 @@ class Cert_8_1_02_Commissioning(unittest.TestCase): self.nodes[COMMISSIONER].set_panid(0xface) self.nodes[COMMISSIONER].set_mode('rsdn') self.nodes[COMMISSIONER].set_masterkey( - 'deadbeefdeadbeefdeadbeefdeadbeef' - ) + 'deadbeefdeadbeefdeadbeefdeadbeef') self.nodes[JOINER].set_mode('rsdn') self.nodes[JOINER].set_masterkey('00112233445566778899aabbccddeeff') @@ -68,8 +68,7 @@ class Cert_8_1_02_Commissioning(unittest.TestCase): self.nodes[COMMISSIONER].commissioner_start() self.simulator.go(3) self.nodes[COMMISSIONER].commissioner_add_joiner( - self.nodes[JOINER].get_eui64(), 'OPENTHREAD' - ) + self.nodes[JOINER].get_eui64(), 'OPENTHREAD') self.nodes[JOINER].interface_up() self.nodes[JOINER].joiner_start('DAERHTNEPO') diff --git a/tests/scripts/thread-cert/Cert_8_2_01_JoinerRouter.py b/tests/scripts/thread-cert/Cert_8_2_01_JoinerRouter.py index 0cb54bb65..d9963013e 100755 --- a/tests/scripts/thread-cert/Cert_8_2_01_JoinerRouter.py +++ b/tests/scripts/thread-cert/Cert_8_2_01_JoinerRouter.py @@ -38,6 +38,7 @@ JOINER = 3 class Cert_8_2_01_JoinerRouter(unittest.TestCase): + def setUp(self): self.simulator = config.create_default_simulator() @@ -48,15 +49,13 @@ class Cert_8_2_01_JoinerRouter(unittest.TestCase): self.nodes[COMMISSIONER].set_panid(0xface) self.nodes[COMMISSIONER].set_mode('rsdn') self.nodes[COMMISSIONER].set_masterkey( - 'deadbeefdeadbeefdeadbeefdeadbeef' - ) + 'deadbeefdeadbeefdeadbeefdeadbeef') self.nodes[COMMISSIONER].enable_whitelist() self.nodes[COMMISSIONER].set_router_selection_jitter(1) self.nodes[JOINER_ROUTER].set_mode('rsdn') self.nodes[JOINER_ROUTER].set_masterkey( - '00112233445566778899aabbccddeeff' - ) + '00112233445566778899aabbccddeeff') self.nodes[JOINER_ROUTER].enable_whitelist() self.nodes[JOINER_ROUTER].set_router_selection_jitter(1) @@ -80,19 +79,15 @@ class Cert_8_2_01_JoinerRouter(unittest.TestCase): self.nodes[COMMISSIONER].commissioner_start() self.simulator.go(5) self.nodes[COMMISSIONER].commissioner_add_joiner( - self.nodes[JOINER_ROUTER].get_eui64(), 'OPENTHREAD' - ) + self.nodes[JOINER_ROUTER].get_eui64(), 'OPENTHREAD') self.nodes[COMMISSIONER].commissioner_add_joiner( - self.nodes[JOINER].get_eui64(), 'OPENTHREAD2' - ) + self.nodes[JOINER].get_eui64(), 'OPENTHREAD2') self.simulator.go(5) self.nodes[COMMISSIONER].add_whitelist( - self.nodes[JOINER_ROUTER].get_joiner_id() - ) + self.nodes[JOINER_ROUTER].get_joiner_id()) self.nodes[JOINER_ROUTER].add_whitelist( - self.nodes[COMMISSIONER].get_addr64() - ) + self.nodes[COMMISSIONER].get_addr64()) self.nodes[JOINER_ROUTER].interface_up() self.nodes[JOINER_ROUTER].joiner_start('OPENTHREAD') @@ -103,19 +98,15 @@ class Cert_8_2_01_JoinerRouter(unittest.TestCase): ) self.nodes[COMMISSIONER].add_whitelist( - self.nodes[JOINER_ROUTER].get_addr64() - ) + self.nodes[JOINER_ROUTER].get_addr64()) self.nodes[JOINER_ROUTER].thread_start() self.simulator.go(5) self.assertEqual(self.nodes[JOINER_ROUTER].get_state(), 'router') self.nodes[JOINER_ROUTER].add_whitelist( - self.nodes[JOINER].get_joiner_id() - ) - self.nodes[JOINER].add_whitelist( - self.nodes[JOINER_ROUTER].get_addr64() - ) + self.nodes[JOINER].get_joiner_id()) + self.nodes[JOINER].add_whitelist(self.nodes[JOINER_ROUTER].get_addr64()) self.nodes[JOINER].interface_up() self.nodes[JOINER].joiner_start('OPENTHREAD2') @@ -125,9 +116,7 @@ class Cert_8_2_01_JoinerRouter(unittest.TestCase): self.nodes[COMMISSIONER].get_masterkey(), ) - self.nodes[JOINER_ROUTER].add_whitelist( - self.nodes[JOINER].get_addr64() - ) + self.nodes[JOINER_ROUTER].add_whitelist(self.nodes[JOINER].get_addr64()) self.nodes[JOINER].thread_start() self.simulator.go(5) diff --git a/tests/scripts/thread-cert/Cert_8_2_02_JoinerRouter.py b/tests/scripts/thread-cert/Cert_8_2_02_JoinerRouter.py index e3e7354c0..7b042504f 100755 --- a/tests/scripts/thread-cert/Cert_8_2_02_JoinerRouter.py +++ b/tests/scripts/thread-cert/Cert_8_2_02_JoinerRouter.py @@ -38,6 +38,7 @@ JOINER = 3 class Cert_8_2_02_JoinerRouter(unittest.TestCase): + def setUp(self): self.simulator = config.create_default_simulator() @@ -48,15 +49,13 @@ class Cert_8_2_02_JoinerRouter(unittest.TestCase): self.nodes[COMMISSIONER].set_panid(0xface) self.nodes[COMMISSIONER].set_mode('rsdn') self.nodes[COMMISSIONER].set_masterkey( - 'deadbeefdeadbeefdeadbeefdeadbeef' - ) + 'deadbeefdeadbeefdeadbeefdeadbeef') self.nodes[COMMISSIONER].enable_whitelist() self.nodes[COMMISSIONER].set_router_selection_jitter(1) self.nodes[JOINER_ROUTER].set_mode('rsdn') self.nodes[JOINER_ROUTER].set_masterkey( - '00112233445566778899aabbccddeeff' - ) + '00112233445566778899aabbccddeeff') self.nodes[JOINER_ROUTER].enable_whitelist() self.nodes[JOINER_ROUTER].set_router_selection_jitter(1) @@ -80,19 +79,15 @@ class Cert_8_2_02_JoinerRouter(unittest.TestCase): self.nodes[COMMISSIONER].commissioner_start() self.simulator.go(5) self.nodes[COMMISSIONER].commissioner_add_joiner( - self.nodes[JOINER_ROUTER].get_eui64(), 'OPENTHREAD' - ) + self.nodes[JOINER_ROUTER].get_eui64(), 'OPENTHREAD') self.nodes[COMMISSIONER].commissioner_add_joiner( - self.nodes[JOINER].get_eui64(), 'OPENTHREAD2' - ) + self.nodes[JOINER].get_eui64(), 'OPENTHREAD2') self.simulator.go(5) self.nodes[COMMISSIONER].add_whitelist( - self.nodes[JOINER_ROUTER].get_joiner_id() - ) + self.nodes[JOINER_ROUTER].get_joiner_id()) self.nodes[JOINER_ROUTER].add_whitelist( - self.nodes[COMMISSIONER].get_addr64() - ) + self.nodes[COMMISSIONER].get_addr64()) self.nodes[JOINER_ROUTER].interface_up() self.nodes[JOINER_ROUTER].joiner_start('OPENTHREAD') @@ -103,19 +98,15 @@ class Cert_8_2_02_JoinerRouter(unittest.TestCase): ) self.nodes[COMMISSIONER].add_whitelist( - self.nodes[JOINER_ROUTER].get_addr64() - ) + self.nodes[JOINER_ROUTER].get_addr64()) self.nodes[JOINER_ROUTER].thread_start() self.simulator.go(5) self.assertEqual(self.nodes[JOINER_ROUTER].get_state(), 'router') self.nodes[JOINER_ROUTER].add_whitelist( - self.nodes[JOINER].get_joiner_id() - ) - self.nodes[JOINER].add_whitelist( - self.nodes[JOINER_ROUTER].get_addr64() - ) + self.nodes[JOINER].get_joiner_id()) + self.nodes[JOINER].add_whitelist(self.nodes[JOINER_ROUTER].get_addr64()) self.nodes[JOINER].interface_up() self.nodes[JOINER].joiner_start('2DAERHTNEPO') diff --git a/tests/scripts/thread-cert/Cert_9_2_02_MGMTCommissionerSet.py b/tests/scripts/thread-cert/Cert_9_2_02_MGMTCommissionerSet.py index 1ab475025..1e5392936 100755 --- a/tests/scripts/thread-cert/Cert_9_2_02_MGMTCommissionerSet.py +++ b/tests/scripts/thread-cert/Cert_9_2_02_MGMTCommissionerSet.py @@ -41,6 +41,7 @@ LEADER = 2 class Cert_9_2_02_MGMTCommissionerSet(unittest.TestCase): + def setUp(self): self.simulator = config.create_default_simulator() @@ -88,15 +89,13 @@ class Cert_9_2_02_MGMTCommissionerSet(unittest.TestCase): leader_messages = self.simulator.get_messages_sent_by(LEADER) msg = leader_messages.next_coap_message('2.04', assert_enabled=True) commissioner_session_id_tlv = command.get_sub_tlv( - msg.coap.payload, mesh_cop.CommissionerSessionId - ) + msg.coap.payload, mesh_cop.CommissionerSessionId) # Step 2 - Harness instructs commissioner to send # MGMT_COMMISSIONER_SET.req to Leader steering_data_tlv = mesh_cop.SteeringData(bytes([0xff])) self.nodes[COMMISSIONER].commissioner_mgmtset_with_tlvs( - [steering_data_tlv] - ) + [steering_data_tlv]) self.simulator.go(5) # Step 3 - Leader responds to MGMT_COMMISSIONER_SET.req with @@ -105,19 +104,16 @@ class Cert_9_2_02_MGMTCommissionerSet(unittest.TestCase): msg = leader_messages.next_coap_message('2.04') # (mesh_cop.State(mesh_cop.MeshCopState.REJECT),) <- this a tuple, don't delete the comma command.check_coap_message( - msg, [mesh_cop.State(mesh_cop.MeshCopState.REJECT)] - ) + msg, [mesh_cop.State(mesh_cop.MeshCopState.REJECT)]) self.simulator.get_messages_sent_by(COMMISSIONER) # Skip LEAD_PET.req # Step 4 - Harness instructs commissioner to send # MGMT_COMMISSIONER_SET.req to Leader self.nodes[COMMISSIONER].commissioner_mgmtset_with_tlvs( - [steering_data_tlv, commissioner_session_id_tlv] - ) + [steering_data_tlv, commissioner_session_id_tlv]) self.simulator.go(5) commissioner_messages = self.simulator.get_messages_sent_by( - COMMISSIONER - ) + COMMISSIONER) msg = commissioner_messages.next_coap_message('0.02', uri_path='/c/cs') rloc = ip_address(self.nodes[LEADER].get_rloc()) leader_aloc = ip_address(self.nodes[LEADER].get_addr_leader_aloc()) @@ -131,8 +127,7 @@ class Cert_9_2_02_MGMTCommissionerSet(unittest.TestCase): leader_messages = self.simulator.get_messages_sent_by(LEADER) msg = leader_messages.next_coap_message('2.04') command.check_coap_message( - msg, [mesh_cop.State(mesh_cop.MeshCopState.ACCEPT)] - ) + msg, [mesh_cop.State(mesh_cop.MeshCopState.ACCEPT)]) # Step 6 - Leader sends a multicast MLE Data Response msg = leader_messages.next_mle_message(mle.CommandType.DATA_RESPONSE) @@ -146,16 +141,14 @@ class Cert_9_2_02_MGMTCommissionerSet(unittest.TestCase): mesh_cop.SteeringData, mesh_cop.BorderAgentLocator, ], - ) - ), + )), ) # Step 7 - Harness instructs commissioner to send # MGMT_COMMISSIONER_SET.req to Leader border_agent_locator_tlv = mesh_cop.BorderAgentLocator(0x0400) self.nodes[COMMISSIONER].commissioner_mgmtset_with_tlvs( - [commissioner_session_id_tlv, border_agent_locator_tlv] - ) + [commissioner_session_id_tlv, border_agent_locator_tlv]) self.simulator.go(5) # Step 8 - Leader responds to MGMT_COMMISSIONER_SET.req with @@ -163,18 +156,15 @@ class Cert_9_2_02_MGMTCommissionerSet(unittest.TestCase): leader_messages = self.simulator.get_messages_sent_by(LEADER) msg = leader_messages.next_coap_message('2.04') command.check_coap_message( - msg, [mesh_cop.State(mesh_cop.MeshCopState.REJECT)] - ) + msg, [mesh_cop.State(mesh_cop.MeshCopState.REJECT)]) # Step 9 - Harness instructs commissioner to send # MGMT_COMMISSIONER_SET.req to Leader - self.nodes[COMMISSIONER].commissioner_mgmtset_with_tlvs( - [ - steering_data_tlv, - commissioner_session_id_tlv, - border_agent_locator_tlv, - ] - ) + self.nodes[COMMISSIONER].commissioner_mgmtset_with_tlvs([ + steering_data_tlv, + commissioner_session_id_tlv, + border_agent_locator_tlv, + ]) self.simulator.go(5) # Step 10 - Leader responds to MGMT_COMMISSIONER_SET.req with @@ -182,14 +172,12 @@ class Cert_9_2_02_MGMTCommissionerSet(unittest.TestCase): leader_messages = self.simulator.get_messages_sent_by(LEADER) msg = leader_messages.next_coap_message('2.04') command.check_coap_message( - msg, [mesh_cop.State(mesh_cop.MeshCopState.REJECT)] - ) + msg, [mesh_cop.State(mesh_cop.MeshCopState.REJECT)]) # Step 11 - Harness instructs commissioner to send # MGMT_COMMISSIONER_SET.req to Leader self.nodes[COMMISSIONER].commissioner_mgmtset_with_tlvs( - [mesh_cop.CommissionerSessionId(0xffff), steering_data_tlv] - ) + [mesh_cop.CommissionerSessionId(0xffff), steering_data_tlv]) self.simulator.go(5) # Step 12 - Leader responds to MGMT_COMMISSIONER_SET.req with @@ -197,18 +185,15 @@ class Cert_9_2_02_MGMTCommissionerSet(unittest.TestCase): leader_messages = self.simulator.get_messages_sent_by(LEADER) msg = leader_messages.next_coap_message('2.04') command.check_coap_message( - msg, [mesh_cop.State(mesh_cop.MeshCopState.REJECT)] - ) + msg, [mesh_cop.State(mesh_cop.MeshCopState.REJECT)]) # Step 13 - Harness instructs commissioner to send # MGMT_COMMISSIONER_SET.req to Leader - self.nodes[COMMISSIONER].commissioner_mgmtset_with_tlvs( - [ - commissioner_session_id_tlv, - steering_data_tlv, - mesh_cop.Channel(0x0, 0x0), - ] - ) + self.nodes[COMMISSIONER].commissioner_mgmtset_with_tlvs([ + commissioner_session_id_tlv, + steering_data_tlv, + mesh_cop.Channel(0x0, 0x0), + ]) self.simulator.go(5) # Step 14 - Leader responds to MGMT_COMMISSIONER_SET.req with @@ -216,8 +201,7 @@ class Cert_9_2_02_MGMTCommissionerSet(unittest.TestCase): leader_messages = self.simulator.get_messages_sent_by(LEADER) msg = leader_messages.next_coap_message('2.04') command.check_coap_message( - msg, [mesh_cop.State(mesh_cop.MeshCopState.ACCEPT)] - ) + msg, [mesh_cop.State(mesh_cop.MeshCopState.ACCEPT)]) # Step 15 - Send ICMPv6 Echo Request to Leader leader_rloc = self.nodes[LEADER].get_rloc() diff --git a/tests/scripts/thread-cert/Cert_9_2_04_ActiveDataset.py b/tests/scripts/thread-cert/Cert_9_2_04_ActiveDataset.py index 1351e533e..b1aa5936d 100755 --- a/tests/scripts/thread-cert/Cert_9_2_04_ActiveDataset.py +++ b/tests/scripts/thread-cert/Cert_9_2_04_ActiveDataset.py @@ -37,6 +37,7 @@ LEADER = 2 class Cert_9_2_04_ActiveDataset(unittest.TestCase): + def setUp(self): self.simulator = config.create_default_simulator() @@ -45,14 +46,12 @@ class Cert_9_2_04_ActiveDataset(unittest.TestCase): self.nodes[i] = node.Node(i, simulator=self.simulator) self.nodes[COMMISSIONER].set_active_dataset( - 10, panid=0xface, master_key='000102030405060708090a0b0c0d0e0f' - ) + 10, panid=0xface, master_key='000102030405060708090a0b0c0d0e0f') self.nodes[COMMISSIONER].set_mode('rsdn') self.nodes[COMMISSIONER].set_router_selection_jitter(1) self.nodes[LEADER].set_active_dataset( - 10, panid=0xface, master_key='000102030405060708090a0b0c0d0e0f' - ) + 10, panid=0xface, master_key='000102030405060708090a0b0c0d0e0f') self.nodes[LEADER].set_mode('rsdn') self.nodes[LEADER].set_router_selection_jitter(1) diff --git a/tests/scripts/thread-cert/Cert_9_2_07_DelayTimer.py b/tests/scripts/thread-cert/Cert_9_2_07_DelayTimer.py index 585d11316..8c6e074eb 100755 --- a/tests/scripts/thread-cert/Cert_9_2_07_DelayTimer.py +++ b/tests/scripts/thread-cert/Cert_9_2_07_DelayTimer.py @@ -48,6 +48,7 @@ COMMISSIONER_PENDING_PANID = 0xafce class Cert_9_2_7_DelayTimer(unittest.TestCase): + def setUp(self): self.simulator = config.create_default_simulator() @@ -70,9 +71,8 @@ class Cert_9_2_7_DelayTimer(unittest.TestCase): self.nodes[LEADER].set_router_selection_jitter(1) self.nodes[ROUTER].set_active_dataset(ROUTER_ACTIVE_TIMESTAMP) - self.nodes[ROUTER].set_pending_dataset( - ROUTER_PENDING_TIMESTAMP, ROUTER_PENDING_ACTIVE_TIMESTAMP - ) + self.nodes[ROUTER].set_pending_dataset(ROUTER_PENDING_TIMESTAMP, + ROUTER_PENDING_ACTIVE_TIMESTAMP) self.nodes[ROUTER].set_mode('rsdn') self.nodes[ROUTER].set_panid(PANID_INIT) self.nodes[ROUTER].set_partition_id(0x1) @@ -122,26 +122,21 @@ class Cert_9_2_7_DelayTimer(unittest.TestCase): panid=COMMISSIONER_PENDING_PANID, ) self.simulator.go(40) - self.assertEqual( - self.nodes[LEADER].get_panid(), COMMISSIONER_PENDING_PANID - ) - self.assertEqual( - self.nodes[COMMISSIONER].get_panid(), COMMISSIONER_PENDING_PANID - ) - self.assertEqual( - self.nodes[ROUTER].get_panid(), COMMISSIONER_PENDING_PANID - ) + self.assertEqual(self.nodes[LEADER].get_panid(), + COMMISSIONER_PENDING_PANID) + self.assertEqual(self.nodes[COMMISSIONER].get_panid(), + COMMISSIONER_PENDING_PANID) + self.assertEqual(self.nodes[ROUTER].get_panid(), + COMMISSIONER_PENDING_PANID) - self.assertEqual( - self.nodes[LEADER].get_channel(), COMMISSIONER_PENDING_CHANNEL - ) + self.assertEqual(self.nodes[LEADER].get_channel(), + COMMISSIONER_PENDING_CHANNEL) self.assertEqual( self.nodes[COMMISSIONER].get_channel(), COMMISSIONER_PENDING_CHANNEL, ) - self.assertEqual( - self.nodes[ROUTER].get_channel(), COMMISSIONER_PENDING_CHANNEL - ) + self.assertEqual(self.nodes[ROUTER].get_channel(), + COMMISSIONER_PENDING_CHANNEL) ipaddrs = self.nodes[ROUTER].get_addrs() for ipaddr in ipaddrs: diff --git a/tests/scripts/thread-cert/Cert_9_2_08_PersistentDatasets.py b/tests/scripts/thread-cert/Cert_9_2_08_PersistentDatasets.py index b6b1b2a66..8af00765b 100755 --- a/tests/scripts/thread-cert/Cert_9_2_08_PersistentDatasets.py +++ b/tests/scripts/thread-cert/Cert_9_2_08_PersistentDatasets.py @@ -49,6 +49,7 @@ MTDS = [ED, SED] class Cert_9_2_8_PersistentDatasets(unittest.TestCase): + def setUp(self): self.simulator = config.create_default_simulator() @@ -56,17 +57,17 @@ class Cert_9_2_8_PersistentDatasets(unittest.TestCase): for i in range(1, 6): self.nodes[i] = node.Node(i, (i in MTDS), simulator=self.simulator) - self.nodes[COMMISSIONER].set_active_dataset( - LEADER_ACTIVE_TIMESTAMP, panid=PANID_INIT, channel=CHANNEL_INIT - ) + self.nodes[COMMISSIONER].set_active_dataset(LEADER_ACTIVE_TIMESTAMP, + panid=PANID_INIT, + channel=CHANNEL_INIT) self.nodes[COMMISSIONER].set_mode('rsdn') self.nodes[COMMISSIONER].add_whitelist(self.nodes[LEADER].get_addr64()) self.nodes[COMMISSIONER].enable_whitelist() self.nodes[COMMISSIONER].set_router_selection_jitter(1) - self.nodes[LEADER].set_active_dataset( - LEADER_ACTIVE_TIMESTAMP, panid=PANID_INIT, channel=CHANNEL_INIT - ) + self.nodes[LEADER].set_active_dataset(LEADER_ACTIVE_TIMESTAMP, + panid=PANID_INIT, + channel=CHANNEL_INIT) self.nodes[LEADER].set_mode('rsdn') self.nodes[LEADER].add_whitelist(self.nodes[COMMISSIONER].get_addr64()) self.nodes[LEADER].add_whitelist(self.nodes[ROUTER].get_addr64()) @@ -74,9 +75,9 @@ class Cert_9_2_8_PersistentDatasets(unittest.TestCase): self.nodes[LEADER].add_whitelist(self.nodes[SED].get_addr64()) self.nodes[LEADER].enable_whitelist() - self.nodes[ROUTER].set_active_dataset( - LEADER_ACTIVE_TIMESTAMP, panid=PANID_INIT, channel=CHANNEL_INIT - ) + self.nodes[ROUTER].set_active_dataset(LEADER_ACTIVE_TIMESTAMP, + panid=PANID_INIT, + channel=CHANNEL_INIT) self.nodes[ROUTER].set_mode('rsdn') self._setUpRouter() @@ -149,16 +150,13 @@ class Cert_9_2_8_PersistentDatasets(unittest.TestCase): self.simulator.go(60) - self.assertEqual( - self.nodes[LEADER].get_panid(), COMMISSIONER_PENDING_PANID - ) - self.assertEqual( - self.nodes[COMMISSIONER].get_panid(), COMMISSIONER_PENDING_PANID - ) + self.assertEqual(self.nodes[LEADER].get_panid(), + COMMISSIONER_PENDING_PANID) + self.assertEqual(self.nodes[COMMISSIONER].get_panid(), + COMMISSIONER_PENDING_PANID) - self.assertEqual( - self.nodes[LEADER].get_channel(), COMMISSIONER_PENDING_CHANNEL - ) + self.assertEqual(self.nodes[LEADER].get_channel(), + COMMISSIONER_PENDING_CHANNEL) self.assertEqual( self.nodes[COMMISSIONER].get_channel(), COMMISSIONER_PENDING_CHANNEL, @@ -186,25 +184,18 @@ class Cert_9_2_8_PersistentDatasets(unittest.TestCase): self.simulator.go(10) - self.assertEqual( - self.nodes[ROUTER].get_panid(), COMMISSIONER_PENDING_PANID - ) - self.assertEqual( - self.nodes[ED].get_panid(), COMMISSIONER_PENDING_PANID - ) - self.assertEqual( - self.nodes[SED].get_panid(), COMMISSIONER_PENDING_PANID - ) + self.assertEqual(self.nodes[ROUTER].get_panid(), + COMMISSIONER_PENDING_PANID) + self.assertEqual(self.nodes[ED].get_panid(), COMMISSIONER_PENDING_PANID) + self.assertEqual(self.nodes[SED].get_panid(), + COMMISSIONER_PENDING_PANID) - self.assertEqual( - self.nodes[ROUTER].get_channel(), COMMISSIONER_PENDING_CHANNEL - ) - self.assertEqual( - self.nodes[ED].get_channel(), COMMISSIONER_PENDING_CHANNEL - ) - self.assertEqual( - self.nodes[SED].get_channel(), COMMISSIONER_PENDING_CHANNEL - ) + self.assertEqual(self.nodes[ROUTER].get_channel(), + COMMISSIONER_PENDING_CHANNEL) + self.assertEqual(self.nodes[ED].get_channel(), + COMMISSIONER_PENDING_CHANNEL) + self.assertEqual(self.nodes[SED].get_channel(), + COMMISSIONER_PENDING_CHANNEL) self.simulator.go(5) diff --git a/tests/scripts/thread-cert/Cert_9_2_09_PendingPartition.py b/tests/scripts/thread-cert/Cert_9_2_09_PendingPartition.py index 53db38a39..60a1e0c3b 100755 --- a/tests/scripts/thread-cert/Cert_9_2_09_PendingPartition.py +++ b/tests/scripts/thread-cert/Cert_9_2_09_PendingPartition.py @@ -45,6 +45,7 @@ ROUTER2 = 4 class Cert_9_2_09_PendingPartition(unittest.TestCase): + def setUp(self): self.simulator = config.create_default_simulator() @@ -52,17 +53,17 @@ class Cert_9_2_09_PendingPartition(unittest.TestCase): for i in range(1, 5): self.nodes[i] = node.Node(i, simulator=self.simulator) - self.nodes[COMMISSIONER].set_active_dataset( - 10, channel=CHANNEL_INIT, panid=PANID_INIT - ) + self.nodes[COMMISSIONER].set_active_dataset(10, + channel=CHANNEL_INIT, + panid=PANID_INIT) self.nodes[COMMISSIONER].set_mode('rsdn') self.nodes[COMMISSIONER].add_whitelist(self.nodes[LEADER].get_addr64()) self.nodes[COMMISSIONER].enable_whitelist() self.nodes[COMMISSIONER].set_router_selection_jitter(1) - self.nodes[LEADER].set_active_dataset( - 10, channel=CHANNEL_INIT, panid=PANID_INIT - ) + self.nodes[LEADER].set_active_dataset(10, + channel=CHANNEL_INIT, + panid=PANID_INIT) self.nodes[LEADER].set_mode('rsdn') self.nodes[LEADER].set_partition_id(0xffffffff) self.nodes[LEADER].add_whitelist(self.nodes[COMMISSIONER].get_addr64()) @@ -70,18 +71,18 @@ class Cert_9_2_09_PendingPartition(unittest.TestCase): self.nodes[LEADER].enable_whitelist() self.nodes[LEADER].set_router_selection_jitter(1) - self.nodes[ROUTER1].set_active_dataset( - 10, channel=CHANNEL_INIT, panid=PANID_INIT - ) + self.nodes[ROUTER1].set_active_dataset(10, + channel=CHANNEL_INIT, + panid=PANID_INIT) self.nodes[ROUTER1].set_mode('rsdn') self.nodes[ROUTER1].add_whitelist(self.nodes[LEADER].get_addr64()) self.nodes[ROUTER1].add_whitelist(self.nodes[ROUTER2].get_addr64()) self.nodes[ROUTER1].enable_whitelist() self.nodes[ROUTER1].set_router_selection_jitter(1) - self.nodes[ROUTER2].set_active_dataset( - 10, channel=CHANNEL_INIT, panid=PANID_INIT - ) + self.nodes[ROUTER2].set_active_dataset(10, + channel=CHANNEL_INIT, + panid=PANID_INIT) self.nodes[ROUTER2].set_mode('rsdn') self.nodes[ROUTER2].add_whitelist(self.nodes[ROUTER1].get_addr64()) self.nodes[ROUTER2].enable_whitelist() diff --git a/tests/scripts/thread-cert/Cert_9_2_10_PendingPartition.py b/tests/scripts/thread-cert/Cert_9_2_10_PendingPartition.py index 42ed0f7ef..379a81cdd 100755 --- a/tests/scripts/thread-cert/Cert_9_2_10_PendingPartition.py +++ b/tests/scripts/thread-cert/Cert_9_2_10_PendingPartition.py @@ -48,6 +48,7 @@ MTDS = [ED1, SED1] class Cert_9_2_10_PendingPartition(unittest.TestCase): + def setUp(self): self.simulator = config.create_default_simulator() @@ -55,17 +56,17 @@ class Cert_9_2_10_PendingPartition(unittest.TestCase): for i in range(1, 6): self.nodes[i] = node.Node(i, (i in MTDS), simulator=self.simulator) - self.nodes[COMMISSIONER].set_active_dataset( - 15, channel=CHANNEL_INIT, panid=PANID_INIT - ) + self.nodes[COMMISSIONER].set_active_dataset(15, + channel=CHANNEL_INIT, + panid=PANID_INIT) self.nodes[COMMISSIONER].set_mode('rsdn') self.nodes[COMMISSIONER].add_whitelist(self.nodes[LEADER].get_addr64()) self.nodes[COMMISSIONER].enable_whitelist() self.nodes[COMMISSIONER].set_router_selection_jitter(1) - self.nodes[LEADER].set_active_dataset( - 15, channel=CHANNEL_INIT, panid=PANID_INIT - ) + self.nodes[LEADER].set_active_dataset(15, + channel=CHANNEL_INIT, + panid=PANID_INIT) self.nodes[LEADER].set_mode('rsdn') self.nodes[LEADER].set_partition_id(0xffffffff) self.nodes[LEADER].add_whitelist(self.nodes[COMMISSIONER].get_addr64()) @@ -73,9 +74,9 @@ class Cert_9_2_10_PendingPartition(unittest.TestCase): self.nodes[LEADER].enable_whitelist() self.nodes[LEADER].set_router_selection_jitter(1) - self.nodes[ROUTER1].set_active_dataset( - 15, channel=CHANNEL_INIT, panid=PANID_INIT - ) + self.nodes[ROUTER1].set_active_dataset(15, + channel=CHANNEL_INIT, + panid=PANID_INIT) self.nodes[ROUTER1].set_mode('rsdn') self.nodes[ROUTER1].add_whitelist(self.nodes[LEADER].get_addr64()) self.nodes[ROUTER1].add_whitelist(self.nodes[ED1].get_addr64()) diff --git a/tests/scripts/thread-cert/Cert_9_2_11_MasterKey.py b/tests/scripts/thread-cert/Cert_9_2_11_MasterKey.py index 1947990e8..0a02440cd 100755 --- a/tests/scripts/thread-cert/Cert_9_2_11_MasterKey.py +++ b/tests/scripts/thread-cert/Cert_9_2_11_MasterKey.py @@ -48,6 +48,7 @@ MTDS = [ED1, SED1] class Cert_9_2_11_MasterKey(unittest.TestCase): + def setUp(self): self.simulator = config.create_default_simulator() @@ -55,26 +56,29 @@ class Cert_9_2_11_MasterKey(unittest.TestCase): for i in range(1, 6): self.nodes[i] = node.Node(i, (i in MTDS), simulator=self.simulator) - self.nodes[COMMISSIONER].set_active_dataset( - 10, channel=CHANNEL_INIT, panid=PANID_INIT, master_key=KEY1 - ) + self.nodes[COMMISSIONER].set_active_dataset(10, + channel=CHANNEL_INIT, + panid=PANID_INIT, + master_key=KEY1) self.nodes[COMMISSIONER].set_mode('rsdn') self.nodes[COMMISSIONER].add_whitelist(self.nodes[LEADER].get_addr64()) self.nodes[COMMISSIONER].enable_whitelist() self.nodes[COMMISSIONER].set_router_selection_jitter(1) - self.nodes[LEADER].set_active_dataset( - 10, channel=CHANNEL_INIT, panid=PANID_INIT, master_key=KEY1 - ) + self.nodes[LEADER].set_active_dataset(10, + channel=CHANNEL_INIT, + panid=PANID_INIT, + master_key=KEY1) self.nodes[LEADER].set_mode('rsdn') self.nodes[LEADER].add_whitelist(self.nodes[COMMISSIONER].get_addr64()) self.nodes[LEADER].add_whitelist(self.nodes[ROUTER1].get_addr64()) self.nodes[LEADER].enable_whitelist() self.nodes[LEADER].set_router_selection_jitter(1) - self.nodes[ROUTER1].set_active_dataset( - 10, channel=CHANNEL_INIT, panid=PANID_INIT, master_key=KEY1 - ) + self.nodes[ROUTER1].set_active_dataset(10, + channel=CHANNEL_INIT, + panid=PANID_INIT, + master_key=KEY1) self.nodes[ROUTER1].set_mode('rsdn') self.nodes[ROUTER1].add_whitelist(self.nodes[LEADER].get_addr64()) self.nodes[ROUTER1].add_whitelist(self.nodes[ED1].get_addr64()) diff --git a/tests/scripts/thread-cert/Cert_9_2_12_Announce.py b/tests/scripts/thread-cert/Cert_9_2_12_Announce.py index 4f6485de7..935b44250 100755 --- a/tests/scripts/thread-cert/Cert_9_2_12_Announce.py +++ b/tests/scripts/thread-cert/Cert_9_2_12_Announce.py @@ -48,6 +48,7 @@ DATASET2_PANID = 0xafce class Cert_9_2_12_Announce(unittest.TestCase): + def setUp(self): self.simulator = config.create_default_simulator() @@ -55,34 +56,34 @@ class Cert_9_2_12_Announce(unittest.TestCase): for i in range(1, 6): self.nodes[i] = node.Node(i, (i == MED), simulator=self.simulator) - self.nodes[LEADER1].set_active_dataset( - DATASET1_TIMESTAMP, channel=DATASET1_CHANNEL, panid=DATASET1_PANID - ) + self.nodes[LEADER1].set_active_dataset(DATASET1_TIMESTAMP, + channel=DATASET1_CHANNEL, + panid=DATASET1_PANID) self.nodes[LEADER1].set_mode('rsdn') self.nodes[LEADER1].add_whitelist(self.nodes[ROUTER1].get_addr64()) self.nodes[LEADER1].enable_whitelist() - self.nodes[ROUTER1].set_active_dataset( - DATASET1_TIMESTAMP, channel=DATASET1_CHANNEL, panid=DATASET1_PANID - ) + self.nodes[ROUTER1].set_active_dataset(DATASET1_TIMESTAMP, + channel=DATASET1_CHANNEL, + panid=DATASET1_PANID) self.nodes[ROUTER1].set_mode('rsdn') self.nodes[ROUTER1].add_whitelist(self.nodes[LEADER1].get_addr64()) self.nodes[ROUTER1].add_whitelist(self.nodes[LEADER2].get_addr64()) self.nodes[ROUTER1].enable_whitelist() self.nodes[ROUTER1].set_router_selection_jitter(1) - self.nodes[LEADER2].set_active_dataset( - DATASET2_TIMESTAMP, channel=DATASET2_CHANNEL, panid=DATASET2_PANID - ) + self.nodes[LEADER2].set_active_dataset(DATASET2_TIMESTAMP, + channel=DATASET2_CHANNEL, + panid=DATASET2_PANID) self.nodes[LEADER2].set_mode('rsdn') self.nodes[LEADER2].add_whitelist(self.nodes[ROUTER1].get_addr64()) self.nodes[LEADER2].add_whitelist(self.nodes[ROUTER2].get_addr64()) self.nodes[LEADER2].enable_whitelist() self.nodes[LEADER2].set_router_selection_jitter(1) - self.nodes[ROUTER2].set_active_dataset( - DATASET2_TIMESTAMP, channel=DATASET2_CHANNEL, panid=DATASET2_PANID - ) + self.nodes[ROUTER2].set_active_dataset(DATASET2_TIMESTAMP, + channel=DATASET2_CHANNEL, + panid=DATASET2_PANID) self.nodes[ROUTER2].set_mode('rsdn') self.nodes[ROUTER2].add_whitelist(self.nodes[LEADER2].get_addr64()) self.nodes[ROUTER2].add_whitelist(self.nodes[MED].get_addr64()) diff --git a/tests/scripts/thread-cert/Cert_9_2_13_EnergyScan.py b/tests/scripts/thread-cert/Cert_9_2_13_EnergyScan.py index 8fe47a8ef..9a270e9af 100755 --- a/tests/scripts/thread-cert/Cert_9_2_13_EnergyScan.py +++ b/tests/scripts/thread-cert/Cert_9_2_13_EnergyScan.py @@ -39,6 +39,7 @@ ED1 = 4 class Cert_9_2_13_EnergyScan(unittest.TestCase): + def setUp(self): self.simulator = config.create_default_simulator() @@ -101,9 +102,7 @@ class Cert_9_2_13_EnergyScan(unittest.TestCase): break self.assertTrue(self.nodes[COMMISSIONER].ping(ipaddr)) - self.nodes[COMMISSIONER].energy_scan( - 0x50000, 0x02, 0x20, 0x3E8, ipaddr - ) + self.nodes[COMMISSIONER].energy_scan(0x50000, 0x02, 0x20, 0x3E8, ipaddr) ipaddrs = self.nodes[ED1].get_addrs() for ipaddr in ipaddrs: @@ -111,13 +110,10 @@ class Cert_9_2_13_EnergyScan(unittest.TestCase): break self.assertTrue(self.nodes[COMMISSIONER].ping(ipaddr)) - self.nodes[COMMISSIONER].energy_scan( - 0x50000, 0x02, 0x20, 0x3E8, ipaddr - ) + self.nodes[COMMISSIONER].energy_scan(0x50000, 0x02, 0x20, 0x3E8, ipaddr) - self.nodes[COMMISSIONER].energy_scan( - 0x50000, 0x02, 0x20, 0x3E8, 'ff33:0040:fdde:ad00:beef:0:0:1' - ) + self.nodes[COMMISSIONER].energy_scan(0x50000, 0x02, 0x20, 0x3E8, + 'ff33:0040:fdde:ad00:beef:0:0:1') self.assertTrue(self.nodes[COMMISSIONER].ping(ipaddr)) diff --git a/tests/scripts/thread-cert/Cert_9_2_14_PanIdQuery.py b/tests/scripts/thread-cert/Cert_9_2_14_PanIdQuery.py index 3cda81422..507f86562 100755 --- a/tests/scripts/thread-cert/Cert_9_2_14_PanIdQuery.py +++ b/tests/scripts/thread-cert/Cert_9_2_14_PanIdQuery.py @@ -39,6 +39,7 @@ LEADER2 = 4 class Cert_9_2_14_PanIdQuery(unittest.TestCase): + def setUp(self): self.simulator = config.create_default_simulator() @@ -48,17 +49,13 @@ class Cert_9_2_14_PanIdQuery(unittest.TestCase): self.nodes[COMMISSIONER].set_panid(0xface) self.nodes[COMMISSIONER].set_mode('rsdn') - self.nodes[COMMISSIONER].add_whitelist( - self.nodes[LEADER1].get_addr64() - ) + self.nodes[COMMISSIONER].add_whitelist(self.nodes[LEADER1].get_addr64()) self.nodes[COMMISSIONER].enable_whitelist() self.nodes[COMMISSIONER].set_router_selection_jitter(1) self.nodes[LEADER1].set_panid(0xface) self.nodes[LEADER1].set_mode('rsdn') - self.nodes[LEADER1].add_whitelist( - self.nodes[COMMISSIONER].get_addr64() - ) + self.nodes[LEADER1].add_whitelist(self.nodes[COMMISSIONER].get_addr64()) self.nodes[LEADER1].add_whitelist(self.nodes[ROUTER1].get_addr64()) self.nodes[LEADER1].enable_whitelist() @@ -106,9 +103,8 @@ class Cert_9_2_14_PanIdQuery(unittest.TestCase): self.nodes[COMMISSIONER].panid_query(0xdead, 0xffffffff, ipaddr) - self.nodes[COMMISSIONER].panid_query( - 0xdead, 0xffffffff, 'ff33:0040:fdde:ad00:beef:0:0:1' - ) + self.nodes[COMMISSIONER].panid_query(0xdead, 0xffffffff, + 'ff33:0040:fdde:ad00:beef:0:0:1') self.assertTrue(self.nodes[COMMISSIONER].ping(ipaddr)) diff --git a/tests/scripts/thread-cert/Cert_9_2_15_PendingPartition.py b/tests/scripts/thread-cert/Cert_9_2_15_PendingPartition.py index 03c9b9935..063a69694 100755 --- a/tests/scripts/thread-cert/Cert_9_2_15_PendingPartition.py +++ b/tests/scripts/thread-cert/Cert_9_2_15_PendingPartition.py @@ -44,6 +44,7 @@ ROUTER2 = 4 class Cert_9_2_15_PendingPartition(unittest.TestCase): + def setUp(self): self.simulator = config.create_default_simulator() @@ -51,17 +52,17 @@ class Cert_9_2_15_PendingPartition(unittest.TestCase): for i in range(1, 5): self.nodes[i] = node.Node(i, simulator=self.simulator) - self.nodes[COMMISSIONER].set_active_dataset( - 15, channel=CHANNEL_INIT, panid=PANID_INIT - ) + self.nodes[COMMISSIONER].set_active_dataset(15, + channel=CHANNEL_INIT, + panid=PANID_INIT) self.nodes[COMMISSIONER].set_mode('rsdn') self.nodes[COMMISSIONER].add_whitelist(self.nodes[LEADER].get_addr64()) self.nodes[COMMISSIONER].enable_whitelist() self.nodes[COMMISSIONER].set_router_selection_jitter(1) - self.nodes[LEADER].set_active_dataset( - 15, channel=CHANNEL_INIT, panid=PANID_INIT - ) + self.nodes[LEADER].set_active_dataset(15, + channel=CHANNEL_INIT, + panid=PANID_INIT) self.nodes[LEADER].set_mode('rsdn') self.nodes[LEADER].set_partition_id(0xffffffff) self.nodes[LEADER].add_whitelist(self.nodes[COMMISSIONER].get_addr64()) @@ -69,18 +70,18 @@ class Cert_9_2_15_PendingPartition(unittest.TestCase): self.nodes[LEADER].enable_whitelist() self.nodes[LEADER].set_router_selection_jitter(1) - self.nodes[ROUTER1].set_active_dataset( - 15, channel=CHANNEL_INIT, panid=PANID_INIT - ) + self.nodes[ROUTER1].set_active_dataset(15, + channel=CHANNEL_INIT, + panid=PANID_INIT) self.nodes[ROUTER1].set_mode('rsdn') self.nodes[ROUTER1].add_whitelist(self.nodes[LEADER].get_addr64()) self.nodes[ROUTER1].add_whitelist(self.nodes[ROUTER2].get_addr64()) self.nodes[ROUTER1].enable_whitelist() self.nodes[ROUTER1].set_router_selection_jitter(1) - self.nodes[ROUTER2].set_active_dataset( - 15, channel=CHANNEL_INIT, panid=PANID_INIT - ) + self.nodes[ROUTER2].set_active_dataset(15, + channel=CHANNEL_INIT, + panid=PANID_INIT) self.nodes[ROUTER2].set_mode('rsdn') self._setUpRouter2() diff --git a/tests/scripts/thread-cert/Cert_9_2_16_ActivePendingPartition.py b/tests/scripts/thread-cert/Cert_9_2_16_ActivePendingPartition.py index 725928a4f..05abade5c 100755 --- a/tests/scripts/thread-cert/Cert_9_2_16_ActivePendingPartition.py +++ b/tests/scripts/thread-cert/Cert_9_2_16_ActivePendingPartition.py @@ -45,6 +45,7 @@ ROUTER2 = 4 class Cert_9_2_16_ActivePendingPartition(unittest.TestCase): + def setUp(self): self.simulator = config.create_default_simulator() @@ -52,17 +53,17 @@ class Cert_9_2_16_ActivePendingPartition(unittest.TestCase): for i in range(1, 5): self.nodes[i] = node.Node(i, simulator=self.simulator) - self.nodes[COMMISSIONER].set_active_dataset( - 1, channel=CHANNEL_INIT, panid=PANID_INIT - ) + self.nodes[COMMISSIONER].set_active_dataset(1, + channel=CHANNEL_INIT, + panid=PANID_INIT) self.nodes[COMMISSIONER].set_mode('rsdn') self.nodes[COMMISSIONER].add_whitelist(self.nodes[LEADER].get_addr64()) self.nodes[COMMISSIONER].enable_whitelist() self.nodes[COMMISSIONER].set_router_selection_jitter(1) - self.nodes[LEADER].set_active_dataset( - 1, channel=CHANNEL_INIT, panid=PANID_INIT - ) + self.nodes[LEADER].set_active_dataset(1, + channel=CHANNEL_INIT, + panid=PANID_INIT) self.nodes[LEADER].set_mode('rsdn') self.nodes[LEADER].set_partition_id(0xffffffff) self.nodes[LEADER].add_whitelist(self.nodes[COMMISSIONER].get_addr64()) @@ -70,18 +71,18 @@ class Cert_9_2_16_ActivePendingPartition(unittest.TestCase): self.nodes[LEADER].enable_whitelist() self.nodes[LEADER].set_router_selection_jitter(1) - self.nodes[ROUTER1].set_active_dataset( - 1, channel=CHANNEL_INIT, panid=PANID_INIT - ) + self.nodes[ROUTER1].set_active_dataset(1, + channel=CHANNEL_INIT, + panid=PANID_INIT) self.nodes[ROUTER1].set_mode('rsdn') self.nodes[ROUTER1].add_whitelist(self.nodes[LEADER].get_addr64()) self.nodes[ROUTER1].add_whitelist(self.nodes[ROUTER2].get_addr64()) self.nodes[ROUTER1].enable_whitelist() self.nodes[ROUTER1].set_router_selection_jitter(1) - self.nodes[ROUTER2].set_active_dataset( - 1, channel=CHANNEL_INIT, panid=PANID_INIT - ) + self.nodes[ROUTER2].set_active_dataset(1, + channel=CHANNEL_INIT, + panid=PANID_INIT) self.nodes[ROUTER2].set_mode('rsdn') self._setUpRouter2() @@ -135,27 +136,22 @@ class Cert_9_2_16_ActivePendingPartition(unittest.TestCase): ) self.simulator.go(5) - self.nodes[COMMISSIONER].send_mgmt_active_set( - active_timestamp=15, network_name='threadCert' - ) + self.nodes[COMMISSIONER].send_mgmt_active_set(active_timestamp=15, + network_name='threadCert') self.simulator.go(100) self.nodes[ROUTER2].start() self.simulator.go(5) self.assertEqual(self.nodes[ROUTER2].get_state(), 'router') - self.assertEqual( - self.nodes[COMMISSIONER].get_network_name(), NETWORK_NAME_FINAL - ) - self.assertEqual( - self.nodes[LEADER].get_network_name(), NETWORK_NAME_FINAL - ) - self.assertEqual( - self.nodes[ROUTER1].get_network_name(), NETWORK_NAME_FINAL - ) - self.assertEqual( - self.nodes[ROUTER2].get_network_name(), NETWORK_NAME_FINAL - ) + self.assertEqual(self.nodes[COMMISSIONER].get_network_name(), + NETWORK_NAME_FINAL) + self.assertEqual(self.nodes[LEADER].get_network_name(), + NETWORK_NAME_FINAL) + self.assertEqual(self.nodes[ROUTER1].get_network_name(), + NETWORK_NAME_FINAL) + self.assertEqual(self.nodes[ROUTER2].get_network_name(), + NETWORK_NAME_FINAL) self.simulator.go(100) diff --git a/tests/scripts/thread-cert/Cert_9_2_17_Orphan.py b/tests/scripts/thread-cert/Cert_9_2_17_Orphan.py index 2e9cbed77..3285d1236 100755 --- a/tests/scripts/thread-cert/Cert_9_2_17_Orphan.py +++ b/tests/scripts/thread-cert/Cert_9_2_17_Orphan.py @@ -43,6 +43,7 @@ ED1 = 3 class Cert_9_2_17_Orphan(unittest.TestCase): + def setUp(self): self.simulator = config.create_default_simulator() @@ -50,17 +51,19 @@ class Cert_9_2_17_Orphan(unittest.TestCase): for i in range(1, 4): self.nodes[i] = node.Node(i, (i == ED1), simulator=self.simulator) - self.nodes[LEADER1].set_active_dataset( - 10, channel=CHANNEL1, panid=PANID_INIT, channel_mask=CHANNEL_MASK - ) + self.nodes[LEADER1].set_active_dataset(10, + channel=CHANNEL1, + panid=PANID_INIT, + channel_mask=CHANNEL_MASK) self.nodes[LEADER1].set_mode('rsdn') self.nodes[LEADER1].add_whitelist(self.nodes[ED1].get_addr64()) self.nodes[LEADER1].enable_whitelist() self.nodes[LEADER1].set_router_selection_jitter(1) - self.nodes[LEADER2].set_active_dataset( - 20, channel=CHANNEL2, panid=PANID_INIT, channel_mask=CHANNEL_MASK - ) + self.nodes[LEADER2].set_active_dataset(20, + channel=CHANNEL2, + panid=PANID_INIT, + channel_mask=CHANNEL_MASK) self.nodes[LEADER2].set_mode('rsdn') self.nodes[LEADER2].enable_whitelist() self.nodes[LEADER2].set_router_selection_jitter(1) diff --git a/tests/scripts/thread-cert/Cert_9_2_18_RollBackActiveTimestamp.py b/tests/scripts/thread-cert/Cert_9_2_18_RollBackActiveTimestamp.py index 3a8fc7db0..ca3728f8c 100755 --- a/tests/scripts/thread-cert/Cert_9_2_18_RollBackActiveTimestamp.py +++ b/tests/scripts/thread-cert/Cert_9_2_18_RollBackActiveTimestamp.py @@ -49,6 +49,7 @@ MTDS = [ED1, SED1] class Cert_9_2_18_RollBackActiveTimestamp(unittest.TestCase): + def setUp(self): self.simulator = config.create_default_simulator() @@ -56,17 +57,19 @@ class Cert_9_2_18_RollBackActiveTimestamp(unittest.TestCase): for i in range(1, 7): self.nodes[i] = node.Node(i, (i in MTDS), simulator=self.simulator) - self.nodes[COMMISSIONER].set_active_dataset( - 1, channel=CHANNEL_INIT, panid=PANID_INIT, master_key=KEY1 - ) + self.nodes[COMMISSIONER].set_active_dataset(1, + channel=CHANNEL_INIT, + panid=PANID_INIT, + master_key=KEY1) self.nodes[COMMISSIONER].set_mode('rsdn') self.nodes[COMMISSIONER].add_whitelist(self.nodes[LEADER].get_addr64()) self.nodes[COMMISSIONER].enable_whitelist() self.nodes[COMMISSIONER].set_router_selection_jitter(1) - self.nodes[LEADER].set_active_dataset( - 1, channel=CHANNEL_INIT, panid=PANID_INIT, master_key=KEY1 - ) + self.nodes[LEADER].set_active_dataset(1, + channel=CHANNEL_INIT, + panid=PANID_INIT, + master_key=KEY1) self.nodes[LEADER].set_mode('rsdn') self.nodes[LEADER].set_partition_id(0xffffffff) self.nodes[LEADER].add_whitelist(self.nodes[COMMISSIONER].get_addr64()) @@ -74,9 +77,10 @@ class Cert_9_2_18_RollBackActiveTimestamp(unittest.TestCase): self.nodes[LEADER].enable_whitelist() self.nodes[LEADER].set_router_selection_jitter(1) - self.nodes[ROUTER1].set_active_dataset( - 1, channel=CHANNEL_INIT, panid=PANID_INIT, master_key=KEY1 - ) + self.nodes[ROUTER1].set_active_dataset(1, + channel=CHANNEL_INIT, + panid=PANID_INIT, + master_key=KEY1) self.nodes[ROUTER1].set_mode('rsdn') self.nodes[ROUTER1].add_whitelist(self.nodes[LEADER].get_addr64()) self.nodes[ROUTER1].add_whitelist(self.nodes[ROUTER2].get_addr64()) @@ -85,9 +89,10 @@ class Cert_9_2_18_RollBackActiveTimestamp(unittest.TestCase): self.nodes[ROUTER1].enable_whitelist() self.nodes[ROUTER1].set_router_selection_jitter(1) - self.nodes[ROUTER2].set_active_dataset( - 1, channel=CHANNEL_INIT, panid=PANID_INIT, master_key=KEY1 - ) + self.nodes[ROUTER2].set_active_dataset(1, + channel=CHANNEL_INIT, + panid=PANID_INIT, + master_key=KEY1) self.nodes[ROUTER2].set_mode('rsdn') self.nodes[ROUTER2].add_whitelist(self.nodes[ROUTER1].get_addr64()) self.nodes[ROUTER2].enable_whitelist() @@ -136,9 +141,8 @@ class Cert_9_2_18_RollBackActiveTimestamp(unittest.TestCase): self.simulator.go(5) self.assertEqual(self.nodes[SED1].get_state(), 'child') - self.nodes[COMMISSIONER].send_mgmt_active_set( - active_timestamp=20000, network_name='GRL' - ) + self.nodes[COMMISSIONER].send_mgmt_active_set(active_timestamp=20000, + network_name='GRL') self.simulator.go(5) self.nodes[COMMISSIONER].send_mgmt_pending_set( diff --git a/tests/scripts/thread-cert/Test_Cli.py b/tests/scripts/thread-cert/Test_Cli.py index cfe688e3b..93f5b6ba6 100755 --- a/tests/scripts/thread-cert/Test_Cli.py +++ b/tests/scripts/thread-cert/Test_Cli.py @@ -35,6 +35,7 @@ LEADER = 1 class Cert_Cli(unittest.TestCase): + def setUp(self): self.nodes = {} self.nodes[LEADER] = node.Node(LEADER) diff --git a/tests/scripts/thread-cert/Test_MacScan.py b/tests/scripts/thread-cert/Test_MacScan.py index 04ccce37e..e0685c729 100755 --- a/tests/scripts/thread-cert/Test_MacScan.py +++ b/tests/scripts/thread-cert/Test_MacScan.py @@ -37,6 +37,7 @@ ROUTER = 2 class Test_MacScan(unittest.TestCase): + def setUp(self): self.nodes = {} for i in range(1, 3): diff --git a/tests/scripts/thread-cert/coap.py b/tests/scripts/thread-cert/coap.py index 68ec87180..8e684907a 100644 --- a/tests/scripts/thread-cert/coap.py +++ b/tests/scripts/thread-cert/coap.py @@ -61,7 +61,6 @@ class CoapOptionsTypes(IntEnum): class CoapOptionHeader(object): - """ Class representing CoAP optiona header. """ def __init__(self, delta, length): @@ -104,7 +103,6 @@ class CoapOptionHeader(object): class CoapOption(object): - """ Class representing CoAP option. """ def __init__(self, _type, value): @@ -120,13 +118,11 @@ class CoapOption(object): return self._value def __repr__(self): - return "CoapOption(type={}, value={})".format( - self.type, hexlify(self.value) - ) + return "CoapOption(type={}, value={})".format(self.type, + hexlify(self.value)) class CoapOptionsFactory(object): - """ Factory that produces CoAP options. """ def parse(self, data, message_info): @@ -148,7 +144,6 @@ class CoapOptionsFactory(object): class CoapCode(object): - """ Class representing CoAP code. """ def __init__(self, code): @@ -182,8 +177,7 @@ class CoapCode(object): @property def dotted(self): return ".".join( - ["{:01d}".format(self._class), "{:02d}".format(self.detail)] - ) + ["{:01d}".format(self._class), "{:02d}".format(self.detail)]) def __eq__(self, other): if isinstance(other, int): @@ -196,16 +190,14 @@ class CoapCode(object): return self.code == other.code else: - raise TypeError( - "Could not compare {} and {}".format(type(self), type(other)) - ) + raise TypeError("Could not compare {} and {}".format( + type(self), type(other))) def __repr__(self): return self.dotted class CoapMessage(object): - """ Class representing CoAP message. """ def __init__( @@ -266,21 +258,21 @@ class CoapMessage(object): def __repr__(self): options_str = ", ".join([repr(opt) for opt in self.options]) - return ("CoapMessage(version={}, type={}, code={}, message_id={}, token={}, options=[{}], payload={},", - "uri-path='{}')").format( - self.version, - CoapMessageType.name[self.type], - self.code, - self.message_id, - hexlify(self.token), - options_str, - self.payload, - self.uri_path, - ) + return ( + "CoapMessage(version={}, type={}, code={}, message_id={}, token={}, options=[{}], payload={},", + "uri-path='{}')").format( + self.version, + CoapMessageType.name[self.type], + self.code, + self.message_id, + hexlify(self.token), + options_str, + self.payload, + self.uri_path, + ) class CoapMessageProxy(object): - """ Proxy class of CoAP message. The main idea behind this class is to delay parsing payload. Due to architecture of the existing solution @@ -299,8 +291,7 @@ class CoapMessageProxy(object): self._message_info = message_info self._mid_to_uri_path_binder = mid_to_uri_path_binder self._uri_path_based_payload_factories = ( - uri_path_based_payload_factories - ) + uri_path_based_payload_factories) @property def version(self): @@ -334,14 +325,12 @@ class CoapMessageProxy(object): def payload(self): try: binded_uri_path = self._mid_to_uri_path_binder.get_uri_path_for( - self.message_id, self.token - ) + self.message_id, self.token) factory = self._uri_path_based_payload_factories[binded_uri_path] - return factory.parse( - io.BytesIO(self._coap_message.payload), self._message_info - ) + return factory.parse(io.BytesIO(self._coap_message.payload), + self._message_info) except RuntimeError: return self._coap_message.payload @@ -352,14 +341,21 @@ class CoapMessageProxy(object): def __repr__(self): options_str = ", ".join([repr(opt) for opt in self.options]) - return ("CoapMessageProxy(version={}, type={}, code={}, message_id={}, token={}, options=[{}], payload={},", - "uri-path='{}')").format( - self.version, self.type, self.code, self.message_id, hexlify(self.token), options_str, self.payload, - self.uri_path, ) + return ( + "CoapMessageProxy(version={}, type={}, code={}, message_id={}, token={}, options=[{}], payload={},", + "uri-path='{}')").format( + self.version, + self.type, + self.code, + self.message_id, + hexlify(self.token), + options_str, + self.payload, + self.uri_path, + ) class CoapMessageIdToUriPathBinder: - """ Class binds message id and token with URI path. """ def __init__(self): @@ -373,12 +369,11 @@ class CoapMessageIdToUriPathBinder: return self._uri_path_binds[message_id][hexlify(token)] except KeyError: raise RuntimeError( - "Could not find URI PATH for message_id: {} and token: {}".format( - message_id, hexlify(token))) + "Could not find URI PATH for message_id: {} and token: {}". + format(message_id, hexlify(token))) class CoapMessageFactory(object): - """ Factory that produces CoAP messages. """ def __init__( @@ -389,8 +384,7 @@ class CoapMessageFactory(object): ): self._options_factory = options_factory self._uri_path_based_payload_factories = ( - uri_path_based_payload_factories - ) + uri_path_based_payload_factories) self._mid_to_uri_path_binder = message_id_to_uri_path_binder def _uri_path_from(self, options): @@ -416,8 +410,7 @@ class CoapMessageFactory(object): def parse(self, data, message_info): version, _type, token_length = self._parse_initial_byte( - data, message_info - ) + data, message_info) code = CoapCode(ord(data.read(1))) message_id = struct.unpack(">H", data.read(2))[0] @@ -428,8 +421,7 @@ class CoapMessageFactory(object): uri_path = self._uri_path_from(options) if uri_path is not None: self._mid_to_uri_path_binder.add_uri_path_for( - message_id, token, uri_path - ) + message_id, token, uri_path) coap_message = CoapMessage( version, diff --git a/tests/scripts/thread-cert/command.py b/tests/scripts/thread-cert/command.py index bf32ad5c5..c3e8e2241 100644 --- a/tests/scripts/thread-cert/command.py +++ b/tests/scripts/thread-cert/command.py @@ -58,22 +58,19 @@ def check_address_query(command_msg, source_node, destination_address): source_rloc = source_node.get_ip6_address(config.ADDRESS_TYPE.RLOC) assert ( - ipv6.ip_address(source_rloc) - == command_msg.ipv6_packet.ipv6_header.source_address - ), ( - "Error: The IPv6 source address is not the RLOC of the originator. The source node's rloc is: " - + str(ipv6.ip_address(source_rloc)) - + ", but the source_address in command msg is: " - + str(command_msg.ipv6_packet.ipv6_header.source_address) - ) + ipv6.ip_address( + source_rloc) == command_msg.ipv6_packet.ipv6_header.source_address + ), ("Error: The IPv6 source address is not the RLOC of the originator. The source node's rloc is: " + + str(ipv6.ip_address(source_rloc)) + + ", but the source_address in command msg is: " + + str(command_msg.ipv6_packet.ipv6_header.source_address)) if isinstance(destination_address, bytearray): destination_address = bytes(destination_address) - assert ( - ipv6.ip_address(destination_address) - == command_msg.ipv6_packet.ipv6_header.destination_address - ), "Error: The IPv6 destination address is not expected." + assert (ipv6.ip_address(destination_address) == + command_msg.ipv6_packet.ipv6_header.destination_address + ), "Error: The IPv6 destination address is not expected." def check_address_notification(command_msg, source_node, destination_node): @@ -86,22 +83,20 @@ def check_address_notification(command_msg, source_node, destination_node): source_rloc = source_node.get_ip6_address(config.ADDRESS_TYPE.RLOC) assert ( - ipv6.ip_address(source_rloc) - == command_msg.ipv6_packet.ipv6_header.source_address + ipv6.ip_address( + source_rloc) == command_msg.ipv6_packet.ipv6_header.source_address ), "Error: The IPv6 source address is not the RLOC of the originator." destination_rloc = destination_node.get_ip6_address( - config.ADDRESS_TYPE.RLOC - ) + config.ADDRESS_TYPE.RLOC) assert ( - ipv6.ip_address(destination_rloc) - == command_msg.ipv6_packet.ipv6_header.destination_address + ipv6.ip_address(destination_rloc) == + command_msg.ipv6_packet.ipv6_header.destination_address ), "Error: The IPv6 destination address is not the RLOC of the destination." -def check_address_error_notification( - command_msg, source_node, destination_address -): +def check_address_error_notification(command_msg, source_node, + destination_address): """Verify source_node sent a properly formatted Address Error Notification command message to destination_address. """ command_msg.assertCoapMessageRequestUriPath('/a/ae') @@ -110,27 +105,23 @@ def check_address_error_notification( source_rloc = source_node.get_ip6_address(config.ADDRESS_TYPE.RLOC) assert ( - ipv6.ip_address(source_rloc) - == command_msg.ipv6_packet.ipv6_header.source_address - ), ( - "Error: The IPv6 source address is not the RLOC of the originator. The source node's rloc is: " - + str(ipv6.ip_address(source_rloc)) - + ", but the source_address in command msg is: " - + str(command_msg.ipv6_packet.ipv6_header.source_address) - ) + ipv6.ip_address( + source_rloc) == command_msg.ipv6_packet.ipv6_header.source_address + ), ("Error: The IPv6 source address is not the RLOC of the originator. The source node's rloc is: " + + str(ipv6.ip_address(source_rloc)) + + ", but the source_address in command msg is: " + + str(command_msg.ipv6_packet.ipv6_header.source_address)) if isinstance(destination_address, bytearray): destination_address = bytes(destination_address) assert ( - ipv6.ip_address(destination_address) - == command_msg.ipv6_packet.ipv6_header.destination_address - ), ( - "Error: The IPv6 destination address is not expected. The destination node's rloc is: " - + str(ipv6.ip_address(destination_address)) - + ", but the destination_address in command msg is: " - + str(command_msg.ipv6_packet.ipv6_header.destination_address) - ) + ipv6.ip_address(destination_address) == + command_msg.ipv6_packet.ipv6_header.destination_address + ), ("Error: The IPv6 destination address is not expected. The destination node's rloc is: " + + str(ipv6.ip_address(destination_address)) + + ", but the destination_address in command msg is: " + + str(command_msg.ipv6_packet.ipv6_header.destination_address)) def check_address_solicit(command_msg, was_router): @@ -151,12 +142,10 @@ def check_address_release(command_msg, destination_node): command_msg.assertCoapMessageContainsTlv(network_layer.MacExtendedAddress) destination_rloc = destination_node.get_ip6_address( - config.ADDRESS_TYPE.RLOC - ) - assert ( - ipv6.ip_address(destination_rloc) - == command_msg.ipv6_packet.ipv6_header.destination_address - ), "Error: The destination is not RLOC address" + config.ADDRESS_TYPE.RLOC) + assert (ipv6.ip_address(destination_rloc) == + command_msg.ipv6_packet.ipv6_header.destination_address + ), "Error: The destination is not RLOC address" def check_tlv_request_tlv(command_msg, check_type, tlv_id): @@ -165,14 +154,12 @@ def check_tlv_request_tlv(command_msg, check_type, tlv_id): tlv_request_tlv = command_msg.get_mle_message_tlv(mle.TlvRequest) if check_type == CheckType.CONTAIN: - assert ( - tlv_request_tlv is not None - ), "Error: The msg doesn't contain TLV Request TLV" + assert (tlv_request_tlv is + not None), "Error: The msg doesn't contain TLV Request TLV" assert any( tlv_id == tlv for tlv in tlv_request_tlv.tlvs ), "Error: The msg doesn't contain TLV Request TLV ID: {}".format( - tlv_id - ) + tlv_id) elif check_type == CheckType.NOT_CONTAIN: if tlv_request_tlv is not None: @@ -186,8 +173,7 @@ def check_tlv_request_tlv(command_msg, check_type, tlv_id): print("TLV Request TLV contains TLV ID: {}".format(tlv_id)) else: print( - "TLV Request TLV doesn't contain TLV ID: {}".format(tlv_id) - ) + "TLV Request TLV doesn't contain TLV ID: {}".format(tlv_id)) else: print("The msg doesn't contain TLV Request TLV") @@ -211,15 +197,11 @@ def check_link_request( check_mle_optional_tlv(command_msg, source_address, mle.SourceAddress) check_mle_optional_tlv(command_msg, leader_data, mle.LeaderData) - check_tlv_request_tlv( - command_msg, tlv_request_address16, mle.TlvType.ADDRESS16 - ) - check_tlv_request_tlv( - command_msg, tlv_request_route64, mle.TlvType.ROUTE64 - ) - check_tlv_request_tlv( - command_msg, tlv_request_link_margin, mle.TlvType.LINK_MARGIN - ) + check_tlv_request_tlv(command_msg, tlv_request_address16, + mle.TlvType.ADDRESS16) + check_tlv_request_tlv(command_msg, tlv_request_route64, mle.TlvType.ROUTE64) + check_tlv_request_tlv(command_msg, tlv_request_link_margin, + mle.TlvType.LINK_MARGIN) def check_link_accept( @@ -247,17 +229,14 @@ def check_link_accept( check_mle_optional_tlv(command_msg, address16, mle.Address16) check_mle_optional_tlv(command_msg, route64, mle.Route64) - check_tlv_request_tlv( - command_msg, tlv_request_link_margin, mle.TlvType.LINK_MARGIN - ) + check_tlv_request_tlv(command_msg, tlv_request_link_margin, + mle.TlvType.LINK_MARGIN) destination_link_local = destination_node.get_ip6_address( - config.ADDRESS_TYPE.LINK_LOCAL - ) + config.ADDRESS_TYPE.LINK_LOCAL) assert ( - ipv6.ip_address(destination_link_local) - == command_msg.ipv6_packet.ipv6_header.destination_address - ), "Error: The destination is unexpected" + ipv6.ip_address(destination_link_local) == command_msg.ipv6_packet. + ipv6_header.destination_address), "Error: The destination is unexpected" def check_icmp_path(sniffer, path, nodes, icmp_type=ipv6.ICMP_ECHO_REQUEST): @@ -273,9 +252,8 @@ def check_icmp_path(sniffer, path, nodes, icmp_type=ipv6.ICMP_ECHO_REQUEST): if i < len_path - 1: next_node = nodes[path[i + 1]] next_node_rloc16 = next_node.get_addr16() - assert ( - next_node_rloc16 == node_icmp_msg.mac_header.dest_address.rloc - ), "Error: The path is unexpected." + assert (next_node_rloc16 == node_icmp_msg.mac_header.dest_address. + rloc), "Error: The path is unexpected." else: return True @@ -327,8 +305,7 @@ def check_mle_optional_tlv(command_msg, type, tlv): def check_mle_advertisement(command_msg): command_msg.assertSentWithHopLimit(255) command_msg.assertSentToDestinationAddress( - config.LINK_LOCAL_ALL_NODES_ADDRESS - ) + config.LINK_LOCAL_ALL_NODES_ADDRESS) command_msg.assertMleMessageContainsTlv(mle.SourceAddress) command_msg.assertMleMessageContainsTlv(mle.LeaderData) command_msg.assertMleMessageContainsTlv(mle.Route64) @@ -344,8 +321,7 @@ def check_parent_request(command_msg, is_first_request): command_msg.assertSentWithHopLimit(255) command_msg.assertSentToDestinationAddress( - config.LINK_LOCAL_ALL_ROUTERS_ADDRESS - ) + config.LINK_LOCAL_ALL_ROUTERS_ADDRESS) command_msg.assertMleMessageContainsTlv(mle.Mode) command_msg.assertMleMessageContainsTlv(mle.Challenge) command_msg.assertMleMessageContainsTlv(mle.Version) @@ -398,21 +374,15 @@ def check_child_id_request( check_mle_optional_tlv(command_msg, tlv_request, mle.TlvRequest) check_mle_optional_tlv(command_msg, mle_frame_counter, mle.MleFrameCounter) - check_mle_optional_tlv( - command_msg, address_registration, mle.AddressRegistration - ) + 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, 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 - ) + 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( @@ -434,36 +404,29 @@ def check_child_id_response( check_mle_optional_tlv(command_msg, route64, mle.Route64) check_mle_optional_tlv(command_msg, network_data, mle.NetworkData) - check_mle_optional_tlv( - command_msg, address_registration, mle.AddressRegistration - ) + 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, active_operational_dataset, mle.ActiveOperationalDataset - ) - check_mle_optional_tlv( - command_msg, pending_operational_dataset, mle.PendingOperationalDataset - ) + check_mle_optional_tlv(command_msg, pending_timestamp, mle.PendingTimestamp) + check_mle_optional_tlv(command_msg, active_operational_dataset, + mle.ActiveOperationalDataset) + check_mle_optional_tlv(command_msg, pending_operational_dataset, + mle.PendingOperationalDataset) if network_data_check is not None: network_data_tlv = command_msg.assertMleMessageContainsTlv( - mle.NetworkData - ) + mle.NetworkData) network_data_check.check(network_data_tlv) def check_prefix(prefix): """Verify if a prefix contains 6loWPAN sub-TLV and border router sub-TLV """ + assert contains_tlv(prefix.sub_tlvs, network_data.BorderRouter + ), 'Prefix doesn\'t contain a border router sub-TLV!' assert contains_tlv( - prefix.sub_tlvs, network_data.BorderRouter - ), 'Prefix doesn\'t contain a border router sub-TLV!' - assert contains_tlv( - prefix.sub_tlvs, network_data.LowpanId - ), 'Prefix doesn\'t contain a LowpanId sub-TLV!' + prefix.sub_tlvs, + network_data.LowpanId), 'Prefix doesn\'t contain a LowpanId sub-TLV!' def check_child_update_request_from_child( @@ -483,9 +446,8 @@ def check_child_update_request_from_child( check_mle_optional_tlv(command_msg, leader_data, mle.LeaderData) check_mle_optional_tlv(command_msg, challenge, mle.Challenge) check_mle_optional_tlv(command_msg, time_out, mle.Timeout) - check_mle_optional_tlv( - command_msg, address_registration, mle.AddressRegistration - ) + check_mle_optional_tlv(command_msg, address_registration, + mle.AddressRegistration) check_mle_optional_tlv(command_msg, tlv_request_tlv, mle.TlvRequest) check_mle_optional_tlv(command_msg, active_timestamp, mle.ActiveTimestamp) @@ -510,13 +472,10 @@ def check_router_id_cached(node, router_id, cached=True): eidcaches = node.get_eidcaches() if cached: assert any( - router_id == (int(rloc, 16) >> 10) for (_, rloc) in eidcaches - ) + 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 - ) + assert (any(router_id == (int(rloc, 16) >> 10) + for (_, rloc) in eidcaches) is False) def contains_tlv(sub_tlvs, tlv_type): @@ -528,10 +487,9 @@ def contains_tlv(sub_tlvs, tlv_type): def contains_tlvs(sub_tlvs, tlv_types): """Verify if all types of tlv in a list are included in a sub-tlv list. """ - return all( - (any(isinstance(sub_tlv, tlv_type) for sub_tlv in sub_tlvs)) - for tlv_type in tlv_types - ) + return all((any(isinstance(sub_tlv, tlv_type) + for sub_tlv in sub_tlvs)) + for tlv_type in tlv_types) def check_secure_mle_key_id_mode(command_msg, key_id_mode): @@ -541,9 +499,9 @@ def check_secure_mle_key_id_mode(command_msg, key_id_mode): assert command_msg.mle.aux_sec_hdr.key_id_mode == key_id_mode -def check_data_response( - command_msg, network_data_check=None, active_timestamp=CheckType.OPTIONAL -): +def check_data_response(command_msg, + network_data_check=None, + active_timestamp=CheckType.OPTIONAL): """Verify a properly formatted Data Response command message. """ check_secure_mle_key_id_mode(command_msg, 0x02) @@ -552,8 +510,7 @@ def check_data_response( check_mle_optional_tlv(command_msg, active_timestamp, mle.ActiveTimestamp) if network_data_check is not None: network_data_tlv = command_msg.assertMleMessageContainsTlv( - mle.NetworkData - ) + mle.NetworkData) network_data_check.check(network_data_tlv) @@ -596,16 +553,14 @@ def check_child_update_response( 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, 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, link_layer_frame_counter, + mle.LinkLayerFrameCounter) check_mle_optional_tlv(command_msg, mle_frame_counter, mle.MleFrameCounter) if (address_registration == CheckType.CONTAIN) and len(CIDs) > 0: @@ -614,8 +569,7 @@ def check_child_update_response( def _check_address_registration(command_msg, CIDs=[]): addresses = command_msg.assertMleMessageContainsTlv( - mle.AddressRegistration - ).addresses + mle.AddressRegistration).addresses for cid in CIDs: found = False for address in addresses: @@ -623,9 +577,7 @@ def _check_address_registration(command_msg, CIDs=[]): if cid == address.cid: found = True break - assert found, "AddressRegistration TLV doesn't have CID {} ".format( - cid - ) + assert found, "AddressRegistration TLV doesn't have CID {} ".format(cid) def get_sub_tlv(tlvs, tlv_type): @@ -637,9 +589,8 @@ def get_sub_tlv(tlvs, tlv_type): def check_address_registration_tlv(addr_reg_tlv, address_set): """Verify all addresses contained in address_set are contained in add_reg_tlv """ - assert all( - addr in addr_reg_tlv.addresses for addr in address_set - ), 'Some addresses are not included in AddressRegistration TLV' + assert all(addr in addr_reg_tlv.addresses for addr in address_set + ), 'Some addresses are not included in AddressRegistration TLV' def assert_contains_tlv(tlvs, check_type, tlv_type): @@ -663,36 +614,32 @@ def check_discovery_request(command_msg): """ assert not isinstance(command_msg.mle, mle.MleMessageSecured) tlvs = command_msg.assertMleMessageContainsTlv(mle.ThreadDiscovery).tlvs - request = assert_contains_tlv( - tlvs, CheckType.CONTAIN, mesh_cop.DiscoveryRequest - ) + request = assert_contains_tlv(tlvs, CheckType.CONTAIN, + mesh_cop.DiscoveryRequest) assert request.version == config.PROTOCOL_VERSION -def check_discovery_response( - command_msg, request_src_addr, steering_data=CheckType.OPTIONAL -): +def check_discovery_response(command_msg, + request_src_addr, + steering_data=CheckType.OPTIONAL): """Verify a properly formatted Thread Discovery Response command message. """ assert not isinstance(command_msg.mle, mle.MleMessageSecured) assert ( - command_msg.mac_header.src_address.type == common.MacAddressType.LONG - ) + command_msg.mac_header.src_address.type == common.MacAddressType.LONG) assert command_msg.mac_header.dest_address == request_src_addr tlvs = command_msg.assertMleMessageContainsTlv(mle.ThreadDiscovery).tlvs - response = assert_contains_tlv( - tlvs, CheckType.CONTAIN, mesh_cop.DiscoveryResponse - ) + response = assert_contains_tlv(tlvs, CheckType.CONTAIN, + mesh_cop.DiscoveryResponse) assert response.version == config.PROTOCOL_VERSION assert_contains_tlv(tlvs, CheckType.CONTAIN, mesh_cop.ExtendedPanid) assert_contains_tlv(tlvs, CheckType.CONTAIN, mesh_cop.NetworkName) assert_contains_tlv(tlvs, steering_data, mesh_cop.SteeringData) assert_contains_tlv(tlvs, steering_data, mesh_cop.JoinerUdpPort) - check_type = ( - CheckType.CONTAIN if response.native_flag else CheckType.OPTIONAL - ) + check_type = (CheckType.CONTAIN + if response.native_flag else CheckType.OPTIONAL) assert_contains_tlv(tlvs, check_type, mesh_cop.CommissionerUdpPort) @@ -700,9 +647,8 @@ def get_joiner_udp_port_in_discovery_response(command_msg): """Get the udp port specified in a DISCOVERY RESPONSE message """ tlvs = command_msg.assertMleMessageContainsTlv(mle.ThreadDiscovery).tlvs - udp_port_tlv = assert_contains_tlv( - tlvs, CheckType.CONTAIN, mesh_cop.JoinerUdpPort - ) + udp_port_tlv = assert_contains_tlv(tlvs, CheckType.CONTAIN, + mesh_cop.JoinerUdpPort) return udp_port_tlv.udp_port @@ -713,9 +659,8 @@ def check_joiner_commissioning_messages(commissioning_messages): assert len(commissioning_messages) >= 2 join_fin_req = commissioning_messages[0] assert join_fin_req.type == mesh_cop.MeshCopMessageType.JOIN_FIN_REQ - assert_contains_tlv( - join_fin_req.tlvs, CheckType.NOT_CONTAIN, mesh_cop.ProvisioningUrl - ) + assert_contains_tlv(join_fin_req.tlvs, CheckType.NOT_CONTAIN, + mesh_cop.ProvisioningUrl) join_ent_rsp = commissioning_messages[1] assert join_ent_rsp.type == mesh_cop.MeshCopMessageType.JOIN_ENT_RSP @@ -723,19 +668,15 @@ def check_joiner_commissioning_messages(commissioning_messages): def check_commissioner_commissioning_messages(commissioning_messages): """Verify COAP messages sent by commissioner while commissioning process. """ - assert any( - msg.type == mesh_cop.MeshCopMessageType.JOIN_FIN_RSP - for msg in commissioning_messages - ) + assert any(msg.type == mesh_cop.MeshCopMessageType.JOIN_FIN_RSP + for msg in commissioning_messages) def check_joiner_router_commissioning_messages(commissioning_messages): """Verify COAP messages sent by joiner router while commissioning process. """ - assert any( - msg.type == mesh_cop.MeshCopMessageType.JOIN_ENT_NTF - for msg in commissioning_messages - ) + assert any(msg.type == mesh_cop.MeshCopMessageType.JOIN_ENT_NTF + for msg in commissioning_messages) return None @@ -746,9 +687,9 @@ def check_payload_same(tp1, tp2): assert len(tp1) == len(tp2) for tlv in tp2: peer_tlv = get_sub_tlv(tp1, type(tlv)) - assert ( - peer_tlv is not None and peer_tlv == tlv - ), 'peer_tlv:{}, tlv:{} type:{}'.format(peer_tlv, tlv, type(tlv)) + assert (peer_tlv is not None and + peer_tlv == tlv), 'peer_tlv:{}, tlv:{} type:{}'.format( + peer_tlv, tlv, type(tlv)) def check_coap_message(msg, payloads, dest_addrs=None): @@ -763,28 +704,28 @@ def check_coap_message(msg, payloads, dest_addrs=None): class SinglePrefixCheck: + def __init__(self, prefix=None, border_router_16=None): self._prefix = prefix self._border_router_16 = border_router_16 def check(self, prefix_tlv): - border_router_tlv = assert_contains_tlv( - prefix_tlv.sub_tlvs, CheckType.CONTAIN, network_data.BorderRouter - ) - assert_contains_tlv( - prefix_tlv.sub_tlvs, CheckType.CONTAIN, network_data.LowpanId - ) + border_router_tlv = assert_contains_tlv(prefix_tlv.sub_tlvs, + CheckType.CONTAIN, + network_data.BorderRouter) + assert_contains_tlv(prefix_tlv.sub_tlvs, CheckType.CONTAIN, + network_data.LowpanId) result = True if self._prefix is not None: result &= self._prefix == binascii.hexlify(prefix_tlv.prefix) if self._border_router_16 is not None: result &= ( - self._border_router_16 == border_router_tlv.border_router_16 - ) + self._border_router_16 == border_router_tlv.border_router_16) return result class PrefixesCheck: + def __init__(self, prefix_cnt=0, prefix_check_list=[]): self._prefix_cnt = prefix_cnt self._prefix_check_list = prefix_check_list @@ -792,9 +733,8 @@ class PrefixesCheck: def check(self, prefix_tlvs): # if prefix_cnt is given, then check count only if self._prefix_cnt > 0: - assert ( - len(prefix_tlvs) >= self._prefix_cnt - ), 'prefix count is less than expected' + assert (len(prefix_tlvs) >= + self._prefix_cnt), 'prefix count is less than expected' else: for prefix_check in self._prefix_check_list: found = False @@ -806,21 +746,22 @@ class PrefixesCheck: class CommissioningDataCheck: + def __init__(self, stable=None, sub_tlv_type_list=[]): self._stable = stable self._sub_tlv_type_list = sub_tlv_type_list def check(self, commissioning_data_tlv): if self._stable is not None: - assert ( - self._stable == commissioning_data_tlv.stable - ), 'Commissioning Data stable flag is not correct' - assert contains_tlvs( - commissioning_data_tlv.sub_tlvs, self._sub_tlv_type_list - ), 'Some sub tlvs are missing in Commissioning Data' + assert (self._stable == commissioning_data_tlv.stable + ), 'Commissioning Data stable flag is not correct' + assert contains_tlvs(commissioning_data_tlv.sub_tlvs, + self._sub_tlv_type_list + ), 'Some sub tlvs are missing in Commissioning Data' class NetworkDataCheck: + def __init__(self, prefixes_check=None, commissioning_data_check=None): self._prefixes_check = prefixes_check self._commissioning_data_check = commissioning_data_check @@ -828,8 +769,7 @@ class NetworkDataCheck: def check(self, network_data_tlv): if self._prefixes_check is not None: prefix_tlvs = [ - tlv - for tlv in network_data_tlv.tlvs + tlv for tlv in network_data_tlv.tlvs if isinstance(tlv, network_data.Prefix) ] self._prefixes_check.check(prefix_tlvs) diff --git a/tests/scripts/thread-cert/common.py b/tests/scripts/thread-cert/common.py index 519b1df44..fe68ad36f 100644 --- a/tests/scripts/thread-cert/common.py +++ b/tests/scripts/thread-cert/common.py @@ -37,14 +37,12 @@ import ipaddress def expect_the_same_class(self, other): if not isinstance(other, self.__class__): - raise TypeError( - "Expected the same class. Got {} and {}".format( - type(self), type(other) - ) - ) + raise TypeError("Expected the same class. Got {} and {}".format( + type(self), type(other))) class MessageInfo(object): + def __init__(self): self.aux_sec_hdr = None self.aux_sec_hdr_bytes = None @@ -109,6 +107,7 @@ class MacAddressType(IntEnum): class MacAddress(object): + def __init__(self, mac_address, _type, big_endian=True): if _type == MacAddressType.SHORT: length = 2 @@ -135,15 +134,11 @@ class MacAddress(object): def convert_to_iid(self): if self._type == MacAddressType.SHORT: - return ( - bytearray([0x00, 0x00, 0x00, 0xff, 0xfe, 0x00]) - + self._mac_address[:2] - ) + return (bytearray([0x00, 0x00, 0x00, 0xff, 0xfe, 0x00]) + + self._mac_address[:2]) elif self._type == MacAddressType.LONG: - return ( - bytearray([self._mac_address[0] ^ 0x02]) - + self._mac_address[1:] - ) + return (bytearray([self._mac_address[0] ^ 0x02]) + + self._mac_address[1:]) else: raise RuntimeError( "Could not convert to IID. Invalid MAC address type: {}".format( @@ -153,8 +148,8 @@ class MacAddress(object): def from_eui64(cls, eui64, big_endian=True): if not isinstance(eui64, bytearray): raise RuntimeError( - "Could not create MAC address from EUI64. Invalid data type: {}".format( - type(eui64))) + "Could not create MAC address from EUI64. Invalid data type: {}" + .format(type(eui64))) return cls(eui64, MacAddressType.LONG) @@ -166,17 +161,15 @@ class MacAddress(object): mac_address = rloc16[:2] else: raise RuntimeError( - "Could not create MAC address from RLOC16. Invalid data type: {}".format( - type(rloc16))) + "Could not create MAC address from RLOC16. Invalid data type: {}" + .format(type(rloc16))) return cls(mac_address, MacAddressType.SHORT) def __eq__(self, other): return (self.type == other.type) and ( - self.mac_address == other.mac_address - ) + self.mac_address == other.mac_address) def __repr__(self): return "MacAddress(mac_address=b'{}', type={})".format( - hexlify(self.mac_address), MacAddressType(self._type) - ) + hexlify(self.mac_address), MacAddressType(self._type)) diff --git a/tests/scripts/thread-cert/config.py b/tests/scripts/thread-cert/config.py index b95230eb5..ad05ab444 100644 --- a/tests/scripts/thread-cert/config.py +++ b/tests/scripts/thread-cert/config.py @@ -56,30 +56,27 @@ REALM_LOCAL_ALL_ROUTERS_ADDRESS = 'ff03::2' LINK_LOCAL_ALL_NODES_ADDRESS = 'ff02::1' LINK_LOCAL_ALL_ROUTERS_ADDRESS = 'ff02::2' -DEFAULT_MASTER_KEY = bytearray( - [ - 0x00, - 0x11, - 0x22, - 0x33, - 0x44, - 0x55, - 0x66, - 0x77, - 0x88, - 0x99, - 0xaa, - 0xbb, - 0xcc, - 0xdd, - 0xee, - 0xff, - ] -) +DEFAULT_MASTER_KEY = bytearray([ + 0x00, + 0x11, + 0x22, + 0x33, + 0x44, + 0x55, + 0x66, + 0x77, + 0x88, + 0x99, + 0xaa, + 0xbb, + 0xcc, + 0xdd, + 0xee, + 0xff, +]) -ADDRESS_TYPE = Enum( - 'ADDRESS_TYPE', ('LINK_LOCAL', 'GLOBAL', 'RLOC', 'ALOC', 'ML_EID') -) +ADDRESS_TYPE = Enum('ADDRESS_TYPE', + ('LINK_LOCAL', 'GLOBAL', 'RLOC', 'ALOC', 'ML_EID')) RSSI = { 'LINK_QULITY_0': -100, 'LINK_QULITY_1': -95, @@ -108,19 +105,21 @@ PROTOCOL_VERSION = 2 def create_default_network_data_prefix_sub_tlvs_factories(): return { - network_data.TlvType.HAS_ROUTE: network_data.HasRouteFactory( - routes_factory=network_data.RoutesFactory( - route_factory=network_data.RouteFactory() - ) - ), - network_data.TlvType.BORDER_ROUTER: network_data.BorderRouterFactory(), - network_data.TlvType.LOWPAN_ID: network_data.LowpanIdFactory(), + network_data.TlvType.HAS_ROUTE: + network_data.HasRouteFactory( + routes_factory=network_data.RoutesFactory( + route_factory=network_data.RouteFactory())), + network_data.TlvType.BORDER_ROUTER: + network_data.BorderRouterFactory(), + network_data.TlvType.LOWPAN_ID: + network_data.LowpanIdFactory(), } def create_default_network_data_prefix_sub_tlvs_factory(): return network_data.PrefixSubTlvsFactory( - sub_tlvs_factories=create_default_network_data_prefix_sub_tlvs_factories()) + sub_tlvs_factories=create_default_network_data_prefix_sub_tlvs_factories( + )) def create_default_network_data_service_sub_tlvs_factories(): @@ -129,53 +128,62 @@ def create_default_network_data_service_sub_tlvs_factories(): def create_default_network_data_service_sub_tlvs_factory(): return network_data.ServiceSubTlvsFactory( - sub_tlvs_factories=create_default_network_data_service_sub_tlvs_factories()) + sub_tlvs_factories= + create_default_network_data_service_sub_tlvs_factories()) def create_default_network_data_commissioning_data_sub_tlvs_factories(): return { - mesh_cop.TlvType.CHANNEL: mesh_cop.ChannelFactory(), - mesh_cop.TlvType.STEERING_DATA: mesh_cop.SteeringDataFactory(), - mesh_cop.TlvType.BORDER_AGENT_LOCATOR: mesh_cop.BorderAgentLocatorFactory(), - mesh_cop.TlvType.COMMISSIONER_SESSION_ID: mesh_cop.CommissionerSessionIdFactory(), - mesh_cop.TlvType.COMMISSIONER_UDP_PORT: mesh_cop.CommissionerUdpPortFactory(), + mesh_cop.TlvType.CHANNEL: + mesh_cop.ChannelFactory(), + mesh_cop.TlvType.STEERING_DATA: + mesh_cop.SteeringDataFactory(), + mesh_cop.TlvType.BORDER_AGENT_LOCATOR: + mesh_cop.BorderAgentLocatorFactory(), + mesh_cop.TlvType.COMMISSIONER_SESSION_ID: + mesh_cop.CommissionerSessionIdFactory(), + mesh_cop.TlvType.COMMISSIONER_UDP_PORT: + mesh_cop.CommissionerUdpPortFactory(), } def create_default_network_data_commissioning_data_sub_tlvs_factory(): return network_data.CommissioningDataSubTlvsFactory( - sub_tlvs_factories=create_default_network_data_commissioning_data_sub_tlvs_factories()) + sub_tlvs_factories= + create_default_network_data_commissioning_data_sub_tlvs_factories()) def create_default_network_data_tlvs_factories(): return { - network_data.TlvType.PREFIX: network_data.PrefixFactory( - sub_tlvs_factory=create_default_network_data_prefix_sub_tlvs_factory() - ), - network_data.TlvType.SERVICE: network_data.ServiceFactory( - sub_tlvs_factory=create_default_network_data_service_sub_tlvs_factory() - ), - network_data.TlvType.COMMISSIONING: network_data.CommissioningDataFactory( - sub_tlvs_factory=create_default_network_data_commissioning_data_sub_tlvs_factory() - ), + network_data.TlvType.PREFIX: + network_data.PrefixFactory( + sub_tlvs_factory= + create_default_network_data_prefix_sub_tlvs_factory()), + network_data.TlvType.SERVICE: + network_data.ServiceFactory( + sub_tlvs_factory= + create_default_network_data_service_sub_tlvs_factory()), + network_data.TlvType.COMMISSIONING: + network_data.CommissioningDataFactory( + sub_tlvs_factory= + create_default_network_data_commissioning_data_sub_tlvs_factory( + )), } def create_default_network_data_tlvs_factory(): return network_data.NetworkDataTlvsFactory( - sub_tlvs_factories=create_default_network_data_tlvs_factories() - ) + sub_tlvs_factories=create_default_network_data_tlvs_factories()) def create_default_mle_tlv_route64_factory(): - return mle.Route64Factory( - link_quality_and_route_data_factory=mle.LinkQualityAndRouteDataFactory()) + return mle.Route64Factory(link_quality_and_route_data_factory=mle. + LinkQualityAndRouteDataFactory()) def create_default_mle_tlv_network_data_factory(): return mle.NetworkDataFactory( - network_data_tlvs_factory=create_default_network_data_tlvs_factory() - ) + network_data_tlvs_factory=create_default_network_data_tlvs_factory()) def create_default_mle_tlv_address_registration_factory(): @@ -187,148 +195,226 @@ def create_default_mle_tlv_address_registration_factory(): def create_default_mle_tlv_thread_discovery_factory(): return mle.ThreadDiscoveryFactory( - thread_discovery_tlvs_factory=create_default_thread_discovery_tlvs_factory()) + thread_discovery_tlvs_factory= + create_default_thread_discovery_tlvs_factory()) def create_default_thread_discovery_tlvs_factory(): return mesh_cop.ThreadDiscoveryTlvsFactory( - sub_tlvs_factories=create_default_thread_discovery_sub_tlvs_factories() - ) + sub_tlvs_factories=create_default_thread_discovery_sub_tlvs_factories()) def create_default_thread_discovery_sub_tlvs_factories(): return { - mesh_cop.TlvType.DISCOVERY_REQUEST: mesh_cop.DiscoveryRequestFactory(), - mesh_cop.TlvType.DISCOVERY_RESPONSE: mesh_cop.DiscoveryResponseFactory(), - mesh_cop.TlvType.EXTENDED_PANID: mesh_cop.ExtendedPanidFactory(), - mesh_cop.TlvType.NETWORK_NAME: mesh_cop.NetworkNameFactory(), - mesh_cop.TlvType.STEERING_DATA: mesh_cop.SteeringDataFactory(), - mesh_cop.TlvType.JOINER_UDP_PORT: mesh_cop.JoinerUdpPortFactory(), - mesh_cop.TlvType.COMMISSIONER_UDP_PORT: mesh_cop.CommissionerUdpPortFactory(), + mesh_cop.TlvType.DISCOVERY_REQUEST: + mesh_cop.DiscoveryRequestFactory(), + mesh_cop.TlvType.DISCOVERY_RESPONSE: + mesh_cop.DiscoveryResponseFactory(), + mesh_cop.TlvType.EXTENDED_PANID: + mesh_cop.ExtendedPanidFactory(), + mesh_cop.TlvType.NETWORK_NAME: + mesh_cop.NetworkNameFactory(), + mesh_cop.TlvType.STEERING_DATA: + mesh_cop.SteeringDataFactory(), + mesh_cop.TlvType.JOINER_UDP_PORT: + mesh_cop.JoinerUdpPortFactory(), + mesh_cop.TlvType.COMMISSIONER_UDP_PORT: + mesh_cop.CommissionerUdpPortFactory(), } def create_default_mle_tlvs_factories(): return { - mle.TlvType.SOURCE_ADDRESS: mle.SourceAddressFactory(), - mle.TlvType.MODE: mle.ModeFactory(), - mle.TlvType.TIMEOUT: mle.TimeoutFactory(), - mle.TlvType.CHALLENGE: mle.ChallengeFactory(), - mle.TlvType.RESPONSE: mle.ResponseFactory(), - mle.TlvType.LINK_LAYER_FRAME_COUNTER: mle.LinkLayerFrameCounterFactory(), - mle.TlvType.MLE_FRAME_COUNTER: mle.MleFrameCounterFactory(), - mle.TlvType.ROUTE64: create_default_mle_tlv_route64_factory(), - mle.TlvType.ADDRESS16: mle.Address16Factory(), - mle.TlvType.LEADER_DATA: mle.LeaderDataFactory(), - mle.TlvType.NETWORK_DATA: create_default_mle_tlv_network_data_factory(), - mle.TlvType.TLV_REQUEST: mle.TlvRequestFactory(), - mle.TlvType.SCAN_MASK: mle.ScanMaskFactory(), - mle.TlvType.CONNECTIVITY: mle.ConnectivityFactory(), - mle.TlvType.LINK_MARGIN: mle.LinkMarginFactory(), - mle.TlvType.STATUS: mle.StatusFactory(), - mle.TlvType.VERSION: mle.VersionFactory(), - mle.TlvType.ADDRESS_REGISTRATION: create_default_mle_tlv_address_registration_factory(), - mle.TlvType.CHANNEL: mle.ChannelFactory(), - mle.TlvType.PANID: mle.PanIdFactory(), - mle.TlvType.ACTIVE_TIMESTAMP: mle.ActiveTimestampFactory(), - mle.TlvType.PENDING_TIMESTAMP: mle.PendingTimestampFactory(), - mle.TlvType.ACTIVE_OPERATIONAL_DATASET: mle.ActiveOperationalDatasetFactory(), - mle.TlvType.PENDING_OPERATIONAL_DATASET: mle.PendingOperationalDatasetFactory(), - mle.TlvType.TIME_REQUEST: mle.TimeRequestFactory(), - mle.TlvType.TIME_PARAMETER: mle.TimeParameterFactory(), - mle.TlvType.THREAD_DISCOVERY: create_default_mle_tlv_thread_discovery_factory(), + mle.TlvType.SOURCE_ADDRESS: + mle.SourceAddressFactory(), + mle.TlvType.MODE: + mle.ModeFactory(), + mle.TlvType.TIMEOUT: + mle.TimeoutFactory(), + mle.TlvType.CHALLENGE: + mle.ChallengeFactory(), + mle.TlvType.RESPONSE: + mle.ResponseFactory(), + mle.TlvType.LINK_LAYER_FRAME_COUNTER: + mle.LinkLayerFrameCounterFactory(), + mle.TlvType.MLE_FRAME_COUNTER: + mle.MleFrameCounterFactory(), + mle.TlvType.ROUTE64: + create_default_mle_tlv_route64_factory(), + mle.TlvType.ADDRESS16: + mle.Address16Factory(), + mle.TlvType.LEADER_DATA: + mle.LeaderDataFactory(), + mle.TlvType.NETWORK_DATA: + create_default_mle_tlv_network_data_factory(), + mle.TlvType.TLV_REQUEST: + mle.TlvRequestFactory(), + mle.TlvType.SCAN_MASK: + mle.ScanMaskFactory(), + mle.TlvType.CONNECTIVITY: + mle.ConnectivityFactory(), + mle.TlvType.LINK_MARGIN: + mle.LinkMarginFactory(), + mle.TlvType.STATUS: + mle.StatusFactory(), + mle.TlvType.VERSION: + mle.VersionFactory(), + mle.TlvType.ADDRESS_REGISTRATION: + create_default_mle_tlv_address_registration_factory(), + mle.TlvType.CHANNEL: + mle.ChannelFactory(), + mle.TlvType.PANID: + mle.PanIdFactory(), + mle.TlvType.ACTIVE_TIMESTAMP: + mle.ActiveTimestampFactory(), + mle.TlvType.PENDING_TIMESTAMP: + mle.PendingTimestampFactory(), + mle.TlvType.ACTIVE_OPERATIONAL_DATASET: + mle.ActiveOperationalDatasetFactory(), + mle.TlvType.PENDING_OPERATIONAL_DATASET: + mle.PendingOperationalDatasetFactory(), + mle.TlvType.TIME_REQUEST: + mle.TimeRequestFactory(), + mle.TlvType.TIME_PARAMETER: + mle.TimeParameterFactory(), + mle.TlvType.THREAD_DISCOVERY: + create_default_mle_tlv_thread_discovery_factory(), } def create_default_mle_crypto_engine(master_key): return net_crypto.CryptoEngine( - crypto_material_creator=net_crypto.MleCryptoMaterialCreator(master_key) - ) + crypto_material_creator=net_crypto.MleCryptoMaterialCreator(master_key)) def create_default_mle_message_factory(master_key): return mle.MleMessageFactory( aux_sec_hdr_factory=net_crypto.AuxiliarySecurityHeaderFactory(), mle_command_factory=mle.MleCommandFactory( - tlvs_factories=create_default_mle_tlvs_factories() - ), + tlvs_factories=create_default_mle_tlvs_factories()), crypto_engine=create_default_mle_crypto_engine(master_key), ) def create_deafult_network_tlvs_factories(): return { - network_layer.TlvType.TARGET_EID: network_layer.TargetEidFactory(), - network_layer.TlvType.MAC_EXTENDED_ADDRESS: network_layer.MacExtendedAddressFactory(), - network_layer.TlvType.RLOC16: network_layer.Rloc16Factory(), - network_layer.TlvType.ML_EID: network_layer.MlEidFactory(), - network_layer.TlvType.STATUS: network_layer.StatusFactory(), - network_layer.TlvType.TIME_SINCE_LAST_TRANSACTION: network_layer.TimeSinceLastTransactionFactory(), - network_layer.TlvType.ROUTER_MASK: network_layer.RouterMaskFactory(), - network_layer.TlvType.ND_OPTION: network_layer.NdOptionFactory(), - network_layer.TlvType.ND_DATA: network_layer.NdDataFactory(), - network_layer.TlvType.THREAD_NETWORK_DATA: network_layer.ThreadNetworkDataFactory( - create_default_network_data_tlvs_factory() - ), - network_layer.TlvType.XTAL_ACCURACY: network_layer.XtalAccuracyFactory(), + network_layer.TlvType.TARGET_EID: + network_layer.TargetEidFactory(), + network_layer.TlvType.MAC_EXTENDED_ADDRESS: + network_layer.MacExtendedAddressFactory(), + network_layer.TlvType.RLOC16: + network_layer.Rloc16Factory(), + network_layer.TlvType.ML_EID: + network_layer.MlEidFactory(), + network_layer.TlvType.STATUS: + network_layer.StatusFactory(), + network_layer.TlvType.TIME_SINCE_LAST_TRANSACTION: + network_layer.TimeSinceLastTransactionFactory(), + network_layer.TlvType.ROUTER_MASK: + network_layer.RouterMaskFactory(), + network_layer.TlvType.ND_OPTION: + network_layer.NdOptionFactory(), + network_layer.TlvType.ND_DATA: + network_layer.NdDataFactory(), + network_layer.TlvType.THREAD_NETWORK_DATA: + network_layer.ThreadNetworkDataFactory( + create_default_network_data_tlvs_factory()), + network_layer.TlvType.XTAL_ACCURACY: + network_layer.XtalAccuracyFactory(), # Routing information are distributed in a Thread network by MLE Routing TLV # which is in fact MLE Route64 TLV. Thread specificaton v1.1. - Chapter 5.20 - network_layer.TlvType.MLE_ROUTING: create_default_mle_tlv_route64_factory(), + network_layer.TlvType.MLE_ROUTING: + create_default_mle_tlv_route64_factory(), } def create_default_network_tlvs_factory(): return SubTlvsFactory( - sub_tlvs_factories=create_deafult_network_tlvs_factories() - ) + sub_tlvs_factories=create_deafult_network_tlvs_factories()) def create_default_mesh_cop_tlvs_factories(): return { - mesh_cop.TlvType.CHANNEL: mesh_cop.ChannelFactory(), - mesh_cop.TlvType.PAN_ID: mesh_cop.PanidFactory(), - mesh_cop.TlvType.EXTENDED_PANID: mesh_cop.ExtendedPanidFactory(), - mesh_cop.TlvType.NETWORK_NAME: mesh_cop.NetworkNameFactory(), - mesh_cop.TlvType.PSKC: mesh_cop.PSKcFactory(), - mesh_cop.TlvType.NETWORK_MASTER_KEY: mesh_cop.NetworkMasterKeyFactory(), - mesh_cop.TlvType.NETWORK_KEY_SEQUENCE_COUNTER: mesh_cop.NetworkKeySequenceCounterFactory(), - mesh_cop.TlvType.NETWORK_MESH_LOCAL_PREFIX: mesh_cop.NetworkMeshLocalPrefixFactory(), - mesh_cop.TlvType.STEERING_DATA: mesh_cop.SteeringDataFactory(), - mesh_cop.TlvType.BORDER_AGENT_LOCATOR: mesh_cop.BorderAgentLocatorFactory(), - mesh_cop.TlvType.COMMISSIONER_ID: mesh_cop.CommissionerIdFactory(), - mesh_cop.TlvType.COMMISSIONER_SESSION_ID: mesh_cop.CommissionerSessionIdFactory(), - mesh_cop.TlvType.SECURITY_POLICY: mesh_cop.SecurityPolicyFactory(), - mesh_cop.TlvType.GET: mesh_cop.GetFactory(), - mesh_cop.TlvType.ACTIVE_TIMESTAMP: mesh_cop.ActiveTimestampFactory(), - mesh_cop.TlvType.COMMISSIONER_UDP_PORT: mesh_cop.CommissionerUdpPortFactory(), - mesh_cop.TlvType.STATE: mesh_cop.StateFactory(), - mesh_cop.TlvType.JOINER_DTLS_ENCAPSULATION: mesh_cop.JoinerDtlsEncapsulationFactory(), - mesh_cop.TlvType.JOINER_UDP_PORT: mesh_cop.JoinerUdpPortFactory(), - mesh_cop.TlvType.JOINER_IID: mesh_cop.JoinerIIDFactory(), - mesh_cop.TlvType.JOINER_ROUTER_LOCATOR: mesh_cop.JoinerRouterLocatorFactory(), - mesh_cop.TlvType.JOINER_ROUTER_KEK: mesh_cop.JoinerRouterKEKFactory(), - mesh_cop.TlvType.PROVISIONING_URL: mesh_cop.ProvisioningUrlFactory(), - mesh_cop.TlvType.VENDOR_NAME: mesh_cop.VendorNameFactory(), - mesh_cop.TlvType.VENDOR_MODEL: mesh_cop.VendorModelFactory(), - mesh_cop.TlvType.VENDOR_SW_VERSION: mesh_cop.VendorSWVersionFactory(), - mesh_cop.TlvType.VENDOR_DATA: mesh_cop.VendorDataFactory(), - mesh_cop.TlvType.VENDOR_STACK_VERSION: mesh_cop.VendorStackVersionFactory(), - mesh_cop.TlvType.UDP_ENCAPSULATION: mesh_cop.UdpEncapsulationFactory(), - mesh_cop.TlvType.IPV6_ADDRESS: mesh_cop.Ipv6AddressFactory(), - mesh_cop.TlvType.PENDING_TIMESTAMP: mesh_cop.PendingTimestampFactory(), - mesh_cop.TlvType.DELAY_TIMER: mesh_cop.DelayTimerFactory(), - mesh_cop.TlvType.CHANNEL_MASK: mesh_cop.ChannelMaskFactory(), - mesh_cop.TlvType.COUNT: mesh_cop.CountFactory(), - mesh_cop.TlvType.PERIOD: mesh_cop.PeriodFactory(), - mesh_cop.TlvType.SCAN_DURATION: mesh_cop.ScanDurationFactory(), - mesh_cop.TlvType.ENERGY_LIST: mesh_cop.EnergyListFactory(), + mesh_cop.TlvType.CHANNEL: + mesh_cop.ChannelFactory(), + mesh_cop.TlvType.PAN_ID: + mesh_cop.PanidFactory(), + mesh_cop.TlvType.EXTENDED_PANID: + mesh_cop.ExtendedPanidFactory(), + mesh_cop.TlvType.NETWORK_NAME: + mesh_cop.NetworkNameFactory(), + mesh_cop.TlvType.PSKC: + mesh_cop.PSKcFactory(), + mesh_cop.TlvType.NETWORK_MASTER_KEY: + mesh_cop.NetworkMasterKeyFactory(), + mesh_cop.TlvType.NETWORK_KEY_SEQUENCE_COUNTER: + mesh_cop.NetworkKeySequenceCounterFactory(), + mesh_cop.TlvType.NETWORK_MESH_LOCAL_PREFIX: + mesh_cop.NetworkMeshLocalPrefixFactory(), + mesh_cop.TlvType.STEERING_DATA: + mesh_cop.SteeringDataFactory(), + mesh_cop.TlvType.BORDER_AGENT_LOCATOR: + mesh_cop.BorderAgentLocatorFactory(), + mesh_cop.TlvType.COMMISSIONER_ID: + mesh_cop.CommissionerIdFactory(), + mesh_cop.TlvType.COMMISSIONER_SESSION_ID: + mesh_cop.CommissionerSessionIdFactory(), + mesh_cop.TlvType.SECURITY_POLICY: + mesh_cop.SecurityPolicyFactory(), + mesh_cop.TlvType.GET: + mesh_cop.GetFactory(), + mesh_cop.TlvType.ACTIVE_TIMESTAMP: + mesh_cop.ActiveTimestampFactory(), + mesh_cop.TlvType.COMMISSIONER_UDP_PORT: + mesh_cop.CommissionerUdpPortFactory(), + mesh_cop.TlvType.STATE: + mesh_cop.StateFactory(), + mesh_cop.TlvType.JOINER_DTLS_ENCAPSULATION: + mesh_cop.JoinerDtlsEncapsulationFactory(), + mesh_cop.TlvType.JOINER_UDP_PORT: + mesh_cop.JoinerUdpPortFactory(), + mesh_cop.TlvType.JOINER_IID: + mesh_cop.JoinerIIDFactory(), + mesh_cop.TlvType.JOINER_ROUTER_LOCATOR: + mesh_cop.JoinerRouterLocatorFactory(), + mesh_cop.TlvType.JOINER_ROUTER_KEK: + mesh_cop.JoinerRouterKEKFactory(), + mesh_cop.TlvType.PROVISIONING_URL: + mesh_cop.ProvisioningUrlFactory(), + mesh_cop.TlvType.VENDOR_NAME: + mesh_cop.VendorNameFactory(), + mesh_cop.TlvType.VENDOR_MODEL: + mesh_cop.VendorModelFactory(), + mesh_cop.TlvType.VENDOR_SW_VERSION: + mesh_cop.VendorSWVersionFactory(), + mesh_cop.TlvType.VENDOR_DATA: + mesh_cop.VendorDataFactory(), + mesh_cop.TlvType.VENDOR_STACK_VERSION: + mesh_cop.VendorStackVersionFactory(), + mesh_cop.TlvType.UDP_ENCAPSULATION: + mesh_cop.UdpEncapsulationFactory(), + mesh_cop.TlvType.IPV6_ADDRESS: + mesh_cop.Ipv6AddressFactory(), + mesh_cop.TlvType.PENDING_TIMESTAMP: + mesh_cop.PendingTimestampFactory(), + mesh_cop.TlvType.DELAY_TIMER: + mesh_cop.DelayTimerFactory(), + mesh_cop.TlvType.CHANNEL_MASK: + mesh_cop.ChannelMaskFactory(), + mesh_cop.TlvType.COUNT: + mesh_cop.CountFactory(), + mesh_cop.TlvType.PERIOD: + mesh_cop.PeriodFactory(), + mesh_cop.TlvType.SCAN_DURATION: + mesh_cop.ScanDurationFactory(), + mesh_cop.TlvType.ENERGY_LIST: + mesh_cop.EnergyListFactory(), } def create_default_mesh_cop_tlvs_factory(): return SubTlvsFactory( - sub_tlvs_factories=create_default_mesh_cop_tlvs_factories() - ) + sub_tlvs_factories=create_default_mesh_cop_tlvs_factories()) def create_default_uri_path_based_payload_factories(): @@ -349,7 +435,8 @@ def create_default_uri_path_based_payload_factories(): def create_default_coap_message_factory(): return coap.CoapMessageFactory( options_factory=coap.CoapOptionsFactory(), - uri_path_based_payload_factories=create_default_uri_path_based_payload_factories(), + uri_path_based_payload_factories= + create_default_uri_path_based_payload_factories(), message_id_to_uri_path_binder=coap.CoapMessageIdToUriPathBinder(), ) @@ -360,8 +447,7 @@ def create_default_ipv6_hop_by_hop_options_factories(): def create_default_ipv6_hop_by_hop_options_factory(): return ipv6.HopByHopOptionsFactory( - options_factories=create_default_ipv6_hop_by_hop_options_factories() - ) + options_factories=create_default_ipv6_hop_by_hop_options_factories()) def create_default_based_on_src_dst_ports_udp_payload_factory(master_key): @@ -375,8 +461,7 @@ def create_default_based_on_src_dst_ports_udp_payload_factory(master_key): 61631: coap_message_factory, 1000: dtls_message_factory, 5684: dtls_message_factory, - } - ) + }) def create_default_dtls_message_factory(): @@ -385,35 +470,48 @@ def create_default_dtls_message_factory(): def create_default_ipv6_icmp_body_factories(): return { - ipv6.ICMP_DESTINATION_UNREACHABLE: ipv6.ICMPv6DestinationUnreachableFactory(), - ipv6.ICMP_ECHO_REQUEST: ipv6.ICMPv6EchoBodyFactory(), - ipv6.ICMP_ECHO_RESPONSE: ipv6.ICMPv6EchoBodyFactory(), - "default": ipv6.BytesPayloadFactory(), + ipv6.ICMP_DESTINATION_UNREACHABLE: + ipv6.ICMPv6DestinationUnreachableFactory(), + ipv6.ICMP_ECHO_REQUEST: + ipv6.ICMPv6EchoBodyFactory(), + ipv6.ICMP_ECHO_RESPONSE: + ipv6.ICMPv6EchoBodyFactory(), + "default": + ipv6.BytesPayloadFactory(), } def create_default_ipv6_upper_layer_factories(master_key): return { - ipv6.IPV6_NEXT_HEADER_UDP: ipv6.UDPDatagramFactory( - udp_header_factory=ipv6.UDPHeaderFactory(), - udp_payload_factory=create_default_based_on_src_dst_ports_udp_payload_factory( - master_key + ipv6.IPV6_NEXT_HEADER_UDP: + ipv6.UDPDatagramFactory( + udp_header_factory=ipv6.UDPHeaderFactory(), + udp_payload_factory= + create_default_based_on_src_dst_ports_udp_payload_factory( + master_key), ), - ), - ipv6.IPV6_NEXT_HEADER_ICMP: ipv6.ICMPv6Factory( - body_factories=create_default_ipv6_icmp_body_factories() - ), + ipv6.IPV6_NEXT_HEADER_ICMP: + ipv6.ICMPv6Factory( + body_factories=create_default_ipv6_icmp_body_factories()), } def create_default_lowpan_extension_headers_factories(): - return {ipv6.IPV6_NEXT_HEADER_HOP_BY_HOP: lowpan.LowpanHopByHopFactory( - hop_by_hop_options_factory=create_default_ipv6_hop_by_hop_options_factory())} + return { + ipv6.IPV6_NEXT_HEADER_HOP_BY_HOP: + lowpan.LowpanHopByHopFactory( + hop_by_hop_options_factory= + create_default_ipv6_hop_by_hop_options_factory()) + } def create_default_ipv6_extension_headers_factories(): - return {ipv6.IPV6_NEXT_HEADER_HOP_BY_HOP: ipv6.HopByHopFactory( - hop_by_hop_options_factory=create_default_ipv6_hop_by_hop_options_factory())} + return { + ipv6.IPV6_NEXT_HEADER_HOP_BY_HOP: + ipv6.HopByHopFactory( + hop_by_hop_options_factory= + create_default_ipv6_hop_by_hop_options_factory()) + } def create_default_ipv6_packet_factory(master_key): @@ -426,11 +524,10 @@ def create_default_ipv6_packet_factory(master_key): def create_default_lowpan_decompressor(context_manager): return lowpan.LowpanDecompressor( lowpan_ip_header_factory=lowpan.LowpanIpv6HeaderFactory( - context_manager=context_manager - ), + context_manager=context_manager), lowpan_extension_headers_factory=lowpan.LowpanExtensionHeadersFactory( - ext_headers_factories=create_default_lowpan_extension_headers_factories() - ), + ext_headers_factories= + create_default_lowpan_extension_headers_factories()), lowpan_udp_header_factory=lowpan.LowpanUdpHeaderFactory(), ) @@ -442,13 +539,13 @@ def create_default_thread_context_manager(): return context_manager -def create_default_lowpan_parser( - context_manager, master_key=DEFAULT_MASTER_KEY -): +def create_default_lowpan_parser(context_manager, + master_key=DEFAULT_MASTER_KEY): return lowpan.LowpanParser( lowpan_mesh_header_factory=lowpan.LowpanMeshHeaderFactory(), lowpan_decompressor=create_default_lowpan_decompressor(context_manager), - lowpan_fragements_buffers_manager=lowpan.LowpanFragmentsBuffersManager(), + lowpan_fragements_buffers_manager=lowpan.LowpanFragmentsBuffersManager( + ), ipv6_packet_factory=create_default_ipv6_packet_factory(master_key), ) diff --git a/tests/scripts/thread-cert/debug.py b/tests/scripts/thread-cert/debug.py index 4d76097a9..b3b03b242 100644 --- a/tests/scripts/thread-cert/debug.py +++ b/tests/scripts/thread-cert/debug.py @@ -27,7 +27,6 @@ # POSSIBILITY OF SUCH DAMAGE. # - from builtins import input diff --git a/tests/scripts/thread-cert/dtls.py b/tests/scripts/thread-cert/dtls.py index 33fd91461..e1d99341b 100644 --- a/tests/scripts/thread-cert/dtls.py +++ b/tests/scripts/thread-cert/dtls.py @@ -91,9 +91,9 @@ class AlertDescription(IntEnum): class Record(ConvertibleToBytes, BuildableFromBytes): - def __init__( - self, content_type, version, epoch, sequence_number, length, fragment - ): + + def __init__(self, content_type, version, epoch, sequence_number, length, + fragment): self.content_type = content_type self.version = version self.epoch = epoch @@ -102,14 +102,10 @@ class Record(ConvertibleToBytes, BuildableFromBytes): self.fragment = fragment def to_bytes(self): - return ( - struct.pack(">B", self.content_type) - + self.version.to_bytes() - + struct.pack(">H", self.epoch) - + self.sequence_number.to_bytes(6, byteorder='big') - + struct.pack(">H", self.length) - + self.fragment - ) + return (struct.pack(">B", self.content_type) + self.version.to_bytes() + + struct.pack(">H", self.epoch) + + self.sequence_number.to_bytes(6, byteorder='big') + + struct.pack(">H", self.length) + self.fragment) @classmethod def from_bytes(cls, data): @@ -119,16 +115,21 @@ class Record(ConvertibleToBytes, BuildableFromBytes): sequence_number = struct.unpack(">Q", b'\x00\x00' + data.read(6))[0] length = struct.unpack(">H", data.read(2))[0] fragment = bytes(data.read(length)) - return cls( - content_type, version, epoch, sequence_number, length, fragment - ) + return cls(content_type, version, epoch, sequence_number, length, + fragment) def __repr__(self): return "Record(content_type={}, version={}, epoch={}, sequence_number={}, length={})".format( - str(self.content_type), self.version, self.epoch, self.sequence_number, self.length, ) + str(self.content_type), + self.version, + self.epoch, + self.sequence_number, + self.length, + ) class Message(ConvertibleToBytes, BuildableFromBytes): + def __init__(self, content_type): self.content_type = content_type @@ -141,6 +142,7 @@ class Message(ConvertibleToBytes, BuildableFromBytes): class HandshakeMessage(Message): + def __init__( self, handshake_type, @@ -159,14 +161,12 @@ class HandshakeMessage(Message): self.body = body def to_bytes(self): - return ( - struct.pack(">B", self.handshake_type) - + struct.pack(">I", self.length)[1:] - + struct.pack(">H", self.message_seq) - + struct.pack(">I", self.fragment_offset)[1:] - + struct.pack(">I", self.fragment_length)[1:] - + self.body.to_bytes() - ) + return (struct.pack(">B", self.handshake_type) + + struct.pack(">I", self.length)[1:] + + struct.pack(">H", self.message_seq) + + struct.pack(">I", self.fragment_offset)[1:] + + struct.pack(">I", self.fragment_length)[1:] + + self.body.to_bytes()) @classmethod def from_bytes(cls, data): @@ -196,22 +196,19 @@ class HandshakeMessage(Message): ) def __repr__(self): - return "Handshake(type={}, length={})".format( - str(self.handshake_type), self.length - ) + return "Handshake(type={}, length={})".format(str(self.handshake_type), + self.length) class ProtocolVersion(ConvertibleToBytes, BuildableFromBytes): + def __init__(self, major, minor): self.major = major self.minor = minor def __eq__(self, other): - return ( - isinstance(self, type(other)) - and self.major == other.major - and self.minor == other.minor - ) + return (isinstance(self, type(other)) and self.major == other.major and + self.minor == other.minor) def to_bytes(self): return struct.pack(">BB", self.major, self.minor) @@ -223,8 +220,7 @@ class ProtocolVersion(ConvertibleToBytes, BuildableFromBytes): def __repr__(self): return "ProtocolVersion(major={}, minor={})".format( - self.major, self.minor - ) + self.major, self.minor) class Random(ConvertibleToBytes, BuildableFromBytes): @@ -237,11 +233,9 @@ class Random(ConvertibleToBytes, BuildableFromBytes): assert len(self.random_bytes) == Random.random_bytes_length def __eq__(self, other): - return ( - isinstance(self, type(other)) - and self.gmt_unix_time == other.gmt_unix_time - and self.random_bytes == other.random_bytes - ) + return (isinstance(self, type(other)) and + self.gmt_unix_time == other.gmt_unix_time and + self.random_bytes == other.random_bytes) def to_bytes(self): return struct.pack(">I", self.gmt_unix_time) + (self.random_bytes) @@ -254,6 +248,7 @@ class Random(ConvertibleToBytes, BuildableFromBytes): class VariableVector(ConvertibleToBytes): + def __init__(self, subrange, ele_cls, elements): self.subrange = subrange self.ele_cls = ele_cls @@ -264,12 +259,10 @@ class VariableVector(ConvertibleToBytes): return len(self.elements) def __eq__(self, other): - return ( - isinstance(self, type(other)) - and self.subrange == other.subrange - and self.ele_cls == other.ele_cls - and self.elements == other.elements - ) + return (isinstance(self, type(other)) and + self.subrange == other.subrange and + self.ele_cls == other.ele_cls and + self.elements == other.elements) def to_bytes(self): data = reduce(lambda ele, acc: acc + ele.to_bytes(), self.elements) @@ -308,6 +301,7 @@ class VariableVector(ConvertibleToBytes): class Opaque(ConvertibleToBytes, BuildableFromBytes): + def __init__(self, byte): self.byte = byte @@ -323,6 +317,7 @@ class Opaque(ConvertibleToBytes, BuildableFromBytes): class CipherSuite(ConvertibleToBytes, BuildableFromBytes): + def __init__(self, cipher): self.cipher = cipher @@ -361,33 +356,29 @@ class CompressionMethod(ConvertibleToBytes, BuildableFromBytes): class Extension(ConvertibleToBytes, BuildableFromBytes): + def __init__(self, extension_type, extension_data): self.extension_type = extension_type self.extension_data = extension_data def __eq__(self, other): - return ( - isinstance(self, type(other)) - and self.extension_type == other.extension_type - and self.extension_data == other.extension_data - ) + return (isinstance(self, type(other)) and + self.extension_type == other.extension_type and + self.extension_data == other.extension_data) def to_bytes(self): - return ( - struct.pack(">H", self.extension_type) - + self.extension_data.to_bytes() - ) + return (struct.pack(">H", self.extension_type) + + self.extension_data.to_bytes()) @classmethod def from_bytes(cls, data): extension_type = struct.unpack(">H", data.read(2))[0] - extension_data = VariableVector.from_bytes( - Opaque, (0, 2 ** 16 - 1), data - ) + extension_data = VariableVector.from_bytes(Opaque, (0, 2**16 - 1), data) return cls(extension_type, extension_data) class ClientHello(HandshakeMessage): + def __init__( self, client_version, @@ -407,33 +398,26 @@ class ClientHello(HandshakeMessage): self.extensions = extensions def to_bytes(self): - return ( - self.client_version.to_bytes() - + self.random.to_bytes() - + self.session_id.to_bytes() - + self.cookie.to_bytes() - + self.cipher_suites.to_bytes() - + self.compression_methods.to_bytes() - + self.extensions.to_bytes() - ) + return (self.client_version.to_bytes() + self.random.to_bytes() + + self.session_id.to_bytes() + self.cookie.to_bytes() + + self.cipher_suites.to_bytes() + + self.compression_methods.to_bytes() + + self.extensions.to_bytes()) @classmethod def from_bytes(cls, data): client_version = ProtocolVersion.from_bytes(data) random = Random.from_bytes(data) session_id = VariableVector.from_bytes(Opaque, (0, 32), data) - cookie = VariableVector.from_bytes(Opaque, (0, 2 ** 8 - 1), data) - cipher_suites = VariableVector.from_bytes( - CipherSuite, (2, 2 ** 16 - 1), data - ) - compression_methods = VariableVector.from_bytes( - CompressionMethod, (1, 2 ** 8 - 1), data - ) + cookie = VariableVector.from_bytes(Opaque, (0, 2**8 - 1), data) + cipher_suites = VariableVector.from_bytes(CipherSuite, (2, 2**16 - 1), + data) + compression_methods = VariableVector.from_bytes(CompressionMethod, + (1, 2**8 - 1), data) extensions = None if data.tell() < len(data.getvalue()): - extensions = VariableVector.from_bytes( - Extension, (0, 2 ** 16 - 1), data - ) + extensions = VariableVector.from_bytes(Extension, (0, 2**16 - 1), + data) return cls( client_version, random, @@ -446,6 +430,7 @@ class ClientHello(HandshakeMessage): class HelloVerifyRequest(HandshakeMessage): + def __init__(self, server_version, cookie): self.server_version = server_version self.cookie = cookie @@ -456,11 +441,12 @@ class HelloVerifyRequest(HandshakeMessage): @classmethod def from_bytes(cls, data): server_version = ProtocolVersion.from_bytes(data) - cookie = VariableVector.from_bytes(Opaque, (0, 2 ** 8 - 1), data) + cookie = VariableVector.from_bytes(Opaque, (0, 2**8 - 1), data) return cls(server_version, cookie) class ServerHello(HandshakeMessage): + def __init__( self, server_version, @@ -478,14 +464,9 @@ class ServerHello(HandshakeMessage): self.extensions = extensions def to_bytes(self): - return ( - self.server_version.to_bytes() - + self.random.to_bytes() - + self.session_id.to_bytes() - + self.cipher_suite.to_bytes() - + self.compression_method.to_bytes() - + self.extensions.to_bytes() - ) + return (self.server_version.to_bytes() + self.random.to_bytes() + + self.session_id.to_bytes() + self.cipher_suite.to_bytes() + + self.compression_method.to_bytes() + self.extensions.to_bytes()) @classmethod def from_bytes(cls, data): @@ -496,9 +477,8 @@ class ServerHello(HandshakeMessage): compression_method = CompressionMethod.from_bytes(data) extensions = None if data.tell() < len(data.getvalue()): - extensions = VariableVector.from_bytes( - Extension, (0, 2 ** 16 - 1), data - ) + extensions = VariableVector.from_bytes(Extension, (0, 2**16 - 1), + data) return cls( server_version, random, @@ -510,6 +490,7 @@ class ServerHello(HandshakeMessage): class ServerHelloDone(HandshakeMessage): + def __init__(self): pass @@ -522,41 +503,49 @@ class ServerHelloDone(HandshakeMessage): class HelloRequest(HandshakeMessage): + def __init__(self): raise NotImplementedError class Certificate(HandshakeMessage): + def __init__(self): raise NotImplementedError class ServerKeyExchange(HandshakeMessage): + def __init__(self): raise NotImplementedError class CertificateRequest(HandshakeMessage): + def __init__(self): raise NotImplementedError class CertificateVerify(HandshakeMessage): + def __init__(self): raise NotImplementedError class ClientKeyExchange(HandshakeMessage): + def __init__(self): raise NotImplementedError class Finished(HandshakeMessage): + def __init__(self, verify_data): raise NotImplementedError class AlertMessage(Message): + def __init__(self, level, description): super(AlertMessage, self).__init__(ContentType.ALERT) self.level = level @@ -576,16 +565,15 @@ class AlertMessage(Message): return cls(None, None) def __repr__(self): - return "Alert(level={}, description={})".format( - str(self.level), str(self.description) - ) + return "Alert(level={}, description={})".format(str(self.level), + str(self.description)) class ChangeCipherSpecMessage(Message): + def __init__(self): - super(ChangeCipherSpecMessage, self).__init__( - ContentType.CHANGE_CIPHER_SPEC - ) + super(ChangeCipherSpecMessage, + self).__init__(ContentType.CHANGE_CIPHER_SPEC) def to_bytes(self): return struct.pack(">B", 1) @@ -600,10 +588,10 @@ class ChangeCipherSpecMessage(Message): class ApplicationDataMessage(Message): + def __init__(self, raw): - super(ApplicationDataMessage, self).__init__( - ContentType.APPLICATION_DATA - ) + super(ApplicationDataMessage, + self).__init__(ContentType.APPLICATION_DATA) self.raw = raw self.body = None @@ -638,7 +626,6 @@ handshake_map = { HandshakeType.FINISHED: None, # Finished } - content_map = { ContentType.CHANGE_CIPHER_SPEC: ChangeCipherSpecMessage, ContentType.ALERT: AlertMessage, @@ -665,11 +652,9 @@ class MessageFactory(object): raise ValueError("DTLS version error, expect DTLSv1.2") last_msg_is_change_cipher_spec = type( - self - ).last_msg_is_change_cipher_spec + self).last_msg_is_change_cipher_spec type(self).last_msg_is_change_cipher_spec = ( - record.content_type == ContentType.CHANGE_CIPHER_SPEC - ) + record.content_type == ContentType.CHANGE_CIPHER_SPEC) # FINISHED message immediately follows CHANGE_CIPHER_SPEC message # We skip FINISHED message as it is encrypted diff --git a/tests/scripts/thread-cert/ipv6.py b/tests/scripts/thread-cert/ipv6.py index 9e285de16..3068ab9c6 100644 --- a/tests/scripts/thread-cert/ipv6.py +++ b/tests/scripts/thread-cert/ipv6.py @@ -39,7 +39,6 @@ try: except ImportError: from itertools import zip_longest - # Next headers for IPv6 protocols IPV6_NEXT_HEADER_HOP_BY_HOP = 0 IPV6_NEXT_HEADER_TCP = 6 @@ -96,7 +95,6 @@ def calculate_checksum(data): class PacketFactory(object): - """ Interface for classes that produce objects from data. """ def parse(self, data, message_info): @@ -111,7 +109,6 @@ class PacketFactory(object): class BuildableFromBytes(object): - """ Interface for classes which can be built from bytes. """ @classmethod @@ -126,7 +123,6 @@ class BuildableFromBytes(object): class ConvertibleToBytes(object): - """ Interface for classes which can be converted to bytes. """ def to_bytes(self): @@ -147,7 +143,6 @@ class ConvertibleToBytes(object): class Header(object): - """ Interface for header classes. """ __metaclass__ = abc.ABCMeta @@ -162,7 +157,6 @@ class Header(object): class ExtensionHeader(object): - """ Base for classes representing Extension Headers in IPv6 packets. """ def __init__(self, next_header, hdr_ext_len=0): @@ -171,7 +165,6 @@ class ExtensionHeader(object): class UpperLayerProtocol(Header, ConvertibleToBytes): - """ Base for classes representing upper layer protocol payload in IPv6 packets. """ def __init__(self, header): @@ -200,7 +193,6 @@ class UpperLayerProtocol(Header, ConvertibleToBytes): class IPv6PseudoHeader(ConvertibleToBytes): - """ Class representing IPv6 pseudo header which is required to calculate upper layer protocol (like e.g. UDP or ICMPv6) checksum. @@ -208,13 +200,11 @@ class IPv6PseudoHeader(ConvertibleToBytes): """ - def __init__( - self, source_address, destination_address, payload_length, next_header - ): + def __init__(self, source_address, destination_address, payload_length, + next_header): self._source_address = self._convert_to_ipaddress(source_address) self._destination_address = self._convert_to_ipaddress( - destination_address - ) + destination_address) self.payload_length = payload_length self.next_header = next_header @@ -251,7 +241,6 @@ class IPv6PseudoHeader(ConvertibleToBytes): class IPv6Header(ConvertibleToBytes, BuildableFromBytes): - """ Class representing IPv6 packet header. """ _version = 6 @@ -271,8 +260,7 @@ class IPv6Header(ConvertibleToBytes, BuildableFromBytes): self.version = self._version self._source_address = self._convert_to_ipaddress(source_address) self._destination_address = self._convert_to_ipaddress( - destination_address - ) + destination_address) self.traffic_class = traffic_class self.flow_label = flow_label self.hop_limit = hop_limit @@ -298,16 +286,13 @@ class IPv6Header(ConvertibleToBytes, BuildableFromBytes): return self._destination_address def to_bytes(self): - data = bytearray( - [ - ((self.version & 0x0F) << 4) - | ((self.traffic_class >> 4) & 0x0F), - ((self.traffic_class & 0x0F) << 4) - | ((self.flow_label >> 16) & 0x0F), - ((self.flow_label >> 8) & 0xff), - ((self.flow_label & 0xff)), - ] - ) + data = bytearray([ + ((self.version & 0x0F) << 4) | ((self.traffic_class >> 4) & 0x0F), + ((self.traffic_class & 0x0F) << 4) | + ((self.flow_label >> 16) & 0x0F), + ((self.flow_label >> 8) & 0xff), + ((self.flow_label & 0xff)), + ]) data += struct.pack(">H", self.payload_length) data += bytearray([self.next_header, self.hop_limit]) data += self.source_address.packed @@ -356,7 +341,6 @@ class IPv6Header(ConvertibleToBytes, BuildableFromBytes): class IPv6Packet(ConvertibleToBytes): - """ Class representing IPv6 packet. IPv6 packet consists of IPv6 header, optional extension header, and upper layer protocol. @@ -402,16 +386,16 @@ class IPv6Packet(ConvertibleToBytes): """ - def __init__( - self, ipv6_header, upper_layer_protocol, extension_headers=None - ): + def __init__(self, + ipv6_header, + upper_layer_protocol, + extension_headers=None): self.ipv6_header = ipv6_header self.upper_layer_protocol = upper_layer_protocol - self.extension_headers = ( - extension_headers if extension_headers is not None else [] - ) + self.extension_headers = (extension_headers + if extension_headers is not None else []) self._update_next_header_values_in_headers() @@ -422,22 +406,17 @@ class IPv6Packet(ConvertibleToBytes): checksum = self.calculate_checksum() if self.upper_layer_protocol.checksum != checksum: - raise RuntimeError( - "Could not create IPv6 packet. " - "Invalid checksum: {}!={}".format( - self.upper_layer_protocol.checksum, checksum - ) - ) + raise RuntimeError("Could not create IPv6 packet. " + "Invalid checksum: {}!={}".format( + self.upper_layer_protocol.checksum, + checksum)) self.upper_layer_protocol.checksum = checksum def _update_payload_length_value_in_ipv6_header(self): - self.ipv6_header.payload_length = len(self.upper_layer_protocol) + sum( - [ - len(extension_header) - for extension_header in self.extension_headers - ] - ) + self.ipv6_header.payload_length = len(self.upper_layer_protocol) + sum([ + len(extension_header) for extension_header in self.extension_headers + ]) def _update_next_header_values_in_headers(self): last_header = self.ipv6_header @@ -464,9 +443,8 @@ class IPv6Packet(ConvertibleToBytes): self.upper_layer_protocol.type, ) - return calculate_checksum( - pseudo_header.to_bytes() + upper_layer_protocol_bytes - ) + return calculate_checksum(pseudo_header.to_bytes() + + upper_layer_protocol_bytes) def to_bytes(self): self._update_payload_length_value_in_ipv6_header() @@ -484,12 +462,10 @@ class IPv6Packet(ConvertibleToBytes): def __repr__(self): return "IPv6Packet(header={}, upper_layer_protocol={})".format( - self.ipv6_header, self.upper_layer_protocol - ) + self.ipv6_header, self.upper_layer_protocol) class UDPHeader(ConvertibleToBytes, BuildableFromBytes): - """ Class representing UDP datagram header. This header is required to construct UDP datagram. @@ -539,7 +515,6 @@ class UDPHeader(ConvertibleToBytes, BuildableFromBytes): class UDPDatagram(UpperLayerProtocol): - """ Class representing UDP datagram. UDP is an upper layer protocol for IPv6 so it can be passed to IPv6 packet as upper_layer_protocol. @@ -576,7 +551,6 @@ class UDPDatagram(UpperLayerProtocol): class ICMPv6Header(ConvertibleToBytes, BuildableFromBytes): - """ Class representing ICMPv6 message header. This header is required to construct ICMPv6 message. @@ -593,8 +567,7 @@ class ICMPv6Header(ConvertibleToBytes, BuildableFromBytes): def to_bytes(self): return bytearray([self.type, self.code]) + struct.pack( - ">H", self.checksum - ) + ">H", self.checksum) @classmethod def from_bytes(cls, data): @@ -609,7 +582,6 @@ class ICMPv6Header(ConvertibleToBytes, BuildableFromBytes): class ICMPv6(UpperLayerProtocol): - """ Class representing ICMPv6 message. ICMPv6 is an upper layer protocol for IPv6 so it can be passed to IPv6 packet as upper_layer_protocol. @@ -640,7 +612,6 @@ class ICMPv6(UpperLayerProtocol): class FragmentHeader(ExtensionHeader): - """ Class representing Fragment extension header. +-------------+----------+-----------------+-----+---+----------------+ @@ -653,6 +624,7 @@ class FragmentHeader(ExtensionHeader): - more_flag to indicate further data (1 bit) - identification for all associated fragments (32 bit) """ + @property def type(self): return 44 @@ -669,7 +641,11 @@ class FragmentHeader(ExtensionHeader): def offset(self): return self._fragm_offset - def __init__(self, next_header=None, fragm_offset=0, more_flag=False, identification=0): + def __init__(self, + next_header=None, + fragm_offset=0, + more_flag=False, + identification=0): super(FragmentHeader, self).__init__(next_header, 0) self._fragm_offset = fragm_offset self._more_flag = more_flag @@ -680,7 +656,10 @@ class FragmentHeader(ExtensionHeader): def to_bytes(self): data = bytearray([self.next_header, 0x00]) - data += bytearray([self._fragm_offset >> 5, ((self._fragm_offset << 3) | self._more_flag) & 0xff]) + data += bytearray([ + self._fragm_offset >> 5, + ((self._fragm_offset << 3) | self._more_flag) & 0xff + ]) data += struct.pack(">I", self._identification) return data @@ -688,7 +667,7 @@ class FragmentHeader(ExtensionHeader): @classmethod def from_bytes(cls, data): next_header = struct.unpack(">B", data.read(1))[0] - struct.unpack(">B", data.read(1))[0] # reserved + struct.unpack(">B", data.read(1))[0] # reserved fragment_offset = struct.unpack(">H", data.read(2))[0] more_flag = fragment_offset & 0x1 identificaton = struct.unpack(">I", data.read(4))[0] @@ -702,7 +681,6 @@ class FragmentHeader(ExtensionHeader): class HopByHop(ExtensionHeader): - """ Class representing HopByHop extension header. HopByHop extension header consists of: @@ -782,7 +760,6 @@ class HopByHop(ExtensionHeader): class HopByHopOptionHeader(ConvertibleToBytes, BuildableFromBytes): - """ Class representing HopByHop option header. """ _header_length = 2 @@ -805,12 +782,10 @@ class HopByHopOptionHeader(ConvertibleToBytes, BuildableFromBytes): def __repr__(self): return "HopByHopOptionHeader(type={}, length={})".format( - self.type, self.length - ) + self.type, self.length) class HopByHopOption(ConvertibleToBytes): - """ Class representing HopByHop option. Class consists of two elements: HopByHopOptionHeader and value (e.g. for MPLOption). @@ -838,12 +813,10 @@ class HopByHopOption(ConvertibleToBytes): def __repr__(self): return "HopByHopOption(header={}, value={})".format( - self.header, self.value - ) + self.header, self.value) class MPLOption(ConvertibleToBytes): - """ Class representing MPL option. """ _header_length = 2 @@ -858,11 +831,8 @@ class MPLOption(ConvertibleToBytes): self.seed_id = seed_id def to_bytes(self): - smv = ( - ((self.S & 0x03) << 6) - | ((self.M & 0x01) << 5) - | ((self.V & 0x01) << 4) - ) + smv = (((self.S & 0x03) << 6) | ((self.M & 0x01) << 5) | + ((self.V & 0x01) << 4)) return bytearray([smv, self.sequence]) + self.seed_id @@ -884,12 +854,10 @@ class MPLOption(ConvertibleToBytes): def __repr__(self): return "MPLOption(S={}, M={}, V={}, sequence={}, seed_id={})".format( - self.S, self.M, self.V, self.sequence, hexlify(self.seed_id) - ) + self.S, self.M, self.V, self.sequence, hexlify(self.seed_id)) class IPv6PacketFactory(PacketFactory): - """ Factory that produces IPv6 packets from data. This factory must be initialized with factories which allow to parse extension headers and upper layer protocols. @@ -950,20 +918,16 @@ class IPv6PacketFactory(PacketFactory): return self._ehf[next_header] except KeyError: raise RuntimeError( - "Could not get Extension Header factory for next_header={}.".format( - next_header - ) - ) + "Could not get Extension Header factory for next_header={}.". + format(next_header)) def _get_upper_layer_protocol_factory_for(self, next_header): try: return self._ulpf[next_header] except KeyError: raise RuntimeError( - "Could not get Upper Layer Protocol factory for next_header={}.".format( - next_header - ) - ) + "Could not get Upper Layer Protocol factory for next_header={}." + .format(next_header)) def _parse_extension_headers(self, data, next_header, message_info): extension_headers = [] @@ -991,34 +955,31 @@ class IPv6PacketFactory(PacketFactory): message_info.destination_ipv6 = ipv6_header.destination_address next_header, extension_headers = self._parse_extension_headers( - data, ipv6_header.next_header, message_info - ) + data, ipv6_header.next_header, message_info) upper_layer_protocol = self._parse_upper_layer_protocol( - data, next_header, message_info - ) + data, next_header, message_info) return IPv6Packet(ipv6_header, upper_layer_protocol, extension_headers) class HopByHopOptionsFactory(object): - """ Factory that produces HopByHop options. """ _one_byte_padding = 0x00 _many_bytes_padding = 0x01 def __init__(self, options_factories=None): - self._options_factories = ( - options_factories if options_factories is not None else {} - ) + self._options_factories = (options_factories + if options_factories is not None else {}) def _get_HopByHopOption_value_factory(self, _type): try: return self._options_factories[_type] except KeyError: raise RuntimeError( - "Could not find HopByHopOption value factory for type={}.".format(_type)) + "Could not find HopByHopOption value factory for type={}.". + format(_type)) def parse(self, data, message_info): options = [] @@ -1036,8 +997,7 @@ class HopByHopOptionsFactory(object): else: factory = self._get_HopByHopOption_value_factory( - option_header.type - ) + option_header.type) option_data = data.read(option_header.length) @@ -1052,7 +1012,6 @@ class HopByHopOptionsFactory(object): class HopByHopFactory(PacketFactory): - """ Factory that produces HopByHop extension headers from data. """ def __init__(self, hop_by_hop_options_factory): @@ -1069,14 +1028,12 @@ class HopByHopFactory(PacketFactory): # Note! Two bytes were read (next_header and hdr_ext_len) so they must # be substracted from header length hop_by_hop_length = ( - self._calculate_extension_header_length(hdr_ext_len) - 2 - ) + self._calculate_extension_header_length(hdr_ext_len) - 2) hop_by_hop_data = data.read(hop_by_hop_length) options = self._hop_by_hop_options_factory.parse( - io.BytesIO(hop_by_hop_data), message_info - ) + io.BytesIO(hop_by_hop_data), message_info) hop_by_hop = HopByHop(next_header, options, hdr_ext_len) @@ -1086,7 +1043,6 @@ class HopByHopFactory(PacketFactory): class MPLOptionFactory(PacketFactory): - """ Factory that produces MPL options for HopByHop extension header. """ def parse(self, data, message_info): @@ -1094,7 +1050,6 @@ class MPLOptionFactory(PacketFactory): class UDPHeaderFactory: - """ Factory that produces UDP header. """ def parse(self, data, message_info): @@ -1104,7 +1059,6 @@ class UDPHeaderFactory: class UdpBasedOnSrcDstPortsPayloadFactory: # TODO: Unittests - """ Factory that produces UDP payload. """ def __init__(self, src_dst_port_based_payload_factories): @@ -1134,7 +1088,6 @@ class UdpBasedOnSrcDstPortsPayloadFactory: class UDPDatagramFactory(PacketFactory): # TODO: Unittests - """ Factory that produces UDP datagrams. """ def __init__(self, udp_header_factory, udp_payload_factory): @@ -1145,9 +1098,8 @@ class UDPDatagramFactory(PacketFactory): header = self._udp_header_factory.parse(data, message_info) # Update message payload length: UDP header (8B) + payload length - message_info.payload_length += len(header) + ( - len(data.getvalue()) - data.tell() - ) + message_info.payload_length += len(header) + (len(data.getvalue()) - + data.tell()) message_info.src_port = header.src_port message_info.dst_port = header.dst_port @@ -1158,13 +1110,11 @@ class UDPDatagramFactory(PacketFactory): class ICMPv6Factory(PacketFactory): - """ Factory that produces ICMPv6 messages from data. """ def __init__(self, body_factories=None): - self._body_factories = ( - body_factories if body_factories is not None else {} - ) + self._body_factories = (body_factories + if body_factories is not None else {}) def _get_icmpv6_body_factory(self, _type): try: @@ -1174,15 +1124,12 @@ class ICMPv6Factory(PacketFactory): if "default" not in self._body_factories: raise RuntimeError( "Could not find specialized factory to parse ICMP body. " - "Unsupported ICMP type: {}".format(_type) - ) + "Unsupported ICMP type: {}".format(_type)) default_factory = self._body_factories["default"] - print( - "Could not find specialized factory to parse ICMP body. " - "Take the default one: {}".format(type(default_factory)) - ) + print("Could not find specialized factory to parse ICMP body. " + "Take the default one: {}".format(type(default_factory))) return default_factory @@ -1191,15 +1138,13 @@ class ICMPv6Factory(PacketFactory): factory = self._get_icmpv6_body_factory(header.type) - message_info.payload_length += len(header) + ( - len(data.getvalue()) - data.tell() - ) + message_info.payload_length += len(header) + (len(data.getvalue()) - + data.tell()) return ICMPv6(header, factory.parse(data, message_info)) class ICMPv6EchoBodyFactory(PacketFactory): - """ Factory that produces ICMPv6 echo message body. """ def parse(self, data, message_info): @@ -1207,7 +1152,6 @@ class ICMPv6EchoBodyFactory(PacketFactory): class BytesPayload(ConvertibleToBytes, BuildableFromBytes): - """ Class representing bytes payload. """ def __init__(self, data): @@ -1225,7 +1169,6 @@ class BytesPayload(ConvertibleToBytes, BuildableFromBytes): class BytesPayloadFactory(PacketFactory): - """ Factory that produces bytes payload. """ def parse(self, data, message_info): @@ -1233,7 +1176,6 @@ class BytesPayloadFactory(PacketFactory): class ICMPv6EchoBody(ConvertibleToBytes, BuildableFromBytes): - """ Class representing body of ICMPv6 echo messages. """ _header_length = 4 @@ -1261,7 +1203,6 @@ class ICMPv6EchoBody(ConvertibleToBytes, BuildableFromBytes): class ICMPv6DestinationUnreachableFactory(PacketFactory): - """ Factory that produces ICMPv6 echo message body. """ def parse(self, data, message_info): @@ -1269,7 +1210,6 @@ class ICMPv6DestinationUnreachableFactory(PacketFactory): class ICMPv6DestinationUnreachable(ConvertibleToBytes, BuildableFromBytes): - """ Class representing body of ICMPv6 Destination Unreachable messages. """ _header_length = 4 diff --git a/tests/scripts/thread-cert/lowpan.py b/tests/scripts/thread-cert/lowpan.py index 01fac9055..6dac3a948 100644 --- a/tests/scripts/thread-cert/lowpan.py +++ b/tests/scripts/thread-cert/lowpan.py @@ -116,7 +116,16 @@ class LowpanIPHC: def __repr__(self): return "LowpanIPHC(tf={}, nh={}, hlim={}, cid={}, sac={}, sam={}, m={}, dac={}, dam={})".format( - self.tf, self.nh, self.hlim, self.cid, self.sac, self.sam, self.m, self.dac, self.dam, ) + self.tf, + self.nh, + self.hlim, + self.cid, + self.sac, + self.sam, + self.m, + self.dac, + self.dam, + ) class LowpanNHC: @@ -201,7 +210,6 @@ class LowpanUDPHC: class LowpanHopByHopFactory: - """ Factory that produces HopByHop extension header. """ def __init__(self, hop_by_hop_options_factory): @@ -213,8 +221,7 @@ class LowpanHopByHopFactory: ext_header_data = data.read(ext_header_length) options = self._hop_by_hop_options_factory.parse( - io.BytesIO(ext_header_data), message_info - ) + io.BytesIO(ext_header_data), message_info) ext_header = ipv6.HopByHop(next_header, options) @@ -224,7 +231,6 @@ class LowpanHopByHopFactory: class LowpanExtensionHeadersFactory: - """ Factory that produces extension headers. """ NHC_NH_INLINE = 0 @@ -232,8 +238,7 @@ class LowpanExtensionHeadersFactory: def __init__(self, ext_headers_factories): self._ext_headers_factories = ( - ext_headers_factories if ext_headers_factories is not None else {} - ) + ext_headers_factories if ext_headers_factories is not None else {}) def _decompress_nh(self, hc, data): if hc.nh == self.NHC_NH_INLINE: @@ -248,10 +253,8 @@ class LowpanExtensionHeadersFactory: except BaseException: raise RuntimeError( - "Could not find an extension header factory for the EID type: {}".format( - eid - ) - ) + "Could not find an extension header factory for the EID type: {}" + .format(eid)) def parse(self, data, message_info): nhc = LowpanNHC.from_bytes(bytearray(data.read(1))) @@ -264,7 +267,6 @@ class LowpanExtensionHeadersFactory: class LowpanUdpHeaderFactory: - """ Factory producing UDP header. """ UDP_HC_C_INLINE = 0 @@ -317,6 +319,7 @@ class LowpanUdpHeaderFactory: class Context: + def __init__(self, prefix, prefix_length=None): if isinstance(prefix, str): prefix, prefix_length = prefix.split("/") @@ -329,19 +332,16 @@ class Context: elif isinstance(prefix, bytearray): self._prefix = prefix - self._prefix_length = ( - prefix_length - if prefix_length is not None - else len(self._prefix) * 8 - ) + self._prefix_length = (prefix_length if prefix_length is not None + else len(self._prefix) * 8) @property def prefix(self): - return self._prefix[: self.prefix_length_all_bytes] + return self._prefix[:self.prefix_length_all_bytes] @property def prefix_full_bytes(self): - return self._prefix[: self.prefix_length_full_bytes] + return self._prefix[:self.prefix_length_full_bytes] @property def prefix_length(self): @@ -364,16 +364,13 @@ class Context: class ContextManager(dict): - """ Class representing Context Manager. """ def __check_index(self, index): if index < 0 or index > 15: raise IndexError( "Invalid index: {}. Valid index is in range [0, 15]".format( - index - ) - ) + index)) def __check_type(self, value): if not isinstance(value, Context): @@ -392,12 +389,10 @@ class ContextManager(dict): class LowpanIpv6HeaderFactory: - """ Factory that produces IPv6 header. """ IPV6_LINKLOCAL_PREFIX = bytearray( - [0xfe, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00] - ) + [0xfe, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]) SHORT_ADDR_PADDING_BYTES = bytearray([0x00, 0x00, 0x00, 0xff, 0xfe, 0x00]) @@ -551,11 +546,8 @@ class LowpanIpv6HeaderFactory: return self.IPV6_LINKLOCAL_PREFIX + bytearray(data.read(8)) elif iphc.sam == self.IPHC_SAM_16B: - return ( - self.IPV6_LINKLOCAL_PREFIX - + self.SHORT_ADDR_PADDING_BYTES - + bytearray(data.read(2)) - ) + return (self.IPV6_LINKLOCAL_PREFIX + self.SHORT_ADDR_PADDING_BYTES + + bytearray(data.read(2))) elif iphc.sam == self.IPHC_SAM_ELIDED: return self.IPV6_LINKLOCAL_PREFIX + src_mac_addr.convert_to_iid() @@ -596,11 +588,9 @@ class LowpanIpv6HeaderFactory: address_overlapping_byte = address_bytes[-required_bytes] overlapping_byte = prefix_overlapping_byte & ~( - 0xff >> prefix_length_rest_bits - ) + 0xff >> prefix_length_rest_bits) overlapping_byte |= address_overlapping_byte & ( - 0xff >> prefix_length_rest_bits - ) + 0xff >> prefix_length_rest_bits) src_addr += bytearray([overlapping_byte]) required_bytes -= 1 @@ -612,11 +602,8 @@ class LowpanIpv6HeaderFactory: required_bytes -= prefix_length_all_bytes required_bytes -= len(address_bytes) - src_addr = ( - prefix[:prefix_length_all_bytes] - + bytearray([0x00] * required_bytes) - + address_bytes - ) + src_addr = (prefix[:prefix_length_all_bytes] + + bytearray([0x00] * required_bytes) + address_bytes) return src_addr @@ -636,8 +623,7 @@ class LowpanIpv6HeaderFactory: elif iphc.sam == self.IPHC_SAM_16B: context = self._context_manager[sci] address_bytes = self.SHORT_ADDR_PADDING_BYTES + bytearray( - data.read(2) - ) + data.read(2)) return self._merge_prefix_with_address( prefix=context.prefix, @@ -656,14 +642,11 @@ class LowpanIpv6HeaderFactory: def _decompress_src_addr(self, iphc, src_mac_addr, sci, data): if iphc.sac == self.IPHC_SAC_STATELESS: - return self._decompress_src_addr_stateless( - iphc, src_mac_addr, data - ) + return self._decompress_src_addr_stateless(iphc, src_mac_addr, data) elif iphc.sac == self.IPHC_SAC_STATEFUL: - return self._decompress_src_addr_stateful( - iphc, src_mac_addr, sci, data - ) + return self._decompress_src_addr_stateful(iphc, src_mac_addr, sci, + data) def _decompress_unicast_dst_addr_stateless(self, iphc, dst_mac_addr, data): if iphc.dam == self.IPHC_DAM_128B: @@ -673,18 +656,14 @@ class LowpanIpv6HeaderFactory: return self.IPV6_LINKLOCAL_PREFIX + bytearray(data.read(8)) elif iphc.dam == self.IPHC_DAM_16B: - return ( - self.IPV6_LINKLOCAL_PREFIX - + self.SHORT_ADDR_PADDING_BYTES - + bytearray(data.read(2)) - ) + return (self.IPV6_LINKLOCAL_PREFIX + self.SHORT_ADDR_PADDING_BYTES + + bytearray(data.read(2))) elif iphc.dam == self.IPHC_DAM_ELIDED: return self.IPV6_LINKLOCAL_PREFIX + dst_mac_addr.convert_to_iid() - def _decompress_unicast_dst_addr_stateful( - self, iphc, dst_mac_addr, dci, data - ): + def _decompress_unicast_dst_addr_stateful(self, iphc, dst_mac_addr, dci, + data): if iphc.dam == self.IPHC_DAM_128B: raise RuntimeError("Reserved") @@ -700,8 +679,7 @@ class LowpanIpv6HeaderFactory: elif iphc.dam == self.IPHC_DAM_16B: context = self._context_manager[dci] address_bytes = self.SHORT_ADDR_PADDING_BYTES + bytearray( - data.read(2) - ) + data.read(2)) return self._merge_prefix_with_address( prefix=context.prefix, @@ -721,13 +699,11 @@ class LowpanIpv6HeaderFactory: def _decompress_unicast_dst_addr(self, iphc, dst_mac_addr, dci, data): if iphc.dac == self.IPHC_DAC_STATELESS: return self._decompress_unicast_dst_addr_stateless( - iphc, dst_mac_addr, data - ) + iphc, dst_mac_addr, data) elif iphc.dac == self.IPHC_DAC_STATEFUL: return self._decompress_unicast_dst_addr_stateful( - iphc, dst_mac_addr, dci, data - ) + iphc, dst_mac_addr, dci, data) def _decompress_multicast_dst_addr_stateless(self, iphc, data): if iphc.dam == self.IPHC_DAM_128B: @@ -735,24 +711,17 @@ class LowpanIpv6HeaderFactory: elif iphc.dam == self.IPHC_DAM_48B: addr48b = bytearray(data.read(6)) - return ( - bytearray([0xff, addr48b[0]]) - + bytearray([0x00] * 9) - + addr48b[1:] - ) + return (bytearray([0xff, addr48b[0]]) + bytearray([0x00] * 9) + + addr48b[1:]) elif iphc.dam == self.IPHC_DAM_32B: addr32b = bytearray(data.read(4)) - return ( - bytearray([0xff, addr32b[0]]) - + bytearray([0x00] * 11) - + addr32b[1:] - ) + return (bytearray([0xff, addr32b[0]]) + bytearray([0x00] * 11) + + addr32b[1:]) elif iphc.dam == self.IPHC_DAM_8B: - return ( - bytearray([0xff, 0x02]) + bytearray([0x00] * 13) + data.read(1) - ) + return (bytearray([0xff, 0x02]) + bytearray([0x00] * 13) + + data.read(1)) def _decompress_multicast_dst_addr_stateful(self, iphc, dci, data): if iphc.dam == self.IPHC_M_DAM_00: @@ -770,13 +739,8 @@ class LowpanIpv6HeaderFactory: if missing_bytes > 0: prefix += bytearray([0x00] * missing_bytes) - return ( - bytearray([0xff]) - + addr48b[:2] - + bytearray([prefix_length]) - + prefix - + addr48b[2:] - ) + return (bytearray([0xff]) + addr48b[:2] + + bytearray([prefix_length]) + prefix + addr48b[2:]) elif iphc.dam == self.IPHC_M_DAM_01: raise RuntimeError("Reserved") @@ -792,15 +756,12 @@ class LowpanIpv6HeaderFactory: return self._decompress_multicast_dst_addr_stateless(iphc, data) elif iphc.dac == self.IPHC_DAC_STATEFUL: - return self._decompress_multicast_dst_addr_stateful( - iphc, dci, data - ) + return self._decompress_multicast_dst_addr_stateful(iphc, dci, data) def _decompress_dst_addr(self, iphc, dst_mac_addr, dci, data): if iphc.m == self.IPHC_M_NO: - return self._decompress_unicast_dst_addr( - iphc, dst_mac_addr, dci, data - ) + return self._decompress_unicast_dst_addr(iphc, dst_mac_addr, dci, + data) elif iphc.m == self.IPHC_M_YES: return self._decompress_multicast_dst_addr(iphc, dci, data) @@ -819,17 +780,15 @@ class LowpanIpv6HeaderFactory: hop_limit = self._decompress_hlim(iphc, data) - src_address = self._decompress_src_addr( - iphc, message_info.source_mac_address, sci, data - ) + src_address = self._decompress_src_addr(iphc, + message_info.source_mac_address, + sci, data) dst_address = self._decompress_dst_addr( - iphc, message_info.destination_mac_address, dci, data - ) + iphc, message_info.destination_mac_address, dci, data) - header = ipv6.IPv6Header( - src_address, dst_address, traffic_class, flow_label, hop_limit - ) + header = ipv6.IPv6Header(src_address, dst_address, traffic_class, + flow_label, hop_limit) header.next_header = next_header @@ -837,7 +796,6 @@ class LowpanIpv6HeaderFactory: class LowpanDecompressor: - """ Class decompressing 6LoWPAN packets. """ def __init__( @@ -848,8 +806,7 @@ class LowpanDecompressor: ): self._lowpan_ip_header_factory = lowpan_ip_header_factory self._lowpan_extension_headers_factory = ( - lowpan_extension_headers_factory - ) + lowpan_extension_headers_factory) self._lowpan_udp_header_factory = lowpan_udp_header_factory def _is_ipv6_extension_header(self, header_first_byte): @@ -897,8 +854,7 @@ class LowpanDecompressor: elif self._is_udp_header(header_first_byte): udp_header = self._lowpan_udp_header_factory.parse( - data, message_info - ) + data, message_info) # Update next header field in the previous header previous_header.next_header = udp_header.type @@ -910,12 +866,10 @@ class LowpanDecompressor: class LowpanMeshHeader(object): - """ Class representing 6LoWPAN mesh header (RFC 4944 5.2). """ - def __init__( - self, hops_left, originator_address, final_destination_address - ): + def __init__(self, hops_left, originator_address, + final_destination_address): self._hops_left = hops_left self._originator_address = originator_address self._final_destination_address = final_destination_address @@ -934,6 +888,7 @@ class LowpanMeshHeader(object): class LowpanMeshHeaderFactory: + def _parse_address(self, data, is_short): if is_short: return common.MacAddress.from_rloc16(bytearray(data.read(2))) @@ -951,19 +906,17 @@ class LowpanMeshHeaderFactory: else: hops_left = ord(data.read(1)) - originator_address = self._parse_address( - data, is_short_originator_address - ) + originator_address = self._parse_address(data, + is_short_originator_address) final_destination_address = self._parse_address( - data, is_short_final_destination_address - ) + data, is_short_final_destination_address) - return LowpanMeshHeader( - hops_left, originator_address, final_destination_address - ) + return LowpanMeshHeader(hops_left, originator_address, + final_destination_address) class LowpanFragmentationHeader(object): + def __init__(self, datagram_size, datagram_tag, datagram_offset=0): self._datagram_size = datagram_size self._datagram_tag = datagram_tag @@ -1001,6 +954,7 @@ class LowpanFragmentationHeader(object): class LowpanFragmentsBuffer(object): + def __init__(self, buffer_size): self._buffer = [None] * buffer_size self._position = 0 @@ -1034,8 +988,7 @@ class LowpanFragmentsBuffer(object): def read(self): if not self.whole_packet_received(): raise ValueError( - "Only a part of the packet has been stored in the buffer." - ) + "Only a part of the packet has been stored in the buffer.") return bytearray(self._buffer) @@ -1044,33 +997,31 @@ class LowpanFragmentsBuffer(object): class LowpanFragmentsBuffersManager(object): + def __init__(self): self._fragments_buffers = {} def _create_key(self, message_info, datagram_tag): - key = ( - bytes(message_info.source_mac_address.mac_address) - + bytes(message_info.destination_mac_address.mac_address) - + bytes(datagram_tag) - ) + key = (bytes(message_info.source_mac_address.mac_address) + + bytes(message_info.destination_mac_address.mac_address) + + bytes(datagram_tag)) return key def _allocate_fragments_buffer(self, key, datagram_size): if datagram_size is None or datagram_size < 0: raise ValueError( - "Could not allocate fragments buffer. Invalid datagram size: {}".format( - datagram_size - ) - ) + "Could not allocate fragments buffer. Invalid datagram size: {}" + .format(datagram_size)) fragments_buffer = LowpanFragmentsBuffer(datagram_size) self._fragments_buffers[key] = fragments_buffer return fragments_buffer - def get_fragments_buffer( - self, message_info, datagram_tag, datagram_size=None - ): + def get_fragments_buffer(self, + message_info, + datagram_tag, + datagram_size=None): key = self._create_key(message_info, datagram_tag) if key not in self._fragments_buffers: @@ -1085,6 +1036,7 @@ class LowpanFragmentsBuffersManager(object): class LowpanParser(object): + def __init__( self, lowpan_mesh_header_factory, @@ -1095,8 +1047,7 @@ class LowpanParser(object): self._lowpan_mesh_header_factory = lowpan_mesh_header_factory self._lowpan_decompressor = lowpan_decompressor self._lowpan_fragments_buffers_manager = ( - lowpan_fragements_buffers_manager - ) + lowpan_fragements_buffers_manager) self._ipv6_packet_factory = ipv6_packet_factory def _peek_n_bytes(self, data, n): @@ -1129,15 +1080,13 @@ class LowpanParser(object): ) ipv6_header, extension_headers, udp_header = self._decompress_iphc( - data, message_info - ) + data, message_info) uncompressed_data = data.read() # Update payload lengths ipv6_header.payload_length = fragmentation_header.datagram_size - len( - ipv6_header - ) + ipv6_header) fragments_buffer.seek(0) fragments_buffer.write(ipv6_header.to_bytes()) @@ -1154,8 +1103,7 @@ class LowpanParser(object): data = io.BytesIO(fragments_buffer.read()) self._lowpan_fragments_buffers_manager.free_fragments_buffer( - message_info, fragmentation_header.datagram_tag - ) + message_info, fragmentation_header.datagram_tag) return self._ipv6_packet_factory.parse(data, message_info) @@ -1179,8 +1127,7 @@ class LowpanParser(object): data = io.BytesIO(fragments_buffer.read()) self._lowpan_fragments_buffers_manager.free_fragments_buffer( - message_info, fragmentation_header.datagram_tag - ) + message_info, fragmentation_header.datagram_tag) return self._ipv6_packet_factory.parse(data, message_info) @@ -1188,8 +1135,7 @@ class LowpanParser(object): def _handle_iphc_header(self, data, message_info): ipv6_header, extension_headers, udp_header = self._decompress_iphc( - data, message_info - ) + data, message_info) uncompressed_data = data.read() @@ -1209,9 +1155,8 @@ class LowpanParser(object): decompressed_data = ipv6_header.to_bytes() + decompressed_data - return self._ipv6_packet_factory.parse( - io.BytesIO(decompressed_data), message_info - ) + return self._ipv6_packet_factory.parse(io.BytesIO(decompressed_data), + message_info) def set_lowpan_context(self, cid, prefix): self._lowpan_decompressor.set_lowpan_context(cid, prefix) @@ -1223,30 +1168,24 @@ class LowpanParser(object): if self._is_mesh_header(first_byte): mesh_header = self._lowpan_mesh_header_factory.parse( - data, message_info - ) + data, message_info) message_info.source_mac_address = ( - mesh_header.originator_address - ) + mesh_header.originator_address) message_info.destination_mac_address = ( - mesh_header.final_destination_address - ) + mesh_header.final_destination_address) elif self._is_first_fragmentation_header(first_byte): return self._handle_first_fragmentation_header( - data, message_info - ) + data, message_info) elif self._is_subsequent_fragmentation_header(first_byte): return self._handle_subsequent_fragmentation_header( - data, message_info - ) + data, message_info) elif self._is_iphc(first_byte): return self._handle_iphc_header(data, message_info) else: raise RuntimeError( - "Unsupported header type: 0x{:02x}".format(first_byte) - ) + "Unsupported header type: 0x{:02x}".format(first_byte)) diff --git a/tests/scripts/thread-cert/mac802154.py b/tests/scripts/thread-cert/mac802154.py index 7d117603c..98488f7c3 100644 --- a/tests/scripts/thread-cert/mac802154.py +++ b/tests/scripts/thread-cert/mac802154.py @@ -26,7 +26,6 @@ # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE # POSSIBILITY OF SUCH DAMAGE. # - """ This module provides simple 802.15.4 MAC parser. """ @@ -44,7 +43,6 @@ from net_crypto import ( class DeviceDescriptors: - """Class representing 802.15.4 Device Descriptors.""" device_descriptors = {} @@ -67,8 +65,8 @@ class DeviceDescriptors: class InformationElement: - """Class representing 802.15.4 MAC Information Element.""" + def __init__(self, id, length, content): self._id = id self._length = length @@ -88,7 +86,6 @@ class InformationElement: class MacHeader: - """Class representing 802.15.4 MAC header.""" class FrameType: @@ -141,7 +138,6 @@ class MacHeader: class MacPayload: - """Class representing 802.15.4 MAC payload.""" def __init__(self, data): @@ -149,7 +145,6 @@ class MacPayload: class MacFrame: - """Class representing 802.15.4 MAC frame.""" IEEE802154_HEADER_IE_TYPE_MASK = 0x8000 @@ -259,9 +254,8 @@ class MacFrame: data.seek(fcs_start) if aux_sec_header and aux_sec_header.security_level: - mic, payload_end = self._parse_mic( - data, aux_sec_header.security_level - ) + mic, payload_end = self._parse_mic(data, + aux_sec_header.security_level) else: payload_end = fcs_start mic = None @@ -272,22 +266,18 @@ class MacFrame: data.seek(cur_pos) while ie_present and cur_pos + 2 < payload_end: header_ie = struct.unpack("> 7 + id = (header_ie & MacFrame.IEEE802154_HEADER_IE_ID_MASK) >> 7 # Currently, payload IE doesn't exist in the code. So only HT2 is required. # TODO: support HT1 when there are Payload IEs in our code assert id != MacFrame.IEEE802154_HEADER_IE_HT1, \ 'Currently there should be no HT1!' - header_ie_length = ( - header_ie & MacFrame.IEEE802154_HEADER_IE_LENGTH_MASK - ) + header_ie_length = (header_ie & + MacFrame.IEEE802154_HEADER_IE_LENGTH_MASK) assert cur_pos + 2 + header_ie_length <= payload_end, \ 'Parsing Header IE error, IE id:{} length:{}'.format(id, header_ie_length) header_ie_content = data.read(header_ie_length) header_ie_list.append( - InformationElement(id, header_ie_length, header_ie_content) - ) + InformationElement(id, header_ie_length, header_ie_content)) cur_pos += 2 + header_ie_length if id == MacFrame.IEEE802154_HEADER_IE_HT2: break @@ -310,9 +300,7 @@ class MacFrame: if ie_present: data.seek(header_ie_start) - extra_open_fields += data.read( - header_ie_end - header_ie_start - ) + extra_open_fields += data.read(header_ie_end - header_ie_start) message_info = MessageInfo() message_info.aux_sec_hdr = aux_sec_header @@ -338,12 +326,10 @@ class MacFrame: message_info.source_mac_address = src_address.mac_address sec_obj = CryptoEngine( - MacCryptoMaterialCreator(config.DEFAULT_MASTER_KEY) - ) + MacCryptoMaterialCreator(config.DEFAULT_MASTER_KEY)) self.payload = MacPayload( - bytearray(open_payload) - + sec_obj.decrypt(private_payload, mic, message_info) - ) + bytearray(open_payload) + + sec_obj.decrypt(private_payload, mic, message_info)) else: self.payload = MacPayload(payload) @@ -372,14 +358,14 @@ class MacFrame: def _parse_address(self, data, mode): if mode == MacHeader.AddressMode.SHORT: - return MacAddress( - data.read(2), MacAddressType.SHORT, big_endian=False - ) + return MacAddress(data.read(2), + MacAddressType.SHORT, + big_endian=False) if mode == MacHeader.AddressMode.EXTENDED: - return MacAddress( - data.read(8), MacAddressType.LONG, big_endian=False - ) + return MacAddress(data.read(8), + MacAddressType.LONG, + big_endian=False) else: return None diff --git a/tests/scripts/thread-cert/mesh_cop.py b/tests/scripts/thread-cert/mesh_cop.py index f5abcb10f..36544f351 100644 --- a/tests/scripts/thread-cert/mesh_cop.py +++ b/tests/scripts/thread-cert/mesh_cop.py @@ -101,6 +101,7 @@ def create_mesh_cop_message_type_set(): # Channel TLV (0) class Channel(object): + def __init__(self, channel_page, channel): self._channel_page = channel_page self._channel = channel @@ -116,23 +117,20 @@ class Channel(object): def __eq__(self, other): common.expect_the_same_class(self, other) - return ( - self._channel_page == other._channel_page - and self._channel == other.__channel - ) + return (self._channel_page == other._channel_page and + self._channel == other.__channel) def __repr__(self): return 'Channel(channel_page={},channel={})'.format( - self._channel_page, self._channel - ) + self._channel_page, self._channel) def to_hex(self): - return struct.pack( - '>BBBH', TlvType.CHANNEL, 3, self.channel_page, self.channel - ) + return struct.pack('>BBBH', TlvType.CHANNEL, 3, self.channel_page, + self.channel) class ChannelFactory(object): + def parse(self, data, message_info): data_tp = struct.unpack('>BH', data.read(3)) channel_page = data_tp[0] @@ -155,6 +153,7 @@ class PanidFactory(object): # ExtendedPanid TLV (2) class ExtendedPanid(object): + def __init__(self, extended_panid): self._extended_panid = extended_panid @@ -163,16 +162,15 @@ class ExtendedPanid(object): return self._extended_panid def __eq__(self, other): - return ( - isinstance(self, type(other)) - and self.extended_panid == other.extended_panid - ) + return (isinstance(self, type(other)) and + self.extended_panid == other.extended_panid) def __repr__(self): return "ExtendedPanid(extended_panid={})".format(self.extended_panid) class ExtendedPanidFactory(object): + def parse(self, data, message_info): extended_panid = struct.unpack(">Q", data.read(8))[0] return ExtendedPanid(extended_panid) @@ -180,6 +178,7 @@ class ExtendedPanidFactory(object): # NetworkName TLV (3) class NetworkName(object): + def __init__(self, network_name): self._network_name = network_name @@ -188,16 +187,15 @@ class NetworkName(object): return self._network_name def __eq__(self, other): - return ( - isinstance(self, type(other)) - and self.network_name == other.network_name - ) + return (isinstance(self, type(other)) and + self.network_name == other.network_name) def __repr__(self): return "NetworkName(network_name={})".format(self.network_name) class NetworkNameFactory(object): + def parse(self, data, message_info): len = message_info.length network_name = struct.unpack("{}s".format(10), data.read(len))[0] @@ -258,6 +256,7 @@ class NetworkMeshLocalPrefixFactory(object): # Steering Data TLV (8) class SteeringData(object): + def __init__(self, bloom_filter): self._bloom_filter = bloom_filter @@ -272,18 +271,16 @@ class SteeringData(object): def __repr__(self): return "SteeringData(bloom_filter={})".format( - hexlify(self._bloom_filter) - ) + hexlify(self._bloom_filter)) def to_hex(self): bloom_filter_len = len(self.bloom_filter) - return ( - struct.pack('>BB', TlvType.STEERING_DATA, bloom_filter_len) - + self.bloom_filter - ) + return (struct.pack('>BB', TlvType.STEERING_DATA, bloom_filter_len) + + self.bloom_filter) class SteeringDataFactory: + def parse(self, data, message_info): bloom_filter = data.read(message_info.length) return SteeringData(bloom_filter) @@ -291,6 +288,7 @@ class SteeringDataFactory: # Border Agent Locator TLV (9) class BorderAgentLocator(object): + def __init__(self, address): self._border_agent_locator = address @@ -305,16 +303,15 @@ class BorderAgentLocator(object): def __repr__(self): return "BorderAgentLocator(rloc16={})".format( - hex(self._border_agent_locator) - ) + hex(self._border_agent_locator)) def to_hex(self): - return struct.pack( - '>BBH', TlvType.BORDER_AGENT_LOCATOR, 2, self.border_agent_locator - ) + return struct.pack('>BBH', TlvType.BORDER_AGENT_LOCATOR, 2, + self.border_agent_locator) class BorderAgentLocatorFactory: + def parse(self, data, message_info): border_agent_locator = struct.unpack(">H", data.read(2))[0] return BorderAgentLocator(border_agent_locator) @@ -322,6 +319,7 @@ class BorderAgentLocatorFactory: # CommissionerId TLV (10) class CommissionerId(object): + def __init__(self, commissioner_id): self._commissioner_id = commissioner_id @@ -333,12 +331,11 @@ class CommissionerId(object): return self.commissioner_id == other.commissioner_id def __repr__(self): - return "CommissionerId(commissioner_id={})".format( - self.commissioner_id - ) + return "CommissionerId(commissioner_id={})".format(self.commissioner_id) class CommissionerIdFactory(object): + def parse(self, data, message_info): commissioner_id = data.getvalue().decode('utf-8') return CommissionerId(commissioner_id) @@ -346,6 +343,7 @@ class CommissionerIdFactory(object): # Commissioner Session ID TLV (11) class CommissionerSessionId(object): + def __init__(self, commissioner_session_id): self._commissioner_session_id = commissioner_session_id @@ -360,8 +358,7 @@ class CommissionerSessionId(object): def __repr__(self): return "CommissionerSessionId(commissioner_session_id={})".format( - self._commissioner_session_id - ) + self._commissioner_session_id) def to_hex(self): return struct.pack( @@ -373,6 +370,7 @@ class CommissionerSessionId(object): class CommissionerSessionIdFactory: + def parse(self, data, message_info): session_id = struct.unpack(">H", data.read(2))[0] return CommissionerSessionId(session_id) @@ -419,6 +417,7 @@ class ActiveTimestampFactory(object): # Commissioner UDP Port TLV (15) class CommissionerUdpPort(object): + def __init__(self, udp_port): self._udp_port = udp_port @@ -436,6 +435,7 @@ class CommissionerUdpPort(object): class CommissionerUdpPortFactory: + def parse(self, data, message_info): udp_port = struct.unpack(">H", data.read(2))[0] return CommissionerUdpPort(udp_port) @@ -443,6 +443,7 @@ class CommissionerUdpPortFactory: # State TLV (16) class State(object): + def __init__(self, state): self._state = state @@ -458,6 +459,7 @@ class State(object): class StateFactory: + def parse(self, data, message_info): state = ord(data.read(1)) return State(state) @@ -478,6 +480,7 @@ class JoinerDtlsEncapsulationFactory(object): # JoinerUdpPort TLV (18) class JoinerUdpPort(object): + def __init__(self, udp_port): self._udp_port = udp_port @@ -486,15 +489,15 @@ class JoinerUdpPort(object): return self._udp_port def __eq__(self, other): - return ( - isinstance(self, type(other)) and self.udp_port == other.udp_port - ) + return (isinstance(self, type(other)) and + self.udp_port == other.udp_port) def __repr__(self): return "JoinerUdpPort(udp_port={})".format(self.udp_port) class JoinerUdpPortFactory(object): + def parse(self, data, message_info): udp_port = struct.unpack(">H", data.read(2))[0] return JoinerUdpPort(udp_port) @@ -541,6 +544,7 @@ class JoinerRouterKEKFactory(object): # ProvisioningURL TLV (32) class ProvisioningUrl(object): + def __init__(self, url): self._url = url @@ -553,6 +557,7 @@ class ProvisioningUrl(object): class ProvisioningUrlFactory: + def parse(self, data, message_info): url = data.decode('utf-8') return ProvisioningUrl(url) @@ -560,6 +565,7 @@ class ProvisioningUrlFactory: # VendorName TLV (33) class VendorName(object): + def __init__(self, vendor_name): self._vendor_name = vendor_name @@ -575,6 +581,7 @@ class VendorName(object): class VendorNameFactory: + def parse(self, data, message_info): vendor_name = data.getvalue().decode('utf-8') return VendorName(vendor_name) @@ -582,6 +589,7 @@ class VendorNameFactory: # VendorModel TLV (34) class VendorModel(object): + def __init__(self, vendor_model): self._vendor_model = vendor_model @@ -597,6 +605,7 @@ class VendorModel(object): class VendorModelFactory: + def parse(self, data, message_info): vendor_model = data.getvalue().decode('utf-8') return VendorModel(vendor_model) @@ -604,6 +613,7 @@ class VendorModelFactory: # VendorSWVersion TLV (35) class VendorSWVersion(object): + def __init__(self, vendor_sw_version): self._vendor_sw_version = vendor_sw_version @@ -615,12 +625,11 @@ class VendorSWVersion(object): return self.vendor_sw_version == other.vendor_sw_version def __repr__(self): - return "VendorName(vendor_sw_version={})".format( - self.vendor_sw_version - ) + return "VendorName(vendor_sw_version={})".format(self.vendor_sw_version) class VendorSWVersionFactory: + def parse(self, data, message_info): vendor_sw_version = data.getvalue() return VendorSWVersion(vendor_sw_version) @@ -628,6 +637,7 @@ class VendorSWVersionFactory: # VendorData TLV (36) class VendorData(object): + def __init__(self, data): self._vendor_data = data @@ -640,12 +650,14 @@ class VendorData(object): class VendorDataFactory(object): + def parse(self, data, message_info): return VendorData(data) # VendorStackVersion TLV (37) class VendorStackVersion(object): + def __init__(self, stack_vendor_oui, build, rev, minor, major): self._stack_vendor_oui = stack_vendor_oui self._build = build @@ -680,6 +692,7 @@ class VendorStackVersion(object): class VendorStackVersionFactory: + def parse(self, data, message_info): stack_vendor_oui = struct.unpack(">H", data.read(2))[0] rest = struct.unpack(">BBBB", data.read(4)) @@ -809,6 +822,7 @@ class EnergyListFactory(object): # Discovery Request TLV (128) class DiscoveryRequest(object): + def __init__(self, version, joiner_flag): self._version = version self._joiner_flag = joiner_flag @@ -822,19 +836,17 @@ class DiscoveryRequest(object): return self._joiner_flag def __eq__(self, other): - return ( - isinstance(self, type(other)) - and self.version == other.version - and self.joiner_flag == other.joiner_flag - ) + return (isinstance(self, type(other)) and + self.version == other.version and + self.joiner_flag == other.joiner_flag) def __repr__(self): return "DiscoveryRequest(version={}, joiner_flag={})".format( - self.version, self.joiner_flag - ) + self.version, self.joiner_flag) class DiscoveryRequestFactory(object): + def parse(self, data, message_info): data_byte = struct.unpack(">B", data.read(1))[0] version = (data_byte & 0xf0) >> 4 @@ -845,6 +857,7 @@ class DiscoveryRequestFactory(object): # Discovery Response TLV (128) class DiscoveryResponse(object): + def __init__(self, version, native_flag): self._version = version self._native_flag = native_flag @@ -858,19 +871,17 @@ class DiscoveryResponse(object): return self._native_flag def __eq__(self, other): - return ( - isinstance(self, type(other)) - and self.version == other.version - and self.native_flag == other.native_flag - ) + return (isinstance(self, type(other)) and + self.version == other.version and + self.native_flag == other.native_flag) def __repr__(self): return "DiscoveryResponse(version={}, native_flag={})".format( - self.version, self.native_flag - ) + self.version, self.native_flag) class DiscoveryResponseFactory(object): + def parse(self, data, message_info): data_byte = struct.unpack(">B", data.read(1))[0] version = (data_byte & 0xf0) >> 4 @@ -880,6 +891,7 @@ class DiscoveryResponseFactory(object): class MeshCopCommand(object): + def __init__(self, _type, tlvs): self._type = _type self._tlvs = tlvs @@ -907,6 +919,7 @@ def create_deault_mesh_cop_msg_type_map(): class MeshCopCommandFactory: + def __init__(self, tlvs_factories): self._tlvs_factories = tlvs_factories self._mesh_cop_msg_type_map = create_deault_mesh_cop_msg_type_map() @@ -920,26 +933,22 @@ class MeshCopCommandFactory: except KeyError: raise KeyError( "Could not find TLV factory. Unsupported TLV type: {}".format( - _type - ) - ) + _type)) def _parse_tlv(self, data): _type = TlvType(ord(data.read(1))) length = self._get_length(data) value = data.read(length) factory = self._get_tlv_factory(_type) - return factory.parse( - io.BytesIO(value), None - ) # message_info not needed here + return factory.parse(io.BytesIO(value), + None) # message_info not needed here def _get_mesh_cop_msg_type(self, msg_type_str): try: return self._mesh_cop_msg_type_map[msg_type_str] except KeyError: raise KeyError( - 'Mesh cop message type not found: {}'.format(msg_type_str) - ) + 'Mesh cop message type not found: {}'.format(msg_type_str)) def parse(self, cmd_type_str, data): cmd_type = self._get_mesh_cop_msg_type(cmd_type_str) @@ -965,5 +974,6 @@ def create_default_mesh_cop_tlv_factories(): class ThreadDiscoveryTlvsFactory(SubTlvsFactory): + def __init__(self, sub_tlvs_factories): super(ThreadDiscoveryTlvsFactory, self).__init__(sub_tlvs_factories) diff --git a/tests/scripts/thread-cert/message.py b/tests/scripts/thread-cert/message.py index 1556acc90..567ba3e79 100644 --- a/tests/scripts/thread-cert/message.py +++ b/tests/scripts/thread-cert/message.py @@ -53,6 +53,7 @@ class MessageType(IntEnum): class Message(object): + def __init__(self): self._type = None self._channel = None @@ -68,9 +69,8 @@ class Message(object): self._type = MessageType.MLE self._mle = udp_datagram.payload - elif isinstance( - udp_datagram.payload, (coap.CoapMessage, coap.CoapMessageProxy) - ): + elif isinstance(udp_datagram.payload, + (coap.CoapMessage, coap.CoapMessageProxy)): self._type = MessageType.COAP self._coap = udp_datagram.payload @@ -145,15 +145,12 @@ class Message(object): elif self._mac_header.frame_type == mac802154.MacHeader.FrameType.DATA: self._type = MessageType.DATA - elif ( - self._mac_header.frame_type - == mac802154.MacHeader.FrameType.COMMAND - ): + elif (self._mac_header.frame_type == + mac802154.MacHeader.FrameType.COMMAND): self._type = MessageType.COMMAND else: - raise ValueError( - 'Invalid mac frame type %d' % self._mac_header.frame_type - ) + raise ValueError('Invalid mac frame type %d' % + self._mac_header.frame_type) @property def ipv6_packet(self): @@ -257,15 +254,10 @@ class Message(object): break if contains_tlv: - print( - "MleMessage contains optional TLV: {}".format(tlv_class_type) - ) + print("MleMessage contains optional TLV: {}".format(tlv_class_type)) else: - print( - "MleMessage doesn't contain optional TLV: {}".format( - tlv_class_type - ) - ) + print("MleMessage doesn't contain optional TLV: {}".format( + tlv_class_type)) def get_coap_message_tlv(self, tlv_class_type): if self.type != MessageType.COAP: @@ -307,11 +299,8 @@ class Message(object): if isinstance(tlv, tlv_class_type): break - print( - "CoapMessage doesn't contain optional TLV: {}".format( - tlv_class_type - ) - ) + print("CoapMessage doesn't contain optional TLV: {}".format( + tlv_class_type)) def assertCoapMessageRequestUriPath(self, uri_path): if self.type != MessageType.COAP: @@ -340,24 +329,19 @@ class Message(object): elif self.mac_header.dest_address.type == common.MacAddressType.LONG: mac_address = common.MacAddress.from_eui64( - bytearray(node.get_addr64(), encoding="utf-8") - ) + bytearray(node.get_addr64(), encoding="utf-8")) if self.mac_header.dest_address == mac_address: sent_to_node = True assert sent_to_node def assertSentToDestinationAddress(self, ipv6_address): - assert ( - self.ipv6_packet.ipv6_header.destination_address - == ipaddress.ip_address(ipv6_address) - ) + assert (self.ipv6_packet.ipv6_header.destination_address == + ipaddress.ip_address(ipv6_address)) def assertSentFromSourceAddress(self, ipv6_address): - assert ( - self.ipv6_packet.ipv6_header.source_address - == ipaddress.ip_address(ipv6_address) - ) + assert (self.ipv6_packet.ipv6_header.source_address == + ipaddress.ip_address(ipv6_address)) def assertSentWithHopLimit(self, hop_limit): assert self.ipv6_packet.ipv6_header.hop_limit == hop_limit @@ -366,21 +350,19 @@ class Message(object): return self.mac_header.dest_address.type == common.MacAddressType.LONG def get_dst_udp_port(self): - assert isinstance( - self.ipv6_packet.upper_layer_protocol, ipv6.UDPDatagram - ) + assert isinstance(self.ipv6_packet.upper_layer_protocol, + ipv6.UDPDatagram) return self.ipv6_packet.upper_layer_protocol.header.dst_port def __repr__(self): - if ( - self.type == MessageType.DTLS - and self.dtls.content_type == dtls.ContentType.HANDSHAKE - ): + if (self.type == MessageType.DTLS and + self.dtls.content_type == dtls.ContentType.HANDSHAKE): return "Message(type={})".format(str(self.dtls.handshake_type)) return "Message(type={})".format(MessageType(self.type).name) class MessagesSet(object): + def __init__(self, messages, commissioning_messages=[]): self._messages = messages self._commissioning_messages = commissioning_messages @@ -413,9 +395,8 @@ class MessagesSet(object): break if assert_enabled: - assert ( - message is not None - ), "Could not find CoapMessage with code: {}".format(code) + assert (message is not None + ), "Could not find CoapMessage with code: {}".format(code) return message @@ -450,9 +431,10 @@ class MessagesSet(object): return message - def next_mle_message( - self, command_type, assert_enabled=True, sent_to_node=None - ): + def next_mle_message(self, + command_type, + assert_enabled=True, + sent_to_node=None): message = self.next_mle_message_of_one_of_command_types(command_type) if assert_enabled: @@ -524,21 +506,15 @@ class MessagesSet(object): continue if msg.dtls.content_type != content_type: continue - if ( - content_type == dtls.ContentType.HANDSHAKE - and msg.dtls.handshake_type != handshake_type - ): + if (content_type == dtls.ContentType.HANDSHAKE and + msg.dtls.handshake_type != handshake_type): continue return msg - t = ( - handshake_type - if content_type == dtls.ContentType.HANDSHAKE - else content_type - ) - raise ValueError( - "Could not find DTLS message of type: {}".format(str(t)) - ) + t = (handshake_type + if content_type == dtls.ContentType.HANDSHAKE else content_type) + raise ValueError("Could not find DTLS message of type: {}".format( + str(t))) def contains_icmp_message(self): for m in self.messages: @@ -586,6 +562,7 @@ class MessagesSet(object): class MessageFactory: + def __init__(self, lowpan_parser): self._lowpan_parser = lowpan_parser @@ -593,14 +570,12 @@ class MessageFactory: for tlv in message.mle.command.tlvs: if isinstance(tlv, mle.SourceAddress): - mac802154.DeviceDescriptors.add( - tlv.address, message.mac_header.src_address - ) + mac802154.DeviceDescriptors.add(tlv.address, + message.mac_header.src_address) if isinstance(tlv, mle.Address16): - mac802154.DeviceDescriptors.add( - tlv.address, message.mac_header.dest_address - ) + mac802154.DeviceDescriptors.add(tlv.address, + message.mac_header.dest_address) def _parse_mac_frame(self, data): mac_frame = mac802154.MacFrame() diff --git a/tests/scripts/thread-cert/mle.py b/tests/scripts/thread-cert/mle.py index 0f6e335a7..8a91dc91c 100644 --- a/tests/scripts/thread-cert/mle.py +++ b/tests/scripts/thread-cert/mle.py @@ -90,6 +90,7 @@ class TlvType(IntEnum): class SourceAddress(object): + def __init__(self, address): self._address = address @@ -107,12 +108,14 @@ class SourceAddress(object): class SourceAddressFactory: + def parse(self, data, message_info): address = struct.unpack(">H", data.read(2))[0] return SourceAddress(address) class Mode(object): + def __init__(self, receiver, secure, device_type, network_data): self._receiver = receiver self._secure = secure @@ -138,12 +141,10 @@ class Mode(object): def __eq__(self, other): common.expect_the_same_class(self, other) - return ( - self.receiver == other.receiver - and self.secure == other.secure - and self.device_type == other.device_type - and self.network_data == other.network_data - ) + return (self.receiver == other.receiver and + self.secure == other.secure and + self.device_type == other.device_type and + self.network_data == other.network_data) def __repr__(self): return "Mode(receiver={}, secure={}, device_type={}, network_data={})".format( @@ -151,6 +152,7 @@ class Mode(object): class ModeFactory: + def parse(self, data, message_info): mode = ord(data.read(1)) receiver = (mode >> 3) & 0x01 @@ -161,6 +163,7 @@ class ModeFactory: class Timeout(object): + def __init__(self, timeout): self._timeout = timeout @@ -178,12 +181,14 @@ class Timeout(object): class TimeoutFactory: + def parse(self, data, message_info): timeout = struct.unpack(">I", data.read(4))[0] return Timeout(timeout) class Challenge(object): + def __init__(self, challenge): self._challenge = challenge @@ -201,12 +206,14 @@ class Challenge(object): class ChallengeFactory: + def parse(self, data, message_info): challenge = data.read() return Challenge(challenge) class Response(object): + def __init__(self, response): self._response = response @@ -224,12 +231,14 @@ class Response(object): class ResponseFactory: + def parse(self, data, message_info): response = data.read() return Response(response) class LinkLayerFrameCounter(object): + def __init__(self, frame_counter): self._frame_counter = frame_counter @@ -244,17 +253,18 @@ class LinkLayerFrameCounter(object): def __repr__(self): return "LinkLayerFrameCounter(frame_counter={})".format( - self.frame_counter - ) + self.frame_counter) class LinkLayerFrameCounterFactory: + def parse(self, data, message_info): frame_counter = struct.unpack(">I", data.read(4))[0] return LinkLayerFrameCounter(frame_counter) class MleFrameCounter(object): + def __init__(self, frame_counter): self._frame_counter = frame_counter @@ -272,12 +282,14 @@ class MleFrameCounter(object): class MleFrameCounterFactory: + def parse(self, data, message_info): frame_counter = struct.unpack(">I", data.read(4))[0] return MleFrameCounter(frame_counter) class LinkQualityAndRouteData(object): + def __init__(self, output, _input, route): self._output = output self._input = _input @@ -298,19 +310,16 @@ class LinkQualityAndRouteData(object): def __eq__(self, other): common.expect_the_same_class(self, other) - return ( - self.output == other.output - and self.input == other.input - and self.route == other.route - ) + return (self.output == other.output and self.input == other.input and + self.route == other.route) def __repr__(self): return "LinkQualityAndRouteData(ouput={}, input={}, route={})".format( - self.output, self.input, self.route - ) + self.output, self.input, self.route) class LinkQualityAndRouteDataFactory: + def parse(self, data, message_info): lqrd = ord(data.read(1)) output = (lqrd >> 6) & 0x3 @@ -320,9 +329,9 @@ class LinkQualityAndRouteDataFactory: class Route64(object): - def __init__( - self, id_sequence, router_id_mask, link_quality_and_route_data - ): + + def __init__(self, id_sequence, router_id_mask, + link_quality_and_route_data): self._id_sequence = id_sequence self._router_id_mask = router_id_mask self._link_quality_and_route_data = link_quality_and_route_data @@ -342,22 +351,20 @@ class Route64(object): def __eq__(self, other): common.expect_the_same_class(self, other) - return ( - self.id_sequence == other.id_sequence - and self.router_id_mask == other.router_id_mask - and self.link_quality_and_route_data - == other.link_quality_and_route_data - ) + return (self.id_sequence == other.id_sequence and + self.router_id_mask == other.router_id_mask and + self.link_quality_and_route_data == + other.link_quality_and_route_data) def __repr__(self): lqrd_str = ", ".join( - ["{}".format(lqrd) for lqrd in self.link_quality_and_route_data] - ) + ["{}".format(lqrd) for lqrd in self.link_quality_and_route_data]) return "Route64(id_sequence={}, router_id_mask={}, link_quality_and_route_data=[{}])".format( self.id_sequence, hex(self.router_id_mask), lqrd_str) class Route64Factory: + def __init__(self, link_quality_and_route_data_factory): self._lqrd_factory = link_quality_and_route_data_factory @@ -369,15 +376,13 @@ class Route64Factory: while data.tell() < len(data.getvalue()): link_quality_and_route_data.append( - self._lqrd_factory.parse(data, message_info) - ) + self._lqrd_factory.parse(data, message_info)) - return Route64( - id_sequence, router_id_mask, link_quality_and_route_data - ) + return Route64(id_sequence, router_id_mask, link_quality_and_route_data) class Address16(object): + def __init__(self, address): self._address = address @@ -395,12 +400,14 @@ class Address16(object): class Address16Factory: + def parse(self, data, message_info): address = struct.unpack(">H", data.read(2))[0] return Address16(address) class LeaderData(object): + def __init__( self, partition_id, @@ -438,21 +445,26 @@ class LeaderData(object): def __eq__(self, other): common.expect_the_same_class(self, other) - return ( - self.partition_id == other.partition_id - and self.weighting == other.weighting - and self.data_version == other.data_version - and self.stable_data_version == other.stable_data_version - and self.leader_router_id == other.leader_router_id - ) + return (self.partition_id == other.partition_id and + self.weighting == other.weighting and + self.data_version == other.data_version and + self.stable_data_version == other.stable_data_version and + self.leader_router_id == other.leader_router_id) def __repr__(self): - return ("LeaderData(partition_id={}, weighting={}, data_version={}, stable_data_version={},", - "leader_router_id={})").format( - self.partition_id, self.weighting, self.data_version, self.stable_data_version, self.leader_router_id, ) + return ( + "LeaderData(partition_id={}, weighting={}, data_version={}, stable_data_version={},", + "leader_router_id={})").format( + self.partition_id, + self.weighting, + self.data_version, + self.stable_data_version, + self.leader_router_id, + ) class LeaderDataFactory: + def parse(self, data, message_info): partition_id = struct.unpack(">I", data.read(4))[0] weighting = ord(data.read(1)) @@ -469,6 +481,7 @@ class LeaderDataFactory: class NetworkData(object): + def __init__(self, tlvs): self._tlvs = tlvs @@ -487,6 +500,7 @@ class NetworkData(object): class NetworkDataFactory: + def __init__(self, network_data_tlvs_factory): self._tlvs_factory = network_data_tlvs_factory @@ -496,6 +510,7 @@ class NetworkDataFactory: class TlvRequest(object): + def __init__(self, tlvs): self._tlvs = tlvs @@ -514,12 +529,14 @@ class TlvRequest(object): class TlvRequestFactory: + def parse(self, data, message_info): tlvs = [b for b in bytearray(data.read())] return TlvRequest(tlvs) class ScanMask(object): + def __init__(self, router, end_device): self._router = router self._end_device = end_device @@ -535,17 +552,16 @@ class ScanMask(object): def __eq__(self, other): common.expect_the_same_class(self, other) - return ( - self.router == other.router and self.end_device == other.end_device - ) + return (self.router == other.router and + self.end_device == other.end_device) def __repr__(self): return "ScanMask(router={}, end_device={})".format( - self.router, self.end_device - ) + self.router, self.end_device) class ScanMaskFactory: + def parse(self, data, message_info): scan_mask = ord(data.read(1)) router = (scan_mask >> 7) & 0x01 @@ -554,6 +570,7 @@ class ScanMaskFactory: class Connectivity(object): + def __init__( self, pp, @@ -615,17 +632,15 @@ class Connectivity(object): def __eq__(self, other): common.expect_the_same_class(self, other) - return ( - self.pp == other.pp - and self.link_quality_3 == other.link_quality_3 - and self.link_quality_2 == other.link_quality_2 - and self.link_quality_1 == other.link_quality_1 - and self.leader_cost == other.leader_cost - and self.id_sequence == other.id_sequence - and self.active_routers == other.active_routers - and self.sed_buffer_size == other.sed_buffer_size - and self.sed_datagram_count == other.sed_datagram_count - ) + return (self.pp == other.pp and + self.link_quality_3 == other.link_quality_3 and + self.link_quality_2 == other.link_quality_2 and + self.link_quality_1 == other.link_quality_1 and + self.leader_cost == other.leader_cost and + self.id_sequence == other.id_sequence and + self.active_routers == other.active_routers and + self.sed_buffer_size == other.sed_buffer_size and + self.sed_datagram_count == other.sed_datagram_count) def __repr__(self): return r"Connectivity(pp={}, \ @@ -650,6 +665,7 @@ class Connectivity(object): class ConnectivityFactory: + def parse(self, data, message_info): pp = ord(data.read(1)) & 0x03 link_quality_3 = ord(data.read(1)) @@ -682,6 +698,7 @@ class ConnectivityFactory: class LinkMargin(object): + def __init__(self, link_margin): self._link_margin = link_margin @@ -699,12 +716,14 @@ class LinkMargin(object): class LinkMarginFactory: + def parse(self, data, message_info): link_margin = ord(data.read(1)) return LinkMargin(link_margin) class Status(object): + def __init__(self, status): self._status = status @@ -722,12 +741,14 @@ class Status(object): class StatusFactory: + def parse(self, data, message_info): status = ord(data.read(1)) return Status(status) class Version(object): + def __init__(self, version): self._version = version @@ -745,12 +766,14 @@ class Version(object): class VersionFactory: + def parse(self, data, message_info): version = struct.unpack(">H", data.read(2))[0] return Version(version) class AddressFull(object): + def __init__(self, ipv6_address): self._ipv6_address = ipv6_address @@ -764,12 +787,12 @@ class AddressFull(object): return self.ipv6_address == other.ipv6_address def __repr__(self): - return "AddressFull(ipv6_address={}')".format( - hexlify(self.ipv6_address) - ) + return "AddressFull(ipv6_address={}')".format(hexlify( + self.ipv6_address)) class AddressFullFactory: + def parse(self, data, message_info): data.read(1) # first byte is ignored ipv6_address = data.read(16) @@ -777,6 +800,7 @@ class AddressFullFactory: class AddressCompressed(object): + def __init__(self, cid, iid): self._cid = cid self._iid = iid @@ -796,11 +820,11 @@ class AddressCompressed(object): def __repr__(self): return "AddressCompressed(cid={}, iid={}')".format( - self.cid, hexlify(self.iid) - ) + self.cid, hexlify(self.iid)) class AddressCompressedFactory: + def parse(self, data, message_info): cid = ord(data.read(1)) & 0x0F iid = bytearray(data.read(8)) @@ -808,6 +832,7 @@ class AddressCompressedFactory: class AddressRegistration(object): + def __init__(self, addresses): self._addresses = addresses @@ -822,12 +847,12 @@ class AddressRegistration(object): def __repr__(self): addresses_str = ", ".join( - ["{}".format(address) for address in self.addresses] - ) + ["{}".format(address) for address in self.addresses]) return "AddressRegistration(addresses=[{}])".format(addresses_str) class AddressRegistrationFactory: + def __init__(self, addr_compressed_factory, addr_full_factory): self._addr_compressed_factory = addr_compressed_factory self._addr_full_factory = addr_full_factory @@ -841,17 +866,16 @@ class AddressRegistrationFactory: if compressed: addresses.append( - self._addr_compressed_factory.parse(data, message_info) - ) + self._addr_compressed_factory.parse(data, message_info)) else: addresses.append( - self._addr_full_factory.parse(data, message_info) - ) + self._addr_full_factory.parse(data, message_info)) return AddressRegistration(addresses) class Channel(object): + def __init__(self, channel_page, channel): self._channel_page = channel_page self._channel = channel @@ -867,18 +891,16 @@ class Channel(object): def __eq__(self, other): common.expect_the_same_class(self, other) - return ( - self.channel_page == other.channel_page - and self.channel == other.channel - ) + return (self.channel_page == other.channel_page and + self.channel == other.channel) def __repr__(self): return "Channel(channel_page={}, channel={})".format( - self.channel_page, self.channel - ) + self.channel_page, self.channel) class ChannelFactory: + def parse(self, data, message_info): channel_page = ord(data.read(1)) channel = struct.unpack(">H", data.read(2))[0] @@ -886,6 +908,7 @@ class ChannelFactory: class PanId: + def __init__(self, pan_id): self._pan_id = pan_id @@ -903,12 +926,14 @@ class PanId: class PanIdFactory: + def parse(self, data, message_info): pan_id = struct.unpack(">H", data.read(2))[0] return PanId(pan_id) class ActiveTimestamp(object): + def __init__(self, timestamp_seconds, timestamp_ticks, u): self._timestamp_seconds = timestamp_seconds self._timestamp_ticks = timestamp_ticks @@ -929,11 +954,9 @@ class ActiveTimestamp(object): def __eq__(self, other): common.expect_the_same_class(self, other) - return ( - self.timestamp_seconds == other.timestamp_seconds - and self.timestamp_ticks == other.timestamp_ticks - and self.u == other.u - ) + return (self.timestamp_seconds == other.timestamp_seconds and + self.timestamp_ticks == other.timestamp_ticks and + self.u == other.u) def __repr__(self): return "ActiveTimestamp(timestamp_seconds={}, timestamp_ticks={}, u={})".format( @@ -941,6 +964,7 @@ class ActiveTimestamp(object): class ActiveTimestampFactory: + def parse(self, data, message_info): seconds = bytearray([0x00, 0x00]) + bytearray(data.read(6)) ticks = struct.unpack(">H", data.read(2))[0] @@ -952,6 +976,7 @@ class ActiveTimestampFactory: class PendingTimestamp(object): + def __init__(self, timestamp_seconds, timestamp_ticks, u): self._timestamp_seconds = timestamp_seconds self._timestamp_ticks = timestamp_ticks @@ -972,11 +997,9 @@ class PendingTimestamp(object): def __eq__(self, other): common.expect_the_same_class(self, other) - return ( - self.timestamp_seconds == other.timestamp_seconds - and self.timestamp_ticks == other.timestamp_ticks - and self.u == other.u - ) + return (self.timestamp_seconds == other.timestamp_seconds and + self.timestamp_ticks == other.timestamp_ticks and + self.u == other.u) def __repr__(self): return "PendingTimestamp(timestamp_seconds={}, timestamp_ticks={}, u={})".format( @@ -984,6 +1007,7 @@ class PendingTimestamp(object): class PendingTimestampFactory: + def parse(self, data, message_info): seconds = bytearray([0x00, 0x00]) + bytearray(data.read(6)) ticks = struct.unpack(">H", data.read(2))[0] @@ -1002,6 +1026,7 @@ class ActiveOperationalDataset: class ActiveOperationalDatasetFactory: + def parse(self, data, message_info): return ActiveOperationalDataset() @@ -1014,11 +1039,13 @@ class PendingOperationalDataset: class PendingOperationalDatasetFactory: + def parse(self, data, message_info): return PendingOperationalDataset() class ThreadDiscovery(object): + def __init__(self, tlvs): self._tlvs = tlvs @@ -1034,6 +1061,7 @@ class ThreadDiscovery(object): class ThreadDiscoveryFactory: + def __init__(self, thread_discovery_tlvs_factory): self._tlvs_factory = thread_discovery_tlvs_factory @@ -1050,6 +1078,7 @@ class TimeRequest: class TimeRequestFactory: + def parse(self, data, message_info): return TimeRequest() @@ -1062,11 +1091,13 @@ class TimeParameter: class TimeParameterFactory: + def parse(self, data, message_info): return TimeParameter() class MleCommand(object): + def __init__(self, _type, tlvs): self._type = _type self._tlvs = tlvs @@ -1081,9 +1112,7 @@ class MleCommand(object): def __repr__(self): tlvs_str = ", ".join(["{}".format(tlv) for tlv in self.tlvs]) - return "MleCommand(type={}, tlvs=[{}])".format( - self.type.name, tlvs_str - ) + return "MleCommand(type={}, tlvs=[{}])".format(self.type.name, tlvs_str) class MleCommandFactory: @@ -1107,9 +1136,7 @@ class MleCommandFactory: except KeyError: raise KeyError( "Could not find TLV factory. Unsupported TLV type: {}".format( - _type - ) - ) + _type)) def _parse_tlv(self, data, message_info): _type = TlvType(ord(data.read(1))) @@ -1132,6 +1159,7 @@ class MleCommandFactory: class MleMessage(object): + def __init__(self, command): self._command = command @@ -1144,6 +1172,7 @@ class MleMessage(object): class MleMessageSecured(MleMessage): + def __init__(self, aux_sec_hdr, command, mic): super(MleMessageSecured, self).__init__(command) self._aux_sec_hdr = aux_sec_hdr @@ -1163,9 +1192,8 @@ class MleMessageSecured(MleMessage): class MleMessageFactory: - def __init__( - self, aux_sec_hdr_factory, mle_command_factory, crypto_engine - ): + + def __init__(self, aux_sec_hdr_factory, mle_command_factory, crypto_engine): self._aux_sec_hdr_factory = aux_sec_hdr_factory self._mle_command_factory = mle_command_factory self._crypto_engine = crypto_engine @@ -1176,17 +1204,14 @@ class MleMessageFactory: enc_data_length = len(data.getvalue()) enc_data = bytearray( - data.read( - enc_data_length - data.tell() - self._crypto_engine.mic_length - ) - ) + data.read(enc_data_length - data.tell() - + self._crypto_engine.mic_length)) mic = bytearray(data.read()) dec_data = self._crypto_engine.decrypt(enc_data, mic, message_info) - command = self._mle_command_factory.parse( - io.BytesIO(dec_data), message_info - ) + command = self._mle_command_factory.parse(io.BytesIO(dec_data), + message_info) return MleMessageSecured(aux_sec_hdr, command, mic) @@ -1206,7 +1231,5 @@ class MleMessageFactory: else: raise RuntimeError( - "Could not create MLE message. Unknown security indicator value: {}".format( - security_indicator - ) - ) + "Could not create MLE message. Unknown security indicator value: {}" + .format(security_indicator)) diff --git a/tests/scripts/thread-cert/net_crypto.py b/tests/scripts/thread-cert/net_crypto.py index 191fa0063..ed6a550c6 100644 --- a/tests/scripts/thread-cert/net_crypto.py +++ b/tests/scripts/thread-cert/net_crypto.py @@ -37,7 +37,6 @@ from Crypto.Cipher import AES class CryptoEngine: - """ Class responsible for encryption and decryption of data. """ def __init__(self, crypto_material_creator): @@ -134,6 +133,7 @@ class CryptoMaterialCreator(object): class MacCryptoMaterialCreator(CryptoMaterialCreator): + def __init__(self, master_key): """ Args: @@ -158,9 +158,8 @@ class MacCryptoMaterialCreator(CryptoMaterialCreator): """ return bytes(eui64 + struct.pack(">LB", frame_counter, security_level)) - def _create_authenticated_data( - self, mhr, auxiliary_security_header, extra_open_fields - ): + def _create_authenticated_data(self, mhr, auxiliary_security_header, + extra_open_fields): """ Create Authenticated Data Read more: 7.6.3.3 CCM prerequisites - Std 802.15.4-2006 @@ -178,8 +177,7 @@ class MacCryptoMaterialCreator(CryptoMaterialCreator): def create_key_and_nonce_and_authenticated_data(self, message_info): _, mac_key = self._generate_keys( - message_info.aux_sec_hdr.sequence_counter - ) + message_info.aux_sec_hdr.sequence_counter) nonce = self._create_nonce( message_info.source_mac_address, @@ -201,6 +199,7 @@ class MacCryptoMaterialCreator(CryptoMaterialCreator): class MleCryptoMaterialCreator(CryptoMaterialCreator): + def __init__(self, master_key): """ Args: @@ -223,14 +222,11 @@ class MleCryptoMaterialCreator(CryptoMaterialCreator): bytes: created Nonce """ - return bytes( - source_eui64[:8] - + struct.pack(">LB", frame_counter, security_level) - ) + return bytes(source_eui64[:8] + + struct.pack(">LB", frame_counter, security_level)) - def _create_authenticated_data( - self, source_address, destination_address, auxiliary_security_header - ): + def _create_authenticated_data(self, source_address, destination_address, + auxiliary_security_header): """ Create Authenticated Data Read more: 4.8 - Thread v1.0 Specification @@ -244,16 +240,12 @@ class MleCryptoMaterialCreator(CryptoMaterialCreator): bytes: Authenticated Data """ - return bytes( - source_address.packed - + destination_address.packed - + auxiliary_security_header - ) + return bytes(source_address.packed + destination_address.packed + + auxiliary_security_header) def create_key_and_nonce_and_authenticated_data(self, message_info): mle_key, _ = self._generate_keys( - message_info.aux_sec_hdr.sequence_counter - ) + message_info.aux_sec_hdr.sequence_counter) nonce = self._create_nonce( message_info.source_mac_address.mac_address, @@ -275,6 +267,7 @@ class MleCryptoMaterialCreator(CryptoMaterialCreator): class AuxiliarySecurityHeader: + def __init__( self, key_id_mode, @@ -313,9 +306,8 @@ class AuxiliarySecurityHeader: key_source = self.key_id[:4] format = ">I" if self._big_endian else "H", data.read(2))[0] @@ -118,6 +119,7 @@ class RouteFactory(object): class RoutesFactory(object): + def __init__(self, route_factory): self._route_factory = route_factory @@ -133,6 +135,7 @@ class RoutesFactory(object): class HasRoute(NetworkData): + def __init__(self, routes, stable): super(HasRoute, self).__init__(stable) self._routes = routes @@ -149,11 +152,11 @@ class HasRoute(NetworkData): def __repr__(self): routes_str = ", ".join(["{}".format(route) for route in self.routes]) return "HasRoute(stable={}, routes=[{}])".format( - self.stable, routes_str - ) + self.stable, routes_str) class HasRouteFactory(object): + def __init__(self, routes_factory): self._routes_factory = routes_factory @@ -164,6 +167,7 @@ class HasRouteFactory(object): class Prefix(NetworkData): + def __init__(self, domain_id, prefix_length, prefix, sub_tlvs, stable): super(Prefix, self).__init__(stable) self._domain_id = domain_id @@ -190,25 +194,29 @@ class Prefix(NetworkData): def __eq__(self, other): common.expect_the_same_class(self, other) - return ( - self.domain_id == other.domain_id - and self.prefix_length == other.prefix_length - and self.prefix == other.prefix - and self.sub_tlvs == other.sub_tlvs - ) + return (self.domain_id == other.domain_id and + self.prefix_length == other.prefix_length and + self.prefix == other.prefix and self.sub_tlvs == other.sub_tlvs) def __repr__(self): sub_tlvs_str = ", ".join(["{}".format(tlv) for tlv in self.sub_tlvs]) return "Prefix(stable={}, domain_id={}, prefix_length={}, prefix={}, sub_tlvs=[{}])".format( - self.stable, self.domain_id, self.prefix_length, hexlify(self.prefix), sub_tlvs_str, ) + self.stable, + self.domain_id, + self.prefix_length, + hexlify(self.prefix), + sub_tlvs_str, + ) class PrefixSubTlvsFactory(NetworkDataSubTlvsFactory): + def __init__(self, sub_tlvs_factories): super(PrefixSubTlvsFactory, self).__init__(sub_tlvs_factories) class PrefixFactory(object): + def __init__(self, sub_tlvs_factory): self._sub_tlvs_factory = sub_tlvs_factory @@ -222,16 +230,15 @@ class PrefixFactory(object): prefix = bytearray(data.read(self._bits_to_bytes(prefix_length))) - sub_tlvs = self._sub_tlvs_factory.parse( - io.BytesIO(data.read()), message_info - ) + sub_tlvs = self._sub_tlvs_factory.parse(io.BytesIO(data.read()), + message_info) - return Prefix( - domain_id, prefix_length, prefix, sub_tlvs, message_info.stable - ) + return Prefix(domain_id, prefix_length, prefix, sub_tlvs, + message_info.stable) class BorderRouter(NetworkData): + def __init__(self, border_router_16, prf, p, s, d, c, r, o, n, stable): super(BorderRouter, self).__init__(stable) self._border_router_16 = border_router_16 @@ -283,24 +290,29 @@ class BorderRouter(NetworkData): def __eq__(self, other): common.expect_the_same_class(self, other) - return ( - self.border_router_16 == other.border_router_16 - and self.prf == other.prf - and self.p == other.p - and self.s == other.s - and self.d == other.d - and self.c == other.c - and self.r == other.r - and self.o == other.o - and self.n == other.n - ) + return (self.border_router_16 == other.border_router_16 and + self.prf == other.prf and self.p == other.p and + self.s == other.s and self.d == other.d and + self.c == other.c and self.r == other.r and + self.o == other.o and self.n == other.n) def __repr__(self): return "BorderRouter(stable={}, border_router_16={}, prf={}, p={}, s={}, d={}, c={}, r={}, o={}, n={})".format( - self.stable, self.border_router_16, self.prf, self.p, self.s, self.d, self.c, self.r, self.o, self.n, ) + self.stable, + self.border_router_16, + self.prf, + self.p, + self.s, + self.d, + self.c, + self.r, + self.o, + self.n, + ) class BorderRouterFactory(object): + def parse(self, data, message_info): border_router_16 = struct.unpack(">H", data.read(2))[0] @@ -316,12 +328,12 @@ class BorderRouterFactory(object): data_byte = ord(data.read(1)) n = (data_byte >> 7) & 0x01 - return BorderRouter( - border_router_16, prf, p, s, d, c, r, o, n, message_info.stable - ) + return BorderRouter(border_router_16, prf, p, s, d, c, r, o, n, + message_info.stable) class LowpanId(NetworkData): + def __init__(self, c, cid, context_length, stable): super(LowpanId, self).__init__(stable) self._c = c @@ -343,19 +355,16 @@ class LowpanId(NetworkData): def __eq__(self, other): common.expect_the_same_class(self, other) - return ( - self.c == other.c - and self.cid == other.cid - and self.context_length == other.context_length - ) + return (self.c == other.c and self.cid == other.cid and + self.context_length == other.context_length) def __repr__(self): return "LowpanId(stable={}, c={}, cid={}, context_length={})".format( - self.stable, self.c, self.cid, self.context_length - ) + self.stable, self.c, self.cid, self.context_length) class LowpanIdFactory(object): + def parse(self, data, message_info): data_byte = ord(data.read(1)) @@ -368,6 +377,7 @@ class LowpanIdFactory(object): class CommissioningData(NetworkData): + def __init__(self, sub_tlvs, stable): super(CommissioningData, self).__init__(stable) self._sub_tlvs = sub_tlvs @@ -382,34 +392,32 @@ class CommissioningData(NetworkData): return self.sub_tlvs == other.sub_tlvs def __repr__(self): - sub_tlvs_str = ", ".format( - ["{}".format(tlv) for tlv in self._sub_tlvs] - ) + sub_tlvs_str = ", ".format(["{}".format(tlv) for tlv in self._sub_tlvs]) return "CommissioningData(stable={}, sub_tlvs=[{}])".format( - self._stable, sub_tlvs_str - ) + self._stable, sub_tlvs_str) class CommissioningDataSubTlvsFactory(SubTlvsFactory): + def __init__(self, sub_tlvs_factories): - super(CommissioningDataSubTlvsFactory, self).__init__( - sub_tlvs_factories - ) + super(CommissioningDataSubTlvsFactory, + self).__init__(sub_tlvs_factories) class CommissioningDataFactory(object): + def __init__(self, sub_tlvs_factory): self._sub_tlvs_factory = sub_tlvs_factory def parse(self, data, message_info): - sub_tlvs = self._sub_tlvs_factory.parse( - io.BytesIO(data.read()), message_info - ) + sub_tlvs = self._sub_tlvs_factory.parse(io.BytesIO(data.read()), + message_info) return CommissioningData(sub_tlvs, message_info.stable) class Service(NetworkData): + def __init__( self, t, @@ -455,29 +463,35 @@ class Service(NetworkData): def __eq__(self, other): common.expect_the_same_class(self, other) - return ( - self.t == other.t - and self.id == other.id - and self.enterprise_number == other.enterprise_number - and self.service_data_length == other.service_data_length - and self.service_data == other.service_data - and self.sub_tlvs == other.sub_tlvs - ) + return (self.t == other.t and self.id == other.id and + self.enterprise_number == other.enterprise_number and + self.service_data_length == other.service_data_length and + self.service_data == other.service_data and + self.sub_tlvs == other.sub_tlvs) def __repr__(self): sub_tlvs_str = ", ".format(["{}".format(tlv) for tlv in self.sub_tlvs]) - return ("LowpanId(stable={}, t={}, id={}, enterprise_number={}, service_data_length={}, service_data={},", - "sub_tlvs=[{}])").format( - self.stable, self.t, self.id, self.enterprise_number, self.service_data_length, self.service_data, - sub_tlvs_str, ) + return ( + "LowpanId(stable={}, t={}, id={}, enterprise_number={}, service_data_length={}, service_data={},", + "sub_tlvs=[{}])").format( + self.stable, + self.t, + self.id, + self.enterprise_number, + self.service_data_length, + self.service_data, + sub_tlvs_str, + ) class ServiceSubTlvsFactory(NetworkDataSubTlvsFactory): + def __init__(self, sub_tlvs_factories): super(ServiceSubTlvsFactory, self).__init__(sub_tlvs_factories) class ServiceFactory(object): + def __init__(self, sub_tlvs_factory): self._sub_tlvs_factory = sub_tlvs_factory @@ -490,9 +504,8 @@ class ServiceFactory(object): service_data_length = ord(data.read(1)) service_data = data.read(service_data_length) - sub_tlvs = self._sub_tlvs_factory.parse( - io.BytesIO(data.read()), message_info - ) + sub_tlvs = self._sub_tlvs_factory.parse(io.BytesIO(data.read()), + message_info) return Service( t, @@ -506,6 +519,7 @@ class ServiceFactory(object): class Server(NetworkData): + def __init__(self, server_16, server_data, stable): super(Server, self).__init__(stable) self._server_16 = server_16 @@ -522,18 +536,16 @@ class Server(NetworkData): def __eq__(self, other): common.expect_the_same_class(self, other) - return ( - self.server_16 == other.server_16 - and self.server_data == other.server_data - ) + return (self.server_16 == other.server_16 and + self.server_data == other.server_data) def __repr__(self): return "LowpanId(stable={}, server_16={}, server_data=b'{}')".format( - self.stable, self.server_16, hexlify(self.server_data) - ) + self.stable, self.server_16, hexlify(self.server_data)) class ServerFactory(object): + def parse(self, data, message_info): server_16 = struct.unpack(">H", data.read(2))[0] server_data = bytearray(data.read()) @@ -542,5 +554,6 @@ class ServerFactory(object): class NetworkDataTlvsFactory(NetworkDataSubTlvsFactory): + def __init__(self, sub_tlvs_factories): super(NetworkDataTlvsFactory, self).__init__(sub_tlvs_factories) diff --git a/tests/scripts/thread-cert/network_layer.py b/tests/scripts/thread-cert/network_layer.py index a84c6495b..4febac5dd 100644 --- a/tests/scripts/thread-cert/network_layer.py +++ b/tests/scripts/thread-cert/network_layer.py @@ -59,6 +59,7 @@ class StatusValues(IntEnum): class TargetEid(object): + def __init__(self, eid): self._eid = eid @@ -75,6 +76,7 @@ class TargetEid(object): class TargetEidFactory(object): + def parse(self, data, message_info): eid = bytearray(data.read(16)) @@ -82,6 +84,7 @@ class TargetEidFactory(object): class MacExtendedAddress(object): + def __init__(self, mac_address): self._mac_address = mac_address @@ -95,11 +98,11 @@ class MacExtendedAddress(object): def __repr__(self): return "MacExtendedAddress(mac_address={})".format( - hexlify(self.mac_address) - ) + hexlify(self.mac_address)) class MacExtendedAddressFactory(object): + def parse(self, data, message_info): mac_address = bytearray(data.read(8)) @@ -107,6 +110,7 @@ class MacExtendedAddressFactory(object): class Rloc16(object): + def __init__(self, rloc16): self._rloc16 = rloc16 @@ -123,6 +127,7 @@ class Rloc16(object): class Rloc16Factory(object): + def parse(self, data, message_info): rloc16 = struct.unpack(">H", data.read(2))[0] @@ -130,6 +135,7 @@ class Rloc16Factory(object): class MlEid(object): + def __init__(self, ml_eid): self._ml_eid = ml_eid @@ -146,6 +152,7 @@ class MlEid(object): class MlEidFactory(object): + def parse(self, data, message_info): ml_eid = bytearray(data.read(8)) @@ -153,6 +160,7 @@ class MlEidFactory(object): class Status(object): + def __init__(self, status): self._status = status @@ -169,6 +177,7 @@ class Status(object): class StatusFactory(object): + def parse(self, data, message_info): status = StatusValues(ord(data.read(1))) @@ -176,6 +185,7 @@ class StatusFactory(object): class TimeSinceLastTransaction(object): + def __init__(self, seconds): self._seconds = seconds @@ -192,6 +202,7 @@ class TimeSinceLastTransaction(object): class TimeSinceLastTransactionFactory(object): + def parse(self, data, message_info): seconds = struct.unpack(">L", data.read(4))[0] @@ -199,6 +210,7 @@ class TimeSinceLastTransactionFactory(object): class RouterMask(object): + def __init__(self, id_sequence, router_id_mask): self._id_sequence = id_sequence self._router_id_mask = router_id_mask @@ -213,18 +225,16 @@ class RouterMask(object): def __eq__(self, other): common.expect_the_same_class(self, other) - return ( - self.id_sequence == other.id_sequence - and self.router_id_mask == other.router_id_mask - ) + return (self.id_sequence == other.id_sequence and + self.router_id_mask == other.router_id_mask) def __repr__(self): return "RouterMask(id_sequence={}, router_id_mask={})".format( - self.id_sequence, hex(self.router_id_mask) - ) + self.id_sequence, hex(self.router_id_mask)) class RouterMaskFactory(object): + def parse(self, data, message_info): id_sequence = ord(data.read(1)) router_id_mask = struct.unpack(">Q", data.read(8))[0] @@ -233,6 +243,7 @@ class RouterMaskFactory(object): class NdOption(object): + def __init__(self, options): self._options = options @@ -245,12 +256,12 @@ class NdOption(object): return self.options == other.options def __repr__(self): - return "NdOption(options=[{}])".format( - ", ".join([str(opt) for opt in self.options]) - ) + return "NdOption(options=[{}])".format(", ".join( + [str(opt) for opt in self.options])) class NdOptionFactory(object): + def parse(self, data, message_info): options = [opt for opt in bytearray(data.read())] return NdOption(options) @@ -276,11 +287,13 @@ class XtalAccuracy: class XtalAccuracyFactory: + def parse(self, data, message_info): return XtalAccuracy() class ThreadNetworkData(object): + def __init__(self, tlvs): self._tlvs = tlvs @@ -293,12 +306,12 @@ class ThreadNetworkData(object): return self.tlvs == other.tlvs def __repr__(self): - return "ThreadNetworkData(tlvs=[{}])".format( - ", ".join([str(tlv) for tlv in self.tlvs]) - ) + return "ThreadNetworkData(tlvs=[{}])".format(", ".join( + [str(tlv) for tlv in self.tlvs])) class ThreadNetworkDataFactory(object): + def __init__(self, network_data_tlvs_factory): self._network_data_tlvs_factory = network_data_tlvs_factory diff --git a/tests/scripts/thread-cert/node.py b/tests/scripts/thread-cert/node.py index 70110ba1d..62a1e7f5f 100755 --- a/tests/scripts/thread-cert/node.py +++ b/tests/scripts/thread-cert/node.py @@ -41,6 +41,7 @@ import unittest class Node: + def __init__(self, nodeid, is_mtd=False, simulator=None): self.nodeid = nodeid self.verbose = int(float(os.getenv('VERBOSE', 0))) @@ -147,8 +148,7 @@ class Node: serialPort = '/dev/ttyUSB%d' % ((nodeid - 1) * 2) self.pexpect = fdpexpect.fdspawn( - os.open(serialPort, os.O_RDWR | os.O_NONBLOCK | os.O_NOCTTY) - ) + os.open(serialPort, os.O_RDWR | os.O_NONBLOCK | os.O_NOCTTY)) def __del__(self): self.destroy() @@ -157,12 +157,9 @@ class Node: if not self._initialized: return - if ( - hasattr(self.pexpect, 'proc') - and self.pexpect.proc.poll() is None - or not hasattr(self.pexpect, 'proc') - and self.pexpect.isalive() - ): + if (hasattr(self.pexpect, 'proc') and self.pexpect.proc.poll() is None + or + not hasattr(self.pexpect, 'proc') and self.pexpect.isalive()): print("%d: exit" % self.nodeid) self.pexpect.send('exit\n') self.pexpect.expect(pexpect.EOF) @@ -178,17 +175,8 @@ class Node: dummy_format_str = br"\[THCI\].*?type=%s.*?" join_ent_ntf = dummy_format_str % br"JOIN_ENT\.ntf" join_ent_rsp = dummy_format_str % br"JOIN_ENT\.rsp" - pattern = ( - b"(" - + join_fin_req - + b")|(" - + join_fin_rsp - + b")|(" - + join_ent_ntf - + b")|(" - + join_ent_rsp - + b")" - ) + pattern = (b"(" + join_fin_req + b")|(" + join_fin_rsp + b")|(" + + join_ent_ntf + b")|(" + join_ent_rsp + b")") messages = [] # There are at most 4 cert messages both for joiner and commissioner @@ -580,12 +568,8 @@ class Node: addrs = self.get_addrs() for addr in addrs: segs = addr.split(':') - if ( - segs[4] == '0' - and segs[5] == 'ff' - and segs[6] == 'fe00' - and segs[7] == 'fc00' - ): + if (segs[4] == '0' and segs[5] == 'ff' and segs[6] == 'fe00' and + segs[7] == 'fc00'): return addr return None @@ -628,47 +612,32 @@ class Node: def __getGlobalAddress(self): global_address = [] for ip6Addr in self.get_addrs(): - if ( - (not re.match(config.LINK_LOCAL_REGEX_PATTERN, ip6Addr, re.I)) - and ( - not re.match( - config.MESH_LOCAL_PREFIX_REGEX_PATTERN, ip6Addr, re.I - ) - ) - and ( - not re.match( - config.ROUTING_LOCATOR_REGEX_PATTERN, ip6Addr, re.I - ) - ) - ): + if ((not re.match(config.LINK_LOCAL_REGEX_PATTERN, ip6Addr, re.I)) + and (not re.match(config.MESH_LOCAL_PREFIX_REGEX_PATTERN, + ip6Addr, re.I)) and + (not re.match(config.ROUTING_LOCATOR_REGEX_PATTERN, ip6Addr, + re.I))): global_address.append(ip6Addr) return global_address def __getRloc(self): for ip6Addr in self.get_addrs(): - if ( - re.match(config.MESH_LOCAL_PREFIX_REGEX_PATTERN, ip6Addr, re.I) - and re.match( - config.ROUTING_LOCATOR_REGEX_PATTERN, ip6Addr, re.I - ) - and not ( - re.match(config.ALOC_FLAG_REGEX_PATTERN, ip6Addr, re.I) - ) - ): + if (re.match(config.MESH_LOCAL_PREFIX_REGEX_PATTERN, ip6Addr, re.I) + and re.match(config.ROUTING_LOCATOR_REGEX_PATTERN, ip6Addr, + re.I) and + not (re.match(config.ALOC_FLAG_REGEX_PATTERN, ip6Addr, + re.I))): return ip6Addr return None def __getAloc(self): aloc = [] for ip6Addr in self.get_addrs(): - if ( - re.match(config.MESH_LOCAL_PREFIX_REGEX_PATTERN, ip6Addr, re.I) - and re.match( - config.ROUTING_LOCATOR_REGEX_PATTERN, ip6Addr, re.I - ) - and re.match(config.ALOC_FLAG_REGEX_PATTERN, ip6Addr, re.I) - ): + if (re.match(config.MESH_LOCAL_PREFIX_REGEX_PATTERN, ip6Addr, re.I) + and re.match(config.ROUTING_LOCATOR_REGEX_PATTERN, ip6Addr, + re.I) and + re.match(config.ALOC_FLAG_REGEX_PATTERN, ip6Addr, re.I)): aloc.append(ip6Addr) return aloc @@ -676,10 +645,9 @@ class Node: def __getMleid(self): for ip6Addr in self.get_addrs(): if re.match( - config.MESH_LOCAL_PREFIX_REGEX_PATTERN, ip6Addr, re.I - ) and not ( - re.match(config.ROUTING_LOCATOR_REGEX_PATTERN, ip6Addr, re.I) - ): + config.MESH_LOCAL_PREFIX_REGEX_PATTERN, ip6Addr, + re.I) and not (re.match( + config.ROUTING_LOCATOR_REGEX_PATTERN, ip6Addr, re.I)): return ip6Addr return None @@ -780,12 +748,10 @@ class Node: results = [] while True: - i = self._expect( - [ - r'\|\s(\S+)\s+\|\s(\S+)\s+\|\s([0-9a-fA-F]{4})\s\|\s([0-9a-fA-F]{16})\s\|\s(\d+)\r?\n', - 'Done', - ] - ) + i = self._expect([ + r'\|\s(\S+)\s+\|\s(\S+)\s+\|\s([0-9a-fA-F]{4})\s\|\s([0-9a-fA-F]{16})\s\|\s(\d+)\r?\n', + 'Done', + ]) if i == 0: results.append(self.pexpect.match.groups()) else: @@ -865,9 +831,11 @@ class Node: self.send_command('dataset commit active') self._expect('Done') - def set_pending_dataset( - self, pendingtimestamp, activetimestamp, panid=None, channel=None - ): + def set_pending_dataset(self, + pendingtimestamp, + activetimestamp, + panid=None, + channel=None): self.send_command('dataset clear') self._expect('Done') diff --git a/tests/scripts/thread-cert/pcap.py b/tests/scripts/thread-cert/pcap.py index 8887b493f..d47881168 100644 --- a/tests/scripts/thread-cert/pcap.py +++ b/tests/scripts/thread-cert/pcap.py @@ -26,7 +26,6 @@ # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE # POSSIBILITY OF SUCH DAMAGE. # - """ Module to provide codec utilities for .pcap formatters. """ import struct diff --git a/tests/scripts/thread-cert/simulator.py b/tests/scripts/thread-cert/simulator.py index fb23ec558..449a3abad 100644 --- a/tests/scripts/thread-cert/simulator.py +++ b/tests/scripts/thread-cert/simulator.py @@ -48,12 +48,12 @@ def dbg_print(*args): class BaseSimulator(object): + def __init__(self): self._nodes = {} self.commissioning_messages = {} self._payload_parse_factory = mesh_cop.MeshCopCommandFactory( - mesh_cop.create_default_mesh_cop_tlv_factories() - ) + mesh_cop.create_default_mesh_cop_tlv_factories()) self._mesh_cop_msg_set = mesh_cop.create_mesh_cop_message_type_set() def __del__(self): @@ -81,18 +81,18 @@ class BaseSimulator(object): if not node: continue for ( - direction, - type, - payload, + direction, + type, + payload, ) in node.read_cert_messages_in_commissioning_log(): if direction == b'send': msg = self._payload_parse_factory.parse( - type.decode("utf-8"), io.BytesIO(payload) - ) + type.decode("utf-8"), io.BytesIO(payload)) self.commissioning_messages[nodeid].append(msg) class RealTime(BaseSimulator): + def __init__(self): super(RealTime, self).__init__() self._sniffer = config.create_default_thread_sniffer() @@ -103,9 +103,7 @@ class RealTime(BaseSimulator): def get_messages_sent_by(self, nodeid): messages = self._sniffer.get_messages_sent_by(nodeid).messages - ret = message.MessagesSet( - messages, self.commissioning_messages[nodeid] - ) + ret = message.MessagesSet(messages, self.commissioning_messages[nodeid]) self.commissioning_messages[nodeid] = [] return ret @@ -207,9 +205,7 @@ class VirtualTime(BaseSimulator): messages = self.devices[addr]['msgs'] self.devices[addr]['msgs'] = [] - ret = message.MessagesSet( - messages, self.commissioning_messages[nodeid] - ) + ret = message.MessagesSet(messages, self.commissioning_messages[nodeid]) self.commissioning_messages[nodeid] = [] return ret @@ -239,14 +235,9 @@ class VirtualTime(BaseSimulator): def receive_events(self): """ Receive events until all devices are asleep. """ while True: - if ( - self.current_event - or len(self.awake_devices) - or ( - self._next_event_time() > self._pause_time - and self.current_nodeid - ) - ): + if (self.current_event or len(self.awake_devices) or + (self._next_event_time() > self._pause_time and + self.current_nodeid)): self.sock.settimeout(self.BLOCK_TIMEOUT) try: msg, addr = self.sock.recvfrom(self.MAX_MESSAGE) @@ -311,10 +302,8 @@ class VirtualTime(BaseSimulator): self.awake_devices.discard(addr) - if ( - self.current_event - and self.current_event[self.EVENT_ADDR] == addr - ): + if (self.current_event and + self.current_event[self.EVENT_ADDR] == addr): # print "Done\t", self.current_event self.current_event = None @@ -335,9 +324,8 @@ class VirtualTime(BaseSimulator): # print "-- Enqueue\t", event bisect.insort(self.event_queue, event) - self._pcap.append( - data, (event_time // 1000000, event_time % 1000000) - ) + self._pcap.append(data, + (event_time // 1000000, event_time % 1000000)) self._add_message(addr[1] - self.port, data) # add radio transmit done events to event queue @@ -461,9 +449,8 @@ class VirtualTime(BaseSimulator): continue dbg_print('syncing', addr, elapsed) self.devices[addr]['time'] = self.current_time - message = struct.pack( - '=QBH', elapsed, self.OT_SIM_EVENT_ALARM_FIRED, 0 - ) + message = struct.pack('=QBH', elapsed, + self.OT_SIM_EVENT_ALARM_FIRED, 0) self._send_message(message, addr) self.awake_devices.add(addr) self.receive_events() diff --git a/tests/scripts/thread-cert/sniffer.py b/tests/scripts/thread-cert/sniffer.py index 5bfbb825f..d6ad885a8 100644 --- a/tests/scripts/thread-cert/sniffer.py +++ b/tests/scripts/thread-cert/sniffer.py @@ -45,7 +45,6 @@ import sniffer_transport class Sniffer: - """ Class representing the Sniffing node, whose main task is listening and logging message exchange performed by other nodes. """ diff --git a/tests/scripts/thread-cert/sniffer_transport.py b/tests/scripts/thread-cert/sniffer_transport.py index 6f443d3bb..f5d9ca1b9 100644 --- a/tests/scripts/thread-cert/sniffer_transport.py +++ b/tests/scripts/thread-cert/sniffer_transport.py @@ -110,16 +110,14 @@ class SnifferSocketTransport(SnifferTransport): def _nodeid_to_address(self, nodeid, ip_address=''): return ( ip_address, - self.BASE_PORT - + (self.PORT_OFFSET * self.WELLKNOWN_NODE_ID) - + nodeid, + self.BASE_PORT + (self.PORT_OFFSET * self.WELLKNOWN_NODE_ID) + + nodeid, ) def _address_to_nodeid(self, address): _, port = address - return ( - port - self.BASE_PORT - (self.PORT_OFFSET * self.WELLKNOWN_NODE_ID) - ) + return (port - self.BASE_PORT - + (self.PORT_OFFSET * self.WELLKNOWN_NODE_ID)) def open(self): if self.is_opened: @@ -132,8 +130,9 @@ class SnifferSocketTransport(SnifferTransport): self._socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) self._socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEPORT, 1) - self._socket.setsockopt(socket.IPPROTO_IP, socket.IP_ADD_MEMBERSHIP, - socket.inet_aton(self.RADIO_GROUP) + socket.inet_aton('127.0.0.1')) + self._socket.setsockopt( + socket.IPPROTO_IP, socket.IP_ADD_MEMBERSHIP, + socket.inet_aton(self.RADIO_GROUP) + socket.inet_aton('127.0.0.1')) self._socket.bind(self._nodeid_to_address(self.WELLKNOWN_NODE_ID)) def close(self): @@ -169,5 +168,6 @@ class MacFrame(ctypes.Structure): class SnifferTransportFactory(object): + def create_transport(self): return SnifferSocketTransport() diff --git a/tests/scripts/thread-cert/test_coap.py b/tests/scripts/thread-cert/test_coap.py index 35d4bb6a6..8747f0118 100755 --- a/tests/scripts/thread-cert/test_coap.py +++ b/tests/scripts/thread-cert/test_coap.py @@ -106,8 +106,9 @@ def any_uri_path(): class TestCoapMessageOptionHeader(unittest.TestCase): + def test_should_return_passed_on_value_when_read_extended_value_is_called_with_value_different_than_13_and_14( - self): + self): # GIVEN value = any_4bits_value_different_than_13_and_14() @@ -118,7 +119,7 @@ class TestCoapMessageOptionHeader(unittest.TestCase): self.assertEqual(value, actual_value) def test_should_return_value_stored_in_first_byte_plus_13_when_read_extended_value_is_called_with_value_equal_13( - self): + self): # GIVEN value = 13 extended_value = any_value() @@ -132,7 +133,7 @@ class TestCoapMessageOptionHeader(unittest.TestCase): self.assertEqual(extended_value + 13, actual_value) def test_should_return_value_stored_in_first_byte_plus_269_when_read_extended_value_is_called_with_value_equal_14( - self): + self): # GIVEN value = 14 extended_value = any_value() @@ -146,7 +147,7 @@ class TestCoapMessageOptionHeader(unittest.TestCase): self.assertEqual(extended_value + 269, actual_value) def test_should_create_CoapOptionHeader_when_from_bytes_classmethod_is_called( - self): + self): # GIVEN delta = any_4bits_value_different_than_13_and_14() length = any_4bits_value_different_than_13_and_14() @@ -161,7 +162,7 @@ class TestCoapMessageOptionHeader(unittest.TestCase): self.assertEqual(length, option_header.length) def test_should_return_True_when_is_payload_marker_property_called_with_delta_and_length_equal_15( - self): + self): # GIVEN delta = 15 length = 15 @@ -176,6 +177,7 @@ class TestCoapMessageOptionHeader(unittest.TestCase): class TestCoapOption(unittest.TestCase): + def test_should_return_type_value_when_type_property_is_called(self): # GIVEN _type = any_coap_option_type() @@ -202,8 +204,9 @@ class TestCoapOption(unittest.TestCase): class TestCoapOptionsFactory(unittest.TestCase): + def test_should_create_list_of_CoapOption_from_bytearray_when_parse_method_is_called( - self): + self): # GIVEN delta = any_4bits_value_lower_or_equal_than_12() length = any_4bits_value_lower_or_equal_than_12() @@ -223,6 +226,7 @@ class TestCoapOptionsFactory(unittest.TestCase): class TestCoapCode(unittest.TestCase): + def test_should_return_code_value_when_code_property_is_called(self): # GIVEN code = any_code() @@ -273,7 +277,7 @@ class TestCoapCode(unittest.TestCase): self.assertEqual(code, (int(_class) << 5) | int(detail)) def test_should_create_CoapCode_when_from_class_and_detail_classmethod_is_called( - self): + self): # GIVEN code = any_code() @@ -287,7 +291,7 @@ class TestCoapCode(unittest.TestCase): self.assertEqual(code, actual_coap_obj.code) def test_should_create_CoapCode_when_from_dotted_string_classmethod_is_called( - self): + self): # GIVEN code = any_code() @@ -301,6 +305,7 @@ class TestCoapCode(unittest.TestCase): class TestCoapMessage(unittest.TestCase): + def test_should_return_version_value_when_version_property_is_called(self): # GIVEN version = any_version() @@ -362,8 +367,7 @@ class TestCoapMessage(unittest.TestCase): self.assertEqual(code, actual_code) def test_should_return_message_id_value_when_message_id_property_is_called( - self - ): + self): # GIVEN message_id = any_message_id() @@ -464,8 +468,7 @@ class TestCoapMessage(unittest.TestCase): self.assertEqual(payload, actual_payload) def test_should_return_uri_path_value_when_uri_path_property_is_called( - self - ): + self): # GIVEN uri_path = any_uri_path() @@ -488,8 +491,9 @@ class TestCoapMessage(unittest.TestCase): class TestCoapMessageIdToUriPathBinder(unittest.TestCase): + def test_should_add_uri_path_to_binds_when_add_uri_path_for_method_is_called( - self): + self): # GIVEN message_id = any_message_id() token = any_token() @@ -504,7 +508,7 @@ class TestCoapMessageIdToUriPathBinder(unittest.TestCase): self.assertEqual(uri_path, binder.get_uri_path_for(message_id, token)) def test_should_raise_KeyError_when_get_uri_path_for_is_called_but_it_is_not_present_in_database( - self): + self): # GIVEN message_id = any_message_id() token = any_token() @@ -513,14 +517,16 @@ class TestCoapMessageIdToUriPathBinder(unittest.TestCase): binder = coap.CoapMessageIdToUriPathBinder() # THEN - self.assertRaises( - RuntimeError, binder.get_uri_path_for, message_id, token - ) + self.assertRaises(RuntimeError, binder.get_uri_path_for, message_id, + token) class TestCoapMessageFactory(unittest.TestCase): + def _create_dummy_payload_factory(self): + class DummyPayloadFactory: + def parse(self, data, message_info): return data.read() @@ -536,16 +542,35 @@ class TestCoapMessageFactory(unittest.TestCase): ) def test_should_create_CoapMessage_from_solicit_request_data_when_parse_method_is_called( - self): + self): # GIVEN - data = bytearray( - [ - 0x42, 0x02, 0x00, 0xBD, 0x65, 0xee, 0xB1, 0x61, - 0x02, 0x61, 0x73, 0xff, 0x01, 0x08, 0x16, 0x6E, - 0x0A, 0x00, 0x00, 0x00, 0x00, 0x02, 0x04, 0x01, - 0x02, - ] - ) + data = bytearray([ + 0x42, + 0x02, + 0x00, + 0xBD, + 0x65, + 0xee, + 0xB1, + 0x61, + 0x02, + 0x61, + 0x73, + 0xff, + 0x01, + 0x08, + 0x16, + 0x6E, + 0x0A, + 0x00, + 0x00, + 0x00, + 0x00, + 0x02, + 0x04, + 0x01, + 0x02, + ]) factory = self._create_coap_message_factory() @@ -563,26 +588,54 @@ class TestCoapMessageFactory(unittest.TestCase): self.assertEqual("as", coap_message.options[1].value.decode("utf-8")) self.assertEqual("/a/as", coap_message.uri_path) self.assertEqual( - bytearray( - [ - 0x01, 0x08, 0x16, 0x6E, 0x0A, 0x00, 0x00, 0x00, - 0x00, 0x02, 0x04, 0x01, 0x02, - ] - ), + bytearray([ + 0x01, + 0x08, + 0x16, + 0x6E, + 0x0A, + 0x00, + 0x00, + 0x00, + 0x00, + 0x02, + 0x04, + 0x01, + 0x02, + ]), coap_message.payload, ) def test_should_create_CoapMessage_from_solicit_response_data_when_parse_method_is_called( - self): + self): # GIVEN - data = bytearray( - [ - 0x62, 0x44, 0x00, 0xBD, 0x65, 0xee, 0xff, 0x04, - 0x01, 0x00, 0x02, 0x02, 0x00, 0x00, 0x07, 0x09, - 0x76, 0x80, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, - 0x00, - ] - ) + data = bytearray([ + 0x62, + 0x44, + 0x00, + 0xBD, + 0x65, + 0xee, + 0xff, + 0x04, + 0x01, + 0x00, + 0x02, + 0x02, + 0x00, + 0x00, + 0x07, + 0x09, + 0x76, + 0x80, + 0x00, + 0x01, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + ]) mid_binder = coap.CoapMessageIdToUriPathBinder() mid_binder.add_uri_path_for(189, bytearray([0x65, 0xee]), "/a/as") @@ -607,13 +660,26 @@ class TestCoapMessageFactory(unittest.TestCase): self.assertEqual(bytearray([0x65, 0xee]), coap_message.token) self.assertEqual(None, coap_message.uri_path) self.assertEqual( - bytearray( - [ - 0x04, 0x01, 0x00, 0x02, 0x02, 0x00, 0x00, 0x07, - 0x09, 0x76, 0x80, 0x00, 0x01, 0x00, 0x00, 0x00, - 0x00, 0x00, - ] - ), + bytearray([ + 0x04, + 0x01, + 0x00, + 0x02, + 0x02, + 0x00, + 0x00, + 0x07, + 0x09, + 0x76, + 0x80, + 0x00, + 0x01, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + ]), coap_message.payload, ) diff --git a/tests/scripts/thread-cert/test_coaps.py b/tests/scripts/thread-cert/test_coaps.py index bb4636652..035d76599 100755 --- a/tests/scripts/thread-cert/test_coaps.py +++ b/tests/scripts/thread-cert/test_coaps.py @@ -37,6 +37,7 @@ ROUTER = 2 class TestCoaps(unittest.TestCase): + def setUp(self): self.simulator = config.create_default_simulator() diff --git a/tests/scripts/thread-cert/test_common.py b/tests/scripts/thread-cert/test_common.py index 42939cd42..f7797c30f 100755 --- a/tests/scripts/thread-cert/test_common.py +++ b/tests/scripts/thread-cert/test_common.py @@ -51,8 +51,9 @@ def any_ipv6_address(): class TestMessageInfo(unittest.TestCase): + def test_should_return_source_ipv6_value_when_source_ipv6_property_is_called( - self): + self): # GIVEN source_ipv6 = any_ipv6_address() @@ -63,12 +64,11 @@ class TestMessageInfo(unittest.TestCase): actual_source_ipv6 = message_info.source_ipv6 # THEN - self.assertEqual( - ipaddress.ip_address(bytes(source_ipv6)), actual_source_ipv6 - ) + self.assertEqual(ipaddress.ip_address(bytes(source_ipv6)), + actual_source_ipv6) def test_should_return_destination_ipv6_value_when_destination_ipv6_property_is_called( - self): + self): # GIVEN destination_ipv6 = any_ipv6_address() @@ -85,7 +85,7 @@ class TestMessageInfo(unittest.TestCase): ) def test_should_return_source_eui64_value_when_source_eui64_property_is_called( - self): + self): # GIVEN source_mac_address = any_eui64() @@ -99,7 +99,7 @@ class TestMessageInfo(unittest.TestCase): self.assertEqual(source_mac_address, actual_source_mac_address) def test_should_return_destination_eui64_value_when_destination_eui64_property_is_called( - self): + self): # GIVEN destination_mac_address = any_eui64() @@ -110,14 +110,14 @@ class TestMessageInfo(unittest.TestCase): actual_destination_mac_address = message_info.destination_mac_address # THEN - self.assertEqual( - destination_mac_address, actual_destination_mac_address - ) + self.assertEqual(destination_mac_address, + actual_destination_mac_address) class TestMacAddress(unittest.TestCase): + def test_should_create_MacAddress_from_eui64_when_from_eui64_classmethod_is_called( - self): + self): # GIVEN eui64 = any_eui64() @@ -129,7 +129,7 @@ class TestMacAddress(unittest.TestCase): self.assertEqual(eui64, mac_address.mac_address) def test_should_create_MacAddress_from_rloc16_int_when_from_rloc16_classmethod_is_called( - self): + self): # GIVEN rloc16 = any_rloc16_int() @@ -141,7 +141,7 @@ class TestMacAddress(unittest.TestCase): self.assertEqual(struct.pack(">H", rloc16), mac_address.mac_address) def test_should_create_MacAddress_from_rloc16_bytearray_when_from_rloc16_classmethod_is_called( - self): + self): # GIVEN rloc16 = any_rloc16_bytearray() @@ -153,7 +153,7 @@ class TestMacAddress(unittest.TestCase): self.assertEqual(rloc16, mac_address.mac_address) def test_should_convert_short_MacAddress_to_iid_when_convert_method_is_called( - self): + self): # GIVEN rloc16 = any_rloc16_bytearray() @@ -164,11 +164,10 @@ class TestMacAddress(unittest.TestCase): # THEN self.assertEqual( - bytearray([0x00, 0x00, 0x00, 0xff, 0xfe, 0x00]) + rloc16, iid - ) + bytearray([0x00, 0x00, 0x00, 0xff, 0xfe, 0x00]) + rloc16, iid) def test_should_convert_eui64_MacAddress_to_iid_when_convert_method_is_called( - self): + self): # GIVEN eui64 = any_eui64() diff --git a/tests/scripts/thread-cert/test_crypto.py b/tests/scripts/thread-cert/test_crypto.py index 3e00407c5..c18b35823 100755 --- a/tests/scripts/thread-cert/test_crypto.py +++ b/tests/scripts/thread-cert/test_crypto.py @@ -36,12 +36,15 @@ import ipaddress import common import net_crypto -master_key = bytearray([0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, - 0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff]) +master_key = bytearray([ + 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xaa, 0xbb, + 0xcc, 0xdd, 0xee, 0xff +]) def convert_aux_sec_hdr_to_bytearray(aux_sec_hdr): - data = bytearray([aux_sec_hdr.security_level | ((aux_sec_hdr.key_id_mode & 0x03) << 3)]) + data = bytearray( + [aux_sec_hdr.security_level | ((aux_sec_hdr.key_id_mode & 0x03) << 3)]) data += struct.pack("L", frame_counter), nonce_bytes.read(4)) self.assertEqual(security_level, ord(nonce_bytes.read(1))) - def test_should_create_authenticated_data_when_create_authenticated_data_method_is_called(self): + def test_should_create_authenticated_data_when_create_authenticated_data_method_is_called( + self): """ Only Key id mode 2. Length of the Auxiliary Security Header is constantly equal 10. @@ -290,64 +339,68 @@ class TestMleCryptoMaterialCreator(unittest.TestCase): # GIVEN source_address = any_ip_address() destination_address = any_ip_address() - auxiliary_security_header_bytes = convert_aux_sec_hdr_to_bytearray(any_auxiliary_security_header()) + auxiliary_security_header_bytes = convert_aux_sec_hdr_to_bytearray( + any_auxiliary_security_header()) creator = net_crypto.MleCryptoMaterialCreator(master_key) # WHEN authenticated_data = creator._create_authenticated_data( - source_address, destination_address, auxiliary_security_header_bytes) + source_address, destination_address, + auxiliary_security_header_bytes) # THEN authenticated_data_bytes = io.BytesIO(authenticated_data) - self.assertEqual(source_address.packed, authenticated_data_bytes.read(16)) - self.assertEqual(destination_address.packed, authenticated_data_bytes.read(16)) - self.assertEqual(auxiliary_security_header_bytes, authenticated_data_bytes.read(10)) + self.assertEqual(source_address.packed, + authenticated_data_bytes.read(16)) + self.assertEqual(destination_address.packed, + authenticated_data_bytes.read(16)) + self.assertEqual(auxiliary_security_header_bytes, + authenticated_data_bytes.read(10)) - def test_should_create_key_and_nonce_and_auth_data_when_create_key_and_nonce_and_auth_data_is_called(self): + def test_should_create_key_and_nonce_and_auth_data_when_create_key_and_nonce_and_auth_data_is_called( + self): # GIVEN message_info = common.MessageInfo() - message_info.source_mac_address = common.MacAddress.from_eui64(any_eui64()) + message_info.source_mac_address = common.MacAddress.from_eui64( + any_eui64()) message_info.source_ipv6 = any_ip_address() message_info.destination_ipv6 = any_ip_address() message_info.aux_sec_hdr = any_auxiliary_security_header() - message_info.aux_sec_hdr_bytes = convert_aux_sec_hdr_to_bytearray(message_info.aux_sec_hdr) + message_info.aux_sec_hdr_bytes = convert_aux_sec_hdr_to_bytearray( + message_info.aux_sec_hdr) creator = net_crypto.MleCryptoMaterialCreator(master_key) # WHEN - key, nonce, auth_data = creator.create_key_and_nonce_and_authenticated_data(message_info) + key, nonce, auth_data = creator.create_key_and_nonce_and_authenticated_data( + message_info) # THEN self.assertEqual( - message_info.source_mac_address.mac_address - + struct.pack( - ">LB", - message_info.aux_sec_hdr.frame_counter, - message_info.aux_sec_hdr.security_level - ), - nonce - ) + message_info.source_mac_address.mac_address + + struct.pack(">LB", message_info.aux_sec_hdr.frame_counter, + message_info.aux_sec_hdr.security_level), nonce) self.assertEqual( - message_info.source_ipv6.packed - + message_info.destination_ipv6.packed - + message_info.aux_sec_hdr_bytes, - auth_data - ) + message_info.source_ipv6.packed + + message_info.destination_ipv6.packed + + message_info.aux_sec_hdr_bytes, auth_data) class TestAuxiliarySecurityHeader(unittest.TestCase): - def test_should_return_key_id_mode_value_when_key_id_mode_property_is_called(self): + def test_should_return_key_id_mode_value_when_key_id_mode_property_is_called( + self): # GIVEN key_id_mode = any_key_id_mode() aux_sec_hdr_obj = net_crypto.AuxiliarySecurityHeader( - key_id_mode, any_security_level(), any_frame_counter(), any_key_id(key_id_mode)) + key_id_mode, any_security_level(), any_frame_counter(), + any_key_id(key_id_mode)) # WHEN actual_key_id_mode = aux_sec_hdr_obj.key_id_mode @@ -355,13 +408,15 @@ class TestAuxiliarySecurityHeader(unittest.TestCase): # THEN self.assertEqual(key_id_mode, actual_key_id_mode) - def test_should_return_security_level_value_when_security_level_property_is_called(self): + def test_should_return_security_level_value_when_security_level_property_is_called( + self): # GIVEN security_level = any_security_level() key_id_mode = any_key_id_mode() aux_sec_hdr_obj = net_crypto.AuxiliarySecurityHeader( - key_id_mode, security_level, any_frame_counter(), any_key_id(key_id_mode)) + key_id_mode, security_level, any_frame_counter(), + any_key_id(key_id_mode)) # WHEN actual_security_level = aux_sec_hdr_obj.security_level @@ -369,13 +424,15 @@ class TestAuxiliarySecurityHeader(unittest.TestCase): # THEN self.assertEqual(security_level, actual_security_level) - def test_should_return_frame_counter_value_when_frame_counter_property_is_called(self): + def test_should_return_frame_counter_value_when_frame_counter_property_is_called( + self): # GIVEN frame_counter = any_frame_counter() key_id_mode = any_key_id_mode() aux_sec_hdr_obj = net_crypto.AuxiliarySecurityHeader( - key_id_mode, any_security_level(), frame_counter, any_key_id(key_id_mode)) + key_id_mode, any_security_level(), frame_counter, + any_key_id(key_id_mode)) # WHEN actual_frame_counter = aux_sec_hdr_obj.frame_counter @@ -397,7 +454,8 @@ class TestAuxiliarySecurityHeader(unittest.TestCase): # THEN self.assertEqual(key_id, actual_key_id) - def test_should_return_sequence_counter_value_when_sequence_counter_property_is_called(self): + def test_should_return_sequence_counter_value_when_sequence_counter_property_is_called( + self): # GIVEN key_id_mode = 2 key_id = any_key_id(key_id_mode) @@ -409,12 +467,14 @@ class TestAuxiliarySecurityHeader(unittest.TestCase): actual_sequence_counter = aux_sec_hdr_obj.sequence_counter # THEN - self.assertEqual(struct.unpack(">I", key_id[:4])[0], actual_sequence_counter) + self.assertEqual( + struct.unpack(">I", key_id[:4])[0], actual_sequence_counter) class TestAuxiliarySecurityHeaderFactory(unittest.TestCase): - def test_should_create_AuxiliarySecurityHeader_from_bytearray_when_parse_method_is_called(self): + def test_should_create_AuxiliarySecurityHeader_from_bytearray_when_parse_method_is_called( + self): # GIVEN key_id_mode = any_key_id_mode() sec_lvl = any_security_level() @@ -423,13 +483,15 @@ class TestAuxiliarySecurityHeaderFactory(unittest.TestCase): factory = net_crypto.AuxiliarySecurityHeaderFactory() - data = bytearray([sec_lvl | key_id_mode << 3]) + struct.pack("> 8) & 0xff, checksum & 0xff]) + body + return bytearray([_type, code, + (checksum >> 8) & 0xff, checksum & 0xff]) + body def any_udp_payload(src_port, dst_port, payload, checksum): @@ -188,7 +186,10 @@ def any_hop_by_hop_payload(next_header, hdr_ext_len, payload): def any_body(): length = any_uint(8) - body = "".join([random.choice(string.ascii_letters + string.digits + string.hexdigits) for _ in range(length)]) + body = "".join([ + random.choice(string.ascii_letters + string.digits + string.hexdigits) + for _ in range(length) + ]) return bytearray(body.encode("utf-8")) @@ -199,7 +200,8 @@ def any_payload(): def any_ip_address(): - return bytearray([0xfe, 0x80]) + bytearray([0x00] * 6) + bytearray([random.getrandbits(8)] * 8) + return bytearray([0xfe, 0x80]) + bytearray([0x00] * 6) + bytearray( + [random.getrandbits(8)] * 8) def any_port(): @@ -232,7 +234,10 @@ def any_mpl_sequence(): def any_mpl_seed_id(S): length = MPLOption._seed_id_length[S] - seed_id = "".join([random.choice(string.ascii_letters + string.digits + string.hexdigits) for _ in range(length)]) + seed_id = "".join([ + random.choice(string.ascii_letters + string.digits + string.hexdigits) + for _ in range(length) + ]) return bytearray(seed_id.encode("utf-8")) @@ -309,12 +314,14 @@ def any_hop_by_hop_bytes_value(length=2): def any_hop_by_hop_bytes_option(): length = any_length() - return HopByHopOption(any_hop_by_hop_bytes_option_header(length), any_hop_by_hop_bytes_value(length)) + return HopByHopOption(any_hop_by_hop_bytes_option_header(length), + any_hop_by_hop_bytes_value(length)) def any_hop_by_hop_mpl_option(): mpl_option = any_mpl_option() - return HopByHopOption(any_hop_by_hop_bytes_option_header(len(mpl_option)), mpl_option) + return HopByHopOption(any_hop_by_hop_bytes_option_header(len(mpl_option)), + mpl_option) def any_identifier(): @@ -343,7 +350,8 @@ def any_message_info(): class TestIPv6Header(unittest.TestCase): - def test_should_convert_IPv6_header_to_bytes_when_to_bytes_method_is_called(self): + def test_should_convert_IPv6_header_to_bytes_when_to_bytes_method_is_called( + self): # GIVEN traffic_class = any_traffic_class() flow_label = any_flow_label() @@ -353,7 +361,8 @@ class TestIPv6Header(unittest.TestCase): source_address = any_ip_address() destination_address = any_ip_address() - ipv6_header = IPv6Header(source_address, destination_address, traffic_class, flow_label, hop_limit, + ipv6_header = IPv6Header(source_address, destination_address, + traffic_class, flow_label, hop_limit, payload_length, next_header) # WHEN @@ -362,16 +371,16 @@ class TestIPv6Header(unittest.TestCase): # THEN self.assertEqual(6, data[0] >> 4) self.assertEqual(traffic_class, ((data[0] << 8 | data[1]) >> 4) & 0xff) - self.assertEqual( - flow_label, ((data[1] & 0x0F) << 16) | (data[2] << 8) | data[3] - ) + self.assertEqual(flow_label, + ((data[1] & 0x0F) << 16) | (data[2] << 8) | data[3]) self.assertEqual(payload_length, struct.unpack("!H", data[4:6])[0]) self.assertEqual(next_header, data[6]) self.assertEqual(hop_limit, data[7]) self.assertEqual(source_address, data[8:24]) self.assertEqual(destination_address, data[24:40]) - def test_should_create_IPv6Header_when_from_bytes_classmethod_is_called(self): + def test_should_create_IPv6Header_when_from_bytes_classmethod_is_called( + self): # GIVEN traffic_class = any_traffic_class() flow_label = any_flow_label() @@ -386,7 +395,8 @@ class TestIPv6Header(unittest.TestCase): (flow_label >> 8) & 0xff, flow_label & 0xff, payload_length >> 8, payload_length & 0xff, next_header, hop_limit]) - data += ip_address(bytes(source_address)).packed + ip_address(bytes(destination_address)).packed + data += ip_address(bytes(source_address)).packed + ip_address( + bytes(destination_address)).packed # WHEN ipv6_header = IPv6Header.from_bytes(io.BytesIO(data)) @@ -399,12 +409,16 @@ class TestIPv6Header(unittest.TestCase): self.assertEqual(next_header, ipv6_header.next_header) self.assertEqual(hop_limit, ipv6_header.hop_limit) self.assertEqual(source_address, ipv6_header.source_address.packed) - self.assertEqual(destination_address, ipv6_header.destination_address.packed) + self.assertEqual(destination_address, + ipv6_header.destination_address.packed) - def test_should_return_proper_header_length_when_IPv6Packet_object_is_called_in_len(self): + def test_should_return_proper_header_length_when_IPv6Packet_object_is_called_in_len( + self): # GIVEN - ipv6_header = IPv6Header(any_traffic_class(), any_flow_label(), any_payload_length(), - any_next_header(), any_hop_limit(), any_ip_address(), any_ip_address()) + ipv6_header = IPv6Header(any_traffic_class(), any_flow_label(), + any_payload_length(), any_next_header(), + any_hop_limit(), any_ip_address(), + any_ip_address()) # WHEN ipv6_header_length = len(ipv6_header) @@ -415,7 +429,8 @@ class TestIPv6Header(unittest.TestCase): class TestUDPHeader(unittest.TestCase): - def test_should_convert_UDP_header_to_bytes_when_to_bytes_method_is_called(self): + def test_should_convert_UDP_header_to_bytes_when_to_bytes_method_is_called( + self): # GIVEN src_port = any_port() dst_port = any_port() @@ -433,7 +448,8 @@ class TestUDPHeader(unittest.TestCase): self.assertEqual(payload_length, struct.unpack("!H", data[4:6])[0]) self.assertEqual(checksum, struct.unpack("!H", data[6:])[0]) - def test_should_create_UDPHeader_when_from_bytes_classmethod_is_called(self): + def test_should_create_UDPHeader_when_from_bytes_classmethod_is_called( + self): # GIVEN src_port = any_port() dst_port = any_port() @@ -452,9 +468,11 @@ class TestUDPHeader(unittest.TestCase): self.assertEqual(payload_length, udp_header.payload_length) self.assertEqual(checksum, udp_header.checksum) - def test_should_return_proper_header_length_when_UDPHeader_object_is_called_in_len(self): + def test_should_return_proper_header_length_when_UDPHeader_object_is_called_in_len( + self): # GIVEN - udp_header = UDPHeader(any_port(), any_port(), any_payload_length(), any_checksum()) + udp_header = UDPHeader(any_port(), any_port(), any_payload_length(), + any_checksum()) # WHEN udp_header_length = len(udp_header) @@ -464,7 +482,8 @@ class TestUDPHeader(unittest.TestCase): def test_should_return_17_when_type_property_is_called(self): # GIVEN - udp_header = UDPHeader(any_port(), any_port(), any_payload_length(), any_checksum()) + udp_header = UDPHeader(any_port(), any_port(), any_payload_length(), + any_checksum()) # THEN self.assertEqual(17, udp_header.type) @@ -472,7 +491,8 @@ class TestUDPHeader(unittest.TestCase): class TestICMPv6Header(unittest.TestCase): - def test_should_convert_icmp_message_header_to_bytes_when_to_bytes_method_is_called(self): + def test_should_convert_icmp_message_header_to_bytes_when_to_bytes_method_is_called( + self): # GIVEN _type = any_type() code = any_code() @@ -488,7 +508,8 @@ class TestICMPv6Header(unittest.TestCase): self.assertEqual(code, data[1]) self.assertEqual(checksum, struct.unpack("!H", data[2:])[0]) - def test_should_create_ICMPv6Header_when_to_bytes_classmethod_is_called(self): + def test_should_create_ICMPv6Header_when_to_bytes_classmethod_is_called( + self): # GIVEN _type = any_type() code = any_code() @@ -504,7 +525,8 @@ class TestICMPv6Header(unittest.TestCase): self.assertEqual(code, icmpv6_header.code) self.assertEqual(checksum, icmpv6_header.checksum) - def test_should_return_proper_header_length_when_ICMPv6Header_object_is_called_in_len(self): + def test_should_return_proper_header_length_when_ICMPv6Header_object_is_called_in_len( + self): # GIVEN icmpv6_header = ICMPv6Header(any_type(), any_code(), any_checksum()) @@ -517,62 +539,50 @@ class TestICMPv6Header(unittest.TestCase): class TestIPv6Packet(unittest.TestCase): - def test_should_build_IPv6Packet_with_ICMP_payload_from_well_know_values_when_to_bytes_method_is_called(self): + def test_should_build_IPv6Packet_with_ICMP_payload_from_well_know_values_when_to_bytes_method_is_called( + self): # GIVEN ipv6_packet = IPv6Packet( - IPv6Header( - source_address="fd00:1234:4555::ff:fe00:1800", - destination_address="ff03::1" - ), + IPv6Header(source_address="fd00:1234:4555::ff:fe00:1800", + destination_address="ff03::1"), ICMPv6( ICMPv6Header(128, 0), ICMPv6EchoBody( - 0, - 2, - bytearray( - [ - 0x80, 0x00, 0xc7, 0xbf, 0x00, 0x00, 0x00, 0x01, - 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, - 0x41, 0x41 - ] - ) - ) - ), - [ - HopByHop( - options=[ - HopByHopOption( - HopByHopOptionHeader(_type=0x6d), - MPLOption(S=1, M=0, V=0, sequence=2, seed_id=bytearray([0x00, 0x18])) - ) - ] - ) - ] - ) + 0, 2, + bytearray([ + 0x80, 0x00, 0xc7, 0xbf, 0x00, 0x00, 0x00, 0x01, 0x41, + 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41 + ]))), [ + HopByHop(options=[ + HopByHopOption( + HopByHopOptionHeader(_type=0x6d), + MPLOption(S=1, + M=0, + V=0, + sequence=2, + seed_id=bytearray([0x00, 0x18]))) + ]) + ]) # WHEN ipv6_packet_bytes = ipv6_packet.to_bytes() # THEN - expected_ipv6_packet_bytes = bytearray( - [ - 0x60, 0x00, 0x00, 0x00, 0x00, 0x22, 0x00, 0x40, - 0xfd, 0x00, 0x12, 0x34, 0x45, 0x55, 0x00, 0x00, - 0x00, 0x00, 0x00, 0xff, 0xfe, 0x00, 0x18, 0x00, - 0xff, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, - 0x3a, 0x00, 0x6d, 0x04, 0x40, 0x02, 0x00, 0x18, - 0x80, 0x00, 0x87, 0x12, 0x00, 0x00, 0x00, 0x02, - 0x80, 0x00, 0xc7, 0xbf, 0x00, 0x00, 0x00, 0x01, - 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, - 0x41, 0x41 - ] - ) + expected_ipv6_packet_bytes = bytearray([ + 0x60, 0x00, 0x00, 0x00, 0x00, 0x22, 0x00, 0x40, 0xfd, 0x00, 0x12, + 0x34, 0x45, 0x55, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xfe, 0x00, + 0x18, 0x00, 0xff, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x3a, 0x00, 0x6d, 0x04, + 0x40, 0x02, 0x00, 0x18, 0x80, 0x00, 0x87, 0x12, 0x00, 0x00, 0x00, + 0x02, 0x80, 0x00, 0xc7, 0xbf, 0x00, 0x00, 0x00, 0x01, 0x41, 0x41, + 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41 + ]) self.assertEqual(expected_ipv6_packet_bytes, ipv6_packet_bytes) - def test_should_build_IPv6Packet_with_UDP_payload_from_well_know_values_when_to_bytes_method_is_called(self): + def test_should_build_IPv6Packet_with_UDP_payload_from_well_know_values_when_to_bytes_method_is_called( + self): # GIVEN ipv6_header = IPv6Header(source_address="fe80::1", destination_address="ff02::2", @@ -581,16 +591,12 @@ class TestIPv6Packet(unittest.TestCase): udp_dgram = UDPDatagram( UDPHeader(src_port=19788, dst_port=19788), BytesPayload( - bytearray( - [ - 0x00, 0x15, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x01, 0x09, 0x01, 0x01, 0x0b, 0x03, - 0x04, 0xc6, 0x69, 0x73, 0x51, 0x0e, 0x01, 0x80, - 0x12, 0x02, 0x00, 0x01, 0xde, 0xad, 0xbe, 0xef - ] - ) - ) - ) + bytearray([ + 0x00, 0x15, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x01, 0x09, 0x01, 0x01, 0x0b, 0x03, 0x04, 0xc6, 0x69, 0x73, + 0x51, 0x0e, 0x01, 0x80, 0x12, 0x02, 0x00, 0x01, 0xde, 0xad, + 0xbe, 0xef + ]))) ipv6_packet = IPv6Packet(ipv6_header, udp_dgram) @@ -598,57 +604,55 @@ class TestIPv6Packet(unittest.TestCase): ipv6_packet_bytes = ipv6_packet.to_bytes() # THEN - expected_ipv6_packet_bytes = bytearray([0x60, 0x00, 0x00, 0x00, 0x00, 0x28, 0x11, 0xff, - 0xfe, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, - 0xff, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, - 0x4d, 0x4c, 0x4d, 0x4c, 0x00, 0x28, 0xe9, 0xf4, - 0x00, 0x15, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x01, 0x09, 0x01, 0x01, 0x0b, 0x03, - 0x04, 0xc6, 0x69, 0x73, 0x51, 0x0e, 0x01, 0x80, - 0x12, 0x02, 0x00, 0x01, 0xde, 0xad, 0xbe, 0xef]) + expected_ipv6_packet_bytes = bytearray([ + 0x60, 0x00, 0x00, 0x00, 0x00, 0x28, 0x11, 0xff, 0xfe, 0x80, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x01, 0xff, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x4d, 0x4c, 0x4d, 0x4c, + 0x00, 0x28, 0xe9, 0xf4, 0x00, 0x15, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x01, 0x09, 0x01, 0x01, 0x0b, 0x03, 0x04, 0xc6, + 0x69, 0x73, 0x51, 0x0e, 0x01, 0x80, 0x12, 0x02, 0x00, 0x01, 0xde, + 0xad, 0xbe, 0xef + ]) self.assertEqual(expected_ipv6_packet_bytes, ipv6_packet_bytes) class TestIPv6PacketFactory(unittest.TestCase): - def test_should_create_IPv6Packet_with_MPL_and_ICMP_when_to_bytes_method_is_called(self): + def test_should_create_IPv6Packet_with_MPL_and_ICMP_when_to_bytes_method_is_called( + self): # GIVEN - ipv6_packet_bytes = bytearray([0x60, 0x00, 0x00, 0x00, 0x00, 0x22, 0x00, 0x40, - 0xfd, 0x00, 0x12, 0x34, 0x45, 0x55, 0x00, 0x00, - 0x00, 0x00, 0x00, 0xff, 0xfe, 0x00, 0x18, 0x00, - 0xff, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, - 0x3a, 0x00, 0x6d, 0x04, 0x40, 0x02, 0x00, 0x18, - 0x80, 0x00, 0x87, 0x12, 0x00, 0x00, 0x00, 0x02, - 0x80, 0x00, 0xc7, 0xbf, 0x00, 0x00, 0x00, 0x01, - 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, - 0x41, 0x41]) + ipv6_packet_bytes = bytearray([ + 0x60, 0x00, 0x00, 0x00, 0x00, 0x22, 0x00, 0x40, 0xfd, 0x00, 0x12, + 0x34, 0x45, 0x55, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xfe, 0x00, + 0x18, 0x00, 0xff, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x3a, 0x00, 0x6d, 0x04, + 0x40, 0x02, 0x00, 0x18, 0x80, 0x00, 0x87, 0x12, 0x00, 0x00, 0x00, + 0x02, 0x80, 0x00, 0xc7, 0xbf, 0x00, 0x00, 0x00, 0x01, 0x41, 0x41, + 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41 + ]) ipv6_factory = IPv6PacketFactory( ehf={ - 0: HopByHopFactory( - hop_by_hop_options_factory=HopByHopOptionsFactory( - options_factories={ - 109: MPLOptionFactory() - } - ) - ) + 0: + HopByHopFactory( + hop_by_hop_options_factory=HopByHopOptionsFactory( + options_factories={109: MPLOptionFactory()})) }, ulpf={ - 58: ICMPv6Factory(body_factories={ - 128: ICMPv6EchoBodyFactory() - }) + 58: ICMPv6Factory(body_factories={128: ICMPv6EchoBodyFactory()}) }) # WHEN - ipv6_packet = ipv6_factory.parse(io.BytesIO(ipv6_packet_bytes), any_message_info()) + ipv6_packet = ipv6_factory.parse(io.BytesIO(ipv6_packet_bytes), + any_message_info()) # THEN - self.assertEqual('fd00:1234:4555::ff:fe00:1800', ipv6_packet.ipv6_header.source_address.compressed) - self.assertEqual('ff03::1', ipv6_packet.ipv6_header.destination_address.compressed) + self.assertEqual('fd00:1234:4555::ff:fe00:1800', + ipv6_packet.ipv6_header.source_address.compressed) + self.assertEqual('ff03::1', + ipv6_packet.ipv6_header.destination_address.compressed) self.assertEqual(64, ipv6_packet.ipv6_header.hop_limit) self.assertEqual(0, ipv6_packet.ipv6_header.next_header) self.assertEqual(34, ipv6_packet.ipv6_header.payload_length) @@ -659,42 +663,48 @@ class TestIPv6PacketFactory(unittest.TestCase): self.assertEqual(1, ipv6_packet.extension_headers[0].options[0].value.S) self.assertEqual(0, ipv6_packet.extension_headers[0].options[0].value.M) self.assertEqual(0, ipv6_packet.extension_headers[0].options[0].value.V) - self.assertEqual(2, ipv6_packet.extension_headers[0].options[0].value.sequence) - self.assertEqual(bytearray([0x00, 0x18]), ipv6_packet.extension_headers[0].options[0].value.seed_id) + self.assertEqual( + 2, ipv6_packet.extension_headers[0].options[0].value.sequence) + self.assertEqual( + bytearray([0x00, 0x18]), + ipv6_packet.extension_headers[0].options[0].value.seed_id) - self.assertEqual(34578, ipv6_packet.upper_layer_protocol.header.checksum) + self.assertEqual(34578, + ipv6_packet.upper_layer_protocol.header.checksum) self.assertEqual(128, ipv6_packet.upper_layer_protocol.header.type) self.assertEqual(0, ipv6_packet.upper_layer_protocol.header.code) self.assertEqual(0, ipv6_packet.upper_layer_protocol.body.identifier) - self.assertEqual(2, ipv6_packet.upper_layer_protocol.body.sequence_number) - self.assertEqual(b'\x80\x00\xc7\xbf\x00\x00\x00\x01AAAAAAAAAA', ipv6_packet.upper_layer_protocol.body.data) + self.assertEqual(2, + ipv6_packet.upper_layer_protocol.body.sequence_number) + self.assertEqual(b'\x80\x00\xc7\xbf\x00\x00\x00\x01AAAAAAAAAA', + ipv6_packet.upper_layer_protocol.body.data) - def test_should_create_IPv6Packet_without_any_extension_header_with_ICMP_when_to_bytes_method_is_called(self): + def test_should_create_IPv6Packet_without_any_extension_header_with_ICMP_when_to_bytes_method_is_called( + self): # GIVEN - ipv6_packet_bytes = bytearray([0x60, 0x00, 0x00, 0x00, 0x00, 0x1A, 0x3A, 0x40, - 0xfd, 0x00, 0x12, 0x34, 0x45, 0x55, 0x00, 0x00, - 0x00, 0x00, 0x00, 0xff, 0xfe, 0x00, 0x18, 0x00, - 0xff, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, - 0x80, 0x00, 0x87, 0x12, 0x00, 0x00, 0x00, 0x02, - 0x80, 0x00, 0xc7, 0xbf, 0x00, 0x00, 0x00, 0x01, - 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, - 0x41, 0x41]) + ipv6_packet_bytes = bytearray([ + 0x60, 0x00, 0x00, 0x00, 0x00, 0x1A, 0x3A, 0x40, 0xfd, 0x00, 0x12, + 0x34, 0x45, 0x55, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xfe, 0x00, + 0x18, 0x00, 0xff, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x80, 0x00, 0x87, 0x12, + 0x00, 0x00, 0x00, 0x02, 0x80, 0x00, 0xc7, 0xbf, 0x00, 0x00, 0x00, + 0x01, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41 + ]) - ipv6_factory = IPv6PacketFactory( - ulpf={ - 58: ICMPv6Factory(body_factories={ - 128: ICMPv6EchoBodyFactory() - }) - }) + ipv6_factory = IPv6PacketFactory(ulpf={ + 58: ICMPv6Factory(body_factories={128: ICMPv6EchoBodyFactory()}) + }) # WHEN - ipv6_packet = ipv6_factory.parse(io.BytesIO(ipv6_packet_bytes), any_message_info()) + ipv6_packet = ipv6_factory.parse(io.BytesIO(ipv6_packet_bytes), + any_message_info()) ipv6_packet._validate_checksum() # THEN - self.assertEqual('fd00:1234:4555::ff:fe00:1800', ipv6_packet.ipv6_header.source_address.compressed) - self.assertEqual('ff03::1', ipv6_packet.ipv6_header.destination_address.compressed) + self.assertEqual('fd00:1234:4555::ff:fe00:1800', + ipv6_packet.ipv6_header.source_address.compressed) + self.assertEqual('ff03::1', + ipv6_packet.ipv6_header.destination_address.compressed) self.assertEqual(64, ipv6_packet.ipv6_header.hop_limit) self.assertEqual(58, ipv6_packet.ipv6_header.next_header) self.assertEqual(26, ipv6_packet.ipv6_header.payload_length) @@ -702,54 +712,57 @@ class TestIPv6PacketFactory(unittest.TestCase): self.assertEqual(0, ipv6_packet.ipv6_header.traffic_class) self.assertEqual(6, ipv6_packet.ipv6_header.version) - self.assertEqual(34578, ipv6_packet.upper_layer_protocol.header.checksum) + self.assertEqual(34578, + ipv6_packet.upper_layer_protocol.header.checksum) self.assertEqual(128, ipv6_packet.upper_layer_protocol.header.type) self.assertEqual(0, ipv6_packet.upper_layer_protocol.header.code) self.assertEqual(0, ipv6_packet.upper_layer_protocol.body.identifier) - self.assertEqual(2, ipv6_packet.upper_layer_protocol.body.sequence_number) - self.assertEqual(b'\x80\x00\xc7\xbf\x00\x00\x00\x01AAAAAAAAAA', ipv6_packet.upper_layer_protocol.body.data) + self.assertEqual(2, + ipv6_packet.upper_layer_protocol.body.sequence_number) + self.assertEqual(b'\x80\x00\xc7\xbf\x00\x00\x00\x01AAAAAAAAAA', + ipv6_packet.upper_layer_protocol.body.data) def test_should_set_message_info_field_when_to_bytes_method_is_called(self): # GIVEN - ipv6_packet_data = bytearray([0x60, 0x00, 0x00, 0x00, 0x00, 0x1A, 0x3A, 0x40, - 0xfd, 0x00, 0x12, 0x34, 0x45, 0x55, 0x00, 0x00, - 0x00, 0x00, 0x00, 0xff, 0xfe, 0x00, 0x18, 0x00, - 0xff, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, - 0x80, 0x00, 0x87, 0x12, 0x00, 0x00, 0x00, 0x02, - 0x80, 0x00, 0xc7, 0xbf, 0x00, 0x00, 0x00, 0x01, - 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, - 0x41, 0x41]) + ipv6_packet_data = bytearray([ + 0x60, 0x00, 0x00, 0x00, 0x00, 0x1A, 0x3A, 0x40, 0xfd, 0x00, 0x12, + 0x34, 0x45, 0x55, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xfe, 0x00, + 0x18, 0x00, 0xff, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x80, 0x00, 0x87, 0x12, + 0x00, 0x00, 0x00, 0x02, 0x80, 0x00, 0xc7, 0xbf, 0x00, 0x00, 0x00, + 0x01, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41 + ]) message_info = any_message_info() message_info.source_ipv6 = "ff::" message_info.destination_address = "ff::" - factory = IPv6PacketFactory( - ulpf={ - 58: ICMPv6Factory(body_factories={ - 128: ICMPv6EchoBodyFactory() - }) - }) + factory = IPv6PacketFactory(ulpf={ + 58: ICMPv6Factory(body_factories={128: ICMPv6EchoBodyFactory()}) + }) # WHEN factory.parse(io.BytesIO(ipv6_packet_data), message_info) # THEN - self.assertEqual("fd00:1234:4555::ff:fe00:1800", message_info.source_ipv6.compressed) + self.assertEqual("fd00:1234:4555::ff:fe00:1800", + message_info.source_ipv6.compressed) self.assertEqual("ff03::1", message_info.destination_ipv6.compressed) class TestUDPDatagram(unittest.TestCase): - def test_should_creates_bytes_from_UDPHeader_and_payload_when_to_bytes_method_is_called(self): + def test_should_creates_bytes_from_UDPHeader_and_payload_when_to_bytes_method_is_called( + self): # GIVEN src_port = any_port() dst_port = any_port() checksum = any_checksum() payload = any_payload() - payload_length = len(payload) + 8 # UDP length consists of UDP header length and payload length + payload_length = len( + payload + ) + 8 # UDP length consists of UDP header length and payload length udp_header = UDPHeader(src_port, dst_port, payload_length, checksum) udp_payload = BytesPayload(payload) @@ -767,14 +780,16 @@ class TestUDPDatagram(unittest.TestCase): class TestIPv6FragmentHeader(unittest.TestCase): - def test_shold_convert_IPv6_fragment_header_to_bytes_when_to_bytes_method_is_called(self): + def test_shold_convert_IPv6_fragment_header_to_bytes_when_to_bytes_method_is_called( + self): # GIVEN type = any_type() offset = any_fragment_offset() more_flag = any_bool() identification = any_fragment_identification() - ipv6_fragment_header = FragmentHeader(type, offset, more_flag, identification) + ipv6_fragment_header = FragmentHeader(type, offset, more_flag, + identification) # WHEN actual = ipv6_fragment_header.to_bytes() @@ -785,7 +800,8 @@ class TestIPv6FragmentHeader(unittest.TestCase): self.assertEqual(expected, actual) - def test_should_create_FragmentHeader_when_from_bytes_classmethod_is_called(self): + def test_should_create_FragmentHeader_when_from_bytes_classmethod_is_called( + self): # GIVEN type = any_type() offset = any_fragment_offset() @@ -807,7 +823,8 @@ class TestIPv6FragmentHeader(unittest.TestCase): class TestICMPv6(unittest.TestCase): - def test_should_creates_bytes_from_ICMPv6Header_and_body_when_to_bytes_method_is_called(self): + def test_should_creates_bytes_from_ICMPv6Header_and_body_when_to_bytes_method_is_called( + self): # GIVEN _type = any_type() code = any_code() @@ -854,11 +871,13 @@ class TestHopByHop(unittest.TestCase): return bytearray([0x00]) elif padding_length > 1: padding_length -= 2 - return bytearray([0x01, padding_length]) + bytearray([0x00 for _ in range(padding_length)]) + return bytearray([0x01, padding_length]) + bytearray( + [0x00 for _ in range(padding_length)]) else: return bytearray() - def test_should_create_bytes_from_HopByHop_when_to_bytes_method_is_called(self): + def test_should_create_bytes_from_HopByHop_when_to_bytes_method_is_called( + self): # GIVEN next_header = any_next_header() hop_by_hop_option = any_hop_by_hop_bytes_option() @@ -870,7 +889,8 @@ class TestHopByHop(unittest.TestCase): data = hop_by_hop.to_bytes() # THEN - expected_data = bytearray([next_header, hdr_ext_len]) + hop_by_hop_option.to_bytes() + expected_data = bytearray([next_header, hdr_ext_len + ]) + hop_by_hop_option.to_bytes() padding_length = self._calculate_required_padding(len(expected_data)) expected_data += self.create_padding(padding_length) @@ -879,7 +899,8 @@ class TestHopByHop(unittest.TestCase): class TestMPLOption(unittest.TestCase): - def test_should_convert_MPLOption_to_bytes_when_to_bytes_method_is_called(self): + def test_should_convert_MPLOption_to_bytes_when_to_bytes_method_is_called( + self): # GIVEN S = any_mpl_S() M = any_mpl_M() @@ -893,10 +914,12 @@ class TestMPLOption(unittest.TestCase): data = mpl_option.to_bytes() # THEN - expected_data = bytearray([(S << 6) | (M << 5) | (V << 4), sequence]) + seed_id + expected_data = bytearray([(S << 6) | (M << 5) | + (V << 4), sequence]) + seed_id self.assertEqual(expected_data, data) - def test_should_create_MPLOption_when_to_bytes_method_is_called_with_data(self): + def test_should_create_MPLOption_when_to_bytes_method_is_called_with_data( + self): # GIVEN S = any_mpl_S() M = any_mpl_M() @@ -922,7 +945,8 @@ class TestMPLOption(unittest.TestCase): self.assertEqual(8, MPLOption._seed_id_length[2]) self.assertEqual(16, MPLOption._seed_id_length[3]) - def test_should_return_proper_length_when_len_is_called_with_mpl_option_object(self): + def test_should_return_proper_length_when_len_is_called_with_mpl_option_object( + self): # GIVEN S = any_mpl_S() M = any_mpl_M() @@ -937,12 +961,14 @@ class TestMPLOption(unittest.TestCase): # THEN SMV_and_sequence_length = 2 - self.assertEqual(SMV_and_sequence_length + len(seed_id), mpl_option_length) + self.assertEqual(SMV_and_sequence_length + len(seed_id), + mpl_option_length) class TestclassHopByHopOption(unittest.TestCase): - def test_should_convert_HopByHopOption_to_bytes_when_to_bytes_method_is_called(self): + def test_should_convert_HopByHopOption_to_bytes_when_to_bytes_method_is_called( + self): # GIVEN length = any_length() header = any_hop_by_hop_bytes_option_header(length) @@ -957,7 +983,8 @@ class TestclassHopByHopOption(unittest.TestCase): expected_data = header.to_bytes() + value.to_bytes() self.assertEqual(expected_data, data) - def test_should_return_length_of_HopByHopOption_when_len_is_called_with_hop_by_hop_option_object(self): + def test_should_return_length_of_HopByHopOption_when_len_is_called_with_hop_by_hop_option_object( + self): # GIVEN length = any_length() header = any_hop_by_hop_bytes_option_header(length) @@ -971,12 +998,14 @@ class TestclassHopByHopOption(unittest.TestCase): # THEN header_length = 2 expected_hop_by_hop_option_length = header_length + length - self.assertEqual(expected_hop_by_hop_option_length, hop_by_hop_option_length) + self.assertEqual(expected_hop_by_hop_option_length, + hop_by_hop_option_length) class TestHopByHopOptionHeader(unittest.TestCase): - def test_should_convert_HopByHopOptionHeader_to_bytes_when_to_bytes_method_is_called(self): + def test_should_convert_HopByHopOptionHeader_to_bytes_when_to_bytes_method_is_called( + self): # GIVEN _type = any_type() length = any_length() @@ -990,7 +1019,8 @@ class TestHopByHopOptionHeader(unittest.TestCase): expected_data = bytearray([_type, length]) self.assertEqual(expected_data, data) - def test_should_create_HopByHopOptionHeader_when_to_bytes_method_is_called_with_data(self): + def test_should_create_HopByHopOptionHeader_when_to_bytes_method_is_called_with_data( + self): # GIVEN _type = any_type() length = any_length() @@ -1004,7 +1034,8 @@ class TestHopByHopOptionHeader(unittest.TestCase): self.assertEqual(_type, option_header.type) self.assertEqual(length, option_header.length) - def test_should_return_proper_length_when_len_is_called_with_HopByHopOptionHeader_object(self): + def test_should_return_proper_length_when_len_is_called_with_HopByHopOptionHeader_object( + self): # GIVEN _type = any_type() length = any_length() @@ -1039,11 +1070,13 @@ class TestHopByHopFactory(unittest.TestCase): return bytearray([0x00]) elif padding_length > 1: padding_length -= 2 - return bytearray([0x01, padding_length]) + bytearray([0x00 for _ in range(padding_length)]) + return bytearray([0x01, padding_length]) + bytearray( + [0x00 for _ in range(padding_length)]) return bytearray() - def test_should_create_HopByHop_object_instance_when_to_bytes_method_is_called_with_data(self): + def test_should_create_HopByHop_object_instance_when_to_bytes_method_is_called_with_data( + self): # GIVEN hop_by_hop_option = any_hop_by_hop_mpl_option() hop_by_hop_option_type = hop_by_hop_option.header.type @@ -1053,44 +1086,51 @@ class TestHopByHopFactory(unittest.TestCase): hop_by_hop_factory = HopByHopFactory( hop_by_hop_options_factory=HopByHopOptionsFactory( - options_factories={ - hop_by_hop_option_type: MPLOptionFactory() - } - ) - ) + options_factories={hop_by_hop_option_type: MPLOptionFactory()})) - data = bytearray([next_header, hdr_ext_len]) + hop_by_hop_option.to_bytes() + data = bytearray([next_header, hdr_ext_len + ]) + hop_by_hop_option.to_bytes() data += self.padding(len(data)) # WHEN - hop_by_hop = hop_by_hop_factory.parse(io.BytesIO(data), any_message_info()) + hop_by_hop = hop_by_hop_factory.parse(io.BytesIO(data), + any_message_info()) # THEN - self.assertEqual(hop_by_hop_option.value.S, hop_by_hop.options[0].value.S) - self.assertEqual(hop_by_hop_option.value.V, hop_by_hop.options[0].value.V) - self.assertEqual(hop_by_hop_option.value.M, hop_by_hop.options[0].value.M) - self.assertEqual(hop_by_hop_option.value.sequence, hop_by_hop.options[0].value.sequence) - self.assertEqual(hop_by_hop_option.value.seed_id, hop_by_hop.options[0].value.seed_id) + self.assertEqual(hop_by_hop_option.value.S, + hop_by_hop.options[0].value.S) + self.assertEqual(hop_by_hop_option.value.V, + hop_by_hop.options[0].value.V) + self.assertEqual(hop_by_hop_option.value.M, + hop_by_hop.options[0].value.M) + self.assertEqual(hop_by_hop_option.value.sequence, + hop_by_hop.options[0].value.sequence) + self.assertEqual(hop_by_hop_option.value.seed_id, + hop_by_hop.options[0].value.seed_id) - def test_should_raise_RuntimeError_when_no_option_factory_is_set_and_parse_method_is_called(self): + def test_should_raise_RuntimeError_when_no_option_factory_is_set_and_parse_method_is_called( + self): # GIVEN hop_by_hop_option = any_hop_by_hop_mpl_option() next_header = any_next_header() hdr_ext_len = self._calculate_hdr_ext_len(2 + len(hop_by_hop_option)) - hop_by_hop_factory = HopByHopFactory(hop_by_hop_options_factory=HopByHopOptionsFactory()) + hop_by_hop_factory = HopByHopFactory( + hop_by_hop_options_factory=HopByHopOptionsFactory()) data = bytes([next_header, hdr_ext_len]) + hop_by_hop_option.to_bytes() data += self.padding(len(data)) # THEN - self.assertRaises(RuntimeError, hop_by_hop_factory.parse, io.BytesIO(data), any_message_info()) + self.assertRaises(RuntimeError, hop_by_hop_factory.parse, + io.BytesIO(data), any_message_info()) class TestMPLOptionFactory(unittest.TestCase): - def test_should_produce_MPLOption_from_bytes_when_to_bytes_method_is_called_with_data(self): + def test_should_produce_MPLOption_from_bytes_when_to_bytes_method_is_called_with_data( + self): # GIVEN S = any_mpl_S() M = any_mpl_M() @@ -1116,7 +1156,8 @@ class TestMPLOptionFactory(unittest.TestCase): class TestUdpBasedOnSrcDstPortsPayloadFactory(unittest.TestCase): - def test_should_create_payload_from_data_when_src_port_factory_is_defined_and_parse_method_is_called(self): + def test_should_create_payload_from_data_when_src_port_factory_is_defined_and_parse_method_is_called( + self): # GIVEN data = any_data() @@ -1135,7 +1176,8 @@ class TestUdpBasedOnSrcDstPortsPayloadFactory(unittest.TestCase): # THEN self.assertEqual(data, actual_data.data) - def test_should_create_payload_from_data_when_dst_port_factory_is_defined_and_parse_method_is_called(self): + def test_should_create_payload_from_data_when_dst_port_factory_is_defined_and_parse_method_is_called( + self): # GIVEN data = any_data() @@ -1154,7 +1196,8 @@ class TestUdpBasedOnSrcDstPortsPayloadFactory(unittest.TestCase): # THEN self.assertEqual(data, actual_data.data) - def test_should_raise_RuntimeError_when_parse_method_is_called_but_required_factory_is_not_defined(self): + def test_should_raise_RuntimeError_when_parse_method_is_called_but_required_factory_is_not_defined( + self): # GIVEN data = any_data() @@ -1162,15 +1205,18 @@ class TestUdpBasedOnSrcDstPortsPayloadFactory(unittest.TestCase): message_info.src_port = any_port() message_info.dst_port = any_port() - factory = UdpBasedOnSrcDstPortsPayloadFactory(src_dst_port_based_payload_factories={}) + factory = UdpBasedOnSrcDstPortsPayloadFactory( + src_dst_port_based_payload_factories={}) # THEN - self.assertRaises(RuntimeError, factory.parse, io.BytesIO(data), message_info) + self.assertRaises(RuntimeError, factory.parse, io.BytesIO(data), + message_info) class TestUDPDatagramFactory(unittest.TestCase): - def test_should_produce_UDPDatagram_from_bytes_when_to_bytes_method_is_called_with_data(self): + def test_should_produce_UDPDatagram_from_bytes_when_to_bytes_method_is_called_with_data( + self): # GIVEN src_port = any_port() dst_port = any_port() @@ -1179,10 +1225,10 @@ class TestUDPDatagramFactory(unittest.TestCase): payload = any_payload() payload_length = len(payload) + len(UDPHeader(0, 0)) - data = bytearray([(src_port >> 8), (src_port & 0xff), - (dst_port >> 8), (dst_port & 0xff), - (payload_length >> 8), (payload_length & 0xff), - (checksum >> 8), (checksum & 0xff)]) + payload + data = bytearray([(src_port >> 8), (src_port & 0xff), (dst_port >> 8), + (dst_port & 0xff), (payload_length >> 8), + (payload_length & 0xff), (checksum >> 8), + (checksum & 0xff)]) + payload factory = UDPDatagramFactory(UDPHeaderFactory(), BytesPayloadFactory()) @@ -1196,7 +1242,8 @@ class TestUDPDatagramFactory(unittest.TestCase): self.assertEqual(udp_dgram.header.checksum, checksum) self.assertEqual(udp_dgram.payload.data, payload) - def test_should_set_src_and_dst_port_in_message_info_when_parse_method_is_called(self): + def test_should_set_src_and_dst_port_in_message_info_when_parse_method_is_called( + self): # GIVEN message_info = any_message_info() @@ -1207,21 +1254,16 @@ class TestUDPDatagramFactory(unittest.TestCase): payload = any_payload() payload_length = len(payload) + len(UDPHeader(0, 0)) - data = ( - bytearray( - [ - (src_port >> 8), - (src_port & 0xff), - (dst_port >> 8), - (dst_port & 0xff), - (payload_length >> 8), - (payload_length & 0xff), - (checksum >> 8), - (checksum & 0xff), - ] - ) - + payload - ) + data = (bytearray([ + (src_port >> 8), + (src_port & 0xff), + (dst_port >> 8), + (dst_port & 0xff), + (payload_length >> 8), + (payload_length & 0xff), + (checksum >> 8), + (checksum & 0xff), + ]) + payload) factory = UDPDatagramFactory(UDPHeaderFactory(), BytesPayloadFactory()) @@ -1235,16 +1277,19 @@ class TestUDPDatagramFactory(unittest.TestCase): class TestICMPv6Factory(unittest.TestCase): - def test_should_produce_ICMPv6_from_bytes_when_to_bytes_method_is_called_with_data(self): + def test_should_produce_ICMPv6_from_bytes_when_to_bytes_method_is_called_with_data( + self): # GIVEN _type = any_type() code = any_code() checksum = any_checksum() body = any_body() - data = bytearray([_type, code, (checksum >> 8), (checksum & 0xff)]) + body + data = bytearray([_type, code, (checksum >> 8), + (checksum & 0xff)]) + body - factory = ICMPv6Factory(body_factories={_type: ICMPv6BytesBodyFactory()}) + factory = ICMPv6Factory( + body_factories={_type: ICMPv6BytesBodyFactory()}) # WHEN icmpv6_msg = factory.parse(io.BytesIO(data), any_message_info()) @@ -1255,7 +1300,8 @@ class TestICMPv6Factory(unittest.TestCase): self.assertEqual(icmpv6_msg.header.checksum, checksum) self.assertEqual(icmpv6_msg.body.bytes, body) - def test_should_raise_RuntimeError_when_method_parse_is_called_but_body_factory_is_not_present(self): + def test_should_raise_RuntimeError_when_method_parse_is_called_but_body_factory_is_not_present( + self): # GIVEN _type = any_type() code = any_code() @@ -1267,12 +1313,14 @@ class TestICMPv6Factory(unittest.TestCase): factory = ICMPv6Factory() # WHEN - self.assertRaises(RuntimeError, factory.parse, io.BytesIO(data), any_message_info()) + self.assertRaises(RuntimeError, factory.parse, io.BytesIO(data), + any_message_info()) class TestBytesPayload(unittest.TestCase): - def test_should_create_BytesPayload_when_from_bytes_class_method_is_called(self): + def test_should_create_BytesPayload_when_from_bytes_class_method_is_called( + self): # GIVEN data = any_data() @@ -1282,7 +1330,8 @@ class TestBytesPayload(unittest.TestCase): # THEN self.assertEqual(data, actual.data) - def test_should_return_exactly_the_same_data_as_passed_to_constructor_when_to_bytes_method_is_called(self): + def test_should_return_exactly_the_same_data_as_passed_to_constructor_when_to_bytes_method_is_called( + self): # GIVEN data = any_data() payload = BytesPayload(data) @@ -1293,7 +1342,8 @@ class TestBytesPayload(unittest.TestCase): # THEN self.assertEqual(data, actual) - def test_should_return_the_same_len_as_data_passed_to_constructor_when_len_is_called_on_BytesPayload_object(self): + def test_should_return_the_same_len_as_data_passed_to_constructor_when_len_is_called_on_BytesPayload_object( + self): # GIVEN data = any_data() payload = BytesPayload(data) @@ -1307,7 +1357,8 @@ class TestBytesPayload(unittest.TestCase): class TestICMPv6EchoBody(unittest.TestCase): - def test_convert_ICMPv6_echo_body_to_data_when_to_bytes_method_is_called(self): + def test_convert_ICMPv6_echo_body_to_data_when_to_bytes_method_is_called( + self): # GIVEN identifier = any_identifier() sequence_number = any_sequence_number() @@ -1319,19 +1370,21 @@ class TestICMPv6EchoBody(unittest.TestCase): actual = body.to_bytes() # THEN - expected = bytearray([identifier >> 8, identifier & 0xff, sequence_number >> 8, sequence_number & 0xff]) + data + expected = bytearray([ + identifier >> 8, identifier & 0xff, sequence_number >> 8, + sequence_number & 0xff + ]) + data self.assertEqual(expected, actual) - def test_should_create_ICMPv6EchoBody_from_data_when_from_bytes_classmethod_is_called(self): + def test_should_create_ICMPv6EchoBody_from_data_when_from_bytes_classmethod_is_called( + self): # GIVEN identifier = any_identifier() sequence_number = any_sequence_number() body_data = any_data() - data = bytearray([(identifier >> 8), - (identifier & 0xff), - (sequence_number >> 8), - (sequence_number & 0xff)]) + data = bytearray([(identifier >> 8), (identifier & 0xff), + (sequence_number >> 8), (sequence_number & 0xff)]) data += body_data # WHEN @@ -1342,19 +1395,24 @@ class TestICMPv6EchoBody(unittest.TestCase): self.assertEqual(sequence_number, actual.sequence_number) self.assertEqual(body_data, actual.data) - def test_should_build_ICMPv6EchoBody_from_well_know_values_when_to_bytes_method_is_called(self): + def test_should_build_ICMPv6EchoBody_from_well_know_values_when_to_bytes_method_is_called( + self): # GIVEN - body = ICMPv6EchoBody(0, 2, bytearray([0x80, 0x00, 0xc7, 0xbf, 0x00, 0x00, 0x00, 0x01, - 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, - 0x41, 0x41])) + body = ICMPv6EchoBody( + 0, 2, + bytearray([ + 0x80, 0x00, 0xc7, 0xbf, 0x00, 0x00, 0x00, 0x01, 0x41, 0x41, + 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41 + ])) # WHEN actual = body.to_bytes() # THEN - expected = bytearray([0x00, 0x00, 0x00, 0x02, 0x80, 0x00, 0xc7, 0xbf, - 0x00, 0x00, 0x00, 0x01, 0x41, 0x41, 0x41, 0x41, - 0x41, 0x41, 0x41, 0x41, 0x41, 0x41]) + expected = bytearray([ + 0x00, 0x00, 0x00, 0x02, 0x80, 0x00, 0xc7, 0xbf, 0x00, 0x00, 0x00, + 0x01, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41 + ]) self.assertEqual(expected, actual) @@ -1368,7 +1426,8 @@ class TestICMPv6EchoBodyFactory(unittest.TestCase): body_data = any_data() data = bytearray([(identifier >> 8) & 0xff, identifier & 0xff, - (sequence_number >> 8) & 0xff, sequence_number & 0xff]) + body_data + (sequence_number >> 8) & 0xff, sequence_number & 0xff + ]) + body_data factory = ICMPv6EchoBodyFactory() @@ -1385,7 +1444,8 @@ class TestICMPv6EchoBodyFactory(unittest.TestCase): class TestICMPv6DestinationUnreachable(unittest.TestCase): - def test_should_convert_ICMPv6DestinationUnreachable_to_bytearray_when_to_bytes_method_is_called(self): + def test_should_convert_ICMPv6DestinationUnreachable_to_bytearray_when_to_bytes_method_is_called( + self): # GIVEN data = any_data() @@ -1395,9 +1455,11 @@ class TestICMPv6DestinationUnreachable(unittest.TestCase): actual_data = icmpv6_dest_unreachable.to_bytes() # THEN - self.assertEqual(bytearray([0x00, 0x00, 0x00, 0x00]) + data, actual_data) + self.assertEqual( + bytearray([0x00, 0x00, 0x00, 0x00]) + data, actual_data) - def test_should_convert_bytearray_to_ICMPv6DestinationUnreachable_when_from_bytes_method_is_called(self): + def test_should_convert_bytearray_to_ICMPv6DestinationUnreachable_when_from_bytes_method_is_called( + self): # GIVEN data = any_data() @@ -1415,13 +1477,15 @@ class TestICMPv6DestinationUnreachable(unittest.TestCase): unused = random.randint(1, 1 << 32) # WHEN - self.assertRaises(RuntimeError, ICMPv6DestinationUnreachable.from_bytes, - io.BytesIO(bytearray(struct.pack(">I", unused)) + data)) + self.assertRaises( + RuntimeError, ICMPv6DestinationUnreachable.from_bytes, + io.BytesIO(bytearray(struct.pack(">I", unused)) + data)) class TestICMPv6DestinationUnreachableFactory(unittest.TestCase): - def test_should_create_ICMPv6DestinationUnreachable_when_parse_method_is_called(self): + def test_should_create_ICMPv6DestinationUnreachable_when_parse_method_is_called( + self): # GIVEN icmp_data = any_data() @@ -1430,7 +1494,8 @@ class TestICMPv6DestinationUnreachableFactory(unittest.TestCase): data = bytearray([0x00, 0x00, 0x00, 0x00]) + icmp_data # WHEN - icmpv6_dest_unreachable = factory.parse(io.BytesIO(data), any_message_info()) + icmpv6_dest_unreachable = factory.parse(io.BytesIO(data), + any_message_info()) # THEN self.assertEqual(icmp_data, icmpv6_dest_unreachable.data) @@ -1462,7 +1527,8 @@ class TestUDPHeaderFactory(unittest.TestCase): class TestHopByHopOptionsFactory(unittest.TestCase): - def test_should_create_option_from_bytearray_when_to_bytes_method_is_called(self): + def test_should_create_option_from_bytearray_when_to_bytes_method_is_called( + self): # GIVEN class DummyOptionFactory: @@ -1470,7 +1536,8 @@ class TestHopByHopOptionsFactory(unittest.TestCase): def parse(self, data, message_info): return data.read() - factory = HopByHopOptionsFactory(options_factories={2: DummyOptionFactory()}) + factory = HopByHopOptionsFactory( + options_factories={2: DummyOptionFactory()}) data = bytearray([0x02, 0x03, 0x11, 0x22, 0x33, 0x01, 0x00]) diff --git a/tests/scripts/thread-cert/test_ipv6_fragmentation.py b/tests/scripts/thread-cert/test_ipv6_fragmentation.py index 90bb4408a..545848353 100755 --- a/tests/scripts/thread-cert/test_ipv6_fragmentation.py +++ b/tests/scripts/thread-cert/test_ipv6_fragmentation.py @@ -71,8 +71,10 @@ class TestIPv6Fragmentation(unittest.TestCase): self.simulator.go(5) self.assertEqual(self.nodes[ROUTER].get_state(), 'router') - mleid_leader = self.nodes[LEADER].get_ip6_address(config.ADDRESS_TYPE.ML_EID) - mleid_router = self.nodes[ROUTER].get_ip6_address(config.ADDRESS_TYPE.ML_EID) + mleid_leader = self.nodes[LEADER].get_ip6_address( + config.ADDRESS_TYPE.ML_EID) + mleid_router = self.nodes[ROUTER].get_ip6_address( + config.ADDRESS_TYPE.ML_EID) self.nodes[LEADER].udp_start("::", 12345) self.nodes[ROUTER].udp_start("::", 12345) diff --git a/tests/scripts/thread-cert/test_lowpan.py b/tests/scripts/thread-cert/test_lowpan.py index 04ebc1c99..4635f88bb 100755 --- a/tests/scripts/thread-cert/test_lowpan.py +++ b/tests/scripts/thread-cert/test_lowpan.py @@ -41,20 +41,22 @@ import lowpan def create_default_lowpan_parser(context_manager): return lowpan.LowpanParser( lowpan_mesh_header_factory=lowpan.LowpanMeshHeaderFactory(), - lowpan_decompressor=config.create_default_lowpan_decompressor(context_manager), - lowpan_fragements_buffers_manager=lowpan.LowpanFragmentsBuffersManager(), + lowpan_decompressor=config.create_default_lowpan_decompressor( + context_manager), + lowpan_fragements_buffers_manager=lowpan.LowpanFragmentsBuffersManager( + ), ipv6_packet_factory=ipv6.IPv6PacketFactory( ehf=config.create_default_ipv6_extension_headers_factories(), ulpf={ - 17: ipv6.UDPDatagramFactory( - udp_header_factory=ipv6.UDPHeaderFactory(), - udp_payload_factory=ipv6.BytesPayloadFactory()), - 58: ipv6.ICMPv6Factory( - body_factories=config.create_default_ipv6_icmp_body_factories() - ) - } - ) - ) + 17: + ipv6.UDPDatagramFactory( + udp_header_factory=ipv6.UDPHeaderFactory(), + udp_payload_factory=ipv6.BytesPayloadFactory()), + 58: + ipv6.ICMPv6Factory( + body_factories=config. + create_default_ipv6_icmp_body_factories()) + })) def any_tf(): @@ -194,7 +196,8 @@ def any_dst_mac_addr(): def any_context(): - prefix = bytearray([random.getrandbits(8) for _ in range(random.randint(2, 15))]) + prefix = bytearray( + [random.getrandbits(8) for _ in range(random.randint(2, 15))]) prefix_length = len(prefix) return lowpan.Context(prefix, prefix_length * 8) @@ -202,9 +205,11 @@ def any_context(): def any_mac_address(): length = random.choice([2, 8]) if length == 2: - return common.MacAddress.from_rloc16(bytearray([random.getrandbits(8) for _ in range(length)])) + return common.MacAddress.from_rloc16( + bytearray([random.getrandbits(8) for _ in range(length)])) elif length == 8: - return common.MacAddress.from_eui64(bytearray([random.getrandbits(8) for _ in range(length)])) + return common.MacAddress.from_eui64( + bytearray([random.getrandbits(8) for _ in range(length)])) def any_hops_left(): @@ -230,7 +235,8 @@ def any_datagram_offset(): class TestLowpanIPHC(unittest.TestCase): - def test_should_create_LowpanIPHC_object_when_from_bytes_classmethod_called(self): + def test_should_create_LowpanIPHC_object_when_from_bytes_classmethod_called( + self): # GIVEN tf = any_tf() nh = any_nh() @@ -243,7 +249,8 @@ class TestLowpanIPHC(unittest.TestCase): dam = any_dam() byte0 = (3 << 5) | (tf << 3) | (nh << 2) | hlim - byte1 = (cid << 7) | (sac << 6) | (sam << 4) | (m << 3) | (dac << 2) | dam + byte1 = (cid << 7) | (sac << 6) | (sam << 4) | (m << 3) | ( + dac << 2) | dam data_bytes = bytearray([byte0, byte1]) @@ -264,24 +271,25 @@ class TestLowpanIPHC(unittest.TestCase): class TestLowpanParser(unittest.TestCase): - def test_should_parse_6lo_with_mesh_hdr_that_contains_hlim_stored_on_2_bytes_when_decompress_method_called(self): + def test_should_parse_6lo_with_mesh_hdr_that_contains_hlim_stored_on_2_bytes_when_decompress_method_called( + self): # GIVEN - lowpan_packet = bytearray([0xbf, 0x13, 0x90, 0x00, 0x48, 0x01, 0x7c, 0x77, - 0x3f, 0xf2, 0xbf, 0xc0, 0x00, 0x24, 0xb1, 0x62, - 0x44, 0x02, 0xf0, 0xba, 0x0d, 0xff, 0x04, 0x01, - 0x00, 0x02, 0x02, 0x08, 0x00, 0x07, 0x09, 0x50, - 0x20, 0x00, 0x20, 0x00, 0x08, 0x00, 0x00, 0x00]) + lowpan_packet = bytearray([ + 0xbf, 0x13, 0x90, 0x00, 0x48, 0x01, 0x7c, 0x77, 0x3f, 0xf2, 0xbf, + 0xc0, 0x00, 0x24, 0xb1, 0x62, 0x44, 0x02, 0xf0, 0xba, 0x0d, 0xff, + 0x04, 0x01, 0x00, 0x02, 0x02, 0x08, 0x00, 0x07, 0x09, 0x50, 0x20, + 0x00, 0x20, 0x00, 0x08, 0x00, 0x00, 0x00 + ]) - ipv6_packet = bytearray([0x60, 0x00, 0x00, 0x00, 0x00, 0x21, 0x11, 0x3f, - 0xfd, 0x00, 0x0d, 0xb8, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0xff, 0xfe, 0x00, 0x90, 0x00, - 0xfd, 0x00, 0x0d, 0xb8, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0xff, 0xfe, 0x00, 0x48, 0x01, - 0xf0, 0xbf, 0xc0, 0x00, 0x00, 0x21, 0xe2, 0xdd, - 0x62, 0x44, 0x02, 0xf0, 0xba, 0x0d, 0xff, 0x04, - 0x01, 0x00, 0x02, 0x02, 0x08, 0x00, 0x07, 0x09, - 0x50, 0x20, 0x00, 0x20, 0x00, 0x08, 0x00, 0x00, - 0x00]) + ipv6_packet = bytearray([ + 0x60, 0x00, 0x00, 0x00, 0x00, 0x21, 0x11, 0x3f, 0xfd, 0x00, 0x0d, + 0xb8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xfe, 0x00, + 0x90, 0x00, 0xfd, 0x00, 0x0d, 0xb8, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0xff, 0xfe, 0x00, 0x48, 0x01, 0xf0, 0xbf, 0xc0, 0x00, + 0x00, 0x21, 0xe2, 0xdd, 0x62, 0x44, 0x02, 0xf0, 0xba, 0x0d, 0xff, + 0x04, 0x01, 0x00, 0x02, 0x02, 0x08, 0x00, 0x07, 0x09, 0x50, 0x20, + 0x00, 0x20, 0x00, 0x08, 0x00, 0x00, 0x00 + ]) message_info = common.MessageInfo() message_info.source_mac_address = common.MacAddress.from_eui64( @@ -295,25 +303,29 @@ class TestLowpanParser(unittest.TestCase): parser = create_default_lowpan_parser(context_manager) # WHEN - actual_ipv6_packet = parser.parse(io.BytesIO(lowpan_packet), message_info) + actual_ipv6_packet = parser.parse(io.BytesIO(lowpan_packet), + message_info) # THEN self.assertEqual(ipv6_packet, actual_ipv6_packet.to_bytes()) - def test_should_parse_6lo_with_uncompressed_udp_and_without_hbh_when_decompress_method_called(self): + def test_should_parse_6lo_with_uncompressed_udp_and_without_hbh_when_decompress_method_called( + self): # GIVEN - lowpan_packet = bytearray([0x7a, 0x33, 0x11, 0x16, 0x33, 0x16, 0x34, 0x00, - 0x14, 0xcf, 0x63, 0x80, 0x00, 0xfa, 0xa5, 0x0b, - 0xc0, 0x00, 0x04, 0x4e, 0x92, 0xbb, 0x53]) + lowpan_packet = bytearray([ + 0x7a, 0x33, 0x11, 0x16, 0x33, 0x16, 0x34, 0x00, 0x14, 0xcf, 0x63, + 0x80, 0x00, 0xfa, 0xa5, 0x0b, 0xc0, 0x00, 0x04, 0x4e, 0x92, 0xbb, + 0x53 + ]) - ipv6_packet = bytearray([0x60, 0x00, 0x00, 0x00, 0x00, 0x14, 0x11, 0x40, - 0xfe, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x02, 0x99, 0x99, 0xff, 0xfe, 0x22, 0x11, 0x00, - 0xfe, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x36, 0x29, 0x96, 0xff, 0xfe, 0xac, 0xff, 0x17, - 0x16, 0x33, 0x16, 0x34, 0x00, 0x14, 0xcf, 0x63, - 0x80, 0x00, 0xfa, 0xa5, 0x0b, 0xc0, 0x00, 0x04, - 0x4e, 0x92, 0xbb, 0x53]) + ipv6_packet = bytearray([ + 0x60, 0x00, 0x00, 0x00, 0x00, 0x14, 0x11, 0x40, 0xfe, 0x80, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x99, 0x99, 0xff, 0xfe, 0x22, + 0x11, 0x00, 0xfe, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x36, + 0x29, 0x96, 0xff, 0xfe, 0xac, 0xff, 0x17, 0x16, 0x33, 0x16, 0x34, + 0x00, 0x14, 0xcf, 0x63, 0x80, 0x00, 0xfa, 0xa5, 0x0b, 0xc0, 0x00, + 0x04, 0x4e, 0x92, 0xbb, 0x53 + ]) message_info = common.MessageInfo() message_info.source_mac_address = common.MacAddress.from_eui64( @@ -324,25 +336,28 @@ class TestLowpanParser(unittest.TestCase): parser = create_default_lowpan_parser(context_manager=None) # WHEN - actual_ipv6_packet = parser.parse(io.BytesIO(lowpan_packet), message_info) + actual_ipv6_packet = parser.parse(io.BytesIO(lowpan_packet), + message_info) # THEN self.assertEqual(ipv6_packet, actual_ipv6_packet.to_bytes()) - def test_should_parse_6lo_with_compressed_udp_and_without_hbh_when_decompress_method_called(self): + def test_should_parse_6lo_with_compressed_udp_and_without_hbh_when_decompress_method_called( + self): # GIVEN - lowpan_packet = bytearray([0x7e, 0x33, 0xf0, 0x16, 0x33, 0x16, 0x34, 0x04, - 0xd2, 0x80, 0x00, 0xfa, 0xa5, 0x0b, 0xc0, 0x00, - 0x04, 0x4e, 0x92, 0xbb, 0x53]) + lowpan_packet = bytearray([ + 0x7e, 0x33, 0xf0, 0x16, 0x33, 0x16, 0x34, 0x04, 0xd2, 0x80, 0x00, + 0xfa, 0xa5, 0x0b, 0xc0, 0x00, 0x04, 0x4e, 0x92, 0xbb, 0x53 + ]) - ipv6_packet = bytearray([0x60, 0x00, 0x00, 0x00, 0x00, 0x14, 0x11, 0x40, - 0xfe, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x02, 0x99, 0x99, 0xff, 0xfe, 0x22, 0x11, 0x00, - 0xfe, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x36, 0x29, 0x96, 0xff, 0xfe, 0xac, 0xff, 0x17, - 0x16, 0x33, 0x16, 0x34, 0x00, 0x14, 0xcf, 0x63, - 0x80, 0x00, 0xfa, 0xa5, 0x0b, 0xc0, 0x00, 0x04, - 0x4e, 0x92, 0xbb, 0x53]) + ipv6_packet = bytearray([ + 0x60, 0x00, 0x00, 0x00, 0x00, 0x14, 0x11, 0x40, 0xfe, 0x80, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x99, 0x99, 0xff, 0xfe, 0x22, + 0x11, 0x00, 0xfe, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x36, + 0x29, 0x96, 0xff, 0xfe, 0xac, 0xff, 0x17, 0x16, 0x33, 0x16, 0x34, + 0x00, 0x14, 0xcf, 0x63, 0x80, 0x00, 0xfa, 0xa5, 0x0b, 0xc0, 0x00, + 0x04, 0x4e, 0x92, 0xbb, 0x53 + ]) message_info = common.MessageInfo() message_info.source_mac_address = common.MacAddress.from_eui64( @@ -353,27 +368,30 @@ class TestLowpanParser(unittest.TestCase): parser = create_default_lowpan_parser(context_manager=None) # WHEN - actual_ipv6_packet = parser.parse(io.BytesIO(lowpan_packet), message_info) + actual_ipv6_packet = parser.parse(io.BytesIO(lowpan_packet), + message_info) # THEN self.assertEqual(ipv6_packet, actual_ipv6_packet.to_bytes()) - def test_should_parse_6lo_with_uncompressed_udp_and_with_uncompressed_hbh_when_decompress_method_called(self): + def test_should_parse_6lo_with_uncompressed_udp_and_with_uncompressed_hbh_when_decompress_method_called( + self): # GIVEN - lowpan_packet = bytearray([0x7a, 0x33, 0x00, 0x11, 0x00, 0x6d, 0x04, 0x40, - 0x02, 0x00, 0x18, 0x16, 0x33, 0x16, 0x34, 0x00, - 0x0c, 0x04, 0xd2, 0x80, 0x00, 0xfa, 0xa5, 0x0b, - 0xc0, 0x00, 0x04, 0x4e, 0x92, 0xbb, 0x53]) + lowpan_packet = bytearray([ + 0x7a, 0x33, 0x00, 0x11, 0x00, 0x6d, 0x04, 0x40, 0x02, 0x00, 0x18, + 0x16, 0x33, 0x16, 0x34, 0x00, 0x0c, 0x04, 0xd2, 0x80, 0x00, 0xfa, + 0xa5, 0x0b, 0xc0, 0x00, 0x04, 0x4e, 0x92, 0xbb, 0x53 + ]) - ipv6_packet = bytearray([0x60, 0x00, 0x00, 0x00, 0x00, 0x1c, 0x00, 0x40, - 0xfe, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x02, 0x99, 0x99, 0xff, 0xfe, 0x22, 0x11, 0x00, - 0xfe, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x36, 0x29, 0x96, 0xff, 0xfe, 0xac, 0xff, 0x17, - 0x11, 0x00, 0x6d, 0x04, 0x40, 0x02, 0x00, 0x18, - 0x16, 0x33, 0x16, 0x34, 0x00, 0x14, 0xcf, 0x63, - 0x80, 0x00, 0xfa, 0xa5, 0x0b, 0xc0, 0x00, 0x04, - 0x4e, 0x92, 0xbb, 0x53]) + ipv6_packet = bytearray([ + 0x60, 0x00, 0x00, 0x00, 0x00, 0x1c, 0x00, 0x40, 0xfe, 0x80, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x99, 0x99, 0xff, 0xfe, 0x22, + 0x11, 0x00, 0xfe, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x36, + 0x29, 0x96, 0xff, 0xfe, 0xac, 0xff, 0x17, 0x11, 0x00, 0x6d, 0x04, + 0x40, 0x02, 0x00, 0x18, 0x16, 0x33, 0x16, 0x34, 0x00, 0x14, 0xcf, + 0x63, 0x80, 0x00, 0xfa, 0xa5, 0x0b, 0xc0, 0x00, 0x04, 0x4e, 0x92, + 0xbb, 0x53 + ]) message_info = common.MessageInfo() message_info.source_mac_address = common.MacAddress.from_eui64( @@ -384,27 +402,30 @@ class TestLowpanParser(unittest.TestCase): parser = create_default_lowpan_parser(context_manager=None) # WHEN - actual_ipv6_packet = parser.parse(io.BytesIO(lowpan_packet), message_info) + actual_ipv6_packet = parser.parse(io.BytesIO(lowpan_packet), + message_info) # THEN self.assertEqual(ipv6_packet, actual_ipv6_packet.to_bytes()) - def test_should_parse_6lo_with_uncompressed_udp_and_with_compressed_hbh_when_decompress_method_called(self): + def test_should_parse_6lo_with_uncompressed_udp_and_with_compressed_hbh_when_decompress_method_called( + self): # GIVEN - lowpan_packet = bytearray([0x7e, 0x33, 0xe0, 0x11, 0x06, 0x6d, 0x04, 0x40, - 0x02, 0x00, 0x18, 0x16, 0x33, 0x16, 0x34, 0x00, - 0x0c, 0x04, 0xd2, 0x80, 0x00, 0xfa, 0xa5, 0x0b, - 0xc0, 0x00, 0x04, 0x4e, 0x92, 0xbb, 0x53]) + lowpan_packet = bytearray([ + 0x7e, 0x33, 0xe0, 0x11, 0x06, 0x6d, 0x04, 0x40, 0x02, 0x00, 0x18, + 0x16, 0x33, 0x16, 0x34, 0x00, 0x0c, 0x04, 0xd2, 0x80, 0x00, 0xfa, + 0xa5, 0x0b, 0xc0, 0x00, 0x04, 0x4e, 0x92, 0xbb, 0x53 + ]) - ipv6_packet = bytearray([0x60, 0x00, 0x00, 0x00, 0x00, 0x1c, 0x00, 0x40, - 0xfe, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x02, 0x99, 0x99, 0xff, 0xfe, 0x22, 0x11, 0x00, - 0xfe, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x36, 0x29, 0x96, 0xff, 0xfe, 0xac, 0xff, 0x17, - 0x11, 0x00, 0x6d, 0x04, 0x40, 0x02, 0x00, 0x18, - 0x16, 0x33, 0x16, 0x34, 0x00, 0x14, 0xcf, 0x63, - 0x80, 0x00, 0xfa, 0xa5, 0x0b, 0xc0, 0x00, 0x04, - 0x4e, 0x92, 0xbb, 0x53]) + ipv6_packet = bytearray([ + 0x60, 0x00, 0x00, 0x00, 0x00, 0x1c, 0x00, 0x40, 0xfe, 0x80, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x99, 0x99, 0xff, 0xfe, 0x22, + 0x11, 0x00, 0xfe, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x36, + 0x29, 0x96, 0xff, 0xfe, 0xac, 0xff, 0x17, 0x11, 0x00, 0x6d, 0x04, + 0x40, 0x02, 0x00, 0x18, 0x16, 0x33, 0x16, 0x34, 0x00, 0x14, 0xcf, + 0x63, 0x80, 0x00, 0xfa, 0xa5, 0x0b, 0xc0, 0x00, 0x04, 0x4e, 0x92, + 0xbb, 0x53 + ]) message_info = common.MessageInfo() message_info.source_mac_address = common.MacAddress.from_eui64( @@ -415,27 +436,30 @@ class TestLowpanParser(unittest.TestCase): parser = create_default_lowpan_parser(context_manager=None) # WHEN - actual_ipv6_packet = parser.parse(io.BytesIO(lowpan_packet), message_info) + actual_ipv6_packet = parser.parse(io.BytesIO(lowpan_packet), + message_info) # THEN self.assertEqual(ipv6_packet, actual_ipv6_packet.to_bytes()) - def test_should_parse_6lo_with_compressed_udp_and_with_compressed_hbh_when_decompress_method_called(self): + def test_should_parse_6lo_with_compressed_udp_and_with_compressed_hbh_when_decompress_method_called( + self): # GIVEN - lowpan_packet = bytearray([0x7e, 0x33, 0xe1, 0x06, 0x6d, 0x04, 0x40, 0x02, - 0x00, 0x18, 0xf0, 0x16, 0x33, 0x16, 0x34, 0x04, - 0xd2, 0x80, 0x00, 0xfa, 0xa5, 0x0b, 0xc0, 0x00, - 0x04, 0x4e, 0x92, 0xbb, 0x53]) + lowpan_packet = bytearray([ + 0x7e, 0x33, 0xe1, 0x06, 0x6d, 0x04, 0x40, 0x02, 0x00, 0x18, 0xf0, + 0x16, 0x33, 0x16, 0x34, 0x04, 0xd2, 0x80, 0x00, 0xfa, 0xa5, 0x0b, + 0xc0, 0x00, 0x04, 0x4e, 0x92, 0xbb, 0x53 + ]) - ipv6_packet = bytearray([0x60, 0x00, 0x00, 0x00, 0x00, 0x1c, 0x00, 0x40, - 0xfe, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x02, 0x99, 0x99, 0xff, 0xfe, 0x22, 0x11, 0x00, - 0xfe, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x36, 0x29, 0x96, 0xff, 0xfe, 0xac, 0xff, 0x17, - 0x11, 0x00, 0x6d, 0x04, 0x40, 0x02, 0x00, 0x18, - 0x16, 0x33, 0x16, 0x34, 0x00, 0x14, 0xcf, 0x63, - 0x80, 0x00, 0xfa, 0xa5, 0x0b, 0xc0, 0x00, 0x04, - 0x4e, 0x92, 0xbb, 0x53]) + ipv6_packet = bytearray([ + 0x60, 0x00, 0x00, 0x00, 0x00, 0x1c, 0x00, 0x40, 0xfe, 0x80, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x99, 0x99, 0xff, 0xfe, 0x22, + 0x11, 0x00, 0xfe, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x36, + 0x29, 0x96, 0xff, 0xfe, 0xac, 0xff, 0x17, 0x11, 0x00, 0x6d, 0x04, + 0x40, 0x02, 0x00, 0x18, 0x16, 0x33, 0x16, 0x34, 0x00, 0x14, 0xcf, + 0x63, 0x80, 0x00, 0xfa, 0xa5, 0x0b, 0xc0, 0x00, 0x04, 0x4e, 0x92, + 0xbb, 0x53 + ]) message_info = common.MessageInfo() message_info.source_mac_address = common.MacAddress.from_eui64( @@ -446,25 +470,28 @@ class TestLowpanParser(unittest.TestCase): parser = create_default_lowpan_parser(context_manager=None) # WHEN - actual_ipv6_packet = parser.parse(io.BytesIO(lowpan_packet), message_info) + actual_ipv6_packet = parser.parse(io.BytesIO(lowpan_packet), + message_info) # THEN self.assertEqual(ipv6_packet, actual_ipv6_packet.to_bytes()) - def test_should_parse_6lo_with_compressed_icmp_and_without_compressed_hbh_when_decompress_method_called(self): + def test_should_parse_6lo_with_compressed_icmp_and_without_compressed_hbh_when_decompress_method_called( + self): # GIVEN - lowpan_packet = bytearray([0x7a, 0xd5, 0xaa, 0x3a, 0x02, 0x99, 0x99, 0xff, - 0xfe, 0x22, 0x11, 0x01, 0x36, 0x29, 0x96, 0xff, - 0xfe, 0xac, 0xff, 0x18, 0x80, 0x00, 0xfa, 0xa5, - 0x0b, 0xc0, 0x00, 0x04, 0x4e, 0x92, 0xbb, 0x53]) + lowpan_packet = bytearray([ + 0x7a, 0xd5, 0xaa, 0x3a, 0x02, 0x99, 0x99, 0xff, 0xfe, 0x22, 0x11, + 0x01, 0x36, 0x29, 0x96, 0xff, 0xfe, 0xac, 0xff, 0x18, 0x80, 0x00, + 0xfa, 0xa5, 0x0b, 0xc0, 0x00, 0x04, 0x4e, 0x92, 0xbb, 0x53 + ]) - ipv6_packet = bytearray([0x60, 0x00, 0x00, 0x00, 0x00, 0x0c, 0x3a, 0x40, - 0x20, 0x00, 0x0d, 0xb8, 0x00, 0x00, 0x00, 0x00, - 0x02, 0x99, 0x99, 0xff, 0xfe, 0x22, 0x11, 0x01, - 0x20, 0x00, 0x0d, 0xb8, 0x00, 0x00, 0x00, 0x00, - 0x36, 0x29, 0x96, 0xff, 0xfe, 0xac, 0xff, 0x18, - 0x80, 0x00, 0x97, 0xf3, 0x0b, 0xc0, 0x00, 0x04, - 0x4e, 0x92, 0xbb, 0x53]) + ipv6_packet = bytearray([ + 0x60, 0x00, 0x00, 0x00, 0x00, 0x0c, 0x3a, 0x40, 0x20, 0x00, 0x0d, + 0xb8, 0x00, 0x00, 0x00, 0x00, 0x02, 0x99, 0x99, 0xff, 0xfe, 0x22, + 0x11, 0x01, 0x20, 0x00, 0x0d, 0xb8, 0x00, 0x00, 0x00, 0x00, 0x36, + 0x29, 0x96, 0xff, 0xfe, 0xac, 0xff, 0x18, 0x80, 0x00, 0x97, 0xf3, + 0x0b, 0xc0, 0x00, 0x04, 0x4e, 0x92, 0xbb, 0x53 + ]) message_info = common.MessageInfo() message_info.source_mac_address = common.MacAddress.from_eui64( @@ -478,25 +505,28 @@ class TestLowpanParser(unittest.TestCase): parser = create_default_lowpan_parser(context_manager) # WHEN - actual_ipv6_packet = parser.parse(io.BytesIO(lowpan_packet), message_info) + actual_ipv6_packet = parser.parse(io.BytesIO(lowpan_packet), + message_info) # THEN self.assertEqual(ipv6_packet, actual_ipv6_packet.to_bytes()) - def test_should_parse_6lo_with_compressed_icmp_and_without_compressed_hbh_when_decompress_method_called_1(self): + def test_should_parse_6lo_with_compressed_icmp_and_without_compressed_hbh_when_decompress_method_called_1( + self): # GIVEN - lowpan_packet = bytearray([0x7a, 0xd5, 0xaa, 0x3a, 0x02, 0x99, 0x99, 0xff, - 0xfe, 0x22, 0x11, 0x01, 0x36, 0x29, 0x96, 0xff, - 0xfe, 0xac, 0xff, 0x18, 0x80, 0x00, 0xfa, 0xa5, - 0x0b, 0xc0, 0x00, 0x04, 0x4e, 0x92, 0xbb, 0x53]) + lowpan_packet = bytearray([ + 0x7a, 0xd5, 0xaa, 0x3a, 0x02, 0x99, 0x99, 0xff, 0xfe, 0x22, 0x11, + 0x01, 0x36, 0x29, 0x96, 0xff, 0xfe, 0xac, 0xff, 0x18, 0x80, 0x00, + 0xfa, 0xa5, 0x0b, 0xc0, 0x00, 0x04, 0x4e, 0x92, 0xbb, 0x53 + ]) - ipv6_packet = bytearray([0x60, 0x00, 0x00, 0x00, 0x00, 0x0c, 0x3a, 0x40, - 0x20, 0x00, 0x0d, 0xb8, 0x00, 0x00, 0x00, 0x00, - 0x02, 0x99, 0x99, 0xff, 0xfe, 0x22, 0x11, 0x01, - 0x20, 0x00, 0x0d, 0xb8, 0x00, 0x00, 0x00, 0x00, - 0x36, 0x29, 0x96, 0xff, 0xfe, 0xac, 0xff, 0x18, - 0x80, 0x00, 0x97, 0xf3, 0x0b, 0xc0, 0x00, 0x04, - 0x4e, 0x92, 0xbb, 0x53]) + ipv6_packet = bytearray([ + 0x60, 0x00, 0x00, 0x00, 0x00, 0x0c, 0x3a, 0x40, 0x20, 0x00, 0x0d, + 0xb8, 0x00, 0x00, 0x00, 0x00, 0x02, 0x99, 0x99, 0xff, 0xfe, 0x22, + 0x11, 0x01, 0x20, 0x00, 0x0d, 0xb8, 0x00, 0x00, 0x00, 0x00, 0x36, + 0x29, 0x96, 0xff, 0xfe, 0xac, 0xff, 0x18, 0x80, 0x00, 0x97, 0xf3, + 0x0b, 0xc0, 0x00, 0x04, 0x4e, 0x92, 0xbb, 0x53 + ]) message_info = common.MessageInfo() message_info.source_mac_address = common.MacAddress.from_eui64( @@ -510,25 +540,28 @@ class TestLowpanParser(unittest.TestCase): parser = create_default_lowpan_parser(context_manager) # WHEN - actual_ipv6_packet = parser.parse(io.BytesIO(lowpan_packet), message_info) + actual_ipv6_packet = parser.parse(io.BytesIO(lowpan_packet), + message_info) # THEN self.assertEqual(ipv6_packet, actual_ipv6_packet.to_bytes()) - def test_should_parse_6lo_with_compressed_icmp_and_without_compressed_hbh_when_decompress_method_called_2(self): + def test_should_parse_6lo_with_compressed_icmp_and_without_compressed_hbh_when_decompress_method_called_2( + self): # GIVEN - lowpan_packet = bytearray([0x7a, 0xf0, 0xa0, 0x3a, 0x20, 0x0d, 0x14, 0x56, - 0x12, 0x55, 0x00, 0x00, 0x25, 0x14, 0x46, 0xff, - 0xfe, 0xdd, 0x2a, 0xfe, 0x80, 0x00, 0xfa, 0xa5, - 0x0b, 0xc0, 0x00, 0x04, 0x4e, 0x92, 0xbb, 0x53]) + lowpan_packet = bytearray([ + 0x7a, 0xf0, 0xa0, 0x3a, 0x20, 0x0d, 0x14, 0x56, 0x12, 0x55, 0x00, + 0x00, 0x25, 0x14, 0x46, 0xff, 0xfe, 0xdd, 0x2a, 0xfe, 0x80, 0x00, + 0xfa, 0xa5, 0x0b, 0xc0, 0x00, 0x04, 0x4e, 0x92, 0xbb, 0x53 + ]) - ipv6_packet = bytearray([0x60, 0x00, 0x00, 0x00, 0x00, 0x0c, 0x3a, 0x40, - 0x20, 0x00, 0x0d, 0xb8, 0x00, 0x00, 0x00, 0x00, - 0x02, 0x99, 0x99, 0xff, 0xfe, 0x22, 0x11, 0x00, - 0x20, 0x0d, 0x14, 0x56, 0x12, 0x55, 0x00, 0x00, - 0x25, 0x14, 0x46, 0xff, 0xfe, 0xdd, 0x2a, 0xfe, - 0x80, 0x00, 0xb3, 0xf3, 0x0b, 0xc0, 0x00, 0x04, - 0x4e, 0x92, 0xbb, 0x53]) + ipv6_packet = bytearray([ + 0x60, 0x00, 0x00, 0x00, 0x00, 0x0c, 0x3a, 0x40, 0x20, 0x00, 0x0d, + 0xb8, 0x00, 0x00, 0x00, 0x00, 0x02, 0x99, 0x99, 0xff, 0xfe, 0x22, + 0x11, 0x00, 0x20, 0x0d, 0x14, 0x56, 0x12, 0x55, 0x00, 0x00, 0x25, + 0x14, 0x46, 0xff, 0xfe, 0xdd, 0x2a, 0xfe, 0x80, 0x00, 0xb3, 0xf3, + 0x0b, 0xc0, 0x00, 0x04, 0x4e, 0x92, 0xbb, 0x53 + ]) message_info = common.MessageInfo() message_info.source_mac_address = common.MacAddress.from_eui64( @@ -542,25 +575,28 @@ class TestLowpanParser(unittest.TestCase): parser = create_default_lowpan_parser(context_manager) # WHEN - actual_ipv6_packet = parser.parse(io.BytesIO(lowpan_packet), message_info) + actual_ipv6_packet = parser.parse(io.BytesIO(lowpan_packet), + message_info) # THEN self.assertEqual(ipv6_packet, actual_ipv6_packet.to_bytes()) - def test_should_parse_6lo_with_compressed_icmp_and_without_compressed_hbh_when_decompress_method_called_3(self): + def test_should_parse_6lo_with_compressed_icmp_and_without_compressed_hbh_when_decompress_method_called_3( + self): # GIVEN - lowpan_packet = bytearray([0x7a, 0xd5, 0xaa, 0x3a, 0x02, 0x99, 0x99, 0xff, - 0xfe, 0x22, 0x11, 0x01, 0x36, 0x29, 0x96, 0xff, - 0xfe, 0xac, 0xff, 0x18, 0x80, 0x00, 0xfa, 0xa5, - 0x0b, 0xc0, 0x00, 0x04, 0x4e, 0x92, 0xbb, 0x53]) + lowpan_packet = bytearray([ + 0x7a, 0xd5, 0xaa, 0x3a, 0x02, 0x99, 0x99, 0xff, 0xfe, 0x22, 0x11, + 0x01, 0x36, 0x29, 0x96, 0xff, 0xfe, 0xac, 0xff, 0x18, 0x80, 0x00, + 0xfa, 0xa5, 0x0b, 0xc0, 0x00, 0x04, 0x4e, 0x92, 0xbb, 0x53 + ]) - ipv6_packet = bytearray([0x60, 0x00, 0x00, 0x00, 0x00, 0x0c, 0x3a, 0x40, - 0x20, 0x00, 0x0d, 0xb8, 0x00, 0x00, 0x00, 0x00, - 0x02, 0x99, 0x99, 0xff, 0xfe, 0x22, 0x11, 0x01, - 0x20, 0x00, 0x0d, 0xb8, 0x00, 0x00, 0x00, 0x00, - 0x36, 0x29, 0x96, 0xff, 0xfe, 0xac, 0xff, 0x18, - 0x80, 0x00, 0x97, 0xf3, 0x0b, 0xc0, 0x00, 0x04, - 0x4e, 0x92, 0xbb, 0x53]) + ipv6_packet = bytearray([ + 0x60, 0x00, 0x00, 0x00, 0x00, 0x0c, 0x3a, 0x40, 0x20, 0x00, 0x0d, + 0xb8, 0x00, 0x00, 0x00, 0x00, 0x02, 0x99, 0x99, 0xff, 0xfe, 0x22, + 0x11, 0x01, 0x20, 0x00, 0x0d, 0xb8, 0x00, 0x00, 0x00, 0x00, 0x36, + 0x29, 0x96, 0xff, 0xfe, 0xac, 0xff, 0x18, 0x80, 0x00, 0x97, 0xf3, + 0x0b, 0xc0, 0x00, 0x04, 0x4e, 0x92, 0xbb, 0x53 + ]) message_info = common.MessageInfo() message_info.source_mac_address = common.MacAddress.from_eui64( @@ -574,24 +610,28 @@ class TestLowpanParser(unittest.TestCase): parser = create_default_lowpan_parser(context_manager) # WHEN - actual_ipv6_packet = parser.parse(io.BytesIO(lowpan_packet), message_info) + actual_ipv6_packet = parser.parse(io.BytesIO(lowpan_packet), + message_info) # THEN self.assertEqual(ipv6_packet, actual_ipv6_packet.to_bytes()) - def test_should_parse_6lo_with_compressed_icmp_and_without_compressed_hbh_when_decompress_method_called_4(self): + def test_should_parse_6lo_with_compressed_icmp_and_without_compressed_hbh_when_decompress_method_called_4( + self): # GIVEN - lowpan_packet = bytearray([0x7a, 0xf5, 0xaa, 0x3a, 0x36, 0x29, 0x96, 0xff, - 0xfe, 0xac, 0xff, 0x18, 0x80, 0x00, 0xfa, 0xa5, - 0x0b, 0xc0, 0x00, 0x04, 0x4e, 0x92, 0xbb, 0x53]) + lowpan_packet = bytearray([ + 0x7a, 0xf5, 0xaa, 0x3a, 0x36, 0x29, 0x96, 0xff, 0xfe, 0xac, 0xff, + 0x18, 0x80, 0x00, 0xfa, 0xa5, 0x0b, 0xc0, 0x00, 0x04, 0x4e, 0x92, + 0xbb, 0x53 + ]) - ipv6_packet = bytearray([0x60, 0x00, 0x00, 0x00, 0x00, 0x0c, 0x3a, 0x40, - 0x20, 0x00, 0x0d, 0xb8, 0x00, 0x00, 0x00, 0x00, - 0x02, 0x99, 0x99, 0xff, 0xfe, 0x22, 0x11, 0x00, - 0x20, 0x00, 0x0d, 0xb8, 0x00, 0x00, 0x00, 0x00, - 0x36, 0x29, 0x96, 0xff, 0xfe, 0xac, 0xff, 0x18, - 0x80, 0x00, 0x97, 0xf4, 0x0b, 0xc0, 0x00, 0x04, - 0x4e, 0x92, 0xbb, 0x53]) + ipv6_packet = bytearray([ + 0x60, 0x00, 0x00, 0x00, 0x00, 0x0c, 0x3a, 0x40, 0x20, 0x00, 0x0d, + 0xb8, 0x00, 0x00, 0x00, 0x00, 0x02, 0x99, 0x99, 0xff, 0xfe, 0x22, + 0x11, 0x00, 0x20, 0x00, 0x0d, 0xb8, 0x00, 0x00, 0x00, 0x00, 0x36, + 0x29, 0x96, 0xff, 0xfe, 0xac, 0xff, 0x18, 0x80, 0x00, 0x97, 0xf4, + 0x0b, 0xc0, 0x00, 0x04, 0x4e, 0x92, 0xbb, 0x53 + ]) message_info = common.MessageInfo() message_info.source_mac_address = common.MacAddress.from_eui64( @@ -605,23 +645,27 @@ class TestLowpanParser(unittest.TestCase): parser = create_default_lowpan_parser(context_manager) # WHEN - actual_ipv6_packet = parser.parse(io.BytesIO(lowpan_packet), message_info) + actual_ipv6_packet = parser.parse(io.BytesIO(lowpan_packet), + message_info) # THEN self.assertEqual(ipv6_packet, actual_ipv6_packet.to_bytes()) - def test_should_parse_6lo_with_compressed_icmp_and_without_compressed_hbh_when_decompress_method_called_5(self): + def test_should_parse_6lo_with_compressed_icmp_and_without_compressed_hbh_when_decompress_method_called_5( + self): # GIVEN - lowpan_packet = bytearray([0x7a, 0xf7, 0xac, 0x3a, 0x80, 0x00, 0xfa, 0xa5, - 0x0b, 0xc0, 0x00, 0x04, 0x4e, 0x92, 0xbb, 0x53]) + lowpan_packet = bytearray([ + 0x7a, 0xf7, 0xac, 0x3a, 0x80, 0x00, 0xfa, 0xa5, 0x0b, 0xc0, 0x00, + 0x04, 0x4e, 0x92, 0xbb, 0x53 + ]) - ipv6_packet = bytearray([0x60, 0x00, 0x00, 0x00, 0x00, 0x0c, 0x3a, 0x40, - 0x20, 0x00, 0x0d, 0xb8, 0x00, 0x00, 0x00, 0x00, - 0x02, 0x99, 0x99, 0xff, 0xfe, 0x22, 0x11, 0x00, - 0x20, 0x0d, 0x14, 0x56, 0x12, 0x55, 0x00, 0x00, - 0x25, 0x14, 0x46, 0xff, 0xfe, 0xdd, 0x2a, 0xfe, - 0x80, 0x00, 0xb3, 0xf3, 0x0b, 0xc0, 0x00, 0x04, - 0x4e, 0x92, 0xbb, 0x53]) + ipv6_packet = bytearray([ + 0x60, 0x00, 0x00, 0x00, 0x00, 0x0c, 0x3a, 0x40, 0x20, 0x00, 0x0d, + 0xb8, 0x00, 0x00, 0x00, 0x00, 0x02, 0x99, 0x99, 0xff, 0xfe, 0x22, + 0x11, 0x00, 0x20, 0x0d, 0x14, 0x56, 0x12, 0x55, 0x00, 0x00, 0x25, + 0x14, 0x46, 0xff, 0xfe, 0xdd, 0x2a, 0xfe, 0x80, 0x00, 0xb3, 0xf3, + 0x0b, 0xc0, 0x00, 0x04, 0x4e, 0x92, 0xbb, 0x53 + ]) message_info = common.MessageInfo() message_info.source_mac_address = common.MacAddress.from_eui64( @@ -631,30 +675,34 @@ class TestLowpanParser(unittest.TestCase): context_manager = lowpan.ContextManager() context_manager[10] = lowpan.Context(prefix="2000:0db8::/64") - context_manager[12] = lowpan.Context(prefix="200d:1456:1255:0000:2514:46ff:fedd:2afe/128") + context_manager[12] = lowpan.Context( + prefix="200d:1456:1255:0000:2514:46ff:fedd:2afe/128") parser = create_default_lowpan_parser(context_manager) # WHEN - actual_ipv6_packet = parser.parse(io.BytesIO(lowpan_packet), message_info) + actual_ipv6_packet = parser.parse(io.BytesIO(lowpan_packet), + message_info) # THEN self.assertEqual(ipv6_packet, actual_ipv6_packet.to_bytes()) - def test_should_parse_6lo_with_compressed_icmp_and_without_compressed_hbh_when_decompress_method_called_6(self): + def test_should_parse_6lo_with_compressed_icmp_and_without_compressed_hbh_when_decompress_method_called_6( + self): # GIVEN - lowpan_packet = bytearray([0x7a, 0xf0, 0xc0, 0x3a, 0x20, 0x0d, 0x14, 0x56, - 0x12, 0x54, 0x00, 0x00, 0x12, 0x54, 0x11, 0xff, - 0xfe, 0x1c, 0x7e, 0xff, 0x80, 0x00, 0xfa, 0xa5, - 0x0b, 0xc0, 0x00, 0x04, 0x4e, 0x92, 0xbb, 0x53]) + lowpan_packet = bytearray([ + 0x7a, 0xf0, 0xc0, 0x3a, 0x20, 0x0d, 0x14, 0x56, 0x12, 0x54, 0x00, + 0x00, 0x12, 0x54, 0x11, 0xff, 0xfe, 0x1c, 0x7e, 0xff, 0x80, 0x00, + 0xfa, 0xa5, 0x0b, 0xc0, 0x00, 0x04, 0x4e, 0x92, 0xbb, 0x53 + ]) - ipv6_packet = bytearray([0x60, 0x00, 0x00, 0x00, 0x00, 0x0c, 0x3a, 0x40, - 0x20, 0x0d, 0x14, 0x56, 0x12, 0x55, 0x00, 0x00, - 0x25, 0x14, 0x46, 0xff, 0xfe, 0xdd, 0x2a, 0xfe, - 0x20, 0x0d, 0x14, 0x56, 0x12, 0x54, 0x00, 0x00, - 0x12, 0x54, 0x11, 0xff, 0xfe, 0x1c, 0x7e, 0xff, - 0x80, 0x00, 0xa5, 0x40, 0x0b, 0xc0, 0x00, 0x04, - 0x4e, 0x92, 0xbb, 0x53]) + ipv6_packet = bytearray([ + 0x60, 0x00, 0x00, 0x00, 0x00, 0x0c, 0x3a, 0x40, 0x20, 0x0d, 0x14, + 0x56, 0x12, 0x55, 0x00, 0x00, 0x25, 0x14, 0x46, 0xff, 0xfe, 0xdd, + 0x2a, 0xfe, 0x20, 0x0d, 0x14, 0x56, 0x12, 0x54, 0x00, 0x00, 0x12, + 0x54, 0x11, 0xff, 0xfe, 0x1c, 0x7e, 0xff, 0x80, 0x00, 0xa5, 0x40, + 0x0b, 0xc0, 0x00, 0x04, 0x4e, 0x92, 0xbb, 0x53 + ]) message_info = common.MessageInfo() message_info.source_mac_address = common.MacAddress.from_eui64( @@ -663,31 +711,35 @@ class TestLowpanParser(unittest.TestCase): bytearray([0x34, 0x29, 0x96, 0xff, 0xfe, 0xac, 0xff, 0x17])) context_manager = lowpan.ContextManager() - context_manager[12] = lowpan.Context(prefix="200d:1456:1255:0000:2514:46ff:fedd:2afe/128") + context_manager[12] = lowpan.Context( + prefix="200d:1456:1255:0000:2514:46ff:fedd:2afe/128") parser = create_default_lowpan_parser(context_manager) # WHEN - actual_ipv6_packet = parser.parse(io.BytesIO(lowpan_packet), message_info) + actual_ipv6_packet = parser.parse(io.BytesIO(lowpan_packet), + message_info) # THEN self.assertEqual(ipv6_packet, actual_ipv6_packet.to_bytes()) - def test_should_parse_6lo_with_compressed_icmp_and_without_compressed_hbh_when_decompress_method_called_7(self): + def test_should_parse_6lo_with_compressed_icmp_and_without_compressed_hbh_when_decompress_method_called_7( + self): # GIVEN - lowpan_packet = bytearray([0x7a, 0xd0, 0xd0, 0x3a, 0x00, 0x02, 0x98, 0xff, - 0xfe, 0x22, 0x12, 0x00, 0x20, 0x0d, 0x14, 0x56, - 0x12, 0x55, 0x00, 0x00, 0x25, 0x14, 0x46, 0xff, - 0xfe, 0xdd, 0x2a, 0xfe, 0x80, 0x00, 0xfa, 0xa5, - 0x0b, 0xc0, 0x00, 0x04, 0x4e, 0x92, 0xbb, 0x53]) + lowpan_packet = bytearray([ + 0x7a, 0xd0, 0xd0, 0x3a, 0x00, 0x02, 0x98, 0xff, 0xfe, 0x22, 0x12, + 0x00, 0x20, 0x0d, 0x14, 0x56, 0x12, 0x55, 0x00, 0x00, 0x25, 0x14, + 0x46, 0xff, 0xfe, 0xdd, 0x2a, 0xfe, 0x80, 0x00, 0xfa, 0xa5, 0x0b, + 0xc0, 0x00, 0x04, 0x4e, 0x92, 0xbb, 0x53 + ]) - ipv6_packet = bytearray([0x60, 0x00, 0x00, 0x00, 0x00, 0x0c, 0x3a, 0x40, - 0xaa, 0xbb, 0xcc, 0xdd, 0x00, 0x00, 0x00, 0x00, - 0x77, 0x82, 0x98, 0xff, 0xfe, 0x22, 0x12, 0x00, - 0x20, 0x0d, 0x14, 0x56, 0x12, 0x55, 0x00, 0x00, - 0x25, 0x14, 0x46, 0xff, 0xfe, 0xdd, 0x2a, 0xfe, - 0x80, 0x00, 0xf5, 0x28, 0x0b, 0xc0, 0x00, 0x04, - 0x4e, 0x92, 0xbb, 0x53]) + ipv6_packet = bytearray([ + 0x60, 0x00, 0x00, 0x00, 0x00, 0x0c, 0x3a, 0x40, 0xaa, 0xbb, 0xcc, + 0xdd, 0x00, 0x00, 0x00, 0x00, 0x77, 0x82, 0x98, 0xff, 0xfe, 0x22, + 0x12, 0x00, 0x20, 0x0d, 0x14, 0x56, 0x12, 0x55, 0x00, 0x00, 0x25, + 0x14, 0x46, 0xff, 0xfe, 0xdd, 0x2a, 0xfe, 0x80, 0x00, 0xf5, 0x28, + 0x0b, 0xc0, 0x00, 0x04, 0x4e, 0x92, 0xbb, 0x53 + ]) message_info = common.MessageInfo() message_info.source_mac_address = common.MacAddress.from_eui64( @@ -696,30 +748,34 @@ class TestLowpanParser(unittest.TestCase): bytearray([0x34, 0x29, 0x96, 0xff, 0xfe, 0xac, 0xff, 0x17])) context_manager = lowpan.ContextManager() - context_manager[13] = lowpan.Context(prefix="AABB:CCDD:0000:0000:7796::/75") + context_manager[13] = lowpan.Context( + prefix="AABB:CCDD:0000:0000:7796::/75") parser = create_default_lowpan_parser(context_manager) # WHEN - actual_ipv6_packet = parser.parse(io.BytesIO(lowpan_packet), message_info) + actual_ipv6_packet = parser.parse(io.BytesIO(lowpan_packet), + message_info) # THEN self.assertEqual(ipv6_packet, actual_ipv6_packet.to_bytes()) - def test_should_parse_6lo_with_compressed_icmp_and_without_compressed_hbh_when_decompress_method_called_8(self): + def test_should_parse_6lo_with_compressed_icmp_and_without_compressed_hbh_when_decompress_method_called_8( + self): # GIVEN - lowpan_packet = bytearray([0x7a, 0xf0, 0xd0, 0x3a, 0x20, 0x0d, 0x14, 0x56, - 0x12, 0x55, 0x00, 0x00, 0x25, 0x14, 0x46, 0xff, - 0xfe, 0xdd, 0x2a, 0xfe, 0x80, 0x00, 0xfa, 0xa5, - 0x0b, 0xc0, 0x00, 0x04, 0x4e, 0x92, 0xbb, 0x53]) + lowpan_packet = bytearray([ + 0x7a, 0xf0, 0xd0, 0x3a, 0x20, 0x0d, 0x14, 0x56, 0x12, 0x55, 0x00, + 0x00, 0x25, 0x14, 0x46, 0xff, 0xfe, 0xdd, 0x2a, 0xfe, 0x80, 0x00, + 0xfa, 0xa5, 0x0b, 0xc0, 0x00, 0x04, 0x4e, 0x92, 0xbb, 0x53 + ]) - ipv6_packet = bytearray([0x60, 0x00, 0x00, 0x00, 0x00, 0x0c, 0x3a, 0x40, - 0xaa, 0xbb, 0xcc, 0xdd, 0x00, 0x00, 0x00, 0x00, - 0x77, 0x99, 0x99, 0xff, 0xfe, 0x22, 0x11, 0x00, - 0x20, 0x0d, 0x14, 0x56, 0x12, 0x55, 0x00, 0x00, - 0x25, 0x14, 0x46, 0xff, 0xfe, 0xdd, 0x2a, 0xfe, - 0x80, 0x00, 0xf5, 0x11, 0x0b, 0xc0, 0x00, 0x04, - 0x4e, 0x92, 0xbb, 0x53]) + ipv6_packet = bytearray([ + 0x60, 0x00, 0x00, 0x00, 0x00, 0x0c, 0x3a, 0x40, 0xaa, 0xbb, 0xcc, + 0xdd, 0x00, 0x00, 0x00, 0x00, 0x77, 0x99, 0x99, 0xff, 0xfe, 0x22, + 0x11, 0x00, 0x20, 0x0d, 0x14, 0x56, 0x12, 0x55, 0x00, 0x00, 0x25, + 0x14, 0x46, 0xff, 0xfe, 0xdd, 0x2a, 0xfe, 0x80, 0x00, 0xf5, 0x11, + 0x0b, 0xc0, 0x00, 0x04, 0x4e, 0x92, 0xbb, 0x53 + ]) message_info = common.MessageInfo() message_info.source_mac_address = common.MacAddress.from_eui64( @@ -728,30 +784,34 @@ class TestLowpanParser(unittest.TestCase): bytearray([0x34, 0x29, 0x96, 0xff, 0xfe, 0xac, 0xff, 0x17])) context_manager = lowpan.ContextManager() - context_manager[13] = lowpan.Context(prefix="AABB:CCDD:0000:0000:7796::/75") + context_manager[13] = lowpan.Context( + prefix="AABB:CCDD:0000:0000:7796::/75") parser = create_default_lowpan_parser(context_manager) # WHEN - actual_ipv6_packet = parser.parse(io.BytesIO(lowpan_packet), message_info) + actual_ipv6_packet = parser.parse(io.BytesIO(lowpan_packet), + message_info) # THEN self.assertEqual(ipv6_packet, actual_ipv6_packet.to_bytes()) - def test_should_parse_6lo_with_compressed_icmp_and_without_compressed_hbh_when_decompress_method_called_9(self): + def test_should_parse_6lo_with_compressed_icmp_and_without_compressed_hbh_when_decompress_method_called_9( + self): # GIVEN - lowpan_packet = bytearray([0x7a, 0xf0, 0xd0, 0x3a, 0x20, 0x0d, 0x14, 0x56, - 0x12, 0x55, 0x00, 0x00, 0x25, 0x14, 0x46, 0xff, - 0xfe, 0xdd, 0x2a, 0xfe, 0x80, 0x00, 0xfa, 0xa5, - 0x0b, 0xc0, 0x00, 0x04, 0x4e, 0x92, 0xbb, 0x53]) + lowpan_packet = bytearray([ + 0x7a, 0xf0, 0xd0, 0x3a, 0x20, 0x0d, 0x14, 0x56, 0x12, 0x55, 0x00, + 0x00, 0x25, 0x14, 0x46, 0xff, 0xfe, 0xdd, 0x2a, 0xfe, 0x80, 0x00, + 0xfa, 0xa5, 0x0b, 0xc0, 0x00, 0x04, 0x4e, 0x92, 0xbb, 0x53 + ]) - ipv6_packet = bytearray([0x60, 0x00, 0x00, 0x00, 0x00, 0x0c, 0x3a, 0x40, - 0xaa, 0xbb, 0xcc, 0xdd, 0x00, 0x00, 0x00, 0x00, - 0x77, 0x99, 0x99, 0xff, 0xfe, 0x22, 0x11, 0x00, - 0x20, 0x0d, 0x14, 0x56, 0x12, 0x55, 0x00, 0x00, - 0x25, 0x14, 0x46, 0xff, 0xfe, 0xdd, 0x2a, 0xfe, - 0x80, 0x00, 0xf5, 0x11, 0x0b, 0xc0, 0x00, 0x04, - 0x4e, 0x92, 0xbb, 0x53]) + ipv6_packet = bytearray([ + 0x60, 0x00, 0x00, 0x00, 0x00, 0x0c, 0x3a, 0x40, 0xaa, 0xbb, 0xcc, + 0xdd, 0x00, 0x00, 0x00, 0x00, 0x77, 0x99, 0x99, 0xff, 0xfe, 0x22, + 0x11, 0x00, 0x20, 0x0d, 0x14, 0x56, 0x12, 0x55, 0x00, 0x00, 0x25, + 0x14, 0x46, 0xff, 0xfe, 0xdd, 0x2a, 0xfe, 0x80, 0x00, 0xf5, 0x11, + 0x0b, 0xc0, 0x00, 0x04, 0x4e, 0x92, 0xbb, 0x53 + ]) message_info = common.MessageInfo() message_info.source_mac_address = common.MacAddress.from_eui64( @@ -759,198 +819,188 @@ class TestLowpanParser(unittest.TestCase): message_info.destination_mac_address = common.MacAddress.from_eui64( bytearray([0x34, 0x29, 0x96, 0xff, 0xfe, 0xac, 0xff, 0x17])) context_manager = lowpan.ContextManager() - context_manager[13] = lowpan.Context(prefix="AABB:CCDD:0000:0000:7796::/75") + context_manager[13] = lowpan.Context( + prefix="AABB:CCDD:0000:0000:7796::/75") parser = create_default_lowpan_parser(context_manager) # WHEN - actual_ipv6_packet = parser.parse(io.BytesIO(lowpan_packet), message_info) + actual_ipv6_packet = parser.parse(io.BytesIO(lowpan_packet), + message_info) # THEN self.assertEqual(ipv6_packet, actual_ipv6_packet.to_bytes()) - def test_should_defragment_big_IPv6_packet_when_parse_method_called_with_fragments_in_random_order(self): + def test_should_defragment_big_IPv6_packet_when_parse_method_called_with_fragments_in_random_order( + self): # GIVEN - fragment_1 = bytearray([0xC5, 0x00, 0x31, 0x9F, 0x7A, 0x33, 0x3A, - 0x80, 0x00, 0xFA, 0xA5, 0x0B, 0xC0, 0x00, 0x04, - 0x4E, 0x92, 0xBB, 0x53, 0x11, 0x44, 0x66, 0x4E, - 0x92, 0xBB, 0x53, 0x1A, 0x44, 0x66, 0x77, 0x99, - 0x15, 0xB3, 0x00, 0x54, 0xCC, 0x54, 0x01, 0xAA, - 0x44, 0x54, 0x12, 0x43, 0x53, 0x11, 0x44, 0x66, - 0x4E, 0x92, 0xBB, 0x53, 0x1A, 0x44, 0x66, 0x77, - 0x99, 0x1A, 0x92, 0xBB, 0x53, 0x11, 0x44, 0x66, - 0x92, 0xBB, 0x53, 0x1A, 0x44, 0x66, 0x77, 0x99, - 0x15, 0xB3, 0x00, 0x54, 0xCC, 0x54, 0x01, 0xAA, - 0x11, 0x44, 0x66, 0x4E, 0x92, 0xBB, 0x53, 0x1A, - 0x80, 0x00, 0xFA, 0xA5, 0x0B, 0xC0, 0x00, 0x04, - 0x4E, 0x92, 0xBB, 0x53, 0x11, 0x4C, 0x66, 0x4E]) + fragment_1 = bytearray([ + 0xC5, 0x00, 0x31, 0x9F, 0x7A, 0x33, 0x3A, 0x80, 0x00, 0xFA, 0xA5, + 0x0B, 0xC0, 0x00, 0x04, 0x4E, 0x92, 0xBB, 0x53, 0x11, 0x44, 0x66, + 0x4E, 0x92, 0xBB, 0x53, 0x1A, 0x44, 0x66, 0x77, 0x99, 0x15, 0xB3, + 0x00, 0x54, 0xCC, 0x54, 0x01, 0xAA, 0x44, 0x54, 0x12, 0x43, 0x53, + 0x11, 0x44, 0x66, 0x4E, 0x92, 0xBB, 0x53, 0x1A, 0x44, 0x66, 0x77, + 0x99, 0x1A, 0x92, 0xBB, 0x53, 0x11, 0x44, 0x66, 0x92, 0xBB, 0x53, + 0x1A, 0x44, 0x66, 0x77, 0x99, 0x15, 0xB3, 0x00, 0x54, 0xCC, 0x54, + 0x01, 0xAA, 0x11, 0x44, 0x66, 0x4E, 0x92, 0xBB, 0x53, 0x1A, 0x80, + 0x00, 0xFA, 0xA5, 0x0B, 0xC0, 0x00, 0x04, 0x4E, 0x92, 0xBB, 0x53, + 0x11, 0x4C, 0x66, 0x4E + ]) - fragment_2 = bytearray([0xE5, 0x00, 0x31, 0x9F, 0x11, - 0x92, 0xBB, 0x53, 0x1A, 0x44, 0x66, 0x77, 0x99, - 0x15, 0xB3, 0x00, 0x54, 0xCC, 0x54, 0x01, 0xAA, - 0x44, 0x54, 0x12, 0xa3, 0x53, 0x11, 0x44, 0x66, - 0xFE, 0x92, 0xBB, 0x53, 0x1A, 0x44, 0x66, 0x77, - 0x99, 0x1A, 0x92, 0xBB, 0x53, 0x11, 0x44, 0x66, - 0x92, 0xBB, 0x53, 0x1A, 0x44, 0x66, 0x77, 0x99, - 0x15, 0xB3, 0x00, 0x54, 0xCC, 0x54, 0x01, 0xAA, - 0x11, 0x44, 0x66, 0x4E, 0x92, 0xBB, 0x53, 0x1A, - 0x80, 0x00, 0xFA, 0xA5, 0x0B, 0xC0, 0x00, 0x04, - 0x4E, 0x92, 0x1B, 0x53, 0x11, 0x44, 0x66, 0x4E, - 0x22, 0xBB, 0x53, 0x1A, 0x44, 0x66, 0x77, 0x99, - 0x15, 0xB3, 0x00, 0x54, 0xCC, 0x54, 0x01, 0xAA]) + fragment_2 = bytearray([ + 0xE5, 0x00, 0x31, 0x9F, 0x11, 0x92, 0xBB, 0x53, 0x1A, 0x44, 0x66, + 0x77, 0x99, 0x15, 0xB3, 0x00, 0x54, 0xCC, 0x54, 0x01, 0xAA, 0x44, + 0x54, 0x12, 0xa3, 0x53, 0x11, 0x44, 0x66, 0xFE, 0x92, 0xBB, 0x53, + 0x1A, 0x44, 0x66, 0x77, 0x99, 0x1A, 0x92, 0xBB, 0x53, 0x11, 0x44, + 0x66, 0x92, 0xBB, 0x53, 0x1A, 0x44, 0x66, 0x77, 0x99, 0x15, 0xB3, + 0x00, 0x54, 0xCC, 0x54, 0x01, 0xAA, 0x11, 0x44, 0x66, 0x4E, 0x92, + 0xBB, 0x53, 0x1A, 0x80, 0x00, 0xFA, 0xA5, 0x0B, 0xC0, 0x00, 0x04, + 0x4E, 0x92, 0x1B, 0x53, 0x11, 0x44, 0x66, 0x4E, 0x22, 0xBB, 0x53, + 0x1A, 0x44, 0x66, 0x77, 0x99, 0x15, 0xB3, 0x00, 0x54, 0xCC, 0x54, + 0x01, 0xAA + ]) - fragment_3 = bytearray([0xE5, 0x00, 0x31, 0x9F, 0x1D, - 0x44, 0x54, 0x12, 0xD3, 0x53, 0x11, 0x44, 0x66, - 0x4E, 0x92, 0xBB, 0x53, 0x1A, 0x44, 0x66, 0x77, - 0x99, 0x1A, 0x92, 0xBB, 0x53, 0x11, 0x44, 0x66, - 0x92, 0xBB, 0x53, 0x1A, 0x44, 0x66, 0x77, 0x99, - 0x15, 0xB3, 0x00, 0x54, 0xCC, 0x54, 0x01, 0xAA, - 0x11, 0x44, 0x66, 0x4E, 0x92, 0xBB, 0x53, 0x1A, - 0xC0, 0x00, 0xFA, 0xA5, 0x0B, 0xC0, 0x00, 0x04, - 0x4E, 0x92, 0xBB, 0x53, 0x11, 0x44, 0xCC, 0x4E, - 0x92, 0xBB, 0x53, 0x1A, 0x44, 0x66, 0x77, 0x99, - 0x15, 0xB3, 0x00, 0x54, 0xCC, 0x54, 0x01, 0xAA, - 0x44, 0x54, 0x12, 0x43, 0x53, 0x11, 0x44, 0x66, - 0x4E, 0x92, 0xBC, 0x53, 0x1A, 0x44, 0x66, 0x77]) + fragment_3 = bytearray([ + 0xE5, 0x00, 0x31, 0x9F, 0x1D, 0x44, 0x54, 0x12, 0xD3, 0x53, 0x11, + 0x44, 0x66, 0x4E, 0x92, 0xBB, 0x53, 0x1A, 0x44, 0x66, 0x77, 0x99, + 0x1A, 0x92, 0xBB, 0x53, 0x11, 0x44, 0x66, 0x92, 0xBB, 0x53, 0x1A, + 0x44, 0x66, 0x77, 0x99, 0x15, 0xB3, 0x00, 0x54, 0xCC, 0x54, 0x01, + 0xAA, 0x11, 0x44, 0x66, 0x4E, 0x92, 0xBB, 0x53, 0x1A, 0xC0, 0x00, + 0xFA, 0xA5, 0x0B, 0xC0, 0x00, 0x04, 0x4E, 0x92, 0xBB, 0x53, 0x11, + 0x44, 0xCC, 0x4E, 0x92, 0xBB, 0x53, 0x1A, 0x44, 0x66, 0x77, 0x99, + 0x15, 0xB3, 0x00, 0x54, 0xCC, 0x54, 0x01, 0xAA, 0x44, 0x54, 0x12, + 0x43, 0x53, 0x11, 0x44, 0x66, 0x4E, 0x92, 0xBC, 0x53, 0x1A, 0x44, + 0x66, 0x77 + ]) - fragment_4 = bytearray([0xE5, 0x00, 0x31, 0x9F, 0x29, - 0x99, 0x1A, 0x92, 0xBB, 0x53, 0x11, 0x44, 0x66, - 0x92, 0xBB, 0x53, 0x1A, 0x44, 0x66, 0x77, 0x99, - 0x15, 0xB3, 0x00, 0x54, 0xCC, 0x54, 0x01, 0xAA, - 0x11, 0x44, 0x66, 0x4E, 0x92, 0xBB, 0x53, 0x1A, - 0x80, 0x00, 0xFA, 0xA5, 0x0B, 0xC0, 0x00, 0x04, - 0x4E, 0x92, 0xBB, 0x53, 0x11, 0x44, 0x66, 0x4E, - 0x92, 0xBB, 0x53, 0x1A, 0x44, 0x66, 0x77, 0x99, - 0x15, 0xB3, 0x00, 0x54, 0xCC, 0x54, 0x01, 0xAA, - 0x44, 0x54, 0x12, 0x43, 0x53, 0x11, 0x44, 0x66, - 0x4E, 0x92, 0xBB, 0x53, 0x1A, 0x44, 0x66, 0x77, - 0x99, 0x1A, 0x92, 0xBB, 0x53, 0x11, 0x44, 0x66, - 0x92, 0xBB, 0x53, 0x1A, 0x44, 0x66, 0x77, 0x99]) + fragment_4 = bytearray([ + 0xE5, 0x00, 0x31, 0x9F, 0x29, 0x99, 0x1A, 0x92, 0xBB, 0x53, 0x11, + 0x44, 0x66, 0x92, 0xBB, 0x53, 0x1A, 0x44, 0x66, 0x77, 0x99, 0x15, + 0xB3, 0x00, 0x54, 0xCC, 0x54, 0x01, 0xAA, 0x11, 0x44, 0x66, 0x4E, + 0x92, 0xBB, 0x53, 0x1A, 0x80, 0x00, 0xFA, 0xA5, 0x0B, 0xC0, 0x00, + 0x04, 0x4E, 0x92, 0xBB, 0x53, 0x11, 0x44, 0x66, 0x4E, 0x92, 0xBB, + 0x53, 0x1A, 0x44, 0x66, 0x77, 0x99, 0x15, 0xB3, 0x00, 0x54, 0xCC, + 0x54, 0x01, 0xAA, 0x44, 0x54, 0x12, 0x43, 0x53, 0x11, 0x44, 0x66, + 0x4E, 0x92, 0xBB, 0x53, 0x1A, 0x44, 0x66, 0x77, 0x99, 0x1A, 0x92, + 0xBB, 0x53, 0x11, 0x44, 0x66, 0x92, 0xBB, 0x53, 0x1A, 0x44, 0x66, + 0x77, 0x99 + ]) - fragment_5 = bytearray([0xE5, 0x00, 0x31, 0x9F, 0x35, - 0x15, 0xB3, 0x00, 0x54, 0xCC, 0x54, 0x01, 0xAA, - 0x11, 0x44, 0x66, 0x4E, 0x92, 0xBB, 0x53, 0x1A, - 0x80, 0x00, 0xFA, 0xA5, 0x0B, 0xC0, 0x00, 0x04, - 0x4E, 0x92, 0xBB, 0x53, 0x11, 0x4C, 0x66, 0x4E, - 0x92, 0xBB, 0x53, 0x1A, 0x44, 0x66, 0x77, 0x99, - 0x15, 0xB3, 0x00, 0x54, 0xCC, 0x54, 0x01, 0xAA, - 0x44, 0x54, 0x12, 0xa3, 0x53, 0x11, 0x44, 0x66, - 0xFE, 0x92, 0xBB, 0x53, 0x1A, 0x44, 0x66, 0x77, - 0x99, 0x1A, 0x92, 0xBB, 0x53, 0x11, 0x44, 0x66, - 0x92, 0xBB, 0x53, 0x1A, 0x44, 0x66, 0x77, 0x99, - 0x15, 0xB3, 0x00, 0x54, 0xCC, 0x54, 0x01, 0xAA, - 0x11, 0x44, 0x66, 0x4E, 0x92, 0xBB, 0x53, 0x1A]) + fragment_5 = bytearray([ + 0xE5, 0x00, 0x31, 0x9F, 0x35, 0x15, 0xB3, 0x00, 0x54, 0xCC, 0x54, + 0x01, 0xAA, 0x11, 0x44, 0x66, 0x4E, 0x92, 0xBB, 0x53, 0x1A, 0x80, + 0x00, 0xFA, 0xA5, 0x0B, 0xC0, 0x00, 0x04, 0x4E, 0x92, 0xBB, 0x53, + 0x11, 0x4C, 0x66, 0x4E, 0x92, 0xBB, 0x53, 0x1A, 0x44, 0x66, 0x77, + 0x99, 0x15, 0xB3, 0x00, 0x54, 0xCC, 0x54, 0x01, 0xAA, 0x44, 0x54, + 0x12, 0xa3, 0x53, 0x11, 0x44, 0x66, 0xFE, 0x92, 0xBB, 0x53, 0x1A, + 0x44, 0x66, 0x77, 0x99, 0x1A, 0x92, 0xBB, 0x53, 0x11, 0x44, 0x66, + 0x92, 0xBB, 0x53, 0x1A, 0x44, 0x66, 0x77, 0x99, 0x15, 0xB3, 0x00, + 0x54, 0xCC, 0x54, 0x01, 0xAA, 0x11, 0x44, 0x66, 0x4E, 0x92, 0xBB, + 0x53, 0x1A + ]) - fragment_6 = bytearray([0xE5, 0x00, 0x31, 0x9F, 0x41, - 0x80, 0x00, 0xFA, 0xA5, 0x0B, 0xC0, 0x00, 0x04, - 0x4E, 0x92, 0x1B, 0x53, 0x11, 0x44, 0x66, 0x4E, - 0x22, 0xBB, 0x53, 0x1A, 0x44, 0x67, 0x77, 0x99, - 0x15, 0xB3, 0x00, 0x54, 0xCC, 0x54, 0x01, 0xAA, - 0x44, 0x54, 0x12, 0xD3, 0x53, 0x11, 0x44, 0x66, - 0x4E, 0x92, 0xBB, 0x53, 0x1A, 0x44, 0x66, 0x77, - 0x99, 0x1A, 0x92, 0xBB, 0x53, 0x11, 0x44, 0x66, - 0x92, 0xBB, 0x53, 0x1A, 0x44, 0x66, 0x77, 0x99, - 0x15, 0xB3, 0x00, 0x54, 0xCC, 0x54, 0x01, 0xAA, - 0x11, 0x44, 0x66, 0x4E, 0x92, 0xBB, 0x53, 0x1A, - 0xC0, 0x00, 0xFA, 0x15, 0x0B, 0xC0, 0x00, 0x04, - 0x4E, 0x92, 0xBB, 0x53, 0x11, 0x44, 0xCC, 0x4E]) + fragment_6 = bytearray([ + 0xE5, 0x00, 0x31, 0x9F, 0x41, 0x80, 0x00, 0xFA, 0xA5, 0x0B, 0xC0, + 0x00, 0x04, 0x4E, 0x92, 0x1B, 0x53, 0x11, 0x44, 0x66, 0x4E, 0x22, + 0xBB, 0x53, 0x1A, 0x44, 0x67, 0x77, 0x99, 0x15, 0xB3, 0x00, 0x54, + 0xCC, 0x54, 0x01, 0xAA, 0x44, 0x54, 0x12, 0xD3, 0x53, 0x11, 0x44, + 0x66, 0x4E, 0x92, 0xBB, 0x53, 0x1A, 0x44, 0x66, 0x77, 0x99, 0x1A, + 0x92, 0xBB, 0x53, 0x11, 0x44, 0x66, 0x92, 0xBB, 0x53, 0x1A, 0x44, + 0x66, 0x77, 0x99, 0x15, 0xB3, 0x00, 0x54, 0xCC, 0x54, 0x01, 0xAA, + 0x11, 0x44, 0x66, 0x4E, 0x92, 0xBB, 0x53, 0x1A, 0xC0, 0x00, 0xFA, + 0x15, 0x0B, 0xC0, 0x00, 0x04, 0x4E, 0x92, 0xBB, 0x53, 0x11, 0x44, + 0xCC, 0x4E + ]) - fragment_7 = bytearray([0xE5, 0x00, 0x31, 0x9F, 0x4D, - 0x92, 0xBB, 0x53, 0x1A, 0x44, 0x66, 0x77, 0x99, - 0x15, 0xB3, 0x00, 0x54, 0xCC, 0x54, 0x01, 0xAA, - 0x44, 0x54, 0x12, 0x43, 0x53, 0x11, 0x44, 0x66, - 0x4E, 0x92, 0xBC, 0x53, 0x1A, 0x44, 0x66, 0x77, - 0x99, 0x1A, 0x92, 0xBB, 0x53, 0x11, 0x44, 0x66, - 0x92, 0xBB, 0x53, 0x1A, 0x44, 0x66, 0x77, 0x99, - 0x15, 0xB3, 0x00, 0x54, 0xCC, 0x54, 0x01, 0xAA, - 0x11, 0x44, 0x66, 0x4E, 0x92, 0xBA, 0x53, 0x1A, - 0x60, 0x00, 0x00, 0x00, 0x00, 0x10, 0x3A, 0x64, - 0xfe, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x02, 0x00, 0x00, 0x11, 0x12, 0x13, 0x14, 0x15, - 0xfe, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]) + fragment_7 = bytearray([ + 0xE5, 0x00, 0x31, 0x9F, 0x4D, 0x92, 0xBB, 0x53, 0x1A, 0x44, 0x66, + 0x77, 0x99, 0x15, 0xB3, 0x00, 0x54, 0xCC, 0x54, 0x01, 0xAA, 0x44, + 0x54, 0x12, 0x43, 0x53, 0x11, 0x44, 0x66, 0x4E, 0x92, 0xBC, 0x53, + 0x1A, 0x44, 0x66, 0x77, 0x99, 0x1A, 0x92, 0xBB, 0x53, 0x11, 0x44, + 0x66, 0x92, 0xBB, 0x53, 0x1A, 0x44, 0x66, 0x77, 0x99, 0x15, 0xB3, + 0x00, 0x54, 0xCC, 0x54, 0x01, 0xAA, 0x11, 0x44, 0x66, 0x4E, 0x92, + 0xBA, 0x53, 0x1A, 0x60, 0x00, 0x00, 0x00, 0x00, 0x10, 0x3A, 0x64, + 0xfe, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, + 0x11, 0x12, 0x13, 0x14, 0x15, 0xfe, 0x80, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00 + ]) - fragment_8 = bytearray([0xE5, 0x00, 0x31, 0x9F, 0x59, - 0x02, 0x00, 0x1A, 0x2A, 0x3F, 0x09, 0xAB, 0x43, - 0x60, 0x00, 0xF0, 0x00, 0x00, 0x10, 0x3A, 0x64, - 0xfe, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x02, 0x00, 0x00, 0x11, 0x12, 0x13, 0x14, 0x15, - 0xfe, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x02, 0x00, 0x1A, 0x2A, 0x3F, 0x09, 0xAB, 0x43, - 0x80, 0x00, 0xFA, 0xA5, 0x0B, 0xC0, 0x00, 0x04, - 0x4E, 0x92, 0xBB, 0x53, 0x11, 0x44, 0x66, 0x4E, - 0x92, 0xBB, 0x53, 0x1A, 0x44, 0x66, 0x77, 0x99, - 0x15, 0xB3, 0x00, 0x54, 0xCC, 0x54, 0x01, 0xAA, - 0x44, 0x54, 0x12, 0x43, 0x53, 0x11, 0x44, 0x66, - 0x4E, 0x92, 0xBC, 0x53, 0x1A, 0x44, 0x66, 0x77]) + fragment_8 = bytearray([ + 0xE5, 0x00, 0x31, 0x9F, 0x59, 0x02, 0x00, 0x1A, 0x2A, 0x3F, 0x09, + 0xAB, 0x43, 0x60, 0x00, 0xF0, 0x00, 0x00, 0x10, 0x3A, 0x64, 0xfe, + 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x11, + 0x12, 0x13, 0x14, 0x15, 0xfe, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x02, 0x00, 0x1A, 0x2A, 0x3F, 0x09, 0xAB, 0x43, 0x80, 0x00, + 0xFA, 0xA5, 0x0B, 0xC0, 0x00, 0x04, 0x4E, 0x92, 0xBB, 0x53, 0x11, + 0x44, 0x66, 0x4E, 0x92, 0xBB, 0x53, 0x1A, 0x44, 0x66, 0x77, 0x99, + 0x15, 0xB3, 0x00, 0x54, 0xCC, 0x54, 0x01, 0xAA, 0x44, 0x54, 0x12, + 0x43, 0x53, 0x11, 0x44, 0x66, 0x4E, 0x92, 0xBC, 0x53, 0x1A, 0x44, + 0x66, 0x77 + ]) - fragment_9 = bytearray([0xE5, 0x00, 0x31, 0x9F, 0x65, - 0x99, 0x1A, 0x92, 0xBB, 0x53, 0x11, 0x44, 0x66, - 0x92, 0xBB, 0x53, 0x1A, 0x44, 0x66, 0x77, 0x99, - 0x15, 0xB3, 0x00, 0x54, 0xCC, 0x54, 0x01, 0xAA, - 0x11, 0x44, 0x66, 0x4E, 0x92, 0xBB, 0x53, 0x1A, - 0x80, 0x00, 0xFA, 0xA5, 0x0B, 0xC0, 0x00, 0x04, - 0x4E, 0x92, 0xBB, 0x53, 0x11, 0x4C, 0x66, 0x4E, - 0x92, 0xBB, 0x53, 0x1A, 0x44, 0x66, 0x77, 0x99, - 0x15, 0xB3, 0x00, 0x54, 0xCC, 0x54, 0x01, 0xAA, - 0x44, 0x54, 0x12, 0xa3, 0x53, 0x11, 0x44, 0x66, - 0xFE, 0x92, 0xBB, 0x53, 0x1A, 0x44, 0x66, 0x77, - 0x99, 0x1A, 0x92, 0xBB, 0x53, 0x11, 0x44, 0x66, - 0x92, 0xBB, 0x53, 0x1A, 0x4D, 0x66, 0x77, 0x99]) + fragment_9 = bytearray([ + 0xE5, 0x00, 0x31, 0x9F, 0x65, 0x99, 0x1A, 0x92, 0xBB, 0x53, 0x11, + 0x44, 0x66, 0x92, 0xBB, 0x53, 0x1A, 0x44, 0x66, 0x77, 0x99, 0x15, + 0xB3, 0x00, 0x54, 0xCC, 0x54, 0x01, 0xAA, 0x11, 0x44, 0x66, 0x4E, + 0x92, 0xBB, 0x53, 0x1A, 0x80, 0x00, 0xFA, 0xA5, 0x0B, 0xC0, 0x00, + 0x04, 0x4E, 0x92, 0xBB, 0x53, 0x11, 0x4C, 0x66, 0x4E, 0x92, 0xBB, + 0x53, 0x1A, 0x44, 0x66, 0x77, 0x99, 0x15, 0xB3, 0x00, 0x54, 0xCC, + 0x54, 0x01, 0xAA, 0x44, 0x54, 0x12, 0xa3, 0x53, 0x11, 0x44, 0x66, + 0xFE, 0x92, 0xBB, 0x53, 0x1A, 0x44, 0x66, 0x77, 0x99, 0x1A, 0x92, + 0xBB, 0x53, 0x11, 0x44, 0x66, 0x92, 0xBB, 0x53, 0x1A, 0x4D, 0x66, + 0x77, 0x99 + ]) - fragment_10 = bytearray([0xE5, 0x00, 0x31, 0x9F, 0x71, - 0x15, 0xB3, 0x00, 0x54, 0xCC, 0x54, 0x01, 0xAA, - 0x11, 0x44, 0x66, 0x4E, 0x92, 0xBB, 0x53, 0x1A, - 0x80, 0x00, 0xFA, 0xA5, 0x0B, 0xC0, 0x00, 0x04, - 0x4E, 0x92, 0x1B, 0x53, 0x11, 0x44, 0x66, 0x4E, - 0x22, 0xBB, 0x51, 0x1A, 0x44, 0x66, 0x77, 0x99, - 0x15, 0xB3, 0x00, 0x54, 0xCC, 0x54, 0x01, 0xAA, - 0x44, 0x54, 0x12, 0xD3, 0x53, 0x11, 0x44, 0x66, - 0x4E, 0x92, 0xBB, 0x53, 0x1A, 0x44, 0x66, 0x77, - 0x99, 0x1A, 0x92, 0xBB, 0x53, 0x11, 0x44, 0x66, - 0x92, 0xBB, 0x53, 0x1A, 0x44, 0x66, 0x77, 0x99, - 0x15, 0xB3, 0x00, 0x54, 0xCC, 0x54, 0x01, 0xAA, - 0x11, 0x44, 0x66, 0x4E, 0x92, 0xBB, 0x53, 0x1A]) + fragment_10 = bytearray([ + 0xE5, 0x00, 0x31, 0x9F, 0x71, 0x15, 0xB3, 0x00, 0x54, 0xCC, 0x54, + 0x01, 0xAA, 0x11, 0x44, 0x66, 0x4E, 0x92, 0xBB, 0x53, 0x1A, 0x80, + 0x00, 0xFA, 0xA5, 0x0B, 0xC0, 0x00, 0x04, 0x4E, 0x92, 0x1B, 0x53, + 0x11, 0x44, 0x66, 0x4E, 0x22, 0xBB, 0x51, 0x1A, 0x44, 0x66, 0x77, + 0x99, 0x15, 0xB3, 0x00, 0x54, 0xCC, 0x54, 0x01, 0xAA, 0x44, 0x54, + 0x12, 0xD3, 0x53, 0x11, 0x44, 0x66, 0x4E, 0x92, 0xBB, 0x53, 0x1A, + 0x44, 0x66, 0x77, 0x99, 0x1A, 0x92, 0xBB, 0x53, 0x11, 0x44, 0x66, + 0x92, 0xBB, 0x53, 0x1A, 0x44, 0x66, 0x77, 0x99, 0x15, 0xB3, 0x00, + 0x54, 0xCC, 0x54, 0x01, 0xAA, 0x11, 0x44, 0x66, 0x4E, 0x92, 0xBB, + 0x53, 0x1A + ]) - fragment_11 = bytearray([0xE5, 0x00, 0x31, 0x9F, 0x7D, - 0xC0, 0x00, 0xFA, 0xA5, 0x0B, 0xC0, 0x00, 0x04, - 0x4E, 0x92, 0xBB, 0x53, 0x11, 0x44, 0xCC, 0x4E, - 0x92, 0xBB, 0x53, 0x1A, 0x44, 0x66, 0x77, 0x99, - 0x15, 0xB3, 0x00, 0x54, 0xCC, 0x54, 0x01, 0xAA, - 0x44, 0x54, 0x12, 0x4A, 0x53, 0x11, 0x44, 0x66, - 0x4E, 0x92, 0xBC, 0x53, 0x1A, 0x44, 0x66, 0x77, - 0x99, 0x1A, 0x92, 0xBB, 0x53, 0x11, 0x44, 0x66, - 0x92, 0xBB, 0x53, 0x1A, 0x44, 0x66, 0x77, 0x99, - 0x15, 0xB3, 0x00, 0x54, 0xCC, 0x54, 0x01, 0xAA, - 0x11, 0x44, 0x66, 0x4E, 0x92, 0xBB, 0x53, 0x1A, - 0x80, 0x00, 0xFA, 0xA5, 0x0B, 0xC0, 0x00, 0x04, - 0x4E, 0x92, 0xBB, 0x53, 0x11, 0x44, 0x66, 0x4E]) + fragment_11 = bytearray([ + 0xE5, 0x00, 0x31, 0x9F, 0x7D, 0xC0, 0x00, 0xFA, 0xA5, 0x0B, 0xC0, + 0x00, 0x04, 0x4E, 0x92, 0xBB, 0x53, 0x11, 0x44, 0xCC, 0x4E, 0x92, + 0xBB, 0x53, 0x1A, 0x44, 0x66, 0x77, 0x99, 0x15, 0xB3, 0x00, 0x54, + 0xCC, 0x54, 0x01, 0xAA, 0x44, 0x54, 0x12, 0x4A, 0x53, 0x11, 0x44, + 0x66, 0x4E, 0x92, 0xBC, 0x53, 0x1A, 0x44, 0x66, 0x77, 0x99, 0x1A, + 0x92, 0xBB, 0x53, 0x11, 0x44, 0x66, 0x92, 0xBB, 0x53, 0x1A, 0x44, + 0x66, 0x77, 0x99, 0x15, 0xB3, 0x00, 0x54, 0xCC, 0x54, 0x01, 0xAA, + 0x11, 0x44, 0x66, 0x4E, 0x92, 0xBB, 0x53, 0x1A, 0x80, 0x00, 0xFA, + 0xA5, 0x0B, 0xC0, 0x00, 0x04, 0x4E, 0x92, 0xBB, 0x53, 0x11, 0x44, + 0x66, 0x4E + ]) - fragment_12 = bytearray([0xE5, 0x00, 0x31, 0x9F, 0x89, - 0x92, 0xBB, 0x53, 0x1A, 0x44, 0x66, 0x77, 0x99, - 0x15, 0xB3, 0x00, 0x54, 0xCC, 0x54, 0x01, 0xAA, - 0x44, 0x54, 0x12, 0x43, 0x53, 0x11, 0x44, 0x66, - 0x4E, 0x92, 0xBB, 0x53, 0x3A, 0x44, 0x66, 0x77, - 0x99, 0x1A, 0x92, 0xBB, 0x53, 0x11, 0x44, 0x66, - 0x92, 0xBB, 0x53, 0x1A, 0x44, 0x66, 0x77, 0x99, - 0x15, 0xB3, 0x00, 0x54, 0xCC, 0x54, 0x01, 0xAA, - 0x11, 0x44, 0x66, 0x4E, 0x92, 0xBB, 0x53, 0x1A, - 0x80, 0x00, 0xFA, 0xA5, 0x0B, 0xC0, 0x00, 0x04, - 0x4E, 0x92, 0xBB, 0x53, 0x11, 0x4C, 0x66, 0x4E, - 0x92, 0xBB, 0x53, 0x1A, 0x44, 0x66, 0x77, 0x99, - 0x15, 0xB3, 0x00, 0x54, 0xCC, 0x54, 0x01, 0xAA]) + fragment_12 = bytearray([ + 0xE5, 0x00, 0x31, 0x9F, 0x89, 0x92, 0xBB, 0x53, 0x1A, 0x44, 0x66, + 0x77, 0x99, 0x15, 0xB3, 0x00, 0x54, 0xCC, 0x54, 0x01, 0xAA, 0x44, + 0x54, 0x12, 0x43, 0x53, 0x11, 0x44, 0x66, 0x4E, 0x92, 0xBB, 0x53, + 0x3A, 0x44, 0x66, 0x77, 0x99, 0x1A, 0x92, 0xBB, 0x53, 0x11, 0x44, + 0x66, 0x92, 0xBB, 0x53, 0x1A, 0x44, 0x66, 0x77, 0x99, 0x15, 0xB3, + 0x00, 0x54, 0xCC, 0x54, 0x01, 0xAA, 0x11, 0x44, 0x66, 0x4E, 0x92, + 0xBB, 0x53, 0x1A, 0x80, 0x00, 0xFA, 0xA5, 0x0B, 0xC0, 0x00, 0x04, + 0x4E, 0x92, 0xBB, 0x53, 0x11, 0x4C, 0x66, 0x4E, 0x92, 0xBB, 0x53, + 0x1A, 0x44, 0x66, 0x77, 0x99, 0x15, 0xB3, 0x00, 0x54, 0xCC, 0x54, + 0x01, 0xAA + ]) - fragment_13 = bytearray([0xE5, 0x00, 0x31, 0x9F, 0x95, - 0x44, 0x54, 0x12, 0xa3, 0x53, 0x11, 0x44, 0x66, - 0xFE, 0x92, 0xBB, 0x53, 0x1A, 0x44, 0x66, 0x77, - 0x99, 0x1A, 0x92, 0xBB, 0x53, 0x11, 0x44, 0x66, - 0x92, 0xBB, 0x53, 0x1A, 0x44, 0x66, 0x77, 0x99, - 0x15, 0xB3, 0x00, 0x54, 0xCC, 0x54, 0x01, 0xAA, - 0x11, 0x44, 0x66, 0x4E, 0x92, 0xBB, 0x53, 0x1A, - 0x80, 0x00, 0xFA, 0xA5, 0x1B, 0xC0, 0x00, 0x04, - 0x4E, 0x92, 0x1B, 0x53, 0x11, 0x44, 0x66, 0x4E, - 0x22, 0xBB, 0x53, 0x1A, 0x44, 0x66, 0x77, 0x99, - 0x15, 0xB3, 0x00, 0x54, 0xCC, 0x54, 0x01, 0xAA, - 0x44, 0x54, 0x12, 0xD3, 0x53, 0x11, 0x44, 0x66]) + fragment_13 = bytearray([ + 0xE5, 0x00, 0x31, 0x9F, 0x95, 0x44, 0x54, 0x12, 0xa3, 0x53, 0x11, + 0x44, 0x66, 0xFE, 0x92, 0xBB, 0x53, 0x1A, 0x44, 0x66, 0x77, 0x99, + 0x1A, 0x92, 0xBB, 0x53, 0x11, 0x44, 0x66, 0x92, 0xBB, 0x53, 0x1A, + 0x44, 0x66, 0x77, 0x99, 0x15, 0xB3, 0x00, 0x54, 0xCC, 0x54, 0x01, + 0xAA, 0x11, 0x44, 0x66, 0x4E, 0x92, 0xBB, 0x53, 0x1A, 0x80, 0x00, + 0xFA, 0xA5, 0x1B, 0xC0, 0x00, 0x04, 0x4E, 0x92, 0x1B, 0x53, 0x11, + 0x44, 0x66, 0x4E, 0x22, 0xBB, 0x53, 0x1A, 0x44, 0x66, 0x77, 0x99, + 0x15, 0xB3, 0x00, 0x54, 0xCC, 0x54, 0x01, 0xAA, 0x44, 0x54, 0x12, + 0xD3, 0x53, 0x11, 0x44, 0x66 + ]) message_info = common.MessageInfo() message_info.source_mac_address = common.MacAddress.from_eui64( @@ -976,169 +1026,1292 @@ class TestLowpanParser(unittest.TestCase): actual_ipv6_packet = parser.parse(io.BytesIO(fragment_1), message_info) # THEN - ipv6_packet = bytearray([0x60, 0x00, 0x00, 0x00, 0x04, 0xD8, 0x3A, 0x40, - 0xfe, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x02, 0x00, 0x00, 0x11, 0x12, 0x13, 0x14, 0x15, - 0xfe, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x02, 0x00, 0x1A, 0x2A, 0x3F, 0x09, 0xAB, 0x43, # / * 40 * / - 0x80, 0x00, 0xAB, 0x64, 0x0B, 0xC0, 0x00, 0x04, - 0x4E, 0x92, 0xBB, 0x53, 0x11, 0x44, 0x66, 0x4E, - 0x92, 0xBB, 0x53, 0x1A, 0x44, 0x66, 0x77, 0x99, - 0x15, 0xB3, 0x00, 0x54, 0xCC, 0x54, 0x01, 0xAA, - 0x44, 0x54, 0x12, 0x43, 0x53, 0x11, 0x44, 0x66, - 0x4E, 0x92, 0xBB, 0x53, 0x1A, 0x44, 0x66, 0x77, - 0x99, 0x1A, 0x92, 0xBB, 0x53, 0x11, 0x44, 0x66, - 0x92, 0xBB, 0x53, 0x1A, 0x44, 0x66, 0x77, 0x99, - 0x15, 0xB3, 0x00, 0x54, 0xCC, 0x54, 0x01, 0xAA, - 0x11, 0x44, 0x66, 0x4E, 0x92, 0xBB, 0x53, 0x1A, # / * 120 * / - 0x80, 0x00, 0xFA, 0xA5, 0x0B, 0xC0, 0x00, 0x04, - 0x4E, 0x92, 0xBB, 0x53, 0x11, 0x4C, 0x66, 0x4E, - 0x92, 0xBB, 0x53, 0x1A, 0x44, 0x66, 0x77, 0x99, - 0x15, 0xB3, 0x00, 0x54, 0xCC, 0x54, 0x01, 0xAA, - 0x44, 0x54, 0x12, 0xa3, 0x53, 0x11, 0x44, 0x66, - 0xFE, 0x92, 0xBB, 0x53, 0x1A, 0x44, 0x66, 0x77, - 0x99, 0x1A, 0x92, 0xBB, 0x53, 0x11, 0x44, 0x66, - 0x92, 0xBB, 0x53, 0x1A, 0x44, 0x66, 0x77, 0x99, - 0x15, 0xB3, 0x00, 0x54, 0xCC, 0x54, 0x01, 0xAA, - 0x11, 0x44, 0x66, 0x4E, 0x92, 0xBB, 0x53, 0x1A, # / * 200 * / - 0x80, 0x00, 0xFA, 0xA5, 0x0B, 0xC0, 0x00, 0x04, - 0x4E, 0x92, 0x1B, 0x53, 0x11, 0x44, 0x66, 0x4E, - 0x22, 0xBB, 0x53, 0x1A, 0x44, 0x66, 0x77, 0x99, - 0x15, 0xB3, 0x00, 0x54, 0xCC, 0x54, 0x01, 0xAA, - 0x44, 0x54, 0x12, 0xD3, 0x53, 0x11, 0x44, 0x66, - 0x4E, 0x92, 0xBB, 0x53, 0x1A, 0x44, 0x66, 0x77, - 0x99, 0x1A, 0x92, 0xBB, 0x53, 0x11, 0x44, 0x66, - 0x92, 0xBB, 0x53, 0x1A, 0x44, 0x66, 0x77, 0x99, - 0x15, 0xB3, 0x00, 0x54, 0xCC, 0x54, 0x01, 0xAA, - 0x11, 0x44, 0x66, 0x4E, 0x92, 0xBB, 0x53, 0x1A, # / * 280 * / - 0xC0, 0x00, 0xFA, 0xA5, 0x0B, 0xC0, 0x00, 0x04, - 0x4E, 0x92, 0xBB, 0x53, 0x11, 0x44, 0xCC, 0x4E, - 0x92, 0xBB, 0x53, 0x1A, 0x44, 0x66, 0x77, 0x99, - 0x15, 0xB3, 0x00, 0x54, 0xCC, 0x54, 0x01, 0xAA, - 0x44, 0x54, 0x12, 0x43, 0x53, 0x11, 0x44, 0x66, - 0x4E, 0x92, 0xBC, 0x53, 0x1A, 0x44, 0x66, 0x77, - 0x99, 0x1A, 0x92, 0xBB, 0x53, 0x11, 0x44, 0x66, - 0x92, 0xBB, 0x53, 0x1A, 0x44, 0x66, 0x77, 0x99, - 0x15, 0xB3, 0x00, 0x54, 0xCC, 0x54, 0x01, 0xAA, - 0x11, 0x44, 0x66, 0x4E, 0x92, 0xBB, 0x53, 0x1A, # / * 360 * / - 0x80, 0x00, 0xFA, 0xA5, 0x0B, 0xC0, 0x00, 0x04, - 0x4E, 0x92, 0xBB, 0x53, 0x11, 0x44, 0x66, 0x4E, - 0x92, 0xBB, 0x53, 0x1A, 0x44, 0x66, 0x77, 0x99, - 0x15, 0xB3, 0x00, 0x54, 0xCC, 0x54, 0x01, 0xAA, - 0x44, 0x54, 0x12, 0x43, 0x53, 0x11, 0x44, 0x66, - 0x4E, 0x92, 0xBB, 0x53, 0x1A, 0x44, 0x66, 0x77, - 0x99, 0x1A, 0x92, 0xBB, 0x53, 0x11, 0x44, 0x66, - 0x92, 0xBB, 0x53, 0x1A, 0x44, 0x66, 0x77, 0x99, - 0x15, 0xB3, 0x00, 0x54, 0xCC, 0x54, 0x01, 0xAA, - 0x11, 0x44, 0x66, 0x4E, 0x92, 0xBB, 0x53, 0x1A, - 0x80, 0x00, 0xFA, 0xA5, 0x0B, 0xC0, 0x00, 0x04, - 0x4E, 0x92, 0xBB, 0x53, 0x11, 0x4C, 0x66, 0x4E, - 0x92, 0xBB, 0x53, 0x1A, 0x44, 0x66, 0x77, 0x99, - 0x15, 0xB3, 0x00, 0x54, 0xCC, 0x54, 0x01, 0xAA, - 0x44, 0x54, 0x12, 0xa3, 0x53, 0x11, 0x44, 0x66, - 0xFE, 0x92, 0xBB, 0x53, 0x1A, 0x44, 0x66, 0x77, - 0x99, 0x1A, 0x92, 0xBB, 0x53, 0x11, 0x44, 0x66, - 0x92, 0xBB, 0x53, 0x1A, 0x44, 0x66, 0x77, 0x99, - 0x15, 0xB3, 0x00, 0x54, 0xCC, 0x54, 0x01, 0xAA, - 0x11, 0x44, 0x66, 0x4E, 0x92, 0xBB, 0x53, 0x1A, - 0x80, 0x00, 0xFA, 0xA5, 0x0B, 0xC0, 0x00, 0x04, - 0x4E, 0x92, 0x1B, 0x53, 0x11, 0x44, 0x66, 0x4E, - 0x22, 0xBB, 0x53, 0x1A, 0x44, 0x67, 0x77, 0x99, - 0x15, 0xB3, 0x00, 0x54, 0xCC, 0x54, 0x01, 0xAA, - 0x44, 0x54, 0x12, 0xD3, 0x53, 0x11, 0x44, 0x66, - 0x4E, 0x92, 0xBB, 0x53, 0x1A, 0x44, 0x66, 0x77, - 0x99, 0x1A, 0x92, 0xBB, 0x53, 0x11, 0x44, 0x66, - 0x92, 0xBB, 0x53, 0x1A, 0x44, 0x66, 0x77, 0x99, - 0x15, 0xB3, 0x00, 0x54, 0xCC, 0x54, 0x01, 0xAA, - 0x11, 0x44, 0x66, 0x4E, 0x92, 0xBB, 0x53, 0x1A, - 0xC0, 0x00, 0xFA, 0x15, 0x0B, 0xC0, 0x00, 0x04, - 0x4E, 0x92, 0xBB, 0x53, 0x11, 0x44, 0xCC, 0x4E, - 0x92, 0xBB, 0x53, 0x1A, 0x44, 0x66, 0x77, 0x99, - 0x15, 0xB3, 0x00, 0x54, 0xCC, 0x54, 0x01, 0xAA, - 0x44, 0x54, 0x12, 0x43, 0x53, 0x11, 0x44, 0x66, - 0x4E, 0x92, 0xBC, 0x53, 0x1A, 0x44, 0x66, 0x77, - 0x99, 0x1A, 0x92, 0xBB, 0x53, 0x11, 0x44, 0x66, - 0x92, 0xBB, 0x53, 0x1A, 0x44, 0x66, 0x77, 0x99, - 0x15, 0xB3, 0x00, 0x54, 0xCC, 0x54, 0x01, 0xAA, - 0x11, 0x44, 0x66, 0x4E, 0x92, 0xBA, 0x53, 0x1A, - 0x60, 0x00, 0x00, 0x00, 0x00, 0x10, 0x3A, 0x64, - 0xfe, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x02, 0x00, 0x00, 0x11, 0x12, 0x13, 0x14, 0x15, - 0xfe, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x02, 0x00, 0x1A, 0x2A, 0x3F, 0x09, 0xAB, 0x43, # / * 720 * / - 0x60, 0x00, 0xF0, 0x00, 0x00, 0x10, 0x3A, 0x64, - 0xfe, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x02, 0x00, 0x00, 0x11, 0x12, 0x13, 0x14, 0x15, - 0xfe, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x02, 0x00, 0x1A, 0x2A, 0x3F, 0x09, 0xAB, 0x43, - 0x80, 0x00, 0xFA, 0xA5, 0x0B, 0xC0, 0x00, 0x04, - 0x4E, 0x92, 0xBB, 0x53, 0x11, 0x44, 0x66, 0x4E, - 0x92, 0xBB, 0x53, 0x1A, 0x44, 0x66, 0x77, 0x99, - 0x15, 0xB3, 0x00, 0x54, 0xCC, 0x54, 0x01, 0xAA, - 0x44, 0x54, 0x12, 0x43, 0x53, 0x11, 0x44, 0x66, - 0x4E, 0x92, 0xBC, 0x53, 0x1A, 0x44, 0x66, 0x77, - 0x99, 0x1A, 0x92, 0xBB, 0x53, 0x11, 0x44, 0x66, - 0x92, 0xBB, 0x53, 0x1A, 0x44, 0x66, 0x77, 0x99, - 0x15, 0xB3, 0x00, 0x54, 0xCC, 0x54, 0x01, 0xAA, - 0x11, 0x44, 0x66, 0x4E, 0x92, 0xBB, 0x53, 0x1A, - 0x80, 0x00, 0xFA, 0xA5, 0x0B, 0xC0, 0x00, 0x04, - 0x4E, 0x92, 0xBB, 0x53, 0x11, 0x4C, 0x66, 0x4E, - 0x92, 0xBB, 0x53, 0x1A, 0x44, 0x66, 0x77, 0x99, - 0x15, 0xB3, 0x00, 0x54, 0xCC, 0x54, 0x01, 0xAA, - 0x44, 0x54, 0x12, 0xa3, 0x53, 0x11, 0x44, 0x66, - 0xFE, 0x92, 0xBB, 0x53, 0x1A, 0x44, 0x66, 0x77, - 0x99, 0x1A, 0x92, 0xBB, 0x53, 0x11, 0x44, 0x66, - 0x92, 0xBB, 0x53, 0x1A, 0x4D, 0x66, 0x77, 0x99, - 0x15, 0xB3, 0x00, 0x54, 0xCC, 0x54, 0x01, 0xAA, - 0x11, 0x44, 0x66, 0x4E, 0x92, 0xBB, 0x53, 0x1A, - 0x80, 0x00, 0xFA, 0xA5, 0x0B, 0xC0, 0x00, 0x04, - 0x4E, 0x92, 0x1B, 0x53, 0x11, 0x44, 0x66, 0x4E, - 0x22, 0xBB, 0x51, 0x1A, 0x44, 0x66, 0x77, 0x99, - 0x15, 0xB3, 0x00, 0x54, 0xCC, 0x54, 0x01, 0xAA, - 0x44, 0x54, 0x12, 0xD3, 0x53, 0x11, 0x44, 0x66, - 0x4E, 0x92, 0xBB, 0x53, 0x1A, 0x44, 0x66, 0x77, - 0x99, 0x1A, 0x92, 0xBB, 0x53, 0x11, 0x44, 0x66, - 0x92, 0xBB, 0x53, 0x1A, 0x44, 0x66, 0x77, 0x99, - 0x15, 0xB3, 0x00, 0x54, 0xCC, 0x54, 0x01, 0xAA, - 0x11, 0x44, 0x66, 0x4E, 0x92, 0xBB, 0x53, 0x1A, - 0xC0, 0x00, 0xFA, 0xA5, 0x0B, 0xC0, 0x00, 0x04, - 0x4E, 0x92, 0xBB, 0x53, 0x11, 0x44, 0xCC, 0x4E, - 0x92, 0xBB, 0x53, 0x1A, 0x44, 0x66, 0x77, 0x99, - 0x15, 0xB3, 0x00, 0x54, 0xCC, 0x54, 0x01, 0xAA, - 0x44, 0x54, 0x12, 0x4A, 0x53, 0x11, 0x44, 0x66, - 0x4E, 0x92, 0xBC, 0x53, 0x1A, 0x44, 0x66, 0x77, - 0x99, 0x1A, 0x92, 0xBB, 0x53, 0x11, 0x44, 0x66, - 0x92, 0xBB, 0x53, 0x1A, 0x44, 0x66, 0x77, 0x99, - 0x15, 0xB3, 0x00, 0x54, 0xCC, 0x54, 0x01, 0xAA, - 0x11, 0x44, 0x66, 0x4E, 0x92, 0xBB, 0x53, 0x1A, # / * 1080 * / - 0x80, 0x00, 0xFA, 0xA5, 0x0B, 0xC0, 0x00, 0x04, - 0x4E, 0x92, 0xBB, 0x53, 0x11, 0x44, 0x66, 0x4E, - 0x92, 0xBB, 0x53, 0x1A, 0x44, 0x66, 0x77, 0x99, - 0x15, 0xB3, 0x00, 0x54, 0xCC, 0x54, 0x01, 0xAA, - 0x44, 0x54, 0x12, 0x43, 0x53, 0x11, 0x44, 0x66, - 0x4E, 0x92, 0xBB, 0x53, 0x3A, 0x44, 0x66, 0x77, - 0x99, 0x1A, 0x92, 0xBB, 0x53, 0x11, 0x44, 0x66, - 0x92, 0xBB, 0x53, 0x1A, 0x44, 0x66, 0x77, 0x99, - 0x15, 0xB3, 0x00, 0x54, 0xCC, 0x54, 0x01, 0xAA, - 0x11, 0x44, 0x66, 0x4E, 0x92, 0xBB, 0x53, 0x1A, - 0x80, 0x00, 0xFA, 0xA5, 0x0B, 0xC0, 0x00, 0x04, - 0x4E, 0x92, 0xBB, 0x53, 0x11, 0x4C, 0x66, 0x4E, - 0x92, 0xBB, 0x53, 0x1A, 0x44, 0x66, 0x77, 0x99, - 0x15, 0xB3, 0x00, 0x54, 0xCC, 0x54, 0x01, 0xAA, - 0x44, 0x54, 0x12, 0xa3, 0x53, 0x11, 0x44, 0x66, - 0xFE, 0x92, 0xBB, 0x53, 0x1A, 0x44, 0x66, 0x77, - 0x99, 0x1A, 0x92, 0xBB, 0x53, 0x11, 0x44, 0x66, - 0x92, 0xBB, 0x53, 0x1A, 0x44, 0x66, 0x77, 0x99, - 0x15, 0xB3, 0x00, 0x54, 0xCC, 0x54, 0x01, 0xAA, - 0x11, 0x44, 0x66, 0x4E, 0x92, 0xBB, 0x53, 0x1A, - 0x80, 0x00, 0xFA, 0xA5, 0x1B, 0xC0, 0x00, 0x04, - 0x4E, 0x92, 0x1B, 0x53, 0x11, 0x44, 0x66, 0x4E, - 0x22, 0xBB, 0x53, 0x1A, 0x44, 0x66, 0x77, 0x99, - 0x15, 0xB3, 0x00, 0x54, 0xCC, 0x54, 0x01, 0xAA, - 0x44, 0x54, 0x12, 0xD3, 0x53, 0x11, 0x44, 0x66]) + ipv6_packet = bytearray([ + 0x60, + 0x00, + 0x00, + 0x00, + 0x04, + 0xD8, + 0x3A, + 0x40, + 0xfe, + 0x80, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x02, + 0x00, + 0x00, + 0x11, + 0x12, + 0x13, + 0x14, + 0x15, + 0xfe, + 0x80, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x02, + 0x00, + 0x1A, + 0x2A, + 0x3F, + 0x09, + 0xAB, + 0x43, # / * 40 * / + 0x80, + 0x00, + 0xAB, + 0x64, + 0x0B, + 0xC0, + 0x00, + 0x04, + 0x4E, + 0x92, + 0xBB, + 0x53, + 0x11, + 0x44, + 0x66, + 0x4E, + 0x92, + 0xBB, + 0x53, + 0x1A, + 0x44, + 0x66, + 0x77, + 0x99, + 0x15, + 0xB3, + 0x00, + 0x54, + 0xCC, + 0x54, + 0x01, + 0xAA, + 0x44, + 0x54, + 0x12, + 0x43, + 0x53, + 0x11, + 0x44, + 0x66, + 0x4E, + 0x92, + 0xBB, + 0x53, + 0x1A, + 0x44, + 0x66, + 0x77, + 0x99, + 0x1A, + 0x92, + 0xBB, + 0x53, + 0x11, + 0x44, + 0x66, + 0x92, + 0xBB, + 0x53, + 0x1A, + 0x44, + 0x66, + 0x77, + 0x99, + 0x15, + 0xB3, + 0x00, + 0x54, + 0xCC, + 0x54, + 0x01, + 0xAA, + 0x11, + 0x44, + 0x66, + 0x4E, + 0x92, + 0xBB, + 0x53, + 0x1A, # / * 120 * / + 0x80, + 0x00, + 0xFA, + 0xA5, + 0x0B, + 0xC0, + 0x00, + 0x04, + 0x4E, + 0x92, + 0xBB, + 0x53, + 0x11, + 0x4C, + 0x66, + 0x4E, + 0x92, + 0xBB, + 0x53, + 0x1A, + 0x44, + 0x66, + 0x77, + 0x99, + 0x15, + 0xB3, + 0x00, + 0x54, + 0xCC, + 0x54, + 0x01, + 0xAA, + 0x44, + 0x54, + 0x12, + 0xa3, + 0x53, + 0x11, + 0x44, + 0x66, + 0xFE, + 0x92, + 0xBB, + 0x53, + 0x1A, + 0x44, + 0x66, + 0x77, + 0x99, + 0x1A, + 0x92, + 0xBB, + 0x53, + 0x11, + 0x44, + 0x66, + 0x92, + 0xBB, + 0x53, + 0x1A, + 0x44, + 0x66, + 0x77, + 0x99, + 0x15, + 0xB3, + 0x00, + 0x54, + 0xCC, + 0x54, + 0x01, + 0xAA, + 0x11, + 0x44, + 0x66, + 0x4E, + 0x92, + 0xBB, + 0x53, + 0x1A, # / * 200 * / + 0x80, + 0x00, + 0xFA, + 0xA5, + 0x0B, + 0xC0, + 0x00, + 0x04, + 0x4E, + 0x92, + 0x1B, + 0x53, + 0x11, + 0x44, + 0x66, + 0x4E, + 0x22, + 0xBB, + 0x53, + 0x1A, + 0x44, + 0x66, + 0x77, + 0x99, + 0x15, + 0xB3, + 0x00, + 0x54, + 0xCC, + 0x54, + 0x01, + 0xAA, + 0x44, + 0x54, + 0x12, + 0xD3, + 0x53, + 0x11, + 0x44, + 0x66, + 0x4E, + 0x92, + 0xBB, + 0x53, + 0x1A, + 0x44, + 0x66, + 0x77, + 0x99, + 0x1A, + 0x92, + 0xBB, + 0x53, + 0x11, + 0x44, + 0x66, + 0x92, + 0xBB, + 0x53, + 0x1A, + 0x44, + 0x66, + 0x77, + 0x99, + 0x15, + 0xB3, + 0x00, + 0x54, + 0xCC, + 0x54, + 0x01, + 0xAA, + 0x11, + 0x44, + 0x66, + 0x4E, + 0x92, + 0xBB, + 0x53, + 0x1A, # / * 280 * / + 0xC0, + 0x00, + 0xFA, + 0xA5, + 0x0B, + 0xC0, + 0x00, + 0x04, + 0x4E, + 0x92, + 0xBB, + 0x53, + 0x11, + 0x44, + 0xCC, + 0x4E, + 0x92, + 0xBB, + 0x53, + 0x1A, + 0x44, + 0x66, + 0x77, + 0x99, + 0x15, + 0xB3, + 0x00, + 0x54, + 0xCC, + 0x54, + 0x01, + 0xAA, + 0x44, + 0x54, + 0x12, + 0x43, + 0x53, + 0x11, + 0x44, + 0x66, + 0x4E, + 0x92, + 0xBC, + 0x53, + 0x1A, + 0x44, + 0x66, + 0x77, + 0x99, + 0x1A, + 0x92, + 0xBB, + 0x53, + 0x11, + 0x44, + 0x66, + 0x92, + 0xBB, + 0x53, + 0x1A, + 0x44, + 0x66, + 0x77, + 0x99, + 0x15, + 0xB3, + 0x00, + 0x54, + 0xCC, + 0x54, + 0x01, + 0xAA, + 0x11, + 0x44, + 0x66, + 0x4E, + 0x92, + 0xBB, + 0x53, + 0x1A, # / * 360 * / + 0x80, + 0x00, + 0xFA, + 0xA5, + 0x0B, + 0xC0, + 0x00, + 0x04, + 0x4E, + 0x92, + 0xBB, + 0x53, + 0x11, + 0x44, + 0x66, + 0x4E, + 0x92, + 0xBB, + 0x53, + 0x1A, + 0x44, + 0x66, + 0x77, + 0x99, + 0x15, + 0xB3, + 0x00, + 0x54, + 0xCC, + 0x54, + 0x01, + 0xAA, + 0x44, + 0x54, + 0x12, + 0x43, + 0x53, + 0x11, + 0x44, + 0x66, + 0x4E, + 0x92, + 0xBB, + 0x53, + 0x1A, + 0x44, + 0x66, + 0x77, + 0x99, + 0x1A, + 0x92, + 0xBB, + 0x53, + 0x11, + 0x44, + 0x66, + 0x92, + 0xBB, + 0x53, + 0x1A, + 0x44, + 0x66, + 0x77, + 0x99, + 0x15, + 0xB3, + 0x00, + 0x54, + 0xCC, + 0x54, + 0x01, + 0xAA, + 0x11, + 0x44, + 0x66, + 0x4E, + 0x92, + 0xBB, + 0x53, + 0x1A, + 0x80, + 0x00, + 0xFA, + 0xA5, + 0x0B, + 0xC0, + 0x00, + 0x04, + 0x4E, + 0x92, + 0xBB, + 0x53, + 0x11, + 0x4C, + 0x66, + 0x4E, + 0x92, + 0xBB, + 0x53, + 0x1A, + 0x44, + 0x66, + 0x77, + 0x99, + 0x15, + 0xB3, + 0x00, + 0x54, + 0xCC, + 0x54, + 0x01, + 0xAA, + 0x44, + 0x54, + 0x12, + 0xa3, + 0x53, + 0x11, + 0x44, + 0x66, + 0xFE, + 0x92, + 0xBB, + 0x53, + 0x1A, + 0x44, + 0x66, + 0x77, + 0x99, + 0x1A, + 0x92, + 0xBB, + 0x53, + 0x11, + 0x44, + 0x66, + 0x92, + 0xBB, + 0x53, + 0x1A, + 0x44, + 0x66, + 0x77, + 0x99, + 0x15, + 0xB3, + 0x00, + 0x54, + 0xCC, + 0x54, + 0x01, + 0xAA, + 0x11, + 0x44, + 0x66, + 0x4E, + 0x92, + 0xBB, + 0x53, + 0x1A, + 0x80, + 0x00, + 0xFA, + 0xA5, + 0x0B, + 0xC0, + 0x00, + 0x04, + 0x4E, + 0x92, + 0x1B, + 0x53, + 0x11, + 0x44, + 0x66, + 0x4E, + 0x22, + 0xBB, + 0x53, + 0x1A, + 0x44, + 0x67, + 0x77, + 0x99, + 0x15, + 0xB3, + 0x00, + 0x54, + 0xCC, + 0x54, + 0x01, + 0xAA, + 0x44, + 0x54, + 0x12, + 0xD3, + 0x53, + 0x11, + 0x44, + 0x66, + 0x4E, + 0x92, + 0xBB, + 0x53, + 0x1A, + 0x44, + 0x66, + 0x77, + 0x99, + 0x1A, + 0x92, + 0xBB, + 0x53, + 0x11, + 0x44, + 0x66, + 0x92, + 0xBB, + 0x53, + 0x1A, + 0x44, + 0x66, + 0x77, + 0x99, + 0x15, + 0xB3, + 0x00, + 0x54, + 0xCC, + 0x54, + 0x01, + 0xAA, + 0x11, + 0x44, + 0x66, + 0x4E, + 0x92, + 0xBB, + 0x53, + 0x1A, + 0xC0, + 0x00, + 0xFA, + 0x15, + 0x0B, + 0xC0, + 0x00, + 0x04, + 0x4E, + 0x92, + 0xBB, + 0x53, + 0x11, + 0x44, + 0xCC, + 0x4E, + 0x92, + 0xBB, + 0x53, + 0x1A, + 0x44, + 0x66, + 0x77, + 0x99, + 0x15, + 0xB3, + 0x00, + 0x54, + 0xCC, + 0x54, + 0x01, + 0xAA, + 0x44, + 0x54, + 0x12, + 0x43, + 0x53, + 0x11, + 0x44, + 0x66, + 0x4E, + 0x92, + 0xBC, + 0x53, + 0x1A, + 0x44, + 0x66, + 0x77, + 0x99, + 0x1A, + 0x92, + 0xBB, + 0x53, + 0x11, + 0x44, + 0x66, + 0x92, + 0xBB, + 0x53, + 0x1A, + 0x44, + 0x66, + 0x77, + 0x99, + 0x15, + 0xB3, + 0x00, + 0x54, + 0xCC, + 0x54, + 0x01, + 0xAA, + 0x11, + 0x44, + 0x66, + 0x4E, + 0x92, + 0xBA, + 0x53, + 0x1A, + 0x60, + 0x00, + 0x00, + 0x00, + 0x00, + 0x10, + 0x3A, + 0x64, + 0xfe, + 0x80, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x02, + 0x00, + 0x00, + 0x11, + 0x12, + 0x13, + 0x14, + 0x15, + 0xfe, + 0x80, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x02, + 0x00, + 0x1A, + 0x2A, + 0x3F, + 0x09, + 0xAB, + 0x43, # / * 720 * / + 0x60, + 0x00, + 0xF0, + 0x00, + 0x00, + 0x10, + 0x3A, + 0x64, + 0xfe, + 0x80, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x02, + 0x00, + 0x00, + 0x11, + 0x12, + 0x13, + 0x14, + 0x15, + 0xfe, + 0x80, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x02, + 0x00, + 0x1A, + 0x2A, + 0x3F, + 0x09, + 0xAB, + 0x43, + 0x80, + 0x00, + 0xFA, + 0xA5, + 0x0B, + 0xC0, + 0x00, + 0x04, + 0x4E, + 0x92, + 0xBB, + 0x53, + 0x11, + 0x44, + 0x66, + 0x4E, + 0x92, + 0xBB, + 0x53, + 0x1A, + 0x44, + 0x66, + 0x77, + 0x99, + 0x15, + 0xB3, + 0x00, + 0x54, + 0xCC, + 0x54, + 0x01, + 0xAA, + 0x44, + 0x54, + 0x12, + 0x43, + 0x53, + 0x11, + 0x44, + 0x66, + 0x4E, + 0x92, + 0xBC, + 0x53, + 0x1A, + 0x44, + 0x66, + 0x77, + 0x99, + 0x1A, + 0x92, + 0xBB, + 0x53, + 0x11, + 0x44, + 0x66, + 0x92, + 0xBB, + 0x53, + 0x1A, + 0x44, + 0x66, + 0x77, + 0x99, + 0x15, + 0xB3, + 0x00, + 0x54, + 0xCC, + 0x54, + 0x01, + 0xAA, + 0x11, + 0x44, + 0x66, + 0x4E, + 0x92, + 0xBB, + 0x53, + 0x1A, + 0x80, + 0x00, + 0xFA, + 0xA5, + 0x0B, + 0xC0, + 0x00, + 0x04, + 0x4E, + 0x92, + 0xBB, + 0x53, + 0x11, + 0x4C, + 0x66, + 0x4E, + 0x92, + 0xBB, + 0x53, + 0x1A, + 0x44, + 0x66, + 0x77, + 0x99, + 0x15, + 0xB3, + 0x00, + 0x54, + 0xCC, + 0x54, + 0x01, + 0xAA, + 0x44, + 0x54, + 0x12, + 0xa3, + 0x53, + 0x11, + 0x44, + 0x66, + 0xFE, + 0x92, + 0xBB, + 0x53, + 0x1A, + 0x44, + 0x66, + 0x77, + 0x99, + 0x1A, + 0x92, + 0xBB, + 0x53, + 0x11, + 0x44, + 0x66, + 0x92, + 0xBB, + 0x53, + 0x1A, + 0x4D, + 0x66, + 0x77, + 0x99, + 0x15, + 0xB3, + 0x00, + 0x54, + 0xCC, + 0x54, + 0x01, + 0xAA, + 0x11, + 0x44, + 0x66, + 0x4E, + 0x92, + 0xBB, + 0x53, + 0x1A, + 0x80, + 0x00, + 0xFA, + 0xA5, + 0x0B, + 0xC0, + 0x00, + 0x04, + 0x4E, + 0x92, + 0x1B, + 0x53, + 0x11, + 0x44, + 0x66, + 0x4E, + 0x22, + 0xBB, + 0x51, + 0x1A, + 0x44, + 0x66, + 0x77, + 0x99, + 0x15, + 0xB3, + 0x00, + 0x54, + 0xCC, + 0x54, + 0x01, + 0xAA, + 0x44, + 0x54, + 0x12, + 0xD3, + 0x53, + 0x11, + 0x44, + 0x66, + 0x4E, + 0x92, + 0xBB, + 0x53, + 0x1A, + 0x44, + 0x66, + 0x77, + 0x99, + 0x1A, + 0x92, + 0xBB, + 0x53, + 0x11, + 0x44, + 0x66, + 0x92, + 0xBB, + 0x53, + 0x1A, + 0x44, + 0x66, + 0x77, + 0x99, + 0x15, + 0xB3, + 0x00, + 0x54, + 0xCC, + 0x54, + 0x01, + 0xAA, + 0x11, + 0x44, + 0x66, + 0x4E, + 0x92, + 0xBB, + 0x53, + 0x1A, + 0xC0, + 0x00, + 0xFA, + 0xA5, + 0x0B, + 0xC0, + 0x00, + 0x04, + 0x4E, + 0x92, + 0xBB, + 0x53, + 0x11, + 0x44, + 0xCC, + 0x4E, + 0x92, + 0xBB, + 0x53, + 0x1A, + 0x44, + 0x66, + 0x77, + 0x99, + 0x15, + 0xB3, + 0x00, + 0x54, + 0xCC, + 0x54, + 0x01, + 0xAA, + 0x44, + 0x54, + 0x12, + 0x4A, + 0x53, + 0x11, + 0x44, + 0x66, + 0x4E, + 0x92, + 0xBC, + 0x53, + 0x1A, + 0x44, + 0x66, + 0x77, + 0x99, + 0x1A, + 0x92, + 0xBB, + 0x53, + 0x11, + 0x44, + 0x66, + 0x92, + 0xBB, + 0x53, + 0x1A, + 0x44, + 0x66, + 0x77, + 0x99, + 0x15, + 0xB3, + 0x00, + 0x54, + 0xCC, + 0x54, + 0x01, + 0xAA, + 0x11, + 0x44, + 0x66, + 0x4E, + 0x92, + 0xBB, + 0x53, + 0x1A, # / * 1080 * / + 0x80, + 0x00, + 0xFA, + 0xA5, + 0x0B, + 0xC0, + 0x00, + 0x04, + 0x4E, + 0x92, + 0xBB, + 0x53, + 0x11, + 0x44, + 0x66, + 0x4E, + 0x92, + 0xBB, + 0x53, + 0x1A, + 0x44, + 0x66, + 0x77, + 0x99, + 0x15, + 0xB3, + 0x00, + 0x54, + 0xCC, + 0x54, + 0x01, + 0xAA, + 0x44, + 0x54, + 0x12, + 0x43, + 0x53, + 0x11, + 0x44, + 0x66, + 0x4E, + 0x92, + 0xBB, + 0x53, + 0x3A, + 0x44, + 0x66, + 0x77, + 0x99, + 0x1A, + 0x92, + 0xBB, + 0x53, + 0x11, + 0x44, + 0x66, + 0x92, + 0xBB, + 0x53, + 0x1A, + 0x44, + 0x66, + 0x77, + 0x99, + 0x15, + 0xB3, + 0x00, + 0x54, + 0xCC, + 0x54, + 0x01, + 0xAA, + 0x11, + 0x44, + 0x66, + 0x4E, + 0x92, + 0xBB, + 0x53, + 0x1A, + 0x80, + 0x00, + 0xFA, + 0xA5, + 0x0B, + 0xC0, + 0x00, + 0x04, + 0x4E, + 0x92, + 0xBB, + 0x53, + 0x11, + 0x4C, + 0x66, + 0x4E, + 0x92, + 0xBB, + 0x53, + 0x1A, + 0x44, + 0x66, + 0x77, + 0x99, + 0x15, + 0xB3, + 0x00, + 0x54, + 0xCC, + 0x54, + 0x01, + 0xAA, + 0x44, + 0x54, + 0x12, + 0xa3, + 0x53, + 0x11, + 0x44, + 0x66, + 0xFE, + 0x92, + 0xBB, + 0x53, + 0x1A, + 0x44, + 0x66, + 0x77, + 0x99, + 0x1A, + 0x92, + 0xBB, + 0x53, + 0x11, + 0x44, + 0x66, + 0x92, + 0xBB, + 0x53, + 0x1A, + 0x44, + 0x66, + 0x77, + 0x99, + 0x15, + 0xB3, + 0x00, + 0x54, + 0xCC, + 0x54, + 0x01, + 0xAA, + 0x11, + 0x44, + 0x66, + 0x4E, + 0x92, + 0xBB, + 0x53, + 0x1A, + 0x80, + 0x00, + 0xFA, + 0xA5, + 0x1B, + 0xC0, + 0x00, + 0x04, + 0x4E, + 0x92, + 0x1B, + 0x53, + 0x11, + 0x44, + 0x66, + 0x4E, + 0x22, + 0xBB, + 0x53, + 0x1A, + 0x44, + 0x66, + 0x77, + 0x99, + 0x15, + 0xB3, + 0x00, + 0x54, + 0xCC, + 0x54, + 0x01, + 0xAA, + 0x44, + 0x54, + 0x12, + 0xD3, + 0x53, + 0x11, + 0x44, + 0x66 + ]) self.assertEqual(ipv6_packet, actual_ipv6_packet.to_bytes()) - def test_should_defragment_IPv6_packet_when_parse_method_called_with_fragments(self): + def test_should_defragment_IPv6_packet_when_parse_method_called_with_fragments( + self): # GIVEN message_info = common.MessageInfo() message_info.source_mac_address = common.MacAddress.from_eui64( @@ -1146,32 +2319,40 @@ class TestLowpanParser(unittest.TestCase): message_info.destination_mac_address = common.MacAddress.from_eui64( bytearray([0x00, 0x00, 0x1A, 0x2A, 0x3F, 0x09, 0xAB, 0x43])) - fragment_1 = bytearray([0xC0, 0x38, 0x12, 0x34, 0x7A, 0x33, 0x3A, 0x80, - 0x00, 0x1A, 0x33, 0x0B, 0xC0, 0x00, 0x04]) + fragment_1 = bytearray([ + 0xC0, 0x38, 0x12, 0x34, 0x7A, 0x33, 0x3A, 0x80, 0x00, 0x1A, 0x33, + 0x0B, 0xC0, 0x00, 0x04 + ]) - fragment_2 = bytearray([0xE0, 0x38, 0x12, 0x34, 0x06, 0x4E, 0x92, 0xBB, - 0x53, 0x11, 0x12, 0x13, 0x14]) + fragment_2 = bytearray([ + 0xE0, 0x38, 0x12, 0x34, 0x06, 0x4E, 0x92, 0xBB, 0x53, 0x11, 0x12, + 0x13, 0x14 + ]) parser = create_default_lowpan_parser(None) # WHEN - self.assertIsNone(parser.parse(io.BytesIO(fragment_1), message_info=message_info)) - actual_ipv6_packet = parser.parse(io.BytesIO(fragment_2), message_info=message_info) + self.assertIsNone( + parser.parse(io.BytesIO(fragment_1), message_info=message_info)) + actual_ipv6_packet = parser.parse(io.BytesIO(fragment_2), + message_info=message_info) # THEN - ipv6_packet = bytearray([0x60, 0x00, 0x00, 0x00, 0x00, 0x10, 0x3A, 0x40, - 0xfe, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x02, 0x00, 0x00, 0x11, 0x12, 0x13, 0x14, 0x15, - 0xfe, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x02, 0x00, 0x1A, 0x2A, 0x3F, 0x09, 0xAB, 0x43, - 0x80, 0x00, 0x1A, 0x33, 0x0B, 0xC0, 0x00, 0x04, - 0x4E, 0x92, 0xBB, 0x53, 0x11, 0x12, 0x13, 0x14]) + ipv6_packet = bytearray([ + 0x60, 0x00, 0x00, 0x00, 0x00, 0x10, 0x3A, 0x40, 0xfe, 0x80, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x11, 0x12, 0x13, + 0x14, 0x15, 0xfe, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, + 0x00, 0x1A, 0x2A, 0x3F, 0x09, 0xAB, 0x43, 0x80, 0x00, 0x1A, 0x33, + 0x0B, 0xC0, 0x00, 0x04, 0x4E, 0x92, 0xBB, 0x53, 0x11, 0x12, 0x13, + 0x14 + ]) self.assertEqual(ipv6_packet, actual_ipv6_packet.to_bytes()) class TestLowpanUdpHeaderFactory(unittest.TestCase): - def test_should_parse_udp_datagram_ports_when_decompress_udp_ports_method_called_with_udphc_p_eq_0(self): + def test_should_parse_udp_datagram_ports_when_decompress_udp_ports_method_called_with_udphc_p_eq_0( + self): # GIVEN factory = lowpan.LowpanUdpHeaderFactory() @@ -1185,14 +2366,16 @@ class TestLowpanUdpHeaderFactory(unittest.TestCase): data_bytes = struct.pack(">H", src_port) + struct.pack(">H", dst_port) # WHEN - actual_src_port, actual_dst_port = factory._decompress_udp_ports(udphc, io.BytesIO(data_bytes)) + actual_src_port, actual_dst_port = factory._decompress_udp_ports( + udphc, io.BytesIO(data_bytes)) # THEN self.assertEqual(src_port, actual_src_port) self.assertEqual(dst_port, actual_dst_port) self.assertEqual(0, p) - def test_should_parse_udp_datagram_ports_when_decompress_udp_ports_method_called_with_udphc_p_eq_1(self): + def test_should_parse_udp_datagram_ports_when_decompress_udp_ports_method_called_with_udphc_p_eq_1( + self): # GIVEN factory = lowpan.LowpanUdpHeaderFactory() @@ -1203,17 +2386,20 @@ class TestLowpanUdpHeaderFactory(unittest.TestCase): src_port = any_src_port() dst_port = any_compressable_dst_port() - data_bytes = struct.pack(">H", src_port) + bytearray([struct.pack(">H", dst_port)[1]]) + data_bytes = struct.pack(">H", src_port) + bytearray( + [struct.pack(">H", dst_port)[1]]) # WHEN - actual_src_port, actual_dst_port = factory._decompress_udp_ports(udphc, io.BytesIO(data_bytes)) + actual_src_port, actual_dst_port = factory._decompress_udp_ports( + udphc, io.BytesIO(data_bytes)) # THEN self.assertEqual(1, p) self.assertEqual(src_port, actual_src_port) self.assertEqual(dst_port, actual_dst_port) - def test_should_parse_udp_datagram_ports_when_decompress_udp_ports_method_called_with_udphc_p_eq_2(self): + def test_should_parse_udp_datagram_ports_when_decompress_udp_ports_method_called_with_udphc_p_eq_2( + self): # GIVEN factory = lowpan.LowpanUdpHeaderFactory() @@ -1224,17 +2410,20 @@ class TestLowpanUdpHeaderFactory(unittest.TestCase): src_port = any_compressable_src_port() dst_port = any_dst_port() - data_bytes = bytearray([struct.pack(">H", src_port)[1]]) + struct.pack(">H", dst_port) + data_bytes = bytearray([struct.pack(">H", src_port)[1]]) + struct.pack( + ">H", dst_port) # WHEN - actual_src_port, actual_dst_port = factory._decompress_udp_ports(udphc, io.BytesIO(data_bytes)) + actual_src_port, actual_dst_port = factory._decompress_udp_ports( + udphc, io.BytesIO(data_bytes)) # THEN self.assertEqual(2, p) self.assertEqual(src_port, actual_src_port) self.assertEqual(dst_port, actual_dst_port) - def test_should_parse_udp_datagram_ports_when_decompress_udp_ports_method_called_with_udphc_p_eq_3(self): + def test_should_parse_udp_datagram_ports_when_decompress_udp_ports_method_called_with_udphc_p_eq_3( + self): # GIVEN factory = lowpan.LowpanUdpHeaderFactory() @@ -1248,14 +2437,16 @@ class TestLowpanUdpHeaderFactory(unittest.TestCase): data_bytes = bytearray([((src_port & 0x0F) << 4) | (dst_port & 0x0F)]) # WHEN - actual_src_port, actual_dst_port = factory._decompress_udp_ports(udphc, io.BytesIO(data_bytes)) + actual_src_port, actual_dst_port = factory._decompress_udp_ports( + udphc, io.BytesIO(data_bytes)) # THEN self.assertEqual(3, p) self.assertEqual(src_port, actual_src_port) self.assertEqual(dst_port, actual_dst_port) - def test_should_parse_udp_datagram_checksum_when_decompress_udp_checksum_called_with_udphc_c_eq_0(self): + def test_should_parse_udp_datagram_checksum_when_decompress_udp_checksum_called_with_udphc_c_eq_0( + self): # GIVEN factory = lowpan.LowpanUdpHeaderFactory() @@ -1268,13 +2459,15 @@ class TestLowpanUdpHeaderFactory(unittest.TestCase): data_bytes = struct.pack(">H", checksum) # WHEN - actual_checksum = factory._decompress_udp_checksum(udphc, io.BytesIO(data_bytes)) + actual_checksum = factory._decompress_udp_checksum( + udphc, io.BytesIO(data_bytes)) # THEN self.assertEqual(0, c) self.assertEqual(checksum, actual_checksum) - def test_should_parse_udp_datagram_checksum_when_decompress_udp_checksum_called_with_udphc_c_eq_1(self): + def test_should_parse_udp_datagram_checksum_when_decompress_udp_checksum_called_with_udphc_c_eq_1( + self): # GIVEN factory = lowpan.LowpanUdpHeaderFactory() @@ -1285,7 +2478,8 @@ class TestLowpanUdpHeaderFactory(unittest.TestCase): data_bytes = bytearray() # WHEN - actual_checksum = factory._decompress_udp_checksum(udphc, io.BytesIO(data_bytes)) + actual_checksum = factory._decompress_udp_checksum( + udphc, io.BytesIO(data_bytes)) # THEN self.assertEqual(1, c) @@ -1294,9 +2488,11 @@ class TestLowpanUdpHeaderFactory(unittest.TestCase): class TestLowpanIpv6HeaderFactory(unittest.TestCase): - IPV6_LINKLOCAL_PREFIX = bytearray([0xfe, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]) + IPV6_LINKLOCAL_PREFIX = bytearray( + [0xfe, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]) - def test_should_parse_traffic_class_and_flow_label_when_decompress_tf_method_called_with_iphc_tf_eq_0(self): + def test_should_parse_traffic_class_and_flow_label_when_decompress_tf_method_called_with_iphc_tf_eq_0( + self): # GIVEN ecn = any_ecn() dscp = any_dscp() @@ -1315,14 +2511,16 @@ class TestLowpanIpv6HeaderFactory(unittest.TestCase): any_sam(), any_m(), any_dac(), any_dam()) # WHEN - actual_traffic_class, actual_flow_label = factory._decompress_tf(iphc, io.BytesIO(data_bytes)) + actual_traffic_class, actual_flow_label = factory._decompress_tf( + iphc, io.BytesIO(data_bytes)) # THEN self.assertEqual(0, tf) self.assertEqual((dscp << 2) | ecn, actual_traffic_class) self.assertEqual(flow_label, actual_flow_label) - def test_should_parse_traffic_class_and_flow_label_when_decompress_tf_method_called_with_iphc_tf_eq_1(self): + def test_should_parse_traffic_class_and_flow_label_when_decompress_tf_method_called_with_iphc_tf_eq_1( + self): # GIVEN ecn = any_ecn() flow_label = any_flow_label() @@ -1339,14 +2537,16 @@ class TestLowpanIpv6HeaderFactory(unittest.TestCase): any_sam(), any_m(), any_dac(), any_dam()) # WHEN - actual_traffic_class, actual_flow_label = factory._decompress_tf(iphc, io.BytesIO(data_bytes)) + actual_traffic_class, actual_flow_label = factory._decompress_tf( + iphc, io.BytesIO(data_bytes)) # THEN self.assertEqual(1, tf) self.assertEqual(ecn, actual_traffic_class) self.assertEqual(flow_label, actual_flow_label) - def test_should_parse_traffic_class_and_flow_label_when_decompress_tf_method_called_with_iphc_tf_eq_2(self): + def test_should_parse_traffic_class_and_flow_label_when_decompress_tf_method_called_with_iphc_tf_eq_2( + self): # GIVEN ecn = any_ecn() dscp = any_dscp() @@ -1360,14 +2560,16 @@ class TestLowpanIpv6HeaderFactory(unittest.TestCase): any_sam(), any_m(), any_dac(), any_dam()) # WHEN - actual_traffic_class, actual_flow_label = factory._decompress_tf(iphc, io.BytesIO(data_bytes)) + actual_traffic_class, actual_flow_label = factory._decompress_tf( + iphc, io.BytesIO(data_bytes)) # THEN self.assertEqual(2, tf) self.assertEqual((dscp << 2) | ecn, actual_traffic_class) self.assertEqual(0, actual_flow_label) - def test_should_parse_traffic_class_and_flow_label_when_decompress_tf_method_called_with_iphc_tf_eq_3(self): + def test_should_parse_traffic_class_and_flow_label_when_decompress_tf_method_called_with_iphc_tf_eq_3( + self): data_bytes = bytearray() factory = lowpan.LowpanIpv6HeaderFactory() @@ -1377,14 +2579,16 @@ class TestLowpanIpv6HeaderFactory(unittest.TestCase): any_sam(), any_m(), any_dac(), any_dam()) # WHEN - actual_traffic_class, actual_flow_label = factory._decompress_tf(iphc, io.BytesIO(data_bytes)) + actual_traffic_class, actual_flow_label = factory._decompress_tf( + iphc, io.BytesIO(data_bytes)) # THEN self.assertEqual(3, tf) self.assertEqual(0, actual_traffic_class) self.assertEqual(0, actual_flow_label) - def test_should_parse_traffic_class_and_flow_label_when_decompress_nh_method_called_with_iphc_nh_eq_0(self): + def test_should_parse_traffic_class_and_flow_label_when_decompress_nh_method_called_with_iphc_nh_eq_0( + self): # GIVEN factory = lowpan.LowpanIpv6HeaderFactory() @@ -1397,13 +2601,15 @@ class TestLowpanIpv6HeaderFactory(unittest.TestCase): data_bytes = bytearray([next_header]) # WHEN - actual_next_header = factory._decompress_nh(iphc, io.BytesIO(data_bytes)) + actual_next_header = factory._decompress_nh(iphc, + io.BytesIO(data_bytes)) # THEN self.assertEqual(0, nh) self.assertEqual(next_header, actual_next_header) - def test_should_parse_traffic_class_and_flow_label_when_decompress_nh_method_called_with_iphc_nh_eq_1(self): + def test_should_parse_traffic_class_and_flow_label_when_decompress_nh_method_called_with_iphc_nh_eq_1( + self): # GIVEN factory = lowpan.LowpanIpv6HeaderFactory() @@ -1414,13 +2620,15 @@ class TestLowpanIpv6HeaderFactory(unittest.TestCase): data_bytes = bytearray() # WHEN - actual_next_header = factory._decompress_nh(iphc, io.BytesIO(data_bytes)) + actual_next_header = factory._decompress_nh(iphc, + io.BytesIO(data_bytes)) # THEN self.assertEqual(1, nh) self.assertEqual(None, actual_next_header) - def test_should_parse_hop_limit_when_decompress_hlim_called_with_iphc_hlim_eq_0(self): + def test_should_parse_hop_limit_when_decompress_hlim_called_with_iphc_hlim_eq_0( + self): # GIVEN hop_limit = any_hop_limit() @@ -1433,13 +2641,15 @@ class TestLowpanIpv6HeaderFactory(unittest.TestCase): data_bytes = bytearray([hop_limit]) # WHEN - actual_hop_limit = factory._decompress_hlim(iphc, io.BytesIO(data_bytes)) + actual_hop_limit = factory._decompress_hlim(iphc, + io.BytesIO(data_bytes)) # THEN self.assertEqual(0, hlim) self.assertEqual(hop_limit, actual_hop_limit) - def test_should_parse_hop_limit_when_decompress_hlim_called_with_iphc_hlim_eq_1(self): + def test_should_parse_hop_limit_when_decompress_hlim_called_with_iphc_hlim_eq_1( + self): # GIVEN factory = lowpan.LowpanIpv6HeaderFactory() @@ -1450,13 +2660,15 @@ class TestLowpanIpv6HeaderFactory(unittest.TestCase): data_bytes = bytearray() # WHEN - actual_hop_limit = factory._decompress_hlim(iphc, io.BytesIO(data_bytes)) + actual_hop_limit = factory._decompress_hlim(iphc, + io.BytesIO(data_bytes)) # THEN self.assertEqual(1, hlim) self.assertEqual(1, actual_hop_limit) - def test_should_parse_hop_limit_when_decompress_hlim_called_with_iphc_hlim_eq_2(self): + def test_should_parse_hop_limit_when_decompress_hlim_called_with_iphc_hlim_eq_2( + self): # GIVEN factory = lowpan.LowpanIpv6HeaderFactory() @@ -1467,13 +2679,15 @@ class TestLowpanIpv6HeaderFactory(unittest.TestCase): data_bytes = bytearray() # WHEN - actual_hop_limit = factory._decompress_hlim(iphc, io.BytesIO(data_bytes)) + actual_hop_limit = factory._decompress_hlim(iphc, + io.BytesIO(data_bytes)) # THEN self.assertEqual(2, hlim) self.assertEqual(64, actual_hop_limit) - def test_should_parse_hop_limit_when_decompress_hlim_called_with_iphc_hlim_eq_3(self): + def test_should_parse_hop_limit_when_decompress_hlim_called_with_iphc_hlim_eq_3( + self): # GIVEN factory = lowpan.LowpanIpv6HeaderFactory() @@ -1484,13 +2698,15 @@ class TestLowpanIpv6HeaderFactory(unittest.TestCase): data_bytes = bytearray() # WHEN - actual_hop_limit = factory._decompress_hlim(iphc, io.BytesIO(data_bytes)) + actual_hop_limit = factory._decompress_hlim(iphc, + io.BytesIO(data_bytes)) # THEN self.assertEqual(3, hlim) self.assertEqual(255, actual_hop_limit) - def test_should_parse_source_address_when_decompress_src_addr_called_with_sac_eq_0_and_sam_eq_0(self): + def test_should_parse_source_address_when_decompress_src_addr_called_with_sac_eq_0_and_sam_eq_0( + self): # GIVEN factory = lowpan.LowpanIpv6HeaderFactory() @@ -1503,14 +2719,17 @@ class TestLowpanIpv6HeaderFactory(unittest.TestCase): sam, any_m(), any_dac(), any_dam()) # WHEN - actual_src_addr = factory._decompress_src_addr(iphc, any_src_mac_addr(), any_sci(), io.BytesIO(src_addr)) + actual_src_addr = factory._decompress_src_addr(iphc, any_src_mac_addr(), + any_sci(), + io.BytesIO(src_addr)) # THEN self.assertEqual(0, sac) self.assertEqual(0, sam) self.assertEqual(bytes(src_addr), actual_src_addr) - def test_should_parse_source_address_when_decompress_src_addr_called_with_sac_eq_0_and_sam_eq_1(self): + def test_should_parse_source_address_when_decompress_src_addr_called_with_sac_eq_0_and_sam_eq_1( + self): # GIVEN factory = lowpan.LowpanIpv6HeaderFactory() @@ -1523,14 +2742,17 @@ class TestLowpanIpv6HeaderFactory(unittest.TestCase): sam, any_m(), any_dac(), any_dam()) # WHEN - actual_src_addr = factory._decompress_src_addr(iphc, any_src_mac_addr(), any_sci(), io.BytesIO(eui64)) + actual_src_addr = factory._decompress_src_addr(iphc, any_src_mac_addr(), + any_sci(), + io.BytesIO(eui64)) # THEN self.assertEqual(0, sac) self.assertEqual(1, sam) self.assertEqual(self.IPV6_LINKLOCAL_PREFIX + eui64, actual_src_addr) - def test_should_parse_source_address_when_decompress_src_addr_called_with_sac_eq_0_and_sam_eq_2(self): + def test_should_parse_source_address_when_decompress_src_addr_called_with_sac_eq_0_and_sam_eq_2( + self): # GIVEN factory = lowpan.LowpanIpv6HeaderFactory() @@ -1543,19 +2765,20 @@ class TestLowpanIpv6HeaderFactory(unittest.TestCase): sam, any_m(), any_dac(), any_dam()) # WHEN - actual_src_addr = factory._decompress_src_addr(iphc, any_src_mac_addr(), any_sci(), io.BytesIO(rloc16)) + actual_src_addr = factory._decompress_src_addr(iphc, any_src_mac_addr(), + any_sci(), + io.BytesIO(rloc16)) # THEN self.assertEqual(0, sac) self.assertEqual(2, sam) self.assertEqual( - self.IPV6_LINKLOCAL_PREFIX - + bytearray([0x00, 0x00, 0x00, 0xff, 0xfe, 0x00]) - + rloc16, - actual_src_addr - ) + self.IPV6_LINKLOCAL_PREFIX + + bytearray([0x00, 0x00, 0x00, 0xff, 0xfe, 0x00]) + rloc16, + actual_src_addr) - def test_should_parse_source_address_when_decompress_src_addr_called_with_sac_eq_0_and_sam_eq_3(self): + def test_should_parse_source_address_when_decompress_src_addr_called_with_sac_eq_0_and_sam_eq_3( + self): # GIVEN factory = lowpan.LowpanIpv6HeaderFactory() @@ -1570,17 +2793,17 @@ class TestLowpanIpv6HeaderFactory(unittest.TestCase): data_bytes = bytearray([]) # WHEN - actual_src_addr = factory._decompress_src_addr(iphc, src_mac_addr, any_sci(), io.BytesIO(data_bytes)) + actual_src_addr = factory._decompress_src_addr(iphc, src_mac_addr, + any_sci(), + io.BytesIO(data_bytes)) # THEN self.assertEqual(0, sac) self.assertEqual(3, sam) self.assertEqual( - self.IPV6_LINKLOCAL_PREFIX - + bytearray([src_mac_addr.mac_address[0] ^ 0x02]) - + src_mac_addr.mac_address[1:], - actual_src_addr - ) + self.IPV6_LINKLOCAL_PREFIX + + bytearray([src_mac_addr.mac_address[0] ^ 0x02]) + + src_mac_addr.mac_address[1:], actual_src_addr) def _merge_prefix_and_address(self, prefix, prefix_length, address): total_bytes = 16 @@ -1596,9 +2819,11 @@ class TestLowpanIpv6HeaderFactory(unittest.TestCase): total_bytes -= prefix_length_in_bytes total_bytes -= len(address) - return prefix[:prefix_length_in_bytes] + bytearray([0x00] * total_bytes) + address + return prefix[:prefix_length_in_bytes] + bytearray( + [0x00] * total_bytes) + address - def test_should_parse_source_address_when_decompress_src_addr_called_with_sac_eq_1_and_sam_eq_0(self): + def test_should_parse_source_address_when_decompress_src_addr_called_with_sac_eq_1_and_sam_eq_0( + self): # GIVEN factory = lowpan.LowpanIpv6HeaderFactory(None) @@ -1611,14 +2836,17 @@ class TestLowpanIpv6HeaderFactory(unittest.TestCase): sam, any_m(), any_dac(), any_dam()) # WHEN - actual_src_addr = factory._decompress_src_addr(iphc, any_src_mac_addr(), any_sci(), io.BytesIO(src_addr)) + actual_src_addr = factory._decompress_src_addr(iphc, any_src_mac_addr(), + any_sci(), + io.BytesIO(src_addr)) # THEN self.assertEqual(1, sac) self.assertEqual(0, sam) self.assertEqual(bytearray([0x00] * 16), actual_src_addr) - def test_should_parse_source_address_when_decompress_src_addr_called_with_sac_eq_1_and_sam_eq_1(self): + def test_should_parse_source_address_when_decompress_src_addr_called_with_sac_eq_1_and_sam_eq_1( + self): # GIVEN sci = any_sci() @@ -1637,17 +2865,20 @@ class TestLowpanIpv6HeaderFactory(unittest.TestCase): iphc = lowpan.LowpanIPHC(any_tf(), any_nh(), any_hlim(), any_cid(), sac, sam, any_m(), any_dac(), any_dam()) - src_addr = self._merge_prefix_and_address(context.prefix, context.prefix_length, eui64) + src_addr = self._merge_prefix_and_address(context.prefix, + context.prefix_length, eui64) # WHEN - actual_src_addr = factory._decompress_src_addr(iphc, any_src_mac_addr(), sci, io.BytesIO(eui64)) + actual_src_addr = factory._decompress_src_addr(iphc, any_src_mac_addr(), + sci, io.BytesIO(eui64)) # THEN self.assertEqual(1, sac) self.assertEqual(1, sam) self.assertEqual(src_addr, actual_src_addr) - def test_should_parse_source_address_when_decompress_src_addr_called_with_sac_eq_1_and_sam_eq_2(self): + def test_should_parse_source_address_when_decompress_src_addr_called_with_sac_eq_1_and_sam_eq_2( + self): # GIVEN sci = any_sci() @@ -1668,17 +2899,20 @@ class TestLowpanIpv6HeaderFactory(unittest.TestCase): iid = bytearray([0x00, 0x00, 0x00, 0xff, 0xfe, 0x00]) + rloc16 - src_addr = self._merge_prefix_and_address(context.prefix, context.prefix_length, iid) + src_addr = self._merge_prefix_and_address(context.prefix, + context.prefix_length, iid) # WHEN - actual_src_addr = factory._decompress_src_addr(iphc, any_src_mac_addr(), sci, io.BytesIO(rloc16)) + actual_src_addr = factory._decompress_src_addr(iphc, any_src_mac_addr(), + sci, io.BytesIO(rloc16)) # THEN self.assertEqual(1, sac) self.assertEqual(2, sam) self.assertEqual(src_addr, actual_src_addr) - def test_should_parse_source_address_when_decompress_src_addr_called_with_sac_eq_1_and_sam_eq_3(self): + def test_should_parse_source_address_when_decompress_src_addr_called_with_sac_eq_1_and_sam_eq_3( + self): # GIVEN sci = any_sci() @@ -1697,21 +2931,25 @@ class TestLowpanIpv6HeaderFactory(unittest.TestCase): iphc = lowpan.LowpanIPHC(any_tf(), any_nh(), any_hlim(), any_cid(), sac, sam, any_m(), any_dac(), any_dam()) - iid = bytearray([src_mac_addr.mac_address[0] ^ 0x02]) + src_mac_addr.mac_address[1:] + iid = bytearray([src_mac_addr.mac_address[0] ^ 0x02 + ]) + src_mac_addr.mac_address[1:] - src_addr = self._merge_prefix_and_address(context.prefix, context.prefix_length, iid) + src_addr = self._merge_prefix_and_address(context.prefix, + context.prefix_length, iid) data_bytes = bytearray([]) # WHEN - actual_src_addr = factory._decompress_src_addr(iphc, src_mac_addr, sci, io.BytesIO(data_bytes)) + actual_src_addr = factory._decompress_src_addr(iphc, src_mac_addr, sci, + io.BytesIO(data_bytes)) # THEN self.assertEqual(1, sac) self.assertEqual(3, sam) self.assertEqual(src_addr, actual_src_addr) - def test_should_parse_dst_addr_when_decompress_dst_addr_called_with_m_eq_0_and_dac_eq_0_and_dam_eq_0(self): + def test_should_parse_dst_addr_when_decompress_dst_addr_called_with_m_eq_0_and_dac_eq_0_and_dam_eq_0( + self): # GIVEN factory = lowpan.LowpanIpv6HeaderFactory() @@ -1721,13 +2959,15 @@ class TestLowpanIpv6HeaderFactory(unittest.TestCase): dac = factory.IPHC_DAC_STATELESS dam = factory.IPHC_DAM_128B - iphc = lowpan.LowpanIPHC(any_tf(), any_nh(), any_hlim(), any_cid(), any_sac(), - any_sam(), m, dac, dam) + iphc = lowpan.LowpanIPHC(any_tf(), any_nh(), any_hlim(), any_cid(), + any_sac(), any_sam(), m, dac, dam) dst_mac_addr = bytearray([0x00] * 8) # WHEN - actual_dst_addr = factory._decompress_dst_addr(iphc, dst_mac_addr, any_dci(), io.BytesIO(ipv6_addr)) + actual_dst_addr = factory._decompress_dst_addr(iphc, dst_mac_addr, + any_dci(), + io.BytesIO(ipv6_addr)) # THEN self.assertEqual(0, m) @@ -1735,7 +2975,8 @@ class TestLowpanIpv6HeaderFactory(unittest.TestCase): self.assertEqual(0, dam) self.assertEqual(ipv6_addr, actual_dst_addr) - def test_should_parse_dst_addr_when_decompress_dst_addr_called_with_m_eq_0_and_dac_eq_0_and_dam_eq_1(self): + def test_should_parse_dst_addr_when_decompress_dst_addr_called_with_m_eq_0_and_dac_eq_0_and_dam_eq_1( + self): # GIVEN factory = lowpan.LowpanIpv6HeaderFactory() @@ -1745,11 +2986,13 @@ class TestLowpanIpv6HeaderFactory(unittest.TestCase): dac = factory.IPHC_DAC_STATELESS dam = factory.IPHC_DAM_64B - iphc = lowpan.LowpanIPHC(any_tf(), any_nh(), any_hlim(), any_cid(), any_sac(), - any_sam(), m, dac, dam) + iphc = lowpan.LowpanIPHC(any_tf(), any_nh(), any_hlim(), any_cid(), + any_sac(), any_sam(), m, dac, dam) # WHEN - actual_dst_addr = factory._decompress_dst_addr(iphc, any_dst_mac_addr(), any_dci(), io.BytesIO(eui64)) + actual_dst_addr = factory._decompress_dst_addr(iphc, any_dst_mac_addr(), + any_dci(), + io.BytesIO(eui64)) # THEN self.assertEqual(0, m) @@ -1757,7 +3000,8 @@ class TestLowpanIpv6HeaderFactory(unittest.TestCase): self.assertEqual(1, dam) self.assertEqual(self.IPV6_LINKLOCAL_PREFIX + eui64, actual_dst_addr) - def test_should_parse_dst_addr_when_decompress_dst_addr_called_with_m_eq_0_and_dac_eq_0_and_dam_eq_2(self): + def test_should_parse_dst_addr_when_decompress_dst_addr_called_with_m_eq_0_and_dac_eq_0_and_dam_eq_2( + self): # GIVEN factory = lowpan.LowpanIpv6HeaderFactory() @@ -1767,24 +3011,25 @@ class TestLowpanIpv6HeaderFactory(unittest.TestCase): dac = factory.IPHC_DAC_STATELESS dam = factory.IPHC_DAM_16B - iphc = lowpan.LowpanIPHC(any_tf(), any_nh(), any_hlim(), any_cid(), any_sac(), - any_sam(), m, dac, dam) + iphc = lowpan.LowpanIPHC(any_tf(), any_nh(), any_hlim(), any_cid(), + any_sac(), any_sam(), m, dac, dam) # WHEN - actual_dst_addr = factory._decompress_dst_addr(iphc, any_dst_mac_addr(), any_dci(), io.BytesIO(rloc16)) + actual_dst_addr = factory._decompress_dst_addr(iphc, any_dst_mac_addr(), + any_dci(), + io.BytesIO(rloc16)) # THEN self.assertEqual(0, m) self.assertEqual(0, dac) self.assertEqual(2, dam) self.assertEqual( - self.IPV6_LINKLOCAL_PREFIX - + bytearray([0x00, 0x00, 0x00, 0xff, 0xfe, 0x00]) - + rloc16, - actual_dst_addr - ) + self.IPV6_LINKLOCAL_PREFIX + + bytearray([0x00, 0x00, 0x00, 0xff, 0xfe, 0x00]) + rloc16, + actual_dst_addr) - def test_should_parse_dst_addr_when_decompress_dst_addr_called_with_m_eq_0_and_dac_eq_0_and_dam_eq_3(self): + def test_should_parse_dst_addr_when_decompress_dst_addr_called_with_m_eq_0_and_dac_eq_0_and_dam_eq_3( + self): # GIVEN factory = lowpan.LowpanIpv6HeaderFactory() @@ -1794,26 +3039,27 @@ class TestLowpanIpv6HeaderFactory(unittest.TestCase): dac = factory.IPHC_DAC_STATELESS dam = factory.IPHC_DAM_ELIDED - iphc = lowpan.LowpanIPHC(any_tf(), any_nh(), any_hlim(), any_cid(), any_sac(), - any_sam(), m, dac, dam) + iphc = lowpan.LowpanIPHC(any_tf(), any_nh(), any_hlim(), any_cid(), + any_sac(), any_sam(), m, dac, dam) data_bytes = bytearray([]) # WHEN - actual_dst_addr = factory._decompress_dst_addr(iphc, dst_mac_addr, any_dci(), io.BytesIO(data_bytes)) + actual_dst_addr = factory._decompress_dst_addr(iphc, dst_mac_addr, + any_dci(), + io.BytesIO(data_bytes)) # THEN self.assertEqual(0, m) self.assertEqual(0, dac) self.assertEqual(3, dam) self.assertEqual( - self.IPV6_LINKLOCAL_PREFIX - + bytearray([dst_mac_addr.mac_address[0] ^ 0x02]) - + dst_mac_addr.mac_address[1:], - actual_dst_addr - ) + self.IPV6_LINKLOCAL_PREFIX + + bytearray([dst_mac_addr.mac_address[0] ^ 0x02]) + + dst_mac_addr.mac_address[1:], actual_dst_addr) - def test_should_raise_RuntimeError_when_decompress_dst_addr_called_with_m_eq_0_and_dac_eq_1_and_dam_eq_0(self): + def test_should_raise_RuntimeError_when_decompress_dst_addr_called_with_m_eq_0_and_dac_eq_1_and_dam_eq_0( + self): # GIVEN factory = lowpan.LowpanIpv6HeaderFactory() @@ -1823,14 +3069,15 @@ class TestLowpanIpv6HeaderFactory(unittest.TestCase): dac = factory.IPHC_DAC_STATEFUL dam = factory.IPHC_DAM_128B - iphc = lowpan.LowpanIPHC(any_tf(), any_nh(), any_hlim(), any_cid(), any_sac(), - any_sam(), m, dac, dam) + iphc = lowpan.LowpanIPHC(any_tf(), any_nh(), any_hlim(), any_cid(), + any_sac(), any_sam(), m, dac, dam) # WHEN self.assertRaises(RuntimeError, factory._decompress_dst_addr, iphc, any_dst_mac_addr(), any_dci(), io.BytesIO(ipv6_addr)) - def test_should_parse_dst_addr_when_decompress_dst_addr_called_with_m_eq_0_and_dac_eq_1_and_dam_eq_1(self): + def test_should_parse_dst_addr_when_decompress_dst_addr_called_with_m_eq_0_and_dac_eq_1_and_dam_eq_1( + self): # GIVEN dci = any_dci() @@ -1847,13 +3094,15 @@ class TestLowpanIpv6HeaderFactory(unittest.TestCase): dac = factory.IPHC_DAC_STATEFUL dam = factory.IPHC_DAM_64B - iphc = lowpan.LowpanIPHC(any_tf(), any_nh(), any_hlim(), any_cid(), any_sac(), - any_sam(), m, dac, dam) + iphc = lowpan.LowpanIPHC(any_tf(), any_nh(), any_hlim(), any_cid(), + any_sac(), any_sam(), m, dac, dam) - dst_addr = self._merge_prefix_and_address(context.prefix, context.prefix_length, eui64) + dst_addr = self._merge_prefix_and_address(context.prefix, + context.prefix_length, eui64) # WHEN - actual_dst_addr = factory._decompress_dst_addr(iphc, any_dst_mac_addr(), dci, io.BytesIO(eui64)) + actual_dst_addr = factory._decompress_dst_addr(iphc, any_dst_mac_addr(), + dci, io.BytesIO(eui64)) # THEN self.assertEqual(0, m) @@ -1861,7 +3110,8 @@ class TestLowpanIpv6HeaderFactory(unittest.TestCase): self.assertEqual(1, dam) self.assertEqual(dst_addr, actual_dst_addr) - def test_should_parse_dst_addr_when_decompress_dst_addr_called_with_m_eq_0_and_dac_eq_1_and_dam_eq_2(self): + def test_should_parse_dst_addr_when_decompress_dst_addr_called_with_m_eq_0_and_dac_eq_1_and_dam_eq_2( + self): # GIVEN dci = any_dci() @@ -1878,15 +3128,17 @@ class TestLowpanIpv6HeaderFactory(unittest.TestCase): dac = factory.IPHC_DAC_STATEFUL dam = factory.IPHC_DAM_16B - iphc = lowpan.LowpanIPHC(any_tf(), any_nh(), any_hlim(), any_cid(), any_sac(), - any_sam(), m, dac, dam) + iphc = lowpan.LowpanIPHC(any_tf(), any_nh(), any_hlim(), any_cid(), + any_sac(), any_sam(), m, dac, dam) iid = bytearray([0x00, 0x00, 0x00, 0xff, 0xfe, 0x00]) + rloc16 - dst_addr = self._merge_prefix_and_address(context.prefix, context.prefix_length, iid) + dst_addr = self._merge_prefix_and_address(context.prefix, + context.prefix_length, iid) # WHEN - actual_dst_addr = factory._decompress_dst_addr(iphc, any_dst_mac_addr(), dci, io.BytesIO(rloc16)) + actual_dst_addr = factory._decompress_dst_addr(iphc, any_dst_mac_addr(), + dci, io.BytesIO(rloc16)) # THEN self.assertEqual(0, m) @@ -1894,7 +3146,8 @@ class TestLowpanIpv6HeaderFactory(unittest.TestCase): self.assertEqual(2, dam) self.assertEqual(dst_addr, actual_dst_addr) - def test_should_parse_dst_addr_when_decompress_dst_addr_called_with_m_eq_0_and_dac_eq_1_and_dam_eq_3(self): + def test_should_parse_dst_addr_when_decompress_dst_addr_called_with_m_eq_0_and_dac_eq_1_and_dam_eq_3( + self): # GIVEN dci = any_dci() @@ -1911,17 +3164,20 @@ class TestLowpanIpv6HeaderFactory(unittest.TestCase): dac = factory.IPHC_DAC_STATEFUL dam = factory.IPHC_DAM_0B - iphc = lowpan.LowpanIPHC(any_tf(), any_nh(), any_hlim(), any_cid(), any_sac(), - any_sam(), m, dac, dam) + iphc = lowpan.LowpanIPHC(any_tf(), any_nh(), any_hlim(), any_cid(), + any_sac(), any_sam(), m, dac, dam) - iid = bytearray([dst_mac_addr.mac_address[0] ^ 0x02]) + dst_mac_addr.mac_address[1:] + iid = bytearray([dst_mac_addr.mac_address[0] ^ 0x02 + ]) + dst_mac_addr.mac_address[1:] - dst_addr = self._merge_prefix_and_address(context.prefix, context.prefix_length, iid) + dst_addr = self._merge_prefix_and_address(context.prefix, + context.prefix_length, iid) data_bytes = bytearray([]) # WHEN - actual_dst_addr = factory._decompress_dst_addr(iphc, dst_mac_addr, dci, io.BytesIO(data_bytes)) + actual_dst_addr = factory._decompress_dst_addr(iphc, dst_mac_addr, dci, + io.BytesIO(data_bytes)) # THEN self.assertEqual(0, m) @@ -1929,7 +3185,8 @@ class TestLowpanIpv6HeaderFactory(unittest.TestCase): self.assertEqual(3, dam) self.assertEqual(dst_addr, actual_dst_addr) - def test_should_parse_dst_addr_when_decompress_dst_addr_called_with_m_eq_1_and_dac_eq_0_and_dam_eq_0(self): + def test_should_parse_dst_addr_when_decompress_dst_addr_called_with_m_eq_1_and_dac_eq_0_and_dam_eq_0( + self): # GIVEN factory = lowpan.LowpanIpv6HeaderFactory() @@ -1939,11 +3196,13 @@ class TestLowpanIpv6HeaderFactory(unittest.TestCase): dac = factory.IPHC_DAC_STATELESS dam = factory.IPHC_DAM_128B - iphc = lowpan.LowpanIPHC(any_tf(), any_nh(), any_hlim(), any_cid(), any_sac(), - any_sam(), m, dac, dam) + iphc = lowpan.LowpanIPHC(any_tf(), any_nh(), any_hlim(), any_cid(), + any_sac(), any_sam(), m, dac, dam) # WHEN - actual_dst_addr = factory._decompress_dst_addr(iphc, any_dst_mac_addr(), any_dci(), io.BytesIO(ipv6_addr)) + actual_dst_addr = factory._decompress_dst_addr(iphc, any_dst_mac_addr(), + any_dci(), + io.BytesIO(ipv6_addr)) # THEN self.assertEqual(1, m) @@ -1951,7 +3210,8 @@ class TestLowpanIpv6HeaderFactory(unittest.TestCase): self.assertEqual(0, dam) self.assertEqual(ipv6_addr, actual_dst_addr) - def test_should_parse_dst_addr_when_decompress_dst_addr_called_with_m_eq_1_and_dac_eq_0_and_dam_eq_1(self): + def test_should_parse_dst_addr_when_decompress_dst_addr_called_with_m_eq_1_and_dac_eq_0_and_dam_eq_1( + self): # GIVEN factory = lowpan.LowpanIpv6HeaderFactory() @@ -1961,14 +3221,18 @@ class TestLowpanIpv6HeaderFactory(unittest.TestCase): dac = factory.IPHC_DAC_STATELESS dam = factory.IPHC_DAM_48B - iphc = lowpan.LowpanIPHC(any_tf(), any_nh(), any_hlim(), any_cid(), any_sac(), - any_sam(), m, dac, dam) + iphc = lowpan.LowpanIPHC(any_tf(), any_nh(), any_hlim(), any_cid(), + any_sac(), any_sam(), m, dac, dam) - expected_dst_addr = bytearray([0xff, addr48b[0], 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, addr48b[1], addr48b[2], addr48b[3], addr48b[4], addr48b[5]]) + expected_dst_addr = bytearray([ + 0xff, addr48b[0], 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, addr48b[1], addr48b[2], addr48b[3], addr48b[4], addr48b[5] + ]) # WHEN - actual_dst_addr = factory._decompress_dst_addr(iphc, any_dst_mac_addr(), any_dci(), io.BytesIO(addr48b)) + actual_dst_addr = factory._decompress_dst_addr(iphc, any_dst_mac_addr(), + any_dci(), + io.BytesIO(addr48b)) # THEN self.assertEqual(1, m) @@ -1976,7 +3240,8 @@ class TestLowpanIpv6HeaderFactory(unittest.TestCase): self.assertEqual(1, dam) self.assertEqual(expected_dst_addr, actual_dst_addr) - def test_should_parse_dst_addr_when_decompress_dst_addr_called_with_m_eq_1_and_dac_eq_0_and_dam_eq_2(self): + def test_should_parse_dst_addr_when_decompress_dst_addr_called_with_m_eq_1_and_dac_eq_0_and_dam_eq_2( + self): # GIVEN factory = lowpan.LowpanIpv6HeaderFactory() @@ -1986,14 +3251,18 @@ class TestLowpanIpv6HeaderFactory(unittest.TestCase): dac = factory.IPHC_DAC_STATELESS dam = factory.IPHC_DAM_32B - iphc = lowpan.LowpanIPHC(any_tf(), any_nh(), any_hlim(), any_cid(), any_sac(), - any_sam(), m, dac, dam) + iphc = lowpan.LowpanIPHC(any_tf(), any_nh(), any_hlim(), any_cid(), + any_sac(), any_sam(), m, dac, dam) - expected_dst_addr = bytearray([0xff, addr32b[0], 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, addr32b[1], addr32b[2], addr32b[3]]) + expected_dst_addr = bytearray([ + 0xff, addr32b[0], 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, addr32b[1], addr32b[2], addr32b[3] + ]) # WHEN - actual_dst_addr = factory._decompress_dst_addr(iphc, any_dst_mac_addr(), any_dci(), io.BytesIO(addr32b)) + actual_dst_addr = factory._decompress_dst_addr(iphc, any_dst_mac_addr(), + any_dci(), + io.BytesIO(addr32b)) # THEN self.assertEqual(1, m) @@ -2001,7 +3270,8 @@ class TestLowpanIpv6HeaderFactory(unittest.TestCase): self.assertEqual(2, dam) self.assertEqual(expected_dst_addr, actual_dst_addr) - def test_should_parse_dst_addr_when_decompress_dst_addr_called_with_m_eq_1_and_dac_eq_0_and_dam_eq_3(self): + def test_should_parse_dst_addr_when_decompress_dst_addr_called_with_m_eq_1_and_dac_eq_0_and_dam_eq_3( + self): # GIVEN factory = lowpan.LowpanIpv6HeaderFactory() @@ -2011,14 +3281,18 @@ class TestLowpanIpv6HeaderFactory(unittest.TestCase): dac = factory.IPHC_DAC_STATELESS dam = factory.IPHC_DAM_8B - iphc = lowpan.LowpanIPHC(any_tf(), any_nh(), any_hlim(), any_cid(), any_sac(), - any_sam(), m, dac, dam) + iphc = lowpan.LowpanIPHC(any_tf(), any_nh(), any_hlim(), any_cid(), + any_sac(), any_sam(), m, dac, dam) - expected_dst_addr = bytearray([0xff, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, addr8b[0]]) + expected_dst_addr = bytearray([ + 0xff, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, addr8b[0] + ]) # WHEN - actual_dst_addr = factory._decompress_dst_addr(iphc, any_dst_mac_addr(), any_dci(), io.BytesIO(addr8b)) + actual_dst_addr = factory._decompress_dst_addr(iphc, any_dst_mac_addr(), + any_dci(), + io.BytesIO(addr8b)) # THEN self.assertEqual(1, m) @@ -2026,7 +3300,8 @@ class TestLowpanIpv6HeaderFactory(unittest.TestCase): self.assertEqual(3, dam) self.assertEqual(expected_dst_addr, actual_dst_addr) - def test_should_raise_RuntimeError_when_decompress_dst_addr_called_with_m_eq_1_and_dac_eq_1_and_dam_eq_0(self): + def test_should_raise_RuntimeError_when_decompress_dst_addr_called_with_m_eq_1_and_dac_eq_1_and_dam_eq_0( + self): # GIVEN dci = any_dci() @@ -2043,8 +3318,8 @@ class TestLowpanIpv6HeaderFactory(unittest.TestCase): dac = factory.IPHC_DAC_STATEFUL dam = factory.IPHC_DAM_128B - iphc = lowpan.LowpanIPHC(any_tf(), any_nh(), any_hlim(), any_cid(), any_sac(), - any_sam(), m, dac, dam) + iphc = lowpan.LowpanIPHC(any_tf(), any_nh(), any_hlim(), any_cid(), + any_sac(), any_sam(), m, dac, dam) prefix = context.prefix[:8] @@ -2054,10 +3329,12 @@ class TestLowpanIpv6HeaderFactory(unittest.TestCase): prefix_length = context.prefix_length - dst_addr = bytearray([0xff]) + addr48b[:2] + bytearray([prefix_length]) + prefix + addr48b[2:] + dst_addr = bytearray([0xff]) + addr48b[:2] + bytearray( + [prefix_length]) + prefix + addr48b[2:] # WHEN - actual_dst_addr = factory._decompress_dst_addr(iphc, any_dst_mac_addr(), dci, io.BytesIO(addr48b)) + actual_dst_addr = factory._decompress_dst_addr(iphc, any_dst_mac_addr(), + dci, io.BytesIO(addr48b)) # THEN self.assertEqual(1, m) @@ -2065,7 +3342,8 @@ class TestLowpanIpv6HeaderFactory(unittest.TestCase): self.assertEqual(0, dam) self.assertEqual(dst_addr, actual_dst_addr) - def test_should_raise_RuntimeError_when_decompress_dst_addr_called_with_m_eq_1_and_dac_eq_1_and_dam_eq_1(self): + def test_should_raise_RuntimeError_when_decompress_dst_addr_called_with_m_eq_1_and_dac_eq_1_and_dam_eq_1( + self): # GIVEN factory = lowpan.LowpanIpv6HeaderFactory() @@ -2075,14 +3353,15 @@ class TestLowpanIpv6HeaderFactory(unittest.TestCase): dac = factory.IPHC_DAC_STATEFUL dam = factory.IPHC_DAM_48B - iphc = lowpan.LowpanIPHC(any_tf(), any_nh(), any_hlim(), any_cid(), any_sac(), - any_sam(), m, dac, dam) + iphc = lowpan.LowpanIPHC(any_tf(), any_nh(), any_hlim(), any_cid(), + any_sac(), any_sam(), m, dac, dam) # WHEN self.assertRaises(RuntimeError, factory._decompress_dst_addr, iphc, any_dst_mac_addr(), any_dci(), io.BytesIO(addr48b)) - def test_should_raise_RuntimeError_when_decompress_dst_addr_called_with_m_eq_1_and_dac_eq_1_and_dam_eq_2(self): + def test_should_raise_RuntimeError_when_decompress_dst_addr_called_with_m_eq_1_and_dac_eq_1_and_dam_eq_2( + self): # GIVEN factory = lowpan.LowpanIpv6HeaderFactory() @@ -2092,14 +3371,15 @@ class TestLowpanIpv6HeaderFactory(unittest.TestCase): dac = factory.IPHC_DAC_STATEFUL dam = factory.IPHC_DAM_32B - iphc = lowpan.LowpanIPHC(any_tf(), any_nh(), any_hlim(), any_cid(), any_sac(), - any_sam(), m, dac, dam) + iphc = lowpan.LowpanIPHC(any_tf(), any_nh(), any_hlim(), any_cid(), + any_sac(), any_sam(), m, dac, dam) # WHEN self.assertRaises(RuntimeError, factory._decompress_dst_addr, iphc, any_dst_mac_addr(), any_dci(), io.BytesIO(addr32b)) - def test_should_parse_dst_addr_when_decompress_dst_addr_called_with_m_eq_1_and_dac_eq_1_and_dam_eq_3(self): + def test_should_parse_dst_addr_when_decompress_dst_addr_called_with_m_eq_1_and_dac_eq_1_and_dam_eq_3( + self): # GIVEN factory = lowpan.LowpanIpv6HeaderFactory() @@ -2109,61 +3389,73 @@ class TestLowpanIpv6HeaderFactory(unittest.TestCase): dac = factory.IPHC_DAC_STATEFUL dam = factory.IPHC_DAM_8B - iphc = lowpan.LowpanIPHC(any_tf(), any_nh(), any_hlim(), any_cid(), any_sac(), - any_sam(), m, dac, dam) + iphc = lowpan.LowpanIPHC(any_tf(), any_nh(), any_hlim(), any_cid(), + any_sac(), any_sam(), m, dac, dam) # WHEN self.assertRaises(RuntimeError, factory._decompress_dst_addr, iphc, any_dst_mac_addr(), any_dci(), io.BytesIO(addr8b)) - def test_should_merge_pfx_with_addr_bytes_when_merge_method_called_with_pfx_shorter_than_missing_bits(self): + def test_should_merge_pfx_with_addr_bytes_when_merge_method_called_with_pfx_shorter_than_missing_bits( + self): # GIVEN factory = lowpan.LowpanIpv6HeaderFactory() prefix = bytearray([0x20, 0x00, 0x0d, 0xb8]) prefix_length = 32 - address_bytes = bytearray([0x1a, 0x2b, 0x3c, 0x4d, 0x5e, 0x6f, 0x70, 0x81]) + address_bytes = bytearray( + [0x1a, 0x2b, 0x3c, 0x4d, 0x5e, 0x6f, 0x70, 0x81]) addr = prefix + bytearray([0x00] * 4) + address_bytes # WHEN - actual_addr = factory._merge_prefix_with_address(prefix, prefix_length, address_bytes) + actual_addr = factory._merge_prefix_with_address( + prefix, prefix_length, address_bytes) # THEN self.assertEqual(addr, actual_addr) - def test_should_merge_pfx_with_addr_bytes_when_merge_method_called_with_pfx_longer_than_missing_bits_overlap(self): + def test_should_merge_pfx_with_addr_bytes_when_merge_method_called_with_pfx_longer_than_missing_bits_overlap( + self): # GIVEN factory = lowpan.LowpanIpv6HeaderFactory() - prefix = bytearray([0x20, 0x00, 0x0d, 0xb8, 0x00, 0x00, 0x00, 0x00, 0x22]) + prefix = bytearray( + [0x20, 0x00, 0x0d, 0xb8, 0x00, 0x00, 0x00, 0x00, 0x22]) prefix_length = 68 - address_bytes = bytearray([0x1a, 0x2b, 0x3c, 0x4d, 0x5e, 0x6f, 0x70, 0x81]) + address_bytes = bytearray( + [0x1a, 0x2b, 0x3c, 0x4d, 0x5e, 0x6f, 0x70, 0x81]) addr = prefix[:-1] + bytearray([0x2a]) + address_bytes[1:] # WHEN - actual_addr = factory._merge_prefix_with_address(prefix, prefix_length, address_bytes) + actual_addr = factory._merge_prefix_with_address( + prefix, prefix_length, address_bytes) # THEN self.assertEqual(addr, actual_addr) - def test_should_merge_pfx_with_address_bytes_when_merge_method_called_with_pfx_longer_than_missing_bits(self): + def test_should_merge_pfx_with_address_bytes_when_merge_method_called_with_pfx_longer_than_missing_bits( + self): # GIVEN factory = lowpan.LowpanIpv6HeaderFactory() - prefix = bytearray([0x20, 0x00, 0x0d, 0xb8, 0x00, 0x00, 0x00, 0x00, - 0x22, 0x00, 0x00, 0x11, 0x01, 0x11, 0x01, 0x22]) + prefix = bytearray([ + 0x20, 0x00, 0x0d, 0xb8, 0x00, 0x00, 0x00, 0x00, 0x22, 0x00, 0x00, + 0x11, 0x01, 0x11, 0x01, 0x22 + ]) prefix_length = 128 - address_bytes = bytearray([0x1a, 0x2b, 0x3c, 0x4d, 0x5e, 0x6f, 0x70, 0x81]) + address_bytes = bytearray( + [0x1a, 0x2b, 0x3c, 0x4d, 0x5e, 0x6f, 0x70, 0x81]) addr = prefix # WHEN - actual_addr = factory._merge_prefix_with_address(prefix, prefix_length, address_bytes) + actual_addr = factory._merge_prefix_with_address( + prefix, prefix_length, address_bytes) # THEN self.assertEqual(addr, actual_addr) @@ -2171,7 +3463,8 @@ class TestLowpanIpv6HeaderFactory(unittest.TestCase): class TestContext(unittest.TestCase): - def test_should_extract_context_from_str_representation_when_constructor_called(self): + def test_should_extract_context_from_str_representation_when_constructor_called( + self): # GIVEN prefix = "2000:db8::/64" @@ -2179,7 +3472,9 @@ class TestContext(unittest.TestCase): c = lowpan.Context(prefix) # THEN - self.assertEqual(bytearray([0x20, 0x00, 0x0d, 0xb8, 0x00, 0x00, 0x00, 0x00]), c.prefix) + self.assertEqual( + bytearray([0x20, 0x00, 0x0d, 0xb8, 0x00, 0x00, 0x00, 0x00]), + c.prefix) self.assertEqual(64, c.prefix_length) self.assertEqual(8, c.prefix_length_full_bytes) @@ -2191,7 +3486,9 @@ class TestContext(unittest.TestCase): c = lowpan.Context(prefix) # THEN - self.assertEqual(bytearray([0x20, 0x00, 0x0d, 0xb8, 0x00, 0x00, 0x00, 0x00]), c.prefix) + self.assertEqual( + bytearray([0x20, 0x00, 0x0d, 0xb8, 0x00, 0x00, 0x00, 0x00]), + c.prefix) self.assertEqual(8, c.prefix_length_full_bytes) self.assertEqual(64, c.prefix_length) @@ -2233,7 +3530,8 @@ class TestLowpanMeshHeader(unittest.TestCase): # GIVEN hops_left = any_hops_left() - mesh_header = lowpan.LowpanMeshHeader(hops_left, any_mac_address(), any_mac_address()) + mesh_header = lowpan.LowpanMeshHeader(hops_left, any_mac_address(), + any_mac_address()) # WHEN actual_hops_left = mesh_header.hops_left @@ -2241,11 +3539,14 @@ class TestLowpanMeshHeader(unittest.TestCase): # THEN self.assertEqual(hops_left, actual_hops_left) - def test_should_return_originator_address_value_when_originator_address_property_called(self): + def test_should_return_originator_address_value_when_originator_address_property_called( + self): # GIVEN originator_address = any_mac_address() - mesh_header = lowpan.LowpanMeshHeader(any_hops_left(), originator_address, any_mac_address()) + mesh_header = lowpan.LowpanMeshHeader(any_hops_left(), + originator_address, + any_mac_address()) # WHEN actual_originator_address = mesh_header.originator_address @@ -2253,17 +3554,21 @@ class TestLowpanMeshHeader(unittest.TestCase): # THEN self.assertEqual(originator_address, actual_originator_address) - def test_should_return_final_destination_address_value_when_final_destination_address_property_called(self): + def test_should_return_final_destination_address_value_when_final_destination_address_property_called( + self): # GIVEN final_destination_address = any_mac_address() - mesh_header = lowpan.LowpanMeshHeader(any_hops_left(), any_mac_address(), final_destination_address) + mesh_header = lowpan.LowpanMeshHeader(any_hops_left(), + any_mac_address(), + final_destination_address) # WHEN actual_final_destination_address = mesh_header.final_destination_address # THEN - self.assertEqual(final_destination_address, actual_final_destination_address) + self.assertEqual(final_destination_address, + actual_final_destination_address) class TestLowpanMeshHeaderFactory(unittest.TestCase): @@ -2281,7 +3586,8 @@ class TestLowpanMeshHeaderFactory(unittest.TestCase): mesh_header_first_byte = (2 << 6) | (v << 5) | (f << 4) if hops_left >= 0x0f: - mesh_header_data = bytearray([mesh_header_first_byte | 0x0f, hops_left]) + mesh_header_data = bytearray( + [mesh_header_first_byte | 0x0f, hops_left]) else: mesh_header_data = bytearray([mesh_header_first_byte | hops_left]) @@ -2290,17 +3596,20 @@ class TestLowpanMeshHeaderFactory(unittest.TestCase): mesh_header_factory = lowpan.LowpanMeshHeaderFactory() # WHEN - mesh_header = mesh_header_factory.parse(io.BytesIO(mesh_header_data), None) + mesh_header = mesh_header_factory.parse(io.BytesIO(mesh_header_data), + None) # THEN self.assertEqual(hops_left, mesh_header.hops_left) self.assertEqual(originator_address, mesh_header.originator_address) - self.assertEqual(final_destination_address, mesh_header.final_destination_address) + self.assertEqual(final_destination_address, + mesh_header.final_destination_address) class TestLowpanFragmentationHeader(unittest.TestCase): - def test_should_return_datagram_size_value_when_datagram_size_property_called(self): + def test_should_return_datagram_size_value_when_datagram_size_property_called( + self): # GIVEN datagram_size = any_datagram_size() @@ -2313,7 +3622,8 @@ class TestLowpanFragmentationHeader(unittest.TestCase): # THEN self.assertEqual(datagram_size, actual_datagram_size) - def test_should_return_datagram_tag_value_when_datagram_tag_property_called(self): + def test_should_return_datagram_tag_value_when_datagram_tag_property_called( + self): # GIVEN datagram_tag = any_datagram_tag() @@ -2326,7 +3636,8 @@ class TestLowpanFragmentationHeader(unittest.TestCase): # THEN self.assertEqual(datagram_tag, actual_datagram_tag) - def test_should_return_datagram_offset_value_when_datagram_offset_property_called(self): + def test_should_return_datagram_offset_value_when_datagram_offset_property_called( + self): # GIVEN datagram_offset = any_datagram_offset() @@ -2339,7 +3650,8 @@ class TestLowpanFragmentationHeader(unittest.TestCase): # THEN self.assertEqual(datagram_offset, actual_datagram_offset) - def test_should_return_False_when_is_first_property_called_and_datagram_offset_is_not_eq_0(self): + def test_should_return_False_when_is_first_property_called_and_datagram_offset_is_not_eq_0( + self): # GIVEN datagram_offset = random.randint(1, (1 << 8) - 1) @@ -2352,17 +3664,21 @@ class TestLowpanFragmentationHeader(unittest.TestCase): # THEN self.assertFalse(is_first) - def test_should_to_bytes_LowpanFragmentationHeader_from_bytes_when_from_bytes_class_method_called(self): + def test_should_to_bytes_LowpanFragmentationHeader_from_bytes_when_from_bytes_class_method_called( + self): # GIVEN datagram_size = any_datagram_size() datagram_tag = any_datagram_tag() datagram_offset = any_datagram_offset() - data = struct.pack(">HHB", ((3 << 14) | (int(datagram_offset != 0) << 13) | datagram_size), + data = struct.pack(">HHB", + ((3 << 14) | + (int(datagram_offset != 0) << 13) | datagram_size), datagram_tag, datagram_offset) # WHEN - fragmentation_header = lowpan.LowpanFragmentationHeader.from_bytes(io.BytesIO(data)) + fragmentation_header = lowpan.LowpanFragmentationHeader.from_bytes( + io.BytesIO(data)) # THEN self.assertEqual(datagram_size, fragmentation_header.datagram_size) @@ -2374,24 +3690,28 @@ class TestLowpanDecompressor(unittest.TestCase): def test_should_parse_parent_request_when_decompress_method_called(self): # GIVEN - data = bytearray([0x7f, 0x3b, 0x02, 0xf0, 0x4d, 0x4c, 0x4d, 0x4c, - 0x5e, 0xaf, 0x00, 0x15, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x01, 0x3b, 0xfb, 0x0e, - 0x3b, 0x15, 0xa1, 0xf9, 0xf5, 0x64, 0xf4, 0x99, - 0xef, 0x70, 0x78, 0x6c, 0x3c, 0x0f, 0x54, 0x4e, - 0x95, 0xe8, 0xf5, 0x27, 0x4c, 0xfc]) + data = bytearray([ + 0x7f, 0x3b, 0x02, 0xf0, 0x4d, 0x4c, 0x4d, 0x4c, 0x5e, 0xaf, 0x00, + 0x15, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x3b, + 0xfb, 0x0e, 0x3b, 0x15, 0xa1, 0xf9, 0xf5, 0x64, 0xf4, 0x99, 0xef, + 0x70, 0x78, 0x6c, 0x3c, 0x0f, 0x54, 0x4e, 0x95, 0xe8, 0xf5, 0x27, + 0x4c, 0xfc + ]) message_info = common.MessageInfo() message_info.source_mac_address = common.MacAddress.from_eui64( bytearray([0x12, 0xcf, 0xd3, 0x8b, 0x3b, 0x61, 0x55, 0x58])) - decompressor = config.create_default_lowpan_decompressor(context_manager=None) + decompressor = config.create_default_lowpan_decompressor( + context_manager=None) # WHEN - ipv6_header, extension_headers, udp_header = decompressor.decompress(io.BytesIO(data), message_info) + ipv6_header, extension_headers, udp_header = decompressor.decompress( + io.BytesIO(data), message_info) # THEN - self.assertEqual("fe80::10cf:d38b:3b61:5558", ipv6_header.source_address.compressed) + self.assertEqual("fe80::10cf:d38b:3b61:5558", + ipv6_header.source_address.compressed) self.assertEqual("ff02::2", ipv6_header.destination_address.compressed) self.assertEqual(17, ipv6_header.next_header) self.assertEqual(255, ipv6_header.hop_limit) @@ -2400,18 +3720,17 @@ class TestLowpanDecompressor(unittest.TestCase): def test_should_parse_parent_response_when_decompress_method_called(self): # GIVEN - data = bytearray([0x7f, 0x33, 0xf0, 0x4d, 0x4c, 0x4d, 0x4c, 0x0f, - 0xe8, 0x00, 0x15, 0x04, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x01, 0x31, 0xb8, 0x16, 0x02, - 0x61, 0xcc, 0x98, 0x90, 0xd6, 0xfd, 0x69, 0xd3, - 0x89, 0xa0, 0x30, 0x49, 0x83, 0x7c, 0xf7, 0xb5, - 0x7f, 0x83, 0x2a, 0x04, 0xf6, 0x3b, 0x8c, 0xe8, - 0xb6, 0x37, 0x51, 0x5b, 0x28, 0x9a, 0x3b, 0xbe, - 0x0d, 0xb3, 0x4e, 0x9f, 0xd8, 0x14, 0xc8, 0xc9, - 0xf4, 0x28, 0xf6, 0x8d, 0xb7, 0xf0, 0x7d, 0x46, - 0x13, 0xc2, 0xb1, 0x69, 0x4d, 0xae, 0xc1, 0x23, - 0x16, 0x62, 0x90, 0xea, 0xff, 0x1b, 0xb7, 0xd7, - 0x1e, 0x5c]) + data = bytearray([ + 0x7f, 0x33, 0xf0, 0x4d, 0x4c, 0x4d, 0x4c, 0x0f, 0xe8, 0x00, 0x15, + 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x31, 0xb8, + 0x16, 0x02, 0x61, 0xcc, 0x98, 0x90, 0xd6, 0xfd, 0x69, 0xd3, 0x89, + 0xa0, 0x30, 0x49, 0x83, 0x7c, 0xf7, 0xb5, 0x7f, 0x83, 0x2a, 0x04, + 0xf6, 0x3b, 0x8c, 0xe8, 0xb6, 0x37, 0x51, 0x5b, 0x28, 0x9a, 0x3b, + 0xbe, 0x0d, 0xb3, 0x4e, 0x9f, 0xd8, 0x14, 0xc8, 0xc9, 0xf4, 0x28, + 0xf6, 0x8d, 0xb7, 0xf0, 0x7d, 0x46, 0x13, 0xc2, 0xb1, 0x69, 0x4d, + 0xae, 0xc1, 0x23, 0x16, 0x62, 0x90, 0xea, 0xff, 0x1b, 0xb7, 0xd7, + 0x1e, 0x5c + ]) message_info = common.MessageInfo() message_info.source_mac_address = common.MacAddress.from_eui64( @@ -2419,14 +3738,18 @@ class TestLowpanDecompressor(unittest.TestCase): message_info.destination_mac_address = common.MacAddress.from_eui64( bytearray([0x12, 0xcf, 0xd3, 0x8b, 0x3b, 0x61, 0x55, 0x58])) - decompressor = config.create_default_lowpan_decompressor(context_manager=None) + decompressor = config.create_default_lowpan_decompressor( + context_manager=None) # WHEN - ipv6_header, extension_headers, udp_header = decompressor.decompress(io.BytesIO(data), message_info) + ipv6_header, extension_headers, udp_header = decompressor.decompress( + io.BytesIO(data), message_info) # THEN - self.assertEqual("fe80::383e:9eed:7a01:36a5", ipv6_header.source_address.compressed) - self.assertEqual("fe80::10cf:d38b:3b61:5558", ipv6_header.destination_address.compressed) + self.assertEqual("fe80::383e:9eed:7a01:36a5", + ipv6_header.source_address.compressed) + self.assertEqual("fe80::10cf:d38b:3b61:5558", + ipv6_header.destination_address.compressed) self.assertEqual(17, ipv6_header.next_header) self.assertEqual(255, ipv6_header.hop_limit) @@ -2437,16 +3760,15 @@ class TestLowpanDecompressor(unittest.TestCase): def test_should_parse_child_id_request_when_decompress_method_called(self): # GIVEN - data = bytearray([0x7f, 0x33, 0xf0, 0x4d, 0x4c, 0x4d, 0x4c, 0x9a, - 0x62, 0x00, 0x15, 0x01, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x01, 0x14, 0x03, 0xe3, 0x72, - 0x50, 0x4f, 0x8c, 0x5c, 0x42, 0x81, 0x68, 0xe2, - 0x11, 0xfc, 0xf5, 0x8c, 0x62, 0x8e, 0x83, 0x99, - 0xe7, 0x26, 0x86, 0x34, 0x3b, 0xa7, 0x68, 0xc7, - 0x93, 0xfb, 0x72, 0xd9, 0xcc, 0x13, 0x5e, 0x5b, - 0x96, 0x0e, 0xf1, 0x80, 0x03, 0x55, 0x4f, 0x27, - 0xc2, 0x96, 0xf4, 0x9c, 0x65, 0x82, 0x97, 0xcf, - 0x97, 0x35, 0x89, 0xc2]) + data = bytearray([ + 0x7f, 0x33, 0xf0, 0x4d, 0x4c, 0x4d, 0x4c, 0x9a, 0x62, 0x00, 0x15, + 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x14, 0x03, + 0xe3, 0x72, 0x50, 0x4f, 0x8c, 0x5c, 0x42, 0x81, 0x68, 0xe2, 0x11, + 0xfc, 0xf5, 0x8c, 0x62, 0x8e, 0x83, 0x99, 0xe7, 0x26, 0x86, 0x34, + 0x3b, 0xa7, 0x68, 0xc7, 0x93, 0xfb, 0x72, 0xd9, 0xcc, 0x13, 0x5e, + 0x5b, 0x96, 0x0e, 0xf1, 0x80, 0x03, 0x55, 0x4f, 0x27, 0xc2, 0x96, + 0xf4, 0x9c, 0x65, 0x82, 0x97, 0xcf, 0x97, 0x35, 0x89, 0xc2 + ]) message_info = common.MessageInfo() message_info.source_mac_address = common.MacAddress.from_eui64( @@ -2454,14 +3776,18 @@ class TestLowpanDecompressor(unittest.TestCase): message_info.destination_mac_address = common.MacAddress.from_eui64( bytearray([0x3a, 0x3e, 0x9e, 0xed, 0x7a, 0x01, 0x36, 0xa5])) - decompressor = config.create_default_lowpan_decompressor(context_manager=None) + decompressor = config.create_default_lowpan_decompressor( + context_manager=None) # WHEN - ipv6_header, extension_headers, udp_header = decompressor.decompress(io.BytesIO(data), message_info) + ipv6_header, extension_headers, udp_header = decompressor.decompress( + io.BytesIO(data), message_info) # THEN - self.assertEqual("fe80::10cf:d38b:3b61:5558", ipv6_header.source_address.compressed) - self.assertEqual("fe80::383e:9eed:7a01:36a5", ipv6_header.destination_address.compressed) + self.assertEqual("fe80::10cf:d38b:3b61:5558", + ipv6_header.source_address.compressed) + self.assertEqual("fe80::383e:9eed:7a01:36a5", + ipv6_header.destination_address.compressed) self.assertEqual(17, ipv6_header.next_header) self.assertEqual(255, ipv6_header.hop_limit) @@ -2472,15 +3798,15 @@ class TestLowpanDecompressor(unittest.TestCase): def test_should_parse_child_id_response_when_decompress_method_called(self): # GIVEN - data = bytearray([0x7f, 0x33, 0xf0, 0x4d, 0x4c, 0x4d, 0x4c, 0x7b, - 0xe3, 0x00, 0x15, 0x05, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x01, 0xe0, 0x57, 0xbf, 0x2f, - 0xc0, 0x4b, 0x1d, 0xac, 0x3c, 0x24, 0x16, 0xdf, - 0xeb, 0x96, 0xeb, 0xda, 0x42, 0xeb, 0x00, 0x89, - 0x5f, 0x39, 0xc9, 0x2b, 0x7d, 0x31, 0xd5, 0x83, - 0x9d, 0xdb, 0xb7, 0xc8, 0xe6, 0x25, 0xd3, 0x7a, - 0x1e, 0x5f, 0x66, 0x9e, 0x63, 0x2d, 0x42, 0x27, - 0x19, 0x41, 0xdc, 0xc4, 0xc4, 0xc0, 0x8c, 0x07]) + data = bytearray([ + 0x7f, 0x33, 0xf0, 0x4d, 0x4c, 0x4d, 0x4c, 0x7b, 0xe3, 0x00, 0x15, + 0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0xe0, 0x57, + 0xbf, 0x2f, 0xc0, 0x4b, 0x1d, 0xac, 0x3c, 0x24, 0x16, 0xdf, 0xeb, + 0x96, 0xeb, 0xda, 0x42, 0xeb, 0x00, 0x89, 0x5f, 0x39, 0xc9, 0x2b, + 0x7d, 0x31, 0xd5, 0x83, 0x9d, 0xdb, 0xb7, 0xc8, 0xe6, 0x25, 0xd3, + 0x7a, 0x1e, 0x5f, 0x66, 0x9e, 0x63, 0x2d, 0x42, 0x27, 0x19, 0x41, + 0xdc, 0xc4, 0xc4, 0xc0, 0x8c, 0x07 + ]) message_info = common.MessageInfo() message_info.source_mac_address = common.MacAddress.from_eui64( @@ -2488,14 +3814,18 @@ class TestLowpanDecompressor(unittest.TestCase): message_info.destination_mac_address = common.MacAddress.from_eui64( bytearray([0x12, 0xcf, 0xd3, 0x8b, 0x3b, 0x61, 0x55, 0x58])) - decompressor = config.create_default_lowpan_decompressor(context_manager=None) + decompressor = config.create_default_lowpan_decompressor( + context_manager=None) # WHEN - ipv6_header, extension_headers, udp_header = decompressor.decompress(io.BytesIO(data), message_info) + ipv6_header, extension_headers, udp_header = decompressor.decompress( + io.BytesIO(data), message_info) # THEN - self.assertEqual("fe80::383e:9eed:7a01:36a5", ipv6_header.source_address.compressed) - self.assertEqual("fe80::10cf:d38b:3b61:5558", ipv6_header.destination_address.compressed) + self.assertEqual("fe80::383e:9eed:7a01:36a5", + ipv6_header.source_address.compressed) + self.assertEqual("fe80::10cf:d38b:3b61:5558", + ipv6_header.destination_address.compressed) self.assertEqual(17, ipv6_header.next_header) self.assertEqual(255, ipv6_header.hop_limit) @@ -2506,25 +3836,28 @@ class TestLowpanDecompressor(unittest.TestCase): def test_should_parse_advertisement_when_decompress_method_called(self): # GIVEN - data = bytearray([0x7f, 0x3b, 0x01, 0xf0, 0x4d, 0x4c, 0x4d, 0x4c, - 0x35, 0x9f, 0x00, 0x15, 0x07, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x01, 0x9e, 0xb8, 0xd0, - 0x2f, 0x2a, 0xe0, 0x00, 0x5d, 0x66, 0x63, 0x05, - 0xa0, 0x59, 0xb0, 0xd4, 0x95, 0x7f, 0xe6, 0x79, - 0x17, 0x87, 0x2c, 0x1d, 0x83, 0xad, 0xc2, 0x64, - 0x47, 0x20, 0x7a, 0xe2]) + data = bytearray([ + 0x7f, 0x3b, 0x01, 0xf0, 0x4d, 0x4c, 0x4d, 0x4c, 0x35, 0x9f, 0x00, + 0x15, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x9e, + 0xb8, 0xd0, 0x2f, 0x2a, 0xe0, 0x00, 0x5d, 0x66, 0x63, 0x05, 0xa0, + 0x59, 0xb0, 0xd4, 0x95, 0x7f, 0xe6, 0x79, 0x17, 0x87, 0x2c, 0x1d, + 0x83, 0xad, 0xc2, 0x64, 0x47, 0x20, 0x7a, 0xe2 + ]) message_info = common.MessageInfo() message_info.source_mac_address = common.MacAddress.from_eui64( bytearray([0x3a, 0x3e, 0x9e, 0xed, 0x7a, 0x01, 0x36, 0xa5])) - decompressor = config.create_default_lowpan_decompressor(context_manager=None) + decompressor = config.create_default_lowpan_decompressor( + context_manager=None) # WHEN - ipv6_header, extension_headers, udp_header = decompressor.decompress(io.BytesIO(data), message_info) + ipv6_header, extension_headers, udp_header = decompressor.decompress( + io.BytesIO(data), message_info) # THEN - self.assertEqual("fe80::383e:9eed:7a01:36a5", ipv6_header.source_address.compressed) + self.assertEqual("fe80::383e:9eed:7a01:36a5", + ipv6_header.source_address.compressed) self.assertEqual("ff02::1", ipv6_header.destination_address.compressed) self.assertEqual(17, ipv6_header.next_header) self.assertEqual(255, ipv6_header.hop_limit) @@ -2537,16 +3870,19 @@ class TestLowpanDecompressor(unittest.TestCase): class TestLowpanFragmentsBuffer(unittest.TestCase): - def test_should_raise_ValueError_when_write_method_called_with_data_length_bigger_than_buffer_length(self): + def test_should_raise_ValueError_when_write_method_called_with_data_length_bigger_than_buffer_length( + self): # GIVEN length = random.randint(1, 1280) - fragments_buffer = lowpan.LowpanFragmentsBuffer(buffer_size=(length - 1)) + fragments_buffer = lowpan.LowpanFragmentsBuffer(buffer_size=(length - + 1)) # THEN self.assertRaises(ValueError, fragments_buffer.write, any_data(length)) - def test_should_move_write_position_by_the_data_length_when_write_method_called(self): + def test_should_move_write_position_by_the_data_length_when_write_method_called( + self): # GIVEN length = random.randint(1, 1280) @@ -2562,17 +3898,20 @@ class TestLowpanFragmentsBuffer(unittest.TestCase): # THEN self.assertEqual(fragments_buffer.tell() - start_position, len(data)) - def test_should_raise_ValueError_when_read_method_called_but_not_whole_packet_has_been_stored_in_buffer(self): + def test_should_raise_ValueError_when_read_method_called_but_not_whole_packet_has_been_stored_in_buffer( + self): # GIVEN data = any_data(length=3) - fragments_buffer = lowpan.LowpanFragmentsBuffer(buffer_size=random.randint(4, 1280)) + fragments_buffer = lowpan.LowpanFragmentsBuffer( + buffer_size=random.randint(4, 1280)) fragments_buffer.write(data) # WHEN self.assertRaises(ValueError, fragments_buffer.read) - def test_should_raise_ValueError_when_seek_method_called_with_offset_bigger_than_buffer_length(self): + def test_should_raise_ValueError_when_seek_method_called_with_offset_bigger_than_buffer_length( + self): # GIVEN offset = random.randint(1281, 2500) @@ -2606,7 +3945,8 @@ class TestLowpanFragmentsBuffer(unittest.TestCase): # THEN self.assertEqual(data, fragments_buffer.read()) - def test_should_write_many_frags_to_the_buffer_and_return_whole_message_when_write_method_called_many_times(self): + def test_should_write_many_frags_to_the_buffer_and_return_whole_message_when_write_method_called_many_times( + self): # GIVEN buffer_size = 42 fragments_buffer = lowpan.LowpanFragmentsBuffer(buffer_size=buffer_size) @@ -2649,18 +3989,20 @@ class TestLowpanFragmentsBuffer(unittest.TestCase): fragments_buffer.write(fragment_6) # THEN - self.assertEqual(bytearray([0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, - 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10, - 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, - 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, 0x20, - 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, - 0x29, 0x2a]), - fragments_buffer.read()) + self.assertEqual( + bytearray([ + 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, + 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10, 0x11, 0x12, 0x13, 0x14, + 0x15, 0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, + 0x1f, 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, + 0x29, 0x2a + ]), fragments_buffer.read()) class TestLowpanFragmentsBuffersManager(unittest.TestCase): - def test_should_raise_ValueError_when_get_fragments_buffer_method_called_with_invalid_dgram_size(self): + def test_should_raise_ValueError_when_get_fragments_buffer_method_called_with_invalid_dgram_size( + self): # GIVEN message_info = common.MessageInfo() message_info.source_mac_address = any_mac_address() @@ -2671,10 +4013,13 @@ class TestLowpanFragmentsBuffersManager(unittest.TestCase): manager = lowpan.LowpanFragmentsBuffersManager() # THEN - self.assertRaises(ValueError, manager.get_fragments_buffer, message_info, any_datagram_tag(), None) - self.assertRaises(ValueError, manager.get_fragments_buffer, message_info, any_datagram_tag(), negative_int) + self.assertRaises(ValueError, manager.get_fragments_buffer, + message_info, any_datagram_tag(), None) + self.assertRaises(ValueError, manager.get_fragments_buffer, + message_info, any_datagram_tag(), negative_int) - def test_should_return_LowpanFragmentsBuffer_when_get_fragments_buffer_method_called_with_valid_dgram_size(self): + def test_should_return_LowpanFragmentsBuffer_when_get_fragments_buffer_method_called_with_valid_dgram_size( + self): # GIVEN message_info = common.MessageInfo() message_info.source_mac_address = any_mac_address() @@ -2685,7 +4030,9 @@ class TestLowpanFragmentsBuffersManager(unittest.TestCase): manager = lowpan.LowpanFragmentsBuffersManager() # WHEN - fragments_buffer = manager.get_fragments_buffer(message_info, any_datagram_tag(), datagram_size) + fragments_buffer = manager.get_fragments_buffer(message_info, + any_datagram_tag(), + datagram_size) # THEN self.assertIsInstance(fragments_buffer, lowpan.LowpanFragmentsBuffer) diff --git a/tests/scripts/thread-cert/test_mac802154.py b/tests/scripts/thread-cert/test_mac802154.py index 449c7adff..bd289c41b 100755 --- a/tests/scripts/thread-cert/test_mac802154.py +++ b/tests/scripts/thread-cert/test_mac802154.py @@ -45,9 +45,8 @@ class TestMacParser(unittest.TestCase): frame = mac802154.MacFrame() frame.parse(io.BytesIO(bytearray([0x12, 0x00, 0x12, 0x34, 0x56]))) - self.assertEqual( - mac802154.MacHeader.FrameType.ACK, - frame.header.frame_type) + self.assertEqual(mac802154.MacHeader.FrameType.ACK, + frame.header.frame_type) self.assertEqual(True, frame.header.frame_pending) self.assertEqual(False, frame.header.ack_request) self.assertEqual(0, frame.header.frame_version) @@ -57,12 +56,15 @@ class TestMacParser(unittest.TestCase): def test_should_parse_data_frame_with_short_addresses(self): frame = mac802154.MacFrame() - frame.parse(io.BytesIO(bytearray([0x61, 0x88, 0x34, 0xce, 0xfa, - 0xad, 0xde, 0xef, 0xbe, 0x12, 0x34, 0xfe, 0xdc]))) + frame.parse( + io.BytesIO( + bytearray([ + 0x61, 0x88, 0x34, 0xce, 0xfa, 0xad, 0xde, 0xef, 0xbe, 0x12, + 0x34, 0xfe, 0xdc + ]))) - self.assertEqual( - mac802154.MacHeader.FrameType.DATA, - frame.header.frame_type) + self.assertEqual(mac802154.MacHeader.FrameType.DATA, + frame.header.frame_type) self.assertEqual(False, frame.header.frame_pending) self.assertEqual(True, frame.header.ack_request) self.assertEqual(0, frame.header.frame_version) @@ -77,17 +79,16 @@ class TestMacParser(unittest.TestCase): def test_should_parse_data_frame_with_extended_addresses(self): frame = mac802154.MacFrame() - frame.parse(io.BytesIO(bytearray([0x61, 0xcc, - 0x56, - 0xce, 0xfa, - 0xde, 0xad, 0xbe, 0xef, 0xde, 0xad, 0xbe, 0xef, - 0x0b, 0xad, 0xf0, 0x0d, 0xba, 0xd0, 0xd0, 0x0d, - 0x12, 0x34, - 0xfe, 0xdc]))) + frame.parse( + io.BytesIO( + bytearray([ + 0x61, 0xcc, 0x56, 0xce, 0xfa, 0xde, 0xad, 0xbe, 0xef, 0xde, + 0xad, 0xbe, 0xef, 0x0b, 0xad, 0xf0, 0x0d, 0xba, 0xd0, 0xd0, + 0x0d, 0x12, 0x34, 0xfe, 0xdc + ]))) - self.assertEqual( - mac802154.MacHeader.FrameType.DATA, - frame.header.frame_type) + self.assertEqual(mac802154.MacHeader.FrameType.DATA, + frame.header.frame_type) self.assertEqual(False, frame.header.frame_pending) self.assertEqual(True, frame.header.ack_request) self.assertEqual(0, frame.header.frame_version) @@ -95,36 +96,26 @@ class TestMacParser(unittest.TestCase): self.assertEqual(bytearray([0xfe, 0xdc]), frame.header.fcs) self.assertEqual(0xface, frame.header.dest_pan_id) self.assertEqual( - bytearray( - reversed( - [ - 0xde, 0xad, 0xbe, 0xef, - 0xde, 0xad, 0xbe, 0xef])), - frame.header.dest_address.mac_address) + bytearray(reversed([0xde, 0xad, 0xbe, 0xef, 0xde, 0xad, 0xbe, + 0xef])), frame.header.dest_address.mac_address) self.assertEqual(0xface, frame.header.src_pan_id) self.assertEqual( - bytearray( - reversed( - [ - 0x0b, 0xad, 0xf0, 0x0d, - 0xba, 0xd0, 0xd0, 0x0d])), - frame.header.src_address.mac_address) + bytearray(reversed([0x0b, 0xad, 0xf0, 0x0d, 0xba, 0xd0, 0xd0, + 0x0d])), frame.header.src_address.mac_address) self.assertEqual(bytearray([0x12, 0x34]), frame.payload.data) def test_should_parse_data_frame_with_short_and_extended_addresses(self): frame = mac802154.MacFrame() - frame.parse(io.BytesIO(bytearray([0x61, 0xc8, - 0x56, - 0xce, 0xfa, - 0xad, 0xde, - 0x0b, 0xad, 0xf0, 0x0d, 0xba, 0xd0, 0xd0, 0x0d, - 0x12, 0x34, - 0xfe, 0xdc]))) + frame.parse( + io.BytesIO( + bytearray([ + 0x61, 0xc8, 0x56, 0xce, 0xfa, 0xad, 0xde, 0x0b, 0xad, 0xf0, + 0x0d, 0xba, 0xd0, 0xd0, 0x0d, 0x12, 0x34, 0xfe, 0xdc + ]))) - self.assertEqual( - mac802154.MacHeader.FrameType.DATA, - frame.header.frame_type) + self.assertEqual(mac802154.MacHeader.FrameType.DATA, + frame.header.frame_type) self.assertEqual(False, frame.header.frame_pending) self.assertEqual(True, frame.header.ack_request) self.assertEqual(0, frame.header.frame_version) @@ -134,29 +125,22 @@ class TestMacParser(unittest.TestCase): self.assertEqual(0xdead, frame.header.dest_address.rloc) self.assertEqual(0xface, frame.header.src_pan_id) self.assertEqual( - bytearray( - reversed( - [ - 0x0b, 0xad, 0xf0, 0x0d, - 0xba, 0xd0, 0xd0, 0x0d])), - frame.header.src_address.mac_address) + bytearray(reversed([0x0b, 0xad, 0xf0, 0x0d, 0xba, 0xd0, 0xd0, + 0x0d])), frame.header.src_address.mac_address) self.assertEqual(bytearray([0x12, 0x34]), frame.payload.data) def test_should_parse_data_frame_with_extended_and_short_addresses(self): frame = mac802154.MacFrame() - frame.parse(io.BytesIO(bytearray([0x61, 0x8c, - 0x56, - 0xce, 0xfa, - 0xde, 0xad, 0xbe, 0xef, - 0xde, 0xad, 0xbe, 0xef, - 0x0d, 0xf0, - 0x12, 0x34, - 0xfe, 0xdc]))) + frame.parse( + io.BytesIO( + bytearray([ + 0x61, 0x8c, 0x56, 0xce, 0xfa, 0xde, 0xad, 0xbe, 0xef, 0xde, + 0xad, 0xbe, 0xef, 0x0d, 0xf0, 0x12, 0x34, 0xfe, 0xdc + ]))) - self.assertEqual( - mac802154.MacHeader.FrameType.DATA, - frame.header.frame_type) + self.assertEqual(mac802154.MacHeader.FrameType.DATA, + frame.header.frame_type) self.assertEqual(False, frame.header.frame_pending) self.assertEqual(True, frame.header.ack_request) self.assertEqual(0, frame.header.frame_version) @@ -164,12 +148,8 @@ class TestMacParser(unittest.TestCase): self.assertEqual(bytearray([0xfe, 0xdc]), frame.header.fcs) self.assertEqual(0xface, frame.header.dest_pan_id) self.assertEqual( - bytearray( - reversed( - [ - 0xde, 0xad, 0xbe, 0xef, - 0xde, 0xad, 0xbe, 0xef])), - frame.header.dest_address.mac_address) + bytearray(reversed([0xde, 0xad, 0xbe, 0xef, 0xde, 0xad, 0xbe, + 0xef])), frame.header.dest_address.mac_address) self.assertEqual(0xface, frame.header.src_pan_id) self.assertEqual(0xf00d, frame.header.src_address.rloc) @@ -177,17 +157,15 @@ class TestMacParser(unittest.TestCase): def test_should_parse_data_request_command(self): frame = mac802154.MacFrame() - frame.parse(io.BytesIO(bytearray([0x63, 0x88, - 0x78, - 0xce, 0xfa, - 0xad, 0xde, - 0x0d, 0xf0, - 0x04, - 0xfe, 0xdc]))) + frame.parse( + io.BytesIO( + bytearray([ + 0x63, 0x88, 0x78, 0xce, 0xfa, 0xad, 0xde, 0x0d, 0xf0, 0x04, + 0xfe, 0xdc + ]))) - self.assertEqual( - mac802154.MacHeader.FrameType.COMMAND, - frame.header.frame_type) + self.assertEqual(mac802154.MacHeader.FrameType.COMMAND, + frame.header.frame_type) self.assertEqual(False, frame.header.frame_pending) self.assertEqual(True, frame.header.ack_request) self.assertEqual(0, frame.header.frame_version) @@ -202,26 +180,77 @@ class TestMacParser(unittest.TestCase): def test_should_decrypt_data_frame(self): - mac802154.DeviceDescriptors.add(0x2001, MacAddress(bytearray( - [0x16, 0x6e, 0x0a, 0x00, 0x00, 0x00, 0x00, 0x07]), MacAddressType.LONG)) + mac802154.DeviceDescriptors.add( + 0x2001, + MacAddress( + bytearray([0x16, 0x6e, 0x0a, 0x00, 0x00, 0x00, 0x00, 0x07]), + MacAddressType.LONG)) frame = mac802154.MacFrame() - frame.parse(io.BytesIO(bytearray([0x69, 0x98, 0x68, # FC, seq - 0xce, 0xfa, # Pan Id - 0x00, 0x20, # Dst addr - 0x01, 0x20, # Src addr - 0x0d, 0x00, 0x00, 0x00, 0x00, 0x01, # Aux Security Header - 0xb5, 0x5a, 0x0d, 0x8e, 0x18, 0x5c, 0xb1, 0x06, # Payload - 0xc4, 0x6f, 0x7d, 0x6b, 0xb5, 0x4a, 0x87, 0x14, - 0xae, 0xdd, 0x8e, 0xb7, 0x37, 0x62, 0x27, 0x48, - 0xc9, 0x53, 0x0c, 0x44, 0x31, 0x59, 0x8b, 0xa2, - 0x83, 0x59, 0xa1, 0x43, # MIC (valid) - 0x74, 0xe0, 0x2a, 0xf6, - 0x99, 0xfc]))) # FCS (valid) + frame.parse( + io.BytesIO( + bytearray([ + 0x69, + 0x98, + 0x68, # FC, seq + 0xce, + 0xfa, # Pan Id + 0x00, + 0x20, # Dst addr + 0x01, + 0x20, # Src addr + 0x0d, + 0x00, + 0x00, + 0x00, + 0x00, + 0x01, # Aux Security Header + 0xb5, + 0x5a, + 0x0d, + 0x8e, + 0x18, + 0x5c, + 0xb1, + 0x06, # Payload + 0xc4, + 0x6f, + 0x7d, + 0x6b, + 0xb5, + 0x4a, + 0x87, + 0x14, + 0xae, + 0xdd, + 0x8e, + 0xb7, + 0x37, + 0x62, + 0x27, + 0x48, + 0xc9, + 0x53, + 0x0c, + 0x44, + 0x31, + 0x59, + 0x8b, + 0xa2, + 0x83, + 0x59, + 0xa1, + 0x43, # MIC (valid) + 0x74, + 0xe0, + 0x2a, + 0xf6, + 0x99, + 0xfc + ]))) # FCS (valid) - self.assertEqual( - mac802154.MacHeader.FrameType.DATA, - frame.header.frame_type) + self.assertEqual(mac802154.MacHeader.FrameType.DATA, + frame.header.frame_type) self.assertEqual(False, frame.header.frame_pending) self.assertEqual(True, frame.header.ack_request) self.assertEqual(1, frame.header.frame_version) @@ -235,45 +264,41 @@ class TestMacParser(unittest.TestCase): self.assertEqual(0, frame.header.aux_sec_header.frame_counter) self.assertEqual(5, frame.header.aux_sec_header.security_level) - self.assertEqual(bytes(bytearray([0x7c, 0x77, 0x80, 0xf0, - 0x4d, 0x4d, 0x4d, 0x4d, - 0xe0, 0x04, 0x44, 0x02, - 0x44, 0x66, 0x13, 0x5f, - 0x22, 0x80, 0xb1, 0x61, - 0x02, 0x61, 0x73, 0x11, - 0x2a, 0xff, 0x01, 0x08, - 0x16, 0x6e, 0x0a, 0x00, - 0x00, 0x00, 0x00, 0x07])), - frame.payload.data) + self.assertEqual( + bytes( + bytearray([ + 0x7c, 0x77, 0x80, 0xf0, 0x4d, 0x4d, 0x4d, 0x4d, 0xe0, 0x04, + 0x44, 0x02, 0x44, 0x66, 0x13, 0x5f, 0x22, 0x80, 0xb1, 0x61, + 0x02, 0x61, 0x73, 0x11, 0x2a, 0xff, 0x01, 0x08, 0x16, 0x6e, + 0x0a, 0x00, 0x00, 0x00, 0x00, 0x07 + ])), frame.payload.data) def test_should_decrypt_command_frame(self): frame = mac802154.MacFrame() - frame.parse(io.BytesIO(bytearray([0x6b, 0xdc, 0xce, 0xce, - 0xfa, 0x02, 0x00, 0x00, - 0x00, 0x00, 0x0a, 0x6e, - 0x16, 0x03, 0x00, 0x00, - 0x00, 0x00, 0x0a, 0x6e, - 0x16, 0x0d, 0x00, 0x00, - 0x00, 0x00, 0x01, 0x04, - 0x2d, 0xbc, 0x12, 0xbe, - 0x0a, 0x4f]))) + frame.parse( + io.BytesIO( + bytearray([ + 0x6b, 0xdc, 0xce, 0xce, 0xfa, 0x02, 0x00, 0x00, 0x00, 0x00, + 0x0a, 0x6e, 0x16, 0x03, 0x00, 0x00, 0x00, 0x00, 0x0a, 0x6e, + 0x16, 0x0d, 0x00, 0x00, 0x00, 0x00, 0x01, 0x04, 0x2d, 0xbc, + 0x12, 0xbe, 0x0a, 0x4f + ]))) - self.assertEqual( - mac802154.MacHeader.FrameType.COMMAND, - frame.header.frame_type) + self.assertEqual(mac802154.MacHeader.FrameType.COMMAND, + frame.header.frame_type) self.assertEqual(False, frame.header.frame_pending) self.assertEqual(True, frame.header.ack_request) self.assertEqual(1, frame.header.frame_version) self.assertEqual(206, frame.header.seq) self.assertEqual(bytearray([0x0a, 0x4f]), frame.header.fcs) self.assertEqual(0xface, frame.header.dest_pan_id) - self.assertEqual(bytearray([0x16, 0x6e, 0x0a, 0x00, - 0x00, 0x00, 0x00, 0x02]), - frame.header.dest_address.mac_address) + self.assertEqual( + bytearray([0x16, 0x6e, 0x0a, 0x00, 0x00, 0x00, 0x00, 0x02]), + frame.header.dest_address.mac_address) self.assertEqual(0xface, frame.header.src_pan_id) - self.assertEqual(bytearray([0x16, 0x6e, 0x0a, 0x00, - 0x00, 0x00, 0x00, 0x03]), - frame.header.src_address.mac_address) + self.assertEqual( + bytearray([0x16, 0x6e, 0x0a, 0x00, 0x00, 0x00, 0x00, 0x03]), + frame.header.src_address.mac_address) self.assertEqual(0, frame.header.aux_sec_header.frame_counter) self.assertEqual(5, frame.header.aux_sec_header.security_level) diff --git a/tests/scripts/thread-cert/test_mle.py b/tests/scripts/thread-cert/test_mle.py index 01526eedc..e00595d1a 100755 --- a/tests/scripts/thread-cert/test_mle.py +++ b/tests/scripts/thread-cert/test_mle.py @@ -59,22 +59,102 @@ def any_network_data(): mode_map = { - 0x00: {"receiver": 0, "secure": 0, "device_type": 0, "network_data": 0}, - 0x08: {"receiver": 1, "secure": 0, "device_type": 0, "network_data": 0}, - 0x04: {"receiver": 0, "secure": 1, "device_type": 0, "network_data": 0}, - 0x0C: {"receiver": 1, "secure": 1, "device_type": 0, "network_data": 0}, - 0x02: {"receiver": 0, "secure": 0, "device_type": 1, "network_data": 0}, - 0x0A: {"receiver": 1, "secure": 0, "device_type": 1, "network_data": 0}, - 0x06: {"receiver": 0, "secure": 1, "device_type": 1, "network_data": 0}, - 0x0E: {"receiver": 1, "secure": 1, "device_type": 1, "network_data": 0}, - 0x01: {"receiver": 0, "secure": 0, "device_type": 0, "network_data": 1}, - 0x09: {"receiver": 1, "secure": 0, "device_type": 0, "network_data": 1}, - 0x05: {"receiver": 0, "secure": 1, "device_type": 0, "network_data": 1}, - 0x0D: {"receiver": 1, "secure": 1, "device_type": 0, "network_data": 1}, - 0x03: {"receiver": 0, "secure": 0, "device_type": 1, "network_data": 1}, - 0x0B: {"receiver": 1, "secure": 0, "device_type": 1, "network_data": 1}, - 0x07: {"receiver": 0, "secure": 1, "device_type": 1, "network_data": 1}, - 0x0F: {"receiver": 1, "secure": 1, "device_type": 1, "network_data": 1} + 0x00: { + "receiver": 0, + "secure": 0, + "device_type": 0, + "network_data": 0 + }, + 0x08: { + "receiver": 1, + "secure": 0, + "device_type": 0, + "network_data": 0 + }, + 0x04: { + "receiver": 0, + "secure": 1, + "device_type": 0, + "network_data": 0 + }, + 0x0C: { + "receiver": 1, + "secure": 1, + "device_type": 0, + "network_data": 0 + }, + 0x02: { + "receiver": 0, + "secure": 0, + "device_type": 1, + "network_data": 0 + }, + 0x0A: { + "receiver": 1, + "secure": 0, + "device_type": 1, + "network_data": 0 + }, + 0x06: { + "receiver": 0, + "secure": 1, + "device_type": 1, + "network_data": 0 + }, + 0x0E: { + "receiver": 1, + "secure": 1, + "device_type": 1, + "network_data": 0 + }, + 0x01: { + "receiver": 0, + "secure": 0, + "device_type": 0, + "network_data": 1 + }, + 0x09: { + "receiver": 1, + "secure": 0, + "device_type": 0, + "network_data": 1 + }, + 0x05: { + "receiver": 0, + "secure": 1, + "device_type": 0, + "network_data": 1 + }, + 0x0D: { + "receiver": 1, + "secure": 1, + "device_type": 0, + "network_data": 1 + }, + 0x03: { + "receiver": 0, + "secure": 0, + "device_type": 1, + "network_data": 1 + }, + 0x0B: { + "receiver": 1, + "secure": 0, + "device_type": 1, + "network_data": 1 + }, + 0x07: { + "receiver": 0, + "secure": 1, + "device_type": 1, + "network_data": 1 + }, + 0x0F: { + "receiver": 1, + "secure": 1, + "device_type": 1, + "network_data": 1 + } } @@ -146,10 +226,22 @@ def any_leader_router_id(): scan_mask_map = { - 0x00: {"router": 0, "end_device": 0}, - 0x40: {"router": 0, "end_device": 1}, - 0x80: {"router": 1, "end_device": 0}, - 0xC0: {"router": 1, "end_device": 1}, + 0x00: { + "router": 0, + "end_device": 0 + }, + 0x40: { + "router": 0, + "end_device": 1 + }, + 0x80: { + "router": 1, + "end_device": 0 + }, + 0xC0: { + "router": 1, + "end_device": 1 + }, } @@ -311,7 +403,8 @@ class TestSourceAddress(unittest.TestCase): class TestSourceAddressFactory(unittest.TestCase): - def test_should_create_SourceAddress_from_bytearray_when_parse_method_is_called(self): + def test_should_create_SourceAddress_from_bytearray_when_parse_method_is_called( + self): # GIVEN address = any_address() @@ -329,11 +422,13 @@ class TestSourceAddressFactory(unittest.TestCase): class TestMode(unittest.TestCase): - def test_should_return_receiver_value_when_receiver_property_is_called(self): + def test_should_return_receiver_value_when_receiver_property_is_called( + self): # GIVEN receiver = any_receiver() - mode = mle.Mode(receiver, any_secure(), any_device_type(), any_network_data()) + mode = mle.Mode(receiver, any_secure(), any_device_type(), + any_network_data()) # WHEN actual_receiver = mode.receiver @@ -345,7 +440,8 @@ class TestMode(unittest.TestCase): # GIVEN secure = any_secure() - mode = mle.Mode(any_receiver(), secure, any_device_type(), any_network_data()) + mode = mle.Mode(any_receiver(), secure, any_device_type(), + any_network_data()) # WHEN actual_secure = mode.secure @@ -353,11 +449,13 @@ class TestMode(unittest.TestCase): # THEN self.assertEqual(secure, actual_secure) - def test_should_return_device_type_value_when_device_type_property_is_called(self): + def test_should_return_device_type_value_when_device_type_property_is_called( + self): # GIVEN device_type = any_device_type() - mode = mle.Mode(any_receiver(), any_secure(), device_type, any_network_data()) + mode = mle.Mode(any_receiver(), any_secure(), device_type, + any_network_data()) # WHEN actual_device_type = mode.device_type @@ -365,11 +463,13 @@ class TestMode(unittest.TestCase): # THEN self.assertEqual(device_type, actual_device_type) - def test_should_return_network_data_value_when_network_data_property_is_called(self): + def test_should_return_network_data_value_when_network_data_property_is_called( + self): # GIVEN network_data = any_network_data() - mode = mle.Mode(any_receiver(), any_secure(), any_device_type(), network_data) + mode = mle.Mode(any_receiver(), any_secure(), any_device_type(), + network_data) # WHEN actual_network_data = mode.network_data @@ -380,7 +480,8 @@ class TestMode(unittest.TestCase): class TestModeFactory(unittest.TestCase): - def test_should_create_Mode_from_bytearray_when_parse_method_is_called(self): + def test_should_create_Mode_from_bytearray_when_parse_method_is_called( + self): # GIVEN mode = any_mode() @@ -396,7 +497,8 @@ class TestModeFactory(unittest.TestCase): self.assertEqual(mode_map[mode]["receiver"], actual_mode.receiver) self.assertEqual(mode_map[mode]["secure"], actual_mode.secure) self.assertEqual(mode_map[mode]["device_type"], actual_mode.device_type) - self.assertEqual(mode_map[mode]["network_data"], actual_mode.network_data) + self.assertEqual(mode_map[mode]["network_data"], + actual_mode.network_data) class TestTimeout(unittest.TestCase): @@ -416,7 +518,8 @@ class TestTimeout(unittest.TestCase): class TestTimeoutFactory(unittest.TestCase): - def test_should_create_Timeout_from_bytearray_when_parse_method_is_called(self): + def test_should_create_Timeout_from_bytearray_when_parse_method_is_called( + self): # GIVEN timeout = any_timeout() @@ -434,7 +537,8 @@ class TestTimeoutFactory(unittest.TestCase): class TestChallenge(unittest.TestCase): - def test_should_return_challenge_value_when_challenge_property_is_called(self): + def test_should_return_challenge_value_when_challenge_property_is_called( + self): # GIVEN challenge = any_challenge() @@ -449,7 +553,8 @@ class TestChallenge(unittest.TestCase): class TestChallengeFactory(unittest.TestCase): - def test_should_create_Challenge_from_bytearray_when_parse_method_is_called(self): + def test_should_create_Challenge_from_bytearray_when_parse_method_is_called( + self): # GIVEN challenge = any_challenge() @@ -467,7 +572,8 @@ class TestChallengeFactory(unittest.TestCase): class TestResponse(unittest.TestCase): - def test_should_return_response_value_when_response_property_is_called(self): + def test_should_return_response_value_when_response_property_is_called( + self): # GIVEN response = any_response() @@ -482,7 +588,8 @@ class TestResponse(unittest.TestCase): class TestResponseFactory(unittest.TestCase): - def test_should_create_Challenge_from_bytearray_when_parse_method_is_called(self): + def test_should_create_Challenge_from_bytearray_when_parse_method_is_called( + self): # GIVEN response = any_response() @@ -500,22 +607,26 @@ class TestResponseFactory(unittest.TestCase): class TestLinkLayerFrameCounter(unittest.TestCase): - def test_should_return_frame_counter_value_when_frame_counter_property_is_called(self): + def test_should_return_frame_counter_value_when_frame_counter_property_is_called( + self): # GIVEN link_layer_frame_counter = any_link_layer_frame_counter() - link_layer_frame_counter_obj = mle.LinkLayerFrameCounter(link_layer_frame_counter) + link_layer_frame_counter_obj = mle.LinkLayerFrameCounter( + link_layer_frame_counter) # WHEN actual_link_layer_frame_counter = link_layer_frame_counter_obj.frame_counter # THEN - self.assertEqual(link_layer_frame_counter, actual_link_layer_frame_counter) + self.assertEqual(link_layer_frame_counter, + actual_link_layer_frame_counter) class TestLinkLayerFrameCounterFactory(unittest.TestCase): - def test_should_create_LinkLayerFrameCounter_from_bytearray_when_parse_method_is_called(self): + def test_should_create_LinkLayerFrameCounter_from_bytearray_when_parse_method_is_called( + self): # GIVEN link_layer_frame_counter = any_link_layer_frame_counter() @@ -524,16 +635,21 @@ class TestLinkLayerFrameCounterFactory(unittest.TestCase): data = struct.pack(">I", link_layer_frame_counter) # WHEN - actual_link_layer_frame_counter = factory.parse(io.BytesIO(data), dict()) + actual_link_layer_frame_counter = factory.parse(io.BytesIO(data), + dict()) # THEN - self.assertTrue(isinstance(actual_link_layer_frame_counter, mle.LinkLayerFrameCounter)) - self.assertEqual(link_layer_frame_counter, actual_link_layer_frame_counter.frame_counter) + self.assertTrue( + isinstance(actual_link_layer_frame_counter, + mle.LinkLayerFrameCounter)) + self.assertEqual(link_layer_frame_counter, + actual_link_layer_frame_counter.frame_counter) class TestMleFrameCounter(unittest.TestCase): - def test_should_return_frame_counter_value_when_frame_counter_property_is_called(self): + def test_should_return_frame_counter_value_when_frame_counter_property_is_called( + self): # GIVEN mle_frame_counter = any_mle_frame_counter() @@ -548,7 +664,8 @@ class TestMleFrameCounter(unittest.TestCase): class TestMleFrameCounterFactory(unittest.TestCase): - def test_should_create_MleFrameCounter_from_bytearray_when_parse_method_is_called(self): + def test_should_create_MleFrameCounter_from_bytearray_when_parse_method_is_called( + self): # GIVEN mle_frame_counter = any_mle_frame_counter() @@ -560,8 +677,10 @@ class TestMleFrameCounterFactory(unittest.TestCase): actual_mle_frame_counter = factory.parse(io.BytesIO(data), dict()) # THEN - self.assertTrue(isinstance(actual_mle_frame_counter, mle.MleFrameCounter)) - self.assertEqual(mle_frame_counter, actual_mle_frame_counter.frame_counter) + self.assertTrue( + isinstance(actual_mle_frame_counter, mle.MleFrameCounter)) + self.assertEqual(mle_frame_counter, + actual_mle_frame_counter.frame_counter) class TestLinkQualityAndRouteData(unittest.TestCase): @@ -605,7 +724,8 @@ class TestLinkQualityAndRouteData(unittest.TestCase): class TestLinkQualityAndRouteDataFactory(unittest.TestCase): - def test_should_create_LinkQualityAndRouteData_from_well_known_byte_when_parse_method_is_called(self): + def test_should_create_LinkQualityAndRouteData_from_well_known_byte_when_parse_method_is_called( + self): # GIVEN factory = mle.LinkQualityAndRouteDataFactory() @@ -619,7 +739,8 @@ class TestLinkQualityAndRouteDataFactory(unittest.TestCase): self.assertEqual(2, actual_lqrd.input) self.assertEqual(6, actual_lqrd.route) - def test_should_create_LinkQualityAndRouteData_from_bytearray_when_parse_method_is_called(self): + def test_should_create_LinkQualityAndRouteData_from_bytearray_when_parse_method_is_called( + self): # GIVEN output = any_output() _input = any_input() @@ -643,11 +764,13 @@ class TestLinkQualityAndRouteDataFactory(unittest.TestCase): class TestRoute64(unittest.TestCase): - def test_should_return_id_sequence_value_when_id_sequence_property_is_called(self): + def test_should_return_id_sequence_value_when_id_sequence_property_is_called( + self): # GIVEN id_sequence = any_id_sequence() - route64_obj = mle.Route64(id_sequence, any_router_id_mask(), any_link_quality_and_route_data()) + route64_obj = mle.Route64(id_sequence, any_router_id_mask(), + any_link_quality_and_route_data()) # WHEN actual_id_sequence = route64_obj.id_sequence @@ -655,11 +778,13 @@ class TestRoute64(unittest.TestCase): # THEN self.assertEqual(id_sequence, actual_id_sequence) - def test_should_return_router_id_mask_value_when_router_id_mask_property_is_called(self): + def test_should_return_router_id_mask_value_when_router_id_mask_property_is_called( + self): # GIVEN router_id_mask = any_router_id_mask() - route64_obj = mle.Route64(any_id_sequence(), router_id_mask, any_link_quality_and_route_data()) + route64_obj = mle.Route64(any_id_sequence(), router_id_mask, + any_link_quality_and_route_data()) # WHEN actual_router_id_mask = route64_obj.router_id_mask @@ -667,22 +792,26 @@ class TestRoute64(unittest.TestCase): # THEN self.assertEqual(router_id_mask, actual_router_id_mask) - def test_should_return_link_quality_and_route_data_value_when_link_quality_and_route_data_property_is_called(self): + def test_should_return_link_quality_and_route_data_value_when_link_quality_and_route_data_property_is_called( + self): # GIVEN link_quality_and_route_data = any_link_quality_and_route_data() - route64_obj = mle.Route64(any_id_sequence(), any_router_id_mask(), link_quality_and_route_data) + route64_obj = mle.Route64(any_id_sequence(), any_router_id_mask(), + link_quality_and_route_data) # WHEN actual_link_quality_and_route_data = route64_obj.link_quality_and_route_data # THEN - self.assertEqual(link_quality_and_route_data, actual_link_quality_and_route_data) + self.assertEqual(link_quality_and_route_data, + actual_link_quality_and_route_data) class TestRoute64Factory(unittest.TestCase): - def test_should_create_Route64_from_bytearray_when_parse_method_is_called(self): + def test_should_create_Route64_from_bytearray_when_parse_method_is_called( + self): # GIVEN class DummyLQRDFactory: @@ -696,11 +825,13 @@ class TestRoute64Factory(unittest.TestCase): for i in range(64): router_count += (router_id_mask >> i) & 0x01 - link_quality_and_route_data = any_link_quality_and_route_data(router_count) + link_quality_and_route_data = any_link_quality_and_route_data( + router_count) factory = mle.Route64Factory(DummyLQRDFactory()) - data = bytearray([id_sequence]) + struct.pack(">Q", router_id_mask) + bytearray(link_quality_and_route_data) + data = bytearray([id_sequence]) + struct.pack( + ">Q", router_id_mask) + bytearray(link_quality_and_route_data) # WHEN actual_route64 = factory.parse(io.BytesIO(data), dict()) @@ -709,7 +840,8 @@ class TestRoute64Factory(unittest.TestCase): self.assertTrue(isinstance(actual_route64, mle.Route64)) self.assertEqual(id_sequence, actual_route64.id_sequence) self.assertEqual(router_id_mask, actual_route64.router_id_mask) - self.assertEqual([b for b in link_quality_and_route_data], actual_route64.link_quality_and_route_data) + self.assertEqual([b for b in link_quality_and_route_data], + actual_route64.link_quality_and_route_data) class TestAddress16(unittest.TestCase): @@ -729,7 +861,8 @@ class TestAddress16(unittest.TestCase): class TestAddress16Factory(unittest.TestCase): - def test_should_create_Address16_from_bytearray_when_parse_method_is_called(self): + def test_should_create_Address16_from_bytearray_when_parse_method_is_called( + self): # GIVEN address = any_address() @@ -747,12 +880,15 @@ class TestAddress16Factory(unittest.TestCase): class TestLeaderData(unittest.TestCase): - def test_should_return_partition_id_value_when_partition_id_property_is_called(self): + def test_should_return_partition_id_value_when_partition_id_property_is_called( + self): # GIVEN partition_id = any_partition_id() - leader_data = mle.LeaderData(partition_id, any_weighting(), any_data_version(), - any_stable_data_version(), any_leader_router_id()) + leader_data = mle.LeaderData(partition_id, any_weighting(), + any_data_version(), + any_stable_data_version(), + any_leader_router_id()) # WHEN actual_partition_id = leader_data.partition_id @@ -760,12 +896,15 @@ class TestLeaderData(unittest.TestCase): # THEN self.assertEqual(partition_id, actual_partition_id) - def test_should_return_weighting_value_when_weighting_property_is_called(self): + def test_should_return_weighting_value_when_weighting_property_is_called( + self): # GIVEN weighting = any_weighting() - leader_data = mle.LeaderData(any_partition_id(), weighting, any_data_version(), - any_stable_data_version(), any_leader_router_id()) + leader_data = mle.LeaderData(any_partition_id(), weighting, + any_data_version(), + any_stable_data_version(), + any_leader_router_id()) # WHEN actual_weighting = leader_data.weighting @@ -773,12 +912,14 @@ class TestLeaderData(unittest.TestCase): # THEN self.assertEqual(weighting, actual_weighting) - def test_should_return_data_version_value_when_data_version_property_is_called(self): + def test_should_return_data_version_value_when_data_version_property_is_called( + self): # GIVEN data_version = any_data_version() - leader_data = mle.LeaderData(any_partition_id(), any_weighting(), data_version, - any_stable_data_version(), any_leader_router_id()) + leader_data = mle.LeaderData(any_partition_id(), any_weighting(), + data_version, any_stable_data_version(), + any_leader_router_id()) # WHEN actual_data_version = leader_data.data_version @@ -786,12 +927,14 @@ class TestLeaderData(unittest.TestCase): # THEN self.assertEqual(data_version, actual_data_version) - def test_should_return_stable_data_version_value_when_stable_data_version_property_is_called(self): + def test_should_return_stable_data_version_value_when_stable_data_version_property_is_called( + self): # GIVEN stable_data_version = any_stable_data_version() - leader_data = mle.LeaderData(any_partition_id(), any_weighting(), any_data_version(), - stable_data_version, any_leader_router_id()) + leader_data = mle.LeaderData(any_partition_id(), any_weighting(), + any_data_version(), stable_data_version, + any_leader_router_id()) # WHEN actual_stable_data_version = leader_data.stable_data_version @@ -799,12 +942,15 @@ class TestLeaderData(unittest.TestCase): # THEN self.assertEqual(stable_data_version, actual_stable_data_version) - def test_should_return_leader_router_id_value_when_leader_router_id_property_is_called(self): + def test_should_return_leader_router_id_value_when_leader_router_id_property_is_called( + self): # GIVEN leader_router_id = any_leader_router_id() - leader_data = mle.LeaderData(any_partition_id(), any_weighting(), any_data_version(), - any_stable_data_version(), leader_router_id) + leader_data = mle.LeaderData(any_partition_id(), any_weighting(), + any_data_version(), + any_stable_data_version(), + leader_router_id) # WHEN actual_leader_router_id = leader_data.leader_router_id @@ -815,7 +961,8 @@ class TestLeaderData(unittest.TestCase): class TestLeaderDataFactory(unittest.TestCase): - def test_should_create_Address16_from_bytearray_when_parse_method_is_called(self): + def test_should_create_Address16_from_bytearray_when_parse_method_is_called( + self): # GIVEN partition_id = any_partition_id() weighting = any_weighting() @@ -836,7 +983,8 @@ class TestLeaderDataFactory(unittest.TestCase): self.assertEqual(partition_id, actual_leader_data.partition_id) self.assertEqual(weighting, actual_leader_data.weighting) self.assertEqual(data_version, actual_leader_data.data_version) - self.assertEqual(stable_data_version, actual_leader_data.stable_data_version) + self.assertEqual(stable_data_version, + actual_leader_data.stable_data_version) self.assertEqual(leader_router_id, actual_leader_data.leader_router_id) @@ -857,7 +1005,8 @@ class TestNetworkData(unittest.TestCase): class TestNetworkDataFactory(unittest.TestCase): - def test_should_create_TlvRequest_from_bytearray_when_parse_method_is_called(self): + def test_should_create_TlvRequest_from_bytearray_when_parse_method_is_called( + self): # GIVEN class DummyNetworkTlvsFactory: @@ -895,7 +1044,8 @@ class TestTlvRequest(unittest.TestCase): class TestTlvRequestFactory(unittest.TestCase): - def test_should_create_TlvRequest_from_bytearray_when_parse_method_is_called(self): + def test_should_create_TlvRequest_from_bytearray_when_parse_method_is_called( + self): # GIVEN tlvs = any_tlvs() @@ -925,7 +1075,8 @@ class TestScanMask(unittest.TestCase): # THEN self.assertEqual(router, actual_router) - def test_should_return_end_device_value_when_end_device_property_is_called(self): + def test_should_return_end_device_value_when_end_device_property_is_called( + self): # GIVEN end_device = any_scan_mask_end_device() @@ -940,7 +1091,8 @@ class TestScanMask(unittest.TestCase): class TestScanMaskFactory(unittest.TestCase): - def test_should_create_ScanMask_from_bytearray_when_parse_method_is_called(self): + def test_should_create_ScanMask_from_bytearray_when_parse_method_is_called( + self): # GIVEN scan_mask = any_scan_mask() @@ -953,8 +1105,10 @@ class TestScanMaskFactory(unittest.TestCase): # THEN self.assertTrue(isinstance(actual_scan_mask, mle.ScanMask)) - self.assertEqual(scan_mask_map[scan_mask]["router"], actual_scan_mask.router) - self.assertEqual(scan_mask_map[scan_mask]["end_device"], actual_scan_mask.end_device) + self.assertEqual(scan_mask_map[scan_mask]["router"], + actual_scan_mask.router) + self.assertEqual(scan_mask_map[scan_mask]["end_device"], + actual_scan_mask.end_device) class TestConnectivity(unittest.TestCase): @@ -963,8 +1117,7 @@ class TestConnectivity(unittest.TestCase): # GIVEN pp = any_pp() - connectivity_obj = mle.Connectivity(pp, - any_link_quality_3(), + connectivity_obj = mle.Connectivity(pp, any_link_quality_3(), any_link_quality_2(), any_link_quality_1(), any_leader_cost(), @@ -979,12 +1132,12 @@ class TestConnectivity(unittest.TestCase): # THEN self.assertEqual(pp, actual_pp) - def test_should_return_link_quality_3_value_when_link_quality_3_property_is_called(self): + def test_should_return_link_quality_3_value_when_link_quality_3_property_is_called( + self): # GIVEN link_quality_3 = any_link_quality_3() - connectivity_obj = mle.Connectivity(any_pp(), - link_quality_3, + connectivity_obj = mle.Connectivity(any_pp(), link_quality_3, any_link_quality_2(), any_link_quality_1(), any_leader_cost(), @@ -999,12 +1152,12 @@ class TestConnectivity(unittest.TestCase): # THEN self.assertEqual(link_quality_3, actual_link_quality_3) - def test_should_return_link_quality_2_value_when_link_quality_2_property_is_called(self): + def test_should_return_link_quality_2_value_when_link_quality_2_property_is_called( + self): # GIVEN link_quality_2 = any_link_quality_2() - connectivity_obj = mle.Connectivity(any_pp(), - any_link_quality_3(), + connectivity_obj = mle.Connectivity(any_pp(), any_link_quality_3(), link_quality_2, any_link_quality_1(), any_leader_cost(), @@ -1019,15 +1172,14 @@ class TestConnectivity(unittest.TestCase): # THEN self.assertEqual(link_quality_2, actual_link_quality_2) - def test_should_return_link_quality_1_value_when_link_quality_1_property_is_called(self): + def test_should_return_link_quality_1_value_when_link_quality_1_property_is_called( + self): # GIVEN link_quality_1 = any_link_quality_1() - connectivity_obj = mle.Connectivity(any_pp(), - any_link_quality_3(), + connectivity_obj = mle.Connectivity(any_pp(), any_link_quality_3(), any_link_quality_2(), - link_quality_1, - any_leader_cost(), + link_quality_1, any_leader_cost(), any_id_sequence(), any_active_routers(), any_sed_buffer_size(), @@ -1039,15 +1191,14 @@ class TestConnectivity(unittest.TestCase): # THEN self.assertEqual(link_quality_1, actual_link_quality_1) - def test_should_return_leader_cost_value_when_leader_cost_property_is_called(self): + def test_should_return_leader_cost_value_when_leader_cost_property_is_called( + self): # GIVEN leader_cost = any_leader_cost() - connectivity_obj = mle.Connectivity(any_pp(), - any_link_quality_3(), + connectivity_obj = mle.Connectivity(any_pp(), any_link_quality_3(), any_link_quality_2(), - any_link_quality_1(), - leader_cost, + any_link_quality_1(), leader_cost, any_id_sequence(), any_active_routers(), any_sed_buffer_size(), @@ -1059,16 +1210,15 @@ class TestConnectivity(unittest.TestCase): # THEN self.assertEqual(leader_cost, actual_leader_cost) - def test_should_return_id_sequence_value_when_id_sequence_property_is_called(self): + def test_should_return_id_sequence_value_when_id_sequence_property_is_called( + self): # GIVEN id_sequence = any_id_sequence() - connectivity_obj = mle.Connectivity(any_pp(), - any_link_quality_3(), + connectivity_obj = mle.Connectivity(any_pp(), any_link_quality_3(), any_link_quality_2(), any_link_quality_1(), - any_leader_cost(), - id_sequence, + any_leader_cost(), id_sequence, any_active_routers(), any_sed_buffer_size(), any_sed_datagram_count()) @@ -1079,17 +1229,16 @@ class TestConnectivity(unittest.TestCase): # THEN self.assertEqual(id_sequence, actual_id_sequence) - def test_should_return_active_routers_value_when_active_routers_property_is_called(self): + def test_should_return_active_routers_value_when_active_routers_property_is_called( + self): # GIVEN active_routers = any_active_routers() - connectivity_obj = mle.Connectivity(any_pp(), - any_link_quality_3(), + connectivity_obj = mle.Connectivity(any_pp(), any_link_quality_3(), any_link_quality_2(), any_link_quality_1(), any_leader_cost(), - any_id_sequence(), - active_routers, + any_id_sequence(), active_routers, any_sed_buffer_size(), any_sed_datagram_count()) @@ -1099,12 +1248,12 @@ class TestConnectivity(unittest.TestCase): # THEN self.assertEqual(active_routers, actual_active_routers) - def test_should_return_sed_buffer_size_value_when_sed_buffer_size_property_is_called(self): + def test_should_return_sed_buffer_size_value_when_sed_buffer_size_property_is_called( + self): # GIVEN sed_buffer_size = any_sed_buffer_size() - connectivity_obj = mle.Connectivity(any_pp(), - any_link_quality_3(), + connectivity_obj = mle.Connectivity(any_pp(), any_link_quality_3(), any_link_quality_2(), any_link_quality_1(), any_leader_cost(), @@ -1119,12 +1268,12 @@ class TestConnectivity(unittest.TestCase): # THEN self.assertEqual(sed_buffer_size, actual_sed_buffer_size) - def test_should_return_sed_datagram_count_value_when_sed_datagram_count_property_is_called(self): + def test_should_return_sed_datagram_count_value_when_sed_datagram_count_property_is_called( + self): # GIVEN sed_datagram_count = any_sed_datagram_count() - connectivity_obj = mle.Connectivity(any_pp(), - any_link_quality_3(), + connectivity_obj = mle.Connectivity(any_pp(), any_link_quality_3(), any_link_quality_2(), any_link_quality_1(), any_leader_cost(), @@ -1142,7 +1291,8 @@ class TestConnectivity(unittest.TestCase): class TestConnectivityFactory(unittest.TestCase): - def test_should_create_Connectivity_from_bytearray_when_parse_method_is_called(self): + def test_should_create_Connectivity_from_bytearray_when_parse_method_is_called( + self): # GIVEN pp = any_pp() link_quality_3 = any_link_quality_3() @@ -1156,8 +1306,11 @@ class TestConnectivityFactory(unittest.TestCase): factory = mle.ConnectivityFactory() - data = bytearray([pp, link_quality_3, link_quality_2, link_quality_1, leader_cost, id_sequence, - active_routers]) + struct.pack(">H", sed_buffer_size) + bytearray([sed_datagram_count]) + data = bytearray([ + pp, link_quality_3, link_quality_2, link_quality_1, leader_cost, + id_sequence, active_routers + ]) + struct.pack(">H", sed_buffer_size) + bytearray( + [sed_datagram_count]) # WHEN actual_connectivity = factory.parse(io.BytesIO(data), dict()) @@ -1172,9 +1325,11 @@ class TestConnectivityFactory(unittest.TestCase): self.assertEqual(id_sequence, actual_connectivity.id_sequence) self.assertEqual(active_routers, actual_connectivity.active_routers) self.assertEqual(sed_buffer_size, actual_connectivity.sed_buffer_size) - self.assertEqual(sed_datagram_count, actual_connectivity.sed_datagram_count) + self.assertEqual(sed_datagram_count, + actual_connectivity.sed_datagram_count) - def test_should_create_Connectivity_without_sed_data_when_parse_method_is_called(self): + def test_should_create_Connectivity_without_sed_data_when_parse_method_is_called( + self): # GIVEN pp = any_pp() link_quality_3 = any_link_quality_3() @@ -1188,8 +1343,10 @@ class TestConnectivityFactory(unittest.TestCase): factory = mle.ConnectivityFactory() - data = bytearray([pp, link_quality_3, link_quality_2, link_quality_1, leader_cost, id_sequence, - active_routers]) + data = bytearray([ + pp, link_quality_3, link_quality_2, link_quality_1, leader_cost, + id_sequence, active_routers + ]) # WHEN actual_connectivity = factory.parse(io.BytesIO(data), dict()) @@ -1209,7 +1366,8 @@ class TestConnectivityFactory(unittest.TestCase): class TestLinkMargin(unittest.TestCase): - def test_should_return_link_margin_value_when_link_margin_property_is_called(self): + def test_should_return_link_margin_value_when_link_margin_property_is_called( + self): # GIVEN link_margin = any_link_margin() @@ -1224,7 +1382,8 @@ class TestLinkMargin(unittest.TestCase): class TestLinkMarginFactory(unittest.TestCase): - def test_should_create_LinkMargin_from_bytearray_when_parse_method_is_called(self): + def test_should_create_LinkMargin_from_bytearray_when_parse_method_is_called( + self): # GIVEN link_margin = any_link_margin() @@ -1257,7 +1416,8 @@ class TestStatus(unittest.TestCase): class TestStatusFactory(unittest.TestCase): - def test_should_create_Status_from_bytearray_when_parse_method_is_called(self): + def test_should_create_Status_from_bytearray_when_parse_method_is_called( + self): # GIVEN status = any_status() @@ -1290,7 +1450,8 @@ class TestVersion(unittest.TestCase): class TestVersionFactory(unittest.TestCase): - def test_should_create_Version_from_bytearray_when_parse_method_is_called(self): + def test_should_create_Version_from_bytearray_when_parse_method_is_called( + self): # GIVEN version = any_version() @@ -1308,7 +1469,8 @@ class TestVersionFactory(unittest.TestCase): class TestAddressRegistrationFull(unittest.TestCase): - def test_should_return_ipv6_address_value_when_ipv6_address_property_is_called(self): + def test_should_return_ipv6_address_value_when_ipv6_address_property_is_called( + self): # GIVEN ipv6_address = any_ipv6_address() @@ -1323,7 +1485,8 @@ class TestAddressRegistrationFull(unittest.TestCase): class TestAddressRegistrationFullFactory(unittest.TestCase): - def test_should_create_AddressFull_from_bytearray_when_parse_method_is_called(self): + def test_should_create_AddressFull_from_bytearray_when_parse_method_is_called( + self): # GIVEN ipv6_address = any_ipv6_address() @@ -1368,7 +1531,8 @@ class TestAddressRegistrationCompressed(unittest.TestCase): class TestAddressRegistrationCompressedFactory(unittest.TestCase): - def test_should_create_AddressRegistrationCompressed_from_bytearray_when_parse_method_is_called(self): + def test_should_create_AddressRegistrationCompressed_from_bytearray_when_parse_method_is_called( + self): # GIVEN cid = any_cid() iid = any_iid() @@ -1381,14 +1545,16 @@ class TestAddressRegistrationCompressedFactory(unittest.TestCase): actual_addr_reg_compressed = factory.parse(io.BytesIO(data), dict()) # THEN - self.assertTrue(isinstance(actual_addr_reg_compressed, mle.AddressCompressed)) + self.assertTrue( + isinstance(actual_addr_reg_compressed, mle.AddressCompressed)) self.assertEqual(cid, actual_addr_reg_compressed.cid) self.assertEqual(iid, actual_addr_reg_compressed.iid) class TestAddressRegistration(unittest.TestCase): - def test_should_return_addresses_value_when_addresses_property_is_called(self): + def test_should_return_addresses_value_when_addresses_property_is_called( + self): # GIVEN addresses = any_addresses() @@ -1403,7 +1569,8 @@ class TestAddressRegistration(unittest.TestCase): class TestAddressRegistrationFactory(unittest.TestCase): - def test_should_create_AddressRegistration_from_bytearray_when_parse_method_is_called(self): + def test_should_create_AddressRegistration_from_bytearray_when_parse_method_is_called( + self): # GIVEN cid = any_cid() iid = any_iid() @@ -1426,12 +1593,14 @@ class TestAddressRegistrationFactory(unittest.TestCase): self.assertTrue(isinstance(actual_addr_reg, mle.AddressRegistration)) self.assertEqual(addresses[0].cid, actual_addr_reg.addresses[0].cid) self.assertEqual(addresses[0].iid, actual_addr_reg.addresses[0].iid) - self.assertEqual(addresses[1].ipv6_address, actual_addr_reg.addresses[1].ipv6_address) + self.assertEqual(addresses[1].ipv6_address, + actual_addr_reg.addresses[1].ipv6_address) class TestChannel(unittest.TestCase): - def test_should_return_channel_page_value_when_channel_page_property_is_called(self): + def test_should_return_channel_page_value_when_channel_page_property_is_called( + self): # GIVEN channel_page = any_channel_page() @@ -1458,7 +1627,8 @@ class TestChannel(unittest.TestCase): class TestChannelFactory(unittest.TestCase): - def test_should_create_Channel_from_bytearray_when_parse_method_is_called(self): + def test_should_create_Channel_from_bytearray_when_parse_method_is_called( + self): # GIVEN channel_page = any_channel_page() channel = any_channel() @@ -1493,7 +1663,8 @@ class TestPanId(unittest.TestCase): class TestPanIdFactory(unittest.TestCase): - def test_should_create_PanId_from_bytearray_when_parse_method_is_called(self): + def test_should_create_PanId_from_bytearray_when_parse_method_is_called( + self): # GIVEN pan_id = any_pan_id() @@ -1511,11 +1682,14 @@ class TestPanIdFactory(unittest.TestCase): class TestActiveTimestamp(unittest.TestCase): - def test_should_return_timestamp_seconds_value_when_timestamp_seconds_property_is_called(self): + def test_should_return_timestamp_seconds_value_when_timestamp_seconds_property_is_called( + self): # GIVEN timestamp_seconds = any_timestamp_seconds() - active_timestamp_obj = mle.ActiveTimestamp(timestamp_seconds, any_timestamp_ticks(), any_u()) + active_timestamp_obj = mle.ActiveTimestamp(timestamp_seconds, + any_timestamp_ticks(), + any_u()) # WHEN actual_timestamp_seconds = active_timestamp_obj.timestamp_seconds @@ -1523,11 +1697,13 @@ class TestActiveTimestamp(unittest.TestCase): # THEN self.assertEqual(timestamp_seconds, actual_timestamp_seconds) - def test_should_return_timestamp_ticks_value_when_timestamp_ticks_property_is_called(self): + def test_should_return_timestamp_ticks_value_when_timestamp_ticks_property_is_called( + self): # GIVEN timestamp_ticks = any_timestamp_ticks() - active_timestamp_obj = mle.ActiveTimestamp(any_timestamp_seconds(), timestamp_ticks, any_u()) + active_timestamp_obj = mle.ActiveTimestamp(any_timestamp_seconds(), + timestamp_ticks, any_u()) # WHEN actual_timestamp_ticks = active_timestamp_obj.timestamp_ticks @@ -1539,7 +1715,8 @@ class TestActiveTimestamp(unittest.TestCase): # GIVEN u = any_u() - active_timestamp_obj = mle.ActiveTimestamp(any_timestamp_seconds(), any_timestamp_ticks(), u) + active_timestamp_obj = mle.ActiveTimestamp(any_timestamp_seconds(), + any_timestamp_ticks(), u) # WHEN actual_u = active_timestamp_obj.u @@ -1550,7 +1727,8 @@ class TestActiveTimestamp(unittest.TestCase): class TestActiveTimestampFactory(unittest.TestCase): - def test_should_create_ActiveTimestamp_from_bytearray_when_parse_method_is_called(self): + def test_should_create_ActiveTimestamp_from_bytearray_when_parse_method_is_called( + self): # GIVEN timestamp_seconds = any_timestamp_seconds() timestamp_ticks = any_timestamp_ticks() @@ -1558,7 +1736,8 @@ class TestActiveTimestampFactory(unittest.TestCase): factory = mle.ActiveTimestampFactory() - data = struct.pack(">Q", timestamp_seconds)[2:] + struct.pack(">H", (timestamp_ticks << 1) | u) + data = struct.pack(">Q", timestamp_seconds)[2:] + struct.pack( + ">H", (timestamp_ticks << 1) | u) # WHEN active_timestamp = factory.parse(io.BytesIO(data), dict()) @@ -1572,11 +1751,14 @@ class TestActiveTimestampFactory(unittest.TestCase): class TestPendingTimestamp(unittest.TestCase): - def test_should_return_timestamp_seconds_value_when_timestamp_seconds_property_is_called(self): + def test_should_return_timestamp_seconds_value_when_timestamp_seconds_property_is_called( + self): # GIVEN timestamp_seconds = any_timestamp_seconds() - pending_timestamp_obj = mle.PendingTimestamp(timestamp_seconds, any_timestamp_ticks(), any_u()) + pending_timestamp_obj = mle.PendingTimestamp(timestamp_seconds, + any_timestamp_ticks(), + any_u()) # WHEN actual_timestamp_seconds = pending_timestamp_obj.timestamp_seconds @@ -1584,11 +1766,13 @@ class TestPendingTimestamp(unittest.TestCase): # THEN self.assertEqual(timestamp_seconds, actual_timestamp_seconds) - def test_should_return_timestamp_ticks_value_when_timestamp_ticks_property_is_called(self): + def test_should_return_timestamp_ticks_value_when_timestamp_ticks_property_is_called( + self): # GIVEN timestamp_ticks = any_timestamp_ticks() - pending_timestamp_obj = mle.PendingTimestamp(any_timestamp_seconds(), timestamp_ticks, any_u()) + pending_timestamp_obj = mle.PendingTimestamp(any_timestamp_seconds(), + timestamp_ticks, any_u()) # WHEN actual_timestamp_ticks = pending_timestamp_obj.timestamp_ticks @@ -1600,7 +1784,8 @@ class TestPendingTimestamp(unittest.TestCase): # GIVEN u = any_u() - pending_timestamp_obj = mle.PendingTimestamp(any_timestamp_seconds(), any_timestamp_ticks(), u) + pending_timestamp_obj = mle.PendingTimestamp(any_timestamp_seconds(), + any_timestamp_ticks(), u) # WHEN actual_u = pending_timestamp_obj.u @@ -1611,7 +1796,8 @@ class TestPendingTimestamp(unittest.TestCase): class TestPendingTimestampFactory(unittest.TestCase): - def test_should_create_PendingTimestamp_from_bytearray_when_parse_method_is_called(self): + def test_should_create_PendingTimestamp_from_bytearray_when_parse_method_is_called( + self): # GIVEN timestamp_seconds = any_timestamp_seconds() timestamp_ticks = any_timestamp_ticks() @@ -1619,7 +1805,8 @@ class TestPendingTimestampFactory(unittest.TestCase): factory = mle.PendingTimestampFactory() - data = struct.pack(">Q", timestamp_seconds)[2:] + struct.pack(">H", (timestamp_ticks << 1) | u) + data = struct.pack(">Q", timestamp_seconds)[2:] + struct.pack( + ">H", (timestamp_ticks << 1) | u) # WHEN pending_timestamp = factory.parse(io.BytesIO(data), dict()) @@ -1633,16 +1820,18 @@ class TestPendingTimestampFactory(unittest.TestCase): class TestMleCommandFactory(unittest.TestCase): - def test_should_create_MleCommand_from_bytearray_when_parse_method_is_called(self): - data = bytearray([0x0b, 0x04, 0x08, 0xa5, 0xf2, 0x9b, 0xde, 0xe3, - 0xd8, 0xbe, 0xb9, 0x05, 0x04, 0x00, 0x00, 0x00, - 0x00, 0x08, 0x04, 0x00, 0x00, 0x00, 0x01, 0x01, - 0x01, 0x0d, 0x02, 0x04, 0x00, 0x00, 0x00, 0xf0, - 0x12, 0x02, 0x00, 0x02, 0x13, 0x09, 0x80, 0x86, - 0xa2, 0x1b, 0x81, 0x6d, 0xb8, 0xb5, 0xe8, 0x0d, - 0x03, 0x0a, 0x0c, 0x09]) + def test_should_create_MleCommand_from_bytearray_when_parse_method_is_called( + self): + data = bytearray([ + 0x0b, 0x04, 0x08, 0xa5, 0xf2, 0x9b, 0xde, 0xe3, 0xd8, 0xbe, 0xb9, + 0x05, 0x04, 0x00, 0x00, 0x00, 0x00, 0x08, 0x04, 0x00, 0x00, 0x00, + 0x01, 0x01, 0x01, 0x0d, 0x02, 0x04, 0x00, 0x00, 0x00, 0xf0, 0x12, + 0x02, 0x00, 0x02, 0x13, 0x09, 0x80, 0x86, 0xa2, 0x1b, 0x81, 0x6d, + 0xb8, 0xb5, 0xe8, 0x0d, 0x03, 0x0a, 0x0c, 0x09 + ]) - factory = mle.MleCommandFactory(config.create_default_mle_tlvs_factories()) + factory = mle.MleCommandFactory( + config.create_default_mle_tlvs_factories()) # WHEN actual_mle_command = factory.parse(io.BytesIO(data), None) @@ -1652,30 +1841,40 @@ class TestMleCommandFactory(unittest.TestCase): self.assertEqual(11, actual_mle_command.type) - self.assertEqual(mle.Response(bytearray([0xa5, 0xf2, 0x9b, 0xde, 0xe3, 0xd8, 0xbe, 0xb9])), - actual_mle_command.tlvs[0]) + self.assertEqual( + mle.Response( + bytearray([0xa5, 0xf2, 0x9b, 0xde, 0xe3, 0xd8, 0xbe, 0xb9])), + actual_mle_command.tlvs[0]) - self.assertEqual(mle.LinkLayerFrameCounter(0), actual_mle_command.tlvs[1]) + self.assertEqual(mle.LinkLayerFrameCounter(0), + actual_mle_command.tlvs[1]) self.assertEqual(mle.MleFrameCounter(1), actual_mle_command.tlvs[2]) - self.assertEqual(mle.Mode(receiver=1, secure=1, device_type=0, network_data=1), - actual_mle_command.tlvs[3]) + self.assertEqual( + mle.Mode(receiver=1, secure=1, device_type=0, network_data=1), + actual_mle_command.tlvs[3]) self.assertEqual(mle.Timeout(240), actual_mle_command.tlvs[4]) self.assertEqual(mle.Version(2), actual_mle_command.tlvs[5]) - self.assertEqual(mle.AddressRegistration(addresses=[ - mle.AddressCompressed(cid=0, iid=bytearray([0x86, 0xa2, 0x1b, 0x81, 0x6d, 0xb8, 0xb5, 0xe8]))]), - actual_mle_command.tlvs[6]) + self.assertEqual( + mle.AddressRegistration(addresses=[ + mle.AddressCompressed( + cid=0, + iid=bytearray( + [0x86, 0xa2, 0x1b, 0x81, 0x6d, 0xb8, 0xb5, 0xe8])) + ]), actual_mle_command.tlvs[6]) - self.assertEqual(mle.TlvRequest(tlvs=[10, 12, 9]), actual_mle_command.tlvs[7]) + self.assertEqual(mle.TlvRequest(tlvs=[10, 12, 9]), + actual_mle_command.tlvs[7]) class TestMleMessageFactory(unittest.TestCase): - def test_should_create_MleMessageSecured_from_bytearray_when_parse_method_is_called(self): + def test_should_create_MleMessageSecured_from_bytearray_when_parse_method_is_called( + self): # GIVEN message_info = common.MessageInfo() message_info.source_ipv6 = "fe80::10cf:d38b:3b61:5558" @@ -1686,17 +1885,18 @@ class TestMleMessageFactory(unittest.TestCase): message_info.destination_mac_address = common.MacAddress.from_eui64( bytearray([0x3a, 0x3e, 0x9e, 0xed, 0x7a, 0x01, 0x36, 0xa5])) - data = bytearray([0x00, 0x15, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x01, 0x14, 0x03, 0xe3, 0x72, 0x50, 0x4f, - 0x8c, 0x5c, 0x42, 0x81, 0x68, 0xe2, 0x11, 0xfc, - 0xf5, 0x8c, 0x62, 0x8e, 0x83, 0x99, 0xe7, 0x26, - 0x86, 0x34, 0x3b, 0xa7, 0x68, 0xc7, 0x93, 0xfb, - 0x72, 0xd9, 0xcc, 0x13, 0x5e, 0x5b, 0x96, 0x0e, - 0xf1, 0x80, 0x03, 0x55, 0x4f, 0x27, 0xc2, 0x96, - 0xf4, 0x9c, 0x65, 0x82, 0x97, 0xcf, 0x97, 0x35, - 0x89, 0xc2]) + data = bytearray([ + 0x00, 0x15, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, + 0x14, 0x03, 0xe3, 0x72, 0x50, 0x4f, 0x8c, 0x5c, 0x42, 0x81, 0x68, + 0xe2, 0x11, 0xfc, 0xf5, 0x8c, 0x62, 0x8e, 0x83, 0x99, 0xe7, 0x26, + 0x86, 0x34, 0x3b, 0xa7, 0x68, 0xc7, 0x93, 0xfb, 0x72, 0xd9, 0xcc, + 0x13, 0x5e, 0x5b, 0x96, 0x0e, 0xf1, 0x80, 0x03, 0x55, 0x4f, 0x27, + 0xc2, 0x96, 0xf4, 0x9c, 0x65, 0x82, 0x97, 0xcf, 0x97, 0x35, 0x89, + 0xc2 + ]) - factory = config.create_default_mle_message_factory(master_key=config.DEFAULT_MASTER_KEY) + factory = config.create_default_mle_message_factory( + master_key=config.DEFAULT_MASTER_KEY) # WHEN actual_mle_message = factory.parse(io.BytesIO(data), message_info) @@ -1706,29 +1906,40 @@ class TestMleMessageFactory(unittest.TestCase): self.assertEqual(11, actual_mle_message.command.type) - self.assertEqual(mle.Response(bytearray([0xa5, 0xf2, 0x9b, 0xde, 0xe3, 0xd8, 0xbe, 0xb9])), - actual_mle_message.command.tlvs[0]) + self.assertEqual( + mle.Response( + bytearray([0xa5, 0xf2, 0x9b, 0xde, 0xe3, 0xd8, 0xbe, 0xb9])), + actual_mle_message.command.tlvs[0]) - self.assertEqual(mle.LinkLayerFrameCounter(0), actual_mle_message.command.tlvs[1]) + self.assertEqual(mle.LinkLayerFrameCounter(0), + actual_mle_message.command.tlvs[1]) - self.assertEqual(mle.MleFrameCounter(1), actual_mle_message.command.tlvs[2]) + self.assertEqual(mle.MleFrameCounter(1), + actual_mle_message.command.tlvs[2]) - self.assertEqual(mle.Mode(receiver=1, secure=1, device_type=0, network_data=1), - actual_mle_message.command.tlvs[3]) + self.assertEqual( + mle.Mode(receiver=1, secure=1, device_type=0, network_data=1), + actual_mle_message.command.tlvs[3]) self.assertEqual(mle.Timeout(240), actual_mle_message.command.tlvs[4]) self.assertEqual(mle.Version(2), actual_mle_message.command.tlvs[5]) - self.assertEqual(mle.AddressRegistration(addresses=[ - mle.AddressCompressed(cid=0, iid=bytearray([0x86, 0xa2, 0x1b, 0x81, 0x6d, 0xb8, 0xb5, 0xe8]))]), - actual_mle_message.command.tlvs[6]) + self.assertEqual( + mle.AddressRegistration(addresses=[ + mle.AddressCompressed( + cid=0, + iid=bytearray( + [0x86, 0xa2, 0x1b, 0x81, 0x6d, 0xb8, 0xb5, 0xe8])) + ]), actual_mle_message.command.tlvs[6]) - self.assertEqual(mle.TlvRequest(tlvs=[10, 12, 9]), actual_mle_message.command.tlvs[7]) + self.assertEqual(mle.TlvRequest(tlvs=[10, 12, 9]), + actual_mle_message.command.tlvs[7]) self.assertEqual(bytearray(data[-4:]), actual_mle_message.mic) - def test_should_create_MleMessageSecured_with_MLE_Data_Response_from_bytearray_when_parse_method_is_called(self): + def test_should_create_MleMessageSecured_with_MLE_Data_Response_from_bytearray_when_parse_method_is_called( + self): # GIVEN message_info = common.MessageInfo() message_info.source_ipv6 = "fe80::241c:b11b:7b62:caf1" @@ -1739,15 +1950,16 @@ class TestMleMessageFactory(unittest.TestCase): message_info.destination_mac_address = common.MacAddress.from_eui64( bytearray([0x3a, 0xba, 0xad, 0xca, 0xfe, 0xde, 0xff, 0xa5])) - data = bytearray([0x00, 0x15, 0x15, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x01, 0xca, 0xd3, 0x45, 0xe2, 0x35, - 0x1d, 0x00, 0x2d, 0x72, 0x71, 0xb1, 0x19, 0xaf, - 0x8b, 0x05, 0xd9, 0x52, 0x74, 0xce, 0xe6, 0x36, - 0x53, 0xeb, 0xc6, 0x25, 0x94, 0x01, 0x6d, 0x20, - 0xdf, 0x30, 0x82, 0xf8, 0xbb, 0x34, 0x47, 0x42, - 0x50, 0xe9, 0x41, 0xa7, 0x33, 0xa5]) + data = bytearray([ + 0x00, 0x15, 0x15, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, + 0xca, 0xd3, 0x45, 0xe2, 0x35, 0x1d, 0x00, 0x2d, 0x72, 0x71, 0xb1, + 0x19, 0xaf, 0x8b, 0x05, 0xd9, 0x52, 0x74, 0xce, 0xe6, 0x36, 0x53, + 0xeb, 0xc6, 0x25, 0x94, 0x01, 0x6d, 0x20, 0xdf, 0x30, 0x82, 0xf8, + 0xbb, 0x34, 0x47, 0x42, 0x50, 0xe9, 0x41, 0xa7, 0x33, 0xa5 + ]) - factory = config.create_default_mle_message_factory(master_key=config.DEFAULT_MASTER_KEY) + factory = config.create_default_mle_message_factory( + master_key=config.DEFAULT_MASTER_KEY) # WHEN actual_mle_message = factory.parse(io.BytesIO(data), message_info) @@ -1757,29 +1969,40 @@ class TestMleMessageFactory(unittest.TestCase): self.assertEqual(8, actual_mle_message.command.type) - self.assertEqual(mle.SourceAddress(address=0x9400), actual_mle_message.command.tlvs[0]) + self.assertEqual(mle.SourceAddress(address=0x9400), + actual_mle_message.command.tlvs[0]) - self.assertEqual(mle.LeaderData( - partition_id=0x06d014ca, - weighting=64, - data_version=131, - stable_data_version=168, - leader_router_id=37 - ), actual_mle_message.command.tlvs[1]) + self.assertEqual( + mle.LeaderData(partition_id=0x06d014ca, + weighting=64, + data_version=131, + stable_data_version=168, + leader_router_id=37), + actual_mle_message.command.tlvs[1]) - self.assertEqual(mle.NetworkData(tlvs=[ - network_data.Prefix( - domain_id=0, - prefix_length=64, - prefix=bytearray([0x12, 0x34, 0x12, 0x34, 0x12, 0x34, 0x12, 0x34]), - sub_tlvs=[ - network_data.LowpanId(c=1, cid=1, context_length=64, stable=1), - network_data.BorderRouter(border_router_16=37888, prf=0, p=1, - s=1, d=0, c=0, r=1, o=1, n=0, stable=1) - ], - stable=1 - ) - ]), actual_mle_message.command.tlvs[2]) + self.assertEqual( + mle.NetworkData(tlvs=[ + network_data.Prefix( + domain_id=0, + prefix_length=64, + prefix=bytearray( + [0x12, 0x34, 0x12, 0x34, 0x12, 0x34, 0x12, 0x34]), + sub_tlvs=[ + network_data.LowpanId( + c=1, cid=1, context_length=64, stable=1), + network_data.BorderRouter(border_router_16=37888, + prf=0, + p=1, + s=1, + d=0, + c=0, + r=1, + o=1, + n=0, + stable=1) + ], + stable=1) + ]), actual_mle_message.command.tlvs[2]) self.assertEqual(bytearray(data[-4:]), actual_mle_message.mic) diff --git a/tests/scripts/thread-cert/test_network_data.py b/tests/scripts/thread-cert/test_network_data.py index 552cc048a..e3e8e3f4a 100755 --- a/tests/scripts/thread-cert/test_network_data.py +++ b/tests/scripts/thread-cert/test_network_data.py @@ -39,9 +39,7 @@ import network_data def convert_route_to_bytearray(route): - return struct.pack( - ">HB", route.border_router_16, ((route.prf & 0x03) << 6) - ) + return struct.pack(">HB", route.border_router_16, ((route.prf & 0x03) << 6)) def convert_routes_to_bytearray(routes): @@ -60,13 +58,10 @@ def convert_border_router_to_bytearray(border_router): data = struct.pack( ">HBB", border_router.border_router_16, - (border_router.o & 0x01) - | ((border_router.r & 0x01) << 1) - | ((border_router.c & 0x01) << 2) - | ((border_router.d & 0x01) << 3) - | ((border_router.s & 0x01) << 4) - | ((border_router.p & 0x01) << 5) - | ((border_router.prf & 0x03) << 6), + (border_router.o & 0x01) | ((border_router.r & 0x01) << 1) | + ((border_router.c & 0x01) << 2) | ((border_router.d & 0x01) << 3) | + ((border_router.s & 0x01) << 4) | ((border_router.p & 0x01) << 5) | + ((border_router.prf & 0x03) << 6), ((border_router.n & 0x01) << 7), ) @@ -75,8 +70,7 @@ def convert_border_router_to_bytearray(border_router): def convert_lowpan_id_to_bytearray(lowpan_id): return bytearray( - [lowpan_id.cid | (lowpan_id.c << 4), lowpan_id.context_length] - ) + [lowpan_id.cid | (lowpan_id.c << 4), lowpan_id.context_length]) def convert_prefix_sub_tlvs_to_bytearray(sub_tlvs): @@ -124,16 +118,13 @@ def convert_service_sub_tlvs_to_bytearray(sub_tlvs): def convert_service_to_bytearray(service): - return ( - struct.pack( - ">BLB", - ((service.t & 0x01) << 7) | ((service.id) & 0x0F), - service.enterprise_number, - service.service_data_length, - ) - + service.service_data - + convert_service_sub_tlvs_to_bytearray(service.sub_tlvs) - ) + return (struct.pack( + ">BLB", + ((service.t & 0x01) << 7) | ((service.id) & 0x0F), + service.enterprise_number, + service.service_data_length, + ) + service.service_data + + convert_service_sub_tlvs_to_bytearray(service.sub_tlvs)) def any_border_router_16(): @@ -171,12 +162,9 @@ def any_prefix(prefix_length=None): if prefix_length is None: prefix_length = any_prefix_length() - return bytearray( - [ - random.getrandbits(8) - for _ in range(int(math.ceil(prefix_length / 8))) - ] - ) + return bytearray([ + random.getrandbits(8) for _ in range(int(math.ceil(prefix_length / 8))) + ]) def any_p(): @@ -231,9 +219,8 @@ def any_border_router(): def any_lowpan_id(): - return network_data.LowpanId( - any_c(), any_cid(), any_context_length(), any_stable() - ) + return network_data.LowpanId(any_c(), any_cid(), any_context_length(), + any_stable()) def any_prefix_sub_tlvs(): @@ -283,9 +270,7 @@ def any_server_data(data_length=None): def any_server(): - return network_data.Server( - any_server_16(), any_server_data(), any_stable() - ) + return network_data.Server(any_server_16(), any_server_data(), any_stable()) def any_service_sub_tlvs(): @@ -305,8 +290,9 @@ def any_stable(): class TestRoute(unittest.TestCase): + def test_should_return_border_router_16_value_when_border_router_16_property_is_called( - self): + self): # GIVEN border_router_16 = any_border_router_16() @@ -332,9 +318,9 @@ class TestRoute(unittest.TestCase): class TestRouteFactory(unittest.TestCase): + def test_should_create_Route_from_bytearray_when_parse_method_is_called( - self - ): + self): # GIVEN border_router_16 = any_border_router_16() prf = any_prf() @@ -342,8 +328,7 @@ class TestRouteFactory(unittest.TestCase): factory = network_data.RouteFactory() data = convert_route_to_bytearray( - network_data.Route(border_router_16, prf) - ) + network_data.Route(border_router_16, prf)) # WHEN actual_route = factory.parse(io.BytesIO(data), None) @@ -355,8 +340,9 @@ class TestRouteFactory(unittest.TestCase): class TestRoutesFactory(unittest.TestCase): + def test_should_create_Route_list_from_bytearray_when_parse_method_is_called( - self): + self): # GIVEN routes = any_routes() @@ -372,6 +358,7 @@ class TestRoutesFactory(unittest.TestCase): class TestHasRoute(unittest.TestCase): + def test_should_return_routes_value_when_routes_property_is_called(self): # GIVEN routes = any_routes() @@ -398,16 +385,15 @@ class TestHasRoute(unittest.TestCase): class TestHasRouteFactory(unittest.TestCase): + def test_should_create_HasRoute_from_bytearray_when_parse_method_is_called( - self - ): + self): # GIVEN routes = any_routes() stable = any_stable() factory = network_data.HasRouteFactory( - network_data.RoutesFactory(network_data.RouteFactory()) - ) + network_data.RoutesFactory(network_data.RouteFactory())) data = convert_routes_to_bytearray(routes) @@ -424,9 +410,9 @@ class TestHasRouteFactory(unittest.TestCase): class TestPrefix(unittest.TestCase): + def test_should_return_domain_id_value_when_domain_id_property_is_called( - self - ): + self): # GIVEN domain_id = any_domain_id() @@ -445,7 +431,7 @@ class TestPrefix(unittest.TestCase): self.assertEqual(domain_id, actual_domain_id) def test_should_return_prefix_length_value_when_prefix_length_property_is_called( - self): + self): # GIVEN prefix_length = any_prefix_length() @@ -482,8 +468,7 @@ class TestPrefix(unittest.TestCase): self.assertEqual(prefix, actual_prefix) def test_should_return_sub_tlvs_value_when_sub_tlvs_property_is_called( - self - ): + self): # GIVEN sub_tlvs = any_prefix_sub_tlvs() @@ -521,15 +506,14 @@ class TestPrefix(unittest.TestCase): class TestPrefixSubTlvsFactory(unittest.TestCase): + def test_should_create_SubTlvs_from_bytearray_when_parse_method_is_called( - self - ): + self): # GIVEN sub_tlvs = any_prefix_sub_tlvs() factory = network_data.PrefixSubTlvsFactory( - config.create_default_network_data_prefix_sub_tlvs_factories() - ) + config.create_default_network_data_prefix_sub_tlvs_factories()) data = convert_prefix_sub_tlvs_to_bytearray(sub_tlvs) @@ -542,9 +526,9 @@ class TestPrefixSubTlvsFactory(unittest.TestCase): class TestPrefixFactory(unittest.TestCase): + def test_should_create_Prefix_from_bytearray_when_parse_method_is_called( - self - ): + self): # GIVEN domain_id = any_domain_id() prefix_length = any_prefix_length() @@ -552,14 +536,10 @@ class TestPrefixFactory(unittest.TestCase): sub_tlvs = any_prefix_sub_tlvs() factory = network_data.PrefixFactory( - config.create_default_network_data_prefix_sub_tlvs_factory() - ) + config.create_default_network_data_prefix_sub_tlvs_factory()) - data = ( - bytearray([domain_id, prefix_length]) - + prefix - + convert_prefix_sub_tlvs_to_bytearray(sub_tlvs) - ) + data = (bytearray([domain_id, prefix_length]) + prefix + + convert_prefix_sub_tlvs_to_bytearray(sub_tlvs)) message_info = common.MessageInfo() @@ -575,8 +555,9 @@ class TestPrefixFactory(unittest.TestCase): class TestBorderRouter(unittest.TestCase): + def test_should_return_border_router_16_value_when_border_router_16_property_is_called( - self): + self): # GIVEN border_router_16 = any_border_router_16() @@ -808,8 +789,9 @@ class TestBorderRouter(unittest.TestCase): class TestBorderRouterFactory(unittest.TestCase): + def test_should_create_BorderRouter_from_bytearray_when_parse_method_is_called( - self): + self): # GIVEN border_router_16 = any_border_router_16() prf = any_prf() @@ -825,10 +807,8 @@ class TestBorderRouterFactory(unittest.TestCase): factory = network_data.BorderRouterFactory() data = convert_border_router_to_bytearray( - network_data.BorderRouter( - border_router_16, prf, p, s, d, c, r, o, n, stable - ) - ) + network_data.BorderRouter(border_router_16, prf, p, s, d, c, r, o, + n, stable)) message_info = common.MessageInfo() message_info.stable = stable @@ -838,11 +818,9 @@ class TestBorderRouterFactory(unittest.TestCase): # THEN self.assertTrue( - isinstance(actual_border_router, network_data.BorderRouter) - ) - self.assertEqual( - border_router_16, actual_border_router.border_router_16 - ) + isinstance(actual_border_router, network_data.BorderRouter)) + self.assertEqual(border_router_16, + actual_border_router.border_router_16) self.assertEqual(prf, actual_border_router.prf) self.assertEqual(p, actual_border_router.p) self.assertEqual(s, actual_border_router.s) @@ -855,13 +833,13 @@ class TestBorderRouterFactory(unittest.TestCase): class TestLowpanId(unittest.TestCase): + def test_should_return_c_value_when_c_property_is_called(self): # GIVEN c = any_c() - lowpan_id = network_data.LowpanId( - c, any_cid(), any_context_length(), any_stable() - ) + lowpan_id = network_data.LowpanId(c, any_cid(), any_context_length(), + any_stable()) # WHEN actual_c = lowpan_id.c @@ -873,9 +851,8 @@ class TestLowpanId(unittest.TestCase): # GIVEN cid = any_cid() - lowpan_id = network_data.LowpanId( - any_c(), cid, any_context_length(), any_stable() - ) + lowpan_id = network_data.LowpanId(any_c(), cid, any_context_length(), + any_stable()) # WHEN actual_cid = lowpan_id.cid @@ -884,13 +861,12 @@ class TestLowpanId(unittest.TestCase): self.assertEqual(cid, actual_cid) def test_should_return_context_length_value_when_context_length_property_is_called( - self): + self): # GIVEN context_length = any_context_length() - lowpan_id = network_data.LowpanId( - any_c(), any_cid(), context_length, any_stable() - ) + lowpan_id = network_data.LowpanId(any_c(), any_cid(), context_length, + any_stable()) # WHEN actual_context_length = lowpan_id.context_length @@ -902,9 +878,8 @@ class TestLowpanId(unittest.TestCase): # GIVEN stable = any_stable() - lowpan_id = network_data.LowpanId( - any_c(), any_cid(), any_context_length(), stable - ) + lowpan_id = network_data.LowpanId(any_c(), any_cid(), + any_context_length(), stable) # WHEN actual_stable = lowpan_id.stable @@ -914,9 +889,9 @@ class TestLowpanId(unittest.TestCase): class TestLowpanIdFactory(unittest.TestCase): + def test_should_create_LowpanId_from_bytearray_when_parse_method_is_called( - self - ): + self): # GIVEN c = any_c() cid = any_cid() @@ -926,8 +901,7 @@ class TestLowpanIdFactory(unittest.TestCase): factory = network_data.LowpanIdFactory() data = convert_lowpan_id_to_bytearray( - network_data.LowpanId(c, cid, context_length, stable) - ) + network_data.LowpanId(c, cid, context_length, stable)) message_info = common.MessageInfo() message_info.stable = stable @@ -943,6 +917,7 @@ class TestLowpanIdFactory(unittest.TestCase): class TestService(unittest.TestCase): + def test_should_return_t_value_when_t_property_is_called(self): # GIVEN t = any_t() @@ -984,7 +959,7 @@ class TestService(unittest.TestCase): self.assertEqual(_id, actual_id) def test_should_return_enterprise_number_value_when_enterprise_number_property_is_called( - self): + self): # GIVEN enterprise_number = any_enterprise_number() @@ -1005,7 +980,7 @@ class TestService(unittest.TestCase): self.assertEqual(enterprise_number, actual_enterprise_number) def test_should_return_service_data_length_value_when_service_data_length_property_is_called( - self): + self): # GIVEN service_data_length = any_service_data_length() @@ -1026,7 +1001,7 @@ class TestService(unittest.TestCase): self.assertEqual(service_data_length, actual_service_data_length) def test_should_return_service_data_value_when_service_data_property_is_called( - self): + self): # GIVEN service_data = any_service_data() @@ -1047,8 +1022,7 @@ class TestService(unittest.TestCase): self.assertEqual(service_data, actual_service_data) def test_should_return_sub_tlvs_value_when_sub_tlvs_property_is_called( - self - ): + self): # GIVEN sub_tlvs = any_service_sub_tlvs() @@ -1090,15 +1064,14 @@ class TestService(unittest.TestCase): class TestServiceSubTlvsFactory(unittest.TestCase): + def test_should_create_SubTlvs_from_bytearray_when_parse_method_is_called( - self - ): + self): # GIVEN sub_tlvs = any_service_sub_tlvs() factory = network_data.ServiceSubTlvsFactory( - config.create_default_network_data_service_sub_tlvs_factories() - ) + config.create_default_network_data_service_sub_tlvs_factories()) data = convert_service_sub_tlvs_to_bytearray(sub_tlvs) @@ -1111,9 +1084,9 @@ class TestServiceSubTlvsFactory(unittest.TestCase): class TestServiceFactory(unittest.TestCase): + def test_should_create_Service_from_bytearray_when_parse_method_is_called( - self - ): + self): # GIVEN t = any_t() _id = any_id() @@ -1124,8 +1097,7 @@ class TestServiceFactory(unittest.TestCase): stable = any_stable() factory = network_data.ServiceFactory( - config.create_default_network_data_service_sub_tlvs_factory() - ) + config.create_default_network_data_service_sub_tlvs_factory()) data = convert_service_to_bytearray( network_data.Service( @@ -1136,8 +1108,7 @@ class TestServiceFactory(unittest.TestCase): service_data, sub_tlvs, stable, - ) - ) + )) message_info = common.MessageInfo() message_info.stable = stable @@ -1150,23 +1121,20 @@ class TestServiceFactory(unittest.TestCase): self.assertEqual(t, actual_service.t) self.assertEqual(_id, actual_service.id) self.assertEqual(enterprise_number, actual_service.enterprise_number) - self.assertEqual( - service_data_length, actual_service.service_data_length - ) + self.assertEqual(service_data_length, + actual_service.service_data_length) self.assertEqual(service_data, actual_service.service_data) self.assertEqual(sub_tlvs, actual_service.sub_tlvs) class TestServer(unittest.TestCase): + def test_should_return_server_16_value_when_server_16_property_is_called( - self - ): + self): # GIVEN server_16 = any_server_16() - server = network_data.Server( - server_16, any_server_data(), any_stable() - ) + server = network_data.Server(server_16, any_server_data(), any_stable()) # WHEN actual_server_16 = server.server_16 @@ -1175,13 +1143,11 @@ class TestServer(unittest.TestCase): self.assertEqual(server_16, actual_server_16) def test_should_return_server_data_value_when_server_data_property_is_called( - self): + self): # GIVEN server_data = any_server_data() - server = network_data.Server( - any_server_16(), server_data, any_stable() - ) + server = network_data.Server(any_server_16(), server_data, any_stable()) # WHEN actual_server_data = server.server_data @@ -1193,9 +1159,7 @@ class TestServer(unittest.TestCase): # GIVEN stable = any_stable() - server = network_data.Server( - any_server_16(), any_server_data(), stable - ) + server = network_data.Server(any_server_16(), any_server_data(), stable) # WHEN actual_stable = server.stable @@ -1205,9 +1169,9 @@ class TestServer(unittest.TestCase): class TestServerFactory(unittest.TestCase): + def test_should_create_Server_from_bytearray_when_parse_method_is_called( - self - ): + self): # GIVEN server_16 = any_server_16() server_data = any_server_data() @@ -1216,8 +1180,7 @@ class TestServerFactory(unittest.TestCase): factory = network_data.ServerFactory() data = convert_server_to_bytearray( - network_data.Server(server_16, server_data, stable) - ) + network_data.Server(server_16, server_data, stable)) message_info = common.MessageInfo() message_info.stable = stable diff --git a/tests/scripts/thread-cert/test_network_layer.py b/tests/scripts/thread-cert/test_network_layer.py index 93cae84f2..95c6861fe 100755 --- a/tests/scripts/thread-cert/test_network_layer.py +++ b/tests/scripts/thread-cert/test_network_layer.py @@ -92,6 +92,7 @@ def any_tlvs_data(count=None): class TestTargetEid(unittest.TestCase): + def test_should_return_eid_value_when_eid_property_is_called(self): # GIVEN eid = any_eid() @@ -105,7 +106,7 @@ class TestTargetEid(unittest.TestCase): self.assertEqual(eid, actual_eid) def test_should_return_True_when_try_to_equal_two_the_same_type_objects_with_the_same_values( - self): + self): # GIVEN eid = any_eid() @@ -116,8 +117,9 @@ class TestTargetEid(unittest.TestCase): class TestTargetEidFactory(unittest.TestCase): + def test_should_create_TargetEid_from_bytearray_when_parse_method_is_called( - self): + self): # GIVEN eid = any_eid() @@ -132,8 +134,9 @@ class TestTargetEidFactory(unittest.TestCase): class TestMacExtendedAddress(unittest.TestCase): + def test_should_return_mac_address_value_when_mac_address_property_is_called( - self): + self): # GIVEN mac_address = any_mac_extended_address() @@ -146,39 +149,38 @@ class TestMacExtendedAddress(unittest.TestCase): self.assertEqual(mac_address, actual_mac_address) def test_should_return_True_when_try_to_equal_two_the_same_type_objects_with_the_same_values( - self): + self): # GIVEN mac_address = any_mac_extended_address() mac_extended_address = network_layer.MacExtendedAddress(mac_address) # THEN - self.assertEqual( - mac_extended_address, network_layer.MacExtendedAddress(mac_address) - ) + self.assertEqual(mac_extended_address, + network_layer.MacExtendedAddress(mac_address)) class TestMacExtendedAddressFactory(unittest.TestCase): + def test_should_create_MacExtendedAddress_from_bytearray_when_parse_method_is_called( - self): + self): # GIVEN mac_address = any_mac_extended_address() factory = network_layer.MacExtendedAddressFactory() # WHEN - mac_extended_address = factory.parse( - io.BytesIO(mac_address), common.MessageInfo() - ) + mac_extended_address = factory.parse(io.BytesIO(mac_address), + common.MessageInfo()) # THEN self.assertTrue( - isinstance(mac_extended_address, network_layer.MacExtendedAddress) - ) + isinstance(mac_extended_address, network_layer.MacExtendedAddress)) self.assertEqual(mac_address, mac_extended_address.mac_address) class TestRloc16(unittest.TestCase): + def test_should_return_rloc16_value_when_rloc16_property_is_called(self): # GIVEN rloc16 = any_rloc16() @@ -192,7 +194,7 @@ class TestRloc16(unittest.TestCase): self.assertEqual(rloc16, actual_rloc16) def test_should_return_True_when_try_to_equal_two_the_same_type_objects_with_the_same_values( - self): + self): # GIVEN rloc16 = any_rloc16() @@ -203,9 +205,9 @@ class TestRloc16(unittest.TestCase): class TestRloc16Factory(unittest.TestCase): + def test_should_create_Rloc16_from_bytearray_when_parse_method_is_called( - self - ): + self): # GIVEN rloc16 = any_rloc16() @@ -222,6 +224,7 @@ class TestRloc16Factory(unittest.TestCase): class TestMlEid(unittest.TestCase): + def test_should_return_ml_eid_value_when_ml_eid_property_is_called(self): # GIVEN ml_eid = any_ml_eid() @@ -235,7 +238,7 @@ class TestMlEid(unittest.TestCase): self.assertEqual(ml_eid, actual_ml_eid) def test_should_return_True_when_try_to_equal_two_the_same_type_objects_with_the_same_values( - self): + self): # GIVEN ml_eid = any_ml_eid() @@ -246,9 +249,9 @@ class TestMlEid(unittest.TestCase): class TestMlEidFactory(unittest.TestCase): + def test_should_create_MlEid_from_bytearray_when_parse_method_is_called( - self - ): + self): # GIVEN ml_eid = any_ml_eid() @@ -263,6 +266,7 @@ class TestMlEidFactory(unittest.TestCase): class TestStatus(unittest.TestCase): + def test_should_return_status_value_when_status_property_is_called(self): # GIVEN status = any_status() @@ -276,7 +280,7 @@ class TestStatus(unittest.TestCase): self.assertEqual(status, actual_status) def test_should_return_True_when_try_to_equal_two_the_same_type_objects_with_the_same_values( - self): + self): # GIVEN status = any_status() @@ -287,9 +291,9 @@ class TestStatus(unittest.TestCase): class TestStatusFactory(unittest.TestCase): + def test_should_create_Status_from_bytearray_when_parse_method_is_called( - self - ): + self): # GIVEN status = any_status() @@ -306,13 +310,13 @@ class TestStatusFactory(unittest.TestCase): class TestTimeSinceLastTransaction(unittest.TestCase): + def test_should_return_seconds_value_when_seconds_property_is_called(self): # GIVEN seconds = any_seconds() time_since_last_transaction = network_layer.TimeSinceLastTransaction( - seconds - ) + seconds) # WHEN actual_seconds = time_since_last_transaction.seconds @@ -321,13 +325,12 @@ class TestTimeSinceLastTransaction(unittest.TestCase): self.assertEqual(seconds, actual_seconds) def test_should_return_True_when_try_to_equal_two_the_same_type_objects_with_the_same_values( - self): + self): # GIVEN seconds = any_seconds() time_since_last_transaction = network_layer.TimeSinceLastTransaction( - seconds - ) + seconds) # THEN self.assertEqual( @@ -337,8 +340,9 @@ class TestTimeSinceLastTransaction(unittest.TestCase): class TestTimeSinceLastTransactionFactory(unittest.TestCase): + def test_should_create_TimeSinceLastTransaction_from_bytearray_when_parse_method_is_called( - self): + self): # GIVEN seconds = any_seconds() @@ -347,29 +351,27 @@ class TestTimeSinceLastTransactionFactory(unittest.TestCase): data = bytearray(struct.pack(">L", seconds)) # WHEN - time_since_last_transaction = factory.parse( - io.BytesIO(data), common.MessageInfo() - ) + time_since_last_transaction = factory.parse(io.BytesIO(data), + common.MessageInfo()) # THEN self.assertTrue( isinstance( time_since_last_transaction, network_layer.TimeSinceLastTransaction, - ) - ) + )) self.assertEqual(seconds, time_since_last_transaction.seconds) class TestRouterMask(unittest.TestCase): + def test_should_return_id_sequence_value_when_id_sequence_property_is_called( - self): + self): # GIVEN id_sequence = any_id_sequence() - router_mask = network_layer.RouterMask( - id_sequence, any_router_id_mask() - ) + router_mask = network_layer.RouterMask(id_sequence, + any_router_id_mask()) # WHEN actual_id_sequence = router_mask.id_sequence @@ -378,13 +380,12 @@ class TestRouterMask(unittest.TestCase): self.assertEqual(id_sequence, actual_id_sequence) def test_should_return_router_id_mask_value_when_router_id_mask_property_is_called( - self): + self): # GIVEN router_id_mask = any_router_id_mask() - router_mask = network_layer.RouterMask( - any_id_sequence(), router_id_mask - ) + router_mask = network_layer.RouterMask(any_id_sequence(), + router_id_mask) # WHEN actual_router_id_mask = router_mask.router_id_mask @@ -393,7 +394,7 @@ class TestRouterMask(unittest.TestCase): self.assertEqual(router_id_mask, actual_router_id_mask) def test_should_return_True_when_try_to_equal_two_the_same_type_objects_with_the_same_values( - self): + self): # GIVEN id_sequence = any_id_sequence() router_id_mask = any_router_id_mask() @@ -401,14 +402,14 @@ class TestRouterMask(unittest.TestCase): router_mask = network_layer.RouterMask(id_sequence, router_id_mask) # THEN - self.assertEqual( - router_mask, network_layer.RouterMask(id_sequence, router_id_mask) - ) + self.assertEqual(router_mask, + network_layer.RouterMask(id_sequence, router_id_mask)) class TestRouterMaskFactory(unittest.TestCase): + def test_should_create_RouterMask_from_bytearray_when_parse_method_is_called( - self): + self): # GIVEN id_sequence = any_id_sequence() router_id_mask = any_router_id_mask() @@ -427,6 +428,7 @@ class TestRouterMaskFactory(unittest.TestCase): class TestNdOption(unittest.TestCase): + def test_should_return_options_value_when_options_property_is_called(self): # GIVEN options = any_options() @@ -440,7 +442,7 @@ class TestNdOption(unittest.TestCase): self.assertEqual(options, actual_options) def test_should_return_True_when_try_to_equal_two_the_same_type_objects_with_the_same_values( - self): + self): # GIVEN options = any_options() @@ -451,9 +453,9 @@ class TestNdOption(unittest.TestCase): class TestNdOptionFactory(unittest.TestCase): + def test_should_create_NdOption_from_bytearray_when_parse_method_is_called( - self - ): + self): # GIVEN options = any_options() @@ -470,6 +472,7 @@ class TestNdOptionFactory(unittest.TestCase): class TestThreadNetworkData(unittest.TestCase): + def test_should_return_options_value_when_options_property_is_called(self): # GIVEN tlvs = any_tlvs_data() @@ -483,41 +486,39 @@ class TestThreadNetworkData(unittest.TestCase): self.assertEqual(tlvs, actual_tlvs) def test_should_return_True_when_try_to_equal_two_the_same_type_objects_with_the_same_values( - self): + self): # GIVEN tlvs = any_tlvs_data() thread_network_data = network_layer.ThreadNetworkData(tlvs) # THEN - self.assertEqual( - thread_network_data, network_layer.ThreadNetworkData(tlvs) - ) + self.assertEqual(thread_network_data, + network_layer.ThreadNetworkData(tlvs)) class TestThreadNetworkDataFactory(unittest.TestCase): + def test_should_create_ThreadNetworkData_from_bytearray_when_parse_method_is_called( - self): + self): # GIVEN tlvs = any_tlvs_data() class DummyNetworkDataTlvsFactory: + def parse(self, data, message_info): return bytearray(data.read()) factory = network_layer.ThreadNetworkDataFactory( - DummyNetworkDataTlvsFactory() - ) + DummyNetworkDataTlvsFactory()) # WHEN - thread_network_data = factory.parse( - io.BytesIO(tlvs), common.MessageInfo() - ) + thread_network_data = factory.parse(io.BytesIO(tlvs), + common.MessageInfo()) # THEN self.assertTrue( - isinstance(thread_network_data, network_layer.ThreadNetworkData) - ) + isinstance(thread_network_data, network_layer.ThreadNetworkData)) self.assertEqual(tlvs, thread_network_data.tlvs) diff --git a/tests/scripts/thread-cert/test_route_table.py b/tests/scripts/thread-cert/test_route_table.py index 18fecdc68..2f38e7d2f 100755 --- a/tests/scripts/thread-cert/test_route_table.py +++ b/tests/scripts/thread-cert/test_route_table.py @@ -42,6 +42,7 @@ ROUTER2 = 3 class TestRouteTable(unittest.TestCase): + def setUp(self): self.simulator = config.create_default_simulator() diff --git a/tests/scripts/thread-cert/test_service.py b/tests/scripts/thread-cert/test_service.py index b4dc97caa..eb6ad1b9d 100755 --- a/tests/scripts/thread-cert/test_service.py +++ b/tests/scripts/thread-cert/test_service.py @@ -49,6 +49,7 @@ SRV_1_SERVER_DATA = 'qux' class Test_Service(unittest.TestCase): + def setUp(self): self.simulator = config.create_default_simulator() @@ -90,13 +91,12 @@ class Test_Service(unittest.TestCase): def hasAloc(self, node_id, service_id): for addr in self.nodes[node_id].get_ip6_address( - config.ADDRESS_TYPE.ALOC - ): + config.ADDRESS_TYPE.ALOC): m = re.match('.*:fc(..)$', addr, re.I) if m is not None: - if m.group(1) == str( - service_id + 10 - ): # for service_id=3 look for '...:fc13' + if m.group( + 1) == str(service_id + + 10): # for service_id=3 look for '...:fc13' return True return False @@ -127,9 +127,8 @@ class Test_Service(unittest.TestCase): self.assertEqual(self.hasAloc(ROUTER2, SRV_0_ID), False) self.assertEqual(self.hasAloc(ROUTER2, SRV_1_ID), False) - self.nodes[ROUTER1].add_service( - SRV_0_ENT_NUMBER, SRV_0_SERVICE_DATA, SRV_0_SERVER_DATA - ) + self.nodes[ROUTER1].add_service(SRV_0_ENT_NUMBER, SRV_0_SERVICE_DATA, + SRV_0_SERVER_DATA) self.nodes[ROUTER1].register_netdata() self.simulator.go(2) @@ -140,14 +139,11 @@ class Test_Service(unittest.TestCase): self.assertEqual(self.hasAloc(ROUTER2, SRV_0_ID), False) self.assertEqual(self.hasAloc(ROUTER2, SRV_1_ID), False) - aloc0 = self.nodes[ROUTER1].get_ip6_address(config.ADDRESS_TYPE.ALOC)[ - 0 - ] + aloc0 = self.nodes[ROUTER1].get_ip6_address(config.ADDRESS_TYPE.ALOC)[0] self.pingFromAll(aloc0) - self.nodes[LEADER].add_service( - SRV_0_ENT_NUMBER, SRV_0_SERVICE_DATA, SRV_0_SERVER_DATA - ) + self.nodes[LEADER].add_service(SRV_0_ENT_NUMBER, SRV_0_SERVICE_DATA, + SRV_0_SERVER_DATA) self.nodes[LEADER].register_netdata() self.simulator.go(2) @@ -160,9 +156,8 @@ class Test_Service(unittest.TestCase): self.pingFromAll(aloc0) - self.nodes[ROUTER2].add_service( - SRV_1_ENT_NUMBER, SRV_1_SERVICE_DATA, SRV_1_SERVER_DATA - ) + self.nodes[ROUTER2].add_service(SRV_1_ENT_NUMBER, SRV_1_SERVICE_DATA, + SRV_1_SERVER_DATA) self.nodes[ROUTER2].register_netdata() self.simulator.go(2) @@ -173,15 +168,11 @@ class Test_Service(unittest.TestCase): self.assertEqual(self.hasAloc(ROUTER2, SRV_0_ID), False) self.assertEqual(self.hasAloc(ROUTER2, SRV_1_ID), True) - aloc1 = self.nodes[ROUTER2].get_ip6_address(config.ADDRESS_TYPE.ALOC)[ - 0 - ] + aloc1 = self.nodes[ROUTER2].get_ip6_address(config.ADDRESS_TYPE.ALOC)[0] self.pingFromAll(aloc0) self.pingFromAll(aloc1) - self.nodes[ROUTER1].remove_service( - SRV_0_ENT_NUMBER, SRV_0_SERVICE_DATA - ) + self.nodes[ROUTER1].remove_service(SRV_0_ENT_NUMBER, SRV_0_SERVICE_DATA) self.nodes[ROUTER1].register_netdata() self.simulator.go(2) @@ -209,9 +200,7 @@ class Test_Service(unittest.TestCase): self.failToPingFromAll(aloc0) self.pingFromAll(aloc1) - self.nodes[ROUTER2].remove_service( - SRV_1_ENT_NUMBER, SRV_1_SERVICE_DATA - ) + self.nodes[ROUTER2].remove_service(SRV_1_ENT_NUMBER, SRV_1_SERVICE_DATA) self.nodes[ROUTER2].register_netdata() self.simulator.go(2) diff --git a/tests/scripts/thread-cert/tlvs_parsing.py b/tests/scripts/thread-cert/tlvs_parsing.py index 63195ff81..5c9920d53 100644 --- a/tests/scripts/thread-cert/tlvs_parsing.py +++ b/tests/scripts/thread-cert/tlvs_parsing.py @@ -30,6 +30,7 @@ import io class SubTlvsFactory(object): + def __init__(self, sub_tlvs_factories): self._sub_tlvs_factories = sub_tlvs_factories @@ -38,8 +39,7 @@ class SubTlvsFactory(object): return self._sub_tlvs_factories[_type] except KeyError: raise RuntimeError( - "Could not find factory. Factory type = {}.".format(_type) - ) + "Could not find factory. Factory type = {}.".format(_type)) def parse(self, data, message_info): sub_tlvs = [] diff --git a/tests/toranj/test-002-form.py b/tests/toranj/test-002-form.py index f74b80997..969d9aed7 100644 --- a/tests/toranj/test-002-form.py +++ b/tests/toranj/test-002-form.py @@ -74,7 +74,6 @@ verify(node.get(wpan.WPAN_KEY) != DEFAULT_KEY) verify(node.get(wpan.WPAN_PANID) != DEFAULT_PANID) verify(node.get(wpan.WPAN_XPANID) != DEFAULT_XPANID) - node.leave() verify(node.get(wpan.WPAN_STATE) == wpan.STATE_OFFLINE) diff --git a/tests/toranj/test-006-traffic-router-end-device.py b/tests/toranj/test-006-traffic-router-end-device.py index 314e6a521..99e5bf2ba 100644 --- a/tests/toranj/test-006-traffic-router-end-device.py +++ b/tests/toranj/test-006-traffic-router-end-device.py @@ -92,9 +92,8 @@ for src, dst in [(ll1, ll2), (ll1, ml2), (ml1, ll2), (ml1, ml2)]: s1 = node1.prepare_tx((src, PORT), (dst, PORT), 'Hi there!', NUM_MSGS) r1 = node2.prepare_rx(s1) - s2 = node2.prepare_tx( - (dst, PORT), (src, PORT), 'Hello back to you!', NUM_MSGS - ) + s2 = node2.prepare_tx((dst, PORT), (src, PORT), 'Hello back to you!', + NUM_MSGS) r2 = node1.prepare_rx(s2) wpan.Node.perform_async_tx_rx() diff --git a/tests/toranj/test-007-traffic-router-sleepy.py b/tests/toranj/test-007-traffic-router-sleepy.py index 241e29143..a8e5253c0 100644 --- a/tests/toranj/test-007-traffic-router-sleepy.py +++ b/tests/toranj/test-007-traffic-router-sleepy.py @@ -97,9 +97,8 @@ for poll_interval in [10, 100, 300]: s1 = node1.prepare_tx((src, PORT), (dst, PORT), 'Hi there!', NUM_MSGS) r1 = node2.prepare_rx(s1) - s2 = node2.prepare_tx( - (dst, PORT), (src, PORT), 'Hello back to you!', NUM_MSGS - ) + s2 = node2.prepare_tx((dst, PORT), (src, PORT), 'Hello back to you!', + NUM_MSGS) r2 = node1.prepare_rx(s2) wpan.Node.perform_async_tx_rx() diff --git a/tests/toranj/test-009-insecure-traffic-join.py b/tests/toranj/test-009-insecure-traffic-join.py index d8268c47a..f02480687 100644 --- a/tests/toranj/test-009-insecure-traffic-join.py +++ b/tests/toranj/test-009-insecure-traffic-join.py @@ -90,9 +90,8 @@ node2.permit_join(duration_sec='100', port=str(rx_port)) # Send insecure reply from node1 to node2 -sender2 = node1.prepare_tx( - (ll1, insecure_port), (ll2, rx_port), "Hi back! (insecure)", NUM_MSGS -) +sender2 = node1.prepare_tx((ll1, insecure_port), (ll2, rx_port), + "Hi back! (insecure)", NUM_MSGS) recver2 = node2.prepare_rx(sender2) wpan.Node.perform_async_tx_rx() verify(sender2.was_successful) @@ -106,9 +105,8 @@ verify(node2.is_associated()) node1.permit_join('0') -sender = node2.prepare_tx( - ll2, (ll1, insecure_port), "Hi (now secure)", NUM_MSGS -) +sender = node2.prepare_tx(ll2, (ll1, insecure_port), "Hi (now secure)", + NUM_MSGS) recver = node1.prepare_rx(sender) wpan.Node.perform_async_tx_rx() verify(sender.was_successful) @@ -116,9 +114,8 @@ verify(recver.was_successful) node2.permit_join('0') -sender2 = node1.prepare_tx( - (ll1, insecure_port), (ll2, rx_port), "Hi back! (secure now)", NUM_MSGS -) +sender2 = node1.prepare_tx((ll1, insecure_port), (ll2, rx_port), + "Hi back! (secure now)", NUM_MSGS) recver2 = node2.prepare_rx(sender2) wpan.Node.perform_async_tx_rx() verify(sender2.was_successful) diff --git a/tests/toranj/test-010-on-mesh-prefix-config-gateway.py b/tests/toranj/test-010-on-mesh-prefix-config-gateway.py index c096b1a55..c111323e4 100644 --- a/tests/toranj/test-010-on-mesh-prefix-config-gateway.py +++ b/tests/toranj/test-010-on-mesh-prefix-config-gateway.py @@ -75,8 +75,7 @@ def verify_prefix( """ for node in node_list: prefixes = wpan.parse_on_mesh_prefix_result( - node.get(wpan.WPAN_THREAD_ON_MESH_PREFIXES) - ) + node.get(wpan.WPAN_THREAD_ON_MESH_PREFIXES)) for p in prefixes: if p.prefix == prefix: verify(int(p.prefix_len) == prefix_len) @@ -90,9 +89,8 @@ def verify_prefix( verify(p.priority == priority) break else: - raise wpan.VerifyError( - 'Did not find prefix {} on node {}'.format(prefix, node) - ) + raise wpan.VerifyError('Did not find prefix {} on node {}'.format( + prefix, node)) # ----------------------------------------------------------------------------------------------------------------------- diff --git a/tests/toranj/test-011-child-table.py b/tests/toranj/test-011-child-table.py index 27e8d2432..813f0745f 100644 --- a/tests/toranj/test-011-child-table.py +++ b/tests/toranj/test-011-child-table.py @@ -72,8 +72,7 @@ for child in children: # Get the child table and verify all children are in the table. child_table = wpan.parse_child_table_result( - router.get(wpan.WPAN_THREAD_CHILD_TABLE) -) + router.get(wpan.WPAN_THREAD_CHILD_TABLE)) verify(len(child_table) == len(children)) @@ -83,21 +82,15 @@ for child in children: if entry.ext_address == ext_addr: break else: - print( - 'Failed to find a child entry for extended address {} in table'.format( - ext_addr - ) - ) + print('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) - ) + verify(int(entry.rloc16, 16) == int(child.get(wpan.WPAN_THREAD_RLOC16), 16)) verify(int(entry.timeout, 0) == 120) verify(entry.is_rx_on_when_idle() is False) verify(entry.is_ftd() is False) - # ----------------------------------------------------------------------------------------------------------------------- # Test finished diff --git a/tests/toranj/test-012-multi-hop-traffic.py b/tests/toranj/test-012-multi-hop-traffic.py index 9d8b0ba0f..4ad13ba6c 100644 --- a/tests/toranj/test-012-multi-hop-traffic.py +++ b/tests/toranj/test-012-multi-hop-traffic.py @@ -50,7 +50,6 @@ from wpan import verify # - Verifies Mesh Header frame forwarding over multiple routers. # - Verifies forwarding of large IPv6 messages (1000 bytes) requiring lowpan fragmentation. - test_name = __file__[:-3] if __file__.endswith('.py') else __file__ print('-' * 120) print('Starting \'{}\''.format(test_name)) @@ -115,15 +114,13 @@ sed_children[0].set(wpan.WPAN_POLL_INTERVAL, '500') for index in range(1, NUM_ROUTERS): routers[index].join_node(routers[index - 1], wpan.JOIN_TYPE_ROUTER) - sed_children[index].join_node( - routers[index], wpan.JOIN_TYPE_SLEEPY_END_DEVICE - ) + sed_children[index].join_node(routers[index], + wpan.JOIN_TYPE_SLEEPY_END_DEVICE) sed_children[index].set(wpan.WPAN_POLL_INTERVAL, '500') fed_children[0].join_node(routers[0], wpan.JOIN_TYPE_END_DEVICE) fed_children[-1].join_node(routers[-1], wpan.JOIN_TYPE_END_DEVICE) - # ----------------------------------------------------------------------------------------------------------------------- # Test implementation @@ -140,12 +137,12 @@ r1_rloc = int(routers[0].get(wpan.WPAN_THREAD_RLOC16), 16) def check_r1_router_table(): - router_table = wpan.parse_router_table_result( - routers[0].get(wpan.WPAN_THREAD_ROUTER_TABLE) - ) + router_table = wpan.parse_router_table_result(routers[0].get( + wpan.WPAN_THREAD_ROUTER_TABLE)) verify(len(router_table) == NUM_ROUTERS) for entry in router_table: - verify(entry.rloc16 == r1_rloc or entry.is_link_established or entry.next_hop != INVALID_ROUTER_ID) + verify(entry.rloc16 == r1_rloc or entry.is_link_established or + entry.next_hop != INVALID_ROUTER_ID) wpan.verify_within(check_r1_router_table, ROUTER_TABLE_WAIT_TIME) diff --git a/tests/toranj/test-013-off-mesh-route-traffic.py b/tests/toranj/test-013-off-mesh-route-traffic.py index 3009c20e1..17060b4a0 100644 --- a/tests/toranj/test-013-off-mesh-route-traffic.py +++ b/tests/toranj/test-013-off-mesh-route-traffic.py @@ -87,7 +87,6 @@ for node in all_nodes: # | | # fed1 sed2 - r1.whitelist_node(r2) r2.whitelist_node(r1) diff --git a/tests/toranj/test-014-ip6-address-add.py b/tests/toranj/test-014-ip6-address-add.py index c9822d05d..6602b3b63 100644 --- a/tests/toranj/test-014-ip6-address-add.py +++ b/tests/toranj/test-014-ip6-address-add.py @@ -82,7 +82,6 @@ wpan.Node.init_all_nodes() # | | # fed1 sed2 - r1.whitelist_node(r2) r2.whitelist_node(r1) @@ -132,8 +131,7 @@ def check_addresses_and_prefixes(): 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) - ) + node.get(wpan.WPAN_THREAD_ON_MESH_PREFIXES)) for p in prefixes: if p.prefix == prefix: verify(p.prefix_len == '64') @@ -148,8 +146,7 @@ def check_addresses_and_prefixes(): break else: # `for` loop finished without finding the prefix. raise wpan.VerifyError( - 'Did not find prefix {} on node {}'.format(prefix, node) - ) + 'Did not find prefix {} on node {}'.format(prefix, node)) # Verify that IPv6 address of `sed2` is present on `r2` (its parent) # "Thread:ChildTable:Addresses". @@ -177,8 +174,7 @@ def check_address_prefix_removed(): # Verify that the related prefix is also removed on all nodes for node in all_nodes: prefixes = wpan.parse_on_mesh_prefix_result( - node.get(wpan.WPAN_THREAD_ON_MESH_PREFIXES) - ) + node.get(wpan.WPAN_THREAD_ON_MESH_PREFIXES)) for p in prefixes: verify(p.prefix != IP6_PREFIX_1) diff --git a/tests/toranj/test-015-same-prefix-on-multiple-nodes.py b/tests/toranj/test-015-same-prefix-on-multiple-nodes.py index fcb07a416..1d9bdfbeb 100644 --- a/tests/toranj/test-015-same-prefix-on-multiple-nodes.py +++ b/tests/toranj/test-015-same-prefix-on-multiple-nodes.py @@ -93,27 +93,18 @@ r2.add_ip6_address_on_interface(IP6_ADDR_2, prefix_len=64) def check_prefix(): for node in [r1, r2]: prefixes = wpan.parse_on_mesh_prefix_result( - node.get(wpan.WPAN_THREAD_ON_MESH_PREFIXES) - ) + 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" - ): + 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) - ) + raise wpan.VerifyError('Did not find prefix {} on node {}'.format( + IP6_PREFIX, r1)) wpan.verify_within(check_prefix, 5) @@ -141,8 +132,7 @@ r1.remove_ip6_address_on_interface(IP6_ADDR_1, prefix_len=64) def check_empty_prefix_list(): for node in [r1, r2]: prefixes = wpan.parse_on_mesh_prefix_result( - node.get(wpan.WPAN_THREAD_ON_MESH_PREFIXES) - ) + node.get(wpan.WPAN_THREAD_ON_MESH_PREFIXES)) verify(len(prefixes) == 0) diff --git a/tests/toranj/test-016-neighbor-table.py b/tests/toranj/test-016-neighbor-table.py index c8bac848d..83609661d 100644 --- a/tests/toranj/test-016-neighbor-table.py +++ b/tests/toranj/test-016-neighbor-table.py @@ -109,9 +109,8 @@ for router in routers[1:]: verify(router.get(wpan.WPAN_NODE_TYPE) == wpan.NODE_TYPE_ROUTER) # Get and parse the neighbor table on routers[0]. -neighbor_table = wpan.parse_neighbor_table_result( - routers[0].get(wpan.WPAN_THREAD_NEIGHBOR_TABLE) -) +neighbor_table = wpan.parse_neighbor_table_result(routers[0].get( + wpan.WPAN_THREAD_NEIGHBOR_TABLE)) verify(len(neighbor_table) == NUM_ROUTERS - 1 + NUM_CHILDREN) @@ -123,14 +122,10 @@ for child in children: break else: raise wpan.VerifyError( - 'Failed to find a child entry for extended address {} in table'.format( - ext_addr - ) - ) + '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(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()) @@ -143,19 +138,15 @@ for router in routers[1:]: break else: raise wpan.VerifyError( - 'Failed to find a router entry for extended address {} in table'.format( - ext_addr - ) - ) + 'Failed to find a router entry for extended address {} in table'. + format(ext_addr)) verify( - int(entry.rloc16, 16) == int(router.get(wpan.WPAN_THREAD_RLOC16), 16) - ) + int(entry.rloc16, 16) == int(router.get(wpan.WPAN_THREAD_RLOC16), 16)) verify(entry.is_rx_on_when_idle()) verify(entry.is_ftd()) verify(entry.is_child() is False) - # ----------------------------------------------------------------------------------------------------------------------- # Test finished diff --git a/tests/toranj/test-017-parent-reset-child-recovery.py b/tests/toranj/test-017-parent-reset-child-recovery.py index b7fec12fd..2b8ca01c5 100644 --- a/tests/toranj/test-017-parent-reset-child-recovery.py +++ b/tests/toranj/test-017-parent-reset-child-recovery.py @@ -157,10 +157,8 @@ wpan.verify_within(check_child_table, 9) # Verify that number of state changes on all children stays as before # (indicating they did not get detached). for i in range(len(all_children)): - verify( - child_num_state_changes[i] - == len(wpan.parse_list(all_children[i].get("stat:ncp"))) - ) + verify(child_num_state_changes[i] == len( + wpan.parse_list(all_children[i].get("stat:ncp")))) # ----------------------------------------------------------------------------------------------------------------------- # Test finished diff --git a/tests/toranj/test-018-child-supervision.py b/tests/toranj/test-018-child-supervision.py index 5c02bb696..75219dc6e 100644 --- a/tests/toranj/test-018-child-supervision.py +++ b/tests/toranj/test-018-child-supervision.py @@ -95,8 +95,7 @@ verify(int(child.get(wpan.WPAN_THREAD_CHILD_TIMEOUT), 0) == CHILD_TIMEOUT) # Verify the child table on parent contains the child with correct timeout child_table = wpan.parse_child_table_result( - parent.get(wpan.WPAN_THREAD_CHILD_TABLE) -) + parent.get(wpan.WPAN_THREAD_CHILD_TABLE)) verify(len(child_table) == 1) verify(int(child_table[0].timeout, 0) == CHILD_TIMEOUT) @@ -113,16 +112,14 @@ parent.set(wpan.WPAN_MAC_WHITELIST_ENABLED, '1') def check_child_is_removed_from_parent_child_table(): child_table = wpan.parse_child_table_result( - parent.get(wpan.WPAN_THREAD_CHILD_TABLE) - ) + parent.get(wpan.WPAN_THREAD_CHILD_TABLE)) verify(len(child_table) == 0) # wait till child is removed from parent's child table # after this child should still be associated -wpan.verify_within( - check_child_is_removed_from_parent_child_table, CHILD_TIMEOUT / speedup + 2 -) +wpan.verify_within(check_child_is_removed_from_parent_child_table, + CHILD_TIMEOUT / speedup + 2) verify(child.is_associated()) # Enable supervision check on child and expect the child to @@ -138,17 +135,15 @@ def check_child_is_detached(): verify(not child.is_associated()) -wpan.verify_within( - check_child_is_detached, CHILD_SUPERVISION_CHECK_TIMEOUT / speedup + 8 -) +wpan.verify_within(check_child_is_detached, + CHILD_SUPERVISION_CHECK_TIMEOUT / speedup + 8) # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # Enable child supervision on parent and disable white-listing -parent.set( - wpan.WPAN_CHILD_SUPERVISION_INTERVAL, str(PARENT_SUPERVISION_INTERVAL) -) +parent.set(wpan.WPAN_CHILD_SUPERVISION_INTERVAL, + str(PARENT_SUPERVISION_INTERVAL)) parent.set(wpan.WPAN_MAC_WHITELIST_ENABLED, '0') # Wait for the child to attach back @@ -171,9 +166,8 @@ time.sleep(PARENT_SUPERVISION_INTERVAL * 1.2 / speedup) # used. Note that supervision interval on parent is set to 1 sec. verify( - int(parent.get("NCP:Counter:TX_PKT_UNICAST"), 0) - >= parent_unicast_tx_count + 1 -) + int(parent.get("NCP:Counter:TX_PKT_UNICAST"), 0) >= + parent_unicast_tx_count + 1) verify(child.is_associated()) diff --git a/tests/toranj/test-019-inform-previous-parent.py b/tests/toranj/test-019-inform-previous-parent.py index d88451c11..d82d995e8 100644 --- a/tests/toranj/test-019-inform-previous-parent.py +++ b/tests/toranj/test-019-inform-previous-parent.py @@ -119,9 +119,8 @@ child.set( wpan.WPAN_CHILD_SUPERVISION_CHECK_TIMEOUT, str(CHILD_SUPERVISION_CHECK_TIMEOUT), ) -parent1.set( - wpan.WPAN_CHILD_SUPERVISION_INTERVAL, str(PARENT_SUPERVISION_INTERVAL) -) +parent1.set(wpan.WPAN_CHILD_SUPERVISION_INTERVAL, + str(PARENT_SUPERVISION_INTERVAL)) # Since child supervision is not enabled on `parent2` and the `child` is # removed from whitelist on `parent2`, after the supervision check timeout @@ -138,14 +137,12 @@ child_num_state_changes = len(wpan.parse_list(child.get("stat:ncp"))) def check_child_is_reattached(): verify( - len(wpan.parse_list(child.get("stat:ncp"))) > child_num_state_changes - ) + len(wpan.parse_list(child.get("stat:ncp"))) > child_num_state_changes) verify(child.is_associated()) -wpan.verify_within( - check_child_is_reattached, CHILD_SUPERVISION_CHECK_TIMEOUT / speedup + 5 -) +wpan.verify_within(check_child_is_reattached, + CHILD_SUPERVISION_CHECK_TIMEOUT / speedup + 5) # Verify that the `child` is now attached to `parent1` child_table = wpan.parse_list(parent1.get(wpan.WPAN_THREAD_CHILD_TABLE)) diff --git a/tests/toranj/test-020-router-table.py b/tests/toranj/test-020-router-table.py index 0c9ac3cdf..41b98f538 100644 --- a/tests/toranj/test-020-router-table.py +++ b/tests/toranj/test-020-router-table.py @@ -123,8 +123,7 @@ INVALID_ROUTER_ID = 63 def check_r1_router_table(): router_table = wpan.parse_router_table_result( - r1.get(wpan.WPAN_THREAD_ROUTER_TABLE) - ) + r1.get(wpan.WPAN_THREAD_ROUTER_TABLE)) verify(len(router_table) == 4) for entry in router_table: if entry.rloc16 == r1_rloc: @@ -150,8 +149,7 @@ wpan.verify_within(check_r1_router_table, WAIT_TIME) def check_r3_router_table(): router_table = wpan.parse_router_table_result( - r3.get(wpan.WPAN_THREAD_ROUTER_TABLE) - ) + r3.get(wpan.WPAN_THREAD_ROUTER_TABLE)) verify(len(router_table) == 4) for entry in router_table: if entry.rloc16 == r1_rloc: @@ -177,8 +175,7 @@ wpan.verify_within(check_r3_router_table, WAIT_TIME) def check_r4_router_table(): router_table = wpan.parse_router_table_result( - r4.get(wpan.WPAN_THREAD_ROUTER_TABLE) - ) + r4.get(wpan.WPAN_THREAD_ROUTER_TABLE)) verify(len(router_table) == 4) for entry in router_table: if entry.rloc16 == r1_rloc: diff --git a/tests/toranj/test-021-address-cache-table.py b/tests/toranj/test-021-address-cache-table.py index 84b611d4c..8aee1d3d8 100644 --- a/tests/toranj/test-021-address-cache-table.py +++ b/tests/toranj/test-021-address-cache-table.py @@ -125,8 +125,7 @@ c3_rloc = int(c3.get(wpan.WPAN_THREAD_RLOC16), 16) def check_r1_router_table(): router_table = wpan.parse_router_table_result( - r1.get(wpan.WPAN_THREAD_ROUTER_TABLE) - ) + r1.get(wpan.WPAN_THREAD_ROUTER_TABLE)) verify(len(router_table) == 3) for entry in router_table: if entry.rloc16 == r3_rloc: @@ -158,8 +157,7 @@ verify(sender.was_successful and recver.was_successful) # c2 and c3 addresses. addr_cache_table = wpan.parse_address_cache_table_result( - r1.get(wpan.WPAN_THREAD_ADDRESS_CACHE_TABLE) -) + r1.get(wpan.WPAN_THREAD_ADDRESS_CACHE_TABLE)) verify(len(addr_cache_table) == 2) for entry in addr_cache_table: @@ -231,8 +229,7 @@ verify(sender.was_successful and recver.was_successful) # The address cache table on r1 should still be the same as before. addr_cache_table = wpan.parse_address_cache_table_result( - r1.get(wpan.WPAN_THREAD_ADDRESS_CACHE_TABLE) -) + r1.get(wpan.WPAN_THREAD_ADDRESS_CACHE_TABLE)) verify(len(addr_cache_table) == 2) for entry in addr_cache_table: @@ -259,8 +256,7 @@ verify(sender.was_successful and recver.was_successful) # verify that the address cache table is updated correctly. addr_cache_table = wpan.parse_address_cache_table_result( - r1.get(wpan.WPAN_THREAD_ADDRESS_CACHE_TABLE) -) + r1.get(wpan.WPAN_THREAD_ADDRESS_CACHE_TABLE)) verify(len(addr_cache_table) == 2) for entry in addr_cache_table: diff --git a/tests/toranj/test-022-multicast-ip6-address.py b/tests/toranj/test-022-multicast-ip6-address.py index 3db89defa..77becad0d 100644 --- a/tests/toranj/test-022-multicast-ip6-address.py +++ b/tests/toranj/test-022-multicast-ip6-address.py @@ -98,7 +98,6 @@ ml_prefix = router.get(wpan.WPAN_IP6_MESH_LOCAL_PREFIX)[1:-1].split('/')[0] ll_all_thread_nodes_addr = 'ff32:40:' + ml_prefix + '1' rl_all_thread_nodes_addr = 'ff33:40:' + ml_prefix + '1' - # List of multicast addresses subscribed by all nodes mcast_addrs = [ "ff02::1", # All nodes link-local diff --git a/tests/toranj/test-023-multicast-traffic.py b/tests/toranj/test-023-multicast-traffic.py index 1467423c5..0580535a8 100644 --- a/tests/toranj/test-023-multicast-traffic.py +++ b/tests/toranj/test-023-multicast-traffic.py @@ -74,9 +74,10 @@ def send_mcast( Verify that the message is received on all nodes in `recving_nodes` list and that it is not received on all nodes in `non_recving_nodes` list. """ - sender = src_node.prepare_tx( - src_addr, mcast_addr, msg_len, mcast_hops=mcast_hops - ) + sender = src_node.prepare_tx(src_addr, + mcast_addr, + msg_len, + mcast_hops=mcast_hops) recvers = [node.prepare_rx(sender) for node in recving_nodes] listeners = [ node.prepare_listener(sender.dst_port, timeout=0.5) @@ -91,15 +92,10 @@ def send_mcast( for lsnr in listeners: # `all_rx_msg` contains a list of (msg_content, (src_addr, src_port)). verify( - len(lsnr.all_rx_msg) == 0 - or all( - [ - msg[1][0] != sender.src_addr - and msg[1][1] != sender.src_port - for msg in lsnr.all_rx_msg - ] - ) - ) + len(lsnr.all_rx_msg) == 0 or all([ + msg[1][0] != sender.src_addr and msg[1][1] != sender.src_port + for msg in lsnr.all_rx_msg + ])) # ----------------------------------------------------------------------------------------------------------------------- @@ -252,9 +248,10 @@ send_mcast( ) # r1 =>> mesh-local all-thread (four hops) -send_mcast( - r1, ml1, ml_all_thread_nodes_addr, [r1, r2, fed, r3, r4, sed], mcast_hops=4 -) +send_mcast(r1, + ml1, + ml_all_thread_nodes_addr, [r1, r2, fed, r3, r4, sed], + mcast_hops=4) # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # Subscribe to a specific multicast address on r2 and sed diff --git a/tests/toranj/test-024-partition-merge.py b/tests/toranj/test-024-partition-merge.py index 55899f0c8..5a16822af 100644 --- a/tests/toranj/test-024-partition-merge.py +++ b/tests/toranj/test-024-partition-merge.py @@ -49,7 +49,6 @@ from wpan import verify # merge the info in combined. # - test_name = __file__[:-3] if __file__.endswith('.py') else __file__ print('-' * 120) print('Starting \'{}\''.format(test_name)) @@ -76,8 +75,7 @@ def verify_prefix( """ for node in node_list: prefixes = wpan.parse_on_mesh_prefix_result( - node.get(wpan.WPAN_THREAD_ON_MESH_PREFIXES) - ) + node.get(wpan.WPAN_THREAD_ON_MESH_PREFIXES)) for p in prefixes: if p.prefix == prefix: verify(int(p.prefix_len) == prefix_len) @@ -91,9 +89,8 @@ def verify_prefix( verify(p.priority == priority) break else: - raise wpan.VerifyError( - "Did not find prefix {} on node {}".format(prefix, node) - ) + raise wpan.VerifyError("Did not find prefix {} on node {}".format( + prefix, node)) # ----------------------------------------------------------------------------------------------------------------------- @@ -183,12 +180,9 @@ def check_r1_r2_roles(): r1_type = r1.get(wpan.WPAN_NODE_TYPE) r2_type = r2.get(wpan.WPAN_NODE_TYPE) verify( - (r1_type == wpan.NODE_TYPE_LEADER and r2_type == wpan.NODE_TYPE_ROUTER) - or ( - r2_type == wpan.NODE_TYPE_LEADER - and r1_type == wpan.NODE_TYPE_ROUTER - ) - ) + (r1_type == wpan.NODE_TYPE_LEADER and + r2_type == wpan.NODE_TYPE_ROUTER) or + (r2_type == wpan.NODE_TYPE_LEADER and r1_type == wpan.NODE_TYPE_ROUTER)) wpan.verify_within(check_r1_r2_roles, short_wait) diff --git a/tests/toranj/test-025-network-data-timeout.py b/tests/toranj/test-025-network-data-timeout.py index 2cab044d4..c25551218 100644 --- a/tests/toranj/test-025-network-data-timeout.py +++ b/tests/toranj/test-025-network-data-timeout.py @@ -74,14 +74,10 @@ def verify_prefix( """ for node in node_list: prefixes = wpan.parse_on_mesh_prefix_result( - node.get(wpan.WPAN_THREAD_ON_MESH_PREFIXES) - ) + 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 - ): + 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) @@ -93,9 +89,8 @@ def verify_prefix( verify(p.priority == priority) break else: - raise wpan.VerifyError( - "Did not find prefix {} on node {}".format(prefix, node) - ) + raise wpan.VerifyError("Did not find prefix {} on node {}".format( + prefix, node)) def verify_no_prefix(node_list, prefix, rloc16): @@ -105,19 +100,13 @@ def verify_no_prefix(node_list, prefix, rloc16): """ for node in node_list: prefixes = wpan.parse_on_mesh_prefix_result( - node.get(wpan.WPAN_THREAD_ON_MESH_PREFIXES) - ) + 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 - ): + 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 - ) - ) + prefix, hex(rloc16), node)) # ----------------------------------------------------------------------------------------------------------------------- @@ -246,9 +235,12 @@ r2.leave() def check_prefixes_on_r1_after_r2_leave(): # Verify that entries added by r1 are still present - verify_prefix( - [r1], prefix1, r1_rloc, on_mesh=True, preferred=True, stable=True - ) + verify_prefix([r1], + prefix1, + r1_rloc, + on_mesh=True, + preferred=True, + stable=True) verify_prefix( [r1], common_prefix, diff --git a/tests/toranj/test-026-slaac-address-wpantund.py b/tests/toranj/test-026-slaac-address-wpantund.py index ab435a780..c9b218e19 100644 --- a/tests/toranj/test-026-slaac-address-wpantund.py +++ b/tests/toranj/test-026-slaac-address-wpantund.py @@ -80,26 +80,21 @@ def verify_prefix( """ for node in node_list: prefixes = wpan.parse_on_mesh_prefix_result( - node.get(wpan.WPAN_THREAD_ON_MESH_PREFIXES) - ) + 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 - ): + 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) - ) + raise wpan.VerifyError("Did not find prefix {} on node {}".format( + prefix, node)) def verify_no_prefix(node_list, prefix): @@ -108,8 +103,7 @@ def verify_no_prefix(node_list, prefix): """ for node in node_list: prefixes = wpan.parse_on_mesh_prefix_result( - node.get(wpan.WPAN_THREAD_ON_MESH_PREFIXES) - ) + node.get(wpan.WPAN_THREAD_ON_MESH_PREFIXES)) for p in prefixes: verify(not p.prefix == prefix) diff --git a/tests/toranj/test-027-child-mode-change.py b/tests/toranj/test-027-child-mode-change.py index 447e1f4b8..720463d5a 100644 --- a/tests/toranj/test-027-child-mode-change.py +++ b/tests/toranj/test-027-child-mode-change.py @@ -47,8 +47,7 @@ def verify_child_table(parent, children): table entry's mode value matches the children Thread mode. """ child_table = wpan.parse_child_table_result( - parent.get(wpan.WPAN_THREAD_CHILD_TABLE) - ) + 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] @@ -57,33 +56,22 @@ def verify_child_table(parent, children): break else: raise wpan.VerifyError( - 'Failed to find a child entry for extended address {} in table'.format( - ext_addr - ) - ) + '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) - ) + 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) - ) + 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)) # ----------------------------------------------------------------------------------------------------------------------- @@ -121,16 +109,12 @@ children = [child1, child2] WAIT_INTERVAL = 6 # Thread Mode for end-device and sleepy end-device -DEVICE_MODE_SLEEPY_END_DEVICE = ( - wpan.THREAD_MODE_FLAG_FULL_NETWORK_DATA - | wpan.THREAD_MODE_FLAG_SECURE_DATA_REQUEST -) -DEVICE_MODE_END_DEVICE = ( - wpan.THREAD_MODE_FLAG_FULL_NETWORK_DATA - | wpan.THREAD_MODE_FLAG_FULL_THREAD_DEV - | wpan.THREAD_MODE_FLAG_SECURE_DATA_REQUEST - | wpan.THREAD_MODE_FLAG_RX_ON_WHEN_IDLE -) +DEVICE_MODE_SLEEPY_END_DEVICE = (wpan.THREAD_MODE_FLAG_FULL_NETWORK_DATA | + wpan.THREAD_MODE_FLAG_SECURE_DATA_REQUEST) +DEVICE_MODE_END_DEVICE = (wpan.THREAD_MODE_FLAG_FULL_NETWORK_DATA | + wpan.THREAD_MODE_FLAG_FULL_THREAD_DEV | + wpan.THREAD_MODE_FLAG_SECURE_DATA_REQUEST | + wpan.THREAD_MODE_FLAG_RX_ON_WHEN_IDLE) # Disable child supervision on all devices parent.set(wpan.WPAN_CHILD_SUPERVISION_INTERVAL, '0') @@ -139,12 +123,10 @@ child2.set(wpan.WPAN_CHILD_SUPERVISION_CHECK_TIMEOUT, '0') # Verify Thread Device Mode on both children verify( - int(child1.get(wpan.WPAN_THREAD_DEVICE_MODE), 0) == DEVICE_MODE_END_DEVICE -) + int(child1.get(wpan.WPAN_THREAD_DEVICE_MODE), 0) == DEVICE_MODE_END_DEVICE) verify( - int(child2.get(wpan.WPAN_THREAD_DEVICE_MODE), 0) - == DEVICE_MODE_SLEEPY_END_DEVICE -) + int(child2.get(wpan.WPAN_THREAD_DEVICE_MODE), 0) == + DEVICE_MODE_SLEEPY_END_DEVICE) def check_child_table(): @@ -171,14 +153,12 @@ verify(sender.was_successful) child1.set(wpan.WPAN_THREAD_DEVICE_MODE, str(DEVICE_MODE_SLEEPY_END_DEVICE)) verify( - int(child1.get(wpan.WPAN_THREAD_DEVICE_MODE), 0) - == DEVICE_MODE_SLEEPY_END_DEVICE -) + int(child1.get(wpan.WPAN_THREAD_DEVICE_MODE), 0) == + DEVICE_MODE_SLEEPY_END_DEVICE) child2.set(wpan.WPAN_THREAD_DEVICE_MODE, str(DEVICE_MODE_END_DEVICE)) verify( - int(child2.get(wpan.WPAN_THREAD_DEVICE_MODE), 0) == DEVICE_MODE_END_DEVICE -) + int(child2.get(wpan.WPAN_THREAD_DEVICE_MODE), 0) == DEVICE_MODE_END_DEVICE) # Verify that the child table on parent is also updated wpan.verify_within(check_child_table, WAIT_INTERVAL) @@ -186,9 +166,8 @@ wpan.verify_within(check_child_table, WAIT_INTERVAL) def check_child2_received_msg(): verify( - int(child2.get(wpan.WPAN_NCP_COUNTER_RX_IP_SEC_TOTAL), 0) - >= child2_rx_ip_counter + NUM_MSGS - ) + int(child2.get(wpan.WPAN_NCP_COUNTER_RX_IP_SEC_TOTAL), 0) >= + child2_rx_ip_counter + NUM_MSGS) wpan.verify_within(check_child2_received_msg, WAIT_INTERVAL) diff --git a/tests/toranj/test-028-router-leader-reset-recovery.py b/tests/toranj/test-028-router-leader-reset-recovery.py index c07738e08..a159a736d 100644 --- a/tests/toranj/test-028-router-leader-reset-recovery.py +++ b/tests/toranj/test-028-router-leader-reset-recovery.py @@ -46,8 +46,7 @@ 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) - ) + 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: @@ -55,10 +54,8 @@ def verify_neighbor_table(node, neighbors): break else: raise wpan.VerifyError( - 'Failed to find a neighbor entry for extended address {} in table'.format( - ext_addr - ) - ) + 'Failed to find a neighbor entry for extended address {} in table' + .format(ext_addr)) # ----------------------------------------------------------------------------------------------------------------------- @@ -123,7 +120,6 @@ wpan.verify_within(check_r2_neighbor_table, WAIT_INTERVAL) verify(r1.get(wpan.WPAN_NODE_TYPE) == wpan.NODE_TYPE_LEADER) verify(r2.get(wpan.WPAN_NODE_TYPE) == wpan.NODE_TYPE_ROUTER) - # Now reset r1 and check that everything recover correctly. r1.reset() diff --git a/tests/toranj/test-029-data-poll-interval.py b/tests/toranj/test-029-data-poll-interval.py index b4213e3a2..b8b64a84d 100644 --- a/tests/toranj/test-029-data-poll-interval.py +++ b/tests/toranj/test-029-data-poll-interval.py @@ -74,26 +74,20 @@ WAIT_TIME = 0.36 # in seconds for poll_interval in [100, 200, 500, 50]: # in milliseconds - poll_count_before = int( - child.get(wpan.WPAN_NCP_COUNTER_TX_PKT_DATA_POLL), 0 - ) + poll_count_before = int(child.get(wpan.WPAN_NCP_COUNTER_TX_PKT_DATA_POLL), + 0) child.set(wpan.WPAN_POLL_INTERVAL, str(poll_interval)) verify(int(child.get(wpan.WPAN_POLL_INTERVAL), 0) == poll_interval) time.sleep(WAIT_TIME) - poll_count_after = int( - child.get(wpan.WPAN_NCP_COUNTER_TX_PKT_DATA_POLL), 0 - ) + poll_count_after = int(child.get(wpan.WPAN_NCP_COUNTER_TX_PKT_DATA_POLL), 0) actual_polls = poll_count_after - poll_count_before expected_polls = WAIT_TIME * 1000 * speedup / poll_interval - print( - "poll interval {} ms, polls -> actual {}, expected {}".format( - poll_interval, actual_polls, expected_polls - ) - ) + print("poll interval {} ms, polls -> actual {}, expected {}".format( + poll_interval, actual_polls, expected_polls)) verify(actual_polls >= int(expected_polls)) @@ -129,7 +123,6 @@ verify(default_poll_interval < new_default_interval <= child_timeout * 2) child.set(wpan.WPAN_THREAD_CHILD_TIMEOUT, str(child_timeout / 1000)) verify(int(child.get(wpan.WPAN_POLL_INTERVAL), 0) == default_poll_interval) - # ----------------------------------------------------------------------------------------------------------------------- # Test finished diff --git a/tests/toranj/test-030-slaac-address-ncp.py b/tests/toranj/test-030-slaac-address-ncp.py index c6edda1cc..3b532081c 100644 --- a/tests/toranj/test-030-slaac-address-ncp.py +++ b/tests/toranj/test-030-slaac-address-ncp.py @@ -88,26 +88,21 @@ def verify_prefix( """ for node in node_list: prefixes = wpan.parse_on_mesh_prefix_result( - node.get(wpan.WPAN_THREAD_ON_MESH_PREFIXES) - ) + 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 - ): + 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) - ) + raise wpan.VerifyError("Did not find prefix {} on node {}".format( + prefix, node)) def verify_no_prefix(node_list, prefix): @@ -116,8 +111,7 @@ def verify_no_prefix(node_list, prefix): """ for node in node_list: prefixes = wpan.parse_on_mesh_prefix_result( - node.get(wpan.WPAN_THREAD_ON_MESH_PREFIXES) - ) + node.get(wpan.WPAN_THREAD_ON_MESH_PREFIXES)) for p in prefixes: verify(not p.prefix == prefix) @@ -191,10 +185,8 @@ slaac_addrs = [node.find_ip6_address_with_prefix(PREFIX) for node in all_nodes] r1.reset() wpan.verify_within(check_prefix_and_slaac_address_are_added, WAIT_INTERVAL) -verify( - [node.find_ip6_address_with_prefix(PREFIX) for node in all_nodes] - == slaac_addrs -) +verify([node.find_ip6_address_with_prefix(PREFIX) + for node in all_nodes] == slaac_addrs) # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # Remove the prefix on r1 and verify that the address and prefix are @@ -217,28 +209,22 @@ wpan.verify_within(check_prefix_and_slaac_address_are_removed, WAIT_INTERVAL) # Add prefix on r2 r2.add_prefix(PREFIX, stable=True, on_mesh=True, slaac=True) wpan.verify_within(check_prefix_and_slaac_address_are_added, WAIT_INTERVAL) -verify( - [node.find_ip6_address_with_prefix(PREFIX) for node in all_nodes] - == slaac_addrs -) +verify([node.find_ip6_address_with_prefix(PREFIX) + for node in all_nodes] == slaac_addrs) # Add same prefix on r1 and verify prefix and addresses stay as before r1.add_prefix(PREFIX, stable=True, on_mesh=True, slaac=True) wpan.verify_within(check_prefix_and_slaac_address_are_added, WAIT_INTERVAL) -verify( - [node.find_ip6_address_with_prefix(PREFIX) for node in all_nodes] - == slaac_addrs -) +verify([node.find_ip6_address_with_prefix(PREFIX) + for node in all_nodes] == slaac_addrs) # Remove on r1, addresses and prefixes should stay as before (r2 still has # the same prefix) r1.remove_prefix(PREFIX) time.sleep(0.5) wpan.verify_within(check_prefix_and_slaac_address_are_added, WAIT_INTERVAL) -verify( - [node.find_ip6_address_with_prefix(PREFIX) for node in all_nodes] - == slaac_addrs -) +verify([node.find_ip6_address_with_prefix(PREFIX) + for node in all_nodes] == slaac_addrs) # Remove the prefix on r2 and verify that the address and prefix are now # removed on all nodes. @@ -252,10 +238,8 @@ wpan.verify_within(check_prefix_and_slaac_address_are_removed, WAIT_INTERVAL) r1.add_prefix(PREFIX, stable=True, on_mesh=True, slaac=False) r2.add_prefix(PREFIX, stable=True, on_mesh=True, slaac=True) wpan.verify_within(check_prefix_and_slaac_address_are_added, WAIT_INTERVAL) -verify( - [node.find_ip6_address_with_prefix(PREFIX) for node in all_nodes] - == slaac_addrs -) +verify([node.find_ip6_address_with_prefix(PREFIX) + for node in all_nodes] == slaac_addrs) # Now remove the prefix on r2 and verify that SLAAC address is removed r2.remove_prefix(PREFIX) @@ -297,10 +281,8 @@ verify(all([not addr.startswith(PREFIX[:-1]) for addr in r1_addrs])) r1.remove_ip6_address_on_interface(IP_ADDRESS) wpan.verify_within(check_prefix_and_slaac_address_are_added, WAIT_INTERVAL) -verify( - [node.find_ip6_address_with_prefix(PREFIX) for node in all_nodes] - == slaac_addrs -) +verify([node.find_ip6_address_with_prefix(PREFIX) + for node in all_nodes] == slaac_addrs) # Re-add the address r1.add_ip6_address_on_interface(IP_ADDRESS) @@ -329,10 +311,8 @@ r1.remove_ip6_address_on_interface(IP_ADDRESS) r1.add_prefix(PREFIX, stable=True, on_mesh=True, slaac=True) wpan.verify_within(check_prefix_and_slaac_address_are_added, WAIT_INTERVAL) -verify( - [node.find_ip6_address_with_prefix(PREFIX) for node in all_nodes] - == slaac_addrs -) +verify([node.find_ip6_address_with_prefix(PREFIX) + for node in all_nodes] == slaac_addrs) for node in all_nodes: node.set(wpan.WPAN_OT_SLAAC_ENABLED, 'false') @@ -342,10 +322,8 @@ wpan.verify_within(check_slaac_address_is_removed, WAIT_INTERVAL) for node in all_nodes: node.set(wpan.WPAN_OT_SLAAC_ENABLED, 'true') wpan.verify_within(check_prefix_and_slaac_address_are_added, WAIT_INTERVAL) -verify( - [node.find_ip6_address_with_prefix(PREFIX) for node in all_nodes] - == slaac_addrs -) +verify([node.find_ip6_address_with_prefix(PREFIX) + for node in all_nodes] == slaac_addrs) r1.remove_prefix(PREFIX) wpan.verify_within(check_prefix_and_slaac_address_are_removed, WAIT_INTERVAL) @@ -364,10 +342,8 @@ wpan.verify_within(check_slaac_address_is_removed, WAIT_INTERVAL) for node in all_nodes: node.set(wpan.WPAN_OT_SLAAC_ENABLED, 'true') wpan.verify_within(check_prefix_and_slaac_address_are_added, WAIT_INTERVAL) -verify( - [node.find_ip6_address_with_prefix(PREFIX) for node in all_nodes] - == slaac_addrs -) +verify([node.find_ip6_address_with_prefix(PREFIX) + for node in all_nodes] == slaac_addrs) # ----------------------------------------------------------------------------------------------------------------------- # Test finished diff --git a/tests/toranj/test-031-meshcop-joiner-commissioner.py b/tests/toranj/test-031-meshcop-joiner-commissioner.py index f06e560fc..7160c6aec 100644 --- a/tests/toranj/test-031-meshcop-joiner-commissioner.py +++ b/tests/toranj/test-031-meshcop-joiner-commissioner.py @@ -39,7 +39,6 @@ test_name = __file__[:-3] if __file__.endswith('.py') else __file__ print('-' * 120) print('Starting \'{}\''.format(test_name)) - # ----------------------------------------------------------------------------------------------------------------------- # Creating `wpan.Nodes` instances diff --git a/tests/toranj/test-032-child-attach-with-multiple-ip-addresses.py b/tests/toranj/test-032-child-attach-with-multiple-ip-addresses.py index 3992b98a9..4dda76897 100644 --- a/tests/toranj/test-032-child-attach-with-multiple-ip-addresses.py +++ b/tests/toranj/test-032-child-attach-with-multiple-ip-addresses.py @@ -121,9 +121,8 @@ def check_addresses_on_child(): wpan.verify_within(check_addresses_on_child, WAIT_TIME) # Remove child from parent's white-list -parent.remove( - wpan.WPAN_MAC_WHITELIST_ENTRIES, child.get(wpan.WPAN_EXT_ADDRESS)[1:-1] -) +parent.remove(wpan.WPAN_MAC_WHITELIST_ENTRIES, + child.get(wpan.WPAN_EXT_ADDRESS)[1:-1]) # Enable supervision check on child, this ensures that child is detached soon. child.set( diff --git a/tests/toranj/test-033-mesh-local-prefix-change.py b/tests/toranj/test-033-mesh-local-prefix-change.py index cbf7f7642..792ac6cf7 100644 --- a/tests/toranj/test-033-mesh-local-prefix-change.py +++ b/tests/toranj/test-033-mesh-local-prefix-change.py @@ -92,9 +92,8 @@ node2.form( verify(node2.is_associated()) verify( - node2.get(wpan.WPAN_IP6_MESH_LOCAL_PREFIX) - == node1.get(wpan.WPAN_IP6_MESH_LOCAL_PREFIX) -) + node2.get(wpan.WPAN_IP6_MESH_LOCAL_PREFIX) == node1.get( + wpan.WPAN_IP6_MESH_LOCAL_PREFIX)) # Ensure that there are only two addresses on the node2 (link-local and mesh-local address) and that RLOC # address is correctly filtered (by wpantund). diff --git a/tests/toranj/test-035-child-timeout-large-data-poll.py b/tests/toranj/test-035-child-timeout-large-data-poll.py index 6753a94a8..02ec362a0 100644 --- a/tests/toranj/test-035-child-timeout-large-data-poll.py +++ b/tests/toranj/test-035-child-timeout-large-data-poll.py @@ -59,7 +59,7 @@ wpan.Node.init_all_nodes() parent.form("poll-timeout") -TIMEOUT = 5 # Child timeout in seconds +TIMEOUT = 5 # Child timeout in seconds child.set(wpan.WPAN_THREAD_CHILD_TIMEOUT, str(TIMEOUT)) diff --git a/tests/toranj/test-036-wpantund-host-route-management.py b/tests/toranj/test-036-wpantund-host-route-management.py index 9049835b2..cd4687629 100644 --- a/tests/toranj/test-036-wpantund-host-route-management.py +++ b/tests/toranj/test-036-wpantund-host-route-management.py @@ -43,7 +43,6 @@ from wpan import verify # - filtering of self added routes is not enabled, and # - it is added at lower preference level. - test_name = __file__[:-3] if __file__.endswith('.py') else __file__ print('-' * 120) print('Starting \'{}\''.format(test_name)) @@ -57,18 +56,19 @@ 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)) + 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: + 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) - ) + raise wpan.VerifyError('Did not find route {} on node {}'.format( + route, node)) # ----------------------------------------------------------------------------------------------------------------------- @@ -100,7 +100,6 @@ wpan.Node.init_all_nodes() # # 3 routers, c3 is added to ensure r3 is promoted to a router quickly! - r1.form("route-test") r1.whitelist_node(r2) @@ -163,8 +162,9 @@ r2.add_route(ROUTE3, prefix_len=LEN3, priority=HIGH_PRIORITY) # We expect to see all 3 routes added on r1 host interface with same priority levels as r2. def check_routes_on_r1_1(): - verify_interface_routes(r1, - [(ROUTE1, LEN1, LOW_METRIC), (ROUTE2, LEN2, MEDIUM_METRIC), (ROUTE3, LEN3, HIGH_METRIC)]) + verify_interface_routes(r1, [(ROUTE1, LEN1, LOW_METRIC), + (ROUTE2, LEN2, MEDIUM_METRIC), + (ROUTE3, LEN3, HIGH_METRIC)]) wpan.verify_within(check_routes_on_r1_1, WAIT_TIME) @@ -178,7 +178,8 @@ r3.add_route(ROUTE2, prefix_len=LEN2, priority=LOW_PRIORITY) # We expect the host interface routes on r1 to change accordingly def check_routes_on_r1_2(): - route_list = [(ROUTE1, LEN1, MEDIUM_METRIC), (ROUTE2, LEN2, MEDIUM_METRIC), (ROUTE3, LEN3, HIGH_METRIC)] + route_list = [(ROUTE1, LEN1, MEDIUM_METRIC), (ROUTE2, LEN2, MEDIUM_METRIC), + (ROUTE3, LEN3, HIGH_METRIC)] verify_interface_routes(r1, route_list) @@ -195,7 +196,8 @@ r2.remove_route(ROUTE3, prefix_len=LEN3) # We expect the host interface routes on r1 to again change accordingly: def check_routes_on_r1_3(): - verify_interface_routes(r1, [(ROUTE1, LEN1, MEDIUM_METRIC), (ROUTE2, LEN2, LOW_METRIC)]) + verify_interface_routes(r1, [(ROUTE1, LEN1, MEDIUM_METRIC), + (ROUTE2, LEN2, LOW_METRIC)]) wpan.verify_within(check_routes_on_r1_3, WAIT_TIME) @@ -213,14 +215,16 @@ verify_interface_routes(r2, []) # - it is added at lower preference level. r1.set(wpan.WPAN_DAEMON_OFF_MESH_ROUTE_FILTER_SELF_AUTO_ADDED, 'false') -verify(r1.get(wpan.WPAN_DAEMON_OFF_MESH_ROUTE_FILTER_SELF_AUTO_ADDED) == 'false') +verify( + r1.get(wpan.WPAN_DAEMON_OFF_MESH_ROUTE_FILTER_SELF_AUTO_ADDED) == 'false') # Add ROUTE1 on r1 with low-priority. Since it's also present on r3 with # medium priority, we should still see the route on host (as medium). r1.add_route(ROUTE1, prefix_len=LEN1, priority=LOW_PRIORITY) -verify_interface_routes(r1, [(ROUTE1, LEN1, MEDIUM_METRIC), (ROUTE2, LEN2, LOW_METRIC)]) +verify_interface_routes(r1, [(ROUTE1, LEN1, MEDIUM_METRIC), + (ROUTE2, LEN2, LOW_METRIC)]) # Now change ROUTE1 on r1 to be same priority as on r2, now the route should # no longer be present on host interface routes. @@ -244,7 +248,8 @@ verify_interface_routes(r1, []) r1.remove_route(ROUTE1, prefix_len=LEN1) r1.remove_route(ROUTE2, prefix_len=LEN2) -verify_interface_routes(r1, [(ROUTE1, LEN1, MEDIUM_METRIC), (ROUTE2, LEN2, LOW_METRIC)]) +verify_interface_routes(r1, [(ROUTE1, LEN1, MEDIUM_METRIC), + (ROUTE2, LEN2, LOW_METRIC)]) verify_interface_routes(r2, []) @@ -261,7 +266,8 @@ verify_interface_routes(r1, [(ROUTE2, LEN2, LOW_METRIC)]) r1.remove_route(ROUTE1, prefix_len=LEN1) -verify_interface_routes(r1, [(ROUTE1, LEN1, MEDIUM_METRIC), (ROUTE2, LEN2, LOW_METRIC)]) +verify_interface_routes(r1, [(ROUTE1, LEN1, MEDIUM_METRIC), + (ROUTE2, LEN2, LOW_METRIC)]) verify_interface_routes(r2, []) diff --git a/tests/toranj/test-037-wpantund-auto-add-route-for-on-mesh-prefix.py b/tests/toranj/test-037-wpantund-auto-add-route-for-on-mesh-prefix.py index 5cc259e24..acb84f789 100644 --- a/tests/toranj/test-037-wpantund-auto-add-route-for-on-mesh-prefix.py +++ b/tests/toranj/test-037-wpantund-auto-add-route-for-on-mesh-prefix.py @@ -52,18 +52,19 @@ 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)) + 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: + 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) - ) + raise wpan.VerifyError('Did not find route {} on node {}'.format( + route, node)) # ----------------------------------------------------------------------------------------------------------------------- @@ -120,7 +121,9 @@ MEDIUM_PRIORITY = 0 WAIT_TIME = 10 # Verify the default daemon configuration -verify(r1.get(wpan.WPAN_DAEMON_ON_MESH_PREFIX_AUTO_ADD_AS_INTERFACE_ROUTE) == 'true') +verify( + r1.get(wpan.WPAN_DAEMON_ON_MESH_PREFIX_AUTO_ADD_AS_INTERFACE_ROUTE) == + 'true') r1.set(wpan.WPAN_DAEMON_OFF_MESH_ROUTE_AUTO_ADD_ON_INTERFACE, 'false') verify(r1.get(wpan.WPAN_DAEMON_OFF_MESH_ROUTE_AUTO_ADD_ON_INTERFACE) == 'false') @@ -134,7 +137,8 @@ r2.add_route(ROUTE5, prefix_len=LEN5, priority=MEDIUM_PRIORITY) # We expect to only see routes associated the first two (which are on-mesh) on r1. def check_routes_on_r1_is_prefix1_and_prefix2(): - verify_interface_routes(r1, [(PREFIX1, LEN1, MEDIUM_METRIC), (PREFIX2, LEN2, MEDIUM_METRIC)]) + verify_interface_routes(r1, [(PREFIX1, LEN1, MEDIUM_METRIC), + (PREFIX2, LEN2, MEDIUM_METRIC)]) wpan.verify_within(check_routes_on_r1_is_prefix1_and_prefix2, WAIT_TIME) @@ -179,14 +183,14 @@ wpan.verify_within(check_routes_on_r1_is_empty, WAIT_TIME) r1.set(wpan.WPAN_DAEMON_OFF_MESH_ROUTE_AUTO_ADD_ON_INTERFACE, 'true') verify(r1.get(wpan.WPAN_DAEMON_OFF_MESH_ROUTE_AUTO_ADD_ON_INTERFACE) == 'true') - r2.add_route(ROUTE5, prefix_len=LEN5, priority=MEDIUM_PRIORITY) r2.add_route(ROUTE4, prefix_len=LEN4, priority=MEDIUM_PRIORITY) r1.add_prefix(PREFIX3, prefix_len=LEN3, on_mesh=True, slaac=False) def check_routes_on_r1_is_prefix3_route4_and_route5(): - route_list = [(PREFIX3, LEN3, MEDIUM_METRIC), (ROUTE4, LEN4, MEDIUM_METRIC), (ROUTE5, LEN5, MEDIUM_METRIC)] + route_list = [(PREFIX3, LEN3, MEDIUM_METRIC), (ROUTE4, LEN4, MEDIUM_METRIC), + (ROUTE5, LEN5, MEDIUM_METRIC)] verify_interface_routes(r1, route_list) @@ -206,7 +210,9 @@ wpan.verify_within(check_routes_on_r1_is_only_route4, WAIT_TIME) # Test behavior when feature is disabled r1.set(wpan.WPAN_DAEMON_ON_MESH_PREFIX_AUTO_ADD_AS_INTERFACE_ROUTE, 'false') -verify(r1.get(wpan.WPAN_DAEMON_ON_MESH_PREFIX_AUTO_ADD_AS_INTERFACE_ROUTE) == 'false') +verify( + r1.get(wpan.WPAN_DAEMON_ON_MESH_PREFIX_AUTO_ADD_AS_INTERFACE_ROUTE) == + 'false') r1.add_prefix(PREFIX3, prefix_len=LEN3, on_mesh=True, slaac=False) wpan.verify_within(check_routes_on_r1_is_only_route4, WAIT_TIME) diff --git a/tests/toranj/test-038-clear-address-cache-for-sed.py b/tests/toranj/test-038-clear-address-cache-for-sed.py index 706a4edec..76f613a78 100644 --- a/tests/toranj/test-038-clear-address-cache-for-sed.py +++ b/tests/toranj/test-038-clear-address-cache-for-sed.py @@ -119,7 +119,6 @@ recver = c.prepare_rx(sender) wpan.Node.perform_async_tx_rx() verify(sender.was_successful and recver.was_successful) - # Force c to switch its parent from r2 to r1 # # r3 ---- r1 ---- r2 @@ -132,7 +131,8 @@ PARENT_SUPERVISION_INTERVAL = 1 REATTACH_WAIT_TIME = CHILD_SUPERVISION_CHECK_TIMEOUT / speedup + 6 -c.set(wpan.WPAN_CHILD_SUPERVISION_CHECK_TIMEOUT, str(CHILD_SUPERVISION_CHECK_TIMEOUT)) +c.set(wpan.WPAN_CHILD_SUPERVISION_CHECK_TIMEOUT, + str(CHILD_SUPERVISION_CHECK_TIMEOUT)) r2.set(wpan.WPAN_CHILD_SUPERVISION_INTERVAL, str(PARENT_SUPERVISION_INTERVAL)) r1.set(wpan.WPAN_CHILD_SUPERVISION_INTERVAL, str(PARENT_SUPERVISION_INTERVAL)) r3.set(wpan.WPAN_CHILD_SUPERVISION_INTERVAL, str(PARENT_SUPERVISION_INTERVAL)) @@ -164,7 +164,6 @@ recver = c.prepare_rx(sender) wpan.Node.perform_async_tx_rx() verify(sender.was_successful and recver.was_successful) - # Force c to switch its parent from r1 to r3 # # r3 ---- r1 ---- r2 @@ -186,7 +185,6 @@ def check_c_is_removed_from_r1_child_table(): wpan.verify_within(check_c_is_removed_from_r1_child_table, REATTACH_WAIT_TIME) - # check that c is now a child of r3 (r3 should have two child, c and c3) child_table = wpan.parse_list(r3.get(wpan.WPAN_THREAD_CHILD_TABLE)) verify(len(child_table) == 2) @@ -197,13 +195,11 @@ verify(len(child_table) == 2) # r1 will still have an entry pointing to r2, and r2 will have an entry # pointing to r1, thus creating a loop (the msg will not be delivered to r3) - sender = r1.prepare_tx(r1_address, c_address, "Hi from r1 to c") recver = c.prepare_rx(sender) wpan.Node.perform_async_tx_rx() verify(sender.was_successful and recver.was_successful) - # ----------------------------------------------------------------------------------------------------------------------- # Test finished diff --git a/tests/toranj/test-100-mcu-power-state.py b/tests/toranj/test-100-mcu-power-state.py index db5aa620b..c430b9d6e 100644 --- a/tests/toranj/test-100-mcu-power-state.py +++ b/tests/toranj/test-100-mcu-power-state.py @@ -84,27 +84,23 @@ verify(node.is_associated()) node.set(wpan.WPAN_NCP_MCU_POWER_STATE, 'low-power') verify( - node.get(wpan.WPAN_NCP_MCU_POWER_STATE) == wpan.MCU_POWER_STATE_LOW_POWER -) + node.get(wpan.WPAN_NCP_MCU_POWER_STATE) == wpan.MCU_POWER_STATE_LOW_POWER) verify(node.get(wpan.WPAN_STATE) == wpan.STATE_ASSOCIATED) node.set(wpan.WPAN_NCP_MCU_POWER_STATE, 'on') verify(node.get(wpan.WPAN_NCP_MCU_POWER_STATE) == wpan.MCU_POWER_STATE_ON) -node.set( - wpan.WPAN_NCP_MCU_POWER_STATE, 'lp' -) # special short-form string for low-power +node.set(wpan.WPAN_NCP_MCU_POWER_STATE, + 'lp') # special short-form string for low-power verify( - node.get(wpan.WPAN_NCP_MCU_POWER_STATE) == wpan.MCU_POWER_STATE_LOW_POWER -) + node.get(wpan.WPAN_NCP_MCU_POWER_STATE) == wpan.MCU_POWER_STATE_LOW_POWER) node.set(wpan.WPAN_NCP_MCU_POWER_STATE, wpan.MCU_POWER_STATE_ON) verify(node.get(wpan.WPAN_NCP_MCU_POWER_STATE) == wpan.MCU_POWER_STATE_ON) node.set(wpan.WPAN_NCP_MCU_POWER_STATE, wpan.MCU_POWER_STATE_LOW_POWER) verify( - node.get(wpan.WPAN_NCP_MCU_POWER_STATE) == wpan.MCU_POWER_STATE_LOW_POWER -) + node.get(wpan.WPAN_NCP_MCU_POWER_STATE) == wpan.MCU_POWER_STATE_LOW_POWER) verify(node.get(wpan.WPAN_STATE) == wpan.STATE_ASSOCIATED) # Verify that `wpantund` will restore the user-set value after NCP reset @@ -112,8 +108,7 @@ verify(node.get(wpan.WPAN_STATE) == wpan.STATE_ASSOCIATED) node.reset() time.sleep(1) verify( - node.get(wpan.WPAN_NCP_MCU_POWER_STATE) == wpan.MCU_POWER_STATE_LOW_POWER -) + node.get(wpan.WPAN_NCP_MCU_POWER_STATE) == wpan.MCU_POWER_STATE_LOW_POWER) node.set(wpan.WPAN_NCP_MCU_POWER_STATE, wpan.MCU_POWER_STATE_ON) # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -135,8 +130,7 @@ wpan.verify_within(check_wpan_is_in_deep_sleep_state, WAIT_TIME) node.get(wpan.WPAN_THREAD_RLOC16) verify( - node.get(wpan.WPAN_NCP_MCU_POWER_STATE) == wpan.MCU_POWER_STATE_LOW_POWER -) + node.get(wpan.WPAN_NCP_MCU_POWER_STATE) == wpan.MCU_POWER_STATE_LOW_POWER) verify(node.get(wpan.WPAN_STATE) == wpan.STATE_DEEP_SLEEP) # Setting the power state to `on` should change wpantund state to `OFFLINE` @@ -150,8 +144,7 @@ wpan.verify_within(check_wpan_is_in_offline_state, WAIT_TIME) node.wpanctl('begin-low-power') wpan.verify_within(check_wpan_is_in_deep_sleep_state, WAIT_TIME) verify( - node.get(wpan.WPAN_NCP_MCU_POWER_STATE) == wpan.MCU_POWER_STATE_LOW_POWER -) + node.get(wpan.WPAN_NCP_MCU_POWER_STATE) == wpan.MCU_POWER_STATE_LOW_POWER) node.set(wpan.WPAN_NCP_MCU_POWER_STATE, wpan.MCU_POWER_STATE_ON) wpan.verify_within(check_wpan_is_in_offline_state, WAIT_TIME) @@ -166,8 +159,7 @@ node.set('Daemon:AutoAssociateAfterReset', '0') # does not change the state. node.wpanctl('begin-low-power') verify( - node.get(wpan.WPAN_NCP_MCU_POWER_STATE) == wpan.MCU_POWER_STATE_LOW_POWER -) + node.get(wpan.WPAN_NCP_MCU_POWER_STATE) == wpan.MCU_POWER_STATE_LOW_POWER) verify(node.get(wpan.WPAN_STATE) == wpan.STATE_ASSOCIATED) # After reset, power state should remain `LOW_POWER` (wpantund would restore the value @@ -199,8 +191,7 @@ node.set('Daemon:Enabled', 'false') verify(node.get('Daemon:Enabled') == 'false') wpan.verify_within(check_wpan_is_in_deep_sleep_state, WAIT_TIME) verify( - node.get(wpan.WPAN_NCP_MCU_POWER_STATE) == wpan.MCU_POWER_STATE_LOW_POWER -) + node.get(wpan.WPAN_NCP_MCU_POWER_STATE) == wpan.MCU_POWER_STATE_LOW_POWER) # Enabling `wpantund` should update the `MCU_POWER_STATE` back to `ON`. node.set('Daemon:Enabled', 'true') @@ -219,8 +210,7 @@ node.set('Daemon:Enabled', 'false') verify(node.get('Daemon:Enabled') == 'false') wpan.verify_within(check_wpan_is_in_deep_sleep_state, WAIT_TIME) verify( - node.get(wpan.WPAN_NCP_MCU_POWER_STATE) == wpan.MCU_POWER_STATE_LOW_POWER -) + node.get(wpan.WPAN_NCP_MCU_POWER_STATE) == wpan.MCU_POWER_STATE_LOW_POWER) node.set('Daemon:Enabled', 'true') wpan.verify_within(check_wpan_is_in_commissioned_state, WAIT_TIME) @@ -236,14 +226,12 @@ node.set('Daemon:AutoAssociateAfterReset', '1') node.set(wpan.WPAN_NCP_MCU_POWER_STATE, wpan.MCU_POWER_STATE_LOW_POWER) verify( - node.get(wpan.WPAN_NCP_MCU_POWER_STATE) == wpan.MCU_POWER_STATE_LOW_POWER -) + node.get(wpan.WPAN_NCP_MCU_POWER_STATE) == wpan.MCU_POWER_STATE_LOW_POWER) node.form("resume-test") verify(node.is_associated()) verify( - node.get(wpan.WPAN_NCP_MCU_POWER_STATE) == wpan.MCU_POWER_STATE_LOW_POWER -) + node.get(wpan.WPAN_NCP_MCU_POWER_STATE) == wpan.MCU_POWER_STATE_LOW_POWER) node.reset() @@ -253,8 +241,7 @@ node.reset() wpan.verify_within(check_wpan_is_in_associating_state, WAIT_TIME) verify( - node.get(wpan.WPAN_NCP_MCU_POWER_STATE) == wpan.MCU_POWER_STATE_LOW_POWER -) + node.get(wpan.WPAN_NCP_MCU_POWER_STATE) == wpan.MCU_POWER_STATE_LOW_POWER) # ----------------------------------------------------------------------------------------------------------------------- # Test finished diff --git a/tests/toranj/test-600-channel-manager-properties.py b/tests/toranj/test-600-channel-manager-properties.py index 8e9f72d4d..d4bf7e7e6 100644 --- a/tests/toranj/test-600-channel-manager-properties.py +++ b/tests/toranj/test-600-channel-manager-properties.py @@ -75,41 +75,33 @@ node.set(wpan.WPAN_CHANNEL_MANAGER_AUTO_SELECT_ENABLED, '0') verify(node.get(wpan.WPAN_CHANNEL_MANAGER_AUTO_SELECT_ENABLED) == 'false') node.set(wpan.WPAN_CHANNEL_MANAGER_AUTO_SELECT_INTERVAL, '1000') -verify( - int(node.get(wpan.WPAN_CHANNEL_MANAGER_AUTO_SELECT_INTERVAL), 0) == 1000 -) +verify(int(node.get(wpan.WPAN_CHANNEL_MANAGER_AUTO_SELECT_INTERVAL), 0) == 1000) all_channls_mask = int('0x7fff800', 0) chan_11_mask = int('0x800', 0) chan_11_to_13_mask = int('0x3800', 0) -node.set( - wpan.WPAN_CHANNEL_MANAGER_SUPPORTED_CHANNEL_MASK, str(all_channls_mask) -) +node.set(wpan.WPAN_CHANNEL_MANAGER_SUPPORTED_CHANNEL_MASK, + str(all_channls_mask)) verify( - int(node.get(wpan.WPAN_CHANNEL_MANAGER_SUPPORTED_CHANNEL_MASK), 0) - == all_channls_mask -) + int(node.get(wpan.WPAN_CHANNEL_MANAGER_SUPPORTED_CHANNEL_MASK), 0) == + all_channls_mask) node.set(wpan.WPAN_CHANNEL_MANAGER_FAVORED_CHANNEL_MASK, str(chan_11_mask)) verify( - int(node.get(wpan.WPAN_CHANNEL_MANAGER_FAVORED_CHANNEL_MASK), 0) - == chan_11_mask -) + int(node.get(wpan.WPAN_CHANNEL_MANAGER_FAVORED_CHANNEL_MASK), 0) == + chan_11_mask) -node.set( - wpan.WPAN_CHANNEL_MANAGER_SUPPORTED_CHANNEL_MASK, str(chan_11_to_13_mask) -) +node.set(wpan.WPAN_CHANNEL_MANAGER_SUPPORTED_CHANNEL_MASK, + str(chan_11_to_13_mask)) verify( - int(node.get(wpan.WPAN_CHANNEL_MANAGER_SUPPORTED_CHANNEL_MASK), 0) - == chan_11_to_13_mask -) + int(node.get(wpan.WPAN_CHANNEL_MANAGER_SUPPORTED_CHANNEL_MASK), 0) == + chan_11_to_13_mask) node.set(wpan.WPAN_CHANNEL_MANAGER_FAVORED_CHANNEL_MASK, str(all_channls_mask)) verify( - int(node.get(wpan.WPAN_CHANNEL_MANAGER_FAVORED_CHANNEL_MASK), 0) - == all_channls_mask -) + int(node.get(wpan.WPAN_CHANNEL_MANAGER_FAVORED_CHANNEL_MASK), 0) == + all_channls_mask) node.set(wpan.WPAN_CHANNEL_MANAGER_AUTO_SELECT_ENABLED, '1') verify(node.get(wpan.WPAN_CHANNEL_MANAGER_AUTO_SELECT_ENABLED) == 'true') @@ -123,26 +115,19 @@ wait_time = 20 while node.get(wpan.WPAN_STATE) != wpan.STATE_ASSOCIATED: if time.time() - start_time > wait_time: - print( - 'Took too long to restore after reset ({}>{} sec)'.format( - time.time() - start_time, wait_time - ) - ) + print('Took too long to restore after reset ({}>{} sec)'.format( + time.time() - start_time, wait_time)) exit(1) time.sleep(2) verify(node.get(wpan.WPAN_CHANNEL_MANAGER_AUTO_SELECT_ENABLED) == 'true') verify( - int(node.get(wpan.WPAN_CHANNEL_MANAGER_FAVORED_CHANNEL_MASK), 0) - == all_channls_mask -) + int(node.get(wpan.WPAN_CHANNEL_MANAGER_FAVORED_CHANNEL_MASK), 0) == + all_channls_mask) verify( - int(node.get(wpan.WPAN_CHANNEL_MANAGER_SUPPORTED_CHANNEL_MASK), 0) - == chan_11_to_13_mask -) -verify( - int(node.get(wpan.WPAN_CHANNEL_MANAGER_AUTO_SELECT_INTERVAL), 0) == 1000 -) + int(node.get(wpan.WPAN_CHANNEL_MANAGER_SUPPORTED_CHANNEL_MASK), 0) == + chan_11_to_13_mask) +verify(int(node.get(wpan.WPAN_CHANNEL_MANAGER_AUTO_SELECT_INTERVAL), 0) == 1000) verify(int(node.get(wpan.WPAN_CHANNEL_MANAGER_DELAY), 0) == 180) # ----------------------------------------------------------------------------------------------------------------------- diff --git a/tests/toranj/test-601-channel-manager-channel-change.py b/tests/toranj/test-601-channel-manager-channel-change.py index 561aa30a5..3635ab4e2 100644 --- a/tests/toranj/test-601-channel-manager-channel-change.py +++ b/tests/toranj/test-601-channel-manager-channel-change.py @@ -45,18 +45,13 @@ def verify_channel(nodes, new_channel, wait_time=20): """ start_time = time.time() - while not all( - [ - (new_channel == int(node.get(wpan.WPAN_CHANNEL), 0)) - for node in nodes - ] - ): + while not all([ + (new_channel == int(node.get(wpan.WPAN_CHANNEL), 0)) for node in nodes + ]): if time.time() - start_time > wait_time: - print( - 'Took too long to switch to channel {} ({}>{} sec)'.format( - new_channel, time.time() - start_time, wait_time - ) - ) + print('Took too long to switch to channel {} ({}>{} sec)'.format( + new_channel, + time.time() - start_time, wait_time)) exit(1) time.sleep(0.1) @@ -142,9 +137,8 @@ verify_channel(all_nodes, 16) # Request different channels from two routers (r1 and r2) -r1.set( - wpan.WPAN_CHANNEL_MANAGER_DELAY, '20' -) # increase the time to ensure r1 change is in process +r1.set(wpan.WPAN_CHANNEL_MANAGER_DELAY, + '20') # increase the time to ensure r1 change is in process r1.set(wpan.WPAN_CHANNEL_MANAGER_NEW_CHANNEL, '17') time.sleep(10.5 / speedup) verify_channel(all_nodes, 16) diff --git a/tests/toranj/test-602-channel-manager-channel-select.py b/tests/toranj/test-602-channel-manager-channel-select.py index 253ce03d7..96230cc4b 100644 --- a/tests/toranj/test-602-channel-manager-channel-select.py +++ b/tests/toranj/test-602-channel-manager-channel-select.py @@ -45,18 +45,13 @@ def verify_channel(nodes, new_channel, wait_time=20): """ start_time = time.time() - while not all( - [ - (new_channel == int(node.get(wpan.WPAN_CHANNEL), 0)) - for node in nodes - ] - ): + while not all([ + (new_channel == int(node.get(wpan.WPAN_CHANNEL), 0)) for node in nodes + ]): if time.time() - start_time > wait_time: - print( - 'Took too long to switch to channel {} ({}>{} sec)'.format( - new_channel, time.time() - start_time, wait_time - ) - ) + print('Took too long to switch to channel {} ({}>{} sec)'.format( + new_channel, + time.time() - start_time, wait_time)) exit(1) time.sleep(0.1) @@ -87,13 +82,11 @@ chan_12_to_15_mask = int('0x000f000', 0) chan_15_to_17_mask = int('0x0038000', 0) # Set supported channel mask to be all channels -node.set( - wpan.WPAN_CHANNEL_MANAGER_SUPPORTED_CHANNEL_MASK, str(all_channls_mask) -) +node.set(wpan.WPAN_CHANNEL_MANAGER_SUPPORTED_CHANNEL_MASK, + str(all_channls_mask)) verify( - int(node.get(wpan.WPAN_CHANNEL_MANAGER_SUPPORTED_CHANNEL_MASK), 0) - == all_channls_mask -) + int(node.get(wpan.WPAN_CHANNEL_MANAGER_SUPPORTED_CHANNEL_MASK), 0) == + all_channls_mask) # Sleep for 4.5 second with speedup factor of 10,000 this is more than 12 # hours. @@ -124,12 +117,10 @@ verify_channel([node], 11) # Even though 11 would be best, quality difference between 11 and 12 is not high enough for selection # algorithm to pick an unfavored channel. -node.set( - wpan.WPAN_CHANNEL_MANAGER_FAVORED_CHANNEL_MASK, str(chan_12_to_15_mask) -) -node.set( - wpan.WPAN_CHANNEL_MANAGER_NEW_CHANNEL, '25' -) # request a channel change to 25 +node.set(wpan.WPAN_CHANNEL_MANAGER_FAVORED_CHANNEL_MASK, + str(chan_12_to_15_mask)) +node.set(wpan.WPAN_CHANNEL_MANAGER_NEW_CHANNEL, + '25') # request a channel change to 25 verify_channel([node], 25) node.set(wpan.WPAN_CHANNEL_MANAGER_CHANNEL_SELECT, 'true') verify(int(node.get(wpan.WPAN_CHANNEL_MANAGER_NEW_CHANNEL), 0) == 12) @@ -140,13 +131,11 @@ verify_channel([node], 12) # This time the quality difference between 11 and 15 should be high enough for selection # algorithm to pick the best though unfavored channel (i.e., channel 11). -node.set( - wpan.WPAN_CHANNEL_MANAGER_NEW_CHANNEL, '25' -) # request a channel change to 25 +node.set(wpan.WPAN_CHANNEL_MANAGER_NEW_CHANNEL, + '25') # request a channel change to 25 verify_channel([node], 25) -node.set( - wpan.WPAN_CHANNEL_MANAGER_FAVORED_CHANNEL_MASK, str(chan_15_to_17_mask) -) +node.set(wpan.WPAN_CHANNEL_MANAGER_FAVORED_CHANNEL_MASK, + str(chan_15_to_17_mask)) node.set(wpan.WPAN_CHANNEL_MANAGER_CHANNEL_SELECT, 'true') verify(int(node.get(wpan.WPAN_CHANNEL_MANAGER_NEW_CHANNEL), 0) == 11) verify_channel([node], 11) @@ -154,9 +143,8 @@ verify_channel([node], 11) # Set channels 12-15 as favorable and request a channel select, verify # that channel is not switched. -node.set( - wpan.WPAN_CHANNEL_MANAGER_FAVORED_CHANNEL_MASK, str(chan_12_to_15_mask) -) +node.set(wpan.WPAN_CHANNEL_MANAGER_FAVORED_CHANNEL_MASK, + str(chan_12_to_15_mask)) node.set(wpan.WPAN_CHANNEL_MANAGER_CHANNEL_SELECT, 'true') verify(int(node.get(wpan.WPAN_CHANNEL_MANAGER_NEW_CHANNEL), 0) == 11) verify_channel([node], 11) @@ -165,9 +153,8 @@ verify_channel([node], 11) # However, since quality difference between current channel 12 and new best channel 11 is not large # enough, no action should be taken. -node.set( - wpan.WPAN_CHANNEL_MANAGER_NEW_CHANNEL, '12' -) # request a channel change to 12 +node.set(wpan.WPAN_CHANNEL_MANAGER_NEW_CHANNEL, + '12') # request a channel change to 12 verify(int(node.get(wpan.WPAN_CHANNEL_MANAGER_NEW_CHANNEL), 0) == 12) verify_channel([node], 12) node.set(wpan.WPAN_CHANNEL_MANAGER_FAVORED_CHANNEL_MASK, str(all_channls_mask)) diff --git a/tests/toranj/test-603-channel-manager-announce-recovery.py b/tests/toranj/test-603-channel-manager-announce-recovery.py index 381f68fba..ce0f62bf2 100644 --- a/tests/toranj/test-603-channel-manager-announce-recovery.py +++ b/tests/toranj/test-603-channel-manager-announce-recovery.py @@ -45,18 +45,13 @@ def verify_channel(nodes, new_channel, wait_time=20): """ start_time = time.time() - while not all( - [ - (new_channel == int(node.get(wpan.WPAN_CHANNEL), 0)) - for node in nodes - ] - ): + while not all([ + (new_channel == int(node.get(wpan.WPAN_CHANNEL), 0)) for node in nodes + ]): if time.time() - start_time > wait_time: - print( - 'Took too long to switch to channel {} ({}>{} sec)'.format( - new_channel, time.time() - start_time, wait_time - ) - ) + print('Took too long to switch to channel {} ({}>{} sec)'.format( + new_channel, + time.time() - start_time, wait_time)) exit(1) time.sleep(0.1) diff --git a/tests/toranj/wpan.py b/tests/toranj/wpan.py index 3eee1ecbc..22b11479f 100644 --- a/tests/toranj/wpan.py +++ b/tests/toranj/wpan.py @@ -264,6 +264,7 @@ def _log(text, new_line=True, flush=True): if flush: sys.stdout.flush() + # ----------------------------------------------------------------------------------------------------------------------- # Node class @@ -273,7 +274,7 @@ class Node(object): # defines the default verbosity setting (can be changed per `Node`) _VERBOSE = False - _SPEED_UP_FACTOR = 1 # defines the default time speed up factor + _SPEED_UP_FACTOR = 1 # defines the default time speed up factor # path to `wpantund`, `wpanctl`, `ot-ncp-ftd`,`ot-ncp` and `ot-rcp` _WPANTUND = '%s/sbin/wpantund' % _WPANTUND_PREFIX @@ -321,10 +322,11 @@ class Node(object): if self._use_posix_app_with_rcp: ncp_socket_path = 'system:{} -s {} {} {}'.format( - self._OT_NCP_FTD_POSIX_APP, self._SPEED_UP_FACTOR, self._OT_RCP, index) + self._OT_NCP_FTD_POSIX_APP, self._SPEED_UP_FACTOR, self._OT_RCP, + index) else: - ncp_socket_path = 'system:{} {} {}'.format( - self._OT_NCP_FTD, index, self._SPEED_UP_FACTOR) + ncp_socket_path = 'system:{} {} {}'.format(self._OT_NCP_FTD, index, + self._SPEED_UP_FACTOR) cmd = self._WPANTUND + \ ' -o Config:NCP:SocketPath \"{}\"'.format(ncp_socket_path) + \ @@ -341,8 +343,9 @@ class Node(object): if self._verbose: _log('$ Node{}.__init__() cmd: {}'.format(index, cmd)) - self._wpantund_process = subprocess.Popen( - cmd, shell=True, stderr=self._tund_log_file) + self._wpantund_process = subprocess.Popen(cmd, + shell=True, + stderr=self._tund_log_file) self._wpanctl_cmd = self._WPANCTL + ' -I ' + self._interface_name + ' ' @@ -383,19 +386,15 @@ class Node(object): """ Runs a wpanctl command on the given wpantund/OT-NCP instance and returns the output """ if self._verbose: - _log( - '$ Node{}.wpanctl(\'{}\')'.format( - self._index, - cmd), - new_line=False) + _log('$ Node{}.wpanctl(\'{}\')'.format(self._index, cmd), + new_line=False) - result = subprocess.check_output( - self._wpanctl_cmd + cmd, - shell=True, - stderr=subprocess.STDOUT) + result = subprocess.check_output(self._wpanctl_cmd + cmd, + shell=True, + stderr=subprocess.STDOUT) - if len( - result) >= 1 and result[-1] == '\n': # remove the last char if it is '\n', + if len(result) >= 1 and result[ + -1] == '\n': # remove the last char if it is '\n', result = result[:-1] if self._verbose: @@ -424,8 +423,9 @@ class Node(object): return self._update_prop('remove', prop_name, value, binary_data) def _update_prop(self, action, prop_name, value, binary_data): - return self.wpanctl(action + ' ' + prop_name + ' ' + ('-d ' if binary_data else '') - + '-v ' + value) # use -v to handle values starting with `-`. + return self.wpanctl(action + ' ' + prop_name + ' ' + + ('-d ' if binary_data else '') + '-v ' + + value) # use -v to handle values starting with `-`. def reset(self): return self.wpanctl('reset') @@ -436,64 +436,65 @@ class Node(object): def leave(self): return self.wpanctl('leave') - def form( - self, - name, - channel=None, - channel_mask=None, - panid=None, - xpanid=None, - key=None, - key_index=None, - node_type=None, - mesh_local_prefix=None, - legacy_prefix=None): - return self.wpanctl('form \"' + name + '\"' - + (' -c {}'.format(channel) if channel is not None else '') - + (' -m {}'.format(channel_mask) if channel_mask is not None else '') - + (' -p {}'.format(panid) if panid is not None else '') - + (' -x {}'.format(xpanid) if xpanid is not None else '') - + (' -k {}'.format(key) if key is not None else '') - + (' -i {}'.format(key_index) if key_index is not None else '') - + (' -T {}'.format(node_type) if node_type is not None else '') - + (' -M {}'.format(mesh_local_prefix) if mesh_local_prefix is not None else '') - + (' -L {}'.format(legacy_prefix) if legacy_prefix is not None else '')) + def form(self, + name, + channel=None, + channel_mask=None, + panid=None, + xpanid=None, + key=None, + key_index=None, + node_type=None, + mesh_local_prefix=None, + legacy_prefix=None): + return self.wpanctl( + 'form \"' + name + '\"' + + (' -c {}'.format(channel) if channel is not None else '') + + (' -m {}'.format(channel_mask) if channel_mask is not None else '' + ) + (' -p {}'.format(panid) if panid is not None else '') + + (' -x {}'.format(xpanid) if xpanid is not None else '') + + (' -k {}'.format(key) if key is not None else '') + + (' -i {}'.format(key_index) if key_index is not None else '') + + (' -T {}'.format(node_type) if node_type is not None else '') + + (' -M {}'.format(mesh_local_prefix + ) if mesh_local_prefix is not None else '') + + (' -L {}'.format(legacy_prefix) if legacy_prefix is not None else '' + )) - def join( - self, - name, - channel=None, - node_type=None, - panid=None, - xpanid=None, - key=None): - return self.wpanctl('join \"' + name + '\"' - + (' -c {}'.format(channel) if channel is not None else '') - + (' -T {}'.format(node_type) if node_type is not None else '') - + (' -p {}'.format(panid) if panid is not None else '') - + (' -x {}'.format(xpanid) if xpanid is not None else '') - + (' -k {}'.format(key) if key is not None else '') - + (' -n')) + def join(self, + name, + channel=None, + node_type=None, + panid=None, + xpanid=None, + key=None): + return self.wpanctl( + 'join \"' + name + '\"' + + (' -c {}'.format(channel) if channel is not None else '') + + (' -T {}'.format(node_type) if node_type is not None else '') + + (' -p {}'.format(panid) if panid is not None else '') + + (' -x {}'.format(xpanid) if xpanid is not None else '') + + (' -k {}'.format(key) if key is not None else '') + (' -n')) def active_scan(self, channel=None): return self.wpanctl( 'scan' + (' -c {}'.format(channel) if channel is not None else '')) def energy_scan(self, channel=None): - return self.wpanctl( - 'scan -e' + (' -c {}'.format(channel) if channel is not None else '')) + return self.wpanctl('scan -e' + ( + ' -c {}'.format(channel) if channel is not None else '')) - def discover_scan( - self, - channel=None, - joiner_only=False, - enable_filtering=False, - panid_filter=None): - return self.wpanctl('scan -d' - + (' -c {}'.format(channel) if channel is not None else '') - + (' -j' if joiner_only else '') - + (' -e' if enable_filtering else '') - + (' -p {}'.format(panid_filter) if panid_filter is not None else '')) + def discover_scan(self, + channel=None, + joiner_only=False, + enable_filtering=False, + panid_filter=None): + return self.wpanctl( + 'scan -d' + + (' -c {}'.format(channel) if channel is not None else '') + + (' -j' if joiner_only else '') + + (' -e' if enable_filtering else '') + + (' -p {}'.format(panid_filter) if panid_filter is not None else '')) def permit_join(self, duration_sec=None, port=None, udp=True, tcp=True): if not udp and not tcp: # incorrect use! @@ -506,72 +507,69 @@ class Node(object): if port is not None and duration_sec is None: duration_sec = '240' - return self.wpanctl('permit-join' - + (' {}'.format(duration_sec) if duration_sec is not None else '') - + (' {}'.format(port) if port is not None else '') - + traffic_type) + return self.wpanctl( + 'permit-join' + + (' {}'.format(duration_sec) if duration_sec is not None else '') + + (' {}'.format(port) if port is not None else '') + traffic_type) def config_gateway(self, prefix, default_route=False, priority=None): - return self.wpanctl('config-gateway ' + prefix - + (' -d' if default_route else '') - + (' -P {}'.format(priority) if priority is not None else '')) + return self.wpanctl( + 'config-gateway ' + prefix + (' -d' if default_route else '') + + (' -P {}'.format(priority) if priority is not None else '')) - def add_prefix( - self, - prefix, - prefix_len=None, - priority=None, - stable=True, - on_mesh=False, - slaac=False, - dhcp=False, - configure=False, - default_route=False, - preferred=False): - return self.wpanctl('add-prefix ' + prefix - + (' -l {}'.format(prefix_len) if prefix_len is not None else '') - + (' -P {}'.format(priority) if priority is not None else '') - + (' -s' if stable else '') - + (' -f' if preferred else '') - + (' -a' if slaac else '') - + (' -d' if dhcp else '') - + (' -c' if configure else '') - + (' -r' if default_route else '') - + (' -o' if on_mesh else '')) + def add_prefix(self, + prefix, + prefix_len=None, + priority=None, + stable=True, + on_mesh=False, + slaac=False, + dhcp=False, + configure=False, + default_route=False, + preferred=False): + return self.wpanctl( + 'add-prefix ' + prefix + + (' -l {}'.format(prefix_len) if prefix_len is not None else '') + + (' -P {}'.format(priority) if priority is not None else '') + + (' -s' if stable else '') + (' -f' if preferred else '') + + (' -a' if slaac else '') + (' -d' if dhcp else '') + + (' -c' if configure else '') + (' -r' if default_route else '') + + (' -o' if on_mesh else '')) def remove_prefix(self, prefix, prefix_len=None): - return self.wpanctl('remove-prefix ' + prefix - + (' -l {}'.format(prefix_len) if prefix_len is not None else '')) + return self.wpanctl('remove-prefix ' + prefix + ( + ' -l {}'.format(prefix_len) if prefix_len is not None else '')) - def add_route( - self, - route_prefix, - prefix_len=None, - priority=None, - stable=True): + def add_route(self, + route_prefix, + prefix_len=None, + priority=None, + stable=True): """route priority [(>0 for high, 0 for medium, <0 for low)]""" - return self.wpanctl('add-route ' + route_prefix - + (' -l {}'.format(prefix_len) if prefix_len is not None else '') - + (' -p {}'.format(priority) if priority is not None else '') - + ('' if stable else '-n')) + return self.wpanctl( + 'add-route ' + route_prefix + + (' -l {}'.format(prefix_len) if prefix_len is not None else '') + + (' -p {}'.format(priority) if priority is not None else '') + + ('' if stable else '-n')) - def remove_route( - self, - route_prefix, - prefix_len=None, - priority=None, - stable=True): + def remove_route(self, + route_prefix, + prefix_len=None, + priority=None, + stable=True): """route priority [(>0 for high, 0 for medium, <0 for low)]""" - return self.wpanctl('remove-route ' + route_prefix - + (' -l {}'.format(prefix_len) if prefix_len is not None else '') - + (' -p {}'.format(priority) if priority is not None else '')) + return self.wpanctl( + 'remove-route ' + route_prefix + + (' -l {}'.format(prefix_len) if prefix_len is not None else '') + + (' -p {}'.format(priority) if priority is not None else '')) def commissioner_start(self): return self.wpanctl('commissioner start') def commissioner_add_joiner(self, eui64, pskd, timeout='100'): - return self.wpanctl( - 'commissioner joiner-add {} {} {}'.format(eui64, timeout, pskd)) + return self.wpanctl('commissioner joiner-add {} {} {}'.format( + eui64, timeout, pskd)) def joiner_join(self, pskd): return self.wpanctl('joiner --join {}'.format(pskd)) @@ -607,10 +605,8 @@ class Node(object): def un_whitelist_node(self, node): """Removes a given node (of node `Node) from the whitelist""" - self.remove( - WPAN_MAC_WHITELIST_ENTRIES, - node.get(WPAN_EXT_ADDRESS)[ - 1:-1]) + self.remove(WPAN_MAC_WHITELIST_ENTRIES, + node.get(WPAN_EXT_ADDRESS)[1:-1]) def is_in_scan_result(self, scan_result): """Checks if node is in the scan results @@ -624,15 +620,13 @@ class Node(object): ext_address = self.get(WPAN_EXT_ADDRESS)[1:-1] for item in scan_result: - if all( - [ - item.network_name == name, - item.panid == panid, - item.xpanid == xpanid, - item.channel == channel, + if all([ + item.network_name == name, item.panid == panid, + item.xpanid == xpanid, item.channel == channel, item.ext_address == ext_address, - (item.type == ScanResult.TYPE_DISCOVERY_SCAN) or ( - item.joinable == joinable)]): + (item.type == ScanResult.TYPE_DISCOVERY_SCAN) or + (item.joinable == joinable) + ]): return True return False @@ -659,8 +653,9 @@ class Node(object): if self._verbose: _log('$ Node{} \'{}\')'.format(self._index, cmd)) - result = subprocess.check_output( - cmd, shell=True, stderr=subprocess.STDOUT) + result = subprocess.check_output(cmd, + shell=True, + stderr=subprocess.STDOUT) return result def remove_ip6_address_on_interface(self, address, prefix_len=64): @@ -674,8 +669,9 @@ class Node(object): if self._verbose: _log('$ Node{} \'{}\')'.format(self._index, cmd)) - result = subprocess.check_output( - cmd, shell=True, stderr=subprocess.STDOUT) + result = subprocess.check_output(cmd, + shell=True, + stderr=subprocess.STDOUT) return result # ------------------------------------------------------------------------------------------------------------------ @@ -692,16 +688,21 @@ class Node(object): try: node._wpantund_process.poll() if node._wpantund_process.returncode is not None: - print('Node {} wpantund instance has terminated unexpectedly'.format(node)) + print( + 'Node {} wpantund instance has terminated unexpectedly' + .format(node)) if disable_logs: node.set(WPAN_OT_LOG_LEVEL, '0') node.leave() except subprocess.CalledProcessError as e: if (node._verbose): - _log(' -> \'{}\' exit code: {}'.format(e.output, e.returncode)) + _log(' -> \'{}\' exit code: {}'.format( + e.output, e.returncode)) interval = time.time() - start_time if interval > wait_time: - print('Took too long to init node {} ({}>{} sec)'.format(node, interval, wait_time)) + print( + 'Took too long to init node {} ({}>{} sec)'.format( + node, interval, wait_time)) raise except BaseException: raise @@ -721,7 +722,8 @@ class Node(object): """Sets up the time speed up factor - should be set before creating any `Node` objects""" if len(Node._all_nodes) != 0: raise Node._NodeError( - 'set_time_speedup_factor() cannot be called after creating a `Node`') + 'set_time_speedup_factor() cannot be called after creating a `Node`' + ) Node._SPEED_UP_FACTOR = factor # ------------------------------------------------------------------------------------------------------------------ @@ -764,15 +766,8 @@ class Node(object): else: msg = data - return AsyncSender( - self, - src_addr, - src_port, - dst_addr, - dst_port, - msg, - count, - mcast_hops) + return AsyncSender(self, src_addr, src_port, dst_addr, dst_port, msg, + count, mcast_hops) def _get_receiver(self, local_port): # Gets or creates a receiver (an `AsyncReceiver`) tied to given port @@ -794,11 +789,8 @@ class Node(object): def prepare_rx(self, sender): """Prepare to receive messages from a sender (an `AsyncSender`)""" receiver = self._get_receiver(sender.dst_port) - receiver._add_sender( - sender.src_addr, - sender.src_port, - sender.msg, - sender.count) + receiver._add_sender(sender.src_addr, sender.src_port, sender.msg, + sender.count) return receiver def prepare_listener(self, local_port, timeout=1): @@ -815,7 +807,8 @@ class Node(object): while asyncore.socket_map: elapsed_time = time.time() - start_time if elapsed_time > timeout: - print('Performing aysnc tx/tx took too long ({}>{} sec)'.format(elapsed_time, timeout)) + print('Performing aysnc tx/tx took too long ({}>{} sec)'. + format(elapsed_time, timeout)) raise Node._NodeError( 'perform_tx_rx timed out ({}>{} sec)'.format( elapsed_time, timeout)) @@ -825,10 +818,10 @@ class Node(object): print('Failed to perform async rx/tx') raise + # ----------------------------------------------------------------------------------------------------------------------- # `AsyncSender` and `AsyncReceiver classes - _SO_BINDTODEVICE = 25 @@ -847,16 +840,15 @@ def _create_socket_address(ip_address, port): class AsyncSender(asyncore.dispatcher): """ An IPv6 async message sender - use `Node.prepare_tx()` to create one""" - def __init__( - self, - node, - src_addr, - src_port, - dst_addr, - dst_port, - msg, - count, - mcast_hops=None): + def __init__(self, + node, + src_addr, + src_port, + dst_addr, + dst_port, + msg, + count, + mcast_hops=None): self._node = node self._src_addr = src_addr self._src_port = src_port @@ -870,18 +862,14 @@ class AsyncSender(asyncore.dispatcher): # Create a socket, bind it to the node's interface sock = socket.socket(socket.AF_INET6, socket.SOCK_DGRAM) - sock.setsockopt( - socket.SOL_SOCKET, - _SO_BINDTODEVICE, - node.interface_name + '\0') + sock.setsockopt(socket.SOL_SOCKET, _SO_BINDTODEVICE, + node.interface_name + '\0') sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEPORT, 1) # Set the IPV6_MULTICAST_HOPS if mcast_hops is not None: - sock.setsockopt( - socket.IPPROTO_IPV6, - socket.IPV6_MULTICAST_HOPS, - mcast_hops) + sock.setsockopt(socket.IPPROTO_IPV6, socket.IPV6_MULTICAST_HOPS, + mcast_hops) # Bind the socket to the given src address if _is_ipv6_addr_link_local(src_addr): @@ -943,18 +931,13 @@ class AsyncSender(asyncore.dispatcher): if self._node._verbose: if sent_len < 30: - info_text = '{} bytes ("{}")'.format( - sent_len, self._tx_buffer[:sent_len]) + info_text = '{} bytes ("{}")'.format(sent_len, + self._tx_buffer[:sent_len]) else: info_text = '{} bytes'.format(sent_len) - _log( - '- Node{} sent {} to [{}]:{} from [{}]:{}'.format( - self._node._index, - info_text, - self._dst_addr, - self._dst_port, - self._src_addr, - self._src_port)) + _log('- Node{} sent {} to [{}]:{} from [{}]:{}'.format( + self._node._index, info_text, self._dst_addr, self._dst_port, + self._src_addr, self._src_port)) self._tx_buffer = self._tx_buffer[sent_len:] @@ -968,6 +951,7 @@ class AsyncSender(asyncore.dispatcher): def handle_close(self): self.close() + # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -977,6 +961,7 @@ class AsyncReceiver(asyncore.dispatcher): _MAX_RECV_SIZE = 2048 class _SenderInfo(object): + def __init__(self, sender_addr, sender_port, msg, count): self._sender_addr = sender_addr self._sender_port = sender_port @@ -995,20 +980,18 @@ class AsyncReceiver(asyncore.dispatcher): def __init__(self, node, local_port): self._node = node self._local_port = local_port - self._senders = [] # list of `_SenderInfo` objects + self._senders = [] # list of `_SenderInfo` objects # contains all received messages as a list of (pkt, (src_addr, # src_port)) self._all_rx = [] - self._timeout = 0 # listen timeout (zero means forever) + self._timeout = 0 # listen timeout (zero means forever) self._started = False self._start_time = 0 # Create a socket, bind it to the node's interface sock = socket.socket(socket.AF_INET6, socket.SOCK_DGRAM) - sock.setsockopt( - socket.SOL_SOCKET, - _SO_BINDTODEVICE, - node.interface_name + '\0') + sock.setsockopt(socket.SOL_SOCKET, _SO_BINDTODEVICE, + node.interface_name + '\0') sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEPORT, 1) # Bind the socket to any IPv6 address with the given local port @@ -1019,8 +1002,7 @@ class AsyncReceiver(asyncore.dispatcher): def _add_sender(self, sender_addr, sender_port, msg, count): self._senders.append( - AsyncReceiver._SenderInfo( - sender_addr, sender_port, msg, count)) + AsyncReceiver._SenderInfo(sender_addr, sender_port, msg, count)) def _set_listen_timeout(self, timeout): self._timeout = timeout @@ -1052,11 +1034,14 @@ class AsyncReceiver(asyncore.dispatcher): if not self._started: self._start_time = time.time() self._started = True - if self._timeout != 0 and time.time() - self._start_time >= self._timeout: + if self._timeout != 0 and time.time( + ) - self._start_time >= self._timeout: self.handle_close() if self._node._verbose: - _log('- Node{} finished listening on port {} for {} sec, received {} msg(s)'.format( - self._node._index, self._local_port, self._timeout, len(self._all_rx))) + _log( + '- Node{} finished listening on port {} for {} sec, received {} msg(s)' + .format(self._node._index, self._local_port, self._timeout, + len(self._all_rx))) return False return True @@ -1078,18 +1063,16 @@ class AsyncReceiver(asyncore.dispatcher): info_text = '{} bytes ("{}")'.format(len(msg), msg) else: info_text = '{} bytes'.format(len(msg)) - _log( - '- Node{} received {} on port {} from [{}]:{}'.format( - self._node._index, - info_text, - self._local_port, - src_addr, - src_port)) + _log('- Node{} received {} on port {} from [{}]:{}'.format( + self._node._index, info_text, self._local_port, src_addr, + src_port)) self._all_rx.append((msg, (src_addr, src_port))) - if all([sender._check_received(msg, src_addr, src_port) - for sender in self._senders]): + if all([ + sender._check_received(msg, src_addr, src_port) + for sender in self._senders + ]): self.handle_close() def handle_close(self): @@ -1097,6 +1080,7 @@ class AsyncReceiver(asyncore.dispatcher): # remove the receiver from the node once the socket is closed self._node._remove_recver(self) + # ----------------------------------------------------------------------------------------------------------------------- @@ -1133,7 +1117,8 @@ def verify_within(condition_checker_func, wait_time, delay_time=0.1): condition_checker_func() except VerifyError as e: if time.time() - start_time > wait_time: - print('Took too long to pass the condition ({}>{} sec)'.format(time.time() - start_time, wait_time)) + print('Took too long to pass the condition ({}>{} sec)'.format( + time.time() - start_time, wait_time)) print(e.message) raise e except BaseException: @@ -1144,6 +1129,7 @@ def verify_within(condition_checker_func, wait_time, delay_time=0.1): time.sleep(delay_time) _is_in_verify_within = old_is_in_verify_within + # ----------------------------------------------------------------------------------------------------------------------- # Parsing `wpanctl` output @@ -1186,7 +1172,8 @@ class ScanResult(object): self._rssi = items[1] else: raise ValueError( - '"{}" does not seem to be a valid scan result string'.result_text) + '"{}" does not seem to be a valid scan result string'. + result_text) @property def type(self): @@ -1226,8 +1213,8 @@ class ScanResult(object): def parse_scan_result(scan_result): """ Parses scan result string and returns an array of `ScanResult` objects""" - return [ScanResult(item) for item in scan_result.split( - '\n')[2:]] # skip first two lines which are table headers + return [ScanResult(item) for item in scan_result.split('\n')[2:] + ] # skip first two lines which are table headers def parse_list(list_string): @@ -1249,6 +1236,7 @@ def parse_list(list_string): # return [line[2:-1].split()[0] for line in list_string.split('\n')[1:-1]] + # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -1264,9 +1252,9 @@ class OnMeshPrefix(object): m = re.match( r'\t"([0-9a-fA-F:]+)\s*prefix_len:(\d+)\s+origin:(\w*)\s+stable:(\w*).* \[' - + r'on-mesh:(\d)\s+def-route:(\d)\s+config:(\d)\s+dhcp:(\d)\s+slaac:(\d)\s+pref:(\d)\s+prio:(\w*)\]' - + r'\s+rloc:(0x[0-9a-fA-F]+)', - text) + + + r'on-mesh:(\d)\s+def-route:(\d)\s+config:(\d)\s+dhcp:(\d)\s+slaac:(\d)\s+pref:(\d)\s+prio:(\w*)\]' + + r'\s+rloc:(0x[0-9a-fA-F]+)', text) verify(m is not None) data = m.groups() @@ -1329,8 +1317,10 @@ class OnMeshPrefix(object): def parse_on_mesh_prefix_result(on_mesh_prefix_list): """ Parses on-mesh prefix list string and returns an array of `OnMeshPrefix` objects""" - return [OnMeshPrefix(item) - for item in on_mesh_prefix_list.split('\n')[1:-1]] + return [ + OnMeshPrefix(item) for item in on_mesh_prefix_list.split('\n')[1:-1] + ] + # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -1399,6 +1389,7 @@ def parse_child_table_result(child_table_list): """ Parses child table list string and returns an array of `ChildEntry` objects""" return [ChildEntry(item) for item in child_table_list.split('\n')[1:-1]] + # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -1455,8 +1446,10 @@ class NeighborEntry(object): def parse_neighbor_table_result(neighbor_table_list): """ Parses neighbor table list string and returns an array of `NeighborEntry` objects""" - return [NeighborEntry(item) - for item in neighbor_table_list.split('\n')[1:-1]] + return [ + NeighborEntry(item) for item in neighbor_table_list.split('\n')[1:-1] + ] + # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -1521,8 +1514,10 @@ class RouterTableEntry(object): def parse_router_table_result(router_table_list): """ Parses router table list string and returns an array of `RouterTableEntry` objects""" - return [RouterTableEntry(item) - for item in router_table_list.split('\n')[1:-1]] + return [ + RouterTableEntry(item) for item in router_table_list.split('\n')[1:-1] + ] + # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -1572,8 +1567,11 @@ class AddressCacheEntry(object): def parse_address_cache_table_result(addr_cache_table_list): """ Parses address cache table list string and returns an array of `AddressCacheEntry` objects""" - return [AddressCacheEntry(item) - for item in addr_cache_table_list.split('\n')[1:-1]] + return [ + AddressCacheEntry(item) + for item in addr_cache_table_list.split('\n')[1:-1] + ] + # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -1618,5 +1616,6 @@ class InterfaceRoute(object): def parse_interface_routes_result(interface_routes_list): """ Parses interface routes list string and returns an array of `InterfaceRoute` objects""" - return [InterfaceRoute(item) - for item in interface_routes_list.split('\n')[1:-1]] + return [ + InterfaceRoute(item) for item in interface_routes_list.split('\n')[1:-1] + ] diff --git a/tools/harness-automation/autothreadharness/harness_case.py b/tools/harness-automation/autothreadharness/harness_case.py index 5cf8fa434..f908e7e1f 100644 --- a/tools/harness-automation/autothreadharness/harness_case.py +++ b/tools/harness-automation/autothreadharness/harness_case.py @@ -154,7 +154,8 @@ class HarnessCase(unittest.TestCase): auto_dut = settings.AUTO_DUT """bool: whether use harness auto dut feature""" - timeout = hasattr(settings, 'TIMEOUT') and settings.TIMEOUT or DEFAULT_TIMEOUT + timeout = hasattr(settings, + 'TIMEOUT') and settings.TIMEOUT or DEFAULT_TIMEOUT """number: timeout in seconds to stop running this test case""" started = 0 @@ -170,17 +171,19 @@ class HarnessCase(unittest.TestCase): self.dut = None self._browser = None self._hc = None - self.result_dir = '%s\\%s' % (settings.OUTPUT_PATH, self.__class__.__name__) + self.result_dir = '%s\\%s' % (settings.OUTPUT_PATH, + self.__class__.__name__) self.history = HistoryHelper() self.add_all_devices = False self.new_th = False harness_info = ConfigParser.ConfigParser() harness_info.read('%s\\info.ini' % settings.HARNESS_HOME) - if harness_info.has_option('Thread_Harness_Info', 'Version') and harness_info.has_option( - 'Thread_Harness_Info', 'Mode' - ): - harness_version = harness_info.get('Thread_Harness_Info', 'Version').rsplit(' ', 1)[1] + if harness_info.has_option('Thread_Harness_Info', + 'Version') and harness_info.has_option( + 'Thread_Harness_Info', 'Mode'): + harness_version = harness_info.get('Thread_Harness_Info', + 'Version').rsplit(' ', 1)[1] harness_mode = harness_info.get('Thread_Harness_Info', 'Mode') if harness_mode == 'External' and harness_version > '1.4.0': @@ -218,7 +221,8 @@ class HarnessCase(unittest.TestCase): while True: try: - pdu = pdu_factory.create_pdu_controller(settings.PDU_CONTROLLER_TYPE) + pdu = pdu_factory.create_pdu_controller( + settings.PDU_CONTROLLER_TYPE) pdu.open(**settings.PDU_CONTROLLER_OPEN_PARAMS) except EOFError: logger.warning('Failed to connect to telnet') @@ -248,18 +252,25 @@ class HarnessCase(unittest.TestCase): time.sleep(2) harness_config = ConfigParser.ConfigParser() - harness_config.read('%s\\Config\\Configuration.ini' % settings.HARNESS_HOME) - if harness_config.has_option('THREAD_HARNESS_CONFIG', 'BrowserAutoNavigate') and harness_config.getboolean( - 'THREAD_HARNESS_CONFIG', 'BrowserAutoNavigate' - ): - logger.error('BrowserAutoNavigate in Configuration.ini should be False') - raise FailError('BrowserAutoNavigate in Configuration.ini should be False') + harness_config.read('%s\\Config\\Configuration.ini' % + settings.HARNESS_HOME) + if harness_config.has_option( + 'THREAD_HARNESS_CONFIG', + 'BrowserAutoNavigate') and harness_config.getboolean( + 'THREAD_HARNESS_CONFIG', 'BrowserAutoNavigate'): + logger.error( + 'BrowserAutoNavigate in Configuration.ini should be False') + raise FailError( + 'BrowserAutoNavigate in Configuration.ini should be False') if settings.MIXED_DEVICE_TYPE: if harness_config.has_option( - 'THREAD_HARNESS_CONFIG', 'EnableDeviceSelection' - ) and not harness_config.getboolean('THREAD_HARNESS_CONFIG', 'EnableDeviceSelection'): - logger.error('EnableDeviceSelection in Configuration.ini should be True') - raise FailError('EnableDeviceSelection in Configuration.ini should be True') + 'THREAD_HARNESS_CONFIG', + 'EnableDeviceSelection') and not harness_config.getboolean( + 'THREAD_HARNESS_CONFIG', 'EnableDeviceSelection'): + logger.error( + 'EnableDeviceSelection in Configuration.ini should be True') + raise FailError( + 'EnableDeviceSelection in Configuration.ini should be True') def _destroy_harness(self): """Stop harness backend service @@ -299,8 +310,8 @@ class HarnessCase(unittest.TestCase): chrome_options.add_argument('--disable-infobars') chrome_options.add_argument('--ignore-certificate-errors') chrome_options.add_experimental_option( - 'prefs', {'profile.managed_default_content_settings.notifications': 1} - ) + 'prefs', + {'profile.managed_default_content_settings.notifications': 1}) browser = webdriver.Chrome(chrome_options=chrome_options) browser.set_page_load_timeout(20) @@ -323,10 +334,11 @@ class HarnessCase(unittest.TestCase): self._browser = None def _init_rf_shield(self): - if getattr(settings, 'SHIELD_CONTROLLER_TYPE', None) and getattr(settings, 'SHIELD_CONTROLLER_PARAMS', None): + if getattr(settings, 'SHIELD_CONTROLLER_TYPE', None) and getattr( + settings, 'SHIELD_CONTROLLER_PARAMS', None): self.rf_shield = get_rf_shield_controller( - shield_type=settings.SHIELD_CONTROLLER_TYPE, params=settings.SHIELD_CONTROLLER_PARAMS - ) + shield_type=settings.SHIELD_CONTROLLER_TYPE, + params=settings.SHIELD_CONTROLLER_PARAMS) else: self.rf_shield = None @@ -355,7 +367,8 @@ class HarnessCase(unittest.TestCase): os.system('del /q "%s\\Reports\\*.*"' % settings.HARNESS_HOME) else: logger.info('Empty files in temps') - os.system('del /q "%s\\Thread_Harness\\temp\\*.*"' % settings.HARNESS_HOME) + os.system('del /q "%s\\Thread_Harness\\temp\\*.*"' % + settings.HARNESS_HOME) # create directory os.system('mkdir %s' % self.result_dir) @@ -393,16 +406,19 @@ class HarnessCase(unittest.TestCase): if dialog and dialog.get_attribute('aria-hidden') == 'false': times = 100 while times: - status = dialog.find_element_by_class_name('status-notify').text + status = dialog.find_element_by_class_name( + 'status-notify').text if 'Searching' in status: logger.info('Still detecting..') elif 'Not' in status: logger.warning('Sniffer device not verified!') - button = dialog.find_element_by_id('snifferAutoDetectBtn') + button = dialog.find_element_by_id( + 'snifferAutoDetectBtn') button.click() elif 'Verified' in status: logger.info('Verified!') - button = dialog.find_element_by_id('saveCaptureSettings') + button = dialog.find_element_by_id( + 'saveCaptureSettings') button.click() break else: @@ -446,12 +462,14 @@ class HarnessCase(unittest.TestCase): if dialog.get_attribute('aria-hidden') != 'false': raise Exception('Missing General Setup dialog') - field = dialog.find_element_by_id('inp_general_child_update_wait_time') + field = dialog.find_element_by_id( + 'inp_general_child_update_wait_time') field.clear() if self.child_timeout: field.send_keys(str(self.child_timeout)) - field = dialog.find_element_by_id('inp_general_sed_polling_rate') + field = dialog.find_element_by_id( + 'inp_general_sed_polling_rate') field.clear() if self.sed_polling_interval: field.send_keys(str(self.sed_polling_interval)) @@ -508,31 +526,33 @@ class HarnessCase(unittest.TestCase): selected_hw_num = len(selected_hw_set) while selected_hw_num: - remove_button = selected_hw_set[selected_hw_num - 1].find_element_by_class_name('removeSelectedDevice') + remove_button = selected_hw_set[selected_hw_num - + 1].find_element_by_class_name( + 'removeSelectedDevice') remove_button.click() selected_hw_num = selected_hw_num - 1 devices = [ - device - for device in settings.GOLDEN_DEVICES - if not self.history.is_bad_golden_device(device[0]) - and not (settings.DUT_DEVICE and device[0] == settings.DUT_DEVICE[0]) + device for device in settings.GOLDEN_DEVICES + if not self.history.is_bad_golden_device(device[0]) and + not (settings.DUT_DEVICE and device[0] == settings.DUT_DEVICE[0]) ] - logger.info('Available golden devices: %s', json.dumps(devices, indent=2)) + logger.info('Available golden devices: %s', json.dumps(devices, + indent=2)) shield_devices = [ - shield_device - for shield_device in settings.SHIELD_GOLDEN_DEVICES - if not self.history.is_bad_golden_device(shield_device[0]) - and not (settings.DUT2_DEVICE and shield_device[0] == settings.DUT2_DEVICE[0]) + shield_device for shield_device in settings.SHIELD_GOLDEN_DEVICES + if not self.history.is_bad_golden_device(shield_device[0]) and + not (settings.DUT2_DEVICE and + shield_device[0] == settings.DUT2_DEVICE[0]) ] - logger.info('Available shield golden devices: %s', json.dumps(shield_devices, indent=2)) + logger.info('Available shield golden devices: %s', + json.dumps(shield_devices, indent=2)) golden_devices_required = self.golden_devices_required dut_device = () if settings.DUT_DEVICE: dut_device = settings.DUT_DEVICE - """check if test case needs to use RF-shield box and its device order in Testbed page Two parameters case_need_shield & device_order should be set in the case script according to the requires: https://openthread.io/certification/test-cases#rf_shielding @@ -562,9 +582,11 @@ class HarnessCase(unittest.TestCase): logger.info('Must set DUT2_DEVICE') raise FailError('DUT2_DEVICE must be set in settings.py') if isinstance(self.device_order, list) and self.device_order: - logger.info('case %s devices ordered by %s ', self.case, self.device_order) + logger.info('case %s devices ordered by %s ', self.case, + self.device_order) else: - logger.info('case %s uses %s as DUT', self.case, settings.DUT2_DEVICE) + logger.info('case %s uses %s as DUT', self.case, + settings.DUT2_DEVICE) # for test bed with multi-vendor devices if settings.MIXED_DEVICE_TYPE: @@ -586,7 +608,8 @@ class HarnessCase(unittest.TestCase): case_id = match_line.group(1) if re.sub(r'\.', ' ', case_id) == self.case: - logger.info('Get line by case %s: %s', case_id, topo_line) + logger.info('Get line by case %s: %s', case_id, + topo_line) topo_device_list = re.split(',', match_line.group(2)) for i in range(len(topo_device_list)): topo_device = re.split(':', topo_device_list[i]) @@ -595,9 +618,12 @@ class HarnessCase(unittest.TestCase): else: continue except Exception as e: - logger.info('Get devices from topology config file error: %s', e) + logger.info('Get devices from topology config file error: %s', + e) raise GoldenDeviceNotEnoughError() - logger.info('Golden devices in topology config file for case %s: %s', case_id, topo_mixed_devices) + logger.info( + 'Golden devices in topology config file for case %s: %s', + case_id, topo_mixed_devices) f_topo.close() golden_device_candidates = [] missing_golden_devices = topo_mixed_devices[:] @@ -611,16 +637,16 @@ class HarnessCase(unittest.TestCase): # mapping device in device_order which needs to be shielded if device_order_item[1]: if 'DUT' in device_order_item[0]: - golden_device_candidates.append(settings.DUT2_DEVICE) + golden_device_candidates.append( + settings.DUT2_DEVICE) dut_device = settings.DUT2_DEVICE matched_dut = True matched = True break for device_item in shield_devices: - if ( - device_order_item[0] == mixed_device_item[0] - and mixed_device_item[1] == device_item[1] - ): + if (device_order_item[0] == mixed_device_item[0] + and + mixed_device_item[1] == device_item[1]): golden_device_candidates.append(device_item) shield_devices.remove(device_item) matched = True @@ -628,21 +654,22 @@ class HarnessCase(unittest.TestCase): # mapping device in device_order which does not need to be shielded else: if 'DUT' in device_order_item[0]: - golden_device_candidates.append(settings.DUT_DEVICE) + golden_device_candidates.append( + settings.DUT_DEVICE) matched_dut = True matched = True break for device_item in devices: - if ( - device_order_item[0] == mixed_device_item[0] - and mixed_device_item[1] == device_item[1] - ): + if (device_order_item[0] == mixed_device_item[0] + and + mixed_device_item[1] == device_item[1]): golden_device_candidates.append(device_item) devices.remove(device_item) matched = True break if not matched: - logger.info('Golden device not enough in : no %s', device_order_item) + logger.info('Golden device not enough in : no %s', + device_order_item) raise GoldenDeviceNotEnoughError() if not matched_dut: raise FailError('Failed to find DUT in device_order') @@ -656,7 +683,9 @@ class HarnessCase(unittest.TestCase): devices.remove(device_item) missing_golden_devices.remove(mixed_device_item) break - logger.info('Golden devices in topology config file mapped in settings : %s', golden_device_candidates) + logger.info( + 'Golden devices in topology config file mapped in settings : %s', + golden_device_candidates) if len(topo_mixed_devices) != len(golden_device_candidates): device_dict = dict() for missing_device in missing_golden_devices: @@ -669,7 +698,8 @@ class HarnessCase(unittest.TestCase): else: devices = golden_device_candidates golden_devices_required = len(devices) - logger.info('All case-needed golden devices: %s', json.dumps(devices, indent=2)) + logger.info('All case-needed golden devices: %s', + json.dumps(devices, indent=2)) # for test bed with single vendor devices else: golden_device_candidates = [] @@ -680,7 +710,8 @@ class HarnessCase(unittest.TestCase): # choose device which needs to be shielded if device_order_item[1]: if 'DUT' in device_order_item[0]: - golden_device_candidates.append(settings.DUT2_DEVICE) + golden_device_candidates.append( + settings.DUT2_DEVICE) dut_device = settings.DUT2_DEVICE matched_dut = True matched = True @@ -703,7 +734,8 @@ class HarnessCase(unittest.TestCase): matched = True break if not matched: - logger.info('Golden device not enough in : no %s', device_order_item) + logger.info('Golden device not enough in : no %s', + device_order_item) raise GoldenDeviceNotEnoughError() if not matched_dut: raise FailError('Failed to find DUT in device_order') @@ -720,7 +752,8 @@ class HarnessCase(unittest.TestCase): raise GoldenDeviceNotEnoughError() # add golden devices - number_of_devices_to_add = len(devices) if self.add_all_devices else golden_devices_required + number_of_devices_to_add = len( + devices) if self.add_all_devices else golden_devices_required for i in range(number_of_devices_to_add): self._add_device(*devices.pop()) @@ -734,24 +767,29 @@ class HarnessCase(unittest.TestCase): # enable AUTO DUT if self.auto_dut: - checkbox_auto_dut = browser.find_element_by_id('EnableAutoDutSelection') + checkbox_auto_dut = browser.find_element_by_id( + 'EnableAutoDutSelection') if not checkbox_auto_dut.is_selected(): checkbox_auto_dut.click() time.sleep(1) if settings.DUT_DEVICE: - radio_auto_dut = browser.find_element_by_class_name('AutoDUT_RadBtns') + radio_auto_dut = browser.find_element_by_class_name( + 'AutoDUT_RadBtns') if not radio_auto_dut.is_selected() and not self.device_order: radio_auto_dut.click() if self.device_order: - selected_hw_set = test_bed.find_elements_by_class_name('selected-hw') + selected_hw_set = test_bed.find_elements_by_class_name( + 'selected-hw') for selected_hw in selected_hw_set: - form_inputs = selected_hw.find_elements_by_tag_name('input') + form_inputs = selected_hw.find_elements_by_tag_name( + 'input') form_port = form_inputs[0] port = form_port.get_attribute('value').encode('utf8') if port == dut_device[0]: - radio_auto_dut = selected_hw.find_element_by_class_name('AutoDUT_RadBtns') + radio_auto_dut = selected_hw.find_element_by_class_name( + 'AutoDUT_RadBtns') if not radio_auto_dut.is_selected(): radio_auto_dut.click() @@ -760,19 +798,23 @@ class HarnessCase(unittest.TestCase): self._connect_devices() button_next = browser.find_element_by_id('nextBtn') if not wait_until( - lambda: 'disabled' not in button_next.get_attribute('class'), - times=(30 + 4 * number_of_devices_to_add), + lambda: 'disabled' not in button_next.get_attribute( + 'class'), + times=(30 + 4 * number_of_devices_to_add), ): bad_ones = [] - selected_hw_set = test_bed.find_elements_by_class_name('selected-hw') + selected_hw_set = test_bed.find_elements_by_class_name( + 'selected-hw') for selected_hw in selected_hw_set: - form_inputs = selected_hw.find_elements_by_tag_name('input') + form_inputs = selected_hw.find_elements_by_tag_name( + 'input') form_port = form_inputs[0] if form_port.is_enabled(): bad_ones.append(selected_hw) for selected_hw in bad_ones: - form_inputs = selected_hw.find_elements_by_tag_name('input') + form_inputs = selected_hw.find_elements_by_tag_name( + 'input') form_port = form_inputs[0] port = form_port.get_attribute('value').encode('utf8') if port == dut_device[0]: @@ -788,7 +830,8 @@ class HarnessCase(unittest.TestCase): self.history.mark_bad_golden_device(port) # remove the bad one - selected_hw.find_element_by_class_name('removeSelectedDevice').click() + selected_hw.find_element_by_class_name( + 'removeSelectedDevice').click() time.sleep(0.1) if len(devices): @@ -804,14 +847,17 @@ class HarnessCase(unittest.TestCase): continue if self.auto_dut and not settings.DUT_DEVICE: - radio_auto_dut = browser.find_element_by_class_name('AutoDUT_RadBtns') + radio_auto_dut = browser.find_element_by_class_name( + 'AutoDUT_RadBtns') if not radio_auto_dut.is_selected(): radio_auto_dut.click() time.sleep(5) button_next.click() - if not wait_until(lambda: self._browser.current_url.endswith('TestExecution.html'), 20): + if not wait_until( + lambda: self._browser.current_url.endswith( + 'TestExecution.html'), 20): raise Exception('Failed to load TestExecution page') except FailError: raise @@ -829,8 +875,10 @@ class HarnessCase(unittest.TestCase): time.sleep(1) checkbox = None - wait_until(lambda: self._browser.find_elements_by_css_selector('.tree-node .tree-title') and True) - elems = self._browser.find_elements_by_css_selector('.tree-node .tree-title') + wait_until(lambda: self._browser.find_elements_by_css_selector( + '.tree-node .tree-title') and True) + elems = self._browser.find_elements_by_css_selector( + '.tree-node .tree-title') finder = re.compile(r'.*\b' + case + r'\b') finder_dotted = re.compile(r'.*\b' + case.replace(' ', r'\.') + r'\b') for elem in elems: @@ -853,7 +901,9 @@ class HarnessCase(unittest.TestCase): elem = self._browser.find_element_by_id('runTest') elem.click() - if not wait_until(lambda: self._browser.find_element_by_id('stopTest') and True, 10): + if not wait_until( + lambda: self._browser.find_element_by_id('stopTest') and True, + 10): raise Exception('Failed to start test case') def _collect_result(self): @@ -863,11 +913,14 @@ class HarnessCase(unittest.TestCase): """ if self.new_th: - os.system('copy "%s\\Reports\\*.*" "%s"' % (settings.HARNESS_HOME, self.result_dir)) + os.system('copy "%s\\Reports\\*.*" "%s"' % + (settings.HARNESS_HOME, self.result_dir)) else: - os.system('copy "%s\\Thread_Harness\\temp\\*.*" "%s"' % (settings.HARNESS_HOME, self.result_dir)) + os.system('copy "%s\\Thread_Harness\\temp\\*.*" "%s"' % + (settings.HARNESS_HOME, self.result_dir)) - os.system('copy "%s\\Captures\\*.pcapng" %s\\' % (settings.HARNESS_HOME, self.result_dir)) + os.system('copy "%s\\Captures\\*.pcapng" %s\\' % + (settings.HARNESS_HOME, self.result_dir)) def _wait_dialog(self): """Wait for dialogs and handle them until done. @@ -884,7 +937,8 @@ class HarnessCase(unittest.TestCase): logger.exception('Failed to get dialog.') else: if dialog and dialog.get_attribute('aria-hidden') == 'false': - title = dialog.find_element_by_class_name('modal-title').text + title = dialog.find_element_by_class_name( + 'modal-title').text time.sleep(1) logger.info('Handling dialog[%s]', title) @@ -918,15 +972,21 @@ class HarnessCase(unittest.TestCase): if self.timeout % 10 == 0: lines = self._hc.tail() if 'SUCCESS: The process "dumpcap.exe" with PID ' in lines: - logger.info('Tshark should be ended now, lets wait at most 30 seconds.') - if not wait_until(lambda: 'tshark.exe' not in subprocess.check_output('tasklist'), 30): + logger.info( + 'Tshark should be ended now, lets wait at most 30 seconds.' + ) + if not wait_until( + lambda: 'tshark.exe' not in subprocess.check_output( + 'tasklist'), 30): res = subprocess.check_output( - 'taskkill /t /f /im tshark.exe', stderr=subprocess.STDOUT, shell=True - ) + 'taskkill /t /f /im tshark.exe', + stderr=subprocess.STDOUT, + shell=True) logger.info(res) # Wait until case really stopped - wait_until(lambda: self._browser.find_element_by_id('runTest') and True, 30) + wait_until(lambda: self._browser.find_element_by_id('runTest') and True, + 30) if error: raise FailError('Fail for previous exceptions') @@ -963,7 +1023,8 @@ class HarnessCase(unittest.TestCase): self.dut.extpanid = settings.THREAD_EXTPANID self.dut.start() - elif title.startswith('MAC Address Required') or title.startswith('DUT Random Extended MAC Address Required'): + elif title.startswith('MAC Address Required') or title.startswith( + 'DUT Random Extended MAC Address Required'): mac = self.dut.mac inp = dialog.find_element_by_id('cnfrmInpText') inp.clear() @@ -973,7 +1034,8 @@ class HarnessCase(unittest.TestCase): ll64 = None for addr in self.dut.addrs: addr = addr.lower() - if addr.startswith('fe80') and not re.match('.+ff:fe00:[0-9a-f]{0,4}$', addr): + if addr.startswith('fe80') and not re.match( + '.+ff:fe00:[0-9a-f]{0,4}$', addr): ll64 = addr break @@ -1006,7 +1068,8 @@ class HarnessCase(unittest.TestCase): elif title.startswith('ML64 Address'): ml64 = None for addr in self.dut.addrs: - if addr.startswith('fd') and not re.match('.+ff:fe00:[0-9a-f]{0,4}$', addr): + if addr.startswith('fd') and not re.match( + '.+ff:fe00:[0-9a-f]{0,4}$', addr): ml64 = addr break @@ -1018,18 +1081,21 @@ class HarnessCase(unittest.TestCase): inp.clear() inp.send_keys(ml64) - elif title.startswith('Shield Devices') or title.startswith('Shield DUT'): + elif title.startswith('Shield Devices') or title.startswith( + 'Shield DUT'): time.sleep(2) if self.rf_shield: logger.info('Shielding devices') with self.rf_shield: self.rf_shield.shield() elif self.dut and settings.SHIELD_SIMULATION: - self.dut.channel = (self.channel == THREAD_CHANNEL_MAX and THREAD_CHANNEL_MIN) or (self.channel + 1) + self.dut.channel = (self.channel == THREAD_CHANNEL_MAX and + THREAD_CHANNEL_MIN) or (self.channel + 1) else: input('Shield DUT and press enter to continue..') - elif title.startswith('Unshield Devices') or title.startswith('Bring DUT back to network'): + elif title.startswith('Unshield Devices') or title.startswith( + 'Bring DUT back to network'): time.sleep(5) if self.rf_shield: logger.info('Unshielding devices') @@ -1044,7 +1110,8 @@ class HarnessCase(unittest.TestCase): body = dialog.find_element_by_id('cnfrmMsg').text body = body.split(': ')[1] params = reduce( - lambda params, param: params.update(((param[0].strip(' '), param[1]),)) or params, + lambda params, param: params.update( + ((param[0].strip(' '), param[1]),)) or params, [it.split('=') for it in body.split(', ')], {}, ) diff --git a/tools/harness-automation/autothreadharness/harness_controller.py b/tools/harness-automation/autothreadharness/harness_controller.py index 5f9ad4a43..d1b8bd951 100644 --- a/tools/harness-automation/autothreadharness/harness_controller.py +++ b/tools/harness-automation/autothreadharness/harness_controller.py @@ -27,7 +27,6 @@ # POSSIBILITY OF SUCH DAMAGE. # - import ConfigParser import logging import os @@ -93,7 +92,8 @@ class HarnessController(object): % (settings.HARNESS_HOME, settings.HARNESS_HOME), ) - self.harness_file = '%s\\harness-%s.log' % (self.result_dir, time.strftime('%Y%m%d%H%M%S')) + self.harness_file = '%s\\harness-%s.log' % ( + self.result_dir, time.strftime('%Y%m%d%H%M%S')) with open(self.harness_file, 'w') as harness_out: self.harness = subprocess.Popen( [ @@ -113,7 +113,10 @@ class HarnessController(object): if self.miniweb: logger.warning('Miniweb already started') else: - with open('%s\\miniweb-%s.log' % (self.result_dir, time.strftime('%Y%m%d%H%M%S')), 'w') as miniweb_out: + with open( + '%s\\miniweb-%s.log' % + (self.result_dir, time.strftime('%Y%m%d%H%M%S')), + 'w') as miniweb_out: self.miniweb = subprocess.Popen( [settings.HARNESS_HOME + '\\MiniWeb\\miniweb.exe'], stdout=miniweb_out, diff --git a/tools/harness-automation/autothreadharness/helpers.py b/tools/harness-automation/autothreadharness/helpers.py index 1a931de85..e8834a127 100644 --- a/tools/harness-automation/autothreadharness/helpers.py +++ b/tools/harness-automation/autothreadharness/helpers.py @@ -27,7 +27,6 @@ # POSSIBILITY OF SUCH DAMAGE. # - import json import logging diff --git a/tools/harness-automation/autothreadharness/open_thread_controller.py b/tools/harness-automation/autothreadharness/open_thread_controller.py index 5bfda3afd..44ad8ac4f 100644 --- a/tools/harness-automation/autothreadharness/open_thread_controller.py +++ b/tools/harness-automation/autothreadharness/open_thread_controller.py @@ -27,7 +27,6 @@ # POSSIBILITY OF SUCH DAMAGE. # - import logging import re import socket @@ -107,7 +106,10 @@ class OpenThreadController(threading.Thread): self.handle.setblocking(0) self._is_net = True else: - self.handle = serial.Serial(self.port, 115200, timeout=0, xonxoff=True) + self.handle = serial.Serial(self.port, + 115200, + timeout=0, + xonxoff=True) self._is_net = False def _read(self, size=512): diff --git a/tools/harness-automation/autothreadharness/pdu_controller.py b/tools/harness-automation/autothreadharness/pdu_controller.py index 058a11cba..6f2f99bc7 100644 --- a/tools/harness-automation/autothreadharness/pdu_controller.py +++ b/tools/harness-automation/autothreadharness/pdu_controller.py @@ -44,6 +44,7 @@ logger = logging.getLogger(__name__) class PduController(object): + def open(self, **params): """Open PDU controller connection""" raise NotImplementedError @@ -71,6 +72,7 @@ class DummyPduController(PduController): class ApcPduController(PduController): + def __init__(self): self.tn = None @@ -168,6 +170,7 @@ class ApcPduController(PduController): class NordicBoardPduController(PduController): + def open(self, **params): pass @@ -178,7 +181,8 @@ class NordicBoardPduController(PduController): boards_serial_numbers = params['boards_serial_numbers'] for serial_number in boards_serial_numbers: - logger.info('Resetting board with the serial number: %s', serial_number) + logger.info('Resetting board with the serial number: %s', + serial_number) self._pin_reset(serial_number) def close(self): @@ -186,10 +190,12 @@ class NordicBoardPduController(PduController): class IpPowerSocketPduController(PduController): + def open(self, **params): self._base_url = 'http://{}/outs.cgi?out'.format(params['ip']) password_manager = HTTPPasswordMgrWithDefaultRealm() - password_manager.add_password(None, self._base_url, params['user'], params['pass']) + password_manager.add_password(None, self._base_url, params['user'], + params['pass']) authentication_handler = HTTPBasicAuthHandler(password_manager) self._opener = build_opener(authentication_handler) @@ -216,6 +222,7 @@ class IpPowerSocketPduController(PduController): class ManualPduController(PduController): + def open(self, **kwargs): pass diff --git a/tools/harness-automation/autothreadharness/rf_shield_controller.py b/tools/harness-automation/autothreadharness/rf_shield_controller.py index e1726548b..cf885d10a 100644 --- a/tools/harness-automation/autothreadharness/rf_shield_controller.py +++ b/tools/harness-automation/autothreadharness/rf_shield_controller.py @@ -33,12 +33,12 @@ import logging import serial import time - ABC = abc.ABC if sys.version_info >= (3, 4) else abc.ABCMeta('ABC', (), {}) logger = logging.getLogger(__name__) class RfShieldController(ABC): + @abc.abstractmethod def shield(self): pass @@ -57,6 +57,7 @@ class RfShieldController(ABC): class RfSwitchController(RfShieldController): + def __init__(self, channel, port): self._channel = channel self._port = port @@ -96,4 +97,5 @@ CONTROLLERS = {'RF_SWITCH': RfSwitchController} def get_rf_shield_controller(shield_type, params): if shield_type in CONTROLLERS: return CONTROLLERS[shield_type](**params) - logger.exception('Unknown RF shield controller type: {}'.format(shield_type)) + logger.exception( + 'Unknown RF shield controller type: {}'.format(shield_type)) diff --git a/tools/harness-automation/autothreadharness/runner.py b/tools/harness-automation/autothreadharness/runner.py index 2b2c60a1d..6950f3d1f 100644 --- a/tools/harness-automation/autothreadharness/runner.py +++ b/tools/harness-automation/autothreadharness/runner.py @@ -27,7 +27,6 @@ # POSSIBILITY OF SUCH DAMAGE. # - import ConfigParser import argparse import fnmatch @@ -57,7 +56,11 @@ class SimpleTestResult(unittest.TestResult): executions = 0 - def __init__(self, path, auto_reboot_args=None, keep_explorer=False, add_all_devices=False): + def __init__(self, + path, + auto_reboot_args=None, + keep_explorer=False, + add_all_devices=False): """Record test results in json file Args: @@ -86,17 +89,20 @@ class SimpleTestResult(unittest.TestResult): if self.auto_reboot_args: test.auto_reboot = True os.system( - 'echo %s > "%s"' - % (' '.join(self.auto_reboot_args + ['-c', test.__class__.__name__]), RESUME_SCRIPT_PATH) - ) + 'echo %s > "%s"' % + (' '.join(self.auto_reboot_args + + ['-c', test.__class__.__name__]), RESUME_SCRIPT_PATH)) # record start timestamp self.started = time.strftime('%Y-%m-%dT%H:%M:%S') os.system('mkdir %s' % test.result_dir) - self.log_handler = logging.FileHandler('%s\\auto-%s.log' % (test.result_dir, time.strftime('%Y%m%d%H%M%S'))) + self.log_handler = logging.FileHandler( + '%s\\auto-%s.log' % + (test.result_dir, time.strftime('%Y%m%d%H%M%S'))) self.log_handler.setLevel(logging.DEBUG) - self.log_handler.setFormatter(logging.Formatter('%(asctime)s %(levelname)s %(message)s')) + self.log_handler.setFormatter( + logging.Formatter('%(asctime)s %(levelname)s %(message)s')) logger.addHandler(self.log_handler) def add_result(self, test, passed, error=None): @@ -120,7 +126,9 @@ class SimpleTestResult(unittest.TestResult): if self.auto_reboot_args: os.system('del "%s"' % RESUME_SCRIPT_PATH) - json.dump(OrderedDict(sorted(self.result.items(), key=lambda t: t[0])), open(self.path, 'w'), indent=2) + json.dump(OrderedDict(sorted(self.result.items(), key=lambda t: t[0])), + open(self.path, 'w'), + indent=2) # save logs logger.removeHandler(self.log_handler) @@ -161,7 +169,10 @@ def list_devices(names=None, continue_from=None, **kwargs): """List devices in settings file and print versions""" if not names: - names = [device for device, _type in settings.GOLDEN_DEVICES if _type == 'OpenThread'] + names = [ + device for device, _type in settings.GOLDEN_DEVICES + if _type == 'OpenThread' + ] if continue_from: continue_from = names.index(continue_from) @@ -207,7 +218,11 @@ def discover( if blacklist: try: - excludes = [line.strip('\n') for line in open(blacklist, 'r').readlines() if not line.startswith('#')] + excludes = [ + line.strip('\n') + for line in open(blacklist, 'r').readlines() + if not line.startswith('#') + ] except BaseException: logger.exception('Failed to open test case black list file') raise @@ -228,10 +243,11 @@ def discover( new_th = False harness_info = ConfigParser.ConfigParser() harness_info.read('%s\\info.ini' % settings.HARNESS_HOME) - if harness_info.has_option('Thread_Harness_Info', 'Version') and harness_info.has_option( - 'Thread_Harness_Info', 'Mode' - ): - harness_version = harness_info.get('Thread_Harness_Info', 'Version').rsplit(' ', 1)[1] + if harness_info.has_option('Thread_Harness_Info', + 'Version') and harness_info.has_option( + 'Thread_Harness_Info', 'Mode'): + harness_version = harness_info.get('Thread_Harness_Info', + 'Version').rsplit(' ', 1)[1] harness_mode = harness_info.get('Thread_Harness_Info', 'Mode') if harness_mode == 'External' and harness_version > '1.4.0': @@ -247,7 +263,7 @@ def discover( discovered = unittest.defaultTestLoader.discover('cases_R140', pattern) if names and continue_from: - names = names[names.index(continue_from) :] + names = names[names.index(continue_from):] for s1 in discovered: for s2 in s1: @@ -257,7 +273,9 @@ def discover( case_name = str(case.__class__.__name__) # grep name - if name_greps and not any(fnmatch.fnmatch(case_name, name_grep) for name_grep in name_greps): + if name_greps and not any( + fnmatch.fnmatch(case_name, name_grep) + for name_grep in name_greps): logger.info('case[%s] skipped by name greps', case_name) continue @@ -268,18 +286,18 @@ def discover( # skip cases if case_name in log.keys(): - if ( - (log[case_name]['passed'] and ('p' in skip)) - or (log[case_name]['passed'] is False and ('f' in skip)) - or (log[case_name]['passed'] is None and ('e' in skip)) - ): - logger.warning('case[%s] skipped for its status[%s]', case_name, log[case_name]['passed']) + if ((log[case_name]['passed'] and ('p' in skip)) or + (log[case_name]['passed'] is False and ('f' in skip)) or + (log[case_name]['passed'] is None and ('e' in skip))): + logger.warning('case[%s] skipped for its status[%s]', + case_name, log[case_name]['passed']) continue # continue from if continue_from: if continue_from != case_name: - logger.warning('case[%s] skipped for continue from[%s]', case_name, continue_from) + logger.warning('case[%s] skipped for continue from[%s]', + case_name, continue_from) continue else: continue_from = None @@ -292,8 +310,8 @@ def discover( # max devices if max_devices and case.golden_devices_required > max_devices: logger.warning( - 'case[%s] skipped for exceeding max golden devices allowed[%d]', case_name, max_devices - ) + 'case[%s] skipped for exceeding max golden devices allowed[%d]', + case_name, max_devices) continue suite.addTest(case) @@ -325,7 +343,8 @@ def discover( settings.PDU_CONTROLLER_OPEN_PARAMS = {} settings.PDU_CONTROLLER_REBOOT_PARAMS = {} - result = SimpleTestResult(result_file, auto_reboot_args, keep_explorer, add_all_devices) + result = SimpleTestResult(result_file, auto_reboot_args, keep_explorer, + add_all_devices) for case in suite: logger.info(case.__class__.__name__) @@ -337,23 +356,50 @@ def discover( def main(): - parser = argparse.ArgumentParser(description='Thread harness test case runner') - parser.add_argument( - '--auto-reboot', '-a', action='store_true', default=False, help='restart system when harness service die' - ) - parser.add_argument( - 'names', metavar='NAME', type=str, nargs='*', default=None, help='test case name, omit to test all' - ) - parser.add_argument( - '--blacklist', '-b', metavar='BLACKLIST_FILE', type=str, help='file to list test cases to skip', default=None - ) - parser.add_argument('--continue-from', '-c', type=str, default=None, help='first case to test') - parser.add_argument('--delete-history', '-d', action='store_true', default=False, help='clear history on startup') - parser.add_argument( - '--keep-explorer', '-e', action='store_true', default=False, help='do not restart explorer.exe at the end' - ) - parser.add_argument('--name-greps', '-g', action='append', default=None, help='grep case by names') - parser.add_argument('--list-file', '-i', type=str, default=None, help='file to list cases names to test') + parser = argparse.ArgumentParser( + description='Thread harness test case runner') + parser.add_argument('--auto-reboot', + '-a', + action='store_true', + default=False, + help='restart system when harness service die') + parser.add_argument('names', + metavar='NAME', + type=str, + nargs='*', + default=None, + help='test case name, omit to test all') + parser.add_argument('--blacklist', + '-b', + metavar='BLACKLIST_FILE', + type=str, + help='file to list test cases to skip', + default=None) + parser.add_argument('--continue-from', + '-c', + type=str, + default=None, + help='first case to test') + parser.add_argument('--delete-history', + '-d', + action='store_true', + default=False, + help='clear history on startup') + parser.add_argument('--keep-explorer', + '-e', + action='store_true', + default=False, + help='do not restart explorer.exe at the end') + parser.add_argument('--name-greps', + '-g', + action='append', + default=None, + help='grep case by names') + parser.add_argument('--list-file', + '-i', + type=str, + default=None, + help='file to list cases names to test') parser.add_argument( '--skip', '-k', @@ -362,9 +408,21 @@ def main(): help='type of results to skip. e for error, f for fail, p for pass.', default='', ) - parser.add_argument('--list-devices', '-l', action='store_true', default=False, help='list devices') - parser.add_argument('--manual-reset', '-m', action='store_true', default=False, help='reset devices manually') - parser.add_argument('--dry-run', '-n', action='store_true', default=False, help='just show what to run') + parser.add_argument('--list-devices', + '-l', + action='store_true', + default=False, + help='list devices') + parser.add_argument('--manual-reset', + '-m', + action='store_true', + default=False, + help='reset devices manually') + parser.add_argument('--dry-run', + '-n', + action='store_true', + default=False, + help='just show what to run') parser.add_argument( '--result-file', '-o', @@ -372,20 +430,37 @@ def main(): default=settings.OUTPUT_PATH + '\\result.json', help='file to store and read current status', ) - parser.add_argument( - '--pattern', '-p', metavar='PATTERN', type=str, help='file name pattern, default to "*.py"', default='*.py' - ) - parser.add_argument('--rerun-fails', '-r', type=int, default=0, help='number of times to rerun failed test cases') - parser.add_argument( - '--add-all-devices', '-t', action='store_true', default=False, help='add all devices to the test bed' - ) - parser.add_argument('--max-devices', '-u', type=int, default=0, help='max golden devices allowed') + parser.add_argument('--pattern', + '-p', + metavar='PATTERN', + type=str, + help='file name pattern, default to "*.py"', + default='*.py') + parser.add_argument('--rerun-fails', + '-r', + type=int, + default=0, + help='number of times to rerun failed test cases') + parser.add_argument('--add-all-devices', + '-t', + action='store_true', + default=False, + help='add all devices to the test bed') + parser.add_argument('--max-devices', + '-u', + type=int, + default=0, + help='max golden devices allowed') args = vars(parser.parse_args()) if args['list_file']: try: - names = [line.strip('\n') for line in open(args['list_file'], 'r').readlines() if not line.startswith('#')] + names = [ + line.strip('\n') + for line in open(args['list_file'], 'r').readlines() + if not line.startswith('#') + ] except BaseException: logger.exception('Failed to open test case list file') raise @@ -403,7 +478,10 @@ def main(): if rerun_fails > 0: for i in range(rerun_fails): - failed_names = {name for name in result.result if result.result[name]['passed'] is False} + failed_names = { + name for name in result.result + if result.result[name]['passed'] is False + } if not failed_names: break logger.info('Rerunning failed test cases') diff --git a/tools/harness-automation/autothreadharness/settings_sample.py b/tools/harness-automation/autothreadharness/settings_sample.py index 6ac25ce55..f558737e1 100644 --- a/tools/harness-automation/autothreadharness/settings_sample.py +++ b/tools/harness-automation/autothreadharness/settings_sample.py @@ -27,7 +27,6 @@ # POSSIBILITY OF SUCH DAMAGE. # - AUTO_DUT = True """bool: Whether use the auto DUT feature of thread harness.""" diff --git a/tools/harness-automation/cases/border_7_1_1.py b/tools/harness-automation/cases/border_7_1_1.py index 8b221a19d..e28f50c44 100644 --- a/tools/harness-automation/cases/border_7_1_1.py +++ b/tools/harness-automation/cases/border_7_1_1.py @@ -27,7 +27,6 @@ # POSSIBILITY OF SUCH DAMAGE. # - from autothreadharness.harness_case import HarnessCase import unittest diff --git a/tools/harness-automation/cases/border_7_1_2.py b/tools/harness-automation/cases/border_7_1_2.py index d1d056a8a..b72979d6d 100644 --- a/tools/harness-automation/cases/border_7_1_2.py +++ b/tools/harness-automation/cases/border_7_1_2.py @@ -27,7 +27,6 @@ # POSSIBILITY OF SUCH DAMAGE. # - import unittest from autothreadharness.harness_case import HarnessCase diff --git a/tools/harness-automation/cases/border_7_1_3.py b/tools/harness-automation/cases/border_7_1_3.py index 9de68b5a6..40e9fe710 100644 --- a/tools/harness-automation/cases/border_7_1_3.py +++ b/tools/harness-automation/cases/border_7_1_3.py @@ -27,7 +27,6 @@ # POSSIBILITY OF SUCH DAMAGE. # - from autothreadharness.harness_case import HarnessCase import unittest diff --git a/tools/harness-automation/cases/border_7_1_4.py b/tools/harness-automation/cases/border_7_1_4.py index 00ecfcb3c..62755f18e 100644 --- a/tools/harness-automation/cases/border_7_1_4.py +++ b/tools/harness-automation/cases/border_7_1_4.py @@ -27,7 +27,6 @@ # POSSIBILITY OF SUCH DAMAGE. # - import unittest from autothreadharness.harness_case import HarnessCase diff --git a/tools/harness-automation/cases/border_7_1_5.py b/tools/harness-automation/cases/border_7_1_5.py index f77fdb831..c675995eb 100644 --- a/tools/harness-automation/cases/border_7_1_5.py +++ b/tools/harness-automation/cases/border_7_1_5.py @@ -27,7 +27,6 @@ # POSSIBILITY OF SUCH DAMAGE. # - import unittest from autothreadharness.harness_case import HarnessCase diff --git a/tools/harness-automation/cases/border_7_1_6.py b/tools/harness-automation/cases/border_7_1_6.py index 81b60a640..53ae7f468 100644 --- a/tools/harness-automation/cases/border_7_1_6.py +++ b/tools/harness-automation/cases/border_7_1_6.py @@ -27,7 +27,6 @@ # POSSIBILITY OF SUCH DAMAGE. # - from autothreadharness.harness_case import HarnessCase import unittest diff --git a/tools/harness-automation/cases/border_7_1_7.py b/tools/harness-automation/cases/border_7_1_7.py index a37674b1e..6993eb2e1 100644 --- a/tools/harness-automation/cases/border_7_1_7.py +++ b/tools/harness-automation/cases/border_7_1_7.py @@ -27,7 +27,6 @@ # POSSIBILITY OF SUCH DAMAGE. # - from autothreadharness.harness_case import HarnessCase import unittest diff --git a/tools/harness-automation/cases/border_7_1_8.py b/tools/harness-automation/cases/border_7_1_8.py index c56fe810c..7841804ee 100644 --- a/tools/harness-automation/cases/border_7_1_8.py +++ b/tools/harness-automation/cases/border_7_1_8.py @@ -27,7 +27,6 @@ # POSSIBILITY OF SUCH DAMAGE. # - import unittest from autothreadharness.harness_case import HarnessCase diff --git a/tools/harness-automation/cases/commissioner_8_1_1.py b/tools/harness-automation/cases/commissioner_8_1_1.py index 32b09f740..db4cb8b13 100644 --- a/tools/harness-automation/cases/commissioner_8_1_1.py +++ b/tools/harness-automation/cases/commissioner_8_1_1.py @@ -27,7 +27,6 @@ # POSSIBILITY OF SUCH DAMAGE. # - import unittest from autothreadharness.harness_case import HarnessCase diff --git a/tools/harness-automation/cases/commissioner_8_1_2.py b/tools/harness-automation/cases/commissioner_8_1_2.py index f31177c47..2022a8f55 100644 --- a/tools/harness-automation/cases/commissioner_8_1_2.py +++ b/tools/harness-automation/cases/commissioner_8_1_2.py @@ -27,7 +27,6 @@ # POSSIBILITY OF SUCH DAMAGE. # - import unittest from autothreadharness.harness_case import HarnessCase diff --git a/tools/harness-automation/cases/commissioner_8_1_6.py b/tools/harness-automation/cases/commissioner_8_1_6.py index ab4d094fc..141fa60e4 100644 --- a/tools/harness-automation/cases/commissioner_8_1_6.py +++ b/tools/harness-automation/cases/commissioner_8_1_6.py @@ -27,7 +27,6 @@ # POSSIBILITY OF SUCH DAMAGE. # - import unittest from autothreadharness.harness_case import HarnessCase diff --git a/tools/harness-automation/cases/commissioner_8_2_1.py b/tools/harness-automation/cases/commissioner_8_2_1.py index 990f08abf..185111855 100644 --- a/tools/harness-automation/cases/commissioner_8_2_1.py +++ b/tools/harness-automation/cases/commissioner_8_2_1.py @@ -27,7 +27,6 @@ # POSSIBILITY OF SUCH DAMAGE. # - import unittest from autothreadharness.harness_case import HarnessCase diff --git a/tools/harness-automation/cases/commissioner_8_2_2.py b/tools/harness-automation/cases/commissioner_8_2_2.py index 5ada36a87..e365967f5 100644 --- a/tools/harness-automation/cases/commissioner_8_2_2.py +++ b/tools/harness-automation/cases/commissioner_8_2_2.py @@ -27,7 +27,6 @@ # POSSIBILITY OF SUCH DAMAGE. # - import unittest from autothreadharness.harness_case import HarnessCase diff --git a/tools/harness-automation/cases/commissioner_8_2_5.py b/tools/harness-automation/cases/commissioner_8_2_5.py index a284b397a..ceebaec1d 100644 --- a/tools/harness-automation/cases/commissioner_8_2_5.py +++ b/tools/harness-automation/cases/commissioner_8_2_5.py @@ -27,7 +27,6 @@ # POSSIBILITY OF SUCH DAMAGE. # - import unittest from autothreadharness.harness_case import HarnessCase diff --git a/tools/harness-automation/cases/commissioner_8_3_1.py b/tools/harness-automation/cases/commissioner_8_3_1.py index 26eef232c..0376820cb 100644 --- a/tools/harness-automation/cases/commissioner_8_3_1.py +++ b/tools/harness-automation/cases/commissioner_8_3_1.py @@ -27,7 +27,6 @@ # POSSIBILITY OF SUCH DAMAGE. # - import unittest from autothreadharness.harness_case import HarnessCase diff --git a/tools/harness-automation/cases/commissioner_9_2_1.py b/tools/harness-automation/cases/commissioner_9_2_1.py index a264e55f0..471ba977e 100644 --- a/tools/harness-automation/cases/commissioner_9_2_1.py +++ b/tools/harness-automation/cases/commissioner_9_2_1.py @@ -27,7 +27,6 @@ # POSSIBILITY OF SUCH DAMAGE. # - import unittest from autothreadharness.harness_case import HarnessCase diff --git a/tools/harness-automation/cases/commissioner_9_2_14.py b/tools/harness-automation/cases/commissioner_9_2_14.py index d090d47f4..2f87c6b41 100644 --- a/tools/harness-automation/cases/commissioner_9_2_14.py +++ b/tools/harness-automation/cases/commissioner_9_2_14.py @@ -27,7 +27,6 @@ # POSSIBILITY OF SUCH DAMAGE. # - import unittest from autothreadharness.harness_case import HarnessCase diff --git a/tools/harness-automation/cases/commissioner_9_2_19.py b/tools/harness-automation/cases/commissioner_9_2_19.py index 78265a7b9..13db30782 100755 --- a/tools/harness-automation/cases/commissioner_9_2_19.py +++ b/tools/harness-automation/cases/commissioner_9_2_19.py @@ -27,7 +27,6 @@ # POSSIBILITY OF SUCH DAMAGE. # - import unittest from autothreadharness.harness_case import HarnessCase diff --git a/tools/harness-automation/cases/commissioner_9_2_2.py b/tools/harness-automation/cases/commissioner_9_2_2.py index 7ea4ab5a2..94ed5fa0c 100644 --- a/tools/harness-automation/cases/commissioner_9_2_2.py +++ b/tools/harness-automation/cases/commissioner_9_2_2.py @@ -27,7 +27,6 @@ # POSSIBILITY OF SUCH DAMAGE. # - import unittest from autothreadharness.harness_case import HarnessCase diff --git a/tools/harness-automation/cases/commissioner_9_2_3.py b/tools/harness-automation/cases/commissioner_9_2_3.py index e13cae288..61aa37be6 100644 --- a/tools/harness-automation/cases/commissioner_9_2_3.py +++ b/tools/harness-automation/cases/commissioner_9_2_3.py @@ -27,7 +27,6 @@ # POSSIBILITY OF SUCH DAMAGE. # - import unittest from autothreadharness.harness_case import HarnessCase diff --git a/tools/harness-automation/cases/commissioner_9_2_4.py b/tools/harness-automation/cases/commissioner_9_2_4.py index 9d46c6e04..c0c8b61b1 100644 --- a/tools/harness-automation/cases/commissioner_9_2_4.py +++ b/tools/harness-automation/cases/commissioner_9_2_4.py @@ -27,7 +27,6 @@ # POSSIBILITY OF SUCH DAMAGE. # - import unittest from autothreadharness.harness_case import HarnessCase diff --git a/tools/harness-automation/cases/ed_6_1_1.py b/tools/harness-automation/cases/ed_6_1_1.py index 52d2e4b68..79deead6d 100644 --- a/tools/harness-automation/cases/ed_6_1_1.py +++ b/tools/harness-automation/cases/ed_6_1_1.py @@ -27,7 +27,6 @@ # POSSIBILITY OF SUCH DAMAGE. # - import unittest from autothreadharness.harness_case import HarnessCase diff --git a/tools/harness-automation/cases/ed_6_1_2.py b/tools/harness-automation/cases/ed_6_1_2.py index a5eb4b01d..1336c493d 100644 --- a/tools/harness-automation/cases/ed_6_1_2.py +++ b/tools/harness-automation/cases/ed_6_1_2.py @@ -27,7 +27,6 @@ # POSSIBILITY OF SUCH DAMAGE. # - import unittest from autothreadharness.harness_case import HarnessCase diff --git a/tools/harness-automation/cases/ed_6_1_3.py b/tools/harness-automation/cases/ed_6_1_3.py index c6a65ece7..e99f86de1 100644 --- a/tools/harness-automation/cases/ed_6_1_3.py +++ b/tools/harness-automation/cases/ed_6_1_3.py @@ -27,7 +27,6 @@ # POSSIBILITY OF SUCH DAMAGE. # - import unittest from autothreadharness.harness_case import HarnessCase diff --git a/tools/harness-automation/cases/ed_6_1_4.py b/tools/harness-automation/cases/ed_6_1_4.py index 99894dcc2..dfcd85dae 100644 --- a/tools/harness-automation/cases/ed_6_1_4.py +++ b/tools/harness-automation/cases/ed_6_1_4.py @@ -27,7 +27,6 @@ # POSSIBILITY OF SUCH DAMAGE. # - import unittest from autothreadharness.harness_case import HarnessCase diff --git a/tools/harness-automation/cases/ed_6_1_5.py b/tools/harness-automation/cases/ed_6_1_5.py index 9e09ab8f2..70b900721 100644 --- a/tools/harness-automation/cases/ed_6_1_5.py +++ b/tools/harness-automation/cases/ed_6_1_5.py @@ -27,7 +27,6 @@ # POSSIBILITY OF SUCH DAMAGE. # - import unittest from autothreadharness.harness_case import HarnessCase diff --git a/tools/harness-automation/cases/ed_6_1_6.py b/tools/harness-automation/cases/ed_6_1_6.py index 399799b88..7d9d9e3b9 100644 --- a/tools/harness-automation/cases/ed_6_1_6.py +++ b/tools/harness-automation/cases/ed_6_1_6.py @@ -27,7 +27,6 @@ # POSSIBILITY OF SUCH DAMAGE. # - import unittest from autothreadharness.harness_case import HarnessCase diff --git a/tools/harness-automation/cases/ed_6_3_1.py b/tools/harness-automation/cases/ed_6_3_1.py index e19a0a594..f8c6cf433 100644 --- a/tools/harness-automation/cases/ed_6_3_1.py +++ b/tools/harness-automation/cases/ed_6_3_1.py @@ -27,7 +27,6 @@ # POSSIBILITY OF SUCH DAMAGE. # - import unittest from autothreadharness.harness_case import HarnessCase diff --git a/tools/harness-automation/cases/ed_6_4_1.py b/tools/harness-automation/cases/ed_6_4_1.py index 261bfa6fa..924ea4ee2 100644 --- a/tools/harness-automation/cases/ed_6_4_1.py +++ b/tools/harness-automation/cases/ed_6_4_1.py @@ -27,7 +27,6 @@ # POSSIBILITY OF SUCH DAMAGE. # - import unittest from autothreadharness.harness_case import HarnessCase diff --git a/tools/harness-automation/cases/ed_6_4_2.py b/tools/harness-automation/cases/ed_6_4_2.py index cb5337dd9..23bb14a65 100644 --- a/tools/harness-automation/cases/ed_6_4_2.py +++ b/tools/harness-automation/cases/ed_6_4_2.py @@ -27,7 +27,6 @@ # POSSIBILITY OF SUCH DAMAGE. # - import unittest from autothreadharness.harness_case import HarnessCase diff --git a/tools/harness-automation/cases/ed_6_5_1.py b/tools/harness-automation/cases/ed_6_5_1.py index fae820c51..7074de44a 100644 --- a/tools/harness-automation/cases/ed_6_5_1.py +++ b/tools/harness-automation/cases/ed_6_5_1.py @@ -27,7 +27,6 @@ # POSSIBILITY OF SUCH DAMAGE. # - import unittest import time diff --git a/tools/harness-automation/cases/ed_6_5_2.py b/tools/harness-automation/cases/ed_6_5_2.py index 08258801e..501d343ad 100644 --- a/tools/harness-automation/cases/ed_6_5_2.py +++ b/tools/harness-automation/cases/ed_6_5_2.py @@ -27,7 +27,6 @@ # POSSIBILITY OF SUCH DAMAGE. # - import unittest from autothreadharness.harness_case import HarnessCase diff --git a/tools/harness-automation/cases/ed_6_5_3.py b/tools/harness-automation/cases/ed_6_5_3.py index 2a9b20edb..5d1e35d69 100644 --- a/tools/harness-automation/cases/ed_6_5_3.py +++ b/tools/harness-automation/cases/ed_6_5_3.py @@ -27,7 +27,6 @@ # POSSIBILITY OF SUCH DAMAGE. # - import unittest from autothreadharness.harness_case import HarnessCase diff --git a/tools/harness-automation/cases/ed_6_6_1.py b/tools/harness-automation/cases/ed_6_6_1.py index 117c88153..e6baa88c6 100644 --- a/tools/harness-automation/cases/ed_6_6_1.py +++ b/tools/harness-automation/cases/ed_6_6_1.py @@ -27,7 +27,6 @@ # POSSIBILITY OF SUCH DAMAGE. # - import unittest from autothreadharness.harness_case import HarnessCase diff --git a/tools/harness-automation/cases/ed_6_6_2.py b/tools/harness-automation/cases/ed_6_6_2.py index 8bc84b435..4d53ab00b 100644 --- a/tools/harness-automation/cases/ed_6_6_2.py +++ b/tools/harness-automation/cases/ed_6_6_2.py @@ -27,7 +27,6 @@ # POSSIBILITY OF SUCH DAMAGE. # - import unittest from autothreadharness.harness_case import HarnessCase diff --git a/tools/harness-automation/cases/ed_9_2_17.py b/tools/harness-automation/cases/ed_9_2_17.py index e245fea48..98f4ef0f9 100644 --- a/tools/harness-automation/cases/ed_9_2_17.py +++ b/tools/harness-automation/cases/ed_9_2_17.py @@ -27,7 +27,6 @@ # POSSIBILITY OF SUCH DAMAGE. # - import unittest from autothreadharness.harness_case import HarnessCase diff --git a/tools/harness-automation/cases/ed_9_2_8.py b/tools/harness-automation/cases/ed_9_2_8.py index 4e254b195..94f5544a6 100644 --- a/tools/harness-automation/cases/ed_9_2_8.py +++ b/tools/harness-automation/cases/ed_9_2_8.py @@ -27,7 +27,6 @@ # POSSIBILITY OF SUCH DAMAGE. # - import unittest from autothreadharness.harness_case import HarnessCase diff --git a/tools/harness-automation/cases/fed_5_7_1.py b/tools/harness-automation/cases/fed_5_7_1.py index feb29e655..780fd5a4d 100755 --- a/tools/harness-automation/cases/fed_5_7_1.py +++ b/tools/harness-automation/cases/fed_5_7_1.py @@ -27,7 +27,6 @@ # POSSIBILITY OF SUCH DAMAGE. # - import unittest from autothreadharness.harness_case import HarnessCase diff --git a/tools/harness-automation/cases/fed_5_7_3.py b/tools/harness-automation/cases/fed_5_7_3.py index c34f1c381..4e341e5c8 100755 --- a/tools/harness-automation/cases/fed_5_7_3.py +++ b/tools/harness-automation/cases/fed_5_7_3.py @@ -27,7 +27,6 @@ # POSSIBILITY OF SUCH DAMAGE. # - import unittest from autothreadharness.harness_case import HarnessCase diff --git a/tools/harness-automation/cases/fed_6_1_7.py b/tools/harness-automation/cases/fed_6_1_7.py index 7fba55f9c..6822e0dcd 100644 --- a/tools/harness-automation/cases/fed_6_1_7.py +++ b/tools/harness-automation/cases/fed_6_1_7.py @@ -27,7 +27,6 @@ # POSSIBILITY OF SUCH DAMAGE. # - import unittest from autothreadharness.harness_case import HarnessCase diff --git a/tools/harness-automation/cases/fed_9_2_13.py b/tools/harness-automation/cases/fed_9_2_13.py index 7b84b4537..5217a2062 100644 --- a/tools/harness-automation/cases/fed_9_2_13.py +++ b/tools/harness-automation/cases/fed_9_2_13.py @@ -27,7 +27,6 @@ # POSSIBILITY OF SUCH DAMAGE. # - import unittest from autothreadharness.harness_case import HarnessCase diff --git a/tools/harness-automation/cases/joiner_8_1_1.py b/tools/harness-automation/cases/joiner_8_1_1.py index d71a7b7d5..d022e727e 100644 --- a/tools/harness-automation/cases/joiner_8_1_1.py +++ b/tools/harness-automation/cases/joiner_8_1_1.py @@ -27,7 +27,6 @@ # POSSIBILITY OF SUCH DAMAGE. # - import unittest from autothreadharness.harness_case import HarnessCase diff --git a/tools/harness-automation/cases/joiner_8_1_6.py b/tools/harness-automation/cases/joiner_8_1_6.py index 844499735..3622f55e0 100644 --- a/tools/harness-automation/cases/joiner_8_1_6.py +++ b/tools/harness-automation/cases/joiner_8_1_6.py @@ -27,7 +27,6 @@ # POSSIBILITY OF SUCH DAMAGE. # - import unittest from autothreadharness.harness_case import HarnessCase diff --git a/tools/harness-automation/cases/leader_5_1_1.py b/tools/harness-automation/cases/leader_5_1_1.py index 465d2bfd8..149b7f4c0 100644 --- a/tools/harness-automation/cases/leader_5_1_1.py +++ b/tools/harness-automation/cases/leader_5_1_1.py @@ -27,7 +27,6 @@ # POSSIBILITY OF SUCH DAMAGE. # - import unittest from autothreadharness.harness_case import HarnessCase diff --git a/tools/harness-automation/cases/leader_5_1_13.py b/tools/harness-automation/cases/leader_5_1_13.py index 001736874..a99e48964 100644 --- a/tools/harness-automation/cases/leader_5_1_13.py +++ b/tools/harness-automation/cases/leader_5_1_13.py @@ -27,7 +27,6 @@ # POSSIBILITY OF SUCH DAMAGE. # - from autothreadharness.harness_case import HarnessCase import time import unittest diff --git a/tools/harness-automation/cases/leader_5_1_5.py b/tools/harness-automation/cases/leader_5_1_5.py index 386496c4e..3e3d70645 100644 --- a/tools/harness-automation/cases/leader_5_1_5.py +++ b/tools/harness-automation/cases/leader_5_1_5.py @@ -27,7 +27,6 @@ # POSSIBILITY OF SUCH DAMAGE. # - from autothreadharness.harness_case import HarnessCase import unittest diff --git a/tools/harness-automation/cases/leader_5_2_3.py b/tools/harness-automation/cases/leader_5_2_3.py index 15bd2afb8..4ee3d7f59 100644 --- a/tools/harness-automation/cases/leader_5_2_3.py +++ b/tools/harness-automation/cases/leader_5_2_3.py @@ -27,7 +27,6 @@ # POSSIBILITY OF SUCH DAMAGE. # - import unittest from autothreadharness.harness_case import HarnessCase diff --git a/tools/harness-automation/cases/leader_5_3_6.py b/tools/harness-automation/cases/leader_5_3_6.py index 89cd19cae..f96c723d3 100644 --- a/tools/harness-automation/cases/leader_5_3_6.py +++ b/tools/harness-automation/cases/leader_5_3_6.py @@ -27,7 +27,6 @@ # POSSIBILITY OF SUCH DAMAGE. # - from autothreadharness.harness_case import HarnessCase import unittest diff --git a/tools/harness-automation/cases/leader_5_3_7.py b/tools/harness-automation/cases/leader_5_3_7.py index 68df333af..d9a024549 100644 --- a/tools/harness-automation/cases/leader_5_3_7.py +++ b/tools/harness-automation/cases/leader_5_3_7.py @@ -27,7 +27,6 @@ # POSSIBILITY OF SUCH DAMAGE. # - import unittest from autothreadharness.harness_case import HarnessCase diff --git a/tools/harness-automation/cases/leader_5_3_8.py b/tools/harness-automation/cases/leader_5_3_8.py index 1e642553c..3d505a006 100644 --- a/tools/harness-automation/cases/leader_5_3_8.py +++ b/tools/harness-automation/cases/leader_5_3_8.py @@ -27,7 +27,6 @@ # POSSIBILITY OF SUCH DAMAGE. # - import unittest from autothreadharness.harness_case import HarnessCase diff --git a/tools/harness-automation/cases/leader_5_5_1.py b/tools/harness-automation/cases/leader_5_5_1.py index 9bbc273cf..ecff0d63d 100644 --- a/tools/harness-automation/cases/leader_5_5_1.py +++ b/tools/harness-automation/cases/leader_5_5_1.py @@ -27,7 +27,6 @@ # POSSIBILITY OF SUCH DAMAGE. # - import re import time import unittest diff --git a/tools/harness-automation/cases/leader_5_5_2.py b/tools/harness-automation/cases/leader_5_5_2.py index 4f97befca..7ab95391e 100644 --- a/tools/harness-automation/cases/leader_5_5_2.py +++ b/tools/harness-automation/cases/leader_5_5_2.py @@ -27,7 +27,6 @@ # POSSIBILITY OF SUCH DAMAGE. # - import time import unittest diff --git a/tools/harness-automation/cases/leader_5_5_3.py b/tools/harness-automation/cases/leader_5_5_3.py index 07eb2fec0..5997c8219 100644 --- a/tools/harness-automation/cases/leader_5_5_3.py +++ b/tools/harness-automation/cases/leader_5_5_3.py @@ -27,7 +27,6 @@ # POSSIBILITY OF SUCH DAMAGE. # - import unittest from autothreadharness.harness_case import HarnessCase diff --git a/tools/harness-automation/cases/leader_5_5_4.py b/tools/harness-automation/cases/leader_5_5_4.py index 0547e7afa..dcabecddb 100644 --- a/tools/harness-automation/cases/leader_5_5_4.py +++ b/tools/harness-automation/cases/leader_5_5_4.py @@ -27,7 +27,6 @@ # POSSIBILITY OF SUCH DAMAGE. # - import unittest from autothreadharness.harness_case import HarnessCase diff --git a/tools/harness-automation/cases/leader_5_5_7.py b/tools/harness-automation/cases/leader_5_5_7.py index b9a5802a7..f4a8f1989 100644 --- a/tools/harness-automation/cases/leader_5_5_7.py +++ b/tools/harness-automation/cases/leader_5_5_7.py @@ -27,7 +27,6 @@ # POSSIBILITY OF SUCH DAMAGE. # - from autothreadharness.harness_case import HarnessCase import unittest diff --git a/tools/harness-automation/cases/leader_5_6_2.py b/tools/harness-automation/cases/leader_5_6_2.py index 06080a7a5..2163cb2e0 100644 --- a/tools/harness-automation/cases/leader_5_6_2.py +++ b/tools/harness-automation/cases/leader_5_6_2.py @@ -27,7 +27,6 @@ # POSSIBILITY OF SUCH DAMAGE. # - from autothreadharness.harness_case import HarnessCase import unittest diff --git a/tools/harness-automation/cases/leader_5_6_4.py b/tools/harness-automation/cases/leader_5_6_4.py index a588660a2..8d3584fae 100644 --- a/tools/harness-automation/cases/leader_5_6_4.py +++ b/tools/harness-automation/cases/leader_5_6_4.py @@ -27,7 +27,6 @@ # POSSIBILITY OF SUCH DAMAGE. # - import unittest from autothreadharness.harness_case import HarnessCase diff --git a/tools/harness-automation/cases/leader_5_6_5.py b/tools/harness-automation/cases/leader_5_6_5.py index aa18f5306..6da7d2393 100644 --- a/tools/harness-automation/cases/leader_5_6_5.py +++ b/tools/harness-automation/cases/leader_5_6_5.py @@ -27,7 +27,6 @@ # POSSIBILITY OF SUCH DAMAGE. # - import unittest from autothreadharness.harness_case import HarnessCase diff --git a/tools/harness-automation/cases/leader_5_6_6.py b/tools/harness-automation/cases/leader_5_6_6.py index 51d80b135..80d83d90a 100644 --- a/tools/harness-automation/cases/leader_5_6_6.py +++ b/tools/harness-automation/cases/leader_5_6_6.py @@ -27,7 +27,6 @@ # POSSIBILITY OF SUCH DAMAGE. # - import unittest from autothreadharness.harness_case import HarnessCase diff --git a/tools/harness-automation/cases/leader_5_8_4.py b/tools/harness-automation/cases/leader_5_8_4.py index 12c984ca6..04aec35b3 100644 --- a/tools/harness-automation/cases/leader_5_8_4.py +++ b/tools/harness-automation/cases/leader_5_8_4.py @@ -27,7 +27,6 @@ # POSSIBILITY OF SUCH DAMAGE. # - import unittest from autothreadharness.harness_case import HarnessCase diff --git a/tools/harness-automation/cases/leader_8_3_1.py b/tools/harness-automation/cases/leader_8_3_1.py index 8e3edf179..0f2d8ef34 100644 --- a/tools/harness-automation/cases/leader_8_3_1.py +++ b/tools/harness-automation/cases/leader_8_3_1.py @@ -27,7 +27,6 @@ # POSSIBILITY OF SUCH DAMAGE. # - import unittest from autothreadharness.harness_case import HarnessCase diff --git a/tools/harness-automation/cases/leader_9_2_1.py b/tools/harness-automation/cases/leader_9_2_1.py index 923782d46..f1d6d5bf4 100644 --- a/tools/harness-automation/cases/leader_9_2_1.py +++ b/tools/harness-automation/cases/leader_9_2_1.py @@ -27,7 +27,6 @@ # POSSIBILITY OF SUCH DAMAGE. # - import unittest from autothreadharness.harness_case import HarnessCase diff --git a/tools/harness-automation/cases/leader_9_2_11.py b/tools/harness-automation/cases/leader_9_2_11.py index 0174d82fd..26203b017 100644 --- a/tools/harness-automation/cases/leader_9_2_11.py +++ b/tools/harness-automation/cases/leader_9_2_11.py @@ -27,7 +27,6 @@ # POSSIBILITY OF SUCH DAMAGE. # - import unittest from autothreadharness.harness_case import HarnessCase diff --git a/tools/harness-automation/cases/leader_9_2_12.py b/tools/harness-automation/cases/leader_9_2_12.py index b35f11033..42b8f031f 100644 --- a/tools/harness-automation/cases/leader_9_2_12.py +++ b/tools/harness-automation/cases/leader_9_2_12.py @@ -27,7 +27,6 @@ # POSSIBILITY OF SUCH DAMAGE. # - import unittest from autothreadharness.harness_case import HarnessCase diff --git a/tools/harness-automation/cases/leader_9_2_18.py b/tools/harness-automation/cases/leader_9_2_18.py index 2a549dfbd..4b231dcb6 100644 --- a/tools/harness-automation/cases/leader_9_2_18.py +++ b/tools/harness-automation/cases/leader_9_2_18.py @@ -27,7 +27,6 @@ # POSSIBILITY OF SUCH DAMAGE. # - import unittest from autothreadharness.harness_case import HarnessCase diff --git a/tools/harness-automation/cases/leader_9_2_19.py b/tools/harness-automation/cases/leader_9_2_19.py index ae605354f..706538207 100755 --- a/tools/harness-automation/cases/leader_9_2_19.py +++ b/tools/harness-automation/cases/leader_9_2_19.py @@ -27,7 +27,6 @@ # POSSIBILITY OF SUCH DAMAGE. # - import unittest from autothreadharness.harness_case import HarnessCase diff --git a/tools/harness-automation/cases/leader_9_2_2.py b/tools/harness-automation/cases/leader_9_2_2.py index 449a63f53..4ae535f67 100644 --- a/tools/harness-automation/cases/leader_9_2_2.py +++ b/tools/harness-automation/cases/leader_9_2_2.py @@ -27,7 +27,6 @@ # POSSIBILITY OF SUCH DAMAGE. # - import unittest from autothreadharness.harness_case import HarnessCase diff --git a/tools/harness-automation/cases/leader_9_2_3.py b/tools/harness-automation/cases/leader_9_2_3.py index 4d1762713..ec5714ca6 100644 --- a/tools/harness-automation/cases/leader_9_2_3.py +++ b/tools/harness-automation/cases/leader_9_2_3.py @@ -27,7 +27,6 @@ # POSSIBILITY OF SUCH DAMAGE. # - import unittest from autothreadharness.harness_case import HarnessCase diff --git a/tools/harness-automation/cases/leader_9_2_4.py b/tools/harness-automation/cases/leader_9_2_4.py index e18cb36cd..35dc7d522 100644 --- a/tools/harness-automation/cases/leader_9_2_4.py +++ b/tools/harness-automation/cases/leader_9_2_4.py @@ -27,7 +27,6 @@ # POSSIBILITY OF SUCH DAMAGE. # - import unittest from autothreadharness.harness_case import HarnessCase diff --git a/tools/harness-automation/cases/leader_9_2_5.py b/tools/harness-automation/cases/leader_9_2_5.py index e4626ce9e..453cd1511 100644 --- a/tools/harness-automation/cases/leader_9_2_5.py +++ b/tools/harness-automation/cases/leader_9_2_5.py @@ -27,7 +27,6 @@ # POSSIBILITY OF SUCH DAMAGE. # - import unittest from autothreadharness.harness_case import HarnessCase diff --git a/tools/harness-automation/cases/leader_9_2_6.py b/tools/harness-automation/cases/leader_9_2_6.py index aecca92b4..a6f519123 100644 --- a/tools/harness-automation/cases/leader_9_2_6.py +++ b/tools/harness-automation/cases/leader_9_2_6.py @@ -27,7 +27,6 @@ # POSSIBILITY OF SUCH DAMAGE. # - import unittest from autothreadharness.harness_case import HarnessCase diff --git a/tools/harness-automation/cases/leader_9_2_7.py b/tools/harness-automation/cases/leader_9_2_7.py index a6f2deecd..7b07fdd13 100644 --- a/tools/harness-automation/cases/leader_9_2_7.py +++ b/tools/harness-automation/cases/leader_9_2_7.py @@ -27,7 +27,6 @@ # POSSIBILITY OF SUCH DAMAGE. # - import unittest from autothreadharness.harness_case import HarnessCase diff --git a/tools/harness-automation/cases/leader_9_2_9.py b/tools/harness-automation/cases/leader_9_2_9.py index 2fa91a256..d0a4b4fcd 100644 --- a/tools/harness-automation/cases/leader_9_2_9.py +++ b/tools/harness-automation/cases/leader_9_2_9.py @@ -27,7 +27,6 @@ # POSSIBILITY OF SUCH DAMAGE. # - import unittest from autothreadharness.harness_case import HarnessCase @@ -38,7 +37,8 @@ class Leader_9_2_9(HarnessCase): case = '9 2 9' golden_devices_required = 3 case_need_shield = True - device_order = [('Router_2', False), ('Commissioner', True), ('Router_1', False), ('DUT', True)] + device_order = [('Router_2', False), ('Commissioner', True), + ('Router_1', False), ('DUT', True)] def on_dialog(self, dialog, title): pass diff --git a/tools/harness-automation/cases/med_6_2_1.py b/tools/harness-automation/cases/med_6_2_1.py index 6599b77bb..2011d6083 100644 --- a/tools/harness-automation/cases/med_6_2_1.py +++ b/tools/harness-automation/cases/med_6_2_1.py @@ -27,7 +27,6 @@ # POSSIBILITY OF SUCH DAMAGE. # - import unittest from autothreadharness.harness_case import HarnessCase diff --git a/tools/harness-automation/cases/med_6_2_2.py b/tools/harness-automation/cases/med_6_2_2.py index 973a8c4ab..dbd6de0f9 100644 --- a/tools/harness-automation/cases/med_6_2_2.py +++ b/tools/harness-automation/cases/med_6_2_2.py @@ -27,7 +27,6 @@ # POSSIBILITY OF SUCH DAMAGE. # - import unittest from autothreadharness.harness_case import HarnessCase diff --git a/tools/harness-automation/cases/med_6_3_2.py b/tools/harness-automation/cases/med_6_3_2.py index 676a676d9..8586fd5b9 100644 --- a/tools/harness-automation/cases/med_6_3_2.py +++ b/tools/harness-automation/cases/med_6_3_2.py @@ -27,7 +27,6 @@ # POSSIBILITY OF SUCH DAMAGE. # - import unittest from autothreadharness.harness_case import HarnessCase diff --git a/tools/harness-automation/cases/med_9_2_10.py b/tools/harness-automation/cases/med_9_2_10.py index 915366978..ef3b473df 100644 --- a/tools/harness-automation/cases/med_9_2_10.py +++ b/tools/harness-automation/cases/med_9_2_10.py @@ -27,7 +27,6 @@ # POSSIBILITY OF SUCH DAMAGE. # - import unittest from autothreadharness.harness_case import HarnessCase @@ -38,7 +37,8 @@ class MED_9_2_10(HarnessCase): case = '9 2 10' golden_devices_required = 4 case_need_shield = True - device_order = [('SED_1', False), ('DUT', False), ('Router_1', False), ('Commissioner', True), ('Leader', True)] + device_order = [('SED_1', False), ('DUT', False), ('Router_1', False), + ('Commissioner', True), ('Leader', True)] def on_dialog(self, dialog, title): pass diff --git a/tools/harness-automation/cases/med_9_2_12.py b/tools/harness-automation/cases/med_9_2_12.py index 7c93f3c24..888240660 100644 --- a/tools/harness-automation/cases/med_9_2_12.py +++ b/tools/harness-automation/cases/med_9_2_12.py @@ -27,7 +27,6 @@ # POSSIBILITY OF SUCH DAMAGE. # - import unittest from autothreadharness.harness_case import HarnessCase diff --git a/tools/harness-automation/cases/med_9_2_13.py b/tools/harness-automation/cases/med_9_2_13.py index f45bf21d8..0f69823d4 100644 --- a/tools/harness-automation/cases/med_9_2_13.py +++ b/tools/harness-automation/cases/med_9_2_13.py @@ -27,7 +27,6 @@ # POSSIBILITY OF SUCH DAMAGE. # - import unittest from autothreadharness.harness_case import HarnessCase diff --git a/tools/harness-automation/cases/med_9_2_18.py b/tools/harness-automation/cases/med_9_2_18.py index 3c17bb89d..bc7bdaf2c 100644 --- a/tools/harness-automation/cases/med_9_2_18.py +++ b/tools/harness-automation/cases/med_9_2_18.py @@ -27,7 +27,6 @@ # POSSIBILITY OF SUCH DAMAGE. # - import unittest from autothreadharness.harness_case import HarnessCase diff --git a/tools/harness-automation/cases/med_9_2_6.py b/tools/harness-automation/cases/med_9_2_6.py index 5b8411c5c..40096d780 100644 --- a/tools/harness-automation/cases/med_9_2_6.py +++ b/tools/harness-automation/cases/med_9_2_6.py @@ -27,7 +27,6 @@ # POSSIBILITY OF SUCH DAMAGE. # - import unittest from autothreadharness.harness_case import HarnessCase diff --git a/tools/harness-automation/cases/reed_5_2_4.py b/tools/harness-automation/cases/reed_5_2_4.py index 8deba1c3b..b73f0182f 100644 --- a/tools/harness-automation/cases/reed_5_2_4.py +++ b/tools/harness-automation/cases/reed_5_2_4.py @@ -27,7 +27,6 @@ # POSSIBILITY OF SUCH DAMAGE. # - import unittest from autothreadharness.harness_case import HarnessCase diff --git a/tools/harness-automation/cases/reed_5_2_5.py b/tools/harness-automation/cases/reed_5_2_5.py index f9e3a8ed1..43fa62733 100644 --- a/tools/harness-automation/cases/reed_5_2_5.py +++ b/tools/harness-automation/cases/reed_5_2_5.py @@ -27,7 +27,6 @@ # POSSIBILITY OF SUCH DAMAGE. # - import unittest from autothreadharness.harness_case import HarnessCase diff --git a/tools/harness-automation/cases/reed_5_2_7.py b/tools/harness-automation/cases/reed_5_2_7.py index d77e80f86..54a3b18da 100644 --- a/tools/harness-automation/cases/reed_5_2_7.py +++ b/tools/harness-automation/cases/reed_5_2_7.py @@ -27,7 +27,6 @@ # POSSIBILITY OF SUCH DAMAGE. # - import unittest from autothreadharness.harness_case import HarnessCase diff --git a/tools/harness-automation/cases/reed_5_5_5.py b/tools/harness-automation/cases/reed_5_5_5.py index c2d71b902..82cb40c6f 100644 --- a/tools/harness-automation/cases/reed_5_5_5.py +++ b/tools/harness-automation/cases/reed_5_5_5.py @@ -27,7 +27,6 @@ # POSSIBILITY OF SUCH DAMAGE. # - import unittest from autothreadharness.harness_case import HarnessCase diff --git a/tools/harness-automation/cases/reed_5_6_7.py b/tools/harness-automation/cases/reed_5_6_7.py index 270fc1dd4..ece67ba36 100644 --- a/tools/harness-automation/cases/reed_5_6_7.py +++ b/tools/harness-automation/cases/reed_5_6_7.py @@ -27,7 +27,6 @@ # POSSIBILITY OF SUCH DAMAGE. # - import unittest from autothreadharness.harness_case import HarnessCase diff --git a/tools/harness-automation/cases/reed_5_7_2.py b/tools/harness-automation/cases/reed_5_7_2.py index 6b357812d..99f3c1860 100755 --- a/tools/harness-automation/cases/reed_5_7_2.py +++ b/tools/harness-automation/cases/reed_5_7_2.py @@ -27,7 +27,6 @@ # POSSIBILITY OF SUCH DAMAGE. # - import unittest from autothreadharness.harness_case import HarnessCase diff --git a/tools/harness-automation/cases/router_5_1_1.py b/tools/harness-automation/cases/router_5_1_1.py index 637a15c60..31962d42f 100644 --- a/tools/harness-automation/cases/router_5_1_1.py +++ b/tools/harness-automation/cases/router_5_1_1.py @@ -27,7 +27,6 @@ # POSSIBILITY OF SUCH DAMAGE. # - import unittest from autothreadharness.harness_case import HarnessCase diff --git a/tools/harness-automation/cases/router_5_1_10.py b/tools/harness-automation/cases/router_5_1_10.py index 8ac88174a..58fbd53e8 100644 --- a/tools/harness-automation/cases/router_5_1_10.py +++ b/tools/harness-automation/cases/router_5_1_10.py @@ -27,7 +27,6 @@ # POSSIBILITY OF SUCH DAMAGE. # - import unittest from autothreadharness.harness_case import HarnessCase diff --git a/tools/harness-automation/cases/router_5_1_11.py b/tools/harness-automation/cases/router_5_1_11.py index a818612cc..1c01dbe35 100644 --- a/tools/harness-automation/cases/router_5_1_11.py +++ b/tools/harness-automation/cases/router_5_1_11.py @@ -27,7 +27,6 @@ # POSSIBILITY OF SUCH DAMAGE. # - import unittest from autothreadharness.harness_case import HarnessCase diff --git a/tools/harness-automation/cases/router_5_1_12.py b/tools/harness-automation/cases/router_5_1_12.py index d69b9e80d..a2cd21e9c 100644 --- a/tools/harness-automation/cases/router_5_1_12.py +++ b/tools/harness-automation/cases/router_5_1_12.py @@ -27,7 +27,6 @@ # POSSIBILITY OF SUCH DAMAGE. # - import unittest from autothreadharness.harness_case import HarnessCase diff --git a/tools/harness-automation/cases/router_5_1_13.py b/tools/harness-automation/cases/router_5_1_13.py index 80e741327..94398afee 100644 --- a/tools/harness-automation/cases/router_5_1_13.py +++ b/tools/harness-automation/cases/router_5_1_13.py @@ -27,7 +27,6 @@ # POSSIBILITY OF SUCH DAMAGE. # - import unittest from autothreadharness.harness_case import HarnessCase diff --git a/tools/harness-automation/cases/router_5_1_2.py b/tools/harness-automation/cases/router_5_1_2.py index c430acab9..2cd73fb5a 100644 --- a/tools/harness-automation/cases/router_5_1_2.py +++ b/tools/harness-automation/cases/router_5_1_2.py @@ -27,7 +27,6 @@ # POSSIBILITY OF SUCH DAMAGE. # - import unittest from autothreadharness.harness_case import HarnessCase diff --git a/tools/harness-automation/cases/router_5_1_3.py b/tools/harness-automation/cases/router_5_1_3.py index b60d16fa2..a92871758 100644 --- a/tools/harness-automation/cases/router_5_1_3.py +++ b/tools/harness-automation/cases/router_5_1_3.py @@ -27,7 +27,6 @@ # POSSIBILITY OF SUCH DAMAGE. # - import unittest from autothreadharness.harness_case import HarnessCase diff --git a/tools/harness-automation/cases/router_5_1_4.py b/tools/harness-automation/cases/router_5_1_4.py index 477336f39..1f7839a9e 100644 --- a/tools/harness-automation/cases/router_5_1_4.py +++ b/tools/harness-automation/cases/router_5_1_4.py @@ -27,7 +27,6 @@ # POSSIBILITY OF SUCH DAMAGE. # - import unittest from autothreadharness.harness_case import HarnessCase diff --git a/tools/harness-automation/cases/router_5_1_6.py b/tools/harness-automation/cases/router_5_1_6.py index f64160922..8d97cbd24 100644 --- a/tools/harness-automation/cases/router_5_1_6.py +++ b/tools/harness-automation/cases/router_5_1_6.py @@ -27,7 +27,6 @@ # POSSIBILITY OF SUCH DAMAGE. # - import unittest from autothreadharness.harness_case import HarnessCase diff --git a/tools/harness-automation/cases/router_5_1_7.py b/tools/harness-automation/cases/router_5_1_7.py index dfecd892d..2c4bd2ac0 100644 --- a/tools/harness-automation/cases/router_5_1_7.py +++ b/tools/harness-automation/cases/router_5_1_7.py @@ -27,7 +27,6 @@ # POSSIBILITY OF SUCH DAMAGE. # - import unittest from autothreadharness.harness_case import HarnessCase diff --git a/tools/harness-automation/cases/router_5_1_8.py b/tools/harness-automation/cases/router_5_1_8.py index adfcf26ff..a97b967e6 100644 --- a/tools/harness-automation/cases/router_5_1_8.py +++ b/tools/harness-automation/cases/router_5_1_8.py @@ -27,7 +27,6 @@ # POSSIBILITY OF SUCH DAMAGE. # - import unittest from autothreadharness.harness_case import HarnessCase diff --git a/tools/harness-automation/cases/router_5_1_9.py b/tools/harness-automation/cases/router_5_1_9.py index 85f30839f..8a9d5527b 100644 --- a/tools/harness-automation/cases/router_5_1_9.py +++ b/tools/harness-automation/cases/router_5_1_9.py @@ -27,7 +27,6 @@ # POSSIBILITY OF SUCH DAMAGE. # - import unittest from autothreadharness.harness_case import HarnessCase diff --git a/tools/harness-automation/cases/router_5_2_1.py b/tools/harness-automation/cases/router_5_2_1.py index 9ac6fb290..d213607cb 100644 --- a/tools/harness-automation/cases/router_5_2_1.py +++ b/tools/harness-automation/cases/router_5_2_1.py @@ -27,7 +27,6 @@ # POSSIBILITY OF SUCH DAMAGE. # - import unittest from autothreadharness.harness_case import HarnessCase diff --git a/tools/harness-automation/cases/router_5_2_6.py b/tools/harness-automation/cases/router_5_2_6.py index d572e00e0..cf7c27490 100644 --- a/tools/harness-automation/cases/router_5_2_6.py +++ b/tools/harness-automation/cases/router_5_2_6.py @@ -27,7 +27,6 @@ # POSSIBILITY OF SUCH DAMAGE. # - import unittest from autothreadharness.harness_case import HarnessCase diff --git a/tools/harness-automation/cases/router_5_2_7.py b/tools/harness-automation/cases/router_5_2_7.py index 90b5ba0d2..ecb1e99ab 100644 --- a/tools/harness-automation/cases/router_5_2_7.py +++ b/tools/harness-automation/cases/router_5_2_7.py @@ -27,7 +27,6 @@ # POSSIBILITY OF SUCH DAMAGE. # - import unittest from autothreadharness.harness_case import HarnessCase diff --git a/tools/harness-automation/cases/router_5_3_1.py b/tools/harness-automation/cases/router_5_3_1.py index 7bedcf637..f2a517b56 100644 --- a/tools/harness-automation/cases/router_5_3_1.py +++ b/tools/harness-automation/cases/router_5_3_1.py @@ -27,7 +27,6 @@ # POSSIBILITY OF SUCH DAMAGE. # - from autothreadharness.harness_case import HarnessCase import unittest diff --git a/tools/harness-automation/cases/router_5_3_10.py b/tools/harness-automation/cases/router_5_3_10.py index b55513a2e..0af1b0963 100644 --- a/tools/harness-automation/cases/router_5_3_10.py +++ b/tools/harness-automation/cases/router_5_3_10.py @@ -27,7 +27,6 @@ # POSSIBILITY OF SUCH DAMAGE. # - from autothreadharness.harness_case import HarnessCase import unittest diff --git a/tools/harness-automation/cases/router_5_3_11.py b/tools/harness-automation/cases/router_5_3_11.py index 74c25b16d..89bf2376e 100644 --- a/tools/harness-automation/cases/router_5_3_11.py +++ b/tools/harness-automation/cases/router_5_3_11.py @@ -27,7 +27,6 @@ # POSSIBILITY OF SUCH DAMAGE. # - from autothreadharness.harness_case import HarnessCase import unittest diff --git a/tools/harness-automation/cases/router_5_3_2.py b/tools/harness-automation/cases/router_5_3_2.py index e91513622..546f86004 100644 --- a/tools/harness-automation/cases/router_5_3_2.py +++ b/tools/harness-automation/cases/router_5_3_2.py @@ -27,7 +27,6 @@ # POSSIBILITY OF SUCH DAMAGE. # - from autothreadharness.harness_case import HarnessCase import unittest diff --git a/tools/harness-automation/cases/router_5_3_3.py b/tools/harness-automation/cases/router_5_3_3.py index 9b1d50deb..9c736f4e8 100644 --- a/tools/harness-automation/cases/router_5_3_3.py +++ b/tools/harness-automation/cases/router_5_3_3.py @@ -27,7 +27,6 @@ # POSSIBILITY OF SUCH DAMAGE. # - from autothreadharness.harness_case import HarnessCase import unittest diff --git a/tools/harness-automation/cases/router_5_3_4.py b/tools/harness-automation/cases/router_5_3_4.py index 19170b8d0..50efcbff6 100644 --- a/tools/harness-automation/cases/router_5_3_4.py +++ b/tools/harness-automation/cases/router_5_3_4.py @@ -27,7 +27,6 @@ # POSSIBILITY OF SUCH DAMAGE. # - from autothreadharness.harness_case import HarnessCase import unittest diff --git a/tools/harness-automation/cases/router_5_3_5.py b/tools/harness-automation/cases/router_5_3_5.py index d527431e7..0c6644e63 100644 --- a/tools/harness-automation/cases/router_5_3_5.py +++ b/tools/harness-automation/cases/router_5_3_5.py @@ -27,7 +27,6 @@ # POSSIBILITY OF SUCH DAMAGE. # - from autothreadharness.harness_case import HarnessCase import unittest diff --git a/tools/harness-automation/cases/router_5_3_9.py b/tools/harness-automation/cases/router_5_3_9.py index c6388c4c7..f9e196cab 100644 --- a/tools/harness-automation/cases/router_5_3_9.py +++ b/tools/harness-automation/cases/router_5_3_9.py @@ -27,7 +27,6 @@ # POSSIBILITY OF SUCH DAMAGE. # - from autothreadharness.harness_case import HarnessCase import unittest diff --git a/tools/harness-automation/cases/router_5_5_1.py b/tools/harness-automation/cases/router_5_5_1.py index 10199705c..45c42bfc4 100644 --- a/tools/harness-automation/cases/router_5_5_1.py +++ b/tools/harness-automation/cases/router_5_5_1.py @@ -27,7 +27,6 @@ # POSSIBILITY OF SUCH DAMAGE. # - from autothreadharness.harness_case import HarnessCase import unittest diff --git a/tools/harness-automation/cases/router_5_5_2.py b/tools/harness-automation/cases/router_5_5_2.py index a1e736438..b3a8a7c89 100644 --- a/tools/harness-automation/cases/router_5_5_2.py +++ b/tools/harness-automation/cases/router_5_5_2.py @@ -27,7 +27,6 @@ # POSSIBILITY OF SUCH DAMAGE. # - from autothreadharness.harness_case import HarnessCase import unittest diff --git a/tools/harness-automation/cases/router_5_5_3.py b/tools/harness-automation/cases/router_5_5_3.py index e2bfcd6c4..a94c84ce9 100644 --- a/tools/harness-automation/cases/router_5_5_3.py +++ b/tools/harness-automation/cases/router_5_5_3.py @@ -27,7 +27,6 @@ # POSSIBILITY OF SUCH DAMAGE. # - from autothreadharness.harness_case import HarnessCase import unittest diff --git a/tools/harness-automation/cases/router_5_5_4.py b/tools/harness-automation/cases/router_5_5_4.py index d62044841..a10de7ca5 100644 --- a/tools/harness-automation/cases/router_5_5_4.py +++ b/tools/harness-automation/cases/router_5_5_4.py @@ -27,7 +27,6 @@ # POSSIBILITY OF SUCH DAMAGE. # - from autothreadharness.harness_case import HarnessCase import unittest diff --git a/tools/harness-automation/cases/router_5_5_7.py b/tools/harness-automation/cases/router_5_5_7.py index 45c5a73ef..e6e1e912b 100644 --- a/tools/harness-automation/cases/router_5_5_7.py +++ b/tools/harness-automation/cases/router_5_5_7.py @@ -27,7 +27,6 @@ # POSSIBILITY OF SUCH DAMAGE. # - from autothreadharness.harness_case import HarnessCase import unittest diff --git a/tools/harness-automation/cases/router_5_6_1.py b/tools/harness-automation/cases/router_5_6_1.py index 90a260e5c..2cf5317c1 100644 --- a/tools/harness-automation/cases/router_5_6_1.py +++ b/tools/harness-automation/cases/router_5_6_1.py @@ -27,7 +27,6 @@ # POSSIBILITY OF SUCH DAMAGE. # - from autothreadharness.harness_case import HarnessCase import unittest diff --git a/tools/harness-automation/cases/router_5_6_3.py b/tools/harness-automation/cases/router_5_6_3.py index 16d75cd5e..ad81f56e2 100644 --- a/tools/harness-automation/cases/router_5_6_3.py +++ b/tools/harness-automation/cases/router_5_6_3.py @@ -27,7 +27,6 @@ # POSSIBILITY OF SUCH DAMAGE. # - from autothreadharness.harness_case import HarnessCase import unittest diff --git a/tools/harness-automation/cases/router_5_6_9.py b/tools/harness-automation/cases/router_5_6_9.py index 29effa054..c79d8fae1 100644 --- a/tools/harness-automation/cases/router_5_6_9.py +++ b/tools/harness-automation/cases/router_5_6_9.py @@ -27,7 +27,6 @@ # POSSIBILITY OF SUCH DAMAGE. # - from autothreadharness.harness_case import HarnessCase import unittest diff --git a/tools/harness-automation/cases/router_5_7_1.py b/tools/harness-automation/cases/router_5_7_1.py index 760df76db..e521896c0 100644 --- a/tools/harness-automation/cases/router_5_7_1.py +++ b/tools/harness-automation/cases/router_5_7_1.py @@ -27,7 +27,6 @@ # POSSIBILITY OF SUCH DAMAGE. # - import unittest from autothreadharness.harness_case import HarnessCase diff --git a/tools/harness-automation/cases/router_5_7_3.py b/tools/harness-automation/cases/router_5_7_3.py index f3c475232..a2489fc8d 100755 --- a/tools/harness-automation/cases/router_5_7_3.py +++ b/tools/harness-automation/cases/router_5_7_3.py @@ -27,7 +27,6 @@ # POSSIBILITY OF SUCH DAMAGE. # - import unittest from autothreadharness.harness_case import HarnessCase diff --git a/tools/harness-automation/cases/router_5_8_2.py b/tools/harness-automation/cases/router_5_8_2.py index f7ea1e7da..60f737e9a 100644 --- a/tools/harness-automation/cases/router_5_8_2.py +++ b/tools/harness-automation/cases/router_5_8_2.py @@ -27,7 +27,6 @@ # POSSIBILITY OF SUCH DAMAGE. # - from autothreadharness.harness_case import HarnessCase import unittest diff --git a/tools/harness-automation/cases/router_5_8_3.py b/tools/harness-automation/cases/router_5_8_3.py index e6ceff5c3..644059c14 100644 --- a/tools/harness-automation/cases/router_5_8_3.py +++ b/tools/harness-automation/cases/router_5_8_3.py @@ -27,7 +27,6 @@ # POSSIBILITY OF SUCH DAMAGE. # - from autothreadharness.harness_case import HarnessCase import unittest diff --git a/tools/harness-automation/cases/router_8_2_1.py b/tools/harness-automation/cases/router_8_2_1.py index dd98c870a..04d3d82d9 100644 --- a/tools/harness-automation/cases/router_8_2_1.py +++ b/tools/harness-automation/cases/router_8_2_1.py @@ -27,7 +27,6 @@ # POSSIBILITY OF SUCH DAMAGE. # - import unittest from autothreadharness.harness_case import HarnessCase diff --git a/tools/harness-automation/cases/router_8_2_2.py b/tools/harness-automation/cases/router_8_2_2.py index 3701ec4e2..938a856e8 100644 --- a/tools/harness-automation/cases/router_8_2_2.py +++ b/tools/harness-automation/cases/router_8_2_2.py @@ -27,7 +27,6 @@ # POSSIBILITY OF SUCH DAMAGE. # - import unittest from autothreadharness.harness_case import HarnessCase diff --git a/tools/harness-automation/cases/router_8_2_5.py b/tools/harness-automation/cases/router_8_2_5.py index 553fd6dad..9ab985a75 100644 --- a/tools/harness-automation/cases/router_8_2_5.py +++ b/tools/harness-automation/cases/router_8_2_5.py @@ -27,7 +27,6 @@ # POSSIBILITY OF SUCH DAMAGE. # - import unittest from autothreadharness.harness_case import HarnessCase diff --git a/tools/harness-automation/cases/router_9_2_10.py b/tools/harness-automation/cases/router_9_2_10.py index c63cc34b7..ad0aa5e0b 100644 --- a/tools/harness-automation/cases/router_9_2_10.py +++ b/tools/harness-automation/cases/router_9_2_10.py @@ -27,7 +27,6 @@ # POSSIBILITY OF SUCH DAMAGE. # - import unittest from autothreadharness.harness_case import HarnessCase @@ -38,7 +37,8 @@ class Router_9_2_10(HarnessCase): case = '9 2 10' golden_devices_required = 4 case_need_shield = True - device_order = [('SED_1', False), ('MED_1', False), ('DUT', False), ('Commissioner', True), ('Leader', True)] + device_order = [('SED_1', False), ('MED_1', False), ('DUT', False), + ('Commissioner', True), ('Leader', True)] def on_dialog(self, dialog, title): pass diff --git a/tools/harness-automation/cases/router_9_2_12.py b/tools/harness-automation/cases/router_9_2_12.py index 003e34820..d4f23008d 100644 --- a/tools/harness-automation/cases/router_9_2_12.py +++ b/tools/harness-automation/cases/router_9_2_12.py @@ -27,7 +27,6 @@ # POSSIBILITY OF SUCH DAMAGE. # - import unittest from autothreadharness.harness_case import HarnessCase diff --git a/tools/harness-automation/cases/router_9_2_13.py b/tools/harness-automation/cases/router_9_2_13.py index eea25994c..3bab13488 100644 --- a/tools/harness-automation/cases/router_9_2_13.py +++ b/tools/harness-automation/cases/router_9_2_13.py @@ -27,7 +27,6 @@ # POSSIBILITY OF SUCH DAMAGE. # - import unittest from autothreadharness.harness_case import HarnessCase diff --git a/tools/harness-automation/cases/router_9_2_14.py b/tools/harness-automation/cases/router_9_2_14.py index 1ebff32c1..7e2cc659b 100644 --- a/tools/harness-automation/cases/router_9_2_14.py +++ b/tools/harness-automation/cases/router_9_2_14.py @@ -27,7 +27,6 @@ # POSSIBILITY OF SUCH DAMAGE. # - import unittest from autothreadharness.harness_case import HarnessCase diff --git a/tools/harness-automation/cases/router_9_2_15.py b/tools/harness-automation/cases/router_9_2_15.py index 23f58f93b..799ef3709 100644 --- a/tools/harness-automation/cases/router_9_2_15.py +++ b/tools/harness-automation/cases/router_9_2_15.py @@ -27,7 +27,6 @@ # POSSIBILITY OF SUCH DAMAGE. # - import unittest from autothreadharness.harness_case import HarnessCase diff --git a/tools/harness-automation/cases/router_9_2_16.py b/tools/harness-automation/cases/router_9_2_16.py index 9283de78d..7ef403099 100644 --- a/tools/harness-automation/cases/router_9_2_16.py +++ b/tools/harness-automation/cases/router_9_2_16.py @@ -27,7 +27,6 @@ # POSSIBILITY OF SUCH DAMAGE. # - import unittest from autothreadharness.harness_case import HarnessCase diff --git a/tools/harness-automation/cases/router_9_2_18.py b/tools/harness-automation/cases/router_9_2_18.py index edd44c5f6..e5c4fb05e 100644 --- a/tools/harness-automation/cases/router_9_2_18.py +++ b/tools/harness-automation/cases/router_9_2_18.py @@ -27,7 +27,6 @@ # POSSIBILITY OF SUCH DAMAGE. # - import unittest from autothreadharness.harness_case import HarnessCase diff --git a/tools/harness-automation/cases/router_9_2_6.py b/tools/harness-automation/cases/router_9_2_6.py index 7b2deb6f7..9cba0c7ac 100644 --- a/tools/harness-automation/cases/router_9_2_6.py +++ b/tools/harness-automation/cases/router_9_2_6.py @@ -27,7 +27,6 @@ # POSSIBILITY OF SUCH DAMAGE. # - import unittest from autothreadharness.harness_case import HarnessCase diff --git a/tools/harness-automation/cases/router_9_2_8.py b/tools/harness-automation/cases/router_9_2_8.py index 1f20cc697..9e7f19000 100644 --- a/tools/harness-automation/cases/router_9_2_8.py +++ b/tools/harness-automation/cases/router_9_2_8.py @@ -27,7 +27,6 @@ # POSSIBILITY OF SUCH DAMAGE. # - import unittest from autothreadharness.harness_case import HarnessCase diff --git a/tools/harness-automation/cases/router_9_2_9.py b/tools/harness-automation/cases/router_9_2_9.py index cc53ddcb3..ea1612649 100644 --- a/tools/harness-automation/cases/router_9_2_9.py +++ b/tools/harness-automation/cases/router_9_2_9.py @@ -27,7 +27,6 @@ # POSSIBILITY OF SUCH DAMAGE. # - import unittest from autothreadharness.harness_case import HarnessCase @@ -38,7 +37,8 @@ class Router_9_2_9(HarnessCase): case = '9 2 9' golden_devices_required = 3 case_need_shield = True - device_order = [('Router_2', False), ('Commissioner', True), ('DUT', False), ('Leader', True)] + device_order = [('Router_2', False), ('Commissioner', True), ('DUT', False), + ('Leader', True)] def on_dialog(self, dialog, title): pass diff --git a/tools/harness-automation/cases/sed_6_1_1.py b/tools/harness-automation/cases/sed_6_1_1.py index 81221a702..6f27b2479 100644 --- a/tools/harness-automation/cases/sed_6_1_1.py +++ b/tools/harness-automation/cases/sed_6_1_1.py @@ -27,7 +27,6 @@ # POSSIBILITY OF SUCH DAMAGE. # - import unittest from autothreadharness.harness_case import HarnessCase diff --git a/tools/harness-automation/cases/sed_6_1_2.py b/tools/harness-automation/cases/sed_6_1_2.py index c3acbc6da..92f335535 100644 --- a/tools/harness-automation/cases/sed_6_1_2.py +++ b/tools/harness-automation/cases/sed_6_1_2.py @@ -27,7 +27,6 @@ # POSSIBILITY OF SUCH DAMAGE. # - import unittest from autothreadharness.harness_case import HarnessCase diff --git a/tools/harness-automation/cases/sed_6_1_3.py b/tools/harness-automation/cases/sed_6_1_3.py index 42fab2306..bb989a0f6 100644 --- a/tools/harness-automation/cases/sed_6_1_3.py +++ b/tools/harness-automation/cases/sed_6_1_3.py @@ -27,7 +27,6 @@ # POSSIBILITY OF SUCH DAMAGE. # - import unittest from autothreadharness.harness_case import HarnessCase diff --git a/tools/harness-automation/cases/sed_6_1_4.py b/tools/harness-automation/cases/sed_6_1_4.py index c508b8277..49eb27d3b 100644 --- a/tools/harness-automation/cases/sed_6_1_4.py +++ b/tools/harness-automation/cases/sed_6_1_4.py @@ -27,7 +27,6 @@ # POSSIBILITY OF SUCH DAMAGE. # - import unittest from autothreadharness.harness_case import HarnessCase diff --git a/tools/harness-automation/cases/sed_6_1_5.py b/tools/harness-automation/cases/sed_6_1_5.py index 49048f443..f7483fba5 100644 --- a/tools/harness-automation/cases/sed_6_1_5.py +++ b/tools/harness-automation/cases/sed_6_1_5.py @@ -27,7 +27,6 @@ # POSSIBILITY OF SUCH DAMAGE. # - import unittest from autothreadharness.harness_case import HarnessCase diff --git a/tools/harness-automation/cases/sed_6_1_6.py b/tools/harness-automation/cases/sed_6_1_6.py index 5c20abc24..6cc8d6979 100644 --- a/tools/harness-automation/cases/sed_6_1_6.py +++ b/tools/harness-automation/cases/sed_6_1_6.py @@ -27,7 +27,6 @@ # POSSIBILITY OF SUCH DAMAGE. # - import unittest from autothreadharness.harness_case import HarnessCase diff --git a/tools/harness-automation/cases/sed_6_2_1.py b/tools/harness-automation/cases/sed_6_2_1.py index 8f340d829..271526608 100644 --- a/tools/harness-automation/cases/sed_6_2_1.py +++ b/tools/harness-automation/cases/sed_6_2_1.py @@ -27,7 +27,6 @@ # POSSIBILITY OF SUCH DAMAGE. # - import unittest from autothreadharness.harness_case import HarnessCase diff --git a/tools/harness-automation/cases/sed_6_2_2.py b/tools/harness-automation/cases/sed_6_2_2.py index a8e317658..d0b68e388 100644 --- a/tools/harness-automation/cases/sed_6_2_2.py +++ b/tools/harness-automation/cases/sed_6_2_2.py @@ -27,7 +27,6 @@ # POSSIBILITY OF SUCH DAMAGE. # - import unittest from autothreadharness.harness_case import HarnessCase diff --git a/tools/harness-automation/cases/sed_6_3_1.py b/tools/harness-automation/cases/sed_6_3_1.py index c79034906..1ef1c619b 100644 --- a/tools/harness-automation/cases/sed_6_3_1.py +++ b/tools/harness-automation/cases/sed_6_3_1.py @@ -27,7 +27,6 @@ # POSSIBILITY OF SUCH DAMAGE. # - import unittest from autothreadharness.harness_case import HarnessCase diff --git a/tools/harness-automation/cases/sed_6_3_2.py b/tools/harness-automation/cases/sed_6_3_2.py index e2ca907ba..88a24a439 100644 --- a/tools/harness-automation/cases/sed_6_3_2.py +++ b/tools/harness-automation/cases/sed_6_3_2.py @@ -27,7 +27,6 @@ # POSSIBILITY OF SUCH DAMAGE. # - import unittest from autothreadharness.harness_case import HarnessCase diff --git a/tools/harness-automation/cases/sed_6_4_1.py b/tools/harness-automation/cases/sed_6_4_1.py index 092ce6306..16c0ad4fc 100644 --- a/tools/harness-automation/cases/sed_6_4_1.py +++ b/tools/harness-automation/cases/sed_6_4_1.py @@ -27,7 +27,6 @@ # POSSIBILITY OF SUCH DAMAGE. # - import unittest from autothreadharness.harness_case import HarnessCase diff --git a/tools/harness-automation/cases/sed_6_4_2.py b/tools/harness-automation/cases/sed_6_4_2.py index d79886714..1589b957e 100644 --- a/tools/harness-automation/cases/sed_6_4_2.py +++ b/tools/harness-automation/cases/sed_6_4_2.py @@ -27,7 +27,6 @@ # POSSIBILITY OF SUCH DAMAGE. # - import unittest from autothreadharness.harness_case import HarnessCase diff --git a/tools/harness-automation/cases/sed_6_5_1.py b/tools/harness-automation/cases/sed_6_5_1.py index c9704e24e..f50f45650 100644 --- a/tools/harness-automation/cases/sed_6_5_1.py +++ b/tools/harness-automation/cases/sed_6_5_1.py @@ -27,7 +27,6 @@ # POSSIBILITY OF SUCH DAMAGE. # - import time import unittest diff --git a/tools/harness-automation/cases/sed_6_5_2.py b/tools/harness-automation/cases/sed_6_5_2.py index e2f3b410f..c4ffff984 100644 --- a/tools/harness-automation/cases/sed_6_5_2.py +++ b/tools/harness-automation/cases/sed_6_5_2.py @@ -27,7 +27,6 @@ # POSSIBILITY OF SUCH DAMAGE. # - import unittest from autothreadharness.harness_case import HarnessCase diff --git a/tools/harness-automation/cases/sed_6_5_3.py b/tools/harness-automation/cases/sed_6_5_3.py index f8a0ca373..896301a51 100644 --- a/tools/harness-automation/cases/sed_6_5_3.py +++ b/tools/harness-automation/cases/sed_6_5_3.py @@ -27,7 +27,6 @@ # POSSIBILITY OF SUCH DAMAGE. # - import unittest from autothreadharness.harness_case import HarnessCase diff --git a/tools/harness-automation/cases/sed_6_6_1.py b/tools/harness-automation/cases/sed_6_6_1.py index f948aa92e..241d6a9cd 100644 --- a/tools/harness-automation/cases/sed_6_6_1.py +++ b/tools/harness-automation/cases/sed_6_6_1.py @@ -27,7 +27,6 @@ # POSSIBILITY OF SUCH DAMAGE. # - import unittest from autothreadharness.harness_case import HarnessCase diff --git a/tools/harness-automation/cases/sed_6_6_2.py b/tools/harness-automation/cases/sed_6_6_2.py index 99d423cfe..befce7be9 100644 --- a/tools/harness-automation/cases/sed_6_6_2.py +++ b/tools/harness-automation/cases/sed_6_6_2.py @@ -27,7 +27,6 @@ # POSSIBILITY OF SUCH DAMAGE. # - import unittest from autothreadharness.harness_case import HarnessCase diff --git a/tools/harness-automation/cases/sed_9_2_10.py b/tools/harness-automation/cases/sed_9_2_10.py index 3ca495359..dc363ad3f 100644 --- a/tools/harness-automation/cases/sed_9_2_10.py +++ b/tools/harness-automation/cases/sed_9_2_10.py @@ -27,7 +27,6 @@ # POSSIBILITY OF SUCH DAMAGE. # - import unittest from autothreadharness.harness_case import HarnessCase @@ -38,7 +37,8 @@ class SED_9_2_10(HarnessCase): case = '9 2 10' golden_devices_required = 4 case_need_shield = True - device_order = [('DUT', False), ('MED_1', False), ('Router_1', False), ('Commissioner', True), ('Leader', True)] + device_order = [('DUT', False), ('MED_1', False), ('Router_1', False), + ('Commissioner', True), ('Leader', True)] def on_dialog(self, dialog, title): pass diff --git a/tools/harness-automation/cases/sed_9_2_13.py b/tools/harness-automation/cases/sed_9_2_13.py index f4e877f93..428086f6a 100644 --- a/tools/harness-automation/cases/sed_9_2_13.py +++ b/tools/harness-automation/cases/sed_9_2_13.py @@ -27,7 +27,6 @@ # POSSIBILITY OF SUCH DAMAGE. # - import unittest from autothreadharness.harness_case import HarnessCase diff --git a/tools/harness-automation/cases/sed_9_2_17.py b/tools/harness-automation/cases/sed_9_2_17.py index 5b718d633..c641ed613 100644 --- a/tools/harness-automation/cases/sed_9_2_17.py +++ b/tools/harness-automation/cases/sed_9_2_17.py @@ -27,7 +27,6 @@ # POSSIBILITY OF SUCH DAMAGE. # - import unittest from autothreadharness.harness_case import HarnessCase diff --git a/tools/harness-automation/cases/sed_9_2_18.py b/tools/harness-automation/cases/sed_9_2_18.py index 800763d4b..df32b9363 100644 --- a/tools/harness-automation/cases/sed_9_2_18.py +++ b/tools/harness-automation/cases/sed_9_2_18.py @@ -27,7 +27,6 @@ # POSSIBILITY OF SUCH DAMAGE. # - import unittest from autothreadharness.harness_case import HarnessCase diff --git a/tools/harness-automation/cases/sed_9_2_6.py b/tools/harness-automation/cases/sed_9_2_6.py index c32a2f2ad..ebd60a6ba 100644 --- a/tools/harness-automation/cases/sed_9_2_6.py +++ b/tools/harness-automation/cases/sed_9_2_6.py @@ -27,7 +27,6 @@ # POSSIBILITY OF SUCH DAMAGE. # - import unittest from autothreadharness.harness_case import HarnessCase diff --git a/tools/harness-automation/cases/sed_9_2_8.py b/tools/harness-automation/cases/sed_9_2_8.py index 49cf7cb76..1d0efc3ed 100644 --- a/tools/harness-automation/cases/sed_9_2_8.py +++ b/tools/harness-automation/cases/sed_9_2_8.py @@ -27,7 +27,6 @@ # POSSIBILITY OF SUCH DAMAGE. # - import unittest from autothreadharness.harness_case import HarnessCase diff --git a/tools/harness-automation/cases_R140/commissioner_8_1_1.py b/tools/harness-automation/cases_R140/commissioner_8_1_1.py index 32b09f740..db4cb8b13 100755 --- a/tools/harness-automation/cases_R140/commissioner_8_1_1.py +++ b/tools/harness-automation/cases_R140/commissioner_8_1_1.py @@ -27,7 +27,6 @@ # POSSIBILITY OF SUCH DAMAGE. # - import unittest from autothreadharness.harness_case import HarnessCase diff --git a/tools/harness-automation/cases_R140/commissioner_8_1_2.py b/tools/harness-automation/cases_R140/commissioner_8_1_2.py index f31177c47..2022a8f55 100755 --- a/tools/harness-automation/cases_R140/commissioner_8_1_2.py +++ b/tools/harness-automation/cases_R140/commissioner_8_1_2.py @@ -27,7 +27,6 @@ # POSSIBILITY OF SUCH DAMAGE. # - import unittest from autothreadharness.harness_case import HarnessCase diff --git a/tools/harness-automation/cases_R140/commissioner_8_1_6.py b/tools/harness-automation/cases_R140/commissioner_8_1_6.py index ab4d094fc..141fa60e4 100755 --- a/tools/harness-automation/cases_R140/commissioner_8_1_6.py +++ b/tools/harness-automation/cases_R140/commissioner_8_1_6.py @@ -27,7 +27,6 @@ # POSSIBILITY OF SUCH DAMAGE. # - import unittest from autothreadharness.harness_case import HarnessCase diff --git a/tools/harness-automation/cases_R140/commissioner_8_2_1.py b/tools/harness-automation/cases_R140/commissioner_8_2_1.py index 990f08abf..185111855 100755 --- a/tools/harness-automation/cases_R140/commissioner_8_2_1.py +++ b/tools/harness-automation/cases_R140/commissioner_8_2_1.py @@ -27,7 +27,6 @@ # POSSIBILITY OF SUCH DAMAGE. # - import unittest from autothreadharness.harness_case import HarnessCase diff --git a/tools/harness-automation/cases_R140/commissioner_8_2_2.py b/tools/harness-automation/cases_R140/commissioner_8_2_2.py index 5ada36a87..e365967f5 100755 --- a/tools/harness-automation/cases_R140/commissioner_8_2_2.py +++ b/tools/harness-automation/cases_R140/commissioner_8_2_2.py @@ -27,7 +27,6 @@ # POSSIBILITY OF SUCH DAMAGE. # - import unittest from autothreadharness.harness_case import HarnessCase diff --git a/tools/harness-automation/cases_R140/commissioner_8_2_5.py b/tools/harness-automation/cases_R140/commissioner_8_2_5.py index a284b397a..ceebaec1d 100755 --- a/tools/harness-automation/cases_R140/commissioner_8_2_5.py +++ b/tools/harness-automation/cases_R140/commissioner_8_2_5.py @@ -27,7 +27,6 @@ # POSSIBILITY OF SUCH DAMAGE. # - import unittest from autothreadharness.harness_case import HarnessCase diff --git a/tools/harness-automation/cases_R140/commissioner_8_3_1.py b/tools/harness-automation/cases_R140/commissioner_8_3_1.py index 26eef232c..0376820cb 100755 --- a/tools/harness-automation/cases_R140/commissioner_8_3_1.py +++ b/tools/harness-automation/cases_R140/commissioner_8_3_1.py @@ -27,7 +27,6 @@ # POSSIBILITY OF SUCH DAMAGE. # - import unittest from autothreadharness.harness_case import HarnessCase diff --git a/tools/harness-automation/cases_R140/commissioner_9_2_1.py b/tools/harness-automation/cases_R140/commissioner_9_2_1.py index a264e55f0..471ba977e 100755 --- a/tools/harness-automation/cases_R140/commissioner_9_2_1.py +++ b/tools/harness-automation/cases_R140/commissioner_9_2_1.py @@ -27,7 +27,6 @@ # POSSIBILITY OF SUCH DAMAGE. # - import unittest from autothreadharness.harness_case import HarnessCase diff --git a/tools/harness-automation/cases_R140/commissioner_9_2_14.py b/tools/harness-automation/cases_R140/commissioner_9_2_14.py index d090d47f4..2f87c6b41 100755 --- a/tools/harness-automation/cases_R140/commissioner_9_2_14.py +++ b/tools/harness-automation/cases_R140/commissioner_9_2_14.py @@ -27,7 +27,6 @@ # POSSIBILITY OF SUCH DAMAGE. # - import unittest from autothreadharness.harness_case import HarnessCase diff --git a/tools/harness-automation/cases_R140/commissioner_9_2_19.py b/tools/harness-automation/cases_R140/commissioner_9_2_19.py index 073d37fd8..c69d915e5 100755 --- a/tools/harness-automation/cases_R140/commissioner_9_2_19.py +++ b/tools/harness-automation/cases_R140/commissioner_9_2_19.py @@ -27,7 +27,6 @@ # POSSIBILITY OF SUCH DAMAGE. # - import unittest from autothreadharness.harness_case import HarnessCase diff --git a/tools/harness-automation/cases_R140/commissioner_9_2_2.py b/tools/harness-automation/cases_R140/commissioner_9_2_2.py index 7ea4ab5a2..94ed5fa0c 100755 --- a/tools/harness-automation/cases_R140/commissioner_9_2_2.py +++ b/tools/harness-automation/cases_R140/commissioner_9_2_2.py @@ -27,7 +27,6 @@ # POSSIBILITY OF SUCH DAMAGE. # - import unittest from autothreadharness.harness_case import HarnessCase diff --git a/tools/harness-automation/cases_R140/commissioner_9_2_3.py b/tools/harness-automation/cases_R140/commissioner_9_2_3.py index e13cae288..61aa37be6 100755 --- a/tools/harness-automation/cases_R140/commissioner_9_2_3.py +++ b/tools/harness-automation/cases_R140/commissioner_9_2_3.py @@ -27,7 +27,6 @@ # POSSIBILITY OF SUCH DAMAGE. # - import unittest from autothreadharness.harness_case import HarnessCase diff --git a/tools/harness-automation/cases_R140/commissioner_9_2_4.py b/tools/harness-automation/cases_R140/commissioner_9_2_4.py index 9d46c6e04..c0c8b61b1 100755 --- a/tools/harness-automation/cases_R140/commissioner_9_2_4.py +++ b/tools/harness-automation/cases_R140/commissioner_9_2_4.py @@ -27,7 +27,6 @@ # POSSIBILITY OF SUCH DAMAGE. # - import unittest from autothreadharness.harness_case import HarnessCase diff --git a/tools/harness-automation/cases_R140/ed_6_1_1.py b/tools/harness-automation/cases_R140/ed_6_1_1.py index 52d2e4b68..79deead6d 100755 --- a/tools/harness-automation/cases_R140/ed_6_1_1.py +++ b/tools/harness-automation/cases_R140/ed_6_1_1.py @@ -27,7 +27,6 @@ # POSSIBILITY OF SUCH DAMAGE. # - import unittest from autothreadharness.harness_case import HarnessCase diff --git a/tools/harness-automation/cases_R140/ed_6_1_2.py b/tools/harness-automation/cases_R140/ed_6_1_2.py index a5eb4b01d..1336c493d 100755 --- a/tools/harness-automation/cases_R140/ed_6_1_2.py +++ b/tools/harness-automation/cases_R140/ed_6_1_2.py @@ -27,7 +27,6 @@ # POSSIBILITY OF SUCH DAMAGE. # - import unittest from autothreadharness.harness_case import HarnessCase diff --git a/tools/harness-automation/cases_R140/ed_6_1_3.py b/tools/harness-automation/cases_R140/ed_6_1_3.py index c6a65ece7..e99f86de1 100755 --- a/tools/harness-automation/cases_R140/ed_6_1_3.py +++ b/tools/harness-automation/cases_R140/ed_6_1_3.py @@ -27,7 +27,6 @@ # POSSIBILITY OF SUCH DAMAGE. # - import unittest from autothreadharness.harness_case import HarnessCase diff --git a/tools/harness-automation/cases_R140/ed_6_1_4.py b/tools/harness-automation/cases_R140/ed_6_1_4.py index 99894dcc2..dfcd85dae 100755 --- a/tools/harness-automation/cases_R140/ed_6_1_4.py +++ b/tools/harness-automation/cases_R140/ed_6_1_4.py @@ -27,7 +27,6 @@ # POSSIBILITY OF SUCH DAMAGE. # - import unittest from autothreadharness.harness_case import HarnessCase diff --git a/tools/harness-automation/cases_R140/ed_6_1_5.py b/tools/harness-automation/cases_R140/ed_6_1_5.py index 9e09ab8f2..70b900721 100755 --- a/tools/harness-automation/cases_R140/ed_6_1_5.py +++ b/tools/harness-automation/cases_R140/ed_6_1_5.py @@ -27,7 +27,6 @@ # POSSIBILITY OF SUCH DAMAGE. # - import unittest from autothreadharness.harness_case import HarnessCase diff --git a/tools/harness-automation/cases_R140/ed_6_1_6.py b/tools/harness-automation/cases_R140/ed_6_1_6.py index 399799b88..7d9d9e3b9 100755 --- a/tools/harness-automation/cases_R140/ed_6_1_6.py +++ b/tools/harness-automation/cases_R140/ed_6_1_6.py @@ -27,7 +27,6 @@ # POSSIBILITY OF SUCH DAMAGE. # - import unittest from autothreadharness.harness_case import HarnessCase diff --git a/tools/harness-automation/cases_R140/ed_6_2_1.py b/tools/harness-automation/cases_R140/ed_6_2_1.py index 5740c625e..26778a658 100755 --- a/tools/harness-automation/cases_R140/ed_6_2_1.py +++ b/tools/harness-automation/cases_R140/ed_6_2_1.py @@ -27,7 +27,6 @@ # POSSIBILITY OF SUCH DAMAGE. # - import unittest from autothreadharness.harness_case import HarnessCase diff --git a/tools/harness-automation/cases_R140/ed_6_2_2.py b/tools/harness-automation/cases_R140/ed_6_2_2.py index 4ee44acd8..778afca8a 100755 --- a/tools/harness-automation/cases_R140/ed_6_2_2.py +++ b/tools/harness-automation/cases_R140/ed_6_2_2.py @@ -27,7 +27,6 @@ # POSSIBILITY OF SUCH DAMAGE. # - import unittest from autothreadharness.harness_case import HarnessCase diff --git a/tools/harness-automation/cases_R140/ed_6_3_1.py b/tools/harness-automation/cases_R140/ed_6_3_1.py index e19a0a594..f8c6cf433 100755 --- a/tools/harness-automation/cases_R140/ed_6_3_1.py +++ b/tools/harness-automation/cases_R140/ed_6_3_1.py @@ -27,7 +27,6 @@ # POSSIBILITY OF SUCH DAMAGE. # - import unittest from autothreadharness.harness_case import HarnessCase diff --git a/tools/harness-automation/cases_R140/ed_6_4_1.py b/tools/harness-automation/cases_R140/ed_6_4_1.py index 261bfa6fa..924ea4ee2 100755 --- a/tools/harness-automation/cases_R140/ed_6_4_1.py +++ b/tools/harness-automation/cases_R140/ed_6_4_1.py @@ -27,7 +27,6 @@ # POSSIBILITY OF SUCH DAMAGE. # - import unittest from autothreadharness.harness_case import HarnessCase diff --git a/tools/harness-automation/cases_R140/ed_6_4_2.py b/tools/harness-automation/cases_R140/ed_6_4_2.py index cb5337dd9..23bb14a65 100755 --- a/tools/harness-automation/cases_R140/ed_6_4_2.py +++ b/tools/harness-automation/cases_R140/ed_6_4_2.py @@ -27,7 +27,6 @@ # POSSIBILITY OF SUCH DAMAGE. # - import unittest from autothreadharness.harness_case import HarnessCase diff --git a/tools/harness-automation/cases_R140/ed_6_5_1.py b/tools/harness-automation/cases_R140/ed_6_5_1.py index fae820c51..7074de44a 100755 --- a/tools/harness-automation/cases_R140/ed_6_5_1.py +++ b/tools/harness-automation/cases_R140/ed_6_5_1.py @@ -27,7 +27,6 @@ # POSSIBILITY OF SUCH DAMAGE. # - import unittest import time diff --git a/tools/harness-automation/cases_R140/ed_6_5_2.py b/tools/harness-automation/cases_R140/ed_6_5_2.py index 08258801e..501d343ad 100755 --- a/tools/harness-automation/cases_R140/ed_6_5_2.py +++ b/tools/harness-automation/cases_R140/ed_6_5_2.py @@ -27,7 +27,6 @@ # POSSIBILITY OF SUCH DAMAGE. # - import unittest from autothreadharness.harness_case import HarnessCase diff --git a/tools/harness-automation/cases_R140/ed_6_5_3.py b/tools/harness-automation/cases_R140/ed_6_5_3.py index 2a9b20edb..5d1e35d69 100755 --- a/tools/harness-automation/cases_R140/ed_6_5_3.py +++ b/tools/harness-automation/cases_R140/ed_6_5_3.py @@ -27,7 +27,6 @@ # POSSIBILITY OF SUCH DAMAGE. # - import unittest from autothreadharness.harness_case import HarnessCase diff --git a/tools/harness-automation/cases_R140/ed_6_6_1.py b/tools/harness-automation/cases_R140/ed_6_6_1.py index 117c88153..e6baa88c6 100755 --- a/tools/harness-automation/cases_R140/ed_6_6_1.py +++ b/tools/harness-automation/cases_R140/ed_6_6_1.py @@ -27,7 +27,6 @@ # POSSIBILITY OF SUCH DAMAGE. # - import unittest from autothreadharness.harness_case import HarnessCase diff --git a/tools/harness-automation/cases_R140/ed_6_6_2.py b/tools/harness-automation/cases_R140/ed_6_6_2.py index 8bc84b435..4d53ab00b 100755 --- a/tools/harness-automation/cases_R140/ed_6_6_2.py +++ b/tools/harness-automation/cases_R140/ed_6_6_2.py @@ -27,7 +27,6 @@ # POSSIBILITY OF SUCH DAMAGE. # - import unittest from autothreadharness.harness_case import HarnessCase diff --git a/tools/harness-automation/cases_R140/ed_9_2_17.py b/tools/harness-automation/cases_R140/ed_9_2_17.py index e245fea48..98f4ef0f9 100755 --- a/tools/harness-automation/cases_R140/ed_9_2_17.py +++ b/tools/harness-automation/cases_R140/ed_9_2_17.py @@ -27,7 +27,6 @@ # POSSIBILITY OF SUCH DAMAGE. # - import unittest from autothreadharness.harness_case import HarnessCase diff --git a/tools/harness-automation/cases_R140/ed_9_2_8.py b/tools/harness-automation/cases_R140/ed_9_2_8.py index 4e254b195..94f5544a6 100755 --- a/tools/harness-automation/cases_R140/ed_9_2_8.py +++ b/tools/harness-automation/cases_R140/ed_9_2_8.py @@ -27,7 +27,6 @@ # POSSIBILITY OF SUCH DAMAGE. # - import unittest from autothreadharness.harness_case import HarnessCase diff --git a/tools/harness-automation/cases_R140/fed_5_7_1.py b/tools/harness-automation/cases_R140/fed_5_7_1.py index 5fb533c98..526d59135 100755 --- a/tools/harness-automation/cases_R140/fed_5_7_1.py +++ b/tools/harness-automation/cases_R140/fed_5_7_1.py @@ -27,7 +27,6 @@ # POSSIBILITY OF SUCH DAMAGE. # - import unittest from autothreadharness.harness_case import HarnessCase diff --git a/tools/harness-automation/cases_R140/fed_5_7_3.py b/tools/harness-automation/cases_R140/fed_5_7_3.py index 6e5fa359d..c8ce6b6ca 100755 --- a/tools/harness-automation/cases_R140/fed_5_7_3.py +++ b/tools/harness-automation/cases_R140/fed_5_7_3.py @@ -27,7 +27,6 @@ # POSSIBILITY OF SUCH DAMAGE. # - import unittest from autothreadharness.harness_case import HarnessCase diff --git a/tools/harness-automation/cases_R140/fed_6_1_7.py b/tools/harness-automation/cases_R140/fed_6_1_7.py index 7fba55f9c..6822e0dcd 100755 --- a/tools/harness-automation/cases_R140/fed_6_1_7.py +++ b/tools/harness-automation/cases_R140/fed_6_1_7.py @@ -27,7 +27,6 @@ # POSSIBILITY OF SUCH DAMAGE. # - import unittest from autothreadharness.harness_case import HarnessCase diff --git a/tools/harness-automation/cases_R140/fed_9_2_13.py b/tools/harness-automation/cases_R140/fed_9_2_13.py index 7b84b4537..5217a2062 100755 --- a/tools/harness-automation/cases_R140/fed_9_2_13.py +++ b/tools/harness-automation/cases_R140/fed_9_2_13.py @@ -27,7 +27,6 @@ # POSSIBILITY OF SUCH DAMAGE. # - import unittest from autothreadharness.harness_case import HarnessCase diff --git a/tools/harness-automation/cases_R140/joiner_8_1_1.py b/tools/harness-automation/cases_R140/joiner_8_1_1.py index d71a7b7d5..d022e727e 100755 --- a/tools/harness-automation/cases_R140/joiner_8_1_1.py +++ b/tools/harness-automation/cases_R140/joiner_8_1_1.py @@ -27,7 +27,6 @@ # POSSIBILITY OF SUCH DAMAGE. # - import unittest from autothreadharness.harness_case import HarnessCase diff --git a/tools/harness-automation/cases_R140/joiner_8_1_6.py b/tools/harness-automation/cases_R140/joiner_8_1_6.py index 844499735..3622f55e0 100755 --- a/tools/harness-automation/cases_R140/joiner_8_1_6.py +++ b/tools/harness-automation/cases_R140/joiner_8_1_6.py @@ -27,7 +27,6 @@ # POSSIBILITY OF SUCH DAMAGE. # - import unittest from autothreadharness.harness_case import HarnessCase diff --git a/tools/harness-automation/cases_R140/leader_5_1_1.py b/tools/harness-automation/cases_R140/leader_5_1_1.py index 465d2bfd8..149b7f4c0 100755 --- a/tools/harness-automation/cases_R140/leader_5_1_1.py +++ b/tools/harness-automation/cases_R140/leader_5_1_1.py @@ -27,7 +27,6 @@ # POSSIBILITY OF SUCH DAMAGE. # - import unittest from autothreadharness.harness_case import HarnessCase diff --git a/tools/harness-automation/cases_R140/leader_5_1_13.py b/tools/harness-automation/cases_R140/leader_5_1_13.py index d321240ef..5e55f8554 100755 --- a/tools/harness-automation/cases_R140/leader_5_1_13.py +++ b/tools/harness-automation/cases_R140/leader_5_1_13.py @@ -27,7 +27,6 @@ # POSSIBILITY OF SUCH DAMAGE. # - import unittest import time diff --git a/tools/harness-automation/cases_R140/leader_5_1_5.py b/tools/harness-automation/cases_R140/leader_5_1_5.py index 386496c4e..3e3d70645 100755 --- a/tools/harness-automation/cases_R140/leader_5_1_5.py +++ b/tools/harness-automation/cases_R140/leader_5_1_5.py @@ -27,7 +27,6 @@ # POSSIBILITY OF SUCH DAMAGE. # - from autothreadharness.harness_case import HarnessCase import unittest diff --git a/tools/harness-automation/cases_R140/leader_5_2_3.py b/tools/harness-automation/cases_R140/leader_5_2_3.py index 15bd2afb8..4ee3d7f59 100755 --- a/tools/harness-automation/cases_R140/leader_5_2_3.py +++ b/tools/harness-automation/cases_R140/leader_5_2_3.py @@ -27,7 +27,6 @@ # POSSIBILITY OF SUCH DAMAGE. # - import unittest from autothreadharness.harness_case import HarnessCase diff --git a/tools/harness-automation/cases_R140/leader_5_3_6.py b/tools/harness-automation/cases_R140/leader_5_3_6.py index 89cd19cae..f96c723d3 100755 --- a/tools/harness-automation/cases_R140/leader_5_3_6.py +++ b/tools/harness-automation/cases_R140/leader_5_3_6.py @@ -27,7 +27,6 @@ # POSSIBILITY OF SUCH DAMAGE. # - from autothreadharness.harness_case import HarnessCase import unittest diff --git a/tools/harness-automation/cases_R140/leader_5_3_7.py b/tools/harness-automation/cases_R140/leader_5_3_7.py index 68df333af..d9a024549 100755 --- a/tools/harness-automation/cases_R140/leader_5_3_7.py +++ b/tools/harness-automation/cases_R140/leader_5_3_7.py @@ -27,7 +27,6 @@ # POSSIBILITY OF SUCH DAMAGE. # - import unittest from autothreadharness.harness_case import HarnessCase diff --git a/tools/harness-automation/cases_R140/leader_5_3_8.py b/tools/harness-automation/cases_R140/leader_5_3_8.py index 1e642553c..3d505a006 100755 --- a/tools/harness-automation/cases_R140/leader_5_3_8.py +++ b/tools/harness-automation/cases_R140/leader_5_3_8.py @@ -27,7 +27,6 @@ # POSSIBILITY OF SUCH DAMAGE. # - import unittest from autothreadharness.harness_case import HarnessCase diff --git a/tools/harness-automation/cases_R140/leader_5_5_1.py b/tools/harness-automation/cases_R140/leader_5_5_1.py index 9bbc273cf..ecff0d63d 100755 --- a/tools/harness-automation/cases_R140/leader_5_5_1.py +++ b/tools/harness-automation/cases_R140/leader_5_5_1.py @@ -27,7 +27,6 @@ # POSSIBILITY OF SUCH DAMAGE. # - import re import time import unittest diff --git a/tools/harness-automation/cases_R140/leader_5_5_2.py b/tools/harness-automation/cases_R140/leader_5_5_2.py index 4f97befca..7ab95391e 100755 --- a/tools/harness-automation/cases_R140/leader_5_5_2.py +++ b/tools/harness-automation/cases_R140/leader_5_5_2.py @@ -27,7 +27,6 @@ # POSSIBILITY OF SUCH DAMAGE. # - import time import unittest diff --git a/tools/harness-automation/cases_R140/leader_5_5_3.py b/tools/harness-automation/cases_R140/leader_5_5_3.py index 07eb2fec0..5997c8219 100755 --- a/tools/harness-automation/cases_R140/leader_5_5_3.py +++ b/tools/harness-automation/cases_R140/leader_5_5_3.py @@ -27,7 +27,6 @@ # POSSIBILITY OF SUCH DAMAGE. # - import unittest from autothreadharness.harness_case import HarnessCase diff --git a/tools/harness-automation/cases_R140/leader_5_5_4.py b/tools/harness-automation/cases_R140/leader_5_5_4.py index 0547e7afa..dcabecddb 100755 --- a/tools/harness-automation/cases_R140/leader_5_5_4.py +++ b/tools/harness-automation/cases_R140/leader_5_5_4.py @@ -27,7 +27,6 @@ # POSSIBILITY OF SUCH DAMAGE. # - import unittest from autothreadharness.harness_case import HarnessCase diff --git a/tools/harness-automation/cases_R140/leader_5_5_7.py b/tools/harness-automation/cases_R140/leader_5_5_7.py index a7193940d..e7bb575f2 100755 --- a/tools/harness-automation/cases_R140/leader_5_5_7.py +++ b/tools/harness-automation/cases_R140/leader_5_5_7.py @@ -27,7 +27,6 @@ # POSSIBILITY OF SUCH DAMAGE. # - import unittest from autothreadharness.harness_case import HarnessCase diff --git a/tools/harness-automation/cases_R140/leader_5_6_2.py b/tools/harness-automation/cases_R140/leader_5_6_2.py index 06080a7a5..2163cb2e0 100755 --- a/tools/harness-automation/cases_R140/leader_5_6_2.py +++ b/tools/harness-automation/cases_R140/leader_5_6_2.py @@ -27,7 +27,6 @@ # POSSIBILITY OF SUCH DAMAGE. # - from autothreadharness.harness_case import HarnessCase import unittest diff --git a/tools/harness-automation/cases_R140/leader_5_6_4.py b/tools/harness-automation/cases_R140/leader_5_6_4.py index a588660a2..8d3584fae 100755 --- a/tools/harness-automation/cases_R140/leader_5_6_4.py +++ b/tools/harness-automation/cases_R140/leader_5_6_4.py @@ -27,7 +27,6 @@ # POSSIBILITY OF SUCH DAMAGE. # - import unittest from autothreadharness.harness_case import HarnessCase diff --git a/tools/harness-automation/cases_R140/leader_5_6_5.py b/tools/harness-automation/cases_R140/leader_5_6_5.py index aa18f5306..6da7d2393 100755 --- a/tools/harness-automation/cases_R140/leader_5_6_5.py +++ b/tools/harness-automation/cases_R140/leader_5_6_5.py @@ -27,7 +27,6 @@ # POSSIBILITY OF SUCH DAMAGE. # - import unittest from autothreadharness.harness_case import HarnessCase diff --git a/tools/harness-automation/cases_R140/leader_5_6_6.py b/tools/harness-automation/cases_R140/leader_5_6_6.py index 51d80b135..80d83d90a 100755 --- a/tools/harness-automation/cases_R140/leader_5_6_6.py +++ b/tools/harness-automation/cases_R140/leader_5_6_6.py @@ -27,7 +27,6 @@ # POSSIBILITY OF SUCH DAMAGE. # - import unittest from autothreadharness.harness_case import HarnessCase diff --git a/tools/harness-automation/cases_R140/leader_5_8_4.py b/tools/harness-automation/cases_R140/leader_5_8_4.py index 12c984ca6..04aec35b3 100755 --- a/tools/harness-automation/cases_R140/leader_5_8_4.py +++ b/tools/harness-automation/cases_R140/leader_5_8_4.py @@ -27,7 +27,6 @@ # POSSIBILITY OF SUCH DAMAGE. # - import unittest from autothreadharness.harness_case import HarnessCase diff --git a/tools/harness-automation/cases_R140/leader_7_1_1.py b/tools/harness-automation/cases_R140/leader_7_1_1.py index 8f8253e86..0ee4c186c 100755 --- a/tools/harness-automation/cases_R140/leader_7_1_1.py +++ b/tools/harness-automation/cases_R140/leader_7_1_1.py @@ -27,7 +27,6 @@ # POSSIBILITY OF SUCH DAMAGE. # - from autothreadharness.harness_case import HarnessCase import unittest diff --git a/tools/harness-automation/cases_R140/leader_7_1_3.py b/tools/harness-automation/cases_R140/leader_7_1_3.py index 58db178f1..9db6a94bc 100755 --- a/tools/harness-automation/cases_R140/leader_7_1_3.py +++ b/tools/harness-automation/cases_R140/leader_7_1_3.py @@ -27,7 +27,6 @@ # POSSIBILITY OF SUCH DAMAGE. # - from autothreadharness.harness_case import HarnessCase import unittest diff --git a/tools/harness-automation/cases_R140/leader_7_1_6.py b/tools/harness-automation/cases_R140/leader_7_1_6.py index fd1d76a6e..1ce1c7e6b 100755 --- a/tools/harness-automation/cases_R140/leader_7_1_6.py +++ b/tools/harness-automation/cases_R140/leader_7_1_6.py @@ -27,7 +27,6 @@ # POSSIBILITY OF SUCH DAMAGE. # - from autothreadharness.harness_case import HarnessCase import unittest diff --git a/tools/harness-automation/cases_R140/leader_7_1_7.py b/tools/harness-automation/cases_R140/leader_7_1_7.py index 9559a7446..062658079 100755 --- a/tools/harness-automation/cases_R140/leader_7_1_7.py +++ b/tools/harness-automation/cases_R140/leader_7_1_7.py @@ -27,7 +27,6 @@ # POSSIBILITY OF SUCH DAMAGE. # - from autothreadharness.harness_case import HarnessCase import unittest diff --git a/tools/harness-automation/cases_R140/leader_8_3_1.py b/tools/harness-automation/cases_R140/leader_8_3_1.py index 8e3edf179..0f2d8ef34 100755 --- a/tools/harness-automation/cases_R140/leader_8_3_1.py +++ b/tools/harness-automation/cases_R140/leader_8_3_1.py @@ -27,7 +27,6 @@ # POSSIBILITY OF SUCH DAMAGE. # - import unittest from autothreadharness.harness_case import HarnessCase diff --git a/tools/harness-automation/cases_R140/leader_9_2_1.py b/tools/harness-automation/cases_R140/leader_9_2_1.py index 923782d46..f1d6d5bf4 100755 --- a/tools/harness-automation/cases_R140/leader_9_2_1.py +++ b/tools/harness-automation/cases_R140/leader_9_2_1.py @@ -27,7 +27,6 @@ # POSSIBILITY OF SUCH DAMAGE. # - import unittest from autothreadharness.harness_case import HarnessCase diff --git a/tools/harness-automation/cases_R140/leader_9_2_11.py b/tools/harness-automation/cases_R140/leader_9_2_11.py index 0174d82fd..26203b017 100755 --- a/tools/harness-automation/cases_R140/leader_9_2_11.py +++ b/tools/harness-automation/cases_R140/leader_9_2_11.py @@ -27,7 +27,6 @@ # POSSIBILITY OF SUCH DAMAGE. # - import unittest from autothreadharness.harness_case import HarnessCase diff --git a/tools/harness-automation/cases_R140/leader_9_2_12.py b/tools/harness-automation/cases_R140/leader_9_2_12.py index b35f11033..42b8f031f 100755 --- a/tools/harness-automation/cases_R140/leader_9_2_12.py +++ b/tools/harness-automation/cases_R140/leader_9_2_12.py @@ -27,7 +27,6 @@ # POSSIBILITY OF SUCH DAMAGE. # - import unittest from autothreadharness.harness_case import HarnessCase diff --git a/tools/harness-automation/cases_R140/leader_9_2_18.py b/tools/harness-automation/cases_R140/leader_9_2_18.py index 2a549dfbd..4b231dcb6 100755 --- a/tools/harness-automation/cases_R140/leader_9_2_18.py +++ b/tools/harness-automation/cases_R140/leader_9_2_18.py @@ -27,7 +27,6 @@ # POSSIBILITY OF SUCH DAMAGE. # - import unittest from autothreadharness.harness_case import HarnessCase diff --git a/tools/harness-automation/cases_R140/leader_9_2_19.py b/tools/harness-automation/cases_R140/leader_9_2_19.py index 5c9dc21ae..a66106452 100755 --- a/tools/harness-automation/cases_R140/leader_9_2_19.py +++ b/tools/harness-automation/cases_R140/leader_9_2_19.py @@ -27,7 +27,6 @@ # POSSIBILITY OF SUCH DAMAGE. # - import unittest from autothreadharness.harness_case import HarnessCase diff --git a/tools/harness-automation/cases_R140/leader_9_2_2.py b/tools/harness-automation/cases_R140/leader_9_2_2.py index 449a63f53..4ae535f67 100755 --- a/tools/harness-automation/cases_R140/leader_9_2_2.py +++ b/tools/harness-automation/cases_R140/leader_9_2_2.py @@ -27,7 +27,6 @@ # POSSIBILITY OF SUCH DAMAGE. # - import unittest from autothreadharness.harness_case import HarnessCase diff --git a/tools/harness-automation/cases_R140/leader_9_2_3.py b/tools/harness-automation/cases_R140/leader_9_2_3.py index 4d1762713..ec5714ca6 100755 --- a/tools/harness-automation/cases_R140/leader_9_2_3.py +++ b/tools/harness-automation/cases_R140/leader_9_2_3.py @@ -27,7 +27,6 @@ # POSSIBILITY OF SUCH DAMAGE. # - import unittest from autothreadharness.harness_case import HarnessCase diff --git a/tools/harness-automation/cases_R140/leader_9_2_4.py b/tools/harness-automation/cases_R140/leader_9_2_4.py index e18cb36cd..35dc7d522 100755 --- a/tools/harness-automation/cases_R140/leader_9_2_4.py +++ b/tools/harness-automation/cases_R140/leader_9_2_4.py @@ -27,7 +27,6 @@ # POSSIBILITY OF SUCH DAMAGE. # - import unittest from autothreadharness.harness_case import HarnessCase diff --git a/tools/harness-automation/cases_R140/leader_9_2_5.py b/tools/harness-automation/cases_R140/leader_9_2_5.py index e4626ce9e..453cd1511 100755 --- a/tools/harness-automation/cases_R140/leader_9_2_5.py +++ b/tools/harness-automation/cases_R140/leader_9_2_5.py @@ -27,7 +27,6 @@ # POSSIBILITY OF SUCH DAMAGE. # - import unittest from autothreadharness.harness_case import HarnessCase diff --git a/tools/harness-automation/cases_R140/leader_9_2_6.py b/tools/harness-automation/cases_R140/leader_9_2_6.py index aecca92b4..a6f519123 100755 --- a/tools/harness-automation/cases_R140/leader_9_2_6.py +++ b/tools/harness-automation/cases_R140/leader_9_2_6.py @@ -27,7 +27,6 @@ # POSSIBILITY OF SUCH DAMAGE. # - import unittest from autothreadharness.harness_case import HarnessCase diff --git a/tools/harness-automation/cases_R140/leader_9_2_7.py b/tools/harness-automation/cases_R140/leader_9_2_7.py index a6f2deecd..7b07fdd13 100755 --- a/tools/harness-automation/cases_R140/leader_9_2_7.py +++ b/tools/harness-automation/cases_R140/leader_9_2_7.py @@ -27,7 +27,6 @@ # POSSIBILITY OF SUCH DAMAGE. # - import unittest from autothreadharness.harness_case import HarnessCase diff --git a/tools/harness-automation/cases_R140/leader_9_2_9.py b/tools/harness-automation/cases_R140/leader_9_2_9.py index 2fa91a256..d0a4b4fcd 100755 --- a/tools/harness-automation/cases_R140/leader_9_2_9.py +++ b/tools/harness-automation/cases_R140/leader_9_2_9.py @@ -27,7 +27,6 @@ # POSSIBILITY OF SUCH DAMAGE. # - import unittest from autothreadharness.harness_case import HarnessCase @@ -38,7 +37,8 @@ class Leader_9_2_9(HarnessCase): case = '9 2 9' golden_devices_required = 3 case_need_shield = True - device_order = [('Router_2', False), ('Commissioner', True), ('Router_1', False), ('DUT', True)] + device_order = [('Router_2', False), ('Commissioner', True), + ('Router_1', False), ('DUT', True)] def on_dialog(self, dialog, title): pass diff --git a/tools/harness-automation/cases_R140/med_6_3_2.py b/tools/harness-automation/cases_R140/med_6_3_2.py index 676a676d9..8586fd5b9 100755 --- a/tools/harness-automation/cases_R140/med_6_3_2.py +++ b/tools/harness-automation/cases_R140/med_6_3_2.py @@ -27,7 +27,6 @@ # POSSIBILITY OF SUCH DAMAGE. # - import unittest from autothreadharness.harness_case import HarnessCase diff --git a/tools/harness-automation/cases_R140/med_9_2_10.py b/tools/harness-automation/cases_R140/med_9_2_10.py index 915366978..ef3b473df 100755 --- a/tools/harness-automation/cases_R140/med_9_2_10.py +++ b/tools/harness-automation/cases_R140/med_9_2_10.py @@ -27,7 +27,6 @@ # POSSIBILITY OF SUCH DAMAGE. # - import unittest from autothreadharness.harness_case import HarnessCase @@ -38,7 +37,8 @@ class MED_9_2_10(HarnessCase): case = '9 2 10' golden_devices_required = 4 case_need_shield = True - device_order = [('SED_1', False), ('DUT', False), ('Router_1', False), ('Commissioner', True), ('Leader', True)] + device_order = [('SED_1', False), ('DUT', False), ('Router_1', False), + ('Commissioner', True), ('Leader', True)] def on_dialog(self, dialog, title): pass diff --git a/tools/harness-automation/cases_R140/med_9_2_12.py b/tools/harness-automation/cases_R140/med_9_2_12.py index 7c93f3c24..888240660 100755 --- a/tools/harness-automation/cases_R140/med_9_2_12.py +++ b/tools/harness-automation/cases_R140/med_9_2_12.py @@ -27,7 +27,6 @@ # POSSIBILITY OF SUCH DAMAGE. # - import unittest from autothreadharness.harness_case import HarnessCase diff --git a/tools/harness-automation/cases_R140/med_9_2_13.py b/tools/harness-automation/cases_R140/med_9_2_13.py index f45bf21d8..0f69823d4 100755 --- a/tools/harness-automation/cases_R140/med_9_2_13.py +++ b/tools/harness-automation/cases_R140/med_9_2_13.py @@ -27,7 +27,6 @@ # POSSIBILITY OF SUCH DAMAGE. # - import unittest from autothreadharness.harness_case import HarnessCase diff --git a/tools/harness-automation/cases_R140/med_9_2_18.py b/tools/harness-automation/cases_R140/med_9_2_18.py index 3c17bb89d..bc7bdaf2c 100755 --- a/tools/harness-automation/cases_R140/med_9_2_18.py +++ b/tools/harness-automation/cases_R140/med_9_2_18.py @@ -27,7 +27,6 @@ # POSSIBILITY OF SUCH DAMAGE. # - import unittest from autothreadharness.harness_case import HarnessCase diff --git a/tools/harness-automation/cases_R140/med_9_2_6.py b/tools/harness-automation/cases_R140/med_9_2_6.py index 5b8411c5c..40096d780 100755 --- a/tools/harness-automation/cases_R140/med_9_2_6.py +++ b/tools/harness-automation/cases_R140/med_9_2_6.py @@ -27,7 +27,6 @@ # POSSIBILITY OF SUCH DAMAGE. # - import unittest from autothreadharness.harness_case import HarnessCase diff --git a/tools/harness-automation/cases_R140/reed_5_2_4.py b/tools/harness-automation/cases_R140/reed_5_2_4.py index 8deba1c3b..b73f0182f 100755 --- a/tools/harness-automation/cases_R140/reed_5_2_4.py +++ b/tools/harness-automation/cases_R140/reed_5_2_4.py @@ -27,7 +27,6 @@ # POSSIBILITY OF SUCH DAMAGE. # - import unittest from autothreadharness.harness_case import HarnessCase diff --git a/tools/harness-automation/cases_R140/reed_5_2_5.py b/tools/harness-automation/cases_R140/reed_5_2_5.py index f9e3a8ed1..43fa62733 100755 --- a/tools/harness-automation/cases_R140/reed_5_2_5.py +++ b/tools/harness-automation/cases_R140/reed_5_2_5.py @@ -27,7 +27,6 @@ # POSSIBILITY OF SUCH DAMAGE. # - import unittest from autothreadharness.harness_case import HarnessCase diff --git a/tools/harness-automation/cases_R140/reed_5_2_7.py b/tools/harness-automation/cases_R140/reed_5_2_7.py index d77e80f86..54a3b18da 100755 --- a/tools/harness-automation/cases_R140/reed_5_2_7.py +++ b/tools/harness-automation/cases_R140/reed_5_2_7.py @@ -27,7 +27,6 @@ # POSSIBILITY OF SUCH DAMAGE. # - import unittest from autothreadharness.harness_case import HarnessCase diff --git a/tools/harness-automation/cases_R140/reed_5_5_5.py b/tools/harness-automation/cases_R140/reed_5_5_5.py index c2d71b902..82cb40c6f 100755 --- a/tools/harness-automation/cases_R140/reed_5_5_5.py +++ b/tools/harness-automation/cases_R140/reed_5_5_5.py @@ -27,7 +27,6 @@ # POSSIBILITY OF SUCH DAMAGE. # - import unittest from autothreadharness.harness_case import HarnessCase diff --git a/tools/harness-automation/cases_R140/reed_5_6_7.py b/tools/harness-automation/cases_R140/reed_5_6_7.py index 270fc1dd4..ece67ba36 100755 --- a/tools/harness-automation/cases_R140/reed_5_6_7.py +++ b/tools/harness-automation/cases_R140/reed_5_6_7.py @@ -27,7 +27,6 @@ # POSSIBILITY OF SUCH DAMAGE. # - import unittest from autothreadharness.harness_case import HarnessCase diff --git a/tools/harness-automation/cases_R140/reed_5_7_2.py b/tools/harness-automation/cases_R140/reed_5_7_2.py index 2e33bf4ad..f7b816272 100755 --- a/tools/harness-automation/cases_R140/reed_5_7_2.py +++ b/tools/harness-automation/cases_R140/reed_5_7_2.py @@ -27,7 +27,6 @@ # POSSIBILITY OF SUCH DAMAGE. # - import unittest from autothreadharness.harness_case import HarnessCase diff --git a/tools/harness-automation/cases_R140/router_5_1_1.py b/tools/harness-automation/cases_R140/router_5_1_1.py index 637a15c60..31962d42f 100755 --- a/tools/harness-automation/cases_R140/router_5_1_1.py +++ b/tools/harness-automation/cases_R140/router_5_1_1.py @@ -27,7 +27,6 @@ # POSSIBILITY OF SUCH DAMAGE. # - import unittest from autothreadharness.harness_case import HarnessCase diff --git a/tools/harness-automation/cases_R140/router_5_1_10.py b/tools/harness-automation/cases_R140/router_5_1_10.py index 8ac88174a..58fbd53e8 100755 --- a/tools/harness-automation/cases_R140/router_5_1_10.py +++ b/tools/harness-automation/cases_R140/router_5_1_10.py @@ -27,7 +27,6 @@ # POSSIBILITY OF SUCH DAMAGE. # - import unittest from autothreadharness.harness_case import HarnessCase diff --git a/tools/harness-automation/cases_R140/router_5_1_11.py b/tools/harness-automation/cases_R140/router_5_1_11.py index a818612cc..1c01dbe35 100755 --- a/tools/harness-automation/cases_R140/router_5_1_11.py +++ b/tools/harness-automation/cases_R140/router_5_1_11.py @@ -27,7 +27,6 @@ # POSSIBILITY OF SUCH DAMAGE. # - import unittest from autothreadharness.harness_case import HarnessCase diff --git a/tools/harness-automation/cases_R140/router_5_1_12.py b/tools/harness-automation/cases_R140/router_5_1_12.py index d69b9e80d..a2cd21e9c 100755 --- a/tools/harness-automation/cases_R140/router_5_1_12.py +++ b/tools/harness-automation/cases_R140/router_5_1_12.py @@ -27,7 +27,6 @@ # POSSIBILITY OF SUCH DAMAGE. # - import unittest from autothreadharness.harness_case import HarnessCase diff --git a/tools/harness-automation/cases_R140/router_5_1_13.py b/tools/harness-automation/cases_R140/router_5_1_13.py index 80e741327..94398afee 100755 --- a/tools/harness-automation/cases_R140/router_5_1_13.py +++ b/tools/harness-automation/cases_R140/router_5_1_13.py @@ -27,7 +27,6 @@ # POSSIBILITY OF SUCH DAMAGE. # - import unittest from autothreadharness.harness_case import HarnessCase diff --git a/tools/harness-automation/cases_R140/router_5_1_2.py b/tools/harness-automation/cases_R140/router_5_1_2.py index c430acab9..2cd73fb5a 100755 --- a/tools/harness-automation/cases_R140/router_5_1_2.py +++ b/tools/harness-automation/cases_R140/router_5_1_2.py @@ -27,7 +27,6 @@ # POSSIBILITY OF SUCH DAMAGE. # - import unittest from autothreadharness.harness_case import HarnessCase diff --git a/tools/harness-automation/cases_R140/router_5_1_3.py b/tools/harness-automation/cases_R140/router_5_1_3.py index b60d16fa2..a92871758 100755 --- a/tools/harness-automation/cases_R140/router_5_1_3.py +++ b/tools/harness-automation/cases_R140/router_5_1_3.py @@ -27,7 +27,6 @@ # POSSIBILITY OF SUCH DAMAGE. # - import unittest from autothreadharness.harness_case import HarnessCase diff --git a/tools/harness-automation/cases_R140/router_5_1_4.py b/tools/harness-automation/cases_R140/router_5_1_4.py index 477336f39..1f7839a9e 100755 --- a/tools/harness-automation/cases_R140/router_5_1_4.py +++ b/tools/harness-automation/cases_R140/router_5_1_4.py @@ -27,7 +27,6 @@ # POSSIBILITY OF SUCH DAMAGE. # - import unittest from autothreadharness.harness_case import HarnessCase diff --git a/tools/harness-automation/cases_R140/router_5_1_6.py b/tools/harness-automation/cases_R140/router_5_1_6.py index f64160922..8d97cbd24 100755 --- a/tools/harness-automation/cases_R140/router_5_1_6.py +++ b/tools/harness-automation/cases_R140/router_5_1_6.py @@ -27,7 +27,6 @@ # POSSIBILITY OF SUCH DAMAGE. # - import unittest from autothreadharness.harness_case import HarnessCase diff --git a/tools/harness-automation/cases_R140/router_5_1_7.py b/tools/harness-automation/cases_R140/router_5_1_7.py index dfecd892d..2c4bd2ac0 100755 --- a/tools/harness-automation/cases_R140/router_5_1_7.py +++ b/tools/harness-automation/cases_R140/router_5_1_7.py @@ -27,7 +27,6 @@ # POSSIBILITY OF SUCH DAMAGE. # - import unittest from autothreadharness.harness_case import HarnessCase diff --git a/tools/harness-automation/cases_R140/router_5_1_8.py b/tools/harness-automation/cases_R140/router_5_1_8.py index adfcf26ff..a97b967e6 100755 --- a/tools/harness-automation/cases_R140/router_5_1_8.py +++ b/tools/harness-automation/cases_R140/router_5_1_8.py @@ -27,7 +27,6 @@ # POSSIBILITY OF SUCH DAMAGE. # - import unittest from autothreadharness.harness_case import HarnessCase diff --git a/tools/harness-automation/cases_R140/router_5_1_9.py b/tools/harness-automation/cases_R140/router_5_1_9.py index 85f30839f..8a9d5527b 100755 --- a/tools/harness-automation/cases_R140/router_5_1_9.py +++ b/tools/harness-automation/cases_R140/router_5_1_9.py @@ -27,7 +27,6 @@ # POSSIBILITY OF SUCH DAMAGE. # - import unittest from autothreadharness.harness_case import HarnessCase diff --git a/tools/harness-automation/cases_R140/router_5_2_1.py b/tools/harness-automation/cases_R140/router_5_2_1.py index 9ac6fb290..d213607cb 100755 --- a/tools/harness-automation/cases_R140/router_5_2_1.py +++ b/tools/harness-automation/cases_R140/router_5_2_1.py @@ -27,7 +27,6 @@ # POSSIBILITY OF SUCH DAMAGE. # - import unittest from autothreadharness.harness_case import HarnessCase diff --git a/tools/harness-automation/cases_R140/router_5_2_6.py b/tools/harness-automation/cases_R140/router_5_2_6.py index d572e00e0..cf7c27490 100755 --- a/tools/harness-automation/cases_R140/router_5_2_6.py +++ b/tools/harness-automation/cases_R140/router_5_2_6.py @@ -27,7 +27,6 @@ # POSSIBILITY OF SUCH DAMAGE. # - import unittest from autothreadharness.harness_case import HarnessCase diff --git a/tools/harness-automation/cases_R140/router_5_2_7.py b/tools/harness-automation/cases_R140/router_5_2_7.py index 90b5ba0d2..ecb1e99ab 100755 --- a/tools/harness-automation/cases_R140/router_5_2_7.py +++ b/tools/harness-automation/cases_R140/router_5_2_7.py @@ -27,7 +27,6 @@ # POSSIBILITY OF SUCH DAMAGE. # - import unittest from autothreadharness.harness_case import HarnessCase diff --git a/tools/harness-automation/cases_R140/router_5_3_1.py b/tools/harness-automation/cases_R140/router_5_3_1.py index 7bedcf637..f2a517b56 100755 --- a/tools/harness-automation/cases_R140/router_5_3_1.py +++ b/tools/harness-automation/cases_R140/router_5_3_1.py @@ -27,7 +27,6 @@ # POSSIBILITY OF SUCH DAMAGE. # - from autothreadharness.harness_case import HarnessCase import unittest diff --git a/tools/harness-automation/cases_R140/router_5_3_10.py b/tools/harness-automation/cases_R140/router_5_3_10.py index b55513a2e..0af1b0963 100755 --- a/tools/harness-automation/cases_R140/router_5_3_10.py +++ b/tools/harness-automation/cases_R140/router_5_3_10.py @@ -27,7 +27,6 @@ # POSSIBILITY OF SUCH DAMAGE. # - from autothreadharness.harness_case import HarnessCase import unittest diff --git a/tools/harness-automation/cases_R140/router_5_3_11.py b/tools/harness-automation/cases_R140/router_5_3_11.py index 74c25b16d..89bf2376e 100755 --- a/tools/harness-automation/cases_R140/router_5_3_11.py +++ b/tools/harness-automation/cases_R140/router_5_3_11.py @@ -27,7 +27,6 @@ # POSSIBILITY OF SUCH DAMAGE. # - from autothreadharness.harness_case import HarnessCase import unittest diff --git a/tools/harness-automation/cases_R140/router_5_3_2.py b/tools/harness-automation/cases_R140/router_5_3_2.py index e91513622..546f86004 100755 --- a/tools/harness-automation/cases_R140/router_5_3_2.py +++ b/tools/harness-automation/cases_R140/router_5_3_2.py @@ -27,7 +27,6 @@ # POSSIBILITY OF SUCH DAMAGE. # - from autothreadharness.harness_case import HarnessCase import unittest diff --git a/tools/harness-automation/cases_R140/router_5_3_3.py b/tools/harness-automation/cases_R140/router_5_3_3.py index 9b1d50deb..9c736f4e8 100755 --- a/tools/harness-automation/cases_R140/router_5_3_3.py +++ b/tools/harness-automation/cases_R140/router_5_3_3.py @@ -27,7 +27,6 @@ # POSSIBILITY OF SUCH DAMAGE. # - from autothreadharness.harness_case import HarnessCase import unittest diff --git a/tools/harness-automation/cases_R140/router_5_3_4.py b/tools/harness-automation/cases_R140/router_5_3_4.py index 19170b8d0..50efcbff6 100755 --- a/tools/harness-automation/cases_R140/router_5_3_4.py +++ b/tools/harness-automation/cases_R140/router_5_3_4.py @@ -27,7 +27,6 @@ # POSSIBILITY OF SUCH DAMAGE. # - from autothreadharness.harness_case import HarnessCase import unittest diff --git a/tools/harness-automation/cases_R140/router_5_3_5.py b/tools/harness-automation/cases_R140/router_5_3_5.py index d527431e7..0c6644e63 100755 --- a/tools/harness-automation/cases_R140/router_5_3_5.py +++ b/tools/harness-automation/cases_R140/router_5_3_5.py @@ -27,7 +27,6 @@ # POSSIBILITY OF SUCH DAMAGE. # - from autothreadharness.harness_case import HarnessCase import unittest diff --git a/tools/harness-automation/cases_R140/router_5_3_9.py b/tools/harness-automation/cases_R140/router_5_3_9.py index c6388c4c7..f9e196cab 100755 --- a/tools/harness-automation/cases_R140/router_5_3_9.py +++ b/tools/harness-automation/cases_R140/router_5_3_9.py @@ -27,7 +27,6 @@ # POSSIBILITY OF SUCH DAMAGE. # - from autothreadharness.harness_case import HarnessCase import unittest diff --git a/tools/harness-automation/cases_R140/router_5_5_1.py b/tools/harness-automation/cases_R140/router_5_5_1.py index 10199705c..45c42bfc4 100755 --- a/tools/harness-automation/cases_R140/router_5_5_1.py +++ b/tools/harness-automation/cases_R140/router_5_5_1.py @@ -27,7 +27,6 @@ # POSSIBILITY OF SUCH DAMAGE. # - from autothreadharness.harness_case import HarnessCase import unittest diff --git a/tools/harness-automation/cases_R140/router_5_5_2.py b/tools/harness-automation/cases_R140/router_5_5_2.py index a1e736438..b3a8a7c89 100755 --- a/tools/harness-automation/cases_R140/router_5_5_2.py +++ b/tools/harness-automation/cases_R140/router_5_5_2.py @@ -27,7 +27,6 @@ # POSSIBILITY OF SUCH DAMAGE. # - from autothreadharness.harness_case import HarnessCase import unittest diff --git a/tools/harness-automation/cases_R140/router_5_5_3.py b/tools/harness-automation/cases_R140/router_5_5_3.py index e2bfcd6c4..a94c84ce9 100755 --- a/tools/harness-automation/cases_R140/router_5_5_3.py +++ b/tools/harness-automation/cases_R140/router_5_5_3.py @@ -27,7 +27,6 @@ # POSSIBILITY OF SUCH DAMAGE. # - from autothreadharness.harness_case import HarnessCase import unittest diff --git a/tools/harness-automation/cases_R140/router_5_5_4.py b/tools/harness-automation/cases_R140/router_5_5_4.py index d62044841..a10de7ca5 100755 --- a/tools/harness-automation/cases_R140/router_5_5_4.py +++ b/tools/harness-automation/cases_R140/router_5_5_4.py @@ -27,7 +27,6 @@ # POSSIBILITY OF SUCH DAMAGE. # - from autothreadharness.harness_case import HarnessCase import unittest diff --git a/tools/harness-automation/cases_R140/router_5_5_7.py b/tools/harness-automation/cases_R140/router_5_5_7.py index 45c5a73ef..e6e1e912b 100755 --- a/tools/harness-automation/cases_R140/router_5_5_7.py +++ b/tools/harness-automation/cases_R140/router_5_5_7.py @@ -27,7 +27,6 @@ # POSSIBILITY OF SUCH DAMAGE. # - from autothreadharness.harness_case import HarnessCase import unittest diff --git a/tools/harness-automation/cases_R140/router_5_6_1.py b/tools/harness-automation/cases_R140/router_5_6_1.py index 90a260e5c..2cf5317c1 100755 --- a/tools/harness-automation/cases_R140/router_5_6_1.py +++ b/tools/harness-automation/cases_R140/router_5_6_1.py @@ -27,7 +27,6 @@ # POSSIBILITY OF SUCH DAMAGE. # - from autothreadharness.harness_case import HarnessCase import unittest diff --git a/tools/harness-automation/cases_R140/router_5_6_3.py b/tools/harness-automation/cases_R140/router_5_6_3.py index 16d75cd5e..ad81f56e2 100755 --- a/tools/harness-automation/cases_R140/router_5_6_3.py +++ b/tools/harness-automation/cases_R140/router_5_6_3.py @@ -27,7 +27,6 @@ # POSSIBILITY OF SUCH DAMAGE. # - from autothreadharness.harness_case import HarnessCase import unittest diff --git a/tools/harness-automation/cases_R140/router_5_6_9.py b/tools/harness-automation/cases_R140/router_5_6_9.py index 29effa054..c79d8fae1 100755 --- a/tools/harness-automation/cases_R140/router_5_6_9.py +++ b/tools/harness-automation/cases_R140/router_5_6_9.py @@ -27,7 +27,6 @@ # POSSIBILITY OF SUCH DAMAGE. # - from autothreadharness.harness_case import HarnessCase import unittest diff --git a/tools/harness-automation/cases_R140/router_5_7_1.py b/tools/harness-automation/cases_R140/router_5_7_1.py index 760df76db..e521896c0 100755 --- a/tools/harness-automation/cases_R140/router_5_7_1.py +++ b/tools/harness-automation/cases_R140/router_5_7_1.py @@ -27,7 +27,6 @@ # POSSIBILITY OF SUCH DAMAGE. # - import unittest from autothreadharness.harness_case import HarnessCase diff --git a/tools/harness-automation/cases_R140/router_5_7_3.py b/tools/harness-automation/cases_R140/router_5_7_3.py index 08856f583..0b5cef1a8 100755 --- a/tools/harness-automation/cases_R140/router_5_7_3.py +++ b/tools/harness-automation/cases_R140/router_5_7_3.py @@ -27,7 +27,6 @@ # POSSIBILITY OF SUCH DAMAGE. # - import unittest from autothreadharness.harness_case import HarnessCase diff --git a/tools/harness-automation/cases_R140/router_5_8_2.py b/tools/harness-automation/cases_R140/router_5_8_2.py index f7ea1e7da..60f737e9a 100755 --- a/tools/harness-automation/cases_R140/router_5_8_2.py +++ b/tools/harness-automation/cases_R140/router_5_8_2.py @@ -27,7 +27,6 @@ # POSSIBILITY OF SUCH DAMAGE. # - from autothreadharness.harness_case import HarnessCase import unittest diff --git a/tools/harness-automation/cases_R140/router_5_8_3.py b/tools/harness-automation/cases_R140/router_5_8_3.py index e6ceff5c3..644059c14 100755 --- a/tools/harness-automation/cases_R140/router_5_8_3.py +++ b/tools/harness-automation/cases_R140/router_5_8_3.py @@ -27,7 +27,6 @@ # POSSIBILITY OF SUCH DAMAGE. # - from autothreadharness.harness_case import HarnessCase import unittest diff --git a/tools/harness-automation/cases_R140/router_7_1_2.py b/tools/harness-automation/cases_R140/router_7_1_2.py index e6a93c55a..93877ff99 100755 --- a/tools/harness-automation/cases_R140/router_7_1_2.py +++ b/tools/harness-automation/cases_R140/router_7_1_2.py @@ -27,7 +27,6 @@ # POSSIBILITY OF SUCH DAMAGE. # - import unittest from autothreadharness.harness_case import HarnessCase diff --git a/tools/harness-automation/cases_R140/router_7_1_4.py b/tools/harness-automation/cases_R140/router_7_1_4.py index 9b5a189e3..eb738c35f 100755 --- a/tools/harness-automation/cases_R140/router_7_1_4.py +++ b/tools/harness-automation/cases_R140/router_7_1_4.py @@ -27,7 +27,6 @@ # POSSIBILITY OF SUCH DAMAGE. # - import unittest from autothreadharness.harness_case import HarnessCase diff --git a/tools/harness-automation/cases_R140/router_7_1_5.py b/tools/harness-automation/cases_R140/router_7_1_5.py index c4fbcaf08..fe9f11b30 100755 --- a/tools/harness-automation/cases_R140/router_7_1_5.py +++ b/tools/harness-automation/cases_R140/router_7_1_5.py @@ -27,7 +27,6 @@ # POSSIBILITY OF SUCH DAMAGE. # - import unittest from autothreadharness.harness_case import HarnessCase diff --git a/tools/harness-automation/cases_R140/router_7_1_8.py b/tools/harness-automation/cases_R140/router_7_1_8.py index 1cd9a3dac..9c966646d 100755 --- a/tools/harness-automation/cases_R140/router_7_1_8.py +++ b/tools/harness-automation/cases_R140/router_7_1_8.py @@ -27,7 +27,6 @@ # POSSIBILITY OF SUCH DAMAGE. # - import unittest from autothreadharness.harness_case import HarnessCase diff --git a/tools/harness-automation/cases_R140/router_8_2_1.py b/tools/harness-automation/cases_R140/router_8_2_1.py index dd98c870a..04d3d82d9 100755 --- a/tools/harness-automation/cases_R140/router_8_2_1.py +++ b/tools/harness-automation/cases_R140/router_8_2_1.py @@ -27,7 +27,6 @@ # POSSIBILITY OF SUCH DAMAGE. # - import unittest from autothreadharness.harness_case import HarnessCase diff --git a/tools/harness-automation/cases_R140/router_8_2_2.py b/tools/harness-automation/cases_R140/router_8_2_2.py index 3701ec4e2..938a856e8 100755 --- a/tools/harness-automation/cases_R140/router_8_2_2.py +++ b/tools/harness-automation/cases_R140/router_8_2_2.py @@ -27,7 +27,6 @@ # POSSIBILITY OF SUCH DAMAGE. # - import unittest from autothreadharness.harness_case import HarnessCase diff --git a/tools/harness-automation/cases_R140/router_8_2_5.py b/tools/harness-automation/cases_R140/router_8_2_5.py index 553fd6dad..9ab985a75 100755 --- a/tools/harness-automation/cases_R140/router_8_2_5.py +++ b/tools/harness-automation/cases_R140/router_8_2_5.py @@ -27,7 +27,6 @@ # POSSIBILITY OF SUCH DAMAGE. # - import unittest from autothreadharness.harness_case import HarnessCase diff --git a/tools/harness-automation/cases_R140/router_9_2_10.py b/tools/harness-automation/cases_R140/router_9_2_10.py index c63cc34b7..ad0aa5e0b 100755 --- a/tools/harness-automation/cases_R140/router_9_2_10.py +++ b/tools/harness-automation/cases_R140/router_9_2_10.py @@ -27,7 +27,6 @@ # POSSIBILITY OF SUCH DAMAGE. # - import unittest from autothreadharness.harness_case import HarnessCase @@ -38,7 +37,8 @@ class Router_9_2_10(HarnessCase): case = '9 2 10' golden_devices_required = 4 case_need_shield = True - device_order = [('SED_1', False), ('MED_1', False), ('DUT', False), ('Commissioner', True), ('Leader', True)] + device_order = [('SED_1', False), ('MED_1', False), ('DUT', False), + ('Commissioner', True), ('Leader', True)] def on_dialog(self, dialog, title): pass diff --git a/tools/harness-automation/cases_R140/router_9_2_12.py b/tools/harness-automation/cases_R140/router_9_2_12.py index 003e34820..d4f23008d 100755 --- a/tools/harness-automation/cases_R140/router_9_2_12.py +++ b/tools/harness-automation/cases_R140/router_9_2_12.py @@ -27,7 +27,6 @@ # POSSIBILITY OF SUCH DAMAGE. # - import unittest from autothreadharness.harness_case import HarnessCase diff --git a/tools/harness-automation/cases_R140/router_9_2_13.py b/tools/harness-automation/cases_R140/router_9_2_13.py index eea25994c..3bab13488 100755 --- a/tools/harness-automation/cases_R140/router_9_2_13.py +++ b/tools/harness-automation/cases_R140/router_9_2_13.py @@ -27,7 +27,6 @@ # POSSIBILITY OF SUCH DAMAGE. # - import unittest from autothreadharness.harness_case import HarnessCase diff --git a/tools/harness-automation/cases_R140/router_9_2_14.py b/tools/harness-automation/cases_R140/router_9_2_14.py index 1ebff32c1..7e2cc659b 100755 --- a/tools/harness-automation/cases_R140/router_9_2_14.py +++ b/tools/harness-automation/cases_R140/router_9_2_14.py @@ -27,7 +27,6 @@ # POSSIBILITY OF SUCH DAMAGE. # - import unittest from autothreadharness.harness_case import HarnessCase diff --git a/tools/harness-automation/cases_R140/router_9_2_15.py b/tools/harness-automation/cases_R140/router_9_2_15.py index 23f58f93b..799ef3709 100755 --- a/tools/harness-automation/cases_R140/router_9_2_15.py +++ b/tools/harness-automation/cases_R140/router_9_2_15.py @@ -27,7 +27,6 @@ # POSSIBILITY OF SUCH DAMAGE. # - import unittest from autothreadharness.harness_case import HarnessCase diff --git a/tools/harness-automation/cases_R140/router_9_2_16.py b/tools/harness-automation/cases_R140/router_9_2_16.py index 9283de78d..7ef403099 100755 --- a/tools/harness-automation/cases_R140/router_9_2_16.py +++ b/tools/harness-automation/cases_R140/router_9_2_16.py @@ -27,7 +27,6 @@ # POSSIBILITY OF SUCH DAMAGE. # - import unittest from autothreadharness.harness_case import HarnessCase diff --git a/tools/harness-automation/cases_R140/router_9_2_18.py b/tools/harness-automation/cases_R140/router_9_2_18.py index edd44c5f6..e5c4fb05e 100755 --- a/tools/harness-automation/cases_R140/router_9_2_18.py +++ b/tools/harness-automation/cases_R140/router_9_2_18.py @@ -27,7 +27,6 @@ # POSSIBILITY OF SUCH DAMAGE. # - import unittest from autothreadharness.harness_case import HarnessCase diff --git a/tools/harness-automation/cases_R140/router_9_2_6.py b/tools/harness-automation/cases_R140/router_9_2_6.py index 7b2deb6f7..9cba0c7ac 100755 --- a/tools/harness-automation/cases_R140/router_9_2_6.py +++ b/tools/harness-automation/cases_R140/router_9_2_6.py @@ -27,7 +27,6 @@ # POSSIBILITY OF SUCH DAMAGE. # - import unittest from autothreadharness.harness_case import HarnessCase diff --git a/tools/harness-automation/cases_R140/router_9_2_8.py b/tools/harness-automation/cases_R140/router_9_2_8.py index 1f20cc697..9e7f19000 100755 --- a/tools/harness-automation/cases_R140/router_9_2_8.py +++ b/tools/harness-automation/cases_R140/router_9_2_8.py @@ -27,7 +27,6 @@ # POSSIBILITY OF SUCH DAMAGE. # - import unittest from autothreadharness.harness_case import HarnessCase diff --git a/tools/harness-automation/cases_R140/router_9_2_9.py b/tools/harness-automation/cases_R140/router_9_2_9.py index cc53ddcb3..ea1612649 100755 --- a/tools/harness-automation/cases_R140/router_9_2_9.py +++ b/tools/harness-automation/cases_R140/router_9_2_9.py @@ -27,7 +27,6 @@ # POSSIBILITY OF SUCH DAMAGE. # - import unittest from autothreadharness.harness_case import HarnessCase @@ -38,7 +37,8 @@ class Router_9_2_9(HarnessCase): case = '9 2 9' golden_devices_required = 3 case_need_shield = True - device_order = [('Router_2', False), ('Commissioner', True), ('DUT', False), ('Leader', True)] + device_order = [('Router_2', False), ('Commissioner', True), ('DUT', False), + ('Leader', True)] def on_dialog(self, dialog, title): pass diff --git a/tools/harness-automation/cases_R140/sed_6_1_1.py b/tools/harness-automation/cases_R140/sed_6_1_1.py index 81221a702..6f27b2479 100755 --- a/tools/harness-automation/cases_R140/sed_6_1_1.py +++ b/tools/harness-automation/cases_R140/sed_6_1_1.py @@ -27,7 +27,6 @@ # POSSIBILITY OF SUCH DAMAGE. # - import unittest from autothreadharness.harness_case import HarnessCase diff --git a/tools/harness-automation/cases_R140/sed_6_1_2.py b/tools/harness-automation/cases_R140/sed_6_1_2.py index c3acbc6da..92f335535 100755 --- a/tools/harness-automation/cases_R140/sed_6_1_2.py +++ b/tools/harness-automation/cases_R140/sed_6_1_2.py @@ -27,7 +27,6 @@ # POSSIBILITY OF SUCH DAMAGE. # - import unittest from autothreadharness.harness_case import HarnessCase diff --git a/tools/harness-automation/cases_R140/sed_6_1_3.py b/tools/harness-automation/cases_R140/sed_6_1_3.py index 42fab2306..bb989a0f6 100755 --- a/tools/harness-automation/cases_R140/sed_6_1_3.py +++ b/tools/harness-automation/cases_R140/sed_6_1_3.py @@ -27,7 +27,6 @@ # POSSIBILITY OF SUCH DAMAGE. # - import unittest from autothreadharness.harness_case import HarnessCase diff --git a/tools/harness-automation/cases_R140/sed_6_1_4.py b/tools/harness-automation/cases_R140/sed_6_1_4.py index c508b8277..49eb27d3b 100755 --- a/tools/harness-automation/cases_R140/sed_6_1_4.py +++ b/tools/harness-automation/cases_R140/sed_6_1_4.py @@ -27,7 +27,6 @@ # POSSIBILITY OF SUCH DAMAGE. # - import unittest from autothreadharness.harness_case import HarnessCase diff --git a/tools/harness-automation/cases_R140/sed_6_1_5.py b/tools/harness-automation/cases_R140/sed_6_1_5.py index 49048f443..f7483fba5 100755 --- a/tools/harness-automation/cases_R140/sed_6_1_5.py +++ b/tools/harness-automation/cases_R140/sed_6_1_5.py @@ -27,7 +27,6 @@ # POSSIBILITY OF SUCH DAMAGE. # - import unittest from autothreadharness.harness_case import HarnessCase diff --git a/tools/harness-automation/cases_R140/sed_6_1_6.py b/tools/harness-automation/cases_R140/sed_6_1_6.py index 5c20abc24..6cc8d6979 100755 --- a/tools/harness-automation/cases_R140/sed_6_1_6.py +++ b/tools/harness-automation/cases_R140/sed_6_1_6.py @@ -27,7 +27,6 @@ # POSSIBILITY OF SUCH DAMAGE. # - import unittest from autothreadharness.harness_case import HarnessCase diff --git a/tools/harness-automation/cases_R140/sed_6_2_1.py b/tools/harness-automation/cases_R140/sed_6_2_1.py index 8f340d829..271526608 100755 --- a/tools/harness-automation/cases_R140/sed_6_2_1.py +++ b/tools/harness-automation/cases_R140/sed_6_2_1.py @@ -27,7 +27,6 @@ # POSSIBILITY OF SUCH DAMAGE. # - import unittest from autothreadharness.harness_case import HarnessCase diff --git a/tools/harness-automation/cases_R140/sed_6_2_2.py b/tools/harness-automation/cases_R140/sed_6_2_2.py index a8e317658..d0b68e388 100755 --- a/tools/harness-automation/cases_R140/sed_6_2_2.py +++ b/tools/harness-automation/cases_R140/sed_6_2_2.py @@ -27,7 +27,6 @@ # POSSIBILITY OF SUCH DAMAGE. # - import unittest from autothreadharness.harness_case import HarnessCase diff --git a/tools/harness-automation/cases_R140/sed_6_3_1.py b/tools/harness-automation/cases_R140/sed_6_3_1.py index c79034906..1ef1c619b 100755 --- a/tools/harness-automation/cases_R140/sed_6_3_1.py +++ b/tools/harness-automation/cases_R140/sed_6_3_1.py @@ -27,7 +27,6 @@ # POSSIBILITY OF SUCH DAMAGE. # - import unittest from autothreadharness.harness_case import HarnessCase diff --git a/tools/harness-automation/cases_R140/sed_6_3_2.py b/tools/harness-automation/cases_R140/sed_6_3_2.py index e2ca907ba..88a24a439 100755 --- a/tools/harness-automation/cases_R140/sed_6_3_2.py +++ b/tools/harness-automation/cases_R140/sed_6_3_2.py @@ -27,7 +27,6 @@ # POSSIBILITY OF SUCH DAMAGE. # - import unittest from autothreadharness.harness_case import HarnessCase diff --git a/tools/harness-automation/cases_R140/sed_6_4_1.py b/tools/harness-automation/cases_R140/sed_6_4_1.py index 092ce6306..16c0ad4fc 100755 --- a/tools/harness-automation/cases_R140/sed_6_4_1.py +++ b/tools/harness-automation/cases_R140/sed_6_4_1.py @@ -27,7 +27,6 @@ # POSSIBILITY OF SUCH DAMAGE. # - import unittest from autothreadharness.harness_case import HarnessCase diff --git a/tools/harness-automation/cases_R140/sed_6_4_2.py b/tools/harness-automation/cases_R140/sed_6_4_2.py index d79886714..1589b957e 100755 --- a/tools/harness-automation/cases_R140/sed_6_4_2.py +++ b/tools/harness-automation/cases_R140/sed_6_4_2.py @@ -27,7 +27,6 @@ # POSSIBILITY OF SUCH DAMAGE. # - import unittest from autothreadharness.harness_case import HarnessCase diff --git a/tools/harness-automation/cases_R140/sed_6_5_1.py b/tools/harness-automation/cases_R140/sed_6_5_1.py index c9704e24e..f50f45650 100755 --- a/tools/harness-automation/cases_R140/sed_6_5_1.py +++ b/tools/harness-automation/cases_R140/sed_6_5_1.py @@ -27,7 +27,6 @@ # POSSIBILITY OF SUCH DAMAGE. # - import time import unittest diff --git a/tools/harness-automation/cases_R140/sed_6_5_2.py b/tools/harness-automation/cases_R140/sed_6_5_2.py index e2f3b410f..c4ffff984 100755 --- a/tools/harness-automation/cases_R140/sed_6_5_2.py +++ b/tools/harness-automation/cases_R140/sed_6_5_2.py @@ -27,7 +27,6 @@ # POSSIBILITY OF SUCH DAMAGE. # - import unittest from autothreadharness.harness_case import HarnessCase diff --git a/tools/harness-automation/cases_R140/sed_6_5_3.py b/tools/harness-automation/cases_R140/sed_6_5_3.py index f8a0ca373..896301a51 100755 --- a/tools/harness-automation/cases_R140/sed_6_5_3.py +++ b/tools/harness-automation/cases_R140/sed_6_5_3.py @@ -27,7 +27,6 @@ # POSSIBILITY OF SUCH DAMAGE. # - import unittest from autothreadharness.harness_case import HarnessCase diff --git a/tools/harness-automation/cases_R140/sed_6_6_1.py b/tools/harness-automation/cases_R140/sed_6_6_1.py index f948aa92e..241d6a9cd 100755 --- a/tools/harness-automation/cases_R140/sed_6_6_1.py +++ b/tools/harness-automation/cases_R140/sed_6_6_1.py @@ -27,7 +27,6 @@ # POSSIBILITY OF SUCH DAMAGE. # - import unittest from autothreadharness.harness_case import HarnessCase diff --git a/tools/harness-automation/cases_R140/sed_6_6_2.py b/tools/harness-automation/cases_R140/sed_6_6_2.py index 99d423cfe..befce7be9 100755 --- a/tools/harness-automation/cases_R140/sed_6_6_2.py +++ b/tools/harness-automation/cases_R140/sed_6_6_2.py @@ -27,7 +27,6 @@ # POSSIBILITY OF SUCH DAMAGE. # - import unittest from autothreadharness.harness_case import HarnessCase diff --git a/tools/harness-automation/cases_R140/sed_9_2_10.py b/tools/harness-automation/cases_R140/sed_9_2_10.py index 3ca495359..dc363ad3f 100755 --- a/tools/harness-automation/cases_R140/sed_9_2_10.py +++ b/tools/harness-automation/cases_R140/sed_9_2_10.py @@ -27,7 +27,6 @@ # POSSIBILITY OF SUCH DAMAGE. # - import unittest from autothreadharness.harness_case import HarnessCase @@ -38,7 +37,8 @@ class SED_9_2_10(HarnessCase): case = '9 2 10' golden_devices_required = 4 case_need_shield = True - device_order = [('DUT', False), ('MED_1', False), ('Router_1', False), ('Commissioner', True), ('Leader', True)] + device_order = [('DUT', False), ('MED_1', False), ('Router_1', False), + ('Commissioner', True), ('Leader', True)] def on_dialog(self, dialog, title): pass diff --git a/tools/harness-automation/cases_R140/sed_9_2_13.py b/tools/harness-automation/cases_R140/sed_9_2_13.py index f4e877f93..428086f6a 100755 --- a/tools/harness-automation/cases_R140/sed_9_2_13.py +++ b/tools/harness-automation/cases_R140/sed_9_2_13.py @@ -27,7 +27,6 @@ # POSSIBILITY OF SUCH DAMAGE. # - import unittest from autothreadharness.harness_case import HarnessCase diff --git a/tools/harness-automation/cases_R140/sed_9_2_17.py b/tools/harness-automation/cases_R140/sed_9_2_17.py index 5b718d633..c641ed613 100755 --- a/tools/harness-automation/cases_R140/sed_9_2_17.py +++ b/tools/harness-automation/cases_R140/sed_9_2_17.py @@ -27,7 +27,6 @@ # POSSIBILITY OF SUCH DAMAGE. # - import unittest from autothreadharness.harness_case import HarnessCase diff --git a/tools/harness-automation/cases_R140/sed_9_2_18.py b/tools/harness-automation/cases_R140/sed_9_2_18.py index 800763d4b..df32b9363 100755 --- a/tools/harness-automation/cases_R140/sed_9_2_18.py +++ b/tools/harness-automation/cases_R140/sed_9_2_18.py @@ -27,7 +27,6 @@ # POSSIBILITY OF SUCH DAMAGE. # - import unittest from autothreadharness.harness_case import HarnessCase diff --git a/tools/harness-automation/cases_R140/sed_9_2_6.py b/tools/harness-automation/cases_R140/sed_9_2_6.py index c32a2f2ad..ebd60a6ba 100755 --- a/tools/harness-automation/cases_R140/sed_9_2_6.py +++ b/tools/harness-automation/cases_R140/sed_9_2_6.py @@ -27,7 +27,6 @@ # POSSIBILITY OF SUCH DAMAGE. # - import unittest from autothreadharness.harness_case import HarnessCase diff --git a/tools/harness-automation/cases_R140/sed_9_2_8.py b/tools/harness-automation/cases_R140/sed_9_2_8.py index 49cf7cb76..1d0efc3ed 100755 --- a/tools/harness-automation/cases_R140/sed_9_2_8.py +++ b/tools/harness-automation/cases_R140/sed_9_2_8.py @@ -27,7 +27,6 @@ # POSSIBILITY OF SUCH DAMAGE. # - import unittest from autothreadharness.harness_case import HarnessCase diff --git a/tools/harness-automation/doc/conf.py b/tools/harness-automation/doc/conf.py index 4a1f02807..25ef992ea 100644 --- a/tools/harness-automation/doc/conf.py +++ b/tools/harness-automation/doc/conf.py @@ -27,7 +27,6 @@ # POSSIBILITY OF SUCH DAMAGE. # - # # Thread Harness Automation documentation build configuration file, created by # sphinx-quickstart on Wed Jun 29 15:18:24 2016. @@ -144,7 +143,6 @@ pygments_style = 'sphinx' # If true, `todo` and `todoList` produce output, else they produce nothing. todo_include_todos = False - # -- Options for HTML output ---------------------------------------------- # The theme to use for HTML and HTML Help pages. See the documentation for @@ -288,15 +286,13 @@ latex_elements = { # Grouping the document tree into LaTeX files. List of tuples # (source start file, target name, title, # author, documentclass [howto, manual, or own class]). -latex_documents = [ - ( - master_doc, - 'ThreadHarnessAutomation.tex', - u'Thread Harness Automation Documentation', - u'OpenThread', - 'manual', - ) -] +latex_documents = [( + master_doc, + 'ThreadHarnessAutomation.tex', + u'Thread Harness Automation Documentation', + u'OpenThread', + 'manual', +)] # The name of an image file (relative to this directory) to place at the top of # the title page. @@ -324,42 +320,36 @@ latex_documents = [ # # latex_domain_indices = True - # -- Options for manual page output --------------------------------------- # One entry per manual page. List of tuples # (source start file, name, description, authors, manual section). -man_pages = [ - ( - master_doc, - 'threadharnessautomation', - u'Thread Harness Automation Documentation', - [author], - 1, - ) -] +man_pages = [( + master_doc, + 'threadharnessautomation', + u'Thread Harness Automation Documentation', + [author], + 1, +)] # If true, show URL addresses after external links. # # man_show_urls = False - # -- Options for Texinfo output ------------------------------------------- # Grouping the document tree into Texinfo files. List of tuples # (source start file, target name, title, author, # dir menu entry, description, category) -texinfo_documents = [ - ( - master_doc, - 'ThreadHarnessAutomation', - u'Thread Harness Automation Documentation', - author, - 'ThreadHarnessAutomation', - 'One line description of project.', - 'Miscellaneous', - ) -] +texinfo_documents = [( + master_doc, + 'ThreadHarnessAutomation', + u'Thread Harness Automation Documentation', + author, + 'ThreadHarnessAutomation', + 'One line description of project.', + 'Miscellaneous', +)] # Documents to append as an appendix to all manuals. # diff --git a/tools/harness-automation/gencsv.py b/tools/harness-automation/gencsv.py index 93a4c2448..9f9b86791 100755 --- a/tools/harness-automation/gencsv.py +++ b/tools/harness-automation/gencsv.py @@ -2,7 +2,6 @@ import json import sys - if len(sys.argv) > 1: filename = sys.argv[1] else: @@ -20,13 +19,10 @@ result = json.load(open(filename, 'r')) o = open('./result.csv', 'w') o.write('Case,Status,Started,Stopped,Reason\n') for k, v in sorted(result.items(), key=get_key): - o.write( - '%s,%s,%s,%s,%s\n' - % ( - k, - (v['passed'] and 'Pass') or 'Fail', - v['started'], - v['stopped'], - (v['error'] or '').replace('\n', ' '), - ) - ) + o.write('%s,%s,%s,%s,%s\n' % ( + k, + (v['passed'] and 'Pass') or 'Fail', + v['started'], + v['stopped'], + (v['error'] or '').replace('\n', ' '), + )) diff --git a/tools/harness-sniffer/OT_Sniffer.py b/tools/harness-sniffer/OT_Sniffer.py index 3df900a5b..21a8678b8 100644 --- a/tools/harness-sniffer/OT_Sniffer.py +++ b/tools/harness-sniffer/OT_Sniffer.py @@ -25,7 +25,6 @@ # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE # POSSIBILITY OF SUCH DAMAGE. - ''''OpenThread Sniffer API implementation''' import os @@ -35,6 +34,7 @@ from ISniffer import ISniffer class OT_Sniffer(ISniffer): + def __init__(self, **kwargs): try: self.channel = kwargs.get('channel', 11) @@ -43,20 +43,27 @@ class OT_Sniffer(ISniffer): self.is_active = False except Exception as e: - ModuleHelper.WriteIntoDebugLogger('OT_Sniffer: [intialize] --> ' + str(e)) + ModuleHelper.WriteIntoDebugLogger('OT_Sniffer: [intialize] --> ' + + str(e)) def discoverSniffer(self): sniffers = [] - p_discover = subprocess.Popen('extcap_ot.bat --extcap-interfaces', stdout=subprocess.PIPE, shell=True) + p_discover = subprocess.Popen('extcap_ot.bat --extcap-interfaces', + stdout=subprocess.PIPE, + shell=True) for line in p_discover.stdout.readlines(): if line.startswith('interface'): try: # e.g. interface {value=COM10:460800}{display=OpenThread Sniffer COM10} - interface_port = line[line.index('value=') + 6 : line.index('}{display')] - sniffers.append(OT_Sniffer(addressofDevice=interface_port, channel=ModuleHelper.Default_Channel)) + interface_port = line[line.index('value=') + + 6:line.index('}{display')] + sniffers.append( + OT_Sniffer(addressofDevice=interface_port, + channel=ModuleHelper.Default_Channel)) except Exception as e: - ModuleHelper.WriteIntoDebugLogger('OT_Sniffer: [discoverSniffer] --> Error: ' + str(e)) + ModuleHelper.WriteIntoDebugLogger( + 'OT_Sniffer: [discoverSniffer] --> Error: ' + str(e)) p_discover.wait() return sniffers @@ -72,14 +79,17 @@ class OT_Sniffer(ISniffer): # start sniffer self.setChannel(channelToCapture) p_where = subprocess.Popen( - 'py -3 -c "import sys; print(sys.executable)"', stdout=subprocess.PIPE, shell=True, + 'py -3 -c "import sys; print(sys.executable)"', + stdout=subprocess.PIPE, + shell=True, ) # python_exe: e.g. C:\Python37\python.exe python_exe = p_where.stdout.readline().strip() if python_exe.endswith(".exe"): # sniffer_py: e.g. C:\Python37\Scripts\sniffer.py - sniffer_py = str(os.path.dirname(python_exe)) + '\\Scripts\\sniffer.py' + sniffer_py = str( + os.path.dirname(python_exe)) + '\\Scripts\\sniffer.py' cmd = [ python_exe, @@ -95,11 +105,13 @@ class OT_Sniffer(ISniffer): captureFileLocation, ] self.is_active = True - ModuleHelper.WriteIntoDebugLogger('OT_Sniffer: [cmd] --> %s' % str(cmd)) + ModuleHelper.WriteIntoDebugLogger('OT_Sniffer: [cmd] --> %s' % + str(cmd)) self.subprocess = subprocess.Popen(cmd) except Exception as e: - ModuleHelper.WriteIntoDebugLogger('OT_Sniffer: [startSniffer] --> Error: ' + str(e)) + ModuleHelper.WriteIntoDebugLogger( + 'OT_Sniffer: [startSniffer] --> Error: ' + str(e)) def stopSniffer(self): """ diff --git a/tools/harness-thci/OpenThread.py b/tools/harness-thci/OpenThread.py index f364e8483..36ef14fea 100644 --- a/tools/harness-thci/OpenThread.py +++ b/tools/harness-thci/OpenThread.py @@ -25,7 +25,6 @@ # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE # POSSIBILITY OF SUCH DAMAGE. - """ >> Thread Host Controller Interface >> Device : OpenThread THCI @@ -208,10 +207,8 @@ class OpenThread(IThci): logging.info('%s: sendCommand[%s]', self.port, cmd) if self.logThreadStatus == self.logStatus['running']: self.logThreadStatus = self.logStatus['pauseReq'] - while ( - self.logThreadStatus != self.logStatus['paused'] - and self.logThreadStatus != self.logStatus['stop'] - ): + while (self.logThreadStatus != self.logStatus['paused'] and + self.logThreadStatus != self.logStatus['stop']): pass try: @@ -248,9 +245,8 @@ class OpenThread(IThci): retry_times -= 1 time.sleep(0.2) if line != 'Done': - raise Exception( - '%s: failed to find end of response' % self.port - ) + raise Exception('%s: failed to find end of response' % + self.port) logging.info('%s: send command[%s] done!', self.port, cmd) return response except Exception as e: @@ -266,8 +262,7 @@ class OpenThread(IThci): self.__sendCommand(cmd) except Exception as e: ModuleHelper.WriteIntoDebugLogger( - '__disableRouterEligible() Error: ' + str(e) - ) + '__disableRouterEligible() Error: ' + str(e)) def __setDeviceMode(self, mode): """set thread device mode: @@ -289,9 +284,8 @@ class OpenThread(IThci): cmd = 'mode %s' % mode return self.__sendCommand(cmd)[-1] == 'Done' except Exception as e: - ModuleHelper.WriteIntoDebugLogger( - 'setDeviceMode() Error: ' + str(e) - ) + ModuleHelper.WriteIntoDebugLogger('setDeviceMode() Error: ' + + str(e)) def __setRouterUpgradeThreshold(self, iThreshold): """set router upgrade threshold @@ -311,8 +305,7 @@ class OpenThread(IThci): return self.__sendCommand(cmd)[-1] == 'Done' except Exception as e: ModuleHelper.WriteIntoDebugLogger( - 'setRouterUpgradeThreshold() Error: ' + str(e) - ) + 'setRouterUpgradeThreshold() Error: ' + str(e)) def __setRouterDowngradeThreshold(self, iThreshold): """set router downgrade threshold @@ -333,8 +326,7 @@ class OpenThread(IThci): return self.__sendCommand(cmd)[-1] == 'Done' except Exception as e: ModuleHelper.WriteIntoDebugLogger( - 'setRouterDowngradeThreshold() Error: ' + str(e) - ) + 'setRouterDowngradeThreshold() Error: ' + str(e)) def __setRouterSelectionJitter(self, iRouterJitter): """set ROUTER_SELECTION_JITTER parameter for REED to upgrade to Router @@ -353,8 +345,7 @@ class OpenThread(IThci): return self.__sendCommand(cmd)[-1] == 'Done' except Exception as e: ModuleHelper.WriteIntoDebugLogger( - 'setRouterSelectionJitter() Error: ' + str(e) - ) + 'setRouterSelectionJitter() Error: ' + str(e)) def __setAddressfilterMode(self, mode): """set address filter mode @@ -371,8 +362,7 @@ class OpenThread(IThci): return False except Exception as e: ModuleHelper.WriteIntoDebugLogger( - '__setAddressFilterMode() Error: ' + str(e) - ) + '__setAddressFilterMode() Error: ' + str(e)) def __startOpenThread(self): """start OpenThread stack @@ -402,9 +392,9 @@ class OpenThread(IThci): self.addBlockedMAC(addr) if self.deviceRole in [ - Thread_Device_Role.Leader, - Thread_Device_Role.Router, - Thread_Device_Role.REED, + Thread_Device_Role.Leader, + Thread_Device_Role.Router, + Thread_Device_Role.REED, ]: self.__setRouterSelectionJitter(1) @@ -415,9 +405,8 @@ class OpenThread(IThci): else: return False except Exception as e: - ModuleHelper.WriteIntoDebugLogger( - 'startOpenThread() Error: ' + str(e) - ) + ModuleHelper.WriteIntoDebugLogger('startOpenThread() Error: ' + + str(e)) def __stopOpenThread(self): """stop OpenThread stack @@ -433,9 +422,8 @@ class OpenThread(IThci): else: return False except Exception as e: - ModuleHelper.WriteIntoDebugLogger( - 'stopOpenThread() Error: ' + str(e) - ) + ModuleHelper.WriteIntoDebugLogger('stopOpenThread() Error: ' + + str(e)) def __isOpenThreadRunning(self): """check whether or not OpenThread is running @@ -508,8 +496,7 @@ class OpenThread(IThci): hexIter = iter(hexPrefix) finalMac = ':'.join( a + b + c + d - for a, b, c, d in zip(hexIter, hexIter, hexIter, hexIter) - ) + for a, b, c, d in zip(hexIter, hexIter, hexIter, hexIter)) prefix = str(finalMac) strIp6Prefix = prefix[:19] return strIp6Prefix + '::' @@ -559,9 +546,7 @@ class OpenThread(IThci): logs.put(line) if 'Join success' in line: - self.joinCommissionedStatus = self.joinStatus[ - 'succeed' - ] + self.joinCommissionedStatus = self.joinStatus['succeed'] break elif 'Join failed' in line: self.joinCommissionedStatus = self.joinStatus['failed'] @@ -597,9 +582,8 @@ class OpenThread(IThci): self.hasActiveDatasetToCommit = True return self.__sendCommand(cmd)[-1] == 'Done' except Exception as e: - ModuleHelper.WriteIntoDebugLogger( - 'setChannelMask() Error: ' + str(e) - ) + ModuleHelper.WriteIntoDebugLogger('setChannelMask() Error: ' + + str(e)) def __setSecurityPolicy(self, securityPolicySecs, securityPolicyFlags): print('call _setSecurityPolicy') @@ -611,9 +595,8 @@ class OpenThread(IThci): self.hasActiveDatasetToCommit = True return self.__sendCommand(cmd)[-1] == 'Done' except Exception as e: - ModuleHelper.WriteIntoDebugLogger( - 'setSecurityPolicy() Error: ' + str(e) - ) + ModuleHelper.WriteIntoDebugLogger('setSecurityPolicy() Error: ' + + str(e)) def __setKeySwitchGuardTime(self, iKeySwitchGuardTime): """ set the Key switch guard time @@ -636,8 +619,7 @@ class OpenThread(IThci): return False except Exception as e: ModuleHelper.WriteIntoDebugLogger( - 'setKeySwitchGuardTime() Error; ' + str(e) - ) + 'setKeySwitchGuardTime() Error; ' + str(e)) def __getCommissionerSessionId(self): """ get the commissioner session id allocated from Leader """ @@ -669,9 +651,8 @@ class OpenThread(IThci): self.handle.close() self.handle = None except Exception as e: - ModuleHelper.WriteIntoDebugLogger( - 'closeConnection() Error: ' + str(e) - ) + ModuleHelper.WriteIntoDebugLogger('closeConnection() Error: ' + + str(e)) def intialize(self): """initialize the serial port with baudrate, timeout parameters""" @@ -685,15 +666,11 @@ class OpenThread(IThci): if self.firmwarePrefix in self.UIStatusMsg: self.deviceConnected = True else: - self.UIStatusMsg = ( - 'Firmware Not Matching Expecting ' - + self.firmwarePrefix - + ' Now is ' - + self.UIStatusMsg - ) + self.UIStatusMsg = ('Firmware Not Matching Expecting ' + + self.firmwarePrefix + ' Now is ' + + self.UIStatusMsg) ModuleHelper.WriteIntoDebugLogger( - 'Err: OpenThread device Firmware not matching..' - ) + 'Err: OpenThread device Firmware not matching..') except Exception as e: ModuleHelper.WriteIntoDebugLogger('intialize() Error: ' + str(e)) @@ -715,14 +692,11 @@ class OpenThread(IThci): cmd = 'networkname %s' % networkName datasetCmd = 'dataset networkname %s' % networkName self.hasActiveDatasetToCommit = True - return ( - self.__sendCommand(cmd)[-1] == 'Done' - and self.__sendCommand(datasetCmd)[-1] == 'Done' - ) + return (self.__sendCommand(cmd)[-1] == 'Done' and + self.__sendCommand(datasetCmd)[-1] == 'Done') except Exception as e: - ModuleHelper.WriteIntoDebugLogger( - 'setNetworkName() Error: ' + str(e) - ) + ModuleHelper.WriteIntoDebugLogger('setNetworkName() Error: ' + + str(e)) def setChannel(self, channel=11): """set channel of Thread device operates on. @@ -743,10 +717,8 @@ class OpenThread(IThci): cmd = 'channel %s' % channel datasetCmd = 'dataset channel %s' % channel self.hasActiveDatasetToCommit = True - return ( - self.__sendCommand(cmd)[-1] == 'Done' - and self.__sendCommand(datasetCmd)[-1] == 'Done' - ) + return (self.__sendCommand(cmd)[-1] == 'Done' and + self.__sendCommand(datasetCmd)[-1] == 'Done') except Exception as e: ModuleHelper.WriteIntoDebugLogger('setChannel() Error: ' + str(e)) @@ -888,14 +860,11 @@ class OpenThread(IThci): self.networkKey = masterKey self.hasActiveDatasetToCommit = True - return ( - self.__sendCommand(cmd)[-1] == 'Done' - and self.__sendCommand(datasetCmd)[-1] == 'Done' - ) + return (self.__sendCommand(cmd)[-1] == 'Done' and + self.__sendCommand(datasetCmd)[-1] == 'Done') except Exception as e: - ModuleHelper.WriteIntoDebugLogger( - 'setNetworkkey() Error: ' + str(e) - ) + ModuleHelper.WriteIntoDebugLogger('setNetworkkey() Error: ' + + str(e)) def addBlockedMAC(self, xEUI): """add a given extended address to the blacklist entry @@ -935,9 +904,8 @@ class OpenThread(IThci): return ret except Exception as e: - ModuleHelper.WriteIntoDebugLogger( - 'addBlockedMAC() Error: ' + str(e) - ) + ModuleHelper.WriteIntoDebugLogger('addBlockedMAC() Error: ' + + str(e)) def addAllowMAC(self, xEUI): """add a given extended address to the whitelist addressfilter @@ -999,9 +967,8 @@ class OpenThread(IThci): return True return False except Exception as e: - ModuleHelper.WriteIntoDebugLogger( - 'clearBlockList() Error: ' + str(e) - ) + ModuleHelper.WriteIntoDebugLogger('clearBlockList() Error: ' + + str(e)) def clearAllowList(self): """clear all entries in whitelist table @@ -1028,9 +995,8 @@ class OpenThread(IThci): return True return False except Exception as e: - ModuleHelper.WriteIntoDebugLogger( - 'clearAllowList() Error: ' + str(e) - ) + ModuleHelper.WriteIntoDebugLogger('clearAllowList() Error: ' + + str(e)) def getDeviceRole(self): """get current device role in Thread Network""" @@ -1102,7 +1068,9 @@ class OpenThread(IThci): if self._update_router_status and eRoleId == Thread_Device_Role.Router: self.__updateRouterStatus() - time.sleep(5) # increase delay temporally (+5s) to remedy TH's delay updates + time.sleep( + 5 + ) # increase delay temporally (+5s) to remedy TH's delay updates return True except Exception as e: @@ -1204,7 +1172,9 @@ class OpenThread(IThci): self._sendline(cmd) self._expect(cmd) # wait echo reply - time.sleep(6) # increase delay temporally (+5s) to remedy TH's delay updates + time.sleep( + 6 + ) # increase delay temporally (+5s) to remedy TH's delay updates except Exception as e: ModuleHelper.WriteIntoDebugLogger('ping() Error: ' + str(e)) @@ -1226,9 +1196,8 @@ class OpenThread(IThci): # wait echo reply time.sleep(1) except Exception as e: - ModuleHelper.WriteIntoDebugLogger( - 'multicast_ping() Error: ' + str(e) - ) + ModuleHelper.WriteIntoDebugLogger('multicast_ping() Error: ' + + str(e)) def getVersionNumber(self): """get OpenThread stack firmware version number""" @@ -1256,10 +1225,8 @@ class OpenThread(IThci): cmd = 'panid %s' % panid datasetCmd = 'dataset panid %s' % panid self.hasActiveDatasetToCommit = True - return ( - self.__sendCommand(cmd)[-1] == 'Done' - and self.__sendCommand(datasetCmd)[-1] == 'Done' - ) + return (self.__sendCommand(cmd)[-1] == 'Done' and + self.__sendCommand(datasetCmd)[-1] == 'Done') except Exception as e: ModuleHelper.WriteIntoDebugLogger('setPANID() Error: ' + str(e)) @@ -1298,9 +1265,7 @@ class OpenThread(IThci): cmd = 'releaserouterid %s' % routerId return self.__sendCommand(cmd)[-1] == 'Done' except Exception as e: - ModuleHelper.WriteIntoDebugLogger( - 'removeRouter() Error: ' + str(e) - ) + ModuleHelper.WriteIntoDebugLogger('removeRouter() Error: ' + str(e)) def setDefaultValues(self): """set default mandatory Thread Network parameter value""" @@ -1342,9 +1307,8 @@ class OpenThread(IThci): try: self.setMAC(self.mac) self.__setChannelMask(self.channelMask) - self.__setSecurityPolicy( - self.securityPolicySecs, self.securityPolicyFlags - ) + self.__setSecurityPolicy(self.securityPolicySecs, + self.securityPolicyFlags) self.setChannel(self.channel) self.setPANID(self.panId) self.setXpanId(self.xpanId) @@ -1354,9 +1318,8 @@ class OpenThread(IThci): self.setPSKc(self.pskc) self.setActiveTimestamp(self.activetimestamp) except Exception as e: - ModuleHelper.WriteIntoDebugLogger( - 'setDefaultValue() Error: ' + str(e) - ) + ModuleHelper.WriteIntoDebugLogger('setDefaultValue() Error: ' + + str(e)) def getDeviceConncetionStatus(self): """check if serial port connection is ready or not""" @@ -1402,9 +1365,8 @@ class OpenThread(IThci): print(cmd) return self.__sendCommand(cmd)[-1] == 'Done' except Exception as e: - ModuleHelper.WriteIntoDebugLogger( - '__setPollPeriod() Error: ' + str(e) - ) + ModuleHelper.WriteIntoDebugLogger('__setPollPeriod() Error: ' + + str(e)) def setLinkQuality(self, EUIadr, LinkQuality): """set custom LinkQualityIn for all receiving messages from the specified EUIadr @@ -1442,9 +1404,8 @@ class OpenThread(IThci): print(cmd) return self.__sendCommand(cmd)[-1] == 'Done' except Exception as e: - ModuleHelper.WriteIntoDebugLogger( - 'setLinkQuality() Error: ' + str(e) - ) + ModuleHelper.WriteIntoDebugLogger('setLinkQuality() Error: ' + + str(e)) def setOutBoundLinkQuality(self, LinkQuality): """set custom LinkQualityIn for all receiving messages from the any address @@ -1469,8 +1430,7 @@ class OpenThread(IThci): return self.__sendCommand(cmd)[-1] == 'Done' except Exception as e: ModuleHelper.WriteIntoDebugLogger( - 'setOutBoundLinkQuality() Error: ' + str(e) - ) + 'setOutBoundLinkQuality() Error: ' + str(e)) def removeRouterPrefix(self, prefixEntry): """remove the configured prefix on a border router @@ -1495,9 +1455,8 @@ class OpenThread(IThci): else: return False except Exception as e: - ModuleHelper.WriteIntoDebugLogger( - 'removeRouterPrefix() Error: ' + str(e) - ) + ModuleHelper.WriteIntoDebugLogger('removeRouterPrefix() Error: ' + + str(e)) def resetAndRejoin(self, timeout): """reset and join back Thread Network with a given timeout delay @@ -1527,9 +1486,8 @@ class OpenThread(IThci): return False return True except Exception as e: - ModuleHelper.WriteIntoDebugLogger( - 'resetAndRejoin() Error: ' + str(e) - ) + ModuleHelper.WriteIntoDebugLogger('resetAndRejoin() Error: ' + + str(e)) def configBorderRouter( self, @@ -1603,9 +1561,8 @@ class OpenThread(IThci): else: return False except Exception as e: - ModuleHelper.WriteIntoDebugLogger( - 'configBorderRouter() Error: ' + str(e) - ) + ModuleHelper.WriteIntoDebugLogger('configBorderRouter() Error: ' + + str(e)) def setNetworkIDTimeout(self, iNwkIDTimeOut): """set networkid timeout for Thread device @@ -1625,9 +1582,8 @@ class OpenThread(IThci): print(cmd) return self.__sendCommand(cmd)[-1] == 'Done' except Exception as e: - ModuleHelper.WriteIntoDebugLogger( - 'setNetworkIDTimeout() Error: ' + str(e) - ) + ModuleHelper.WriteIntoDebugLogger('setNetworkIDTimeout() Error: ' + + str(e)) def setKeepAliveTimeOut(self, iTimeOut): """set keep alive timeout for device @@ -1648,9 +1604,8 @@ class OpenThread(IThci): print(cmd) return self.__sendCommand(cmd)[-1] == 'Done' except Exception as e: - ModuleHelper.WriteIntoDebugLogger( - 'setKeepAliveTimeOut() Error: ' + str(e) - ) + ModuleHelper.WriteIntoDebugLogger('setKeepAliveTimeOut() Error: ' + + str(e)) def setKeySequenceCounter(self, iKeySequenceValue): """ set the Key sequence counter corresponding to Thread Network master key @@ -1676,8 +1631,7 @@ class OpenThread(IThci): return False except Exception as e: ModuleHelper.WriteIntoDebugLogger( - 'setKeySequenceCounter() Error; ' + str(e) - ) + 'setKeySequenceCounter() Error; ' + str(e)) def getKeySequenceCounter(self): """get current Thread Network key sequence""" @@ -1708,8 +1662,7 @@ class OpenThread(IThci): return self.setKeySequenceCounter(keySequence) except Exception as e: ModuleHelper.WriteIntoDebugLogger( - 'incrementKeySequenceCounter() Error: ' + str(e) - ) + 'incrementKeySequenceCounter() Error: ' + str(e)) def setNetworkDataRequirement(self, eDataRequirement): """set whether the Thread device requires the full network data @@ -1768,9 +1721,8 @@ class OpenThread(IThci): # send server data ntf to leader return self.__sendCommand('netdataregister')[-1] == 'Done' except Exception as e: - ModuleHelper.WriteIntoDebugLogger( - 'configExternalRouter() Error: ' + str(e) - ) + ModuleHelper.WriteIntoDebugLogger('configExternalRouter() Error: ' + + str(e)) def getNeighbouringRouters(self): """get neighboring routers information @@ -1813,8 +1765,7 @@ class OpenThread(IThci): return routerInfo except Exception as e: ModuleHelper.WriteIntoDebugLogger( - 'getNeighbouringDevice() Error: ' + str(e) - ) + 'getNeighbouringDevice() Error: ' + str(e)) def getChildrenInfo(self): """get all children information @@ -1862,9 +1813,8 @@ class OpenThread(IThci): print(childrenInfoAll) return childrenInfoAll except Exception as e: - ModuleHelper.WriteIntoDebugLogger( - 'getChildrenInfo() Error: ' + str(e) - ) + ModuleHelper.WriteIntoDebugLogger('getChildrenInfo() Error: ' + + str(e)) def setXpanId(self, xPanId): """set extended PAN ID of Thread Network @@ -1891,10 +1841,8 @@ class OpenThread(IThci): self.xpanId = xpanid self.hasActiveDatasetToCommit = True - return ( - self.__sendCommand(cmd)[-1] == 'Done' - and self.__sendCommand(datasetCmd)[-1] == 'Done' - ) + return (self.__sendCommand(cmd)[-1] == 'Done' and + self.__sendCommand(datasetCmd)[-1] == 'Done') except Exception as e: ModuleHelper.WriteIntoDebugLogger('setXpanId() Error: ' + str(e)) @@ -2025,9 +1973,8 @@ class OpenThread(IThci): print(cmd) return self.__sendCommand(cmd)[-1] == 'Done' except Exception as e: - ModuleHelper.WriteIntoDebugLogger( - 'forceSetSlaac() Error: ' + str(e) - ) + ModuleHelper.WriteIntoDebugLogger('forceSetSlaac() Error: ' + + str(e)) def setSleepyNodePollTime(self): pass @@ -2140,8 +2087,7 @@ class OpenThread(IThci): if self.__sendCommand(cmd)[-1] == 'Done': if self.logThreadStatus == self.logStatus['stop']: self.logThread = ThreadRunner.run( - target=self.__readCommissioningLogs, args=(120,) - ) + target=self.__readCommissioningLogs, args=(120,)) return True else: return False @@ -2182,9 +2128,8 @@ class OpenThread(IThci): else: return False except Exception as e: - ModuleHelper.writeintodebuglogger( - 'allowcommission() error: ' + str(e) - ) + ModuleHelper.writeintodebuglogger('allowcommission() error: ' + + str(e)) def joinCommissioned(self, strPSKd='threadjpaketest', waitTime=20): """start joiner @@ -2206,8 +2151,7 @@ class OpenThread(IThci): if self.logThreadStatus == self.logStatus['stop']: self.logThread = ThreadRunner.run( - target=self.__readCommissioningLogs, args=(maxDuration,) - ) + target=self.__readCommissioningLogs, args=(maxDuration,)) t_end = time.time() + maxDuration while time.time() < t_end: @@ -2249,29 +2193,26 @@ class OpenThread(IThci): if 'direction' in infoType: EncryptedPacket.Direction = ( PlatformDiagnosticPacket_Direction.IN - if 'recv' in infoValue - else PlatformDiagnosticPacket_Direction.OUT - if 'send' in infoValue - else PlatformDiagnosticPacket_Direction.UNKNOWN - ) + if 'recv' in infoValue else + PlatformDiagnosticPacket_Direction.OUT + if 'send' in infoValue else + PlatformDiagnosticPacket_Direction.UNKNOWN) elif 'type' in infoType: EncryptedPacket.Type = ( PlatformDiagnosticPacket_Type.JOIN_FIN_req - if 'JOIN_FIN.req' in infoValue - else PlatformDiagnosticPacket_Type.JOIN_FIN_rsp - if 'JOIN_FIN.rsp' in infoValue - else PlatformDiagnosticPacket_Type.JOIN_ENT_req - if 'JOIN_ENT.ntf' in infoValue - else PlatformDiagnosticPacket_Type.JOIN_ENT_rsp - if 'JOIN_ENT.rsp' in infoValue - else PlatformDiagnosticPacket_Type.UNKNOWN - ) + if 'JOIN_FIN.req' in infoValue else + PlatformDiagnosticPacket_Type.JOIN_FIN_rsp + if 'JOIN_FIN.rsp' in infoValue else + PlatformDiagnosticPacket_Type.JOIN_ENT_req + if 'JOIN_ENT.ntf' in infoValue else + PlatformDiagnosticPacket_Type. + JOIN_ENT_rsp if 'JOIN_ENT.rsp' in + infoValue else PlatformDiagnosticPacket_Type.UNKNOWN) elif 'len' in infoType: bytesInEachLine = 16 EncryptedPacket.TLVsLength = int(infoValue) - payloadLineCount = ( - int(infoValue) + bytesInEachLine - 1 - ) / bytesInEachLine + payloadLineCount = (int(infoValue) + bytesInEachLine - + 1) / bytesInEachLine while payloadLineCount > 0: payloadLineCount = payloadLineCount - 1 payloadLine = rawLogs.get() @@ -2283,11 +2224,8 @@ class OpenThread(IThci): if '..' not in payloadValues[num]: payload.append(int(payloadValues[num], 16)) - EncryptedPacket.TLVs = ( - PlatformPackets.read(EncryptedPacket.Type, payload) - if payload != [] - else [] - ) + EncryptedPacket.TLVs = (PlatformPackets.read( + EncryptedPacket.Type, payload) if payload != [] else []) ProcessedLogs.append(EncryptedPacket) return ProcessedLogs @@ -2318,8 +2256,7 @@ class OpenThread(IThci): print('%s call MGMT_ED_SCAN' % self.port) channelMask = '' channelMask = '0x' + self.__convertLongToHex( - self.__convertChannelMask(listChannelMask) - ) + self.__convertChannelMask(listChannelMask)) try: cmd = 'commissioner energy %s %s %s %s %s' % ( channelMask, @@ -2331,13 +2268,10 @@ class OpenThread(IThci): print(cmd) return self.__sendCommand(cmd)[-1] == 'Done' except Exception as e: - ModuleHelper.writeintodebuglogger( - 'MGMT_ED_SCAN() error: ' + str(e) - ) + ModuleHelper.writeintodebuglogger('MGMT_ED_SCAN() error: ' + str(e)) - def MGMT_PANID_QUERY( - self, sAddr, xCommissionerSessionId, listChannelMask, xPanId - ): + def MGMT_PANID_QUERY(self, sAddr, xCommissionerSessionId, listChannelMask, + xPanId): """send MGMT_PANID_QUERY message to a given destination Args: @@ -2351,8 +2285,7 @@ class OpenThread(IThci): panid = '' channelMask = '' channelMask = '0x' + self.__convertLongToHex( - self.__convertChannelMask(listChannelMask) - ) + self.__convertChannelMask(listChannelMask)) if not isinstance(xPanId, str): panid = str(hex(xPanId)) @@ -2362,13 +2295,11 @@ class OpenThread(IThci): print(cmd) return self.__sendCommand(cmd)[-1] == 'Done' except Exception as e: - ModuleHelper.writeintodebuglogger( - 'MGMT_PANID_QUERY() error: ' + str(e) - ) + ModuleHelper.writeintodebuglogger('MGMT_PANID_QUERY() error: ' + + str(e)) - def MGMT_ANNOUNCE_BEGIN( - self, sAddr, xCommissionerSessionId, listChannelMask, xCount, xPeriod - ): + def MGMT_ANNOUNCE_BEGIN(self, sAddr, xCommissionerSessionId, + listChannelMask, xCount, xPeriod): """send MGMT_ANNOUNCE_BEGIN message to a given destination Returns: @@ -2378,8 +2309,7 @@ class OpenThread(IThci): print('%s call MGMT_ANNOUNCE_BEGIN' % self.port) channelMask = '' channelMask = '0x' + self.__convertLongToHex( - self.__convertChannelMask(listChannelMask) - ) + self.__convertChannelMask(listChannelMask)) try: cmd = 'commissioner announce %s %s %s %s' % ( channelMask, @@ -2390,9 +2320,8 @@ class OpenThread(IThci): print(cmd) return self.__sendCommand(cmd)[-1] == 'Done' except Exception as e: - ModuleHelper.writeintodebuglogger( - 'MGMT_ANNOUNCE_BEGIN() error: ' + str(e) - ) + ModuleHelper.writeintodebuglogger('MGMT_ANNOUNCE_BEGIN() error: ' + + str(e)) def MGMT_ACTIVE_GET(self, Addr='', TLVs=[]): """send MGMT_ACTIVE_GET command @@ -2419,9 +2348,8 @@ class OpenThread(IThci): return self.__sendCommand(cmd)[-1] == 'Done' except Exception as e: - ModuleHelper.WriteIntoDebugLogger( - 'MGMT_ACTIVE_GET() Error: ' + str(e) - ) + ModuleHelper.WriteIntoDebugLogger('MGMT_ACTIVE_GET() Error: ' + + str(e)) def MGMT_ACTIVE_SET( self, @@ -2488,18 +2416,12 @@ class OpenThread(IThci): if listChannelMask is not None: cmd += ' channelmask ' cmd += '0x' + self.__convertLongToHex( - self.__convertChannelMask(listChannelMask) - ) + self.__convertChannelMask(listChannelMask)) - if ( - sPSKc is not None - or listSecurityPolicy is not None - or xCommissioningSessionId is not None - or xTmfPort is not None - or xSteeringData is not None - or xBorderRouterLocator is not None - or BogusTLV is not None - ): + if (sPSKc is not None or listSecurityPolicy is not None or + xCommissioningSessionId is not None or + xTmfPort is not None or xSteeringData is not None or + xBorderRouterLocator is not None or BogusTLV is not None): cmd += ' binary ' if sPSKc is not None: @@ -2585,9 +2507,8 @@ class OpenThread(IThci): return self.__sendCommand(cmd)[-1] == 'Done' except Exception as e: - ModuleHelper.WriteIntoDebugLogger( - 'MGMT_ACTIVE_SET() Error: ' + str(e) - ) + ModuleHelper.WriteIntoDebugLogger('MGMT_ACTIVE_SET() Error: ' + + str(e)) def MGMT_PENDING_GET(self, Addr='', TLVs=[]): """send MGMT_PENDING_GET command @@ -2614,9 +2535,8 @@ class OpenThread(IThci): return self.__sendCommand(cmd)[-1] == 'Done' except Exception as e: - ModuleHelper.WriteIntoDebugLogger( - 'MGMT_PENDING_GET() Error: ' + str(e) - ) + ModuleHelper.WriteIntoDebugLogger('MGMT_PENDING_GET() Error: ' + + str(e)) def MGMT_PENDING_SET( self, @@ -2691,9 +2611,8 @@ class OpenThread(IThci): return self.__sendCommand(cmd)[-1] == 'Done' except Exception as e: - ModuleHelper.WriteIntoDebugLogger( - 'MGMT_PENDING_SET() Error: ' + str(e) - ) + ModuleHelper.WriteIntoDebugLogger('MGMT_PENDING_SET() Error: ' + + str(e)) def MGMT_COMM_GET(self, Addr='ff02::1', TLVs=[]): """send MGMT_COMM_GET command @@ -2716,9 +2635,8 @@ class OpenThread(IThci): return self.__sendCommand(cmd)[-1] == 'Done' except Exception as e: - ModuleHelper.WriteIntoDebugLogger( - 'MGMT_COMM_GET() Error: ' + str(e) - ) + ModuleHelper.WriteIntoDebugLogger('MGMT_COMM_GET() Error: ' + + str(e)) def MGMT_COMM_SET( self, @@ -2768,9 +2686,8 @@ class OpenThread(IThci): return self.__sendCommand(cmd)[-1] == 'Done' except Exception as e: - ModuleHelper.WriteIntoDebugLogger( - 'MGMT_COMM_SET() Error: ' + str(e) - ) + ModuleHelper.WriteIntoDebugLogger('MGMT_COMM_SET() Error: ' + + str(e)) def setActiveDataset(self, listActiveDataset=[]): print('%s call setActiveDataset' % self.port) @@ -2795,9 +2712,8 @@ class OpenThread(IThci): self.hasActiveDatasetToCommit = True return self.__sendCommand(cmd)[-1] == 'Done' except Exception as e: - ModuleHelper.WriteIntoDebugLogger( - 'setActiveTimestamp() Error: ' + str(e) - ) + ModuleHelper.WriteIntoDebugLogger('setActiveTimestamp() Error: ' + + str(e)) def setUdpJoinerPort(self, portNumber): """set Joiner UDP Port @@ -2826,9 +2742,8 @@ class OpenThread(IThci): print(cmd) return self.__sendCommand(cmd)[-1] == 'Done' - def sendBeacons( - self, sAddr, xCommissionerSessionId, listChannelMask, xPanId - ): + def sendBeacons(self, sAddr, xCommissionerSessionId, listChannelMask, + xPanId): print('%s call sendBeacons' % self.port) self._sendline('scan') return True diff --git a/tools/harness-thci/OpenThread_WpanCtl.py b/tools/harness-thci/OpenThread_WpanCtl.py index 44ac56699..bd81dca4b 100644 --- a/tools/harness-thci/OpenThread_WpanCtl.py +++ b/tools/harness-thci/OpenThread_WpanCtl.py @@ -25,7 +25,6 @@ # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE # POSSIBILITY OF SUCH DAMAGE. - """ >> Thread Host Controller Interface >> Device : OpenThread_WpanCtl THCI @@ -45,7 +44,6 @@ from GRLLibs.UtilityModules.enums import PlatformDiagnosticPacket_Direction, Pla from GRLLibs.UtilityModules.ModuleHelper import ModuleHelper from GRLLibs.ThreadPacket.PlatformPackets import PlatformDiagnosticPacket, PlatformPackets from GRLLibs.UtilityModules.Plugins.AES_CMAC import Thread_PBKDF2 - """regex: used to split lines""" LINESEPX = re.compile(r'\r\n|\n') @@ -71,25 +69,35 @@ class OpenThread_WpanCtl(IThci): self.handle = None self.AutoDUTEnable = False self._is_net = False # whether device is through ser2net - self.logStatus = {'stop': 'stop', 'running': 'running', 'pauseReq': 'pauseReq', 'paused': 'paused'} + self.logStatus = { + 'stop': 'stop', + 'running': 'running', + 'pauseReq': 'pauseReq', + 'paused': 'paused' + } self.logThreadStatus = self.logStatus['stop'] # connection type 'ip' stands for SSH - self.connectType = (kwargs.get('Param5')).strip().lower() if kwargs.get('Param5') is not None else 'usb' + self.connectType = (kwargs.get('Param5')).strip().lower( + ) if kwargs.get('Param5') is not None else 'usb' # comma separated CLI prompt, wpanctl cmd prefix, Wpan interface - (self.prompt, self.wpan_cmd_prefix, self.wpan_interface) = ( - kwargs.get('Param8').strip().split(',') if kwargs.get('Param8') else ['#', 'wpanctl', 'wpan0'] - ) + (self.prompt, self.wpan_cmd_prefix, + self.wpan_interface) = (kwargs.get('Param8').strip().split(',') + if kwargs.get('Param8') else + ['#', 'wpanctl', 'wpan0']) self.wpan_cmd_prefix += ' ' # comma separated setting commands - self.precmd = (kwargs.get('Param9')).strip().split(',') if kwargs.get('Param9') else [] + self.precmd = (kwargs.get('Param9') + ).strip().split(',') if kwargs.get('Param9') else [] if self.connectType == 'ip': self.dutIpv4 = kwargs.get('TelnetIP') self.dutPort = kwargs.get('TelnetPort') self.port = self.dutIpv4 + ':' + self.dutPort # username for SSH - self.username = kwargs.get('Param6').strip() if kwargs.get('Param6') else None + self.username = kwargs.get('Param6').strip() if kwargs.get( + 'Param6') else None # password for SSH - self.password = kwargs.get('Param7').strip() if kwargs.get('Param7') else None + self.password = kwargs.get('Param7').strip() if kwargs.get( + 'Param7') else None else: self.port = kwargs.get('SerialPort') self.intialize() @@ -202,7 +210,8 @@ class OpenThread_WpanCtl(IThci): logging.info('%s: sendCommand[%s]', self.port, cmd) if self.logThreadStatus == self.logStatus['running']: self.logThreadStatus = self.logStatus['pauseReq'] - while self.logThreadStatus not in (self.logStatus['paused'], self.logStatus['stop']): + while self.logThreadStatus not in (self.logStatus['paused'], + self.logStatus['stop']): pass ssh_stdin = None @@ -215,12 +224,14 @@ class OpenThread_WpanCtl(IThci): retry_times -= 1 try: if self._is_net: - ssh_stdin, ssh_stdout, ssh_stderr = self.handle.exec_command(cmd) + ssh_stdin, ssh_stdout, ssh_stderr = self.handle.exec_command( + cmd) else: self._sendline(cmd) self._expect(cmd) except Exception as e: - logging.exception('%s: failed to send command[%s]: %s', self.port, cmd, str(e)) + logging.exception('%s: failed to send command[%s]: %s', + self.port, cmd, str(e)) if retry_times == 0: raise else: @@ -236,20 +247,25 @@ class OpenThread_WpanCtl(IThci): stderr_lines = ssh_stderr.readlines() if stderr_lines: for stderr_line in stderr_lines: - if re.search(r'Not\s+Found|failed\s+with\s+error', stderr_line.strip(), re.M | re.I): + if re.search(r'Not\s+Found|failed\s+with\s+error', + stderr_line.strip(), re.M | re.I): print('Command failed: %s' % stderr_line) return 'Fail' print('Got line: %s' % stderr_line) - logging.info('%s: the read line is[%s]', self.port, stderr_line) + logging.info('%s: the read line is[%s]', self.port, + stderr_line) response.append(str(stderr_line.strip())) elif stdout_lines: for stdout_line in stdout_lines: - logging.info('%s: the read line is[%s]', self.port, stdout_line) - if re.search(r'Not\s+Found|failed\s+with\s+error', stdout_line.strip(), re.M | re.I): + logging.info('%s: the read line is[%s]', self.port, + stdout_line) + if re.search(r'Not\s+Found|failed\s+with\s+error', + stdout_line.strip(), re.M | re.I): print('Command failed') return 'Fail' print('Got line: ' + stdout_line) - logging.info('%s: send command[%s] done!', self.port, cmd) + logging.info('%s: send command[%s] done!', self.port, + cmd) response.append(str(stdout_line.strip())) response.append(self.prompt) return response @@ -262,7 +278,8 @@ class OpenThread_WpanCtl(IThci): response.append(line) if re.match(self.prompt, line): break - elif re.search(r'Not\s+Found|failed\s+with\s+error', line, re.M | re.I): + elif re.search(r'Not\s+Found|failed\s+with\s+error', + line, re.M | re.I): print('Command failed') return 'Fail' @@ -270,7 +287,8 @@ class OpenThread_WpanCtl(IThci): time.sleep(0.1) if retry_times == 0: - raise Exception('%s: failed to find end of response' % self.port) + raise Exception('%s: failed to find end of response' % + self.port) logging.info('%s: send command[%s] done!', self.port, cmd) return response except Exception as e: @@ -287,7 +305,8 @@ class OpenThread_WpanCtl(IThci): value string without special characters """ if isinstance(value, str): - if (value[0] == '"' and value[-1] == '"') or (value[0] == '[' and value[-1] == ']'): + if (value[0] == '"' and value[-1] == '"') or (value[0] == '[' and + value[-1] == ']'): return value[1:-1] return value @@ -301,7 +320,8 @@ class OpenThread_WpanCtl(IThci): segments[i] = '0' * (4 - len(element)) + element if empty is not None: - segments = segments[:empty] + ['0000'] * (8 - len(segments) + 1) + segments[empty + 1 :] + segments = segments[:empty] + ['0000'] * (8 - len(segments) + + 1) + segments[empty + 1:] return ':'.join(segments) @@ -325,7 +345,8 @@ class OpenThread_WpanCtl(IThci): cmd = self.wpan_cmd_prefix + 'setprop Thread:DeviceMode %d' % mode return self.__sendCommand(cmd)[0] != 'Fail' except Exception as e: - ModuleHelper.WriteIntoDebugLogger('setDeviceMode() Error: ' + str(e)) + ModuleHelper.WriteIntoDebugLogger('setDeviceMode() Error: ' + + str(e)) def __setRouterUpgradeThreshold(self, iThreshold): """set router upgrade threshold @@ -340,10 +361,12 @@ class OpenThread_WpanCtl(IThci): """ print('call __setRouterUpgradeThreshold') try: - cmd = self.wpan_cmd_prefix + 'setprop Thread:RouterUpgradeThreshold %s' % str(iThreshold) + cmd = self.wpan_cmd_prefix + 'setprop Thread:RouterUpgradeThreshold %s' % str( + iThreshold) return self.__sendCommand(cmd)[0] != 'Fail' except Exception as e: - ModuleHelper.WriteIntoDebugLogger('setRouterUpgradeThreshold() Error: ' + str(e)) + ModuleHelper.WriteIntoDebugLogger( + 'setRouterUpgradeThreshold() Error: ' + str(e)) def __setRouterDowngradeThreshold(self, iThreshold): """set router downgrade threshold @@ -359,10 +382,12 @@ class OpenThread_WpanCtl(IThci): """ print('call __setRouterDowngradeThreshold') try: - cmd = self.wpan_cmd_prefix + 'setprop Thread:RouterDowngradeThreshold %s' % str(iThreshold) + cmd = self.wpan_cmd_prefix + 'setprop Thread:RouterDowngradeThreshold %s' % str( + iThreshold) return self.__sendCommand(cmd)[0] != 'Fail' except Exception as e: - ModuleHelper.WriteIntoDebugLogger('setRouterDowngradeThreshold() Error: ' + str(e)) + ModuleHelper.WriteIntoDebugLogger( + 'setRouterDowngradeThreshold() Error: ' + str(e)) def __setRouterSelectionJitter(self, iRouterJitter): """set ROUTER_SELECTION_JITTER parameter for REED to upgrade to Router @@ -376,10 +401,12 @@ class OpenThread_WpanCtl(IThci): """ print('call _setRouterSelectionJitter') try: - cmd = self.wpan_cmd_prefix + 'setprop Thread:RouterSelectionJitter %s' % str(iRouterJitter) + cmd = self.wpan_cmd_prefix + 'setprop Thread:RouterSelectionJitter %s' % str( + iRouterJitter) return self.__sendCommand(cmd) != 'Fail' except Exception as e: - ModuleHelper.WriteIntoDebugLogger('setRouterSelectionJitter() Error: ' + str(e)) + ModuleHelper.WriteIntoDebugLogger( + 'setRouterSelectionJitter() Error: ' + str(e)) def __setAddressfilterMode(self, mode): """set address filter mode @@ -401,7 +428,8 @@ class OpenThread_WpanCtl(IThci): return True return False except Exception as e: - ModuleHelper.WriteIntoDebugLogger('__setAddressFilterMode() Error: ' + str(e)) + ModuleHelper.WriteIntoDebugLogger( + '__setAddressFilterMode() Error: ' + str(e)) def __startOpenThreadWpan(self): """start OpenThreadWpan @@ -447,7 +475,10 @@ class OpenThread_WpanCtl(IThci): else: pass - if self.deviceRole in [Thread_Device_Role.Leader, Thread_Device_Role.Router, Thread_Device_Role.REED]: + if self.deviceRole in [ + Thread_Device_Role.Leader, Thread_Device_Role.Router, + Thread_Device_Role.REED + ]: self.__setRouterSelectionJitter(1) if startType == 'form': @@ -469,7 +500,10 @@ class OpenThread_WpanCtl(IThci): if self.__isOpenThreadWpanRunning(): self.isPowerDown = False if self.hasActiveDatasetToCommit: - if self.__sendCommand(self.wpan_cmd_prefix + 'setprop Dataset:Command SetActive')[0] == 'Fail': + if self.__sendCommand( + self.wpan_cmd_prefix + + 'setprop Dataset:Command SetActive' + )[0] == 'Fail': raise Exception('failed to commit active dataset') else: self.hasActiveDatasetToCommit = False @@ -478,7 +512,8 @@ class OpenThread_WpanCtl(IThci): else: return False except Exception as e: - ModuleHelper.WriteIntoDebugLogger('startOpenThreadWpan() Error: ' + str(e)) + ModuleHelper.WriteIntoDebugLogger('startOpenThreadWpan() Error: ' + + str(e)) def __stopOpenThreadWpan(self): """stop OpenThreadWpan @@ -489,15 +524,15 @@ class OpenThread_WpanCtl(IThci): """ print('call stopOpenThreadWpan') try: - if ( - self.__sendCommand(self.wpan_cmd_prefix + 'leave')[0] != 'Fail' - and self.__sendCommand(self.wpan_cmd_prefix + 'dataset erase')[0] != 'Fail' - ): + if (self.__sendCommand(self.wpan_cmd_prefix + 'leave')[0] != 'Fail' + and self.__sendCommand(self.wpan_cmd_prefix + + 'dataset erase')[0] != 'Fail'): return True else: return False except Exception as e: - ModuleHelper.WriteIntoDebugLogger('stopOpenThreadWpan() Error: ' + str(e)) + ModuleHelper.WriteIntoDebugLogger('stopOpenThreadWpan() Error: ' + + str(e)) def __isOpenThreadWpanRunning(self): """check whether or not OpenThreadWpan is running @@ -507,7 +542,9 @@ class OpenThread_WpanCtl(IThci): False: OpenThreadWpan is not running """ print('call __isOpenThreadWpanRunning') - if self.__stripValue(self.__sendCommand(self.wpan_cmd_prefix + 'getprop -v NCP:State')[0]) == 'associated': + if self.__stripValue( + self.__sendCommand(self.wpan_cmd_prefix + + 'getprop -v NCP:State')[0]) == 'associated': print('*****OpenThreadWpan is running') return True else: @@ -526,7 +563,8 @@ class OpenThread_WpanCtl(IThci): actual router id allocated by leader """ routerList = [] - routerList = self.__sendCommand(self.wpan_cmd_prefix + 'getprop -v Thread:RouterTable') + routerList = self.__sendCommand(self.wpan_cmd_prefix + + 'getprop -v Thread:RouterTable') print(routerList) print(xRloc16) @@ -574,7 +612,9 @@ class OpenThread_WpanCtl(IThci): prefix2 = self.__lstrip0x(prefix1) hexPrefix = str(prefix2).ljust(16, '0') hexIter = iter(hexPrefix) - finalMac = ':'.join(a + b + c + d for a, b, c, d in zip(hexIter, hexIter, hexIter, hexIter)) + finalMac = ':'.join( + a + b + c + d + for a, b, c, d in zip(hexIter, hexIter, hexIter, hexIter)) prefix = str(finalMac) strIp6Prefix = prefix[:19] return strIp6Prefix + '::' @@ -639,23 +679,28 @@ class OpenThread_WpanCtl(IThci): cmd = self.wpan_cmd_prefix + 'setprop NCP:ChannelMask %s' % channelMask datasetCmd = self.wpan_cmd_prefix + 'setprop Dataset:ChannelMaskPage0 %s' % channelMask self.hasActiveDatasetToCommit = True - return self.__sendCommand(cmd)[0] != 'Fail' and self.__sendCommand(datasetCmd)[0] != 'Fail' + return self.__sendCommand(cmd)[0] != 'Fail' and self.__sendCommand( + datasetCmd)[0] != 'Fail' except Exception as e: - ModuleHelper.WriteIntoDebugLogger('setChannelMask() Error: ' + str(e)) + ModuleHelper.WriteIntoDebugLogger('setChannelMask() Error: ' + + str(e)) def __setSecurityPolicy(self, securityPolicySecs, securityPolicyFlags): print('call _setSecurityPolicy') try: - cmd1 = self.wpan_cmd_prefix + 'setprop Dataset:SecPolicy:KeyRotation %s' % str(securityPolicySecs) + cmd1 = self.wpan_cmd_prefix + 'setprop Dataset:SecPolicy:KeyRotation %s' % str( + securityPolicySecs) if securityPolicyFlags == 'onrcb': cmd2 = self.wpan_cmd_prefix + 'setprop Dataset:SecPolicy:Flags 0xff' else: print('unknown policy flag :' + securityPolicyFlags) return False self.hasActiveDatasetToCommit = True - return self.__sendCommand(cmd1) != 'Fail' and self.__sendCommand(cmd2) != 'Fail' + return self.__sendCommand(cmd1) != 'Fail' and self.__sendCommand( + cmd2) != 'Fail' except Exception as e: - ModuleHelper.WriteIntoDebugLogger('setSecurityPolicy() Error: ' + str(e)) + ModuleHelper.WriteIntoDebugLogger('setSecurityPolicy() Error: ' + + str(e)) def __setKeySwitchGuardTime(self, iKeySwitchGuardTime): """ set the Key switch guard time @@ -670,26 +715,31 @@ class OpenThread_WpanCtl(IThci): print('%s call setKeySwitchGuardTime' % self.port) print(iKeySwitchGuardTime) try: - cmd = self.wpan_cmd_prefix + 'setprop Network:KeySwitchGuardTime %s' % str(iKeySwitchGuardTime) + cmd = self.wpan_cmd_prefix + 'setprop Network:KeySwitchGuardTime %s' % str( + iKeySwitchGuardTime) if self.__sendCommand(cmd)[0] != 'Fail': time.sleep(1) return True else: return False except Exception as e: - ModuleHelper.WriteIntoDebugLogger('setKeySwitchGuardTime() Error; ' + str(e)) + ModuleHelper.WriteIntoDebugLogger( + 'setKeySwitchGuardTime() Error; ' + str(e)) def __getCommissionerSessionId(self): """ get the commissioner session id allocated from Leader """ print('%s call getCommissionerSessionId' % self.port) - return self.__sendCommand(self.wpan_cmd_prefix + 'getprop -v Commissioner:SessionId')[0] + return self.__sendCommand(self.wpan_cmd_prefix + + 'getprop -v Commissioner:SessionId')[0] def __getJoinerState(self): """ get joiner state """ maxDuration = 150 # seconds t_end = time.time() + maxDuration while time.time() < t_end: - joinerState = self.__stripValue(self.__sendCommand(self.wpan_cmd_prefix + 'getprop -v NCP:State')[0]) + joinerState = self.__stripValue( + self.__sendCommand(self.wpan_cmd_prefix + + 'getprop -v NCP:State')[0]) if joinerState == 'offline:commissioned': return True elif joinerState == 'associating:credentials-needed': @@ -750,7 +800,8 @@ class OpenThread_WpanCtl(IThci): else: self._is_net = False except Exception as e: - ModuleHelper.WriteIntoDebugLogger('connect to serial Error: ' + str(e)) + ModuleHelper.WriteIntoDebugLogger('connect to serial Error: ' + + str(e)) elif self.connectType == 'ip': print('My IP: %s Port: %s' % (self.dutIpv4, self.dutPort)) @@ -758,18 +809,22 @@ class OpenThread_WpanCtl(IThci): import paramiko if not self.password: - transport = paramiko.Transport((self.dutIpv4, int(self.dutPort))) + transport = paramiko.Transport( + (self.dutIpv4, int(self.dutPort))) transport.start_client() transport.auth_none(self.username) self.handle = paramiko.SSHClient() - self.handle.set_missing_host_key_policy(paramiko.AutoAddPolicy()) + self.handle.set_missing_host_key_policy( + paramiko.AutoAddPolicy()) self.handle._transport = transport else: self.handle = paramiko.SSHClient() - self.handle.set_missing_host_key_policy(paramiko.AutoAddPolicy()) - self.handle.connect( - self.dutIpv4, port=int(self.dutPort), username=self.username, password=self.password - ) + self.handle.set_missing_host_key_policy( + paramiko.AutoAddPolicy()) + self.handle.connect(self.dutIpv4, + port=int(self.dutPort), + username=self.username, + password=self.password) print('login success (ssh)') self.deviceConnected = True for precmd in self.precmd: @@ -778,7 +833,8 @@ class OpenThread_WpanCtl(IThci): self._is_net = True except Exception as e: - ModuleHelper.WriteIntoDebugLogger('connect to ssh Error: ' + str(e)) + ModuleHelper.WriteIntoDebugLogger('connect to ssh Error: ' + + str(e)) else: raise Exception('Unknown port schema') @@ -790,7 +846,8 @@ class OpenThread_WpanCtl(IThci): self.handle.close() self.handle = None except Exception as e: - ModuleHelper.WriteIntoDebugLogger('closeConnection() Error: ' + str(e)) + ModuleHelper.WriteIntoDebugLogger('closeConnection() Error: ' + + str(e)) def intialize(self): """initialize the serial port with baudrate, timeout parameters""" @@ -804,10 +861,11 @@ class OpenThread_WpanCtl(IThci): self.UIStatusMsg = self.getVersionNumber() if self.firmwarePrefix not in self.UIStatusMsg: self.deviceConnected = False - self.UIStatusMsg = ( - 'Firmware Not Matching Expecting ' + self.firmwarePrefix + ' Now is ' + self.UIStatusMsg - ) - raise Exception('Err: OpenThread device Firmware not matching..') + self.UIStatusMsg = ('Firmware Not Matching Expecting ' + + self.firmwarePrefix + ' Now is ' + + self.UIStatusMsg) + raise Exception( + 'Err: OpenThread device Firmware not matching..') self.__sendCommand(self.wpan_cmd_prefix + 'leave') self.__sendCommand(self.wpan_cmd_prefix + 'dataset erase') else: @@ -832,9 +890,11 @@ class OpenThread_WpanCtl(IThci): cmd = self.wpan_cmd_prefix + 'setprop -s Network:Name %s' % networkName datasetCmd = self.wpan_cmd_prefix + 'setprop Dataset:NetworkName %s' % networkName self.hasActiveDatasetToCommit = True - return self.__sendCommand(cmd)[0] != 'Fail' and self.__sendCommand(datasetCmd)[0] != 'Fail' + return self.__sendCommand(cmd)[0] != 'Fail' and self.__sendCommand( + datasetCmd)[0] != 'Fail' except Exception as e: - ModuleHelper.WriteIntoDebugLogger('setNetworkName() Error: ' + str(e)) + ModuleHelper.WriteIntoDebugLogger('setNetworkName() Error: ' + + str(e)) def setChannel(self, channel=15): """set channel of Thread device operates on. @@ -855,14 +915,16 @@ class OpenThread_WpanCtl(IThci): cmd = self.wpan_cmd_prefix + 'setprop NCP:Channel %s' % channel datasetCmd = self.wpan_cmd_prefix + 'setprop Dataset:Channel %s' % channel self.hasActiveDatasetToCommit = True - return self.__sendCommand(cmd)[0] != 'Fail' and self.__sendCommand(datasetCmd)[0] != 'Fail' + return self.__sendCommand(cmd)[0] != 'Fail' and self.__sendCommand( + datasetCmd)[0] != 'Fail' except Exception as e: ModuleHelper.WriteIntoDebugLogger('setChannel() Error: ' + str(e)) def getChannel(self): """get current channel""" print('%s call getChannel' % self.port) - return self.__sendCommand(self.wpan_cmd_prefix + 'getprop -v NCP:Channel')[0] + return self.__sendCommand(self.wpan_cmd_prefix + + 'getprop -v NCP:Channel')[0] def setMAC(self, xEUI): """set the extended addresss of Thread device @@ -914,41 +976,50 @@ class OpenThread_WpanCtl(IThci): else: if bType == MacType.FactoryMac: macAddr64 = self.__stripValue( - self.__sendCommand(self.wpan_cmd_prefix + 'getprop -v NCP:HardwareAddress')[0] - ) + self.__sendCommand(self.wpan_cmd_prefix + + 'getprop -v NCP:HardwareAddress')[0]) elif bType == MacType.HashMac: macAddr64 = self.__stripValue( - self.__sendCommand(self.wpan_cmd_prefix + 'getprop -v NCP:MACAddress')[0] - ) + self.__sendCommand(self.wpan_cmd_prefix + + 'getprop -v NCP:MACAddress')[0]) else: macAddr64 = self.__stripValue( - self.__sendCommand(self.wpan_cmd_prefix + 'getprop -v NCP:ExtendedAddress')[0] - ) + self.__sendCommand(self.wpan_cmd_prefix + + 'getprop -v NCP:ExtendedAddress')[0]) return int(macAddr64, 16) def getLL64(self): """get link local unicast IPv6 address""" print('%s call getLL64' % self.port) - return self.__stripValue(self.__sendCommand(self.wpan_cmd_prefix + 'getprop -v IPv6:LinkLocalAddress')[0]) + return self.__stripValue( + self.__sendCommand(self.wpan_cmd_prefix + + 'getprop -v IPv6:LinkLocalAddress')[0]) def getMLEID(self): """get mesh local endpoint identifier address""" print('%s call getMLEID' % self.port) - return self.__stripValue(self.__sendCommand(self.wpan_cmd_prefix + 'getprop -v IPv6:MeshLocalAddress')[0]) + return self.__stripValue( + self.__sendCommand(self.wpan_cmd_prefix + + 'getprop -v IPv6:MeshLocalAddress')[0]) def getRloc16(self): """get rloc16 short address""" print('%s call getRloc16' % self.port) - rloc16 = self.__sendCommand(self.wpan_cmd_prefix + 'getprop -v Thread:RLOC16')[0] + rloc16 = self.__sendCommand(self.wpan_cmd_prefix + + 'getprop -v Thread:RLOC16')[0] return int(rloc16, 16) def getRloc(self): """get router locator unicast IPv6 address""" print('%s call getRloc' % self.port) - prefix = self.__stripValue(self.__sendCommand(self.wpan_cmd_prefix + 'getprop -v IPv6:MeshLocalPrefix')[0]) + prefix = self.__stripValue( + self.__sendCommand(self.wpan_cmd_prefix + + 'getprop -v IPv6:MeshLocalPrefix')[0]) mlprefix = prefix.split('/')[0] - rloc16 = self.__lstrip0x(self.__sendCommand(self.wpan_cmd_prefix + 'getprop -v Thread:RLOC16')[0]) + rloc16 = self.__lstrip0x( + self.__sendCommand(self.wpan_cmd_prefix + + 'getprop -v Thread:RLOC16')[0]) print('prefix: %s' % prefix) print('mlprefix: %s ' % mlprefix) @@ -965,11 +1036,14 @@ class OpenThread_WpanCtl(IThci): print('%s call getGlobal' % self.port) globalAddrs = [] - mleid = self.__stripValue(self.__sendCommand(self.wpan_cmd_prefix + 'getprop -v IPv6:MeshLocalAddress')[0]) + mleid = self.__stripValue( + self.__sendCommand(self.wpan_cmd_prefix + + 'getprop -v IPv6:MeshLocalAddress')[0]) mleid = ModuleHelper.GetFullIpv6Address(mleid).lower() - addrs = self.__sendCommand(self.wpan_cmd_prefix + 'getprop -v IPv6:AllAddresses') + addrs = self.__sendCommand(self.wpan_cmd_prefix + + 'getprop -v IPv6:AllAddresses') # find rloc address firstly as a reference for current mesh local prefix as for some TCs, # mesh local prefix may be updated through pending dataset management. @@ -1021,9 +1095,11 @@ class OpenThread_WpanCtl(IThci): self.networkKey = masterKey self.hasActiveDatasetToCommit = True - return self.__sendCommand(cmd)[0] != 'Fail' and self.__sendCommand(datasetCmd)[0] != 'Fail' + return self.__sendCommand(cmd)[0] != 'Fail' and self.__sendCommand( + datasetCmd)[0] != 'Fail' except Exception as e: - ModuleHelper.WriteIntoDebugLogger('setNetworkkey() Error: ' + str(e)) + ModuleHelper.WriteIntoDebugLogger('setNetworkkey() Error: ' + + str(e)) def addBlockedMAC(self, xEUI): """add a given extended address to the blacklist entry @@ -1062,7 +1138,8 @@ class OpenThread_WpanCtl(IThci): return ret except Exception as e: - ModuleHelper.WriteIntoDebugLogger('addBlockedMAC() Error: ' + str(e)) + ModuleHelper.WriteIntoDebugLogger('addBlockedMAC() Error: ' + + str(e)) def addAllowMAC(self, xEUI): """add a given extended address to the whitelist addressfilter @@ -1123,7 +1200,8 @@ class OpenThread_WpanCtl(IThci): return True return False except Exception as e: - ModuleHelper.WriteIntoDebugLogger('clearBlockList() Error: ' + str(e)) + ModuleHelper.WriteIntoDebugLogger('clearBlockList() Error: ' + + str(e)) def clearAllowList(self): """clear all entries in whitelist table @@ -1150,12 +1228,15 @@ class OpenThread_WpanCtl(IThci): return True return False except Exception as e: - ModuleHelper.WriteIntoDebugLogger('clearAllowList() Error: ' + str(e)) + ModuleHelper.WriteIntoDebugLogger('clearAllowList() Error: ' + + str(e)) def getDeviceRole(self): """get current device role in Thread Network""" print('%s call getDeviceRole' % self.port) - return self.__stripValue(self.__sendCommand(self.wpan_cmd_prefix + 'getprop -v Network:NodeType')[0]) + return self.__stripValue( + self.__sendCommand(self.wpan_cmd_prefix + + 'getprop -v Network:NodeType')[0]) def joinNetwork(self, eRoleId): """make device ready to join the Thread Network with a given role @@ -1241,7 +1322,8 @@ class OpenThread_WpanCtl(IThci): print('OpenThreadWpan is not running') return None - return self.__sendCommand(self.wpan_cmd_prefix + 'getprop -v Network:PartitionId')[0] + return self.__sendCommand(self.wpan_cmd_prefix + + 'getprop -v Network:PartitionId')[0] def getParentAddress(self): """get Thread device's parent extended address and rloc16 short address @@ -1251,16 +1333,18 @@ class OpenThread_WpanCtl(IThci): """ print('%s call getParentAddress' % self.port) parentInfo = [] - parentInfo = self.__stripValue(self.__sendCommand(self.wpan_cmd_prefix + 'getprop -v Thread:Parent')).split( - ' ' - ) + parentInfo = self.__stripValue( + self.__sendCommand(self.wpan_cmd_prefix + + 'getprop -v Thread:Parent')).split(' ') return parentInfo[0] def powerDown(self): """power down the OpenThreadWpan""" print('%s call powerDown' % self.port) - if self.__sendCommand(self.wpan_cmd_prefix + 'setprop Daemon:AutoAssociateAfterReset false')[0] != 'Fail': + if self.__sendCommand( + self.wpan_cmd_prefix + + 'setprop Daemon:AutoAssociateAfterReset false')[0] != 'Fail': time.sleep(0.5) if self.__sendCommand(self.wpan_cmd_prefix + 'reset')[0] != 'Fail': self.isPowerDown = True @@ -1282,10 +1366,14 @@ class OpenThread_WpanCtl(IThci): else: return False - if self.__sendCommand(self.wpan_cmd_prefix + 'setprop Daemon:AutoAssociateAfterReset true')[0] == 'Fail': + if self.__sendCommand( + self.wpan_cmd_prefix + + 'setprop Daemon:AutoAssociateAfterReset true')[0] == 'Fail': return False - if self.__stripValue(self.__sendCommand(self.wpan_cmd_prefix + 'getprop -v NCP:State')[0]) != 'associated': + if self.__stripValue( + self.__sendCommand(self.wpan_cmd_prefix + + 'getprop -v NCP:State')[0]) != 'associated': print('powerUp failed') return False else: @@ -1303,7 +1391,8 @@ class OpenThread_WpanCtl(IThci): self._sendline(self.wpan_cmd_prefix + 'reset') self.isPowerDown = True - if self.__sendCommand(self.wpan_cmd_prefix + 'getprop -v NCP:State')[0] != 'associated': + if self.__sendCommand(self.wpan_cmd_prefix + + 'getprop -v NCP:State')[0] != 'associated': print('[FAIL] reboot') return False else: @@ -1322,9 +1411,11 @@ class OpenThread_WpanCtl(IThci): print('%s call ping' % self.port) print('destination: %s' % destination) try: - cmd = 'ping %s -c 1 -s %s -I %s' % (destination, str(length), self.wpan_interface) + cmd = 'ping %s -c 1 -s %s -I %s' % (destination, str(length), + self.wpan_interface) if self._is_net: - ssh_stdin, ssh_stdout, ssh_stderr = self.handle.exec_command(cmd) + ssh_stdin, ssh_stdout, ssh_stderr = self.handle.exec_command( + cmd) else: self._sendline(cmd) self._expect(cmd) @@ -1344,21 +1435,25 @@ class OpenThread_WpanCtl(IThci): print('%s call multicast_Ping' % self.port) print('destination: %s' % destination) try: - cmd = 'ping %s -c 1 -s %s -I %s' % (destination, str(length), self.wpan_interface) + cmd = 'ping %s -c 1 -s %s -I %s' % (destination, str(length), + self.wpan_interface) if self._is_net: - ssh_stdin, ssh_stdout, ssh_stderr = self.handle.exec_command(cmd) + ssh_stdin, ssh_stdout, ssh_stderr = self.handle.exec_command( + cmd) else: self._sendline(cmd) self._expect(cmd) # wait echo reply time.sleep(1) except Exception as e: - ModuleHelper.WriteIntoDebugLogger('multicast_ping() Error: ' + str(e)) + ModuleHelper.WriteIntoDebugLogger('multicast_ping() Error: ' + + str(e)) def getVersionNumber(self): """get OpenThreadWpan stack firmware version number""" print('%s call getVersionNumber' % self.port) - versionStr = self.__sendCommand(self.wpan_cmd_prefix + 'getprop -v NCP:Version')[0] + versionStr = self.__sendCommand(self.wpan_cmd_prefix + + 'getprop -v NCP:Version')[0] return self.__stripValue(versionStr) @@ -1383,7 +1478,8 @@ class OpenThread_WpanCtl(IThci): cmd = self.wpan_cmd_prefix + 'setprop -s Network:PANID %s' % panid datasetCmd = self.wpan_cmd_prefix + 'setprop Dataset:PanId %s' % panid self.hasActiveDatasetToCommit = True - return self.__sendCommand(cmd)[0] != 'Fail' and self.__sendCommand(datasetCmd)[0] != 'Fail' + return self.__sendCommand(cmd)[0] != 'Fail' and self.__sendCommand( + datasetCmd)[0] != 'Fail' except Exception as e: ModuleHelper.WriteIntoDebugLogger('setPANID() Error: ' + str(e)) @@ -1468,7 +1564,8 @@ class OpenThread_WpanCtl(IThci): try: self.setMAC(self.mac) self.__setChannelMask(self.channelMask) - self.__setSecurityPolicy(self.securityPolicySecs, self.securityPolicyFlags) + self.__setSecurityPolicy(self.securityPolicySecs, + self.securityPolicyFlags) self.setChannel(self.channel) self.setPANID(self.panId) self.setXpanId(self.xpanId) @@ -1478,7 +1575,8 @@ class OpenThread_WpanCtl(IThci): self.setPSKc(self.pskc) self.setActiveTimestamp(self.activetimestamp) except Exception as e: - ModuleHelper.WriteIntoDebugLogger('setDefaultValue() Error: ' + str(e)) + ModuleHelper.WriteIntoDebugLogger('setDefaultValue() Error: ' + + str(e)) def getDeviceConncetionStatus(self): """check if serial port connection is ready or not""" @@ -1520,11 +1618,13 @@ class OpenThread_WpanCtl(IThci): False: fail to set the data poll period for sleepy end device """ try: - cmd = self.wpan_cmd_prefix + 'setprop NCP:SleepyPollInterval %s' % str(iPollPeriod) + cmd = self.wpan_cmd_prefix + 'setprop NCP:SleepyPollInterval %s' % str( + iPollPeriod) print(cmd) return self.__sendCommand(cmd)[0] != 'Fail' except Exception as e: - ModuleHelper.WriteIntoDebugLogger('__setPollingRate() Error: ' + str(e)) + ModuleHelper.WriteIntoDebugLogger('__setPollingRate() Error: ' + + str(e)) def setLinkQuality(self, EUIadr, LinkQuality): """set custom LinkQualityIn for all receiving messages from the specified EUIadr @@ -1589,9 +1689,12 @@ class OpenThread_WpanCtl(IThci): print('%s call resetAndRejoin' % self.port) print(timeout) try: - if self.__sendCommand(self.wpan_cmd_prefix + 'setprop Daemon:AutoAssociateAfterReset false')[0] != 'Fail': + if self.__sendCommand(self.wpan_cmd_prefix + + 'setprop Daemon:AutoAssociateAfterReset false' + )[0] != 'Fail': time.sleep(0.5) - if self.__sendCommand(self.wpan_cmd_prefix + 'reset')[0] != 'Fail': + if self.__sendCommand(self.wpan_cmd_prefix + + 'reset')[0] != 'Fail': self.isPowerDown = True else: return False @@ -1607,19 +1710,31 @@ class OpenThread_WpanCtl(IThci): else: return False - if self.__sendCommand(self.wpan_cmd_prefix + 'setprop Daemon:AutoAssociateAfterReset true')[0] == 'Fail': + if self.__sendCommand( + self.wpan_cmd_prefix + + 'setprop Daemon:AutoAssociateAfterReset true')[0] == 'Fail': return False - if self.__stripValue(self.__sendCommand(self.wpan_cmd_prefix + 'getprop -v NCP:State')[0]) != 'associated': + if self.__stripValue( + self.__sendCommand(self.wpan_cmd_prefix + + 'getprop -v NCP:State') + [0]) != 'associated': print('[FAIL] reset and rejoin') return False return True except Exception as e: - ModuleHelper.WriteIntoDebugLogger('resetAndRejoin() Error: ' + str(e)) + ModuleHelper.WriteIntoDebugLogger('resetAndRejoin() Error: ' + + str(e)) - def configBorderRouter( - self, P_Prefix, P_stable=1, P_default=1, P_slaac_preferred=0, P_Dhcp=0, P_preference=0, P_on_mesh=1, P_nd_dns=0 - ): + def configBorderRouter(self, + P_Prefix, + P_stable=1, + P_default=1, + P_slaac_preferred=0, + P_Dhcp=0, + P_preference=0, + P_on_mesh=1, + P_nd_dns=0): """configure the border router with a given prefix entry parameters Args: @@ -1657,7 +1772,8 @@ class OpenThread_WpanCtl(IThci): if P_on_mesh == 1: parameter += ' -o' - cmd = self.wpan_cmd_prefix + 'add-prefix %s %s -P %d' % (prefix, parameter, P_preference) + cmd = self.wpan_cmd_prefix + 'add-prefix %s %s -P %d' % ( + prefix, parameter, P_preference) print(parameter) print(cmd) if self.__sendCommand(cmd)[0] != 'Fail': @@ -1665,7 +1781,8 @@ class OpenThread_WpanCtl(IThci): else: return False except Exception as e: - ModuleHelper.WriteIntoDebugLogger('configBorderRouter() Error: ' + str(e)) + ModuleHelper.WriteIntoDebugLogger('configBorderRouter() Error: ' + + str(e)) def setNetworkIDTimeout(self, iNwkIDTimeOut): """set networkid timeout for OpenThreadWpan @@ -1694,11 +1811,13 @@ class OpenThread_WpanCtl(IThci): print('%s call setKeepAliveTimeOut' % self.port) print(iTimeOut) try: - cmd = self.wpan_cmd_prefix + 'setprop NCP:SleepyPollInterval %s' % str(iTimeOut * 1000) + cmd = self.wpan_cmd_prefix + 'setprop NCP:SleepyPollInterval %s' % str( + iTimeOut * 1000) print(cmd) return self.__sendCommand(cmd)[0] != 'Fail' except Exception as e: - ModuleHelper.WriteIntoDebugLogger('setKeepAliveTimeOut() Error: ' + str(e)) + ModuleHelper.WriteIntoDebugLogger('setKeepAliveTimeOut() Error: ' + + str(e)) def setKeySequenceCounter(self, iKeySequenceValue): """ set the Key sequence counter corresponding to Thread Network master key @@ -1716,20 +1835,23 @@ class OpenThread_WpanCtl(IThci): # avoid key switch guard timer protection for reference device self.__setKeySwitchGuardTime(0) - cmd = self.wpan_cmd_prefix + 'setprop Network:KeyIndex %s' % str(iKeySequenceValue) + cmd = self.wpan_cmd_prefix + 'setprop Network:KeyIndex %s' % str( + iKeySequenceValue) if self.__sendCommand(cmd)[0] != 'Fail': time.sleep(1) return True else: return False except Exception as e: - ModuleHelper.WriteIntoDebugLogger('setKeySequenceCounter() Error: ' + str(e)) + ModuleHelper.WriteIntoDebugLogger( + 'setKeySequenceCounter() Error: ' + str(e)) def getKeySequenceCounter(self): """get current Thread Network key sequence""" print('%s call getKeySequenceCounter' % self.port) keySequence = '' - keySequence = self.__sendCommand(self.wpan_cmd_prefix + 'getprop -v Network:KeyIndex')[0] + keySequence = self.__sendCommand(self.wpan_cmd_prefix + + 'getprop -v Network:KeyIndex')[0] return keySequence def incrementKeySequenceCounter(self, iIncrementValue=1): @@ -1754,7 +1876,8 @@ class OpenThread_WpanCtl(IThci): print(keySequence) return self.setKeySequenceCounter(keySequence) except Exception as e: - ModuleHelper.WriteIntoDebugLogger('incrementKeySequenceCounter() Error: ' + str(e)) + ModuleHelper.WriteIntoDebugLogger( + 'incrementKeySequenceCounter() Error: ' + str(e)) def setNetworkDataRequirement(self, eDataRequirement): """set whether the Thread device requires the full network data @@ -1793,9 +1916,11 @@ class OpenThread_WpanCtl(IThci): prefix = self.__convertIp6PrefixStringToIp6Address(str(P_Prefix)) try: if P_stable: - cmd = self.wpan_cmd_prefix + 'add-route %s -l 64 -p %d' % (prefix, R_Preference) + cmd = self.wpan_cmd_prefix + 'add-route %s -l 64 -p %d' % ( + prefix, R_Preference) else: - cmd = self.wpan_cmd_prefix + 'add-route %s -l 64 -p %d -n' % (prefix, R_Preference) + cmd = self.wpan_cmd_prefix + 'add-route %s -l 64 -p %d -n' % ( + prefix, R_Preference) print(cmd) if self.__sendCommand(cmd)[0] != 'Fail': @@ -1803,7 +1928,8 @@ class OpenThread_WpanCtl(IThci): else: return False except Exception as e: - ModuleHelper.WriteIntoDebugLogger('configExternalRouter() Error: ' + str(e)) + ModuleHelper.WriteIntoDebugLogger('configExternalRouter() Error: ' + + str(e)) def getNeighbouringRouters(self): """get neighboring routers information @@ -1849,7 +1975,8 @@ class OpenThread_WpanCtl(IThci): self.xpanId = xpanid self.hasActiveDatasetToCommit = True - return self.__sendCommand(cmd)[0] != 'Fail' and self.__sendCommand(datasetCmd)[0] != 'Fail' + return self.__sendCommand(cmd)[0] != 'Fail' and self.__sendCommand( + datasetCmd)[0] != 'Fail' except Exception as e: ModuleHelper.WriteIntoDebugLogger('setXpanId() Error: ' + str(e)) @@ -1897,7 +2024,8 @@ class OpenThread_WpanCtl(IThci): print('%s call setPartationId' % self.port) print(partationId) - cmd = self.wpan_cmd_prefix + 'setprop Network:PartitionId %s' % (str(hex(partationId)).rstrip('L')) + cmd = self.wpan_cmd_prefix + 'setprop Network:PartitionId %s' % (str( + hex(partationId)).rstrip('L')) print(cmd) return self.__sendCommand(cmd)[0] != 'Fail' @@ -1950,7 +2078,8 @@ class OpenThread_WpanCtl(IThci): cmd = self.wpan_cmd_prefix + 'setprop IPv6:MeshLocalPrefix %s' % sMeshLocalPrefix datasetCmd = self.wpan_cmd_prefix + 'setprop Dataset:MeshLocalPrefix %s' % sMeshLocalPrefix self.hasActiveDatasetToCommit = True - return self.__sendCommand(cmd)[0] != 'Fail' and self.__sendCommand(datasetCmd)[0] != 'Fail' + return self.__sendCommand(cmd)[0] != 'Fail' and self.__sendCommand( + datasetCmd)[0] != 'Fail' except Exception as e: ModuleHelper.WriteIntoDebugLogger('setMLPrefix() Error: ' + str(e)) @@ -1979,7 +2108,8 @@ class OpenThread_WpanCtl(IThci): def getChildTimeoutValue(self): """get child timeout""" print('%s call getChildTimeoutValue' % self.port) - childTimeout = self.__sendCommand(self.wpan_cmd_prefix + 'getprop -v Thread:ChildTimeout')[0] + childTimeout = self.__sendCommand(self.wpan_cmd_prefix + + 'getprop -v Thread:ChildTimeout')[0] return int(childTimeout) def diagnosticGet(self, strDestinationAddr, listTLV_ids=[]): @@ -2012,7 +2142,8 @@ class OpenThread_WpanCtl(IThci): False: fail to start Commissioner """ print('%s call startCollapsedCommissioner' % self.port) - startCmd = self.wpan_cmd_prefix + 'form %s -c %s -T router' % (self.networkName, str(self.channel)) + startCmd = self.wpan_cmd_prefix + 'form %s -c %s -T router' % ( + self.networkName, str(self.channel)) if self.__sendCommand(startCmd) != 'Fail': time.sleep(2) cmd = self.wpan_cmd_prefix + 'commissioner start' @@ -2046,7 +2177,8 @@ class OpenThread_WpanCtl(IThci): # long timeout value to avoid automatic joiner removal (in seconds) timeout = 500 - cmd = self.wpan_cmd_prefix + 'commissioner joiner-add %s %s %s' % (eui64, str(timeout), strPSKd) + cmd = self.wpan_cmd_prefix + 'commissioner joiner-add %s %s %s' % ( + eui64, str(timeout), strPSKd) print(cmd) if not self.isActiveCommissioner: self.startCollapsedCommissioner() @@ -2068,7 +2200,8 @@ class OpenThread_WpanCtl(IThci): print('%s call setProvisioningUrl' % self.port) self.provisioningUrl = strURL if self.deviceRole == Thread_Device_Role.Commissioner: - cmd = self.wpan_cmd_prefix + 'setprop Commissioner:ProvisioningUrl %s' % (strURL) + cmd = self.wpan_cmd_prefix + 'setprop Commissioner:ProvisioningUrl %s' % ( + strURL) print(cmd) return self.__sendCommand(cmd)[0] != 'Fail' return True @@ -2088,12 +2221,14 @@ class OpenThread_WpanCtl(IThci): return True if self.__sendCommand(cmd)[0] != 'Fail': self.isActiveCommissioner = True - time.sleep(40) # time for petition process and at least one keep alive + time.sleep( + 40) # time for petition process and at least one keep alive return True else: return False except Exception as e: - ModuleHelper.WriteIntoDebugLogger('allowcommission() error: ' + str(e)) + ModuleHelper.WriteIntoDebugLogger('allowcommission() error: ' + + str(e)) def joinCommissioned(self, strPSKd='threadjpaketest', waitTime=20): """start joiner @@ -2106,7 +2241,8 @@ class OpenThread_WpanCtl(IThci): False: fail to start joiner """ print('%s call joinCommissioned' % self.port) - cmd = self.wpan_cmd_prefix + 'joiner --start %s %s' % (strPSKd, self.provisioningUrl) + cmd = self.wpan_cmd_prefix + 'joiner --start %s %s' % ( + strPSKd, self.provisioningUrl) print(cmd) if self.__sendCommand(cmd)[0] != 'Fail': if self.__getJoinerState(): @@ -2143,27 +2279,26 @@ class OpenThread_WpanCtl(IThci): if 'direction' in infoType: EncryptedPacket.Direction = ( PlatformDiagnosticPacket_Direction.IN - if 'recv' in infoValue - else PlatformDiagnosticPacket_Direction.OUT - if 'send' in infoValue - else PlatformDiagnosticPacket_Direction.UNKNOWN - ) + if 'recv' in infoValue else + PlatformDiagnosticPacket_Direction.OUT + if 'send' in infoValue else + PlatformDiagnosticPacket_Direction.UNKNOWN) elif 'type' in infoType: EncryptedPacket.Type = ( PlatformDiagnosticPacket_Type.JOIN_FIN_req - if 'JOIN_FIN.req' in infoValue - else PlatformDiagnosticPacket_Type.JOIN_FIN_rsp - if 'JOIN_FIN.rsp' in infoValue - else PlatformDiagnosticPacket_Type.JOIN_ENT_req - if 'JOIN_ENT.ntf' in infoValue - else PlatformDiagnosticPacket_Type.JOIN_ENT_rsp - if 'JOIN_ENT.rsp' in infoValue - else PlatformDiagnosticPacket_Type.UNKNOWN - ) + if 'JOIN_FIN.req' in infoValue else + PlatformDiagnosticPacket_Type.JOIN_FIN_rsp + if 'JOIN_FIN.rsp' in infoValue else + PlatformDiagnosticPacket_Type.JOIN_ENT_req + if 'JOIN_ENT.ntf' in infoValue else + PlatformDiagnosticPacket_Type. + JOIN_ENT_rsp if 'JOIN_ENT.rsp' in + infoValue else PlatformDiagnosticPacket_Type.UNKNOWN) elif 'len' in infoType: bytesInEachLine = 16 EncryptedPacket.TLVsLength = int(infoValue) - payloadLineCount = (int(infoValue) + bytesInEachLine - 1) / bytesInEachLine + payloadLineCount = (int(infoValue) + bytesInEachLine - + 1) / bytesInEachLine while payloadLineCount > 0: payloadLineCount = payloadLineCount - 1 payloadLine = rawLogs.get() @@ -2175,12 +2310,14 @@ class OpenThread_WpanCtl(IThci): if '..' not in payloadValues[num]: payload.append(int(payloadValues[num], 16)) - EncryptedPacket.TLVs = PlatformPackets.read(EncryptedPacket.Type, payload) if payload != [] else [] + EncryptedPacket.TLVs = PlatformPackets.read( + EncryptedPacket.Type, payload) if payload != [] else [] ProcessedLogs.append(EncryptedPacket) return ProcessedLogs - def MGMT_ED_SCAN(self, sAddr, xCommissionerSessionId, listChannelMask, xCount, xPeriod, xScanDuration): + def MGMT_ED_SCAN(self, sAddr, xCommissionerSessionId, listChannelMask, + xCount, xPeriod, xScanDuration): """send MGMT_ED_SCAN message to a given destinaition. Args: @@ -2211,7 +2348,8 @@ class OpenThread_WpanCtl(IThci): except Exception as e: ModuleHelper.WriteIntoDebugLogger('MGMT_ED_SCAN() error: ' + str(e)) - def MGMT_PANID_QUERY(self, sAddr, xCommissionerSessionId, listChannelMask, xPanId): + def MGMT_PANID_QUERY(self, sAddr, xCommissionerSessionId, listChannelMask, + xPanId): """send MGMT_PANID_QUERY message to a given destination Args: @@ -2230,13 +2368,16 @@ class OpenThread_WpanCtl(IThci): panid = str(hex(xPanId)) try: - cmd = self.wpan_cmd_prefix + 'commissioner pan-id-query %s %s %s' % (panid, channelMask, sAddr) + cmd = self.wpan_cmd_prefix + 'commissioner pan-id-query %s %s %s' % ( + panid, channelMask, sAddr) print(cmd) return self.__sendCommand(cmd) != 'Fail' except Exception as e: - ModuleHelper.WriteIntoDebugLogger('MGMT_PANID_QUERY() error: ' + str(e)) + ModuleHelper.WriteIntoDebugLogger('MGMT_PANID_QUERY() error: ' + + str(e)) - def MGMT_ANNOUNCE_BEGIN(self, sAddr, xCommissionerSessionId, listChannelMask, xCount, xPeriod): + def MGMT_ANNOUNCE_BEGIN(self, sAddr, xCommissionerSessionId, + listChannelMask, xCount, xPeriod): """send MGMT_ANNOUNCE_BEGIN message to a given destination Returns: @@ -2256,7 +2397,8 @@ class OpenThread_WpanCtl(IThci): print(cmd) return self.__sendCommand(cmd) != 'Fail' except Exception as e: - ModuleHelper.WriteIntoDebugLogger('MGMT_ANNOUNCE_BEGIN() error: ' + str(e)) + ModuleHelper.WriteIntoDebugLogger('MGMT_ANNOUNCE_BEGIN() error: ' + + str(e)) def MGMT_ACTIVE_GET(self, Addr='', TLVs=[]): """send MGMT_ACTIVE_GET command @@ -2276,7 +2418,8 @@ class OpenThread_WpanCtl(IThci): if self.__sendCommand(setTLVCmd)[0] == 'Fail': return False else: - if self.__sendCommand(self.wpan_cmd_prefix + 'dataset erase')[0] == 'Fail': + if self.__sendCommand(self.wpan_cmd_prefix + + 'dataset erase')[0] == 'Fail': return False if Addr != '': @@ -2289,7 +2432,8 @@ class OpenThread_WpanCtl(IThci): return self.__sendCommand(cmd)[0] != 'Fail' except Exception as e: - ModuleHelper.WriteIntoDebugLogger('MGMT_ACTIVE_GET() Error: ' + str(e)) + ModuleHelper.WriteIntoDebugLogger('MGMT_ACTIVE_GET() Error: ' + + str(e)) def MGMT_ACTIVE_SET( self, @@ -2321,7 +2465,8 @@ class OpenThread_WpanCtl(IThci): try: cmd = self.wpan_cmd_prefix + 'dataset mgmt-set-active' - if self.__sendCommand(self.wpan_cmd_prefix + 'dataset erase')[0] == 'Fail': + if self.__sendCommand(self.wpan_cmd_prefix + + 'dataset erase')[0] == 'Fail': return False if listActiveTimestamp is not None: @@ -2337,17 +2482,20 @@ class OpenThread_WpanCtl(IThci): return False if sNetworkName is not None: - setNetworkNameCmd = self.wpan_cmd_prefix + 'setprop Dataset:NetworkName ' + str(sNetworkName) + setNetworkNameCmd = self.wpan_cmd_prefix + 'setprop Dataset:NetworkName ' + str( + sNetworkName) if self.__sendCommand(setNetworkNameCmd)[0] == 'Fail': return False if xChannel is not None: - setChannelCmd = self.wpan_cmd_prefix + 'setprop Dataset:Channel ' + str(xChannel) + setChannelCmd = self.wpan_cmd_prefix + 'setprop Dataset:Channel ' + str( + xChannel) if self.__sendCommand(setChannelCmd)[0] == 'Fail': return False if sMeshLocalPrefix is not None: - setMLPrefixCmd = self.wpan_cmd_prefix + 'setprop Dataset:MeshLocalPrefix ' + str(sMeshLocalPrefix) + setMLPrefixCmd = self.wpan_cmd_prefix + 'setprop Dataset:MeshLocalPrefix ' + str( + sMeshLocalPrefix) if self.__sendCommand(setMLPrefixCmd)[0] == 'Fail': return False @@ -2358,34 +2506,30 @@ class OpenThread_WpanCtl(IThci): return False if xPanId is not None: - setPanIdCmd = self.wpan_cmd_prefix + 'setprop Dataset:PanId ' + str(xPanId) + setPanIdCmd = self.wpan_cmd_prefix + 'setprop Dataset:PanId ' + str( + xPanId) if self.__sendCommand(setPanIdCmd)[0] == 'Fail': return False if listChannelMask is not None: setChannelMaskCmd = ( - self.wpan_cmd_prefix - + 'setprop Dataset:ChannelMaskPage0 ' - + '0x' - + self.__convertLongToHex(self.__convertChannelMask(listChannelMask)) - ) + self.wpan_cmd_prefix + 'setprop Dataset:ChannelMaskPage0 ' + + '0x' + self.__convertLongToHex( + self.__convertChannelMask(listChannelMask))) if self.__sendCommand(setChannelMaskCmd)[0] == 'Fail': return False - if ( - sPSKc is not None - or listSecurityPolicy is not None - or xCommissioningSessionId is not None - or xTmfPort is not None - or xSteeringData is not None - or xBorderRouterLocator is not None - or BogusTLV is not None - ): + if (sPSKc is not None or listSecurityPolicy is not None or + xCommissioningSessionId is not None or + xTmfPort is not None or xSteeringData is not None or + xBorderRouterLocator is not None or BogusTLV is not None): setRawTLVCmd = self.wpan_cmd_prefix + 'setprop Dataset:RawTlvs ' if sPSKc is not None: setRawTLVCmd += '0410' - stretchedPskc = Thread_PBKDF2.get(sPSKc, ModuleHelper.Default_XpanId, ModuleHelper.Default_NwkName) + stretchedPskc = Thread_PBKDF2.get(sPSKc, + ModuleHelper.Default_XpanId, + ModuleHelper.Default_NwkName) pskc = '%x' % stretchedPskc if len(pskc) < 32: @@ -2466,7 +2610,8 @@ class OpenThread_WpanCtl(IThci): return self.__sendCommand(cmd)[0] != 'Fail' except Exception as e: - ModuleHelper.WriteIntoDebugLogger('MGMT_ACTIVE_SET() Error: ' + str(e)) + ModuleHelper.WriteIntoDebugLogger('MGMT_ACTIVE_SET() Error: ' + + str(e)) def MGMT_PENDING_GET(self, Addr='', TLVs=[]): """send MGMT_PENDING_GET command @@ -2485,7 +2630,8 @@ class OpenThread_WpanCtl(IThci): if self.__sendCommand(setTLVCmd)[0] == 'Fail': return False else: - if self.__sendCommand(self.wpan_cmd_prefix + 'dataset erase')[0] == 'Fail': + if self.__sendCommand(self.wpan_cmd_prefix + + 'dataset erase')[0] == 'Fail': return False if Addr != '': @@ -2498,7 +2644,8 @@ class OpenThread_WpanCtl(IThci): return self.__sendCommand(cmd)[0] != 'Fail' except Exception as e: - ModuleHelper.WriteIntoDebugLogger('MGMT_PENDING_GET() Error: ' + str(e)) + ModuleHelper.WriteIntoDebugLogger('MGMT_PENDING_GET() Error: ' + + str(e)) def MGMT_PENDING_SET( self, @@ -2522,7 +2669,8 @@ class OpenThread_WpanCtl(IThci): print('%s call MGMT_PENDING_SET' % self.port) try: cmd = self.wpan_cmd_prefix + 'dataset mgmt-set-pending' - if self.__sendCommand(self.wpan_cmd_prefix + 'dataset erase')[0] == 'Fail': + if self.__sendCommand(self.wpan_cmd_prefix + + 'dataset erase')[0] == 'Fail': return False if listPendingTimestamp is not None: @@ -2538,22 +2686,26 @@ class OpenThread_WpanCtl(IThci): return False if xDelayTimer is not None: - setDelayTimerCmd = self.wpan_cmd_prefix + 'setprop Dataset:Delay ' + str(xDelayTimer) + setDelayTimerCmd = self.wpan_cmd_prefix + 'setprop Dataset:Delay ' + str( + xDelayTimer) if self.__sendCommand(setDelayTimerCmd)[0] == 'Fail': return False if sNetworkName is not None: - setNetworkNameCmd = self.wpan_cmd_prefix + 'setprop Dataset:NetworkName ' + str(sNetworkName) + setNetworkNameCmd = self.wpan_cmd_prefix + 'setprop Dataset:NetworkName ' + str( + sNetworkName) if self.__sendCommand(setNetworkNameCmd)[0] == 'Fail': return False if xChannel is not None: - setChannelCmd = self.wpan_cmd_prefix + 'setprop Dataset:Channel ' + str(xChannel) + setChannelCmd = self.wpan_cmd_prefix + 'setprop Dataset:Channel ' + str( + xChannel) if self.__sendCommand(setChannelCmd)[0] == 'Fail': return False if sMeshLocalPrefix is not None: - setMLPrefixCmd = self.wpan_cmd_prefix + 'setprop Dataset:MeshLocalPrefix ' + str(sMeshLocalPrefix) + setMLPrefixCmd = self.wpan_cmd_prefix + 'setprop Dataset:MeshLocalPrefix ' + str( + sMeshLocalPrefix) if self.__sendCommand(setMLPrefixCmd)[0] == 'Fail': return False @@ -2564,7 +2716,8 @@ class OpenThread_WpanCtl(IThci): return False if xPanId is not None: - setPanIdCmd = self.wpan_cmd_prefix + 'setprop Dataset:PanId ' + str(xPanId) + setPanIdCmd = self.wpan_cmd_prefix + 'setprop Dataset:PanId ' + str( + xPanId) if self.__sendCommand(setPanIdCmd)[0] == 'Fail': return False @@ -2576,7 +2729,8 @@ class OpenThread_WpanCtl(IThci): return self.__sendCommand(cmd)[0] != 'Fail' except Exception as e: - ModuleHelper.WriteIntoDebugLogger('MGMT_PENDING_SET() Error: ' + str(e)) + ModuleHelper.WriteIntoDebugLogger('MGMT_PENDING_SET() Error: ' + + str(e)) def MGMT_COMM_GET(self, Addr='ff02::1', TLVs=[]): """send MGMT_COMM_GET command @@ -2600,7 +2754,8 @@ class OpenThread_WpanCtl(IThci): return self.__sendCommand(cmd)[0] != 'Fail' except Exception as e: - ModuleHelper.WriteIntoDebugLogger('MGMT_COMM_GET() Error: ' + str(e)) + ModuleHelper.WriteIntoDebugLogger('MGMT_COMM_GET() Error: ' + + str(e)) def MGMT_COMM_SET( self, @@ -2635,12 +2790,14 @@ class OpenThread_WpanCtl(IThci): elif xCommissionerSessionID is None: # use original session id if self.isActiveCommissioner is True: - cmd += '0b02' + self.__lstrip0x(self.__getCommissionerSessionId()) + cmd += '0b02' + self.__lstrip0x( + self.__getCommissionerSessionId()) else: pass if xSteeringData is not None: - cmd += '08' + str(len(hex(xSteeringData)[2:])) + str(hex(xSteeringData)[2:]) + cmd += '08' + str(len(hex(xSteeringData)[2:])) + str( + hex(xSteeringData)[2:]) if xBorderRouterLocator is not None: cmd += '0902' + str(hex(xBorderRouterLocator)) @@ -2653,7 +2810,8 @@ class OpenThread_WpanCtl(IThci): return self.__sendCommand(cmd)[0] != 'Fail' except Exception as e: - ModuleHelper.WriteIntoDebugLogger('MGMT_COMM_SET() Error: ' + str(e)) + ModuleHelper.WriteIntoDebugLogger('MGMT_COMM_SET() Error: ' + + str(e)) def setActiveDataset(self, listActiveDataset=[]): print('%s call setActiveDataset' % self.port) @@ -2667,7 +2825,8 @@ class OpenThread_WpanCtl(IThci): cmd = self.wpan_cmd_prefix + 'setprop Network:PSKc %s' % strPSKc datasetCmd = self.wpan_cmd_prefix + 'setprop Dataset:PSKc %s' % strPSKc self.hasActiveDatasetToCommit = True - return self.__sendCommand(cmd)[0] != 'Fail' and self.__sendCommand(datasetCmd)[0] != 'Fail' + return self.__sendCommand(cmd)[0] != 'Fail' and self.__sendCommand( + datasetCmd)[0] != 'Fail' except Exception as e: ModuleHelper.WriteIntoDebugLogger('setPSKc() Error: ' + str(e)) @@ -2682,7 +2841,8 @@ class OpenThread_WpanCtl(IThci): self.hasActiveDatasetToCommit = True return self.__sendCommand(cmd)[0] != 'Fail' except Exception as e: - ModuleHelper.WriteIntoDebugLogger('setActiveTimestamp() Error: ' + str(e)) + ModuleHelper.WriteIntoDebugLogger('setActiveTimestamp() Error: ' + + str(e)) def setUdpJoinerPort(self, portNumber): """set Joiner UDP Port @@ -2713,7 +2873,8 @@ class OpenThread_WpanCtl(IThci): else: return False - def sendBeacons(self, sAddr, xCommissionerSessionId, listChannelMask, xPanId): + def sendBeacons(self, sAddr, xCommissionerSessionId, listChannelMask, + xPanId): print('%s call sendBeacons' % self.port) self._sendline(self.wpan_cmd_prefix + 'scan') return True