Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding support for specifying TTL of the multicast traffic. Defaulting to 0 (instead of 1). #12

Merged
merged 1 commit into from
Feb 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ services:

* **to_bus** and **from_bus**

Pipes data to or from the `bus`. Expects a single argument, the `bus_id`, which needs to be in the range 0-255.
Pipes data to or from the `bus`. Expects a single argument, the `bus_id`, which needs to be in the range 0-255. In addition, `to_bus` accepts the optional argument `--ttl` which can be used to set the TTL (Time-to-Live) of the outgoing multicast datagram, it defaults to `--ttl 0` (which constrains the traffic to the own host only).

* **record**

Expand All @@ -87,6 +87,7 @@ services:

Rate limit the flow through a pipe on a line-by-line basis. Expects a single required argument, `interval`, and an optional argument, `--key` with a format specification of how to find the key of each line whereby to "group" the flow.


### 3rd-party tools

* **socat**
Expand Down Expand Up @@ -131,6 +132,12 @@ services:
restart: always
command: ["from_bus 3 | socat STDIN UDP4-DATAGRAM:1458"]

sink2:
image: ghcr.io/mo-rise/porla
network_mode: host
restart: always
command: ["from_bus 3 | to_bus 255 --ttl 1"]

record_1:
image: ghcr.io/mo-rise/porla
network_mode: host
Expand Down
14 changes: 13 additions & 1 deletion bash-init.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,19 @@
set -euo pipefail

function to_bus () {
socat STDIN "UDP4-DATAGRAM:239.111.42.$1:12737"
bus="$1"

#Read the argument values
while [ $# -gt 0 ]
do
case "$1" in
--ttl) ttl="$2"; shift;;
--) shift;;
esac
shift;
done

socat STDIN "UDP4-DATAGRAM:239.111.42.$bus:12737,ip-multicast-ttl=${ttl:-0}"
}
export to_bus

Expand Down
2 changes: 1 addition & 1 deletion tests/test_porla.bats
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ teardown() {

docker run -d -v "$TMP_DIR":/recordings --network=host porla "from_bus 37 | record /recordings/out.txt"

docker run -v "$TMP_DIR":/recordings --network=host porla "cat /recordings/test.txt | to_bus 37"
docker run -v "$TMP_DIR":/recordings --network=host porla "cat /recordings/test.txt | to_bus 37 --ttl 1"

assert_exists "$TMP_DIR"/out.txt

Expand Down
Loading