【Mininet】基于Mininet测量路径的损耗率

实验参考:

基于Mininet测量路径的损耗率

SDN常用控制器安装部署之POX篇

实验步骤:

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

 

#!/usr/bin/pythonfrom mininet.net import Mininet
from mininet.node import Node
from mininet.link import TCLink
from mininet.log import  setLogLevel, info
from threading import Timer
from mininet.util import quietRun
from time import sleepdef 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.intf2link0.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 intfprint switch.cmd( 'ovs-vsctl add-port dp0 %s' % intf )for intf in switch1.intfs.values():print intfprint switch1.cmd( 'ovs-vsctl add-port dp1 %s' % intf )# Note: controller and switch are in root namespace, and we# can connect via loopback interfaceswitch.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 <http://www.gnu.org/licenses/>.
#
 
"""
This is a demonstration file created to show how to obtain flow 
and port statistics from OpenFlow 1.0-enabled switches. The flow
statistics handler contains a summary of web-only traffic.
"""# standard includes
from pox.core import core
from pox.lib.util import dpidToStr
import pox.openflow.libopenflow_01 as of
from pox.lib.addresses import IPAddr, EthAddr# include as part of the betta branch
from pox.openflow.of_json import *
from pox.lib.recoco import Timer
import timelog = core.getLogger()src_dpid = 0
dst_dpid = 0
input_pkts = 0
output_pkts = 0def getTheTime():  #fuction to create a timestampflock = 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_countinput_pkts = f.packet_countif 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_countif 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 format
def _handle_portstats_received (event):#print "\n<<<STATS-REPLY: Return PORT stats for Switch", event.connection.dpid,"at ",getTheTime()#for f in event.stats:#if int(f.port_no)<65534:#print "   PortNo:", f.port_no, " Fwd's Pkts:", f.tx_packets, " Fwd's Bytes:", f.tx_bytes, " Rc'd Pkts:", f.rx_packets, " Rc's Bytes:", f.rx_bytes#print "   PortNo:", f.port_no,  " TxDrop:", f.tx_dropped, " RxDrop:", f.rx_dropped, " TxErr:", f.tx_errors, " RxErr:", f.rx_errors, " CRC:", f.rx_crc_err, " Coll:", f.collisions stats = flow_stats_to_list(event.stats)log.debug("PortStatsReceived from %s: %s", dpidToStr(event.connection.dpid), stats)def _handle_ConnectionUp (event):global src_dpid, dst_dpidprint "ConnectionUp: ", dpidToStr(event.connection.dpid)for m in event.connection.features.ports:if m.name == "s0-eth0":src_dpid = event.connection.dpidelif m.name == "s1-eth0":dst_dpid = event.connection.dpidmsg = of.ofp_flow_mod()msg.priority =1msg.idle_timeout = 0msg.match.in_port =1msg.actions.append(of.ofp_action_output(port = of.OFPP_ALL))event.connection.send(msg)msg = of.ofp_flow_mod()msg.priority =1msg.idle_timeout = 0msg.match.in_port =2msg.actions.append(of.ofp_action_output(port = of.OFPP_ALL))event.connection.send(msg)msg = of.ofp_flow_mod()msg.priority =10msg.idle_timeout = 0msg.hard_timeout = 0msg.match.dl_type = 0x0800msg.match.nw_tos = 0x64msg.match.in_port=1msg.match.nw_dst = "192.168.123.2"msg.actions.append(of.ofp_action_output(port = 2))event.connection.send(msg)msg = of.ofp_flow_mod()msg.priority =10msg.idle_timeout = 0msg.hard_timeout = 0msg.match.dl_type = 0x0800msg.match.nw_tos = 0x64msg.match.nw_dst = "192.168.123.1"msg.actions.append(of.ofp_action_output(port = 1))event.connection.send(msg)# main functiont to launch the module
def launch ():# attach handsers to listnerscore.openflow.addListenerByName("FlowStatsReceived", _handle_flowstats_received) core.openflow.addListenerByName("PortStatsReceived", _handle_portstats_received) core.openflow.addListenerByName("ConnectionUp", _handle_ConnectionUp)# timer set to execute every five secondsTimer(1, _timer_func, recurring=True)

 

3. 运行脚本flow_stats.py。

4. 运行脚本mymininet.py:

 

 

5. 查看POX控制台信息:

 

实验结论:

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

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

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/549985.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

