基础要求提交
a) /home/用户名/学号/lab2/目录下执行ovs-vsctl show命令、以及p0和p1连通性测试的执行结果截图;
b) /home/用户名/学号/lab2/目录下开启Mininet CLI并执行pingall命令的截图、上述目录下查看OVS流表的命令结果截图,wireshark抓包截图
进阶要求
代码
#!/usr/bin/env 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='127.0.0.1')
info( '*** Adding controller\n' )
c0=net.addController(name='c0',
controller=Controller,
protocol='OpenFlow13',
port=6653)
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='10.0.0.1', defaultRoute=None)
h2 = net.addHost('h2', cls=Host, ip='10.0.0.2', defaultRoute=None)
h3 = net.addHost('h3', cls=Host, ip='10.0.0.3', defaultRoute=None)
h4 = net.addHost('h4', cls=Host, ip='10.0.0.4', defaultRoute=None)
info( '*** Add links\n')
net.addLink(h1, s1,1,1)
net.addLink(h2, s1,1,2)
net.addLink(h3, s2,1,1)
net.addLink(h4, s2,1,2)
net.addLink(s1, s2,3,3)
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()
执行结果
个人总结
心得体会
这次的实验操作,比之前一两次要增加些难度。主要在于,其中一部分步骤需要一些细节的关键的步骤操作去解决完成,但是这些我们要花比较多的时间去查资料、学习、请教交流才有这些关键点解决步骤。其次是代码基础比较差,对于简单的代码还比较能快速理解,但是关于流表创建那部分,代码比较长,很容易输错,需要练习并培养细心度,也要快速学习码代码的能力。
遇到的问题:
(一)如何用wireshark 抓包
解决方法:
- 抓包时一定要在终端运行该网络
1.选中端口
2.点击star即可开始抓包
可通过在终端输入pingall命令在网络拓扑中发送数据包,以便抓包
(二)选中端口后报错don't have permission to capture on that device
解决方法:
参考文章:解决ubuntu系统中wireshark:Couldn't run /usr/bin/dumpcap in child process: Permission denied的问题...
(三)命名不熟悉
简单总结一下:
1.打开mininet可视化:在学号目录下输入sudo ./mininet/examples/miniedit.py
2.终端运行.py文件:sudo python3 XXX.py
sudo mn --custom XXX.py --topo mytoo
(四)建立网络虚拟空间,测试p0和p1连通性时如何让代码停下
解决方法:
输入:ctrl+c 即可结束测试
(五)下发流表、查看流表不成功
解决方法:
下发流表和查看流表的操作都要在网络运行的情况下才能执行,所以要开启两个终端,一个运行网络,一个进行下发流表和流表查看
从图中可以看出网络一开始是全连通的,当我们进行完下发流表后再输入pingall命令查看如下,网络已按要求划分好
标签:mininet,sudo,s2,s1,vlan,交换机,vSwitch,net,Open From: https://www.cnblogs.com/calsk/p/16712276.html