neutron ml2


在介绍ml2之前,先介绍下以往的core-plugin,它主要的工作是与数据库打交道,真正起作用的是agent,然而对于每种core-plugin来说他们绝大部代码是重复的,在实际的网络部署中,想用linuxbridge就不能用openvswitch,想用vlan就不能用greMl2插件就可以很好解决这样的问题,在复杂的二层网络中可以灵活地部署网络。

Ml2插件是一种允许OpenStack网络同时地利用多种二层网络技术的框架。目前与openswitchlinuxbridgehyperv L2 agent协同工作。ml2框架对简化新增L2网络技术的做了很好支持,比起以往新增加的核心插件,ML2框架需要更少的初期以及后期维护工作。

 

ML2驱动包括类型驱动和机制驱动,分别实现了网络类型和网络机制的可扩展性。

1类型驱动(TypeDriver):

    类型驱动可以管理多种网络类型,目前支持local, flat, vlan, gre, vxlan等。

2机制驱动(MechanismDriver

    机制驱动处理由类型驱动建立的信息,并且确保能够用于指定的网络机制。机制驱动接口支持网络、子网、端口的创建、更新、删除操作。对每个资源,机制驱动暴露出两种方法ACTION_RESOURCE_precommit,和ACTION_RESOURCE_postcommit。这种precommit方法用于验证action是否有效和维护机制驱动的私有的数据库,并且这种方法不能被阻塞。postcommit主要负责操作资源。

举个例子,看下ciscoupdate_port机制驱动的两个方法,你可以自己跟踪一下, update_port_precommit维护自己私有的数据库,update_port_postcommit配置物理交换机。

    def update_port_precommit(self, context):

        port = context.current

        if self._is_deviceowner_compute(port) and self._is_status_active(port):

            self._port_action(context, self._configure_nxos_db)

 

def update_port_postcommit(self, context):

    port = context.current

        if self._is_deviceowner_compute(port) and self._is_status_active(port):

            self._port_action(context, self._configure_switch_entry)

 

Ml2工作机制:

  在ml2框架中实现了两个ManagerTypeManagerMechanismManager,分别管理类型驱动和网络驱动,TypeManager可以根据用户创建的网络类型调用相应的类型驱动,MechanismManager是根据计算节点的部署环境和neuron配置文件决定调用哪种机制驱动。

1)类型驱动:

不同的类型驱动都有自己的ml2_*TYPE*_allocations表,类型驱动主要工作维护自己的数据库表:

ml2_gre_allocations;

+-----------+------------+------+-----+---------+-------+

| Field     | Type       | Null | Key | Default | Extra |

+-----------+------------+------+-----+---------+-------+

| gre_id    | int(11)    | NO   | PRI | NULL    |       |

| allocated | tinyint(1) | NO   |     | NULL    |       |

+-----------+------------+------+-----+---------+-------+

 ml2_vlan_allocations;

+------------------+-------------+------+-----+---------+-------+

| Field            | Type        | Null | Key | Default | Extra |

+------------------+-------------+------+-----+---------+-------+

| physical_network | varchar(64) | NO   | PRI | NULL    |       |

| vlan_id          | int(11)     | NO   | PRI | NULL    |       |

| allocated        | tinyint(1)  | NO   |     | NULL    |       |

+------------------+-------------+------+-----+---------+-------+

2)机制驱动

机制驱动可以在openstack环境中同时使用不同的网络机制,那么他是如何工作的呢?假如我的计算节点Ac-a),部署了neutron-openvswitch-agent服务,当启动虚拟机时(指定网络id),nova-scheduler把虚拟机调度到c-a节点上,c-anova-compute服务会调用neutroncreate_port接口,其中create_port中会使用一个很重要的方法:bind_portMechanismManager),MechanismManager.bind_port会循环调用所有支持的网络机制的bind_port方法进行端口与agent绑定,绑定成功则返回。

openvswitch机制驱动bind_port主要根据调度到c-a的主机名和机制驱动的agent_type去数据库agents表中找对应的agent服务的信息(每种机制驱动都有自己的agent_typevif_typec-a的主机名是通过create_portdevice_owner获得的),再判断openvswitch是否支持端口所在的网络类型。经过上面的处理就把端口和openvswitch这种网络机制绑定起来。

具体操作如下:

MechanismManager

    def bind_port(self, context):

        binding = context._binding

        for driver in self.ordered_mech_drivers:#循环顺序调用

            try:

                driver.obj.bind_port(context)#调用机制驱动的bind_port

                if binding.segment:

                    binding.driver = driver.name              

                    return#绑定上则返回

            except Exception:

                LOG.exception(_("Mechanism driver %s failed in "

                                "bind_port"),

                              driver.name)

        binding.vif_type = portbindings.VIF_TYPE_BINDING_FAILED

 

 

MechanismDriver

    def bind_port(self, context):

        vnic_type = context.current.get(portbindings.VNIC_TYPE,

                                        portbindings.VNIC_NORMAL)

        if vnic_type not in self.supported_vnic_types:

            return   

        for agent in context.host_agents(self.agent_type):#根据agent_typebind_host从数据库表agents获去

            if agent['alive']:

                for segment in context.network.network_segments:

                    if self.try_to_bind_segment_for_agent(context, segment,

                                                          agent):#检测网络机制是否支持port所在网络的网络类型

                        return#绑定上则返回

            else:

                LOG.warning(_("Attempting to bind with dead agent: %s"),

                            agent)

 

绑定完成会在数据库中记录绑定的信息

ml2_port_bindings;

+--------------------------------------+--------+----------+-------------+--------------------------------------+-----------+------------------------------------------------+---------+

| port_id                              | host   | vif_type | driver      | segment                              | vnic_type | vif_details                                    | profile |

+--------------------------------------+--------+----------+-------------+--------------------------------------+-----------+------------------------------------------------+---------+

| 54259db7-68f2-4b33-a37c-8f134100f3fc | ubuntu | ovs      | openvswitch | 884cc396-ccec-4e56-9dc8-e6ccd3e7c9ea | normal    | {"port_filter": true, "ovs_hybrid_plug": true} |         |

| 5e1c574a-e345-4c65-889f-59bff79fa31d | ubuntu | ovs      | openvswitch | 884cc396-ccec-4e56-9dc8-e6ccd3e7c9ea | normal    | {"port_filter": true, "ovs_hybrid_plug": true} | {}      |

+--------------------------------------+--------+----------+-------------+--------------------------------------+-----------+------------------------------------------------+---------+

Nova端会根据vif_type使用不同的网络机制。

相关内容