Sim
Class PacketWatcher

java.lang.Object
  extended by Sim.PacketWatcher
All Implemented Interfaces:
PacketListener

public class PacketWatcher
extends java.lang.Object
implements PacketListener

PacketWatcher watches over any Packets to which it is assigned to listen, and maintains statistics on those packets.


Constructor Summary
PacketWatcher(double timeout)
          Constructs a new PacketWatcher.
 
Method Summary
 int getArrived()
          Returns number of successfully arrived packets.
 int getCreated()
          Returns the number of originated packets.
 java.util.ArrayList<java.lang.Double> getDistancesList()
          Returns the list of hops for each packet.
 java.util.ArrayList<java.lang.Integer> getHopsList()
          Returns the list of hops for each packet.
 int getLost()
          Returns the number of lost packets.
 int getOutstanding()
          Returns the number of packets still outstanding (created packets that have yet to be lost or arrive).
 java.util.ArrayList<java.lang.Double> getTimeList()
          Returns the list of hops for each packet.
 void packetArrived(Packet p, double time, boolean repeat)
          Event called when a Packet arrives at its destination.
 void packetOriginated(Packet p, double time)
          Event called when a Packet is given to a Node for sending.
 void reportTotalHops(Packet p, int hops, double d)
          Event called when a Packet is is passed to a new node, including the terminating node.
 void scheduleRecurringLossUpdate(Simulation sim, double rate)
          Schedules a recurring event to operate in the Simulation to call updateLost(double) every "rate" seconds, starting from the simulations current time plus "rate." The most often the event occurs, the less memory is used, but updating the statistic too often can cause a high amount of CPU overhead.
 void updateLost(double time)
          Calculates the lost packets statistic by examining the timeouts.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

PacketWatcher

public PacketWatcher(double timeout)
Constructs a new PacketWatcher.

Parameters:
timeout - if any packet takes more than this many seconds to arrive, it is considered lost.
Method Detail

scheduleRecurringLossUpdate

public void scheduleRecurringLossUpdate(Simulation sim,
                                        double rate)
Schedules a recurring event to operate in the Simulation to call updateLost(double) every "rate" seconds, starting from the simulations current time plus "rate." The most often the event occurs, the less memory is used, but updating the statistic too often can cause a high amount of CPU overhead.

Parameters:
sim - non-null Simulation
rate - event recurrence rate

getCreated

public int getCreated()
Returns the number of originated packets.


getOutstanding

public int getOutstanding()
Returns the number of packets still outstanding (created packets that have yet to be lost or arrive).


getArrived

public int getArrived()
Returns number of successfully arrived packets.


getLost

public int getLost()
Returns the number of lost packets. updateLost(double) should be called before this method to make sure that the loss statistic is up to date.


getHopsList

public java.util.ArrayList<java.lang.Integer> getHopsList()
Returns the list of hops for each packet.

Returns:

getDistancesList

public java.util.ArrayList<java.lang.Double> getDistancesList()
Returns the list of hops for each packet.

Returns:

getTimeList

public java.util.ArrayList<java.lang.Double> getTimeList()
Returns the list of hops for each packet.

Returns:

updateLost

public void updateLost(double time)
Calculates the lost packets statistic by examining the timeouts. This method can be called periodically to reduce the amount of memory used.

Parameters:
time - a time value to update that is greater than or equal to any time value passed to packetOriginated(Packet, double) or packetArrived(Packet, double, boolean).

packetOriginated

public void packetOriginated(Packet p,
                             double time)
Event called when a Packet is given to a Node for sending. This event only occurs once for any given Packet.

Specified by:
packetOriginated in interface PacketListener
Parameters:
p - non-null Packet
time - Time of origination.

packetArrived

public void packetArrived(Packet p,
                          double time,
                          boolean repeat)
Event called when a Packet arrives at its destination. This method can happen multiple times if there is packet duplication. The first time a Packet arrives, repeat is false. All subsequent events, if they occur, repeat is true.

Specified by:
packetArrived in interface PacketListener
Parameters:
p - non-null Packet that arrived
time - Time of arrival, which is after time of origination for this Packet
repeat - true if another copy of the Packet arrived, false if first time.

reportTotalHops

public void reportTotalHops(Packet p,
                            int hops,
                            double d)
Description copied from interface: PacketListener
Event called when a Packet is is passed to a new node, including the terminating node.

Specified by:
reportTotalHops in interface PacketListener
Parameters:
p - non-null Packet