文档章节

Open vSwitch使用案例扩展实验

wangxuwei
 wangxuwei
发布于 2017/05/20 15:49
字数 2356
阅读 35
收藏 0

一、实验目的

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

二、实验原理

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

三、实验任务

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

四、实验步骤

4.1 搭建环境

本实验创建一个带有Mininet镜像的虚拟机。

4.2 实验任务一

通过vi ovsSingleBr.py创建脚本并添加内容。本实验通过python脚本自定义拓扑:

#!/usr/bin/python
 
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" )
    switch0 = Node( 's0', inNamespace=False )
 
    h0 = Node( 'h0' )
    h1 = Node( 'h1' )
    h2 = Node( 'h2' )
 
    info( "*** Creating links\n" )
    Link( h0, switch0)
    Link( h1, switch0)
    Link( h2, switch0)
 
    info( "*** Configuring hosts\n" )
    h0.setIP( '192.168.123.1/24' )
    h1.setIP( '192.168.123.2/24' )
    h2.setIP( '192.168.123.3/24' )
       
    info( "*** Starting network using Open vSwitch\n" )
    switch0.cmd( 'ovs-vsctl del-br dp0' )
    switch0.cmd( 'ovs-vsctl add-br dp0' )
 
    for intf in switch0.intfs.values():
        print intf
        print switch0.cmd( 'ovs-vsctl add-port dp0 %s' % intf )
 
    # Note: controller and switch are in root namespace, and we
    # can connect via loopback interface
    #switch0.cmd( 'ovs-vsctl set-controller dp0 tcp:127.0.0.1:6633' )
  
    print switch0.cmd(r'ovs-vsctl show')
 
    print switch0.cmd(r'ovs-ofctl add-flow dp0 idle_timeout=0,priority=1,in_port=1,actions=flood' ) 
    print switch0.cmd(r'ovs-ofctl add-flow dp0 idle_timeout=0,priority=1,in_port=2,actions=flood' )
    print switch0.cmd(r'ovs-ofctl add-flow dp0 idle_timeout=0,priority=1,in_port=3,actions=flood' )
  
    print switch0.cmd(r'ovs-ofctl add-flow dp0 idle_timeout=0,priority=10,ip,nw_dst=192.168.123.1,actions=output:1' ) 
    print switch0.cmd(r'ovs-ofctl add-flow dp0 idle_timeout=0,priority=10,ip,nw_dst=192.168.123.2,actions=output:2' ) 
    print switch0.cmd(r'ovs-ofctl add-flow dp0 idle_timeout=0,priority=10,ip,nw_dst=192.168.123.3,actions=output:3')
 
    #switch0.cmd('tcpdump -i s0-eth0 -U -w aaa &')
    #h0.cmd('tcpdump -i h0-eth0 -U -w aaa &')
    info( "*** Running test\n" )
    h0.cmdPrint( 'ping -c 3 ' + h1.IP() )
    h0.cmdPrint( 'ping -c 3 ' + h2.IP() )
 
    #print switch0.cmd( 'ovs-ofctl show dp0' )    
    #print switch0.cmd( 'ovs-ofctl dump-tables  dp0' )
    #print switch0.cmd( 'ovs-ofctl dump-ports   dp0' )
    #print switch0.cmd( 'ovs-ofctl dump-flows  dp0' )
    #print switch0.cmd( 'ovs-ofctl dump-aggregate  dp0' )
    #print switch0.cmd( 'ovs-ofctl queue-stats dp0' )
 
    info( "*** Stopping network\n" )
    switch0.cmd( 'ovs-vsctl del-br dp0' )
    switch0.deleteIntfs()
    info( '\n' )
 
if __name__ == '__main__':
    setLogLevel( 'info' )
    info( '*** Scratch network demo (kernel datapath)\n' )
    Mininet.init()
    myNet()

通过命令chmod a+x ovsSingleBr.py将ovsSingleBr.py文件赋权限。此脚本并未连接控制器,只通过脚本中手动给交换机下发流表实现主机间的通信。

执行脚本、结果如下显示:

$ sudo ./ovsSingleBr.py 
*** Scratch network demo (kernel datapath)
*** Creating nodes
*** Creating links
*** Configuring hosts
*** Starting network using Open vSwitch
s0-eth0

s0-eth1

s0-eth2

