# Copyright (c) 2021 Project CHIP Authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# Auto-generated scripts for harness use only, please review before automation. The endpoints and cluster names are currently set to default

name:
    15.4.9. [TC-SC-4.9] Operational Discovery - RIO support [DUT as
    Commissionee]

PICS:
    - MCORE.ROLE.COMMISSIONEE
    - MCORE.SC.LWIP

config:
    nodeId: 0x12344321
    cluster: "Basic Information"
    endpoint: 0

tests:
    - label: "Precondition"
      verification: |
          1. TH_CR1 is a Commissioner, working over Ethernet or Wi-Fi transport, able to commission DUT into a given Fabric and implementing RFC-4191
          2. TH_CR2 is a Commissioner/Controller Thread 1.3 device (only on Thread, not on Wi-Fi or Ethernet), joined to the PAN of the BR and already commissioned on the same Fabric
          3. DUT_CE is a Commissionee Ethernet or Wi-Fi device and implementing RFC-4191
          4. DUT_CE will adopt an address on the GUA prefix e.g. 2001:12ab::/64 and use it as default route (::/0)
          5. DUT_CE sees the RA w/ RIO and adds the off-mesh prefix preferred route, so that any messages for that off-mesh prefix routes there INSTEAD of the default gateway
          6. BR is a Thread 1.3 border router, with link to DUT over Wi-Fi or Ethernet, in the same VLAN
          7. RT is a Wi-Fi or Ethernet router advertising a default route (i,e, against ::/0 prefix) with a GUA prefix advertised. That prefix MUST also route to the public internet to avoid the different entities bailing out of having this prefix because it’s an invalid environment detected to be artificial.
      disabled: true

    - label:
          "Step 1: Using TH_CR1, commission the DUT_CE onto the Matter network"
      verification: |
          Using chip-tool (TH_CR1) provision the device using cmd

          ./out/debug/chip-tool pairing ble-wifi node-id ssid password setup-pin-code discriminator
      disabled: true

    - label: "Step 2: Bring the TH_CR2 onto the thread network"
      verification: |
          Build openthread POSIX cli app with RCP and have it join the thread network that the BR is part of.

          If you don't have the app, follow the below "Instructions to build the POSIX app"

          if you have the RCP connected to the raspi, launch the ot-cli app with RCP
          $ sudo ./build/posix/src/posix/ot-cli 'spinel+hdlc+uart:///dev/ttyACM0?uart-baudrate=115200' -v
          ./build/posix/src/posix/ot-cli[68007]: Running OPENTHREAD/thread-reference-20200818-1820-g095f530bd; POSIX; Jul 18 2022 22:44:35
          ./build/posix/src/posix/ot-cli[68007]: Thread version: 4
          ./build/posix/src/posix/ot-cli[68007]: Thread interface:
          ./build/posix/src/posix/ot-cli[68007]: RCP version: OPENTHREAD/thread-reference-20200818-1615-gfdf3c3034; NRF52840; Jul 17 2022 17:10:13
          > dataset set active <PROVIDE THE DATASET OF THE BR THAT YOU NEED TO JOIN i.e BR hosted in TH>
          > dataset commit active
          > ifconfig up
          > thread start

          With the above set of commands, the RCP should join the thread network hosted by the BR.
          >srp client autostart enable


          Instructions to build the posix app.
          1. Get Nordic nRF52840 dongle.
          2. Attach it to the raspi/Ubuntu machine
          Follow the instructions at https://github.com/openthread/openthread/blob/main/src/posix/README.md
          3. git clone --recursive git@github.com:openthread/openthread.git
          4. cd openthread/
          5. ./script/bootstrap
          6. ./bootstrap
          7. ./script/cmake-build posix
          8. follow the instructions to build the RCP dongle (or get the RCP image from README file in the test harness and flash it on the RCP)
          8. ./build/posix/src/posix/ot-cli 'spinel+hdlc+uart:///dev/ttyACM0?uart-baudrate=115200' -v
      disabled: true

    - label:
          "Step 3: Using TH_CR2, using ICMPv6 echo to ping with a payload >= 32
          bytes to the the DUT_CE that is already commissioned to the Matter
          network. IP address is determined by operational discovery of the
          DNS-SD operational service record (_matter._tcp service instance) of
          DUT_CE done by TH_CR2."
      verification: |
          In the RCP Shell , have the TH_CR2 discover the device IP address using
          > dns service 87E1B004E235A130-8FC7772401CD0696 _matter._tcp.default.service.arpa.
          DNS service resolution response for 177AC531F48BE736-0000000000000190 for service _matter._tcp.default.service.arpa.
          Port:5540, Priority:0, Weight:0, TTL:6913
          Host:72FF282E7739731F.default.service.arpa.
          HostAddress:fd11:66:0:0:22ae:27fe:13ac:54df TTL:6915
          TXT:[SII=35303030, SAI=333030, T=30] TTL:6913
          Ping the IP address of the wifi device

          > ping fd11:66:0:0:22ae:27fe:13ac:54df
          16 bytes from fd11:66:0:0:22ae:27fe:13ac:54df : icmp_seq=2 hlim=64 time=14ms
          1 packets transmitted, 1 packets received. Packet loss = 0.0%. Round-trip min/avg/max = 14/14.0/14 ms.
          Done

          The ping command should be successful.
      disabled: true
