五种方案实现双链路可靠数据传输

发布于:2025-03-19 ⋅ 阅读:(15) ⋅ 点赞:(0)

本文介绍五种双链路数据传输方案,目标是利用设备的多个传输通道,(如双有线网口,网口+wifi, 网口+5G等场景 , 网口+ 自组网, 自组网 + 5G等),将数据复制后分流、分路同时传输,以期提高数据传输可靠性,满足高可靠性传输的应用场景需求。部分方案给出了实际验证结果 。

使用iptables TEE实现双链路可靠数传

安装 配置

通过内核级数据包复制,将流量镜像到另一网口.验证方法如下:

  1. 安装TEE内核模块(需确认OpenWrt内核支持):

    opkg install kmod-ipt-tee
    
  2. 添加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 域套接字通信等场景中使用。<