コード例 #1
0
ファイル: manager.py プロジェクト: faramirs/wot
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()
コード例 #2
0
ファイル: tester.py プロジェクト: zhangbo4969/ryu-oe
 def close(self):
     if self.test_thread is not None:
         hub.kill(self.test_thread)
     if self.ingress_event:
         self.ingress_event.set()
     hub.joinall([self.test_thread])
     self._test_end('--- Test terminated ---')
コード例 #3
0
ファイル: tester.py プロジェクト: paisa4ever/ryu
 def close(self):
     if self.test_thread is not None:
         hub.kill(self.test_thread)
     if self.ingress_event:
         self.ingress_event.set()
     hub.joinall([self.test_thread])
     self._test_end('--- Test terminated ---')
コード例 #4
0
 def _disable_router(self):
     if self._arp_thread is not None:
         self._arp_thread.kill()
         hub.joinall([self._arp_thread])
         self._arp_thread = None
     # TODO: implement real routing logic
     self.logger.debug('TODO:_disable_router')
コード例 #5
0
ファイル: subscriber.py プロジェクト: markjen/magma
 def _activate_subscriber_rules(self):
     def activate_flows():
         ip_addr = convert_ip_str_to_ip_proto(self.cfg.ip)
         self._ec.activate_rules(
             imsi=self.cfg.imsi,
             msisdn=None,
             uplink_tunnel=None,
             ip_addr=ip_addr,
             apn_ambr=default_ambr_config,
             policies=self._policies,
             shard_id=0,
             local_f_teid_ng=0,
         )
         if self._esc:
             self._esc.activate_rules(
                 imsi=self.cfg.imsi,
                 msisdn=None,
                 uplink_tunnel=None,
                 ip_addr=ip_addr,
                 apn_ambr=default_ambr_config,
                 policies=self._policies,
                 shard_id=0,
                 local_f_teid_ng=0,
             )
     hub.joinall([hub.spawn(activate_flows)])
コード例 #6
0
ファイル: sample_router.py プロジェクト: AkiraSuu/ryu
 def _disable_router(self):
     if self._arp_thread is not None:
         self._arp_thread.kill()
         hub.joinall([self._arp_thread])
         self._arp_thread = None
     # TODO: implement real routing logic
     self.logger.debug('TODO:_disable_router')
コード例 #7
0
ファイル: manager.py プロジェクト: Qazzzz/ryu
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()
コード例 #8
0
ファイル: manager.py プロジェクト: unifycore/ryu
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()
コード例 #9
0
ファイル: manager.py プロジェクト: MrCocoaCat/ryu
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()
コード例 #10
0
 def close(self):
     self.is_active = False
     if self.link_discovery:
         self.lldp_event.set()
         self.link_event.set()
         self.msg_event.set()
         hub.joinall(self.threads)
コード例 #11
0
ファイル: subscriber.py プロジェクト: stjordanis/magma-1
    def _deactivate_subscriber_rules(self):
        if self._nuke_flows_on_exit:

            def deactivate_flows():
                self._ec.deactivate_rules(imsi=self.cfg.imsi, rule_ids=None)

            hub.joinall([hub.spawn(deactivate_flows)])
コード例 #12
0
ファイル: ofa_neutron_agent.py プロジェクト: Annjana/ryu
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()
コード例 #13
0
ファイル: manager.py プロジェクト: MichalPalatinus/ryu
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()
コード例 #14
0
ファイル: gauge_pollers.py プロジェクト: gizmoguy/faucet
 def stop(self):
     super(GaugeThreadPoller, self).stop()
     self._running = False
     if self.is_active():
         hub.kill(self.thread)
         hub.joinall([self.thread])
         self.thread = None
コード例 #15
0
ファイル: l2switczh.py プロジェクト: xianhuawei/utils
 def close(self):
     self.is_active = False
     if self.link_discovery:
         self.lldp_event.set()
         self.link_event.set()
         self.msg_event.set()
         hub.joinall(self.threads)
