Openvswitch手册(5): VLAN and Bonding
我们这一节来看Port
一般来说一个Port就是一个Interface,当然也有一个Port对应多个Interface的情况,成为Bond
VLAN Configuration
Port的一个重要的方面就是VLAN Configuration,有两种模式:
- trunk port,这个port不配置tag,配置trunks,如果trunks为空,则所有的VLAN都trunk,也就意味着对于所有的VLAN的包,本身带什么VLAN ID,就是携带者什么VLAN ID,如果没有设置VLAN,就属于VLAN 0,全部允许通过。如果trunks不为空,则仅仅带着这些VLAN ID的包通过。
- access port,这个port配置tag,从这个port进来的包会被打上这个tag,如果从其他的trunk port中进来的本身就带有VLAN ID的包,如果VLAN ID等于tag,则会从这个port发出,从其他的access port上来的包,如果tag相同,也会被forward到这个port。从access port发出的包不带VLAN ID。如果一个本身带VLAN ID的包到达access port,即便VLAN ID等于tag,也会被抛弃。
我们创建下面的拓扑来做一个实验:
sudo ovs-vsctl add-port helloworld first_br
sudo ovs-vsctl add-port helloworld second_br
sudo ovs-vsctl add-port helloworld third_br
sudo ovs-vsctl set Port vnet8 tag=101
sudo ovs-vsctl set Port vnet9 tag=102
sudo ovs-vsctl set Port vnet10 tag=103
sudo ovs-vsctl set Port first_br tag=103
sudo ovs-vsctl clear Port second_br tag
sudo ovs-vsctl set Port third_br trunks=101,102
sudo ovs-vsctl set bridge helloworld flood-vlans=101,102,103
sudo ovs-vsctl -- --id=@mirror get Mirror mirrorvnet9 -- remove Bridge helloworld mirrors @mirror
$ sudo ovs-vsctl show
c24322e6-8453-402a-afaf-64757ef231e9
Bridge helloworld
Port "vnet8"
tag: 101
Interface "vnet8"
Port first_br
tag: 103
Interface first_br
Port second_br
Interface second_br
Port "vnet10"
tag: 103
Interface "vnet10"
Port helloworld
Interface helloworld
type: internal
Port "vnet9"
tag: 102
Interface "vnet9"
Port third_br
trunks: [101, 102]
Interface third_br
ovs_version: "2.0.1"
我们首先从10.10.10.3来ping 10.10.10.4,应该first_if和second_if能够收到包。
first_if收到包了,从first_br出来的包头是没有VLAN ID的
$ sudo tcpdump -n -e -i first_if arp
tcpdump: verbose output suppressed, use -v or -vv for full protocol decode
listening on first_if, link-type EN10MB (Ethernet), capture size 65535 bytes
23:22:45.707470 ca:d4:fd:47:a6:ce > 52:54:00:9b:d5:be, ethertype ARP (0x0806), length 42: Request who-has 10.10.10.3 tell 10.10.10.4, length 28
23:22:45.708170 52:54:00:9b:d5:be > ca:d4:fd:47:a6:ce, ethertype ARP (0x0806), length 42: Reply 10.10.10.3 is-at 52:54:00:9b:d5:be, length 28
second_if也收到包了,由于second_br是trunk port,因而出来的包头是有VLAN ID的,103
$ sudo tcpdump -n -e -i second_if arp
tcpdump: WARNING: second_br: no IPv4 address assigned
tcpdump: verbose output suppressed, use -v or -vv for full protocol decode
listening on second_br, link-type EN10MB (Ethernet), capture size 65535 bytes
23:22:45.707727 ca:d4:fd:47:a6:ce > 52:54:00:9b:d5:be, ethertype 802.1Q (0x8100), length 46: vlan 103, p 0, ethertype ARP, Request who-has 10.10.10.3 tell 10.10.10.4, length 28
23:22:45.708176 52:54:00:9b:d