.MESH_INIT_COND: &MESH_INIT_COND
  test script: InitCondMesh
  restore post cmd set:
  - ''
  - - 'MSSC SSC[1-<node_num>] ram'
    - ['P SSC[1-<node_num>] C +FREEHEAP:']
#  - - 'MSSC SSC[1-<node_num>] mesh -Q -o 1'
#    - ['P SSC[1-<node_num>] C MESH_NETWORK']

.mesh_get_all_dut_mac: &mesh_get_all_dut_mac
  LIST_MERGE:
    - - 'MSSC SSC[1-<node_num>] mac'
      - ['R SSC[1-<node_num>] A <device_mac>:\+STAMAC:(.+)\r\n']

.mesh_check_tree_num: &mesh_check_tree_num
  LIST_MERGE:
    - - 'MSSC SSC[1-<node_num>] mesh -Q -o 2'
      - ['P SSC[1-<node_num>] T topo']
    - - 'MESHTREE'
      - ['R PC_COM RE "MESHTREE:%%s"%%(<tree_node_num>)']

.mesh_tree_stably: &mesh_tree_stably
  LIST_MERGE:
    - - 'SSC MNODE(0) mesh -Q -o 1 -t <stable_check_time>'
      - ['P MNODE(0) RE "MESH_NETWORK:1,%%s"%%(<node_num>)', 'P MNODE(0) C MESH_STABLE_CHECK:PASS']

.deinit_mesh: &deinit_mesh
  LIST_MERGE:
    - - 'MSSC SSC[1-<node_num>] mesh -I -o 1'
      - ['P SSC[1-<node_num>] C +MESH:DEINITED']

.mesh_force_reboot: &mesh_force_reboot
  LIST_MERGE:
    - - 'MSSC SSC[1-<node_num>] restore'
      - ['P SSC[1-<node_num>] C !!!ready!!!']

.mesh_config_all_duts: &mesh_config_all_duts
  LIST_MERGE:
    - - 'MSSC SSC[1-<node_num>] meshset -M -o 0 -t <map_auth_mode> -e <map_password> -l 10'
      - ['P SSC[1-<node_num>] C +MESHSET:MAP_AUTH,OK']
    - - 'MSSC SSC[1-<node_num>] meshset -G -o 0 -m <mesh_id> -s <router_ssid> -p <router_password> -n
        <router_channel> -b <router_bssid> -t <max_connect> -e <map_password> -i <ie_encrypt>'
      - ['P SSC[1-<node_num>] C +MESHSET:CFG,OK']
    - - 'MSSC SSC[1-<node_num>] meshset -L -o 0 -l <max_layer>'
      - ['P SSC[1-<node_num>] C +MESHSET:MLAYER,OK']
    - - 'MSSC SSC[1-<node_num>] meshset -W -o 0 -t <duration_ms> -n <cnx_rssi> -l <select_rssi> -i <switch_rssi> -k <backoff_rssi>'
      - ['P SSC[1-<node_num>] C +MESHSET:SWITCH,OK']
    - - 'MSSC SSC[1-<node_num>] meshset -K -o 0 -i <allow_roots>'
      - ['P SSC[1-<node_num>] C +MESHSET:ALLOW_ROOTS,OK']
    - - 'MSSC SSC[1-<node_num>] meshset -J -o 0 -t <assoc_expire>'
      - ['P SSC[1-<node_num>] C +MESHSET:ASSOC,OK']

.mesh_set_same_ssid_softap: &mesh_set_same_ssid_softap
  LIST_MERGE:
    - - 'MSSC SSC[1-3] op -S -o 2'
      - ['P SSC[1-3] C +MODE:OK']
    - - 'MSSC SSC[1-3] ap -S -s <target_ssid> -p <target_password> -t <target_auth_enum> -n
        [<router_channel>,<router_channel>,<wrong_channel>]'
      - ['P SSC[1-3] C +SAP:OK']

