博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Open vSwitch系列实验(一):Open vSwitch使用案例扩展实验
阅读量:6247 次
发布时间:2019-06-22

本文共 9906 字,大约阅读时间需要 33 分钟。

一、实验目的

  • 通过python脚本调用OpenvSwitch命令;
  • 学习Mininet基于python脚本创建拓扑的实现;
  • 进一步深度使用“ovs-vsctl”命令直接控制Open vSwitch。

二、实验原理

在SDN环境中,控制器可以通过对交换机下发流表操作来控制交换机的转发行为。在本实验中,使用Mininet基于python的脚本,调用“ovs-vsctl”命令直接控制Open vSwitch。使用默认的交换机泛洪规则,设置更高的优先级规则进行预先定义IP报文的转发。在多个交换机中通过设置不同TOS值的数据包将通过不同的方式到达目的地址,验证主机间的连通性及到达目的的时间。

三、实验任务

使用默认的交换机泛洪规则,设置更高的优先级规则进行预先定义IP报文的转发,不同TOS值的数据包将通过不同的方式到达目的地址。

TOS包括共8位,包括3 bit的优先权字段(取值可以从000-111所有值),4 bit的TOS子字段和1 bit未用位但必须置0。

3bit的8个优先级的定义如下:

111--Network Control(网络控制);

110--Internetwork Control(网间控制);

101--Critic(关键);

100--Flash Override(疾速);

011--Flash(闪速);

010--Immediate(快速);

001--Priority(优先);

000--Routine(普通)。

优先级6和7一般保留给网络控制数据使用,如路由。

优先级5推荐给语音数据使用。

优先级4由视频会议和视频流使用。

优先级3给语音控制数据使用。

优先级1和2给数据业务使用。

优先级0为默认标记值。

1.ovsSingleBr

1 #!/usr/bin/python 2 #调用mininet模块  3 from mininet.net import Mininet 4 from mininet.node import Node 5 from mininet.link import Link 6 from mininet.log import  setLogLevel, info 7 #mynet函数  8 def myNet(): 9     "Create network from scratch using Open vSwitch."10  11     info( "*** Creating nodes\n" )12     switch0 = Node( 's0', inNamespace=False )13     14     h0 = Node( 'h0' )15     h1 = Node( 'h1' )16     h2 = Node( 'h2' )17  18     info( "*** Creating links\n" )19     Link( h0, switch0)20     Link( h1, switch0)21     Link( h2, switch0)22  23     info( "*** Configuring hosts\n" )24     h0.setIP( '192.168.123.1/24' )25     h1.setIP( '192.168.123.2/24' )26     h2.setIP( '192.168.123.3/24' )27        28     info( "*** Starting network using Open vSwitch\n" )29     switch0.cmd( 'ovs-vsctl del-br dp0' )30     switch0.cmd( 'ovs-vsctl add-br dp0' )31     #print all the intf of the values32     for intf in switch0.intfs.values():33         print intf34         print switch0.cmd( 'ovs-vsctl add-port dp0 %s' % intf )35  36     # Note: controller and switch are in root namespace, and we37     # can connect via loopback interface38     #switch0.cmd( 'ovs-vsctl set-controller dp0 tcp:127.0.0.1:6633' )39   40     print switch0.cmd(r'ovs-vsctl show')41  42     print switch0.cmd(r'ovs-ofctl add-flow dp0 idle_timeout=0,priority=1,in_port=1,actions=flood' ) 43     print switch0.cmd(r'ovs-ofctl add-flow dp0 idle_timeout=0,priority=1,in_port=2,actions=flood' )44     print switch0.cmd(r'ovs-ofctl add-flow dp0 idle_timeout=0,priority=1,in_port=3,actions=flood' )45   46     print switch0.cmd(r'ovs-ofctl add-flow dp0 idle_timeout=0,priority=10,ip,nw_dst=192.168.123.1,actions=output:1' ) 47     print switch0.cmd(r'ovs-ofctl add-flow dp0 idle_timeout=0,priority=10,ip,nw_dst=192.168.123.2,actions=output:2' ) 48     print switch0.cmd(r'ovs-ofctl add-flow dp0 idle_timeout=0,priority=10,ip,nw_dst=192.168.123.3,actions=output:3')49  50     #switch0.cmd('tcpdump -i s0-eth0 -U -w aaa &')51     #h0.cmd('tcpdump -i h0-eth0 -U -w aaa &')52     info( "*** Running test\n" )53     h0.cmdPrint( 'ping -c 3 ' + h1.IP() )54     h0.cmdPrint( 'ping -c 3 ' + h2.IP() )55  56     #print switch0.cmd( 'ovs-ofctl show dp0' )    57     #print switch0.cmd( 'ovs-ofctl dump-tables  dp0' )58     #print switch0.cmd( 'ovs-ofctl dump-ports   dp0' )59     #print switch0.cmd( 'ovs-ofctl dump-flows  dp0' )60     #print switch0.cmd( 'ovs-ofctl dump-aggregate  dp0' )61     #print switch0.cmd( 'ovs-ofctl queue-stats dp0' )62  63     info( "*** Stopping network\n" )64     switch0.cmd( 'ovs-vsctl del-br dp0' )65     switch0.deleteIntfs()66     info( '\n' )67  68 if __name__ == '__main__':69     setLogLevel( 'info' )70     info( '*** Scratch network demo (kernel datapath)\n' )71     Mininet.init()72     myNet()

 

