4c4
<  *
---
>  * 
19c19
<  *
---
>  * 
47d46
<   bytes = 0;
51,57c50
<   q_ = new PacketQueue();
< 
<   // prevent division by zero for unconfigured queues
<   for (int i=0; i<MAX_PREC; i++) {
<     qParam_[i].bp_.ifreeze_time_ = 1;
<     qParam_[i].bp_.dfreeze_time_ = 1;
<   }
---
>   q_ = new PacketQueue();	
62c55
< //   Added option to config q_w by Thilo,
---
> //   Added option to config q_w by Thilo, 
68,89d60
<   } else if ((mredMode >= bio_ssi) && (mredMode <= bio_aat)) {
<     qParam_[prec].bp_.increment_    = atof(argv[4]);
<     qParam_[prec].bp_.decrement_    = atof(argv[5]);
<     qParam_[prec].bp_.ifreeze_time_ = atof(argv[6]);
<     qParam_[prec].bp_.dfreeze_time_ = atof(argv[7]);
<     qParam_[prec].edp_.th_max       = atoi(argv[8]);
< 
<     // ensure that we do not care hold_time for the first time
<     qParam_[prec].bv_.ihold_time_   = -1 * qParam_[prec].bp_.ifreeze_time_ - 0.0000001;
<     qParam_[prec].bv_.dhold_time_   = -1 * qParam_[prec].bp_.dfreeze_time_ - 0.0000001;
< 
<     qParam_[prec].bv_.pmark_        = 0;
<     qParam_[prec].qlen              = 0;
< 
<     qParam_[prec].edv_.v_ave        = 0;
< 
<     // minth is optional
<     if (argc > 9)
<       qParam_[prec].edp_.th_min     = atoi(argv[9]);
<     else
<       qParam_[prec].edp_.th_min     = 0;
<     return;
91c62
< 
---
>   
99c70
<   if (argc > 7)
---
>   if (argc > 7)  
101c72
<   else
---
>   else 
103c74
< 
---
>   
117c88
< 
---
>     
129c100
<   qParam_[prec].qlen--;
---
>   qParam_[prec].qlen--;		
133c104
< //    Called by enque() to set idle_ to 0
---
> //    Called by enque() to set idle_ to 0 
136,141c107,108
<   // do not act for BIO
<   if ((mredMode >= bio_ssi) && (mredMode <= bio_aat))
<     return;
< 
<   if (mredMode == rio_c) {
<     for (int i = prec; i < numPrec; i++)
---
>   if (mredMode == rio_c) { 
>     for (int i = prec; i < numPrec; i++) 
143,144c110,111
<   } else if (mredMode == rio_d) {
<     qParam_[prec].idle_ = 0;
---
>   } else if (mredMode == rio_d) { 
>     qParam_[prec].idle_ = 0; 
147,267c114
<   }
< }
< 
< void redQueue::increment_pm(int prec) {
<   double now;
< 
<   if (qParam_[prec].bv_.pmark_ >= 1)
<     return;
< 
<   now = Scheduler::instance().clock();
< 
<   /*
<      BLUE algoritmasinda yoktu ama bana geen sre ile orantili bir artim yapmak daha mantikli
<      geliyor. Eger ben 2 freetime'lik bir sure idle/overflow kaldi ise o kadar kez increment etmek
<      mantikli gibi.
< 
<      Ama deque surekli cagriliyor da, bu islem otomatik olarak mi yapiliyor?
< 
<      Eger bu mantik gerekli ise, t'yi float da yapmak sozkonusu olabilir.
<    */
< //  int t = (now - qParam_[prec].bv_.ihold_time_) / qParam_[prec].bp_.ifreeze_time_;
<    int t=1;
< 
<   if (t >= 1) {
<     t = 1;
<     qParam_[prec].bv_.ihold_time_ = now;
<     qParam_[prec].bv_.pmark_ += (float)t * qParam_[prec].bp_.increment_;
<     if (qParam_[prec].bv_.pmark_ > 1)
<       qParam_[prec].bv_.pmark_ = 1;
<   }
< }
< 
< void redQueue::decrement_pm(int prec) {
<   double now;
< 
<   if (qParam_[prec].bv_.pmark_ <= 0)
<     return;
< 
<   now = Scheduler::instance().clock();
< 
<   /*
<      BLUE algoritmasinda yoktu ama bana geen sre ile orantili bir artim yapmak daha mantikli
<      geliyor. Eger ben 2 freetime'lik bir sure idle/overflow kaldi ise o kadar kez increment etmek
<      mantikli gibi.
< 
<      Ama deque surekli cagriliyor da, bu islem otomatik olarak mi yapiliyor?
< 
<      Eger bu mantik gerekli ise, t'yi float da yapmak sozkonusu olabilir.
<    */
< //  int t = (now - qParam_[prec].bv_.dhold_time_) / qParam_[prec].bp_.dfreeze_time_;
<    int t=1;
< 
<   if (t >= 1) {
<     t = 1;
<     qParam_[prec].bv_.dhold_time_ = now;
<     qParam_[prec].bv_.pmark_ -= (float)t * qParam_[prec].bp_.decrement_;
<     if (qParam_[prec].bv_.pmark_ < 0)
<       qParam_[prec].bv_.pmark_ = 0;
<   }
< }
< 
< 
< int redQueue::bio_boundary_check(int prec)
< {
<   int i;
<   int ql = 0;
< 
<   // do not do something for RIO 
<   if (mredMode < bio_ssi) 
<     return -1;
< 
<   for (i=0; i<=prec; i++)
<     ql += qParam_[i].qlen;
< 
<   switch (mredMode) {
<     case bio_asi:
<     case bio_ast:
<       if (ql == 0) {
<         decrement_pm(prec);
<         return -1;
<       }
<       if (qParam_[prec].qlen >= qParam_[prec].edp_.th_max) {
<         increment_pm(prec);
<         return 1;
<       }
<       break;
<     case bio_aai:
<     case bio_aat:
<       if (ql == 0) {
<         decrement_pm(prec);
<         return -1;
<       }
<       if (ql >= qParam_[prec].edp_.th_max) {
<         increment_pm(prec);
<         return 1;
<       }
<       break;
<     case bio_ssi:
<     case bio_sst:
<       if (qParam_[prec].qlen == 0) {
<         decrement_pm(prec);
<         return -1;
<       }
<       if (qParam_[prec].qlen >= qParam_[prec].edp_.th_max) {
<         increment_pm(prec);
<         return 1;
<       }
<       break;
<     case bio_sai:
<     case bio_sat:
<       if (qParam_[prec].qlen == 0) {
<         decrement_pm(prec);
<         return -1;
<       }
<       if (ql >= qParam_[prec].edp_.th_max) {
<         increment_pm(prec);
<         return 1;
<       }
<       break;
<   }
<   return 0;
---
>   } 
275c122
< 
---
>   
277c124
< 
---
>   
279c126
< 
---
>   
282,283c129,130
<       for(i=0; i<prec; i++)
<         if(qParam_[i].qlen != 0) idle = 0;
---
>       for(i=0; i<prec; i++) 
> 	if(qParam_[i].qlen != 0) idle = 0;
285,290c132,137
<         for (i=prec;i<numPrec;i++) {
<           if (qParam_[i].qlen == 0) {
<             qParam_[i].idle_ = 1;
<             qParam_[i].idletime_ = now;
<           } else break;
<         }
---
> 	for (i=prec;i<numPrec;i++) {
> 	  if (qParam_[i].qlen == 0) {
> 	    qParam_[i].idle_ = 1;
> 	    qParam_[i].idletime_ = now;
> 	  } else break;
> 	}			
298c145
<     }
---
>     }			
302d148
< 
306c152
< //    Fix the bug that idle_ flag may be set to 0 when
---
> //    Fix the bug that idle_ flag may be set to 0 when 
313,316c159,160
<   int ql=0;
< 
<   if (q_->length() > (qlim-1)) {
<     printf("Oops: q overflowed %d %d\n", q_->length(), qlim);
---
>   
>   if (q_->length() > (qlim-1))
318,319c162
<   }
< 
---
>   
321c164
< 
---
>   
328,329c171
<       bytes += (hdr_cmn::access(pkt))->size();
<       return PKT_ENQUEUED;
---
>       return PKT_ENQUEUED;		
334c176
<     for (int i = prec; i < numPrec; i++) {
---
>     for (int i = prec; i < numPrec; i++) {	
340c182
<       calcAvg(i, m+1);
---
>       calcAvg(i, m+1); 
346c188
<     }
---
>     }	
352c194
<     }
---
>     }	
356,420c198,200
< 
<   switch (mredMode) {
<     case bio_aai:
<     case bio_asi:
<     case bio_sai:
<     case bio_ssi:
<       if (bio_boundary_check(prec) > 0) {
<         // forced drop
<         return PKT_DROPPED;
<       }
< 
<       ql = 0;
<       for (int i=prec+1; i<numPrec; i++)
<         ql += qParam_[i].qlen;
<       if (ql == 0) {
<         u = Random::uniform(0.0, 1.0);
< 
<         //drop it
<         if (u <= qParam_[prec].bv_.pmark_) {
<           // early drop
<           if (ecn) {
<             q_->enque(pkt);
<             //virtually, this new packet is queued in one of the multiple queues,
<             //thus increasing the length of that virtual queue
<             qParam_[prec].qlen++;
<             bytes += (hdr_cmn::access(pkt))->size();
<             return PKT_MARKED;
<           }
<           return PKT_EDROPPED;
<         }
<       }
<       break;
< 
<     case bio_aat:
<     case bio_ast:
<     case bio_sat:
<     case bio_sst:
<       if (bio_boundary_check(prec) > 0) {
<         // forced drop
<         return PKT_DROPPED;
<       }
< 
<       ql = 0;
<       for (int i=0; i<=prec; i++)
<         ql += qParam_[i].qlen;
<       if (ql > qParam_[prec].edp_.th_min) {
<         u = Random::uniform(0.0, 1.0);
< 
<         //drop it
<         if (u <= qParam_[prec].bv_.pmark_) {
<           // early drop
<           if (ecn) {
<             q_->enque(pkt);
<             bytes += (hdr_cmn::access(pkt))->size();
<             //virtually, this new packet is queued in one of the multiple queues,
<             //thus increasing the length of that virtual queue
<             qParam_[prec].qlen++;
<             return PKT_MARKED;
<           }
<           return PKT_EDROPPED;
<         }
<       }
<       break;
<     default:
<       // RIO
---
>   // enqueu packet if we are using ecn
>   if (ecn) {
>     q_->enque(pkt);	
422,479c202,243
<       //if the avg is greater than the min threshold,
<       //there can be only two cases.....
<       if (qParam_[prec].edv_.v_ave > qParam_[prec].edp_.th_min) {
<         //either the avg is less than the max threshold
<         if (qParam_[prec].edv_.v_ave <= qParam_[prec].edp_.th_max) {
<           //in which case determine the probabilty for dropping the packet,
< 
<           qParam_[prec].edv_.count++;
<           qParam_[prec].edv_.v_prob = (1/qParam_[prec].edp_.max_p_inv) *
< 	    (qParam_[prec].edv_.v_ave-qParam_[prec].edp_.th_min) /
<             (qParam_[prec].edp_.th_max-qParam_[prec].edp_.th_min);
< 
<           pb = qParam_[prec].edv_.v_prob;
<           pa = pb/(1.0 - qParam_[prec].edv_.count*pb);
< 
<           qParam_[prec].red_pmark_ = pa;
<           if (qParam_[prec].red_pmark_ < 0)
<             qParam_[prec].red_pmark_ = 0.0;
<           else if (qParam_[prec].red_pmark_ > 1)
<             qParam_[prec].red_pmark_ = 1.0;
< 
<           //now determining whether to drop the packet or not
<           u = Random::uniform(0.0, 1.0);
< 
<           //drop it
<           if (u <= pa) {
<             // early drop
<             
<             // When average queue length is between min. threshold and max. threshold 
<             // and the packet is dropped, the value of edv_.count should be set to 0.
<             // by Janusz Gozdecki <gozdecki@kt.agh.edu.pl>, 7/13/2002
<             qParam_[prec].edv_.count = 0; 
< 	    if (ecn) {
<               q_->enque(pkt);	
<               bytes += (hdr_cmn::access(pkt))->size();
<     
<               //virtually, this new packet is queued in one of the multiple queues,
<               //thus increasing the length of that virtual queue
<               qParam_[prec].qlen++;
< 
<               // set idle_ to 0
< 	      updateIdleFlag(prec);
< 	      return PKT_MARKED;
< 	    }
< 	    return PKT_EDROPPED;
<           }
<         } else { //if avg queue is greater than max. threshold
<           // forced drop (even for ECN)
<           
<           qParam_[prec].edv_.count = 0;
<           return PKT_DROPPED;
<         }
<       } else {
<         // When average queue length is between min. threshold and max. threshold 
<         // and the packet is not dropped the value of edv_.count should be unchanged
<         // rather than -1 (which causes a significant impact on the number of early packet drops).
<         // by Janusz Gozdecki <gozdecki@kt.agh.edu.pl>, 7/13/2002
<         qParam_[prec].edv_.count = -1;
---
>     //virtually, this new packet is queued in one of the multiple queues,
>     //thus increasing the length of that virtual queue
>     qParam_[prec].qlen++;
>   }
>   
>   //if the avg is greater than the min threshold,
>   //there can be only two cases.....
>   if (qParam_[prec].edv_.v_ave > qParam_[prec].edp_.th_min) {
>     //either the avg is less than the max threshold
>     if (qParam_[prec].edv_.v_ave <= qParam_[prec].edp_.th_max) {
>       //in which case determine the probabilty for dropping the packet,
>       
>       qParam_[prec].edv_.count++;
>       qParam_[prec].edv_.v_prob = (1/qParam_[prec].edp_.max_p_inv) *
> 	(qParam_[prec].edv_.v_ave-qParam_[prec].edp_.th_min) /
> 	(qParam_[prec].edp_.th_max-qParam_[prec].edp_.th_min);
>       
>       pb = qParam_[prec].edv_.v_prob;
>       pa = pb/(1.0 - qParam_[prec].edv_.count*pb);
> 
>       //now determining whether to drop the packet or not
>       u = Random::uniform(0.0, 1.0);
>       
>       //drop it
>       if (u <= pa) {
> 	// When average queue length is between min. threshold and max. threshold 
> 	// and the packet is dropped, the value of edv_.count should be set to 0.
> 	// by Janusz Gozdecki <gozdecki@kt.agh.edu.pl>, 7/13/2002
> 	qParam_[prec].edv_.count = 0; 
> 	if (ecn) {
> 	  // set idle_ to 0
> 	  updateIdleFlag(prec); 
> 	  return PKT_MARKED;
> 	}
> 	return PKT_EDROPPED;
>       }
>     } else { //if avg queue is greater than max. threshold
>       qParam_[prec].edv_.count = 0;
>       if (ecn) {
> 	// set idle_ to 0
> 	updateIdleFlag(prec); 
> 	return PKT_MARKED;
481c245,253
<   } // switch (mredMode)
---
>       return PKT_DROPPED;
>     }
>   } else {
>     // When average queue length is between min. threshold and max. threshold 
>     // and the packet is not dropped the value of edv_.count should be unchanged
>     // rather than -1 (which causes a significant impact on the number of early packet drops).
>     // by Janusz Gozdecki <gozdecki@kt.agh.edu.pl>, 7/13/2002
>     qParam_[prec].edv_.count = -1;
>   }
483,484c255,263
<   // if the packet survives the above conditions it
<   // is finally queued in the underlying queue
---
>   // if ecn is on, then the packet has already been enqueued
>   if(ecn) { 
>     // set idle_ to 0
>     updateIdleFlag(prec); 
>     return PKT_ENQUEUED;
>   }
>   
>   //if the packet survives the above conditions it
>   //is finally queued in the underlying queue
486,489c265,267
<   bytes += (hdr_cmn::access(pkt))->size();
< 
<   // virtually, this new packet is queued in one of the multiple queues,
<   // thus increasing the length of that virtual queue
---
>   
>   //virtually, this new packet is queued in one of the multiple queues,
>   //thus increasing the length of that virtual queue
493,494c271,272
<   updateIdleFlag(prec);
< 
---
>   updateIdleFlag(prec); 
>   
501,509c279
<   Packet *pkt;
< 
<   pkt = q_->deque();
<   if (pkt != NULL) {
<      bytes -= (hdr_cmn::access(pkt))->size();
<      if (bytes < 0)
<          printf("\n\n\n\t********Error in redQueue:deque()\n\n\n\n\n");
<   }
<   return(pkt);
---
>   return(q_->deque());
513c283
< //   This method calculates avg queue length, given the prec number,
---
> //   This method calculates avg queue length, given the prec number, 
516c286
< //   If it is true, the calculated size of queue n includes the sizes of all
---
> //   If it is true, the calculated size of queue n includes the sizes of all 
549c319
< 
---
>   
591,597d360
< 
< float redQueue::getMarkP(int prec) {
<   if ((mredMode >= bio_ssi) && (mredMode <= bio_aat)) {
<     return qParam_[prec].bv_.pmark_;
<   }
<   return qParam_[prec].red_pmark_;
< }
