package Simulator; import java.io.*; /** * Models Message object in the simulator. */ public class Message implements TimeCompare { // Fields int MessNum; // Message number protected double nextArrivalTime; protected long msgSize; // Message Size String MessageType; int RouterTableNum; // which router table the message follow public int NextObjectIndex; // what is the next road node index in a router table // The following fields are only used for the probing message (including Cprobing) // they are useless for the traffic message double Pstarting_time; // the sending time of each probing message double QueuingTime []; // the message queuing time // The following field are used only for Cprobing message long SizeOfSented=0; // false is RoundtripTime, true is UnitripTime // no influrence on Cprobing and AdaptiveCprobing boolean MessMeasurementType; // Constructor for traffic message public Message(int number, int RouterTableNum, String Type, long msgSize, double time) { this.RouterTableNum = RouterTableNum; this.MessNum = number; this.nextArrivalTime = time; this.NextObjectIndex = 0; this.MessageType = Type; this.msgSize = msgSize; } // Constructor for probing message public Message(int number, int RouterTableNum, int NodeNum, double PST, String Type, long msgSize, double time, int NextObjectIndex, boolean MessMeasurementType) { this.RouterTableNum = RouterTableNum; this.MessNum = number; this.nextArrivalTime = time; //this.NextObjectIndex = 0; this.MessageType = Type; this.msgSize = msgSize; this.QueuingTime = new double[NodeNum*2-1]; this.Pstarting_time = PST; this.NextObjectIndex = NextObjectIndex; this.MessMeasurementType = MessMeasurementType; } // Commands public void setTime (double Time) { nextArrivalTime = Time; } public boolean setNextNode (int RoadNodeNum) { boolean responseMess_GetToDestination = false; if ((MessageType.compareTo("ICMP-response") == 0) || (MessageType.compareTo("RoundTripTime-ProbingResponse") == 0) || (MessageType.compareTo("CP-response")== 0) || (MessageType.compareTo("HTTP-response")== 0)) { if (NextObjectIndex == 0) // the response message gets to its source, erase this message responseMess_GetToDestination = true; else NextObjectIndex --; } else // -request message { if (NextObjectIndex == RoadNodeNum - 1) { // the request message gets to its destination, // change its type to corresponding response type. if (MessageType.equals("RoundTripTime-ProbingRequest")) { if (MessMeasurementType) responseMess_GetToDestination = true; // Unitrip time probing else MessageType = "RoundTripTime-ProbingResponse"; } if (MessageType.compareTo("ICMP-request")==0) { if (MessMeasurementType) responseMess_GetToDestination = true; // Unitrip time probing else MessageType = "ICMP-response"; } if (MessageType.compareTo("CP-request")==0) MessageType = "CP-response"; if (MessageType.compareTo("HTTP-request")== 0) { // no response message needed in flat/slope traffic pattern // the response message needed in web traffic pattern // this var means the request mess arriaved at the destination router responseMess_GetToDestination = true; } else NextObjectIndex --; } else NextObjectIndex ++; } return responseMess_GetToDestination; } // Queries public double getArrivalTime() { return nextArrivalTime; } public long getSize() { return msgSize; } public boolean isLessThan (TimeCompare other) { return this.nextArrivalTime < ((Message) other).getArrivalTime(); } public boolean isEqualTo (TimeCompare other) { return this.nextArrivalTime == ((Message) other).getArrivalTime(); } public boolean isGreaterThan (TimeCompare other) { return this.nextArrivalTime > ((Message) other).getArrivalTime(); } public boolean equalOrGreaterThan (TimeCompare other) { return this.nextArrivalTime >= ((Message) other).getArrivalTime(); } public boolean equalOrLessThan (TimeCompare other) { return this.nextArrivalTime <= ((Message) other).getArrivalTime(); } }