Google is committed to advancing racial equity for Black communities. See how.
本頁面由 Cloud Translation API 翻譯而成。
Switch to English

運行OTBR Docker

OpenThread邊界路由器(OTBR)需要線程RCP節點才能加入線程網絡。 OTBR Docker支持物理RCP(OpenThread軟件狗)或模擬RCP。

如果要將OTBR Docker連接到其他物理線程設備,請使用物理RCP。如果要使用模擬線程網絡測試邊界路由,請使用模擬RCP。

物理RCP

將任何受支持的OpenThread平台用於物理RCP。有關更多信息,請參閱《 OpenThread邊界路由器構建和配置指南》中的“構建和刷新RCP”步驟。

附加RCP

  1. 構建並刷新後,通過USB將RCP設備連接到運行OTBR Docker的計算機。
  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

將模擬的OpenThread RCP構建用於模擬的RCP。如果要在一台計算機上使用模擬線程網絡測試邊界路由,這將很有用。

生成模擬的RCP應用程序

  1. 克隆OpenThread存儲庫:
    cd ~
    git clone https://github.com/openthread/openthread
  2. 引導並構建模擬的應用程序:
    cd openthread
    ./bootstrap
    make -f examples/Makefile-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/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將會關閉。