# 8/12 Test VxLAN on pure legacy network
[TOC]
## Topology
* Entire Network

* VM1

* VM2

* VM3

## Environment
### VM1
* Hardware setting
* interface: enp0s3
* ip address: 192.168.56.101/24
* default gateway: 192.168.56.102 (VM3)
* Mininet
* s1
* s1-eth1: connected to h1
* vxlan: VxLAN interface
* h1
* ip address: 10.0.0.1
### VM2
* Hardware setting
* interface: enp0s3
* ip address: 192.168.7.3/24
* default gateway: 192.168.7.4 (VM3)
* Mininet
* s1
* s1-eth1: connected to h1
* vxlan: VxLAN interface
* h1
* ip address: 10.0.0.2
### VM3
* Interfaces
* enp0s3: connected to s1
* enp0s8: connected to s2
* Mininet
* s1
* s1-eth1: connect to s2
* ip address: 192.168.56.102/24
* s2
* s2-eth1: connect to s1
* ip address: 192.168.7.4/24
## Commands
### VM1
```bash
# create a topology with a switch(s1) and a host(h1)
$ sudo mn --topo single,1
# add a port on s1, set the type to vxlan
$mininet > sh ovs-vsctl add-port s1 vxlan -- set interface vxlan type=vxlan option:remote_ip=192.168.7.3 option:key=100
```
### VM2
```bash
# create a topology with a switch(s1) and a host(h1)
$ sudo mn --topo single,1
# add a port on s1, set the type as vxlan
$mininet > sh ovs-vsctl add-port s1 vxlan -- set interface vxlan type=vxlan option:remote_ip=192.168.56.101 option:key=100
# set h1's ip address to 10.0.0.2
$mininet > h1 ifconfig h1-eth0 10.0.0.2
```
### VM3
* <span>topo.py</span>
```python
from mininet.topo import Topo
class MyTopo( Topo ):
def __init__( self ):
Topo.__init__( self )
# Add switches
s1 = self.addSwitch( 's1' )
s2 = self.addSwitch( 's2' )
# Add links
self.addLink( s1, s2 )
topos = { 'mytopo': MyTopo }
```
* Terminal Command
```bash
$ sudo mn --custom topo.py --topo mytopo
# bind ethernet interfaces on ovs bridges
$ sudo ovs-vsctl add-port s1 enp0s3
$ sudo ovs-vsctl add-port s2 enp0s8
# allocate ip addresses for ovs bridges
$ sudo dhclient enp0s3
$ sudo dhclient enp0s8
# add flow rules on s1
$ sudo ovs-ofctl add-flow s1 'priority=50000,udp,nw_dst=192.168.7.3,actions=output:1'
$ sudo ovs-ofctl add-flow s1 'priority=50000,udp,nw_dst=192.168.56.101,actions=output:2,mod_dl_src:08:00:27:c4:d9:6f,mod_dl_dst:08:00:27:91:1b:a1'
# add flow rules on s2
$ sudo ovs-ofctl add-flow s2 'priority=50000,udp,nw_dst=192.168.56.101,actions=output:1'
$ sudo ovs-ofctl add-flow s2 'priority=50000,udp,nw_dst=192.168.7.3,actions=output:2,mod_dl_src:08:00:27:10:6b:6c,mod_dl_dst:ff:ff:ff:ff:ff:ff'
```
## Result