File: sctp-multipleFastRtx.cc

package info (click to toggle)
ns2 2.35%2Bdfsg-2.1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 78,780 kB
  • ctags: 27,490
  • sloc: cpp: 172,923; tcl: 107,130; perl: 6,391; sh: 6,143; ansic: 5,846; makefile: 816; awk: 525; csh: 355
file content (1226 lines) | stat: -rw-r--r-- 42,885 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
/*
 * Copyright (c) 2006-2009 by the Protocol Engineering Lab, U of Delaware
 * All rights reserved.
 *
 * Protocol Engineering Lab web page : http://pel.cis.udel.edu/
 *
 * Paul D. Amer        <amer@@cis,udel,edu>
 * Armando L. Caro Jr. <acaro@@cis,udel,edu>
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 *
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 *
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 *
 * 3. Neither the name of the University nor of the Laboratory may be used
 *    to endorse or promote products derived from this software without
 *    specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 * SUCH DAMAGE.
 */

/* MultipleFastRtx extension implements the Caro Multiple Fast Retransmit
 * Algorithm. Caro's Algorithm introduces a fastRtxRecover state variable
 * per TSN in the send buffer. Any time a TSN is retransmitted, its
 * fastRtxRecover is set to the highest TSN outstanding at the time of
 * retransmit. That way, only missing reports triggered by TSNs beyond
 * fastRtxRecover may trigger yet another fast retransmit.
 */

#ifndef lint
static const char rcsid[] =
"@(#) $Header: /cvsroot/nsnam/ns-2/sctp/sctp-multipleFastRtx.cc,v 1.6 2011/10/02 22:32:34 tom_henderson Exp $ (UD/PEL)";
#endif

#include "ip.h"
#include "sctp-multipleFastRtx.h"
#include "flags.h"
#include "random.h"
#include "template.h"

#include "sctpDebug.h"

#ifdef DMALLOC
#include "dmalloc.h"
#endif

#define	MIN(x,y)	(((x)<(y))?(x):(y))
#define	MAX(x,y)	(((x)>(y))?(x):(y))

static class MultipleFastRtxSctpClass : public TclClass 
{ 
public:
  MultipleFastRtxSctpClass() : TclClass("Agent/SCTP/MultipleFastRtx") {}
  TclObject* create(int, const char*const*) 
  {
    return (new MultipleFastRtxSctpAgent());
  }
} classSctpMultipleFastRtx;

MultipleFastRtxSctpAgent::MultipleFastRtxSctpAgent() : SctpAgent()
{
}

void MultipleFastRtxSctpAgent::delay_bind_init_all()
{
  delay_bind_init_one("mfrCount_");
  SctpAgent::delay_bind_init_all();
}

int MultipleFastRtxSctpAgent::delay_bind_dispatch(const char *cpVarName, 
					  const char *cpLocalName, 
					  TclObject *opTracer)
{
  if(delay_bind(cpVarName, cpLocalName, "mfrCount_", &tiMfrCount, opTracer))
    return TCL_OK;

  return SctpAgent::delay_bind_dispatch(cpVarName, cpLocalName, opTracer);
}

void MultipleFastRtxSctpAgent::TraceAll()
{
  char cpOutString[500];
  Node_S *spCurrNode = NULL;
  SctpDest_S *spCurrDest = NULL;
  double dCurrTime = Scheduler::instance().clock();

  for(spCurrNode = sDestList.spHead;
      spCurrNode != NULL;
      spCurrNode = spCurrNode->spNext)
    {
      spCurrDest = (SctpDest_S *) spCurrNode->vpData;
      SetSource(spCurrDest); // gives us the correct source addr & port
      sprintf(cpOutString,
	      "time: %-8.5f  "
	      "saddr: %-2d sport: %-2d daddr: %-2d dport: %-2d "
	      "cwnd: %d pba: %d out: %d ssthresh: %d peerRwnd: %d "
	      "rto: %-6.3f srtt: %-6.3f rttvar: %-6.3f "
	      "assocErrors: %d pathErrors: %d dstatus: %s isPrimary: %s "
	      "frCount: %d mfrCount: %d timeoutCount: %d rcdCount: %d"
	      " availSwnd: %d\n",
	      dCurrTime,
	      addr(), port(), spCurrDest->iNsAddr, spCurrDest->iNsPort,
	      spCurrDest->iCwnd, spCurrDest->iPartialBytesAcked, 
	      spCurrDest->iOutstandingBytes, spCurrDest->iSsthresh, 
	      uiPeerRwnd,
	      spCurrDest->dRto, spCurrDest->dSrtt, 
	      spCurrDest->dRttVar,
	      iAssocErrorCount,
	      spCurrDest->iErrorCount,
	      spCurrDest->eStatus ? "ACTIVE" : "INACTIVE",
	      (spCurrDest == spPrimaryDest) ? "TRUE" : "FALSE",
	      int(tiFrCount),
	      // BEGIN -- MultipleFastRtx changes to this function  
	      int(tiMfrCount),
              // END -- MultipleFastRtx changes to this function  
	      spCurrDest->iTimeoutCount,
	      spCurrDest->iRcdCount,
	      uiAvailSwnd);
      if(channel_)
	(void)Tcl_Write(channel_, cpOutString, strlen(cpOutString));
    }

  sprintf(cpOutString, "\n");
  if(channel_)
    (void)Tcl_Write(channel_, cpOutString, strlen(cpOutString));
}

void MultipleFastRtxSctpAgent::TraceVar(const char* cpVar)
{
  char cpOutString[500];
  Node_S *spCurrNode = NULL;
  SctpDest_S *spCurrDest = NULL;
  double dCurrTime = Scheduler::instance().clock();

  if(!strcmp(cpVar, "cwnd_"))
    for(spCurrNode = sDestList.spHead;
	spCurrNode != NULL;
	spCurrNode = spCurrNode->spNext)
      {
	spCurrDest = (SctpDest_S *) spCurrNode->vpData;
	SetSource(spCurrDest); // gives us the correct source addr & port
	sprintf(cpOutString,
		"time: %-8.5f  "
		"saddr: %-2d sport: %-2d daddr: %-2d dport: %-2d "
		"cwnd: %d pba: %d out: %d ssthresh: %d peerRwnd: %d\n",
		dCurrTime, 
		addr(), port(), 
		spCurrDest->iNsAddr, spCurrDest->iNsPort,
		spCurrDest->iCwnd, spCurrDest->iPartialBytesAcked, 
		spCurrDest->iOutstandingBytes, spCurrDest->iSsthresh, 
		uiPeerRwnd);
	if(channel_)
	  (void)Tcl_Write(channel_, cpOutString, strlen(cpOutString));
      }

  else if(!strcmp(cpVar, "rto_"))
    for(spCurrNode = sDestList.spHead;
	spCurrNode != NULL;
	spCurrNode = spCurrNode->spNext)
      {
	spCurrDest = (SctpDest_S *) spCurrNode->vpData;
	SetSource(spCurrDest); // gives us the correct source addr & port
	sprintf(cpOutString,
		"time: %-8.5f  "
		"saddr: %-2d sport: %-2d daddr: %-2d dport: %-2d "
		"rto: %-6.3f srtt: %-6.3f rttvar: %-6.3f\n",
		dCurrTime, 
		addr(), port(), 
		spCurrDest->iNsAddr, spCurrDest->iNsPort,
		spCurrDest->dRto, spCurrDest->dSrtt, 
		spCurrDest->dRttVar);
	if(channel_)
	  (void)Tcl_Write(channel_, cpOutString, strlen(cpOutString));
      }

  else if(!strcmp(cpVar, "errorCount_"))
    for(spCurrNode = sDestList.spHead;
	spCurrNode != NULL;
	spCurrNode = spCurrNode->spNext)
      {
	spCurrDest = (SctpDest_S *) spCurrNode->vpData;
	SetSource(spCurrDest); // gives us the correct source addr & port
	sprintf(cpOutString, 
		"time: %-8.5f  "
		"saddr: %-2d sport: %-2d daddr: %-2d dport: %-2d "
		"assocErrors: %d pathErrors: %d dstatus: %s isPrimary: %s\n",
		dCurrTime, 
		addr(), port(), 
		spCurrDest->iNsAddr, spCurrDest->iNsPort,
		iAssocErrorCount,
		spCurrDest->iErrorCount,
		spCurrDest->eStatus ? "ACTIVE" : "INACTIVE",
		(spCurrDest == spPrimaryDest) ? "TRUE" : "FALSE");
	if(channel_)
	  (void)Tcl_Write(channel_, cpOutString, strlen(cpOutString));
      }

  else if(!strcmp(cpVar, "frCount_"))
    {
      sprintf(cpOutString, 
	      "time: %-8.5f  "
	      "frCount: %d\n",
	      dCurrTime, 
	      int(*((TracedInt*) cpVar)) );
      if(channel_)
	(void)Tcl_Write(channel_, cpOutString, strlen(cpOutString));
    }

  // BEGIN -- MultipleFastRtx changes to this function  
  else if(!strcmp(cpVar, "mfrCount_"))
    {
      sprintf(cpOutString, 
	      "time: %-8.5f  "
	      "mfrCount: %d\n",
	      dCurrTime, 
	      int(*((TracedInt*) cpVar)) );
      if(channel_)
	(void)Tcl_Write(channel_, cpOutString, strlen(cpOutString));
    }
  // END -- MultipleFastRtx changes to this function  

  else if(!strcmp(cpVar, "timeoutCount_"))
    {
    for(spCurrNode = sDestList.spHead;
	spCurrNode != NULL;
	spCurrNode = spCurrNode->spNext)
      {
	spCurrDest = (SctpDest_S *) spCurrNode->vpData;
	SetSource(spCurrDest); // gives us the correct source addr & port
	sprintf(cpOutString, 
		"time: %-8.5f  "
		"saddr: %-2d sport: %-2d daddr: %-2d dport: %-2d "
		"timeoutCount: %d\n",
		dCurrTime, 
		addr(), port(), 
		spCurrDest->iNsAddr, spCurrDest->iNsPort,
		spCurrDest->iTimeoutCount);
	if(channel_)
	  (void)Tcl_Write(channel_, cpOutString, strlen(cpOutString));
      }
    }

  else if(!strcmp(cpVar, "rcdCount_"))
    {
    for(spCurrNode = sDestList.spHead;
	spCurrNode != NULL;
	spCurrNode = spCurrNode->spNext)
      {
	spCurrDest = (SctpDest_S *) spCurrNode->vpData;
	SetSource(spCurrDest); // gives us the correct source addr & port
	sprintf(cpOutString, 
		"time: %-8.5f  "
		"saddr: %-2d sport: %-2d daddr: %-2d dport: %-2d "
		"rcdCount: %d\n",
		dCurrTime, 
		addr(), port(), 
		spCurrDest->iNsAddr, spCurrDest->iNsPort,
		spCurrDest->iRcdCount);
	if(channel_)
	  (void)Tcl_Write(channel_, cpOutString, strlen(cpOutString));
      }
    }

  else
    {
      sprintf(cpOutString,
	      "time: %-8.5f  "
	      "saddr: %-2d sport: %-2d daddr: %-2d dport: %-2d %s: %s\n",
	      dCurrTime, addr(), port(), daddr(), dport(),
	      cpVar, "ERROR (unepected trace variable)"); 
      if(channel_)
	(void)Tcl_Write(channel_, cpOutString, strlen(cpOutString));
    }

  sprintf(cpOutString, "\n");
  if(channel_)
    (void)Tcl_Write(channel_, cpOutString, strlen(cpOutString));
}


void MultipleFastRtxSctpAgent::AddToSendBuffer(SctpDataChunkHdr_S *spChunk, 
				int iChunkSize,
				u_int uiReliability,
				SctpDest_S *spDest)
{
  DBG_I(AddToSendBuffer);
  DBG_PL(AddToSendBuffer, "spDest=%p  iChunkSize=%d"), 
    spDest, iChunkSize DBG_PR;

  Node_S *spNewNode = new Node_S;
  spNewNode->eType = NODE_TYPE_SEND_BUFFER;
  spNewNode->vpData = new SctpSendBufferNode_S;

  SctpSendBufferNode_S * spNewNodeData 
    = (SctpSendBufferNode_S *) spNewNode->vpData;

  /* This can NOT simply be a 'new SctpDataChunkHdr_S', because we need to
   * allocate the space for the ENTIRE data chunk and not just the data
   * chunk header.  
   */
  spNewNodeData->spChunk = (SctpDataChunkHdr_S *) new u_char[iChunkSize];
  memcpy(spNewNodeData->spChunk, spChunk, iChunkSize);

  spNewNodeData->eAdvancedAcked = FALSE;
  spNewNodeData->eGapAcked = FALSE;
  spNewNodeData->eAddedToPartialBytesAcked = FALSE;
  spNewNodeData->iNumMissingReports = 0;
  spNewNodeData->iUnrelRtxLimit = uiReliability;
  spNewNodeData->eMarkedForRtx = NO_RTX;
  spNewNodeData->eIneligibleForFastRtx = FALSE;
  spNewNodeData->iNumTxs = 1;
  spNewNodeData->spDest = spDest;

  // BEGIN -- MultipleFastRtx changes to this function  
  spNewNodeData->uiFastRtxRecover = 0;
  // END -- MultipleFastRtx changes to this function  

  /* Is there already a DATA chunk in flight measuring an RTT? 
   * (6.3.1.C4 RTT measured once per round trip)
   */
  if(spDest->eRtoPending == FALSE)  // NO?
    {
      spNewNodeData->dTxTimestamp = Scheduler::instance().clock();
      spDest->eRtoPending = TRUE;   // ...well now there is :-)
    }
  else
    spNewNodeData->dTxTimestamp = 0; // don't use this check for RTT estimate

  InsertNode(&sSendBuffer, sSendBuffer.spTail, spNewNode, NULL);

  DBG_X(AddToSendBuffer);
}