2b05a0c0-015b-44cd-8ce8-d540d9f551c4
    Bridge "dp0"
        Port "s0-eth0"
            Interface "s0-eth0"
        Port "dp0"
            Interface "dp0"
                type: internal
        Port "s0-eth1"
            Interface "s0-eth1"
        Port "s0-eth2"
            Interface "s0-eth2"
    ovs_version: "2.5.2"







*** Running test
*** h0 : ('ping -c 3 192.168.123.2',)
PING 192.168.123.2 (192.168.123.2) 56(84) bytes of data.
64 bytes from 192.168.123.2: icmp_seq=1 ttl=64 time=1.27 ms
64 bytes from 192.168.123.2: icmp_seq=2 ttl=64 time=0.082 ms
64 bytes from 192.168.123.2: icmp_seq=3 ttl=64 time=0.076 ms

--- 192.168.123.2 ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2010ms
rtt min/avg/max/mdev = 0.076/0.478/1.276/0.564 ms
*** h0 : ('ping -c 3 192.168.123.3',)
PING 192.168.123.3 (192.168.123.3) 56(84) bytes of data.
64 bytes from 192.168.123.3: icmp_seq=1 ttl=64 time=0.599 ms
64 bytes from 192.168.123.3: icmp_seq=2 ttl=64 time=0.080 ms
64 bytes from 192.168.123.3: icmp_seq=3 ttl=64 time=0.042 ms

--- 192.168.123.3 ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2045ms
rtt min/avg/max/mdev = 0.042/0.240/0.599/0.254 ms
*** Stopping network
...

 

4.3 实验任务二

通过vi ovsMultiBr.py创建脚本并添加内容。本实验通过python脚本自定义拓扑:

#!/usr/bin/python
 
from mininet.net import Mininet
from mininet.node import Node
from mininet.link import TCLink
from mininet.log import  setLogLevel, info
 
