<s> """<STR_LIT>""" <EOL> from mininet . node import Node , Host , OVSSwitch , Controller <EOL> from mininet . link import Link , Intf <EOL> from mininet . net import Mininet <EOL> from mininet . topo import LinearTopo <EOL> from mininet . topolib import TreeTopo <EOL> from mininet . util import quietRun , errRun <EOL> from mininet . examples . clustercli import CLI <EOL> from mininet . log import setLogLevel , debug , info , error <EOL> from mininet . clean import addCleanupCallback <EOL> from signal import signal , SIGINT , SIG_IGN <EOL> from subprocess import Popen , PIPE , STDOUT <EOL> import os <EOL> from random import randrange <EOL> import sys <EOL> import re <EOL> from itertools import groupby <EOL> from operator import attrgetter <EOL> from distutils . version import StrictVersion <EOL> def findUser ( ) : <EOL> "<STR_LIT>" <EOL> return ( <EOL> os . environ . get ( '<STR_LIT>' , False ) or <EOL> ( quietRun ( '<STR_LIT>' ) . split ( ) or [ False ] ) [ <NUM_LIT:0> ] or <EOL> quietRun ( '<STR_LIT>' ) . strip ( ) ) <EOL> class ClusterCleanup ( object ) : <EOL> "<STR_LIT>" <EOL> inited = False <EOL> serveruser = { } <EOL> @ classmethod <EOL> def add ( cls , server , user = '<STR_LIT>' ) : <EOL> "<STR_LIT>" <EOL> if not cls . inited : <EOL> addCleanupCallback ( cls . cleanup ) <EOL> if not user : <EOL> user = findUser ( ) <EOL> cls . serveruser [ server ] = user <EOL> @ classmethod <EOL> def cleanup ( cls ) : <EOL> "<STR_LIT>" <EOL> info ( '<STR_LIT>' ) <EOL> for server , user in cls . serveruser . iteritems ( ) : <EOL> if server == '<STR_LIT:localhost>' : <EOL> continue <EOL> else : <EOL> cmd = [ '<STR_LIT>' , user , '<STR_LIT:-c>' , <EOL> '<STR_LIT>' % ( user , server ) ] <EOL> info ( cmd , '<STR_LIT:\n>' ) <EOL> info ( quietRun ( cmd ) ) <EOL> class RemoteMixin ( object ) : <EOL> "<STR_LIT>" <EOL> sshbase = [ '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] <EOL> def __init__ ( self , name , server = '<STR_LIT:localhost>' , user = None , serverIP = None , <EOL> controlPath = False , splitInit = False , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> self . server = server if server else '<STR_LIT:localhost>' <EOL> self . serverIP = ( serverIP if serverIP <EOL> else self . findServerIP ( self . server ) ) <EOL> self . user = user if user else findUser ( ) <EOL> ClusterCleanup . add ( server = server , user = user ) <EOL> if controlPath is True : <EOL> controlPath = '<STR_LIT>' <EOL> self . controlPath = controlPath <EOL> self . splitInit = splitInit <EOL> if self . user and self . server != '<STR_LIT:localhost>' : <EOL> self . dest = '<STR_LIT>' % ( self . user , self . serverIP ) <EOL> self . sshcmd = [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , self . user ] + self . sshbase <EOL> if self . controlPath : <EOL> self . sshcmd += [ '<STR_LIT>' , '<STR_LIT>' + self . controlPath , <EOL> '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' + '<STR_LIT:1>' ] <EOL> self . sshcmd += [ self . dest ] <EOL> self . isRemote = True <EOL> else : <EOL> self . dest = None <EOL> self . sshcmd = [ ] <EOL> self . isRemote = False <EOL> self . shell , self . pid = None , None <EOL> super ( RemoteMixin , self ) . __init__ ( name , ** kwargs ) <EOL> _ipMatchRegex = re . compile ( r'<STR_LIT>' ) <EOL> @ classmethod <EOL> def findServerIP ( cls , server ) : <EOL> "<STR_LIT>" <EOL> ipmatch = cls . _ipMatchRegex . findall ( server ) <EOL> if ipmatch : <EOL> return ipmatch [ <NUM_LIT:0> ] <EOL> output = quietRun ( '<STR_LIT>' % server ) <EOL> ips = cls . _ipMatchRegex . findall ( output ) <EOL> ip = ips [ <NUM_LIT:0> ] if ips else None <EOL> return ip <EOL> def startShell ( self , * args , ** kwargs ) : <EOL> "<STR_LIT>" <EOL> if self . isRemote : <EOL> kwargs . update ( mnopts = '<STR_LIT:-c>' ) <EOL> super ( RemoteMixin , self ) . startShell ( * args , ** kwargs ) <EOL> self . sendCmd ( '<STR_LIT>' ) <EOL> if not self . splitInit : <EOL> self . finishInit ( ) <EOL> def finishInit ( self ) : <EOL> "<STR_LIT>" <EOL> self . pid = int ( self . waitOutput ( ) ) <EOL> def rpopen ( self , * cmd , ** opts ) : <EOL> "<STR_LIT>" <EOL> params = { '<STR_LIT>' : PIPE , <EOL> '<STR_LIT>' : PIPE , <EOL> '<STR_LIT>' : STDOUT , <EOL> '<STR_LIT>' : True } <EOL> params . update ( opts ) <EOL> return self . _popen ( * cmd , ** params ) <EOL> def rcmd ( self , * cmd , ** opts ) : <EOL> """<STR_LIT>""" <EOL> popen = self . rpopen ( * cmd , ** opts ) <EOL> result = '<STR_LIT>' <EOL> while True : <EOL> poll = popen . poll ( ) <EOL> result += popen . stdout . read ( ) <EOL> if poll is not None : <EOL> break <EOL> return result <EOL> @ staticmethod <EOL> def _ignoreSignal ( ) : <EOL> "<STR_LIT>" <EOL> os . setpgrp ( ) <EOL> def _popen ( self , cmd , sudo = True , tt = True , ** params ) : <EOL> """<STR_LIT>""" <EOL> if type ( cmd ) is str : <EOL> cmd = cmd . split ( ) <EOL> if self . isRemote : <EOL> if sudo : <EOL> cmd = [ '<STR_LIT>' , '<STR_LIT>' ] + cmd <EOL> if tt : <EOL> cmd = self . sshcmd + cmd <EOL> else : <EOL> sshcmd = list ( self . sshcmd ) <EOL> sshcmd . remove ( '<STR_LIT>' ) <EOL> cmd = sshcmd + cmd <EOL> else : <EOL> if self . user and not sudo : <EOL> cmd = [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , self . user ] + cmd <EOL> params . update ( preexec_fn = self . _ignoreSignal ) <EOL> debug ( '<STR_LIT>' , cmd , '<STR_LIT:\n>' ) <EOL> popen = super ( RemoteMixin , self ) . _popen ( cmd , ** params ) <EOL> return popen <EOL> def popen ( self , * args , ** kwargs ) : <EOL> "<STR_LIT>" <EOL> return super ( RemoteMixin , self ) . popen ( * args , tt = False , ** kwargs ) <EOL> def addIntf ( self , * args , ** kwargs ) : <EOL> "<STR_LIT>" <EOL> kwargs . update ( moveIntfFn = RemoteLink . moveIntf ) <EOL> return super ( RemoteMixin , self ) . addIntf ( * args , ** kwargs ) <EOL> class RemoteNode ( RemoteMixin , Node ) : <EOL> "<STR_LIT>" <EOL> pass <EOL> class RemoteHost ( RemoteNode ) : <EOL> "<STR_LIT>" <EOL> pass <EOL> class RemoteOVSSwitch ( RemoteMixin , OVSSwitch ) : <EOL> "<STR_LIT>" <EOL> OVSVersions = { } <EOL> def __init__ ( self , * args , ** kwargs ) : <EOL> kwargs . update ( batch = True ) <EOL> super ( RemoteOVSSwitch , self ) . __init__ ( * args , ** kwargs ) <EOL> def isOldOVS ( self ) : <EOL> "<STR_LIT>" <EOL> cls = type ( self ) <EOL> if self . server not in cls . OVSVersions : <EOL> vers = self . cmd ( '<STR_LIT>' ) <EOL> cls . OVSVersions [ self . server ] = re . findall ( <EOL> r'<STR_LIT>' , vers ) [ <NUM_LIT:0> ] <EOL> return ( StrictVersion ( cls . OVSVersions [ self . server ] ) < <EOL> StrictVersion ( '<STR_LIT>' ) ) <EOL> @ classmethod <EOL> def batchStartup ( cls , switches , ** _kwargs ) : <EOL> "<STR_LIT>" <EOL> key = attrgetter ( '<STR_LIT>' ) <EOL> for server , switchGroup in groupby ( sorted ( switches , key = key ) , key ) : <EOL> info ( '<STR_LIT>' % server ) <EOL> group = tuple ( switchGroup ) <EOL> switch = group [ <NUM_LIT:0> ] <EOL> OVSSwitch . batchStartup ( group , run = switch . cmd ) <EOL> return switches <EOL> @ classmethod <EOL> def batchShutdown ( cls , switches , ** _kwargs ) : <EOL> "<STR_LIT>" <EOL> key = attrgetter ( '<STR_LIT>' ) <EOL> for server , switchGroup in groupby ( sorted ( switches , key = key ) , key ) : <EOL> info ( '<STR_LIT>' % server ) <EOL> group = tuple ( switchGroup ) <EOL> switch = group [ <NUM_LIT:0> ] <EOL> OVSSwitch . batchShutdown ( group , run = switch . rcmd ) <EOL> return switches <EOL> class RemoteLink ( Link ) : <EOL> "<STR_LIT>" <EOL> def __init__ ( self , node1 , node2 , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> self . node1 = node1 <EOL> self . node2 = node2 <EOL> self . tunnel = None <EOL> kwargs . setdefault ( '<STR_LIT>' , { } ) <EOL> kwargs . setdefault ( '<STR_LIT>' , { } ) <EOL> self . cmd = None <EOL> Link . __init__ ( self , node1 , node2 , ** kwargs ) <EOL> def stop ( self ) : <EOL> "<STR_LIT>" <EOL> if self . tunnel : <EOL> self . tunnel . terminate ( ) <EOL> self . intf1 . delete ( ) <EOL> self . intf2 . delete ( ) <EOL> else : <EOL> Link . stop ( self ) <EOL> self . tunnel = None <EOL> def makeIntfPair ( self , intfname1 , intfname2 , addr1 = None , addr2 = None , <EOL> node1 = None , node2 = None , deleteIntfs = True ) : <EOL> """<STR_LIT>""" <EOL> node1 = self . node1 if node1 is None else node1 <EOL> node2 = self . node2 if node2 is None else node2 <EOL> server1 = getattr ( node1 , '<STR_LIT>' , '<STR_LIT:localhost>' ) <EOL> server2 = getattr ( node2 , '<STR_LIT>' , '<STR_LIT:localhost>' ) <EOL> if server1 == server2 : <EOL> return Link . makeIntfPair ( intfname1 , intfname2 , addr1 , addr2 , <EOL> node1 , node2 , deleteIntfs = deleteIntfs ) <EOL> self . tunnel = self . makeTunnel ( node1 , node2 , intfname1 , intfname2 , <EOL> addr1 , addr2 ) <EOL> return self . tunnel <EOL> @ staticmethod <EOL> def moveIntf ( intf , node , printError = True ) : <EOL> """<STR_LIT>""" <EOL> intf = str ( intf ) <EOL> cmd = '<STR_LIT>' % ( intf , node . pid ) <EOL> node . rcmd ( cmd ) <EOL> links = node . cmd ( '<STR_LIT>' ) <EOL> if not '<STR_LIT>' % intf in links : <EOL> if printError : <EOL> error ( '<STR_LIT>' + intf + <EOL> '<STR_LIT>' + node . name + '<STR_LIT:\n>' ) <EOL> return False <EOL> return True <EOL> def makeTunnel ( self , node1 , node2 , intfname1 , intfname2 , <EOL> addr1 = None , addr2 = None ) : <EOL> "<STR_LIT>" <EOL> assert node1 . server != '<STR_LIT:localhost>' or node2 . server != '<STR_LIT:localhost>' <EOL> if node2 . server == '<STR_LIT:localhost>' : <EOL> return self . makeTunnel ( node2 , node1 , intfname2 , intfname1 , <EOL> addr2 , addr1 ) <EOL> for node in node1 , node2 : <EOL> cmd = '<STR_LIT>' + node . user <EOL> result = node . rcmd ( cmd ) <EOL> if result : <EOL> raise Exception ( '<STR_LIT>' % <EOL> ( node , result ) ) <EOL> dest = '<STR_LIT>' % ( node2 . user , node2 . serverIP ) <EOL> cmd = [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> dest , '<STR_LIT>' ] <EOL> self . cmd = cmd <EOL> tunnel = node1 . rpopen ( cmd , sudo = False ) <EOL> debug ( '<STR_LIT>' ) <EOL> ch = tunnel . stdout . read ( <NUM_LIT:1> ) <EOL> if ch != '<STR_LIT:@>' : <EOL> raise Exception ( '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' % ( node1 , node1 . dest ) , '<STR_LIT:to>' , <EOL> '<STR_LIT>' % ( node2 , node2 . dest ) , <EOL> '<STR_LIT>' , cmd , '<STR_LIT:\n>' ) <EOL> for node in node1 , node2 : <EOL> if not self . moveIntf ( '<STR_LIT>' , node ) : <EOL> raise Exception ( '<STR_LIT>' % node ) <EOL> for node , intf , addr in ( ( node1 , intfname1 , addr1 ) , <EOL> ( node2 , intfname2 , addr2 ) ) : <EOL> if not addr : <EOL> result = node . cmd ( '<STR_LIT>' , intf ) <EOL> else : <EOL> result = node . cmd ( '<STR_LIT>' , intf , <EOL> '<STR_LIT:address>' , addr ) <EOL> if result : <EOL> raise Exception ( '<STR_LIT>' % ( intf , result ) ) <EOL> return tunnel <EOL> def status ( self ) : <EOL> "<STR_LIT>" <EOL> if self . tunnel : <EOL> if self . tunnel . poll ( ) is not None : <EOL> status = "<STR_LIT>" % self . tunnel . returncode <EOL> else : <EOL> status = "<STR_LIT>" % ( <EOL> self . tunnel . pid , self . cmd ) <EOL> else : <EOL> status = "<STR_LIT:OK>" <EOL> result = "<STR_LIT>" % ( Link . status ( self ) , status ) <EOL> return result <EOL> class Placer ( object ) : <EOL> "<STR_LIT>" <EOL> def __init__ ( self , servers = None , nodes = None , hosts = None , <EOL> switches = None , controllers = None , links = None ) : <EOL> """<STR_LIT>""" <EOL> self . servers = servers or [ ] <EOL> self . nodes = nodes or [ ] <EOL> self . hosts = hosts or [ ] <EOL> self . switches = switches or [ ] <EOL> self . controllers = controllers or [ ] <EOL> self . links = links or [ ] <EOL> def place ( self , node ) : <EOL> "<STR_LIT>" <EOL> assert self , node <EOL> return '<STR_LIT:localhost>' <EOL> class RandomPlacer ( Placer ) : <EOL> "<STR_LIT>" <EOL> def place ( self , nodename ) : <EOL> """<STR_LIT>""" <EOL> assert nodename <EOL> return self . servers [ randrange ( <NUM_LIT:0> , len ( self . servers ) ) ] <EOL> class RoundRobinPlacer ( Placer ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , * args , ** kwargs ) : <EOL> Placer . __init__ ( self , * args , ** kwargs ) <EOL> self . next = <NUM_LIT:0> <EOL> def place ( self , nodename ) : <EOL> """<STR_LIT>""" <EOL> assert nodename <EOL> server = self . servers [ self . next ] <EOL> self . next = ( self . next + <NUM_LIT:1> ) % len ( self . servers ) <EOL> return server <EOL> class SwitchBinPlacer ( Placer ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , * args , ** kwargs ) : <EOL> Placer . __init__ ( self , * args , ** kwargs ) <EOL> self . servdict = dict ( enumerate ( self . servers ) ) <EOL> self . hset = frozenset ( self . hosts ) <EOL> self . sset = frozenset ( self . switches ) <EOL> self . cset = frozenset ( self . controllers ) <EOL> self . placement = self . calculatePlacement ( ) <EOL> @ staticmethod <EOL> def bin ( nodes , servers ) : <EOL> "<STR_LIT>" <EOL> nlen = len ( nodes ) <EOL> slen = len ( servers ) <EOL> quotient = int ( nlen / slen ) <EOL> binsizes = { server : quotient for server in servers } <EOL> remainder = nlen % slen <EOL> for server in servers [ <NUM_LIT:0> : remainder ] : <EOL> binsizes [ server ] += <NUM_LIT:1> <EOL> tickets = sum ( [ binsizes [ server ] * [ server ] <EOL> for server in servers ] , [ ] ) <EOL> return { node : ticket for node , ticket in zip ( nodes , tickets ) } <EOL> def calculatePlacement ( self ) : <EOL> "<STR_LIT>" <EOL> placement = { } <EOL> switchFor = { } <EOL> for src , dst in self . links : <EOL> if src in self . hset and dst in self . sset : <EOL> switchFor [ src ] = dst <EOL> if dst in self . hset and src in self . sset : <EOL> switchFor [ dst ] = src <EOL> placement = self . bin ( self . switches , self . servers ) <EOL> placement . update ( self . bin ( self . controllers , self . servers ) ) <EOL> for h in self . hosts : <EOL> if h in placement : <EOL> continue <EOL> if h in switchFor : <EOL> placement [ h ] = placement [ switchFor [ h ] ] <EOL> else : <EOL> raise Exception ( <EOL> "<STR_LIT>" + h ) <EOL> return placement <EOL> def place ( self , node ) : <EOL> """<STR_LIT>""" <EOL> return self . placement [ node ] <EOL> class HostSwitchBinPlacer ( Placer ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , * args , ** kwargs ) : <EOL> Placer . __init__ ( self , * args , ** kwargs ) <EOL> scount = len ( self . servers ) <EOL> self . hbin = max ( int ( len ( self . hosts ) / scount ) , <NUM_LIT:1> ) <EOL> self . sbin = max ( int ( len ( self . switches ) / scount ) , <NUM_LIT:1> ) <EOL> self . cbin = max ( int ( len ( self . controllers ) / scount ) , <NUM_LIT:1> ) <EOL> info ( '<STR_LIT>' , scount ) <EOL> info ( '<STR_LIT>' , self . hbin , self . sbin , self . cbin , '<STR_LIT:\n>' ) <EOL> self . servdict = dict ( enumerate ( self . servers ) ) <EOL> self . hset = frozenset ( self . hosts ) <EOL> self . sset = frozenset ( self . switches ) <EOL> self . cset = frozenset ( self . controllers ) <EOL> self . hind , self . sind , self . cind = <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> <EOL> def place ( self , nodename ) : <EOL> """<STR_LIT>""" <EOL> if nodename in self . hset : <EOL> server = self . servdict [ self . hind / self . hbin ] <EOL> self . hind += <NUM_LIT:1> <EOL> elif nodename in self . sset : <EOL> server = self . servdict [ self . sind / self . sbin ] <EOL> self . sind += <NUM_LIT:1> <EOL> elif nodename in self . cset : <EOL> server = self . servdict [ self . cind / self . cbin ] <EOL> self . cind += <NUM_LIT:1> <EOL> else : <EOL> info ( '<STR_LIT>' , nodename ) <EOL> server = self . servdict [ <NUM_LIT:0> ] <EOL> return server <EOL> class MininetCluster ( Mininet ) : <EOL> "<STR_LIT>" <EOL> sshcmd = [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] <EOL> def __init__ ( self , * args , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> params = { '<STR_LIT:host>' : RemoteHost , <EOL> '<STR_LIT>' : RemoteOVSSwitch , <EOL> '<STR_LIT>' : RemoteLink , <EOL> '<STR_LIT>' : True } <EOL> params . update ( kwargs ) <EOL> servers = params . pop ( '<STR_LIT>' , [ '<STR_LIT:localhost>' ] ) <EOL> servers = [ s if s else '<STR_LIT:localhost>' for s in servers ] <EOL> self . servers = servers <EOL> self . serverIP = params . pop ( '<STR_LIT>' , { } ) <EOL> if not self . serverIP : <EOL> self . serverIP = { server : RemoteMixin . findServerIP ( server ) <EOL> for server in self . servers } <EOL> self . user = params . pop ( '<STR_LIT:user>' , findUser ( ) ) <EOL> if params . pop ( '<STR_LIT>' ) : <EOL> self . precheck ( ) <EOL> self . connections = { } <EOL> self . placement = params . pop ( '<STR_LIT>' , SwitchBinPlacer ) <EOL> self . cdir = os . environ [ '<STR_LIT>' ] + '<STR_LIT>' <EOL> errRun ( [ '<STR_LIT>' , '<STR_LIT>' , self . cdir ] ) <EOL> Mininet . __init__ ( self , * args , ** params ) <EOL> def popen ( self , cmd ) : <EOL> "<STR_LIT>" <EOL> assert self <EOL> old = signal ( SIGINT , SIG_IGN ) <EOL> conn = Popen ( cmd , stdin = PIPE , stdout = PIPE , close_fds = True ) <EOL> signal ( SIGINT , old ) <EOL> return conn <EOL> def baddLink ( self , * args , ** kwargs ) : <EOL> "<STR_LIT>" <EOL> pass <EOL> def precheck ( self ) : <EOL> """<STR_LIT>""" <EOL> result = <NUM_LIT:0> <EOL> info ( '<STR_LIT>' ) <EOL> for server in self . servers : <EOL> ip = self . serverIP [ server ] <EOL> if not server or server == '<STR_LIT:localhost>' : <EOL> continue <EOL> info ( server , '<STR_LIT>' ) <EOL> dest = '<STR_LIT>' % ( self . user , ip ) <EOL> cmd = [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , self . user ] <EOL> cmd += self . sshcmd + [ '<STR_LIT>' , dest , '<STR_LIT>' ] <EOL> debug ( '<STR_LIT:U+0020>' . join ( cmd ) , '<STR_LIT:\n>' ) <EOL> _out , _err , code = errRun ( cmd ) <EOL> if code != <NUM_LIT:0> : <EOL> error ( '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> % ( server , '<STR_LIT:U+0020>' . join ( cmd ) ) ) <EOL> result |= code <EOL> if result : <EOL> error ( '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> sys . exit ( <NUM_LIT:1> ) <EOL> info ( '<STR_LIT:\n>' ) <EOL> def modifiedaddHost ( self , * args , ** kwargs ) : <EOL> "<STR_LIT>" <EOL> assert self <EOL> kwargs [ '<STR_LIT>' ] = True <EOL> return Mininet . addHost ( * args , ** kwargs ) <EOL> def placeNodes ( self ) : <EOL> """<STR_LIT>""" <EOL> if not self . servers or not self . topo : <EOL> return <EOL> nodes = self . topo . nodes ( ) <EOL> placer = self . placement ( servers = self . servers , <EOL> nodes = self . topo . nodes ( ) , <EOL> hosts = self . topo . hosts ( ) , <EOL> switches = self . topo . switches ( ) , <EOL> links = self . topo . links ( ) ) <EOL> for node in nodes : <EOL> config = self . topo . nodeInfo ( node ) <EOL> if '<STR_LIT>' in config . keys ( ) and config [ '<STR_LIT>' ] is None : <EOL> config [ '<STR_LIT>' ] = '<STR_LIT:localhost>' <EOL> server = config . setdefault ( '<STR_LIT>' , placer . place ( node ) ) <EOL> if server : <EOL> config . setdefault ( '<STR_LIT>' , self . serverIP [ server ] ) <EOL> info ( '<STR_LIT>' % ( node , server ) ) <EOL> key = ( None , server ) <EOL> _dest , cfile , _conn = self . connections . get ( <EOL> key , ( None , None , None ) ) <EOL> if cfile : <EOL> config . setdefault ( '<STR_LIT>' , cfile ) <EOL> def addController ( self , * args , ** kwargs ) : <EOL> "<STR_LIT>" <EOL> controller = Mininet . addController ( self , * args , ** kwargs ) <EOL> if ( isinstance ( controller , Controller ) <EOL> and controller . IP ( ) == '<STR_LIT:127.0.0.1>' <EOL> and '<STR_LIT>' in controller . cmd ( '<STR_LIT>' ) ) : <EOL> Intf ( '<STR_LIT>' , node = controller ) . updateIP ( ) <EOL> return controller <EOL> def buildFromTopo ( self , * args , ** kwargs ) : <EOL> "<STR_LIT>" <EOL> info ( '<STR_LIT>' ) <EOL> self . placeNodes ( ) <EOL> info ( '<STR_LIT:\n>' ) <EOL> Mininet . buildFromTopo ( self , * args , ** kwargs ) <EOL> def testNsTunnels ( ) : <EOL> "<STR_LIT>" <EOL> net = Mininet ( host = RemoteHost , link = RemoteLink ) <EOL> h1 = net . addHost ( '<STR_LIT>' ) <EOL> h2 = net . addHost ( '<STR_LIT>' , server = '<STR_LIT>' ) <EOL> net . addLink ( h1 , h2 ) <EOL> net . start ( ) <EOL> net . pingAll ( ) <EOL> net . stop ( ) <EOL> def testRemoteNet ( remote = '<STR_LIT>' ) : <EOL> "<STR_LIT>" <EOL> print '<STR_LIT>' <EOL> net = Mininet ( host = RemoteHost , switch = RemoteOVSSwitch , <EOL> link = RemoteLink ) <EOL> c0 = net . addController ( '<STR_LIT>' ) <EOL> Intf ( '<STR_LIT>' , node = c0 ) . updateIP ( ) <EOL> print "<STR_LIT>" <EOL> h1 = net . addHost ( '<STR_LIT>' ) <EOL> print "<STR_LIT>" <EOL> h2 = net . addHost ( '<STR_LIT>' , server = remote ) <EOL> print "<STR_LIT>" <EOL> s1 = net . addSwitch ( '<STR_LIT>' ) <EOL> print "<STR_LIT>" <EOL> s2 = net . addSwitch ( '<STR_LIT>' , server = remote ) <EOL> print "<STR_LIT>" <EOL> net . addLink ( h1 , s1 ) <EOL> net . addLink ( s1 , s2 ) <EOL> net . addLink ( h2 , s2 ) <EOL> net . start ( ) <EOL> print '<STR_LIT>' , quietRun ( '<STR_LIT>' ) . strip ( ) <EOL> for node in c0 , h1 , h2 , s1 , s2 : <EOL> print '<STR_LIT>' , node , '<STR_LIT>' , node . cmd ( '<STR_LIT>' ) . strip ( ) <EOL> net . pingAll ( ) <EOL> CLI ( net ) <EOL> net . stop ( ) <EOL> remoteHosts = [ '<STR_LIT>' ] <EOL> remoteSwitches = [ '<STR_LIT>' ] <EOL> remoteServer = '<STR_LIT>' <EOL> def HostPlacer ( name , * args , ** params ) : <EOL> "<STR_LIT>" <EOL> if name in remoteHosts : <EOL> return RemoteHost ( name , * args , server = remoteServer , ** params ) <EOL> else : <EOL> return Host ( name , * args , ** params ) <EOL> def SwitchPlacer ( name , * args , ** params ) : <EOL> "<STR_LIT>" <EOL> if name in remoteSwitches : <EOL> return RemoteOVSSwitch ( name , * args , server = remoteServer , ** params ) <EOL> else : <EOL> return RemoteOVSSwitch ( name , * args , ** params ) <EOL> def ClusterController ( * args , ** kwargs ) : <EOL> "<STR_LIT>" <EOL> controller = Controller ( * args , ** kwargs ) <EOL> Intf ( '<STR_LIT>' , node = controller ) . updateIP ( ) <EOL> return controller <EOL> def testRemoteTopo ( ) : <EOL> "<STR_LIT>" <EOL> topo = LinearTopo ( <NUM_LIT:2> ) <EOL> net = Mininet ( topo = topo , host = HostPlacer , switch = SwitchPlacer , <EOL> link = RemoteLink , controller = ClusterController ) <EOL> net . start ( ) <EOL> net . pingAll ( ) <EOL> net . stop ( ) <EOL> def testRemoteSwitches ( ) : <EOL> "<STR_LIT>" <EOL> servers = [ '<STR_LIT:localhost>' , '<STR_LIT>' ] <EOL> topo = TreeTopo ( depth = <NUM_LIT:4> , fanout = <NUM_LIT:2> ) <EOL> net = MininetCluster ( topo = topo , servers = servers , <EOL> placement = RoundRobinPlacer ) <EOL> net . start ( ) <EOL> net . pingAll ( ) <EOL> net . stop ( ) <EOL> def testMininetCluster ( ) : <EOL> "<STR_LIT>" <EOL> servers = [ '<STR_LIT:localhost>' , '<STR_LIT>' ] <EOL> topo = TreeTopo ( depth = <NUM_LIT:3> , fanout = <NUM_LIT:3> ) <EOL> net = MininetCluster ( topo = topo , servers = servers , <EOL> placement = SwitchBinPlacer ) <EOL> net . start ( ) <EOL> net . pingAll ( ) <EOL> net . stop ( ) <EOL> def signalTest ( ) : <EOL> "<STR_LIT>" <EOL> h = RemoteHost ( '<STR_LIT>' , server = '<STR_LIT>' ) <EOL> h . shell . send_signal ( SIGINT ) <EOL> h . shell . poll ( ) <EOL> if h . shell . returncode is None : <EOL> print '<STR_LIT>' , h , '<STR_LIT>' <EOL> else : <EOL> print '<STR_LIT>' , h , '<STR_LIT>' , h . shell . returncode <EOL> h . stop ( ) <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> setLogLevel ( '<STR_LIT:info>' ) <EOL> signalTest ( ) </s>
