本文整理汇总了Python中mininet.util.ipAdd函数的典型用法代码示例。如果您正苦于以下问题:Python ipAdd函数的具体用法?Python ipAdd怎么用?Python ipAdd使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了ipAdd函数的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: build
def build( self ):
print "Build network based on our topology."
net = Mininet( topo=None, build=False, link=TCLink, ipBase=self.minieditIpBase )
net.controllers = self.addControllers()
# Make nodes
print "Getting Hosts and Switches."
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:
ipBaseNum, prefixLen = netParse( self.minieditIpBase )
ip = ipAdd(i=nodeNum, prefixLen=prefixLen, ipBaseNum=ipBaseNum)
net.addHost( name, ip=ip )
else:
raise Exception( "Cannot create mystery node: " + name )
# Make links
print "Getting Links."
for link in self.links.values():
( src, dst, linkopts ) = link
srcName, dstName = src[ 'text' ], dst[ 'text' ]
src, dst = net.nameToNode[ srcName ], net.nameToNode[ dstName ]
net.addLink(src, dst, **linkopts)
self.printInfo()
# Build network (we have to do this separately at the moment )
net.build()
return net
示例2: addHost
def addHost( self, name, cls=None, **params ):
"""Add host.
name: name of host to add
cls: custom host class/constructor (optional)
params: parameters for host
returns: added host"""
defaults = {}
autoSetIp = params.get( 'autoSetIp', True )
if autoSetIp:
# Default IP and MAC addresses
defaults[ 'ip' ] = ipAdd( self.nextIP, ipBaseNum=self.ipBaseNum,
prefixLen=self.prefixLen) + '/%s' % (self.prefixLen,)
if self.autoSetMacs:
defaults[ 'mac' ] = macColonHex( self.nextIP )
self.nextIP += 1
if self.autoPinCpus:
defaults[ 'cores' ] = self.nextCore
self.nextCore = ( self.nextCore + 1 ) % self.numCores
defaults.update( params )
if not cls:
cls = self.host
h = cls( name, **defaults )
self.hosts.append( h )
self.nameToNode[ name ] = h
return h
示例3: build
def build( self, count=1,ipstart=0x0a010000, br='br-int', brdp="0000abcdef000001" ):
if isinstance(ipstart, str): ipstart=int(ipstart,16)
customBr = self.addSwitch( str(br), dpid=str(brdp) )
hosts = [ self.addHost( 'h%d' % i, ip= ipAdd(i,16,ipstart)+'/8') for i in range( 1, count + 1 ) ]
# Add links
for h in hosts:
self.addLink( h, customBr)
示例4: addHost
def addHost( self, name, cls=None, **params ):
"""Add host.
name: name of host to add
cls: custom host class/constructor (optional)
params: parameters for host
returns: added host"""
# Default IP and MAC addresses
defaults = { 'ip': ipAdd( self.nextIP,
ipBaseNum=self.ipBaseNum,
prefixLen=self.prefixLen ) +
'/%s' % self.prefixLen }
print defaults
IPS=[]
for lin in defaults.values():
IPS.append(lin[0:8])
print IPS
with open('my_dict.json','a')as f:
json.dump(defaults.values(),f)
f.write('\n')
if self.autoSetMacs:
defaults[ 'mac'] = macColonHex( self.nextIP )
if self.autoPinCpus:
defaults[ 'cores' ] = self.nextCore
self.nextCore = ( self.nextCore + 1 ) % self.numCores
self.nextIP += 1
defaults.update( params )
if not cls:
cls = self.host
h = cls( name, **defaults )
self.hosts.append( h )
self.nameToNode[ name ] = h
return h
示例5: _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
示例6: addStation
def addStation( self, name, cls=None, **params ):
"""Add host.
name: name of host to add
cls: custom host class/constructor (optional)
params: parameters for host
returns: added host"""
#Default IP and MAC addresses
defaults = { 'ip': ipAdd( self.nextIP,
ipBaseNum=self.ipBaseNum,
prefixLen=self.prefixLen ) +
'/%s' % self.prefixLen }
if self.autoSetMacs:
defaults[ 'mac' ] = macColonHex( self.nextIP )
if self.autoPinCpus:
defaults[ 'cores' ] = self.nextCore
self.nextCore = ( self.nextCore + 1 ) % self.numCores
#self.nextIP += 1
defaults.update( params )
if not cls:
cls = self.host
h = cls( name, **defaults )
self.hosts.append( h )
self.nameToNode[ name ] = h
self.wirelessifaceControl.append(self.nextIface)
self.wirelessdeviceControl.append(name)
self.stationName.append(name)
os.system("iw phy phy%s set netns %s" % (self.nextIface, h.pid))
self.host.cmd(h,"ip link set dev wlan%s name %s-wlan0" % (self.nextIface, h))
self.host.cmd(h,"ifconfig %s-wlan0 up" % h)
self.host.cmd(h,"ifconfig %s-wlan0 10.1.1.%s/%s" % (h, self.nextIP, self.prefixLen))
#callfun="start"
#intf=self.nextIface
#src=name
#wlink(callfun, intf, src)
#self.host.cmd(h,"iw %s-wlan0 connect %s" % (h, "my_ssid"))
self.nextIP += 1
self.nextIface+=1
#os.system("iw dev wlan2 interface add mesh2 type station")
#os.system("sleep 2")
#os.system("sleep 2")
#os.system("iw dev mesh2 station join bazookaa")
return h
示例7: printInfo
def printInfo( self ):
"print nodes and links."
for widget in self.widgetToItem:
name = widget[ 'text' ]
tags = self.canvas.gettags( self.widgetToItem[ widget ] )
x1, y1 = self.canvas.coords( self.widgetToItem[ widget ] )
nodeNum = int( name[ 1: ] )
if 'Switch' in tags:
print "Switch "+name+" at "+str(x1)+"/"+str(y1)+"."
elif 'Host' in tags:
ipBaseNum, prefixLen = netParse( self.minieditIpBase )
print 'ipBaseNum='+str(ipBaseNum)
print 'prefixLen='+str(prefixLen)
ip = ipAdd(i=nodeNum, prefixLen=prefixLen, ipBaseNum=ipBaseNum)
print "Host "+name+" with IP "+ip+" at "+str(x1)+"/"+str(y1)+"."
else:
raise Exception( "Cannot create mystery node: " + name )
for link in self.links.values():
( src, dst, linkopts ) = link
srcName, dstName = src[ 'text' ], dst[ 'text' ]
print "Link from "+srcName+" to "+dstName+"."
示例8: addHost
def addHost(self, name, cls=None, **params):
"""Add host.
name: name of host to add
cls: custom host class/constructor (optional)
params: parameters for host
returns: added host"""
# Default IP and MAC addresses
defaults = {
"ip": ipAdd(self.nextIP, ipBaseNum=self.ipBaseNum, prefixLen=self.prefixLen) + "/%s" % self.prefixLen
}
if self.autoSetMacs:
defaults["mac"] = macColonHex(self.nextIP)
if self.autoPinCpus:
defaults["cores"] = self.nextCore
self.nextCore = (self.nextCore + 1) % self.numCores
self.nextIP += 1
defaults.update(params)
if not cls:
cls = self.host
h = cls(name, **defaults)
self.hosts.append(h)
self.nameToNode[name] = h
return h
示例9: addTransitPortalRouter
def addTransitPortalRouter( self, name, cls=None, **params ):
"""Add transit portal router.
name: name of transit portal router to add
cls: custom router class/constructor (optional)
returns: added transit portal router ."""
# Default IP and MAC addresses
defaults = { 'ip': ipAdd( self.nextIP,
ipBaseNum=self.ipBaseNum,
prefixLen=self.prefixLen ) +
'/%s' % self.prefixLen }
if self.autoSetMacs:
defaults[ 'mac'] = macColonHex( self.nextIP )
if self.autoPinCpus:
defaults[ 'cores' ] = self.nextCore
self.nextCore = ( self.nextCore + 1 ) % self.numCores
self.nextIP += 1
defaults.update( params )
if not cls:
cls = self.transitPortalRouter
tpr = cls( name, **defaults )
self.transitPortalRouters.append( tpr )
self.nameToNode[ name ] = tpr
return tpr
示例10: getNextIp
def getNextIp( self ):
ip = ipAdd( self.nextIP,
ipBaseNum=self.ipBaseNum,
prefixLen=self.prefixLen ) + '/%s' % self.prefixLen
self.nextIP += 1
return ip