> For the complete documentation index, see [llms.txt](https://kth-expeca.gitbook.io/testbedconfig/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://kth-expeca.gitbook.io/testbedconfig/checks-and-tests/sdr.md).

# Software-Defined Radios

## Reserve an SDR

### On Horizon (Openstack's web interface)

* Go to "Reservations"->"Leases"->"Create Lease".
* Choose a name for your lease.
* Choose the starting date, end data, and/or lease duration.
* Go to "Networks" tab, select "Reserve Network".
* Choose a proper "Network Name".
* From "Resource Properties" drop down lists, choose your "vlan\_id".
* Press "Create" on the last tab.
* Wait on the "Reservations"->"Leases" page, until the lease status turns "ACTIVE" from "PENDING".

Now if you check the networks in "Network"->"Networks", you should find a new network with the name you chose.

Write down "Segmentation ID" from the network's page. This is the VLAN id on the tenant switch. Check that a new VLAN is created on the tenant switch and the SDR's interface is an UNTAGGED members of the VLAN.

In this example, VLAN ID is 102 and the SDR's port is `te1/0/29`:

```
ssh expeca@10.10.1.3
switchf789d1#show vlan
Created by: D-Default, S-Static, G-GVRP, R-Radius Assigned VLAN, V-Voice VLAN

Vlan       Name           Tagged Ports      UnTagged Ports      Created by    
---- ----------------- ------------------ ------------------ ----------------                        
102         102         te1/0/1,te1/0/50      te1/0/29              S
```

## Hello World Test

### On Horizon (Openstack's web interface)

* Create a new container with the image `praqma/network-multitool`.
* Attach the SDR's RJ45 network to this container.
* Set the labels: `networks.1.interface=eno12429,networks.1.ip=10.30.1.200/24`
* Go to "Scheduler Hints" tab, create a custom "Scheduler Hint" with the name "reservation" and set its value to the reservation id of your worker lease.
* Press "Create" and wait on "Container"->"Containers" page for the created container to turn into "Running" state.

On the tenant switch, check that the chosen interface and the SDR's interface are both UNTAGGED members of the VLAN. In this example, worker's port is `te1/0/32`:

```
ssh expeca@10.10.1.3
switchf789d1#show vlan
Created by: D-Default, S-Static, G-GVRP, R-Radius Assigned VLAN, V-Voice VLAN

Vlan       Name           Tagged Ports      UnTagged Ports      Created by    
---- ----------------- ------------------ ------------------ ----------------                        
102         102         te1/0/1,te1/0/50  te1/0/29,te1/0/32         S
```

On the console page of the container, you should be able to ping the SDR's interface.

## Reboot Test

* Create a new container with the image `samiemostafavi/sdr-tools`.
* Select the sdr network to be attached to the container.
* Set the labels: `networks.1.interface=eno12429,networks.1.ip=10.30.1.200/24`.
* Set the env variables: `SERVICE=reboot,SDR=sdr-02,JSON_PATH=sdrs.json`

In the logs you have to observe these:

```
You have chosen sdr-02
sdr-02 is reachable: {'mango': {'ip': '10.30.1.3', 'port': '22', 'tenant-port': 'te1/0/29', 'up': False}, 'ni': {'ip': '10.30.1.4', 'port': '22', 'tenant-port': 'te2/0/14', 'up': True}}
SSHing to 10.30.1.4, username:root, password: 
running command on 10.30.1.4: 
/sbin/reboot > /dev/null 2>&1 &
Waiting 200 seconds for the sdr to load
10 seconds to the next poll...
10 seconds to the next poll...
10 seconds to the next poll...
sdr-02 ni is up.
```

## WiFi Test

In order to test WiFi end-to-end networking, you must reserve one worker with at least two 1Gbps interfaces and two software-defined radios (only rj45 ports suffice).

We create the following network:

```
  sdr-02(AP)           sdr-09(STA)
  10.30.1.3     ||     10.30.1.17
192.168.11.1 <------> 192.168.11.10
```

* Change the SDRs designs to Mango. Run the following sequence twice, once for `sdr-02` and again for `sdr-09`:
  * Create a new container with the image `samiemostafavi/sdr-tools`.
  * Select sdr-0x-rj45 network to be attached to the container.
  * Set the labels: `networks.1.interface=eno12429,networks.1.ip=10.30.1.200/24`.
  * Set the env variables: `SERVICE=change_design,DESIGN=mango,SDR=sdr-0x,JSON_PATH=sdrs.json`.
* Run `sdr-02` as the WiFi access point:
  * Create a new container with the image `samiemostafavi/sdr-tools`.
  * Select sdr-02-rj45 network to be attached to the container.
  * Set the labels: `networks.1.interface=eno12429,networks.1.ip=10.30.1.200/24`.
  * Set the env variables: `SERVICE=start_mango,DESIGN=mango,SDR=sdr-02,SIDE=ap,CONFIG={"mac_addr":"40:d8:55:04:20:12"},JSON_PATH=sdrs.json`.

If everything goes well, you should see the following output in the AP sdr logs:

```
sdr-02 mango is running ap with ip 192.168.11.1.
```

* Run `sdr-09` as the WiFi station:
  * Create a new container with the image `samiemostafavi/sdr-tools`.
  * Select sdr-09-rj45 network to be attached to the container.
  * Set the labels: `networks.1.interface=eno12429,networks.1.ip=10.30.1.200/24`.
  * Set the env variables: `SERVICE=start_mango,DESIGN=mango,SDR=sdr-09,SIDE=sta,CONFIG={"mac_addr":"40:d8:55:04:20:19"},JSON_PATH=sdrs.json`.

If you see the following in the STA sdr, it means that the connection has been established:

```
command stdout: 
192.168.11.10
sdr-09 mango is running sta with ip 192.168.11.10.
```

* Check the connection quality: For the station side use `sdr-09` and `SIDE=sta`, for the access point side use `sdr-02` and `SIDE=ap`:
  * Create a new container with the image `samiemostafavi/sdr-tools`.
  * Select sdr-09-rj45 network to be attached to the container.
  * Set the labels: `networks.1.interface=eno12429,networks.1.ip=10.30.1.200/24`.
  * Set the env variables: `SERVICE=check_mango,SDR=sdr-09,SIDE=sta,JSON_PATH=./sdrs.json,SPEED_CHECK=192.168.11.1`.

You will get information like bandwidth, frequency and an iperf speed test.

## End-to-End WiFi Test

We create the following network:

```
   worker-01(eno12429)                                               worker-01(eno12399)
         server              sdr-02(AP)          sdr-09(STA)               client
      10.30.1.251 <--------> 10.30.1.3     ||    10.30.1.17  <-------->  10.30.1.252
                            192.168.11.1 <----> 192.168.11.10
```

Continue the privious test with configuring the routing tables on the SDRs:

* Run AP wifi routing configs on `sdr-02`:
  * Create a new container with the image `samiemostafavi/sdr-tools`.
  * Select sdr-02-rj45 network to be attached to the container.
  * Set the labels: `networks.1.interface=eno12429,networks.1.ip=10.30.1.200/24`.
  * Set the env variables:

    ```
    SERVICE=config_mango_routes,SDR=sdr-02,SIDE=ap,JSON_PATH=sdrs.json,PROTOCOL=udp,SERVER_IP=10.30.1.251,SERVER_PORT=50000,AP_SERVER_PORT=50500,AP_STA_PORT=50000,STA_MAC_ADDR=40:d8:55:04:20:19,STA_IP=192.168.11.10,STA_AP_PORT=50500
    ```
* Run STA wifi routing configs on `sdr-09`:
  * Create a new container with the image `samiemostafavi/sdr-tools`.
  * Select sdr-02-rj45 network to be attached to the container.
  * Set the labels: `networks.1.interface=eno12399,networks.1.ip=10.30.1.201/24`.
  * Set the env variables:

    ```
    SERVICE=config_mango_routes,SDR=sdr-09,SIDE=sta,JSON_PATH=sdrs.json,PROTOCOL=udp,CLIENT_IP=10.30.1.252,CLIENT_PORT=50000,STA_CLIENT_PORT=50000,STA_AP_PORT=50500,AP_IP=192.168.11.1,AP_STA_PORT=50000
    ```
* Run IRTT Server
  * Create a new container with the image `nuriafe99/irtt-server`.
  * Select sdr-02-rj45 network to be attached to the container.
  * Set the labels: `networks.1.interface=eno12429,networks.1.ip=10.30.1.251/24`.
* Run IRTT Client
  * Create a new container with the image `samiemostafavi/sdr-tools`.
  * Select sdr-09-rj45 network to be attached to the container.
  * Set the labels: `networks.1.interface=eno12399,networks.1.ip=10.30.1.252/24`.

Open the client's console and run the following command:

```
irtt client -i 10ms -d 100s -l 172 --fill=rand 10.30.1.17:50000 --local=0.0.0.0:50000
```