コード例 #16
0
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()
コード例 #17
0
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()
コード例 #18
0
ファイル: app_manager.py プロジェクト: MrCocoaCat/ryu
 def stop(self):
     if self.main_thread:
         hub.kill(self.main_thread)
     # 将标识设置为False
     self.is_active = False
     self._send_event(self._event_stop, None)
     hub.joinall(self.threads)
コード例 #19
0
ファイル: manager.py プロジェクト: shenerguang/ryu
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()
コード例 #20
0
 def stop(self):
     super(GaugeThreadPoller, self).stop()
     self._running = False
     if self.is_active():
         hub.kill(self.thread)
         hub.joinall([self.thread])
         self.thread = None
コード例 #21
0
ファイル: client.py プロジェクト: Aries-Sushi/ryu
    def stop(self):
        # NOTE(jkoelker) Stop the idl and event_proxy threads first
        #                letting them finish their current loop.
        self.is_active = False
        hub.joinall(self.threads)

        self._idl.close()
        super(RemoteOvsdb, self).stop()
コード例 #22
0
    def serve(self):
        send_thr = hub.spawn(self._send_loop)

        try:
            self._recv_loop()
        finally:
            hub.kill(send_thr)
            hub.joinall([send_thr])
コード例 #23
0
    def stop(self):
        # NOTE(jkoelker) Stop the idl and event_proxy threads first
        #                letting them finish their current loop.
        self.is_active = False
        hub.joinall(self.threads)

        self._idl.close()
        super(RemoteOvsdb, self).stop()
コード例 #24
0
    def serve(self):
        send_thr = hub.spawn(self._send_loop)

        try:
            self._recv_loop()
        finally:
            hub.kill(send_thr)
            hub.joinall([send_thr])
コード例 #25
0
    def _activate_subscriber_rules(self):
        def activate_flows():
            self._ec.activate_flows(imsi=self.cfg.imsi,
                                    ip_addr=self.cfg.ip,
                                    static_rule_ids=self._static_rule_names,
                                    dynamic_rules=self._dynamic_rules,
                                    fut=Future())

        hub.joinall([hub.spawn(activate_flows)])
コード例 #26
0
ファイル: manager.py プロジェクト: wwmm1/MC
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()
コード例 #27
0
ファイル: test_hub.py プロジェクト: 5g-empower/empower-ryu
    def test_spawn_exception_joinall(self):
        def _child():
            raise Exception("hoge")

        threads = []
        with hub.Timeout(2):
            threads.append(hub.spawn(_child))
            threads.append(hub.spawn(_child))
            hub.sleep(0.5)
            hub.joinall(threads)
コード例 #28
0
ファイル: test_hub.py プロジェクト: momor666/ryu
    def test_spawn_exception_joinall(self):
        def _child():
            raise Exception("hoge")

        threads = []
        with hub.Timeout(2):
            threads.append(hub.spawn(_child))
            threads.append(hub.spawn(_child))
            hub.sleep(0.5)
            hub.joinall(threads)
コード例 #29
0
ファイル: subscriber.py プロジェクト: rupa455/magma
    def _deactivate_subscriber_rules(self):
        ip_addr = convert_ip_str_to_ip_proto(self.cfg.ip)
        if self._nuke_flows_on_exit:

            def deactivate_flows():
                self._ec.deactivate_rules(imsi=self.cfg.imsi,
                                          ip_addr=ip_addr,
                                          rule_ids=None)

            hub.joinall([hub.spawn(deactivate_flows)])
コード例 #30
0
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()
コード例 #31
0
ファイル: oxp_super.py プロジェクト: bigclouds/ryu
    def serve(self):
        send_thr = hub.spawn(self._send_loop)

        hello = self.oxproto_parser.OXPHello(self)
        self.send_msg(hello)

        try:
            self._recv_loop()
        finally:
            hub.kill(send_thr)
            hub.joinall([send_thr])
