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 #ifndef lint
00042 static const char rcsid[] =
00043 "@(#) $Header: /nfs/jade/vint/CVSROOT/ns-2/sctp/sctp-hbAfterRto.cc,v 1.3 2005/10/07 05:58:29 tomh Exp $ (UD/PEL)";
00044 #endif
00045
00046 #include "ip.h"
00047 #include "sctp-hbAfterRto.h"
00048 #include "flags.h"
00049 #include "random.h"
00050 #include "template.h"
00051
00052 #include "sctpDebug.h"
00053
00054 #ifdef DMALLOC
00055 #include "dmalloc.h"
00056 #endif
00057
00058 #define MIN(x,y) (((x)<(y))?(x):(y))
00059 #define MAX(x,y) (((x)>(y))?(x):(y))
00060
00061 static class HbAfterRtoSctpClass : public TclClass
00062 {
00063 public:
00064 HbAfterRtoSctpClass() : TclClass("Agent/SCTP/HbAfterRto") {}
00065 TclObject* create(int, const char*const*)
00066 {
00067 return (new HbAfterRtoSctpAgent());
00068 }
00069 } classSctpHbAfterRto;
00070
00071 HbAfterRtoSctpAgent::HbAfterRtoSctpAgent() : SctpAgent()
00072 {
00073 }
00074
00075 void HbAfterRtoSctpAgent::delay_bind_init_all()
00076 {
00077 SctpAgent::delay_bind_init_all();
00078 }
00079
00080 int HbAfterRtoSctpAgent::delay_bind_dispatch(const char *cpVarName,
00081 const char *cpLocalName,
00082 TclObject *opTracer)
00083 {
00084 return SctpAgent::delay_bind_dispatch(cpVarName, cpLocalName, opTracer);
00085 }
00086
00087 void HbAfterRtoSctpAgent::Timeout(SctpChunkType_E eChunkType,
00088 SctpDest_S *spDest)
00089 {
00090 DBG_I(Timeout);
00091 DBG_PL(Timeout, "eChunkType=%s spDest=%p"),
00092 (eChunkType == SCTP_CHUNK_DATA) ? "DATA" : "HEARTBEAT",
00093 spDest
00094 DBG_PR;
00095
00096 double dCurrTime = Scheduler::instance().clock();
00097
00098 DBG_PL(Timeout, "dCurrTime=%f"), dCurrTime DBG_PR;
00099
00100 if(eChunkType == SCTP_CHUNK_DATA)
00101 {
00102 spDest->eRtxTimerIsRunning = FALSE;
00103
00104
00105
00106 if(spDest->iCwnd > 1 * (int) uiMaxDataSize)
00107 {
00108 spDest->iSsthresh = MAX(spDest->iCwnd/2,
00109 iInitialCwnd * (int) uiMaxDataSize);
00110 spDest->iCwnd = 1*uiMaxDataSize;
00111 spDest->iPartialBytesAcked = 0;
00112 tiCwnd++;
00113 }
00114
00115 spDest->opCwndDegradeTimer->force_cancel();
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131
00132
00133
00134
00135
00136
00137
00138
00139
00140
00141 spDest->eRtoPending = FALSE;
00142 }
00143
00144 DBG_PL(Timeout, "was spDest->dRto=%f"), spDest->dRto DBG_PR;
00145 spDest->dRto *= 2;
00146 if(spDest->dRto > dMaxRto)
00147 spDest->dRto = dMaxRto;
00148 tdRto++;
00149 DBG_PL(Timeout, "now spDest->dRto=%f"), spDest->dRto DBG_PR;
00150
00151 spDest->iTimeoutCount++;
00152 spDest->iErrorCount++;
00153 DBG_PL(Timeout, "now spDest->iErrorCount=%d"), spDest->iErrorCount DBG_PR;
00154
00155 if(spDest->eStatus == SCTP_DEST_STATUS_ACTIVE)
00156 {
00157 iAssocErrorCount++;
00158 DBG_PL(Timeout, "now iAssocErrorCount=%d"), iAssocErrorCount DBG_PR;
00159
00160
00161 if(spDest->iErrorCount > (int) uiPathMaxRetrans)
00162 {
00163 spDest->eStatus = SCTP_DEST_STATUS_INACTIVE;
00164 if(spDest == spNewTxDest)
00165 {
00166 spNewTxDest = GetNextDest(spDest);
00167 DBG_PL(Timeout, "failing over from %p to %p"),
00168 spDest, spNewTxDest DBG_PR;
00169 }
00170 }
00171 if(iAssocErrorCount > (int) uiAssociationMaxRetrans)
00172 {
00173
00174
00175 DBG_PL(Timeout, "abruptly closing the association!") DBG_PR;
00176 Close();
00177 DBG_X(Timeout);
00178 return;
00179 }
00180 }
00181
00182
00183 tiTimeoutCount++;
00184 tiErrorCount++;
00185
00186 if(spDest->iErrorCount > (int) uiChangePrimaryThresh &&
00187 spDest == spPrimaryDest)
00188 {
00189 spPrimaryDest = spNewTxDest;
00190 DBG_PL(Timeout, "changing primary from %p to %p"),
00191 spDest, spNewTxDest DBG_PR;
00192 }
00193
00194 if(eChunkType == SCTP_CHUNK_DATA)
00195 {
00196 TimeoutRtx(spDest);
00197
00198
00199
00200
00201
00202
00203 if(GetNextDest(spDest) != spDest)
00204 SendHeartbeat(spDest);
00205
00206
00207 }
00208 else if(eChunkType == SCTP_CHUNK_HB)
00209 {
00210 if(uiHeartbeatInterval != 0)
00211 SendHeartbeat(spDest);
00212 }
00213
00214 DBG_X(Timeout);
00215 }