def myNet():
    "Create network from scratch using Open vSwitch."
 
    info( "*** Creating nodes\n" )
    switch0 = Node( 's0', inNamespace=False )
    switch1 = Node( 's1', inNamespace=False )
    switch2 = Node( 's2', inNamespace=False )
    switch3 = Node( 's3', inNamespace=False )
    switch4 = Node( 's4', inNamespace=False )
    h0 = Node( 'h0' )
    h1 = Node( 'h1' )
 
    info( "*** Creating links\n" )
    linkopts0=dict(bw=100, delay='1ms', loss=0)
    linkopts1=dict(bw=1, delay='100ms', loss=0)
    linkopts2=dict(bw=10, delay='50ms', loss=0)
    linkopts3=dict(bw=100, delay='1ms', loss=0)
    TCLink( h0, switch0, **linkopts0)
    TCLink( switch0, switch1, **linkopts0)
    TCLink( switch0, switch2, **linkopts0)
    TCLink( switch0, switch3, **linkopts0)
    TCLink( switch1, switch4,**linkopts1)
    TCLink( switch2, switch4,**linkopts2)
    TCLink( switch3, switch4,**linkopts3)
    TCLink( h1, switch4, **linkopts0)
 
    info( "*** Configuring hosts\n" )
    h0.setIP( '192.168.123.1/24' )
    h1.setIP( '192.168.123.2/24' )
    info( str( h0 ) + '\n' )
    info( str( h1 ) + '\n' )
       
    info( "*** Starting network using Open vSwitch\n" )
    switch0.cmd( 'ovs-vsctl del-br dp0' )
    switch0.cmd( 'ovs-vsctl add-br dp0' )
    switch1.cmd( 'ovs-vsctl del-br dp1' )
    switch1.cmd( 'ovs-vsctl add-br dp1' )
    switch2.cmd( 'ovs-vsctl del-br dp2' )
    switch2.cmd( 'ovs-vsctl add-br dp2' )
    switch3.cmd( 'ovs-vsctl del-br dp3' )
    switch3.cmd( 'ovs-vsctl add-br dp3' )
    switch4.cmd( 'ovs-vsctl del-br dp4' )
    switch4.cmd( 'ovs-vsctl add-br dp4' )
 
    for intf in switch0.intfs.values():
        print intf
        print switch0.cmd( 'ovs-vsctl add-port dp0 %s' % intf )
 
    for intf in switch1.intfs.values():
        print intf
        print switch1.cmd( 'ovs-vsctl add-port dp1 %s' % intf )
 
    for intf in switch2.intfs.values():
        print intf
        print switch2.cmd( 'ovs-vsctl add-port dp2 %s' % intf )
 
    for intf in switch3.intfs.values():
        print intf
        print switch3.cmd( 'ovs-vsctl add-port dp3 %s' % intf )
 
    for intf in switch4.intfs.values():
        print intf
        print switch4.cmd( 'ovs-vsctl add-port dp4 %s' % intf )
   
    print switch1.cmd(r'ovs-ofctl add-flow dp1 idle_timeout=0,priority=1,in_port=1,actions=flood' )
    print switch1.cmd(r'ovs-ofctl add-flow dp1 idle_timeout=0,priority=1,in_port=1,actions=output:2' ) 
    print switch1.cmd(r'ovs-ofctl add-flow dp1 idle_timeout=0,priority=1,in_port=2,actions=output:1' )
    print switch2.cmd(r'ovs-ofctl add-flow dp2 idle_timeout=0,priority=1,in_port=1,actions=output:2' )
    print switch2.cmd(r'ovs-ofctl add-flow dp2 idle_timeout=0,priority=1,in_port=2,actions=output:1' )
    print switch3.cmd(r'ovs-ofctl add-flow dp3 idle_timeout=0,priority=1,in_port=1,actions=output:2' )    
    print switch3.cmd(r'ovs-ofctl add-flow dp3 idle_timeout=0,priority=1,in_port=2,actions=output:1' )
    print switch4.cmd(r'ovs-ofctl add-flow dp4 idle_timeout=0,priority=1,in_port=1,actions=output:4' )
    print switch4.cmd(r'ovs-ofctl add-flow dp4 idle_timeout=0,priority=1,in_port=2,actions=output:4' )
    print switch4.cmd(r'ovs-ofctl add-flow dp4 idle_timeout=0,priority=1,in_port=3,actions=output:4' )
    print switch4.cmd(r'ovs-ofctl add-flow dp4 idle_timeout=0,priority=1,in_port=4,actions=output:3' )
   
    #print switch0.cmd(r'ovs-ofctl add-flow dp0 idle_timeout=0,priority=10,ip,nw_dst=192.168.123.2,actions=output:4')
    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') 
    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')
    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') 
    #print switch0.cmd(r'ovs-ofctl add-flow dp0 idle_timeout=0,priority=10,ip,nw_dst=192.168.123.1,actions=output:1')
 
    #switch0.cmd('tcpdump -i s0-eth0 -U -w aaa &')
    #h0.cmd('tcpdump -i h0-eth0 -U -w aaa &')
    info( "*** Running test\n" )
    h0.cmdPrint( 'ping -Q 0x10 -c 3 ' + h1.IP() )
    h0.cmdPrint( 'ping -Q 0x20 -c 3 ' + h1.IP() )
    h0.cmdPrint( 'ping -Q 0x30 -c 3 ' + h1.IP() )
    #h1.cmdPrint('iperf -s -p 12345 -u &')
    #h0.cmdPrint('iperf -c ' + h1.IP() +' -u -b 10m -p 12345 -t 10 -i 1')
 
    #print switch0.cmd( 'ovs-ofctl show dp0' )    
    #print switch1.cmd( 'ovs-ofctl show dp1' )
    #print switch2.cmd( 'ovs-ofctl show dp2' )
    #print switch3.cmd( 'ovs-ofctl show dp3' )
    #print switch4.cmd( 'ovs-ofctl show dp4' )  
    #print switch0.cmd( 'ovs-ofctl dump-tables  dp0' )
    #print switch0.cmd( 'ovs-ofctl dump-ports   dp0' )
    #print switch0.cmd( 'ovs-ofctl dump-flows  dp0' )
    #print switch0.cmd( 'ovs-ofctl dump-aggregate  dp0' )
    #print switch0.cmd( 'ovs-ofctl queue-stats dp0' )
 
    #print "Testing video transmission between h1 and h2"
    #h1.cmd('./myrtg_svc -u > myrd &')
    #h0.cmd('./mystg_svc -trace st 192.168.123.2')
 
    info( "*** Stopping network\n" )
    switch0.cmd( 'ovs-vsctl del-br dp0' )
    switch0.deleteIntfs()
    switch1.cmd( 'ovs-vsctl del-br dp1' )
    switch1.deleteIntfs()
    switch2.cmd( 'ovs-vsctl del-br dp2' )
    switch2.deleteIntfs()
    switch3.cmd( 'ovs-vsctl del-br dp3' )
    switch3.deleteIntfs()
    switch4.cmd( 'ovs-vsctl del-br dp4' )
    switch4.deleteIntfs()
    info( '\n' )
 
