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 hip( mn, ip_addr ): ip_addr = some( ip_addr, name='IP address' ) host = next( ( h for h in mn.hosts if h.IP() == ip_addr ), None ) if is_some( host ): return host else: raise ValueError( 'no host matches the provided IP address' )
def sid( mn, dpid ): dpid = some( dpid, name='DPID' ) switch = next( ( s for s in mn.switches if int( s.dpid ) == dpid ), None ) if is_some( switch ): return switch else: raise ValueError( 'no switch matches the provided DPID' )
def __init__( self, mn, node ): node = some( node, name='node' ) if isinstance( node, Node ): self.node = SpecialNode._check_valid_node( mn, node ) else: name = SpecialNode._check_valid_name( mn, str( node ) ) self.node = SpecialNode._check_valid_node( mn, mn[name] )
def as_name( mn, node ): node = some( node, name='node' ) if isinstance( node, Node ): node = NodeUtils.check_valid_node( mn, node ) return node.name else: return NodeUtils.check_valid_name( mn, str( node ) )
def __init__( self, num, node, name=None, cls=VirIntf, mac=None, ip=None, \ **params ): """ Constructs a new PortConfig object. - num : the port number - node: the node that owns this port - name: the port name (optional) - cls : the interface class (default is VirIntf) - mac : the MAC address for the interface - ip : the IP address for the interface """ self.num = as_int(num) self.node = some(node) self.name = as_str(fallback(name, '{0}-e{1}'.format(node.name, num))) self.cls = as_a(some(cls), subclass_of=Intf) self.mac = mac self.ip = ip params['ip'] = ip self.params = params self._peer = None # linked PortConfig
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 _build_common_link(self, net, cls=Link, **params): p1, p2 = self.port1, self.port2 params['port1'] = p1.num params['port2'] = p2.num params['cls'] = some(cls) params['intfName1'] = p1.name params['intfName2'] = p2.name params['addr1'] = p1.mac params['addr2'] = p2.mac params['cls1'] = p1.cls params['cls2'] = p2.cls params['params1'] = p1.params params['params2'] = p2.params n1, n2 = self.node1, self.node2 return net.addLink(n1.name, n2.name, **params)
def add_ring_remote_vir_host(self, h_name, user, server, h_portnum, h_port_ip, ringnum, sw_name, **params): h_name = some(h_name, name='h_name') h_portnum = as_int(h_portnum, minim=0, name='h_portnum') h_port_ip = as_str(h_port_ip, name='h_port_ip') ringnum = as_oneof(ringnum, self.rings.keys(), valname='ringnum', containername='ring numbers') sw_name = as_oneof(sw_name, self.switches.keys(), valname='sw_name', containername='switch names') ring = self.rings[ringnum] if not any(s.name == sw_name for s in ring.get_nodes()): raise ValueError('no switch named "{}" exists in ring {}'.format( sw_name, ringnum)) self.__add_remote_vir_host(h_name, user, server, **params) h_port_cfg = NodeUtils.get_host_vir_port_cfg(h_portnum, h_port_ip) sw_port_cfg = RingPorts.ring_to_host_vir() self.__add_host_link(h_name, h_port_cfg, sw_name, sw_port_cfg)
def add_flow_rule(self, *rule): ofver = some(self.netnode.protocols) return self.netnode.cmd('ovs-ofctl', '-O', ofver, 'add-flow', self.name, *rule)
def __init__(self, ringnum, nodes, links): self.ringnum = ringnum self.nodes = some(nodes, name='nodes') self.links = some(links, name='links')
def put( self, intf, qos ): intf = as_a( intf, instance_of=Intf, name='intf' ) qos = some( qos, name='qos' ) self.cache_map[intf.name] = qos