OpenThread 边界路由器 (OTBR) 需要线程 RCP 节点才能加入线程网络。OTBR Docker 同时支持物理 RCP (OpenThread 加密狗) 或模拟 RCP。
如果要将 OTBR Docker 连接到其他物理线程设备,请使用物理 RCP。如果要使用模拟线程网络测试边界路由,请使用模拟 RCP。
物理 RCP
使用任何受支持的 OpenThread 平台作为物理 RCP。如需了解详情,请参阅 OpenThread 边界路由器构建和配置指南中的构建和刷写 RCP 步骤。
连接 RCP
- 构建并刷写后,通过 USB 将 RCP 设备连接到运行 OTBR Docker 的机器。
- 通过检查
/dev
,确定 RCP 设备的串行端口名称:ls /dev/tty*
/dev/ttyACMO
启动 OTBR Docker 容器
在新的终端窗口中,启动 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
将模拟 OpenThread RCP build 用于模拟 RCP。如果您要使用单个线程上的模拟线程网络测试边界路由,这会很有用。
构建模拟 RCP 应用
克隆 OpenThread 代码库:
cd ~
git clone https://github.com/openthread/openthread
引导和构建模拟应用:
cd openthread
./bootstrap
make -f examples/Makefile-simulation
设置双向数据流
使用 socat
命令行实用程序建立双向数据流,以在模拟 RCP 和 OTBR Docker 之间转移数据。
打开一个新的终端窗口来运行此过程,因为它必须在 OTBR Docker 运行时保持运行。
安装
socat
:sudo apt-get install socat
启动
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
打开新的终端窗口来运行模拟 RCP,因为它必须在 OTBR Docker 运行时保持运行。
使用
socat
输出中的第一个串行端口,启动模拟 RCP 应用。例如,如果使用socat
输出中的/dev/pts/2
:~/openthread/output/simulation/bin/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 将关闭。