OpenThread 边界路由器 (OTBR) 需要一个线程 RCP 节点才能加入线程网络。OTBR Docker 同时支持实体 RCP(OpenThread 加密狗)或模拟 RCP。
如果要将 OTBR Docker 连接到其他物理线程设备,请使用物理 RCP。如果要使用模拟线程网络测试边界路由,请使用模拟 RCP。
物理 RCP
为物理 RCP 使用任何受支持的 OpenThread 平台。如需了解详情,请参阅 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
为模拟 RCP 使用模拟 OpenThread RCP build。如果您想在单台机器上使用模拟线程网络测试边界路由,这会非常有用。
构建模拟 RCP 应用
克隆 OpenThread 代码库:
cd ~
git clone https://github.com/openthread/openthread
引导和构建模拟应用:
cd openthread
./bootstrap
./script/cmake-build 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/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 将会关闭。