Connecting two Mininet networks with GRE tunnel

Update1: I have a follow up post with some newer examples and extra which might help you debug any issues.

Update2: I have another post that show how to use Linux GRE tunnels instead of the OVS builtin GRE support.  Seems more stable.

——-

I was wondering if there was a way to connect two separate Mininet networks, then a little while ago, I came across a post about OpenVSwitch and using GRE tunnels.  So today, I thought I would try an experiment and try and connect two separate Mininet networks that are also running in separate VMs.

First, I started two Mininet networks in the separate VMs.

VM2(VirtualBox 192.168.56.102):

  • host2
  • switch2

I use the following mininet custom topology.

from mininet.topo import Topo

class MyTopo( Topo ):
    "Simple topology example."

    def __init__( self ):
        "Create custom topo."

        # Initialize topology
        Topo.__init__( self )

        # Add hosts and switches
        leftHost = self.addHost( 'h2' )
        leftSwitch = self.addSwitch( 's2' )

        # Add links
        self.addLink( leftHost, leftSwitch )


topos = { 'mytopo': ( lambda: MyTopo() ) }

Start the network.

sudo mn –custom ./simple.py –topo mytopo –switch ovsk

VM1 (VirtualBox 192.168.56.101):

  • host1
  • switch1

I use the following mininet custom topology.

from mininet.topo import Topo

class MyTopo( Topo ):
    "Simple topology example."

    def __init__( self ):
        "Create custom topo."

        # Initialize topology
        Topo.__init__( self )

        # Add hosts and switches
        h1 = self.addHost( 'h1' )
        s1 = self.addSwitch( 's1' )

        # Add links
        self.addLink( h1, s1 )


topos = { 'mytopo': ( lambda: MyTopo() ) }

Start the VM and have it point to the controller in the other VM.

sudo mn --custom ./simple.py --topo mytopo --switch ovsk --controller=remote,ip=192.168.56.102,port=6633

But before I can connect them, I have to change the default IP address that the hosts get automatically configured with so that I do not get two hosts with 10.0.0.1.  So I open an xterm in host2 and changed the IP address from the default assigned IP of 10.0.0.1 to 10.0.0.2.

ifconfig h2-eth0 inet 10.0.0.2

To make sure, I try and ping h1 from h2 from VM2 mininet CLI and it fails.

mininet> h2 ping -c 1 10.0.0.1
PING 10.0.0.1 (10.0.0.1) 56(84) bytes of data.
From 10.0.0.2 icmp_seq=1 Destination Host Unreachable

--- 10.0.0.1 ping statistics ---
1 packets transmitted, 0 received, +1 errors, 100% packet loss, time 0ms

Now we setup the tunnel between the switches.

VM1:

sudo ovs-vsctl add-port s1 s1-gre1 -- set interface s1-gre1 type=gre options:remote_ip=192.168.56.102

VM2:

sudo ovs-vsctl add-port s2 s2-gre1 -- set interface s2-gre1 type=gre options:remote_ip=192.168.56.101

And then I try the test again.

mininet> h2 ping -c 1 10.0.0.1
PING 10.0.0.1 (10.0.0.1) 56(84) bytes of data.
64 bytes from 10.0.0.1: icmp_req=1 ttl=64 time=0.044 ms

--- 10.0.0.1 ping statistics ---
1 packets transmitted, 1 received, 0% packet loss, time 0ms
rtt min/avg/max/mdev = 0.044/0.044/0.044/0.000 ms

It was a fun test.  Hope someone finds this useful.  I hope to add the feature into my next version on MiniEdit.

Miniedit 2.0.0.5

With September rolling in, family life got pretty busy.  Thought I would put out a release with a few more updates.

  • Connect switch or host nodes to physical interface (like the example hwintf.py)
  • Add host cpu opts
    • cpu: desired overall system CPU fraction
      • scheduler: host, cfs or rt
    • cores: (real) core(s) this host can run on
  • Udpate load and save with above additions
  • Change load/save file format to Python dictionary

Download Miniedit 2.0.0.5 here.

If requested, I can make a script that will convert the pre-2.0.0.5 save file format to the new style.  Just leave a comment.  But hopefully the networks you have created are small enough to just recreate manually.

Upgrading Open vSwitch in Mininet 2.0 VM to OVS 1.10

Update:  I have a followup post on how to do the same thing but instead building and installing Debian package files.  It’s a cleaner approach and allows easier upgrades over and over.

—————————

Just want to share something I learned from the Mininet mailing list and tried out. These are instructions, courtesy of Vikram Dham from this post, but have been slightly altered for my own reading.

The following instruction are how to upgrade the Open vSwitch version that comes in the Mininet 2.0 VM to Open vSwitch 1.10.  Some features that I have seen are support for OpenFlow 1.2 and VXLAN tunnels.

1. Setting up Mininet VM, it you already don’t have it.
– Download the Mininet 2.0 vm and import it in VirtualBox.  These should be similar to the instruction on the Mininet site.
– Download Mininet 2.0 from https://github.com/mininet/mininet/downloads/
– Import unzip the package
– Import appliance into VirtualBox
– Change setting to add additional Host Only network adapter
– Start VM and login as mininet
– Enable the second interface ‘sudo dhclient eth1’

2. Become root
sudo -s

3. Remove old packaes
apt-get remove openvswitch-common openvswitch-datapath-dkms openvswitch-controller openvswitch-pki openvswitch-switch

4. Download and unpack Open vSwitch 1.10
cd /root
wget http://openvswitch.org/releases/openvswitch-1.10.0.tar.gz
tar zxvf openvswitch-1.10.0.tar.gz

5. Build and install
cd openvswitch-1.10.0
./configure –prefix=/usr –with-linux=/lib/modules/`uname -r`/build
make
make install
make modules_install
rmmod openvswitch
depmod -a

6. Disable to default controller
echo “manual” >> /etc/init/openvswitch-controller.override
/etc/init.d/openvswitch-controller stop

7. Start OVS server process
/etc/init.d/openvswitch-switch start

Now you should have a working Mininet using OVS 1.10. Below are some steps to test the new OVS 1.10 features that you now have available.

8. Start mininet with a test topology
cd /home/mininet/mininet/examples
./emptynet.py

9. In another window, check what protocol the switch is running.
ovs-ofctl -O OpenFlow10 show s3
ovs-ofctl -O OpenFlow12 show s3

10. One of the above will error, showing that is does not support that version.  Now let’s change it to OF1.2.
ovs-vsctl set bridge s3 protocols=OpenFlow12

You will see that OpenFlow12 command worked.

11. You can run another command to see if the protocol is set on the switch.

root@mininet-vm:~# ovs-vsctl list bridge s3
_uuid               : e3171ac1-0b53-4770-be32-e5903e3801be
controller          : [b82acc19-5536-42b9-95eb-22942e683b98]
datapath_id         : "0000000000000003"
datapath_type       : ""
external_ids        : {}
fail_mode           : secure
flood_vlans         : []
flow_tables         : {}
mirrors             : []
name                : "s3"
netflow             : []
other_config        : {datapath-id="0000000000000003"}
ports               : [34a45885-7cda-4cb8-a76c-35e048795201, c33e59b5-050b-4fad-92da-e495d66de4a4, d0c18e1a-fc46-4f41-89df-968cd59c01d5]
protocols           : ["OpenFlow12"]
sflow               : []
status              : {}
stp_enable          : false

12. You can enable all supported protocols by running the following.
ovs-vsctl set bridge s3 protocols=OpenFlow10,OpenFlow12,OpenFlow13