---
# System prepended metadata

title: Exercises - OpenDaylight

---

# Exercises - OpenDaylight

## Set up the environment

Tutorial VM (**Lab7-ODL.ova**): 
- https://drive.google.com/open?id=1Pofg0l9n_3Go4TlIfg20rhrXz9T6ZKnz 
(user: **tutorial**, psw: **tutorial**)
- **Backup:** https://intrig.dca.fee.unicamp.br:8840/index.php/s/atasnPfukOH7N4g 
(user: **tutorial**, psw: **tutorial**)

Hash code md5:
- 2e3b1614af71cad5c5df14b58fdc9ec0  Lab7-ODL.ova 

## Exercises

Exercises are divided in three parts:

1. Learning-Switch (Reactive Mode)
2. Flow Programming Through REST (Proactive Mode)
3. OVSDB (Open vSwitch database)



### Part 1: Learning-Switch (Reactive Mode)

**1)** Start the ODL controller in debug mode  **#Terminal 1**

```bash
$ cd $control
$ ./karaf debug
```

**2)** Verify if the feature `sdnhub-tutorial-learning-switch` is installed
```bash
> feature:list -i |grep sdnhub-tutorial-learning-switch
```
:::warning
**2.1)** If it is not installed, install it
```bash
> feature:install sdnhub-tutorial-learning-switch
```
:::

:::warning
**2.2)** Wait until the `Learning-Switch` program is installed and **active**
```bash
> bundle:list -s |grep learning-switch
189 | Active   |  80 | 1.0.0.SNAPSHOT          org.sdnhub.odl.tutorial.learning-switch.impl  
```
:::

:::warning
If you want to know a little more how the learning-switch program works, explore the following Java-based file: 
```bash
vim $learn/TutorialL2Forwarding.java 
```
Pay attention to the code block from line #143. 
:::

**3)** Start mininet topology **#Change to a second terminal (Terminal 2)**
```bash
sudo mn --topo single,3 --mac --switch ovsk,protocols=OpenFlow13 --controller remote
```

:::warning
**3.1)** We wait until the controller is connected to the mininet topology **(Terminal 3)**:
```bash
$ sudo ovs-vsctl show
       Controller "tcp:127.0.0.1:6653"
       is_connected: true
```
:::

**4)** Try to do ping between “host1” and “host2” **(Terminal 2)**:
```bash
mininet> h1 ping -c5 h2
From 10.0.0.1 icmp_seq=1 Destination Host Unreachable
From 10.0.0.1 icmp_seq=1 Destination Host Unreachable
```

:::danger
**Question:** Why is the Ping failing?
:::

:::info
:::spoiler Tips:
Verify flow rules in "s1" **(Terminal 3)**:
```bash
sudo ovs-ofctl -O OpenFlow13 dump-flows s1
```
Ping still fails because there is no default rule in the switch to send packet-in messages to the controller (Only for OpenFlow 1.3).
:::


**5)** Add the next rule and verify the ping **(Terminal 2)**:
```bash
mininet> s1 ovs-ofctl add-flow tcp:127.0.0.1:6654 -O OpenFlow13 priority=1,action=output:controller
mininet> h1 ping -c 10 h2
```

:::danger
**Question:** Why are the first two round-trip time (RTT) records higher than the rest of RTT records?
:::

:::info
:::spoiler Tips:
Reference: *"Comparison of SDN OpenFlow Network Simulator and Emulators: EstiNet vs. Mininet"
[http://www.estinet.com/fckimages/14117014621397232510.pdf](http://www.estinet.com/fckimages/14117014621397232510.pdf)*
:::

### Part 2: Flow Programming Through REST (Proactive Mode)

It is possible to use RESTconf to send static flows to the controller. The REST input is based on the YANG model.

**1)** Start and configure the ODL controller (**Terminal #1**)
```bash
> logout # Logout to the controller
cd $control
./karaf clean # Clean features and bundles
```

:::warning
**1.1)** Install the necessary features to use **Restconf**:
```bash
> feature:install odl-restconf odl-mdsal-apidocs
```
**1.2)** Wait until features are installed and **active**
```bash
> bundle:list -s | grep restconf
> bundle:list -s | grep mdsal
```
:::

**2)** Start the mininet topology (**Terminal #2**)
```bash
mininet > exit # Exit to the mininet
sudo mn -c # Clean mininet configuration
sudo mn --topo single,3 --mac --switch ovsk,protocols=OpenFlow13 --controller remote
```

:::warning
**2.1)** We wait until the controller is connected to the mininet topology **(Terminal 3)**:
```bash
$ sudo ovs-vsctl show
       Controller "tcp:127.0.0.1:6653"
       is_connected: true
```
:::

**3)** Open Postman application:
```bash
tutorial@VM-1:~$ ./Postman/Postman &
```

**4)** In the Postman app, there is a collection (“2REST”) with the REST-API calls that we need in this activity.

