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

OpenWeave工具

jinja-placeholder-0 /index.md“> 在GitHub上查看源代碼

OpenWeave包括一組用於配置,管理和測試OpenWeave部署的命令行工具。

建立編織工具

weave-tools目標將構建用於分發的精選Weave命令行工具的tar存檔。它包括以下工具:

工具描述 獨立構建位置
gen-qr-code 產生QR碼 /src/tools/misc
mock-device 通用編織設備模擬器 /src/test-apps
weave 生成和管理編織證書 /src/tools/weave
weave-device-descriptor 編碼和解碼Weave設備描述符字符串以配對QR碼 /src/test-apps
weave-device-mgr 管理設備配對過程 /src/device-manager/python
weave-heartbeat 發送和接收“ 心跳” 個人資料消息 /src/test-apps
weave-key-export 發送密鑰導出請求 /src/test-apps
weave-ping 發送和接收Echo 配置文件消息 /src/test-apps

要建立目標:

  1. 安裝所有構建先決條件
  2. 在沒有BlueZ支持的情況下配置OpenWeave:
     cd <path-to-openweave-core>
    ./configure --without-bluez 
  3. 使weave-tools目標:
     make weave-tools 
  4. 檢查tar存檔的根openweave-core目錄:
     ls weave*
        weave-tools-x86_64-unknown-linux-gnu-4.0d.tar.gz

gen-qr碼

gen-qr-code工具需要Python qrcode模塊。使用pip進行安裝:

 pip install --user qrcode

使用gen-qr-code生成QR碼以進行設備配對。該工具的輸入必須位於本地文件中。例如,要生成將用戶發送到https://www.google.com的QR碼:

  1. 創建一個帶有QR碼字符串的文件:
     echo "https://www.google.com" >> ~/ow_qrcode 
  2. 生成該字符串的64x64 QR代碼:
     ./gen-qr-code -v 1 -s 64 < ~/ow_qrcode 
  3. 要將QR碼另存為圖像,請指定輸出文件:
     ./gen-qr-code -v 1 -s 64 < ~/ow_qrcode > ~/ow_qrcode.png
    Use the weave-device-descriptor tool to generate the device descriptor string
    for use in a Weave device's pairing QR code.

模擬設備

mock-device工具模擬通用的Weave節點。其他工具和測試用例腳本使用此工具來封裝Weave功能。實例化各個Happy節點上的模擬設備,以在模擬拓撲中測試Weave功能。

例如,要啟動偵聽fd00:0:1:1::1的IPv6地址的Weave模擬設備,請首先將該IPv6地址添加到lo (回送)接口:

 sudo ifconfig lo add fd00:0:1:1::1/64

然後啟動Weave模擬設備:

 ./mock-device -a fd00:0:1:1::1
WEAVE:ML: Binding IPv6 TCP listen endpoint to [fd00:0:1:1::1]:11095
WEAVE:ML: Listening on IPv6 TCP endpoint
WEAVE:ML: Binding general purpose IPv4 UDP endpoint to [::]:11095
WEAVE:IN: IPV6_PKTINFO: 92
WEAVE:ML: Binding general purpose IPv6 UDP endpoint to [fd00:0:1:1::1]:11095 (lo)
WEAVE:ML: Listening on general purpose IPv6 UDP endpoint
WEAVE:ML: Binding IPv6 multicast receive endpoint to [ff02::1]:11095 (lo)
WEAVE:ML: Listening on IPv6 multicast receive endpoint
WEAVE:EM: Cannot listen for BLE connections, null BleLayer
Weave Node Configuration:
  Fabric Id: 1
  Subnet Number: 1
  Node Id: 1
WEAVE:SD: init()
Weave Node Configuration:
  Fabric Id: 1
  Subnet Number: 1
  Node Id: 1
  Listening Addresses:
      fd00:0:1:1::1 (ipv6)
  Pairing Server: fd00:0:1:1::1
Mock Time Sync is disabled and not initialized
Mock System Time Offset initialized to: 3.213773 sec
Listening for requests...
Weave Node ready to service events; PID: 256904; PPID: 251571

使用--help標誌可查看所有可用的配置選項。

編織設備描述符

weave-device-descriptor工具對設備描述符字符串進行編碼或解碼。這些字符串包含已編碼到其Weave配對QR碼中的設備的標識信息。使用--help標誌和encodedecode選項可獲取更多信息。

 ./weave-device-descriptor encode --help
./weave-device-descriptor decode --help

編碼

例如,要使用以下標識信息對設備描述符字符串進行編碼,請使用適當的標誌和值:

領域
供應商ID -V 1
產品編號 -p 1
產品修訂號 -r 2
序列號 -s 18B4300000000004
生產日期 -m 2018/05/02
802.15.4 MAC地址(線程,BLE) -8 000D6F000DA80466
配對碼 -P AB713H
 ./weave-device-descriptor encode -V 1 -p 1 -r 2 -s 18B4300000000004 -m 2018/05/02 \
                                   -8 000D6F000DA80466 -w 5CF370800E77 -P AB713H
1V:1$P:1$R:2$D:180502$S:18B4300000000004$L:000D6F000DA80466$W:5CF370800E77$C:AB713H$

將此輸出字符串與gen-qr-code工具一起使用以生成QR碼。

解碼

使用decode選項可解碼設備描述符字符串的元素。要解碼的元素具有以下語法:

1 + <device-descriptor-element> + $

例如,要解碼W:5CF370800E77設備描述符元素:

 ./weave-device-descriptor decode 1W:5CF370800E77$
Primary WiFi MAC: 5C:F3:70:80:0E:77

編織心跳

使用weave-heartbeat在兩個Weave節點之間發送和接收Heartbeat 配置文件消息。心跳提供了一種方法,可以指示一個節點對網絡中的其他節點的活動狀態,或者檢查某個節點是否保持與結構的連接。

成功的心跳需要一個節點充當服務器(偵聽並響應心跳),並且一個節點充當客戶端(發送心跳)。

