A Mininet host in one VM talks to another host in anther VM via GRE tunnel

 

In the first VM, we have an IP address (192.168.229.134) that can talk to another VM with IP address (192.168.229.141)

 

 

 

[script 1 in the first VM]

#!/usr/bin/python

 

from mininet.net import Mininet

from mininet.node import  Controller, RemoteController, OVSKernelSwitch

from mininet.cli import CLI

from mininet.log import setLogLevel

from mininet.link import TCLink, Intf

 

def topology():

    "Create a network."

    net = Mininet( controller=Controller, link=TCLink, switch=OVSKernelSwitch )

    print "*** Creating nodes"

    s1 = net.addSwitch( 's1')

    h1 = net.addHost( 'h1', ip="10.0.0.1" )

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

 

    print "*** Adding Link"

    net.addLink(h1,s1)

 

    print "*** Starting network"

    c0.start()

    s1.start( [c0] )

    s1.cmd("ip link add s1-gre1 type gretap local 192.168.229.134 remote 192.168.229.141 ttl 64")

    s1.cmd("ip link set s1-gre1 up")

    Intf("s1-gre1", node=s1)

 

    print "*** Running CLI"

    net.start()

    CLI( net )

    print "*** Stopping network"

    s1.cmd("ip link del dev s1-gre1")

    net.stop()

 

if __name__ == '__main__':

    setLogLevel( 'info' )

    topology()

 

[script 2 in the second VM]

#!/usr/bin/python

 

from mininet.net import Mininet

from mininet.node import  Controller, RemoteController, OVSKernelSwitch

from mininet.cli import CLI

from mininet.log import setLogLevel

from mininet.link import TCLink, Intf

 

def topology():

    "Create a network."

    net = Mininet( controller=Controller, link=TCLink, switch=OVSKernelSwitch )

    print "*** Creating nodes"

    s2 = net.addSwitch( 's2')

    h2 = net.addHost( 'h2', ip="10.0.0.2" )

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

 

    print "*** Adding Link"

    net.addLink(h2,s2)

 

    print "*** Starting network"

    c0.start()

    s2.start( [c0] )

    s2.cmd("ip link add s2-gre1 type gretap local 192.168.229.141 remote 192.168.229.134 ttl 64")

    s2.cmd("ip link set s2-gre1 up")

    Intf("s2-gre1", node=s2)

 

    print "*** Running CLI"

    net.start()

    CLI( net )

    print "*** Stopping network"

    s2.cmd("ip link del dev s2-gre1")

    net.stop()

 

if __name__ == '__main__':

    setLogLevel( 'info' )

    topology()

 

Open a terminal in the first VM to run controller program

Open another terminal in the first VM to run the script 1

 

Open a terminal in the second VM

 

Check the controller terminal again that we can find that the switch1 and switch2 are already connected to the controller.

 

Try ping

 

H1 can talk to H2 now.

 

[references]

https://techandtrains.com/2014/01/25/using-linux-gre-tunnels-to-connect-two-mininet-networks/

https://techandtrains.com/2014/01/20/connecting-two-mininet-networks-with-gre-tunnel-part-2/

 

Dr. Chih-Heng Ke (smallko@gmail.com)

Department of Computer Science and Information Engineering,

National Quemoy University, Kinmen, Taiwan.