2.ovsMultiBr

这里通过设置不通的tos值和和不通的优先级来改变数据包的转发方式,其中在代码中可以看出priority的值,然后tos的值用的是16进制来表示,TOS表示服务类型,一共8bits,比如0x30:00110000,然后有相应的对照,

1 #!/usr/bin/python  2    3 from mininet.net import Mininet  4 from mininet.node import Node  5 from mininet.link import TCLink  6 from mininet.log import  setLogLevel, info  7    8 def myNet():  9     "Create network from scratch using Open vSwitch." 10   11     info( "*** Creating nodes\n" ) 12     switch0 = Node( 's0', inNamespace=False ) 13     switch1 = Node( 's1', inNamespace=False ) 14     switch2 = Node( 's2', inNamespace=False ) 15     switch3 = Node( 's3', inNamespace=False ) 16     switch4 = Node( 's4', inNamespace=False ) 17     h0 = Node( 'h0' ) 18     h1 = Node( 'h1' ) 19   20     info( "*** Creating links\n" ) 21     linkopts0=dict(bw=100, delay='1ms', loss=0) 22     linkopts1=dict(bw=1, delay='100ms', loss=0) 23     linkopts2=dict(bw=10, delay='50ms', loss=0) 24     linkopts3=dict(bw=100, delay='1ms', loss=0) 25     TCLink( h0, switch0, **linkopts0) 26     TCLink( switch0, switch1, **linkopts0) 27     TCLink( switch0, switch2, **linkopts0) 28     TCLink( switch0, switch3, **linkopts0) 29     TCLink( switch1, switch4,**linkopts1) 30     TCLink( switch2, switch4,**linkopts2) 31     TCLink( switch3, switch4,**linkopts3) 32     TCLink( h1, switch4, **linkopts0) 33   34     info( "*** Configuring hosts\n" ) 35     h0.setIP( '192.168.123.1/24' ) 36     h1.setIP( '192.168.123.2/24' ) 37     info( str( h0 ) + '\n' ) 38     info( str( h1 ) + '\n' ) 39         40     info( "*** Starting network using Open vSwitch\n" ) 41     switch0.cmd( 'ovs-vsctl del-br dp0' ) 42     switch0.cmd( 'ovs-vsctl add-br dp0' ) 43     switch1.cmd( 'ovs-vsctl del-br dp1' ) 44     switch1.cmd( 'ovs-vsctl add-br dp1' ) 45     switch2.cmd( 'ovs-vsctl del-br dp2' ) 46     switch2.cmd( 'ovs-vsctl add-br dp2' ) 47     switch3.cmd( 'ovs-vsctl del-br dp3' ) 48     switch3.cmd( 'ovs-vsctl add-br dp3' ) 49     switch4.cmd( 'ovs-vsctl del-br dp4' ) 50     switch4.cmd( 'ovs-vsctl add-br dp4' ) 51   52     for intf in switch0.intfs.values(): 53         print intf 54         print switch0.cmd( 'ovs-vsctl add-port dp0 %s' % intf ) 55   56     for intf in switch1.intfs.values(): 57         print intf 58         print switch1.cmd( 'ovs-vsctl add-port dp1 %s' % intf ) 59   60     for intf in switch2.intfs.values(): 61         print intf 62         print switch2.cmd( 'ovs-vsctl add-port dp2 %s' % intf ) 63   64     for intf in switch3.intfs.values(): 65         print intf 66         print switch3.cmd( 'ovs-vsctl add-port dp3 %s' % intf ) 67   68     for intf in switch4.intfs.values(): 69         print intf 70         print switch4.cmd( 'ovs-vsctl add-port dp4 %s' % intf ) 71     72     print switch1.cmd(r'ovs-ofctl add-flow dp1 idle_timeout=0,priority=1,in_port=1,actions=flood' ) 73     print switch1.cmd(r'ovs-ofctl add-flow dp1 idle_timeout=0,priority=1,in_port=1,actions=output:2' )  74     print switch1.cmd(r'ovs-ofctl add-flow dp1 idle_timeout=0,priority=1,in_port=2,actions=output:1' ) 75     print switch2.cmd(r'ovs-ofctl add-flow dp2 idle_timeout=0,priority=1,in_port=1,actions=output:2' ) 76     print switch2.cmd(r'ovs-ofctl add-flow dp2 idle_timeout=0,priority=1,in_port=2,actions=output:1' ) 77     print switch3.cmd(r'ovs-ofctl add-flow dp3 idle_timeout=0,priority=1,in_port=1,actions=output:2' )     78     print switch3.cmd(r'ovs-ofctl add-flow dp3 idle_timeout=0,priority=1,in_port=2,actions=output:1' ) 79     print switch4.cmd(r'ovs-ofctl add-flow dp4 idle_timeout=0,priority=1,in_port=1,actions=output:4' ) 80     print switch4.cmd(r'ovs-ofctl add-flow dp4 idle_timeout=0,priority=1,in_port=2,actions=output:4' ) 81     print switch4.cmd(r'ovs-ofctl add-flow dp4 idle_timeout=0,priority=1,in_port=3,actions=output:4' ) 82     print switch4.cmd(r'ovs-ofctl add-flow dp4 idle_timeout=0,priority=1,in_port=4,actions=output:3' ) 83     84     #print switch0.cmd(r'ovs-ofctl add-flow dp0 idle_timeout=0,priority=10,ip,nw_dst=192.168.123.2,actions=output:4') 85     print switch0.cmd(r'ovs-ofctl add-flow dp0 idle_timeout=0,priority=10,ip,nw_dst=192.168.123.2,nw_tos=0x10,actions=output:2')  86     print switch0.cmd(r'ovs-ofctl add-flow dp0 idle_timeout=0,priority=10,ip,nw_dst=192.168.123.2,nw_tos=0x20,actions=output:3') 87     print switch0.cmd(r'ovs-ofctl add-flow dp0 idle_timeout=0,priority=10,ip,nw_dst=192.168.123.2,nw_tos=0x30,actions=output:4')  88     #print switch0.cmd(r'ovs-ofctl add-flow dp0 idle_timeout=0,priority=10,ip,nw_dst=192.168.123.1,actions=output:1') 89   90     #switch0.cmd('tcpdump -i s0-eth0 -U -w aaa &') 91     #h0.cmd('tcpdump -i h0-eth0 -U -w aaa &') 92     info( "*** Running test\n" ) 93     h0.cmdPrint( 'ping -Q 0x10 -c 3 ' + h1.IP() ) 94     h0.cmdPrint( 'ping -Q 0x20 -c 3 ' + h1.IP() ) 95     h0.cmdPrint( 'ping -Q 0x30 -c 3 ' + h1.IP() ) 96     #h1.cmdPrint('iperf -s -p 12345 -u &') 97     #h0.cmdPrint('iperf -c ' + h1.IP() +' -u -b 10m -p 12345 -t 10 -i 1') 98   99     #print switch0.cmd( 'ovs-ofctl show dp0' )    100     #print switch1.cmd( 'ovs-ofctl show dp1' )101     #print switch2.cmd( 'ovs-ofctl show dp2' )102     #print switch3.cmd( 'ovs-ofctl show dp3' )103     #print switch4.cmd( 'ovs-ofctl show dp4' )  104     #print switch0.cmd( 'ovs-ofctl dump-tables  dp0' )105     #print switch0.cmd( 'ovs-ofctl dump-ports   dp0' )106     #print switch0.cmd( 'ovs-ofctl dump-flows  dp0' )107     #print switch0.cmd( 'ovs-ofctl dump-aggregate  dp0' )108     #print switch0.cmd( 'ovs-ofctl queue-stats dp0' )109  110     #print "Testing video transmission between h1 and h2"111     #h1.cmd('./myrtg_svc -u > myrd &')112     #h0.cmd('./mystg_svc -trace st 192.168.123.2')113  114     info( "*** Stopping network\n" )115     switch0.cmd( 'ovs-vsctl del-br dp0' )116     switch0.deleteIntfs()117     switch1.cmd( 'ovs-vsctl del-br dp1' )118     switch1.deleteIntfs()119     switch2.cmd( 'ovs-vsctl del-br dp2' )120     switch2.deleteIntfs()121     switch3.cmd( 'ovs-vsctl del-br dp3' )122     switch3.deleteIntfs()123     switch4.cmd( 'ovs-vsctl del-br dp4' )124     switch4.deleteIntfs()125     info( '\n' )126  127 if __name__ == '__main__':128     setLogLevel( 'info' )129     info( '*** Scratch network demo (kernel datapath)\n' )130     Mininet.init()131     myNet()

 

