# TR143d

TR143d package provides 'Device.IP.Diagnostics.' datamodel parameters and manages the backend for various diagnostic operations.

## Good to Know

It currently supports IPPing, Traceroute, DownloadDiagnostics, UploadDiagnostics, UDPEchoDiagnostics and ServerSelectionDiagnostics.

The datamodel implementation has been written in 'C' programming language and is being installed as a bbfdm micro-service to expose the datamodel functionality. The backend of various diagnostics are implemented using 'shell' programming.

Currently `DownloadDiagnostics` has two variant, for `an7581` based chipsets, its usages Airoha fastpath tr143 implementation using `speed_test` module, for rest of the platforms it mostly relies on Curl utility.

### Limitations with fastpath/speed_test module for DownloadDiagnostic

- Only available for `an7581` chip targets
- 'speed_test' module does not support 'https' protocol
- This module do not provide protocol based error codes when fails, so to show the actual failure in the output, current implementation uses libcurl to collect the exact error code.
- This module fails to download with IPv6 address so backend uses legacy mechanism (i.e. curl) to perform the diagnostic with IPv6 addresses.
- DownloadDiagnostic with 'FTP' protocol is not yet implemented with 'speed_test' and hence depends on the curl based mechanism.
- 'speed_test' module provides the timestamps for all time related parameters like ROMTime, BOMTime, EOMTime etc as below:
  ROMTime:(1751006637:323389120)
  BOMTime:(1751006637:388715440)
  EOMTime:(1751006638:500266320)

  As per our understanding the second part after the ':' should be in usec unit, but usec couldn't be in 9 digits form. So currently backend treats it as nsec and converts it to usec to produce the output.

### Time based DownloadDiagnostics

`TimeBasedTestDuration` bounds the test by time instead of by file size. The transfer is cut short once the duration elapses, and that truncation is a successful outcome rather than `Error_Timeout`. On the Airoha fastpath the duration maps onto the module's own `duration=` knob; elsewhere it bounds the curl transfer.

The accepted range is 0 to 999 seconds, the full range of the data model definition, and the backends bound the transfer by the same ceiling. On the fastpath the poll loop is given the duration plus ten seconds, for the module to finalise the run and for the next sample to observe it. A duration past the ceiling is refused with a fault rather than quietly cut short and then reported as a complete test.

The ceiling doubles as the bound on a size based test, so a stalled size based transfer on the fastpath takes that long to report `Error_Timeout`.

### Summary
- Airoha fastpath (speed_test module) currently used in 'DownloadDiagnostics' on an7581 platform and it only works with 'http' protocol on 'IPv4' network.

## Manual Testing

`test/server` holds an HTTP server for driving `DownloadDiagnostics` and `UploadDiagnostics` against a device, and a compose file to run it:

```sh
cd test/server && docker compose up -d && docker compose logs -f
```

It logs a line per transfer with the byte count, duration and rate, which is what you cross-reference against the `BOMTime`/`EOMTime` the device reports. Point the device at the host running it:

- `DownloadURL=http://<host>:8000/1G.bin` — a size based test; the size comes from the URL, either from the digits in the basename or from `?size=90MB`
- `DownloadURL=http://<host>:8000/stream` — a time based test; the body is endless, so it outlasts any `TimeBasedTestDuration`
- `UploadURL=http://<host>:8000/upload.bin` — any path answers `PUT` and `POST`

See the docstring at the top of `tr143_server.py` for the full route list and the options for serving real files or keeping uploaded payloads.
