Open vSwitch使用案例扩展实验

实验参考

Open vSwitch使用案例扩展实验

实验步骤

1. 实验任务一。

1.创建新文件ovsSingleBr.py并编辑以下内容:

#!/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()

2.改为可执行文件并将其执行:

./ovsSingleBr.py

结果如下显示:

  

2. 实验任务二。

1. 创建新文件ovsMultiBr.py并编辑以下内容:

#!/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()

2. 改为可执行文件并将其执行:

./ovsMultiBr.py

结果如下显示:

3.实验总结

不知道为什么,我的截图,这个ping总有问题,是我代码敲错了么?可是这个实验我重复做了三次,它总是这样的。我还会回来解决它的!!

原文地址:https://www.cnblogs.com/fcw245838813/p/12267213.html

时间: 2024-08-29 17:18:08

Open vSwitch使用案例扩展实验的相关文章

Open vSwitch的GRE隧道实验网络

实验参考 Open vSwitch的GRE隧道实验网络 实验步骤: 1.配置VM1 (1)Open vSwitch服务验证 验证虚拟机VM1的OvS服务是否被启动好: # ps -ef|grep ovs  2. 在VM1中创建两个bridge: # ovs-vsctl add-br br0 # ovs-vsctl add-br br1  3. 配置br0: # ifconfig eth0 0 up # ifconfig br0 20.0.2.12 netmask 255.255.255.248

搭建基于Open vSwitch的VxLAN隧道实验

1. VXLAN简介 VXLAN 是 Virtual eXtensible LANs 的缩写,它是对 VLAN 的一个扩展,是非常新的一个 tunnel 技术,在Open vSwitch中应用也非常多.Linux 内核的 upstream 中也刚刚加入 VXLAN 的实现.相比 GRE tunnel 它有着很好的扩展性,同时解决了很多其它问题. 从数量上讲,它把 12 bit 的 VLAN tag 扩展成了 24 bit.从实现上讲,它是 L2 over UDP,它利用了UDP 同时也是 IPv

caffe扩展实验

caffe实现caltech101图像分类 这里讲述如何用自己的数据集,在caffe平台一步步实现的过程[新手参考]; 主要分为下面3个环节: 数据集准备 Dataset preparation caffe网络准备 Caffe network files preparation 从零开始训练和微调 From scratch training and finetuning 复制imagenet项目到MyNet,修改内容完成caltech101数据集分类网络 数据集准备: caltech101(加利

PPTP VPN在Cisco Router上的应用二:PPTP扩展实验

本文继续上一篇关于PPTP VPN的实验. 拓扑图依旧使用上次的拓扑,配置不变.读者需要在上一篇博文的基础上来阅读本文. 拓扑图如下: 本博文关于PPTP的实验包括以下内容: 实验1:基本的PPTP Server配置和Client配置(WinXP和Win7) 实验2:使用不加密的PPTP配置 实验3:使用PAP或CHAP认证的PPTP配置 实验4:PPTP问题1:TCP1723被阻止导致无法拨通 实验5:GRE防火墙检测和PAT转换问题 实验6:综合实验1:PPTP在实际工程的应用 实验7:综合

IPSec VPN扩展实验

需求:Site1 和 Site2,Site3分别建立IPSec VPN,实现流量加解密. Site1: interface Loopback0 ip address 1.1.1.1 255.255.255.0 ! interface FastEthernet0/0 ip address 192.168.12.1 255.255.255.0 ! ip route 0.0.0.0 0.0.0.0 192.168.12.254 crypto isakmp policy 100 encr 3des au

扩展实验:LAMP+NFS

拓扑图 Http server1 172.20.10 http server2 172.20.1.11 mariadb\NFS 172.20.1.12 效果:客户机在使用IP分别访问server1 和 server2,使用相同的账号.密码,看到帖子的内容完全一样,上传的附件在两台server中完全一致. 实施过程: 在http server 1.2中安装Apache.php,两台机的过程一样,则不重复列出过程 172.20.1.10安装Apache和php 编译安装Apache2.4版本,事先安

BGP项目实验案例(基于华为设备)

一:BGP概述1:自治系统自治系统是由同一个技术管理机构管理.使用同一选录策略的一组路由器的集合. 2:动态路由的分类(1)按自治系统分类IGP:自治系统内部路由协议,包括RIP.OSPF.ISIS.EIGRPEGP:自治系统之间的路由协议,包括BGP,BGP的作用是控制路由的传播和选择最优路由(2)按协议类型分类距离矢量路由协议链路状态路由协议 3:BGP的概念BGP是一种运行在AS和AS之间的动态路由协议,主要作用是在AS之间自动交换无环路信息.以此来构建AS的拓扑图,从而消除路由环路并实施

Tomcat服务器 Tomcat应用案例 、 Varnish代理服务器

案例1:安装部署Tomcat服务器案例2:使用Tomcat部署虚拟主机案例3:使用Varnish加速Web1 案例1:安装部署Tomcat服务器1.1 问题 本案例要求部署Tomcat服务器,具体要求如下:安装部署JDK基础环境安装部署Tomcat服务器创建JSP测试页面,文件名为test.jsp,显示服务器当前时间然后客户机访问此Web服务器验证效果:使用火狐浏览器访问Tomcat服务器的8080端口,浏览默认首页使用火狐浏览器访问Tomcat服务器的8080端口,浏览默认测试页面1.2 方案

在CentOS7上配置Open vSwitch和VXLAN

在CentOS7上配置Open vSwitch和VXLAN 环境 实验环境 主机环境 [[email protected] ~]$ uname -a Linux node0 3.10.0-123.9.3.el7.x86_64 #1 SMP Thu Nov 6 15:06:03 UTC 2014 x86_64 x86_64 x86_64 GNU/Linux [[email protected] ~]$ cat /etc/redhat-release CentOS Linux release 7.0