⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 cbr_traffic.cc

📁 运行于linux上的CIMS套件
💻 CC
字号:
/* -*-	Mode:C++; c-basic-offset:8; tab-width:8; indent-tabs-mode:t -*- *//* * Copyright (c) Xerox Corporation 1997. All rights reserved. *   * License is granted to copy, to use, and to make and to use derivative * works for research and evaluation purposes, provided that Xerox is * acknowledged in all documentation pertaining to any such copy or derivative * work. Xerox grants no other licenses expressed or implied. The Xerox trade * name should not be used in any advertising without its written permission. *   * XEROX CORPORATION MAKES NO REPRESENTATIONS CONCERNING EITHER THE * MERCHANTABILITY OF THIS SOFTWARE OR THE SUITABILITY OF THIS SOFTWARE * FOR ANY PARTICULAR PURPOSE.  The software is provided "as is" without * express or implied warranty of any kind. *   * These notices must be retained in any copies of any part of this software. */#include <stdlib.h> #include "random.h"#include "trafgen.h"#include "ranvar.h"int sq = 0; //SHK/*  * Constant bit rate traffic source.   Parameterized by interval, (optional) * random noise in the interval, and packet size.   */class CBR_Traffic : public TrafficGenerator { public:	CBR_Traffic();	virtual double next_interval(int&);	//HACK so that udp agent knows interpacket arrival time within a burst	inline double interval() { return (interval_); } protected:	virtual void start();	void init();	double rate_;     /* send rate during on time (bps) */	double interval_; /* packet inter-arrival time during burst (sec) */	double random_;	int seqno_;	int maxpkts_;};static class CBRTrafficClass : public TclClass { public:	CBRTrafficClass() : TclClass("Application/Traffic/CBR") {}	TclObject* create(int, const char*const*) {		return (new CBR_Traffic());	}} class_cbr_traffic;CBR_Traffic::CBR_Traffic() : seqno_(0){	bind_bw("rate_", &rate_);	bind("random_", &random_);	bind("packetSize_", &size_);	bind("maxpkts_", &maxpkts_);        /* Wan: */        bind("seqno_",&seqno_);}void CBR_Traffic::init(){        // compute inter-packet interval 	interval_ = (double)(size_ << 3)/(double)rate_;	if (agent_)		agent_->set_pkttype(PT_CBR);}void CBR_Traffic::start(){        init();        running_ = 1;        timeout();}double CBR_Traffic::next_interval(int& size){	// Recompute interval in case rate_ or size_ has changes	interval_ = (double)(size_ << 3)/(double)rate_;	double t = interval_;	if (random_)		t += interval_ * Random::uniform(-0.5, 0.5);		size = size_;        sq = seqno_; //SHK 	if (++seqno_ < maxpkts_)		return(t);	else		return(-1); }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -