博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
【Mininet】基于Mininet测量路径的损耗率
阅读量:4708 次
发布时间:2019-06-10

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

实验参考:

实验步骤:

1. 在装有mininet的虚拟机中新建文件mymininet.py并编辑以下内容,这里要注意一点,文中的dp0与dp1须填POX安装的虚拟机的地址,由于本次实验是在同一台虚拟机中安装,因此地址为127.0.0.1:

 

#!/usr/bin/python from mininet.net import Mininetfrom mininet.node import Nodefrom mininet.link import TCLinkfrom mininet.log import  setLogLevel, infofrom threading import Timerfrom mininet.util import quietRunfrom time import sleep def myNet(cname='controller', cargs='-v ptcp:'):    "Create network from scratch using Open vSwitch."    info( "*** Creating nodes\n" )    controller = Node( 'c0', inNamespace=False )    switch = Node( 's0', inNamespace=False )    switch1 = Node( 's1', inNamespace=False )    h0 = Node( 'h0' )    h1 = Node( 'h1' )        info( "*** Creating links\n" )    linkopts0=dict(bw=100, delay='1ms', loss=0)    linkopts1=dict(bw=100, delay='1ms', loss=10)    link0=TCLink( h0, switch, **linkopts0)    link1 = TCLink( switch, switch1, **linkopts1)         link2 = TCLink( h1, switch1, **linkopts0)    #print link0.intf1, link0.intf2    link0.intf2.setMAC("0:0:0:0:0:1")    link1.intf1.setMAC("0:0:0:0:0:2")    link1.intf2.setMAC("0:1:0:0:0:1")     link2.intf2.setMAC("0:1:0:0:0:2")     info( "*** Configuring hosts\n" )    h0.setIP( '192.168.123.1/24' )    h1.setIP( '192.168.123.2/24' )           info( "*** Starting network using Open vSwitch\n" )    switch.cmd( 'ovs-vsctl del-br dp0' )    switch.cmd( 'ovs-vsctl add-br dp0' )    switch1.cmd( 'ovs-vsctl del-br dp1' )    switch1.cmd( 'ovs-vsctl add-br dp1' )     controller.cmd( cname + ' ' + cargs + '&' )         for intf in switch.intfs.values():        print intf        print switch.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 )       # Note: controller and switch are in root namespace, and we    # can connect via loopback interface    switch.cmd( 'ovs-vsctl set-controller dp0 tcp:127.0.0.1:6633' )    switch1.cmd( 'ovs-vsctl set-controller dp1 tcp:127.0.0.1:6633' )      info( '*** Waiting for switch to connect to controller' )    while 'is_connected' not in quietRun( 'ovs-vsctl show' ):        sleep( 1 )        info( '.' )    info( '\n' )     #info( "*** Running test\n" )    h0.cmdPrint( 'ping -Q 0x64 -c 20 ' + h1.IP() )        sleep( 1 )     info( "*** Stopping network\n" )    controller.cmd( 'kill %' + cname )    switch.cmd( 'ovs-vsctl del-br dp0' )    switch.deleteIntfs()    switch1.cmd( 'ovs-vsctl del-br dp1' )    switch1.deleteIntfs()    info( '\n' ) if __name__ == '__main__':    setLogLevel( 'info' )    info( '*** Scratch network demo (kernel datapath)\n' )    Mininet.init()    myNet()

 

2. 在装有POX的虚拟机(本次实验与mininet安装在同一台虚拟机)里新建文件flow_stats.py并编辑以下内容:

