Open vSwitch中PATCH类型的端口有如下定义:“A pair of virtual devices that act as a patch cable”(一根虚拟电缆),同时在OpenvSwitch官方FAQ可以找到PATCH端口的用途“If
you still want to connect two bridges, you can use a pair of patch ports”(用于连接两个网桥)。

简单化,patch port成对,可以看作是一根虚拟电缆,用来连接两个网桥,如下图:

创建两个网桥br1和br2

ovs-vsctl add-br br1  
ovs-vsctl add-br br2  

创建内部端口

ovs-vsctl add-port br1 tap1 -- set Interface tap1 type=internal  
ovs-vsctl add-port br2 tap2 -- set Interface tap2 type=internal  

设置netns命名空间

ip link set tap1 netns ns1  
ip link set tap2 netns ns2  

配置各自命名空间内的ip地址:

ip netns exec ns1 ip addr add 192.168.0.101/24 dev tap1  
ip netns exec ns1 ip link set tap1 up  
ip netns exec ns1 ip link set lo up

ip netns exec ns2 ip addr add 192.168.0.102/24 dev tap2  
ip netns exec ns2 ip link set tap2 up  
ip netns exec ns2 ip link set lo up  

创建patch port

ovs-vsctl add-port br1 patch-ovs-1 -- set Interface patch-ovs-1 type=patch -- set Interface patch-ovs-1 options:peer=patch-ovs-2

ovs-vsctl add-port br2 patch-ovs-2 -- set Interface patch-ovs-2 type=patch -- set Interface patch-ovs-2 options:peer=patch-ovs-1  

测试

ip netns exec ns1 ping 192.168.0.102  
ip netns exec ns2 ping 192.168.0.101  
comments powered by Disqus