Skip to content

Commit

Permalink
Since subnet associated w/ Virtual gateway now, removed the VirtualSu…
Browse files Browse the repository at this point in the history
…bnet

class that designed while ago.
  • Loading branch information
QingWang0909 committed Apr 29, 2018
1 parent 344af2c commit ea7518b
Show file tree
Hide file tree
Showing 11 changed files with 336 additions and 497 deletions.
9 changes: 5 additions & 4 deletions example/mininet/DHCP_L3.py
Original file line number Diff line number Diff line change
Expand Up @@ -309,19 +309,17 @@ def startNetworkWithLinearTopo( hostCount ):
ret = addSwitchToDHCPInstance2('mininet-dhcp-2')
print(ret)

time.sleep(5)
time.sleep(3)

hosts = net.hosts
for host in hosts:
mountPrivateResolvconf(host)
startDHCPclient(host)
waitForIP(host)
time.sleep(2)


# Start L3 Service
ret = enableL3Routing()
print (ret)

ret = addVirtualGateway('mininet-gateway-1')
print (ret)

Expand All @@ -331,6 +329,9 @@ def startNetworkWithLinearTopo( hostCount ):
ret = addSwitchToGateway('mininet-gateway-1')
print (ret)

ret = enableL3Routing()
print (ret)


def clearGatewayInstance(name):
data = {}
Expand Down
269 changes: 269 additions & 0 deletions example/mininet/multi_gateway.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,269 @@
#!/usr/bin/python
import json

import httplib
import os
import subprocess
import time
from mininet.cli import CLI
from mininet.log import setLogLevel, info
from mininet.net import Mininet
from mininet.node import RemoteController
from mininet.topo import Topo
from mininet.util import irange

HOME_FOLDER = os.getenv('HOME')


class LinearTopo(Topo):
"""
construct a network of N hosts and N-1 switches, connected as follows:
h1 <-> s1 <-> s2 .. sN-1
| | |
h2 h3 hN
"""
def __init__(self, N, **params):
Topo.__init__(self, **params)

hosts = [ self.addHost( 'h%s' % h )
for h in irange( 1, N ) ]

switches = [ self.addSwitch( 's%s' % s, protocols=["OpenFlow13"] )
for s in irange( 1, N - 1 ) ]

# Wire up switches
last = None
for switch in switches:
if last:
self.addLink( last, switch )
last = switch


# Wire up hosts
self.addLink( hosts[ 0 ], switches[ 0 ] )
for host, switch in zip( hosts[ 1: ], switches ):
self.addLink( host, switch )



def getControllerIP():
guest_ip = subprocess.check_output("/sbin/ifconfig eth1 | grep 'inet addr:' | cut -d: -f2 | awk '{ print $1}'",
shell=True)
split_ip = guest_ip.split('.')
split_ip[3] = '1'
return '.'.join(split_ip)


def rest_call(path, data, action):
headers = {
'Content-type': 'application/json',
'Accept' : 'application/json',
}
body = json.dumps(data)

conn = httplib.HTTPConnection(getControllerIP(), 8080)
conn.request(action, path, body, headers)
response = conn.getresponse()

ret = (response.status, response.reason, response.read())
conn.close()
return ret


def addVirtualGateway(name):
data = {
"gateway-name" : name,
"gateway-mac" : "aa:bb:cc:dd:ee:ff"
}
ret = rest_call('/wm/routing/gateway', data, 'POST')
return ret


def addInterfaceToGateway1(name):
data = {
"interfaces" : [
{
"interface-name" : "interface-1",
"interface-ip" : "10.0.0.1",
"interface-mask" : "255.255.255.0"
},
{
"interface-name" : "interface-2",
"interface-ip" : "20.0.0.1",
"interface-mask" : "255.255.255.0"
},
{
"interface-name" : "interface-3",
"interface-ip" : "30.0.0.1",
"interface-mask" : "255.255.255.0"
}
]
}
ret = rest_call('/wm/routing/gateway/' + name, data, 'POST')
return ret


