def __init__( self, of_version='14', autoarp=False, enable_varanus=True, verbosity='info' ): """ Construct a new MininetRunner with specific arguments. - of_version : The OpenFlow version to use (default is 14) - autoarp : If true, each host will be automatically configured with ARP entries for every other host - enable_varanus: If true, VARANUS SDN controllers and collectors will be enabled - verbosity : The level of verbosity """ self.of_version = 'OpenFlow' + some( of_version ) setLogLevel( some( verbosity ) ) self.enable_varanus = as_bool( enable_varanus, name='enable_varanus' ) self.cli = CLIConfig() self.controllers = {} self.hosts = {} self.switches = {} self.links = [] self.built = False self.started = False self.net = Mininet( build=False, \ autoStaticArp=as_bool( autoarp, name='autoarp' ), \ controller=NullController ) self._preconfig()
def _build_base( self, net, startcmd, stopcmd, morecmds=None, \ have_mininet=None, hidden=False, **params ): params['have_mininet'] = as_bool(have_mininet, name='have_mininet') hidden = as_bool(hidden, name='hidden') params['cls'] = CustomRemoteHiddenHost if hidden else CustomRemoteHost return self._build_host( net, startcmd, stopcmd, morecmds=morecmds, \ **params )
def _build_base(self, net, have_mininet=None, managed=True, hidden=False, **params): params['have_mininet'] = as_bool(have_mininet, name='have_mininet') managed = as_bool(managed, name='managed') hidden = as_bool(hidden, name='hidden') if managed: params['cls'] = RemoteHiddenHost if hidden else RemoteHost else: params[ 'cls'] = RemoteUnmanagedHiddenHost if hidden else RemoteUnmanagedHost return self._build_host(net, **params)
def _build_base( self, net, startcmd, stopcmd, morecmds=None, hidden=False, \ **params ): hidden = as_bool(hidden, name='hidden') params['cls'] = CustomLocalHiddenHost if hidden else CustomLocalHost return self._build_host( net, startcmd, stopcmd, morecmds=morecmds, \ **params )
def _build_host( self, net, startcmd, stopcmd, morecmds=None, inNamespace=None, \ **params ): # Do not configure by default any IP or MAC params['ip'] = None params['mac'] = None params['inNamespace'] = as_bool(inNamespace, name='inNamespace') return net.addHost( self.name, startcmd=startcmd, stopcmd=stopcmd, \ morecmds=morecmds, **params )
def as_node( mn, node, unpack_special=False ): node = some( node, name='node' ) unpack_special = as_bool( unpack_special, name='unpack_special' ) if isinstance( node, SpecialNode ): return node.node if unpack_special else node elif isinstance( node, Node ): return NodeUtils.check_valid_node( mn, node ) else: name = NodeUtils.check_valid_name( mn, str( node ) ) return mn[name]
def __init__(self, *args, **kwargs): """ In kwargs: - user : ssh session user name - server : ssh remote server hostname/address - inNamespace : boolean indicating if in network namespace (must only be True when have_mininet is also True) - have_mininet: boolean indicating if the remote node has Mininet """ user = some(kwargs['user'], name='user') server = some(kwargs['server'], name='server') inNamespace = as_bool(kwargs['inNamespace'], name='inNamespace') have_mininet = as_bool(kwargs['have_mininet'], name='have_mininet') if inNamespace and not have_mininet: raise ValueError( 'remote node must have Mininet in order to be in a separate network namespace' ) # Validate server hostname/address resolve(server) self.user = user self.server = server self.have_mininet = have_mininet sshprefix = [ 'ssh', \ '-q', \ '-o', 'BatchMode=yes', \ '-o', 'ForwardAgent=yes' ] sshdest = '{}@{}'.format(self.user, self.server) self.sshcmd = sshprefix + [sshdest] self.sshcmd_tt = sshprefix + ['-tt', sshdest] if 'cmd_prefix' in kwargs: cmd_prefix = kwargs['cmd_prefix'] if is_some(cmd_prefix): self.sshcmd += cmd_prefix self.sshcmd_tt += cmd_prefix super(RemoteNodeMixin, self).__init__(*args, **kwargs)
def run(prog_args=sys.argv[1:]): parser = build_arg_parser() args, extra = parser.parse_known_args(prog_args) local_varanus_home = os.path.dirname( os.path.dirname(os.path.realpath(sys.argv[0]))) cfg_mod = import_config_module(args.config) mn = MininetRunner( of_version=args.of, \ autoarp=args.arp, \ enable_varanus=not args.novaranus, \ verbosity=args.v ) continue_prog = as_bool(cfg_mod.pre_start_config(mn, extra, local_varanus_home), name='continue_prog') if continue_prog: mn.build() mn.start() cfg_mod.post_start_config(mn, extra, local_varanus_home) mn.interact()
def _new_port(self, portnum, name=None, is_virtual=None, **params): is_virtual = as_bool(is_virtual, name='is_virtual') cls = VirOVSPortConfig if is_virtual else PhyOVSPortConfig return cls(portnum, self, name=name, **params)
def _build_base(self, net, have_mininet=None, **params): params['have_mininet'] = as_bool(have_mininet, name='have_mininet') params['cls'] = RemoteOVSSwitch return self._build_switch(net, **params)
def _build_base(self, net, hidden=False, **params): hidden = as_bool(hidden, name='hidden') params['cls'] = LocalHiddenHost if hidden else LocalHost return self._build_host(net, **params)
def _build_switch(self, net, dpid=None, inNamespace=None, **params): if is_some(dpid): params['dpid'] = '{:x}'.format(dpid) params['inNamespace'] = as_bool(inNamespace, name='inNamespace') return net.addSwitch(self.name, **params)
def _build_host(self, net, inNamespace=None, **params): # Do not configure by default any IP or MAC params['ip'] = None params['mac'] = None params['inNamespace'] = as_bool(inNamespace, name='inNamespace') return net.addHost(self.name, **params)
def __init__(self, portnum, name=None, is_virtual=True, **params): self.portnum = as_int(portnum, minim=0, name='portnum') self.name = as_str(name, name='name') if is_some(name) else None self.is_virtual = as_bool(is_virtual, name='is_virtual') self.params = params
def dpid_as_hex(self, add_prefix=True): add_prefix = as_bool(add_prefix, name='add_prefix') if add_prefix: return '0x{}'.format(self.dpid) else: return str(self.dpid)