initial condition:
- tag: MESH_DEINIT_STA
  <<: *MESH_INIT_COND
  initial condition detail: all DUTs with mesh not inited, station mode
  check cmd set:
  - ''
  - - MSSC SSC[1-<node_num>] mesh -Q
    - - P SSC[1-<node_num>] C MESH_STATE_NONE
  - - MSSC SSC[1-<node_num>] op -S -o 1
    - - P SSC[1-<node_num>] C +MODE:OK
  - *mesh_get_all_dut_mac
  restore cmd set:
  - ''
  - - MSSC SSC[1-<node_num>] mesh -I -o 1
    - - P SSC[1-<node_num>] C +MESH_DEINITED
  - - MSSC SSC[1-<node_num>] op -S -o 1
    - - P SSC[1-<node_num>] C +MODE:OK
  - *mesh_get_all_dut_mac
  force restore cmd set:
  - ''
#  - - MSSC SSC[1-<node_num>] reboot
  - - FREBOOT SSC[1-<node_num>]
    - - P SSC[1-<node_num>] C !!!ready!!!
  - *mesh_get_all_dut_mac
- tag: MESH_INIT1
  <<: *MESH_INIT_COND
  initial condition detail: DUTs with mesh network already established, router....
  check cmd set:
  - ''
  - *mesh_get_all_dut_mac
  - - VALUE <tree_node_num> <node_num>
    - - R PC_COM L OK
  - *mesh_check_tree_num
  - *mesh_tree_stably
  - - MSSC SSC[1-<node_num>] mesh -Q -o 3
    - - P SSC[1-<node_num>] RE "MID,%%s"%%(<mesh_id>)
      - P SSC[1-<node_num>] RE "MROUTER,%%s"%%(<router_ssid>)
      - P SSC[1-<node_num>] RE "SWITCH_PARENT,%%s"%%(<duration_ms>)
      - P SSC[1-<node_num>] C NO_SPECIFIC_SETTINGS
  restore cmd set:
  - ''
  - - MSSC SSC[1-<node_num>] mesh -I -o 1
    - - P SSC[1-<node_num>] C MESH_DEINITED
  - - MSSC SSC[1-<node_num>] op -S -o 1
    - - P SSC[1-<node_num>] C +MODE:OK
  - *mesh_get_all_dut_mac
  - - MSSC SSC[1-<node_num>] mesh -I
    - - P SSC[1-<node_num>] C +MESH:INIT,OK
  - *mesh_config_all_duts
  - - MSSC SSC[1-<node_num>] mesh -T
    - - P SSC[1-<node_num>] C +MESH:START,OK
  - - DELAY <delay_time>
    - - ''
  - - VALUE <tree_node_num> <node_num>
    - - R PC_COM L OK
  - *mesh_check_tree_num
  - *mesh_tree_stably
  force restore cmd set:
  - ''
  - - MSSC SSC[1-<node_num>] reboot
    - - P SSC[1-<node_num>] C !!!ready!!!
  - *mesh_get_all_dut_mac
  - - MSSC SSC[1-<node_num>] mesh -I
    - - P SSC[1-<node_num>] C +MESH:INIT,OK
  - *mesh_config_all_duts
  - - MSSC SSC[1-<node_num>] mesh -T
    - - P SSC[1-<node_num>] C +MESH:START,OK
  - - DELAY <delay_time>
    - - ''
  - - VALUE <tree_node_num> <node_num>
    - - R PC_COM L OK
  - *mesh_check_tree_num
  - *mesh_tree_stably
