- 整体结构
- bin
- doc
- etc
- init.d/
- neutron/
- api-paste.ini
- dhcp_agent.ini
- fwaas_driver.ini
- l3_agent.ini
- lbaas_agent.ini
- metadata_agent.ini
- metering_agent.ini
- vpn_agent.ini
- neutron.conf
- policy.json
- rootwrap.conf
- services.conf
- neutron
- agent
- common/
- linux/
- metadata/
- dhcp_agent.py
- firewall.py
- l2population_rpc.py
- l3_agent.py
- l3_ha_agent.py
- netns_cleanup_util.py
- ovs_cleanup_util.py
- rpc.py
- securitygroups_rpc.py
- api
- rpc
- v2
- views
- api_common.py
- extensions.py
- versions.py
- cmd
- common
- config.py
- constants.py
- exceptions.py
- ipv6_utils.py
- log.py
- rpc.py
- test_lib.py
- topics.py
- utils.py
- db
- agents_db.py
- agentschedulers_db.py
- api.py
- common_db_mixin.py
- db_base_plugin_v2.py
- migration
- model_base.py
- models_v2.py
- securitygroups_rpc_base.py
- sqlalchemyutils.py
- 扩展资源和操作类
- allowedaddresspairs_db.py
- dvr_mac_db.py
- external_net_db.py
- extradhcpopt_db.py
- extraroute_db.py
- firewall
- l3_agentschedulers_db.py
- l3_attrs_db.py
- l3_db.py
- l3_dvr_db.py
- l3_gwmode_db.py
- l3_hamode_db.py
- l3_hascheduler_db.py
- loadbalancer
- metering
- portbindings_base.py
- portbindings_db.py
- portsecurity_db.py
- quota_db.py
- routedserviceinsertion_db.py
- routerservicetype_db.py
- securitygroups_db.py
- servicetype_db.py
- vpn
- debug
- commands.py
- debug_agent.py
- shell.py
- extensions
- agent.py
- allowedaddresspairs.py
- dhcpagentscheduler.py
- dvr.py
- external_net.py
- extraroute.py
- extra_dhcp_opt.py
- firewall.py
- flavor.py
- l3.py
- l3agentscheduler.py
- l3_ext_gw_mode.py
- lbaas_agentscheduler.py
- loadbalancer.py
- metering.py
- multiprovidernet.py
- portbindings.py
- portsecurity.py
- providernet.py
- quotasv2.py
- routedserviceinsertion.py
- routerservicetype.py
- securitygroup.py
- servicetype.py
- vpnaas.py
- hacking
- checks.py
- locale
- notifiers
- nova.py
- openstack
- common
- cache
- context.py
- eventlet_backdoor.py
- fileutils.py
- fixture
- local.py
- lockutils.py
- log.py
- loopingcall.py
- middleware
- periodic_task.py
- policy.py
- processutils.py
- service.py
- systemd.py
- threadgroup.py
- uuidutils.py
- versionutils.py
- _i18n.py
- plugins
- bigswitch
- agent
- common
- ibm
- agent
- common
- sdnve_api.py
- sdnve_api_fake.py
- sdnve_neutron_plugin.py
- ml2
- common
- config.py
- db.py
- drivers
- driver_api.py
- driver_context.py
- managers.py
- models.py
- plugin.py
- rpc.py
- ofagent
- agent
- common
- openvswitch
- agent
- common
- ovs_models_v2.py
- scheduler
- dhcp_agent_scheduler.py
- l3_agent_scheduler.py
- server
- services
- firewall
- agents
- drivers
- fwaas_plugin.py
- l3_apic.py
- l3_router_plugin.py
- loadbalancer
- agent
- agent_scheduler.py
- constants.py
- drivers
- plugin.py
- metering
- agents
- drivers
- metering_plugin.py
- provider_configuration.py
- service_base.py
- tests
- auth.py
- context.py
- hooks.py
- i18n.py
- manager.py
- neutron_plugin_base_v2.py
- policy.py
- quota.py
- service.py
- version.py
- wsgi.py
- rally-jobs
- extra
- plugins
- __init__.py
- neutron-neutron.yaml
- tools
- check_bash.sh
- check_i18n.py
- check_i18n_test_case.txt
- clean.sh
- i18n_cfg.py
- install_venv.py
- install_venv_common.py
- pretty_tox.sh
- with_venv.sh
- 理解代码
- REST API 专题
- RPC 专题
- agent RPC
- plugin RPC
- neutron-server RPC
- Plugin 专题
- Extension 专题
- Agent 专题
agent
agent
主要包括xenapi目录(xen相关)、ovs_neutron_agent.py和ovs_dvr_neutron_agent.py文件(运行在各个节点上的对网桥进行操作的代理)。
ovs_neutron_agent.py文件main函数主要过程如下:
def main():
cfg.CONF.register_opts(ip_lib.OPTS)
common_config.init(sys.argv[1:])
common_config.setup_logging(cfg.CONF)
logging_config.setup_logging(cfg.CONF)
q_utils.log_opt_values(LOG)
try:
agent_config = create_agent_config_map(cfg.CONF)
except ValueError as e:
LOG.error(_('%s Agent terminated!'), e)
sys.exit(1)
is_xen_compute_host = 'rootwrap-xen-dom0' in agent_config['root_helper']
if is_xen_compute_host:
# Force ip_lib to always use the root helper to ensure that ip
# commands target xen dom0 rather than domU.
cfg.CONF.set_default('ip_lib_force_root', True)
agent = OVSNeutronAgent(**agent_config)
signal.signal(signal.SIGTERM, handle_sigterm)
# Start everything.
LOG.info(_("Agent initialized successfully, now running... "))
agent.daemon_loop()
sys.exit(0)
首先是读取各种配置信息,然后提取agent相关的属性。
然后生成一个agent实例(OVSNeutronAgent类),并调用其daemon_loop()函数,该函数进一步执行rpc_loop()。
OVSNeutronAgent类初始化的时候,会依次调用setup_rpc()、setup_integration_br()和setup_physical_bridges()。
ovs_dvr_neutron_agent.py文件是neutron实现分布式路由器设计时的agent。
setup_rpc()
setup_rpc()首先创建了两个rpc句柄,分别是
self.plugin_rpc = OVSPluginApi(topics.PLUGIN)
self.state_rpc = agent_rpc.PluginReportStateAPI(topics.PLUGIN)
其中,前者是与neutron-server(准确的说是ovs plugin)进行通信,通过rpc消息调用plugin的方法。这些消息在neutron.agent.rpc.PluginApi类中定义,包括get_device_details、get_devices_details_list、update_device_down、update_device_up、tunnel_sync、security_group_rules_for_devices等。
后者是agent定期将自身的状态上报给neutron-server。
之后,创建dispatcher和所关注的消息主题:
self.dispatcher = self.create_rpc_dispatcher()
# Define the listening consumers for the agent
consumers = [[topics.PORT, topics.UPDATE],
[topics.NETWORK, topics.DELETE],
[constants.TUNNEL, topics.UPDATE],
[topics.SECURITY_GROUP, topics.UPDATE]]
这样,neutron-server发到这四个主题的消息,会被agent接收到。agent会检查端口是否在本地,如果在本地则进行对应动作。
创建消费者rpc连接来接收rpc消息:
self.connection = agent_rpc.create_consumers(self.dispatcher,
self.topic,
consumers)
最后,创建heartbeat,定期的调用self._report_state(),通过state_rpc来汇报本地状态。
图表 3展示了这一过程,是一个很好的理解agent端的rpc实现的例子。
setup_integration_br()
清除integration网桥上的int_peer_patch_port端口和流表,添加一条normal流。
setup_physical_bridges()
创建准备挂载物理网卡的网桥,添加一条normal流,然后创建veth对,连接到integration网桥,添加drop流规则,禁止未经转换的流量经过veth对。
上一篇:openvswitch
下一篇:common

发布评论
需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。