00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057 #ifndef RAP_H
00058 #define RAP_H
00059
00060 #include "ns-process.h"
00061 #include "app.h"
00062 #include "utilities.h"
00063
00064
00065
00066
00067 enum RapTimeoutType
00068 {
00069 RAP_IPG_TIMEOUT,
00070 RAP_RTT_TIMEOUT
00071 };
00072
00073
00074
00075
00076 enum RapLossType
00077 {
00078 RAP_TIMER_BASED,
00079 RAP_ACK_BASED
00080 };
00081
00082
00083
00084
00085 enum RapPacketStatusType
00086 {
00087 RAP_SENT,
00088 RAP_PURGED,
00089 RAP_INACTIVE
00090 };
00091
00092 class TransHistoryEntry
00093 {
00094 public:
00095 TransHistoryEntry(int seq, RapPacketStatusType stat = RAP_SENT) {
00096 seqno = seq;
00097 status = stat;
00098 departureTime = Scheduler::instance().clock();
00099 };
00100
00101 int seqno;
00102 RapPacketStatusType status;
00103 double departureTime;
00104 };
00105
00106
00107 const int RH_DATA = 0x01;
00108 const int RH_ACK = 0x02;
00109
00110 struct hdr_rap
00111 {
00112 int seqno_;
00113 int size_;
00114 int rap_flags_;
00115
00116 int lastRecv;
00117 int lastMiss;
00118 int prevRecv;
00119
00120 static int offset_;
00121 inline static int& offset() { return offset_; }
00122 inline static hdr_rap* access(const Packet* p) {
00123 return (hdr_rap*) p->access(offset_);
00124 }
00125
00126 int& seqno() { return seqno_; }
00127 int& size() { return size_; }
00128 int& flags() { return rap_flags_; }
00129 };
00130
00131 class RapAgent;
00132
00133 class IpgTimer : public TimerHandler
00134 {
00135 public:
00136 IpgTimer(RapAgent *a) : TimerHandler() { a_ = a; }
00137
00138 protected:
00139 virtual void expire(Event *e);
00140 RapAgent *a_;
00141 };
00142
00143 class RttTimer : public TimerHandler
00144 {
00145 public:
00146 RttTimer(RapAgent *a) : TimerHandler() { a_ = a; }
00147
00148 protected:
00149 virtual void expire(Event *e);
00150 RapAgent *a_;
00151 };
00152
00153
00154 const int RF_ANYACK = 0x01;
00155 const int RF_STOP = 0x02;
00156 const int RF_COUNTPKT = 0x04;
00157
00158 class RapAgent : public Agent
00159 {
00160 public:
00161 RapAgent();
00162 ~RapAgent();
00163
00164 void recv(Packet*, Handler*);
00165 void timeout(int type);
00166
00167 int GetSeqno() { return seqno_; }
00168 double GetTimeout() { return timeout_; }
00169 int GetDebugFlag() { return debugEnable_; }
00170 FILE *GetLogfile() { return logfile_; }
00171
00172 void IncrementLossCount() { sessionLossCount_++; }
00173
00174 void start();
00175 void stop();
00176 void listen();
00177 void advanceby(int delta);
00178 void finish();
00179
00180
00181 double srtt() { return srtt_; }
00182 double ipg() { return ipg_; }
00183
00184 int anyack() { return flags_ & RF_ANYACK; }
00185 int is_stopped() { return flags_ & RF_STOP; }
00186 int counting_pkt() { return flags_ & RF_COUNTPKT; }
00187 void FixIpg(double fipg) { fixIpg_ = fipg; }
00188
00189 protected:
00190 virtual int command(int argc, const char*const* argv);
00191
00192 void IpgTimeout();
00193 void RttTimeout();
00194
00195 void IncreaseIpg() {
00196 fixIpg_ = 0;
00197 ipg_ /= beta_;
00198 }
00199 void DecreaseIpg() {
00200 if (fixIpg_ != 0)
00201 ipg_ = fixIpg_;
00202 else
00203 ipg_ *= srtt_ / (alpha_ * ipg_ + srtt_);
00204 }
00205
00206
00207 void UpdateTimeValues(double sampleRtt);
00208
00209
00210 int LossDetection(RapLossType type, hdr_rap *ackHeader = NULL);
00211
00212 void LossHandler();
00213
00214
00215 void SendPacket(int nbytes, AppData *data = 0);
00216
00217 void RecvAck(hdr_rap *ackHeader);
00218
00219 IpgTimer ipgTimer_;
00220 RttTimer rttTimer_;
00221
00222 List transmissionHistory_;
00223
00224 TracedInt seqno_;
00225 TracedInt sessionLossCount_;
00226 TracedInt curseq_;
00227
00228 TracedDouble ipg_;
00229 double beta_;
00230 double alpha_;
00231
00232 TracedDouble srtt_;
00233 double variance_;
00234 double delta_;
00235 double mu_;
00236 double phi_;
00237
00238 double overhead_;
00239
00240 int useFineGrain_;
00241 double frtt_;
00242 double xrtt_;
00243 double kxrtt_;
00244 double kfrtt_;
00245
00246 TracedDouble timeout_;
00247
00248 double startTime_, stopTime_;
00249
00250 int debugEnable_;
00251 FILE *logfile_;
00252
00253
00254 int lastRecv_;
00255 int lastMiss_;
00256 int prevRecv_;
00257 void UpdateLastHole(int seqNum);
00258 void SendAck(int seqNum);
00259
00260 int rap_base_hdr_size_;
00261
00262
00263
00264
00265 int dctr_;
00266
00267 int dpthresh_;
00268
00269
00270 int flags_;
00271 double fixIpg_;
00272 };
00273
00274 #endif // RAP_H