Using Linux GRE tunnels to connect two Mininet networks

I’ve had a few posts about how to use Open vSwitch’s built in GRE tunnel support to connect two Mininet networks. As many that have tried to use my scripts, I’ve also found it a pain to get going. Sometimes it works, sometimes it doesn’t. Then I saw a post in the Mininet mailing list from Felix Wallaschek about how he uses Linux GRE tunnels to connect separate Mininet networks in a program he setup called Maxinet. I decided to take a look at how his application did it and try using that same method.

Below is an example of the commands to run on one of the systems running Mininet. You would need to setup this tunnel before you can bind it into your switch in Mininet using the Intf(name, node) method like the example in mininet/examples/hwintf.py.

sudo ip link add s1-gre1 type gretap remote 192.168.56.103 local 192.168.56.102 ttl 64
sudo ip link set dev s1-gre1 up

A few notes. I am using Ubuntu 12.04. The version of Open vSwitch that comes with this version of Ubuntu does not play nicely with the Linux GRE tunnels. But when I upgraded to Open vSwitch 2.0, everything worked much better. So below are the scripts that I had in my previous post, but changed to setup and use Linux GRE tunnels.

Script for VM1(192.168.56.102):

#!/usr/bin/python

from mininet.net import Mininet
from mininet.node import Controller, RemoteController, Node
from mininet.cli import CLI
from mininet.log import setLogLevel, info
from mininet.link import Link, Intf

def emptyNet():

    NODE1_IP='192.168.56.102'
    NODE2_IP='192.168.56.103'
    CONTROLLER_IP='192.168.56.103'

    net = Mininet( topo=None,
                   build=False)

    net.addController( 'c0',
                      controller=RemoteController,
                      ip=CONTROLLER_IP,
                      port=6633)

    h1 = net.addHost( 'h1', ip='10.0.0.1' )
    h2 = net.addHost( 'h2', ip='10.0.0.2' )
    s1 = net.addSwitch( 's1' )
    net.addLink( h1, s1 )
    net.addLink( h2, s1 )

    # Delete old tunnel if still exists
    s1.cmd('ip tun del s1-gre1')
    # Create GRE tunnel
    s1.cmd('ip li ad s1-gre1 type gretap local '+NODE1_IP+' remote '+NODE2_IP+' ttl 64')
    s1.cmd('ip li se dev s1-gre1 up')
    Intf( 's1-gre1', node=s1 )

    net.start()
    CLI( net )
    net.stop()

if __name__ == '__main__':
    setLogLevel( 'info' )
    emptyNet()

Script for VM2(192.168.56.103):

#!/usr/bin/python

from mininet.net import Mininet
from mininet.node import Controller, RemoteController
from mininet.cli import CLI
from mininet.log import setLogLevel, info
from mininet.link import Link, Intf

def emptyNet():

    NODE1_IP='192.168.56.102'
    NODE2_IP='192.168.56.103'
    CONTROLLER_IP='192.168.56.103'

    net = Mininet( topo=None,
                   build=False)

    net.addController( 'c0',
                      controller=RemoteController,
                      ip=CONTROLLER_IP,
                      port=6633)

    h3 = net.addHost( 'h3', ip='10.0.0.3' )
    h4 = net.addHost( 'h4', ip='10.0.0.4' )
    s2 = net.addSwitch( 's2' )
    net.addLink( h3, s2 )
    net.addLink( h4, s2 )

    # Delete old tunnel if still exists
    s2.cmd('ip tun del s2-gre1')
    # Create GRE tunnel
    s2.cmd('ip li ad s2-gre1 type gretap local '+NODE2_IP+' remote '+NODE1_IP+' ttl 64')
    s2.cmd('ip li se dev s2-gre1 up')
    Intf( 's2-gre1', node=s2 )

    net.start()
    CLI( net )
    net.stop()

if __name__ == '__main__':
    setLogLevel( 'info' )
    emptyNet()

I just run the above script on the appropriate VM and then test it. Below shows me having h1 on the VM1 Mininet ping h3 on the VM2 Mininet.

mininet> h1 ping -c 1 10.0.0.3
PING 10.0.0.3 (10.0.0.3) 56(84) bytes of data.
64 bytes from 10.0.0.3: icmp_req=1 ttl=64 time=7.97 ms

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

One other thing to note, the above is a point to point network. If you are going to have more than two Mininet networks, you will also need to add the ‘key’ parameter to tunnel creation command.

Thanks again Felix for showing us how to use Linux GRE tunnels with Mininet.

This post ‘Using Linux GRE tunnels to connect two Mininet networks’ first appeared on https://gregorygee.wordpress.com/.

Advertisements

