diff --git a/README.md b/README.md index 5fa472f..d0b8da4 100644 --- a/README.md +++ b/README.md @@ -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** @@ -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** @@ -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 diff --git a/bash-init.sh b/bash-init.sh index 479ebe1..3b1669d 100644 --- a/bash-init.sh +++ b/bash-init.sh @@ -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 diff --git a/tests/test_porla.bats b/tests/test_porla.bats index b78a33b..5b6e5de 100644 --- a/tests/test_porla.bats +++ b/tests/test_porla.bats @@ -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