Executar o OTBR Docker

Veja o código-fonte no GitHub

O OpenThread Border Router (OTBR) requer um nó RCP do Thread para participar de uma rede Thread. O Docker OTBR é compatível com um RCP físico (do Dongle ThreadThread) ou um RCP simulado.

Se você quiser conectar o Docker OTBR a outros dispositivos Thread físicos, use um RCP físico. Se você quiser testar o roteamento de borda com uma rede Thread simulada, use um RCP simulado.

RCP físico

Use qualquer plataforma OpenThread compatível para o RCP físico. Consulte a etapa Criar e atualizar RCP no guia de criação e configuração do roteador de borda do OpenThread para mais informações.

Anexar o RCP

  1. Depois de criar e atualizar, anexe o dispositivo RCP à máquina que executa o Docker OTBR via USB.
  2. Determine o nome da porta serial do dispositivo RCP verificando /dev:
    ls /dev/tty*
    /dev/ttyACMO
    

Iniciar o contêiner do Docker OTBR

Em uma nova janela do terminal, inicie o OTBR Docker, que faz referência à porta serial do RCP. Por exemplo, se o RCP estiver montado em /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

Após a conclusão, a saída será semelhante a esta:

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.

O Docker OTBR está em execução. Deixe essa janela do terminal aberta e em execução em segundo plano. Se você sair do processo ou fechar a janela, o Docker OTBR vai ser desativado.

Acesse Testar conectividade para continuar com a configuração do OTBR Docker.

RCP simulado

Use um build de RCP simulado do OpenThread para o RCP simulado. Isso é útil se você quiser testar o roteamento de borda com uma rede Thread simulada em uma única máquina.

Criar o aplicativo RCP simulado

  1. Clone o repositório do OpenThread:

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

  2. Inicialize e crie o aplicativo simulado:

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

Configurar um fluxo de dados bidirecional

Use o utilitário de linha de comando socat para estabelecer um fluxo de dados bidirecional para transferir dados entre o RCP simulado e o Docker OTBR.

  1. Abra uma nova janela do terminal para executar esse processo, já que ele precisa ficar em execução enquanto o OTBR Docker estiver em execução.

  2. Instale socat:

    sudo apt-get install socat
    

  3. Iniciar 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]
    

Anote as duas portas seriais em negrito na saída. Use o primeiro para o RCP simulado e o segundo para o Docker do OTBR. No exemplo de saída acima:

  • /dev/pts/2 = porta RCP simulada
  • /dev/pts/7 = OTBR Docker

Deixe essa janela do terminal aberta e em execução em segundo plano.

Iniciar o RCP simulado

  1. Abra uma nova janela do terminal para executar o RCP simulado, já que ele precisa ficar em execução enquanto o Docker OTBR está em execução.

  2. Usando a primeira porta serial na saída socat, inicie o aplicativo RCP simulado. Por exemplo, se estiver usando /dev/pts/2 da saída socat:

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

Não há saída nesse comando. Deixe essa janela do terminal aberta e em execução em segundo plano.

Iniciar o contêiner do Docker OTBR

Em uma nova janela do terminal, inicie o Docker OTBR usando a segunda porta serial na saída socat. Por exemplo, se estiver usando /dev/pts/7 da saída socat:

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

O comando também está usando a porta /dev/ttyUSB0. Esse é o ponto de ativação padrão no contêiner do Docker.

Após a conclusão, a saída será semelhante a esta:

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.

O Docker OTBR está em execução. Deixe essa janela do terminal aberta e em execução em segundo plano. Se você sair do processo ou fechar a janela, o Docker OTBR vai ser desativado.