1.创建拓扑
代码:
#!/usr/bin/python
from mininet.topo import Topo
class topo2(Topo):
def __init__(self):
Topo.__init__(self)
switchs = []
for i in range(2):
sw = self.addSwitch("s{}".format(i + 1))
switchs.append(sw)
self.addLink(switchs[0], switchs[1])
id = 1
for sw in switchs:
for i in range(3):
h = self.addHost("h{}".format(id))
self.addLink(sw, h)
id += 1
topos = {"topo2": (lambda : topo2()) }
2.利用OVS命令下发流表,实现VLAN功能
对s1下流表:
zhangsihuai@ubuntu:~$ sudo ovs-ofctl -O OpenFlow13 add-flow s1 priority=1,in_port=2,actions=push_vlan:0x8100,set_field:4096-\\>vlan_vid,output:1
zhangsihuai@ubuntu:~$ sudo ovs-ofctl -O OpenFlow13 add-flow s1 priority=1,in_port=3,actions=push_vlan:0x8100,set_field:4097-\\>vlan_vid,output:1
zhangsihuai@ubuntu:~$ sudo ovs-ofctl -O OpenFlow13 add-flow s1 priority=1,in_port=4,actions=push_vlan:0x8100,set_field:4098-\\>vlan_vid,output:1
zhangsihuai@ubuntu:~$ sudo ovs-ofctl -O OpenFlow13 add-flow s1 priority=1,dl_vlan=2,actions=pop_vlan,output=4
zhangsihuai@ubuntu:~$ sudo ovs-ofctl -O OpenFlow13 add-flow s1 priority=1,dl_vlan=1,actions=pop_vlan,output=3
zhangsihuai@ubuntu:~$ sudo ovs-ofctl -O OpenFlow13 add-flow s1 priority=1,dl_vlan=0,actions=pop_vlan,output=2
zhangsihuai@ubuntu:~$
对s2下流表:
zhangsihuai@ubuntu:~$ sudo ovs-ofctl -O OpenFlow13 add-flow s2 priority=1,in_port=4,actions=push_vlan:0x8100,set_field:4098-\\>vlan_vid,output:1
zhangsihuai@ubuntu:~$ sudo ovs-ofctl -O OpenFlow13 add-flow s2 priority=1,in_port=3,actions=push_vlan:0x8100,set_field:4097-\\>vlan_vid,output:1
zhangsihuai@ubuntu:~$ sudo ovs-ofctl -O OpenFlow13 add-flow s2 priority=1,in_port=2,actions=push_vlan:0x8100,set_field:4096-\\>vlan_vid,output:1
zhangsihuai@ubuntu:~$ sudo ovs-ofctl -O OpenFlow13 add-flow s2 priority=1,dl_vlan=0,actions=pop_vlan,output=2
zhangsihuai@ubuntu:~$ sudo ovs-ofctl -O OpenFlow13 add-flow s2 priority=1,dl_vlan=1,actions=pop_vlan,output=3
zhangsihuai@ubuntu:~$ sudo ovs-ofctl -O OpenFlow13 add-flow s2 priority=1,dl_vlan=2,actions=pop_vlan,output=4
3.利用OVS命令查看流表
4.验证性测试
截图验证:
h1--h4互通
h2--h5互通
h3--h6互通
其余主机间无法通信