OpenWrt batman-adv 로 mesh 구성하기

OpenWrt를 사용하여 mesh network를 만드는 방법과 메시의 라우팅 프로토콜인 batman-adv 를 설정하는 방법입니다.

일러두기

  • 메쉬는 node끼리 통신하기 위한 전용 터널(backhaul)이지 AP가 아닙니다. 따라서 클라이언트가 직접 메쉬 네트워크로 접속할 수 없습니다.
  • 제가 가지고 있는 라우터가 2개밖에 없어 테스트용으로 라우터 2개(gateway, bridge)만으로 메쉬를 구성하였습니다. 그러나 라우터 2개로는 메쉬 의미가 없으며 이 둘이 이더넷 케이블로 연결된 경우 메쉬 설정이 필요없습니다. 이런 경우 빠른 로밍 (802.11r)이 필요하며 백홀용 이더넷 케이블이 있기 때문에 일반적으로 메쉬보다 간단하고 성능이 뛰어납니다.
  • 이 글에 앞서 빠른 로밍을 설정 해둔 상태라면 mesh 테스트를 위해 빠른 로밍 설정을 끄고 로밍없는 AP로 전환하십시요.

메쉬 구성도

mesh topology

사전준비

  • OpenWrt로 플래시된 라우터 적어도 3개 이상(2개는 메쉬의 의미가 없습니다.)
  • 초기 메쉬 패키지 설치를 위해 gateway node를 제외한 다른 node는 Dumb AP 구성이 되어 있어야 합니다.

노드 구성예

  1. lan 환경
    • subnet : 192.168.1.0/24
    • mask : 255.255.255.0
    • gateway : 192.168.1.1
    • dhcp : 192.168.1.100~250
  2. 메쉬 노드 구성
    • device : radio1 (2.4ghz channel 11)
    • mode : mesh (ieee 802.11s)
    • ssid : mesh
    • encryption: wpa3
    • password : $tr0ngP@ssw0rd
    • subnnet : 192.168.33.0/24
  3. ap 구성(추후 빠른로밍으로 구성)
    • device : radio0 (5.0ghz channel 36/157)
    • ssid : OpenWrt50
    • network : nowire

메쉬 지원여부 확인

대부분 초기 OpenWrt 설치시 탑재된 모든 드라이버/펌웨어가 802.11s 메쉬 (또는 IBSS)를 지원하는 것으로 보이지만 모두 지원하는 것은 아닙니다. iw 명령으로 "mesh point"(또는 "IBSS")를 찾아서 메쉬 지원여부를 확인합니다.

iw list | grep -xi "^wiphy.*\|.* ibss$\|.* mesh point$"

rroot@home:~# iw list | grep -xi "^wiphy.*\|.* ibss$\|.* mesh point$"
Wiphy phy1
                 * IBSS
                 * mesh point
Wiphy phy0
                 * IBSS
                 * mesh point
root@home:~#

메쉬를 지원하지 않는 드라이버/펌웨어일 경우

OpenWrt 처음 설치시 탑재된 *-ct 드라이버/펌웨어가 메쉬를 지원하지 않는 경우 "클래식 드라이버/펌웨어"(-ct 없음)이 지원하는 경우일 수 있습니다.

다음은 Qualcom Atheros QCA988x 칩 제품 mac802.11 무선 드라이버를 사용하는 라우터의 예시입니다. 먼저 가지고 있는 라우터의 무선 칩셋 정보를 파악한 후 아래 예시처럼 현재 내 라우터에 설치되어 있는 드라이버/펌웨어 확인하고 -ct 없는 드라이버/펌웨어 설치 및 재부팅하여 와이파이 상태와 메쉬지원 여부를 다시 확인합니다. (드라이버/펌웨어를 다시 설치하면 와이파이가 안 될 수 있습니다. 이럴경우 와이파이는 luci에서 설정이나 작동여부를 확인하고 설정을 조정후에는 다시한번 재부팅해 보세요. 그럼에도 와이파이가 이상이 있거나 메쉬지원이 안되면 최초 드라이버/펌웨어로 롤백한 후 재부팅하면 원래 상태로 돌아옵니다. 이 작업은 와이파이가 이상이 있을 경우를 대비해 라우터와 PC간 이더넷 케이블로 연결된 상태에서 진행하세요. 이렇게 해도 메쉬지원이 안될 경우 forum.openwrt.org 의 지원이나 정확한 칩셋 정보를 확인하세요.)

opkg list-installed | grep ath10k
ath10k-firmware-qca9984-ct - 2020-07-02-1
kmod-ath10k-ct - 4.14.195+2019-09-09-5e8cd86f-1

opkg update
......
......

opkg remove ath10k-firmware-qca9984-ct kmod-ath10k-ct
opkg install ath10k-firmware-qca9984 kmod-ath10k
reboot

패키지 설치

모든 노드(gateway 및 bridge node 포함)에 아래 패키지를 설치합니다.

