ns-allinone-2.35/ns-2.35/diffserv/dsPolicy.cc
int SFDPolicy::applyPolicer(policyTableEntry *policy, policerTableEntry *policer, Packet *pkt) {
  int fid, src_id, dst_id;
  struct flow_entry *p;

  hdr_ip* iph = hdr_ip::access(pkt);
  fid = iph->flowid();
  dst_id = iph->daddr();
  src_id = iph->saddr();

  //  printf("enter applyPolicer\n");
  //printFlowTable();
  
  p = flow_table.head;
  while (p) {
    // Check if the flow has been recorded before.
    if (p->fid == iph->flowid()) {
      //if (p->src_id == src_id && p->dst_id == dst_id) {
      if (p->bytes_sent > policy->cir) {
	// Use downgrade2 code to judge how to penalize out-profile packets.
	if (policer->downgrade2 == 0) {
	  // Penalize every packet beyond th.
	  //printf("leave applyPolicer  %d, every downgrade\n", p->fid);
	  return(policer->downgrade1);
	} else if (policer->downgrade2 == 1) {
	  // Randomized penalization.
	  if (Random::uniform(0.0, 1.0) > (1 - (policy->cir/p->bytes_sent))) {
	    //printf("leave applyPolicer %d, random initial.\n", p->fid);
	    return(policer->initialCodePt);
	  } else {
	    //printf("leave applyPolicer %d, random, downgrade\n", p->fid);
	    return(policer->downgrade1);
	  }
	} else {
	  // Simple scheduling on penalization.
	  if (p->count == 5) {
	    // Penalize 4 out of every 5 packets.
	    p->count = 0;
	    //printf("leave applyPolicer %d, initial, %d\n", p->fid, p->count);
	    return(policer->initialCodePt);
	  } else {
	    p->count++;
	    //printf("leave applyPolicer %d, downgrade, %d\n", p->fid, p->count);
	    return(policer->downgrade1);
	  }
	}
      } else {
	//	printf("leave applyPolicer, initial\n");
	return(policer->initialCodePt);
      }
    }
    p = p->next;
  }
  
  // Can't find the record for this flow.
  if (!p) {
    printf ("MISS: no flow %d (%d, %d) in the table\n", fid, src_id, dst_id);
    printFlowTable();
};
  
  //  printf("leave applyPolicer, init but problem...\n");
  return(policer->initialCodePt);
}
/*-----------------------------------------------------------------------------
void SFDPolicy::applyPolicer(policyTableEntry *policy, int initialCodePt, Packet *pkt) 
    Prints the policyTable, one entry per line.
-----------------------------------------------------------------------------*/
void SFDPolicy::applyPolicer(policyTableEntry *policy, int initialCodePt, Packet *pkt)
Prints the policyTable, one entry per line.
void SFDPolicy :: applyPolicer ( policyTableEntry * policy int initialCodePt Packet * pkt ) Prints the policyTable one entry per line .
int SFDPolicy::applyPolicer(policyTableEntry *policy, policerTableEntry *policer, Packet *pkt) {
  int fid, src_id, dst_id;
  struct flow_entry *p;
  hdr_ip* iph = hdr_ip::access(pkt);
  fid = iph->flowid();
  dst_id = iph->daddr();
  src_id = iph->saddr();
  p = flow_table.head;
  while (p) {
    if (p->fid == iph->flowid()) {
      if (p->bytes_sent > policy->cir) {
	if (policer->downgrade2 == 0) {
	  return(policer->downgrade1);
	} else if (policer->downgrade2 == 1) {
	  if (Random::uniform(0.0, 1.0) > (1 - (policy->cir/p->bytes_sent))) {
	    return(policer->initialCodePt);
	  } else {
	    return(policer->downgrade1);
	  }
	} else {
	  if (p->count == 5) {
	    p->count = 0;
	    return(policer->initialCodePt);
	  } else {
	    p->count++;
	    return(policer->downgrade1);
	  }
	}
      } else {
	return(policer->initialCodePt);
      }
    }
    p = p->next;
  }
  if (!p) {
    printf ("MISS: no flow %d (%d, %d) in the table\n", fid, src_id, dst_id);
    printFlowTable();
};
  return(policer->initialCodePt);
}
int SFDPolicy :: applyPolicer ( policyTableEntry * policy , policerTableEntry * policer , Packet * pkt ) { int fid , src_id , dst_id ; struct flow_entry * p ; hdr_ip * iph = hdr_ip :: access ( pkt ) ; fid = iph -> flowid ( ) ; dst_id = iph -> daddr ( ) ; src_id = iph -> saddr ( ) ; p = flow_table . head ; while ( p ) { if ( p -> fid == iph -> flowid ( ) ) { if ( p -> bytes_sent > policy -> cir ) { if ( policer -> downgrade2 == 0 ) { return ( policer -> downgrade1 ) ; } else if ( policer -> downgrade2 == 1 ) { if ( Random :: uniform ( 0.0 , 1.0 ) > ( 1 - ( policy -> cir / p -> bytes_sent ) ) ) { return ( policer -> initialCodePt ) ; } else { return ( policer -> downgrade1 ) ; } } else { if ( p -> count == 5 ) { p -> count = 0 ; return ( policer -> initialCodePt ) ; } else { p -> count ++ ; return ( policer -> downgrade1 ) ; } } } else { return ( policer -> initialCodePt ) ; } } p = p -> next ; } if ( ! p ) { printf ( " \n " , fid , src_id , dst_id ) ; printFlowTable ( ) ; } ; return ( policer -> initialCodePt ) ; }
void SFDPolicy::applyPolicer(policyTableEntry *policy, int initialCodePt, Packet *pkt)
Prints the policyTable, one entry per line.
void SFDPolicy :: applyPolicer ( policyTableEntry * policy int initialCodePt Packet * pkt ) Prints the policyTable one entry per line .
//  printf("enter applyPolicer\n"); //printFlowTable(); // Check if the flow has been recorded before. //if (p->src_id == src_id && p->dst_id == dst_id) { // Use downgrade2 code to judge how to penalize out-profile packets. // Penalize every packet beyond th. //printf("leave applyPolicer  %d, every downgrade\n", p->fid); // Randomized penalization. //printf("leave applyPolicer %d, random initial.\n", p->fid); //printf("leave applyPolicer %d, random, downgrade\n", p->fid); // Simple scheduling on penalization. // Penalize 4 out of every 5 packets. //printf("leave applyPolicer %d, initial, %d\n", p->fid, p->count); //printf("leave applyPolicer %d, downgrade, %d\n", p->fid, p->count); //	printf("leave applyPolicer, initial\n"); // Can't find the record for this flow. //  printf("leave applyPolicer, init but problem...\n");