使用回送接口模擬兩個節點,測試weave-heartbeat工具:

  1. 將每個心跳節點要使用的IPv6地址添加到lo (環回)接口:
     sudo ifconfig lo add fd00:0:1:1::1/64
    sudo ifconfig lo add fd00:0:1:1::2/64 
  2. fd00:0:1:1::1地址上啟動Heartbeat服務器,並為其分配node-id 1:

     ./weave-heartbeat --node-addr fd00:0:1:1::1 --node-id 1 --listen
        WEAVE:ML: Binding IPv6 TCP listen endpoint to [fd00:0:1:1::1]:11095
        WEAVE:ML: Listening on IPv6 TCP endpoint
        WEAVE:ML: Binding general purpose IPv4 UDP endpoint to [::]:11095
        WEAVE:IN: IPV6_PKTINFO: 92
        WEAVE:ML: Binding general purpose IPv6 UDP endpoint to [fd00:0:1:1::1]:11095 (lo)
        WEAVE:ML: Listening on general purpose IPv6 UDP endpoint
        WEAVE:ML: Binding IPv6 multicast receive endpoint to [ff02::1]:11095 (lo)
        WEAVE:ML: Listening on IPv6 multicast receive endpoint
        WEAVE:EM: Cannot listen for BLE connections, null BleLayer
        Weave Node Configuration:
          Fabric Id: 1
          Subnet Number: 1
          Node Id: 1
          Listening Addresses:
              fd00:0:1:1::1 (ipv6)
        Listening for Heartbeats...
        Weave Node ready to service events; PID: 170883; PPID: 170418

  3. 打開第二個終端窗口,並在fd00:0:1:1::2 IPv6地址( node-id為2且第一個節點的IPv6地址作為Heartbeat的目的地)上啟動Heartbeat客戶端:

     ./weave-heartbeat --node-addr fd00:0:1:1::2 --node-id 2 --dest-addr fd00:0:1:1::1 1
        WEAVE:ML: Binding IPv6 TCP listen endpoint to [fd00:0:1:1::2]:11095
        WEAVE:ML: Listening on IPv6 TCP endpoint
        WEAVE:ML: Binding general purpose IPv4 UDP endpoint to [::]:11095
        WEAVE:IN: IPV6_PKTINFO: 92
        WEAVE:ML: Binding general purpose IPv6 UDP endpoint to [fd00:0:1:1::2]:11095 (lo)
        WEAVE:ML: Listening on general purpose IPv6 UDP endpoint
        WEAVE:ML: Binding IPv6 multicast receive endpoint to [ff02::1]:11095 (lo)
        WEAVE:ML: Listening on IPv6 multicast receive endpoint
        WEAVE:EM: Cannot listen for BLE connections, null BleLayer
        WEAVE:EM: Binding 0 : Allocated
        Weave Node Configuration:
          Fabric Id: 1
          Subnet Number: 1
          Node Id: 2
          Listening Addresses:
              fd00:0:1:1::2 (ipv6)
        Sending Heartbeats via UDP to node 1 (fd00:0:1:1::1) every 1000 ms
        Weave Node ready to service events; PID: 170932; PPID: 170608
        WEAVE:EM: Binding 0 : Configuring
        WEAVE:EM: Binding 0 : Preparing
        WEAVE:EM: Binding 0 : Ready, peer 1 ([fd00:0:1:1::1]:11095) via UDP

  4. 成功連接後,節點2將心跳發送到節點1,節點1記錄從節點2接收到的心跳:

     Node 1
    <code></code>
    WEAVE:EM: Msg rcvd 00000013:1 1 0000000000000002 0000 C993 0 MsgId:1380A259
    WEAVE:EM: ec id: 1, AppState: 0xb8e89790
    Heartbeat from node 2 (fd00:0:1:1::2): state=1, err=No Error
    ### Node 2
    <code></code>
    WEAVE:EM: ec id: 1, AppState: 0x0
    WEAVE:EM: Msg sent 00000013:1 1 0000000000000001 0000 C993 0 MsgId:1380A259
    Heartbeat sent to node 1: state=1
     

模擬設備心跳

weave-heartbeat實例化服務器和客戶端的mock-device 。通過使用mock-device代替第一個weave-heartbeat Heartbeat服務器,可以演示相同的Heartbeat功能:

 ./mock-device -a fd00:0:1:1::1

編織

使用weave-ping在兩個Weave節點之間發送和接收Echo 配置文件消息。迴聲有效載荷由請求節點提供的任意數據組成,並且有望在響應中逐字回顯。 Echo提供了一種測試網絡連接和延遲的方法。

成功的Echo需要一個節點充當服務器(偵聽並響應Echo請求),一個節點充當客戶端(發送Echo請求)。

