(一)基本要求
/home/用户名/学号/lab2/目录下执行ovs-vsctl show命令、以及p0和p1连通性测试的执行结果截图;
/home/用户名/学号/lab2/目录下开启Mininet CLI并执行pingall命令的截图
上述目录下查看OVS流表的命令结果截图
wireshark抓包截图
h1
h3
h2
h4
(二)进阶要求
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='10.0.0.0/8')
info( '*** Adding controller\n' )
c0=net.addController(name='c0',
controller=Controller,
protocol='tcp',
port=6633)
info( '*** Add switches\n')
s1 = net.addSwitch('s1')
s2 = net.addSwitch('s2')
info( '*** Add hosts\n')
h1 = net.addHost('h1', ip='10.0.0.1')
h2 = net.addHost('h2', ip='10.0.0.2')
h3 = net.addHost('h3', ip='10.0.0.3')
h4 = net.addHost('h4', ip='10.0.0.4')
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.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()
结果截图
抓包
h1
h3
h4
h2
个人总结:
- 困难:在做基础实验时,可能是上次实验遗留,虚拟机上已经存在多个网桥,有点疑惑,后来在网上搜到用sudo mn -c命令进行配置删除,然后是对实验指导PPT的描述理解有误,将p0和p1都配置在了ns0,导致ping不通。而且,最开始抓包时抓取的是s1的eth1,观察不到vlan的ID,后来发现要观察eth3.
- 心得:通过这次实验以及在网上查找资料了解了openswitch的使用及配置方法,学会了在命令行下进行流表的下发,观察到了VLAN的应用,感受到了集中控制转发路径的灵活和自由。还有就是做实验要多动手,边做边想,不要希望把一切都想清楚了再动手,这样往往很难想清楚。