Add flexible topology input parsing
Now you can pass a topology name followed by params. For example, to create a switch with 3 hosts: sudo mn --topo single,3
This commit is contained in:
@@ -153,3 +153,28 @@ 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
|
||||
Reference in New Issue
Block a user