Neutron-server初始化 — Neutron L2 Agent服务初始化

OpenvSwitch,简称OVS是一个虚拟交换软件,主要用于虚拟机VM环境,作为一个虚拟交换机,支持Xen/XenServer, KVM, and VirtualBox多种虚拟化技术。在这种某一台机器的虚拟化的环境中,一个虚拟交换机(vswitch)主要有两个作用:1. 传递虚拟机VM之间的流量。2. 实现VM和外界网络的通信。

在openstack中目前用的比较多的L2层agent应该就是openvswitch agent了。本文大致分析了一下openvswithc agent做了哪些事。

Ovs agent初始化

以常用的openvswitch agent为例,可以执行以下命令启动agent服务:
CLI:

service neutron-openvswitch-agent start

setup.cfg配置文件的以下内容可以知道,实际执行的方法是:
neutron.plugins.openvswitch.agent.ovs_neutron_agent:main

[entry_points]  
console-scripts =   
    ...  
    neutron-openvswitch-agent = neutron.plugins.openvswitch.agent.ovs_neutron_agent:main  
    ...
a. 启动过程解析

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

def main(bridge_classes):
    try:
        # 从配置文件中读取agent的配置,主要是network_mappings,各个bridges名称 
        agent_config = create_agent_config_map(cfg.CONF)
    except ValueError:
        LOG.exception(_LE("Agent failed to create agent config map"))
        raise SystemExit(1)
    prepare_xen_compute()
    validate_local_ip(agent_config['local_ip'])
    try:
        # 创建agent实例
        agent = OVSNeutronAgent(bridge_classes, **agent_config)
    except (RuntimeError, ValueError) as e:
        LOG.error(_LE("%s Agent terminated!"), e)
        sys.exit(1)
    # Agent initialized successfully
    agent.daemon_loop()

启动时做了以下工作:
1. 设置plugin_rpc,这是用来与neutron-server通信的。
2. 设置state_rpc,用于agent状态信息上报。
3. 设置connection,用于接收neutron-server的消息。
4. 启动状态周期上报。
5. 设置br-int。
6. 设置bridge_mapping对应的网桥。
7. 初始化sg_agent,用于处理security group。
8. 周期检测br-int上的端口变化,调用process_network_ports处理添加/删除端口。

b. neutron-server/nova与ovs agent的交互解析
  1. neutron-server和neutron-openvswitch-agent的消息队列如下:
    这里写图片描述
    neutron-server可能会发生上述四种消息广播给neutron-openvswitch-agent。openvswitch agent会先看一下端口是否在本地,如果在本地则进行对应动作。

  2. nova与neutron-openvswitch-agent的交互,这张图片来源于GongYongSheng在香港峰会的PPT:
    这里写图片描述
    首先boot虚机时,nova-compute发消息给neutron-server请求创建port。之后,在driver里面在br-int上建立port后,neutron-openvswitch-port循环检测br-int会发现新增端口,对其设定合适的openflow规则以及localvlan,最后将port状态设置为ACTIVE。

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

c. OVSNeutronAgent函数解析

在OVSNeutronAgent的docstring中,概要说明了agent实现虚拟的方式,有以下几点:
1) 创建br-int, br-tun以及每个物理网络接口一个bridge。
2) 虚拟机的虚拟网卡都会接入到br-int。使用同一个虚拟网络的虚拟网卡共享一个local的VLAN(与外部网络的VLAN无关,vlan id可以重叠)。这个local的VLAN id会映射到外部网络的某个VLAN id。
3) 对于network_type是VLAN或者FLAT的网络,在br-int和各个物理网络bridge之间创建一个虚拟网卡,用于限定流规则、映射或者删除VLAN id等处理。
4) 对于network_type是GRE的,每个租户在不同hypervisor之间的网络通信通过一个逻辑交换机标识符(Logical Switch identifier)进行区分,并创建一个连通各个hypervisor的br-tun的通道(tunnel)网络。Port patching用于连通br-int和各个hypervisor的br-tun上的VLAN。

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

class OVSNeutronAgent(sg_rpc.SecurityGroupAgentRpcCallbackMixin,
                      l2population_rpc.L2populationRpcCallBackTunnelMixin,
                      dvr_rpc.DVRAgentRpcCallbackMixin):
    '''Implements OVS-based tunneling, VLANs and flat networks.

    Two local bridges are created: an integration bridge (defaults to
    'br-int') and a tunneling bridge (defaults to 'br-tun'). An
    additional bridge is created for each physical network interface
    used for VLANs and/or flat networks.

    All VM VIFs are plugged into the integration bridge. VM VIFs on a
    given virtual network share a common "local" VLAN (i.e. not
    propagated externally). The VLAN id of this local VLAN is mapped
    to the physical networking details realizing that virtual network.

    For virtual networks realized as GRE tunnels, a Logical Switch
    (LS) identifier is used to differentiate tenant traffic on
    inter-HV tunnels. A mesh of tunnels is created to other
    Hypervisors in the cloud. These tunnels originate and terminate on
    the tunneling bridge of each hypervisor. Port patching is done to
    connect local VLANs 
  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值