def test(self):
        self.nodes[LEADER].start()
        self.simulator.go(config.LEADER_STARTUP_DELAY)
        self.assertEqual(self.nodes[LEADER].get_state(), 'leader')

        self.nodes[COMMISSIONER].start()
        self.simulator.go(config.ROUTER_STARTUP_DELAY)
        self.assertEqual(self.nodes[COMMISSIONER].get_state(), 'router')
        self.simulator.get_messages_sent_by(LEADER)

        self.collect_rlocs()
        self.collect_rloc16s()

        self.nodes[COMMISSIONER].commissioner_start()
        self.simulator.go(3)

        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)

        steering_data_tlv = mesh_cop.SteeringData(bytes([0xff]))
        self.nodes[COMMISSIONER].commissioner_mgmtset_with_tlvs(
            [steering_data_tlv])
        self.simulator.go(5)

        self.nodes[COMMISSIONER].commissioner_mgmtset_with_tlvs(
            [steering_data_tlv, commissioner_session_id_tlv])
        self.simulator.go(5)

        border_agent_locator_tlv = mesh_cop.BorderAgentLocator(0x0400)
        self.nodes[COMMISSIONER].commissioner_mgmtset_with_tlvs(
            [commissioner_session_id_tlv, border_agent_locator_tlv])
        self.simulator.go(5)

        self.nodes[COMMISSIONER].commissioner_mgmtset_with_tlvs([
            steering_data_tlv,
            commissioner_session_id_tlv,
            border_agent_locator_tlv,
        ])
        self.simulator.go(5)

        self.nodes[COMMISSIONER].commissioner_mgmtset_with_tlvs(
            [mesh_cop.CommissionerSessionId(0xffff), steering_data_tlv])
        self.simulator.go(5)

        self.nodes[COMMISSIONER].commissioner_mgmtset_with_tlvs([
            commissioner_session_id_tlv,
            steering_data_tlv,
            mesh_cop.Channel(0x0, 0x0),
        ])
        self.simulator.go(5)

        leader_rloc = self.nodes[LEADER].get_rloc()
        commissioner_rloc = self.nodes[COMMISSIONER].get_rloc()
        self.assertTrue(self.nodes[COMMISSIONER].ping(leader_rloc))
        self.simulator.go(1)
        self.assertTrue(self.nodes[LEADER].ping(commissioner_rloc))
Beispiel #2
0
    def test(self):
        self.nodes[LEADER].start()
        self.simulator.go(5)
        self.assertEqual(self.nodes[LEADER].get_state(), 'leader')

        self.nodes[COMMISSIONER].start()
        self.simulator.go(5)
        self.assertEqual(self.nodes[COMMISSIONER].get_state(), 'router')

        # Skip all other Coaps sent by Leader
        self.simulator.get_messages_sent_by(COMMISSIONER)
        self.simulator.get_messages_sent_by(LEADER)

        # Commissioner start
        self.nodes[COMMISSIONER].commissioner_start()
        self.simulator.go(3)
        self.simulator.get_messages_sent_by(COMMISSIONER)  # Skip LEAD_PET.req

        # Get CommissionerSessionId from LEAD_PET.rsp
        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)

        # 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])
        self.simulator.go(5)

        # Step 3 - Leader responds to MGMT_COMMISSIONER_SET.req with
        # MGMT_COMMISSIONER_SET.rsp
        leader_messages = self.simulator.get_messages_sent_by(LEADER)
        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)])
        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])
        self.simulator.go(5)
        commissioner_messages = self.simulator.get_messages_sent_by(
            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())
        command.check_coap_message(
            msg,
            [steering_data_tlv, commissioner_session_id_tlv],
            dest_addrs=[rloc, leader_aloc],
        )

        # Step 5 - Leader sends MGMT_COMMISSIONER_SET.rsp to commissioner
        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)])

        # Step 6 - Leader sends a multicast MLE Data Response
        msg = leader_messages.next_mle_message(mle.CommandType.DATA_RESPONSE)
        command.check_data_response(
            msg,
            command.NetworkDataCheck(
                commissioning_data_check=command.CommissioningDataCheck(
                    stable=0,
                    sub_tlv_type_list=[
                        mesh_cop.CommissionerSessionId,
                        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])
        self.simulator.go(5)

        # Step 8 - Leader responds to MGMT_COMMISSIONER_SET.req with
        # MGMT_COMMISSIONER_SET.rsp
        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)])

        # 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.simulator.go(5)

        # Step 10 - Leader responds to MGMT_COMMISSIONER_SET.req with
        # MGMT_COMMISSIONER_SET.rsp
        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)])

        # 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])
        self.simulator.go(5)

        # Step 12 - Leader responds to MGMT_COMMISSIONER_SET.req with
        # MGMT_COMMISSIONER_SET.rsp
        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)])

        # 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.simulator.go(5)

        # Step 14 - Leader responds to MGMT_COMMISSIONER_SET.req with
        # MGMT_COMMISSIONER_SET.rsp
        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)])

        # Step 15 - Send ICMPv6 Echo Request to Leader
        leader_rloc = self.nodes[LEADER].get_rloc()
        self.assertTrue(self.nodes[COMMISSIONER].ping(leader_rloc))