GRE Tunnel

[Prerequisite] make sure you have inserted the ip_gre module into the kernel.







   Experiment to connect three hosts together without switch.     H1---H2---H3


from import Mininet

from mininet.node import Controller, RemoteController, OVSKernelSwitch, OVSLegacyKernelSwitch, UserSwitch

from mininet.cli import CLI

from mininet.log import setLogLevel

from import Link, TCLink


def topology():

    "Create a network."

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

    print "*** Creating nodes"

    h1 = net.addHost( 'h1', mac='00:00:00:00:00:01')

    h2 = net.addHost( 'h2', mac='00:00:00:00:00:02', ip='' )

    h3 = net.addHost( 'h3', mac='00:00:00:00:00:03', ip='' )

    h4 = net.addHost( 'h4', mac='00:00:00:00:00:04', ip='' )

    h5 = net.addHost( 'h5', mac='00:00:00:00:00:05')

    h6 = net.addHost( 'h6', mac='00:00:00:00:00:06', ip='' )

    h7 = net.addHost( 'h7', mac='00:00:00:00:00:07', ip='' )

    h8 = net.addHost( 'h8', mac='00:00:00:00:00:08', ip='' )

    h9 = net.addHost( 'h9', mac='00:00:00:00:00:09', ip='' )

    h10 = net.addHost( 'h10', mac='00:00:00:00:00:0A', ip='' )

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

    print "*** Creating links"

    Link(h1, h2)

    Link(h1, h3, intfName1='h1-eth1')

    Link(h1, h4, intfName1='h1-eth2')

    Link(h5, h6)

    Link(h5, h7, intfName1='h5-eth1')

    Link(h5, h8, intfName1='h5-eth2')

    Link(h9, h10)

    Link(h9, h1, intfName1='h9-eth1', intfName2='h1-eth3')

    Link(h10, h5, intfName1='h10-eth1', intfName2='h5-eth3')

    h1.cmd("sudo ifconfig h1-eth0 0")

    h1.cmd("sudo ifconfig h1-eth1 0")

    h1.cmd("sudo ifconfig h1-eth2 0")

    h1.cmd("sudo ifconfig h1-eth3 0")

    h1.cmd("sudo brctl addbr mybr")

    h1.cmd("sudo brctl addif mybr h1-eth0")

    h1.cmd("sudo brctl addif mybr h1-eth1")

    h1.cmd("sudo brctl addif mybr h1-eth2")

    h1.cmd("sudo brctl addif mybr h1-eth3")

    h1.cmd("sudo ifconfig mybr up")

    h5.cmd("sudo ifconfig h5-eth0 0")

    h5.cmd("sudo ifconfig h5-eth1 0")

    h5.cmd("sudo ifconfig h5-eth2 0")

    h5.cmd("sudo ifconfig h5-eth3 0")

    h5.cmd("sudo brctl addbr mybr2")

    h5.cmd("sudo brctl addif mybr2 h5-eth0")

    h5.cmd("sudo brctl addif mybr2 h5-eth1")

    h5.cmd("sudo brctl addif mybr2 h5-eth2")

    h5.cmd("sudo brctl addif mybr2 h5-eth3")

    h5.cmd("sudo ifconfig mybr2 up")

    h9.cmd("sudo echo 1 > /proc/sys/net/ipv4/ip_forward")

    h10.cmd("sudo echo 1 > /proc/sys/net/ipv4/ip_forward")

    h9.cmd("sudo ifconfig h9-eth1 netmask")

    h10.cmd("sudo ifconfig h10-eth1 netmask")

    #No NAT setting: can not talk to

    #configure gre tunnel

    h9.cmd("sudo ip tunnel add netb mode gre remote local ttl 255")

    h9.cmd("sudo ip addr add dev netb")

    h9.cmd("sudo ifconfig netb up")

    h9.cmd("sudo ip route add via")

    h10.cmd("sudo ip tunnel add neta mode gre remote local ttl 255")

    h10.cmd("sudo ip addr add dev neta")

    h10.cmd("sudo ifconfig neta up")

    h10.cmd("sudo ip route add via")

    h2.cmd("sudo ip route add via")

    h3.cmd("sudo ip route add via")

    h4.cmd("sudo ip route add via")

    h6.cmd("sudo ip route add via")

    h7.cmd("sudo ip route add via")

    h8.cmd("sudo ip route add via")


    print "*** Running CLI"

    CLI( net )

    print "*** Stopping network"



if __name__ == '__main__':

    setLogLevel( 'info' )










Dr. Chih-Heng Ke

Department of Computer Science and Information Engineering, National Quemoy University, Kinmen, Taiwan

Email: /