def stop( self ): "Stop the controller(s), switches and hosts" info( '*** Stopping %i controllers\n' % len( self.controllers ) ) for controller in self.controllers: info( controller.name + ' ' ) controller.stop() info( '\n' ) if self.terms: info( '*** Stopping %i terms\n' % len( self.terms ) ) self.stopXterms() info( '*** Stopping %i links\n' % len( self.links ) ) for link in self.links: info( '.' ) link.stop() info( '\n' ) if(self.isWireless): info( '*** Stopping %i baseStations\n' % len( self.baseStations ) ) stopped = {} for n in range(len(self.wirelessdeviceControl)): if (str(self.wirelessdeviceControl[n]) in self.baseStationName ): os.system("ifconfig wlan%s down" % str(n+1)) for swclass, baseStations in groupby( sorted( self.baseStations, key=type ), type ): baseStations = tuple( baseStations ) if hasattr( swclass, 'batchShutdown' ): success = swclass.batchShutdown( baseStations ) stopped.update( { s: s for s in success } ) for baseStation in self.baseStations: info( baseStation.name + ' ' ) if baseStation not in stopped: baseStation.stop() baseStation.terminate() info( '\n' ) info( '*** Stopping %i hosts\n' % len( self.hosts ) ) for host in self.hosts: for n in range(len(self.wirelessdeviceControl)): if(str(self.wirelessdeviceControl[n])==host.name): self.host.cmd(host, "ifconfig %s-wlan0 down" % (str(self.wirelessdeviceControl[n]))) self.host.cmd(host, "ip link set dev %s-wlan0 name wlan%s" % (str(self.wirelessdeviceControl[n]), str(n+1))) info( host.name + ' ' ) host.terminate() info( '\n' ) else: info( '*** Stopping %i switches\n' % len( self.switches ) ) stopped = {} for swclass, switches in groupby( sorted( self.switches, key=type ), type ): switches = tuple( switches ) if hasattr( swclass, 'batchShutdown' ): success = swclass.batchShutdown( switches ) stopped.update( { s: s for s in success } ) for switch in self.switches: info( switch.name + ' ' ) if switch not in stopped: switch.stop() switch.terminate() info( '\n' ) info( '*** Stopping %i hosts\n' % len( self.hosts ) ) for host in self.hosts: info( host.name + ' ' ) host.terminate() info( '\n' ) module(0, False) #Stopping WiFi Module info( '\n*** Done\n' )
def stop(self): "Stop the controller(s), switches and hosts" info('*** Stopping %i controllers\n' % len(self.controllers)) for controller in self.controllers: info(controller.name + ' ') controller.stop() info('\n') if self.terms: info('*** Stopping %i terms\n' % len(self.terms)) self.stopXterms() info('*** Stopping %i links\n' % len(self.links)) for link in self.links: info('.') link.stop() info('\n') if (self.isWireless): info('*** Stopping %i baseStations\n' % len(self.baseStations)) stopped = {} for n in range(len(self.wirelessdeviceControl)): if (str(self.wirelessdeviceControl[n]) in self.baseStationName): os.system("ifconfig wlan%s down" % str(n + 1)) for swclass, baseStations in groupby( sorted(self.baseStations, key=type), type): baseStations = tuple(baseStations) if hasattr(swclass, 'batchShutdown'): success = swclass.batchShutdown(baseStations) stopped.update({s: s for s in success}) for baseStation in self.baseStations: info(baseStation.name + ' ') if baseStation not in stopped: baseStation.stop() baseStation.terminate() info('\n') info('*** Stopping %i hosts\n' % len(self.hosts)) for host in self.hosts: for n in range(len(self.wirelessdeviceControl)): if (str(self.wirelessdeviceControl[n]) == host.name): self.host.cmd( host, "ifconfig %s-wlan0 down" % (str(self.wirelessdeviceControl[n]))) self.host.cmd( host, "ip link set dev %s-wlan0 name wlan%s" % (str(self.wirelessdeviceControl[n]), str(n + 1))) info(host.name + ' ') host.terminate() info('\n') else: info('*** Stopping %i switches\n' % len(self.switches)) stopped = {} for swclass, switches in groupby(sorted(self.switches, key=type), type): switches = tuple(switches) if hasattr(swclass, 'batchShutdown'): success = swclass.batchShutdown(switches) stopped.update({s: s for s in success}) for switch in self.switches: info(switch.name + ' ') if switch not in stopped: switch.stop() switch.terminate() info('\n') info('*** Stopping %i hosts\n' % len(self.hosts)) for host in self.hosts: info(host.name + ' ') host.terminate() info('\n') module(0, False) #Stopping WiFi Module info('\n*** Done\n')
def __init__( self, topo=None, switch=OVSKernelSwitch, host=Host, controller=DefaultController, link=Link, intf=Intf, build=True, xterms=False, cleanup=False, ipBase='10.0.0.0/8', inNamespace=False, autoSetMacs=False, autoStaticArp=False, autoPinCpus=False, listenPort=None, waitConnected=False, interfaceID=3, ssid="my_ssid", mode="g", channel="1", wirelessRadios=0): """Create Mininet object. topo: Topo (topology) object or None switch: default Switch class host: default Host class/constructor controller: default Controller class/constructor link: default Link class/constructor intf: default Intf class/constructor ipBase: base IP address for hosts, build: build now from topo? xterms: if build now, spawn xterms? cleanup: if build now, cleanup before creating? inNamespace: spawn switches and controller in net namespaces? autoSetMacs: set MAC addrs automatically like IP addresses? autoStaticArp: set all-pairs static MAC addrs? autoPinCpus: pin hosts to (real) cores (requires CPULimitedHost)? listenPort: base listening port to open; will be incremented for each additional switch in the net if inNamespace=False""" self.topo = topo self.switch = switch self.baseStation = switch self.host = host self.controller = controller self.link = link self.intf = intf self.ipBase = ipBase self.ipBaseNum, self.prefixLen = netParse( self.ipBase ) self.nextIP = 1 # start for address allocation self.inNamespace = inNamespace self.xterms = xterms self.cleanup = cleanup self.autoSetMacs = autoSetMacs self.autoStaticArp = autoStaticArp self.autoPinCpus = autoPinCpus self.numCores = numCores() self.nextCore = 0 # next core for pinning hosts to CPUs self.listenPort = listenPort self.waitConn = waitConnected self.wirelessdeviceControl = [] self.wirelessifaceControl = [] self.nextIface = 1 self.baseStationName = [] self.stationName = [] self.interfaceID = interfaceID self.ssid = ssid self.mode = mode self.channel = channel self.wirelessRadios = wirelessRadios self.isWireless = Node.isWireless self.hosts = [] self.switches = [] self.baseStations = [] self.controllers = [] self.links = [] self.nameToNode = {} # name to Node (Host/Switch) objects self.terms = [] # list of spawned xterm processes Mininet.init() # Initialize Mininet if necessary if (Node.isWireless==True or self.wirelessRadios!=0): Node.isWireless=True module(self.wirelessRadios, Node.isWireless) #Initatilize WiFi Module self.built = False if topo and build: self.build()
def __init__(self, topo=None, switch=OVSKernelSwitch, host=Host, controller=DefaultController, link=Link, intf=Intf, build=True, xterms=False, cleanup=False, ipBase='10.0.0.0/8', inNamespace=False, autoSetMacs=False, autoStaticArp=False, autoPinCpus=False, listenPort=None, waitConnected=False, interfaceID=3, ssid="my_ssid", mode="g", channel="1", wirelessRadios=0): """Create Mininet object. topo: Topo (topology) object or None switch: default Switch class host: default Host class/constructor controller: default Controller class/constructor link: default Link class/constructor intf: default Intf class/constructor ipBase: base IP address for hosts, build: build now from topo? xterms: if build now, spawn xterms? cleanup: if build now, cleanup before creating? inNamespace: spawn switches and controller in net namespaces? autoSetMacs: set MAC addrs automatically like IP addresses? autoStaticArp: set all-pairs static MAC addrs? autoPinCpus: pin hosts to (real) cores (requires CPULimitedHost)? listenPort: base listening port to open; will be incremented for each additional switch in the net if inNamespace=False""" self.topo = topo self.switch = switch self.baseStation = switch self.host = host self.controller = controller self.link = link self.intf = intf self.ipBase = ipBase self.ipBaseNum, self.prefixLen = netParse(self.ipBase) self.nextIP = 1 # start for address allocation self.inNamespace = inNamespace self.xterms = xterms self.cleanup = cleanup self.autoSetMacs = autoSetMacs self.autoStaticArp = autoStaticArp self.autoPinCpus = autoPinCpus self.numCores = numCores() self.nextCore = 0 # next core for pinning hosts to CPUs self.listenPort = listenPort self.waitConn = waitConnected self.wirelessdeviceControl = [] self.wirelessifaceControl = [] self.nextIface = 1 self.baseStationName = [] self.stationName = [] self.interfaceID = interfaceID self.ssid = ssid self.mode = mode self.channel = channel self.wirelessRadios = wirelessRadios self.isWireless = Node.isWireless self.hosts = [] self.switches = [] self.baseStations = [] self.controllers = [] self.links = [] self.nameToNode = {} # name to Node (Host/Switch) objects self.terms = [] # list of spawned xterm processes Mininet.init() # Initialize Mininet if necessary if (Node.isWireless == True or self.wirelessRadios != 0): Node.isWireless = True module(self.wirelessRadios, Node.isWireless) #Initatilize WiFi Module self.built = False if topo and build: self.build()