实验目的
在给定如上实验拓扑情况下,用vlan得到下列虚拟网段
- h1--h4互通
- h2--h5互通
- h3--h6互通
- 其余主机间无法通信
实验步骤
1. 创建拓扑
#! /usr/bin/python
from mininet.topo import Topo
from mininet.net import Mininet
from mininet.node import RemoteController,CPULimitedHost
from mininet.link import TCLink
class MyTopo(Topo):
def __init__(self):
Topo.__init__(self)
# add switch
sw1 = self.addSwitch(‘sw1‘)
sw2 = self.addSwitch(‘sw2‘)
# add host
h1 = self.addHost(‘h1‘)
h2 = self.addHost(‘h2‘)
h3 = self.addHost(‘h3‘)
h4 = self.addHost(‘h4‘)
h5 = self.addHost(‘h5‘)
h6 = self.addHost(‘h6‘)
# add link
self.addLink(sw1, h1, 1, 1)
self.addLink(sw1, h2, 2, 1)
self.addLink(sw1, h3, 3, 1)
self.addLink(sw2, h4, 1, 1)
self.addLink(sw2, h5, 2, 1)
self.addLink(sw2, h6, 3, 1)
self.addLink(sw1, sw2, 4, 4)
topos = { ‘mytopo‘: ( lambda: MyTopo() ) }
截图如下
2.利用OVS命令下发流表,实现VLAN功能
参考链接:http://blog.csdn.net/rocson001/article/details/73163041
- switch1
sudo ovs-ofctl -O OpenFlow13 add-flow sw1 priority=1,in_port=1,actions=push_vlan:0x8100,set_field:4096-\>vlan_vid,output:4
sudo ovs-ofctl -O OpenFlow13 add-flow sw1 priority=1,in_port=2,actions=push_vlan:0x8100,set_field:4097-\>vlan_vid,output:4
sudo ovs-ofctl -O OpenFlow13 add-flow sw1 priority=1,in_port=3,actions=push_vlan:0x8100,set_field:4098-\>vlan_vid,output:4
sudo ovs-ofctl -O OpenFlow13 add-flow sw1 priority=1,dl_vlan=0,actions=pop_vlan,output:1
sudo ovs-ofctl -O OpenFlow13 add-flow sw1 priority=1,dl_vlan=1,actions=pop_vlan,output:2
sudo ovs-ofctl -O OpenFlow13 add-flow sw1 priority=1,dl_vlan=2,actions=pop_vlan,output:3
- switch2
sudo ovs-ofctl -O OpenFlow13 add-flow sw2 priority=1,in_port=1,actions=push_vlan:0x8100,set_field:4096-\>vlan_vid,output:4
sudo ovs-ofctl -O OpenFlow13 add-flow sw2 priority=1,in_port=2,actions=push_vlan:0x8100,set_field:4097-\>vlan_vid,output:4
sudo ovs-ofctl -O OpenFlow13 add-flow sw2 priority=1,in_port=3,actions=push_vlan:0x8100,set_field:4098-\>vlan_vid,output:4
sudo ovs-ofctl -O OpenFlow13 add-flow sw2 priority=1,dl_vlan=0,actions=pop_vlan,output:1
sudo ovs-ofctl -O OpenFlow13 add-flow sw2 priority=1,dl_vlan=1,actions=pop_vlan,output:2
sudo ovs-ofctl -O OpenFlow13 add-flow sw2 priority=1,dl_vlan=2,actions=pop_vlan,output:3
3.利用OVS命令查看流表
- switch1
$ sudo ovs-ofctl -O OpenFlow13 dump-flows sw1
OFPST_FLOW reply (OF1.3) (xid=0x2):
cookie=0x0, duration=3098.183s, table=0, n_packets=21, n_bytes=1302, priority=1,dl_vlan=2 actions=strip_vlan,output:3
cookie=0x0, duration=3098.221s, table=0, n_packets=22, n_bytes=1348, priority=1,dl_vlan=0 actions=strip_vlan,output:1
cookie=0x0, duration=3098.199s, table=0, n_packets=22, n_bytes=1348, priority=1,dl_vlan=1 actions=strip_vlan,output:2
cookie=0x0, duration=3098.254s, table=0, n_packets=21, n_bytes=1218, priority=1,in_port=3 actions=push_vlan:0x8100,set_field:2->vlan_vid,output:4
cookie=0x0, duration=3098.342s, table=0, n_packets=22, n_bytes=1260, priority=1,in_port=1 actions=push_vlan:0x8100,set_field:0->vlan_vid,output:4
cookie=0x0, duration=3098.308s, table=0, n_packets=22, n_bytes=1260, priority=1,in_port=2 actions=push_vlan:0x8100,set_field:1->vlan_vid,output:4
cookie=0x0, duration=3934.114s, table=0, n_packets=1362, n_bytes=219298, priority=0 actions=CONTROLLER:65535
- switch2
$ sudo ovs-ofctl -O OpenFlow13 dump-flows sw2
OFPST_FLOW reply (OF1.3) (xid=0x2):
cookie=0x0, duration=3132.991s, table=0, n_packets=21, n_bytes=1302, priority=1,dl_vlan=2 actions=strip_vlan,output:3
cookie=0x0, duration=3136.604s, table=0, n_packets=22, n_bytes=1348, priority=1,dl_vlan=0 actions=strip_vlan,output:1
cookie=0x0, duration=3136.593s, table=0, n_packets=22, n_bytes=1348, priority=1,dl_vlan=1 actions=strip_vlan,output:2
cookie=0x0, duration=3136.626s, table=0, n_packets=21, n_bytes=1218, priority=1,in_port=3 actions=push_vlan:0x8100,set_field:2->vlan_vid,output:4
cookie=0x0, duration=3136.667s, table=0, n_packets=22, n_bytes=1260, priority=1,in_port=1 actions=push_vlan:0x8100,set_field:0->vlan_vid,output:4
cookie=0x0, duration=3136.654s, table=0, n_packets=22, n_bytes=1260, priority=1,in_port=2 actions=push_vlan:0x8100,set_field:1->vlan_vid,output:4
cookie=0x0, duration=3973.664s, table=0, n_packets=1394, n_bytes=225662, priority=0 actions=CONTROLLER:65535
4.验证性测试
5.Wireshark抓包验证
原文地址:https://www.cnblogs.com/tr3e/p/8322077.html
时间: 2024-10-12 23:39:28