def addInterfaceToGateway2(name):
data = {
"interfaces" : [
{
"interface-name" : "interface-4",
"interface-ip" : "40.0.0.1",
"interface-mask" : "255.255.255.0"
},
{
"interface-name" : "interface-5",
"interface-ip" : "50.0.0.1",
"interface-mask" : "255.255.255.0"
},
{
"interface-name" : "interface-6",
"interface-ip" : "60.0.0.1",
"interface-mask" : "255.255.255.0"
}
]
}
ret = rest_call('/wm/routing/gateway/' + name, data, 'POST')
return ret


def addSwitchToGateway1(name):
data = {
"gateway-name" : name,
"gateway-ip" : "127.0.0.1",
"switches": [
{
"dpid": "1"
},
{
"dpid": "2"
}
]
}
ret = rest_call('/wm/routing/gateway/' + name, data, 'POST')
return ret


def addSwitchToGateway2(name):
data = {
"gateway-name" : name,
"gateway-ip" : "127.0.0.1",
"switches": [
{
"dpid": "3"
},
{
"dpid": "4"
},
{
"dpid": "5"
}
]
}
ret = rest_call('/wm/routing/gateway/' + name, data, 'POST')
return ret


def configureDefaultGatewayForHost(host, defaultGatewayIP):
host.cmd('route add default gw ' + defaultGatewayIP);


def enableL3Routing():
data = {
"enable" : "true"
}
ret = rest_call('/wm/routing/config', data, 'POST')
return ret


def disableL3Routing():
data = {
"enable" : "false"
}
ret = rest_call('/wm/routing/config', data, 'POST')
return ret


def startNetworkWithLinearTopo( hostCount ):
global net
net = Mininet(topo=LinearTopo(hostCount), build=False)

remote_ip = getControllerIP()
info('** Adding Floodlight Controller\n')
net.addController('c1', controller=RemoteController,
ip=remote_ip, port=6653)

# Build the network
net.build()
net.start()

# Start L3 Routing
ret = enableL3Routing()
print (ret)

addVirtualGateway('mininet-gateway-1')
addInterfaceToGateway1('mininet-gateway-1')
ret = addSwitchToGateway1('mininet-gateway-1')
print (ret)

addVirtualGateway('mininet-gateway-2')
addInterfaceToGateway2('mininet-gateway-2')
ret = addSwitchToGateway2('mininet-gateway-2')
print (ret)

# Need to configure default gw for host
host1 = net.getNodeByName('h1')
host1.setIP('10.0.0.10', prefixLen=24)
defaultGatewayIP1 = "10.0.0.1"
configureDefaultGatewayForHost(host1, defaultGatewayIP1)

host2 = net.getNodeByName('h2')
host2.setIP('20.0.0.10', prefixLen=24)
defaultGatewayIP2 = "20.0.0.1"
configureDefaultGatewayForHost(host2, defaultGatewayIP2)

host3 = net.getNodeByName('h3')
host3.setIP('30.0.0.10', prefixLen=24)
defaultGatewayIP3 = "30.0.0.1"
configureDefaultGatewayForHost(host3, defaultGatewayIP3)

host4 = net.getNodeByName('h4')
host4.setIP('40.0.0.10', prefixLen=24)
defaultGatewayIP4 = "40.0.0.1"
configureDefaultGatewayForHost(host4, defaultGatewayIP4)

host5 = net.getNodeByName('h5')
host5.setIP('50.0.0.10', prefixLen=24)
defaultGatewayIP5 = "50.0.0.1"
configureDefaultGatewayForHost(host5, defaultGatewayIP5)

host6 = net.getNodeByName('h6')
host6.setIP('60.0.0.10', prefixLen=24)
defaultGatewayIP6 = "60.0.0.1"
configureDefaultGatewayForHost(host6, defaultGatewayIP6)



def clearGatewayInstance(name):
data = {}
ret = rest_call('/wm/routing/gateway/' + name, data, 'DELETE')
return ret


def stopNetwork():
if net is not None:
info('** Tearing down network\n')
clearGatewayInstance('mininet-gateway-1')
net.stop()


if __name__ == '__main__':
setLogLevel('info')
startNetworkWithLinearTopo(6)
CLI(net)
stopNetwork()




6 changes: 0 additions & 6 deletions example/mininet/routing_L3.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,12 +156,6 @@ def addSwitchToGateway(name):
},
{
"dpid": "3"
},
{
"dpid": "4"
},
{
"dpid": "5"
}
]
}
Expand Down
Loading

0 comments on commit ea7518b

Please sign in to comment.