コード例 #32
0
ファイル: flow_query.py プロジェクト: jaredmullane/docu_2
    def get_table_stats(test_controller):
        """
        Send an ovs request to retrieve all table stats, wait on queue
        """
        queue = hub.Queue()

        def request_table_stats():
            test_controller.table_stats_lookup(queue)

        hub.joinall([hub.spawn(request_table_stats)])
        return queue.get(block=True)
コード例 #33
0
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()
コード例 #34
0
ファイル: controller.py プロジェクト: beba-eu/beba-ctrl
    def serve(self):
        send_thr = hub.spawn(self._send_loop)

        # send hello message immediately
        hello = self.ofproto_parser.OFPHello(self)
        self.send_msg(hello)

        try:
            self._recv_loop()
        finally:
            hub.kill(send_thr)
            hub.joinall([send_thr])
コード例 #35
0
    def serve(self):
        send_thr = hub.spawn(self._send_loop)

        # send hello message immediately
        hello = self.ofproto_parser.OFPHello(self)
        self.send_msg(hello)

        try:
            self._recv_loop()
        finally:
            hub.kill(send_thr)
            hub.joinall([send_thr])
コード例 #36
0
ファイル: manager.py プロジェクト: huangkun93/ryu
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()
コード例 #37
0
ファイル: zserver.py プロジェクト: 5g-empower/empower-ryu
    def start(self):
        self.is_active = True
        self.sock.settimeout(GLOBAL_CONF.socket_timeout)

        self._threads.append(hub.spawn(self._send_loop))
        self._threads.append(hub.spawn(self._recv_loop))

        self.server.send_event_to_observers(
            zserver_event.EventZClientConnected(self))

        hub.joinall(self._threads)

        self.server.send_event_to_observers(
            zserver_event.EventZClientDisconnected(self))
コード例 #38
0
ファイル: flow_query.py プロジェクト: jaredmullane/docu_2
    def lookup(self):
        queue = hub.Queue()

        def get_stats():
            self._tc.ryu_query_lookup(
                _generate_ryu_req(self._table_id, self._match, self._cookie),
                queue)

        hub.joinall([hub.spawn(get_stats)])
        flows = queue.get(block=True)
        return [
            FlowStats(flow.packet_count, flow.byte_count, flow.duration_sec,
                      flow.cookie) for flow in flows
        ]
コード例 #39
0
ファイル: zserver.py プロジェクト: yonk42/ryu
    def start(self):
        self.is_active = True
        self.sock.settimeout(GLOBAL_CONF.socket_timeout)

        self._threads.append(hub.spawn(self._send_loop))
        self._threads.append(hub.spawn(self._recv_loop))

        self.server.send_event_to_observers(
            zserver_event.EventZClientConnected(self))

        hub.joinall(self._threads)

        self.server.send_event_to_observers(
            zserver_event.EventZClientDisconnected(self))
コード例 #40
0
ファイル: test_hub.py プロジェクト: momor666/ryu
    def test_spawn_kill_die_joinall(self):
        def _child(result):
            result.append(1)

        threads = []
        result = []
        with hub.Timeout(2):
            threads.append(hub.spawn(_child, result))
            threads.append(hub.spawn(_child, result))
            hub.sleep(0.5)
            for t in threads:
                hub.kill(t)
            hub.joinall(threads)
        assert len(result) == 2
コード例 #41
0
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()
コード例 #42
0
ファイル: daemon.py プロジェクト: rubiruchi/Dragon-Knight
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()
コード例 #43
0
ファイル: test_hub.py プロジェクト: 5g-empower/empower-ryu
    def test_spawn_kill_die_joinall(self):
        def _child(result):
            result.append(1)

        threads = []
        result = []
        with hub.Timeout(2):
            threads.append(hub.spawn(_child, result))
            threads.append(hub.spawn(_child, result))
            hub.sleep(0.5)
            for t in threads:
                hub.kill(t)
            hub.joinall(threads)
        assert len(result) == 2