/* Go thru the send buffer deleting all chunks which have a tsn <= the 
 * tsn parameter passed in. We assume the chunks in the rtx list are ordered by 
 * their tsn value. In addtion, for each chunk deleted:
 *   1. we add the chunk length to # newly acked bytes and partial bytes acked
 *   2. we update round trip time if appropriate
 *   3. stop the timer if the chunk's destination timer is running
 */
void MultipleFastRtxSctpAgent::SendBufferDequeueUpTo(u_int uiTsn)
{
  DBG_I(SendBufferDequeueUpTo);

  Node_S *spDeleteNode = NULL;
  Node_S *spCurrNode = sSendBuffer.spHead;
  SctpSendBufferNode_S *spCurrNodeData = NULL;

  /* PN: 5/2007. Simulate send window */
  u_short usChunkSize = 0;

  iAssocErrorCount = 0;

  while(spCurrNode != NULL &&
	((SctpSendBufferNode_S*)spCurrNode->vpData)->spChunk->uiTsn <= uiTsn)
    {
      spCurrNodeData = (SctpSendBufferNode_S *) spCurrNode->vpData;

      /* Only count this chunk as newly acked and towards partial bytes
       * acked if it hasn't been gap acked or marked as ack'd due to rtx
       * limit.  
       */
      if((spCurrNodeData->eGapAcked == FALSE) &&
	 (spCurrNodeData->eAdvancedAcked == FALSE) )
	{
	  uiHighestTsnNewlyAcked = spCurrNodeData->spChunk->uiTsn;

	  spCurrNodeData->spDest->iNumNewlyAckedBytes 
	    += spCurrNodeData->spChunk->sHdr.usLength;

	  /* only add to partial bytes acked if we are in congestion
	   * avoidance mode and if there was cwnd amount of data
	   * outstanding on the destination (implementor's guide) 
	   */
	  if(spCurrNodeData->spDest->iCwnd >spCurrNodeData->spDest->iSsthresh &&
	     ( spCurrNodeData->spDest->iOutstandingBytes 
	       >= spCurrNodeData->spDest->iCwnd) )
	    {
	      spCurrNodeData->spDest->iPartialBytesAcked 
		+= spCurrNodeData->spChunk->sHdr.usLength;
	    }
	}


      // BEGIN -- MultipleFastRtx changes to this function  

      /* This is to ensure that Max.Burst is applied when a SACK
       * acknowledges a chunk which has been fast retransmitted. (If the
       * fast rtx recover variable is set, that can only be because it was
       * fast rtxed.) This is a proposed change to RFC2960 section 7.2.4
       */
      if(spCurrNodeData->uiFastRtxRecover > 0)
	eApplyMaxBurst = TRUE;

      // END -- MultipleFastRtx changes to this function  

	    
      /* We update the RTT estimate if the following hold true:
       *   1. RTO pending flag is set (6.3.1.C4 measured once per round trip)
       *   2. Timestamp is set for this chunk (ie, we were measuring this chunk)
       *   3. This chunk has not been retransmitted
       *   4. This chunk has not been gap acked already 
       *   5. This chunk has not been advanced acked (pr-sctp: exhausted rtxs)
       */
      if(spCurrNodeData->spDest->eRtoPending == TRUE &&
	 spCurrNodeData->dTxTimestamp > 0 &&
	 spCurrNodeData->iNumTxs == 1 &&
	 spCurrNodeData->eGapAcked == FALSE &&
	 spCurrNodeData->eAdvancedAcked == FALSE) 
	{

	  /* If the chunk is marked for timeout rtx, then the sender is an 
	   * ambigious state. Were the sacks lost or was there a failure?
	   * Since we don't clear the error counter below, we also don't
	   * update the RTT. This could be a problem for late arriving SACKs.
	   */
	  if(spCurrNodeData->eMarkedForRtx != TIMEOUT_RTX)
	    RttUpdate(spCurrNodeData->dTxTimestamp, spCurrNodeData->spDest);
	  spCurrNodeData->spDest->eRtoPending = FALSE;
	}

      /* if there is a timer running on the chunk's destination, then stop it
       */
      if(spCurrNodeData->spDest->eRtxTimerIsRunning == TRUE)
	StopT3RtxTimer(spCurrNodeData->spDest);

      /* We don't want to clear the error counter if it's cleared already;
       * otherwise, we'll unnecessarily trigger a trace event.
       *
       * Also, the error counter is cleared by SACKed data ONLY if the
       * TSNs are not marked for timeout retransmission and has not been
       * gap acked before. Without this condition, we can run into a
       * problem for failure detection. When a failure occurs, some data
       * may have made it through before the failure, but the sacks got
       * lost. When the sender retransmits the first outstanding, the
       * receiver will sack all the data whose sacks got lost. We don't
       * want these sacks to clear the error counter, or else failover
       * would take longer.
       */
      if(spCurrNodeData->spDest->iErrorCount != 0 &&
	 spCurrNodeData->eMarkedForRtx != TIMEOUT_RTX &&
	 spCurrNodeData->eGapAcked == FALSE)
	{
	  DBG_PL(SendBufferDequeueUpTo, 
		 "clearing error counter for %p with tsn=%lu"), 
	    spCurrNodeData->spDest, spCurrNodeData->spChunk->uiTsn DBG_PR;

	  spCurrNodeData->spDest->iErrorCount = 0; // clear error counter
	  tiErrorCount++;                          // ... and trace it too!
	  spCurrNodeData->spDest->eStatus = SCTP_DEST_STATUS_ACTIVE;
	  if(spCurrNodeData->spDest == spPrimaryDest &&
	     spNewTxDest != spPrimaryDest) 
	    {
	      DBG_PL(SendBufferDequeueUpTo,
		     "primary recovered... migrating back from %p to %p"),
		spNewTxDest, spPrimaryDest DBG_PR;
	      spNewTxDest = spPrimaryDest; // return to primary
	    }
	}

      /* PN: 5/2007. Simulate send window */
      usChunkSize = spCurrNodeData->spChunk->sHdr.usLength;
      
      spDeleteNode = spCurrNode;
      spCurrNode = spCurrNode->spNext;

      DeleteNode(&sSendBuffer, spDeleteNode);
      spDeleteNode = NULL;

        /* PN: 5/2007. Simulate send window */
      if (uiInitialSwnd) 
      {
        uiAvailSwnd += usChunkSize;

	DBG_PL(SendBufferDequeueUpTo, "AvailSendwindow=%ld"), uiAvailSwnd DBG_PR;
      }

    }

  DBG_X(SendBufferDequeueUpTo);
}