总结:

1.泛洪规则是根据优先级以及tos值而定

2.tos值设置越大,时间使用越少

转载于:https://www.cnblogs.com/a1164520408/p/9629255.html

你可能感兴趣的文章
Hive-有意思的query
查看>>
SylixOS调试与性能分析技术--内存泄漏检测
查看>>
消息队列-ActiveMQ
查看>>
LoadRunner12使用教程(二)——回放与录制
查看>>
工作收获点
查看>>
PhpStorm Terminal终端无法打开
查看>>
学习笔记TF036:实现Bidirectional LSTM Classifier
查看>>
应用监控预警&服务链路跟踪-Pinpoint介绍
查看>>
前端:后端,我要分手
查看>>
smarty isset 怎样使用
查看>>
用图帮你了解https的原理
查看>>
区块链如何改变AI
查看>>
HTML5/JavaScript UI控件Wijmo Enterprise 2018v2发布
查看>>
工业仪表盘控件Iocomp ActiveX常见问题(2):Visual Basic中的错误
查看>>
Docker下使用selenium+testng实现web自动化
查看>>
当执行npm时遇到的问题
查看>>
JAVA程序员面试30问(附带答案)
查看>>
Java性能调优攻略全分享,七步搞定!(附学习资料分享)
查看>>
企业级 SpringBoot 教程 (六)springboot整合mybatis
查看>>
程序员写了一段注释, 第二天惨被公司开除, 公司巧妙回怼
查看>>