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

📄 ertps_traffic.cc

📁 WIMAX code for NS-2, v1.05
💻 CC
字号:
/**************************************************************************************
* *Copyright (c) 2006 Regents of the University of Chang Gung 						*
* *All rights reserved.													* *																* * Redistribution and use in source and binary forms, with or without						* * modification, are permitted provided that the following conditions					* * are met: 															* * 1. Redistributions of source code must retain the above copyright						* *    notice, this list of conditions and the following disclaimer.						* * 2. Redistributions in binary form must reproduce the above copyright					* *    notice, this list of conditions and the following disclaimer in the						* *    documentation and/or other materials provided with the distribution.					* * 3. All advertising materials mentioning features or use of this software					* *    must display the following acknowledgement:									* *	This product includes software developed by the Computer Systems					* *	Engineering Group at Lawrence Berkeley Laboratory.							* * 4. Neither the name of the University nor of the Laboratory may be used					* *    to endorse or promote products derived from this software without					* *    specific prior written permission.										* *5. If you have any problem about these codes, 									*       please mail to antibanish@gmail.com or b9229008@stmail.cgu.edu.tw                    			*
**************************************************************************************/#include <stdlib.h> #include "random.h"#include "trafgen.h"#include "ranvar.h"/*  * Constant bit rate traffic source.   Parameterized by interval, (optional) * random noise in the interval, and packet size.   */double talk_spurt=0.03,silence_spurt=0.01,duration=0,last_duration=0;int talking_=1;class ertPS_Traffic : public TrafficGenerator { public:	ertPS_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 ertPSTrafficClass : public TclClass { public:	ertPSTrafficClass() : TclClass("Application/Traffic/ertPS") {}	TclObject* create(int, const char*const*) {		return (new ertPS_Traffic());	}} class_ertPS_Traffic;ertPS_Traffic::ertPS_Traffic() : seqno_(0){	/*bind_bw("rate_", &rate_);	bind("random_", &random_);	bind("packetSize_", &size_);	bind("maxpkts_", &maxpkts_);*/
	rate_=448000;
	random_=10;
	size_=210;
	maxpkts_=268435456;}void ertPS_Traffic::init(){        // compute inter-packet interval 	interval_ = (double)(size_ << 3)/(double)rate_;	//printf("interval_ : %f \n",interval_);	if (agent_)		if (agent_->get_pkttype() != PT_TCP && 		    agent_->get_pkttype() != PT_TFRC)			//Setting packet type to ertPS.			agent_->set_pkttype(PT_ertPS);}void ertPS_Traffic::start(){        init();        running_ = 1;        timeout();}double ertPS_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);			if(talking_ == 1 && (duration - last_duration) > talk_spurt)//If talking time is large than talk-spurt.	{			agent_->size() = 128;		if(talking_ == 1)		{			last_duration = duration;			talking_=0;		}		//printf("          ~~~~ change to silence ~~~~~\n");	}	else if(talking_ == 1 && (duration - last_duration) <= talk_spurt)//If talking time is less than talk-spurt.	{		agent_->size() = size_;		//printf("         ~~~~ talk mode ~~~~~\n");	}	else if(talking_ == 0 && (duration - last_duration) > silence_spurt)//If silence time is large than silence-spurt.	{		agent_->size() = size_;		if(talking_ == 0)		{			last_duration=duration;			talking_ = 1;		}		//printf("          ~~~~ change to talk ~~~~~\n");	}	else if(talking_ == 0 && (duration - last_duration) <= silence_spurt)//If silence time is less than silence-spurt.	{		agent_->size() = 128;		//printf("          ~~~~ silence mode ~~~~~\n");	}	duration = duration + t;	//printf("---------- ertPS traffic t : %f \t",t);	//printf("size : %d ----------\n",agent_->size());	if (++seqno_ < maxpkts_)		return(t);	else		return(-1); }

⌨️ 快捷键说明

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