Skip to content

Instantly share code, notes, and snippets.

@pichuang
Created March 30, 2014 16:35
Show Gist options
  • Save pichuang/9875468 to your computer and use it in GitHub Desktop.
Save pichuang/9875468 to your computer and use it in GitHub Desktop.
Create Fat Tree Topology
#!/usr/bin/env 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, TCLink
from mininet.topo import Topo
from mininet.util import dumpNodeConnections
import logging
import os
logging.basicConfig(level=logging.DEBUG)
logger = logging.getLogger( __name__ )
class HugeTopo(Topo):
logger.debug("Class HugeTopo")
CoreSwitchList = []
AggSwitchList = []
EdgeSwitchList = []
HostList = []
iNUMBER = 0
def __init__(self):
logger.debug("Class HugeTopo init")
iNUMBER = 4
self.iNUMBER = iNUMBER
self.iCoreLayerSwitch = iNUMBER
self.iAggLayerSwitch = iNUMBER * 2
self.iEdgeLayerSwitch = iNUMBER * 2
self.iHost = self.iEdgeLayerSwitch * 2
#Init Topo
Topo.__init__(self)
def createTopo(self):
logger.debug("Start create Core Layer Swich")
self.createCoreLayerSwitch(self.iCoreLayerSwitch)
logger.debug("Start create Agg Layer Swich ")
self.createAggLayerSwitch(self.iAggLayerSwitch)
logger.debug("Start create Edge Layer Swich ")
self.createEdgeLayerSwitch(self.iEdgeLayerSwitch)
logger.debug("Start create Host")
self.createHost(self.iHost)
"""
Create Switch and Host
"""
def createCoreLayerSwitch(self, NUMBER):
logger.debug("Create Core Layer")
for x in range(1, NUMBER+1):
PREFIX = "100"
if x >= int(10):
PREFIX = "10"
self.CoreSwitchList.append(self.addSwitch(PREFIX + str(x)))
def createAggLayerSwitch(self, NUMBER):
logger.debug( "Create Agg Layer")
for x in range(1, NUMBER+1):
PREFIX = "200"
if x >= int(10):
PREFIX = "20"
self.AggSwitchList.append(self.addSwitch(PREFIX + str(x)))
def createEdgeLayerSwitch(self, NUMBER):
logger.debug("Create Edge Layer")
for x in range(1, NUMBER+1):
PREFIX = "300"
if x >= int(10):
PREFIX = "30"
self.EdgeSwitchList.append(self.addSwitch(PREFIX + str(x)))
def createHost(self, NUMBER):
logger.debug("Create Host")
for x in range(1, NUMBER+1):
PREFIX = "400"
if x >= int(10):
PREFIX = "40"
self.HostList.append(self.addHost(PREFIX + str(x)))
"""
Create Link
"""
def createLink(self):
logger.debug("Create Core to Agg")
for x in range(0, self.iAggLayerSwitch, 2):
self.addLink(self.CoreSwitchList[0], self.AggSwitchList[x], bw=1000, loss=5)
self.addLink(self.CoreSwitchList[1], self.AggSwitchList[x], bw=1000, loss=5)
for x in range(1, self.iAggLayerSwitch, 2):
self.addLink(self.CoreSwitchList[2], self.AggSwitchList[x], bw=1000, loss=5)
self.addLink(self.CoreSwitchList[3], self.AggSwitchList[x], bw=1000, loss=5)
logger.debug("Create Agg to Edge")
for x in range(0, self.iAggLayerSwitch, 2):
self.addLink(self.AggSwitchList[x], self.EdgeSwitchList[x], bw=100)
self.addLink(self.AggSwitchList[x], self.EdgeSwitchList[x+1], bw=100)
self.addLink(self.AggSwitchList[x+1], self.EdgeSwitchList[x], bw=100)
self.addLink(self.AggSwitchList[x+1], self.EdgeSwitchList[x+1], bw=100)
logger.debug("Create Edge to Host")
for x in range(0, self.iEdgeLayerSwitch):
## limit = 2 * x + 1
self.addLink(self.EdgeSwitchList[x], self.HostList[2 * x])
self.addLink(self.EdgeSwitchList[x], self.HostList[2 * x + 1])
def enableSTP():
"""
//HATE: Dirty Code
"""
for x in range(1,5):
cmd = "ovs-vsctl set Bridge %s stp_enable=true" % ("100" + str(x))
os.system(cmd)
print cmd
for x in range(1, 9):
cmd = "ovs-vsctl set Bridge %s stp_enable=true" % ("200" + str(x))
os.system(cmd)
print cmd
cmd = "ovs-vsctl set Bridge %s stp_enable=true" % ("300" + str(x))
os.system(cmd)
print cmd
def iperfTest(net, topo):
logger.debug("Start iperfTEST")
h1000, h1015, h1016 = net.get(topo.HostList[0], topo.HostList[14], topo.HostList[15])
#iperf Server
h1000.popen('iperf -s -u -i 1 > iperf_server_differentPod_result', shell=True)
#iperf Server
h1015.popen('iperf -s -u -i 1 > iperf_server_samePod_result', shell=True)
#iperf Client
h1016.cmdPrint('iperf -c ' + h1000.IP() + ' -u -t 10 -i 1 -b 100m')
h1016.cmdPrint('iperf -c ' + h1015.IP() + ' -u -t 10 -i 1 -b 100m')
def pingTest(net):
logger.debug("Start Test all network")
net.pingAll()
def createTopo():
logging.debug("LV1 Create HugeTopo")
topo = HugeTopo()
topo.createTopo()
topo.createLink()
logging.debug("LV1 Start Mininet")
CONTROLLER_IP = "127.0.0.1"
CONTROLLER_PORT = 6633
net = Mininet(topo=topo, link=TCLink, controller=None)
net.addController( 'controller',controller=RemoteController,ip=CONTROLLER_IP,port=CONTROLLER_PORT)
net.start()
logger.debug("LV1 dumpNode")
enableSTP()
dumpNodeConnections(net.hosts)
pingTest(net)
iperfTest(net, topo)
CLI(net)
net.stop()
if __name__ == '__main__':
setLogLevel('info')
if os.getuid() != 0:
logger.debug("You are NOT root")
elif os.getuid() == 0:
createTopo()
@haojh
Copy link

