OpenWrt系统上配置batman-adv快速开始与配置详解
batman-adv 的安装和配置
802.11s 配置于 2018 年 9 月在运行非 CT 固件的 Archer C7v2 设备上开发和测试openwrt-18.06(master如果运行 18.06 及其旧版本,请参阅上面关于配置更改的说明batman-adv)。
EA8300 的当前(2019.1 及以后)batman-adv配置master已于 2019 年 5 月确认。
您的设备是否支持 802.11s 或 IBSS?
通常情况下,需要使用 802.11s 或 IBSS(“临时”)来建立网状网络。
本页未详细讨论 IBSS 配置。更多信息请参阅WiFi /etc/config/wireless 文件。
请注意,并非所有驱动程序/固件组合都支持 802.11s 网状网络(或 IBSS)。您可以通过检查iw phy输出结果中是否包含“mesh point”(或“IBSS”)来确认这一点。如果您的设备不支持 -CT 驱动程序/固件,则“经典”(不带 -CT 参数)版本可能支持。
root@test:~# iw phy | fgrep mesh* mesh point* #{ managed } <= 16, #{ AP, mesh point } <= 16, #{ IBSS } <= 1,* mesh point* #{ managed } <= 16, #{ AP, mesh point } <= 16, #{ IBSS } <= 1,* mesh point* #{ managed } <= 16, #{ AP, mesh point } <= 16, #{ IBSS } <= 1, 据报道,mwlwifi驱动程序支持的某些 Marvell 芯片不支持 802.11s,即使在功能列表中显示支持。
详情请参见https://github.com/kaloz/mwlwifi/issues?utf8=%E2%9C%93&q=is%3Aissue+802.11s
概述
本教程将介绍以下步骤。
- 安装 batman-adv 所需的软件包
- 配置 batman-adv 将运行的网格
- 配置 batman-adv 使用网格
- 配置一个或多个 VLAN 以便由 batman-adv 进行路由
虽然这里描述的是 802.11s 网状网络,但也可以使用自组织(IBSS)网状网络或点对点链路。
请注意,由于 batman-adv 报头的存在,使用MTU为 1500 的以太网链路会将 PMTU 降低到 1500 以下。batman-adv 通常用于管理分片,但分片会导致吞吐量略微下降。在许多应用场景中,以太网链路的更高速度、更低延迟和/或更高可靠性足以弥补这种影响。
安装
opkg update
opkg install kmod-batman-adv 建议便于监控和调试
opkg install batctl 如果batctl不可用,请安装batctl-default。
要启用 802.11s 网状网络:
# Remove
opkg remove wpad-basic
opkg remove wpad-basic-wolfssl# Install
opkg install wpad-mesh-openssl # or wpad-mesh-wolfssl 如果要构建/组装自己的镜像,则需要删除默认镜像wpad-basic,因为它与默认镜像冲突wpad-mesh-*。
截至 2019 年 9 月,wpad-openssl或者也wpad-wolfssl足以用于 802.11s,并且是完整版本。 wpad
笔记:
-
wpad-basic-wolfssl仅支持802.11r和802.11w。 -
wpad-mesh-openssl仅wpad-mesh-wolfssl支持802.11r/w和802.11s。 -
wpad-openssl并且wpad-wolfssl是完整版本,wpad支持802.11k/v/r/w和802.11s。 - 完整版意味着它不像其他版本
wpad那样为了减小大小而进行任何删减。basicmesh
配置
一般的
从 2019.1 版本开始,batman-adv 的配置仅通过一个配置文件完成/etc/config/network。当前版本不再/etc/config/batman-adv使用其他配置文件。
有关与“'”交互的选项,option proto 'batadv请参阅手册batctl页,目前可从以下网址获取:https://downloads.open-mesh.org/batman/manpages/batctl.8.html
/lib/netifd/proto/batadv*.sh目前 已应用 UCI 配置。
这里不讨论VLAN/lib/netifd/proto/batadv_vlan.sh特定配置,但可以通过查看和参考 batman-adv 文档来了解。
(1)802.11s 加密认证网状网络
在本演示中,我们使用 802.11s 网状网络。也可以使用其他网状网络和点对点链路。
警告 - 请勿使用 uci、iw 或 mesh11sd 等软件包配置完整的 802.11s 回程链路,因为由此产生的 HWMP mac 路由与 batman-adv 不兼容。
使用相同的配置节 配置所有/etc/config/wireless网格节点:
config wifi-iface 'mesh0'option device 'radio5pci'option ifname 'mesh0'option network 'nwi_mesh0'option mode 'mesh'option mesh_fwding '0'option mesh_id '<your advertised mesh "name" goes here>'option encryption 'psk2+ccmp'option key '<your secure pass phrase goes here>' 请注意,在 18.01 版本中,“key”才是放置密码短语的正确位置,而不是“sae_password”。
要点:
在很多地方,我使用比默认配置更具描述性的名称,或者为了清晰起见而添加一个并非必需的名称。
-
radio5pci/etc/config/wireless需要与设备中的声明匹配,例如config wifi-device 'radio5pci“- 所有无线电设备都需要在同一频道上,并且配置成可以相互操作(基本上配置要完全相同)。
-
-
mesh0为了清晰起见,这是一个用于标识接口本身名称的固定标识符(否则它将被动态分配)。 -
nwi_mesh0这是指向配置文件中/etc/config/network用于设置MTU并将其与 batman-adv 接口关联的条目的引用。此处选择此名称是为了便于阅读,而不是为了与 OpenWrt 等接口名称前缀结构相匹配。 -
mesh_fwding '0'关闭 802.11s 转发/路由;它将由每个节点上的 batman-adv 处理。 -
psk2+ccmp目前来看,这是家庭用户最安全的选择。
应用后,mesh0应该可以在输出中看到ip link。
8: mesh0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP mode DORMANT group default qlen 1000link/ether 32:23:03:xx:xx:xx brd ff:ff:ff:ff:ff:ff 可以通过以下命令确认网状网络的运行情况iw dev mesh0 station dump。您应该在列表中看到其他对等节点,这mesh plink: ESTAB表明对等连接已成功建立。
点击查看示例iw dev mesh0 station dump输出
如果在与条目关联之前测试网格/etc/config/network,您可能需要使用ip来启动接口并修改其参数,例如MTU。
(2)将 batman-adv 与 Mesh 关联
现在网状网络已经(或可能)启动并运行,创建 batman-adv 接口以通过网状网络路由流量。
使用相同的两个配置段配置所有网格节点/etc/config/network:
第一个bat0是“控制”接口。这里直接取自引入 2019 年配置 的提交 54af5a2 。
如有需要,请进行调整。有关与option proto 'batadv“'”交互的选项,请参阅batctl手册页,目前可从以下网址获取:https: //downloads.open-mesh.org/batman/manpages/batctl.8.html
config interface 'bat0'option proto 'batadv'option routing_algo 'BATMAN_IV'option aggregated_ogms 1option ap_isolation 0option bonding 0option fragmentation 1#option gw_bandwidth '10000/2000'option gw_mode 'off'#option gw_sel_class 20option log_level 0option orig_interval 1000option bridge_loop_avoidance 1option distributed_arp_table 1option multicast_mode 1option network_coding 0option hop_penalty 30option isolation_mark '0x00000000/0x00000000' 第二种方法是将“物理”链路置于控制之下bat0。
在这种情况下,OpenWrt 中的无线管理功能会在无线接口启动时自动进行关联。有关如何添加其他链路类型的建议, 请参阅提交记录 54af5a2 。
config interface 'nwi_mesh0'option mtu '2304'option proto 'batadv_hardif'option master 'bat0' 要点:
-
nwi_mesh0/etc/config/wireless需要与设备中的声明匹配,例如option network 'nwi_mesh0“ - 此处MTU设置为 2304,这是802.11s 链路支持的最大 MTU 值。建议最小 MTU 设置为 1532,以便为典型的 1500 字节以太网数据包提供 batman-adv 路由。MTU不能超过链路的原生MTU。
截至目前(2018 年秋季,batman-adv 2018.2),默认路由算法为 BATMAN_IV (4)。根据作者经验,BATMAN_V (5) 在此本地部署应用中不够稳定。例如,请参阅https://forum.openwrt.org/t/batman-v-routing-on-prem-connectivity-loss-seen/20432
网状网络建立完毕且网络配置完成后,您应该bat0在输出中看到。和/或的ip link输出应该表明各个 batman-adv 节点正在通过网状网络“看到”彼此。 batctl obatctl n
点击查看诊断结果
(3) 通过 batman-adv 桥接 VLAN
注意:本文不讨论如何配置交换机以使用 VLAN、如何将无线接口与网桥关联以及如何防火墙流量。有关这些操作的详细信息,请参阅其他文档,以便更好地了解它们如何应用于您的实际情况。
既然 batman-adv 现在已经能够在对等体之间路由数据包,那么剩下的步骤就是利用该功能来路由“有用的”流量。
根据每个节点的具体情况,/etc/config/network参考这些示例进行编辑。多个 VLAN 可以通过单个 batman-adv 接口进行桥接/路由。
此option delegate '0设置会“关闭”接口上的某些IPv6相关功能。如果您正在使用IPv6,则应检查此设置是否适合您的应用程序。
按照目前的惯例,OpenWrt 会给网桥接口命名时,在其名称前加上类似br-“yield”br-vlan1111之类的前缀。Linux 内核对接口名称的长度通常有 15 个字符的限制,这其中也包括br-前缀。
这些网桥的MTU不会大于其桥接接口中最小的MTU。一旦包含典型的以太网接口,即使网桥中的一个或多个成员的MTU更大, MTU也将为 1500 或更小。这是 Linux 系统中网桥的一般工作方式,并非 OpenWrt 特有的限制。
使用 IPv4 地址的桥接
config interface 'vlan1111'option type 'bridge'option stp '1'option ifname 'eth1.1111 bat0.1111'option proto 'static'option ipaddr '192.168.11.11'option netmask '255.255.255.0'option delegate '0'
没有 IPv4 地址的桥接
config interface 'vlan2222'option type 'bridge'option stp '1'option ifname 'eth1.2222 bat0.2222'option proto 'none'option auto '1'option delegate '0'
无以太网接口的桥接器
(例如“仅”用于桥接无线接口)
config interface 'vlan3333'option type 'bridge'option stp '1'option ifname 'bat0.3333'option proto 'none'option auto '1'option delegate '0'
与DSA的衔接
自 OpenWrt 版本 21.02.0 起,交换机采用 DSA 架构,而非之前的架构swconfig。
要使上述任何示例正常工作,您必须首先在配置中创建桥接和 VLAN,/etc/config/network并将 Batman VLAN 桥接起来。
您可以更改桥接的内容,您可以参考DSA 迷你教程和转换为 DSA。
桥接所有 LAN 端口和 Batman VLAN 接口(稍后将按 VLAN 分隔)
config deviceoption name 'br-lan'option type 'bridge'list ports 'lan1'list ports 'lan2'list ports 'lan3'list ports 'lan4'list ports 'bat0.1' # Batman VLAN 1list ports 'bat0.2' # Batman VLAN 2option stp '1'option igmp_snooping '1'option ipv6 '0'option mtu '2304'
驱动程序级VLAN
# VLAN 1, br-lan.1, the VLAN with all ports bridged together (you can change what to bridge)
config bridge-vlanoption device 'br-lan'option vlan '1'list ports 'lan1'list ports 'lan2'list ports 'lan3'list ports 'lan4'list ports 'bat0.1'# VLAN 2, br-lan.2, using only Batman's 2nd VLAN, separated from the rest
config bridge-vlanoption device 'br-lan'option vlan '2'list ports 'bat0.2'
网络接口
# LAN with VLAN 1, and bridged(as stated above) with Batman VLAN 1 and all 4 Ethernet ports
config interface 'lan'option device 'br-lan.1' # VLAN number 1option proto 'static'option ipaddr '192.168.1.254'option netmask '255.255.255.0'option force_link 'yes'# Guest network in VLAN 2, and bridged(as stated above) with Batman VLAN 2
config interface 'guest'option device 'br-lan.2'option proto 'static'option ipaddr '192.168.2.254'option netmask '255.255.255.0'option force_link 'yes' 第二个节点应禁用DHCP并采用类似的设置,唯一的区别是为网络使用不同的 IP 地址(lan:192.168.1.254和 guest:192.168.2.254应使用该子网中的 另一个IP 地址)。
# LAN with VLAN 1, and bridged(as stated above) with Batman VLAN 1 and all 4 Ethernet ports
config interface 'lan'option device 'br-lan.1' # VLAN number 1option proto 'static'option ipaddr '192.168.1.100'option netmask '255.255.255.0'option force_link 'yes'# Guest network in VLAN 2, and bridged(as stated above) with Batman VLAN 2
config interface 'guest'option device 'br-lan.2'option proto 'static'option ipaddr '192.168.2.100'option netmask '255.255.255.0'option force_link 'yes'
(可选)/etc/bat-hosts
这不是必须的步骤——它可以让一些诊断输出更容易阅读。
创建该文件后,/etc/bat-hosts许多命令的输出结果batctl会将 MAC 地址替换为符号名称。这些名称不必是主机名,也不必与DNS 记录一致。
要使用的 MAC 地址是“原始”接口的地址bat0,在本例配置中,即mesh0每个节点上的接口的地址。
32:b5:c2:aa:aa:aa office.5g
c6:6e:1f:bb:bb:bb garage.5g
32:b5:c2:cc:cc:cc front.5g
1a:d6:c7:dd:dd:dd back.5g
c6:e9:84:ee:ee:ee devel.5g
batman-adv bat0(主网格界面)的选项
/etc/config/network这些是batman-adv 的 主网络接口选项。
本节内容参考了官方的 batman-adv 文档编写,可能会有所更改。如果遇到任何问题,请查阅官方文档。
| Name | Type | Default | Range | Description |
|---|---|---|---|---|
aggregated_ogms | boolean | 1 | 0, 1 | OGMs AKA Originator Messages are messages used to determine the qualities needed to direct neighbors and spreading this message throughout the whole mesh, aggregating them reduces the number of packets being sent. |
routing_algo | string | BATMAN_IV | BATMAN_IV or BATMAN_V | Which routing algorithm to use - more info below but for now use BATMAN_IV until BATMAN_V is ready for actual use. |
bonding | boolean | 0 | 0, 1 | If some interfaces are similar in quality and speed, it's possible to distribute frames through them using Round Robin which shows a 50% throughput increase, but if the links aren't similar in speed and since it isn't detected by BATMAN_IV, you may actually lose throughput, so it should be done explicitly on known nodes. |
fragmentation | boolean | 1 | 0, 1 | Since batman-adv prepends its own headers and some clients aren't aware of that, packets are optimized for 1500 MTU even though 1528 is required, if it isn't possible with some devices fragmentation is used(the algorithm that handles fragmented data). |
gw_mode | string | off | off, client, server | Gateway mode, if set to server other nodes are notified of that node's internet connection and must be complemented by gw_bandwidth, that notifies the algorithm that server is one of the best paths for internet access.If set to client, the criteria by which batman-adv will choose a gateway(other nodes with gw_mode set as server) is required to be set with gw_sel_class. |
gw_bandwidth | string | 10000/2000 | not specified | (Server) Set the bandwidth, so client nodes will know about the gateway's quality stated by download/upload, units can be suffixed with mbit or kbit (10mbit/2mbit), if you state download but not upload, upload defaults to the value of download / 5, so 100mbit without upload would default to 100 / 5 = 20mbit. |
gw_sel_class | integer | BATMAN_IV 20BATMAN_V 5000 | BATMAN_IV 1, 256BATMAN_V 0, Not specified | (Client) Set the criteria by which to select a gateway(internet connection) indicated by TQ. With BATMAN_IV_ set in routed_algo:default: 20 (late switch)1 (Fast), prioritize by advertised throughput and link quality, use until gateway disappears.2 (Stable), prioritize by link quality only, use until gateway disappears.3 (Fast Switch), prioritize link quality only, but scan and switch to a better gateway if found.XX (Late Switch), prioritize link quality only, but scan and switch to a better gateway if found, which is at least XX TQ better than the currently selected gateway, where XX is between 3-256.With BATMAN_V set in routed_algo:default: 5000 (Late Switch), 5000 kbit/s throughput.example: 1500 (Fast Switch), scan and switch to another gateway only if its throughput is at least 1500 kbit/s faster than the current, throughput is evaluated by determining what's lower: advertised throughput or the maximum bandwidth across the entire path. |
log_level | integer | 0 | 0, 255 (8 bit Bitmask) | Standard warning/error messages are sent to the kernel log, but more is possible(depending if compiling with debugging enabled). [0] all debug output disabled (none) [1](BIT 0 set) messages related to routing / flooding / broadcasting (batman), [2](BIT 1 set) messages related to route added / changed / deleted (routes) [4](BIT 2 set) messages related to translation table operations (tt) [8](BIT 3 set) messages related to bridge loop avoidance (bla) [16](BIT 4 set) messages related to arp snooping and distributed arp table (dat) [32](BIT 5 set) messages related to network coding (nc) [64](BIT 6 set) messages related to multicast (mcast) [128](BIT 7 set) messages related to throughput meter (tp) [255](ALL BITS set) Enable all messages NOTE: Integer values are form the Kernel docs and bitfield from batman-adv source |
orig_interval | integer | 1000 | not specified | Specified in milliseconds, the interval in which batman-adv floods the network with its protocol information, '1000' as a default means a message per second which allows batman to recognize a route change up to a minute. In a static environment(nodes aren't moving, rare up/down of nodes) you might want to increase the interval value to save bandwidth, inversely, in a highly mobile environment(cars) but remember that will drastically increase traffic. It's recommended to keep the default unless there are problems. |
bridge_loop_avoidance | boolean | 1 | 0, 1 | In bridged LAN setups, this should be enabled in order to avoid broadcast loops that can completely flood the entire LAN(this option might need to be compiled), if you don't connect multiple batman-adv hosts to the same ethernet or don't use bridging, you can disable this option. |
distributed_arp_table | boolean | 1 | 0, 1 | Mesh-wide ARP table cache, helps non-mesh clients get ARP responses more reliably without much delay(this option might need to be compiled). |
multicast_mode | boolean | 1 | 0, 1 | A more efficient, group aware multicast forwarding infrastructure, aiming to reduce unnecessary packet transmissions, if disabled, every multicast traffic will flood every node(broadcast). |
multicast_fanout | integer | 16 | not specified | Requires and related to multicast_mode, batman-adv detects potential multicast listeners who are interested in traffic to a given multicast destination address, so no listeners means nothing is transmitted.The default value of 16 is the max number of listeners before a classic flooding of all multicast frames is used, if it's equal or under 16, batman-adv can use individual unicast transmissions instead - that's the fanoutNOTE: Classic multicast flooding will still happen if: -- No IGMP/MLD querier -- The packet's destination is an IPv4 multicast -- The IPv6 multicast destination is ff02::1. |
network_coding | boolean | 1 | 0, 1 | Combine two packets into a single transmission, which saves air-time but requires: -- At least 3 nodes to be effective -- One node must act as a relay which has this option enabled -- Relay must support Promiscuous mode (both receive and send) -- Support MTU value of at least 1546. |
hop_penalty | boolean | 30 | not specified | Modify batman_adv's preference for multihop routes vs short routes, the value is applied to the TQ of each forwarded OGM, propagating the cost of an extra hop(packet must be received and re-transmitted), the higher it's the more unlikely other nodes will choose the current node as an intermediate hop towards any node, otherwise, a lower value will result in longer routes because re-transmissions aren't penalized. |
ap_isolation | boolean | 0 | 0, 1 | Standard WiFi APs support AP Isolation, which prevents clients communicating with each other, if the WiFi AP interface is bridged into batman-adv mesh network, it might be desirable to extend this isolation throughout the mesh by enabling this option. |
isolation_mark | string | 0x00000000/0x00000000 | 0, 1 | An extension of ap_isolation, it allows the user to decide which client is classified as isolated via firewall rules, increasing the flexibility of the isolation, batman-adv extracts the fwmark the firewall attached to each packet it receives through the soft-interface and decides based on that value if the source client is isolated or not, this value is defined as a value/mask, in the firewall, a simple case is to mark all the packets coming with a fwmark using tc, you then set the fwmark you've set with tc in this option for it to work. |
可能需要编译的选项是官方 BATMAN 文档中列出的需要编译的选项,OpenWrt 软件包 batman-adv 可能不需要编译,这取决于实际编译的内容。
BATMAN_IV使用 OGM 来确定链路质量并在网状网络中传播消息,但这种方法也有缺点:无线接口会随着时间的推移而出现丢包,最终导致更多开销(由于传输协议的原因);此外,最好能够更快地检测链路质量变化,而不是先将其传播到网状网络中(反正网状网络的远端也不关心);而且对于某些任务,或许可以避免使用 OGM。
BATMAN_V目前在现场似乎存在一些问题,但它是更好的算法,因为它引入了 ELP(回声定位协议),这是一种不会在用于邻居发现的网状网络中转发/重新广播的数据包。此外,它还使用 OGM v2 来进一步确定整体最佳传输路径,而任务分离正是降低开销的原因。邻居发现可以单独进行,并且可以减少多接口处理。最后,BATMAN_V 使用吞吐量作为指标,而不是像 BATMAN_IV 那样使用丢包率作为指标。
TQ -传输质量算法(Batman IV),用于通过查找节点的接收和发送质量来确定更好的路径,其中发送速度优先。TQ 是通过传播 OGM 消息并找到最佳路径来计算的。TQ 的值从最大值 255 开始(从 255 计数到 0),并通过每个节点重新计算 TQ 并将其传输到下一个节点,依此类推。
运行中
网内和网外接入
如上所述,当桥接 VLAN 时,如果一个节点桥接到有线网络,则网外客户端无需任何额外配置即可访问网内客户端,反之亦然。网外客户端还可以通过网状网络访问其他网外客户端(例如不同 AP 的客户端和/或有线网络上的客户端)。使用 BATMAN_IV 的五节点本地网状网络,初始 ping 请求通常会在一到两秒内返回。
多个节点桥接到同一网络段
目前尚未对使用桥接多个节点连接到同一有线网络的情况进行深入研究。STP或许可以作为一种“简易”方案,但也有案例表明,其他网络协议中涉及设备端交换机的桥接环路似乎无法仅靠 STP 检测和解决。
对五个已部署并参与 batman-adv 项目的 OpenWrt 节点中的两个进行快速测试,这两个节点通过 Cisco SG300 系列交换机连接到有线网络。拔掉“活动”网线后,大约 90 秒内发生“故障切换”,并且在接下来的半分钟内仍存在干扰。batctl cl声明表 (claim table) 的输出似乎也以大致相同的时间尺度清空和更新。OpenWrt 网桥中的 STP 配置为 hello_time 2.00 秒、max_age 20.00 秒和 forward_delay 2.00 秒,表明 STP 切换时间约为 26 秒。在一个节点上观察声明表,同时关闭bat0“首选网关”(不改变以太网连接),发现与关闭节点相关的声明在被移除前有大约一分钟的延迟。因此,目前认为这些延迟主要是由 batman-adv 的运行引起的。
batman-adv功能与广告网关相关。它似乎是为大规模部署而设计的,其工作原理似乎是通过调节DHCP分配,而不是通过网状路由逻辑本身动态路由数据包。
其他系统的日志充斥着内核信息:arp:43:05:43:05:00:00 是多播
batman-adv桥接环路避免协议似乎对 0.0.0.0 使用无偿 ARP,并设置了组播位,这被认定为“滥用 ARP 数据包”。一些符合RFC规范的系统会将此记录为错误,因为“安装此类条目违反了RFC 1812规范,但某些专有负载均衡技术要求路由器这样做。”
/etc/config/batman-adv禁用 桥接环路避免协议option bridge_loop_avoidance 0是解决此问题的一种方法,但如果这样做,强烈建议使用 STP 或其他环路避免方法。
对于 FreeBSD 和基于 FreeBSD 的系统,此设置应该会删除日志消息,但会像arp(4)net.link.ether.inet.allow_multicast=1中描述的那样“污染”ARP 表。
