# Compare ADR with a fixed spreading factor in ns-3

This is a second tool route for the LoRaWAN link-budget and ADR concept. It runs the real `adr-example` in the [signetlabdei LoRaWAN ns-3 module](https://github.com/signetlabdei/lorawan), paired with the same example with ADR disabled. The module simulates **Class A** end devices only. Its output is a model result, **not a radio capture**.

The positions and random path-loss additions are **synthetic** model inputs, with `RngSeed=7` and `RngRun=1`. The source is `examples/adr-example.cc` at LoRaWAN commit `e45b4af428c92f30b2e6c201055809110758125f`. The compatible ns-3 tag `ns-3.48` resolves to commit `d2add90b452d600cfb4859baed8e9ea633519447`. The six conditions use 16 devices, 30 twenty-minute periods, a 4 km half-side placement square, a 5 km gateway spacing and maximum random losses of 0, 10 or 20 dB. `scenario.json` records the inputs.

## Run locally or in a free Linux cloud shell

Use a Linux terminal with a C++ compiler, Git, CMake ≥3.13 and Python 3 with matplotlib. A free cloud shell with these tools works; its CPU and memory limits determine build time. Download `run.sh`, `analyze.py` and `scenario.json` from this lab page into one directory, then run these commands there. No paid ns-3 service or radio hardware is needed.

```bash
git clone --depth 1 --branch ns-3.48 https://gitlab.com/nsnam/ns-3-dev.git ns-3-dev
test "$(git -C ns-3-dev rev-parse HEAD)" = d2add90b452d600cfb4859baed8e9ea633519447
git clone https://github.com/signetlabdei/lorawan.git ns-3-dev/src/lorawan
git -C ns-3-dev/src/lorawan checkout e45b4af428c92f30b2e6c201055809110758125f
test "$(git -C ns-3-dev/src/lorawan rev-parse HEAD)" = e45b4af428c92f30b2e6c201055809110758125f
(cd ns-3-dev && ./ns3 configure --enable-examples --enable-modules lorawan && ./ns3 build -j 8)
bash run.sh "$PWD/ns-3-dev" "$PWD/results"
python3 analyze.py "$PWD/results"
```

On Debian or Ubuntu, `sudo apt install g++ python3 python3-matplotlib cmake git` supplies the listed dependencies. On a managed cloud shell, use its preinstalled compiler and Python packages if package installation is unavailable. The build uses no more than eight jobs.

`run.sh` writes six directories under `results/`. Each has the real simulator's `stdout.log`, `nodeData.txt` and `globalPerformance.txt`. `analyze.py` reads these outputs, prints the six rows, writes `summary.csv` and renders `delivery.png`. Open that PNG in a browser. The 10-byte **reference** airtime is calculated from each run's final spreading factors using the module's time-on-air formula and stated PHY assumptions; it is **not a measurement of the actual LoRaWAN uplink frame or of all packets across the run**. Delivery uses the module's global MAC packet tracker across the run. The example's final console line covers only the final 20-minute window.

Expected output for this pinned, fixed-seed run is in `expected-summary.csv`; compare your own CSV with it. Small differences after changing versions, seeds or parameters require a fresh evidence record rather than editing expected values.

The result does not establish real-world coverage, battery life, or a good ADR policy for a field deployment.
