Last active
November 27, 2024 15:23
-
-
Save starbops/fcf48b1d30c5dbecdbf8 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
from mininet.topo import Topo | |
from mininet.net import Mininet | |
from mininet.node import RemoteController | |
from mininet.link import TCLink | |
from mininet.cli import CLI | |
from mininet.util import dumpNodeConnections | |
from mininet.log import setLogLevel | |
class MyTopo( Topo ): | |
"""Fat tree topology example.""" | |
def __init__( self ): | |
"""Create custom topo.""" | |
self.hns = ['4001', '4002', '4003', '4004', | |
'4005', '4006', '4007', '4008', | |
'4009', '4010', '4011', '4012', | |
'4013', '4014', '4015', '4016', | |
] | |
self.esns = ['3001', '3002', '3003', '3004', | |
'3005', '3006', '3007', '3008', | |
] | |
self.asns = ['2001', '2002', '2003', '2004', | |
'2005', '2006', '2007', '2008', | |
] | |
self.csns = ['1001', '1002', '1003', '1004'] | |
# Initialize topology | |
Topo.__init__( self ) | |
# Add hosts and switches | |
hs = [self.addHost(hn) for hn in self.hns] # hosts | |
ess = [self.addSwitch(esn) for esn in self.esns] # edge switches | |
ass = [self.addSwitch(asn) for asn in self.asns] # agg switches | |
css = [self.addSwitch(csn) for csn in self.csns] # core switches | |
# Add links | |
for i in range(8): # host <-> edge | |
self.addLink(hs[2*i], ess[i], bw=100) | |
self.addLink(hs[2*i+1], ess[i], bw=100) | |
for i in range(0, 8, 2): # edge <-> agg | |
self.addLink(ess[i], ass[i], bw=100) | |
self.addLink(ess[i+1], ass[i], bw=100) | |
self.addLink(ess[i], ass[i+1], bw=100) | |
self.addLink(ess[i+1], ass[i+1], bw=100) | |
for i in range(4): # agg <-> core | |
if i < 4/2: | |
for j in range(0, 8, 2): | |
self.addLink(css[i], ass[j], bw=1000, loss=5) | |
else: | |
for j in range(1, 8, 2): | |
self.addLink(css[i], ass[j], bw=1000, loss=5) | |
def perf_test(): | |
"""Create network and run simple performance test""" | |
topo = MyTopo() | |
net = Mininet(topo=topo, link=TCLink, controller=None) | |
net.addController('floodlight', controller=RemoteController, ip='127.0.0.1') | |
net.start() | |
print 'Dumping host connections' | |
dumpNodeConnections(net.hosts) | |
print 'Testing network connectivity' | |
net.pingAll() | |
print 'Testing bandwidth' | |
iperf_serv1, iperf_serv2, iperf_cli= net.get('4001', '4016', '4002') | |
iperf_serv1.popen('iperf -s -u -i 1 > iperf-result-4001.log', shell=True) | |
iperf_serv2.popen('iperf -s -u -i 1 > iperf-result-4016.log', shell=True) | |
iperf_cli.cmdPrint('iperf -c ' + iperf_serv1.IP() + ' -u -t 10 -i 1 -b 100m') | |
iperf_cli.cmdPrint('iperf -c ' + iperf_serv2.IP() + ' -u -t 10 -i 1 -b 100m') | |
print 'Cleaning up' | |
iperf_serv1.cmdPrint('killall -9 iperf') | |
iperf_serv2.cmdPrint('killall -9 iperf') | |
#CLI(net) | |
net.stop() | |
if __name__ == '__main__': | |
setLogLevel('info') | |
perf_test() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This file is modified from
~/mininet/custom/topo-2sw-2host.py