OTBR Docker 실행

GitHub에서 소스 보기

OTBR (OpenThread Border Router)는 스레드 네트워크에 참여하기 위해 스레드 RCP 노드가 필요합니다. OTBR Docker는 물리적 RCP (OpenThread 동글) 또는 시뮬레이션된 RCP를 모두 지원합니다.

OTBR Docker를 다른 실제 스레드 기기에 연결하려면 실제 RCP를 사용하세요. 시뮬레이션된 스레드 네트워크에서 테두리 라우팅을 테스트하려면 시뮬레이션된 RCP를 사용하세요.

실제 RCP

실제 RCP에 지원되는 OpenThread 플랫폼을 사용합니다. 자세한 내용은 OpenThread Border Router 빌드 및 구성 가이드의 빌드 및 플래시 RCP 단계를 참고하세요.

RCP 첨부

  1. 빌드 및 플래시 후 USB를 통해 OTBR Docker를 실행하는 머신에 RCP 기기를 연결합니다.
  2. /dev를 확인하여 RCP 기기의 직렬 포트 이름을 확인합니다.
    ls /dev/tty*
    /dev/ttyACMO
    

OTBR Docker 컨테이너 시작

새 터미널 창에서 RCP 직렬 포트를 참조하는 OTBR Docker를 시작합니다. 예를 들어 RCP가 /dev/ttyACM0에 마운트되는 경우 다음을 충족해야 합니다.

docker run --sysctl "net.ipv6.conf.all.disable_ipv6=0 net.ipv4.conf.all.forwarding=1 net.ipv6.conf.all.forwarding=1" -p 8080:80 --dns=127.0.0.1 -it --volume /dev/ttyACM0:/dev/ttyACM0 --privileged openthread/otbr --radio-url spinel+hdlc+uart:///dev/ttyACM0

성공하면 다음과 비슷한 출력이 표시됩니다.

WARNING: Localhost DNS setting (--dns=127.0.0.1) may fail in containers.
RADIO_URL: spinel+hdlc+uart:///dev/ttyACM0
TUN_INTERFACE_NAME: wpan0
NAT64_PREFIX: 64:ff9b::/96
AUTO_PREFIX_ROUTE: true
AUTO_PREFIX_SLAAC: true
Current platform is ubuntu
* Applying /etc/sysctl.d/10-console-messages.conf ...
kernel.printk = 4 4 1 7
* Applying /etc/sysctl.d/10-ipv6-privacy.conf ...
net.ipv6.conf.all.use_tempaddr = 2
net.ipv6.conf.default.use_tempaddr = 2
* Applying /etc/sysctl.d/10-kernel-hardening.conf ...
kernel.kptr_restrict = 1
* Applying /etc/sysctl.d/10-link-restrictions.conf ...
fs.protected_hardlinks = 1
fs.protected_symlinks = 1
* Applying /etc/sysctl.d/10-magic-sysrq.conf ...
kernel.sysrq = 176
* Applying /etc/sysctl.d/10-network-security.conf ...
net.ipv4.conf.default.rp_filter = 1
net.ipv4.conf.all.rp_filter = 1
net.ipv4.tcp_syncookies = 1
* Applying /etc/sysctl.d/10-ptrace.conf ...
kernel.yama.ptrace_scope = 1
* Applying /etc/sysctl.d/10-zeropage.conf ...
vm.mmap_min_addr = 65536
* Applying /etc/sysctl.d/60-otbr-ip-forward.conf ...
net.ipv6.conf.all.forwarding = 1
net.ipv4.ip_forward = 1
* Applying /etc/sysctl.conf ...
 * Starting userspace NAT64 tayga             [ OK ]
/usr/sbin/service
 * Starting domain name service... bind9      [ OK ]
/usr/sbin/service
 * dbus is not running
 * Starting system message bus dbus           [ OK ]
   ...fail!
otWeb[155]: border router web started on wpan0
otbr-agent[224]: Thread interface wpan0
otbr-agent[224]: Thread is down
otbr-agent[224]: Check if Thread is up: OK
otbr-agent[224]: Stop publishing service
otbr-agent[224]: PSKc is not initialized
otbr-agent[224]: Check if PSKc is initialized: OK
otbr-agent[224]: Initialize OpenThread Border Router Agent: OK
otbr-agent[224]: Border router agent started.

OTBR Docker가 실행 중입니다. 이 터미널 창을 열어 두고 백그라운드에서 실행합니다. 프로세스를 종료하거나 창을 닫으면 OTBR Docker가 종료됩니다.

연결 테스트로 이동하여 OTBR Docker 설정을 계속 진행합니다.

시뮬레이션된 RCP

시뮬레이션된 RCP에 시뮬레이션된 OpenThread RCP 빌드를 사용합니다. 이는 단일 머신에서 시뮬레이션된 스레드 네트워크를 사용하여 테두리 라우팅을 테스트하려는 경우에 유용합니다.

시뮬레이션된 RCP 애플리케이션 빌드

  1. OpenThread 저장소 클론:

    cd ~
    git clone https://github.com/openthread/openthread
    

  2. 시뮬레이션된 애플리케이션 부트스트랩 및 빌드:

    cd openthread
    ./bootstrap
    ./script/cmake-build simulation
    

양방향 데이터 스트림 설정

