• Main Page
  • Classes
  • Files
  • File List

/Users/yzchen/ns/ns-allinone-2.33/ns-2.33/rap/rap.h

00001 /* -*-  Mode:C++; c-basic-offset:8; tab-width:8; indent-tabs-mode:t -*- */
00002 
00003 /*
00004  * rap.h
00005  * Copyright (C) 1997 by the University of Southern California
00006  * $Id: rap.h,v 1.6 2005/08/25 18:58:11 johnh Exp $
00007  *
00008  * This program is free software; you can redistribute it and/or
00009  * modify it under the terms of the GNU General Public License,
00010  * version 2, as published by the Free Software Foundation.
00011  *
00012  * This program is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015  * GNU General Public License for more details.
00016  *
00017  * You should have received a copy of the GNU General Public License along
00018  * with this program; if not, write to the Free Software Foundation, Inc.,
00019  * 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
00020  *
00021  *
00022  * The copyright of this module includes the following
00023  * linking-with-specific-other-licenses addition:
00024  *
00025  * In addition, as a special exception, the copyright holders of
00026  * this module give you permission to combine (via static or
00027  * dynamic linking) this module with free software programs or
00028  * libraries that are released under the GNU LGPL and with code
00029  * included in the standard release of ns-2 under the Apache 2.0
00030  * license or under otherwise-compatible licenses with advertising
00031  * requirements (or modified versions of such code, with unchanged
00032  * license).  You may copy and distribute such a system following the
00033  * terms of the GNU GPL for this module and the licenses of the
00034  * other code concerned, provided that you include the source code of
00035  * that other code when and as the GNU GPL requires distribution of
00036  * source code.
00037  *
00038  * Note that people who make modified versions of this module
00039  * are not obligated to grant this special exception for their
00040  * modified versions; it is their choice whether to do so.  The GNU
00041  * General Public License gives permission to release a modified
00042  * version without this exception; this exception also makes it
00043  * possible to release a modified version which carries forward this
00044  * exception.
00045  *
00046  */
00047 
00048 //
00049 // rap.h 
00050 //      Header File for the 'RAP Source' Agent Class
00051 //
00052 // Author: 
00053 //   Mohit Talwar (mohit@catarina.usc.edu)
00054 //
00055 // $Header: /cvsroot/nsnam/ns-2/rap/rap.h,v 1.6 2005/08/25 18:58:11 johnh Exp $
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 // RapTimeoutType
00065 //      Possible timeout events
00066 
00067 enum RapTimeoutType 
00068 {
00069         RAP_IPG_TIMEOUT,                // IPG timer fires
00070         RAP_RTT_TIMEOUT         // RTT timer fires
00071 };
00072 
00073 // RapLossType
00074 //      Possible loss types
00075 
00076 enum RapLossType 
00077 {
00078         RAP_TIMER_BASED,                // TIMER based loss detection
00079         RAP_ACK_BASED                   // ACK based loss detection
00080 };
00081 
00082 // RapPacketStatus 
00083 //      Possible packet types in the transmission history
00084 
00085 enum RapPacketStatusType
00086 {
00087         RAP_SENT,                       // Packet has been sent
00088         RAP_PURGED,                     // Packet detected lost or received
00089         RAP_INACTIVE                    // Cluster loss ignored
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 // RAP packet header flags
00107 const int RH_DATA = 0x01;
00108 const int RH_ACK  = 0x02;
00109 
00110 struct hdr_rap 
00111 {
00112         int seqno_;             // Seq num of packet being sent/acked
00113         int size_;              // Size of user data inside this packet
00114         int rap_flags_;         // Flags to separate data/ack packets
00115         
00116         int lastRecv;           // Last hole at the RAP sink...
00117         int lastMiss;
00118         int prevRecv;
00119 
00120         static int offset_;     // offset for this header
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 // Rap flags
00154 const int RF_ANYACK = 0x01;     // Received first ack
00155 const int RF_STOP   = 0x02;     // This agent has stopped
00156 const int RF_COUNTPKT = 0x04;    // This agent will send up to certain # of pkts
00157 
00158 class RapAgent : public Agent   // RAP source
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         // Data member access methods
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();              // ipgTimer_ handler
00193         void RttTimeout();              // rttTimer_ handler
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         // Adjust RTT estimate based on sample
00207         void UpdateTimeValues(double sampleRtt); 
00208 
00209         // Detect TIMER_BASED or ACK_BASED losses
00210         int LossDetection(RapLossType type, hdr_rap *ackHeader = NULL);
00211         // Increase ipg_ and mark history INACTIVE
00212         void LossHandler();             
00213 
00214         // Send a DATA packet
00215         void SendPacket(int nbytes, AppData *data = 0); 
00216         // Process an ACK
00217         void RecvAck(hdr_rap *ackHeader); 
00218 
00219         IpgTimer ipgTimer_;             // Send event
00220         RttTimer rttTimer_;             // IPG decrease event
00221 
00222         List transmissionHistory_;      // Of packets sent out
00223   
00224         TracedInt seqno_;               // Current sequence number
00225         TracedInt sessionLossCount_;    // ~ Packets lost in RAP session
00226         TracedInt curseq_;              // max # of pkts sent
00227 
00228         TracedDouble ipg_;              // Inter packet gap
00229         double beta_;                   // Decrease factor
00230         double alpha_;                  // Increase factor 
00231 
00232         TracedDouble srtt_;             // Smoothened round trip time
00233         double variance_;               // Variance in rtt samples
00234         double delta_;                  // Jacobson/Karl 's constants...
00235         double mu_;
00236         double phi_;
00237 
00238         double overhead_;               // Max random delay added to IPG
00239 
00240         int useFineGrain_;              // Use fine grain rate adaptation?
00241         double frtt_;                   // Fine grain feedback signals
00242         double xrtt_;
00243         double kxrtt_;
00244         double kfrtt_;
00245 
00246         TracedDouble timeout_;  // Timeout estimate
00247 
00248         double startTime_, stopTime_;   // Of this agent's life
00249 
00250         int debugEnable_;
00251         FILE *logfile_;
00252 
00253         // Data and methods as required by RAP receiver
00254         int lastRecv_;          // Last hole at the RAP sink...
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         // Data packet counter: the number of data packets that we've sent 
00263         // in a RTT. If we have not sent much we should not increase 
00264         // rate because we don't have enough packets to probe for losses
00265         int dctr_;
00266         // The percentage threshold for increasing rate.
00267         int dpthresh_; 
00268 
00269         // Misc flags
00270         int flags_;
00271         double fixIpg_;
00272 };
00273 
00274 #endif // RAP_H

Generated on Tue Aug 10 2010 16:16:08 for ns-2.33 by  doxygen 1.7.1