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