- tag: MESH_INIT_SWITCH
  <<: *MESH_INIT_COND
  initial condition detail: 3 duts in softAP mode with same ssid/password, all duts establish network
  check cmd set:
  - ''
  - - SSC SSC[1-3] ap -Q
    - - P SSC[1-3] RE "RE "APCONFIG:%%s"%%(<target_ssid>)
  - - MSSC SSC[4-<node_num>] mac
    - -  R SSC[4-<node_num>] A <device_mac>:\+STAMAC:(.+)\r\n
  - - VALUE <tree_node_num> <node_num>-3
    - - R PC_COM L OK
  - - MSSC SSC[4-<node_num>] mesh -Q -o 2
    - - P SSC[4-<node_num>] T topo
  - - MESHTREE
    - - R PC_COM RE "TREE_TOTAL_NODES:%%s"%%(<tree_node_num>)
  - - MSSC SSC[4-<node_num>] mesh -Q -o 3
      - P SSC[4-<node_num>] RE "MROUTER,%%s"%%(<target_ssid>)
  - - DELAY 5
    - - P PC_COM C +DELAYDONE
      - P SSC[4-<node_num>] NC MESH_EVENT_DISCONNECTED
  restore cmd set:
  - ''
  - - ASSERT
    - - ''
  force restore cmd set:
  - ''
  - - MSSC SSC[1-<node_num>] reboot
    - - P SSC[1-<node_num>] C !!!ready!!!
  - *mesh_get_all_dut_mac
  - *mesh_set_same_ssid_softap
  - - MSSC SSC[4-<node_num>] mesh -I
    - - P SSC[4-<node_num>] C +MESH:INIT,OK
  - - MSSC SSC[4-<node_num>] meshset -M -o 0 -t <map_auth_mode> -e <map_password> -l 10
    - - P SSC[4-<node_num>] C +MESHSET:MAP_AUTH,OK
  - - MSSC SSC[4-<node_num>] meshset -G -o 0 -m <mesh_id> -s <target_ssid> -p <target_password> -n <try_channel> -h 1 -t
      <max_connect> -e <map_password> -i <ie_encrypt>
    - - P SSC[4-<node_num>] C +MESHSET:CFG,OK
  - - MSSC SSC[4-<node_num>] meshset -L -o 0 -l <max_layer>
    - - P SSC[4-<node_num>] C +MESHSET:MLAYER,OK
  - - MSSC SSC[4-<node_num>] meshset -W -o 0 -t <duration_ms> -n <cnx_rssi> -l <select_rssi> -i <switch_rssi> -k <backoff_rssi>
    - - P SSC[4-<node_num>] C +MESHSET:SWITCH,OK
  - - MSSC SSC[4-<node_num>] meshset -K -o 0 -i <allow_roots>
    - - P SSC[4-<node_num>] C +MESHSET:ALLOW_ROOTS,OK
  - - MSSC SSC[4-<node_num>] mesh -T
    - - P SSC[4-<node_num>] C +MESH:START,OK
  - - DELAY <delay_time>
    - - ''
  - - VALUE <tree_node_num> <node_num>-3
    - - R PC_COM L OK
  - - MSSC SSC[4-<node_num>] mesh -Q -o 2
    - - P SSC[4-<node_num>] T topo
  - - MESHTREE
    - - R PC_COM RE "TREE_TOTAL_NODES:%%s"%%(<tree_node_num>)
  - - DELAY 10
    - - P PC_COM C +DELAYDONE
      - P SSC[4-<node_num>] NC MESH_EVENT_DISCONNECTED
- tag: MESH_NO_ROUTER
  <<: *MESH_INIT_COND
  initial condition detail: DUTs with mesh network already established, router....
  check cmd set:
  - ''
  - *mesh_get_all_dut_mac
  - - VALUE <tree_node_num> <node_num>
    - - R PC_COM L OK
  - *mesh_check_tree_num
  - *mesh_tree_stably
  - - MSSC SSC[1-<node_num>] mesh -Q -o 3
    - - P SSC[1-<node_num>] RE "MID,%%s"%%(<mesh_id>)
      - P SSC[1-<node_num>] C NO_ROUTER
  restore cmd set:
  - ''
  - - ASSERT
    - - ''
  force restore cmd set:
  - ''
  - - ASSERT
    - - ''
- tag: MESH_STABLE
  <<: *MESH_INIT_COND
  initial condition detail: DUTs with mesh network already established and stable, never restore
  check cmd set:
  - ''
  - *mesh_get_all_dut_mac
  - - MSSC SSC[1-<node_num>] mesh -Q -o 2
    - - P SSC[1-<node_num>] T topo
  - - MESHTREE stable
    - - P PC_COM RE "MESHTREE:%%s%20nodes"%%(<node_num>)
  restore cmd set:
  - ''
  - - ASSERT
    - - ''
  force restore cmd set:
  - ''
  - - ASSERT
    - - ''