【Mininet】Mininet设置带宽之简单性能测试

实验参考&#xff1a; Mininet设置带宽之简单性能测试 实验步骤&#xff1a; 1. 进入mininet/custom目录下&#xff0c;通过vi mymininet1.py创建脚本并添加内容&#xff08;本实验通过python脚本自定义拓扑&#xff0c;创建包含一个交换机、四个主机的网络拓扑&#xff09;&am…

java 配置tocat_Tomcat安装配置及Eclipse配置详解

整个安装过程我们先学习安装jdk和配置然后是安装tomcat和配置&#xff0c;最后我们学习安装eclipse和配置以及web程序的使用和发布举例1. 安装jdk和配置(1)下载jdk安装包&#xff1a;(2)按照步骤点击下一步进行jdk软件的安装。(3)配置javajdk的环境变量**配置环境变量包括java_…

【Mininet】Mininet动态改变转发规则实验

实验参考&#xff1a; Mininet动态改变转发规则实验 SDN常用控制器安装部署之POX篇 实验步骤&#xff1a; 1. 在装有POX的虚拟机里&#xff0c;/root/pox目录下新建文件lab_controller.py&#xff0c;并编辑以下内容&#xff1a; 1 from pox.core import core2 3 import pox.o…

php搜索图片不显示不出来了,PHP CURL采集百度搜寻结果图片不显示问题的解决方法【第1/4页】...

1.根据关键字采集百度搜寻结果根据关键字采集百度搜寻结果&#xff0c;可以使用curl实现&#xff0c;代码如下&#xff1a;<?php function doCurl($url, $dataarray(), $headerarray(), $timeout30){$ch curl_init();curl_setopt($ch, CURLOPT_URL, $url);curl_setopt($ch…

数据库,XML,MDB --- 我们来TXT...

数据库,XML,MDB --- 我们来TXT... 转贴请注明来自http://blog.csdn.net/a11s 作者:董含君 blog已经迁移到http://a11s.cnblogs.com呵呵,有数据库当然用数据库,SQL Server多好用, mySQL多好用... 不能给客户端随便装服务啊,那就access或者其他单机的xsl之类,或者干脆XML XML是…

php文件怎么设置隐藏显示代码,php文件隐藏的方法

php文件隐藏的方法&#xff1a;1、在“httpd.conf”里任意位置添加代码为“AddType application/x-httpd-php .asp .py .pl .jsp aspx”&#xff1b;2、对PHP使用未知扩展名。隐藏你的.php文件今天做PHP在线手册镜像的时候看到了这个方法,哈哈,以前都没有注意到,所以说,手册是最…

【Mininet】Mininet脚本实现控制交换机行为

实验参考&#xff1a; Mininet脚本实现控制交换机行为 实验步骤&#xff1a; 1. 一台交换机两台主机&#xff0c;实现从1端口进入的数据流转发到2端口&#xff0c;从2端口进入的数据流转发到1端口。 1. 创建新文件mymininet1.py并编辑以下内容&#xff08;注意要将控制器设置为…

matlab2018b中svm无法运行,关于matlab2018a版本错误使用 svmclassify 分类器

当我们照常使用分类器函数svmclassify时&#xff0c;2018版的matlab会报出以下错误&#xff1a;解决办法&#xff1a;1&#xff0c;下载libsvm(一般下载最新版本就ok了)包&#xff0c;并将其添加至matlab的toolbox文件里。并打开matlab编辑器&#xff0c;主页 / 设置路径 / 添…

【Mininet】Mininet MAC地址学习实验

实验参考&#xff1a; Mininet MAC地址学习实验 实验步骤&#xff1a; 1. 在虚拟机上启动mininet&#xff0c;创建一个线型拓扑&#xff08;如下图所示&#xff09;&#xff0c;控制器设置为无&#xff08;# sudo mn –-topo linear –-mac –-switch ovsk –-controllernone&a…

【Mininet】基于Mininet的VxLAN实验

实验参考&#xff1a; 基于Mininet的VxLAN实验 实验步骤&#xff1a; 1. 如下图所示&#xff0c;在两台虚拟机中利用mininet创建两个网络&#xff0c;利用VxLAN连通这两个mininet环境。关闭默认的控制器后&#xff0c;通过下发流表确保网络的连通性&#xff1a; 2. 先查看两台虚…

Ajax基石脚本异步并发调用参数传递

