예제 #1
0
    def do_dcc(self, args):
        """dcc <addr> [ <duration> ] <enable> [ <password> ]"""
        args = args.split()
        if _debug: DCCConsoleCmd._debug("do_dcc %r", args)

        try:
            addr = args[0]

            if len(args) == 2:
                enable_disable = args[1]
                time_duration = password = None

            elif len(args) == 3:
                if args[1].isdigit():
                    time_duration = int(args[1])
                    enable_disable = args[2]
                    password = None
                else:
                    time_duration = None
                    enable_disable = args[1]
                    password = args[2]
            else:
                time_duration = int(args[1])
                enable_disable = args[2]
                password = args[3]

            # build a request
            request = DeviceCommunicationControlRequest(
                enableDisable=enable_disable,
                )
            request.pduDestination = Address(addr)

            if time_duration is not None:
                request.timeDuration = time_duration
            if password is not None:
                request.password = password
            if _debug: DCCConsoleCmd._debug("    - request: %r", request)

            # make an IOCB
            iocb = IOCB(request)
            if _debug: DCCConsoleCmd._debug("    - iocb: %r", iocb)

            # give it to the application
            this_application.request_io(iocb)

            # wait for it to complete
            iocb.wait()

            # do something for error/reject/abort
            if iocb.ioError:
                sys.stdout.write(str(iocb.ioError) + '\n')
            else:
                if _debug: DCCConsoleCmd._debug("    - ack")

        except Exception as error:
            DCCConsoleCmd._exception("exception: %r", error)
예제 #2
0
    def test_incorrect_password(self):
        """Test disabling communication that requires a password."""
        if _debug:
            TestDeviceCommunicationControl._debug("test_incorrect_password")

        # create a network
        anet = ApplicationNetwork("test_incorrect_password")

        # add the service capability to the IUT
        anet.iut.add_capability(WhoIsIAmServices)
        anet.iut.add_capability(DeviceCommunicationControlServices)

        # set the password
        anet.iut_device_object._dcc_password = "******"

        # test sequence
        anet.td.start_state.doc("7-6-0") \
            .send(DeviceCommunicationControlRequest(
                destination=anet.iut.address,
                timeDuration=1,
                enableDisable='disable',
                password="******",
                )).doc("7-6-1") \
            .receive(Error,
                errorClass='security',
                errorCode='passwordFailure',
                ).doc("7-6-2") \
            .success()

        # no IUT application layer matching
        anet.iut.start_state.success()

        # run the group
        anet.run()
예제 #3
0
    def test_disable_initiation(self):
        """Test disabling initiation.  After the DCC request send the IUT
        a WhoIsRequest and verify that the IAmRequest makes it back.
        """
        if _debug:
            TestDeviceCommunicationControl._debug("test_disable_initiation")

        # create a network
        anet = ApplicationNetwork("test_disable_initiation")

        # add the service capability to the IUT
        anet.iut.add_capability(WhoIsIAmServices)
        anet.iut.add_capability(DeviceCommunicationControlServices)

        # test sequence
        anet.td.start_state.doc("7-3-0") \
            .send(DeviceCommunicationControlRequest(
                destination=anet.iut.address,
                enableDisable='disableInitiation',
                )).doc("7-3-1") \
            .receive(SimpleAckPDU).doc("7-3-2") \
            .send(WhoIsRequest(destination=anet.vlan.broadcast_address)).doc("7-3-3") \
            .receive(IAmRequest, pduSource=anet.iut.address).doc("7-3-4") \
            .success()

        # no IUT application layer matching
        anet.iut.start_state.success()

        # run the group
        anet.run()
예제 #4
0
    def test_disable(self):
        """Test."""
        if _debug: TestDeviceCommunicationControl._debug("test_disable")

        # create a network
        anet = ApplicationNetwork("test_disable")

        # add the service capability to the IUT
        anet.iut.add_capability(WhoIsIAmServices)
        anet.iut.add_capability(DeviceCommunicationControlServices)

        # test sequence
        anet.td.start_state.doc("7-2-0") \
            .send(DeviceCommunicationControlRequest(
                destination=anet.iut.address,
                enableDisable='disable',
                )).doc("7-2-1") \
            .receive(SimpleAckPDU).doc("7-2-2") \
            .send(WhoIsRequest(destination=anet.vlan.broadcast_address)).doc("7-2-3") \
            .timeout(10).doc("7-2-4") \
            .success()

        # no IUT application layer matching
        anet.iut.start_state.success()

        # run the group
        anet.run()
    def dcc(self, address=None, duration=None, password=None, state=None):
        """
        Will send DeviceCommunicationControl request
        """
        if not self._started:
            raise ApplicationNotStarted(
                "BACnet stack not running - use startApp()")

        if not address:
            raise ValueError("Provide address for request")

        if not state:
            raise ValueError(
                "Provide state ('enable', 'disable', 'disableInitiation'")

        # build a request
        request = DeviceCommunicationControlRequest()
        request.enableDisable = DeviceCommunicationControlRequestEnableDisable.enumerations[
            state]
        request.pduDestination = Address(address)
        if duration:
            request.duration = Unsigned16(duration)

        request.password = CharacterString(password)

        self._log.debug("{:>12} {}".format("- request:", request))

        iocb = IOCB(request)  # make an IOCB

        # pass to the BACnet stack
        deferred(self.this_application.request_io, iocb)

        # Unconfirmed request...so wait until complete
        iocb.wait()  # Wait for BACnet response

        if iocb.ioResponse:  # successful response
            apdu = iocb.ioResponse

            if not isinstance(apdu, SimpleAckPDU):  # expect an ACK
                self._log.warning("Not an ack, see debug for more infos.")
                self._log.debug("Not an ack. | APDU : {} / {}".format(
                    (apdu, type(apdu))))
                return

        if iocb.ioError:  # unsuccessful: error/reject/abort
            apdu = iocb.ioError
            reason = find_reason(apdu)
            raise NoResponseFromController(
                "APDU Abort Reason : {}".format(reason))

        self._log.info(
            "DeviceCommunicationControl request sent to device : {}".format(
                address))
예제 #6
0
    def test_disable_time_duration(self):
        """Test disabling communication for a specific amount of time in
        minutes.  After turning off communications, wait for 30 seconds and
        send a request and nothing should come back.  Wait an additional 30
        seconds and try again, this time receiving the response."""
        if _debug:
            TestDeviceCommunicationControl._debug("test_disable_time_duration")

        # create a network
        anet = ApplicationNetwork("test_disable_time_duration")

        # add the service capability to the IUT
        anet.iut.add_capability(WhoIsIAmServices)
        anet.iut.add_capability(DeviceCommunicationControlServices)

        # test sequence
        anet.td.start_state.doc("7-4-0") \
            .send(DeviceCommunicationControlRequest(
                destination=anet.iut.address,
                enableDisable='disable',
                timeDuration=1,
                )).doc("7-4-1") \
            .receive(SimpleAckPDU).doc("7-4-2") \
            .timeout(30).doc("7-4-3") \
            .send(WhoIsRequest(
                destination=anet.vlan.broadcast_address,
                )).doc("7-4-4") \
            .timeout(30.1).doc("7-4-5") \
            .send(WhoIsRequest(
                destination=anet.vlan.broadcast_address,
                )).doc("7-4-6") \
            .receive(IAmRequest, pduSource=anet.iut.address).doc("7-4-7") \
            .success()

        # no IUT application layer matching
        anet.iut.start_state.success()

        # run the group a little longer than a minute
        anet.run(61)