LocalBindAddress not working
-
Hi,
I am currently trying to create multiple local devices within my application. Like in previous posts I created virtual networks (Linux ipconfig) and then tried to bind the different devices to the corresponding addresses.The issue is that as soon as I add withLocalBindAddress to the IpNetworkBuilder, nothing happens, not even with one device, it is not discovered, cant be read etc.. When examining the network traffic with wireshark, the WhoIsRouter is sent the same way as without the bindAddress, but no NPDUs are received.
Here is my code:
int localDeviceID = Integer.parseInt(deviceData.getAttribute("id")); network[localDeviceID] = new IpNetworkBuilder().withPort(bacnetPort) .withLocalBindAddress(deviceData .getElementsByTagName("ip") .item(0).getTextContent()) .withBroadcast("192.168.1.255",24) .build(); transport[localDeviceID] = new DefaultTransport(network[localDeviceID]); transport[localDeviceID].setTimeout(500000); transport[localDeviceID].setSegTimeout(15000); localDeviceHashMap.put(localDeviceID,new LocalDevice(localDeviceID, transport[localDeviceID])); localDeviceHashMap.get(localDeviceID).initialize();
No exceptions or errors are generated, but when enabling logging, WhoIsRouter is always sent. When not using localBindAddress and only one device two NPDUs are received. When using it nothing happens after the WhoIsRouter.
Any help would be greatly appreciated.
-
Hi STAstefan,
it is not discovered,
You are using an external application to do the discovery? And, you can see in Wireshark that the broadcast is reaching the Linux machine but you do not see responses. Can you confirm in the routing you've set up that it is delivery the broadcast of the WhoIs to the local addresses you are binding? If you do not specify an address the network builder will use
0.0.0.0
which will receive messages sent to255.255.255.255
on the network. I would have expected you to see broadcasts to the192.168.1.255
address when you initialize the local devices. Are you? What address is your other device broadcasting its WhoIs at? -
Hi,
I am using two machines, the Linux one is running the bacnet4j application (ip: 192.168.1.180) and the second one is a windows machine running YABE to debug my app.
Without localBind, YABE discovers the device (Transport is set to BacNet/IP over Udp, BAC5, local endpoint empty) and even before starting YABE, WhoIsRouter(to 192.168.1.255) is sent by bacnet4j followed by the reception of NPDUs from the local network (i've got the slf4j logging enabled).
When I bind the local device (IpNetworkBuilder) to 192.168.1.180 or a virtual network (192.168.1.181) without changing anything else nothing is happening. The logger prints that WhoIsRouter is sent but nothing received, in wireshark the two WhoIsRouter requests are identical, but no NDPUs are received. The WhoIs requests from YABE with the same settings as before, reach my Linux machine but no eventHandler is ever called.YABE is broadcasting the WhoIs to 192.168.1.255 and 255.255.255.255.
-
Hi,
if anyone should experience the same problems I did, here a quick rundown of what is happening.
Bacnet4j allows the user to bind a local device to a specific ip-address. This function is needed if it is necessary to host multiple local devices from one host. In Windows virtual networks can be created and with .withLocalBindAddress(virtual interface address), the device is henceforth reachable under that address.
In Linux on the other hand, binding broadcast ports like UDP in Bacnet to a specific address of a virtual network is forbidden, but fails quietly, there are just no packets received by the socket. If this is done by the user the packages of the UDP broadcast (for example WhoIs sent from YABE) do reach the Linux machine and even show in wireshark/tcpdump. But they are dropped before they reach the socket, this functionality is handled by the kernel itself and i could not find a way to turn it off (purpose of it is anti spoofing).
So hosting multiple localdevices with different IP addresses on the same port is a non trivial problem in Linux.I managed to get it working tough, my solution is part of a bigger project that will be published, if anyone is interested, i'll post a link to it once it that is done.
-
Thanks for sharing what you found.
It's possible in the latest Mango and BACnet4J to have multiple local devices bind the
0.0.0.0
address for port47808
and then have unique device IDs (and BBMDs to make it make sense).Let us know what you come up with for using particular addresses!