/* returns a boolean of whether a fast retransmit is necessary
 */
Boolean_E MultipleFastRtxSctpAgent::ProcessGapAckBlocks(u_char *ucpSackChunk,
					 Boolean_E eNewCumAck)
{
  DBG_I(ProcessGapAckBlocks);

  Boolean_E eFastRtxNeeded = FALSE;
  u_int uiHighestTsnSacked = uiHighestTsnNewlyAcked;
  u_int uiStartTsn;
  u_int uiEndTsn;

  Node_S *spCurrNode = NULL;
  SctpSendBufferNode_S *spCurrNodeData = NULL;
  Node_S *spCurrDestNode = NULL;
  SctpDest_S *spCurrDestNodeData = NULL;

  SctpSackChunk_S *spSackChunk = (SctpSackChunk_S *) ucpSackChunk;

  u_short usNumGapAcksProcessed = 0;

  /* NE: number of Non-Renegable Gap Ack Blocks processed */
  u_short usNumNonRenegGapAcksProcessed = 0;

  SctpGapAckBlock_S *spCurrGapAck = NULL;

  /* NE: 06/2009 */
  SctpGapAckBlock_S *spCurrNonRenegGapAck = NULL;

  Node_S *spPrevNode = sSendBuffer.spHead;
  Boolean_E eDoNotChangeCurrNode = FALSE;

  u_short usNumGapAckBlocks = spSackChunk->usNumGapAckBlocks;

  /* NE: number of Non-Renegable Gap Ack Blocks reported */
  u_short usNumNonRenegGapAckBlocks = 0;

  /* NE: let's decide which block (Gap Ack or Non-Renegable Gap Ack) 
     is used for the calculation */
  Boolean_E eUseGapAckBlock = FALSE;
  u_int uiGapAckStartTsn;
  u_int uiNonRenegGapAckStartTsn;

  /* NE: since the SctpSackChunk_S and SctpNonRenegSackChunk_S structure sizes 
     are different, the offset to point first Gap Ack Block should be calculated
     based on the chunk type */
  if (!eUseNonRenegSacks) { /* SACK Chunk */  
    spCurrGapAck  = 
      (SctpGapAckBlock_S *) (ucpSackChunk + sizeof(SctpSackChunk_S));

    DBG_PL(ProcessGapAckBlocks,"CumAck=%d, NumGapAckBlocks=%u"), 
      spSackChunk->uiCumAck, usNumGapAckBlocks DBG_PR;
  }
  else {                    /* NR-SACK Chunk*/
    usNumGapAckBlocks = 
      ((SctpNonRenegSackChunk_S *)ucpSackChunk)->usNumGapAckBlocks;
    usNumNonRenegGapAckBlocks = 
      ((SctpNonRenegSackChunk_S *)ucpSackChunk)->usNumNonRenegSackBlocks;

    DBG_PL(ProcessGapAckBlocks,
	   "CumAck=%d, NumGapAckBlocks=%u NumNonRenegGapAckBlocks=%u"), 
      spSackChunk->uiCumAck, usNumGapAckBlocks, usNumNonRenegGapAckBlocks DBG_PR;

    /* NE: initial Gap Ack and Non-Renegable Gap Ack Block offsets */
    spCurrGapAck  = 
      (SctpGapAckBlock_S *) (ucpSackChunk + sizeof(SctpNonRenegSackChunk_S));
    spCurrNonRenegGapAck = 
      (SctpGapAckBlock_S *) (ucpSackChunk + sizeof(SctpNonRenegSackChunk_S) + 
			     usNumGapAckBlocks * sizeof(SctpGapAckBlock_S));

    /* NE: if there is no reported Gap Ack Blocks, just use Non-Renegable Gap 
       Ack Blocks */
    if ((usNumGapAckBlocks == 0) && (usNumNonRenegGapAckBlocks > 0)) {
      spCurrGapAck = spCurrNonRenegGapAck; 
      
      eUseGapAckBlock = FALSE;
      
      uiNonRenegGapAckStartTsn = 
	spSackChunk->uiCumAck + spCurrNonRenegGapAck->usStartOffset;
      
      DBG_PL(ProcessGapAckBlocks,"uiNonRenegGapAckStartTsn=%u"), 
	uiNonRenegGapAckStartTsn DBG_PR;
    } /* NE: if there is no reported Non-Renegable Gap Ack Blocks, 
	 just use Gap Ack Blocks */
    else if (usNumNonRenegGapAckBlocks == 0 && (usNumGapAckBlocks > 0)) {
      eUseGapAckBlock = TRUE;

      uiGapAckStartTsn = spSackChunk->uiCumAck + spCurrGapAck->usStartOffset;
      
      DBG_PL(ProcessGapAckBlocks,"uiGapAckStartTsn=%u"), 
	uiGapAckStartTsn DBG_PR;
    } /* NE: If there is both Gap Ack and Non-Renegable Gap Ack Blocks, use 
	 the block with lower start TSN value*/
    else if ((usNumGapAckBlocks > 0) && (usNumNonRenegGapAckBlocks > 0)) {
      
      uiGapAckStartTsn = spSackChunk->uiCumAck + spCurrGapAck->usStartOffset;
      uiNonRenegGapAckStartTsn = 
	spSackChunk->uiCumAck + spCurrNonRenegGapAck->usStartOffset;

      if (uiGapAckStartTsn < uiNonRenegGapAckStartTsn) {
	eUseGapAckBlock = TRUE;

	DBG_PL(ProcessGapAckBlocks,"uiGapAckStartTsn=%u"), 
	  uiGapAckStartTsn DBG_PR;
      }
      else if (uiNonRenegGapAckStartTsn < uiGapAckStartTsn) {
	spCurrGapAck = spCurrNonRenegGapAck; 
	eUseGapAckBlock = FALSE;
	
	DBG_PL(ProcessGapAckBlocks,"uiNonRenegGapAckStartTsn=%u"), 
	  uiNonRenegGapAckStartTsn DBG_PR;
      }
      else {
	DBG_PL(ProcessGapAckBlocks,
	       "WARNING! This statement should not be reached!") DBG_PR;
      }
    }
    else {
      DBG_PL(ProcessGapAckBlocks,
	     "WARNING! This statement should not be reached!") DBG_PR;
    }
  }

  // BEGIN -- MultipleFastRtx changes to this function    
  u_int uiHighestOutstandingTsn = GetHighestOutstandingTsn();

  /* We want to track any time a regular FR and a MFR is invoked
   */
  Boolean_E eFrInvoked = FALSE;
  Boolean_E eMfrInvoked = FALSE;
  // END -- MultipleFastRtx changes to this function    

  if(sSendBuffer.spHead == NULL) // do we have ANYTHING in the rtx buffer?
    {
      /* This COULD mean that this sack arrived late, and a previous one
       * already cum ack'd everything. ...so, what do we do? nothing??
       */
    }
  
  else // we do have chunks in the rtx buffer
    {
      /* make sure we clear all the spFirstOutstanding pointers before
       * using them!  
       */
      for(spCurrDestNode = sDestList.spHead;
	  spCurrDestNode != NULL;
	  spCurrDestNode = spCurrDestNode->spNext)
	{
	  spCurrDestNodeData = (SctpDest_S *) spCurrDestNode->vpData;
	  spCurrDestNodeData->spFirstOutstanding = NULL;
	}

      /* NE: process all reported Gap Ack/Non-Renegable Ack Blocks */
      for(spCurrNode = sSendBuffer.spHead;
	  (spCurrNode != NULL) &&
	    ((usNumGapAcksProcessed != usNumGapAckBlocks) ||
	     (usNumNonRenegGapAcksProcessed != usNumNonRenegGapAckBlocks)); 
	  spCurrNode = spCurrNode->spNext)                
	{
	  spCurrNodeData = (SctpSendBufferNode_S *) spCurrNode->vpData;

	  /* is this chunk the first outstanding on its destination?
	   */
	  if(spCurrNodeData->spDest->spFirstOutstanding == NULL &&
	     spCurrNodeData->eGapAcked == FALSE &&
	     spCurrNodeData->eAdvancedAcked == FALSE)
	    {
	      /* yes, it is the first!
	       */
	      spCurrNodeData->spDest->spFirstOutstanding = spCurrNodeData;
	    }

	  DBG_PL(ProcessGapAckBlocks, "--> rtx list chunk begin") DBG_PR;

	  DBG_PL(ProcessGapAckBlocks, "    TSN=%d"), 
	    spCurrNodeData->spChunk->uiTsn 
	    DBG_PR;

	  DBG_PL(ProcessGapAckBlocks, "    %s=%s %s=%s"),
	    "eGapAcked", 
	    spCurrNodeData->eGapAcked ? "TRUE" : "FALSE",
	    "eAddedToPartialBytesAcked",
	    spCurrNodeData->eAddedToPartialBytesAcked ? "TRUE" : "FALSE" 
	    DBG_PR;

	  DBG_PL(ProcessGapAckBlocks, "    NumMissingReports=%d NumTxs=%d"),
	    spCurrNodeData->iNumMissingReports, 
	    spCurrNodeData->iNumTxs 
	    DBG_PR;

	  DBG_PL(ProcessGapAckBlocks, "<-- rtx list chunk end") DBG_PR;
	  
	  DBG_PL(ProcessGapAckBlocks,"GapAckBlock StartOffset=%d EndOffset=%d"),
	    spCurrGapAck->usStartOffset, spCurrGapAck->usEndOffset DBG_PR;

	  uiStartTsn = spSackChunk->uiCumAck + spCurrGapAck->usStartOffset;
	  uiEndTsn = spSackChunk->uiCumAck + spCurrGapAck->usEndOffset;

	  /* NE: Change the calculation of Highest TSN SACKed since the 
	     previous calculation is using the TSNs from the send buffer and 
	     with the introduction of NR-SACKs send buffer may not have
	     the Highest TSN SACKed in the send buffer */
	  if(uiHighestTsnSacked < uiEndTsn)
	    uiHighestTsnSacked = uiEndTsn;
	  
	  DBG_PL(ProcessGapAckBlocks, "GapAckBlock StartTsn=%d EndTsn=%d"),
	    uiStartTsn, uiEndTsn DBG_PR;

	  if(spCurrNodeData->spChunk->uiTsn < uiStartTsn)
	    {
	      /* This chunk is NOT being acked and is missing at the receiver
	       */

	      /* If this chunk was GapAcked before, then either the
	       * receiver has renegged the chunk (which our simulation
	       * doesn't do) or this SACK is arriving out of order.
	       */
	      if(spCurrNodeData->eGapAcked == TRUE)
		{
		  DBG_PL(ProcessGapAckBlocks, 
			 "out of order SACK? setting TSN=%d eGapAcked=FALSE"),
		    spCurrNodeData->spChunk->uiTsn DBG_PR;
		  spCurrNodeData->eGapAcked = FALSE;
		  spCurrNodeData->spDest->iOutstandingBytes 
		    += spCurrNodeData->spChunk->sHdr.usLength;

		  /* section 6.3.2.R4 says that we should restart the
		   * T3-rtx timer here if it isn't running already. In our
		   * implementation, it isn't necessary since
		   * ProcessSackChunk will restart the timer for any
		   * destinations which have outstanding data and don't
		   * have a timer running.
		   */
		}
	    }
	  else if((uiStartTsn <= spCurrNodeData->spChunk->uiTsn) && 
		  (spCurrNodeData->spChunk->uiTsn <= uiEndTsn) )
	    {
	      /* This chunk is being acked via a gap ack block
	       */
	      DBG_PL(ProcessGapAckBlocks, "gap ack acks this chunk: %s%s"),
		"eGapAcked=",
		spCurrNodeData->eGapAcked ? "TRUE" : "FALSE" 
		DBG_PR;

	      /* HTNA algorithm... we need to know the highest TSN sacked
	       * (even if it isn't new), so that when the sender is in
	       * Fast Recovery, the outstanding tsns beyond the last sack
	       * tsn do not have their missing reports incremented
	       */
	      if(uiHighestTsnSacked < spCurrNodeData->spChunk->uiTsn)
		uiHighestTsnSacked = spCurrNodeData->spChunk->uiTsn;

	      if(spCurrNodeData->eGapAcked == FALSE)
		{
		  DBG_PL(ProcessGapAckBlocks, "setting eGapAcked=TRUE") DBG_PR;
		  spCurrNodeData->eGapAcked = TRUE;

		  /* HTNA algorithm... we need to know the highest TSN
		   * newly acked
		   */
		  if(uiHighestTsnNewlyAcked < spCurrNodeData->spChunk->uiTsn)
		    uiHighestTsnNewlyAcked = spCurrNodeData->spChunk->uiTsn;

		  if(spCurrNodeData->eAdvancedAcked == FALSE)
		    {
		      spCurrNodeData->spDest->iNumNewlyAckedBytes 
			+= spCurrNodeData->spChunk->sHdr.usLength;
		    }

		  /* only increment partial bytes acked if we are in
		   * congestion avoidance mode, we have a new cum ack, and
		   * we haven't already incremented it for this sack
		   */
		  if(( spCurrNodeData->spDest->iCwnd 
		       > spCurrNodeData->spDest->iSsthresh) &&
		     eNewCumAck == TRUE &&
		     spCurrNodeData->eAddedToPartialBytesAcked == FALSE)
		    {
		      DBG_PL(ProcessGapAckBlocks, 
			     "setting eAddedToPartiallyBytesAcked=TRUE") DBG_PR;

		      spCurrNodeData->eAddedToPartialBytesAcked = TRUE; // set

		      spCurrNodeData->spDest->iPartialBytesAcked 
			+= spCurrNodeData->spChunk->sHdr.usLength;
		    }
		  /* We update the RTT estimate if the following hold true:
		   *   1. RTO pending flag is set (6.3.1.C4)
		   *   2. Timestamp is set for this chunk 
		   *   3. This chunk has not been retransmitted
		   *   4. This chunk has not been gap acked already 
		   *   5. This chunk has not been advanced acked (pr-sctp)
		   */
		  if(spCurrNodeData->spDest->eRtoPending == TRUE &&
		     spCurrNodeData->dTxTimestamp > 0 &&
		     spCurrNodeData->iNumTxs == 1 &&
		     spCurrNodeData->eAdvancedAcked == FALSE) 
		    {
		      /* If the chunk is marked for timeout rtx, then the
		       * sender is an ambigious state. Were the sacks lost
		       * or was there a failure?  Since we don't clear the
		       * error counter below, we also don't update the
		       * RTT. This could be a problem for late arriving
		       * SACKs.
		       */
		      if(spCurrNodeData->eMarkedForRtx != TIMEOUT_RTX)
			RttUpdate(spCurrNodeData->dTxTimestamp, 
				  spCurrNodeData->spDest);
		      spCurrNodeData->spDest->eRtoPending = FALSE;
		    }

		  /* section 6.3.2.R3 - Stop the timer if this is the
		   * first outstanding for this destination (note: it may
		   * have already been stopped if there was a new cum
		   * ack). If there are still outstanding bytes on this
		   * destination, we'll restart the timer later in
		   * ProcessSackChunk() 
		   */
		  if(spCurrNodeData->spDest->spFirstOutstanding 
		     == spCurrNodeData)
		    
		    {
		      if(spCurrNodeData->spDest->eRtxTimerIsRunning == TRUE)
			StopT3RtxTimer(spCurrNodeData->spDest);
		    }
		  
		  iAssocErrorCount = 0;
		  
		  /* We don't want to clear the error counter if it's
		   * cleared already; otherwise, we'll unnecessarily
		   * trigger a trace event.
		   *
		   * Also, the error counter is cleared by SACKed data
		   * ONLY if the TSNs are not marked for timeout
		   * retransmission and has not been gap acked
		   * before. Without this condition, we can run into a
		   * problem for failure detection. When a failure occurs,
		   * some data may have made it through before the
		   * failure, but the sacks got lost. When the sender
		   * retransmits the first outstanding, the receiver will
		   * sack all the data whose sacks got lost. We don't want
		   * these sacks * to clear the error counter, or else
		   * failover would take longer.
		   */
		  if(spCurrNodeData->spDest->iErrorCount != 0  &&
		     spCurrNodeData->eMarkedForRtx != TIMEOUT_RTX)
		    {
		      DBG_PL(ProcessGapAckBlocks,
			     "clearing error counter for %p with tsn=%lu"), 
			spCurrNodeData->spDest, 
			spCurrNodeData->spChunk->uiTsn DBG_PR;

		      spCurrNodeData->spDest->iErrorCount = 0; // clear errors
		      tiErrorCount++;                       // ... and trace it!
		      spCurrNodeData->spDest->eStatus = SCTP_DEST_STATUS_ACTIVE;
		      if(spCurrNodeData->spDest == spPrimaryDest &&
			 spNewTxDest != spPrimaryDest) 
			{
			  DBG_PL(ProcessGapAckBlocks,
				 "primary recovered... "
				 "migrating back from %p to %p"),
			    spNewTxDest, spPrimaryDest DBG_PR;
			  spNewTxDest = spPrimaryDest; // return to primary
			}
		    }

		  spCurrNodeData->eMarkedForRtx = NO_RTX; // unmark
		}
	    }
	  else if(spCurrNodeData->spChunk->uiTsn > uiEndTsn)
	    {
	      /* This point in the rtx buffer is already past the tsns which are
	       * being acked by this gap ack block.  
	       */

	      /* NE: let's increment the number of Gap Ack/Non-Renegable Gap 
		 Ack Blocks processed*/
	      if (!eUseNonRenegSacks) {
		usNumGapAcksProcessed++;
	      }
	      else {
		if (eUseGapAckBlock) {
		  usNumGapAcksProcessed++;
		}
		else {
		  usNumNonRenegGapAcksProcessed++;
		}
	      }

	      /* Did we process all the gap ack blocks?
	       */
	      if((usNumGapAcksProcessed != usNumGapAckBlocks) || 
		 (usNumNonRenegGapAcksProcessed != usNumNonRenegGapAckBlocks))
		{ 
		  /* NE: since the SctpSackChunk_S and SctpNonRenegSackChunk_S 
		     structure sizes are different, the offset to point next 
		     Gap Ack Block should be calculated based on the chunk type 
		  */ 
		  if (!eUseNonRenegSacks) 
		    {
		      spCurrGapAck 
			= ((SctpGapAckBlock_S *)
			   (ucpSackChunk + sizeof(SctpSackChunk_S) 
			    +(usNumGapAcksProcessed * sizeof(SctpGapAckBlock_S))));
		      
		      DBG_PL(ProcessGapAckBlocks, "jump to next gap ack block") 
			DBG_PR;
		    }
		  else 
		    {
		      spCurrGapAck 
			= ((SctpGapAckBlock_S *)
			   (ucpSackChunk + sizeof(SctpNonRenegSackChunk_S) + 
			    (usNumGapAcksProcessed * sizeof(SctpGapAckBlock_S))));
		      
		      spCurrNonRenegGapAck 
			= ((SctpGapAckBlock_S *)
			   (ucpSackChunk + sizeof(SctpNonRenegSackChunk_S)
			    +(usNumGapAckBlocks * sizeof(SctpGapAckBlock_S)) 
			    +(usNumNonRenegGapAcksProcessed * sizeof(SctpGapAckBlock_S))));
		      
		      /* NE: Let's determine which block to use next. The next 
			 Gap Ack Block or the next Non-Renegable Gap Ack Block.
			 If all Gap Ack Blocks are processed let's use 
			 Non-Renegable Gap Ack Blocks */
		      if ((usNumGapAckBlocks == usNumGapAcksProcessed) && 
			  (usNumNonRenegGapAckBlocks > usNumNonRenegGapAcksProcessed)) {
			
			spCurrGapAck = spCurrNonRenegGapAck; 
			
			eUseGapAckBlock = FALSE;

			uiNonRenegGapAckStartTsn = 
			  spSackChunk->uiCumAck + spCurrNonRenegGapAck->usStartOffset;			
			
			DBG_PL(ProcessGapAckBlocks, "jump to next nr gap ack block") 
			  DBG_PR;
			
			DBG_PL(ProcessGapAckBlocks,"uiNonRenegGapAckStartTsn=%u"), 
			  uiNonRenegGapAckStartTsn DBG_PR;

		      } /* NE: If all Non-Renegable Gap Ack Blocks are processed, let's 
			   use Gap Ack Blocks */
		      else if ((usNumNonRenegGapAckBlocks == usNumNonRenegGapAcksProcessed)
			       && (usNumGapAckBlocks > usNumGapAcksProcessed)) {
			
			eUseGapAckBlock = TRUE;

			uiGapAckStartTsn = 
			  spSackChunk->uiCumAck + spCurrGapAck->usStartOffset;
			
			DBG_PL(ProcessGapAckBlocks, "jump to next gap ack block") 
			  DBG_PR;
			
			DBG_PL(ProcessGapAckBlocks,"uiGapAckStartTsn=%u"), 
			  uiGapAckStartTsn DBG_PR;

		      } /* NE: If there is both Gap Ack and Non-Renegable Gap 
			   Ack Blocks, use the block with lower start TSN value*/
		      else if ((usNumGapAckBlocks > usNumGapAcksProcessed) && 
			       (usNumNonRenegGapAckBlocks > usNumNonRenegGapAcksProcessed)){
			
			uiGapAckStartTsn = 
			  spSackChunk->uiCumAck + spCurrGapAck->usStartOffset;
			uiNonRenegGapAckStartTsn = 
			  spSackChunk->uiCumAck + spCurrNonRenegGapAck->usStartOffset;
			
			if (uiGapAckStartTsn < uiNonRenegGapAckStartTsn) {
			  
			  eUseGapAckBlock = TRUE;

			  DBG_PL(ProcessGapAckBlocks, "jump to next gap ack block") 
			    DBG_PR;

			  DBG_PL(ProcessGapAckBlocks,"uiGapAckStartTsn=%u"), 
			    uiGapAckStartTsn DBG_PR;
			}
			else if (uiNonRenegGapAckStartTsn < uiGapAckStartTsn) {
			  
			  spCurrGapAck = spCurrNonRenegGapAck; 
			  
			  eUseGapAckBlock = FALSE;

			  DBG_PL(ProcessGapAckBlocks, "jump to next nr gap ack block") 
			    DBG_PR;

			  DBG_PL(ProcessGapAckBlocks,"uiNonRenegGapAckStartTsn=%u"), 
			    uiNonRenegGapAckStartTsn DBG_PR;
			}
			else {
			  DBG_PL(ProcessGapAckBlocks,
				 "WARNING! This statement should not be reached!") 
			    DBG_PR;
			}
		      }
		      
		      eDoNotChangeCurrNode=TRUE;
		    }
		}

	      /* If this chunk was GapAcked before, then either the
	       * receiver has renegged the chunk (which our simulation
	       * doesn't do) or this SACK is arriving out of order.
	       */
	      /* NE: with the new implementation of NR-SACKs, Gap Ack Blocks and
		 Non-Renegable Gap Ack Blocks are disjoint and may constitute 
		 consecutive blocks which may cause a TSN to be seem like 
		 RENEGED but it is not the case */
	      if(spCurrNodeData->eGapAcked == TRUE && !eUseNonRenegSacks)
		{
		  DBG_PL(ProcessGapAckBlocks, 
			 "out of order SACK? setting TSN=%d eGapAcked=FALSE"),
		    spCurrNodeData->spChunk->uiTsn DBG_PR;
		  spCurrNodeData->eGapAcked = FALSE;
		  spCurrNodeData->spDest->iOutstandingBytes 
		    += spCurrNodeData->spChunk->sHdr.usLength;
		  
		  /* section 6.3.2.R4 says that we should restart the
		   * T3-rtx timer here if it isn't running already. In our
		   * implementation, it isn't necessary since
		   * ProcessSackChunk will restart the timer for any
		   * destinations which have outstanding data and don't
		   * have a timer running.
		   */
		}
	    }
	  
	  /* 04/18: PN: With NR-SACKS tsns can be missing in the send buffer,
	   * Need to track previous sbuf node for correct gap ack processing
	     */
	  if (eDoNotChangeCurrNode == TRUE) {
	    spCurrNode = spPrevNode; //spPrevNode remains unchanged 
	  }
	  else {
	    spPrevNode = spCurrNode; 
	  }
	  eDoNotChangeCurrNode=FALSE;
	}

      /* By this time, either we have run through the entire send buffer or we
       * have run out of gap ack blocks. In the case that we have run out of gap
       * ack blocks before we finished running through the send buffer, we need
       * to mark the remaining chunks in the send buffer as eGapAcked=FALSE.
       * This final marking needs to be done, because we only trust gap ack info
       * from the last SACK. Otherwise, renegging (which we don't do) or out of
       * order SACKs would give the sender an incorrect view of the peer's rwnd.
       */
      for(; spCurrNode != NULL; spCurrNode = spCurrNode->spNext)
	{
	  /* This chunk is NOT being acked and is missing at the receiver
	   */
	  spCurrNodeData = (SctpSendBufferNode_S *) spCurrNode->vpData;

	  /* If this chunk was GapAcked before, then either the
	   * receiver has renegged the chunk (which our simulation
	   * doesn't do) or this SACK is arriving out of order.
	   */
	  if(spCurrNodeData->eGapAcked == TRUE)
	    {
	      DBG_PL(ProcessGapAckBlocks, 
		     "out of order SACK? setting TSN=%d eGapAcked=FALSE"),
		spCurrNodeData->spChunk->uiTsn DBG_PR;
	      spCurrNodeData->eGapAcked = FALSE;
	      spCurrNodeData->spDest->iOutstandingBytes 
		+= spCurrNodeData->spChunk->sHdr.usLength;

	      /* section 6.3.2.R4 says that we should restart the T3-rtx
	       * timer here if it isn't running already. In our
	       * implementation, it isn't necessary since ProcessSackChunk
	       * will restart the timer for any destinations which have
	       * outstanding data and don't have a timer running.
	       */
	    }
	}

      /* NE : We need to process all Gap Ack Blocks since the uiHighestTsnSacked 
	 variable is calculated using the Gap Ack Blocks instead of using TSNs 
	 in the send buffer. So, if there are Gap Ack Blocks which are not 
	 processed then use them to calculate uiHighestTsnSacked variable */ 
      /* Did we process all the gap ack blocks?
       */
      while(usNumGapAcksProcessed != usNumGapAckBlocks)
	{
	  DBG_PL(ProcessGapAckBlocks, "jump to next gap ack block") 
	    DBG_PR;
	  
	  /* NE: since the SctpSackChunk_S and SctpNonRenegSackChunk_S structure
	     sizes are different, the offset to point first Gap Ack Block should
	     be calculated based on the chunk type */
	  if (!eUseNonRenegSacks) 
	    {
	      spCurrGapAck 
		= ((SctpGapAckBlock_S *)
		   (ucpSackChunk + sizeof(SctpSackChunk_S)
		    +(usNumGapAcksProcessed * sizeof(SctpGapAckBlock_S))));
	    }
	  else {
	    
	    spCurrGapAck 
	      = ((SctpGapAckBlock_S *)
		 (ucpSackChunk + sizeof(SctpNonRenegSackChunk_S)
		  +(usNumGapAcksProcessed * sizeof(SctpGapAckBlock_S))));
	  }
	  
	  uiStartTsn = spSackChunk->uiCumAck + spCurrGapAck->usStartOffset;
	  uiEndTsn = spSackChunk->uiCumAck + spCurrGapAck->usEndOffset;

	  /* NE: Change the calculation of Highest TSN SACKed since the 
	     previous calculation is using the TSNs from the send buffer and 
	     with the introduction of NR-SACKs send buffer may not have
	     the Highest TSN SACKed in the send buffer */
	  if(uiHighestTsnSacked < uiEndTsn)
	    uiHighestTsnSacked = uiEndTsn;
	  
	  usNumGapAcksProcessed++;
	}

      /* NE : We need to process also all Non-Renegable Gap Ack Blocks since the
	 uiHighestTsnSacked variable is calculated using the Gap Ack Blocks 
	 instead of using TSNs in the send buffer. So, if there are Gap Ack 
	 Blocks which are not processed then use them to calculate 
	 uiHighestTsnSacked variable */ 
      /* Did we process all the non-renegable gap ack blocks?
       */
      if (eUseNonRenegSacks) 
	{
	  while(usNumNonRenegGapAcksProcessed != usNumNonRenegGapAckBlocks)
	    {
	      DBG_PL(ProcessGapAckBlocks, "jump to next nr-gap ack block") 
		DBG_PR;
	      
	      spCurrGapAck 
		= ((SctpGapAckBlock_S *)
		   (ucpSackChunk + sizeof(SctpNonRenegSackChunk_S)
		    +(usNumGapAckBlocks * sizeof(SctpGapAckBlock_S))
		    +(usNumNonRenegGapAcksProcessed * sizeof(SctpGapAckBlock_S))));
	      
	      
	      uiStartTsn = spSackChunk->uiCumAck + spCurrGapAck->usStartOffset;
	      uiEndTsn = spSackChunk->uiCumAck + spCurrGapAck->usEndOffset;

	      /* NE: Change the calculation of Highest TSN SACKed since the 
		 previous calculation is using the TSNs from the send buffer and 
		 with the introduction of NR-SACKs send buffer may not have
		 the Highest TSN SACKed in the send buffer */
	      if(uiHighestTsnSacked < uiEndTsn)
		uiHighestTsnSacked = uiEndTsn;
	      
	      usNumNonRenegGapAcksProcessed++;
	    }
	}

      DBG_PL(ProcessGapAckBlocks, "now incrementing missing reports...") DBG_PR;
      DBG_PL(ProcessGapAckBlocks, "uiHighestTsnNewlyAcked=%d"), 
	     uiHighestTsnNewlyAcked DBG_PR;

      for(spCurrNode = sSendBuffer.spHead;
	  spCurrNode != NULL; 
	  spCurrNode = spCurrNode->spNext)
	{
	  spCurrNodeData = (SctpSendBufferNode_S *) spCurrNode->vpData;

	  DBG_PL(ProcessGapAckBlocks, "TSN=%d eGapAcked=%s"), 
	    spCurrNodeData->spChunk->uiTsn,
	    spCurrNodeData->eGapAcked ? "TRUE" : "FALSE"
	    DBG_PR;

	  if(spCurrNodeData->eGapAcked == FALSE)
	    {
	      // BEGIN -- MultipleFastRtx changes to this function  

	      /* Caro's Multiple Fast Rtx Algorithm 
	       * (in addition to existing HTNA algorithm)
	       */
	      if(( (spCurrNodeData->spChunk->uiTsn < uiHighestTsnNewlyAcked) ||
		   (eNewCumAck == TRUE && 
		    uiHighestTsnNewlyAcked <= uiRecover &&
		    spCurrNodeData->spChunk->uiTsn < uiHighestTsnSacked) ) &&
		 uiHighestTsnNewlyAcked > spCurrNodeData->uiFastRtxRecover)
		{
		  spCurrNodeData->iNumMissingReports++;
		  DBG_PL(ProcessGapAckBlocks, 
			 "incrementing missing report for TSN=%d to %d"), 
		    spCurrNodeData->spChunk->uiTsn,
		    spCurrNodeData->iNumMissingReports
		    DBG_PR;

		  if(spCurrNodeData->iNumMissingReports == iFastRtxTrigger &&
		     spCurrNodeData->eAdvancedAcked == FALSE)
		    {
		      if(spCurrNodeData->uiFastRtxRecover == 0)
			eFrInvoked = TRUE;
		      else
			eMfrInvoked = TRUE;

		      spCurrNodeData->iNumMissingReports = 0;
		      MarkChunkForRtx(spCurrNodeData, FAST_RTX);
		      eFastRtxNeeded = TRUE;
		      spCurrNodeData->uiFastRtxRecover =uiHighestOutstandingTsn;
			
		      DBG_PL(ProcessGapAckBlocks, 
			     "resetting missing report for TSN=%d to 0"), 
			spCurrNodeData->spChunk->uiTsn
			DBG_PR;
		      DBG_PL(ProcessGapAckBlocks, 
			     "setting uiFastRtxRecover=%d"), 
			spCurrNodeData->uiFastRtxRecover
			DBG_PR;
		    }
		}
	      // END -- MultipleFastRtx changes to this function  
	    }
	}
    }

  // BEGIN -- MultipleFastRtx changes to this function    
  if(eFrInvoked == TRUE)
    tiFrCount++;
  if(eMfrInvoked == TRUE)
    tiMfrCount++;
  // END -- MultipleFastRtx changes to this function    

  DBG_PL(ProcessGapAckBlocks, "eFastRtxNeeded=%s"), 
    eFastRtxNeeded ? "TRUE" : "FALSE" DBG_PR;
  DBG_X(ProcessGapAckBlocks);
  return eFastRtxNeeded;
}