本文介紹五種雙鏈路數據傳輸方案,目標是利用設備的多個傳輸通道,(如雙有線網口,網口+wifi, 網口+5G等場景 , 網口+ 自組網, 自組網 + 5G等),將數據復制后分流、分路同時傳輸,以期提高數據傳輸可靠性,滿足高可靠性傳輸的應用場景需求。部分方案給出了實際驗證結果 。
使用iptables TEE實現雙鏈路可靠數傳
安裝 配置
通過內核級數據包復制,將流量鏡像到另一網口.驗證方法如下:
-
安裝TEE內核模塊(需確認OpenWrt內核支持):
opkg install kmod-ipt-tee
-
添加iptables規則復制數據包到目標網口
root@test:~# iptables -t mangle -D PREROUTING -p udp --dport 8899 -j TEE --gateway 192.168.2.1 root@test:~# iptables -t mangle -D PREROUTING -p udp --dport 8899 -j TEE --gateway 192.168.100.1
其中192.168.2.1為網關地址, 即將所有udp 8899的包抄送 192.168.2.1和192.168.100.1。
測試環境
測試設備一臺路由器,有三個網口,分別是lan, wan1, wan2。
lan地址: 192.17.5.235
wan1 網關地址: 192.168.2.1
wan2 網關地址: 192.168.100.1
驗證方法
在路由器lan口下掛一臺pc, 向lan口發包:
iperf -u -p 8899 -c 192.17.5.235 -i 1 -t 1000 -b 1M
根據 上一節中,增加兩臺防火墻規則 , 執行結果如下:
root@test:~# iptables -t mangle -D PREROUTING -p udp --dport 8899 -j TEE --gateway 192.168.2.1
root@test:~# iptables -t mangle -D PREROUTING -p udp --dport 8899 -j TEE --gateway 192.168.100.1
root@test:~# iptables -t mangle -L
# Warning: iptables-legacy tables present, use iptables-legacy to see them
Chain PREROUTING (policy ACCEPT)
target prot opt source destination
TEE udp -- anywhere anywhere udp dpt:8899 TEE gw:192.168.2.1
TEE udp -- anywhere anywhere udp dpt:8899 TEE gw:192.168.100.1
在分別在路由器的wan1, wan2上抓包:
tcpdump -i wan1 udp port 8899 -vvv
tcpdump -i wan2 udp port 8899 -vvv
預期結果 是在 wan1,wan2上均能看到被復制 的udp包。
d:\AppGallery\iperf-2.0.9-win64>iperf -u -p 8899 -c 172.17.5.235 -i 1 -t 1000 -b 1k
iptables -t mangle -D PREROUTING -p udp --dport 8899 -j TEE --gateway 192.168.2.1
iptables -t mangle -D PREROUTING -p udp --dport 8899 -j TEE --gateway 192.168.100.1
Socat多路轉發
介紹
socat
是一個功能強大的網絡工具,常被用于創建兩個數據流之間的雙向通信通道,也被稱為 “套接字導管(Socket CAT)”,類似于 cat
命令處理文件的方式來處理套接字。以下是關于它的詳細介紹:
主要特點
-
多協議支持:
socat
支持眾多網絡協議,包括 TCP、UDP、UNIX 域套接字、SSL/TLS、IPv4、IPv6 等。這使得它能夠在不同類型的網絡端點之間建立連接,比如在 TCP 客戶端和服務器、UDP 廣播和多播環境、UNIX 域套接字通信等場景中使用。<