天天看點

GRE and VXLAN with Open vSwitch

因為在OpenStack的Neutron中比較常用,是以參考别人的部落格試了下OVS的一些隧道封裝功能(GRE,VXLAN)。

實驗:實作兩個host的Network namespace之間的通信,NS可以了解為host裡的VM(VM通過NS隔離,參考資料裡涉及到了VM,KVM還不熟悉,這裡就略掉了),如下圖所示:

<a href="http://s1.51cto.com/wyfs02/M01/83/A6/wKiom1d5xYTS3S6fAACTGwzDcvc576.png-wh_500x0-wm_3-wmp_4-s_904513884.png" target="_blank"></a>

在host1中建立一個network namespace <code>red</code>,以及一對veth(veth0,veth1)

,其中veth0添加到<code>red</code>裡,配置IP并且up起來。

OVS建立一個bridge <code>br-int</code>,并且把前面建立的veth對裡的<code>veth1</code>作為端口添加到這個bridge上并up起來,然後給端口打上vlan tag 10。

host2的配置和host1幾乎完全相同,唯一不同的是veth0的IP位址時10.1.1.2/24

在host1上配置

其中192.168.4.202是host2上的eth2

在host2上配置

其中192.168.4.201是host1的eth2位址。

可以通過OVS檢視配置

驗證兩個host上的red network namespace是否連通

在host1上ping

同時在host2的eth2上抓包可以看到

可以看到有ICMP的包通過GRE的封裝發送過來。

首先在host1和host2上把ovs上的gre0 port 删掉

然後在host1和host2上分别配置vxlan,和GRE的差別就是type字段改成<code>vxlan</code>

驗證

tcpdump -i eth2 tcpdump: verbose output suppressed, use -v or -vv for full protocol decode listening on eth2, link-type EN10MB (Ethernet), capture size 65535 bytes 16:38:40.018375 ARP, Request who-has 192.168.4.202 tell 192.168.4.201, length 46 16:38:40.018422 ARP, Reply 192.168.4.202 is-at 08:00:27:fd:39:c8 (oui Unknown), length 28 16:38:40.018724 IP 192.168.4.201.60827 &gt; 192.168.4.202.4789: UDP, length 54 16:38:40.019324 IP 192.168.4.202.56167 &gt; 192.168.4.201.4789: UDP, length 54 16:38:40.020405 IP 192.168.4.201.57614 &gt; 192.168.4.202.4789: UDP, length 110 16:38:40.021146 IP 192.168.4.202.39657 &gt; 192.168.4.201.4789: UDP, length 110 16:38:41.018502 IP 192.168.4.201.57614 &gt; 192.168.4.202.4789: UDP, length 110 16:38:41.018674 IP 192.168.4.202.39657 &gt; 192.168.4.201.4789: UDP, length 110 16:38:42.019908 IP 192.168.4.201.57614 &gt; 192.168.4.202.4789: UDP, length 110 16:38:42.020198 IP 192.168.4.202.39657 &gt; 192.168.4.201.4789: UDP, length 110 16:38:43.021400 IP 192.168.4.201.57614 &gt; 192.168.4.202.4789: UDP, length 110 16:38:43.021597 IP 192.168.4.202.39657 &gt; 192.168.4.201.4789: UDP, length 110 16:38:45.018441 ARP, Request who-has 192.168.4.201 tell 192.168.4.202, length 28 16:38:45.019091 ARP, Reply 192.168.4.201 is-at 08:00:27:f4:b2:82 (oui Unknown), length 46 16:38:45.020773 IP 192.168.4

.202.56167 &gt; 192.168.4.201.4789: UDP, length 54 16:38:45.021771 IP 192.168.4.201.55994 &gt; 192.168.4.202.4789: UDP, length 54

端口4789就是vxlan的端口。

參考:

<a href="http://blog.scottlowe.org/2013/09/09/namespaces-vlans-open-vswitch-and-gre-tunnels/" target="_blank">http://blog.scottlowe.org/2013/09/09/namespaces-vlans-open-vswitch-and-gre-tunnels/</a>

<a href="http://blog.scottlowe.org/2013/05/07/using-gre-tunnels-with-open-vswitch/" target="_blank">http://blog.scottlowe.org/2013/05/07/using-gre-tunnels-with-open-vswitch/</a>

<a href="http://blog.csdn.net/landhang/article/details/8885927" target="_blank">http://blog.csdn.net/landhang/article/details/8885927</a>

      本文轉自灬落魄灬  51CTO部落格,原文連結:http://blog.51cto.com/smoke520/1795207,如需轉載請自行聯系原作者

繼續閱讀