# Measure parent choice and radio duty

Compare a leaf-only node’s route and radio duty with always-on CSMA and a scheduled TSCH configuration.

## Run on Linux x86-64 with Docker and X11

The image, Java, compiler and simulator ran on this host under Apptainer.
Docker is unavailable here: the laptop Docker invocation is syntax-reviewed,
not claimed as laptop-tested. Windows, macOS and ARM display setup is outside
this recipe. No paid service or account is required.

Download `lab-files.tar.gz` from this lab page. In a terminal:

```bash
mkdir cooja-lab
cd cooja-lab
tar -xzf ~/Downloads/lab-files.tar.gz
git clone --depth 1 --branch release/v4.9 https://github.com/contiki-ng/contiki-ng.git contiki-ng
test "$(git -C contiki-ng rev-parse HEAD)" = c20b12cd2db707d6c07918f8b26cfeb52cf298ca
git -C contiki-ng submodule update --init --depth 1 tools/cooja
test "$(git -C contiki-ng/tools/cooja rev-parse HEAD)" = 33d41ae9f8acd6075fb903b0bcd5b4122bad8d8f
mkdir -p jdk17 home/contiki-ng
curl -fL 'https://github.com/adoptium/temurin17-binaries/releases/download/jdk-17.0.20.1%2B1/OpenJDK17U-jdk_x64_linux_hotspot_17.0.20.1_1.tar.gz' -o jdk17.tar.gz
echo '3808d1d15e3ec6bd5b84057fb5d84c33d8a1536a258146bcea2e603fc726e08e  jdk17.tar.gz' | sha256sum -c -
tar -xzf jdk17.tar.gz --strip-components=1 -C jdk17
xhost +si:localuser:$(id -un)
bash cooja-mesh-exercises/docker-launch.sh
# After closing Cooja:
xhost -si:localuser:$(id -un)
```

The launcher binds the packet at `/lab`. Cooja loads `/lab/cooja-mesh-exercises.csc`
and compiles the included upstream example files (any small scenario edits are listed in UPSTREAM.md). The project header enables
logging and any explicitly documented parameter changes. The supplied Makefiles
expect the recipe's `/home/user/contiki-ng` mount. The first Gradle build requires
Internet. To use your own native Java 17 installation, set CONTIKI in the supplied
Makefiles to your checkout and open the CSC with that release's Cooja.

The script starts automatically and stops at `TEST OK` or `TEST FAILED`. The GUI
stays open. Use **Mote output → Filter** to show the rows named in the steps;
clear the filter to inspect other messages. **File → Open simulation → Browse...**
loads another CSC. Reopen the original CSC for a fresh seed-1 run.
Times are simulated times, not wall-clock times. `expected-output.txt` is the
unaltered headless serial/test log, including actual measurements and the test result.

For headless Docker execution, replace `--gui --autostart` in the launcher with
`--no-gui --logdir=/lab/run-output` and remove the display requirement/mount.
Cooja writes `COOJA.testlog` under that writable output directory.

## Run and measure

Both variants use unchanged upstream examples/rpl-udp plus shell and
simple-energest modules. Root 1=(0,0), relays 2=(-30,25), 3=(30,25),
leaf 5=(0,55). Seed 1, 300 s, UDGM 50/100 m and TX/RX success 1.
The -csma CSC sets MAKE_MAC_CSMA; the main/-tsch CSC sets MAKE_MAC_TSCH,
TSCH_CONF_AUTOSTART=1. Both leaf builds set RPL_CONF_DEFAULT_LEAF_ONLY=1.
Only the TSCH MAC schedule turns the radio off between scheduled activity;
leaf-only removes the forwarding role. This is not Zigbee child polling or
OpenThread sleepy-end-device behavior. CSMA and TSCH are different MAC trials,
not different Zigbee application profiles.

The ScriptRunner queries mote 5's candidate neighbors at 240 s, RPL status at
241 s, TSCH schedule/status at 242/243 s, then pings the root at 250 s.
Simple Energest records radio/CPU state times every 60 seconds. Its counts are
simulation state-time counters, not measured milliamps or joules.

| Observation | CSMA | TSCH |
|---|---|---|
| Delivered / attempted application requests | 85 / 85 | 83 / 83 |
| Leaf parent and path | 3; 5→3→1 | 3; 5→3→1 |
| Root ping | 112 ms RTT, TTL 63 | 265 ms RTT, TTL 63 |
| Final complete leaf radio interval | 60,000,000 / 60,000,000 | 2,566,500 / 60,000,000 |
| Calculated interval radio duty | 100% | 4.2775% |
| Displayed integer permil | 1000 | 42 |

The last TSCH period ends at 240.971 s and covers the previous 60 seconds.
Do not average the printed truncated permil values; sum raw radio counts and
raw total-time counts when calculating a multi-period ratio. The first TSCH
period is 18,940,500 / 60,002,020 (315 permil) because association is included.
A lower steady-state duty ratio does not by itself prove equivalent latency,
recovery, battery life or field reliability. Read the longer ping RTT too.

Ledger: claim, role, candidate parents, chosen parent, route length, MAC,
association state, observation window, raw radio and total counts, delivery,
latency, missing data, limitation, decision and retest trigger. Reopen each CSC
for a clean run. Change one factor and repeat before drawing a comparison.

## Original Zigbee exercises: explicit paper boundary

These preserve the application and operational decisions of the legacy page;
none of the following Zigbee/Matter mechanisms is executed by this packet.

1. Addressing: keep the stable IEEE/EUI-64 identity distinct from a mutable
   16-bit short routing address and a group address. Do not use a Cooja mote ID
   or IPv6 address as evidence that Zigbee address assignment ran. Check parent
   child-table occupancy and depth before attributing a join failure to RF.
2. Commissioning: name coordinator/Trust Center owner, role, join authorization,
   install-code/key boundary, direct observation and saved artifact. Define
   reset and stale-state cleanup, then repeat the join in a real implementation.
3. Binding: record source endpoint/client cluster and destination/server cluster
   or group. For On/Off 0x0006, test local control with the hub application down.
   Packets reaching a joined device do not prove the correct endpoint changed.
4. Bridge telemetry: record device identity, Zigbee attribute, bridge owner,
   target topic/entity, units, timestamps and stale/cached behavior. Stop the
   bridge and retain failure evidence; approve translation, not native support.
5. OTA: split powered routers and battery devices into cohorts. Specify health
   checks, staging, pause/rollback criteria, post-update verification and recovery
   ownership. A transfer-time estimate alone is not a safe rollout plan.
6. Migration: classify each behavior as native, bridged, replaced, deferred or
   unsupported. Name user impact and retest after controller/firmware changes.

Accept only the measured RPL path and scheduled-radio comparison. Hold binding,
bridge, commissioning, migration readiness and hardware power claims for their
own implementation evidence. No reusable credentials are required by this lab.


## Tested version

Contiki-NG release/v4.9 c20b12cd, Cooja 4.8 (2022071901), Temurin 17.0.20.1, image sha256:b14d5afb0a2a852d9e72bbed607ead03f6ccc5f4d4dee44f0799110be2f4b609