コード例 #44
0
ファイル: manager.py プロジェクト: Jasonlyt/ryu
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()
コード例 #45
0
ファイル: test_hub.py プロジェクト: 5g-empower/empower-ryu
    def test_spawn_kill_nowait_joinall(self):
        # XXX this test relies on the scheduling behaviour.
        # the intention here is, killing threads before they get active.

        def _child(result):
            result.append(1)

        threads = []
        result = []
        with hub.Timeout(2):
            threads.append(hub.spawn(_child, result))
            for t in threads:
                hub.kill(t)
            hub.joinall(threads)
        assert len(result) == 0
コード例 #46
0
ファイル: test_hub.py プロジェクト: momor666/ryu
    def test_spawn_kill_nowait_joinall(self):
        # XXX this test relies on the scheduling behaviour.
        # the intention here is, killing threads before they get active.

        def _child(result):
            result.append(1)

        threads = []
        result = []
        with hub.Timeout(2):
            threads.append(hub.spawn(_child, result))
            for t in threads:
                hub.kill(t)
            hub.joinall(threads)
        assert len(result) == 0
コード例 #47
0
ファイル: subscriber.py プロジェクト: sanjay-ACL/magma
 def _activate_subscriber_rules(self):
     def activate_flows():
         self._ec.activate_rules(imsi=self.cfg.imsi,
                                 ip_addr=self.cfg.ip,
                                 apn_ambr=default_ambr_config,
                                 static_rule_ids=self._static_rule_names,
                                 dynamic_rules=self._dynamic_rules)
         if self._esc:
             self._esc.activate_rules(
                 imsi=self.cfg.imsi,
                 ip_addr=self.cfg.ip,
                 apn_ambr=default_ambr_config,
                 static_rule_ids=self._static_rule_names,
                 dynamic_rules=self._dynamic_rules)
     hub.joinall([hub.spawn(activate_flows)])
コード例 #48
0
ファイル: oxp_super.py プロジェクト: hu1uwa/ryu
    def serve(self):
        # TODO: entry point
        send_thr = hub.spawn(self._send_loop)

        # send hello message immediately
        #hello = self.ofproto_parser.OFPHello(self)
        #self.send_msg(hello)
        buf = "Server"
        self.socket.sendall(buf)

        try:
            self._recv_loop()
        finally:
            hub.kill(send_thr)
            hub.joinall([send_thr])
コード例 #49
0
ファイル: test_hub.py プロジェクト: 5g-empower/empower-ryu
    def test_spawn_kill_joinall(self):
        def _child(ev2, result):
            ev2.wait()
            result.append(1)

        ev2 = hub.Event()
        threads = []
        result = []
        with hub.Timeout(2):
            threads.append(hub.spawn(_child, ev2, result))
            threads.append(hub.spawn(_child, ev2, result))
            hub.sleep(0.5)
            for t in threads:
                hub.kill(t)
            hub.joinall(threads)
        assert len(result) == 0
コード例 #50
0
ファイル: controller.py プロジェクト: leftyLin/ryu
    def serve(self):
        send_thr = hub.spawn(self._send_loop)

        # send hello message immediately
        hello = self.ofproto_parser.OFPHello(self)
        self.send_msg(hello)

        echo_thr = hub.spawn(self._echo_request_loop)

        try:
            self._recv_loop()
        finally:
            hub.kill(send_thr)
            hub.kill(echo_thr)
            hub.joinall([send_thr, echo_thr])
            self.is_active = False
コード例 #51
0
ファイル: test_hub.py プロジェクト: momor666/ryu
    def test_spawn_kill_joinall(self):
        def _child(ev2, result):
            ev2.wait()
            result.append(1)

        ev2 = hub.Event()
        threads = []
        result = []
        with hub.Timeout(2):
            threads.append(hub.spawn(_child, ev2, result))
            threads.append(hub.spawn(_child, ev2, result))
            hub.sleep(0.5)
            for t in threads:
                hub.kill(t)
            hub.joinall(threads)
        assert len(result) == 0
