如何在NS2中产生和使用Poisson Traffic
转载地址:http://140.116.164.80/~smallko/ns2/poisson_ch.htm
1.請把底下的程式碼拷貝到一個新的檔案(poisson.cc),並且把poisson.cc放在~//tools的目錄下
(若是在make時有問題,請自己用手輸入底下的程式碼)
#include <stdlib.h> #include "random.h" #include "trafgen.h" #include "ranvar.h" class Poisson_Traffic : public TrafficGenerator { public: Poisson_Traffic(); virtual void timeout(); virtual double next_interval(int&); protected: virtual void start(); void init(); double rate_; /* Mean sending rate (b/s) */ double interval_; /* Mean time between each packet generation (sec) */ int seqno_; /* Each generated packet has a unique sequence number */ int maxpkts_; /* No source can generate more than maxpkts_ packets */ }; static class PoissonTrafficClass : public TclClass { public: PoissonTrafficClass() : TclClass("Application/Traffic/Poisson") {} TclObject* create(int, const char*const*) { return (new Poisson_Traffic()); } } class_poisson_traffic; Poisson_Traffic::Poisson_Traffic() : seqno_(0) { bind_bw("rate_", &rate_); bind("interval_", &interval_); bind("packetSize_", &size_); bind("maxpkts_", &maxpkts_); } void Poisson_Traffic::init() { /* * If the user did not specify a mean packet inter-generation time, * then calculate it based on the rate_ and the packetSize_ */ if (interval_ < 0.0) interval_ = (double)(size_ << 3) / (double)rate_; /* * Assign unique packet type ID to each packet sent by a Poisson * source. */ if (agent_) agent_->set_pkttype(PT_POISSON); } void Poisson_Traffic::start() { init(); running_ = 1; timeout(); } double Poisson_Traffic::next_interval(int& size) { size = size_; if (++seqno_ < maxpkts_) return(Random::exponential(interval_)); else return(-1); } void Poisson_Traffic::timeout() { if(! running_) return; agent_->sendmsg(size_); nextPkttime_ = next_interval(size_); timer_.resched(nextPkttime_); } |
2.修改~/tcl/lib/ns-default.tcl
請加入底下的程式碼
Application/Traffic/Poisson set interval_ -1.0 Application/Traffic/Poisson set rate_ 1Mb Application/Traffic/Poisson set packetSize_ 500 Application/Traffic/Poisson set maxpkts_ 268435456 |
3.修改~/trace/cmu-trace.cc
………………………..
case PT_GAF:
case PT_PING:
break;
case PT_POISSON:
break;
………………………
4.修改~/trace/trace.cc
……………………..
/* UDP's now have seqno's too */
if (t == PT_RTP || t == PT_CBR || t == PT_UDP || t == PT_EXP ||
t == PT_PARETO || t == PT_POISSON)
seqno = rh->seqno();
……………………..
5.修改packet.h
……………………………
PT_FTP,
PT_PARETO,
PT_EXP,
PT_POISSON,
PT_INVAL,
……………………………
name_[PT_EXP]= "exp";
name_[PT_POISSON]= "poisson";
………………………………..
6.修改Makefile
………………………………………
tools/expoo.o tools/cbr_traffic.o tools/poisson.o \
………………………………………
7.重新編譯
make clean; make
測試的tcl script
#Create a simulator object set ns [new Simulator] #Define different colors for data flows $ns color 1 Blue $ns color 2 Red #Open the nam trace file set nf [open out.nam w] $ns namtrace-all $nf set nd [open out.tr w] $ns trace-all $nd #Define a 'finish' procedure proc finish {} { global ns nf nd $ns flush-trace #Close the trace file close $nf close $nd #Execute nam on the trace file #exec nam out.nam & exit 0 } #Create four nodes set n0 [$ns node] set n1 [$ns node] set n2 [$ns node] set n3 [$ns node] #Create links between the nodes $ns duplex-link $n0 $n2 1Mb 10ms DropTail $ns duplex-link $n1 $n2 1Mb 10ms DropTail $ns duplex-link $n3 $n2 1Mb 10ms SFQ $ns duplex-link-op $n0 $n2 orient right-down $ns duplex-link-op $n1 $n2 orient right-up $ns duplex-link-op $n2 $n3 orient right #Monitor the queue for the link between node 2 and node 3 $ns duplex-link-op $n2 $n3 queuePos 0.5 #Create a UDP agent and attach it to node n0 set udp0 [new Agent/UDP] $udp0 set packetSize_ 1500 $udp0 set class_ 1 $ns attach-agent $n0 $udp0 # Create a Poisson traffic source and attach it to udp0 set Poi0 [new Application/Traffic/Poisson] $Poi0 set packetSize_ 1500 $Poi0 set rate_ 1Mb $Poi0 attach-agent $udp0 #Create a UDP agent and attach it to node n1 set udp1 [new Agent/UDP] $udp1 set class_ 2 $ns attach-agent $n1 $udp1 # Create a CBR traffic source and attach it to udp1 set cbr1 [new Application/Traffic/CBR] $cbr1 set packetSize_ 500 $cbr1 set interval_ 0.005 $cbr1 attach-agent $udp1 #Create a Null agent (a traffic sink) and attach it to node n3 set null0 [new Agent/Null] $ns attach-agent $n3 $null0 #Connect the traffic sources with the traffic sink $ns connect $udp0 $null0 $ns connect $udp1 $null0 #Schedule events for the CBR agents $ns at 0.5 "$Poi0 start" $ns at 1.0 "$cbr1 start" $ns at 4.0 "$cbr1 stop" $ns at 4.5 "$Poi0 stop" #Call the finish procedure after 5 seconds of simulation time $ns at 5.0 "finish" #Run the simulation $ns run |
參考資料
1. http://www.cs.stonybrook.edu/%7Ekostas/src/poisson/install-poisson-ns-2.27.html
如何在NS2中产生和使用Poisson Traffic相关推荐
- python 概率分布函数_如何在Python中实现这五类强大的概率分布
匿名用户 1级 2016-04-25 回答 首页 所有文章 观点与动态 基础知识 系列教程 实践项目 工具与框架应用 工具资源 伯乐在线 > Python - 伯乐在线 > 所有文章 &g ...
- 如何在SharePoint2010中添加Deep Zoom Image
如何在SharePoint2010中添加Deep Zoom Image 应用范围 SharePoint 2010 Foundation:SharePoint 2010 Standard:SharePo ...
- php如何对数组进行分组,如何在PHP中对数组进行分组排序
如何在PHP中对数组进行分组排序 发布时间:2021-01-04 16:28:51 来源:亿速云 阅读:98 作者:Leah 这篇文章将为大家详细讲解有关如何在PHP中对数组进行分组排序,文章内容质量 ...
- html中section与div,如何在html中的section标签内包含div标签
我正在制作一个完整版块的页面网站,如this.每个页面都有自己的标签.目前我的网页有4个部分(呈现不同的背景颜色).如何在html中的section标签内包含div标签 我的第一部分有一个容器div, ...
- html img调用js,html调用js变量 如何在html中输出js文件中的变量
html页面代码中怎么调用js变量?html页面代码中怎么调用js变量,例如 在html代码中插入js代码: a=取浏览你把index1.js 中的onReady 去掉,把index1.js改成 fu ...
- 如何在OpenCV中为InRange阈值选择颜色的最佳HSV值
如何在OpenCV中为InRange阈值选择颜色的最佳HSV值 1. 效果图 2. 源码 参考 之前的博客介绍了如何使用Python,OpenCV通过HSV颜色空间转换检测对象,并进行轨迹追踪.怎么选 ...
- 管理 zabbix_Zabbix 2019 峰会丨看睿象云如何在 Zabbix 中玩转告警
2019年11月29日-30日,为期两天的 Zabbix 大会中国站在北京盛大召开,本届 Zabbix 大会以"新视界,新技术,共建未来新监控!"为主题,为与会人员提供前沿的监控技 ...
- 如何在JavaScript中实现链接列表
If you are learning data structures, a linked list is one data structure you should know. If you do ...
- csv文件示例_如何在R中使用数据框和CSV文件-带有示例的详细介绍
csv文件示例 Welcome! If you want to start diving into data science and statistics, then data frames, CSV ...
最新文章
- 远程办公是巨头游戏?十倍扩容,他们如何做到百万级并发流量
- 视频可以转换html,10 个免费的 HTML 视频转换工具
- 电脑故障检测软件_有什么软件可以检测出电脑配置是否达到游戏配置。
- MongoDB入门教程(1)
- 每次新建Android项目都报样式找不到的错误?
- 网络(9)-HTTPS协议
- mysql dr模式_DR模式下的mysql (abb读写分离)
- 1000道Python题库系列分享五(40道)
- 怎样开图纸便宜_一步一步教你如何看懂工程图纸,值得收藏!
- SqlParameter的使用
- 知识计算机硬件 教学设计,计算机硬件教案
- 推荐几个比较骚的技术公众号【文末福利】
- JQuery实现图片点击放大
- CDH安装手册(自整理)
- 如何配置系统数据库服务器地址,如何配置系统数据库服务器地址
- js获取当前浏览器页面高度及宽度信息的方法
- C#窗体程序连接SQL Server数据库实现账号登录、账号注册、修改密码、账号注销和实名认证(不定时更新)
- 想要学习人工智能,有哪些大学专业可以选择?
- IT外包劣根难除?自由职客开创IT外包行业新势态
- 大数据算法可能塑造更恶劣的互联网世界
热门文章
- java 8 详解_java8新特性详解(转载)
- 阿黛尔 优秀的两首音乐作品(live)
- 如何在storyboard设置圆角(cornerRadius)、边框(borderWidth)等操作。
- 激荡 20 年:IE 浏览器的辉煌与落寞
- RandomAccess接口有什么作用?
- 招投标法、政府采购法、合同法、著作权法
- 【广州华锐互动】ChatGpt在元宇宙游戏领域有哪些应用场景?
- Linux文件,目录权限管理
- 中国医用口罩市场前瞻及投资策略建议报告2022-2028年
- Nancy框架:在页面使用Nancy.ViewEngines.Razor.NancyRazorViewBase时显示ViewEngines找不到