ns-allinone-2.35/ns-2.35/diffserv/ew.cc
int EWPolicy::applyPolicer(policyTableEntry *, policerTableEntry *policer, Packet *pkt) {
  //printf("enter applyPolicer ");

  // can't count/penalize ACKs:
  //   with resp: may cause inaccurate calculation with TSW(??)
  //   with req:  may cause resp retransmission.
  // just pass them through
  hdr_cmn *th = hdr_cmn::access(pkt);
  hdr_ip* iph = hdr_ip::access(pkt);
  int dst_id = iph->daddr();
  int src_id = iph->saddr();

  if (th->ptype() == PT_ACK)
    return(policer->initialCodePt);

  // for other packets...

  // Get time
  now = Scheduler::instance().clock();

  // keep arrival packet stats
  if (ewP) {
    printf("TRR %d %d %d %d\n", (int)now, src_id, dst_id, th->size());
    ewP->updateStats(PKT_ARRIVAL);
  }

  // For other packets:
  if (dropPacket(pkt)) {
    // keep packet stats
    if (ewP)
      ewP->updateStats(PKT_DROP);
    
    //printf("downgrade!\n");	
    return(policer->downgrade1);
  } else {
    // keep packet stats
    if (ewP)
      ewP->updateStats(PKT_DEPT);

    // conduct EW detection
    if (ewP)
      ewP->run(pkt);
    
    if (ewB)
      ewB->run(pkt);    

    //printf("initial!\n");	
    return(policer->initialCodePt);
  }
}
// EW Policer
//  1. do measurement: P: both arrival and departure; B: only departure
//  2. make packet drop decisions
EW Policer
1. do measurement: P: both arrival and departure; B: only departure
2. make packet drop decisions
EW Policer 1 . do measurement : P : both arrival and departure ; B : only departure 2 . make packet drop decisions
int EWPolicy::applyPolicer(policyTableEntry *, policerTableEntry *policer, Packet *pkt) {
  hdr_cmn *th = hdr_cmn::access(pkt);
  hdr_ip* iph = hdr_ip::access(pkt);
  int dst_id = iph->daddr();
  int src_id = iph->saddr();
  if (th->ptype() == PT_ACK)
    return(policer->initialCodePt);
  now = Scheduler::instance().clock();
  if (ewP) {
    printf("TRR %d %d %d %d\n", (int)now, src_id, dst_id, th->size());
    ewP->updateStats(PKT_ARRIVAL);
  }
  if (dropPacket(pkt)) {
    if (ewP)
      ewP->updateStats(PKT_DROP);
    return(policer->downgrade1);
  } else {
    if (ewP)
      ewP->updateStats(PKT_DEPT);
    if (ewP)
      ewP->run(pkt);
    if (ewB)
      ewB->run(pkt);    
    return(policer->initialCodePt);
  }
}
int EWPolicy :: applyPolicer ( policyTableEntry * , policerTableEntry * policer , Packet * pkt ) { hdr_cmn * th = hdr_cmn :: access ( pkt ) ; hdr_ip * iph = hdr_ip :: access ( pkt ) ; int dst_id = iph -> daddr ( ) ; int src_id = iph -> saddr ( ) ; if ( th -> ptype ( ) == PT_ACK ) return ( policer -> initialCodePt ) ; now = Scheduler :: instance ( ) . clock ( ) ; if ( ewP ) { printf ( " \n " , ( int ) now , src_id , dst_id , th -> size ( ) ) ; ewP -> updateStats ( PKT_ARRIVAL ) ; } if ( dropPacket ( pkt ) ) { if ( ewP ) ewP -> updateStats ( PKT_DROP ) ; return ( policer -> downgrade1 ) ; } else { if ( ewP ) ewP -> updateStats ( PKT_DEPT ) ; if ( ewP ) ewP -> run ( pkt ) ; if ( ewB ) ewB -> run ( pkt ) ; return ( policer -> initialCodePt ) ; } }
EW Policer
1. do measurement: P: both arrival and departure; B: only departure
2. make packet drop decisions
EW Policer 1 . do measurement : P : both arrival and departure ; B : only departure 2 . make packet drop decisions
//printf("enter applyPolicer "); // can't count/penalize ACKs: //   with resp: may cause inaccurate calculation with TSW(??) //   with req:  may cause resp retransmission. // just pass them through // for other packets... // Get time // keep arrival packet stats // For other packets: // keep packet stats //printf("downgrade!\n");	 // keep packet stats // conduct EW detection //printf("initial!\n");	