def main(): common_config.init(sys.argv[1:]) # the following check is a transitional workaround to make this work # with different versions of ryu. # TODO(yamamoto) remove this later if ryu_cfg.CONF is not cfg.CONF: ryu_cfg.CONF(project='ryu', args=[]) common_config.setup_logging() AppManager.run_apps(['neutron.plugins.ofagent.agent.ofa_neutron_agent'])
def main(): common_config.init(sys.argv[1:]) # the following check is a transitional workaround to make this work # with different versions of ryu. # TODO(yamamoto) remove this later if ryu_cfg.CONF is not cfg.CONF: ryu_cfg.CONF(project="ryu", args=[]) common_config.setup_logging() AppManager.run_apps(["neutron.plugins.ofagent.agent.ofa_neutron_agent"])
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 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 main(): try: CONF(project='ryu', version='ofa_neutron_agent %s' % version, default_config_files=['/usr/local/etc/ryu/ryu.conf']) except cfg.ConfigFilesNotFoundError: CONF(project='ryu', version='ofa_neutron_agent %s' % version) osn_config.setup_logging(CONF) app_lists = CONF.app_lists + CONF.app if not app_lists: app_lists = ['neutron.plugins.ofagent.agent.ofa_neutron_agent'] app_mgr = AppManager.get_instance() app_mgr.load_apps(app_lists) contexts = app_mgr.create_contexts() services = [] services.extend(app_mgr.instantiate_apps(**contexts)) webapp = wsgi.start_service(app_mgr) if webapp: thr = hub.spawn(webapp) services.append(thr) try: hub.joinall(services) finally: app_mgr.close()
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 # keep old behaivor, run ofp if no application is specified. if not app_lists: app_lists = ['ryu.controller.ofp_handler'] app_mgr = AppManager.get_instance() app_mgr.load_apps(app_lists) contexts = app_mgr.create_contexts() services = [] services.extend(app_mgr.instantiate_apps(**contexts)) 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, chassis_name): self.next_network_id = 0 self.db_store = db_store.DbStore() self.chassis_name = chassis_name self.ip = cfg.CONF.df.local_ip self.tunnel_type = cfg.CONF.df.tunnel_type self.sync_finished = False nb_driver_class = importutils.import_class(cfg.CONF.df.nb_db_class) self.nb_api = api_nb.NbApi( nb_driver_class(), use_pubsub=cfg.CONF.df.enable_df_pub_sub) self.vswitch_api = ovsdb_vswitch_impl.OvsdbSwitchApi( self.ip, self.nb_api) kwargs = dict( nb_api=self.nb_api, vswitch_api=self.vswitch_api, db_store=self.db_store ) app_mgr = AppManager.get_instance() self.open_flow_app = app_mgr.instantiate(RyuDFAdapter, **kwargs) self.topology = None self.enable_selective_topo_dist = \ cfg.CONF.df.enable_selective_topology_distribution self.integration_bridge = cfg.CONF.df.integration_bridge
def main(): try: CONF(project='ryu', version='ofa_neutron_agent %s' % version, default_config_files=['/usr/local/etc/ryu/ryu.conf']) except cfg.ConfigFilesNotFoundError: CONF(project='ryu', version='ofa_neutron_agent %s' % version) osn_config.setup_logging(CONF) app_lists = CONF.app_lists + CONF.app if not app_lists: app_lists = [ 'ryu.app.ofctl.service', 'neutron.plugins.ofagent.agent.ofa_neutron_agent' ] app_mgr = AppManager.get_instance() app_mgr.load_apps(app_lists) contexts = app_mgr.create_contexts() services = [] services.extend(app_mgr.instantiate_apps(**contexts)) webapp = wsgi.start_service(app_mgr) if webapp: thr = hub.spawn(webapp) services.append(thr) try: hub.joinall(services) finally: app_mgr.close()
def main(args=None, prog=None): # 加载函数库 _parse_user_flags() # 加载配置文件 try: CONF(args=args, prog=prog, project='ryu', version='ryu-manager %s' % version, default_config_files=['/usr/local/etc/ryu/ryu.conf']) except cfg.ConfigFilesNotFoundError: CONF(args=args, prog=prog, project='ryu', version='ryu-manager %s' % version) log.init_log() logger = logging.getLogger(__name__) if CONF.enable_debugger: msg = 'debugging is available (--enable-debugger option is turned on)' logger.info(msg) else: hub.patch(thread=True) if CONF.pid_file: with open(CONF.pid_file, 'w') as pid_file: pid_file.write(str(os.getpid())) app_lists = CONF.app_lists + CONF.app # keep old behavior, run ofp if no application is specified. # 如果配置文件的列表为空,则加载ryu.controller.ofp_handler if not app_lists: app_lists = ['ryu.controller.ofp_handler'] # 创建实例,调用get_instance,实现单例模式 app_mgr = AppManager.get_instance() # 加载app_lists中的app app_mgr.load_apps(app_lists) # 创建上下文 contexts = app_mgr.create_contexts() services = [] services.extend(app_mgr.instantiate_apps(**contexts)) webapp = wsgi.start_service(app_mgr) if webapp: thr = hub.spawn(webapp) # 加入services列表 services.append(thr) try: # 对server服务列表遍历wait hub.joinall(services) except KeyboardInterrupt: # KeyboardInterrupt 用户中断执行(通常是输入^C) logger.debug("Keyboard Interrupt received. " "Closing RYU application manager...") finally: app_mgr.close()
def load(self): """ Instantiates and schedules the Ryu app eventlets in the service eventloop. """ # Some setups might not use REDIS if (self._magma_service.config['redis_enabled']): # Wait for redis as multiple controllers rely on it while not redisAvailable(self.rule_id_mapper.redis_cli): logging.warning("Pipelined waiting for redis...") time.sleep(1) else: self.rule_id_mapper._rule_nums_by_rule = {} self.rule_id_mapper._rules_by_rule_num = {} self.session_rule_version_mapper._version_by_imsi_and_rule = {} self.interface_to_prefix_mapper._prefix_by_interface = {} self.tunnel_id_mapper._tunnel_map = {} manager = AppManager.get_instance() manager.load_apps([app.module for app in self._apps]) contexts = manager.create_contexts() contexts['rule_id_mapper'] = self.rule_id_mapper contexts[ 'session_rule_version_mapper'] = self.session_rule_version_mapper contexts['interface_to_prefix_mapper'] = self.interface_to_prefix_mapper contexts['tunnel_id_mapper'] = self.tunnel_id_mapper contexts['app_futures'] = {app.name: Future() for app in self._apps} contexts['internal_ip_allocator'] = \ InternalIPAllocator(self._magma_service.config) contexts['config'] = self._magma_service.config contexts['mconfig'] = self._magma_service.mconfig contexts['loop'] = self._magma_service.loop contexts['service_manager'] = self sessiond_chan = ServiceRegistry.get_rpc_channel( 'sessiond', ServiceRegistry.LOCAL) mobilityd_chan = ServiceRegistry.get_rpc_channel( 'mobilityd', ServiceRegistry.LOCAL) contexts['rpc_stubs'] = { 'mobilityd': MobilityServiceStub(mobilityd_chan), 'sessiond': LocalSessionManagerStub(sessiond_chan), } # Instantiate and schedule apps for app in manager.instantiate_apps(**contexts): # Wrap the eventlet in asyncio so it will stop when the loop is # stopped future = aioeventlet.wrap_greenthread(app, self._magma_service.loop) # Schedule the eventlet for evaluation in service loop asyncio.ensure_future(future) # In development mode, run server so that if environment.is_dev_mode(): server_thread = of_rest_server.start(manager) future = aioeventlet.wrap_greenthread(server_thread, self._magma_service.loop) asyncio.ensure_future(future)
def initialize(self): app_mgr = AppManager.get_instance() LOG.debug(("RYU openflow stack, DragonFlow OpenFlow Controller")) l3app_kwargs = dict( idle_timeout=self.cfg.CONF.subnet_flows_idle_timeout, hard_timeout=self.cfg.CONF.subnet_flows_hard_timeout ) self.open_flow_hand = app_mgr.instantiate(OFPHandler, None, None) self.l3_app = app_mgr.instantiate(L3ReactiveApp, None, **l3app_kwargs)
def main(): """ Loads the Ryu apps we want to run from the config file. This should exit on keyboard interrupt. """ # Run asyncio loop in a greenthread so we can evaluate other eventlets # TODO: Remove once Ryu migrates to asyncio asyncio.set_event_loop_policy(aioeventlet.EventLoopPolicy()) service = MagmaService('pipelined') service_config = service.config if environment.is_dev_mode(): of_rest_server.configure(service_config) # Set Ryu config params cfg.CONF.ofp_listen_host = "127.0.0.1" # Load the ryu apps service_manager = ServiceManager(service) service_manager.load() def callback(returncode): if returncode != 0: logging.error( "Failed to set MASQUERADE: %d", returncode ) if service.mconfig.nat_enabled: call_process('iptables -t nat -A POSTROUTING -o %s -j MASQUERADE' % service.config['nat_iface'], callback, service.loop ) service.loop.create_task(monitor_ifaces( service.config['monitored_ifaces'], service.loop), ) manager = AppManager.get_instance() # Add pipelined rpc servicer pipelined_srv = PipelinedRpcServicer( service.loop, manager.applications.get('MeterStatsController', None), manager.applications.get('EnforcementController', None), manager.applications.get('EnforcementStatsController', None), manager.applications.get('DPIController', None), service_manager) pipelined_srv.add_to_server(service.rpc_server) # Run the service loop service.run() # Cleanup the service service.close()
def start_ryu_apps(self, launch_successful_future): """ Starts up ryu applications, all the configuration is parsed from the test_setup config provided in the unit test. If apps throw an exception on launch, error is passed in the launch_successful_future and will prevent infinitely waiting. """ self.reset_static_vars() hub.spawn(self._process_queue) app_lists = [a.value.name for a in self._test_setup.apps] app_futures = { controller.value.app_future: future for (controller, future) in self._test_setup.references.items() } manager = AppManager.get_instance() manager.load_apps(app_lists) contexts = manager.create_contexts() contexts['sids_by_ip'] = {} # shared by both metering apps contexts['rule_id_mapper'] = \ self._test_setup.service_manager.rule_id_mapper contexts['internal_ip_allocator'] = \ InternalIPAllocator(self._test_setup.config) contexts['session_rule_version_mapper'] = \ self._test_setup.service_manager.session_rule_version_mapper contexts['interface_to_prefix_mapper'] = \ self._test_setup.service_manager.interface_to_prefix_mapper contexts['restart_info_store'] = \ self._test_setup.service_manager.restart_info_store contexts['app_futures'] = app_futures contexts['config'] = self._test_setup.config contexts['mconfig'] = self._test_setup.mconfig contexts['loop'] = self._test_setup.loop contexts['rpc_stubs'] = self._test_setup.rpc_stubs contexts['service_manager'] = self._test_setup.service_manager contexts['ebpf_manager'] = None contexts['qos_manager'] = QosManager(self._test_setup.loop, self._test_setup.config) logging.basicConfig( level=logging.INFO, format='[%(asctime)s %(levelname)s %(name)s] %(message)s', ) services = [] try: services.extend(manager.instantiate_apps(**contexts)) except Exception as e: launch_successful_future.set_result( "Ryu apps launch exception: {}".format(e), ) raise launch_successful_future.set_result("Setup successful") self.run(manager)
def main(args=None, prog=None): _parse_user_flags() try: CONF(args=args, prog=prog, project='ryu', version='ryu-manager %s' % version, default_config_files=['/usr/local/etc/ryu/ryu.conf']) except cfg.ConfigFilesNotFoundError: CONF(args=args, prog=prog, project='ryu', version='ryu-manager %s' % version) log.init_log() logger = logging.getLogger(__name__) if CONF.enable_debugger: msg = 'debugging is available (--enable-debugger option is turned on)' logger.info(msg) else: hub.patch(thread=True) if CONF.pid_file: with open(CONF.pid_file, 'w') as pid_file: pid_file.write(str(os.getpid())) app_lists = CONF.app_lists + CONF.app # print('1:app_lists:',app_lists) #('1:app_lists:', []) # keep old behavior, run ofp if no application is specified. if not app_lists: app_lists = ['ryu.controller.ofp_handler'] app_mgr = AppManager.get_instance() # print('2:app_mgr',app_mgr) #('2:app_mgr', <ryu.base.app_manager.AppManager object at 0x7ff3ce974450>) app_mgr.load_apps(app_lists) # print('17:app_lists:',app_lists) #('17:app_lists:', ['ryu.controller.ofp_handler']) contexts = app_mgr.create_contexts() # print('22:contexts',contexts) #('22:contexts', {}) services = [] services.extend(app_mgr.instantiate_apps(**contexts)) # print('services:',services) #('services:', [<eventlet.greenthread.GreenThread object at 0x7f4f3540c190>]) webapp = wsgi.start_service(app_mgr) if webapp: thr = hub.spawn(webapp) services.append(thr) try: hub.joinall(services) except KeyboardInterrupt: logger.debug("Keyboard Interrupt received. " "Closing RYU application manager...") finally: app_mgr.close()
def __init__(self, *args, **kwargs): super(Loader, self).__init__(*args, **kwargs) self.feature_events = [] self.table_id = 0 self.ryu_mgr = AppManager.get_instance() self.install(OFPHandler) self.install(SwitchListen(lambda ev: self.switch_features_handler(ev))) self.start_listening()
def __init__(self, *args, **kwargs): super(DynamicLoader, self).__init__(*args, **kwargs) self.ryu_mgr = AppManager.get_instance() self.available_app = [] self.init_apps() wsgi = self.create_wsgi_app('0.0.0.0', 5566) self.mapper = wsgi.mapper wsgi.registory['DLController'] = self self.init_mapper()
def setUp(self): if not check_env(): raise SkipTest("Environment doesn't support this test.") self._topo_builder = None self.apps_under_test = [] self.mgr = AppManager.get_instance() self.mc = None self.controller_thread = threading.Thread( target=self._start_controller)
def main(args=None, prog=None): _parse_user_flags() try: CONF(args=args, prog=prog, project='ryu', version='ryu-manager %s' % version, default_config_files=['/usr/local/etc/ryu/ryu.conf']) except cfg.ConfigFilesNotFoundError: CONF(args=args, prog=prog, project='ryu', version='ryu-manager %s' % version) log.init_log() logger = logging.getLogger(__name__) if CONF.enable_debugger: msg = 'debugging is available (--enable-debugger option is turned on)' logger.info(msg) else: hub.patch(thread=True) if CONF.pid_file: with open(CONF.pid_file, 'w') as pid_file: pid_file.write(str(os.getpid())) app_lists = CONF.app_lists + CONF.app # keep old behavior, run ofp if no application is specified. if not app_lists: app_lists = ['ryu.controller.ofp_handler'] app_mgr = AppManager.get_instance() app_mgr.load_apps(app_lists) # sys.stdout.write("hello world!\n") contexts = app_mgr.create_contexts() services = [] services.extend(app_mgr.instantiate_apps(**contexts)) webapp = wsgi.start_service(app_mgr) if webapp: thr = hub.spawn(webapp) services.append(thr) try: hub.joinall(services) except KeyboardInterrupt: logger.debug("Keyboard Interrupt received. " "Closing RYU application manager...") finally: for name, app in app_mgr.applications.items(): if getattr(app, "set_xml", None): app.set_xml() app_mgr.close()
def main(args=None, prog=None): _parse_user_flags() try: CONF(args=args, prog=prog, project='ryu', version='ryu-manager %s' % version, default_config_files=['/usr/local/etc/ryu/ryu.conf']) except cfg.ConfigFilesNotFoundError: CONF(args=args, prog=prog, project='ryu', version='ryu-manager %s' % version) log.init_log() logger = logging.getLogger(__name__) if CONF.enable_debugger: msg = 'debugging is available (--enable-debugger option is turned on)' logger.info(msg) else: hub.patch(thread=True) if CONF.pid_file: with open(CONF.pid_file, 'w') as pid_file: pid_file.write(str(os.getpid())) app_lists = CONF.app_lists + CONF.app # keep old behavior, run ofp if no application is specified. if not app_lists: app_lists = ['ryu.controller.ofp_handler'] # step1: 实例化AppManager,是之后管理的基础 app_mgr = AppManager.get_instance() # step2:加载需要的服务,并不实例化,只是保存在对应字典中,还要加载每个app所需要的app app_mgr.load_apps(app_lists) # step3:实例化依赖模块,上面的APP可能需要其他模块服务,进行实例化 contexts = app_mgr.create_contexts() services = [] # step4:关键的一步,实例化app services.extend(app_mgr.instantiate_apps(**contexts)) webapp = wsgi.start_service(app_mgr) if webapp: thr = hub.spawn(webapp) services.append(thr) try: hub.joinall(services) except KeyboardInterrupt: logger.debug("Keyboard Interrupt received. " "Closing RYU application manager...") finally: app_mgr.close()
def main(args=None, prog=None): try: CONF(args=args, prog=prog, project='ryu', version='ryu-manager %s' % version, default_config_files=['/usr/local/etc/ryu/ryu.conf']) except cfg.ConfigFilesNotFoundError: CONF(args=args, prog=prog, project='ryu', version='ryu-manager %s' % version) log.init_log() if CONF.pid_file: import os with open(CONF.pid_file, 'w') as pid_file: pid_file.write(str(os.getpid())) app_lists = CONF.app_lists + CONF.app # keep old behaivor, run ofp if no application is specified. if not app_lists: app_lists = ['ryu.controller.ofp_handler'] #if CONF.oxp_role == 'super': # app_lists.extend(['ryu.openexchange.super.oxp_server_handler', # 'ryu.openexchange.super.topology', # 'ryu.openexchange.super.routing']) #elif CONF.oxp_role == 'domain': # app_lists.extend( # ['ryu.openexchange.domain.oxp_client_handler', # 'ryu.openexchange.network.abstract', # 'ryu.openexchange.network.topo_reply', # 'ryu.openexchange.network.echo_loop', # 'ryu.openexchange.domain.translation']) app_mgr = AppManager.get_instance() app_mgr.load_apps(app_lists) contexts = app_mgr.create_contexts() services = [] services.extend(app_mgr.instantiate_apps(**contexts)) webapp = wsgi.start_service(app_mgr) if webapp: thr = hub.spawn(webapp) services.append(thr) try: hub.joinall(services) finally: app_mgr.close()
def TracePacket(self, request, context): if not self._service_manager.is_app_enabled( PacketTracingController.APP_NAME): context.set_code(grpc.StatusCode.UNAVAILABLE) context.set_details('Service not enabled!') return PacketDropTableId(table_id=-1) manager = AppManager.get_instance() drop_table_id = manager.applications[PacketTracingController.__name__] \ .trace_packet(request.pkt, request.imsi) return PacketDropTableId(table_id=drop_table_id)
def run(self): self.nb_api = ovsdb_nb_impl.OvsdbNbApi(self.remote_db_ip) #self.nb_api = etcd_nb_impl.EtcdNbApi() self.nb_api.initialize() self.vswitch_api = ovsdb_vswitch_impl.OvsdbSwitchApi(self.ip) self.vswitch_api.initialize() app_mgr = AppManager.get_instance() self.open_flow_app = app_mgr.instantiate(OFPHandler, None, None) self.open_flow_app.start() self.l2_app = app_mgr.instantiate(L2App, None, None) self.l2_app.start() self.db_sync_loop()
def main(args=None, prog=None): try: CONF(args=args, prog=prog, project='ryu', version='ryu-manager {}'.format(version), default_config_files=['/usr/local/etc/ryu/ryu.conf']) except cfg.ConfigFilesNotFoundError: CONF(args=args, prog=prog, project='ryu', version='ryu-manager {}'.format(version)) log.init_log() hub.patch(thread=True) if CONF.pid_file: LOG.info('Pid file : %s', CONF.pid_file) import os with open(CONF.pid_file, 'w') as pid_file: pid_file.write(str(os.getpid())) app_lists = CONF.app_lists + CONF.app if not app_lists: app_lists = ['ryu.controller.ofp_handler', 'dragon_knight.dk_plugin'] if 'ryu.controller.ofp_handler' not in app_lists: app_lists.append('ryu.controller.ofp_handler') if 'dragon_knight.dk_plugin' not in app_lists: app_lists.append('dragon_knight.dk_plugin') app_mgr = AppManager.get_instance() app_mgr.load_apps(app_lists) contexts = app_mgr.create_contexts() services = [] services.extend(app_mgr.instantiate_apps(**contexts)) webapp = wsgi.start_service(app_mgr) if webapp: thr = hub.spawn(webapp) services.append(thr) try: hub.joinall(services) finally: app_mgr.close()
def main(): args = sys.argv[1:] try: CONF(args=args, prog=sys.argv[0], project='daolicontroller', version='1.1', default_config_files=['/etc/daolicontroller/daolicontroller.conf']) except cfg.ConfigFilesNotFoundError: CONF(args=args, prog=sys.argv[0], project='daolicontroller', version='1.1') log.init_log() #if ryu_cfg.CONF is not CONF: # ryu_cfg.CONF(args=args, project='ryu') #if CONF.enable_debugger: # LOG = logging.getLogger('daolicontroller') # msg = 'debugging is available (--enable-debugger option is turned on)' # LOG.info(msg) #else: #hub.patch(thread=True) AppManager.run_apps(['daolicontroller.ofa_agent'])
def main(args=None, prog=None): try: CONF( args=args, prog=prog, project="ryu", version="ryu-manager {}".format(version), default_config_files=["/usr/local/etc/ryu/ryu.conf"], ) except cfg.ConfigFilesNotFoundError: CONF(args=args, prog=prog, project="ryu", version="ryu-manager {}".format(version)) log.init_log() hub.patch(thread=True) if CONF.pid_file: LOG.info("Pid file : %s", CONF.pid_file) import os with open(CONF.pid_file, "w") as pid_file: pid_file.write(str(os.getpid())) app_lists = CONF.app_lists + CONF.app if not app_lists: app_lists = ["ryu.controller.ofp_handler", "dragon_knight.dk_plugin"] if "ryu.controller.ofp_handler" not in app_lists: app_lists.append("ryu.controller.ofp_handler") if "dragon_knight.dk_plugin" not in app_lists: app_lists.append("dragon_knight.dk_plugin") app_mgr = AppManager.get_instance() app_mgr.load_apps(app_lists) contexts = app_mgr.create_contexts() services = [] services.extend(app_mgr.instantiate_apps(**contexts)) 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, chassis_name): self.next_network_id = 0 self.db_store = db_store.DbStore() self.nb_api = None self.vswitch_api = None self.chassis_name = chassis_name self.ip = cfg.CONF.df.local_ip self.tunnel_type = cfg.CONF.df.tunnel_type self.sync_finished = False kwargs = dict( db_store=self.db_store ) app_mgr = AppManager.get_instance() self.open_flow_app = app_mgr.instantiate(RyuDFAdapter, **kwargs)
def load(self): app_mgr = AppManager.get_instance() self.open_flow_app = app_mgr.instantiate(OFPHandler, None, None) self.open_flow_app.start() for app in self.apps_list: app_class_name = self.apps_location_prefix + "." + app try: app_class = importutils.import_class(app_class_name) app = app_mgr.instantiate(app_class, None, **self.params) app.start() self.apps.append(app) except ImportError as e: LOG.exception(_LE("Error loading application by class, %s"), e) raise ImportError(_("Application class not found."))
def main(args=None, prog=None): try: CONF( args=args, prog=prog, project='daolicontroller', version='1.1', default_config_files=['/etc/daolicontroller/daolicontroller.conf']) except cfg.ConfigFilesNotFoundError: CONF(args=args, prog=prog, project='daolicontroller', version='1.1') log.init_log() if ryu_cfg.CONF is not CONF: ryu_cfg.CONF(args=args, project='ryu') if CONF.enable_debugger: LOG = logging.getLogger('daolicontroller') msg = 'debugging is available (--enable-debugger option is turned on)' LOG.info(msg) else: hub.patch(thread=True) AppManager.run_apps(['daolicontroller.ofa_agent'])
def main(args=None, prog=None): try: CONF(args=args, prog=prog, project='ryu', version='ryu-manager %s' % version, default_config_files=['/usr/local/etc/ryu/ryu.conf']) except cfg.ConfigFilesNotFoundError: CONF(args=args, prog=prog, project='ryu', version='ryu-manager %s' % version) log.init_log() if CONF.enable_debugger: LOG = logging.getLogger('ryu.cmd.manager') msg = 'debugging is available (--enable-debugger option is turned on)' LOG.info(msg) else: hub.patch(thread=True) if CONF.pid_file: import os with open(CONF.pid_file, 'w') as pid_file: pid_file.write(str(os.getpid())) app_lists = CONF.app_lists + CONF.app # keep old behaivor, run ofp if no application is specified. if not app_lists: app_lists = ['ryu.controller.ofp_handler'] app_mgr = AppManager.get_instance() app_mgr.load_apps(app_lists) contexts = app_mgr.create_contexts() services = [] services.extend(app_mgr.instantiate_apps(**contexts)) webapp = wsgi.start_service(app_mgr) if webapp: thr = hub.spawn(webapp) services.append(thr) try: hub.joinall(services) finally: app_mgr.close()
def main(args=None, prog=None): try: CONF(args=args, prog=prog, project='ryu', version='ryu-manager %s' % version, default_config_files=['/usr/local/etc/ryu/ryu.conf']) except cfg.ConfigFilesNotFoundError: CONF(args=args, prog=prog, project='ryu', version='ryu-manager %s' % version) log.init_log() logger = logging.getLogger(__name__) if CONF.enable_debugger: msg = 'debugging is available (--enable-debugger option is turned on)' logger.info(msg) else: hub.patch(thread=True) if CONF.pid_file: import os with open(CONF.pid_file, 'w') as pid_file: pid_file.write(str(os.getpid())) app_lists = CONF.app_lists + CONF.app # keep old behavior, run ofp if no application is specified. if not app_lists: app_lists = ['ryu.controller.ofp_handler'] app_mgr = AppManager.get_instance() app_mgr.load_apps(app_lists) contexts = app_mgr.create_contexts() services = [] services.extend(app_mgr.instantiate_apps(**contexts)) webapp = wsgi.start_service(app_mgr) if webapp: thr = hub.spawn(webapp) services.append(thr) try: hub.joinall(services) except KeyboardInterrupt: logger.debug("Keyboard Interrupt received. " "Closing RYU application manager...") finally: app_mgr.close()
def load(self): """ Instantiates and schedules the Ryu app eventlets in the service eventloop. """ manager = AppManager.get_instance() manager.load_apps([app.module for app in self._apps]) contexts = manager.create_contexts() contexts['rule_id_mapper'] = RuleIDToNumMapper() contexts[ 'session_rule_version_mapper'] = self.session_rule_version_mapper contexts['app_futures'] = {app.name: Future() for app in self._apps} contexts['config'] = self._magma_service.config contexts['mconfig'] = self._magma_service.mconfig contexts['loop'] = self._magma_service.loop contexts['service_manager'] = self records_chan = ServiceRegistry.get_rpc_channel('meteringd_records', ServiceRegistry.CLOUD) sessiond_chan = ServiceRegistry.get_rpc_channel( 'sessiond', ServiceRegistry.LOCAL) mobilityd_chan = ServiceRegistry.get_rpc_channel( 'mobilityd', ServiceRegistry.LOCAL) contexts['rpc_stubs'] = { 'metering_cloud': MeteringdRecordsControllerStub(records_chan), 'mobilityd': MobilityServiceStub(mobilityd_chan), 'sessiond': LocalSessionManagerStub(sessiond_chan), } # Instantiate and schedule apps for app in manager.instantiate_apps(**contexts): # Wrap the eventlet in asyncio so it will stop when the loop is # stopped future = aioeventlet.wrap_greenthread(app, self._magma_service.loop) # Schedule the eventlet for evaluation in service loop asyncio.ensure_future(future) # In development mode, run server so that if environment.is_dev_mode(): server_thread = of_rest_server.start(manager) future = aioeventlet.wrap_greenthread(server_thread, self._magma_service.loop) asyncio.ensure_future(future)
def main(): log.init_log() app_mgr = AppManager.get_instance() app_mgr.load_apps(['./ryu_controller.py']) contexts = app_mgr.create_contexts() services = [] services.extend(app_mgr.instantiate_apps(**contexts)) webapp = wsgi.start_service(app_mgr) if webapp: thr = hub.spawn(webapp) services.append(thr) print services try: hub.joinall(services) finally: app_mgr.close()
def run(self): sb_db_connection = ('tcp:%s:6640' % self.sb_db_ip) self.ovsdb_sb = connection.Connection(sb_db_connection, 10, 'OVN_Southbound') local_connection = ('tcp:%s:6640' % self.ip) self.ovsdb_local = connection.Connection(local_connection, 10, 'Open_vSwitch') self.ovsdb_sb.start() self.ovsdb_local.start() self.idl_sb = self.ovsdb_sb.idl self.idl = self.ovsdb_local.idl app_mgr = AppManager.get_instance() self.open_flow_app = app_mgr.instantiate(OFPHandler, None, None) self.open_flow_app.start() self.l2_app = app_mgr.instantiate(L2App, None, None) self.l2_app.start() self.db_sync_loop()
def run(self): #self.nb_api = ovsdb_nb_impl.OvsdbNbApi(self.remote_db_ip) self.nb_api = ramcloud_nb_impl.RamcloudNbApi(db_ip=self.remote_db_ip) self.nb_api.initialize() self.vswitch_api = ovsdb_vswitch_impl.OvsdbSwitchApi(self.ip) self.vswitch_api.initialize() app_mgr = AppManager.get_instance() self.open_flow_app = app_mgr.instantiate(OFPHandler, None, None) self.open_flow_app.start() kwargs = dict( db_store=self.db_store ) self.l2_app = app_mgr.instantiate(L2App, None, **kwargs) self.l2_app.start() self.l3_app = app_mgr.instantiate(L3App, None, **kwargs) self.l3_app.start() while self.l2_app.dp is None or self.l3_app.dp is None: time.sleep(5) self.db_sync_loop()
def __init__(self, chassis_name): self.next_network_id = 0 self.db_store = db_store.DbStore() self.chassis_name = chassis_name self.ip = cfg.CONF.df.local_ip self.tunnel_type = cfg.CONF.df.tunnel_type self.sync_finished = False nb_driver_class = importutils.import_class(cfg.CONF.df.nb_db_class) self.nb_api = api_nb.NbApi(nb_driver_class(), use_pubsub=cfg.CONF.df.enable_df_pub_sub) self.vswitch_api = ovsdb_vswitch_impl.OvsdbSwitchApi( self.ip, self.nb_api) kwargs = dict(nb_api=self.nb_api, vswitch_api=self.vswitch_api, db_store=self.db_store) app_mgr = AppManager.get_instance() self.open_flow_app = app_mgr.instantiate(RyuDFAdapter, **kwargs) self.topology = None self.enable_selective_topo_dist = \ cfg.CONF.df.enable_selective_topology_distribution
def real_main(): LOGGER.info('I win leader election, Ryu controller start running') app_lists = CONF.app_lists + CONF.app # keep old behaivor, run ofp if no application is specified. if not app_lists: app_lists = ['ryu.controller.ofp_handler'] app_mgr = AppManager.get_instance() app_mgr.load_apps(app_lists) contexts = app_mgr.create_contexts() services = [] services.extend(app_mgr.instantiate_apps(**contexts)) webapp = wsgi.start_service(app_mgr) if webapp: thr = hub.spawn(webapp) services.append(thr) try: hub.joinall(services) finally: app_mgr.close()
def main(args=None, prog=None): try: CONF(args=args, prog=prog, project='ryu', version='ryu-manager %s' % version, default_config_files=['/usr/local/etc/ryu/ryu.conf']) except cfg.ConfigFilesNotFoundError: CONF(args=args, prog=prog, project='ryu', version='ryu-manager %s' % version) log.init_log() if CONF.pid_file: import os with open(CONF.pid_file, 'w') as pid_file: pid_file.write(str(os.getpid())) app_lists = CONF.app_lists + CONF.app # keep old behaivor, run ofp if no application is specified. if not app_lists: app_lists = ['ryu.controller.ofp_handler'] # add oxp_handler #app_lists.append('ryu.openexchange.oxp_handler') app_mgr = AppManager.get_instance() app_mgr.load_apps(app_lists) contexts = app_mgr.create_contexts() services = [] services.extend(app_mgr.instantiate_apps(**contexts)) webapp = wsgi.start_service(app_mgr) if webapp: thr = hub.spawn(webapp) services.append(thr) try: hub.joinall(services) finally: app_mgr.close()
def main(args=None, prog=None): try: CONF(args=args, prog=prog, project='ryu', version='ryu-manager %s' % version, default_config_files=['/usr/local/etc/ryu/ryu.conf']) except cfg.ConfigFilesNotFoundError: CONF(args=args, prog=prog, project='ryu', version='ryu-manager %s' % version) log.init_log() logger = logging.getLogger(__name__) if CONF.enable_debugger: msg = 'debugging is available (--enable-debugger option is turned on)' logger.info(msg) else: hub.patch(thread=True) if CONF.pid_file: import os with open(CONF.pid_file, 'w') as pid_file: pid_file.write(str(os.getpid())) app_lists = CONF.app_lists + CONF.app print(app_lists) # keep old behavior, run ofp if no application is specified. if not app_lists: #app_lists = ['ryu.controller.ofp_handler'] app_lists = ['ryu.app.rest_firewall'] app_mgr = AppManager.get_instance() app_mgr.load_apps(app_lists) contexts = app_mgr.create_contexts() services = [] services.extend(app_mgr.instantiate_apps(**contexts))
def __init__(self, ryu_app): app_mgr = AppManager.get_instance() self.ofctl_app = app_mgr.instantiate(OfctlService) self.ofctl_app.start() self._app = ryu_app
def main(): """ Loads the Ryu apps we want to run from the config file. This should exit on keyboard interrupt. """ # Run asyncio loop in a greenthread so we can evaluate other eventlets # TODO: Remove once Ryu migrates to asyncio asyncio.set_event_loop_policy(aioeventlet.EventLoopPolicy()) service = MagmaService('pipelined', mconfigs_pb2.PipelineD()) # Optionally pipe errors to Sentry sentry_init(service_name=service.name) service_config = service.config if environment.is_dev_mode(): of_rest_server.configure(service_config) # Set Ryu config params cfg.CONF.ofp_listen_host = "127.0.0.1" # override mconfig using local config. # TODO: move config compilation to separate module. enable_nat = service.config.get('enable_nat', service.mconfig.nat_enabled) service.config['enable_nat'] = enable_nat logging.info("Nat: %s", enable_nat) vlan_tag = service.config.get( 'sgi_management_iface_vlan', service.mconfig.sgi_management_iface_vlan, ) service.config['sgi_management_iface_vlan'] = vlan_tag sgi_ip = service.config.get( 'sgi_management_iface_ip_addr', service.mconfig.sgi_management_iface_ip_addr, ) service.config['sgi_management_iface_ip_addr'] = sgi_ip sgi_gateway_ip = service.config.get( 'sgi_management_iface_gw', service.mconfig.sgi_management_iface_gw, ) service.config['sgi_management_iface_gw'] = sgi_gateway_ip # Keep router mode off for smooth upgrade path service.config['dp_router_enabled'] = service.config.get( 'dp_router_enabled', False, ) if 'virtual_mac' not in service.config: if service.config['dp_router_enabled']: up_bridge_name = service.config.get( 'uplink_bridge', UPLINK_OVS_BRIDGE_NAME, ) mac_addr = get_if_hwaddr(up_bridge_name) else: mac_addr = get_if_hwaddr(service.config.get('bridge_name')) service.config['virtual_mac'] = mac_addr # this is not read from yml file. service.config['uplink_port'] = OFPP_LOCAL uplink_port_name = service.config.get('ovs_uplink_port_name', None) if enable_nat is False and uplink_port_name is not None: service.config['uplink_port'] = BridgeTools.get_ofport( uplink_port_name, ) # header enrichment related configuration. service.config['proxy_port_name'] = PROXY_PORT_NAME he_enabled_flag = False if service.mconfig.he_config: he_enabled_flag = service.mconfig.he_config.enable_header_enrichment he_enabled = service.config.get('he_enabled', he_enabled_flag) service.config['he_enabled'] = he_enabled # monitoring related configuration mtr_interface = service.config.get('mtr_interface', None) if mtr_interface: mtr_ip = get_ip_from_if(mtr_interface) service.config['mtr_ip'] = mtr_ip # Load the ryu apps service_manager = ServiceManager(service) service_manager.load() def callback(returncode): if returncode != 0: logging.error( "Failed to set MASQUERADE: %d", returncode, ) # TODO fix this hack for XWF if enable_nat is True or service.config.get('setup_type') == 'XWF': call_process( 'iptables -t nat -A POSTROUTING -o %s -j MASQUERADE' % service.config['nat_iface'], callback, service.loop, ) service.loop.create_task( monitor_ifaces( service.config['monitored_ifaces'], ), ) manager = AppManager.get_instance() # Add pipelined rpc servicer pipelined_srv = PipelinedRpcServicer( service.loop, manager.applications.get('GYController', None), manager.applications.get('EnforcementController', None), manager.applications.get('EnforcementStatsController', None), manager.applications.get('DPIController', None), manager.applications.get('UEMacAddressController', None), manager.applications.get('CheckQuotaController', None), manager.applications.get('IPFIXController', None), manager.applications.get('VlanLearnController', None), manager.applications.get('TunnelLearnController', None), manager.applications.get('Classifier', None), manager.applications.get('InOutController', None), manager.applications.get('NGServiceController', None), service.config, service_manager, ) pipelined_srv.add_to_server(service.rpc_server) if service.config['setup_type'] == 'CWF': bridge_ip = service.config['bridge_ip_address'] has_quota_port = service.config['has_quota_port'] no_quota_port = service.config['no_quota_port'] def on_exit_server_thread(): service.StopService(None, None) # For CWF start quota check servers start_check_quota_server( run_flask, bridge_ip, has_quota_port, True, on_exit_server_thread, ) start_check_quota_server( run_flask, bridge_ip, no_quota_port, False, on_exit_server_thread, ) if service.config['setup_type'] == 'LTE': polling_interval = service.config.get( 'ovs_gtp_stats_polling_interval', MIN_OVSDB_DUMP_POLLING_INTERVAL, ) collector = GTPStatsCollector( polling_interval, service.loop, ) collector.start() # Run the service loop service.run() # Cleanup the service service.close()
def main(): cfg.CONF(project='ryu') logging_config.setup_logging(cfg.CONF) AppManager.run_apps(['neutron.plugins.ofagent.agent.ofa_neutron_agent'])
def main(): config.parse_args(sys.argv, default_config_files=DEFAULT_CONFIG) if ryu_cfg.CONF is not CONF: ryu_cfg.CONF(project='ryu', args=[]) logging.setup(CONF, "daolicontroller") AppManager.run_apps(['daolicontroller.ofa_agent'])
def main(): config.init(sys.argv[1:], default_config_files=DEFAULT_CONFIG) if ryu_cfg.CONF is not cfg.CONF: ryu_cfg.CONF(project='ryu', args=[]) config.setup_logging() AppManager.run_apps(['daoliagent.ofa_agent'])
import logging logging.basicConfig(level=logging.DEBUG) class Echo(WebSocketHandler): def initialize(self, clients=[]): super(Echo, self).initialize() self.clients = clients def open(self): self.clients.append(self) def on_message(self, message): for client in self.clients: client.write_message("hello") def close(self): print "bye" ws_clients = [] Application([ ("/echo", Echo, {"clients":ws_clients}), ], static_path=os.path.join(os.path.dirname(__file__), "html")).listen(8888) apps = AppManager() apps.load_apps(["ryu.controller.ofp_handler", "ryu.app.simple_switch", "ofc2ws"]) contexts = apps.create_contexts() contexts["ws_clients"] = ws_clients apps.instantiate_apps(**contexts) OpenflowController().listen(6633) IOLoop.instance().start()
def _start_controller(self): # Actually start running a controller thread AppManager.run_apps(self.apps_under_test)
def reset_static_vars(self): """ Reset static vars for running nosetests """ AppManager._instance = AppManager() MagmaController.TABLES = {}