10 Responses to Using Linux GRE tunnels to connect two Mininet networks

  1. Pingback: Connecting two Mininet networks with GRE tunnel – Part 2 | Tech and Trains

  2. ashishk29 says:

    Hi,
    Do you execute these scripts using python directly, or using the “mn” command?

  3. Pingback: Using Linux GRE tunnels to connect two Mininet networks | heodaohoa

  4. bmullan says:

    What I’d really like to see someone write-up are thoughts and techniques to implement VxLAN using Unicast vs Multicast. GRE tunnels are fairly easy to setup and they do work but their configuration becomes complex with any type of scale.

    VxLAN originally required multicast be configured in the network which most Internet Service Providers and IaaS cloud providers don’t or won’t support unless you happen to be a particularly big customer.

    Today Unicast VxLAN has been gaining more support. Cisco and other networking equipment manufacturers have implemented Unicast capability for VxLAN but it usually requires their equipment.

    I’d like to see more impetus given to an Open Source solution. MetaCloud & Cumulus opensourced VXFLD (https://github.com/CumulusNetworks/vxfld) last year just before Cisco bought MetaCloud. But there are also now other approaches I believe such as CoreOS’s opensource of Flannel (https://github.com/coreos/flannel) which I believe is not necessarily tied solely to either CoreOS or Docker.

    The linux bridge & OVS can both support VxLAN and looking at L2MISS, L3MISS as well as other options in the linux bridge seem to point to possibilities of a open source solution to VTEP & VxLAN implementation independent of proprietary networking equipment choices.

  5. Pingback: connecting mininet networks on different machines | duongnguyentung

  6. heodaohoa says:

    Hi there,

    Sorry for my question if it sounds stupid. I am quite new to this. Actually, what I am trying to do is to connect several Mininet networks. Could you please tell me the command that I have to you to create tunnels (I. E. With the key parameter as you said) .

    Many thanks in advance.

    Best,
    Daniel

    • Gregory Gee says:

      To use a key, just add that value to the end of the command. The key must be a number. When setting up each end of the tunnel just make sure you use the same key.

      PC1:
      sudo ip link add s1-gre1 type gretap remote 192.168.56.103 local 192.168.56.102 ttl 64 key 1

      PC2:
      sudo ip link add s1-gre1 type gretap remote 192.168.56.102 local 192.168.56.103 ttl 64 key 1

  7. heodaohoa says:

    Thanks for your prompt reply. I have tried the following code, however, it does not work for me. Could you please point out where is the error?

    – VM1 (Controller , s0, h10, h20)

    s0.cmd(‘ip li ad s0-gre1 type gretap local ‘+CONTROLLER_IP+’ remote ‘+NODE1_IP+’ ttl 64 key 1′)

    s0.cmd(‘ip li ad s0-gre2 type gretap local ‘+CONTROLLER_IP+’ remote ‘+NODE2_IP+’ ttl 64 key 3′)

    – VM2: (s1, h1, h2)

    s1.cmd(‘ip li ad s1-gre1 type gretap local ‘+NODE1_IP+’ remote ‘+NODE2_IP+’ ttl 64 key 2′)

    s1.cmd(‘ip li ad s1-gre2 type gretap local ‘+NODE1_IP+’ remote ‘+CONTROLLER_IP+’ ttl 64 key 1′)

    – VM3:(s2, h3,h4)

    s2.cmd(‘ip li ad s2-gre1 type gretap local ‘+NODE2_IP+’ remote ‘+NODE1_IP+’ ttl 64 key 2′)

    s2.cmd(‘ip li ad s2-gre2 type gretap local ‘+NODE2_IP+’ remote ‘+CONTROLLER_IP+’ ttl 64 key 3′)

    (Basically I have 3 Mininets on 3 VMs, I want them to talk to each other.)

    VM1:
    s0.cmd(‘ip tun del s0-gre1’)
    s0.cmd(‘ip tun del s0-gre2’)
    s0.cmd(‘ip li del s0-gre1’)
    s0.cmd(‘ip li del s0-gre2’)

    s0.cmd(‘ip li ad s0-gre1 type gretap local ‘+CONTROLLER_IP+’ remote ‘+NODE1_IP+’ ttl 64 key 01′)
    s0.cmd(‘ip li ad s0-gre2 type gretap local ‘+CONTROLLER_IP+’ remote ‘+NODE2_IP+’ ttl 64 key 02′)

    s0.cmd(‘ip li se dev s0-gre1 up’)
    s0.cmd(‘ip li se dev s0-gre2 up’)
    Intf( ‘s0-gre1’, node=s0 )
    Intf( ‘s0-gre2’, node=s0 )

    Thank you very much.

    Best,

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: