00001 #include <list> 00002 #include <rndgen.h> 00003 00004 #include "devPkt.h" 00005 #include "devAP.h" 00006 #include "SlottedAloha.h" 00007 00020 DevPkt::DevPkt(DESystem *_System, 00021 DevPktGen* _thePktGen, 00022 DevAP *_theAP, 00023 int _ID 00024 ) 00025 : DEDevice(_System), thePktGen(_thePktGen), theAP(_theAP), ID(_ID), 00026 attempt_counter(1) 00027 { 00028 theTxTimeProbeHist = 0; 00029 theTxAttemptsProbeHist = 0; 00030 }; 00031 00032 void DevPkt::setup(ParamManager *Param, GlobalProbeManager *Results) 00033 { 00034 Param->addClass ("Dev_Test_Pkt", "Data Terminal for Test"); 00035 Param->addParameter ("Dev_Test_Pkt", new DoubleParameter("meanWaitingSlots", "mean Waiting Slots", "2", "(0,inf)" )); 00036 } 00037 00048 void DevPkt::Initialize() 00049 { 00050 meanWaitingSlots = get<DoubleParameter,double>(Param, "meanWaitingSlots", "Dev_Test_Pkt", ""); 00051 00052 DETime oneSlot = DETime(time_int(1), time_int(0), time_int(0)); 00053 if( theTxTimeProbeHist ) 00054 delete( theTxTimeProbeHist ); 00055 theTxTimeProbeHist = Results->getGlobalProbeHistogram("TxTime", double(oneSlot)); 00056 00057 if( theTxAttemptsProbeHist ) 00058 delete( theTxAttemptsProbeHist ); 00059 theTxAttemptsProbeHist = Results->getGlobalProbeHistogram("TxAttempts"); 00060 00061 generationTime = T->BeginOfTheNextUsefulStep(); 00062 00063 newEvent(new Ev_AP_Packet_Arrival(theAP, this), T->ToBeginOfTheNextUsefulStep()); 00064 } 00065 00066 00073 void DevPkt::HEv_Pkt_Feedback(int type) 00074 { 00075 if( type == 0 ) { 00076 double foo = *T-generationTime; 00077 theTxTimeProbeHist->Observe(foo); 00078 theTxAttemptsProbeHist->Observe(attempt_counter); 00079 00080 thePktGen->RemoveTerminal(this); 00081 delete this; 00082 } 00083 else { 00084 thePktGen->AddBacklogged(); 00085 attempt_counter++; 00086 DETime foo = DETime( time_int(rndGeometric0(meanWaitingSlots)), time_int(0), time_int(0)); 00087 newEvent(new Ev_AP_Packet_Arrival(theAP, this), foo + T->ToBeginOfTheNextUsefulStep() ); 00088 } 00089 } 00090 00091 00092