本文整理汇总了Python中mininet.util.custom函数的典型用法代码示例。如果您正苦于以下问题:Python custom函数的具体用法?Python custom怎么用?Python custom使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了custom函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: main
def main():
"Create and run experiment"
start = time()
topo = MNTopo()
host = custom(CPULimitedHost, cpu=.15) # 15% of system bandwidth
link = custom(TCLink, max_queue_size=200)
net = Mininet(topo=topo, host=host, link=link)
net.start()
print "*** Dumping network connections:"
dumpNetConnections(net)
print "*** Testing connectivity"
net.pingAll()
if args.cli:
# Run CLI instead of experiment
CLI(net)
else:
print "*** Running experiment"
run_topology_experiment(net)
net.stop()
end = time()
os.system("killall -9 bwm-ng")
print "Experiment took %.3f seconds" % (end - start)
示例2: main
def main():
"Create and run experiment"
start = time()
topo = ParkingLotTopo(n=args.n)
host = custom(CPULimitedHost, cpu=.15) # 15% of system bandwidth
link = custom(TCLink, bw=args.bw, delay='1ms',
max_queue_size=200)
net = Mininet(topo=topo, host=host, link=link)
net.start()
cprint("*** Dumping network connections:", "green")
dumpNetConnections(net)
cprint("*** Testing connectivity", "blue")
net.pingAll()
if args.cli:
# Run CLI instead of experiment
CLI(net)
else:
cprint("*** Running experiment", "magenta")
run_parkinglot_expt(net, n=args.n)
net.stop()
end = time()
os.system("killall -9 bwm-ng")
cprint("Experiment took %.3f seconds" % (end - start), "yellow")
示例3: pairNet
def pairNet( pairs=1, useSwitches=False, bw=None, cpu=-1, **kwargs ):
"Convenience function for creating pair networks"
clients, servers = [], []
# This is a bit ugly - a lot of work to avoid flushing
# routes; I think we should rethink how that works.
class MyHost( CPULimitedHost ):
"Put clients in root namespace and DON'T flush routes"
def __init__( self, name, **kwargs ):
# First N (=pairs) hosts are clients, in root NS
kwargs.pop('inNamespace', True)
isServer = int( name[ 1: ] ) > pairs
CPULimitedHost.__init__( self, name, inNamespace=isServer, **kwargs )
def setDefaultRoute( self, intf ):
"Hack of sorts: don't set or flush route"
pass
cpu = custom( MyHost, cpu=cpu )
link = custom( TCLink, bw=bw )
topo = PairTopo( pairs, useSwitches )
net = Mininet( topo, host=MyHost, **kwargs )
net.hosts = sorted( net.hosts, key=lambda h: natural( h.name ) )
clients, servers = net.hosts[ :pairs ], net.hosts[ pairs: ]
info( "*** Configuring host routes\n" )
for client, server in zip( clients, servers ):
client.setHostRoute( server.IP(), client.defaultIntf() )
server.setHostRoute( client.IP(), server.defaultIntf() )
return net, clients, servers
示例4: set_topo
def set_topo(self, optNet, init_ip = False, init_mac = False):
# add hosts
hosts = {}
for node in optNet.get_logical_nodes():
if init_ip and init_mac:
host = self.addHost('h%d'% node, ip='0.0.0.0', mac=self.hostid_to_mac(node)) #DONT DO IT UNLESS U SET DHCLIENTS
elif init_ip:
host = self.addHost('h%d'% node, ip='0.0.0.0') #DONT DO IT UNLESS U SET DHCLIENTS
if init_mac:
host = self.addHost('h%d'% node, mac=self.hostid_to_mac(node))
else:
host = self.addHost('h%d'% node)
hosts[node] = host
# add switches
switches = {}
for node in optNet.nodes():
switches[node] = self.addSwitch('s%d' % node, mac = "")
CAPACITY_TO_MBITS = 5
MAX_MBITS = 50
# link hosts to switches
for node in optNet.get_logical_nodes():
_bw = MAX_MBITS
intf = custom( TCIntf, bw=_bw )
self.addLink(switches[node], hosts[node], intf=intf )
# link switches
for edge in optNet.physical_links():
if edge[0] in switches.keys() and edge[1] in switches.keys():
_bw = CAPACITY_TO_MBITS * optNet.get_plink_capacity(edge)
intf = custom( TCIntf, bw=_bw )
self.addLink(switches[edge[0]], switches[edge[1]], intf=intf)
示例5: launch_network
def launch_network(k=4, bw=10, ip_alias=True, fair_queues=False, cli=False):
signal.signal(signal.SIGTERM, signal_term_handler)
# Cleanup the network
cleanup()
sh("killall ospfd zebra getLoads.py nc")
# Remove tmp files and old namespaces
subprocess.call(['rm', '/tmp/*.log', '/tmp/*.pid', '/tmp/mice*'])
subprocess.call(['rm', '/var/run/netns/*'])
# Flush root namespace mangle table
subprocess.call(["iptables", "-t", "mangle" ,"-F"])
subprocess.call(["iptables", "-t", "mangle" ,"-X"])
# Topology
topo = FatTree(k=k, sflow=False, ovs_switches=False)
# Interfaces
if fair_queues:
print("*** Using FairQueues at the network interfaces")
intf = custom(DCTCIntf, bw=bw)
else:
print("*** Using normal pFIFO queues at the network interfaces")
intf = custom(PrioFifoIntf, bw=bw)
# Network
net = IPNet(topo=topo, debug=_lib.DEBUG_FLAG, intf=intf)
# Save the TopoDB object
TopologyDB(net=net).save(cfg.DB_path)
# Start the network
net.start()
# Setup hash seeds
setupHashSeeds(topo)
# Start intreface collectors
startCounterCollectors(topo, interval=1)
if ip_alias:
setupSecondaryIps(net)
if cli:
# Start the Fibbing CLI
FibbingCLI(net)
else:
print("*** Looping forever. Press CTRL+C to quit")
while True:
try:
time.sleep(2)
except KeyboardInterrupt:
print("*** KeyboardInterrupt catched! Shutting down")
break
net.stop()
stopCounterCollectors(topo)
示例6: main
def main():
topo = KLTopo()
host = custom(CPULimitedHost, cpu=.15)
link = custom(TCLink, bw=10, delay='1ms', max_queue_size=200)
net = Mininet(topo=topo, host=host, link=link, controller=RemoteController)
net.start()
dumpNetConnections(net)
CLI(net)
示例7: RegularTreeNet
def RegularTreeNet(depth=4, fanout=2, bw=BW, cpu=-1, queue=100):
"Create an empty network and add nodes to it."
topo = TreeTopo(depth, fanout)
host = custom(CPULimitedHost, cpu=cpu)
link = custom(TCLink, bw=bw, max_queue_size=queue)
#net = Mininet(host=host, link=link, switch=OVSKernelSwitch, controller=RemoteController, autoSetMacs=True, autoStaticArp=False)
net = Mininet(topo, host=host, link=link, switch=OVSKernelSwitch, controller=OVSController, autoSetMacs=True, autoStaticArp=False)
return net
示例8: run_experiment
def run_experiment( output = "sender.dump"):
topo = MyTopo()
host = custom(CPULimitedHost, cpu = .15)
link = custom(TCLink, bw=1000, delay='100ms')
net = Mininet(topo=topo, host=host, link=link)
net.start()
dumpNetConnections(net)
net.pingAll()
sender = net.getNodeByName('sender')
receiver = net.getNodeByName('receiver')
if CAPTURE_ACKS:
sender.cmd("tcpdump -tt -nn 'tcp port 5001' &> %s &" % output)
else:
sender.cmd("tcpdump -tt -nn 'tcp dst port 5001' &> %s &" % output)
sleep(1)
# randomize address, because after a few repeats, the slow start is not observed anymore
rand = str(random.randint(0,99)).zfill(2)
receiver_IP = '1%s.11.0.2' % rand
gateway_IP = '1%s.11.0.1' % rand
receiver.cmd('../lwip/tcpsink -p 5001 -i %s -g %s &> receiver.out &' % (receiver_IP, gateway_IP))
#make receiver forward packets from sender to internal tap interface
receiver.cmd('sysctl net.ipv4.ip_forward=1')
sender.cmd('sysctl net.core.netdev_max_backlog=500000')
sender.cmd('sysctl net.ipv4.tcp_congestion_control=cubic')
#add default route so that sender can sender to receiver's tap interface through the mininet link
sender.cmd('route add default gw %s' % receiver.IP())
#reduce MTU because otherwise the receive window is the limiting factor
sender.cmd('ifconfig sender-eth0 mtu 200')
print "starting transmission of data to %s" % receiver_IP
sender.sendCmd('python sender.py --receiver=%s &> sender.out' % receiver_IP)
print "waiting for transmission to complete"
sender.waitOutput()
print "killing tcpdump"
sender.cmd('killall tcpdump')
sleep(1)
print "killing tcpsink"
receiver.cmd("killall tcpsink")
net.stop()
示例9: NonBlockingNet
def NonBlockingNet(k=4, bw=10, cpu=-1, queue=100):
""" Create a NonBlocking Net """
topo = NonBlockingTopo(k)
host = custom(CPULimitedHost, cpu=cpu)
link = custom(TCLink, bw=bw, max_queue_size=queue)
net = Mininet(topo, host=host, link=link, switch=OVSKernelSwitch, controller=Controller)
return net
示例10: NonBlockingNet
def NonBlockingNet(k=4, bw=10, cpu=-1, queue=100):
''' Create a NonBlocking Net '''
topo = NonBlockingTopo(k)
host = custom(CPULimitedHost, cpu=cpu)
link = custom(TCLink, bw=bw, max_queue_size=queue)
#net = Mininet(topo, host=host, link=link, switch=OVSKernelSwitch, controller=RemoteController)
net = Mininet(topo, host=host, link=link, switch=OVSKernelSwitch, controller=OVSController, autoSetMacs=True, autoStaticArp=False)
return net
示例11: NonBlockingNet
def NonBlockingNet(k=4, bw=100, cpu=-1, queue=100):
"Convenience function for creating a non-blocking network"
topo = NonBlockingTopo(k)
host = custom(CPULimitedHost, cpu=cpu)
link = custom(TCLink, bw=bw, max_queue_size=queue)
net = Mininet(topo, host=host, link=link,
switch=OVSKernelSwitch, controller=Controller,
autoPinCpus=opts.static, autoStaticArp=True)
return net
示例12: main
def main():
"Create and run experiment"
start = time()
if 'seed' in vars(args):
random.seed(args.seed)
k = args.k
host = custom(CPULimitedHost, cpu=4.0/(k**3))
link = custom(TCLink, bw=args.bw, delay='0ms')
if args.control:
topo = NonblockingFatTreeTopo(k=k)
net = Mininet(topo=topo, host=host, link=link, build=True, cleanup=True, autoPinCpus=True, autoSetMacs=True)
else:
topo = FatTreeTopo(k=k)
net = Mininet(topo=topo, host=host, link=link, build=True, cleanup=True, autoPinCpus=True, autoSetMacs=True, controller=RemoteController)
net.start()
flowsToCreate = []
for fcount in range(args.fph):
if args.traffic.startswith('stride'):
stride_amt = int(args.traffic.split(',')[1])
matrix = compute_stride(k, stride_amt)
elif args.traffic.startswith('stag'):
edge_prob, pod_prob = map(float, args.traffic.split(',')[1:])
matrix = compute_stagger_prob(k, edge_prob, pod_prob)
elif args.traffic.startswith('random'):
matrix = compute_random(k)
elif args.traffic.startswith('randbij'):
matrix = compute_randbij(k)
else:
raise Exception('Unrecognized traffic type')
print "Running with matrix", matrix
addMatrixToFlow(flowsToCreate, matrix)
if args.controller:
controller = Popen(args.controller, shell=True, preexec_fn=os.setsid)
# NOTE: special signal for random number of flows
if args.fph >= 6:
random.shuffle(flowsToCreate)
flowsToCreate = flowsToCreate[0:len(flowsToCreate)/2]
start = time()
run_expt(net, k, flowsToCreate)
end = time()
if args.controller:
os.killpg(controller.pid, signal.SIGKILL)
net.stop()
示例13: FatTreeNet
def FatTreeNet(k=4, bw=10, cpu=-1, queue=100):
''' Create a Fat-Tree network '''
info('*** Creating the topology')
topo = FatTreeTopo(k)
host = custom(CPULimitedHost, cpu=cpu)
link = custom(TCLink, bw=bw, max_queue_size=queue)
net = Mininet(topo, host=host, link=link, switch=OVSKernelSwitch,
controller=RemoteController, autoStaticArp=True)
return net
示例14: LinearNet
def LinearNet(n=2, m=4, bw=100, cpu=-1, queue=100):
''' Create a Linear network '''
info('*** Creating the topology')
topo = LinearMultipathTopo(n,m)
host = custom(CPULimitedHost, cpu=cpu)
link = custom(TCLink, bw=bw, max_queue_size=queue)
net = Mininet(topo, host=host, link=link, switch=OVSKernelSwitch,
controller=RemoteController)
return net
示例15: __init__
def __init__(self, k = 4):
''' Create FatTree topology
k : Number of pods (can support upto k^3/4 hosts)
'''
super(FatTreeTopo, self).__init__()
self.k = k
self.node_gen = FatTreeNode
self.numPods = k
self.aggPerPod = k / 2
pods = range(0, k)
edge_sw = range(0, k/2)
agg_sw = range(k/2, k)
core_sw = range(1, k/2+1)
hosts = range(2, k/2+2)
for p in pods:
for e in edge_sw:
edge = self.node_gen(p, e, 1)
edge_opts = self.def_opts(edge.name_str())
self.addSwitch(edge.name_str(), **edge_opts)
for h in hosts:
host = self.node_gen(p, e, h)
host_opts = self.def_opts(host.name_str())
self.addHost(host.name_str(), **host_opts)
self.addLink(edge.name_str(),host.name_str())
for a in agg_sw:
agg = self.node_gen(p, a, 1)
agg_opts = self.def_opts(agg.name_str())
self.addSwitch(agg.name_str(), **agg_opts)
link = custom(TCLink, bw=100, max_queue_size=100)
self.addLink(agg.name_str(),edge.name_str(), cls=link)
for a in agg_sw:
agg = FatTreeNode(p, a, 1)
i = 1
for c in core_sw:
core = self.node_gen(k, a-k/2+1, c)
core_opts = self.def_opts(core.name_str())
self.addSwitch(core.name_str(), **core_opts)
if i == 1:
band=100
else:
band=100
i = i + 1
link = custom(TCLink, bw=band, max_queue_size=100)
self.addLink(agg.name_str(),core.name_str(), cls=link)