#!/usr/bin/python# Copyright 2012 William Yu# wyu@ateneo.edu## This file is part of POX.## POX is free software: you can redistribute it and/or modify# it under the terms of the GNU General Public License as published by# the Free Software Foundation, either version 3 of the License, or# (at your option) any later version.## POX is distributed in the hope that it will be useful,# but WITHOUT ANY WARRANTY; without even the implied warranty of# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the# GNU General Public License for more details.## You should have received a copy of the GNU General Public License# along with POX. If not, see 
.# """This is a demonstration file created to show how to obtain flow and port statistics from OpenFlow 1.0-enabled switches. The flowstatistics handler contains a summary of web-only traffic.""" # standard includesfrom pox.core import corefrom pox.lib.util import dpidToStrimport pox.openflow.libopenflow_01 as offrom pox.lib.addresses import IPAddr, EthAddr # include as part of the betta branchfrom pox.openflow.of_json import *from pox.lib.recoco import Timerimport time log = core.getLogger() src_dpid = 0dst_dpid = 0input_pkts = 0output_pkts = 0 def getTheTime(): #fuction to create a timestamp flock = time.localtime() then = "[%s-%s-%s" %(str(flock.tm_year),str(flock.tm_mon),str(flock.tm_mday)) if int(flock.tm_hour)<10: hrs = "0%s" % (str(flock.tm_hour)) else: hrs = str(flock.tm_hour) if int(flock.tm_min)<10: mins = "0%s" % (str(flock.tm_min)) else: mins = str(flock.tm_min) if int(flock.tm_sec)<10: secs = "0%s" % (str(flock.tm_sec)) else: secs = str(flock.tm_sec) then +="]%s.%s.%s" % (hrs,mins,secs) return then # handler for timer function that sends the requests to all the# switches connected to the controller.def _timer_func (): for connection in core.openflow._connections.values(): connection.send(of.ofp_stats_request(body=of.ofp_flow_stats_request())) connection.send(of.ofp_stats_request(body=of.ofp_port_stats_request())) log.debug("Sent %i flow/port stats request(s)", len(core.openflow._connections)) # handler to display flow statistics received in JSON format# structure of event.stats is defined by ofp_flow_stats()def _handle_flowstats_received (event): #stats = flow_stats_to_list(event.stats) #log.debug("FlowStatsReceived from %s: %s", dpidToStr(event.connection.dpid), stats) global src_dpid, dst_dpid, input_pkts, output_pkts #print "src_dpid=", dpidToStr(src_dpid), "dst_dpid=", dpidToStr(dst_dpid) for f in event.stats: if f.match.dl_type==0x0800 and f.match.nw_dst==IPAddr("192.168.123.2") and f.match.nw_tos==0x64 and event.connection.dpid==src_dpid: #print "input: ", f.byte_count, f.packet_count input_pkts = f.packet_count if f.match.dl_type==0x0800 and f.match.nw_dst==IPAddr("192.168.123.2") and f.match.nw_tos==0x64 and event.connection.dpid==dst_dpid: #print "output: ", f.byte_count, f.packet_count output_pkts = f.packet_count if input_pkts !=0: print getTheTime(), "Path Loss Rate =", (input_pkts-output_pkts)*1.0/input_pkts*100, "%" # handler to display port statistics received in JSON formatdef _handle_portstats_received (event): #print "\n<<

 

3. 运行脚本flow_stats.py。

4. 运行脚本mymininet.py:

 

 

5. 查看POX控制台信息:

 

实验结论:

基于Mininet的脚本设计拓扑,主要是对交换机间传输数据包的路径损耗速率进行设置,并且通过控制器POX进行测量。

转载于:https://www.cnblogs.com/ptolemy/p/11255968.html

你可能感兴趣的文章
iOS应用日志:开始编写日志组件与异常日志
查看>>
Linux通过NFS实现文件共享
查看>>
java安装1.8和1.7,报错:Error: Registry key 'Software\JavaSoft\Java Runtime Environment'\CurrentVers...
查看>>
iOS多线程编程之NSOperation和NSOperationQueue的使用(转自容芳志专栏)
查看>>
svn不能添加.a文件的解决方法
查看>>
15模块-Maps【管理地图控件】
查看>>
[转]crontab命令指南
查看>>
vue 二级列表折叠面板
查看>>
ClientValidationEnabled
查看>>
Linux 硬盘分区、分区、删除分区、格式化、挂载、卸载
查看>>
Jam - an open-source build system
查看>>
编写一个程序,将d:\java目录下的所有.java文件复制到d:\jad目录下,并将原来文件的扩展名从.java改为.jad。...
查看>>
Mysql命令大全
查看>>
nginx.conf 基础配置
查看>>
centos创建文件命令
查看>>
【php】 php能做什么
查看>>
VTK初学一,比较常见的错误2
查看>>
结队-贪吃蛇-项目进度
查看>>
Axure自动备份功能!让意外不在可怕!
查看>>
robot Framework实战
查看>>