[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[ns] counting packet losses in a queue



Hi,
if you want to count packet losses in a queue, e.g., DropTail,
then you have to add only one new variable in the derived
class of your queue type, e.g., My_DropTail, and in the method:

void My_DropTail::enque(Packet* p)
{
  q_->enque(p);
  if (q_->length() >= qlim_)
  {

/* new lines (count packet losses, print info about the lost packet) */

    lost_packets_counter_++; /* new variable */

    if (MY_INFO_OUTPUT == 1)
    { /+ print some infos about the lost packet */
      double now = Scheduler::instance().clock();

      hdr_cmn *ph = hdr_cmn::access(p);

      if (ph->ptype() == PT_TCP || ph->ptype() == PT_ACK)
      {
        hdr_ip *iph = hdr_ip::access(p);

        ns_addr_t src = iph->src();
        ns_addr_t dst = iph->dst();

        hdr_tcp *tcph = hdr_tcp::access(p);

        int seqno = tcph->seqno();

        cout << "DTQ #" << setw(3) << my_instance_number
             << ": packet loss in a router (C = " << setw(3)
             << src.addr_ << ":" << setw(3) << src.port_ << " -> "
             << setw(3) << dst.addr_ << ":" << setw(3) << dst.port_
             << ", S = " << setw(8) << seqno << ", L = " << setw(8)
             << lost_packets_counter_ << ") [T = ";
        cout.form("%12.6lf", now) << "]" << endl;
      }
      else
      {
        cout << "DTQ #" << setw(3) << my_instance_number
             << ": packet loss in a router (L = " << setw(8)
             << lost_packets_counter_ << ") [T = ";
        cout.form("%12.6lf", now) << "]" << endl;
      }
    }

*/ original code */

    if (drop_front_)
    { /* remove from head of queue */
      Packet *pp = q_->deque();
      drop(pp);
    }
    else
    {
      q_->remove(p);
      drop(p);
    }
  }
}

That's it. For counting delivered packets you can use another
variable in the dequeue-method. 

Best regards,
Michael Savoric
 
======================================================
E-Mail:		savoric@ee.tu-berlin.de

Phone:	 	(030)314-23840

Postal address:	Technical University Berlin
		Telecommunication Networks Group (TKN)
		Einsteinufer 25, 10587 Berlin
======================================================