Пример #1
0
    def test_remote_broadcast_3(self):
        """Remote broadcast, nonexistent network."""
        if _debug: TestUnconfirmedRequests._debug("test_remote_broadcast_3")

        # create a network
        tnet = TNetwork()

        # test device sends request and sees the response
        tnet.td.start_state.doc("3-1-0") \
            .send(WhoIsRequest(
                destination=RemoteBroadcast(3),
                )).doc("3-1-1") \
            .success()

        # sniffer on network 1 sees the request and the response
        tnet.sniffer1.start_state.doc("3-2-0") \
            .receive(PDU,
                pduData=xtob('01.80.00.00.03'       # who is router to network
                    )
                ).doc("3-2-1") \
            .timeout(3).doc("3-2-3") \
            .success()

        # network 2 sees local broadcast looking for network 3
        tnet.sniffer2.start_state.doc('3-3-0') \
            .receive(PDU,
                pduData=xtob('01.88.00.01.01.01.00.00.03'
                    )
                ).doc("3-3-1") \
            .timeout(3).doc("3-3-2") \
            .success()

        # run the group
        tnet.run()
Пример #2
0
    def test_address_equality(self):
        if _debug: TestAddressEquality._debug("test_address_equality")

        assert Address(1) == LocalStation(1)
        assert Address("2") == LocalStation(2)
        assert Address("*") == LocalBroadcast()
        assert Address("3:4") == RemoteStation(3, 4)
        assert Address("5:*") == RemoteBroadcast(5)
        assert Address("*:*") == GlobalBroadcast()
Пример #3
0
    def test_remote_broadcast(self):
        if _debug: TestRemoteBroadcast._debug("test_remote_broadcast")

        # one parameter, correct type
        with self.assertRaises(TypeError):
            RemoteBroadcast()
        with self.assertRaises(TypeError):
            RemoteBroadcast('x')

        # test bad network
        with self.assertRaises(ValueError):
            RemoteBroadcast(-1)
        with self.assertRaises(ValueError):
            RemoteBroadcast(65536)

        # match
        test_addr = RemoteBroadcast(1)
        self.match_address(test_addr, 3, 1, None, None)
        assert str(test_addr) == "1:*"
Пример #4
0
    def test_address_equality_str_routed(self):
        if _debug: TestAddressEquality._debug("test_address_equality_str_routed")

        if not settings.route_aware:
            if _debug: TestAddressEquality._debug("    - not route aware")
            return

        assert Address("3:[email protected]") == RemoteStation(3, 4, route=Address("6.7.8.9"))
        assert Address("5:*@6.7.8.9") == RemoteBroadcast(5, route=Address("6.7.8.9"))
        assert Address("*:*@6.7.8.9") == GlobalBroadcast(route=Address("6.7.8.9"))
Пример #5
0
    def test_remote_broadcast_2(self):
        """Remote broadcast, matching device."""
        if _debug: TestUnconfirmedRequests._debug("test_remote_broadcast_2")

        # create a network
        tnet = TNetwork()

        # test device sends request and sees the response
        tnet.td.start_state.doc("2-1-0") \
            .send(WhoIsRequest(
                destination=RemoteBroadcast(2),
                )).doc("2-1-1") \
            .success()

        # sniffer on network 1 sees the request and the response
        tnet.sniffer1.start_state.doc("2-2-0") \
            .receive(PDU,
                pduData=xtob('01.80.00.00.02'       # who is router to network
                    )
                ).doc("2-2-1") \
            .receive(PDU,
                pduData=xtob('01.80.01.00.02'       # I am router to network
                    )
                ).doc("2-2-1") \
            .receive(PDU,
                pduData=xtob('01.20.00.02.00.ff'    # remote broadcast goes out
                    '10.08'
                    )
                ).doc("2-2-1") \
            .receive(PDU,
                pduData=xtob('01.08.00.02.01.04'    # unicast response
                    '10.00.c4.02.00.00.04.22.04.00.91.00.22.03.e7'
                    )
                ).doc("2-2-2") \
            .timeout(3).doc("2-2-3") \
            .success()

        # network 2 sees local broadcast request and unicast response
        tnet.sniffer2.start_state.doc('2-3-0') \
            .receive(PDU,
                pduData=xtob('01.08.00.01.01.01'    # local broadcast
                    '10.08'
                    )
                ).doc("2-3-1") \
            .receive(PDU,
                pduData=xtob('01.20.00.01.01.01.ff' # unicast response
                    '10.00.c4.02.00.00.04.22.04.00.91.00.22.03.e7'
                    )
                ).doc("2-3-1") \
            .timeout(3).doc("2-3-2") \
            .success()

        # run the group
        tnet.run()
Пример #6
0
    def test_remote_broadcast_routed(self):
        if _debug: TestRemoteBroadcast._debug("test_remote_broadcast_routed")

        if not settings.route_aware:
            if _debug: TestRemoteBroadcast._debug("    - not route aware")
            return

        # match
        test_addr = RemoteBroadcast(1, route=Address("1.2.3.4"))
        self.match_address(test_addr, 3, 1, None, None)
        assert str(test_addr) == "1:*@1.2.3.4"
pdu.put_long(1819222305)
pdu.put_short(25964)
pdu.put(104)
pdu.debug_contents()
print(str(pdu.pduData.decode('utf-8')))

#%% Addresses

# Local stations hold address data
from bacpypes.pdu import LocalStation, LocalBroadcast
from bacpypes.pdu import RemoteStation, RemoteBroadcast, GlobalBroadcast
addr1 = LocalStation(b'123456')  # 6 octet long address
addr2 = LocalStation(12)
addr1.addrAddr
addr2.addrAddr
# When the byte string is six octets long followed by \xba \xc0 the
# Address is interpreted as an IP address
addr3 = LocalStation(b'\x01\x02\x03\x04\xba\xc0')
addr3.__repr__()
# the last octet is the port address
addr4 = LocalStation(b'1234\xba\xc1')
addr4.__repr__()

# Local broadcast - sent to all devices on the network
print(LocalBroadcast())
# Remote station - Destination other than local network
print(RemoteStation(15, 75))  # Network number,  integer
# Remote broadcast
print(RemoteBroadcast(15))  # Network number
# Global broadcast
print(GlobalBroadcast())