运行 OTBR Docker

<ph type="x-smartling-placeholder"></ph> 在 GitHub 上查看源代码

OpenThread 边界路由器 (OTBR) 需要 Thread RCP 节点才能加入 Thread 网络。OTBR Docker 支持物理 RCP (OpenThread) 加密狗)或模拟 RCP。

如果要将 OTBR Docker 连接到其他物理 Thread 设备,请使用 物理 RCP。如果您想使用模拟线程测试边界路线 请使用模拟 RCP。

物理 RCP

将任何受支持的 OpenThread 平台用于 物理 RCP。请参阅构建并刷写 RCP 请参阅 OpenThread 边界路由器构建和配置指南中的步骤, 信息。

连接 RCP

  1. 构建并刷写后,将 RCP 设备连接到运行 通过 USB 访问 OTBR Docker。
  2. 通过检查 /dev 确定 RCP 设备的串行端口名称:
    ls /dev/tty*
    /dev/ttyACMO
    

启动 OTBR Docker 容器

otbr-agent

在新的终端窗口中,启动 OTBR Docker,并引用 RCP 的串行端口。 例如,如果将 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 build。如果您 您想要在单个 虚拟机。

构建模拟 RCP 应用

  1. 克隆 OpenThread 代码库:

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

  2. 引导并构建模拟应用:

    cd openthread
    ./script/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. 打开一个新的终端窗口,以运行模拟 RCP,因为它必须保留下来 在 OTBR Docker 运行时运行。

  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 输出。例如,如果使用 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 就会 。