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

📄 timer-802_16.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 "timer-802_16.h"
#include <packet.h>
#include <assert.h>
#include <random.h>
#include <scheduler.h>
#include "mac-802_16.h"


void Mac802_16Timer::start(long double time)
{
	Scheduler &s = Scheduler::instance();

	assert(busy_ == 0);
	busy_ = 1;
	paused_ = 0;
	stime = s.clock();
	wtime = time;
	assert(wtime >= 0.0);
	////event.uid_ = 0;
	s.schedule(this, &event, wtime);
}
 
void Mac802_16Timer::stop(void)
{ 
	Scheduler &s = Scheduler::instance();

	assert(busy_);
	if(paused_ == 0)
		s.cancel(&event);
}

void Mac802_16Timer::handle(Event* e)
{
}

//BackoffTime
void Backofftimer::start(int cw,int idle,long double symbolDuration){
	Scheduler &s = Scheduler::instance();	assert(busy_ == 0);	busy_ = 1;	paused_ = 0;	stime = s.clock();	
	wtime = (Random::random() % cw)*2*symbolDuration;	if(idle == 0)		paused_ = 1;	else {		assert(wtime >= 0.0);		s.schedule(this, &event, wtime);	}
}
void Backofftimer::pause(long double symbolDuration){	Scheduler &s = Scheduler::instance();	double st = s.clock();	double rt = stime + latence;	double sr = st - rt;	double mst = (symbolDuration);    int slots = int (sr/mst);	if(slots < 0)		slots = 0;	assert(busy_ && ! paused_);	paused_ = 1;	wtime -= (slots * symbolDuration);	assert(rtime >= 0.0);	latence = 0.0;	s.cancel(&intr);}
void Backofftimer::resume(double tmp){	Scheduler &s = Scheduler::instance();	assert(busy_ && paused_);	paused_ = 0;	stime = s.clock();
	latence=tmp;		assert(wtime + tmp >= 0.0);       	s.schedule(this, &intr, wtime + tmp);}
void Backofftimer::handle(Event *){	busy_ = 0;	paused_ = 0;	stime = 0.0;	rtime = 0.0;	latence = 0.0;	mac->BFhandler();}

void BWBackofftimer::start(int cw,int idle,long double symbolDuration){
	Scheduler &s = Scheduler::instance();	assert(busy_ == 0);	busy_ = 1;	paused_ = 0;	stime = s.clock();	
	wtime = (Random::random() % cw)*2*symbolDuration;	if(idle == 0)		paused_ = 1;	else {		assert(wtime >= 0.0);		s.schedule(this, &event, wtime);	}
}
void BWBackofftimer::pause(long double symbolDuration){	Scheduler &s = Scheduler::instance();	double st = s.clock();	double rt = stime + latence;	double sr = st - rt;	double mst = (symbolDuration);    int slots = int (sr/mst);	if(slots < 0)		slots = 0;	assert(busy_ && ! paused_);	paused_ = 1;	wtime -= (slots * symbolDuration);	assert(rtime >= 0.0);	latence = 0.0;	s.cancel(&intr);}
void BWBackofftimer::resume(double tmp){	Scheduler &s = Scheduler::instance();	assert(busy_ && paused_);	paused_ = 0;	stime = s.clock();
	latence=tmp;		assert(wtime + tmp >= 0.0);       	s.schedule(this, &intr, wtime + tmp);}
void BWBackofftimer::handle(Event *){	busy_ = 0;	paused_ = 0;	stime = 0.0;	rtime = 0.0;	latence = 0.0;	mac->BWhandler();}


void TransDATAtimer::start(long double z)
{
	Scheduler &s = Scheduler::instance();
	assert(busy_ == 0);
	busy_ = 1;
	paused_ = 0;
	stime = s.clock();
	wtime = z;
	assert(wtime >= 0.0);
	//event.uid_ = 0;
	s.schedule(this, &event, wtime);
}
void TransDATAtimer::stop()
{
	Scheduler &s = Scheduler::instance();

	assert(busy_);
	if(paused_ == 0)
		s.cancel(&event);

}
void TransDATAtimer::handle(Event*)
{ 
	//mac->tdhandler();
}

void Preamble::start(long double time)
{
	Scheduler &s = Scheduler::instance();
	assert(busy_ == 0);
	busy_ = 1;
	paused_ = 0;
	stime = s.clock();
	rtime = time;
	intr.uid_=0;
#ifdef USE_SLOT_TIME
	ROUND_TIME();
#endif
	assert(rtime >= 0.0);
	s.schedule(this, &intr, rtime);
}
void Preamble::handle(Event* e)
{ 
	busy_=0;
	paused_=0;
	stime=0.0;
	wtime=0.0;
	mac->PreambleHandler();
}

void TX16timer::start(long double time)
{
	Scheduler &s = Scheduler::instance();

	assert(busy_ == 0);
	intr.uid_=0;
	busy_ = 1;
	paused_ = 0;
	stime = s.clock();
	rtime = time;
#ifdef USE_SLOT_TIME
	ROUND_TIME();
#endif
	assert(rtime >= 0.0);

	s.schedule(this, &intr, rtime);
}
void TX16timer::handle(Event* e)
{ 
	busy_=0;
	paused_=0;
	stime=0.0;
	wtime=0.0;
	mac->TX16timerHandler();
}

