实验2:Open vSwitch虚拟交换机实践
实验报告
1. 在/home/用户名/学号/lab2/目录下执行ovs-vsctl show命令、以及p0和p1连通性测试的执行结果截图
2. 在/home/用户名/学号/lab2/目录下开启Mininet CLI的截图
3. 通过命令行终端输入“ovs-ofctl”命令,直接在s1和s2上添加流表,划分出所要求的VLAN
4. 查看流表
5. 主机连通性测试
6. 利用wireshark抓包,抓取s1的3号端口
从图中可以看出:s1向s3发送的包中ID为0,而s2向s4发送的包中ID为1,符合预期
7.进阶要求
-
python代码如下
from mininet.net import Mininet
from mininet.node import Controller, RemoteController, OVSController
from mininet.node import CPULimitedHost, Host, Node
from mininet.node import OVSKernelSwitch, UserSwitch
from mininet.node import IVSSwitch
from mininet.cli import CLI
from mininet.log import setLogLevel, info
from mininet.link import TCLink, Intf
from subprocess import call
def mynetwork():
net = Mininet( topo=None,build=False,ipBase='192.168.0.0/24')
info( '*** Adding controller\n' )
c0=net.addController(name='c0',
controller=Controller,
protocol='tcp',
port=6633)
info( '*** Add switches\n')
s1 = net.addSwitch('s1', cls=OVSKernelSwitch)
s2 = net.addSwitch('s2', cls=OVSKernelSwitch)
info( '*** Add hosts\n')
h1 = net.addHost('h1', cls=Host, ip='192.168.0.1', defaultRoute=None)
h2 = net.addHost('h2', cls=Host, ip='192.168.0.2', defaultRoute=None)
h3 = net.addHost('h3', cls=Host, ip='192.168.0.3', defaultRoute=None)
h4 = net.addHost('h4', cls=Host, ip='192.168.0.4', defaultRoute=None)
info( '*** Add links\n')
net.addLink(h1, s1, 1, 1)
net.addLink(s1, h2, 2, 1)
net.addLink(s1, s2, 3, 3)
net.addLink(s2, h3, 1, 1)
net.addLink(s2, h4, 2, 1)
info( '*** Starting network\n')
net.build()
info( '*** Starting controllers\n')
for controller in net.controllers:
controller.start()
info( '*** Starting switches\n')
net.get('s1').start([c0])
net.get('s2').start([c0])
info( '*** Post configure switches and hosts\n')
#s1、s2分别调用cmd()实现添加流表和划分vlan的操作
s1.cmd('sudo ovs-ofctl -O OpenFlow13 add-flow s1 priority=1,in_port=1,actions=push_vlan:0x8100,set_field:4096-\>vlan_vid,output:3')
s1.cmd('sudo ovs-ofctl -O OpenFlow13 add-flow s1 priority=1,in_port=2,actions=push_vlan:0x8100,set_field:4097-\>vlan_vid,output:3')
s1.cmd('sudo ovs-ofctl -O OpenFlow13 add-flow s1 priority=1,dl_vlan=0,actions=pop_vlan,output:1')
s1.cmd('sudo ovs-ofctl -O OpenFlow13 add-flow s1 priority=1,dl_vlan=1,actions=pop_vlan,output:2')
s2.cmd('sudo ovs-ofctl -O OpenFlow13 add-flow s2 priority=1,in_port=1,actions=push_vlan:0x8100,set_field:4096-\>vlan_vid,output:3')
s2.cmd('sudo ovs-ofctl -O OpenFlow13 add-flow s2 priority=1,in_port=2,actions=push_vlan:0x8100,set_field:4097-\>vlan_vid,output:3')
s2.cmd('sudo ovs-ofctl -O OpenFlow13 add-flow s2 priority=1,dl_vlan=0,actions=pop_vlan,output:1')
s2.cmd('sudo ovs-ofctl -O OpenFlow13 add-flow s2 priority=1,dl_vlan=1,actions=pop_vlan,output:2')
CLI(net)
net.stop()
if __name__ == '__main__':
setLogLevel( 'info' )
mynetwork()
-
运行Python程序
-
查看连通性
由图可知连通性与之前一致
8.实验总结 在这次实验过程中,学习了Open vSwitch虚拟交换机的一些相关知识与概念,中间遇到过一些比较奇怪的小bug(,把文件删除后只能从前几个步骤重新再做一遍,所以消耗的时间也比较久。虽然之后的实验中可能也还会遇到这样的可能性,但是做实验的时间还是很宝贵的,所以还是需要避免类似的情况反复出现。之前只了解过一些Vlan的概念,这次实验加深了对Vlan的实现方式的理解,但是实验过程中涉及到的一些原理还是不够了解,还需要继续学习。
标签:ovs,cmd,s2,s1,vlan,交换机,vSwitch,net,Open From: https://www.cnblogs.com/amb1tion/p/16706042.html