JoelBender / BACpypes3

BACnet communications library
33 stars 7 forks source link

26 custom router info #39

Closed JoelBender closed 3 months ago

JoelBender commented 3 months ago

@ChristianTremblay This branch changes the routing path and status methods to async functions. There should not be any changes to normal library user applications unless they have provided their own cache implementation. There is a sample application that goes along with this that uses Redis as a secondary cache. Please review this branch.

ChristianTremblay commented 3 months ago

BAC0.discover() gives me

2024-03-24 15:25:30,434 - INFO    | Found those networks : {1, 2, 303, 304, 10001, 211}
2024-03-24 15:25:30,436 - INFO    | Discovering network 304
2024-03-24 15:25:33,430 - INFO    | Discovering network 1
2024-03-24 15:25:36,440 - INFO    | Discovering network 2
2024-03-24 15:25:39,437 - INFO    | Discovering network 10001
2024-03-24 15:25:42,431 - INFO    | Discovering network 211
2024-03-24 15:25:45,441 - INFO    | Discovering network 303
2024-03-24 15:25:48,429 - INFO    | Discovery done. Found 13 devices on 6 BACnet networks.

bacnet.this_application.app.nsap.router_info_cache.debug_contents() gives

 path_info = {
        (1, 304) : (<IPv4Address 192.168.211.4>, 0)
        (1, 211) : (<IPv4Address 192.168.211.4>, 0)
        (1, 10001) : (<IPv4Address 192.168.211.30>, 0)
        (1, 303) : (<IPv4Address 192.168.211.30>, 0)
        (1, 2) : (<IPv4Address 192.168.210.253>, 0)
        }
    router_dnets = {
        (1, <IPv4Address 192.168.211.4>) : {304, 211}
        (1, <IPv4Address 192.168.211.30>) : {10001, 303}
        (1, <IPv4Address 192.168.210.253>) : {2}
        }

This made me change the function I had bacnet.routing_table

that now gives :

{'192.168.211.4': Source Network: 1 | Address: 192.168.211.4 | Destination Networks: {304, 211} | Path: [((1, 304), <RouterState.AVAILABLE: 0>), ((1, 211), <RouterState.AVAILABLE: 0>)],
 '192.168.210.253': Source Network: 1 | Address: 192.168.210.253 | Destination Networks: {2} | Path: [((1, 2), <RouterState.AVAILABLE: 0>)],
 '192.168.211.30': Source Network: 1 | Address: 192.168.211.30 | Destination Networks: {10001, 303} | Path: [((1, 10001), <RouterState.AVAILABLE: 0>), ((1, 303), <RouterState.AVAILABLE: 0>)]}

I created an enum for RouterState... maybe it would be a good thing on your side for clarity as the meaning of status is hidden as constant in the netservice module

JoelBender commented 3 months ago

There is already a RouterEntryStatus in basetypes that matches the embedded enumeration in BACnetRouterEntry in the standard. Good idea! That change should be pretty simple.

I also don't have a slot for performance-index, so I could make that a 3-element tuple or a dataclass with encode() and decode() methods. Humph.

JoelBender commented 3 months ago

I'm postponing performance-index again.