sch_rapid.h:
	in rapid_connection structure, add one member:
        	int num_retrans;
	to keep track of the number of retransmitted segments in the queue for each connection

sch_rapid.c:
1. rapid_reuse_or_create_connection(): 
initialize num_retrans before "return rc":
	rc->num_retrans = 0;

2. rapid_enqueue():
(1) When a retransmitted segments needs to be enqueued, enqueue it in the corresponding queue for that connection and update the counter of retransmitted segments. The position field for rapid_cb structures of retransmitted segments is -2.

cb = rapid_skb_cb(skb);
data_len = qdisc_pkt_len(skb) - (sizeof(struct ethhdr) + (iph->ihl * 4) + (th->doff * 4));
	 
if (rc->highest_SEQ_num == (u32)0) {  /* have not enqueued data */
            rc->highest_SEQ_num = ntohl(th->seq) + data_len;
        }
        else {
           if (!after((ntohl(th->seq) + data_len), rc->highest_SEQ_num)) {
               cb->probe_position=-2; 
               rc->num_retrans++;  
             
#ifdef LOG_ENQUEUES
       printk(KERN_DEBUG "sch_rapid: enqueue-RTR t_k= %llu A= %u s= %u\n",
            rqd->NOW, (ntohl(th->seq) + data_len), qdisc_pkt_len(skb));
#endif
           }
           else
           {
              rc->highest_SEQ_num = ntohl(th->seq) + data_len;
              cb->probe_position = 0; /* for those data segments which are not retransmissions, not in probe stream when first enqueued */
           }
        }

(2) if the queue is empty and the segment to be enqueued is retransmited segment, set the virtual departure time for the segment as current link clock.

	if (rapid_queue_peek(rc) == NULL) {
           /* If it's a retransmission, assign a departure time= link clock time and enqueue it
            *else do rapid_schedule_segment
            */

           if(cb->probe_position == 0)
           {
              read_lock_bh(&(ca->ca_lock)); /* NOTE: hold lock for call to rapid_schedule_segment */
              rapid_schedule_segment(rqd, rc, skb); /* computes departure time in cb of skb */
              read_unlock_bh(&(ca->ca_lock)); /* NOTE: hold lock for call to rapid_schedule_segment */
           }
           else if(cb->probe_position == -2)
              cb->virtual_departure_time = rqd->LinkClock;

           rc->departure_time = cb->virtual_departure_time;
#ifdef LOG_ENQUEUES
           printk(KERN_DEBUG "sch_rapid: enqueue-NIL t_k= %llu t_d= %llu A= %u s= %u\n",
                  rqd->NOW, cb->virtual_departure_time,
                         (ntohl(th->seq) + data_len), qdisc_pkt_len(skb));
#endif
           ret = rapid_schedule(&(rqd->schedule_heap), rc);
           if (ret != 0)
               printk(KERN_INFO "sch_rapid: Failed to schedule departure\n");
        }
        else {
#ifdef LOG_ENQUEUES
           printk(KERN_DEBUG "sch_rapid: enqueue-QUE t_k= %llu A= %u s= %u\n",
                         rqd->NOW, (ntohl(th->seq) + data_len), qdisc_pkt_len(skb));
#endif

        }


3. rapid_dequeue():
(1) if the segment to be dequeued is a retransmited segment, decrease num_retrans and dequeue the segment:

        int retransmit_dequeue_flag;
        retransmit_dequeue_flag=0;

	if (cb->probe_position != 0) { /* is in probe stream */
           /* If the dequeued segment is a retransmitted segment,
            *then decrease the retransmission counter in rc
            */
           if(cb->probe_position == -2)
           {
             iph = ip_hdr(skb);
             th = tcp_hdr(skb);
             data_len = qdisc_pkt_len(skb) - (sizeof(struct ethhdr) + (iph->ihl * 4) + (th->doff * 4));
             rc->num_retrans--;
             retransmit_dequeue_flag=1;
           }
           send_skb = rapid_dequeue_head(rc);
           send_cb = rapid_skb_cb(send_skb);
           /* verify that it is a RAPID connection and update the inflight probe
            * array for this segment.
            */
           if ((rc->sock != NULL) &&
               (rc->rapid_cookie == RAPID_MAGIC_COOKIE) &&
               ((void *)(send_skb->sk) == rc->sock) && retransmited_dequeue_flag == 0)
               rapid_update_probes(rqd, rc, send_skb); 
               pause_gap = 0;
               pause_idle = 0;
        }


(2) after the segment is dequeued, if the head of the queue is a retransmited segments, assign a virtual departure time for that segment as link clock; if the next to be dequeued is a data segment and there are some retransmited segments in the queue, create probe streams immediately.

		  if(head_cb->probe_position == -2)
                  {
                     head_cb->virtual_departure_time = rqd->LinkClock;
                  }
                  else if (head_cb->probe_position == 0) {
                     /* The conditions for creating a probe stream are:
                      * - enough segments queued to probe for a minimum number of rates
                      *   given the number of equal size gaps used.
                      * - having this connection's departure scheduled a number of times
                      *   that correspond to possible departures in a minimum size
                      *   probe stream.
                      * - the connection is in TCP slow start.
                      *
                      * if there's retransmitted segments in the queue,
                      * create pstream immediately */
                     if ((rapid_queue_len(rc) >= (MIN_RATES * EQUAL_GAPS)) ||
                         (rc->stream_trys >= (MIN_RATES * EQUAL_GAPS)) ||
                         (ca->SS_state == SS_STATE_ON) || (rc->num_retrans > 0) ) {

                         rc->stream_trys = 0;
                         if (send_skb == NULL)
                            rapid_create_probes(rqd, rc, head_skb);
                         else
                            rapid_create_probes(rqd, rc, send_skb);                     }
                     else
                        {
                         rc->stream_trys++;                                                  rapid_schedule_segment(rqd, rc, head_skb); /* computes departure for head_cb */
                        }
                  }