/***** Network and service differentiation extensions to cloudsim 3.0 ***** Gokul poduval & Chen-Khong Tham * computer communication networks (CCN) lab * Dept of Electrical & Computer Engineering * National University of Singapore * August 2004 ** licence: GPL-http://www.gnu.org/copyleft/gpl.html * copyright (c) 2004, the University of Melbourne, australia and National * University of Singapor E * infopacket. java-implementation of a information packet. **/package Org. cloudid. cloudsim; import Java. text. decimalformat; import Java. util. vector; import Org. cloudid. cloudsim. core. cloudsim; import Org. cloudid. cloudsim. core. cloudsimtags;/*** traverses the network to collect information, similar to ping * infopacket class can be used to gather information from the network layer. * An infopacket traverses the network topology similar to * {@ Link gridsim.net. netpacket}, * But it collects information like bandwidths, and round trip time etc. it is * the equivalent of ICMP in physical networks. * <p> * You can set all the parameters to an infopacket that can be applied to a * netpacket. so if you want to find out the kind of information that a * particle type of netpacket is experiencing, set the size and Network * CLASS OF AN IN Fopacket to the same as the netpacket, and send it to the same * destination from the same source. ** @ author Gokul poduval * @ author Chen-Khong Tham, National University of Singapore * @ since cloudsim toolkit 1.0 */public class infopacket implements packet {/** the name. */private final string name; // packet name/** the size. */private long size; // size of this packet/** the packet ID. */ Private Final int packetid; // ID of this packet/** the src id. */private final int srcid; // original sender ID/** the Dest ID. */private int destid; // destination ID/** the last. */private int last; // last hop/** the tag. */private int tag; // whether going or returning/** the hops number. */private int hopsnumber; // Number of hops/** the ping size. */private long pingsize; // or Iginal Ping size/** the net service type. */private int netservicetype; // level of service type/** the bandwidth. */private double bandwidth; // bottleneck/** the entities. */private vector <integer> entities; // list of entity IDS/** the entry times. */private vector <double> entrytimes; // list of entry times/** the exit times. */private vector <double> exittimes; // list of exit times/ ** The baud rates. */private vector <double> baudrates; // list of entity's baud rate/** the num. */private decimalformat num; // formatting the decimal points/*** constructs a new information packet. ** @ Param name of this packet * @ Param packetid the ID of this packet * @ Param size of the packet * @ Param srcid the ID of the entity that sends out this packet * @ Param destid the ID Of the entity to which this packet is destined * @ Param netservicetype the class of traffic this packet belongs to ** @ pre name! = NULL * @ post $ none */Public infopacket (string name, int packetid, long size, int srcid, int destid, int netservicetype) {This. name = Name; this. packetid = packetid; this. srcid = srcid; this. destid = destid; this. size = size; this. netservicetype = netservicetype; Init ();}/*** initialises common attributes. ** @ pre $ none * @ post $ none */private void Init () {This. last = srcid; this. tag = clo Udsimtags. infopkt_submit; this. bandwidth =-1; this. hopsnumber = 0; this. pingsize = This. size; If (name! = NULL) {This. entities = new vector <integer> (); this. entrytimes = new vector <double> (); this. exittimes = new vector <double> (); this. baudrates = new vector <double> (); num = new decimalformat ("#0.000 #"); // 4 decimal spaces}/*** returns the ID of this packet. ** @ return packet ID ** @ pre $ none * @ post $ none */@ override public int GETID () {return packetid;}/*** sets original size of Ping Request. ** @ Param size ping data size (in bytes) ** @ pre size> = 0 * @ post $ none */Public void setoriginalpingsize (Long SIZE) {This. pingsize = size;}/*** gets original size of Ping request. ** @ return original size ** @ pre $ none * @ post $ none */public long getoriginalpingsize () {return pingsize ;} /*** convert to the string form * returns a human-readable information of this packet. ** @ return descrip Tion of this packet ** @ pre $ none * @ post $ none */@ override Public String tostring () {If (name = NULL) {return "Empty infopacket that contains no ping information. ";} int size = 1000; // Number of chars stringbuffer sb = new stringbuffer (size); sb. append ("Ping information for" + name + "\ n"); sb. append ("entity name \ tentry time \ texit time \ t bandwidth \ n"); sb. append ("------------------------- ------------------------------- \ N "); string tab =" "; // 4 spaces for (INT I = 0; I <entities. size (); I ++) {int resid = entities. get (I ). intvalue (); sb. append (cloudsim. getentityname (resid) + "\ t"); string entry = getdata (entrytimes, I); string exit = getdata (exittimes, I); string BW = getdata (baudrates, i); sb. append (Entry + TAB + exit + TAB + BW + "\ n");} sb. append ("\ nround tr IP time: "+ num. format (this. gettotalresponsetime (); sb. append ("seconds"); sb. append ("\ nNumber of hops:" + this. getnumhop (); sb. append ("\ nbottleneck bandwidth:" + bandwidth + "bits/s"); return sb. tostring ();}/*** get the relevant data * gets relevant data from a list. ** @ Param v a list * @ Param index the location in a list ** @ return the data ** @ pre v! = NULL * @ post index> 0 */private string getdata (vector <double> V, int index) {string result; try {double OBJ = v. get (INDEX); double id = obj. doublevalue (); Result = num. format (ID);} catch (exception e) {result = "N/A";} return result;}/*** gets the size of this packet. ** @ return size of the packet. ** @ pre $ none * @ post $ none */@ override public long getsize () {return size;}/*** sets the size of this packet. ** @ Param size of the packet ** @ return <tt> true </tt> if it is successful, <tt> false </tt> otherwise ** @ pre size> = 0 * @ post $ none */@ override public Boolean setsize (Long SIZE) {If (size <0) {return false;} This. size = size; return true;}/*** gets the ID of the entity to which the packet is destined. ** @ return the desination ID ** @ pre $ none * @ post $ none */@ override public int getdestid () {return destid ;} /*** gets the ID of the entity that sent out this packet. ** @ return the source ID ** @ pre $ none * @ post $ none */@ override public int getsrcid () {return srcid ;} /*** get the hop points ** returns the number of hops that this packet has traversed. since the * packet takes a round trip, the same router may have been traversed * twice. ** @ return the number of hops this packet has traversed ** @ pre $ none * @ post $ none */Public int getnumhop () {int pair = 2; return (hopsnumber-Pair) + 1)/pair; // target once, SRC twice does not count}/*** packet's time in the Network * gets the total time that this packet has spent in the network. this is * basically the RTT. dividing this by half shoshould be the approximate * latency. * <p> * RTT is taken as the final entry time-first exit time. ** @ return total round time ** @ pre $ none * @ post $ none */Public double gettotalresponsetime () {If (exittimes = NULL | entrytimes = NULL) {return 0;} double time = 0; try {double starttime = exittimes. firstelement (). doublevalue (); double receivetime = entrytimes. lastelement (). doublevalue (); time = receivetime-starttime;} catch (exception e) {time = 0;} return time ;} /*** returns the bottleneck bandwidth between the source and the destination. ** @ return the Bottleneck Bandwidth ** @ pre $ none * @ post $ none */Public double getbaudrate () {return bandwidth ;} /*** this method shocould be called by network entities that count as hops, for * e.g. routers or cloudresources. it shoshould not be called by links etc. ** @ Param ID the ID of the hop that this infopacket is traversing ** @ pre ID> 0 * @ post $ none */Public void addhop (int id) {If (entities = NULL) {return;} hopsnumber ++; entities. add (integer. valueof (ID);}/*** enter time ** this method shocould be called by routers and other entities * when this infopacket reaches them along with the current simulation time. ** @ Param time current simulation time, use * {@ link gridsim. cloudsim # clock ()} to obtain this *** @ pre time> = 0 * @ post $ none */Public void addentrytime (double time) {If (entrytimes = NULL) {return;} If (time <0) {time = 0.0;} entrytimes. add (double. valueof (time);}/*** departure time ** this method shocould be called by routers and other entities * when this infopacket is leaving them. it shoshould also supply the current * simulation time. ** @ Param time current simulation time, use * {@ link gridsim. cloudsim # clock ()} to obtain this *** @ pre time> = 0 * @ post $ none */Public void addexittime (double time) {If (exittimes = NULL) {return;} If (time <0) {time = 0.0;} exittimes. add (double. valueof (time);}/*** Add the baud rate * every entity that the infopacket traverses shocould Add the baud rate of * the link on which this packet will be sent out next. ** @ Param baudrate the entity's baud rate in bits/s ** @ pre baudrate> 0 * @ post $ none */Public void addbaudrate (double baudrate) {If (baudrates = NULL) {return;} baudrates. add (New Double (baudrate); If (bandwidth <0 | baudrate <this. bandwidth) {This. bandwidth = baudrate; }}/ *** returns the list of all the bandwidths that this packet has traversed. ** @ return a double array of links bandwidths ** @ pre $ none * @ post $ none */public object [] getdetailbaudrate () {If (baudrates = NULL) {return NULL;} return baudrates. toarray ();}/*** returns the list of all the hops that this packet has traversed. ** @ return an integer array of hop IDs ** @ pre $ none * @ post $ none */public object [] getdetailhops () {If (entities = NULL) {return NULL;} return entities. toarray ();}/*** returns the list of all entry time that this packet has traversed. ** @ return an integer array of entry time ** @ pre $ none * @ post $ none */public object [] getdetailentrytimes () {If (entrytimes = NULL) {return NULL;} return entrytimes. toarray ();}/*** returns the list of all exit time that this packet has traversed. ** @ return an integer array of exit time ** @ pre $ none * @ post $ none */public object [] getdetailexittimes () {If (exittimes = NULL) {return NULL;} return exittimes. toarray ();}/*** gets an entity ID from the last hop that this packet has traversed. ** @ return an entity ID ** @ pre $ none * @ post $ none */@ override public int getlast () {return last ;} /*** sets an entity ID from the last hop that this packet has traversed. ** @ Param last an entity ID from the last hop ** @ pre last> 0 * @ post $ none */@ override public void setlast (INT last) {This. last = last;}/*** gets the network service type of this packet. ** @ return the network service type ** @ pre $ none * @ post $ none */@ override public int getnetservicetype () {return netservicetype ;} /*** sets the network service type of this packet. ** @ Param netservicetype the packet's network service type ** @ pre netservicetype> = 0 * @ post $ none */@ override public void setnetservicetype (INT netservicetype) {This. netservicetype = netservicetype;}/*** gets this packet tag. ** @ return this packet tag ** @ pre $ none * @ post $ none */@ override public int gettag () {return tag ;} /*** sets the tag of this packet. ** @ Param tag the packet's tag ** @ return <tt> true </tt> If successful, <tt> false </tt> otherwise ** @ PRE Tag> 0 * @ post $ none */Public Boolean settag (INT tag) {Boolean flag = false; Switch (TAG) {Case cloudsimtags. infopkt_submit: Case cloudsimtags. infopkt_return: This. tag = tag; flag = true; break; default: Flag = false; break;} return flag;}/*** sets the destination ID for this packet. ** @ Param ID this packet's destination ID ** @ pre ID> 0 * @ post $ none */Public void setdestid (int id) {This. destid = ID ;}}