:::warning
**4.1)** Execute the “forward” and “reverse” REST-API calls:
:::
![](https://i.imgur.com/8tWPbVW.png)


**5)** Prints all flow entries in switch s1 (**terminal #2**)
```bash
mininet> sh ovs-ofctl dump-flows s1 -O OpenFlow13
OFPST_FLOW reply (OF1.3) (xid=0x2):
 cookie=0x0, duration=5264.052s, table=0, n_packets=20, n_bytes=1624, in_port=1 actions=output:2
 cookie=0x0, duration=4983.190s, table=0, n_packets=17, n_bytes=1498, in_port=2 actions=output:1
```

**6)** Testing connectivity between hosts h1 and h2
```bash
mininet> h1 ping -c 5 h2
PING 10.0.0.2 (10.0.0.2) 56(84) bytes of data.
64 bytes from 10.0.0.2: icmp_seq=1 ttl=64 time=0.432 ms
64 bytes from 10.0.0.2: icmp_seq=2 ttl=64 time=0.118 ms
```

**7)** Finally, stop “controller” (**Terminal #1**) and “mininet” (**Terminal #2**):
```bash
opendaylight-user@root> logout # Logout to the controller
mininet > exit # Exit to the mininet
```

### Part 3: OVSDB (Open vSwitch database)

**1)** Run the ODL Controller (**Terminal 1**):
```bash
$ cd /home/tutorial/controller-base/opendaylight/
$ ./run.sh
```

*Note: Wait until all plugins are loaded and started by the controller*
![](https://i.imgur.com/2mtngIa.png)


**2)** Create a new topology in Mininet (**Terminal 2**):
```bash
$ sudo mn -c
$ sudo mn --topo linear,2 --controller remote
```

:::warning
**2.1)** We wait until the controller is connected to the mininet topology **(Terminal 3)**:
```bash
$ sudo ovs-vsctl show
       Controller "tcp:127.0.0.1:6653"
       is_connected: true
```
:::

**3)** Start browser and open [http://127.0.0.1:8080](http://127.0.0.1:8080) (user: **admin**, pw: **admin**)

**4)** Try to do ping between “host1” and “host2” (**Terminal 2**):
```bash
mininet> h1 ping -c5 h2
```

**5)** Refresh de ODL GUI (press F5 in browser)

:::danger
**Question:** Did you see some different in the topology shown by the ODL GUI before and after the use of the ping command?
:::

**6)** The current topology created by Mininet will be modify using the ODL OVSDB plugin.

:::warning
**6.1)** Check in the controller terminal if two ovsdb plugins are **installed** and **activated**:
```bash
osgi> ss ovs
```
![](https://i.imgur.com/pEZiHTK.png)
:::

**7)** Setting up the OVS Manager

Open the **Postman** app and open the **“3Mininet + OVSDB + OF”** Collection:

:::warning
**7.1)** Execute the fist REST-API call in Postman: **Connect to OVSDB Server (1)**:
![](https://i.imgur.com/DD3ZWLt.png)


**7.2)** After the host is connected to the controller. The OVS configuration will reflect the established connection with a boolean value in the **"Manager"** table in the **"is_connected"** column of **"true"**.
```bash
tutorial@VM-1:~$ sudo ovs-vsctl show
b12e9e0b-20cb-4c09-a599-ccbf33a3f014
    Manager "ptcp:6640"
        is_connected: true
```
:::

**8)** Execute the remaining REST-API calls **(2-9)** in Postman and pay attention into the ODL GUI **(F5 refresh for each call)**:
![](https://i.imgur.com/S3YMLiU.png)


:::danger
**Question:** Could you explain with your own words all the process?
:::

**9)** On the Mininet console, ping between 2 hosts. Make sure that the ping succeeds with the new topology.
```bash
mininet> h1 ping -c10 h2
PING 10.0.0.2 (10.0.0.2) 56(84) bytes of data.
64 bytes from 10.0.0.2: icmp_seq=3 ttl=64 time=2.91 ms
64 bytes from 10.0.0.2: icmp_seq=4 ttl=64 time=0.064 ms
64 bytes from 10.0.0.2: icmp_seq=5 ttl=64 time=0.061 ms
64 bytes from 10.0.0.2: icmp_seq=6 ttl=64 time=0.152 ms
64 bytes from 10.0.0.2: icmp_seq=7 ttl=64 time=0.112 ms
64 bytes from 10.0.0.2: icmp_seq=8 ttl=64 time=0.063 ms
64 bytes from 10.0.0.2: icmp_seq=9 ttl=64 time=0.160 ms
64 bytes from 10.0.0.2: icmp_seq=10 ttl=64 time=0.048 ms
```

:::danger
**Question:** Exploring the ODL GUI (http://127.0.0.1:8080), which entries are present in each virtual switch (i.e., s1, s2, br1, br2)?
:::

:::info
:::spoiler Tips:
Navigate through the other taps: “Flows” or “Troubleshoot”