if __name__ == '__main__':
    setLogLevel( 'info' )
    info( '*** Scratch network demo (kernel datapath)\n' )
    Mininet.init()
    myNet()

通过命令chmod a+x ovsMultiBr.py将ovsMultiBr.py文件赋权限。此脚本并未连接控制器,只通过脚本中手动给交换机下发流表实现主机间的通信。在此任务二中,给多个交换机下发流表,通过ping操作测试验证主机间的连通性,并通过-Q参数设置不通的tos值查看主机间的连通性。

执行脚本命令,结果如下显示:

$ sudo ./ovsMultiBr.py 
*** Scratch network demo (kernel datapath)
*** Creating nodes
*** Creating links
(100.00Mbit 1ms delay 0.00000% loss) (100.00Mbit 1ms delay 0.00000% loss) (100.00Mbit 1ms delay 0.00000% loss) (100.00Mbit 1ms delay 0.00000% loss) (100.00Mbit 1ms delay 0.00000% loss) (100.00Mbit 1ms delay 0.00000% loss) (100.00Mbit 1ms delay 0.00000% loss) (100.00Mbit 1ms delay 0.00000% loss) (1.00Mbit 100ms delay 0.00000% loss) (1.00Mbit 100ms delay 0.00000% loss) (10.00Mbit 50ms delay 0.00000% loss) (10.00Mbit 50ms delay 0.00000% loss) (100.00Mbit 1ms delay 0.00000% loss) (100.00Mbit 1ms delay 0.00000% loss) (100.00Mbit 1ms delay 0.00000% loss) (100.00Mbit 1ms delay 0.00000% loss) *** Configuring hosts
h0
h1
*** Starting network using Open vSwitch
s0-eth0

s0-eth1

s0-eth2

s0-eth3

s1-eth0

s1-eth1

s2-eth0

s2-eth1

s3-eth0

s3-eth1

s4-eth0

s4-eth1

s4-eth2

s4-eth3















*** Running test
*** h0 : ('ping -Q 0x10 -c 3 192.168.123.2',)
PING 192.168.123.2 (192.168.123.2) 56(84) bytes of data.
64 bytes from 192.168.123.2: icmp_seq=1 ttl=64 time=117 ms
64 bytes from 192.168.123.2: icmp_seq=2 ttl=64 time=107 ms
64 bytes from 192.168.123.2: icmp_seq=3 ttl=64 time=107 ms

--- 192.168.123.2 ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2002ms
rtt min/avg/max/mdev = 107.461/110.712/117.011/4.462 ms
*** h0 : ('ping -Q 0x20 -c 3 192.168.123.2',)
PING 192.168.123.2 (192.168.123.2) 56(84) bytes of data.
64 bytes from 192.168.123.2: icmp_seq=1 ttl=64 time=57.8 ms
64 bytes from 192.168.123.2: icmp_seq=2 ttl=64 time=57.4 ms
64 bytes from 192.168.123.2: icmp_seq=3 ttl=64 time=57.6 ms

--- 192.168.123.2 ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2002ms
rtt min/avg/max/mdev = 57.469/57.664/57.879/0.167 ms
*** h0 : ('ping -Q 0x30 -c 3 192.168.123.2',)
PING 192.168.123.2 (192.168.123.2) 56(84) bytes of data.
64 bytes from 192.168.123.2: icmp_seq=1 ttl=64 time=8.82 ms
64 bytes from 192.168.123.2: icmp_seq=2 ttl=64 time=8.41 ms
64 bytes from 192.168.123.2: icmp_seq=3 ttl=64 time=8.40 ms

--- 192.168.123.2 ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2003ms
rtt min/avg/max/mdev = 8.400/8.545/8.826/0.212 ms
*** Stopping network
..............


五、实验结论

