openstack學習之neutron_架構

neutron包括瞭如下幾個組成部分:rest API定義,neutron server和agent。

Rest API
包括標準API(Networking Rest API)和擴展API(Networking Rest API extensions)。該部分是neutron的對外訪問接口,neutron的所有功能全部通過這些api對外展現。

標準api
neutron的前身是nova-network。nova-network只實現了L2(OSI網絡模型的第二層,數據鏈路層)的網絡服務。這一層實現對虛擬機來說,相當於一塊網卡,並且網卡接入了一個交換機。如果不同的虛擬機網卡都接入了同一個交換機(或者不同的交換機,但交換機之間有級聯),這些虛擬機就都屬於同一個網絡了,可以互相通信。nova-network還提供了DHCP,floating IP功能。

nova-network沒有提供L3的功能,這就導致了一個限制,不同的網絡之間沒法通信(1個用戶創建了2個網絡,並且需要兩個網絡中的虛擬機互相通信)。這個問題可以通過floating ip來解決。具體介紹可以參考這篇文章http://www.mirantis.com/blog/vlanmanager-network-flow-analysis/
其中的scenario 6和scenario 7。

標準api的定義基於nova-network中的L2功能,核心的rest資源(resource)有network,subnet,port。

擴展API
neturon項目目標是能夠提供更多的網絡服務(涵蓋所有網絡層次)。擴展API就是neutron爲了描述這些新加的網絡服務。目前已有的擴展有L3(router),L4(TPC/udp firewall)及L7(http/https load balancer)。隨着neutron項目的不斷成熟,擴展API會逐漸變成標準api。

這些API都在openstack的官方文檔中有詳細說明,可以參考。

Neutron server(或者說是Rest API server)
實現neutron定義的API,包括標準和擴展兩部分。neutron server中又包括:
rest api:
實現標準API。

extension:
實現擴展API。neutron中定義了3中類型的extension,分別是:
ResourceExtension

"""Add top level resources to the OpenStack API in Neutron."""


ActionExtension
"""Add custom actions to core Neutron OpenStack API controllers."""

RequestExtension
    """Extend requests and responses of core Neutron OpenStack API controllers.
    Provide a way to add data to responses and handle custom request data
    that is sent to core Neutron OpenStack API controllers.
    """
目前neutron中的extension主要是第一種:resource extension。resource extension除了增加新的資源類型外,還可以給已有的資源增加屬性(Extended attributes for core resources)

rest api和extension只是實現了rest的前端框架部分,解析HTTP請求,並將該請求轉變爲對一個資源的操作。對資源的操作代碼不在前端實現,而是在後面介紹的plugin中實現。

core plugin:
rest的後端實現。前端的rest框架會調用plugin的相應方法來實現rest api規定的語義。
core plugin會有標準API的實現,及對network,subnet和port的各種操作。除了標準API外,還會實現一些extension API。不同的Plugin實現的extension API是不一樣的。可以查看plugin代碼中的_supported_extension_aliases屬性。

比如linux bridge plugin:
    _supported_extension_aliases = ["provider", "external-net", "router",
                                    "ext-gw-mode", "binding", "quotas",
                                    "security-group", "agent", "extraroute",
                                    "l3_agent_scheduler",
                                    "dhcp_agent_scheduler"]
比如openvswitch plugin:
    _supported_extension_aliases = ["provider", "external-net", "router",
                                    "ext-gw-mode", "binding", "quotas",
                                    "security-group", "agent", "extraroute",
                                    "l3_agent_scheduler",
                                    "dhcp_agent_scheduler",
                                    "extra_dhcp_opt",
                                    "allowed-address-pairs"]
可以看到ovs比linux bridge多支持了2個extension: extra_dhcp_opt和allowed-address-pairs。目前neturon中提供了很多的core plugin。每種plugin最核心的功能就是L2的支持,不同的plugin採用不同的技術實現。ovs和linuxbridge都是用軟件方法來實現虛擬交換機。有些Plugin可以使用硬件設備實現對虛擬機的支持,如cisco等。

網絡虛擬化技術
關鍵就是虛擬交換機(virtual ethernet bridging or VEB)。目前VEB有軟件和硬件的實現方式。
軟件實現的代表就是linux bridge和openvswitch。
硬件實現目前主要有兩個技術方案:IEEE 802.1Qbg Edge Virtual Bridging和IEEE 802.1BR Bridge Port Extension。可在網上查找先關資料。
IEEE 802.1Qbg Edge Virtual Bridging是由HP提出的方案,並被衆多廠商支持;EEE 802.1BR是有cisco提出的方案。目前兩個方案應該還沒有成爲正式標準。

