> For the complete documentation index, see [llms.txt](https://wiki.ng-cdi.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://wiki.ng-cdi.com/network-devops/mininet-rest-api.md).

# Mininet: REST API

Mininet is an excellent extensible network emulation tool, however, currently is designed for human input...

## Get Nodes

<mark style="color:blue;">`GET`</mark> `http://localhost/mn/api/nodes`

This endpoint allows you to get a list of nodes within the topology.

#### Query Parameters

| Name  | Type   | Description                               |
| ----- | ------ | ----------------------------------------- |
| class | string | Only return nodes of a given python class |

{% tabs %}
{% tab title="200 Node list built successfully" %}

```
{
  "c0": {
    "class": "Controller"
  },
  "h2": {
    "class": "Host"
  },
  "s1": {
    "class": "OVSSwitch"
  },
  "h1": {
    "class": "Host"
  }
}
```

{% endtab %}
{% endtabs %}

## Get Node Information

<mark style="color:blue;">`GET`</mark> `http://localhost/mn/api/node/:node_name`

Get the information regarding a given node

#### Path Parameters

| Name       | Type   | Description                                        |
| ---------- | ------ | -------------------------------------------------- |
| node\_name | string | The name of the node to get get the information of |

{% tabs %}
{% tab title="200 Node information found" %}

```
{
  "ips": [
    "10.0.0.1"
  ],
  "macs": [
    "96:03:52:ef:ba:39"
  ],
  "class": "Host",
  "name": "h1"
}
```

{% endtab %}

{% tab title="400 Could not find node" %}

```
{"error": "node does not exist"}
```

{% endtab %}
{% endtabs %}

## Ping a Host Set

<mark style="color:blue;">`GET`</mark> `http://localhost/mn/api/pingset`

Run a ping to a host pair matrix

#### Query Parameters

| Name  | Type   | Description                         |
| ----- | ------ | ----------------------------------- |
| hosts | string | a comma-separated set of host names |

{% tabs %}
{% tab title="200 Host pings ran okay" %}

```
{
  "h2-h1": {
    "received": 1,
    "rtt_avg": 4.764,
    "sender": "h2",
    "sent": 1,
    "target": "h1"
  },
  "h1-h2": {
    "received": 1,
    "rtt_avg": 4.708,
    "sender": "h1",
    "sent": 1,
    "target": "h2"
  }
}
```

{% endtab %}

{% tab title="400 Host set empty" %}

```
{"error": "no hosts given"}
```

{% endtab %}
{% endtabs %}

## Ping all hosts

<mark style="color:blue;">`GET`</mark> `http://localhost/mn/api/pingall`

Ping a complete host set

{% tabs %}
{% tab title="200 Host pings ran okay" %}

```
{
  "h2-h1": {
    "received": 1,
    "rtt_avg": 3.37,
    "sender": "h2",
    "sent": 1,
    "target": "h1"
  },
  "h1-h2": {
    "received": 1,
    "rtt_avg": 2.682,
    "sender": "h1",
    "sent": 1,
    "target": "h2"
  }
}
```

{% endtab %}
{% endtabs %}

## Run iperf between 2 hosts

<mark style="color:blue;">`GET`</mark> `http://localhost/mn/api/iperf`

#### Query Parameters

| Name   | Type    | Description                              |
| ------ | ------- | ---------------------------------------- |
| time   | integer | number of seconds to run for ( >0, < 31) |
| type   | string  | l4 type to run \[tcp, udp]               |
| client | string  | host to run as iperf client              |
| server | string  | host to run as iperf server              |

{% tabs %}
{% tab title="200 Iperf test ran okay" %}

```
{
  "server": "h1",
  "client": "h2",
  "server_speed": "13243 Mbits/sec",
  "client_speed": "13256 Mbits/sec",
  "traffic_type": "TCP",
  "seconds": 1
}
```

{% endtab %}

{% tab title="400 " %}

```
{"error": "server not a valid host"}
```

{% endtab %}
{% endtabs %}
