Untitled
unknown
plain_text
2 years ago
1.5 kB
10
Indexable
from mininet.net import Mininet
from mininet.topo import Topo
from mininet.node import CPULimitedHost
from mininet.link import TCLink
from mininet.log import setLogLevel, info
class CustomTopology(Topo):
def build(self):
# Add switches
switch1 = self.addSwitch('s1')
switch2 = self.addSwitch('s2')
# Add hosts
host1 = self.addHost('h1', cpu=.1) # 10% of system CPU
host2 = self.addHost('h2', cpu=.1)
host3 = self.addHost('h3', cpu=.1)
# Add links with bandwidth limit of 10 Mbps
self.addLink(switch1, host1, bw=10)
self.addLink(switch1, host2, bw=10)
self.addLink(switch2, host3, bw=10)
self.addLink(switch1, switch2, bw=10)
def bandwidth_test():
# Create Mininet object
net = Mininet(topo=CustomTopology(), host=CPULimitedHost, link=TCLink, controller=None)
# Start Mininet
net.start()
# Print network nodes
info('*** Network nodes: hosts={}, switches={}\n'.format(net.hosts, net.switches))
# Test bandwidth between h1 and h3 using iperf
h1, h3 = net.get('h1', 'h3')
result = h3.cmd('iperf -s &') # Start iperf server on h3
result = h1.cmd('iperf -c {} -t 5'.format(h3.IP())) # Start iperf client on h1, connecting to h3
info('*** Bandwidth test result:\n{}\n'.format(result))
# Stop Mininet
net.stop()
if __name__ == '__main__':
# Set Mininet log level
setLogLevel('info')
# Run Mininet application
bandwidth_test()
Editor is loading...
Leave a Comment