網絡類型(tenant network type)
neutron定義了幾種網絡類型(網絡拓撲):local, flat, vlan, gre和vxlan。網絡類型的實現需要core plugin的支持。
linux bridge支持:local和vlan; ovs支持local, vlan, gre和vxlan。

service_plugins
除了core plugin外,neutron中又引入了service plugin的概念。service plugin用來實現extension API。對於extension是放在core plugin還是service plugin來實現,一般遵循:
如果是增加了新的資源類型並且該資源不依賴於L2層的實現,則放在service plugin中實現;如果是擴展已有資源(network, subnet,port)的屬性,則在core plugin中。
新增資源如:firwall, router, loadbalancer,vpn等。這些都有相應的service plugin: FirewallPlugin,L3RouterPlugin,LoadBalancerPlugin,VPNPlugin等。

目前很多core plugin也實現了router的功能,如linux bridge和openvswitch。從L3RouterPlugin的說明文檔中來看,這些應該放在service plugin中。services.l3_router.README
"This service plugin implements the L3 routing functionality (resources router
and floatingip) that in earlier releases before Havana was provided by core
plugins (openvswitch, linuxbridge, ... etc).
Core plugins can now choose not to implement L3 routing functionality and
instead delegate that to the L3 routing service plugin."

每個neturon server中可以加載多個service plugiin,但只能加載一個core plugin。neturon引入了ML2 core plugin,解決只能加載一個core plugin的限制。ML2 core plugin允許同時加載多個mechanism driver,可以達到同時使用不同的L2實現技術的效果。

neturon server啓動時候,根據配置文件動態加載相應的core plugin及service plugins。neturon server中會對收到的rest api請求進行解析,並最終轉換成對該plugin(core or service)中相應方法的調用。具體工作原理類似《openstack學習之RPC服務實現分析》講到的Service和Manager的工作方式,可以參看該文章。

數據模型
主要在db目錄中,定義neutron中的主要數據模型,實現數據模型在數據庫中的持久化操作。

agent
agent用來輔助plugin(core or service)完成其功能。plugin的某些功能需要操作遠程系統,這些情況一般都通過該系統上的agent來實現。根據功能的不同,agent可以有很多種:

core agent:
輔助core plugin的agent叫core agent(or L2 agent)。這個agent由core plugin還提供,放在core plugin的代碼目錄中。L2 agent需要安裝在所有需要接入虛擬網路的節點上(如compute node, dhcp node, L3 router node等)。L2 agent會根據neutron中定義的網絡模型,來配置底層的虛擬網絡實現(如linux bridge,openvswitch等),以實現neutron中的網絡定義。

dhcp agent:
負責給虛擬機分配IP地址。core plugin會調用dhcp agent完成ip管理分配等功能。core plugin通過繼承DhcpAgentSchedulerDbMixin來實現對dhcp agent的操作。dhcp agent可以安裝在任何節點上,neturon支持dhcp agent集羣(系統中運行多個dhcp agent實例),並且可以通過配置文件制定dhcp agent的調度策略。

L3 agent:
提供路由(router)功能,可以連接不同的tenant network。可以實現tenant network和外網(public)的連接,是外部用戶可以直接訪問改虛擬機。如可以給虛擬機分配一個Internet IP地址,就可以通過Internet訪問這臺機器。
service plugin(or core plugin)通過繼承L3AgentSchedulerPluginBase對L3 agent進行操作。和DHCP agent類似,l3 agnet可以安裝在任何節點上,neturon支持l3 agent集羣(系統中運行多個l3 agent實例),並且可以通過配置文件制定l3 agent的調度策略。

其他agents:
還有一些其他的agent,如metadata agent, metering agent, loadbalancer agent等,讀者可自行查看。

plugin和agent
plugin和agent之間是雙向交互的。plugin在實現rest api的過程中會調用agent;agent也會根據所在節點上的狀態來調用plugin來更新網絡的狀態。比如neturon中創建的port狀態默認是down的,core agent在配置好該port會更新改port的狀態爲up,即通過調用plugin完成。每個plugin會創建一個RPC server用來監聽agent的請求。

這幾個組成部分就介紹完了,後面會繼續寫一下neturon的運行時狀態及分析一下這幾個部分之間的交互。



發佈了29 篇原創文章 · 獲贊 8 · 訪問量 9萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章