socat 명령줄 유틸리티를 사용하여 양방향 데이터 스트림을 시뮬레이션한 시뮬레이션된 RCP 및 OTBR Docker 간에 전송합니다.

  1. OTBR Docker가 실행되는 동안 실행이 유지되어야 하므로 새 터미널 창을 열어 이 프로세스를 실행합니다.

  2. socat를 설치합니다.

    sudo apt-get install socat
    

  3. socat 시작:

    socat -d -d pty,raw,echo=0 pty,raw,echo=0
    2018/09/06 09:58:29 socat[242994] N PTY is /dev/pts/2
    2018/09/06 09:58:29 socat[242994] N PTY is /dev/pts/7
    2018/09/06 09:58:29 socat[242994] N starting data transfer loop with FDs [5,5] and [7,7]
    

출력에서 굵게 표시된 두 개의 직렬 포트를 확인합니다. 첫 번째는 시뮬레이션된 RCP에, 두 번째는 OTBR Docker에 사용됩니다. 위의 출력 예는 다음과 같습니다.

  • /dev/pts/2 = 시뮬레이션된 RCP 포트
  • /dev/pts/7 = OTBR Docker

이 터미널 창을 열어 두고 백그라운드에서 실행되도록 합니다.

시뮬레이션된 RCP 시작

  1. OTBR Docker가 실행되는 동안은 실행 상태로 두어야 하므로 시뮬레이션된 RCP를 실행하기 위해 새 터미널 창을 엽니다.

  2. socat 출력의 첫 번째 직렬 포트를 사용하여 시뮬레이션된 RCP 애플리케이션을 시작합니다. 예를 들어 socat 출력에서 /dev/pts/2를 사용하는 경우:

    ~/openthread/build/simulation/examples/apps/ncp/ot-rcp 1 > /dev/pts/2 < /dev/pts/2
    

이 명령어에서는 출력이 없습니다. 이 터미널 창을 열어 두고 백그라운드에서 실행합니다.

OTBR Docker 컨테이너 시작

새 터미널 창에서 socat 출력의 두 번째 직렬 포트를 사용하여 OTBR Docker를 시작합니다. 예를 들어 socat 출력에서 /dev/pts/7를 사용하는 경우:

docker run --sysctl "net.ipv6.conf.all.disable_ipv6=0 net.ipv4.conf.all.forwarding=1 net.ipv6.conf.all.forwarding=1" -p 8080:80 --dns=127.0.0.1 -it --volume /dev/pts/7:/dev/ttyUSB0 --privileged openthread/otbr

이 명령어는 /dev/ttyUSB0 포트도 사용합니다. 이는 Docker 컨테이너 내의 기본 마운트 지점입니다.

성공하면 다음과 비슷한 출력이 표시됩니다.

WARNING: Localhost DNS setting (--dns=127.0.0.1) may fail in containers.
RADIO_URL: spinel+hdlc+uart:///dev/ttyUSB0
TUN_INTERFACE_NAME: wpan0
NAT64_PREFIX: 64:ff9b::/96
AUTO_PREFIX_ROUTE: true
AUTO_PREFIX_SLAAC: true
Current platform is ubuntu
* Applying /etc/sysctl.d/10-console-messages.conf ...
kernel.printk = 4 4 1 7
* Applying /etc/sysctl.d/10-ipv6-privacy.conf ...
net.ipv6.conf.all.use_tempaddr = 2
net.ipv6.conf.default.use_tempaddr = 2
* Applying /etc/sysctl.d/10-kernel-hardening.conf ...
kernel.kptr_restrict = 1
* Applying /etc/sysctl.d/10-link-restrictions.conf ...
fs.protected_hardlinks = 1
fs.protected_symlinks = 1
* Applying /etc/sysctl.d/10-magic-sysrq.conf ...
kernel.sysrq = 176
* Applying /etc/sysctl.d/10-network-security.conf ...
net.ipv4.conf.default.rp_filter = 1
net.ipv4.conf.all.rp_filter = 1
net.ipv4.tcp_syncookies = 1
* Applying /etc/sysctl.d/10-ptrace.conf ...
kernel.yama.ptrace_scope = 1
* Applying /etc/sysctl.d/10-zeropage.conf ...
vm.mmap_min_addr = 65536
* Applying /etc/sysctl.d/60-otbr-ip-forward.conf ...
net.ipv6.conf.all.forwarding = 1
net.ipv4.ip_forward = 1
* Applying /etc/sysctl.conf ...
 * Starting userspace NAT64 tayga             [ OK ]
/usr/sbin/service
 * Starting domain name service... bind9      [ OK ]
/usr/sbin/service
 * dbus is not running
 * Starting system message bus dbus           [ OK ]
   ...fail!
otWeb[155]: border router web started on wpan0
otbr-agent[224]: Thread interface wpan0
otbr-agent[224]: Thread is down
otbr-agent[224]: Check if Thread is up: OK
otbr-agent[224]: Stop publishing service
otbr-agent[224]: PSKc is not initialized
otbr-agent[224]: Check if PSKc is initialized: OK
otbr-agent[224]: Initialize OpenThread Border Router Agent: OK
otbr-agent[224]: Border router agent started.

OTBR Docker가 실행 중입니다. 이 터미널 창을 열어 두고 백그라운드에서 실행합니다. 프로세스를 종료하거나 창을 닫으면 OTBR Docker가 종료됩니다.