本文整理汇总了Python中mininet.log.warn函数的典型用法代码示例。如果您正苦于以下问题:Python warn函数的具体用法?Python warn怎么用?Python warn使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了warn函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: delete
def delete( self ):
"Delete interface"
if self.nsInstalled:
warn( "You can not delete once installed ns-3 device, "
"run mininet.ns3.clear() to delete all ns-3 devices\n" )
else:
Intf.delete( self )
示例2: __init__
def __init__( self, name, n=1, reactive=True, runAsRoot=False, **params):
"""n: number of ONOS instances to run (1)
reactive: run in reactive mode (True)
runAsRoot: run ONOS as root (False)"""
self.check()
self.count = n
self.reactive = reactive
self.runAsRoot = runAsRoot
self.ids = range( 0, self.count )
Controller.__init__( self, name, **params )
self.proxies = []
# We don't need to run as root, and it can interfere
# with starting Zookeeper manually
self.user = None
if not self.runAsRoot:
try:
self.user = quietRun( 'who am i' ).split()[ 0 ]
self.sendCmd( 'su', self.user )
self.waiting = False
except:
warn( '__init__: failed to drop privileges\n' )
self.cmd( 'mkdir -p', self.logDir )
# Need to run commands from ONOS dir
self.cmd( 'cd', self.onosDir )
self.cmd( 'export PATH=$PATH:%s' % self.onosDir )
示例3: defaultIntf
def defaultIntf(self):
"Return interface for lowest port"
ports = self.intfs.keys()
if ports:
return self.intfs[min(ports)]
else:
warn("*** defaultIntf: warning:", self.name, "has no interfaces\n")
示例4: validatePort
def validatePort( self, intf ):
"Validate intf's OF port number"
ofport = int( self.cmd( 'ovs-vsctl get Interface', intf,
'ofport' ) )
if ofport != self.ports[ intf ]:
warn( 'WARNING: ofport for', intf, 'is actually', ofport,
'\n' )
示例5: removeLink
def removeLink( self, node, intf_name ):
if self.debug_flag1:
args = (node, intf_name)
print "EXEC: removeLink(%s, %s):" % args
assert isinstance(node, Host) #Node)
assert intf_name in node.nameToIntf
dummy = self.nameToNode.get("dummy", None)
if dummy is None:
error('dummy node does not exist\n')
return
assert isinstance(dummy, Dummy)
# Special case: Node already connected to dummy.
intf = node.nameToIntf[intf_name]
assert intf.link != None
assert intf.link.intf1 == intf or intf.link.intf2 == intf
assert intf.node != dummy
if intf.link.intf1.node == dummy or intf.link.intf2.node == dummy:
warn('intf %s of %s already removed\n' % (intf_name, node.name))
return
unused = dummy.nameToUnusedPorts
if len(unused) == 0:
dummy_intf_port = dummy.newPort()
dummy_intf_name = 'dummy-eth' + str(dummy_intf_port)
unused[dummy_intf_name] = dummy_intf_port
else:
dummy_intf_name = min(unused, key=unused.get)
self.moveLink(node, dummy, intf_name, dummy_intf_name)
示例6: start
def start():
""" Start the simulator thread in background.
It should be called after configuration of all ns-3 objects
(TBintfs, Segments and Links).
Attempt of adding an ns-3 object when simulator thread is
running may result in segfault. You should stop it first."""
global thread
if 'thread' in globals() and thread.isAlive():
warn( "NS-3 simulator thread already running." )
return
# Install all TapBridge ns-3 devices not installed yet.
for intf in allTBIntfs:
if not intf.nsInstalled:
intf.nsInstall()
# Set up the simulator thread.
thread = threading.Thread( target = runthread )
thread.daemon = True
# Start the simulator thread (this is where fork happens).
# FORK!
thread.start()
# FORK:PARENT
# Code below is executed in the parent thread.
# Move all tap interfaces not moved yet to the right namespace.
for intf in allTBIntfs:
if not intf.inRightNamespace:
intf.namespaceMove()
return
示例7: checkListening
def checkListening( self ):
"Warn if remote controller is not accessible"
listening = self.cmd( "echo A | telnet -e A %s %d" %
( self.ip, self.port ) )
if 'Unable' in listening:
warn( "Unable to contact the remote controller"
" at %s:%d\n" % ( self.ip, self.port ) )
示例8: addAp
def addAp( self, node, channelNumber, ssid=None, enableQos=False, port=None, intfName=None, **attrs):
if ssid is None:
ssid = self.baseSsid + str(len (self.aps) + 1)
if channelNumber <= 0 or channelNumber > self.maxChannelNumber:
channelNumber = random.randint (1, self.maxChannelNumber)
warn("illegal channel number, choose a random channel number %s.\n", channelNumber)
phyHelper = ns.wifi.YansWifiPhyHelper().Default()
phyHelper.Set ("ChannelNumber", ns.core.UintegerValue(channelNumber))
if enableQos:
macHelper = ns.wifi.QosWifiMacHelper.Default()
else:
macHelper = ns.wifi.NqosWifiMacHelper.Default()
setAttributes (macHelper.SetType, "ns3::ApWifiMac", attrs)
tb = self.add (node, phyHelper, macHelper, port, intfName)
if type( ssid ) is str:
wifissid = ns.wifi.Ssid (ssid)
else:
wifissid = ssid
try:
tb.nsDevice.GetMac ().SetAttribute ("Ssid", ns.wifi.SsidValue (wifissid))
except:
warn("the type of wifissid isn't ssidvalue.\n")
wifissid = ns.wifi.Ssid (self.baseSsid + str(len (self.aps) + 1))
tb.nsDevice.GetMac ().SetAttribute ("Ssid", ns.wifi.SsidValue (wifissid))
self.aps.append(tb)
return tb
示例9: setPosition
def setPosition( node, x, y, z ):
""" Set the ns-3 (x, y, z) position of a Mininet node.
Coordinates are in the 3D Cartesian system.
The unit is meters.
node: Mininet node
x: integer or float x coordinate
y: integer or float y coordinate
z: integer or float z coordinate"""
# Check if this Mininet node has assigned the underlying ns-3 node.
if hasattr( node, 'nsNode' ) and node.nsNode is not None:
# If it is assigned, go ahead.
pass
else:
# If not, create new ns-3 node and assign it to this Mininet node.
node.nsNode = ns.network.Node()
allNodes.append( node )
try:
mm = node.nsNode.GetObject( ns.mobility.MobilityModel.GetTypeId() )
if x is None:
x = 0.0
if y is None:
y = 0.0
if z is None:
z = 0.0
# Set postion coordinates in the ns-3 node
pos = mm.SetPosition( ns.core.Vector( x, y, z ) )
except AttributeError:
warn( "ns-3 mobility model not found, not setting position\n" )
示例10: fixLimits
def fixLimits():
"Fix ridiculously small resource limits."
debug( "*** Setting resource limits\n" )
try:
rlimitTestAndSet( RLIMIT_NPROC, 8192 )
rlimitTestAndSet( RLIMIT_NOFILE, 16384 )
#Increase open file limit
sysctlTestAndSet( 'fs.file-max', 10000 )
#Increase network buffer space
sysctlTestAndSet( 'net.core.wmem_max', 16777216 )
sysctlTestAndSet( 'net.core.rmem_max', 16777216 )
sysctlTestAndSet( 'net.ipv4.tcp_rmem', '10240 87380 16777216' )
sysctlTestAndSet( 'net.ipv4.tcp_wmem', '10240 87380 16777216' )
sysctlTestAndSet( 'net.core.netdev_max_backlog', 5000 )
#Increase arp cache size
sysctlTestAndSet( 'net.ipv4.neigh.default.gc_thresh1', 4096 )
sysctlTestAndSet( 'net.ipv4.neigh.default.gc_thresh2', 8192 )
sysctlTestAndSet( 'net.ipv4.neigh.default.gc_thresh3', 16384 )
#Increase routing table size
sysctlTestAndSet( 'net.ipv4.route.max_size', 32768 )
#Increase number of PTYs for nodes
sysctlTestAndSet( 'kernel.pty.max', 20000 )
except:
warn( "*** Error setting resource limits. "
"Mininet's performance may be affected.\n" )
示例11: addSta
def addSta( self, node, channelNumber, ssid=None, enableQos=False, enableScan = True, port=None, intfName=None, **attrs):
if ssid is None:
ssid = ""
if channelNumber <= 0 or channelNumber > self.maxChannelNumber:
channelNumber = random.randint (1, self.maxChannelNumber)
warn("illegal channel number, choose a random channel number %s.\n", channelNumber)
phyHelper = ns.wifi.YansWifiPhyHelper().Default()
phyHelper.Set ("ChannelNumber", ns.core.UintegerValue(channelNumber))
if enableQos:
macHelper = ns.wifi.QosWifiMacHelper.Default()
else:
macHelper = ns.wifi.NqosWifiMacHelper.Default()
setAttributes (macHelper.SetType, "ns3::StaWifiMac", attrs)
tb = self.add (node, phyHelper, macHelper, port, intfName)
if type( ssid ) is str:
wifissid = ns.wifi.Ssid (ssid)
else:
wifissid = ssid
try:
tb.nsDevice.GetMac ().SetAttribute ("Ssid", ns.wifi.SsidValue (wifissid))
except:
warn("the type of wifissid isn't ssidvalue.\n")
tb.nsDevice.GetMac ().SetAttribute ("Ssid", ns.wifi.SsidValue (""))
if enableScan:
tb.nsDevice.GetMac ().SetAttribute ("ScanType", ns.core.EnumValue (ns.wifi.StaWifiMac.ACTIVE))
tb.nsDevice.GetMac ().SetAttribute ("MaxScanningChannelNumber", ns.core.UintegerValue(self.maxChannelNumber))
else:
tb.nsDevice.GetMac ().SetAttribute ("ScanType", ns.core.EnumValue (ns.wifi.StaWifiMac.NOTSUPPORT))
self.stas.append(tb)
return tb
示例12: waitConnected
def waitConnected(self, timeout=None, delay=0.5):
"""wait for each switch to connect to a controller,
up to 5 seconds
timeout: time to wait, or None to wait indefinitely
delay: seconds to sleep per iteration
returns: True if all switches are connected"""
info("*** Waiting for switches to connect\n")
time = 0
remaining = list(self.switches)
while True:
for switch in tuple(remaining):
if switch.connected():
info("%s " % switch)
remaining.remove(switch)
if not remaining:
info("\n")
return True
if time > timeout and timeout is not None:
break
sleep(delay)
time += delay
warn("Timed out after %d seconds\n" % time)
for switch in remaining:
if not switch.connected():
warn("Warning: %s is not connected to a controller\n" % switch.name)
else:
remaining.remove(switch)
return not remaining
示例13: check_net_config
def check_net_config( self ):
"Check for any previous CMSnet configurations and adjust if necessary."
try:
with open(self.config_folder+"/cn.config_cmsnet", "r") as f:
config_raw = f.read()
config = {}
if config_raw:
config, l = defaultDecoder.raw_decode(config_raw)
for attr in config:
if attr.startswith("topo"): # Handle separately.
pass
elif attr == "net_cls":
cls = getattr(mininet.net, config[attr])
setattr(self, attr, cls)
elif attr.endswith("cls"):
cls = getattr(cmsnet.cms_comp, config[attr])
setattr(self, attr, cls)
elif isinstance(config[attr], basestring):
setattr(self, attr, str(config[attr]))
else:
setattr(self, attr, config[attr])
topo_cls_name = config.get("topo_cls")
if topo_cls_name:
topo_cls = getattr(cmsnet.cms_topo, topo_cls_name)
topo_opts = config.get("topo_opts", {})
topo = topo_cls(**topo_opts)
self.params.update({'topo': topo})
else:
warn("\nNo topology exists for CMSnet\n")
f.close()
except IOError as e:
info("\nNo config exists for CMSnet\n")
示例14: _run_pox_switch
def _run_pox_switch( self ):
if self.pox_pid is not None:
warn( "Killing old pox switch to restart new one." )
self._kill_pox_switch()
self._build_cmd_args()
self.cmd( self.command, printPid=True )
self.pox_pid = self.lastPid
print "MY POX PIDDDDDDDDDD: "+str(self.pox_pid)
self.started_switch = True
return
"Run the POX switch"
# @GLY
print "running !"
if self.pox_pid is not None:
print "poxid is not none"
warn( "Killing old pox switch to restart new one." )
self.lastPid = self.pox_pid
self._kill_pox_switch()
self.pox_pid = self.lastPid
else:
self.pox_pid = 1
print "yyyyyyyyyyyyyyyy"
self._build_cmd_args()
self.cmd( self.command, printPid=True )
self.started_switch = True
示例15: do_arp
def do_arp( self, line ):
"Send gratuitous arps from all data network hosts"
startTime = time.time()
try:
count = int( line )
except:
count = 1
# Technically this check should be on the host
if '-U' not in quietRun( 'arping -h', shell=True ):
warn( 'Please install iputils-arping.\n' )
return
# This is much faster if we do it in parallel
for host in self.mn.net.hosts:
intf = host.defaultIntf()
# -b: keep using broadcasts; -f: quit after 1 reply
# -U: gratuitous ARP update
host.sendCmd( 'arping -bf -c', count, '-U -I',
intf.name, intf.IP() )
for host in self.mn.net.hosts:
# We could check the output here if desired
host.waitOutput()
info( '.' )
info( '\n' )
elapsed = time.time() - startTime
debug( 'Completed in %.2f seconds\n' % elapsed )