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:
Brandon Heller
2010-03-04 21:29:32 -08:00
parent 1a40cd0477
commit bb941950d5
2 changed files with 54 additions and 8 deletions
+25
View File
@@ -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