opkg update
opkg install batctl-full
opkg install kmod-batman-adv
opkg remove wpad-basic-wolfssl
opkg install wpad-wolfssl

메쉬 node 기본구성(공통)

모든 node의 네트워크 및 와이파이 설정을 각각 아래와 같이 합니다.

/etc/config/wireless를 아래와 같이 수정(추가)해 batman-adv가 실행될 메쉬를 구성합니다.

  • wmesh 인터페이스를 추가합니다.(mesh_id, key, encryption은 모든 노드가 같아야 합니다.)
  • wmesh의 device는 여기서는 2.4ghz channel 11로 하였습니다.(모든 node의 hwmode와 channel은 동일해야 합니다.)
  • 그리고 기존에 있던 default_radio1 (2.4g)인터페이스는 메쉬로 사용할 것으므로 주석처리하여 AP를 사용하지 않게 하였습니다.(radio* 이 2.4g에 대응하는지 5g에 대응하는지는 기종 마다 차이가 있을 수 있습니다.)
  • 만약 메쉬와 별도로 2.4ghz 주파수 대역의 wifi AP를 제공하고 싶다면 default_radio1 주석처리 하지 않으면 됩니다.
  • 마지막으로 ap로 사용할 5g 네트워크 존을 lan에서 batman으로 바꾸어 줍니다.
config wifi-device 'radio0'
        ...
        option channel '36'
        option band '5g'

config wifi-iface 'default_radio0'
        ...
        option device 'radio0'
        option network 'batman'
        option ssid 'OpenWrt50'

config wifi-device 'radio1'
        ...
        option channel '11'
        option band '2g'

#config wifi-iface 'default_radio1'
#       option device 'radio1'
#       option network 'lan'
#       option mode 'ap'
#       option ssid 'OpenWrt24'
#       option encryption 'psk2+ccmp'
#       option key '$tr0ngP@ssw0rd'

config wifi-iface 'wmesh'
        option device 'radio1'
        option network 'bat0_hardif'
        option mode 'mesh'
        option mesh_id 'mesh'
        option mesh_fwding '0'
        option mesh_ttl '1'
        option mcast_rate '24000'
        option encryption 'sae'
        option key '$tr0ngP@ssw0rd'

batman 인터페이스를 생성하기 위해 /etc/config/network 를 아래와 같이 추가합니다.

  • 메쉬를 통해 트래픽을 라우팅하기위한 batman-adv 인터페이스 bat0와 하드인터페이스를 만듭니다.
...
config interface 'bat0'
        option proto 'batadv'
        option routing_algo 'BATMAN_IV'
        option aggregated_ogms '1'
        option ap_isolation '0'
        option bonding '0'
        option fragmentation '1'
        option gw_mode 'off'
        option log_level '0'
        option orig_interval '1000'
        option bridge_loop_avoidance '1'
        option distributed_arp_table '1'
        option multicast_mode '1'
        option multicast_fanout '16'
        option network_coding '0'
        option hop_penalty '30'
        option isolation_mark '0x00000000/0x00000000'

config interface 'bat0_hardif'
        option proto 'batadv_hardif'
        option master 'bat0'
        option mtu '1536'

재부팅 후 확인

라우터를 재부팅 후 batman 인터페이스가 작동하는지 확인합니다.

reboot
......
ip link | grep bat0
batctl if

root@home:~# ip link | grep bat0
60: bat0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue master br-mesh state UNKNOWN mode DEFAULT group default qlen 1000
69: wlan0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1536 qdisc noqueue master bat0 state UP mode DORMANT group default qlen 1000
root@home:~# batctl if
wlan1: active
root@home:~#

모든 node의 설정을 마친 후 각각의 node에서 이웃하는 메쉬 node를 확인합니다. 아래처럼 이웃하는 node의 정보가 나와야 정상입니다. 응답하지 않으면 구성에 문제가 있는것으므로 설정을 다시 확인하고 재부팅하세요.(아래 예시는 라우터 2개로 메쉬를 구성하여 이웃하는 node가 1개만 보입니다.)

batctl n
iw dev <ifname> station dump
batctl ping <MAC addr>

root@home:~#
root@home:~# batctl n
[B.A.T.M.A.N. adv openwrt-2019.2-9, MainIF/MAC: mesh0/78:xx:xx:xx:xx:xx (bat0/46:xx:xx:xx:xx:xx BATMAN_IV)]
IF             Neighbor              last-seen
        wlan1     bc:xx:xx:xx:xx:xx    0.790s
