本文整理汇总了Python中mininet.net.Containernet.addLink方法的典型用法代码示例。如果您正苦于以下问题:Python Containernet.addLink方法的具体用法?Python Containernet.addLink怎么用?Python Containernet.addLink使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mininet.net.Containernet
的用法示例。
在下文中一共展示了Containernet.addLink方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: tfTopo
# 需要导入模块: from mininet.net import Containernet [as 别名]
# 或者: from mininet.net.Containernet import addLink [as 别名]
def tfTopo():
net = Containernet( topo=None, controller=RemoteController, switch=OVSKernelSwitch )
net.addController( 'c0', RemoteController, ip="127.0.0.1", port=6633 )
# Hosts
h1 = net.addHost('h1', ip='10.0.0.1', mac='00:00:00:00:00:01')
h2 = net.addHost('h2', ip='10.0.0.2', mac='00:00:00:00:00:02')
h3 = net.addHost('h3', ip='10.0.0.3', mac='00:00:00:00:00:03', cls=Docker, dimage='gmiotto/click',mem_limit=1024*1024*10)
h4 = net.addHost('h4', ip='10.0.0.4', mac='00:00:00:00:00:04')
h5 = net.addHost('h5', ip='10.0.0.5', mac='00:00:00:00:00:05')
#Switches
s1 = net.addSwitch('s1')
s2 = net.addSwitch('s2')
s3 = net.addSwitch('s3')
s4 = net.addSwitch('s4')
s5 = net.addSwitch('s5')
net.addLink(h3,s3)
net.addLink(h3,s3)
net.addLink(s1,s2)
net.addLink(s2,s3)
net.addLink(s3,s4)
net.addLink(s4,s5)
net.addLink(h1,s1)
net.addLink(h2,s2)
net.addLink(h4,s4)
net.addLink(h5,s5)
net.start()
for host in net.hosts:
if "h" in host.name:
host.cmd('ethtool -K %s-eth0 tso off' % host.name)
#call("echo %s "% 'ha',shell=True)
CLI(net)
net.stop()
示例2: addLink
# 需要导入模块: from mininet.net import Containernet [as 别名]
# 或者: from mininet.net.Containernet import addLink [as 别名]
def addLink(self, node1, node2, **params):
"""
Able to handle Datacenter objects as link
end points.
"""
assert node1 is not None
assert node2 is not None
LOG.debug("addLink: n1=%s n2=%s" % (str(node1), str(node2)))
# ensure type of node1
if isinstance( node1, basestring ):
if node1 in self.dcs:
node1 = self.dcs[node1].switch
if isinstance( node1, Datacenter ):
node1 = node1.switch
# ensure type of node2
if isinstance( node2, basestring ):
if node2 in self.dcs:
node2 = self.dcs[node2].switch
if isinstance( node2, Datacenter ):
node2 = node2.switch
# try to give containers a default IP
if isinstance( node1, Docker ):
if "params1" not in params:
params["params1"] = {}
if "ip" not in params["params1"]:
params["params1"]["ip"] = self.getNextIp()
if isinstance( node2, Docker ):
if "params2" not in params:
params["params2"] = {}
if "ip" not in params["params2"]:
params["params2"]["ip"] = self.getNextIp()
# ensure that we allow TCLinks between data centers
# TODO this is not optimal, we use cls=Link for containers and TCLink for data centers
# see Containernet issue: https://github.com/mpeuster/containernet/issues/3
if "cls" not in params:
params["cls"] = TCLink
link = Containernet.addLink(self, node1, node2, **params)
# try to give container interfaces a default id
node1_port_id = node1.ports[link.intf1]
if isinstance(node1, Docker):
if "id" in params["params1"]:
node1_port_id = params["params1"]["id"]
node1_port_name = link.intf1.name
node2_port_id = node2.ports[link.intf2]
if isinstance(node2, Docker):
if "id" in params["params2"]:
node2_port_id = params["params2"]["id"]
node2_port_name = link.intf2.name
# add edge and assigned port number to graph in both directions between node1 and node2
# port_id: id given in descriptor (if available, otherwise same as port)
# port: portnumber assigned by Containernet
attr_dict = {}
# possible weight metrics allowed by TClink class:
weight_metrics = ['bw', 'delay', 'jitter', 'loss']
edge_attributes = [p for p in params if p in weight_metrics]
for attr in edge_attributes:
# if delay: strip ms (need number as weight in graph)
match = re.search('([0-9]*\.?[0-9]+)', params[attr])
if match:
attr_number = match.group(1)
else:
attr_number = None
attr_dict[attr] = attr_number
attr_dict2 = {'src_port_id': node1_port_id, 'src_port_nr': node1.ports[link.intf1],
'src_port_name': node1_port_name,
'dst_port_id': node2_port_id, 'dst_port_nr': node2.ports[link.intf2],
'dst_port_name': node2_port_name}
attr_dict2.update(attr_dict)
self.DCNetwork_graph.add_edge(node1.name, node2.name, attr_dict=attr_dict2)
attr_dict2 = {'src_port_id': node2_port_id, 'src_port_nr': node2.ports[link.intf2],
'src_port_name': node2_port_name,
'dst_port_id': node1_port_id, 'dst_port_nr': node1.ports[link.intf1],
'dst_port_name': node1_port_name}
attr_dict2.update(attr_dict)
self.DCNetwork_graph.add_edge(node2.name, node1.name, attr_dict=attr_dict2)
return link
示例3: setLogLevel
# 需要导入模块: from mininet.net import Containernet [as 别名]
# 或者: from mininet.net.Containernet import addLink [as 别名]
"""
from mininet.net import Containernet
from mininet.node import Controller
from mininet.cli import CLI
from mininet.link import TCLink
from mininet.log import info, setLogLevel
setLogLevel('info')
net = Containernet(controller=Controller)
info('*** Adding controller\n')
net.addController('c0')
info('*** Adding docker containers\n')
d1 = net.addDocker('d1', ip='10.0.0.251', dimage="ubuntu:trusty")
d2 = net.addDocker('d2', ip='10.0.0.252', dimage="ubuntu:trusty")
info('*** Adding switches\n')
s1 = net.addSwitch('s1')
s2 = net.addSwitch('s2')
info('*** Creating links\n')
net.addLink(d1, s1)
net.addLink(s1, s2, cls=TCLink, delay='100ms', bw=1)
net.addLink(s2, d2)
info('*** Starting network\n')
net.start()
info('*** Testing connectivity\n')
net.ping([d1, d2])
info('*** Running CLI\n')
CLI(net)
info('*** Stopping network')
net.stop()
示例4: info
# 需要导入模块: from mininet.net import Containernet [as 别名]
# 或者: from mininet.net.Containernet import addLink [as 别名]
info('*** Adding controller\n')
net.addController('c0')
info('*** Adding docker containers\n')
d1 = net.addDocker('d1', dimage="ubuntu:trusty")
d2 = net.addDocker('d2', dimage="containernet_example:ubuntu1404")
d3 = net.addDocker('d3', dimage="containernet_example:ubuntu1604")
d4 = net.addDocker('d4', dimage="containernet_example:ubuntu1804")
d5 = net.addDocker('d5', dimage="containernet_example:centos6")
d6 = net.addDocker('d6', dimage="containernet_example:centos7")
info('*** Adding switches\n')
s1 = net.addSwitch('s1')
info('*** Creating links\n')
net.addLink(d1, s1)
net.addLink(d2, s1)
net.addLink(d3, s1)
net.addLink(d4, s1)
net.addLink(d5, s1)
net.addLink(d6, s1)
info('*** Starting network\n')
net.start()
info('*** Testing connectivity\n')
net.ping([d2, d1])
net.ping([d3, d1])
net.ping([d4, d1])
net.ping([d5, d1])
net.ping([d6, d1])
示例5: tfTopo
# 需要导入模块: from mininet.net import Containernet [as 别名]
# 或者: from mininet.net.Containernet import addLink [as 别名]
def tfTopo():
net = Containernet( topo=None, controller=RemoteController, switch=OVSKernelSwitch )
net.addController( 'c0', RemoteController, ip="127.0.0.1", port=6633 )
#Arguments
opts, args = getopt.getopt(sys.argv[1:], "", ["flows=", "dos="])
for o, a in opts:
if o == "--flows":
number_of_flows=int(a)
print "Flows: ",a
elif o in ("--dos"):
number_of_dos=int(a)
print "DoS: ",a
# Hosts
h1 = net.addHost('h1', ip='10.0.0.1', mac='00:00:00:00:00:01')
h2 = net.addHost('h2', ip='10.0.0.2', mac='00:00:00:00:00:02')
h3 = net.addHost('h3', ip='10.0.0.3', mac='00:00:00:00:00:03')
h4 = net.addHost('h4', ip='10.0.0.4', mac='00:00:00:00:00:04')
h5 = net.addHost('h5', ip='10.0.0.5', mac='00:00:00:00:00:05')
h6 = net.addHost('h6', ip='10.0.0.6', mac='00:00:00:00:00:06')
h7 = net.addHost('h7', ip='10.0.0.7', mac='00:00:00:00:00:07')
h8 = net.addHost('h8', ip='10.0.0.8', mac='00:00:00:00:00:08')
h9 = net.addHost('h9', ip='10.0.0.9', mac='00:00:00:00:00:09')
h10 = net.addHost('h10', ip='10.0.0.10', mac='00:00:00:00:00:10')
p1 = net.addHost('p1', ip='10.0.1.1', mac='00:00:00:00:01:01', cls=Docker, dimage='gmiotto/click',mem_limit=1024*1024*10, cpu_quota=pop_cpu_percentage*100,cpu_period=10000)
p2 = net.addHost('p2', ip='10.0.1.2', mac='00:00:00:00:01:02', cls=Docker, dimage='gmiotto/click',mem_limit=1024*1024*10, cpu_quota=pop_cpu_percentage*100,cpu_period=10000)
p3 = net.addHost('p3', ip='10.0.1.3', mac='00:00:00:00:01:03', cls=Docker, dimage='gmiotto/click',mem_limit=1024*1024*10, cpu_quota=pop_cpu_percentage*100,cpu_period=10000)
p4 = net.addHost('p4', ip='10.0.1.4', mac='00:00:00:00:01:04', cls=Docker, dimage='gmiotto/click',mem_limit=1024*1024*10, cpu_quota=pop_cpu_percentage*100,cpu_period=10000)
p5 = net.addHost('p5', ip='10.0.1.5', mac='00:00:00:00:01:05', cls=Docker, dimage='gmiotto/click',mem_limit=1024*1024*10, cpu_quota=pop_cpu_percentage*100,cpu_period=10000)
p6 = net.addHost('p6', ip='10.0.1.6', mac='00:00:00:00:01:06', cls=Docker, dimage='gmiotto/click',mem_limit=1024*1024*10, cpu_quota=pop_cpu_percentage*100,cpu_period=10000)
#Switches
s1 = net.addSwitch('s1')
s2 = net.addSwitch('s2')
s3 = net.addSwitch('s3')
s4 = net.addSwitch('s4')
s5 = net.addSwitch('s5')
s6 = net.addSwitch('s6')
s7 = net.addSwitch('s7')
s8 = net.addSwitch('s8')
s9 = net.addSwitch('s9')
s10 = net.addSwitch('s10')
#PoP Hosts
net.addLink(p1,s1, cls=TCLink, delay=pop_link_delay,bw=pop_link_bw,loss=pop_link_loss)
net.addLink(p1,s1)
net.addLink(p2,s2, cls=TCLink, delay=pop_link_delay,bw=pop_link_bw,loss=pop_link_loss)
net.addLink(p2,s2)
net.addLink(p3,s3, cls=TCLink, delay=pop_link_delay,bw=pop_link_bw,loss=pop_link_loss)
net.addLink(p3,s3)
net.addLink(p4,s4, cls=TCLink, delay=pop_link_delay,bw=pop_link_bw,loss=pop_link_loss)
net.addLink(p4,s4)
net.addLink(p5,s5, cls=TCLink, delay=pop_link_delay,bw=pop_link_bw,loss=pop_link_loss)
net.addLink(p5,s5)
net.addLink(p6,s6, cls=TCLink, delay=pop_link_delay,bw=pop_link_bw,loss=pop_link_loss)
net.addLink(p6,s6)
#Normal Hosts
net.addLink(h1,s1, cls=TCLink, delay=host_switch_delay,bw=host_switch_bw,loss=host_switch_loss)
net.addLink(h2,s2, cls=TCLink, delay=host_switch_delay,bw=host_switch_bw,loss=host_switch_loss)
net.addLink(h3,s3, cls=TCLink, delay=host_switch_delay,bw=host_switch_bw,loss=host_switch_loss)
net.addLink(h4,s4, cls=TCLink, delay=host_switch_delay,bw=host_switch_bw,loss=host_switch_loss)
net.addLink(h5,s5, cls=TCLink, delay=host_switch_delay,bw=host_switch_bw,loss=host_switch_loss)
net.addLink(h6,s6, cls=TCLink, delay=host_switch_delay,bw=host_switch_bw,loss=host_switch_loss)
net.addLink(h7,s7, cls=TCLink, delay=host_switch_delay,bw=host_switch_bw,loss=host_switch_loss)
net.addLink(h8,s8, cls=TCLink, delay=host_switch_delay,bw=host_switch_bw,loss=host_switch_loss)
net.addLink(h9,s9, cls=TCLink, delay=host_switch_delay,bw=host_switch_bw,loss=host_switch_loss)
net.addLink(h10,s10, cls=TCLink, delay=host_switch_delay,bw=host_switch_bw,loss=host_switch_loss)
net.addLink(s7, s1, cls=TCLink, delay=inter_switch_delay,bw=inter_switch_bw,loss=inter_switch_loss) #s7-s1
net.addLink(s7, s2, cls=TCLink, delay=inter_switch_delay,bw=inter_switch_bw,loss=inter_switch_loss)
net.addLink(s1, s2, cls=TCLink, delay=inter_switch_delay,bw=inter_switch_bw,loss=inter_switch_loss)
net.addLink(s1, s8, cls=TCLink, delay=inter_switch_delay,bw=inter_switch_bw,loss=inter_switch_loss)
net.addLink(s1, s3, cls=TCLink, delay=inter_switch_delay,bw=inter_switch_bw,loss=inter_switch_loss)
net.addLink(s1, s6, cls=TCLink, delay=inter_switch_delay,bw=inter_switch_bw,loss=inter_switch_loss)
net.addLink(s8, s3, cls=TCLink, delay=inter_switch_delay,bw=inter_switch_bw,loss=inter_switch_loss)
net.addLink(s2, s5, cls=TCLink, delay=inter_switch_delay,bw=inter_switch_bw,loss=inter_switch_loss)
net.addLink(s2, s4, cls=TCLink, delay=inter_switch_delay,bw=inter_switch_bw,loss=inter_switch_loss)
net.addLink(s3, s5, cls=TCLink, delay=inter_switch_delay,bw=inter_switch_bw,loss=inter_switch_loss)
net.addLink(s3, s4, cls=TCLink, delay=inter_switch_delay,bw=inter_switch_bw,loss=inter_switch_loss)
net.addLink(s4, s9, cls=TCLink, delay=inter_switch_delay,bw=inter_switch_bw,loss=inter_switch_loss)
net.addLink(s4, s6, cls=TCLink, delay=inter_switch_delay,bw=inter_switch_bw,loss=inter_switch_loss)
net.addLink(s5, s6, cls=TCLink, delay=inter_switch_delay,bw=inter_switch_bw,loss=inter_switch_loss)
net.addLink(s5, s10, cls=TCLink, delay=inter_switch_delay,bw=inter_switch_bw,loss=inter_switch_loss)
net.addLink(s9, s6, cls=TCLink, delay=inter_switch_delay,bw=inter_switch_bw,loss=inter_switch_loss)
net.addLink(s10, s6, cls=TCLink, delay=inter_switch_delay,bw=inter_switch_bw,loss=inter_switch_loss)
net.start()
for host in net.hosts:
if "h" in host.name:
host.cmd('ethtool -K %s-eth0 tso off' % host.name)
#.........这里部分代码省略.........
示例6: tfTopo
# 需要导入模块: from mininet.net import Containernet [as 别名]
# 或者: from mininet.net.Containernet import addLink [as 别名]
def tfTopo():
net = Containernet( topo=None, controller=RemoteController, switch=OVSKernelSwitch )
net.addController( 'c0', RemoteController, ip="127.0.0.1", port=6633 )
#Arguments
opts, args = getopt.getopt(sys.argv[1:], "", ["flows=", "dos="])
for o, a in opts:
if o == "--flows":
number_of_flows=int(a)
print "Flows: ",a
elif o in ("--dos"):
number_of_dos=int(a)
print "DoS: ",a
# Hosts
h1 = net.addHost('h1', ip='10.0.0.1', mac='00:00:00:00:00:01')
h2 = net.addHost('h2', ip='10.0.0.2', mac='00:00:00:00:00:02')
h3 = net.addHost('h3', ip='10.0.0.3', mac='00:00:00:00:00:03')
h4 = net.addHost('h4', ip='10.0.0.4', mac='00:00:00:00:00:04')
h5 = net.addHost('h5', ip='10.0.0.5', mac='00:00:00:00:00:05')
h6 = net.addHost('h6', ip='10.0.0.6', mac='00:00:00:00:00:06')
h7 = net.addHost('h7', ip='10.0.0.7', mac='00:00:00:00:00:07')
h8 = net.addHost('h8', ip='10.0.0.8', mac='00:00:00:00:00:08')
h9 = net.addHost('h9', ip='10.0.0.9', mac='00:00:00:00:00:09')
h10 = net.addHost('h10', ip='10.0.0.10', mac='00:00:00:00:00:10')
p1 = net.addHost('p1', ip='10.0.1.1', mac='00:00:00:00:01:01', cls=Docker, dimage='gmiotto/click',mem_limit=1024*1024*10, cpu_quota=pop_cpu_percentage*100,cpu_period=10000)
p2 = net.addHost('p2', ip='10.0.1.2', mac='00:00:00:00:01:02', cls=Docker, dimage='gmiotto/click',mem_limit=1024*1024*10, cpu_quota=pop_cpu_percentage*100,cpu_period=10000)
p3 = net.addHost('p3', ip='10.0.1.3', mac='00:00:00:00:01:03', cls=Docker, dimage='gmiotto/click',mem_limit=1024*1024*10, cpu_quota=pop_cpu_percentage*100,cpu_period=10000)
p4 = net.addHost('p4', ip='10.0.1.4', mac='00:00:00:00:01:04', cls=Docker, dimage='gmiotto/click',mem_limit=1024*1024*10, cpu_quota=pop_cpu_percentage*100,cpu_period=10000)
p5 = net.addHost('p5', ip='10.0.1.5', mac='00:00:00:00:01:05', cls=Docker, dimage='gmiotto/click',mem_limit=1024*1024*10, cpu_quota=pop_cpu_percentage*100,cpu_period=10000)
#Switches
s1 = net.addSwitch('s1')
s2 = net.addSwitch('s2')
s3 = net.addSwitch('s3')
s4 = net.addSwitch('s4')
s5 = net.addSwitch('s5')
s6 = net.addSwitch('s6')
s7 = net.addSwitch('s7')
s8 = net.addSwitch('s8')
s9 = net.addSwitch('s9')
s10 = net.addSwitch('s10')
#PoP Hosts
net.addLink(p1,s1, cls=TCLink, delay=pop_link_delay,bw=pop_link_bw,loss=pop_link_loss)
net.addLink(p1,s1)
net.addLink(p2,s2, cls=TCLink, delay=pop_link_delay,bw=pop_link_bw,loss=pop_link_loss)
net.addLink(p2,s2)
net.addLink(p3,s3, cls=TCLink, delay=pop_link_delay,bw=pop_link_bw,loss=pop_link_loss)
net.addLink(p3,s3)
net.addLink(p4,s4, cls=TCLink, delay=pop_link_delay,bw=pop_link_bw,loss=pop_link_loss)
net.addLink(p4,s4)
net.addLink(p5,s5, cls=TCLink, delay=pop_link_delay,bw=pop_link_bw,loss=pop_link_loss)
net.addLink(p5,s5)
#Normal Hosts
net.addLink(h1,s1, cls=TCLink, delay=host_switch_delay,bw=host_switch_bw,loss=host_switch_loss)
net.addLink(h2,s2, cls=TCLink, delay=host_switch_delay,bw=host_switch_bw,loss=host_switch_loss)
net.addLink(h3,s3, cls=TCLink, delay=host_switch_delay,bw=host_switch_bw,loss=host_switch_loss)
net.addLink(h4,s4, cls=TCLink, delay=host_switch_delay,bw=host_switch_bw,loss=host_switch_loss)
net.addLink(h5,s5, cls=TCLink, delay=host_switch_delay,bw=host_switch_bw,loss=host_switch_loss)
net.addLink(h6,s6, cls=TCLink, delay=host_switch_delay,bw=host_switch_bw,loss=host_switch_loss)
net.addLink(h7,s7, cls=TCLink, delay=host_switch_delay,bw=host_switch_bw,loss=host_switch_loss)
net.addLink(h8,s8, cls=TCLink, delay=host_switch_delay,bw=host_switch_bw,loss=host_switch_loss)
net.addLink(h9,s9, cls=TCLink, delay=host_switch_delay,bw=host_switch_bw,loss=host_switch_loss)
net.addLink(h10,s10, cls=TCLink, delay=host_switch_delay,bw=host_switch_bw,loss=host_switch_loss)
net.addLink(s7, s1, cls=TCLink, delay=inter_switch_delay,bw=inter_switch_bw,loss=inter_switch_loss) #s7-s1
net.addLink(s7, s2, cls=TCLink, delay=inter_switch_delay,bw=inter_switch_bw,loss=inter_switch_loss)
net.addLink(s1, s2, cls=TCLink, delay=inter_switch_delay,bw=inter_switch_bw,loss=inter_switch_loss)
net.addLink(s1, s8, cls=TCLink, delay=inter_switch_delay,bw=inter_switch_bw,loss=inter_switch_loss)
net.addLink(s1, s3, cls=TCLink, delay=inter_switch_delay,bw=inter_switch_bw,loss=inter_switch_loss)
net.addLink(s1, s6, cls=TCLink, delay=inter_switch_delay,bw=inter_switch_bw,loss=inter_switch_loss)
net.addLink(s8, s3, cls=TCLink, delay=inter_switch_delay,bw=inter_switch_bw,loss=inter_switch_loss)
net.addLink(s2, s5, cls=TCLink, delay=inter_switch_delay,bw=inter_switch_bw,loss=inter_switch_loss)
net.addLink(s2, s4, cls=TCLink, delay=inter_switch_delay,bw=inter_switch_bw,loss=inter_switch_loss)
net.addLink(s3, s5, cls=TCLink, delay=inter_switch_delay,bw=inter_switch_bw,loss=inter_switch_loss)
net.addLink(s3, s4, cls=TCLink, delay=inter_switch_delay,bw=inter_switch_bw,loss=inter_switch_loss)
net.addLink(s4, s9, cls=TCLink, delay=inter_switch_delay,bw=inter_switch_bw,loss=inter_switch_loss)
net.addLink(s4, s6, cls=TCLink, delay=inter_switch_delay,bw=inter_switch_bw,loss=inter_switch_loss)
net.addLink(s5, s6, cls=TCLink, delay=inter_switch_delay,bw=inter_switch_bw,loss=inter_switch_loss)
net.addLink(s5, s10, cls=TCLink, delay=inter_switch_delay,bw=inter_switch_bw,loss=inter_switch_loss)
net.addLink(s9, s6, cls=TCLink, delay=inter_switch_delay,bw=inter_switch_bw,loss=inter_switch_loss)
net.addLink(s10, s6, cls=TCLink, delay=inter_switch_delay,bw=inter_switch_bw,loss=inter_switch_loss)
net.start()
for host in net.hosts:
if "h" in host.name:
host.cmd('ethtool -K %s-eth0 tso off' % host.name)
host.cmd('python httpserver.py 80 &')
for host in net.hosts:
if "p" in host.name:
#.........这里部分代码省略.........
示例7: simpleTestTopology
# 需要导入模块: from mininet.net import Containernet [as 别名]
# 或者: from mininet.net.Containernet import addLink [as 别名]
class simpleTestTopology( unittest.TestCase ):
"""
Helper class to do basic test setups.
s1 -- s2 -- s3 -- ... -- sN
"""
def __init__(self, *args, **kwargs):
self.net = None
self.s = [] # list of switches
self.h = [] # list of hosts
self.d = [] # list of docker containers
self.docker_cli = None
super(simpleTestTopology, self).__init__(*args, **kwargs)
def createNet(
self,
nswitches=1, nhosts=0, ndockers=0,
autolinkswitches=False):
"""
Creates a Mininet instance and automatically adds some
nodes to it.
"""
self.net = Containernet( controller=Controller )
self.net.addController( 'c0' )
# add some switches
for i in range(0, nswitches):
self.s.append(self.net.addSwitch('s%d' % i))
# if specified, chain all switches
if autolinkswitches:
for i in range(0, len(self.s) - 1):
self.net.addLink(self.s[i], self.s[i + 1])
# add some hosts
for i in range(0, nhosts):
self.h.append(self.net.addHost('h%d' % i))
# add some dockers
for i in range(0, ndockers):
self.d.append(self.net.addDocker('d%d' % i, dimage="ubuntu:trusty"))
def startNet(self):
self.net.start()
def stopNet(self):
self.net.stop()
def getDockerCli(self):
"""
Helper to interact with local docker instance.
"""
if self.docker_cli is None:
self.docker_cli = docker.APIClient(
base_url='unix://var/run/docker.sock')
return self.docker_cli
@staticmethod
def setUp():
pass
@staticmethod
def tearDown():
cleanup()
# make sure that all pending docker containers are killed
with open(os.devnull, 'w') as devnull:
subprocess.call(
"docker rm -f $(docker ps --filter 'label=com.containernet' -a -q)",
stdout=devnull,
stderr=devnull,
shell=True)
def getContainernetContainers(self):
"""
List the containers managed by containernet
"""
return self.getDockerCli().containers(filters={"label": "com.containernet"})
示例8: topology
# 需要导入模块: from mininet.net import Containernet [as 别名]
# 或者: from mininet.net.Containernet import addLink [as 别名]
def topology():
"Create a network with some docker containers acting as hosts."
net = Containernet(controller=Controller)
info('*** Adding controller\n')
net.addController('c0')
info('*** Adding hosts\n')
h1 = net.addHost('h1')
h2 = net.addHost('h2')
info('*** Adding docker containers\n')
d1 = net.addDocker('d1', ip='10.0.0.251', dimage="ubuntu:trusty")
d2 = net.addDocker('d2', ip='10.0.0.252', dimage="ubuntu:trusty", cpu_period=50000, cpu_quota=25000)
d3 = net.addHost(
'd3', ip='11.0.0.253', cls=Docker, dimage="ubuntu:trusty", cpu_shares=20)
d5 = net.addDocker('d5', dimage="ubuntu:trusty", volumes=["/:/mnt/vol1:rw"])
info('*** Adding switch\n')
s1 = net.addSwitch('s1')
s2 = net.addSwitch('s2', cls=OVSSwitch)
s3 = net.addSwitch('s3')
info('*** Creating links\n')
net.addLink(h1, s1)
net.addLink(s1, d1)
net.addLink(h2, s2)
net.addLink(d2, s2)
net.addLink(s1, s2)
#net.addLink(s1, s2, cls=TCLink, delay="100ms", bw=1, loss=10)
# try to add a second interface to a docker container
net.addLink(d2, s3, params1={"ip": "11.0.0.254/8"})
net.addLink(d3, s3)
info('*** Starting network\n')
net.start()
net.ping([d1, d2])
# our extended ping functionality
net.ping([d1], manualdestip="10.0.0.252")
net.ping([d2, d3], manualdestip="11.0.0.254")
info('*** Dynamically add a container at runtime\n')
d4 = net.addDocker('d4', dimage="ubuntu:trusty")
# we have to specify a manual ip when we add a link at runtime
net.addLink(d4, s1, params1={"ip": "10.0.0.254/8"})
# other options to do this
#d4.defaultIntf().ifconfig("10.0.0.254 up")
#d4.setIP("10.0.0.254")
net.ping([d1], manualdestip="10.0.0.254")
info('*** Running CLI\n')
CLI(net)
info('*** Stopping network')
net.stop()
示例9: tfTopo
# 需要导入模块: from mininet.net import Containernet [as 别名]
# 或者: from mininet.net.Containernet import addLink [as 别名]
def tfTopo():
net = Containernet( topo=None, controller=RemoteController, switch=OVSKernelSwitch )
net.addController( 'c0', RemoteController, ip="127.0.0.1", port=6633 )
# Hosts
h1 = net.addHost('h1', ip='10.0.0.1', mac='00:00:00:00:00:01')
h2 = net.addHost('h2', ip='10.0.0.2', mac='00:00:00:00:00:02')
h3 = net.addHost('h3', ip='10.0.0.3', mac='00:00:00:00:00:03', cls=Docker, dimage='gmiotto/click',mem_limit=1024*1024*10, cpu_shares=2)
h4 = net.addHost('h4', ip='10.0.0.4', mac='00:00:00:00:00:04', cls=Docker, dimage='gmiotto/click',mem_limit=1024*1024*10, cpu_shares=10)
h5 = net.addHost('h5', ip='10.0.0.5', mac='00:00:00:00:00:05', cls=Docker, dimage='gmiotto/click',mem_limit=1024*1024*10, cpu_shares=10)
h6 = net.addHost('h6', ip='10.0.0.6', mac='00:00:00:00:00:06')
h7 = net.addHost('h7', ip='10.0.0.7', mac='00:00:00:00:00:07')
h8 = net.addHost('h8', ip='10.0.0.8', mac='00:00:00:00:00:08')
h9 = net.addHost('h9', ip='10.0.0.9', mac='00:00:00:00:00:09')
#Switches
s1 = net.addSwitch('s1')
s2 = net.addSwitch('s2')
s3 = net.addSwitch('s3')
s4 = net.addSwitch('s4')
s5 = net.addSwitch('s5')
s6 = net.addSwitch('s6')
s7 = net.addSwitch('s7')
s8 = net.addSwitch('s8')
s9 = net.addSwitch('s9')
net.addLink(h3,s3)
net.addLink(h3,s3)
net.addLink(h4,s4)
net.addLink(h4,s4)
net.addLink(h5,s5)
net.addLink(h5,s5)
net.addLink(s1,s6)
net.addLink(s1,s7)
#net.addLink(s6, s3, cls=TCLink, delay="100ms", bw=0.5, loss=0)
net.addLink(s6,s3)
net.addLink(s6, s4, cls=TCLink, delay="1ms", bw=2, loss=0)
#net.addLink(s6,s4)
net.addLink(s6,s5)
net.addLink(s7,s3)
net.addLink(s7,s5)
net.addLink(s3,s8)
net.addLink(s3,s9)
net.addLink(s4,s8, cls=TCLink, delay="1ms", bw=2, loss=0)
net.addLink(s4,s9)
net.addLink(s5,s9)
net.addLink(s8,s2)
net.addLink(s9,s2)
net.addLink(h1,s1)
net.addLink(h2,s2)
net.addLink(h6,s6)
net.addLink(h7,s7)
net.addLink(h8,s8)
net.addLink(h9,s9)
net.start()
for host in net.hosts:
if "h" in host.name:
host.cmd('ethtool -K %s-eth0 tso off' % host.name)
call("sudo bash Click/runFirewall.sh h3 Click/firewall3.click ",shell=True)
call("sudo bash Click/runFirewall.sh h4 Click/firewall3.click ",shell=True)
call("sudo bash Click/runFirewall.sh h5 Click/firewall3.click ",shell=True)
h2.cmd('python -m SimpleHTTPServer 80 &')
CLI(net)
net.stop()