def monitorTest(N=3, seconds=3): "Run pings and monitor multiple hosts" topo = SingleSwitchTopo(N) net = Mininet(topo) net.start() hosts = net.hosts print "Starting test..." 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], '&') print "Monitoring output for", seconds, "seconds" for h, line in monitorFiles(outfiles, seconds, timeoutms=500): if h: print '%s: %s' % (h.name, line) for h in hosts: h.cmd('kill %ping') net.stop()
def clusterSanity(): "Sanity check for cluster mode" topo = SingleSwitchTopo() net = MininetCluster(topo=topo) net.start() CLI(net) net.stop()
def exampleAllHosts(vlan): """Simple example of how VLANHost can be used in a script""" # This is where the magic happens... host = partial(VLANHost, vlan=vlan) # vlan (type: int): VLAN ID to be used by all hosts # Start a basic network using our VLANHost topo = SingleSwitchTopo(k=2) net = Mininet(host=host, topo=topo) net.start() CLI(net) net.stop()
def testHostWithPrivateDirs(): "Test bind mounts" topo = SingleSwitchTopo( 10 ) privateDirs = [ ( '/var/log', '/tmp/%(name)s/var/log' ), ( '/var/run', '/tmp/%(name)s/var/run' ), '/var/mn' ] host = partial( Host, privateDirs=privateDirs ) net = Mininet( topo=topo, host=host ) net.start() directories = [ directory[ 0 ] if isinstance( directory, tuple ) else directory for directory in privateDirs ] info( 'Private Directories:', directories, '\n' ) CLI( net ) net.stop()
def monitorhosts(hosts=5, sched='cfs'): "Start a bunch of pings and monitor them using popen" mytopo = SingleSwitchTopo(hosts) cpu = .5 / hosts myhost = custom(CPULimitedHost, cpu=cpu, sched=sched) net = Mininet(topo=mytopo, host=myhost) net.start() # Start a bunch of pings popens = {} last = net.hosts[-1] for host in net.hosts: popens[host] = host.popen("ping -c5 %s" % last.IP()) last = host # Monitor them and print output for host, line in pmonitor(popens): if host: print "<%s>: %s" % (host.name, line.strip()) # Done net.stop()
def pmonitorTest(N=3, seconds=10): "Run pings and monitor multiple hosts using pmonitor" topo = SingleSwitchTopo(N) net = Mininet(topo) net.start() hosts = net.hosts print "Starting test..." server = hosts[0] popens = {} for h in hosts: popens[h] = h.popen('ping', server.IP()) print "Monitoring output for", seconds, "seconds" endTime = time() + seconds for h, line in pmonitor(popens, timeoutms=500): if h: print '<%s>: %s' % (h.name, line), if time() >= endTime: for p in popens.values(): p.send_signal(SIGINT) net.stop()
def testSingle5( self ): "Ping test on 5-host single-switch topology" mn = Mininet( SingleSwitchTopo( k=5 ), self.switchClass, Host, Controller, waitConnected=True ) dropped = mn.run( mn.ping ) self.assertEqual( dropped, 0 )
def testMinimal( self ): "Ping test on minimal topology" mn = Mininet( SingleSwitchTopo(), self.switchClass, Host, Controller, waitConnected=True ) dropped = mn.run( mn.ping ) self.assertEqual( dropped, 0 )