Exemplo n.º 1
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.
    # 如果配置文件的列表为空,则加载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()
Exemplo n.º 2
0
    def switch_features_handler(self, ev):
        datapath = ev.msg.datapath
        self.datapaths[datapath.id] = datapath

        ofproto = datapath.ofproto
        parser = datapath.ofproto_parser


        # install table-miss flow entry
        #
        # We specify NO BUFFER to max_len of the output action due to
        # OVS bug. At this moment, if we specify a lesser number, e.g.,
        # 128, OVS will send Packet-In with invalid buffer_id and
        # truncated packet data. In that case, we cannot output packets
        # correctly.  The bug has been fixed in OVS v2.1.0.
        match = parser.OFPMatch()
        actions = [parser.OFPActionOutput(ofproto.OFPP_CONTROLLER,
                                          ofproto.OFPCML_NO_BUFFER)]
        self.add_flow(datapath, 0, match, actions)

        self.logger.debug("datapath id %s", datapath.id)

        match = parser.OFPMatch(eth_type=ether_types.ETH_TYPE_IP, ipv4_dst=ipAdd(datapath.id))
        actions = [parser.OFPActionOutput(1)]
        self.add_flow(datapath, 1, match, actions)

        hub.patch(socket=True, thread=True, os=True, select=True)
        if len(self.datapaths) == len(self.topo):
            # All switches have connected
            # Can call to install new path from here
            hub.spawn_after(10, self._cyclic_update)
Exemplo n.º 3
0
Arquivo: manager.py Projeto: 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()
Exemplo n.º 4
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()
Exemplo n.º 5
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()
Exemplo n.º 6
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()
Exemplo n.º 7
0
    def __init__(self, test_setup, launch_successful_future):
        """ If verification fails throw an exception, don't start ryu apps """
        if test_setup.integ_test is False:
            hub.patch(thread=True)
            assert_pipelined_not_running()

        self._test_setup = test_setup
        self.keep_running = True
        self.done = False
        self.event_queue = hub.Queue()
        thread = threading.Thread(target=self.start_ryu_apps,
                                  args=(launch_successful_future, ))
        thread.daemon = True
        thread.start()
Exemplo n.º 8
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()
Exemplo n.º 9
0
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()
Exemplo n.º 10
0
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()
Exemplo n.º 11
0
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))
Exemplo n.º 12
0
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'])
Exemplo n.º 13
0
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#	http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
# implied.
# See the License for the specific language governing permissions and
# limitations under the License.

from ryu.lib import hub
hub.patch(thread=False)

from ryu import cfg

import logging
from ryu import log
log.early_init_log(logging.DEBUG)

from ryu import flags
from ryu import version
from ryu.app import wsgi
from ryu.base.app_manager import AppManager
from ryu.controller import controller
from ryu.topology import switches

CONF = cfg.CONF
Exemplo n.º 14
0
from ryu.lib import hub
hub.patch()

import sys

from oslo_config import cfg
from oslo_log import log as logging

from ryu.base.app_manager import AppManager
from ryu import cfg as ryu_cfg

from daolicontroller import config

CONF = cfg.CONF
DEFAULT_CONFIG = ["/etc/nova/nova.conf"]

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'])
Exemplo n.º 15
0
#
#    Unless required by applicable law or agreed to in writing, software
#    distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
#    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
#    License for the specific language governing permissions and limitations
#    under the License.
#
# @author: Fumihiko Kakuma, VA Linux Systems Japan K.K.
# @author: YAMAMOTO Takashi, VA Linux Systems Japan K.K.

# NOTE: This module is used by Neutron "ofagent" agent for
# IceHouse release.  Juno and later releases do not use this.
# TODO: Remove this module when IceHouse is EOL'ed.

from ryu.lib import hub
hub.patch()

from ryu import cfg

from neutron.common import config as logging_config

from ryu.base.app_manager import AppManager


def main():
    cfg.CONF(project='ryu')
    logging_config.setup_logging(cfg.CONF)
    AppManager.run_apps(['neutron.plugins.ofagent.agent.ofa_neutron_agent'])


if __name__ == "__main__":
Exemplo n.º 16
0
#!/usr/bin/env python

from ryu.lib import hub
#hub.patch(thread=False)
hub.patch(thread=True)

import logging
import sys

from oslo_config import cfg

from ryu import cfg as ryu_cfg
from ryu import log
log.early_init_log(logging.DEBUG)

from ryu.base.app_manager import AppManager

CONF = cfg.CONF
CONF.register_cli_opts([
    cfg.BoolOpt('enable-debugger', default=False,
                help='don\'t overwrite Python standard threading library'
                '(use only for debugging)'),
])

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:
Exemplo n.º 17
0
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#    http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
# implied.
# See the License for the specific language governing permissions and
# limitations under the License.

from ryu.lib import hub
hub.patch(thread=False)

from ryu import cfg

import logging
from ryu import log
log.early_init_log(logging.DEBUG)

from ryu import flags
from ryu import version
from ryu.app import wsgi
from ryu.base.app_manager import AppManager
from ryu.controller import controller
from ryu.topology import switches

Exemplo n.º 18
0
def main(args=None, prog=None):

    print('aaa')
    try:
        print('aaa')
        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']
        print('bbb')
        app_lists = ['ryu.app.rest_firewall']

    app_mgr = AppManager.get_instance()
    app_mgr.load_apps(app_lists)
    contexts = app_mgr.create_contexts()
    print('contexts:')
    print(contexts)

    services = []
    services.extend(app_mgr.instantiate_apps(**contexts))

    webapp = wsgi.start_service(app_mgr)
    print('ccc')
    print(webapp)
    if webapp:
        thr = hub.spawn(webapp)
        services.append(thr)
    print('ddd')
    try:
        print(services[0])
        services[1].wait()
        print('eee3')
        services[0].wait()
        print('eee')
        hub.joinall(services)
        print('fff')
    except KeyboardInterrupt:
        logger.debug("Keyboard Interrupt received. "
                     "Closing RYU application manager...")
    finally:
        app_mgr.close()