void RX16timer::start(long double time)
{
	Scheduler &s = Scheduler::instance();

	assert(busy_ == 0);

	busy_ = 1;
	paused_ = 0;
	stime = s.clock();
	rtime = time;
#ifdef USE_SLOT_TIME
	ROUND_TIME();
#endif
	assert(rtime >= 0.0);

	s.schedule(this, &intr, rtime);
}
void RX16timer::handle(Event* e)
{ 
	busy_=0;
	paused_=0;
	stime=0.0;
	wtime=0.0;
	mac->RX16timerHandler();
}


void Defer16Timer::start(long double time)
{
	Scheduler &s = Scheduler::instance();

	assert(busy_ == 0);
	intr.uid_=0;
	busy_ = 1;
	paused_ = 0;
	stime = s.clock();
	rtime = time;
#ifdef USE_SLOT_TIME
	ROUND_TIME();
#endif
	assert(rtime >= 0.0);

	s.schedule(this, &intr, rtime);
}
void Defer16Timer::handle(Event* e)
{ 
	busy_=0;
	paused_=0;
	stime=0.0;
	wtime=0.0;
	mac->Defer16TimerHandler(); 
}

void ULmap16timer::start(long double time, int BCID, int Symbol_number)
{
	Scheduler &s = Scheduler::instance();
	BCID_=BCID;
	Symbol_number_=Symbol_number;
	assert(busy_ == 0);
	busy_ = 1;
	paused_ = 0;
	stime = s.clock();
	wtime = time;
	assert(wtime >= 0.0);
	event.uid_ = 0;
	s.schedule(this, &event, wtime);
}
/*void ULmap16timer::stop()
{
	Scheduler &s = Scheduler::instance();

	assert(busy_);
	if(paused_ == 0)
		s.cancel(&event);

}*/
void ULmap16timer::handle(Event*)
{ 
	busy_=0;
	paused_=0;
	stime=0.0;
	wtime=0.0;
	mac->ULmapHandler(BCID_,Symbol_number_);
}

void DLmap16timer::start(long double time, int DL_burst_num, int Symbol_offset)
{
	Scheduler &s = Scheduler::instance();
	assert(busy_ == 0);
	busy_ = 1;
	paused_ = 0;
	time_=time;
	DL_burst_num_=DL_burst_num;
	Symbol_offset_=Symbol_offset;
	stime = s.clock();
	wtime = time;
	assert(wtime >= 0.0);
	event.uid_ = 0;
	s.schedule(this, &event, wtime);
}
/*void DLmap16timer::stop()
{
	Scheduler &s = Scheduler::instance();

	assert(busy_);
	if(paused_ == 0)
		s.cancel(&event);

}*/
void DLmap16timer::handle(Event*)
{ 
	busy_=0;
	paused_=0;
	stime=0.0;
	wtime=0.0;
	mac->DLmapHandler(time_, DL_burst_num_, Symbol_offset_);
}
void ResumeSStimer::start(long double time,int usr){	
		Scheduler &s = Scheduler::instance();	
		assert(busy_ == 0);	
		busy_ = 1;
		paused_ = 1;
		bcid_=usr;
		stime = s.clock();
		wtime = time;
		assert(wtime >= 0.0);
		event.uid_ = 0;
		s.schedule(this, &event, wtime);
}
void ResumeSStimer::stop(){
	Scheduler &s = Scheduler::instance();
	assert(busy_);
	if(paused_ == 0)
		s.cancel(&event);
}
void ResumeSStimer::handle(Event*){ 
	busy_=0;
	paused_=0;
	stime=0.0;
	wtime=0.0;
	mac->ResumeSS16timerHandler(bcid_);	
}

void ResumeBStimer::start(long double time,int usr){	
		Scheduler &s = Scheduler::instance();	
		assert(busy_ == 0);	
		busy_ = 1;
		paused_ = 1;
		bcid_=usr;
		stime = s.clock();
		wtime = time;
		assert(wtime >= 0.0);
		event.uid_ = 0;
		s.schedule(this, &event, wtime);
}
void ResumeBStimer::stop(){
	Scheduler &s = Scheduler::instance();
	assert(busy_);
	if(paused_ == 0)
		s.cancel(&event);
}
void ResumeBStimer::handle(Event*){ 
	busy_=0;
	paused_=0;
	stime=0.0;
	wtime=0.0;
	mac->ResumeBS16timerHandler(bcid_);	
}
void SendULmap16timer::start(long double time){
	Scheduler &s = Scheduler::instance();
	assert(busy_ == 0);
	busy_ = 1;
	paused_ = 0;
	stime = s.clock();
	wtime = time;
	assert(wtime >= 0.0);
	event.uid_ = 0;
	s.schedule(this, &event, wtime);
}
void SendULmap16timer::stop(){
	Scheduler &s = Scheduler::instance();
	assert(busy_);
	if(paused_ == 0)
		s.cancel(&event);

}
void SendULmap16timer::handle(Event*){ 
	busy_=0;
	paused_=0;
	stime=0.0;
	wtime=0.0;
	mac->SendULmapHandler();
}

void SendDLmap16timer::start(long double time){
	Scheduler &s = Scheduler::instance();
	assert(busy_ == 0);
	busy_ = 1;
	paused_ = 0;
	stime = s.clock();
	wtime = time;
	assert(wtime >= 0.0);
	event.uid_ = 0;
	s.schedule(this, &event, wtime);
}
void SendDLmap16timer::stop(){
	Scheduler &s = Scheduler::instance();
	assert(busy_);
	if(paused_ == 0)
		s.cancel(&event);

}
void SendDLmap16timer::handle(Event*){ 
	busy_=0;
	paused_=0;
	stime=0.0;
	wtime=0.0;
	mac->SendDLmapHandler();
}

⌨️ 快捷键说明

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