haojh commented Apr 26, 2018

*** Ping: testing ping reachability
4001 -> X X X X X X X X X X X X X X X
4002 -> X X X X X X X X X X X X X X X
4003 -> X X X X X X X X X X X X X X X
4004 -> X X X X X X X X X X X X X X X
4005 -> X X X X X X X X X X X X X X X
4006 -> X X X X X X X X X X X X X X X
4007 -> X X X X X X X X X X X X X X X
4008 -> X X X X X X X X X X X X X X X
4009 -> X X X X X X X X X X X X X X X
4010 -> X X X X X X X X X X X X X X X
4011 -> X X X X X X X X X X X X X X X
4012 -> X X X X X X X X X X X X X X X
4013 -> X X X X X X X X X X X X X X X
4014 -> X X X X X X X X X X X X X X X
4015 -> X X X X X X X X X X X X X X X
4016 -> X X X X X X X X X X X X X X X
*** Results: 100% dropped (0/240 received)
初学mininet,看了楼主的代码,在Ubuntu下运行了下,显示像上面那样,100% dropped 是不是说没连接上?

@WillWang0110
Copy link

*** Ping: testing ping reachability
4001 -> X X X X X X X X X X X X X X X
4002 -> X X X X X X X X X X X X X X X
4003 -> X X X X X X X X X X X X X X X
4004 -> X X X X X X X X X X X X X X X
4005 -> X X X X X X X X X X X X X X X
4006 -> X X X X X X X X X X X X X X X
4007 -> X X X X X X X X X X X X X X X
4008 -> X X X X X X X X X X X X X X X
4009 -> X X X X X X X X X X X X X X X
4010 -> X X X X X X X X X X X X X X X
4011 -> X X X X X X X X X X X X X X X
4012 -> X X X X X X X X X X X X X X X
4013 -> X X X X X X X X X X X X X X X
4014 -> X X X X X X X X X X X X X X X
4015 -> X X X X X X X X X X X X X X X
4016 -> X X X X X X X X X X X X X X X
*** Results: 100% dropped (0/240 received)
初学mininet,看了楼主的代码,在Ubuntu下运行了下,显示像上面那样,100% dropped 是不是说没连接上?

因为楼主的代码只是提供了一个tree,还没设置flow path,这个可以在command line里自己设置一个逻辑就好了。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment