本文整理汇总了Python中mininet.net.Mininet类的典型用法代码示例。如果您正苦于以下问题:Python Mininet类的具体用法?Python Mininet怎么用?Python Mininet使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Mininet类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: start_networking
def start_networking(self):
setLogLevel("info")
net = Mininet(topo=self, \
controller=lambda name: RemoteController(name))
net.start()
# setup each switch
for sw in net.switches:
# set ofp version
self.set_ofp_version(sw, ['OpenFlow10', 'OpenFlow13'])
# if sw is bridge, set it up for normal SW
swEntry = self.switchList[sw.name][1]
isBridge = swEntry["bridge"]
if isBridge:
self.set_normalsw(sw)
self.switchList[sw.name].append(sw)
# setup each host
for host in net.hosts:
self.add_ipv6address(host)
self.hostList[host.name].append(host)
# execute pre_command
if "pre_cmd_file" in self.jsonData:
cmd_file = self.jsonData["pre_cmd_file"]
self.exec_usercmd(cmd_file)
CLI(net)
# execute post_command
if "post_cmd_file" in self.jsonData:
cmd_file = self.jsonData["post_cmd_file"]
self.exec_usercmd(cmd_file)
net.stop()
示例2: run
def run( n ):
topo = OpticalTopo( n )
net = Mininet( topo=topo, controller=RemoteController, autoSetMacs=True )
net.start()
#installStaticFlows( net )
CLI( net )
net.stop()
示例3: topology
def topology():
"Create a network."
net = Mininet( controller=Controller, link=TCLink, switch=OVSKernelSwitch )
print "*** Creating nodes"
sta1 = net.addStation( 'sta1', mac='00:00:00:00:00:02', ip='10.0.0.2/8', position='10,20,0' )
sta2 = net.addStation( 'sta2', mac='00:00:00:00:00:03', ip='10.0.0.3/8', position='10,30,0' )
ap1 = net.addBaseStation( 'ap1', ssid= 'new-ssid', mode= 'g', channel= '1', position='15,30,0' )
c1 = net.addController( 'c1', controller=Controller )
"""uncomment to plot graph"""
#net.plotGraph(max_x=60, max_y=60)
print "*** Creating links"
net.addLink(ap1, sta1)
net.addLink(ap1, sta2)
print "*** Starting network"
net.build()
c1.start()
ap1.start( [c1] )
print "*** Running CLI"
CLI( net )
print "*** Stopping network"
net.stop()
示例4: test
def test():
topo = DssTopo()
net = Mininet(topo, link=TCLink)
net.start()
pidList(net)
global NPAUSE
global NRESUME
NPAUSE = 'sudo /home/kd/VirtualTimeKernel/test_virtual_time/freeze_all_procs -f -p %s'%pIDS
NRESUME ='sudo /home/kd/VirtualTimeKernel/test_virtual_time/freeze_all_procs -u -p %s'%pIDS
#block
print(net.get('h1').cmd('ping -c 1 10.0.0.2'))
net.get('h1').cmd('ping -c 40 10.0.0.2 > %sbl.test'% FileOut)
#dont block
net.get('h1').cmd('/home/kd/VirtualTimeKernel/iputils/ping -c 40 -D 10.0.0.2 > %svt.test &'% FileOut)
time.sleep(5)
for x in range(0,int(sys.argv[3])):
print 'pausing'
pause()
time.sleep(stime)
print 'resumed'
time.sleep(30)
net.stop()
示例5: build
def build( self ):
print "Build network based on our topology."
net = Mininet( topo=None, build=False, link=TCLink, ipBase=self.minieditIpBase )
net.controllers = self.addControllers()
# Make nodes
print "Getting Hosts and Switches."
for widget in self.widgetToItem:
name = widget[ 'text' ]
tags = self.canvas.gettags( self.widgetToItem[ widget ] )
nodeNum = int( name[ 1: ] )
if 'Switch' in tags:
net.addSwitch( name )
elif 'Host' in tags:
ipBaseNum, prefixLen = netParse( self.minieditIpBase )
ip = ipAdd(i=nodeNum, prefixLen=prefixLen, ipBaseNum=ipBaseNum)
net.addHost( name, ip=ip )
else:
raise Exception( "Cannot create mystery node: " + name )
# Make links
print "Getting Links."
for link in self.links.values():
( src, dst, linkopts ) = link
srcName, dstName = src[ 'text' ], dst[ 'text' ]
src, dst = net.nameToNode[ srcName ], net.nameToNode[ dstName ]
net.addLink(src, dst, **linkopts)
self.printInfo()
# Build network (we have to do this separately at the moment )
net.build()
return net
示例6: LowMnNet
def LowMnNet(n, nn, nnn):
print "############ Instanitiate a mininet of topology LowMnTopo ###############\n"
topo = LowMnTopo(n, nn, nnn)
ctrl_port=6633
net = Mininet(topo=topo, ipBase='10.0.0.0/8', autoSetMacs=True, host=CPULimitedHost, link=TCLink)
net.start()
return net
示例7: main
def main():
# All b/w are in megabits
max_bw = 1000
# B/w of queue 1 and queue 2
values = [3,1,4]
topo = MyTopo(max_bw)
net = Mininet(topo, link = TCLink, controller = partial(RemoteController, ip = '127.0.0.1', port = 6633))
net.start()
# Queue set in between h1 and s1
cmd = 'ovs-vsctl -- set Port s2-eth4 [email protected] -- \
[email protected] create QoS type=linux-htb other-config:max-rate=1000000000 [email protected],[email protected],[email protected],[email protected] -- \
[email protected] create Queue other-config:min-rate=%d other-config:max-rate=%d -- \
[email protected] create Queue other-config:min-rate=%d other-config:max-rate=%d -- \
[email protected] create Queue other-config:min-rate=%d other-config:max-rate=%d -- \
[email protected] create Queue other-config:min-rate=%d other-config:max-rate=%d' % \
(max_bw * 10**6, max_bw * 10**6, \
values[0] * 10**6, values[0] * 10**6, \
values[1] * 10**6, values[1] * 10**6, \
values[2] * 10**6, values[2] * 10**6)
sp.call(cmd, shell = True)
CLI(net)
net.stop()
示例8: main
def main():
net = Mininet()
# create hosts
h1 = net.addHost('h1')
h2 = net.addHost('h2')
# create switch
s1 = net.addSwitch('S1')
# create controller
c1 = net.addController('c1')
# create links
net.addLink(h1, s1)
net.addLink(h2, s1)
net.start()
# start web server on h2
print('starting web server...')
h2.cmd('python -m SimpleHTTPServer 80 &')
sleep(2)
# use h1 as a web client
print('accessing web server..')
h1.cmd('curl', h2.IP())
# CLI(net)
print('kill web server..')
h2.cmd('kill %python')
print('finish.')
net.stop()
示例9: multiping
def multiping(netsize, chunksize, seconds):
"Ping subsets of size chunksize in net of size netsize"
# Create network and identify subnets
topo = SingleSwitchTopo(netsize)
net = Mininet(topo=topo)
net.start()
hosts = net.hosts
subnets = chunks(hosts, chunksize)
# Create polling object
fds = [host.stdout.fileno() for host in hosts]
poller = poll()
for fd in fds:
poller.register(fd, POLLIN)
# Start pings
for subnet in subnets:
ips = [host.IP() for host in subnet]
for host in subnet:
startpings(host, ips)
# Monitor output
endTime = time() + seconds
while time() < endTime:
readable = poller.poll(1000)
for fd, _mask in readable:
node = Node.outToNode[fd]
print "%s:" % node.name, node.monitor().strip()
# Stop pings
for host in hosts:
host.cmd("kill %while")
net.stop()
示例10: monitorTest
def monitorTest( N=3, seconds=3 ):
"Run pings and monitor multiple hosts"
topo = SingleSwitchTopo( N )
net = Mininet( topo )
net.start()
hosts = net.hosts
info( "Starting test...\n" )
server = hosts[ 0 ]
outfiles, errfiles = {}, {}
for h in hosts:
# Create and/or erase output files
outfiles[ h ] = '/tmp/%s.out' % h.name
errfiles[ h ] = '/tmp/%s.err' % h.name
h.cmd( 'echo >', outfiles[ h ] )
h.cmd( 'echo >', errfiles[ h ] )
# Start pings
h.cmdPrint('ping', server.IP(),
'>', outfiles[ h ],
'2>', errfiles[ h ],
'&' )
info( "Monitoring output for", seconds, "seconds\n" )
for h, line in monitorFiles( outfiles, seconds, timeoutms=500 ):
if h:
info( '%s: %s\n' % ( h.name, line ) )
for h in hosts:
h.cmd('kill %ping')
net.stop()
示例11: topoTest
def topoTest():
"Create network and run simple performance test"
topo = ITATopo()
# topo = ITATopo(12, 10)
net = Mininet(topo=topo, host=CPULimitedHost, link=TCLink)
net.interact()
示例12: main
def main():
# Defines the log level
setLogLevel('info')
# parses command line arguments
parser = OptionParser()
parser.add_option('-H', dest='hosts', default=5,
help='Number of hosts per switch')
parser.add_option('-S', dest='switches', default=2,
help='Number of switches')
(options, args) = parser.parse_args()
# Build network topology (see mininet/topo.py)
topo = LinearTopo(int(options.switches), int(options.hosts))
# Creates the Network using a remote controller
net = Mininet(topo,
controller=lambda a: RemoteController(a, ip='127.0.0.1'))
# Starts the network
net.start()
# Run the mininet client
CLI(net)
# Stop the network
net.stop()
示例13: run
def run():
"Create network and run the CLI"
topo = InternetTopo()
net = Mininet(topo=topo)
net.start()
CLI(net)
net.stop()
示例14: emptyNet
def emptyNet():
net = Mininet(topo=None, build=False)
c0 = Controller('c0', inNamespace=False)
h1 = Host('h1')
h2 = Host('h2')
#intf1 = Intf("h1-eth1")
#intf2 = Intf("h2-eth1")
s1 = OVSSwitch('br0', inNamespace=False)
Link(h1, s1)
Link(h2, s1)
c0.start()
s1.start([c0])
net.start()
#s1.cmd('ovs-vsctl set bridge br0 protocols=OpenFlow13')
CLI(net)
net.stop()
h1.stop()
h2.stop()
s1.stop()
c0.stop()
示例15: testLinkBandwidth
def testLinkBandwidth( self ):
"Verify that link bandwidths are accurate within a bound."
if self.switchClass is UserSwitch:
self.skipTest( 'UserSwitch has very poor performance -'
' skipping for now' )
BW = 5 # Mbps
BW_TOLERANCE = 0.8 # BW fraction below which test should fail
# Verify ability to create limited-link topo first;
lopts = { 'bw': BW, 'use_htb': True }
# Also verify correctness of limit limitng within a bound.
mn = Mininet( SingleSwitchOptionsTopo( n=N, lopts=lopts ),
link=TCLink, switch=self.switchClass,
waitConnected=True )
bw_strs = mn.run( mn.iperf, fmt='m' )
loptsStr = ', '.join( '%s: %s' % ( opt, value )
for opt, value in lopts.items() )
msg = ( '\nTesting link bandwidth limited to %d Mbps per link\n'
'iperf results[ client, server ]: %s\n'
'Topo = SingleSwitchTopo, %s hosts\n'
'Link = TCLink\n'
'lopts = %s\n'
'host = default\n'
'switch = %s\n'
% ( BW, bw_strs, N, loptsStr, self.switchClass ) )
# On the client side, iperf doesn't wait for ACKs - it simply
# reports how long it took to fill up the TCP send buffer.
# As long as the kernel doesn't wait a long time before
# delivering bytes to the iperf server, its reported data rate
# should be close to the actual receive rate.
serverRate, _clientRate = bw_strs
bw = float( serverRate.split(' ')[0] )
self.assertWithinTolerance( bw, BW, BW_TOLERANCE, msg )