Fixed MininetFacade and moved main logic into run. First shot at "test" function

This commit is contained in:
Brian O'Connor
2013-09-11 12:00:13 -07:00
committed by Brian O'Connor
parent dc882d6905
commit 7c962d2f61
+28 -11
View File
@@ -30,18 +30,24 @@ class DataController( Controller ):
"Ignore spurious error" "Ignore spurious error"
pass pass
class MininetFacade( object ):
class MininetFacade:
"TODO: CLI that can talk to two or more networks" "TODO: CLI that can talk to two or more networks"
def __init__( self, *args ): def __init__( self, net, *args, **kwargs ):
self.nets = args self.net = net
self.nets = [ net ] + list( args ) + kwargs.values()
self.nameToNet = kwargs
self.nameToNet['net'] = net
# default is first net # default is first net
def __getattr__( self, name ): def __getattr__( self, name ):
return getattr( self.nets[ 0 ], name ) return getattr( self.net, name )
def __getitem__( self, key ): def __getitem__( self, key ):
#search kwargs for net named key
if key in self.nameToNet:
return self.nameToNet[ key ]
#search each net for node named key
for net in self.nets: for net in self.nets:
if key in net: if key in net:
return net[ key ] return net[ key ]
@@ -91,9 +97,7 @@ class ControlNetwork( Topo ):
# Make it Happen!! # Make it Happen!!
def run( func=CLI ):
setLogLevel( 'info' )
info( '* Creating Control Network\n' ) info( '* Creating Control Network\n' )
ctopo = ControlNetwork( n=4, dataController=DataController ) ctopo = ControlNetwork( n=4, dataController=DataController )
cnet = Mininet( topo=ctopo, ipBase='192.168.123.0/24', controller=None ) cnet = Mininet( topo=ctopo, ipBase='192.168.123.0/24', controller=None )
@@ -113,8 +117,10 @@ for host in cnet.hosts:
info( '* Starting Data Network\n') info( '* Starting Data Network\n')
net.start() net.start()
mn = MininetFacade( net, cnet ) mn = MininetFacade( net, cnet=cnet )
CLI( mn )
# run the function passed as an argument
func( mn )
info( '* Stopping Data Network\n' ) info( '* Stopping Data Network\n' )
net.stop() net.stop()
@@ -124,8 +130,19 @@ info( '* Stopping Control Network\n' )
#cnet.hosts = list( set( cnet.hosts ) - set( dataControllers ) ) #cnet.hosts = list( set( cnet.hosts ) - set( dataControllers ) )
cnet.stop() cnet.stop()
def test( net ):
netLoss = net.pingAll()
cnetLoss = net['cnet'].pingAll()
if __name__ == '__main__':
setLogLevel( 'info' )
import argparse
parser = argparse.ArgumentParser(description='TODO:description')
parser.add_argument('--test', dest='func', action='store_const',
const=test, default=CLI,
help='TODO: test help')
args = parser.parse_args()
run( func=args.func )