Relays TCP traffic and optionally adds interference to test those connections
1.0K
Simple utility to relay tcp traffic to a specific host and port.
It can be useful also to add interference (test under stress) a TCP based network connection (ex: Live streaming)
docker pull jcenzano/docker-tcp-proxygit clone [email protected]:jordicenzano/tcp-proxy-docker.gitmake./tcp-proxy.sh listenPort DestHost DestPort
To relay all TCP connections on your port 1234 to my.cool.host:80:
docker run -it --rm -p 1234:2000 jcenzano/tcp-proxy 2000 my.cool.host 80
You can simulate bad networks conditions (rate, loss, delays, corrupt, duplication, reordering) using netem more info
In the following example we will simulate 1Mbps of BW streaming to Facebook
docker run -itd --cap-add=NET_ADMIN --name tcp-relay --rm -p 1935:2000 jcenzano/docker-tcp-proxy:latest 2000 rtmp-pc.facebook.com 443
ffmpeg. Remember to point to localhost:1935ffmpeg -hide_banner -y \
-f lavfi -re -i smptebars=size=1280x720:rate=30 \
-f lavfi -i sine=frequency=1000:sample_rate=48000 -pix_fmt yuv420p \
-c:v libx264 -b:v 6000k -g 60 -profile:v baseline -preset veryfast \
-c:a aac -b:a 48k \
-f flv "rtmps://localhost:1935/rtmp/MY-STREAM-KEY"
(*) With OBS in MAC you could have certificate problems using RTMPS
docker exec tcp-relay sh -c "tc qdisc add dev eth0 root netem rate 1000kbit"
At this point you can observe/measure how your communication protocol deals with those BW restrictions
Finally remove your network limits
docker exec tcp-relay sh -c "tc qdisc del dev eth0 root"
iperf -s -i 2 -p 6000
tcp-proxy-docker with this command to get packets from 1935 in localhost and send it (internally) to localhost (host.docker.internal) port 6000docker run -it --cap-add=NET_ADMIN --name test-net --rm -p 1935:2000 jcenzano/docker-tcp-proxy:latest 2000 host.docker.internal 6000
iperf client in localhost pointing to port 1935iperf -c localhost -i 2 -t 300 -p 1935
...
[ 4] 0.0- 2.0 sec 62.9 MBytes 264 Mbits/sec
[ 4] 2.0- 4.0 sec 73.7 MBytes 309 Mbits/sec
[ 4] 4.0- 6.0 sec 75.1 MBytes 315 Mbits/sec
[ 4] 6.0- 8.0 sec 72.2 MBytes 303 Mbits/sec
[ 4] 8.0-10.0 sec 64.7 MBytes 271 Mbits/sec
[ 4] 10.0-12.0 sec 58.0 MBytes 243 Mbits/sec
[ 4] 12.0-14.0 sec 62.1 MBytes 260 Mbits/sec
...
docker exec test-net sh -c "tc qdisc add dev eth0 root netem rate 1000kbit"
...
[ 4] 28.0-30.0 sec 61.1 MBytes 256 Mbits/sec
[ 4] 30.0-32.0 sec 61.4 MBytes 258 Mbits/sec
[ 4] 32.0-34.0 sec 57.2 MBytes 240 Mbits/sec
[ 4] 34.0-36.0 sec 52.7 MBytes 221 Mbits/sec
[ 4] 36.0-38.0 sec 212 KBytes 870 Kbits/sec <-- Limit to 1Mbps
[ 4] 38.0-40.0 sec 235 KBytes 964 Kbits/sec
[ 4] 40.0-42.0 sec 235 KBytes 964 Kbits/sec
...
docker exec test-net sh -c "tc qdisc del dev eth0 root netem"
Content type
Image
Digest
Size
51.3 MB
Last updated
over 6 years ago
docker pull jcenzano/docker-tcp-proxy