netcopilot is designed to assist you in network simulation. It allows you to directly call related APIs via hdc command-line interface (CLI) to simulate preset network scenarios.
The netcopilot tool is supported since API version 20.
Before using the netcopilot tool, you need to obtain the hdc tool.
hdc shell netcopilot <Parameter> <Sub-parameter>
The following table lists the command parameters and sub-parameters. You can also run the hdc shell command and then run the netcopilot request.
| CLI Parameters | Sub-parameter | Function | Description |
|---|---|---|---|
| -h | NA | Outputs help information. | NA |
| -e | 0: off; 1: on | Enables or disables netcopilot. | When this switch is disabled, other options are unavailable. |
| -p | NA | Prints the list of network scenarios. | By default, the list of preset network simulation scenarios is printed. In & out of elevator Leave home WLAN range Enter home WLAN range Busy cafeteria Parking garage Riding the subway Riding high-speed train (switching between SIM cards) Highway driving |
| -s | Scenario ID | Starts a network simulation. | You can switch between different network simulation scenarios. Network simulations must meet the corresponding network adapter requirements. For scenarios such as using the elevator, disconnecting WLAN when leaving home, or connecting WLAN when arriving home, both WLAN and cellular networks must be connected. For all other scenarios, either WLAN or cellular networks need to be connected. |
| -c | Scenario ID | Cancels a network simulation. | NA |
| -P | Scenario ID | Prints details about a custom scenario. | Only custom scenarios are supported. |
| -a | Details about a custom scenario | Adds a custom scenario. | Adds a custom scenario using a JSON string. The following is an example of the format: { "scenarioName": "Custom scenario", "uplinkBandwidth": 1000000, "downlinkBandwidth": 5000000, "uplinkLatency": 200, "downlinkLatency": 200, "uplinkDropRate": 0.05, "downlinkDropRate": 0.01 } |
| -d | Custom scenario ID | Deletes a custom scenario. | The custom scenario ID is generated by netcopilot backend. After obtaining the ID from the list using -p, you can delete the scenario using -d. |
> hdc shell netcopilot -h netcopilot usage: -h : show help message -e <enable>: 0 for disable, 1 for enable -p : print all scenario info -s <scenario id>: simulate specified network scenario -c : cancel simulating scenario -P <scenario id>: print specified scenario details -a <custom scenario details>: add custom network scenario -d <scenario id>: delete custom network scenario
> hdc shell netcopilot -e 0 Disable netcopilot success > hdc shell netcopilot -e 1 Enable netcopilot success
> hdc shell netcopilot -p +------------+------------------------------+ | ScenarioID | ScenarioName | +------------+------------------------------+ 1 | In & out of elevator 2 | Leave home WLAN range 3 | Enter home WLAN range 4 | Busy cafeteria 5 | Parking garage 6 | Riding the subway 7 | Riding high-speed train (switching between SIM cards) 8 | Highway driving +------------+------------------------------+
> hdc shell netcopilot -a "{\"scenarioName\":\"Custom scenario 1\",\"uplinkBandwidth\":100000,\"downlinkBandwidth\":500000,\"uplinkLatency\":200,\"downlinkLatency\":200,\"uplinkDropRate\":0.05,\"downlinkDropRate\":0.01}"
The sub-parameters of the custom scenario need to be converted into JSON character strings.