8000 mininet/mininet/util.py at patches/fixsetup · ifa6/mininet · GitHub
[go: up one dir, main page]

Skip to content

Latest commit

 

History

History
209 lines (179 loc) · 6.29 KB

util.py

File metadata and controls

209 lines (179 loc) · 6.29 KB
returns: ip address string w.x.y.z, or 10.x.y.z if w==0"""
w = ( ip & 0xff000000 ) >> 24
w = 10 if w == 0 else w
x = ( ip & 0xff0000 ) >> 16
y = ( ip & 0xff00 ) >> 8
z = ip & 0xff
return "%i.%i.%i.%i" % ( w, x, y, z )
def ipNum( w, x, y, z ):
"""Generate unsigned int from components ofIP address
returns: w << 24 | x << 16 | y << 8 | z"""
return ( w << 24 ) | ( x << 16 ) | ( y << 8 ) | z
def ipParse( ip ):
"Parse an IP address and return an unsigned int."
args = [ int( arg ) for arg in ip.split( '.' ) ]
return ipNum( *args )
def checkInt( s ):
"Check if input string is an int"
try:
int( s )
return True
except ValueError:
return False
def checkFloat( s ):
"Check if input string is a float"
try:
float( s )
return True
except ValueError:
return False
def makeNumeric( s ):
"Convert string to int or float if numeric."
if checkInt( s ):
return int( s )
elif checkFloat( s ):
return float( s )
else:
return s
# Other stuff we use
def fixLimits():
"Fix ridiculously small resource limits."
setrlimit( RLIMIT_NPROC, ( 4096, 8192 ) )
setrlimit( RLIMIT_NOFILE, ( 16384, 32768 ) )
0