เครื่องมือ OpenWeave

ดูแหล่งที่มาบน GitHub

OpenWeave มีชุดเครื่องมือบรรทัดคำสั่งเพื่อกำหนดค่า จัดการ และทดสอบการใช้งาน OpenWeave

สร้างเครื่องมือสาน

weave-tools เป้าหมายสร้าง 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. กำหนดค่า OpenWeave โดยการสนับสนุน Bluez:
    cd <path-to-openweave-core>
    ./configure --without-bluez
  3. Make the weave-tools target:
    make weave-tools
  4. Check the root openweave-core directory for the tar archive:
    ls weave*
        weave-tools-x86_64-unknown-linux-gnu-4.0d.tar.gz

gen-qr-code

The gen-qr-code tool requires the Python qrcode module. Use pip to install it:

pip install --user qrcode

ใช้ gen-qr-code เพื่อสร้างรหัส QR เพื่อวัตถุประสงค์ในการจับคู่อุปกรณ์ อินพุตสำหรับเครื่องมือต้องอยู่ในไฟล์ในเครื่อง ยกตัวอย่างเช่นการสร้าง QR โค้ดที่ส่งให้ผู้ใช้ https://www.google.com :

  1. สร้างไฟล์ที่มีสตริงรหัส QR นี้:
    echo "https://www.google.com" >> ~/ow_qrcode
  2. Generate a 64x64 QR code of that string:
    ./gen-qr-code -v 1 -s 64 < ~/ow_qrcode
  3. To save the QR code as an image, specify an output file:
    ./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

The mock-device tool simulates a generic Weave node. Other tools and test case scripts use this tool to encapsulate Weave functionality. Instantiate mock devices on individual Happy nodes to test Weave functionality in a simulated topology.

For example, to start a Weave mock device listening on an IPv6 address of fd00:0:1:1::1, first add that IPv6 address to the lo (loopback) interface:

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 ถอดรหัสเครื่องมือหรือถอดรหัสสตริงบ่งอุปกรณ์ สตริงเหล่านี้มีข้อมูลระบุอุปกรณ์ที่เข้ารหัสเป็นรหัส QR การจับคู่ Weave ใช้ --help ธงที่มี encode หรือ decode ตัวเลือกสำหรับข้อมูลเพิ่มเติม

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

เข้ารหัส

ตัวอย่างเช่น ในการเข้ารหัสสตริงตัวอธิบายอุปกรณ์ด้วยข้อมูลการระบุต่อไปนี้ ให้ใช้แฟล็กและค่าที่เหมาะสม:

ฟิลด์ ธง ความคุ้มค่า
รหัสผู้ขาย -V 1
รหัสสินค้า -p 1
หมายเลขการแก้ไขผลิตภัณฑ์ -r 2
หมายเลขซีเรียล -s 18B4300000000004
วันผลิต -m 2018/05/02
ที่อยู่ MAC 802.15.4 (เธรด, 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 การส่งและรับ การเต้นของหัวใจ ข้อความรายละเอียดระหว่างสองโหนดสาน Heartbeat เป็นเครื่องมือในการบ่งชี้ความพร้อมใช้งานของโหนดหนึ่งไปยังโหนดอื่นในเครือข่าย หรือเพื่อตรวจสอบว่าโหนดยังคงเชื่อมต่อกับแฟบริกหรือไม่

Heartbeat ที่ประสบความสำเร็จต้องใช้หนึ่งโหนดเพื่อทำหน้าที่เป็นเซิร์ฟเวอร์ (ฟังและตอบสนองต่อ Heartbeat) และหนึ่งโหนดเพื่อทำหน้าที่เป็นไคลเอนต์ (การส่ง 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. Start the Heartbeat server on the fd00:0:1:1::1 address and assign it a node-id of 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. Open a second terminal window and start the Heartbeat client on the fd00:0:1:1::2 IPv6 address with a node-id of 2 and the first node's IPv6 address as the destination for the 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: Binding0: 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: Binding0: Configuring
        WEAVE:EM: Binding0: Preparing
        WEAVE:EM: Binding0: Ready, peer 1 ([fd00:0:1:1::1]:11095) via UDP

  4. After a successful connection, node 2 sends Heartbeats to node 1, and node 1 logs Heartbeats received from node 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 instantiates mock-device สำหรับทั้งเซิร์ฟเวอร์และไคลเอ็นต์ ฟังก์ชั่นการเต้นของหัวใจเดียวกันสามารถแสดงให้เห็นโดยใช้ mock-device ในสถานที่แรก weave-heartbeat เซิร์ฟเวอร์การเต้นของหัวใจ:

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

สานปิง

ใช้ weave-ping เพื่อส่งและรับ Echo ข้อความรายละเอียดระหว่างสองโหนดสาน เพย์โหลดของ Echo ประกอบด้วยข้อมูลที่กำหนดเองโดยโหนดที่ร้องขอ และคาดว่าจะสะท้อนกลับแบบคำต่อคำในการตอบสนอง Echo เป็นวิธีทดสอบการเชื่อมต่อเครือข่ายและเวลาแฝง

Echo ที่ประสบความสำเร็จต้องใช้หนึ่งโหนดเพื่อทำหน้าที่เป็นเซิร์ฟเวอร์ (ฟังและตอบสนองต่อคำขอ Echo) และหนึ่งโหนดเพื่อทำหน้าที่เป็นไคลเอนต์ (ส่งคำขอ Echo)

ทดสอบการ weave-ping เครื่องมือที่ใช้อินเตอร์เฟซย้อนกลับไปเลียนแบบสองโหนด:

  1. เพิ่มที่อยู่ IPv6 ที่จะใช้สำหรับแต่ละโหนดก้องไป lo (ย้อนกลับ) อินเตอร์เฟซ:
    sudo ifconfig lo add fd00:0:1:1::1/64
    sudo ifconfig lo add fd00:0:1:1::2/64
  2. Start the Echo server on the fd00:0:1:1::1 address, assigning it a node-id of 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. Open a second terminal window and start the Echo client on the fd00:0:1:1::2 IPv6 address with a node-id of 2 and the first node's IPv6 address as the destination for the Echo request:

    ./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. After a successful connection, node 1 logs Echo Requests from node 2, and node 2 logs Echo Responses from node 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 instantiates mock-device สำหรับทั้งเซิร์ฟเวอร์และไคลเอ็นต์ การทำงาน Echo เดียวกันสามารถแสดงให้เห็นโดยใช้ mock-device ในสถานที่แรก weave-ping เซิร์ฟเวอร์ Echo:

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