此实验并未连接控制器,只通过脚本在单个/多个交换机中下发静态流表实现主机间的通信。在给多个交换机下发流表时,通过ping操作测试验证主机间的连通性,并通过-Q参数设置不同的tos值验证主机间的连通性及到达目的地址的时间,通过验证发现,tos值设置越大,时间使用越少。

 

  • 本站原创文章仅代表作者观点,不代表SDNLAB立场。所有原创内容版权均属SDNLAB,欢迎大家转发分享。但未经授权,严禁任何媒体(平面媒体、网络媒体、自媒体等)以及微信公众号复制、转载、摘编或以其他方式进行使用,转载须注明来自 SDNLAB并附上本文链接。

本文转载自:http://www.sdnlab.com/experimental-platform/

wangxuwei
粉丝 27
博文 343
码字总数 137316
作品 0
杭州
其他
私信 提问
启用 Open vSwitch - 每天5分钟玩转 OpenStack(127)

Linux Bridge 和 Open vSwitch 是目前 OpenStack 中使用最广泛的两种虚机交换机技术。 前面各章节我们已经学习了如何用 Linux Bridge 作为 ML2 mechanism driver 实现 Neutron 网络。 今天开...

CloudMAN
2016/12/19
181
0
详解 ML2 Core Plugin(II) - 每天5分钟玩转 OpenStack(72)

上一节我们讨论了 ML2 Plugin 解决的问题,本节将继续研究 ML2 的架构。 ML2 对二层网络进行抽象和建模,引入了 type driver 和 mechansim driver。 这两类 driver 解耦了 Neutron 所支持的网...

CloudMAN
2016/08/12
261
0
两张图总结 Neutron 架构 - 每天5分钟玩转 OpenStack(74)

前面我们详细讨论了 Neutron 架构,包括 Neutron Server,Core 和 Service Agent。现在用两张图做个总结。 先看第一张: 与 OpenStack 其他服务一样,Neutron 采用的是分布式架构,包括 Neut...

CloudMAN
2016/08/17
330
0
Neutron中Linux Bridge与Open vSwitch优劣势对比

目前说到虚拟交换机,通常会想到使用Open vSwitch做虚拟交换机,因为支持Open vSwitch的个人和企业都想要有一个开放的模式把他们的服务集成进OpenStack。 Open vSwitch社区做了大量的工作,希...

技术小能手
2018/07/09
0
0
OVS 中的各种网络设备 - 每天5分钟玩转 OpenStack(128)

上一节我们启用了 Open vSwitch,本节将查看当前的网络状态并介绍 Open vSwitch 涉及的各种网络设备 初始网络状态 查看一下当前的网络状态。 控制节点 ifconfig 显示控制节点上有三个网桥 br...

CloudMAN
2016/12/21
151
0

没有更多内容

加载失败,请刷新页面

加载更多

cesium调用天地图服务

本文转载于:专业的前端网站➧cesium调用天地图服务 全球矢量地图服务 var viewer = new Cesium.Viewer("cesiumContainer", { animation: false, //是否显示动画控件 baseLayerPi...

前端老手
24分钟前
4
0
Docker常用命令

场景一:镜像下载、运行及删除 COMMAND DESC 查看 docker images 列出所有镜像(images) docker ps 列出正在运行的容器(containers) docker ps -a 列出所有的容器 docker pull centos 下载cen...

_Change_
25分钟前
5
0
Spark ML使用DataFrame进行K-Means

1.前言 前一篇文章使用了RDD的方式,进行了K-Means聚类. 从Spark 2.0开始,程序包中基于RDD的API spark.mllib已进入维护模式.现在,用于Spark的主要机器学习API是软件包中基于DataFrame的API...

一位不知名的帅气网友
28分钟前
4
0
当遇到美女面试官之如何理解Redis的Expire Key(过期键)

  在面试中遇到美女面试官时,我们以为面试会比较容易过,也能好好表现自己技术的时候了。然而却出现以下这一幕,当美女面试官听说你使用过Redis时,那么问题来了。 👩面试官:Q1,你知道...

ccww_
32分钟前
5
0
干货来袭!游戏背景音乐的角色创建和主界面

角色创建/选择 在一些大型的游戏中,例如多人在线的游戏玩家必须创建一个游戏的虚拟人物进行扮演游戏。初次玩这款游戏的人都会进行创建,选择职业起名字性别选择编辑人设样式等等的操作,通常...

奇亿音乐
35分钟前
3
0

没有更多内容

加载失败,请刷新页面

加载更多

返回顶部
顶部