本文整理汇总了Python中mininet.net.Mininet.buildFromTopo方法的典型用法代码示例。如果您正苦于以下问题:Python Mininet.buildFromTopo方法的具体用法?Python Mininet.buildFromTopo怎么用?Python Mininet.buildFromTopo使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mininet.net.Mininet
的用法示例。
在下文中一共展示了Mininet.buildFromTopo方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: pingall_test
# 需要导入模块: from mininet.net import Mininet [as 别名]
# 或者: from mininet.net.Mininet import buildFromTopo [as 别名]
def pingall_test(folder, exe, topo=SingleSwitchTopo(4), custom_topo=None, custom_test=None, expect_pct=0):
ip="127.0.0.1"
port=6633
if not VERBOSE:
lg.setLogLevel('critical')
ctrlr = lambda n: RemoteController(n, ip=ip, port=port, inNamespace=False)
net = Mininet(switch=OVSSwitch, controller=ctrlr, autoStaticArp=False,cleanup=True)
c1 = net.addController('c1')
if custom_topo:
custom_topo.build(net)
else:
net.buildFromTopo(topo)
# Start the network
net.start()
# Fork off Frenetic process
devnull = None if VERBOSE else open(os.devnull, 'w')
frenetic_proc = Popen(
['/home/vagrant/src/frenetic/frenetic.native', 'http-controller','--verbosity','debug'],
stdout=devnull, stderr=devnull
)
# Wait a few seconds for frenetic to initialize, otherwise
time.sleep(5)
# And fork off application
app_proc = Popen(
['/usr/bin/python2.7',exe],
stdout=devnull, stderr=devnull, cwd=CODE_ROOT+folder
)
if custom_test:
got_pct = int(custom_test(net))
else:
got_pct = int(net.pingAll())
expected_msg = " expected "+str(expect_pct)+"% dropped got "+str(got_pct)+"% dropped"
print exe + ("...ok" if expect_pct==got_pct else expected_msg)
frenetic_proc.kill()
app_proc.kill()
# Ocassionally shutting down the network throws an error, which is superfluous because
# the net is already shut down. So ignore.
try:
net.stop()
except OSError:
pass
示例2: mnScript
# 需要导入模块: from mininet.net import Mininet [as 别名]
# 或者: from mininet.net.Mininet import buildFromTopo [as 别名]
def mnScript():
"Creating a Mininet net"
net = Mininet( controller=RemoteController, switch=OVSKernelSwitch, autoSetMacs=True, listenPort=7001 )
topo = MyTopo()
#Build and Start
net.buildFromTopo( topo )
net.start()
print "*** Starting Group ***"
print "*** Socket"
s = initsocket()
request = Request()
request.id = 1
request.action = request.ACTION.GET_GROUP
#request.action = request.ACTION.GET_COMPLETE_GROUP
s.send (request.toJson() )
jsonStr = s.recv()
print "*** Group"
group = GroupFactory().decodeJson(jsonStr)
src = net.nameToNode[ "h" + str(group.source) ]
print "*** Setup CA:FE ARP in source:", src.name
src.cmd("arp -s 10.0.2.254 ca:fe:ca:fe:ca:fe")
print "*** Start udpapp in source( " + src.name + " ) manually ;)"
#src.cmd("udpapp -m &")
for host in group.hosts:
if host.id != group.source:
h = net.nameToNode[ "h" + str(host.id) ]
print "*** Setup CA:FE ARP in " + h.name
h.cmd("arp -s 10.0.2.254 ca:fe:ca:fe:ca:fe")
print "*** Starting udpapp in " + h.name
#h.cmd("udpapp -c " + h.name + " &")
#sleep( 1 )
print "*** Starting CLI ***"
CLI( net )
print "*** Stopping net ***"
net.stop()
示例3: mnScript
# 需要导入模块: from mininet.net import Mininet [as 别名]
# 或者: from mininet.net.Mininet import buildFromTopo [as 别名]
def mnScript():
"Creating a Mininet net"
net = Mininet( controller=RemoteController, switch=OVSKernelSwitch, autoSetMacs=True, listenPort=6634 )
print "*** Creating Remote Controller"
c0 = net.addController( 'c0' )
topo = MyTopo()
#Build and Start
net.buildFromTopo( topo )
net.start()
print "*** Starting Group ***"
print "*** Socket"
s = initsocket()
request = Request()
request.id = 1
request.action = request.ACTION.GET_GROUP
s.send (request.toJson() )
jsonStr = s.recv()
print "*** Group"
group = GroupFactory().decodeJson(jsonStr)
src = net.nameToNode[ "h" + str(group.source) ]
print "*** Setup CA:FE ARP in source"
src.cmd("arp -s 10.0.2.254 ca:fe:ca:fe:ca:fe")
print "*** Starting udpapp in source"
cmdThread( src, "echo blah > /home/openflow/htest" ) #"udpapp -m > " + src.name + ".log" )
for host in group.hosts:
h = net.nameToNode[ "h" + str(host.id) ]
print "*** Setup CA:FE ARP in " + h.name
h.cmd("arp -s 10.0.2.254 ca:fe:ca:fe:ca:fe")
print "*** Starting udpapp in " + h.name
cmdThread( h, "ping 10.0.0.1 > " + h.name + ".log") #"udpapp -c > " + h.name + ".log" )
print "*** Starting CLI ***"
CLI( net )
print "*** Stopping net ***"
net.stop()
示例4: setLogLevel
# 需要导入模块: from mininet.net import Mininet [as 别名]
# 或者: from mininet.net.Mininet import buildFromTopo [as 别名]
self.addLink(node, child)
else:
node = self.addHost("h%s" % self.hostNum)
self.hostNum += 1
return node
if __name__ == "__main__":
setLogLevel("info")
topo = TreeTopo(depth=3, fanout=2)
network = Mininet(switch=OVSKernelSwitch, controller=RemoteController)
c0 = network.addController("c0", controller=RemoteController, ip="192.168.56.101", port=6633)
network.buildFromTopo(topo)
h1, h2, h3, h4, h5, h6, h7, h8 = network.getNodeByName("h1", "h2", "h3", "h4", "h5", "h6", "h7", "h8")
network.start()
h1.cmd("iperf -s -u &")
h8.cmd("iperf -c 10.0.0.1 -u -t 100 -b 10M &")
h2.cmd("iperf -s -u &")
h7.cmd("iperf -u -c 10.0.0.2 -t 100 -b 10M &")
h3.cmd("iperf -s -u &")
h6.cmd("iperf -u -c 10.0.0.3 -t 100 -b 10M &")
h4.cmd("iperf -s -u &")
h5.cmd("iperf -u -c 10.0.0.4 -t 100 -b 40M &")
# network.run( CLI, network )
CLI(network)
示例5: buildFromTopo
# 需要导入模块: from mininet.net import Mininet [as 别名]
# 或者: from mininet.net.Mininet import buildFromTopo [as 别名]
def buildFromTopo( self, *args, **kwargs ):
"Start network"
info( '*** Placing nodes\n' )
self.placeNodes()
info( '\n' )
Mininet.buildFromTopo( self, *args, **kwargs )