本文整理汇总了Python中mininet.net.Mininet.build方法的典型用法代码示例。如果您正苦于以下问题:Python Mininet.build方法的具体用法?Python Mininet.build怎么用?Python Mininet.build使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mininet.net.Mininet
的用法示例。
在下文中一共展示了Mininet.build方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: startNetworkWithLinearTopo
# 需要导入模块: from mininet.net import Mininet [as 别名]
# 或者: from mininet.net.Mininet import build [as 别名]
def startNetworkWithLinearTopo( hostCount ):
global net
net = Mininet(topo=LinearTopo(hostCount), build=False)
remote_ip = getControllerIP()
info('** Adding Floodlight Controller\n')
net.addController('c1', controller=RemoteController,
ip=remote_ip, port=6653)
# Build the network
net.build()
net.start()
# Start DHCP
ret = enableDHCPServer()
print(ret)
addDHCPInstance1('mininet-dhcp-1')
ret = addNodePortTupleToDHCPInstance1('mininet-dhcp-1')
print(ret)
addDHCPInstance2('mininet-dhcp-2')
ret = addNodePortTupleToDHCPInstance2('mininet-dhcp-2')
print(ret)
hosts = net.hosts
for host in hosts:
mountPrivateResolvconf(host)
startDHCPclient(host)
waitForIP(host)
示例2: topology
# 需要导入模块: from mininet.net import Mininet [as 别名]
# 或者: from mininet.net.Mininet import build [as 别名]
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()
示例3: topology
# 需要导入模块: from mininet.net import Mininet [as 别名]
# 或者: from mininet.net.Mininet import build [as 别名]
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' )
ap1 = net.addBaseStation( 'ap1', ssid= 'new-ssid', mode= 'g', channel= '1', position='50,50,0' )
c1 = net.addController( 'c1', controller=Controller )
print "*** adding Link"
net.addLink(sta1, ap1)
print "*** Starting network"
net.build()
c1.start()
ap1.start( [c1] )
"""uncomment to plot graph"""
net.plotGraph(max_x=100, max_y=100)
getTrace(sta1, 'examples/replaying/replayingBandwidth/throughputData.dat')
replayingBandwidth()
print "*** Running CLI"
CLI( net )
print "*** Stopping network"
net.stop()
示例4: myNet
# 需要导入模块: from mininet.net import Mininet [as 别名]
# 或者: from mininet.net.Mininet import build [as 别名]
def myNet():
MultiSwitch13 = partial( MultiSwitch, protocols='OpenFlow13' )
#tree_topo = TreeTopo(depth=3,fanout=2)
tree_topo = SingleSwitchTopo(n=14)
net = Mininet(controller=RemoteController, topo=tree_topo, switch=MultiSwitch13, build=False, autoSetMacs=True)
info( '*** Adding controllers\n')
#c1 = net.addController('c1', controller=RemoteController, ip="127.0.0.1", port=6633)
c1 = net.addController('c1', controller=RemoteController, ip="192.168.1.1", port=6633)
c2 = net.addController('c2', controller=RemoteController, ip="192.168.1.2", port=6633)
c3 = net.addController('c3', controller=RemoteController, ip="192.168.1.3", port=6633)
# info( '*** Add hosts\n')
# h1 = net.addHost( 'h1', ip='10.0.0.1' )
# h2 = net.addHost( 'h2', ip='10.0.0.2' )
# h3 = net.addHost( 'h3', ip='10.0.0.3' )
# h4 = net.addHost( 'h4', ip='10.0.0.4' )
# info( '*** Add switches\n')
# s1 = net.addSwitch( 's1', cls=OVSKernelSwitch, protocols='OpenFlow13' )
# s2 = net.addSwitch( 's2', cls=OVSKernelSwitch, protocols='OpenFlow13' )
# s3 = net.addSwitch( 's3', cls=OVSKernelSwitch, protocols='OpenFlow13' )
# s4 = net.addSwitch( 's4', cls=OVSKernelSwitch, protocols='OpenFlow13' )
# info( '*** Add links\n')
# s1.linkTo( h1 )
# s1.linkTo( s2 )
# s2.linkTo( h2 )
# s2.linkTo( s3 )
# s3.linkTo( h3 )
# s3.linkTo( s4 )
# s4.linkTo( h4 )
info( '*** Starting network\n')
net.build()
info( '*** Starting controllers\n')
c1.start()
c2.start()
c3.start()
# info( '*** Starting switches\n')
# s1.start([c1,c2,c3])
# s2.start([c1,c2,c3])
# s3.start([c1,c2,c3])
# s4.start([c1,c2,c3])
net.start()
net.staticArp()
# i = 0;
# while i < 10:
# h1, h2 = random.choice(net.hosts), random.choice(net.hosts)
# print h1.IP(), "-->", h2.IP()
# sent, received, rttmin, rttavg, rttmax, rttdev = ping(h1, h2)
# print received,"/",sent
# i = i + 1
# sleep(1)
CLI( net )
net.stop()
示例5: topology
# 需要导入模块: from mininet.net import Mininet [as 别名]
# 或者: from mininet.net.Mininet import build [as 别名]
def topology():
"Create a network."
net = Mininet( controller=Controller, link=TCLink, switch=OVSKernelSwitch )
#wirelessRadios = Number of STAs + APs
print "*** Creating nodes"
ap1 = net.addBaseStation( 'ap1', ssid="simplewifi", mode="g", channel="5" )
sta1 = net.addStation( 'sta1', ip='192.168.0.1/24' )
sta2 = net.addStation( 'sta2', ip='192.168.0.2/24' )
h3 = net.addHost( 'h3', ip='192.168.0.3/24' )
h4 = net.addHost( 'h4', ip='192.168.0.4/24' )
c0 = net.addController('c0', controller=Controller, ip='127.0.0.1', port=6633 )
print "*** Adding Link"
net.addLink(sta1, ap1)
net.addLink(sta2, ap1)
net.addLink(h3, ap1)
net.addLink(h4, ap1)
print "*** Starting network"
net.build()
c0.start()
ap1.start( [c0] )
print "*** Running CLI"
CLI( net )
print "*** Stopping network"
net.stop()
示例6: topology
# 需要导入模块: from mininet.net import Mininet [as 别名]
# 或者: from mininet.net.Mininet import build [as 别名]
def topology():
"Create a network."
net = Mininet( controller=Controller, link=TCLink, switch=OVSKernelSwitch )
print "*** Creating nodes"
h1 = net.addHost( 'h1', mac='00:00:00:00:00:01', ip='10.0.0.1/8' )
h2 = net.addHost( 'h2', mac='00:00:00:00:00:02', ip='10.0.0.2/8' )
h3 = net.addHost( 'h3', mac='00:00:00:00:00:03', ip='10.0.0.3/8' )
s4 = net.addSwitch( 's4', mac='00:00:00:00:00:10')
s5 = net.addSwitch( 's5', mac='00:00:00:00:00:11')
c6 = net.addController( 'c6', controller=RemoteController, defaultIP="127.0.0.1", port=6633)
print "*** Creating links"
net.addLink(s4, s5, 3, 5, bw=100)
net.addLink(s5, h3, 2, 0, bw=100)
net.addLink(s5, h2, 1, 0, bw=100)
net.addLink(s4, h2, 2, 0, bw=100)
net.addLink(s4, h1, 1, 0, bw=100)
print "*** Starting network"
net.build()
s5.start( [c6] )
s4.start( [c6] )
c6.start()
print "*** Running CLI"
CLI( net )
print "*** Stopping network"
net.stop()
示例7: build
# 需要导入模块: from mininet.net import Mininet [as 别名]
# 或者: from mininet.net.Mininet import build [as 别名]
def build( self ):
"Build network based on our topology."
net = Mininet(controller=RemoteController, topo=None )
# Make controller
net.addController( 'c0' )
# Make nodes
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:
net.addHost( name, ip=ipStr( nodeNum ) )
else:
raise Exception( "Cannot create mystery node: " + name )
# Make links
for link in self.links.values():
( src, dst ) = link
srcName, dstName = src[ 'text' ], dst[ 'text' ]
src, dst = net.nameToNode[ srcName ], net.nameToNode[ dstName ]
src.linkTo( dst )
# Build network (we have to do this separately at the moment )
net.build()
return net
示例8: customNet
# 需要导入模块: from mininet.net import Mininet [as 别名]
# 或者: from mininet.net.Mininet import build [as 别名]
def customNet():
net = Mininet()
#Adding hosts
pc0 = net.addHost( 'h1' )
pc1 = net.addHost( 'h2' )
pc2 = net.addHost( 'h3' )
pc3 = net.addHost( 'h4' )
#Adding switches
switch0 = net.addSwitch( 's1' )
switch1 = net.addSwitch( 's2' )
router2 = net.addSwitch( 'r2' )
router3 = net.addSwitch( 'r3' )
# Add links
net.addLink( pc0, switch0 )
net.addLink( pc1, switch0 )
net.addLink( pc2, switch1 )
net.addLink( pc3, switch1 )
net.addLink( switch0, router3 )
net.addLink( switch1, router2 )
net.addLink( router2, router3 )
net.build()
net.start()
CLI( net )
net.stop()
示例9: main
# 需要导入模块: from mininet.net import Mininet [as 别名]
# 或者: from mininet.net.Mininet import build [as 别名]
def main(argv):
global _remControl
global _controllers
remote_ip = '127.0.0.1'
lan = 2
try:
opts, args = getopt(argv[1:], 'r:l:', ['remote-ip=','lan='])
except GetoptError as err:
print err.msg, err.opt
exit(1);
print opts
print args
for opt, arg in opts:
if opt in ('-r', '--remote-ip'):
remote_ip = arg
if opt in ('-l', '--lan'):
lan = int(arg)
_remControl = RemoteController('Remote Controller', ip=remote_ip)
_controllers['remote'] = _remControl
topo = HomeTopo(ethHosts=lan)
net = Mininet(topo=topo, switch=MultiController, host=CPULimitedHost,
link=TCLink, autoPinCpus=True, build=False)
net.addController(_controller)
net.build()
topo.routerSetup(net)
net.start()
dumpNodeConnections(net.hosts)
CLI( net )
net.stop()
示例10: startNetwork
# 需要导入模块: from mininet.net import Mininet [as 别名]
# 或者: from mininet.net.Mininet import build [as 别名]
def startNetwork():
global net
topo = TreeTopo( depth=2, fanout=2 )
net = Mininet( topo=topo, build=False )
remote_ip = getControllerIP()
info('** Adding Floodlight Controller\n')
net.addController('c1', controller=RemoteController,
ip=remote_ip, port=6653)
# Build the network
net.build()
net.start()
# Start DHCP
ret = enableDHCPServer()
print(ret)
ret = addDHCPInstance1('mininet-dhcp-1')
ret = addSwitchToDHCPInstance1('mininet-dhcp-1')
print(ret)
ret = addDHCPInstance2('mininet-dhcp-2')
ret = addSwitchToDHCPInstance2('mininet-dhcp-2')
print(ret)
hosts = net.hosts
for host in hosts:
mountPrivateResolvconf(host)
startDHCPclient(host)
waitForIP(host)
示例11: config
# 需要导入模块: from mininet.net import Mininet [as 别名]
# 或者: from mininet.net.Mininet import build [as 别名]
def config( opts ):
dhcp = bool(opts.dhcp)
routers = bool(opts.routers)
ipv6 = bool(opts.ipv6)
ipv4 = bool(opts.ipv4)
if opts.onosIp != '':
controllers = opts.onosIp.split( ',' )
else:
controllers = ['127.0.0.1']
topo = ComcastLeafSpineFabric(dhcp=dhcp, routers=routers, ipv6=ipv6,
ipv4=ipv4)
net = Mininet( topo=topo, link=TCLink, build=False,
controller=None, autoSetMacs=True )
i = 0
for ip in controllers:
net.addController( "c%s" % ( i ), controller=RemoteController, ip=ip )
i += 1
net.build()
net.start()
CLI( net )
net.stop()
示例12: myNetwork
# 需要导入模块: from mininet.net import Mininet [as 别名]
# 或者: from mininet.net.Mininet import build [as 别名]
def myNetwork():
net = Mininet( topo=None,
build=False,
ipBase='10.0.0.0/8')
info( '*** Adding controller\n' )
info( '*** Add switches\n')
s1 = net.addSwitch('s1', cls=OVSKernelSwitch, failMode='standalone')
info( '*** Add hosts\n')
h1 = net.addHost('h1', cls=Host, ip='10.0.0.1', defaultRoute=None)
h2 = net.addHost('h2', cls=Host, ip='10.0.0.2', defaultRoute=None)
info( '*** Add links\n')
net.addLink(s1, h1)
net.addLink(s1, h2)
info( '*** Starting network\n')
net.build()
info( '*** Starting controllers\n')
for controller in net.controllers:
controller.start()
info( '*** Starting switches\n')
net.get('s1').start([])
info( '*** Post configure switches and hosts\n')
CLI(net)
net.stop()
示例13: topology
# 需要导入模块: from mininet.net import Mininet [as 别名]
# 或者: from mininet.net.Mininet import build [as 别名]
def topology():
"Create a network."
net = Mininet( controller=Controller, link=TCLink, switch=OVSKernelSwitch )
image = 'shub1905/chaos:hostapd_latest'
image2 = 'shub1905/ubuntu:updated_wpa'
cmd = '/bin/ash'
cmd2 = '/bin/bash'
print "*** Creating nodes"
sta1 = net.addStation( 'sta1', ip='10.0.0.1', passwd='123456789a', encrypt='wpa2', cls=Docker, dimage=image2, dcmd=cmd2 )
sta2 = net.addStation( 'sta2', ip='10.0.0.2', passwd='12346789a', encrypt='wpa2', cls=Docker, dimage=image2, dcmd=cmd2 )
sta3 = net.addStation( 'sta3', ip='10.0.0.3', passwd='123456789a', encrypt='wpa2', cls=Docker, dimage=image2, dcmd=cmd2 )
# sta1 = net.addStation( 'sta1', passwd='123456789a', encrypt='wpa2' ) #encrypt=(wpa,wpa2,wep)
# sta2 = net.addStation( 'sta2', passwd='123456789a', encrypt='wpa2' ) #encrypt=(wpa,wpa2,wep)
ap1 = net.addBaseStation( 'ap1', ssid="simplewifi", mode="g", channel="5", passwd='123456789a', encrypt='wpa2' ) #encrypt=(wpa,wpa2,wep)
c0 = net.addController('c0', controller=Controller, ip='127.0.0.1', port=6633 )
print "*** Associating Stations"
net.addLink(sta1, ap1)
net.addLink(sta2, ap1)
net.addLink(sta3, ap1)
print "*** Starting network"
net.build()
c0.start()
ap1.start( [c0] )
print "*** Running CLI"
CLI( net )
print "*** Stopping network"
net.stop()
示例14: MininetTopo
# 需要导入模块: from mininet.net import Mininet [as 别名]
# 或者: from mininet.net.Mininet import build [as 别名]
def MininetTopo(switchnum):
# 存放 switch 參照
switchlist = []
# 產生一個 Mininet Object
net = Mininet()
# 在 Mininet 中加入兩個 hosts
info("Create host nodes.\n")
lefthost = net.addHost("h1")
righthost = net.addHost("h2")
info("Create switch node.\n")
# 連接至 remote controller, 6633 為 Ryu controller 預設 port
info("Connect to controller node.\n")
c1 = net.addController(name='c1',controller=RemoteController,ip='192.168.89.129',port=6633)
c2 = net.addController(name='c2',controller=RemoteController,ip='192.168.89.130',port=6634)
count = 1
while count <= int(switchnum):
# switch name 設為 s1, s2, s3...
switchname = "s" + str(count)
# 加入新的 switch, switch 種類使用 OVSSwitch (即 OpenvSwitch) 取代預設的 Linux OVSKernelSwitch, OpenFlow protocol 使用 1.3 版, 最後將參照存放進 list
switchlist.append(net.addSwitch(switchname, switch=OVSSwitch, protocols='OpenFlow13', failMode='secure'))
count+=1
# 加入 link, 串起 h1 和 s1
info("Create Links.\n")
net.addLink(lefthost, switchlist[0])
# s2 之後每台 switch 和前一台連接
count=1
while count <= int(switchnum)-1:
net.addLink(switchlist[count-1],switchlist[count])
count+=1
# 加入 link, 串起 sn 和 h2
net.addLink(righthost, switchlist[len(switchlist)-1])
info("build and start.\n")
# 建立 topo
net.build()
c1.start()
c2.start()
switchlist[0].start([c1])
switchlist[1].start([c1])
switchlist[2].start([c1])
switchlist[3].start([c2])
switchlist[4].start([c2])
switchlist[5].start([c2])
# 啟動 switches 和 controller
#net.start()
# 進入 Command Line Interface
CLI(net)
示例15: setup
# 需要导入模块: from mininet.net import Mininet [as 别名]
# 或者: from mininet.net.Mininet import build [as 别名]
def setup(argv):
ctls = sys.argv[1].split(',')
ifs = sys.argv[2].split(',') if len(sys.argv) > 1 else []
co = CO(1)
for i in range (len(ctls)):
co.addController('c%s' % i, controller=RemoteController, ip=ctls[i])
# make/setup Mininet object
net = Mininet()
co.build()
co.injectInto(net)
#co.dumpCfg('co.json')
# add external ports - hard-codedish
# add the ports that we will use as VxLAN endpoints
x1 = net.get('ovs1001')
x1.cmd('ip link add ovs1001-eth0 type veth peer name leaf101-eth0')
x1.cmd('vconfig add ovs1001-eth0 100')
attachDev(net, 'leaf101', 'leaf101-eth0')
for i in ifs:
attachDev(net, 'leaf102', i)
# start everything
net.build()
co.start()
# wire VxLAN endpoints to cross connects.
attachDev(net, 'ovs1001', 'ovs1001-eth0.100')
CLI(net)
net.stop()