使用回送接口模擬兩個節點來測試weave-ping工具:

  1. 將要用於每個Echo節點的IPv6地址添加到lo (環回)接口:
     sudo ifconfig lo add fd00:0:1:1::1/64
    sudo ifconfig lo add fd00:0:1:1::2/64 
  2. fd00:0:1:1::1地址上啟動Echo服務器, fd00:0:1:1::1分配node-id 1:

     ./weave-ping --node-addr fd00:0:1:1::1 --node-id 1 --listen
        WEAVE:ML: Binding IPv6 TCP listen endpoint to [fd00:0:1:1::1]:11095
        WEAVE:ML: Listening on IPv6 TCP endpoint
        WEAVE:ML: Binding general purpose IPv4 UDP endpoint to [::]:11095
        WEAVE:IN: IPV6_PKTINFO: 92
        WEAVE:ML: Binding general purpose IPv6 UDP endpoint to [fd00:0:1:1::1]:11095 (lo)
        WEAVE:ML: Listening on general purpose IPv6 UDP endpoint
        WEAVE:ML: Binding IPv6 multicast receive endpoint to [ff02::1]:11095 (lo)
        WEAVE:ML: Listening on IPv6 multicast receive endpoint
        WEAVE:EM: Cannot listen for BLE connections, null BleLayer
        WEAVE:SD: init()
        Weave Node Configuration:
          Fabric Id: 1
          Subnet Number: 1
          Node Id: 1
          Listening Addresses:
              fd00:0:1:1::1 (ipv6)
        Listening for Echo requests...
        Iteration 0
        Weave Node ready to service events; PID: 120927; PPID: 113768
        WEAVE:ECH: Listening...

  3. 打開第二個終端窗口,並在fd00:0:1:1::2 IPv6地址( node-id為2且第一個節點的IPv6地址作為Echo請求的目的地)上啟動Echo客戶端:

     ./weave-ping --node-addr fd00:0:1:1::2 --node-id 2 --dest-addr fd00:0:1:1::1 1
        WEAVE:ML: Binding general purpose IPv4 UDP endpoint to [::]:11095
        WEAVE:IN: IPV6_PKTINFO: 92
        WEAVE:ML: Binding general purpose IPv6 UDP endpoint to [fd00:0:1:1::2]:11095 (lo)
        WEAVE:ML: Listening on general purpose IPv6 UDP endpoint
        WEAVE:ML: Binding IPv6 multicast receive endpoint to [ff02::1]:11095 (lo)
        WEAVE:ML: Listening on IPv6 multicast receive endpoint
        WEAVE:EM: Cannot listen for BLE connections, null BleLayer
        WEAVE:SD: init()
        Weave Node Configuration:
          Fabric Id: 1
          Subnet Number: 1
          Node Id: 2
          Listening Addresses:
              fd00:0:1:1::2 (ipv6)
        Sending Echo requests to node 1 at fd00:0:1:1::1
        Iteration 0
        Weave Node ready to service events; PID: 121125; PPID: 121017
        WEAVE:ML: Con start 9A00 0000000000000001 0001
        WEAVE:ML: Con DNS complete 9A00 0
        WEAVE:ML: TCP con start 9A00 fd00:0:1:1::1 11095
        WEAVE:ML: TCP con complete 9A00 0
        WEAVE:ML: Con complete 9A00
        Connection established to node 1 (fd00:0:1:1::1)

  4. 成功連接之後,節點1記錄來自節點2的回顯請求,節點2記錄來自節點1的回顯響應:

     Node 1
    <code></code>
    WEAVE:ML: Con rcvd AA00 fd00:0:1:1::2 41675
    Connection received from node 2 (fd00:0:1:1::2)
    WEAVE:EM: Msg rcvd 00000001:1 15 0000000000000002 AA00 B8A5 0 MsgId:00000000
    WEAVE:EM: ec id: 1, AppState: 0xfce0ca80
    Echo Request from node 2 (fd00:0:1:1::2): len=15 ... sending response.
    WEAVE:EM: Msg sent 00000001:2 15 0000000000000002 AA00 B8A5 0 MsgId:00000000
    WEAVE:EM: Msg rcvd 00000001:1 15 0000000000000002 AA00 B8A6 0 MsgId:00000001
    ### Node 2
    <code></code>
    WEAVE:EM: ec id: 1, AppState: 0xd239baa0
    WEAVE:EM: Msg sent 00000001:1 15 0000000000000001 9A00 B8A5 0 MsgId:00000000
    WEAVE:EM: Msg rcvd 00000001:2 15 0000000000000001 9A00 B8A5 0 MsgId:00000000
    Echo Response from node 1 (fd00:0:1:1::1): 1/1(100.00%) len=15 time=0.228ms
     

帶模擬設備的迴聲

weave-ping實例化服務器和客戶端的mock-device 。通過使用mock-device代替第一台weave-ping Echo服務器,可以演示相同的Echo功能:

 ./mock-device -a fd00:0:1:1::1