def add_remote_vir_ovs_switch_ring(self, ringnum, size, user, server): ringnum = as_int(ringnum, minim=1, name='ringnum') size = as_int(size, minim=1, name='size') rb = self.get_ring_builder(ringnum) node_builder = self.get_ring_remote_switch_builder(user, server) rb.add_nodes(size, node_builder) ring = rb.build() self.add_existing_ovs_switch_ring(ring)
def _build_forward_rule(src, dest, table=0, priority=1): src = as_str(src) dest = as_str(dest) table = as_int(table, minim=0) priority = as_int(priority, minim=0) rule = 'table={0}'.format(table) rule += ',priority={0}'.format(priority) rule += ',in_port={0}'.format(src) rule += ',actions=output:{0}'.format(dest) return rule
def add_remote_collector(self, c_name, user, server, varanus_home, cid, **params): c_name = as_str(c_name, name='c_name') cid = as_int(cid, name='cid') self.__add_remote_collector(c_name, user, server, varanus_home, cid, **params)
def __init__(self, name, user, server, varanus_home, sudo=None, collector_port=32800, **params): self.collector_port = as_int(collector_port, minim=1, maxim=65535, name='collector_port') daemon = VaranusUtils.get_daemonizer_script(varanus_home, sudo=sudo) startcmd = partial(SDNControllerUtils.start_sdncontroller, varanus_home, daemon) stopcmd = partial(SDNControllerUtils.stop_sdncontroller, varanus_home, daemon) viewcmd = partial(SDNControllerUtils.view_sdncontroller, varanus_home, daemon) super( RemoteSDNControllerConfig, self ).__init__( name, user, server, \ startcmd=startcmd, \ stopcmd=stopcmd, \ morecmds={'view' : viewcmd}, \ **params )
def add_pica8_switch(self, sw_name, user, server, dpid, **params): sw_name = as_str(sw_name, name='sw_name') dpid = as_int(dpid, minim=0, name='dpid') sw = NodeUtils.add_pica8_switch(self.mr, sw_name, user, server, dpid, **params) self.switches[sw_name] = sw
def get_address( host, port ): if is_some( host ) and is_some( port ): host = resolve( host ) port = as_int( port, minim=1, maxim=65535, name='port' ) return ( host, port ) else: return None
def add_vir_collector_link(self, c_name, c_portnum, sw_name, sw_portnum): c_name = as_oneof(c_name, self.collectors.keys(), valname='c_name', containername='collector names') sw_name = as_oneof(sw_name, self.switches.keys(), valname='sw_name', containername='switch names') c_portnum = as_int(c_portnum, minim=0, name='c_portnum') sw_portnum = as_int(sw_portnum, minim=0, name='sw_portnum') c_port_cfg = NodeUtils.get_generic_vir_port_cfg(c_portnum) sw_port_cfg = NodeUtils.get_switch_to_collector_vir_port_cfg( sw_portnum) self.__add_collector_link(c_name, c_port_cfg, sw_name, sw_port_cfg)
def __init__(self, name, ip=None, port=None, **params): super(ControllerConfig, self).__init__(name, ip=ip, port=port, **params) self.ip = as_str(ip, name='ip') if is_some(ip) else None self.port = as_int(port, minim=1, maxim=65535, name='port') if is_some(port) else None
def add_vir_switch_link(self, sw_name1, sw_portnum1, sw_name2, sw_portnum2): sw_name1 = as_oneof(sw_name1, self.switches.keys(), valname='sw_name1', containername='switch names') sw_name2 = as_oneof(sw_name2, self.switches.keys(), valname='sw_name2', containername='switch names') sw_portnum1 = as_int(sw_portnum1, minim=0, name='sw_portnum1') sw_portnum2 = as_int(sw_portnum2, minim=0, name='sw_portnum2') port_cfg1 = NodeUtils.get_generic_vir_port_cfg(sw_portnum1) port_cfg2 = NodeUtils.get_generic_vir_port_cfg(sw_portnum2) self.__add_switch_link(sw_name1, port_cfg1, sw_name2, port_cfg2)
def add_vir_host_link(self, h_name, h_portnum, h_port_ip, sw_name, sw_portnum): h_name = as_oneof(h_name, self.hosts.keys(), valname='h_name', containername='host names') sw_name = as_oneof(sw_name, self.switches.keys(), valname='sw_name', containername='switch names') h_portnum = as_int(h_portnum, minim=0, name='h_portnum') h_port_ip = as_str(h_port_ip, name='h_port_ip') sw_portnum = as_int(sw_portnum, minim=0, name='sw_portnum') h_port_cfg = NodeUtils.get_host_vir_port_cfg(h_portnum, h_port_ip) sw_port_cfg = NodeUtils.get_generic_vir_port_cfg(sw_portnum) self.__add_host_link(h_name, h_port_cfg, sw_name, sw_port_cfg)
def add_nodes(self, num_nodes, node_builder, port1_cfg=None, port2_cfg=None, link_builder=None): num_nodes = as_int(num_nodes, minim=1, name='num_nodes') for _ in xrange(num_nodes): self.add_node(node_builder, port1_cfg, port2_cfg, link_builder)
def add_local_collector(self, c_name, cid, **params): varanus_home = self.local_varanus_home if not is_some(varanus_home): raise RuntimeError( 'VARANUS home is not defined, cannot add collector') c_name = as_str(c_name, name='c_name') cid = as_int(cid, name='cid') self.__add_local_collector(c_name, varanus_home, cid, **params)
def __init__( self, listenport, eval_cmd, mn ): self._listenport = as_int( listenport, minim=1, maxim=65535, name='listenport' ) self._eval_cmd = as_callable( eval_cmd, name='eval_cmd' ) self.mn = mn self.shell_handlers = {} self._server_timeout = 1 self.sock_timeout = 1 self._active_thread = None self._shutdown_check = threading.Event()
def _get_props(num): """ Returns name, intf_opts given a port number. """ num = as_int(num, minim=1, maxim=52) if num < 49: name = 'ge-1/1/' + str(num) intf_opts = {'link_speed': 'auto'} else: name = 'te-1/1/' + str(num) intf_opts = {'link_speed': '10G'} return name, intf_opts
def start_rcli( listenport, mn ): listenport = as_int( listenport, minim=1, maxim=65535, name='listenport' ) srv = _RCLIServer._ACTIVE_SERVER if is_some( srv ) and srv.is_active(): return False else: # Specialized eval() function with specific globals and locals eval_cmd = _build_eval_func( mn ) srv = _RCLIServer( listenport, eval_cmd, mn ) srv.start() _RCLIServer._ACTIVE_SERVER = srv return True
def add_phy_host_link(self, h_name, h_portname, h_portnum, h_port_ip, h_port_mac, sw_name, sw_portname, sw_portnum): h_name = as_oneof(h_name, self.hosts.keys(), valname='h_name', containername='host names') sw_name = as_oneof(sw_name, self.switches.keys(), valname='sw_name', containername='switch names') h_portname = as_str(h_portname, name='h_portname') h_portnum = as_int(h_portnum, minim=0, name='h_portnum') h_port_ip = as_str(h_port_ip, name='h_port_ip') h_port_mac = as_str(h_port_mac, name='h_port_mac') if is_some(h_port_mac) else None sw_portname = as_str(sw_portname, name='sw_portname') sw_portnum = as_int(sw_portnum, minim=0, name='sw_portnum') h_port_cfg = NodeUtils.get_host_phy_port_cfg(h_portname, h_portnum, h_port_ip, h_port_mac) sw_port_cfg = NodeUtils.get_generic_phy_port_cfg( sw_portname, sw_portnum) self.__add_host_link(h_name, h_port_cfg, sw_name, sw_port_cfg)
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 __init__(self, name, hostname='localhost', ip=None, port=6553, **params): # We do not support 'ip' parameter if is_some(ip): warn( 'Ignoring \'ip\' parameter passed to network controller (use \'hostname\' instead)' ) ip = resolve(hostname) port = as_int(port, minim=1, maxim=65535, name='port') self.hostname = hostname super(NetworkControllerConfig, self).__init__(name, ip=ip, port=port, **params)
def add_ring_remote_vir_collector(self, c_name, user, server, varanus_home, cid, ringnum, **params): c_name = as_str(c_name, name='c_name') cid = as_int(cid, name='cid') ringnum = as_oneof(ringnum, self.rings.keys(), valname='ringnum', containername='ring numbers') ring = self.rings[ringnum] self.__add_remote_collector(c_name, user, server, varanus_home, cid, **params) c_port_num = 1 sw_port_cfg = RingPorts.ring_to_collector_vir() for sw in ring.get_nodes(): c_port_cfg = NodeUtils.get_generic_vir_port_cfg(c_port_num) self.__add_collector_link(c_name, c_port_cfg, sw.name, sw_port_cfg) c_port_num += 1
def __init__(self, ringnum, prefix='n', port1_cfg=None, port2_cfg=None, link_builder=None): self.ringnum = as_int(ringnum, minim=0, name='ringnum') self.prefix = as_str(prefix, allow_empty=True, name='prefix') self.port1_cfg = as_a(port1_cfg, instance_of=PortConfig, name='port1_cfg') if is_some(port1_cfg) else None self.port2_cfg = as_a(port2_cfg, instance_of=PortConfig, name='port2_cfg') if is_some(port2_cfg) else None self.link_builder = as_callable( link_builder, name='link_builder') if is_some(link_builder) else None self.nodes = [] self.links = []
def add_ring_local_vir_collector(self, c_name, cid, ringnum, **params): varanus_home = self.local_varanus_home if not is_some(varanus_home): raise RuntimeError( 'VARANUS home is not defined, cannot add collector') c_name = as_str(c_name, name='c_name') cid = as_int(cid, name='cid') ringnum = as_oneof(ringnum, self.rings.keys(), valname='ringnum', containername='ring numbers') ring = self.rings[ringnum] self.__add_local_collector(c_name, varanus_home, cid, **params) c_port_num = 1 sw_port_cfg = RingPorts.ring_to_collector_vir() for sw in ring.get_nodes(): c_port_cfg = NodeUtils.get_generic_vir_port_cfg(c_port_num) self.__add_collector_link(c_name, c_port_cfg, sw.name, sw_port_cfg) c_port_num += 1
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 __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 as_valid_portnum(port, self): if isinstance(port, PortConfig): as_the(port.node, self) return port.num else: return as_oneof(as_int(port), self.ports)