原文地址: https://blogs.oracle.com/ronen/entry/diving_into_openstack_network_architecture2網絡
譯文轉自:http://blog.csdn.net/halcyonbaby/article/details/41604459oracle
前文中,咱們學習了openstack網絡使用的幾個基本網絡組件,並經過一些簡單的use case解釋網絡如何連通的。本文中,咱們會經過一個稍微複雜(其實仍然至關基本)的use case(兩個網絡間路由)探索網絡的設置。 路由使用的組件與連通內部網絡相同,使用namespace建立一個隔離的container,容許subnet間的網絡包中轉。
記住咱們在第一篇文章中所說的,這只是使用OVS插件的例子。openstack還有不少插件使用不一樣的方式,咱們提到的只是其中一種。oop
Use case #4: Routing traffic between two isolated networks
現實中,咱們會建立不一樣的網絡用於不一樣的目的。咱們也會須要把這些網絡鏈接起來。由於兩個網絡在不一樣的IP段,咱們須要router將他們鏈接起來。爲了分析這種設置,咱們建立另外一個network(net2)並配置一個20.20.20.0/24的subnet。在建立這個network後,咱們啓動一個Oracle Linux的虛擬機,並鏈接到net2。下圖是從OpenstackGUI上看到的網絡拓撲圖:學習
![](http://static.javashuo.com/static/loading.gif)
進一步探索,咱們會在openstack網絡節點上看到另外一個namespace,這個namespace用於爲新建立的網絡提供服務。如今咱們有兩個namespace,每一個network一個。spa
- # ip netns list
- qdhcp-63b7fcf2-e921-4011-8da9-5fc2444b42dd
- qdhcp-5f833617-6179-4797-b7c0-7d420d84040c
能夠經過nova net-list查看network的ID信息,或者使用UI查看網絡信息。.net
- # nova net-list
- +--------------------------------------+-------+------+
- | ID | Label | CIDR |
- +--------------------------------------+-------+------+
- | 5f833617-6179-4797-b7c0-7d420d84040c | net1 | None |
- | 63b7fcf2-e921-4011-8da9-5fc2444b42dd | net2 | None |
- +--------------------------------------+-------+------+
咱們新建立的network,net2有本身的namespace,這個namespace與net1是分離的。在namespace中,咱們能夠看到兩個網絡接口,一個local,一個是用於DHCP服務。 插件
- # ip netns exec qdhcp-63b7fcf2-e921-4011-8da9-5fc2444b42dd ip addr
- 1: lo: mtu 65536 qdisc noqueue state UNKNOWN
- link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
- inet 127.0.0.1/8 scope host lo
- inet6 ::1/128 scope host
- valid_lft forever preferred_lft forever
- 19: tap16630347-45: mtu 1500 qdisc noqueue state UNKNOWN
- link/ether fa:16:3e:bd:94:42 brd ff:ff:ff:ff:ff:ff
- inet 20.20.20.3/24 brd 20.20.20.255 scope global tap16630347-45
- inet6 fe80::f816:3eff:febd:9442/64 scope link
- valid_lft forever preferred_lft forever
net1和net2兩個network沒有被聯通,咱們須要建立一個router,經過router將兩個network聯通。Openstack Neutron向用戶提供了建立router並將兩個或多個network鏈接的能力。router其實只是一個額外的namespace。使用Neutron建立router能夠經過GUI或者命令行操做:命令行
- # neutron router-create my-router
- Created a new router:
- +-----------------------+--------------------------------------+
- | Field | Value |
- +-----------------------+--------------------------------------+
- | admin_state_up | True |
- | external_gateway_info | |
- | id | fce64ebe-47f0-4846-b3af-9cf764f1ff11 |
- | name | my-router |
- | status | ACTIVE |
- | tenant_id | 9796e5145ee546508939cd49ad59d51f |
- +-----------------------+--------------------------------------+
如今咱們將兩個netwrok經過router鏈接:code
查看subnet的ID:router
- # neutron subnet-list
- +--------------------------------------+------+---------------+------------------------------------------------+
- | id | name | cidr | allocation_pools |
- +--------------------------------------+------+---------------+------------------------------------------------+
- | 2d7a0a58-0674-439a-ad23-d6471aaae9bc | | 10.10.10.0/24 | {"start": "10.10.10.2", "end": "10.10.10.254"} |
- | 4a176b4e-a9b2-4bd8-a2e3-2dbe1aeaf890 | | 20.20.20.0/24 | {"start": "20.20.20.2", "end": "20.20.20.254"} |
- +--------------------------------------+------+---------------+------------------------------------------------+
將subnet 10.10.10.0/24添加到router:
- # neutron router-interface-add fce64ebe-47f0-4846-b3af-9cf764f1ff11 subnet=2d7a0a58-0674-439a-ad23-d6471aaae9bc
- Added interface 0b7b0b40-f952-41dd-ad74-2c15a063243a to router fce64ebe-47f0-4846-b3af-9cf764f1ff11.
將subnet 20.20.20.0/24添加到router:
- # neutron router-interface-add fce64ebe-47f0-4846-b3af-9cf764f1ff11 subnet=4a176b4e-a9b2-4bd8-a2e3-2dbe1aeaf890
- Added interface dc290da0-0aa4-4d96-9085-1f894cf5b160 to router fce64ebe-47f0-4846-b3af-9cf764f1ff11.
此時,咱們在查看網絡拓撲會發現兩個網絡被router打通:
![](http://static.javashuo.com/static/loading.gif)
咱們還能夠發現兩個網絡接口鏈接到router,做爲各自subnet的gateway。
咱們能夠看到爲router建立的namespace。
- # ip netns list
- qrouter-fce64ebe-47f0-4846-b3af-9cf764f1ff11
- qdhcp-63b7fcf2-e921-4011-8da9-5fc2444b42dd
- qdhcp-5f833617-6179-4797-b7c0-7d420d84040c
咱們進入namespace內部能夠看到:
- # ip netns exec qrouter-fce64ebe-47f0-4846-b3af-9cf764f1ff11 ip addr
- 1: lo: mtu 65536 qdisc noqueue state UNKNOWN
- link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
- inet 127.0.0.1/8 scope host lo
- inet6 ::1/128 scope host
- valid_lft forever preferred_lft forever
- 20: qr-0b7b0b40-f9: mtu 1500 qdisc noqueue state UNKNOWN
- link/ether fa:16:3e:82:47:a6 brd ff:ff:ff:ff:ff:ff
- inet 10.10.10.1/24 brd 10.10.10.255 scope global qr-0b7b0b40-f9
- inet6 fe80::f816:3eff:fe82:47a6/64 scope link
- valid_lft forever preferred_lft forever
- 21: qr-dc290da0-0a: mtu 1500 qdisc noqueue state UNKNOWN
- link/ether fa:16:3e:c7:7c:9c brd ff:ff:ff:ff:ff:ff
- inet 20.20.20.1/24 brd 20.20.20.255 scope global qr-dc290da0-0a
- inet6 fe80::f816:3eff:fec7:7c9c/64 scope link
- valid_lft forever preferred_lft forever
咱們看到兩個網絡接口,「qr-dc290da0-0a「 和 「qr-0b7b0b40-f9。這兩個網絡接口鏈接到OVS上,使用兩個network/subnet的gateway IP。
- # ovs-vsctl show
- 8a069c7c-ea05-4375-93e2-b9fc9e4b3ca1
- Bridge "br-eth2"
- Port "br-eth2"
- Interface "br-eth2"
- type: internal
- Port "eth2"
- Interface "eth2"
- Port "phy-br-eth2"
- Interface "phy-br-eth2"
- Bridge br-ex
- Port br-ex
- Interface br-ex
- type: internal
- Bridge br-int
- Port "int-br-eth2"
- Interface "int-br-eth2"
- Port "qr-dc290da0-0a"
- tag: 2
- Interface "qr-dc290da0-0a"
- type: internal
- Port "tap26c9b807-7c"
- tag: 1
- Interface "tap26c9b807-7c"
- type: internal
- Port br-int
- Interface br-int
- type: internal
- Port "tap16630347-45"
- tag: 2
- Interface "tap16630347-45"
- type: internal
- Port "qr-0b7b0b40-f9"
- tag: 1
- Interface "qr-0b7b0b40-f9"
- type: internal
- ovs_version: "1.11.0"
咱們能夠看到,這些接口鏈接到」br-int",並打上了所在network對應的VLAN標籤。這裏咱們能夠經過gateway地址(20.20.20.1)成功的ping通router namespace:
![](http://static.javashuo.com/static/loading.gif)
咱們還能夠看到IP地址爲20.20.20.2能夠ping通IP地址爲10.10.10.2的虛擬機:
![](http://static.javashuo.com/static/loading.gif)
兩個subnet經過namespace中的網絡接口互相連通。在namespace中,Neutron將系統參數net.ipv4.ip_forward設置爲1。命令查看以下:
- # ip netns exec qrouter-fce64ebe-47f0-4846-b3af-9cf764f1ff11 sysctl net.ipv4.ip_forward
- net.ipv4.ip_forward = 1
咱們能夠看到namespace中的系統參數net.ipv4.ip_forward被設置,這種設置不會對namespace外產生影響。
總結
建立router時,Neutron會建立一個叫qrouter-的namespace。subnets經過OVS的br-int網橋上的網絡接口接入router。網絡接口被設置了正確的VLAN,從而能夠連入它們對應的network。例子中,網絡接口qr-0b7b0b40-f9的IP被設置爲10.10.10.1,VLAN標籤爲1,它能夠鏈接到「net1」。經過在namespace中設置系統參數net.ipv4.ip_forward爲1,從而容許路由生效。
本文介紹瞭如何使用network namespace建立一個router。下一篇文章中,咱們會探索浮動IP如何使用iptables工做。這也許更復雜可是依然使用這些基本的網絡組件。