67c67
< dsREDQueue::dsREDQueue() : de_drop_(NULL), link_(NULL), channel_(0)  {
---
> dsREDQueue::dsREDQueue() : de_drop_(NULL), link_(NULL)   {
71,72c71
< 
<   ds = NULL;  
---
>   
83c82
< 
---
>   
90,92c89,91
< 
<   qToDq = 0;		// q to be dequed, initialized to 0
< 
---
>   
>   qToDq = 0;		// q to be dequed, initialized to 0	
>   
101,103c100
< 
<   clearDetailedStats();
< 
---
>   
107c104
< 
---
>   
113c110
< 
---
>   
116c113
< 
---
>   
123c120
< 
---
>   
148c145
< Post: Adjusts policy's TSW state variables avgRate and arrivalTime
---
> Post: Adjusts policy's TSW state variables avgRate and arrivalTime 
159,160c156,157
<   // Modified by xuanc(xuanc@isi.edu) Oct 18, 2001,
<   // referring to the patch contributed by
---
>   // Modified by xuanc(xuanc@isi.edu) Oct 18, 2001, 
>   // referring to the patch contributed by 
172c169
< void enque(Packet* pkt)
---
> void enque(Packet* pkt) 
174c171
< This method is not used by the inheriting classes; it only serves as an
---
> This method is not used by the inheriting classes; it only serves as an 
181c178
<   codePt = iph->prio();
---
>   codePt = iph->prio();	
183c180
< 
---
>   
185c182
<   lookupPHBTable(codePt, &eq_id, &prec);
---
>   lookupPHBTable(codePt, &eq_id, &prec);	
193c190
< 
---
>   
196,211c193
< 
<   struct detailedStatType *dsp = NULL;
<   int pkt_size = (hdr_cmn::access(pkt))->size(); 
<   { // stat block
<     // get a ptr to the stats block for the packet
<     int flow_id = iph->fid_;
<     dsp = getDS(flow_id, codePt);
< 
<     // finally log the packet arrival 
<     if (dsp) {
<       dsp->p_arr++;
<       dsp->b_arr += pkt_size;
<     }
<   }
< 
< 
---
>   
214,236d195
<     /*   let q(i) to be the size of the queue, packet(i) experiences when it is to be queued
< 
<          we want to calculate (sum(q(i), 0, n-1) / n) for the queueing delay indication. This 
<          in fact gives the number of avg bytes each packets sees in queue. With the bw information
<          queueing delay can easily be calculated.
<          
<          However, we cannot have a large array to hold the qsize each packet sees. We should find aother
<          way to calculate this value
<          
<          q_delay(n)   = 1/n     * sum(q(i), 0, n-1)
<          q_delay(n+1) = 1/(n+1) * sum(q(i), 0, n)
<                       = 1/(n+1) * (q(n) + sum(q(i), 0, n-1)) 
<                       = 1/(n+1) * (q(n) + n * q_delay(n))
<                       
<          we're calculating this below  
<      */
<     if (dsp) {
< //      dsp->qdelay = ((dsp->qdelay * dsp->b_enq) + redq_[eq_id].bytes) / (dsp->b_enq + pkt_size);
<       dsp->qdelay = ((dsp->qdelay * dsp->p_enq) + redq_[eq_id].bytes) / (dsp->p_enq + 1);
< 
<       dsp->p_enq++;
<       dsp->b_enq += pkt_size;
<     }
241,245d199
<     if (dsp) {
<       dsp->p_drop++;
<       dsp->b_drop += pkt_size;
<     }
< 
247c201
<     break;
---
>          break;
251,255d204
<     if (dsp) {
<       dsp->p_edrop++;
<       dsp->b_edrop += pkt_size;
<     }
< 
259,271c208,209
<     if (dsp) {
< //    dsp->qdelay = ((dsp->qdelay * dsp->b_enq) + redq_[eq_id].bytes) / (dsp->b_enq + pkt_size);
<       dsp->qdelay = ((dsp->qdelay * dsp->p_enq) + redq_[eq_id].bytes) / (dsp->p_enq + 1);
<       
<       dsp->p_mark++;
<       dsp->b_mark += pkt_size;
<     
<       dsp->p_enq++;
<       dsp->b_enq += pkt_size;
<     }
< 
<     hf->ce() = 1; 	// mark Congestion Experienced bit
<     break;
---
>     hf->ce() = 1; 	// mark Congestion Experienced bit		
>     break;			
287c225
< 
---
>   
289c227
<   if (dq_id < numQueues_)
---
>   if (dq_id < numQueues_) 
291,292c229,230
< 
<   if (p) {
---
>   
>   if (p) { 
297,304d234
<     { // measurement block
<       struct detailedStatType *dsp = getDS(iph->fid_, iph->prio()); 
<       if (dsp) {     
<         dsp->p_deq++;
<         dsp->b_deq += (hdr_cmn::access(p))->size();
<       }
<     }
< 
319c249
< 
---
>     
323c253
<     redq_[dq_id].updateVREDLen(prec);
---
>     redq_[dq_id].updateVREDLen(prec);	
326,327d255
< 
<     redq_[dq_id].bio_boundary_check(prec);
360c288
<     }
---
>     }			
405c333
<     // find the Queue with highest priority,
---
>     // find the Queue with highest priority, 
419c347
< }
---
> }	
423,424c351,352
<     Assigns the queue and prec parameters values corresponding to a given code
< point.  The code point is assumed to be present in the PHB table.  If it is
---
>     Assigns the queue and prec parameters values corresponding to a given code 
> point.  The code point is assumed to be present in the PHB table.  If it is 
483c411
< void setNumPrec(int prec)
---
> void setNumPrec(int prec) 
507c435
< 
---
>   
516,531d443
<   else if (strcmp(mode, "BIO-AAI") == 0)
<     tempMode = bio_aai;
<   else if (strcmp(mode, "BIO-AAT") == 0)
<     tempMode = bio_aat;
<   else if (strcmp(mode, "BIO-SAI") == 0)
<     tempMode = bio_sai;
<   else if (strcmp(mode, "BIO-SAT") == 0)
<     tempMode = bio_sat;
<   else if (strcmp(mode, "BIO-ASI") == 0)
<     tempMode = bio_asi;
<   else if (strcmp(mode, "BIO-AST") == 0)
<     tempMode = bio_ast;
<   else if (strcmp(mode, "BIO-SSI") == 0)
<     tempMode = bio_ssi;
<   else if (strcmp(mode, "BIO-SST") == 0)
<     tempMode = bio_sst;
536c448
< 
---
>   
650,654d561
<   if (strcmp(argv[1], "getMarkP") == 0) {
<     Tcl& tcl = Tcl::instance();
<     tcl.resultf("%f", redq_[atoi(argv[2])].getMarkP(atoi(argv[3])));
<     return(TCL_OK);
<   }
724,725c631,632
<   }
<   // Returns the length of one virtual queue, in packets
---
>   } 
>   // Returns the length of one virtual queue, in packets 
734,763d640
< 
< 
<   if ((argc == 3) && (strcmp(argv[1], "attach") == 0)) {
<         int mode;
<         const char* id = argv[2];
< 	Tcl& tcl = Tcl::instance();
<         
<         Tcl_Channel ch = Tcl_GetChannel(tcl.interp(), (char*)id,
< 				  &mode);
<         if (ch == 0) {
< 	        tcl.resultf("trace: can't attach %s for writing", id);
< 	        return (TCL_ERROR);
<         }
< 
<         channel_ = ch;
<         createDetailedStats();
<         return (TCL_OK);
<   }
< 
<   if (strcmp(argv[1], "resetDetailedStats") == 0) {
<     clearDetailedStats();
<     return(TCL_OK);
<   }
< 
<   if (strcmp(argv[1], "dumpDetailedStats") == 0) {
<     dumpDetailedStats();
<     return(TCL_OK);
<   }
< 
< 
768,951d644
< detailedStatType *dsREDQueue::getDS(int flow_id, int cp)
< {
<   if (ds == NULL) {
<     /* user have not enabled stats for this queue
<        so we do not need to keep statistics. 
<      */
<     return NULL;
<   } 
<    
<    
<   if (flow_id >= MAX_FLOWS) {
<     printf("***** Too large flow_id. There is no space on ds[][] to keep data for this flow\n\tflow_id: %d, MAX_FLOWS: %d\n", flow_id, MAX_FLOWS);
<     return NULL;
<   }
<   if (cp >= MAX_CP) {
<     printf("***** Too large codePt. There is no space on ds[][] to keep data for this codePt\n\tcodePt: %d, MAX_CP: %d\n", cp, MAX_CP);
<     return NULL;
<   }
<   
<   return ds + flow_id * MAX_CP + cp;
< }
< 
< 
< void dsREDQueue::createDetailedStats() {
<    if (ds == NULL) {
<       printf("Enabling detailed stats\n");
<       ds = (detailedStatType *) malloc(sizeof(detailedStatType) * MAX_CP * MAX_FLOWS);
<    }
< }   
< 
< void dsREDQueue::clearDetailedStats() {
<    detailedStatType *dsp;
< 
<    if (!ds)
<      return;
< 
<    memset(ds, 0x00, sizeof(detailedStatType) * MAX_CP * MAX_FLOWS);
<    for (int i=0; i<MAX_FLOWS; i++)
<       for (int j=0; j<MAX_CP; j++) {
<          dsp = getDS(i, j);
<          if (dsp)
<            dsp->last_reset = Scheduler::instance().clock();
<       }
< }
< 
< 
< void dsREDQueue::dumpDetailedStats() {
<    struct detailedStatType *dsp;
<    struct detailedStatType ds;
<    char buff[1024*100];
<    char tmp[1024*10];
< 
<    if (channel_ == 0)
<       return;
< 
<    memset(&ds, 0x00, sizeof(ds));
<    for (int flow=0; flow<MAX_FLOWS; flow++) {
<       for (int cp=0; cp<MAX_CP; cp++) {
<          dsp = getDS(flow, cp);
< 
<          if (dsp->p_arr != 0) 
<             ds.qdelay = ((ds.qdelay * ds.p_enq) + (dsp->qdelay * dsp->p_enq)) / (ds.p_enq + dsp->p_enq);
<          ds.p_arr += dsp->p_arr;
<          ds.b_arr += dsp->b_arr;
<          ds.p_enq += dsp->p_enq;
<          ds.b_enq += dsp->b_enq;
<          ds.p_deq += dsp->p_deq;
<          ds.b_deq += dsp->b_deq;
<          ds.p_mark += dsp->p_mark;
<          ds.b_mark += dsp->b_mark;
<          ds.p_drop += dsp->p_drop;
<          ds.b_drop += dsp->b_drop;
<          ds.p_edrop += dsp->p_edrop;
<          ds.b_edrop += dsp->b_edrop;
<       }      
<    }
< 
<    sprintf(buff, "%.1f\ta\ta\t%.2f\t%d\t%d\t%d\t%d\t%d\t%d\t%d\t%d\t%d\t%d\t%d\t%d\t",
<          Scheduler::instance().clock(),
<          ds.qdelay,
<          ds.p_arr, ds.b_arr, 
<          ds.p_enq, ds.b_enq, 
<          ds.p_deq, ds.b_deq, 
<          ds.p_mark, ds.b_mark, 
<          ds.p_drop, ds.b_drop, 
<          ds.p_edrop, ds.b_edrop);
< 
< 
<    for (int flow=0; flow<MAX_FLOWS; flow++) {
<       memset(&ds, 0x00, sizeof(ds));
<       for (int cp=0; cp<MAX_CP; cp++) {
<          dsp = getDS(flow, cp);
<          
<          if (dsp->p_arr != 0) 
<             ds.qdelay = ((ds.qdelay * ds.p_enq) + (dsp->qdelay * dsp->p_enq)) / (ds.p_enq + dsp->p_enq);
<          ds.p_arr += dsp->p_arr;
<          ds.b_arr += dsp->b_arr;
<          ds.p_enq += dsp->p_enq;
<          ds.b_enq += dsp->b_enq;
<          ds.p_deq += dsp->p_deq;
<          ds.b_deq += dsp->b_deq;
<          ds.p_mark += dsp->p_mark;
<          ds.b_mark += dsp->b_mark;
<          ds.p_drop += dsp->p_drop;
<          ds.b_drop += dsp->b_drop;
<          ds.p_edrop += dsp->p_edrop;
<          ds.b_edrop += dsp->b_edrop;
<       }      
< 
<       if (ds.p_arr == 0)
<          continue;
< 
<       sprintf(tmp, "%d\ta\t%.2f\t%d\t%d\t%d\t%d\t%d\t%d\t%d\t%d\t%d\t%d\t%d\t%d\t",
<          flow, 
<          ds.qdelay,
<          ds.p_arr, ds.b_arr, 
<          ds.p_enq, ds.b_enq, 
<          ds.p_deq, ds.b_deq, 
<          ds.p_mark, ds.b_mark, 
<          ds.p_drop, ds.b_drop, 
<          ds.p_edrop, ds.b_edrop);
<       strcat(buff, tmp);
<    }
< 
<    for (int cp=0; cp<MAX_CP; cp++) {
<       memset(&ds, 0x00, sizeof(ds));
<       for (int flow=0; flow<MAX_FLOWS; flow++) {
<          dsp = getDS(flow, cp);
<          
<          if (dsp->p_arr != 0) 
<             ds.qdelay = ((ds.qdelay * ds.p_enq) + (dsp->qdelay * dsp->p_enq)) / (ds.p_enq + dsp->p_enq);
<          ds.p_arr += dsp->p_arr;
<          ds.b_arr += dsp->b_arr;
<          ds.p_enq += dsp->p_enq;
<          ds.b_enq += dsp->b_enq;
<          ds.p_deq += dsp->p_deq;
<          ds.b_deq += dsp->b_deq;
<          ds.p_mark += dsp->p_mark;
<          ds.b_mark += dsp->b_mark;
<          ds.p_drop += dsp->p_drop;
<          ds.b_drop += dsp->b_drop;
<          ds.p_edrop += dsp->p_edrop;
<          ds.b_edrop += dsp->b_edrop;
<       }      
< 
<       if (ds.p_arr == 0)
<          continue;
< 
<       sprintf(tmp, "a\t%d\t%.2f\t%d\t%d\t%d\t%d\t%d\t%d\t%d\t%d\t%d\t%d\t%d\t%d\t",
<          cp,
<          ds.qdelay,
<          ds.p_arr, ds.b_arr, 
<          ds.p_enq, ds.b_enq, 
<          ds.p_deq, ds.b_deq, 
<          ds.p_mark, ds.b_mark, 
<          ds.p_drop, ds.b_drop, 
<          ds.p_edrop, ds.b_edrop);
<       strcat(buff, tmp);
<    }
< 
<    for (int flow=0; flow<MAX_FLOWS; flow++) {
<       for (int cp=0; cp<MAX_CP; cp++) {
<          dsp = getDS(flow, cp);
<          
<          if (dsp->p_arr == 0)
<             continue;
< 
<          sprintf(tmp, "%d\t%d\t%.2f\t%d\t%d\t%d\t%d\t%d\t%d\t%d\t%d\t%d\t%d\t%d\t%d\t",
<             flow, cp,
<             dsp->qdelay,
<             dsp->p_arr, dsp->b_arr, 
<             dsp->p_enq, dsp->b_enq, 
<             dsp->p_deq, dsp->b_deq, 
<             dsp->p_mark, dsp->b_mark, 
<             dsp->p_drop, dsp->b_drop, 
<             dsp->p_edrop, dsp->b_edrop);
<          strcat(buff, tmp);
<       }
<    }
<    
<    strcat(buff, "\n");
<    Tcl_Write(channel_, buff, strlen(buff));
< }
< 
