Neutron OpenvSwitch agent工作原理

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


看一下openvswitch agent的启动:

[plain]  view plain  copy
  1. neutron/plugins/openvswitch/agent/ovs_neutron_agent.py:main()  
  2.     plugin = OVSNeutronAgent(**agent_config)  
  3.         self.setup_rpc()  
  4.             self.plugin_rpc = OVSPluginApi(topics.PLUGIN)  
  5.             self.state_rpc = agent_rpc.PluginReportStateAPI(topics.PLUGIN)  
  6.             self.connection = agent_rpc.create_consumers(...)  
  7.             heartbeat = loopingcall.FixedIntervalLoopingCall(self._report_state)  
  8.         self.setup_integration_br()  
  9.         self.setup_physical_bridges(bridge_mappings)  
  10.         self.sg_agent = OVSSecurityGroupAgent(...)  
  11.     plugin.daemon_loop()  
  12.         self.rpc_loop()  
  13.                     port_info = self.update_ports(ports)  
  14.                     sync = self.process_network_ports(port_info)  

启动时做了以下工作:

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处理添加/删除端口。


neutron-server和neutron-openvswitch-agent的消息队列如下:



neutron-server可能会发生上述四种消息广播给neutron-openvswitch-agent。openvswitch agent会先看一下端口是否在本地,如果在本地则进行对应动作。


最后看下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。