def __init__(self, *args, **kwargs): super(Switches, self).__init__(*args, **kwargs) self.name = 'switches' self.dps = {} # datapath_id => Datapath class self.port_state = {} # datapath_id => ports self.ports = PortDataState() # Port class -> PortData class self.links = LinkState() # Link class -> timestamp self.is_active = True # by jesse : for other controller link self.cports = PortDataState() self.clinks = LinkState() # by jesse : for same switch port link (in_port == out_port) self.sports = PortDataState() self.slinks = LinkState() # by jesse : add vlan self.update_lldp_data_flag = False self.link_discovery = self.CONF.observe_links if self.link_discovery: self.install_flow = self.CONF.install_lldp_flow self.explicit_drop = self.CONF.explicit_drop self.lldp_event = hub.Event() self.link_event = hub.Event() self.threads.append(hub.spawn(self.lldp_loop)) self.threads.append(hub.spawn(self.link_loop))
def __init__(self, *args, **kwargs): super(Generic_Agent_CHT, self).__init__(*args, **kwargs) global CTRL_TYPE hub.spawn(self.exit_detect_thread) CTRL_TYPE = raw_input('Please input SDN Controller Type: ') while True: try: # Get SYSTEM_NAME from Generic_LLDP_Module response = self.session.post(GENERIC_URL_BASE + '/controllers/regist/' + CTRL_TYPE) # if response code not 200, raise an exception response.raise_for_status() data = yaml.safe_load(response.text) self.SYSTEM_NAME = data['system_name'] self.LLDP_FORMAT = data['LLDP_subtype'] break except Exception as e: print e time.sleep(5) self.datapaths = {} self.links = {} self.mac_to_port = {} self.LLDP_recv_port = {} self.hosts = {} hub.spawn(self.lldp_thread)
def start(self): self.receive = True self.queue = hub.Queue() self.receive_thread = hub.spawn(self.receiver) self.logger.info('server: receiver thread spawned') self.processor_thread = hub.spawn(self.service_queue) self.logger.info('server: processor thread spawned')
def _create_bgp_speaker_for_vlan(self, vlan, bgp_speaker_key): """Set up BGP speaker for an individual VLAN if required. Args: vlan (valve VLAN): VLAN for BGP speaker. Returns: ryu.services.protocols.bgp.bgpspeaker.BGPSpeaker: BGP speaker. """ route_handler = lambda x: self._bgp_route_handler(x, bgp_speaker_key) server_address = sorted(vlan.bgp_server_addresses_by_ipv(bgp_speaker_key.ipv))[0] beka = Beka( local_address=str(server_address), bgp_port=vlan.bgp_port, local_as=vlan.bgp_as, router_id=vlan.bgp_routerid, peer_up_handler=self._bgp_up_handler, peer_down_handler=self._bgp_down_handler, route_handler=route_handler, error_handler=self.logger.warning) for ip_dst, ip_gw in self._vlan_prefixes_by_ipv(vlan, bgp_speaker_key.ipv): beka.add_route(prefix=str(ip_dst), next_hop=str(ip_gw)) for bgp_neighbor_address in vlan.bgp_neighbor_addresses_by_ipv(bgp_speaker_key.ipv): beka.add_neighbor( connect_mode=vlan.bgp_connect_mode, peer_ip=str(bgp_neighbor_address), peer_as=vlan.bgp_neighbor_as) hub.spawn(beka.run) return beka
def __init__(self,*args,**kwargs): super(ForwardingBasic,self).__init__(args,kwargs) self.CONF.register_opts([ cfg.StrOpt("topology",default = None, help = "Specified network topology", ) ]) self.topo = "fattree" self.topo = None self.name = "Forwarding-Basic" self.spanning_tree_done = True self.spanning_tree_links = set([]) self.mac_to_port = {} self.mac_to_port.setdefault(0,{}) self.install_port_events = True self.total_links = 0 self.poll_port_stats = True self.link_rate_out_file = open("logs/link_rate.out.%s" %time.strftime("%Y%m%d_%H%M%S") ,'w') if self.topo is None: self.logger.info("No topology specified.") else: self.logger.info("Specified topology is %s" %self.topo) if self.topo == 'fattree': self.expected_links = 64 self.fat_tree_k = 4 spawn(self.send_port_req_loop)
def __init__(self, *args, **kwargs): super(Ryu,self).__init__(*args,**kwargs) #--- register for configuration options self.CONF.register_opts([ cfg.StrOpt('SciPassConfig',default='/etc/SciPass/SciPass.xml', help='where to find the SciPass config file'), ]) self.logger.error("Starting SciPass") self.datapaths = {} self.isactive = 1 self.statsInterval = 5 self.balanceInterval = 15 self.bal = None self.stats = {} self.stats_thread = hub.spawn(self._stats_loop) self.balance_thread = hub.spawn(self._balance_loop) self.ports = defaultdict(dict); self.prefix_bytes = defaultdict(lambda: defaultdict(int)) self.lastStatsTime = None self.flowmods = {} api = SciPass(logger = self.logger, config_file = self.CONF.SciPassConfig ) api.registerForwardingStateChangeHandler(self.changeSwitchForwardingState) self.api = api wsgi = kwargs['wsgi'] wsgi.register(SciPassRest, {'api' : self.api})
def _wait_bpdu_timer(self): time_exceed = False while True: self.wait_timer_event = hub.Event() message_age = (self.designated_times.message_age if self.designated_times else 0) timer = self.port_times.max_age - message_age timeout = hub.Timeout(timer) try: self.wait_timer_event.wait() except hub.Timeout as t: if t is not timeout: err_msg = 'Internal error. Not my timeout.' raise RyuException(msg=err_msg) self.logger.info('[port=%d] Wait BPDU timer is exceeded.', self.ofport.port_no, extra=self.dpid_str) time_exceed = True finally: timeout.cancel() self.wait_timer_event = None if time_exceed: break if time_exceed: # Bridge.recalculate_spanning_tree hub.spawn(self.wait_bpdu_timeout)
def start_sock_server(self): if os.path.exists(SOCKFILE): os.unlink(SOCKFILE) self.sock = hub.socket.socket(hub.socket.AF_UNIX, hub.socket.SOCK_DGRAM) self.sock.bind(SOCKFILE) hub.spawn(self.recv_loop)
def agent_main_wrapper(bridge_classes): ovs_agent.main(bridge_classes) # The following call terminates Ryu's AppManager.run_apps(), # which is needed for clean shutdown of an agent process. # The close() call must be called in another thread, otherwise # it suicides and ends prematurely. hub.spawn(app_manager.AppManager.get_instance().close)
def start(self): # Only two main green threads are required for APGW bgp-agent. # One for NetworkController, another for BGPS core. # If configuration file was provided and loaded successfully. We start # BGPS core using these settings. If no configuration file is provided # or if configuration file is missing minimum required settings BGPS # core is not started. if self.config_file: LOG.debug('Loading config. from settings file.') settings = self.load_config(self.config_file) # Configure log settings, if available. if getattr(settings, 'LOGGING', None): dictConfig(settings.LOGGING) if getattr(settings, 'BGP', None): self._start_core(settings) if getattr(settings, 'SSH', None) is not None: hub.spawn(ssh.SSH_CLI_CONTROLLER.start, None, **settings.SSH) # Start Network Controller to server RPC peers. t = hub.spawn(net_ctrl.NET_CONTROLLER.start, *[], **{net_ctrl.NC_RPC_BIND_IP: self.bind_ip, net_ctrl.NC_RPC_BIND_PORT: self.bind_port}) LOG.debug('Started Network Controller') super(RyuBGPSpeaker, self).start() return t
def __init__(self, *args, **kwargs): super(ProxyAccess, self).__init__(*args, **kwargs) self.mac_to_port = {} self.ip_to_mac = {} self.dps = [] self.web_server_dp = None hub.spawn(self._redirect)
def start(self): super(RyuBGPSpeaker, self).start() # If configuration file was provided and loaded successfully, we start # BGPSpeaker using the given settings. # If no configuration file is provided or if any minimum required # setting is missing, BGPSpeaker will not be started. if self.config_file: LOG.debug('Loading config file %s...', self.config_file) settings = load_config(self.config_file) # Configure logging settings, if available. if hasattr(settings, 'LOGGING'): # Not implemented yet. LOG.debug('Loading LOGGING settings... (NOT implemented yet)') # from logging.config import dictConfig # logging_settings = dictConfig(settings.LOGGING) # Configure BGP settings, if available. if hasattr(settings, 'BGP'): LOG.debug('Loading BGP settings...') self._start_speaker(settings.BGP) # Configure SSH settings, if available. if hasattr(settings, 'SSH'): LOG.debug('Loading SSH settings...') hub.spawn(SSH_CLI_CONTROLLER.start, **settings.SSH) # Start RPC server with the given RPC settings. rpc_settings = { NC_RPC_BIND_PORT: CONF.rpc_port, NC_RPC_BIND_IP: validate_rpc_host(CONF.rpc_host), } return hub.spawn(NET_CONTROLLER.start, **rpc_settings)
def main(): try: CONF(project='ryu', version='ryu-manager %s' % version, default_config_files=['/usr/local/etc/ryu/ryu.conf']) except cfg.ConfigFilesNotFoundError: CONF(project='ryu', version='ryu-manager %s' % version) log.init_log() app_lists = CONF.app_lists + CONF.app app_mgr = AppManager() app_mgr.load_apps(app_lists) contexts = app_mgr.create_contexts() app_mgr.instantiate_apps(**contexts) services = [] # TODO: do the following in app_manager's instantiate_apps() ofpapp = controller.start_service(app_mgr) if ofpapp: thr = hub.spawn(ofpapp) services.append(thr) webapp = wsgi.start_service(app_mgr) if webapp: thr = hub.spawn(webapp) services.append(thr) try: hub.joinall(services) finally: app_mgr.close()
def start(self): super(RemoteOvsdb, self).start() t = hub.spawn(self._run_thread, self._idl_loop) self.threads.append(t) t = hub.spawn(self._run_thread, self._event_proxy_loop) self.threads.append(t)
def _start_recv_nw_sock(self, port): self.nwsock = hub.socket.socket(hub.socket.AF_INET, hub.socket.SOCK_STREAM) self.nwsock.bind(("0.0.0.0", port)) self.nwsock.listen(5) hub.spawn(self._recv_loop_nw_sock)
def __init__(self, *args, **kwargs): super(RyuController, self).__init__(*args, **kwargs) self.mac_to_port = {} self.flowstats = {} self.detected_flags = {} self.done = False self.byte_treshold = 500000 self.packet_treshold = 5000 self.detected_flags = {} if socket.gethostname() == 'lt-debian': self.gateway_port = 1 self.map_port_mac = { 3: '52:54:00:12:e9:0b', 1: '52:54:00:34:0d:1f', 65534: '32:32:7c:ac:49:42' } elif socket.gethostname() == 'OVS-Switch': self.gateway_port = 1 self.map_port_mac = { 1: '52:54:00:ee:6e:d7', 2: '52:54:00:2d:0f:99', 65534: '82:c8:6a:fe:33:4f' } else: self.gateway_port = 33 self.map_port_mac = { 32: '00:0c:29:a7:de:cd', 33: '00:0a:f7:1a:a9:34', 34: '00:1b:21:bd:dc:9d' } self.gateway_mac = haddr_to_bin(self.map_port_mac[self.gateway_port]) self.threads.append(hub.spawn(parser.run)) self.threads.append(hub.spawn(counter.run)) self.threads.append(hub.spawn(self.poller))
def _create_dot1x_speaker(self, dot1x_intf, chewie_id, radius_ip, radius_port, radius_secret): chewie = Chewie( # pylint: disable=too-many-function-args dot1x_intf, self.logger, self.auth_handler, self.failure_handler, self.logoff_handler, radius_ip, radius_port, radius_secret, chewie_id) hub.spawn(chewie.run) return chewie
def __init__(self, inception, zk_storage=False): # zk_storage: Decide whether to use zookeeper (True) or not (False) self.zk_storage = zk_storage self.inception = inception if self.zk_storage: # Flag indicating master/slave role self.master_ctl = False self.pos_path = "/pos" self.arp_path = "/arp" self.queue_path = "/queue" self.leader_path = "/election" self.pktin_path = "/log/packet_in" self.rpc_path = "/log/rpc" self.digest_to_pktin = {} zk_logger = logging.getLogger('kazoo') zk_log_level = log.LOG_LEVELS[CONF.zk_log_level] zk_logger.setLevel(zk_log_level) console_handler = logging.StreamHandler() console_handler.setLevel(zk_log_level) console_handler.setFormatter(logging.Formatter(CONF.log_formatter)) zk_logger.addHandler(console_handler) self.zk = client.KazooClient(hosts=CONF.zk_servers, logger=zk_logger) self.zk.start() self.zk.ensure_path(self.pos_path) self.zk.ensure_path(self.arp_path) self.zk.ensure_path(self.pktin_path) self.zk.ensure_path(self.rpc_path) self.pkt_queue = self.zk.LockingQueue(self.queue_path) self.thread_pkt = hub.spawn(self.handle_pkt_queue) hub.spawn(self.run_for_leader)
def _handle_open(self, msg): self.peer_as = msg.my_as peer_holdtime = msg.hold_time self.hold_time = min(peer_holdtime, self.hold_time) self.peer_id = msg.bgp_identifier self.peer_capabilities = msg.data for capability in self.peer_capabilities: if isinstance(capability, BGP4.multi_protocol_extension): if capability.addr_family == 1: self._4or6 = 4 elif capability.addr_family == 2: self._4or6 = 6 else: self._4or6 = 0 if isinstance(capability, BGP4.support_4_octets_as_num): self.peer_as = capability.as_num LOG.info('BGP peer info. 4/6: %s, AS %s, hold time %s, ID %s, capability %s', self._4or6, self.peer_as, self.hold_time, self.peer_id, self.peer_capabilities) self.send_open_msg() if self.__check_capabilities(self.peer_capabilities): self.peer_last_keepalive_timestamp = time.time() hub.spawn(self.keepalive) self.send_current_route_table() else: self.send_notification_msg(err_code=2, err_subcode=0, data="Capability check failed.")
def __init__(self, *args, **kwargs): super(SDNIP, self).__init__(*args, **kwargs) self.fwd = kwargs['fwd'] self.hop_db = kwargs['hop_db'] self.cfg_mgr = SDNIPConfigManager() self.waiters = {} self.bgp_speaker =\ BGPSpeaker(self.cfg_mgr.as_number, str(self.cfg_mgr.router_id), bgp_server_port=self.cfg_mgr.listen_port, best_path_change_handler=self.best_path_change_handler, peer_down_handler=self.peer_down_handler, peer_up_handler=self.peer_up_handler) speaker_ids = self.cfg_mgr.get_all_speaker_id() for speaker_id in speaker_ids: self.bgp_speaker.neighbor_add(speaker_id, self.cfg_mgr.as_number, is_next_hop_self=True) hub.spawn(self.prefix_check_loop) if with_dk: dk_plugin.DynamicLoader.register_custom_cmd('sdn-ip:info', self.cmd_self_info) dk_plugin.DynamicLoader.register_custom_cmd('sdn-ip:routes', self.cmd_list_routes) dk_plugin.DynamicLoader.register_custom_cmd('sdn-ip:flows', self.cmd_get_flows)
def start(self): self.epl.listen(9999, "127.0.0.1") self.icsq = self.epl.incoming_connection_status() self.mql = message_queue(queuename, self.epl) self.threads.append(hub.spawn(self._broker_loop)) self.logger.info("Started broker communication...") self.threads.append(hub.spawn(self._event_loop))
def _meter_stats_reply_handler(self, ev): body = ev.msg.body dpid = ev.msg.datapath.id self.logger.info('datapath meter_id kbps ') self.logger.info('---------------- -------- --------') modified_ports = [] for stat in sorted(body, key=attrgetter('meter_id')): if stat.meter_id in self.time_prev[dpid]: sleep = float(stat.duration_sec) + (stat.duration_nsec / 10.0**9) - self.time_prev[dpid][stat.meter_id] self.meter_speed[dpid][stat.meter_id] = self._get_speed(stat.byte_in_count, self.meter_prev[dpid][stat.meter_id], sleep) else: self.meter_speed[dpid][stat.meter_id] = 0 self.time_prev[dpid][stat.meter_id] = float(stat.duration_sec) + (stat.duration_nsec / 10.0**9) self.meter_prev[dpid][stat.meter_id] = stat.byte_in_count self.logger.info("%016x %08x %6.1f",dpid, stat.meter_id, self.meter_speed[dpid][stat.meter_id]) if stat.meter_id in self.meter_to_src[dpid]: src = self.meter_to_src[dpid][stat.meter_id] port = self.mac_to_port[dpid][src] self.rate_used[dpid].setdefault(port, {}) self.rate_used_mod[dpid].setdefault(port, {}) self.rate_used[dpid][port][src] = self.meter_speed[dpid][stat.meter_id] if (self.rate_used[dpid][port][src] >= int(self.rate_allocated[dpid][port][src]*0.7) and (self.rate_allocated[dpid][port][src] < self.rate_request[dpid][port][src])): if int(self.rate_allocated[dpid][port][src]*1.5) < self.rate_request[dpid][port][src]: self.rate_used_mod[dpid][port][src] = int(self.rate_allocated[dpid][port][src]*1.5) else: self.rate_used_mod[dpid][port][src] = self.rate_request[dpid][port][src] if port not in modified_ports: modified_ports.append(port) else: self.rate_used_mod[dpid][port][src] = self.rate_used[dpid][port][src] for port in modified_ports: hub.spawn(self._mod_port_meters, dpid, port)
def __init__(self, *args, **kwargs): super(HLApp, self).__init__(*args, **kwargs) self.commandSender = CommandSender.get_instance() self.flow_collector = kwargs['flow_collector'] self.network_monitor = kwargs['network_monitor'] self.flowClassifier = FlowClassifier.get_instance() self.routeCalculator = RouteCalculator.get_instance() self.pathPreInstall = PathPreInstall() self.activePairSelector = ActivePairSelector() self.rerouter = None self.DISCOVER_PERIOD = 5 self.COLLECTOR_PERIOD = 5 self.FLOW_COUNT = 1 self.TCP_IDLE_TIME = 10 self.ICMP_IDLE_TIME = 60 self.network_monitor_thread = hub.spawn(self._monitor) self.flow_collector_thread = hub.spawn(self._collector)
def main(): try: CONF(project='ryu', version='ryu-manager %s' % version, default_config_files=['/usr/local/etc/ryu/ryu.conf']) except cfg.ConfigFilesNotFoundError: CONF(project='ryu', version='ryu-manager %s' % version) log.init_log() # always enable ofp for now. app_lists = CONF.app_lists + CONF.app + ['ryu.controller.ofp_handler'] app_mgr = AppManager() app_mgr.load_apps(app_lists) contexts = app_mgr.create_contexts() app_mgr.instantiate_apps(**contexts) services = [] ctlr = controller.OpenFlowController() thr = hub.spawn(ctlr) services.append(thr) webapp = wsgi.start_service(app_mgr) if webapp: thr = hub.spawn(webapp) services.append(thr) try: hub.joinall(services) finally: app_mgr.close()
def __init__(self, as_number, router_id, bgp_server_port=DEFAULT_BGP_SERVER_PORT, refresh_stalepath_time=DEFAULT_REFRESH_STALEPATH_TIME, refresh_max_eor_time=DEFAULT_REFRESH_MAX_EOR_TIME, best_path_change_handler=None, peer_down_handler=None, peer_up_handler=None, ssh_console=False, label_range=DEFAULT_LABEL_RANGE): """Create a new BGPSpeaker object with as_number and router_id to listen on bgp_server_port. ``as_number`` specifies an Autonomous Number. It must be an integer between 1 and 65535. ``router_id`` specifies BGP router identifier. It must be the string representation of an IPv4 address (e.g. 10.0.0.1). ``bgp_server_port`` specifies TCP listen port number. 179 is used if not specified. ``refresh_stalepath_time`` causes the BGP speaker to remove stale routes from the BGP table after the timer expires, even if the speaker does not receive a Router-Refresh End-of-RIB message. This feature is disabled (not implemented yet). ``refresh_max_eor_time`` causes the BGP speaker to generate a Route-Refresh End-of-RIB message if it was not able to generate one due to route flapping. This feature is disabled (not implemented yet). ``best_path_change_handler``, if specified, is called when any best remote path is changed due to an update message or remote peer down. The handler is supposed to take one argument, the instance of an EventPrefix class instance. ``peer_down_handler``, if specified, is called when BGP peering session goes down. ``peer_up_handler``, if specified, is called when BGP peering session goes up. """ super(BGPSpeaker, self).__init__() settings = {} settings[LOCAL_AS] = as_number settings[ROUTER_ID] = router_id settings[BGP_SERVER_PORT] = bgp_server_port settings[REFRESH_STALEPATH_TIME] = refresh_stalepath_time settings[REFRESH_MAX_EOR_TIME] = refresh_max_eor_time settings[LABEL_RANGE] = label_range self._core_start(settings) self._init_signal_listeners() self._best_path_change_handler = best_path_change_handler self._peer_down_handler = peer_down_handler self._peer_up_handler = peer_up_handler if ssh_console: hub.spawn(ssh.SSH_CLI_CONTROLLER.start)
def __init__(self, *args, **kwargs): super(RpcVRRPManager, self).__init__(*args, **kwargs) self._args = args self._kwargs = kwargs self._peers = [] self._rpc_events = hub.Queue(128) self.server_thread = hub.spawn(self._peer_accept_thread) self.event_thread = hub.spawn(self._rpc_request_loop_thread)
def datapath_handler(self, ev): # Target switch datapath self.dp = ev.dp version = self.dp.ofproto.OFP_VERSION if version not in self._OFCTL: raise OFPUnknownVersion(version=version) self.ofctl = self._OFCTL[version] hub.spawn(self._do_test)
def peer_accept_handler(self, new_sock, addr): peer = Peer(self._rpc_events) table = { rpc.MessageType.REQUEST: peer._handle_vrrp_request, } peer._endpoint = rpc.EndPoint(new_sock, disp_table=table) self._peers.append(peer) hub.spawn(self._peer_loop_thread, peer)
def start(self, is_active, peer_addr, conn_handle): if is_active: with Timeout(DEFAULT_CONN_TIMEOUT, socket.error): self._socket.connect(peer_addr) hub.spawn(conn_handle, self._socket, True) else: self._socket.listen(50) hub.spawn(self._listen_loop, conn_handle)
def conn_handle(self, socket, is_active): if is_active: self._state_map = self._ACTIVE_STATE_MAP else: self._state_map = self._PASSIVE_STATE_MAP self._socket = socket self.state_change(ldp_event.LDP_STATE_INITIAL) hub.spawn(self._recv_loop)
def _deactivate_subscriber_rules(self): def deactivate_flows(): self._ec.deactivate_rules(imsi=self.cfg.imsi, rule_ids=None) hub.joinall([hub.spawn(deactivate_flows)])
def __init__(self, *args, **kwargs): super(SimpleSwitch13, self).__init__(*args, **kwargs) self.mac_to_port = {} self.datapaths = {} self.monitor_thread = hub.spawn(self._monitor)
def start(self): super(BMPStation, self).start() return hub.spawn( StreamServer((SERVER_HOST, SERVER_PORT), self.loop).serve_forever)
def start(self, ryudp): self.ryudp = ryudp self.stop() self.thread = hub.spawn(self)
from operator import attrgetter
def start(self): """ Hook that is called after startup initialization is done. """ self.threads.append(hub.spawn(self._event_loop))
def __init__(self, *args, **kwargs): super(SamplerSwitch, self).__init__(*args, **kwargs) self.datapaths = {} self.monitor_thread = hub.spawn(self._monitor) #hub that will query switches
def __init__(self, *args, **kwargs): super(SimpleMonitor, self).__init__(*args, **kwargs) self.datapaths = {} self.monitor_thread = hub.spawn(self._monitor)
def _enable_router(self): if self._arp_thread is None: self._arp_thread = hub.spawn(self._arp_loop) # TODO: implement real routing logic self.logger.debug('TODO:_enable_router')
def start(self): self.stop() self.thread = hub.spawn(self)
def start(self): super(NIB,self).start() self.logger.debug("start here ing") self.threads.append(hub.spawn(self.queue_stats_request))
def __init__(self, *args, **kwargs): super(PortStatsReporter, self).__init__(*args, **kwargs) self.datapaths = {} self.monitor_thread = hub.spawn(self._monitor) self.monitoring_time = 5
def __init__(self, *args, **kwargs): super(Controller, self).__init__(*args, **kwargs) conf = DictionaryConfiguration() # configurations for the system # arp table for different tenants self.arp_table = { # {tenant_id ->{ip -> mac}} 1: { # d1 '191.168.1.1': '00:00:00:00:00:01', '191.168.1.4': '00:00:00:00:00:04', '191.168.1.6': '00:00:00:00:00:06', '191.168.111.1': '10:00:00:00:00:00', # d2 '191.168.2.1': '00:00:00:00:00:21', }, 2: { # d1 '191.168.1.3': '00:00:00:00:00:03', '191.168.1.2': '00:00:00:00:00:02', '191.168.1.5': '00:00:00:00:00:05', '191.168.1.7': '00:00:00:00:00:07', # d2 '191.168.2.2': '00:00:00:00:00:22' } } # pmac -> tenant_id self.host_pmac = { '00:00:00:00:00:01': 1, '00:00:00:00:00:02': 2, '00:00:00:00:00:03': 2, '00:00:00:00:00:04': 1, '00:00:00:00:00:05': 2, '00:00:00:00:00:06': 1, '10:00:00:00:00:00': 1, '00:00:00:00:00:21': 1, '00:00:00:00:00:07': 2, '00:00:00:00:00:22': 2 } # tenant_id -> tenant_level self.tenant_level = {1: 2, 2: 1} # record all potential subnet self.subnets = ['191.0.0.0/8', '192.0.0.0/8', '10.0.0.0/8'] # record all potential gateway # 'NAT' : port_no # datacenter_id : port_no self.potential_gateway = { 10: { 2: 6 }, 11: { 2: 6 }, 12: { 2: 6 }, 13: { 1: 5 }, 14: { 1: 5 }, 15: { 1: 5 } } # remote datacenter_id -> {dpid -> peer} # if there is no peer, then peer is -1 self.gateways_datacenter_port = {2: {10: -1, 11: 12, 12: 11}} # record all potential gateway_ip # datacenter_id -> [gateway_ip] self.gateway_ip = ['191.0.0.1'] # record speed for tenant # tenant_id -> speed self.tenant_speed = { # 1: 1024 * 1, # 2: 1024 * 1 } # record all datacenter_id self.all_datacenter_id = [1, 2] # record for system # data in controller self.vmac_to_pmac = { # {vmac -> vmac} } self.pmac_to_vmac = { # {pmac -> vmac} } self.dpid_to_vmac = {} # {dpid -> vmac} self.datapathes = {} # {dpid -> datapath} self.dpid_to_ports = {} # {dpid -> ports} self.dpid_to_dpid = {} # {(dpid, port_id) -> dpid} self.switch_topo = nx.Graph() # switch topo self.port_speed = { } # {dpid -> {remote_dpid -> 'max_speed' - 'cur_speed'}} self.meters = {} # {dpid -> {meter_id -> band_id}} self.gateways = {} # {dpid -> {port_no -> datacenter_id}} self.gateway_vmac = {} # {dpid -> vmac} self.host_queue = {} # gateway_id -> queue for host self.switch_gateway_connection = { } # (switch_id, gateway_id) -> (switch_port, gateway_port) self.host_gateway = {} # {vmac -> gateway_id} # components self.flow_manager = FlowManager(datapathes=self.datapathes, gateways=self.gateways) self.lldp_manager = LLDPListener( datapathes=self.datapathes, dpid_potrs=self.dpid_to_ports, dpid_to_dpid=self.dpid_to_dpid, topo=self.switch_topo, DEFAULT_TTL=self.DEFAULT_TTL, port_speed=self.port_speed, potential_gateways=self.potential_gateway) self.swtich_manager = SwitchManager( datapathes=self.datapathes, dpid_to_ports=self.dpid_to_ports, dpid_to_vmac=self.dpid_to_vmac, lldp_manager=self.lldp_manager, meters=self.meters, subnets=self.subnets, potential_gateway=self.potential_gateway) self.arp_manager = ArpManager( arp_table=self.arp_table, pmac_to_vmac=self.pmac_to_vmac, gateway_ip=self.gateway_ip, gateways=self.gateways, dpid_to_vmac=self.dpid_to_vmac, switch_gateway_connection=self.switch_gateway_connection, datapathes=self.datapathes, host_gateway=self.host_gateway) self.mac_manager = MacManager(tenant_level=self.tenant_level) self.meter_manager = MeterModifier(meters=self.meters) self.host_manager = HostManager(host_pmac=self.host_pmac, mac_manager=self.mac_manager, pmac_to_vmac=self.pmac_to_vmac, vmac_to_pmac=self.vmac_to_pmac, tenant_speed=self.tenant_speed, meter_manager=self.meter_manager) self.topo_manager = TopoManager(topo=self.switch_topo, dpid_to_dpid=self.dpid_to_dpid) self.gateway_manager = GatewayManager( gateways=self.gateways, potential_gateway=self.potential_gateway, gateway_flow_table_inquire_time=self.GATEWAY_FLOW_INQUIRY_TIME, datapathes=self.datapathes, gateway_port_inquire_time=self.GATEWAY_PORT_INQUIRY_TIME, gateway_datacenter_port_max_speed=self.DEFAULT_GG_BW, balance_time_interval=self.GATEWAY_BALANCE_TIME, all_datacenter_id=self.all_datacenter_id, topo_manager=self.topo_manager, meter_manager=self.meter_manager) # hub self.init_hub = hub.spawn(self.init_controller) self.gateway_statistics_inquiry_hub = hub.spawn( self.gateway_manager.inquiry_gateway_flow_table_info) self.gateways_datacenter_port_hub = hub.spawn( self.gateway_manager.inquiry_gateway_datacenter_port) # self.gateway_banlance_hub = hub.spawn(self.gateway_manager.gateway_balance_hub) self.gateway_init_record_hub = hub.spawn( self.gateway_manager.init_gateway_record)
def _websocket_handler(self, ws): rpc_client = WebSocketRPCClient(ws) self.app.rpc_clients.append(rpc_client) # init_client requires a running event loop spawn(self.app.init_client, rpc_client) rpc_client.serve_forever()
def __init__(self, *args, **kwargs): super(ProjectCCMP, self).__init__(*args, **kwargs) self.mac_to_port = {} self.topology_api_app = self self.datapath_list = {} self.arp_table = {} self.switches = [] self.hosts = {} self.multipath_group_ids = {} self.group_ids = [] self.adjacency = defaultdict( dict ) #self.adjacency[s1.dpid][s2.dpid] = s1.port_no self.adjacency[s2.dpid][s1.dpid] = s2.port_no self.bandwidths = defaultdict(lambda: defaultdict(lambda: DEFAULT_BW)) self.paths = defaultdict(list) self.host_ip = { (13, 19): ["10.0.0.1", "10.0.0.7"], (13, 20): ["10.0.0.1", "10.0.0.8"], (13, 21): ["10.0.0.1", "10.0.0.9"], (13, 22): ["10.0.0.1", "10.0.0.10"], (13, 23): ["10.0.0.1", "10.0.0.11"], (13, 24): ["10.0.0.1", "10.0.0.12"], (14, 19): ["10.0.0.2", "10.0.0.7"], (14, 20): ["10.0.0.2", "10.0.0.8"], (14, 21): ["10.0.0.2", "10.0.0.9"], (14, 22): ["10.0.0.2", "10.0.0.10"], (14, 23): ["10.0.0.2", "10.0.0.11"], (14, 24): ["10.0.0.2", "10.0.0.12"], (15, 19): ["10.0.0.3", "10.0.0.7"], (15, 20): ["10.0.0.3", "10.0.0.8"], (15, 21): ["10.0.0.3", "10.0.0.9"], (15, 22): ["10.0.0.3", "10.0.0.10"], (15, 23): ["10.0.0.3", "10.0.0.11"], (15, 24): ["10.0.0.3", "10.0.0.12"], (16, 19): ["10.0.0.4", "10.0.0.7"], (16, 20): ["10.0.0.4", "10.0.0.8"], (16, 21): ["10.0.0.4", "10.0.0.9"], (16, 22): ["10.0.0.4", "10.0.0.10"], (16, 23): ["10.0.0.4", "10.0.0.11"], (16, 24): ["10.0.0.4", "10.0.0.12"], (17, 19): ["10.0.0.5", "10.0.0.7"], (17, 20): ["10.0.0.5", "10.0.0.8"], (17, 21): ["10.0.0.5", "10.0.0.9"], (17, 22): ["10.0.0.5", "10.0.0.10"], (17, 23): ["10.0.0.5", "10.0.0.11"], (17, 24): ["10.0.0.5", "10.0.0.12"], (18, 19): ["10.0.0.6", "10.0.0.7"], (18, 20): ["10.0.0.6", "10.0.0.8"], (18, 21): ["10.0.0.6", "10.0.0.9"], (18, 22): ["10.0.0.6", "10.0.0.10"], (18, 23): ["10.0.0.6", "10.0.0.11"], (18, 24): ["10.0.0.6", "10.0.0.12"] } self.host_port = { (13, 19): [5, 5], (13, 20): [5, 6], (13, 21): [5, 5], (13, 22): [5, 5], (13, 23): [5, 6], (13, 24): [5, 5], (14, 19): [5, 5], (14, 20): [5, 6], (14, 21): [5, 5], (14, 22): [5, 5], (14, 23): [5, 6], (14, 24): [5, 5], (15, 19): [6, 5], (15, 20): [6, 6], (15, 21): [6, 5], (15, 22): [6, 5], (15, 23): [6, 6], (15, 24): [6, 5], (16, 19): [5, 5], (16, 20): [5, 6], (16, 21): [5, 5], (16, 22): [5, 5], (16, 23): [5, 6], (16, 24): [5, 5], (17, 19): [5, 5], (17, 20): [5, 6], (17, 21): [5, 5], (17, 22): [5, 5], (17, 23): [5, 6], (17, 24): [5, 5], (18, 19): [5, 5], (18, 20): [5, 6], (18, 21): [5, 5], (18, 22): [5, 5], (18, 23): [5, 6], (18, 24): [5, 5] } #h1-eth0<->s13-eth5 (OK OK) #h2-eth0<->s14-eth5 (OK OK) #h3-eth0<->s15-eth6 (OK OK) #h4-eth0<->s16-eth5 (OK OK) #h5-eth0<->s17-eth5 (OK OK) #h6-eth0<->s18-eth5 (OK OK) #h7-eth0<->s19-eth5 (OK OK) #h8-eth0<->s20-eth6 (OK OK) #h9-eth0<->s21-eth5 (OK OK) #h10-eth0<->s22-eth5 (OK OK) #h11-eth0<->s23-eth6 (OK OK) #h12-eth0<->s24-eth5 (OK OK) self.count = 0 self.isInstallFlows = False self.isReInstallFlows = False self.monitor_thread = hub.spawn(self._monitor)