[root@kunpeng82 devuser]# ovs-vsctl add-br s1
[root@kunpeng82 devuser]# ovs-vsctl add-br s2
patch port 说明请看https://arthurchiao.github.io/blog/ovs-deep-dive-4-patch-port/
ovs里的不同bridge之间可以通过patch port进行连接,类似于linux的veth接口。
[root@kunpeng82 devuser]# ovs-vsctl add-port s1 s1_p1 ovs-vsctl: Error detected while setting up 's1_p1': could not open network device s1_p1 (No such device). See ovs-vswitchd log for details. ovs-vsctl: The default log directory is "/var/log/openvswitch". [root@kunpeng82 devuser]# ovs-vsctl add-port s1 s1_p2 ovs-vsctl: Error detected while setting up 's1_p2': could not open network device s1_p2 (No such device). See ovs-vswitchd log for details. ovs-vsctl: The default log directory is "/var/log/openvswitch".
[root@kunpeng82 ovs]# ovs-vsctl add-port s2 s2_p3 ovs-vsctl: Error detected while setting up 's2_p3': could not open network device s2_p3 (No such device). See ovs-vswitchd log for details. ovs-vsctl: The default log directory is "/var/log/openvswitch". [root@kunpeng82 ovs]# ovs-vsctl add-port s2 s2_p4 ovs-vsctl: Error detected while setting up 's2_p4': could not open network device s2_p4 (No such device). See ovs-vswitchd log for details. ovs-vsctl: The default log directory is "/var/log/openvswitch".
[root@kunpeng82 ovs]# ip netns add ns_s1 [root@kunpeng82 ovs]# ip link set s1_p1 netns ns_s1 Cannot find device "s1_p1"
[root@kunpeng82 ovs]# ovs-vsctl set Interface s1_p1 type=internal
[root@kunpeng82 ovs]# ip link set s1_p1 netns ns_s1
[root@kunpeng82 ovs]#
[root@kunpeng82 ovs]# ip netns exec ns_s1 ip addr add 192.168.1.103/24 dev s1_p1
[root@kunpeng82 ovs]# ip netns exec ns_s1 ifconfig s1_p1 up
[root@kunpeng82 ovs]#
==================================================================================
[root@kunpeng82 ovs]# ovs-vsctl set Interface s2_p4 type=internal
[root@kunpeng82 ovs]# ip link set s2_p4 netns ns_s2
[root@kunpeng82 ovs]# ip netns exec ns_s2 ip addr add 192.168.1.104/24 dev s2_p4
[root@kunpeng82 ovs]# ip netns exec ns_s2 ifconfig s2_p4 up
查了下原因,原来是lo处于down状态
Bridge "s1" Port "s1_p2" Interface "s1_p2" error: "could not open network device s1_p2 (No such device)" Port "s1" Interface "s1" type: internal Port "s1_p1" Interface "s1_p1" type: internal Bridge "s2" Port "s2_p3" Interface "s2_p3" error: "could not open network device s2_p3 (No such device)" Port "s2" Interface "s2" type: internal Port "s2_p4" Interface "s2_p4" type: internal
[root@kunpeng82 ovs]# ovs-ofctl show s1 OFPT_FEATURES_REPLY (xid=0x2): dpid:0000121c99afe147 n_tables:254, n_buffers:0 capabilities: FLOW_STATS TABLE_STATS PORT_STATS QUEUE_STATS ARP_MATCH_IP actions: output enqueue set_vlan_vid set_vlan_pcp strip_vlan mod_dl_src mod_dl_dst mod_nw_src mod_nw_dst mod_nw_tos mod_tp_src mod_tp_dst 1(s1_p1): addr:00:00:00:00:00:00 config: PORT_DOWN state: LINK_DOWN speed: 0 Mbps now, 0 Mbps max LOCAL(s1): addr:12:1c:99:af:e1:47 config: PORT_DOWN state: LINK_DOWN speed: 0 Mbps now, 0 Mbps max OFPT_GET_CONFIG_REPLY (xid=0x4): frags=normal miss_send_len=0 [root@kunpeng82 ovs]# ovs-appctl fdb/show s1 port VLAN MAC Age 1 0 3e:db:bf:e6:e9:83 62
[root@kunpeng82 ovs]# cat conn.sh ovs-vsctl set Interface s1_p1 ofport_request=10 ovs-vsctl set Interface s1_p1 type=internal ovs-vsctl set Interface s1_p2 ofport_request=11 ovs-vsctl set Interface s2_p3 ofport_request=1 ovs-vsctl set Interface s2_p4 type=internal ovs-vsctl set Interface s2_p4 ofport_request=2 #ovs-vsctl set Interface s1_p2 type=patch #ovs-vsctl set Interface s1_p2 options:peer=s2_p3 #ovs-vsctl set Interface s2_p3 type=patch #ovs-vsctl set Interface s2_p3 options:peer=s1_p2 [root@kunpeng82 ovs]# bash conn.sh [root@kunpeng82 ovs]# ovs-ofctl show s1 OFPT_FEATURES_REPLY (xid=0x2): dpid:0000121c99afe147 n_tables:254, n_buffers:0 capabilities: FLOW_STATS TABLE_STATS PORT_STATS QUEUE_STATS ARP_MATCH_IP actions: output enqueue set_vlan_vid set_vlan_pcp strip_vlan mod_dl_src mod_dl_dst mod_nw_src mod_nw_dst mod_nw_tos mod_tp_src mod_tp_dst 10(s1_p1): addr:02:22:cd:30:d8:12 config: PORT_DOWN state: LINK_DOWN speed: 0 Mbps now, 0 Mbps max LOCAL(s1): addr:12:1c:99:af:e1:47 config: PORT_DOWN state: LINK_DOWN speed: 0 Mbps now, 0 Mbps max OFPT_GET_CONFIG_REPLY (xid=0x4): frags=normal miss_send_len=0
[root@kunpeng82 ovs]# ovs-ofctl show s2
OFPT_FEATURES_REPLY (xid=0x2): dpid:0000bac4cfc32341
n_tables:254, n_buffers:0
capabilities: FLOW_STATS TABLE_STATS PORT_STATS QUEUE_STATS ARP_MATCH_IP
actions: output enqueue set_vlan_vid set_vlan_pcp strip_vlan mod_dl_src mod_dl_dst mod_nw_src mod_nw_dst mod_nw_tos mod_tp_src mod_tp_dst
2(s2_p4): addr:00:00:00:00:00:00
config: PORT_DOWN
state: LINK_DOWN
speed: 0 Mbps now, 0 Mbps max
LOCAL(s2): addr:ba:c4:cf:c3:23:41
config: PORT_DOWN
state: LINK_DOWN
speed: 0 Mbps now, 0 Mbps max
OFPT_GET_CONFIG_REPLY (xid=0x4): frags=normal miss_send_len=0
[root@kunpeng82 ovs]# ovs-ofctl add-flow s1 "in_port=10, actions=output:10" [root@kunpeng82 ovs]# ovs-ofctl dumps-flow s1 ovs-ofctl: unknown command 'dumps-flow'; use --help for help [root@kunpeng82 ovs]# ovs-ofctl dump-flows s1 cookie=0x0, duration=113.408s, table=0, n_packets=0, n_bytes=0, in_port="s1_p1" actions=output:"s1_p1" cookie=0x0, duration=3138.806s, table=0, n_packets=26, n_bytes=2012, priority=0 actions=NORMAL
现在ip netns exec ns_s1 ping 192.168.1.104
[root@kunpeng82 ovs]# ovs-ofctl add-flow s1 "in_port=10, actions=output:11" [root@kunpeng82 ovs]# ovs-ofctl add-flow s1 "in_port=11, actions=output:10" [root@kunpeng82 ovs]# ovs-ofctl add-flow s2 "in_port=1, actions=output:2" [root@kunpeng82 ovs]# ovs-ofctl add-flow s2 "in_port=2, actions=output:1"
配了之后还是无法ping,看下bridge
Bridge "s1" Port "s1_p2" Interface "s1_p2" type: patch error: "s1_p2: patch type requires valid 'peer' argument" Port "s1" Interface "s1" type: internal Port "s1_p1" Interface "s1_p1" type: internal Bridge "s2" Port "s2_p3" Interface "s2_p3" error: "could not open network device s2_p3 (No such device)" Port "s2" Interface "s2" type: internal Port "s2_p4" Interface "s2_p4" type: internal
ovs-vsctl set Interface s2_p3 type=patch
[root@kunpeng82 ovs]# ovs-vsctl set Interface s1_p2 type=patch [root@kunpeng82 ovs]# ovs-vsctl set Interface s1_p2 options:peer=s2_p3 [root@kunpeng82 ovs]# ovs-vsctl set Interface s2_p3 options:peer=s1_p2 [root@kunpeng82 ovs]# ovs-vsctl show Bridge "s1" Port "s1_p2" Interface "s1_p2" type: patch options: {peer="s2_p3"} Port "s1" Interface "s1" type: internal Port "s1_p1" Interface "s1_p1" type: internal Bridge "s2" Port "s2_p3" Interface "s2_p3" type: patch options: {peer="s1_p2"} Port "s2" Interface "s2" type: internal Port "s2_p4" Interface "s2_p4" type: internal ovs_version: "2.12.0"
删除流表
ovs-ofctl del-flows s1 in_port=10 ovs-ofctl del-flows s1 in_port=11 ovs-ofctl del-flows s2 in_port=1 ovs-ofctl del-flows s2 in_port=2
[root@kunpeng82 ovs]# ovs-ofctl dump-flows s1
cookie=0x0, duration=6012.896s, table=0, n_packets=105, n_bytes=6702, priority=0 actions=NORMAL
[root@kunpeng82 ovs]# ovs-ofctl dump-flows s2
cookie=0x0, duration=6010.965s, table=0, n_packets=56, n_bytes=4616, priority=0 actions=NORMAL