本文整理汇总了Python中mininet.link.Link类的典型用法代码示例。如果您正苦于以下问题:Python Link类的具体用法?Python Link怎么用?Python Link使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Link类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
def __init__( self, node1, node2, port1=None, port2=None, allowed=True,
intfName1=None, intfName2=None, linkType='OPTICAL',
annotations={}, speed1=0, speed2=0, **params ):
"Creates a dummy link without a virtual ethernet pair."
self.allowed = allowed
self.annotations = annotations
self.linkType = linkType
params1 = { 'speed': speed1 }
params2 = { 'speed': speed2 }
if isinstance( node1, OpticalSwitch ):
cls1 = OpticalIntf
else:
cls1 = Intf
# bad hack to stop error message from appearing when we try to set up intf in a packet switch,
# and there is no interface there( because we do not run makeIntfPair ). This way, we just set lo up
intfName1 = 'lo'
if isinstance( node2, OpticalSwitch ):
cls2 = OpticalIntf
else:
cls2 = Intf
intfName2 = 'lo'
Link.__init__( self, node1, node2, port1=port1, port2=port2,
intfName1=intfName1, intfName2=intfName2, cls1=cls1,
cls2=cls2, params1=params1, params2=params2 )
示例2: __init__
def __init__(
self,
node1,
node2,
port1=None,
port2=None,
intfName1=None,
intfName2=None,
addr1=None,
addr2=None,
ip1=None,
ip2=None,
**params
):
Link.__init__(
self,
node1,
node2,
port1=port1,
port2=port2,
intfName1=intfName1,
intfName2=intfName2,
cls1=TCIntf,
cls2=TCIntf,
addr1=addr1,
addr2=addr2,
params1=params,
params2=params,
)
if ip1 is not None:
self.intf1.setIP(ip1)
if ip2 is not None:
self.intf2.setIP(ip2)
示例3: __init__
def __init__(self, node1, node2, port1=None, port2=None, allowed=True,
intfName1=None, intfName2=None, linkType='OPTICAL',
annotations={}, speed1=0, speed2=0, **params):
"Creates a dummy link without a virtual ethernet pair."
self.allowed = allowed
self.annotations = annotations
self.linkType = linkType
self.port1 = port1
self.port2 = port2
params1 = { 'speed': speed1 }
params2 = { 'speed': speed2 }
# self.isCrossConnect = True if self.annotations.get('optical.type') == 'cross-connect' else False
if isinstance(node1, LINCSwitch) and isinstance(node2, LINCSwitch):
self.isCrossConnect = False
else:
self.isCrossConnect = True
if isinstance(node1, LINCSwitch):
cls1 = LINCIntf
if self.isCrossConnect:
node1.crossConnects.append(self)
else:
cls1 = Intf
# bad hack to stop error message from appearing when we try to set up intf in a packet switch,
# and there is no interface there( because we do not run makeIntfPair ). This way, we just set lo up
intfName1 = 'lo'
if isinstance(node2, LINCSwitch):
cls2 = LINCIntf
if self.isCrossConnect:
node2.crossConnects.append(self)
else:
cls2 = Intf
intfName2 = 'lo'
Link.__init__(self, node1, node2, port1=port1, port2=port2,
intfName1=intfName1, intfName2=intfName2, cls1=cls1,
cls2=cls2, params1=params1, params2=params2)
示例4: stop
def stop( self ):
"Stop this link"
if self.tunnel:
self.intf1.delete()
self.intf2.delete()
else:
Link.stop( self )
self.tunnel = None
示例5: __init__
def __init__(self, node1, node2, port1=None, port2=None,
intfName1=None, intfName2=None, **params):
Link.__init__(self, node1, node2, port1=port1, port2=port2,
intfName1=intfName1, intfName2=intfName2,
cls1=SdnIntf,
cls2=SdnIntf,
params1=params,
params2=params)
self._connected = True
示例6: __init__
def __init__( self, node1, node2, **kwargs ):
"""Initialize a RemoteLink
see Link() for parameters"""
# Create links on remote node
self.node1 = node1
self.node2 = node2
self.tunnel = None
kwargs.setdefault( 'params1', {} )
kwargs.setdefault( 'params2', {} )
Link.__init__( self, node1, node2, **kwargs )
示例7: __init__
def __init__( self, node1, node2, **kwargs ):
"See Link.__init__() for options"
self.isPatchLink = False
if ( isinstance( node1, OVSSwitch ) and
isinstance( node2, OVSSwitch ) and
getattr( node1, 'ovsdb', None ) ==
getattr( node2, 'ovsdb', None ) ):
self.isPatchLink = True
kwargs.update( cls1=OVSIntf, cls2=OVSIntf )
Link.__init__( self, node1, node2, **kwargs )
示例8: __init__
def __init__(self, node1, node2, port1=None, port2=None,
intf_name1=None, intf_name2=None,
addr1=None, addr2=None, **params):
Link.__init__(self, node1, node2, port1=port1, port2=port2,
intfName1=intf_name1, intfName2=intf_name2,
cls1=ECNIntf,
cls2=ECNIntf,
addr1=addr1, addr2=addr2,
params1=params,
params2=params)
示例9: _create_links
def _create_links(self, links):
def is_remote(node):
return isinstance(node, RemoteSwitch)
def is_local(node):
return not is_remote(node)
self._info('**** Create %d link(s)' % len(links))
for id, link in links.iteritems():
self._debug('\tCreate link %s with params: %s' % (id, link))
node1 = self.net.get(link['node1'])
node2 = self.net.get(link['node2'])
name_to_node = {'node1': node1, 'node2': node2}
link.update(name_to_node)
remote = filter(is_remote, [node1, node2])
local = filter(is_local, [node1, node2])
if not remote:
self.net.addLink(**link)
else:
sw = local[0]
r = remote[0]
intfName = r.params['local_intf_name']
r_mac = None # unknown, r.params['remote_mac']
r_port = r.params['remote_port']
self._debug('\tadd hw interface (%s) to node (%s)' % (intfName, sw.name))
# This hack avoids calling __init__ which always makeIntfPair()
link = Link.__new__(Link)
i1 = Intf(intfName, node=sw, link=link)
i2 = Intf(intfName, node=r, mac=r_mac, port=r_port, link=link)
i2.mac = r_mac # mn runs 'ifconfig', which resets mac to None
#
link.intf1, link.intf2 = i1, i2
示例10: _auto_config_intf
def _auto_config_intf(self, node_name, intf_name, **param):
node = self.nodemap[node_name]
if 'port' not in param:
param['port'] = node.newPort()
if intf_name == 'auto':
intf_name = Link.intfName(node, param['port'])
if intf_name in node.nameToIntf:
error("Node %s already has interface %s." % (node, name))
return False
net = self.mn
if 'ip' not in param:
ip = net.nextIP
net.nextIP += 1
sufix = ipAdd(ip, ipBaseNum=net.ipBaseNum, prefixLen=net.prefixLen)
prefix = '/%s' % net.prefixLen
param['ip'] = sufix + prefix
if 'mac' not in param:
param['mac'] = macColonHex(ip)
elif 'mac' not in param:
ip, prefix = netParse(param['ip'])
param['mac'] = macColonHex(ip)
if 'cores' not in param and net.autoPinCpus:
param['cores'] = self.nextCore
net.nextCore = (net.nextCore + 1) % net.numCores
return True
示例11: status
def status( self ):
"Detailed representation of link"
if self.tunnel:
if self.tunnel.poll() is not None:
status = "Tunnel EXITED %s" % self.tunnel.returncode
else:
status = "Tunnel Running (%s: %s)" % (
self.tunnel.pid, self.cmd )
else:
status = "OK"
result = "%s %s" % ( Link.status( self ), status )
return result
示例12: makeIntfPair
def makeIntfPair( self, intfname1, intfname2, addr1=None, addr2=None,
node1=None, node2=None, deleteIntfs=True ):
"""Create pair of interfaces
intfname1: name of interface 1
intfname2: name of interface 2
(override this method [and possibly delete()]
to change link type)"""
node1 = self.node1 if node1 is None else node1
node2 = self.node2 if node2 is None else node2
server1 = getattr( node1, 'server', 'localhost' )
server2 = getattr( node2, 'server', 'localhost' )
if server1 == server2:
# Link within same server
Link.makeIntfPair( intfname1, intfname2, addr1, addr2,
node1, node2, deleteIntfs=deleteIntfs )
# Need to reduce the MTU of all emulated hosts to 1450 for GRE
# tunneling, otherwise packets larger than 1400 bytes cannot be
# successfully transmitted through the tunnel.
node1.cmd('ip link set dev %s mtu 1450' % intfname1)
node2.cmd('ip link set dev %s mtu 1450' % intfname2)
else:
# Otherwise, make a tunnel
self.makeTunnel( node1, node2, intfname1, intfname2, addr1, addr2 )
self.tunnel = 1
示例13: connectToRootNS
def connectToRootNS( net, ip='10.123.123.1', mac='00123456789A', prefixLen=8, routes=['10.0.0.0/8']):
print "*** Creating controller"
c0 = net.addController( 'c0', ip='127.0.0.1', port=6633 )
rootswitch = net.addSwitch('roots1',)
rootswitch.dpid = 'FFFFFFFFFFFFFFFF'
# Connect hosts to root namespace via switch. Starts network.
# network: Mininet() network object
# ip: IP address for root namespace node
# prefixLen: IP address prefix length (e.g. 8, 16, 24)
# routes: host networks to route to"
# Create a node in root namespace and link to switch 0
root = Node( 'root', inNamespace=False )
intf = Link( root, rootswitch ).intf1
intf.setMAC(mac)
root.setIP( ip, prefixLen, intf )
print "*** Added Interface", str(intf), "Connected To Root-NameSpace"
fixNetworkManager(str(intf))
for host in net.hosts:
net.addLink(host,rootswitch)
# Add routes from root ns to hosts
for route in routes:
root.cmd( 'route add -net ' + route + ' dev ' + str( intf ) )
root.cmd('service network-manager restart')
return rootswitch
示例14: add
def add( self, node, port=None, intfName=None ):
if hasattr( node, 'nsNode' ) and node.nsNode is not None:
pass
else:
node.nsNode = ns.network.Node()
allNodes.append( node )
device = ns.network.SimpleNetDevice()
device.SetChannel(self.channel)
device.SetAddress (ns.network.Mac48Address.Allocate ())
node.nsNode.AddDevice(device)
if port is None:
port = node.newPort()
if intfName is None:
intfName = Link.intfName( node, port ) # classmethod
tb = TBIntf( intfName, node, port, node.nsNode, device )
return tb
示例15: Host
h0 = Host( 'h0' )
h1 = Host( 'h1' )
h2 = Host( 'h2' )
h3 = Host( 'h3' )
s0 = OVSKernelSwitch( 's0' ,inNamespace=False )
s1 = OVSKernelSwitch( 's1' ,inNamespace=False )
s2 = OVSKernelSwitch( 's2', inNamespace=False )
s3 = OVSKernelSwitch( 's3' ,inNamespace=False )
c0 = RemoteController( 'c0', ip = '10.108.100.195' )
c1 = RemoteController( 'c1', ip = '10.108.100.248' )
c2 = RemoteController( 'c2', ip = '10.108.102.176' )
c3 = RemoteController( 'c3', ip = '10.108.101.48' )
l1 = Link( h0, s1 )
Link( h1, s1 )
Link( h2, s2 )
Link( h3, s3 )
Link( s0, s1 )
Link( s0, s2 )
Link( s0, s3 )
h0.setIP( '10.1.0.1/16' )
h1.setIP( '10.1.0.2/16' )
h2.setIP( '10.2.0.1/16' )
h3.setIP( '10.3.0.1/16' )
print h0.cmd('ifconfig')
c0.start()
c1.start()