コード例 #52
0
ファイル: test_hub.py プロジェクト: 5g-empower/empower-ryu
    def test_spawn_joinall(self):
        def _child(ev2, result):
            ev2.wait()
            hub.sleep(0.5)
            result.append(1)
            raise BaseException("this exception should not be propagated")

        ev2 = hub.Event()
        threads = []
        result = []
        with hub.Timeout(2):
            threads.append(hub.spawn(_child, ev2, result))
            threads.append(hub.spawn(_child, ev2, result))
            hub.sleep(0.5)
            ev2.set()  # this should wake up the above created two threads
            hub.joinall(threads)
        assert len(result) == 2
コード例 #53
0
ファイル: manager.py プロジェクト: Huangmachi/ryu
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()
コード例 #54
0
ファイル: app_manager.py プロジェクト: allen791210/ryu
    def run_apps(app_lists):
        """Run a set of Ryu applications

        A convenient method to load and instantiate apps.
        This blocks until all relevant apps stop.
        """
        app_mgr = AppManager.get_instance()
        app_mgr.load_apps(app_lists)
        contexts = app_mgr.create_contexts()
        services = app_mgr.instantiate_apps(**contexts)
        webapp = wsgi.start_service(app_mgr)
        if webapp:
            services.append(hub.spawn(webapp))
        try:
            hub.joinall(services)
        finally:
            app_mgr.close()
コード例 #55
0
ファイル: manager.py プロジェクト: Aries-Sushi/ryu
    def _bulk_read_handler(self, ev):
        results = []

        def done(gt, *args, **kwargs):
            if gt in self.threads:
                self.threads.remove(gt)

            results.append(gt.wait())

        threads = []
        for c in self._clients.values():
            gt = hub.spawn(c.read_request_handler, ev, bulk=True)
            threads.append(gt)
            self.threads.append(gt)
            gt.link(done)

        hub.joinall(threads)
        rep = event.EventReadReply(None, results)
        self.reply_to_request(ev, rep)
コード例 #56
0
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()
コード例 #57
0
ファイル: zclient.py プロジェクト: 5g-empower/empower-ryu
    def start(self):
        self.is_active = True
        try:
            self.sock = create_connection(self.client.zserv_addr)
        except socket.error as e:
            self.logger.exception(
                'Cannot connect to Zebra server%s: %s',
                self.client.zserv_addr, e)
            self.stop()
            return None

        self.sock.settimeout(GLOBAL_CONF.socket_timeout)

        self.threads.append(hub.spawn(self._send_loop))
        self.threads.append(hub.spawn(self._recv_loop))

        # Send the following messages at starting connection.
        # - ZEBRA_HELLO to register route_type
        # - ZEBRA_ROUTER_ID_ADD to get router_id
        # - ZEBRA_INTERFACE_ADD to get info for interfaces
        self.client.send_msg(
            zebra.ZebraMessage(
                version=self.client.zserv_ver,
                body=zebra.ZebraHello(
                    route_type=self.client.route_type,
                    instance=0)))
        self.client.send_msg(
            zebra.ZebraMessage(
                version=self.client.zserv_ver,
                body=zebra.ZebraRouterIDAdd()))
        self.client.send_msg(
            zebra.ZebraMessage(
                version=self.client.zserv_ver,
                body=zebra.ZebraInterfaceAdd()))

        self.client.send_event_to_observers(
            zclient_event.EventZServConnected(self))

        hub.joinall(self.threads)

        self.client.send_event_to_observers(
            zclient_event.EventZServDisconnected(self))
コード例 #58
0
ファイル: manager.py プロジェクト: changbl/ryu
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()
コード例 #59
0
ファイル: manager.py プロジェクト: hu1uwa/ryu
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()
コード例 #60
0
ファイル: app_manager.py プロジェクト: alanquillin/ryu
 def stop(self):
     if self.main_thread:
         hub.kill(self.main_thread)
     self.is_active = False
     self._send_event(self._event_stop, None)
     hub.joinall(self.threads)