00001 /* -*- Mode:C++ -*- */ 00002 // 00003 // Copyright (c) 2006 Regents of the SIGNET lab, University of Padova. 00004 // All rights reserved. 00005 // 00006 // Redistribution and use in source and binary forms, with or without 00007 // modification, are permitted provided that the following conditions 00008 // are met: 00009 // 1. Redistributions of source code must retain the above copyright 00010 // notice, this list of conditions and the following disclaimer. 00011 // 2. Redistributions in binary form must reproduce the above copyright 00012 // notice, this list of conditions and the following disclaimer in the 00013 // documentation and/or other materials provided with the distribution. 00014 // 3. Neither the name of the University of Padova (SIGNET lab) nor the 00015 // names of its contributors may be used to endorse or promote products 00016 // derived from this software without specific prior written permission. 00017 // 00018 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 00019 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 00020 // TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 00021 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 00022 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 00023 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 00024 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 00025 // OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 00026 // WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 00027 // OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 00028 // ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00029 // 00030 00031 00032 #ifndef CBR_MODULE_H 00033 #define CBR_MODULE_H 00034 00035 #include <module.h> 00036 00037 #define CBR_DROP_REASON_UNKNOWN_TYPE "UKT" 00038 #define CBR_DROP_REASON_RECEIVED "RCV" 00039 #define CBR_DROP_REASON_OUT_OF_SEQUENCE "OOS" 00040 #define CBR_DROP_REASON_WRONG_SADDR "WSA" 00041 #define CBR_DROP_REASON_WRONG_SPORT "WSP" 00042 #define CBR_DROP_REASON_EXCEEDED_PLAYOUT "EPB" 00043 00044 00045 #define HDR_CBR(P) (hdr_cbr::access(P)) 00046 00047 extern packet_t PT_MCBR; 00048 00049 typedef struct hdr_cbr { 00050 00051 double ts; 00052 int sn; 00053 bool rftt_valid; 00056 double rftt; 00062 static int offset_; 00063 inline static int& offset() { return offset_; } 00064 inline static struct hdr_cbr* access(const Packet* p) { 00065 return (struct hdr_cbr*)p->access(offset_); 00066 } 00067 00068 } hdr_cbr; 00069 00070 00071 class CbrModule; 00072 00073 00078 class SendTimer : public TimerHandler 00079 { 00080 public: 00081 SendTimer(CbrModule *m) : TimerHandler() { module = m; } 00082 00083 protected: 00084 virtual void expire(Event *e); 00085 CbrModule* module; 00086 }; 00087 00088 00093 class CbrModule : public Module 00094 { 00095 friend class SendTimer; 00096 00097 public: 00098 00099 CbrModule(); 00100 ~CbrModule(); 00101 00102 virtual void recv(Packet*); 00103 virtual void recv(Packet* p, Handler* h); 00104 virtual int command(int argc, const char*const* argv); 00105 virtual int crLayCommand(ClMessage* m); 00106 00107 virtual double GetRTT(); 00108 virtual double GetFTT(); 00109 virtual double GetFTTpob(); 00110 00111 00112 virtual double GetPER(); 00113 virtual double GetTHR(); 00114 00115 virtual double GetPER_PB(); 00116 00117 virtual double GetRTTstd(); 00118 virtual double GetFTTstd(); 00119 00120 virtual void resetStats(); 00121 00122 00123 protected: 00124 00125 static int uidcnt_; 00126 nsaddr_t dstPort_; 00127 nsaddr_t dstAddr_; 00128 00129 00133 virtual void sendPkt(); 00137 virtual void transmit(); 00138 00144 virtual void initPkt(Packet* p); 00145 00150 virtual void start(); 00151 00152 00157 virtual void stop(); 00158 00159 virtual void updateRTT(double rtt); 00160 virtual void updateFTT(double ftt); 00161 virtual void updateThroughput(int bytes, double dt); 00162 00163 virtual void incrPktLost(int npkts); 00164 virtual void incrPktRecv(); 00165 virtual void incrPktOoseq(); 00166 virtual void incrPktInvalid(); 00167 00168 virtual void incrPktOutBuff(); 00169 00170 virtual double getTimeBeforeNextPkt(); 00171 00172 00173 double alpha_; 00176 int txsn; 00177 int hrsn; 00179 int pkts_recv; 00181 int pkts_ooseq; 00184 // playout buffer ------------- 00185 00186 virtual double getMOS(double Pdrop, double delay, double rsource); 00187 00188 virtual void updateMOS(double Pdrop, double delay, double rsource); 00189 virtual double GetMOS(); 00190 double addfd_; 00191 double fd_; 00192 00193 double cr_; 00194 double MOS; 00195 00196 int pob_; // if 1 then playout buffer is used 00197 00198 double pob_time; // playout buffer delay 00199 00200 int pkts_opt; 00202 double first_pkt_rftt; // reference froward trip time 00203 00204 int first_pkt_; // first packet 00205 00206 //---------------------- 00207 00208 int pkts_lost; 00211 int pkts_invalid; 00213 int pkts_last_reset; 00217 double rftt; 00220 double srtt; 00223 double sftt; 00225 double lrtime; 00227 double sthr; 00230 double period_; 00231 int pktSize_; 00232 SendTimer sendTmr_; 00235 /* Cumulative statistics */ 00236 00237 double sumrtt; 00238 double sumrtt2; 00239 int rttsamples; 00241 double sumftt; 00242 double sumftt2; 00243 int fttsamples; 00245 double sumbytes; 00246 double sumdt; 00247 00248 00249 00250 int PoissonTraffic_; 00251 00252 00253 }; 00254 00255 00256 00257 00258 #endif /* CBR_MODULE_H */