在Ajax开发框架中&#xff0c;最基本的划分是服务器端和客户端。服务器端相对来说比较简单&#xff0c;只要是可以开发动态网页的语言都可以胜任&#xff1b;客户端浏览器就是JScript/JavaScript的天下了&#xff0c;好像没有看到有VBScript做的Ajax客户端库&#xff0c;就算它…

matlab disteclud,机器学习实战ByMatlab(3)K-means算法

K-means算法属于无监督学习聚类算法&#xff0c;其计算步骤还是挺简单的&#xff0c;思想也挺容易理解&#xff0c;而且还可以在思想中体会到EM算法的思想。K-means 算法的优缺点&#xff1a;1.优点&#xff1a;容易实现2.缺点&#xff1a;可能收敛到局部最小值&#xff0c;在大…

智能安全实验室-Defendio杀马2.4.0.420-实时防护-内存防护、新浏览器导航界面...

智能安全实验室&#xff0d;杀马(Defendio) 2.4.0.420 &#xff1a;实时防护&#xff0d;内存防护、新浏览器导航界面等 详细信息请访问&#xff1a;http://unruledboy.cnblogs.com/archive/2006/02/02/Defendio.html怎样获取最新版本&#xff1f;□智能更新&#xff1a;打开现…

【RTOS】基于V7开发板的最新版FreeRTOS V10.2.0程序模板,含MDK和IAR,支持串口打印任务执行情况...

模板下载&#xff1a; 链接&#xff1a;https://pan.baidu.com/s/1N32Hx7cTbDoRinuzTUB3zw 提取码&#xff1a;6aox 1、MDK使用MDK5.26及其以上版本。 2、IAR使用IAR8.30及其以上版本。 3、教程直可以先看之前发布的&#xff0c;除了新增的一些功能&#xff0c;其它功能基本…

自动图片轮播php源码,js实现自动图片轮播代码

本文实例为大家分享了轮播的具体代码&#xff0c;自动轮播&#xff0c;居中显示&#xff0c;供大家参考&#xff0c;具体内容如下#div1{width: 192px;height: 120px;border: 1px solid gray;margin: 0 auto;position: relative;overflow: hidden;}#div1 img{position: absolute…

【Open vSwitch】Open vSwitch使用案例扩展实验

实验参考&#xff1a; Open vSwitch使用案例扩展实验 实验步骤&#xff1a; 1. 实验任务一。 1.创建新文件ovsSingleBr.py并编辑以下内容&#xff1a; 1 #!/usr/bin/python2 3 from mininet.net import Mininet4 from mininet.node import Node5 from mininet.link import Lin…

【Open vSwitch】Open vSwitch的GRE隧道实验网络

实验参考&#xff1a; Open vSwitch的GRE隧道实验网络 实验步骤&#xff1a; 1. 配置VM: 1. 本次要实现的拓扑如下&#xff1a; 先验证虚拟机VM1的OvS服务是否被启动好&#xff1a; 2. 在VM1中创建两个bridge&#xff1a; 1 # ovs-vsctl add-br br0 2 # ovs-vsctl add-br br1 3…

php web音视频通话,实现音视频通话(Web)

实现音视频通话(Web)网易云信音视频通话产品的基本功能包括高质量的实时音视频通话。当您成功初始化 SDK 之后&#xff0c;您可以简单体验本产品的基本业务流程。本文档为您展示音视频通话提供的基本业务流程。前提条件请确认您已完成以下操作&#xff1a;快速跑通Sample Code注…

【Open vSwitch】Open vSwitch的VxLAN隧道网络实验

验参考&#xff1a; Open vSwitch的VxLAN隧道网络实验 实验步骤&#xff1a; 1. 预先配置: 1. 验证两虚拟机的OvS服务是否被启动好&#xff1a; # ps –ef|grep ovs 2. 登陆两台安装Mininet的虚拟机&#xff0c;分别查看IP地址&#xff1a; VM1&#xff08;192.168.0.102&#…

centos oracle创建库,CentOS Oracle安装必要的软件创建数据库

CentOS Oracle安装系统的特性&#xff0c;既可作为高校计算机专业CentOS Oracle安装学习&#xff0c;也可以作为CentOS系统开源爱好者、CentOS系统用户CentOS Oracle安装系统的特性&#xff0c;&#xff0c;既可作为高校计算机专业CentOS Oracle安装学习&#xff0c;也可以作为…