Re: [Bacnet-developers] Source port
Brought to you by:
skarg
|
From: Jacques L. <ja...@le...> - 2023-06-13 02:57:12
|
For some reason, the error 130 has vanished, I can't reproduce it anymore.
This script "test.sh" thus runs well:
#!/bin/bash
generic="$1"
if [[ "$generic" == "1" ]]; then
PORT1=0
PORT2=0
IP=127.0.0.1
else
PORT1=47809
PORT2=47810
IP=10.10.50.25
fi
BACNET_IP_PORT=$PORT1 BACNET_BBMD_PORT=47808 BACNET_BBMD_ADDRESS=$IP
bash -c "./bacrpm 22222 8 22222 12; echo '22222=$?'" &
BACNET_IP_PORT=$PORT2 BACNET_BBMD_PORT=47808 BACNET_BBMD_ADDRESS=$IP
bash -c "./bacrpm 12345 8 12345 12; echo '12345=$?'" &
Calling it as "./test.sh 0" will use specific ports and the real box IP
address. Calling it as "./test.sh 1" will use 0 as the port (I suppose
the O/S is doing dynamic port allocation in this case, as random port
numbers are used, as confirmed with tcpdump) and the generic localhost
address 127.0.0.1.
Both techniques seem to work nicely.
Thank you Mr. Kargs!
JL
Le 2023-06-12 à 11 h 10, Jacques Lemieux a écrit :
> I apologize because I just found out that I was using the same
> BACNET_IP_PORT value for both queries. If I use 47809 for the first
> query and 47810 for the second one, both queries terminate with
> output, but the second one to complete seems to always exit with the
> error code 130.
>
> This error code 130 means:
>
> $ LANG=en_US errno 130
> EOWNERDEAD 130 Owner died
>
> So this looks like some kind of programming error to me as the queries
> are now supposed to both terminate successfully.
>
> Thank you !
>
> JL
>
>
> Le 2023-06-12 à 11 h 02, Jacques Lemieux a écrit :
>>
>> Hello Mr. Kargs and many thanks for your kind reply.
>>
>> I am very new to Bacnet and at this stage I'm just trying to follow
>> recipes that work.
>>
>> I've been following the instructions to use the BBMD mechanism,
>> executing these commands:
>>
>> 1) Start the server in a terminal window.
>>
>> ./bacserv 1234
>>
>> 2) In a second terminal window, run these two commands
>> _sequentially_, they work very well. They query the firmware versions
>> of devices 12345 and 22222.
>>
>> BACNET_IP_PORT=47809 BACNET_BBMD_PORT=47808
>> BACNET_BBMD_ADDRESS=10.10.50.25 bash -c "./bacrpm 12345 8 12345 12"
>>
>> BACNET_IP_PORT=47809 BACNET_BBMD_PORT=47808
>> BACNET_BBMD_ADDRESS=10.10.50.25 bash -c "./bacrpm 22222 8 22222 12"
>>
>> 3) In a second terminal window, run the two same commands in parallel.
>>
>> When I run ("source") this script (which runs both commands in
>> parallel due to the background operator "&")
>>
>> BACNET_IP_PORT=47809 BACNET_BBMD_PORT=47808
>> BACNET_BBMD_ADDRESS=10.10.50.25 bash -c "./bacrpm 12345 8 12345 12;
>> echo '12345=$?'" &
>> BACNET_IP_PORT=47809 BACNET_BBMD_PORT=47808
>> BACNET_BBMD_ADDRESS=10.10.50.25 bash -c "./bacrpm 22222 8 22222 12;
>> echo '22222=$?'" &
>>
>> I get these possible outputs:
>>
>> Case A, good output, but errno 130 (thread programming error code) on
>> the second request.
>>
>> device #12345
>> {
>> application-software-version: "2.0.0"
>> }
>> 12345=0
>> device #22222
>> {
>> application-software-version: "2.1.0.01"
>> }
>> 22222=130
>>
>> Case B, good result for first query, no output for second query and
>> invalid errno 130 again.
>>
>> device #12345
>>
>> {
>> application-software-version: "2.0.0"
>> }
>> 12345=0
>>
>> Error: APDU Timeout!
>> 22222=130
>>
>> So now the question is whether using the command line utilities
>> through BBMD is actually supported when the commands originate from
>> the same box.
>>
>> Any comments on this issue would be greatly appreciated !
>>
>> Many thanks !
>>
>> JL
>>
>>
>> Le 2023-06-12 à 09 h 30, Steve Karg a écrit :
>>> Hello Jacques,
>>>
>>> ref 135 addendum a:
>>> https://bacnet.org/wp-content/uploads/sites/4/2022/08/Add-1995-135a.pdf
>>>
>>> /*J.1.2 Addressing within B/IP Networks*
>>> /
>>> /.../
>>> /The default UDP port for both directed messages and broadcasts
>>> shall be X’BAC0’ and all B/IP devices shall support it. In some
>>> cases, e.g., a situation where it is desirable for two groups of
>>> BACnet devices to coexist independently on the same IP subnet, the
>>> UDP port may be configured locally to a different value without it
>>> being considered a violation of this protocol.
>>> /
>>>
>>> Although it makes sense to use an arbitrary UDP port from a single
>>> PC that is a client, imagine if all devices in the network did the
>>> same thing. How would they be discovered using dynamic binding
>>> (i.e. Who-Is or Who-Has services) via their configured UDP port?
>>>
>>> Historically, the BACnet/IP UDP port number used in the device
>>> applied to both src and dst address of all BACnet/IP messages
>>> initiated (sent) and executed (received), so some vendors may have
>>> taken a shortcut in their device and chosen not reply to the UDP
>>> port indicated in the received messages, or they use dynamic binding
>>> and are unable find the device instance using their configured UDP port.
>>>
>>> The standard mechanism for the case of multiple applications within
>>> the same device (i.e. PC) is to use a local BBMD that supports
>>> Foreign Device Registration, and have each application instance
>>> (which requires a unique MAC, which for BACnet/IP means unique IP
>>> and UDP port pair, so usually just a unique UDP port per
>>> application) register as a Foreign Device to the local BBMD, and all
>>> traffic originates from the BBMD.
>>>
>>> Another alternative is to add the 'loopback' foreign device with
>>> virtual routing patch, as implemented by obvius
>>> <https://github.com/bacnet-stack/bacnet-stack/commit/06b158deb9614f939812b0fe07d551c22125581e> branch.
>>>
>>> Best Regards,
>>>
>>> Steve
>>>
>>>
>>>
>>>
>>> On Fri, Jun 9, 2023 at 5:21 PM Jacques Lemieux <ja...@le...>
>>> wrote:
>>>
>>> I also posted this question on the Bacnet forum page on sourceforge.
>>>
>>> Many thanks.
>>>
>>> JL
>>>
>>> ============
>>>
>>>
>>> Hello !
>>>
>>> We are using the standard Bacnet stack utility to get data out
>>> of some Bacnet devices owned by a client.
>>> We found out that the bacrpm does not behave well when launched
>>> exactly at the same time to query two different Bacnet devices.
>>> They sometimes work ok, but generally they either exit with a 0
>>> status code but no output, or a 130 error code (some threading
>>> programming error). I suppose that this is due to the fact that
>>> both instances of the utility receive the data for both devices
>>> and get mixed up.
>>>
>>> So I opened the stack code and changed it a bit to use a
>>> different source port 50000 for the Ethernet socket, instead of
>>> the standard one 47808.
>>>
>>> As the tcpdump log below shows, the request was really made from
>>> the source port 50000, but the device replied to the port 47808
>>> instead. When looking at the data sent in the payload (bold
>>> below), we can see that the port to reply to, 50000 (0xC350),
>>> does not appear in the payload sent to the Bacnet device.
>>>
>>> I read somewhere that someone succeeded using a source port
>>> different than 47808 for Bacnet communications, so my question
>>> is: should a Bacnet device always reply to the source port from
>>> which the query is coming from, or does the standard mandate to
>>> always reply to port 47808, even if the query comes from a
>>> different source port such as 50000?
>>>
>>> Many thanks !
>>>
>>> Jacques Lemieux
>>> Montréal Canada
>>>
>>> |21:58:45.354664a0:88:69:a9:a7:59>ff:ff:ff:ff:ff:ff,ethertypeIPv4(0x0800),length60:IP(tos0x0,ttl64,id55709,offset0,flags[DF],protoUDP(17),length46)
>>> 10.0.0.43.50000>10.0.0.255.47808:UDP,length18
>>> 0x0000:4500002ed99d400040114bf80a00002b
>>> 0x0010:0a0000ffc350bac0001a65b7**810b0012**
>>> 0x0020:**0120ffff00ff10080a30391a3039**
>>> 21:58:45.42217984:89:ec:30:00:0c>ff:ff:ff:ff:ff:ff,ethertypeIPv4(0x0800),length67:IP(tos0x0,ttl255,id53871,offset0,flags[none],protoUDP(17),length53)
>>> 10.0.0.169.47808>10.0.0.255.47808:UDP,length25
>>> 0x0000:45000035d26f0000ff11d3a00a0000a9
>>> 0x0010:0a0000ffbac0bac00021221f**810b0019**
>>> 0x0020:**0120ffff00ff1000c4020030392205c4** 0x0030:**9103220409** |
>>>
>>> _______________________________________________
>>> BACnet-developers mailing list
>>> BAC...@li...
>>> https://lists.sourceforge.net/lists/listinfo/bacnet-developers
>>>
>>>
>>>
>>> _______________________________________________
>>> BACnet-developers mailing list
>>> BAC...@li...
>>> https://lists.sourceforge.net/lists/listinfo/bacnet-developers |