root@home:~#
root@home:~# iw dev wlan1 station dump
Station bc:xx:xx:xx:xx:xx (on mesh0)
        inactive time:  40 ms
        rx bytes:       8621059
        rx packets:     81755
        tx bytes:       361570
        tx packets:     3234
        tx retries:     0
        tx failed:      0
        rx drop misc:   21475
        signal:         -42 [-49, -55, -46, -47] dBm
        signal avg:     -40 [-47, -52, -44, -45] dBm
        Toffset:        18446744064360292497 us
        tx bitrate:     288.9 MBit/s MCS 31 short GI
        rx bitrate:     260.0 MBit/s MCS 31
        rx duration:    76265414 us
        last ack signal:-40 dBm
        mesh llid:      0
        mesh plid:      0
        mesh plink:     ESTAB
        mesh local PS mode:     ACTIVE
        mesh peer PS mode:      ACTIVE
        mesh non-peer PS mode:  ACTIVE
        authorized:     yes
        authenticated:  yes
        associated:     yes
        preamble:       long
        WMM/WME:        yes
        MFP:            yes
        TDLS peer:      no
        DTIM period:    2
        beacon interval:100
        connected time: 2846 seconds
root@home:~#
root@home:~# batctl ping bc:xx:xx:xx:xx:xx
PING bc:xx:xx:xx:xx:xx (bc:xx:xx:xx:xx:xx) 20(48) bytes of data
20 bytes from bc:xx:xx:xx:xx:xx icmp_seq=1 ttl=50 time=5.07 ms
20 bytes from bc:xx:xx:xx:xx:xx icmp_seq=2 ttl=50 time=3.35 ms
20 bytes from bc:xx:xx:xx:xx:xx icmp_seq=3 ttl=50 time=1.78 ms
^C--- bc:xx:xx:xx:xx:xx ping statistics ---
3 packets transmitted, 3 received, 0% packet loss
rtt min/avg/max/mdev = 1.776/3.397/5.070/1.345 ms
root@home:~#

여기까지 하면 모든 메쉬 노드가 서로 연결된 상태입니다.

gateway node 구성

네트워크 구성

메쉬 네트워크는 브릿지 설정 및 lan네트워크와 분리하고 ip를 부여하기 위해 /etc/config/network 에 다음과 같이 추가합니다.

...
config device
        option name 'br-bat0'
        option type 'bridge'
        option stp '1'
        list ports 'bat0'

config interface 'batman'
        option device 'br-bat0'
        option proto 'static'
        option ipaddr '192.168.33.1'
        option netmask '255.255.255.0'
        option ipv6 '0'
        option delegate '0'

방화벽 구성

/etc/config/firewall

...
config zone
        option name 'wlan'
        option input 'ACCEPT'
        option output 'ACCEPT'
        option forward 'REJECT'
        list network 'batman'

config forwarding
        option src 'wlan'
        option dest 'lan'

config forwarding
        option src 'wlan'
        option dest 'wan'
...

DHCP 구성

ap에 연결된 장치가 192.168.33.0/24 의 ip를 부여 받을 수 있도록 dhcp를 구성합니다.

/etc/config/dhcp

...
config dhcp 'batman'
        option interface 'batman'
        option start '50'
        option limit '100'
        option leasetime '12h'
        option dhcpv4 'server'
        option dhcpv6 'disabled'
        list ra_flags 'none'

bridge node 구성

네트워크 구성

bridge 노드의 /etc/config/network를 다음과 같이 수정합니다.

...
config device
        option name 'br-bat0'
        option type 'bridge'
        option stp '1'
        list ports 'bat0'

config interface 'batman'
        option device 'br-bat0'
        option proto 'static'
        option ipaddr '192.168.33.2'
        option netmask '255.255.255.0'
        option gateway '192.168.33.1'
        list dns '192.168.33.1'
        option ipv6 '0'
        option delegate '0'

서비스 재시작

/etc/init.d/firewall restart
/etc/init.d/dnsmasq restart
/etc/init.d/network restart

확인

네트워크 재시작 후 Dumb AP로 구성되어 있는 상태에서 이더넷 케이블을 제거하고 bridge node에서 AP로 작동중인 wifi로 접속 후 ping 으로 노드와 인터넷 접속여부를 확인합니다.

ifconfig | grep 192
ping 192.168.33.1
ping 1.1.1.1

ping 응답 확인이 되면 메쉬설정이 완료된 것입니다. (가능하면 각 노드는 이더넷 케이블은 연결해 유선환경을 만드는걸 추천합니다. 저 같은 경우 무선 메쉬환경에서 속도가 만족스럽지 않네요)

마지막으로 위의 "메쉬 구성도" 완성을 위해 AP에 대한 빠른로밍 설정을 하세요.

추가정보

luci > network > interface 에서 bat0, if_mesh0 확인해보면 아래처럼 Unsupported protocol type 라고 나오는데 이것은 luci에서 지원하지 않아서 나타나는 현상으로 에러가 아니므로 무시하시면 됩니다. 또는 아직 정식 저장소에 올라오지는 않았지만 이것을 따로 설치하면 luci를 이용할 수 있습니다.

luci err message(unsupported protocol type)

참고사이트

Comments

No comments yet. Why don’t you start the discussion?

답글 남기기

이메일 주소는 공개되지 않습니다. 필수 필드는 *로 표시됩니다