本文整理汇总了Python中mininet.net.Mininet.addHost方法的典型用法代码示例。如果您正苦于以下问题:Python Mininet.addHost方法的具体用法?Python Mininet.addHost怎么用?Python Mininet.addHost使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mininet.net.Mininet
的用法示例。
在下文中一共展示了Mininet.addHost方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: topology
# 需要导入模块: from mininet.net import Mininet [as 别名]
# 或者: from mininet.net.Mininet import addHost [as 别名]
def topology():
net = Mininet(controller=Controller, link=TCLink, switch=OVSKernelSwitch)
print "*** Creating nodes"
h1 = net.addHost('red1', mac='00:00:00:00:10:01', ip='10.0.10.1/24')
h2 = net.addHost('blue1', mac='00:00:00:00:20:01', ip='10.0.20.1/24')
s1 = net.addSwitch('s1', protocols='OpenFlow13')
ctrl = RemoteController('ryu', ip='192.168.10.1')
print "*** Creating links"
net.addLink(s1, h1, bw=10)
net.addLink(s1, h2, bw=10)
print "*** Starting network"
net.build()
ctrl.start()
s1.start([ctrl])
s1.cmd(
'ovs-vsctl add-port s1 vtep2 -- set interface vtep2 type=vxlan option:remote_ip=192.168.20.2 option:key=flow ofport_request=12 &')
s1.cmd(
'ovs-vsctl add-port s1 vtep3 -- set interface vtep3 type=vxlan option:remote_ip=192.168.30.2 option:key=flow ofport_request=13 &')
print "*** Running Ping"
time.sleep(5)
h1.cmd('ping -c 1 10.0.10.10 &')
h1.cmd('ifconfig red1-eth0 mtu 1450')
# h1.cmd('python -m SimpleHTTPServer 80 &')
h2.cmd('ping -c 1 10.0.20.10 &')
h2.cmd('ifconfig blue1-eth0 mtu 1450')
print "*** Running CLI"
CLI(net)
print "*** Stopping network"
net.stop()
示例2: createEmptyNet
# 需要导入模块: from mininet.net import Mininet [as 别名]
# 或者: from mininet.net.Mininet import addHost [as 别名]
def createEmptyNet():
final_hosts=[]
final_switches=[]
net = Mininet(controller=OVSController,link=TCLink)
net.addController('c0')
evenflag=1
oddflag=1
evenflagip='11.0.0.'
oddflagip='11.0.1.'
for x in range(0,B*A):
if x%2==0:
final_hosts.append(net.addHost('h'+str(x+1), ip=evenflagip+str(evenflag)+'/24'))
evenflag+=1
else:
final_hosts.append(net.addHost('h'+str(x+1), ip=oddflagip+str(oddflag)+'/24'))
oddflag+=1
for x in range(0,A):
final_switches.append(net.addSwitch('s'+str(x+1)))
bwidth=0
for x in range(0,A):
for y in range(0,B):
net.addLink( final_hosts[B*x+y], final_switches[x] , bw=bwidth+1)
bwidth=(bwidth+1)%2
for x in range(0,A-1):
net.addLink(final_switches[x],final_switches[x+1],bw=2)
net.start()
CLI( net )
net.stop()
示例3: emptyNet
# 需要导入模块: from mininet.net import Mininet [as 别名]
# 或者: from mininet.net.Mininet import addHost [as 别名]
def emptyNet():
"Create an empty network and add nodes to it."
net = Mininet( topo=None,
build=False)
net.addController( 'c0',
controller=RemoteController,
ip='0.0.0.0' )
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' )
s1 = net.addSwitch( 's1', cls=OVSSwitch )
net.addLink( h1, s1 )
net.addLink( h2, s1 )
net.addLink( h3, s1 )
net.start()
s1.cmd('ifconfig s1 inet 10.0.0.10')
CLI( net )
net.stop()
示例4: emptyNet
# 需要导入模块: from mininet.net import Mininet [as 别名]
# 或者: from mininet.net.Mininet import addHost [as 别名]
def emptyNet() :
l=[int(i) for i in raw_input().split()]
X=l[0]
Y=l[1]
net=Mininet(controller=Controller,link=TCLink)
net.addController('c0')
info('Adding Switches\n')
S=[]
for i in range(Y) :
switchname='S'+str(i)
S.append(net.addSwitch(switchname))
k=0
H=[]
info('Adding Hosts\n')
for i in range(Y) :
for j in range(X) :
if k%2 == 0 :
hostname='H'+str(k)
ipaddr='10.0.0.'+str(k+1)+'/24'
H.append(net.addHost(hostname,ip=ipaddr))
else :
hostname='H'+str(k)
ipaddr='10.0.1.'+str(k+1)+'/24'
H.append(net.addHost(hostname,ip=ipaddr))
k=k+1
示例5: createTopo
# 需要导入模块: from mininet.net import Mininet [as 别名]
# 或者: from mininet.net.Mininet import addHost [as 别名]
def createTopo( ):
"Simple topology example."
net = Mininet( controller=RemoteController)
info( '*** Adding controller\n' )
net.addController( 'c0', controller=RemoteController,ip="127.0.0.1",port=6633 )
# Add hosts and switches
leftHost = net.addHost( 'h1' )
rightHost = net.addHost( 'h2' )
leftSwitch = net.addSwitch( 's3' )
rightSwitch = net.addSwitch( 's4' )
centerSwitchl = net.addSwitch( 's5' )
centerSwitchr = net.addSwitch( 's6' )
# Add links
net.addLink( leftHost, leftSwitch )
net.addLink( leftSwitch, centerSwitchl )
net.addLink( centerSwitchl, centerSwitchr )
net.addLink( centerSwitchr, rightSwitch)
linkOpts = {'bw':10};
net.addLink( rightSwitch, rightHost, cls=TCLink, **linkOpts)
info( '*** Starting network\n')
net.start()
info( '*** Running CLI\n' )
CLI( net )
info( '*** Stopping network' )
net.stop()
示例6: dummyNet
# 需要导入模块: from mininet.net import Mininet [as 别名]
# 或者: from mininet.net.Mininet import addHost [as 别名]
def dummyNet():
net = Mininet( controller=RemoteController )
net.addController( 'r0' , controller=RemoteController,
ip='10.39.1.18',
port=6633)
p = net.addHost( 'p', ip='10.0.0.2' )
c = net.addHost( 'c', ip='10.0.0.1' )
t11 = net.addHost( 't11', ip='10.0.0.11' )
#
s1 = net.addSwitch( 's1' )
#
net.addLink( p, s1 )
net.addLink( s1, t11 )
net.addLink( s1, c )
#
p.setMAC(mac='00:00:00:01:00:02')
c.setMAC(mac='00:00:00:01:00:01')
t11.setMAC(mac='00:00:00:00:01:01')
#To fix "network is unreachable"
p.setDefaultRoute(intf='p-eth0')
c.setDefaultRoute(intf='c-eth0')
t11.setDefaultRoute(intf='t11-eth0')
#
net.start()
#
run_tnodes([t11])
#
CLI( net )
net.stop()
示例7: myTopo
# 需要导入模块: from mininet.net import Mininet [as 别名]
# 或者: from mininet.net.Mininet import addHost [as 别名]
def myTopo():
net = Mininet(switch=OVSKernelSwitch)
net.addController('controller01',controller=RemoteController,ip=ofc_ip, port=ofc_port)
spine1 = net.addSwitch(spine1_name, dpid=spine1_dpid)
leaf1 = net.addSwitch(leaf1_name, dpid=leaf1_dpid)
leaf2 = net.addSwitch(leaf2_name, dpid=leaf2_dpid)
host1 = net.addHost(host1_name, ip=host1_ip)
host2 = net.addHost(host2_name, ip=host2_ip)
host3 = net.addHost(host3_name, ip=host3_ip)
host4 = net.addHost(host4_name, ip=host4_ip)
net.addLink(spine1, leaf1)
net.addLink(spine1, leaf2)
net.addLink(leaf1, host1)
net.addLink(leaf1, host2)
net.addLink(leaf2, host3)
net.addLink(leaf2, host4)
net.start()
print "Dumping node connections"
dumpNodeConnections(net.switches)
dumpNodeConnections(net.hosts)
ofp_version(spine1, ['OpenFlow13'])
ofp_version(leaf1, ['OpenFlow13'])
ofp_version(leaf2, ['OpenFlow13'])
CLI(net)
net.stop()
示例8: Mesh
# 需要导入模块: from mininet.net import Mininet [as 别名]
# 或者: from mininet.net.Mininet import addHost [as 别名]
def Mesh(switches=4):
"Create A Mesh Topo"
clients = servers = cservers = switches
print "*** Mesh With", switches, "Switches,", clients, "Client,", servers, "Servers,", cservers, "CacheServers"
"Create Switches And Hosts"
cli = []
ser = []
cse = []
swi = []
links = [] # Links to be monitored
net = Mininet( controller=RemoteController, switch=OVSKernelSwitch, build=False )
i = 0
h = 0
print "*** Creating Clients"
for h in range(0, clients):
cli.append(net.addHost('cli%s' % (h+1)))
print "*** Creating Servers"
for h in range(0, servers):
ser.append(net.addHost('ser%s' % (h+1)))
print "*** Creating CacheServers"
for h in range(0, cservers):
cse.append(net.addHost('cse%s' % (h+1)))
print "*** Creating Switches"
root = connectToRootNS(net)
# When you create a new topology you have to save in some way the link and sw that you want to be monitored
for i in range(switches):
sw = (net.addSwitch('s%s_c' % (i+1)))
print "Connect", cli[i], "To", sw
print "Connect", ser[i], "To", sw
print "Connect", cse[i], "To", sw
net.addLink(cli[i], sw)
net.addLink(ser[i], sw)
net.addLink(cse[i], sw)
for rhs in swi:
if i == (switches-1):
links.append(net.addLink(sw,rhs))
else:
net.addLink(sw, rhs)
print "Connect", sw, "To", rhs
swi.append(sw)
print "*** Configure Clients"
for h in range(0,clients):
node_config(cli[h],(h+1))
print "*** Configure Servers"
for h in range(0,servers):
node_config(ser[h],(h+1))
print "*** Configure CacheServers"
for h in range(0,cservers):
node_config(cse[h],(h+1))
print "*** Prepare Link To Be Monitored"
for link in links:
portsToBeMonitored.append(portToBeMonitored( swi[len(swi)-1].dpid, # Switch To Be Monitored
str(link.intf1), # Intf To Be Monitored
str(link.intf2))) # Connected To
swi.append(root)
fixSwitchIntf(swi)
return net
示例9: MyTopo
# 需要导入模块: from mininet.net import Mininet [as 别名]
# 或者: from mininet.net.Mininet import addHost [as 别名]
class MyTopo(object):
def __init__(self, cname='onos', cips=['10.0.3.1']):
# Create network with multiple controllers
self.net = Mininet(controller=RemoteController, switch=OVSKernelSwitch,
build=False, autoSetMacs=True)
# Add controllers with input IPs to the network
ctrls = [RemoteController(cname, cip, 6633) for cip in cips]
for ctrl in ctrls:
print ctrl.ip
self.net.addController(ctrl)
# Add components
self.s1 = self.net.addSwitch('s1', protocols='OpenFlow13')
h1 = self.net.addHost('h1', ip='192.168.0.9', mac='00:00:00:00:00:01')
h2 = self.net.addHost('h2', ip='192.168.0.10', mac='00:00:00:00:00:02')
# Add links
self.net.addLink(h1, self.s1)
self.net.addLink(h2, self.s1)
def run(self):
self.net.build()
self.net.start()
self.s1.cmd('ovs-vsctl set bridge s1 protocols=OpenFlow13')
self.s1.cmd('ovs-vsctl add-port s1 vxlan1')
self.s1.cmd('ovs-vsctl set interface vxlan1 type=vxlan option:remote_ip=flow option:local_ip=flow option:key=flow')
CLI(self.net)
self.net.stop()
示例10: emptyNet
# 需要导入模块: from mininet.net import Mininet [as 别名]
# 或者: from mininet.net.Mininet import addHost [as 别名]
def emptyNet(nHost,nSwitch):
"Create an empty network and add nodes to it."
net = Mininet( controller=Controller )
info( '*** Adding controller ***\n' )
net.addController( 'c0' )
info( '*** Adding hosts\n' )
odd = []
even = []
arr = []
for i in range(nHost):
if i%2 == 0:
randomN = random.randint(1,50000)
h1 = net.addHost('h' +str(i), ip = subnet1 + str(i+1) )
s = 'h' + str(i)
arr.append({s:randomN} )
odd.append(h1)
else:
h2 = net.addHost('h' + str(i),ip = subnet2 + str(i+1) )
randomN = random.randint(1,50000)
s = 'h' + str(i)
arr.append({s:randomN})
even.append(h2)
print 'Host name and their id are as follows : '
print arr
# h1 = net.addHost( 'h1', ip= ip1 )
# h2 = net.addHost( 'h2', ip= ip2 )
info( '*** Adding switch\n' )
switch = []
for i in range(nSwitch):
s3 = net.addSwitch('s'+str(i+1))
switch.append(s3)
# s3 = net.addSwitch( 's3' )
info( '*** Creating links\n' )
for i in range(nSwitch):
a = net.addLink( odd[i], switch[i])
a.intf1.config(bw=2)
b = net.addLink(even[i], switch[i])
b.intf1.config(bw=1)
for i in range(nSwitch-1):
net.addLink(switch[i], switch[i+1])
# net.addLink( h1, s3 )
# net.addLink( h2, s3 )
info( '*** Starting network\n')
net.start()
info( '*** Running CLI\n' )
CLI( net )
info( '*** Stopping network' )
net.stop()
示例11: myNetwork
# 需要导入模块: from mininet.net import Mininet [as 别名]
# 或者: from mininet.net.Mininet import addHost [as 别名]
def myNetwork():
net = Mininet()
host_1 = net.addHost('host_1', ip='192.168.0.10/24')
router_1 = net.addHost('router_1')
net.addLink(host_1, router_1)
# Interface binding with the SDN_hub's eth1
Intf( 'eth1', node=router_1)
# Print information
info( '*** Starting network\n')
net.start()
router_1.cmd('ifconfig router-eth0 0')
router_1.cmd('ifconfig router-eth1 0')
router_1.cmd("ip addr add 192.168.0.1/24 brd + dev router_1-eth0")
router_1.cmd("ip addr add 10.0.0.1 brd + dev router_1-eth1")
router_1.cmd("echo 1 > /proc/sys/net/ipv4/ip_forward")
host_1.cmd("ip route add default via 192.168.0.1")
CLI(net)
net.stop()
示例12: topology
# 需要导入模块: from mininet.net import Mininet [as 别名]
# 或者: from mininet.net.Mininet import addHost [as 别名]
def topology():
"Create a network."
net = Mininet( controller=RemoteController, link=TCLink, switch=OVSKernelSwitch )
print "*** Creating nodes"
s1 = net.addSwitch( 's1', listenPort=6634, mac='00:00:00:00:00:01' )
s4 = net.addSwitch( 's4', listenPort=6635, mac='00:00:00:00:00:04' )
s6 = net.addSwitch( 's6', listenPort=6636, mac='00:00:00:00:00:06' )
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' )
h4 = net.addHost( 'h4', mac='00:00:00:00:00:04', ip='10.0.0.4/8' )
#c7 = net.addController( 'c5', controller=RemoteController, ip='127.0.0.1', port=6633 )
c7 = net.addController( 'c5', controller=RemoteController, ip='192.168.59.105', port=6633 )
print "*** Creating links"
net.addLink(s1, h2, 1, 0)
net.addLink(s1, s4, 2, 1)
net.addLink(s4, h4, 3, 0)
net.addLink(s4, s6, 2, 1)
net.addLink(s6, h3, 2, 0)
print "*** Starting network"
net.build()
s1.start( [c7] )
s4.start( [c7] )
s6.start( [c7] )
c7.start()
print "*** Running CLI"
CLI( net )
print "*** Stopping network"
net.stop()
示例13: myNet
# 需要导入模块: from mininet.net import Mininet [as 别名]
# 或者: from mininet.net.Mininet import addHost [as 别名]
def myNet():
net = Mininet(controller=RemoteController)
net.addController( 'c0',ip='127.0.0.1')
#NAT
s1 = net.addSwitch( 's1', dpid = '000000000000000A', protocols = 'OpenFlow13')
#Internal hosts
alice = net.addHost( 'alice', ip='192.168.0.2/24', defaultRoute='via 192.168.0.1', mac='0000000000E1')
bob = net.addHost( 'bob', ip='192.168.0.3/24', defaultRoute='via 192.168.0.1', mac='0000000000E2')
#External host
charlie = net.addHost( 'charlie', ip='10.0.0.100', mac='0000000000E3')
net.addLink(s1, alice)
net.addLink(s1, bob)
net.addLink(s1, charlie)
net.start()
alice.cmd('arp -s 192.168.0.1 00:00:00:00:00:e3 -i alice-eth0')
alice.cmd('arp -s 192.168.0.3 00:00:00:00:00:e2 -i alice-eth0')
bob.cmd('arp -s 192.168.0.1 00:00:00:00:00:e3 -i bob-eth0')
bob.cmd('arp -s 192.168.0.2 00:00:00:00:00:e1 -i bob-eth0')
charlie.cmd('arp -s 10.0.0.2 00:00:00:00:00:e1 -i charlie-eth0')
charlie.cmd('arp -s 10.0.0.3 00:00:00:00:00:e2 -i charlie-eth0')
c = net.get('c0')
CLI(net)
net.stop()
示例14: emptyNet
# 需要导入模块: from mininet.net import Mininet [as 别名]
# 或者: from mininet.net.Mininet import addHost [as 别名]
def emptyNet():
net = Mininet(controller=RemoteController, switch=OVSKernelSwitch)
c1 = net.addController('c1', controller=RemoteController, ip="127.0.0.1", port=6633)
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' )
s1 = net.addSwitch( 's1' )
s2 = net.addSwitch( 's2' )
s1.linkTo( h1 )
s1.linkTo( h2 )
s2.linkTo( h3 )
s2.linkTo( h4 )
s1.linkTo( s2 )
net.build()
c1.start()
s1.start([c1])
s2.start([c1])
CLI( net )
net.stop()
示例15: config_net
# 需要导入模块: from mininet.net import Mininet [as 别名]
# 或者: from mininet.net.Mininet import addHost [as 别名]
def config_net(self):
net = Mininet(switch=OVSKernelSwitch,controller=RemoteController)
print '*** Adding controller'
net.addController('c0',ip=self.controller_ip)
print '*** Adding hosts'
h1 = net.addHost( 'h1', mac='00:00:00:00:00:01')
h2 = net.addHost( 'h2', mac='00:00:00:00:00:02')
h3 = net.addHost( 'h3', mac='00:00:00:00:00:03')
h4 = net.addHost( 'h4', mac='00:00:00:00:00:04')
print '*** Adding switch'
s1 = net.addSwitch( 's1' )
s2 = net.addSwitch( 's2' )
s3 = net.addSwitch( 's3' )
print '*** Creating links'
net.addLink(h1,s2)
net.addLink(h2,s2)
net.addLink(h3,s3)
net.addLink(h4,s3)
net.addLink(s1,s2)
net.addLink(s1,s3)
self.net = net