2.a)
ovs-vsctl show命令:
p0和p1连通性测试的执行结果截图;
2.b)
开启Mininet CLI并执行pingall命令
查看ovs流表
wireshark抓包截图
3.进阶
代码
from mininet.net import Mininet
from mininet.node import Node
from mininet.link import Link
from mininet.log import setLogLevel, info
def myNet():
"Create network from scratch using Open vSwitch."
info( "*** Creating nodes\n" )
switch1 = Node( 's1', inNamespace=False )
switch2 = Node( 's2', inNamespace=False )
h1 = Node( 'h1' )
h2 = Node( 'h2' )
h3 = Node( 'h3' )
h4 = Node( 'h4' )
info( "*** Creating links\n" )
Link( h1, switch1)
Link( h2, switch1)
Link( h3, switch2)
Link( h4, switch2)
Link( switch1, switch2)
info( "*** Configuring hosts\n" )
h1.setIP( '192.168.123.1/24' )
h2.setIP( '192.168.123.2/24' )
h3.setIP( '192.168.123.3/24' )
h4.setIP( '192.168.123.4/24' )
switch1.cmd( 'ovs-vsctl del-br dp0' )
switch1.cmd( 'ovs-vsctl add-br dp0' )
switch2.cmd( 'ovs-vsctl del-br dp1' )
switch2.cmd( 'ovs-vsctl add-br dp1' )
for intf in switch1.intfs.values():
print (intf)
print (switch1.cmd( 'ovs-vsctl add-port dp0 %s' % intf ))
for intf in switch2.intfs.values():
print (intf)
print (switch2.cmd( 'ovs-vsctl add-port dp1 %s' % intf ))
print (switch1.cmd(r'ovs-vsctl show'))
print (switch2.cmd(r'ovs-vsctl show'))
print (switch1.cmd(r'ovs-ofctl -O OpenFlow13 add-flow dp0 priority=1,in_port=1,actions=push_vlan:0x8100,set_field:4096-\>vlan_vid,output:3'))
print (switch1.cmd(r'ovs-ofctl -O OpenFlow13 add-flow dp0 priority=1,in_port=2,actions=push_vlan:0x8100,set_field:4097-\>vlan_vid,output:3'))
print (switch1.cmd(r'ovs-ofctl -O OpenFlow13 add-flow dp0 priority=1,dl_vlan=0,actions=pop_vlan,output:1'))
print (switch1.cmd(r'ovs-ofctl -O OpenFlow13 add-flow dp0 priority=1,dl_vlan=1,actions=pop_vlan,output:2'))
print (switch2.cmd(r'ovs-ofctl -O OpenFlow13 add-flow dp1 priority=1,in_port=1,actions=push_vlan:0x8100,set_field:4096-\>vlan_vid,output:3'))
print (switch2.cmd(r'ovs-ofctl -O OpenFlow13 add-flow dp1 priority=1,in_port=2,actions=push_vlan:0x8100,set_field:4097-\>vlan_vid,output:3'))
print (switch2.cmd(r'ovs-ofctl -O OpenFlow13 add-flow dp1 priority=1,dl_vlan=0,actions=pop_vlan,output:1'))
print (switch2.cmd(r'ovs-ofctl -O OpenFlow13 add-flow dp1 priority=1,dl_vlan=1,actions=pop_vlan,output:2'))
h1.cmdPrint( 'ping -c 3 ' + h3.IP() )
h2.cmdPrint( 'ping -c 3 ' + h4.IP() )
h1.cmdPrint( 'ping -c 3 ' + h4.IP() )
h2.cmdPrint( 'ping -c 3 ' + h3.IP() )
info( "*** Stopping network\n" )
switch1.cmd( 'ovs-vsctl del-br dp0' )
switch1.deleteIntfs()
switch2.cmd( 'ovs-vsctl del-br dp1' )
switch2.deleteIntfs()
info( '\n' )
if __name__ == '__main__':
setLogLevel( 'info' )
info( '*** Scratch network demo (kernel datapath)\n' )
Mininet.init()
myNet()
执行结果
个人总结
这次实验总体难度不算很高,但也遇到了几个问题。第一个问题p0与p1没有ping通,原因:
配置p1的ip地址时配给了192.168.1.100(改ip地址已配给了p0)结果导致失败。
第二个问题:没有完全理解ppt的内容不知道下发流表作用,不知道为什么h1和h3,h2和h4ping不通。导致
在这一步骤卡住一会。
第三个问题运行 sudo mn --custom...时候导致网桥被删除,不知原因是什么。
第四个问题然后就是在做进阶的时候,网站中的示例代码多少有一点不好理解好几遍确定将之理解后才开始做
通过此次实验我学会了学会了ovs基础操作、下发流表、抓包等功能,对sdn的理解又多了一点。