ns-allinone-2.35/ns-2.35/diffserv/dsPolicy.cc
void SFDPolicy::applyMeter(policyTableEntry *, Packet *pkt) {
  int fid, src_id, dst_id;
  struct flow_entry *p, *q, *new_entry;

  double now = Scheduler::instance().clock();
  hdr_cmn* hdr = hdr_cmn::access(pkt);
  hdr_ip* iph = hdr_ip::access(pkt);
  fid = iph->flowid();
  dst_id = iph->daddr();
  src_id = iph->saddr();

  //  printf("enter applyMeter\n");
  //  printFlowTable();

  p = q = flow_table.head;
  while (p) {
    // Check if the flow has been recorded before.
    if (p->fid == fid) {
    //if (p->src_id == src_id && p->dst_id == dst_id ) {
      p->last_update = now;
      p->bytes_sent += hdr->size();
      return;
    } else if (p->last_update + FLOW_TIME_OUT < now){
      // The coresponding flow is expired.      
      if (p == flow_table.head){
	if (p == flow_table.tail) {
	  flow_table.head = flow_table.tail = NULL;
	  free(p);
	  p = q = NULL;
	} else {
	  flow_table.head = p->next;
	  free(p);
	  p = q = flow_table.head;
	}
      } else {
	q->next = p->next;
	if (p == flow_table.tail)
	  flow_table.tail = q;
	free(p);
	p = q->next;
      }
    } else {
      q = p;
      p = q->next;
    }
  }
  
  // This is the firt time the flow shown up
  if (!p) {
    new_entry = new flow_entry;
    new_entry->fid = fid;
    new_entry->src_id = src_id;
    new_entry->dst_id = dst_id;
    new_entry->last_update = now;
    new_entry->bytes_sent = hdr->size();
    new_entry->count = 0;
    new_entry->next = NULL;
    
    // always insert the new entry to the tail.
    if (flow_table.tail)
      flow_table.tail->next = new_entry;
    else
      flow_table.head = new_entry;
    flow_table.tail = new_entry;
  }
  
  //  printf("leave applyMeter\n");
  return;
}
/*-----------------------------------------------------------------------------
 void SFDPolicy::applyMeter(policyTableEntry *policy, Packet *pkt)
 Flow states are kept in a linked list.
 Record how many bytes has been sent per flow and check if there is any flow
 timeout.
-----------------------------------------------------------------------------*/
void SFDPolicy::applyMeter(policyTableEntry *policy, Packet *pkt)
Flow states are kept in a linked list.
Record how many bytes has been sent per flow and check if there is any flow
timeout.
void SFDPolicy :: applyMeter ( policyTableEntry * policy Packet * pkt ) Flow states are kept in a linked list . Record how many bytes has been sent per flow and check if there is any flow timeout .
void SFDPolicy::applyMeter(policyTableEntry *, Packet *pkt) {
  int fid, src_id, dst_id;
  struct flow_entry *p, *q, *new_entry;
  double now = Scheduler::instance().clock();
  hdr_cmn* hdr = hdr_cmn::access(pkt);
  hdr_ip* iph = hdr_ip::access(pkt);
  fid = iph->flowid();
  dst_id = iph->daddr();
  src_id = iph->saddr();
  p = q = flow_table.head;
  while (p) {
    if (p->fid == fid) {
      p->last_update = now;
      p->bytes_sent += hdr->size();
      return;
    } else if (p->last_update + FLOW_TIME_OUT < now){
      if (p == flow_table.head){
	if (p == flow_table.tail) {
	  flow_table.head = flow_table.tail = NULL;
	  free(p);
	  p = q = NULL;
	} else {
	  flow_table.head = p->next;
	  free(p);
	  p = q = flow_table.head;
	}
      } else {
	q->next = p->next;
	if (p == flow_table.tail)
	  flow_table.tail = q;
	free(p);
	p = q->next;
      }
    } else {
      q = p;
      p = q->next;
    }
  }
  if (!p) {
    new_entry = new flow_entry;
    new_entry->fid = fid;
    new_entry->src_id = src_id;
    new_entry->dst_id = dst_id;
    new_entry->last_update = now;
    new_entry->bytes_sent = hdr->size();
    new_entry->count = 0;
    new_entry->next = NULL;
    if (flow_table.tail)
      flow_table.tail->next = new_entry;
    else
      flow_table.head = new_entry;
    flow_table.tail = new_entry;
  }
  return;
}
void SFDPolicy :: applyMeter ( policyTableEntry * , Packet * pkt ) { int fid , src_id , dst_id ; struct flow_entry * p , * q , * new_entry ; double now = Scheduler :: instance ( ) . clock ( ) ; hdr_cmn * hdr = hdr_cmn :: access ( pkt ) ; hdr_ip * iph = hdr_ip :: access ( pkt ) ; fid = iph -> flowid ( ) ; dst_id = iph -> daddr ( ) ; src_id = iph -> saddr ( ) ; p = q = flow_table . head ; while ( p ) { if ( p -> fid == fid ) { p -> last_update = now ; p -> bytes_sent += hdr -> size ( ) ; return ; } else if ( p -> last_update + FLOW_TIME_OUT < now ) { if ( p == flow_table . head ) { if ( p == flow_table . tail ) { flow_table . head = flow_table . tail = NULL ; free ( p ) ; p = q = NULL ; } else { flow_table . head = p -> next ; free ( p ) ; p = q = flow_table . head ; } } else { q -> next = p -> next ; if ( p == flow_table . tail ) flow_table . tail = q ; free ( p ) ; p = q -> next ; } } else { q = p ; p = q -> next ; } } if ( ! p ) { new_entry = new flow_entry ; new_entry -> fid = fid ; new_entry -> src_id = src_id ; new_entry -> dst_id = dst_id ; new_entry -> last_update = now ; new_entry -> bytes_sent = hdr -> size ( ) ; new_entry -> count = 0 ; new_entry -> next = NULL ; if ( flow_table . tail ) flow_table . tail -> next = new_entry ; else flow_table . head = new_entry ; flow_table . tail = new_entry ; } return ; }
void SFDPolicy::applyMeter(policyTableEntry *policy, Packet *pkt)
Flow states are kept in a linked list.
void SFDPolicy :: applyMeter ( policyTableEntry * policy Packet * pkt ) Flow states are kept in a linked list .
//  printf("enter applyMeter\n"); //  printFlowTable(); // Check if the flow has been recorded before. //if (p->src_id == src_id && p->dst_id == dst_id ) { // The coresponding flow is expired.       // This is the firt time the flow shown up // always insert the new entry to the tail. //  printf("leave applyMeter\n");