neutron openvswitch agent源码分析

本文详细分析了neutron-openvswitch-agent的启动过程,从启动脚本到OVS应用的启动,包括配置文件的加载、网桥与流表的创建、RPC服务的设置。主要内容涉及ovs_neutron_agent的main()方法调用,native模式下的启动,Ryu的使用,以及如何根据配置创建和管理br-int、br-tun和物理网络相关的br-phys网桥。此外,还讨论了流表规则的设定,特别是arp_responder的响应机制,并介绍了两个主要的定时任务及其功能。
摘要由CSDN通过智能技术生成

1.neutron-openvswitch-agent启动脚本定义在/usr/bin/neutron-openvswitch-agent中,它调用了ovs_neutron_agent中的main()方法。

启动命令:

usr/bin/python2 /usr/bin/neutron-openvswitch-agent --config-file /usr/share/neutron/neutron-dist.conf --config-file /etc/neutron/neutron.conf --config-file /etc/neutron/plugins/ml2/openvswitch_agent.ini --config-dir /etc/neutron/conf.d/common --config-dir /etc/neutron/conf.d/neutron-openvswitch-agent --log-file /var/log/neutron/openvswitch-agent.log

2.该方法又调用了ovs agent中的main()方法。

neutron/cmd/eventlet/plugins/ovs_neutron_agent.py
def main():
    agent_main.main()

3.根据of_interface的配置,包含ovs-ofctl和native两种方式,执行具体的启动流程。

neutron/plugins/ml2/drivers/openvswitch/agent/main.py

def main():

    common_config.init(sys.argv[1:])

    driver_name = cfg.CONF.OVS.of_interface

    mod_name = _main_modules[driver_name]

    mod = importutils.import_module(mod_name)

    mod.init_config()

    common_config.setup_logging()

    profiler.setup("neutron-ovs-agent", cfg.CONF.host)

    mod.main()

4.根据neutron.conf中的默认配置,执行native中的mian()方法。

neutron/plugins/ml2/drivers/openvswitch/agent/openflow/native/main.py

def main():

    app_manager.AppManager.run_apps([

        'neutron.plugins.ml2.drivers.openvswitch.agent.'

        'openflow.native.ovs_ryuapp',

    ])

5.通过Ryu启动OVS应用,调用ovs agent的main()方法。

neutron/plugins/ml2/drivers/openvswitch/agent/openflow/native/ovs_ryuapp.py

def agent_main_wrapper(bridge_classes):

    try:

        ovs_agent.main(bridge_classes)

    except Exception:

        with excutils.save_and_reraise_exception():

            LOG.exception("Agent main thread died of an exception")

    finally:

        # The following call terminates Ryu's AppManager.run_apps(),

        # which is needed for clean shutdown of an agent process.

        # The close() call must be called in another thread, otherwise

        # it suicides and ends prematurely.

        hub.spawn(app_manager.AppManager.get_instance().close)



class OVSNeutronAgentRyuApp(app_manager.RyuApp):

    OFP_VERSIONS = [ofproto_v1_3.OFP_VERSION]



    def start(self):

        # Start Ryu event loop thread

        super(OVSNeutronAgentRyuApp, self).start()



        def _make_br_cls(br_cls):

            return functools.partial(br_cls, ryu_app=self)



        # Start agent main loop thread

        bridge_classes = {

            'br_int': _make_br_cls(br_int.OVSIntegrationBridge),

            'br_phys': _make_br_cls(br_phys.OVSPhysicalBridge),

            'br_tun': _make_br_cls(br_tun.OVSTunnelBridge),

        }

        return hub.spawn(agent_main_wrapper, bridge_classes, raise_error=True)

6.加载配置文件、插件,校验配置项,创建ovs agent实例,daemon_loop()方法定时更新端口信息。

neutron/plugins/ml2/drivers/openvswitch/agent/ovs_neutron_agent.py

def main(bridge_classes):

    prepare_xen_compute()

    ovs_capabilities.register()

    ext_manager.register_opts(cfg.CONF)



    ext_mgr = ext_manager.L2AgentExtensionsManager(cfg.CONF)



    # now that all extensions register
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值