1
0
mirror of https://github.com/JoelBender/bacpypes synced 2025-09-28 22:15:23 +08:00

handy to have a router to multiple networks

This commit is contained in:
Joel Bender 2021-08-13 17:56:55 -04:00
parent 172070fc85
commit c6fca99764

View File

@ -222,7 +222,7 @@ def main():
)
# add an argument for interval
parser.add_argument('net2', type=int,
parser.add_argument('net2', type=int, nargs='+',
help='network number of second network',
)
@ -252,25 +252,10 @@ def main():
local_address = Address(args.addr1)
local_network = args.net1
vlan_network = args.net2
# create the VLAN router, bind it to the local network
router = VLANRouter(local_address, local_network)
# create a VLAN
vlan = Network(broadcast_address=LocalBroadcast())
# create a node for the router, address 1 on the VLAN
router_addr = Address(1)
router_node = Node(router_addr)
vlan.add_node(router_node)
# bind the router stack to the vlan network through this node
router.nsap.bind(router_node, vlan_network, router_addr)
# send network topology
deferred(router.nse.i_am_router_to_network)
# add the dynamic property list
if args.plist:
RandomAnalogValueObject.properties.append(CurrentPropertyList())
@ -278,40 +263,55 @@ def main():
# register it now that all its properties are defined
register_object_type(RandomAnalogValueObject, vendor_id=999)
# make some devices
for device_number in range(2, 2 + args.count):
# device identifier is assigned from the address
device_instance = vlan_network * 100 + device_number
_log.debug(" - device_instance: %r", device_instance)
for vlan_network in args.net2:
# create a VLAN
vlan = Network(broadcast_address=LocalBroadcast())
# make a vlan device object
vlan_device = \
LocalDeviceObject(
objectName="VLAN Node %d" % (device_instance,),
objectIdentifier=('device', device_instance),
maxApduLengthAccepted=1024,
segmentationSupported='noSegmentation',
vendorIdentifier=15,
# create a node for the router, address 1 on the VLAN
router_addr = Address(1)
router_node = Node(router_addr)
vlan.add_node(router_node)
# bind the router stack to the vlan network through this node
router.nsap.bind(router_node, vlan_network, router_addr)
# send network topology
deferred(router.nse.i_am_router_to_network)
# make some devices
for device_number in range(2, 2 + args.count):
# device identifier is assigned from the address
device_instance = vlan_network * 100 + device_number
_log.debug(" - device_instance: %r", device_instance)
# make a vlan device object
vlan_device = \
LocalDeviceObject(
objectName="VLAN Node %d" % (device_instance,),
objectIdentifier=('device', device_instance),
maxApduLengthAccepted=1024,
segmentationSupported='noSegmentation',
vendorIdentifier=15,
)
_log.debug(" - vlan_device: %r", vlan_device)
vlan_address = Address(device_number)
_log.debug(" - vlan_address: %r", vlan_address)
# make the application, add it to the network
vlan_app = VLANApplication(vlan_device, vlan_address)
vlan.add_node(vlan_app.vlan_node)
_log.debug(" - vlan_app: %r", vlan_app)
# make a random value object
ravo = RandomAnalogValueObject(
objectIdentifier=('analogValue', 1),
objectName='Random-1-%d' % (device_instance,),
)
_log.debug(" - vlan_device: %r", vlan_device)
_log.debug(" - ravo: %r", ravo)
vlan_address = Address(device_number)
_log.debug(" - vlan_address: %r", vlan_address)
# make the application, add it to the network
vlan_app = VLANApplication(vlan_device, vlan_address)
vlan.add_node(vlan_app.vlan_node)
_log.debug(" - vlan_app: %r", vlan_app)
# make a random value object
ravo = RandomAnalogValueObject(
objectIdentifier=('analogValue', 1),
objectName='Random-1-%d' % (device_instance,),
)
_log.debug(" - ravo: %r", ravo)
# add it to the device
vlan_app.add_object(ravo)
# add it to the device
vlan_app.add_object(ravo)
_log.debug("running")