文章内容很好,如果我只是收藏起来,那就实在是太浪费,还是动手练习一次,好好补一下我的网络。还是用UnitedStack的UOS,创建一个虚拟机来完成全部的试验。
文章就一个小笔误,把ns2写成ns3。外面很多转载的文章,都没注明出处,搞的以为是原创。如果错误都一样,就有点不好意思。
和IBM的文档不一样的地方是:我使用的是Ubuntu 14.04,减少很多没必要的麻烦。
创建一个Ubuntu 14.04的最小配置虚拟机,ssh到虚拟机上。
查看Ubuntu版本
# lsb_release -a No LSB modules are available. Distributor ID: Ubuntu Description: Ubuntu 14.04.1 LTS Release: 14.04 Codename: trusty OVSUbuntu 14.04的OVS版本,已经是2.02,所以默认安装就可以。不过不同的发行版,ovs的名字会有点不同。
apt-cache search openvswitch开始安装
apt-get install openvswitch-switch查看OVS运行情况
# ps -ea | grep ovs 3007 ? 00:00:00 ovsdb-server 3017 ? 00:00:00 ovs-vswitchd查看OVS版本
# ovs-appctl --version ovs-appctl (Open vSwitch) 2.0.2 Compiled Aug 15 2014 14:31:01查看 OVS 支持的 OpenFlow 协议的版本
# ovs-ofctl --version ovs-ofctl (Open vSwitch) 2.0.2 Compiled Aug 15 2014 14:31:02 OpenFlow versions 0x1:0x4 OpenFlow 命令创建一个OVS交换机
ovs-vsctl add-br ovs-switch创建一个端口 p0,设置端口 p0 的 OpenFlow 端口编号为 100
ovs-vsctl add-port ovs-switch p0 -- set Interface p0 ofport_request=100设置网络接口设备类型为”internal”,
ovs-vsctl set Interface p0 type=internal查看设置结果
# ethtool -i p0 driver: openvswitch version: firmware-version: bus-info: supports-statistics: no supports-test: no supports-eeprom-access: no supports-register-dump: no supports-priv-flags: no创建一个name space:ns0,把p0端口接入到ns0里,并且配置ip地址 192.168.1.100/24
ip netns add ns0 ip link set p0 netns ns0 ip netns exec ns0 ip addr add 192.168.1.100/24 dev p0 ip netns exec ns0 ifconfig p0 promisc up查看创建结果
# ovs-vsctl show 6507c214-0c7a-4159-9813-977074f73aa1 Bridge ovs-switch Port "p0" Interface "p0" type: internal Port ovs-switch Interface ovs-switch type: internal ovs_version: "2.0.2"重复步骤,创建p1和p2端口
ovs-vsctl add-port ovs-switch p1 -- set Interface p1 ofport_request=101 ovs-vsctl set Interface p1 type=internal ip netns add ns1 ip link set p1 netns ns1 ip netns exec ns1 ip addr add 192.168.1.101/24 dev p1 ip netns exec ns1 ifconfig p1 promisc up查看创建结果
# ovs-vsctl show 6507c214-0c7a-4159-9813-977074f73aa1 Bridge ovs-switch Port "p1" Interface "p1" type: internal Port "p0" Interface "p0" type: internal Port ovs-switch Interface ovs-switch type: internal ovs_version: "2.0.2"创建p2
ovs-vsctl add-port ovs-switch p2 -- set Interface p2 ofport_request=102 ovs-vsctl set Interface p2 type=internal ip netns add ns2 ip link set p2 netns ns2 ip netns exec ns2 ip addr add 192.168.1.102/24 dev p2 ip netns exec ns2 ifconfig p2 promisc up查看
# ovs-vsctl show 6507c214-0c7a-4159-9813-977074f73aa1 Bridge ovs-switch Port "p1" Interface "p1" type: internal Port "p2" Interface "p2" type: internal Port "p0" Interface "p0" type: internal Port ovs-switch Interface ovs-switch type: internal ovs_version: "2.0.2"查看创建的交换机信息,获得dpid,端口openflow端口编号
# ovs-ofctl show ovs-switch OFPT_FEATURES_REPLY (xid=0x2): dpid:0000d23b94ce4146 n_tables:254, n_buffers:256 capabilities: FLOW_STATS TABLE_STATS PORT_STATS QUEUE_STATS ARP_MATCH_IP actions: OUTPUT SET_VLAN_VID SET_VLAN_PCP STRIP_VLAN SET_DL_SRC SET_DL_DST SET_NW_SRC SET_NW_ DST SET_NW_TOS SET_TP_SRC SET_TP_DST ENQUEUE 100(p0): addr:00:00:00:00:00:00 config: PORT_DOWN state: LINK_DOWN speed: 0 Mbps now, 0 Mbps max 101(p1): addr:00:00:00:00:00:00 config: PORT_DOWN state: LINK_DOWN speed: 0 Mbps now, 0 Mbps max 102(p2): addr:00:00:00:00:00:00 config: PORT_DOWN state: LINK_DOWN speed: 0 Mbps now, 0 Mbps max LOCAL(ovs-switch): addr:2a:be:0c:72:40:45 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获取openflow端口编号
# ovs-vsctl get Interface p0 ofport 100 # ovs-vsctl get Interface p1 ofport 101 # ovs-vsctl get Interface p2 ofport 102