[Javanetsim-cvs] javaNetSim/core/protocolsuite/tcp_ip Tcp.java,1.26,1.27 Udp.java,1.30,1.31
Status: Beta
Brought to you by:
darkkey
From: gift <gi...@us...> - 2005-12-07 13:25:01
|
Update of /cvsroot/javanetsim/javaNetSim/core/protocolsuite/tcp_ip In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv24529/core/protocolsuite/tcp_ip Modified Files: Tcp.java Udp.java Log Message: Counters implementation Index: Tcp.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/core/protocolsuite/tcp_ip/Tcp.java,v retrieving revision 1.26 retrieving revision 1.27 diff -C2 -d -r1.26 -r1.27 *** Tcp.java 5 Dec 2005 15:56:20 -0000 1.26 --- Tcp.java 7 Dec 2005 13:24:51 -0000 1.27 *************** *** 117,132 **** public class TCP_HashTableElement { ! public byte PortStatus; // 0 - free port; 1 - port is being listened to; 2 - busy. ! public Object application; //points to application that listens to this port | provided PortStatus==1 ! public String connectedtoIP; //contains IP of the other connected computer | provided PortStatus==2 ! public int connectedtoPort; //contains port number of the other connected computer | provided PortStatus==2 /*statistic block*/ ! public int received_segments; //counter inc when a segment is received ! public int sent_segments; //counter inc when a segment is sent ! public int sent_ACK; //counter inc when an ACK is sent ! public int received_duplicates;//counter inc when a duplicate of a received segment is received again ! public int sent_duplicates; //counter inc when a duplicate of a segment is resent /*end of statistic block*/ ! public int seq_number; /*database*/ --- 117,132 ---- public class TCP_HashTableElement { ! public byte PortStatus=0; // 0 - free port; 1 - port is being listened to; 2 - busy. ! public Object application=null; //points to application that listens to this port | provided PortStatus==1 ! public String connectedtoIP=""; //contains IP of the other connected computer | provided PortStatus==2 ! public int connectedtoPort=0; //contains port number of the other connected computer | provided PortStatus==2 /*statistic block*/ ! public int received_segments=0; //counter inc when a segment is received ! public int sent_segments=0; //counter inc when a segment is sent ! public int sent_ACK=0; //counter inc when an ACK is sent ! public int received_duplicates=0;//counter inc when a duplicate of a received segment is received again ! public int sent_duplicates=0; //counter inc when a duplicate of a segment is resent /*end of statistic block*/ ! public int seq_number=0; /*database*/ *************** *** 161,173 **** /*end of database*/ ! public boolean isFIN_sent; ! public boolean isFIN_confirmed; ! public boolean isPassive; /** * 0 - no status; 1 - is being connected; 2 - is connected; 3 - connection error */ ! public byte ApplicationStatus; ! public boolean isServer; public Timer timer=null; //our timer for this connection --- 161,173 ---- /*end of database*/ ! public boolean isFIN_sent=false; ! public boolean isFIN_confirmed=false; ! public boolean isPassive=false; /** * 0 - no status; 1 - is being connected; 2 - is connected; 3 - connection error */ ! public byte ApplicationStatus=0; ! public boolean isServer=false; public Timer timer=null; //our timer for this connection *************** *** 175,178 **** --- 175,201 ---- public Timer Servertimer=null; + /* + * This method adds statistics to the TCP stack + * @author gift (sourceforge.net user) + * @param TCPStack Tcp stack to add statistics + * @return Nothing. + * @version v0.20 + */ + public void addstats(Tcp TCPStack) + { + TCPStack.IncReceivedDuplicatesNumber(this.received_duplicates); + TCPStack.IncReceivedSegmentsNumber(this.received_segments); + TCPStack.IncSentACKSegmentsNumber(this.sent_ACK); + TCPStack.IncSentDuplicatesNumber(this.sent_duplicates); + TCPStack.IncSentSegmentsNumber(this.sent_segments); + } + + /* + * This method resets element by setting default valuse + * @author gift (sourceforge.net user) + * @param Unused. + * @return Nothing. + * @version v0.20 + */ public void reset() { *************** *** 198,202 **** this.Servertimer = null; } ! this.PortStatus=0; this.application=null; --- 221,225 ---- this.Servertimer = null; } ! this.PortStatus=0; this.application=null; *************** *** 273,278 **** private ProtocolStack mParentStack; private int window_size=10; ! private int total_received=0; ! private int total_sent=0; private static final int PORT_QUANT=100; private static final int PORT_START_NUMBER=3000; --- 296,310 ---- private ProtocolStack mParentStack; private int window_size=10; ! // private int total_received=0; ! // private int total_sent=0; ! ! /*statistic block*/ ! private int received_segments=0; //counter inc when a segment is received ! private int sent_segments=0; //counter inc when a segment is sent ! private int sent_ACK=0; //counter inc when an ACK is sent ! private int received_duplicates=0;//counter inc when a duplicate of a received segment is received again ! private int sent_duplicates=0; //counter inc when a duplicate of a segment is resent ! /*end of statistic block*/ ! private static final int PORT_QUANT=100; private static final int PORT_START_NUMBER=3000; *************** *** 311,321 **** */ public void TCPsetTimer(TCP_HashTableElement Elm) ! { ! ! if(Elm.timer==null){ System.out.println("Timer init!"); Elm.timer=new Timer(); ! Elm.timer.schedule(new TCPTask(Elm,TCP_TIME),50,TCP_TIME); } --- 343,351 ---- */ public void TCPsetTimer(TCP_HashTableElement Elm) ! { if(Elm.timer==null){ System.out.println("Timer init!"); Elm.timer=new Timer(); ! Elm.timer.schedule(new TCPTask(Elm,TCP_TIME,this),50,TCP_TIME); } *************** *** 328,336 **** private TCP_HashTableElement Elm; private long repTime; ! public TCPTask (TCP_HashTableElement inElm, long time) { this.Elm=inElm; this.repTime=time; } --- 358,368 ---- private TCP_HashTableElement Elm; private long repTime; + private Tcp TCPptr; ! public TCPTask (TCP_HashTableElement inElm, long time, Tcp inTCP) { this.Elm=inElm; this.repTime=time; + this.TCPptr=inTCP; } *************** *** 381,385 **** TCP_Info.setDescription("Connection timeout! Closing connection to host: "+ Elm.connectedtoIP + ":" + Elm.connectedtoPort+"."); Simulation.addLayerInfo(TCP_Info); ! Elm.reset(); } --- 413,417 ---- TCP_Info.setDescription("Connection timeout! Closing connection to host: "+ Elm.connectedtoIP + ":" + Elm.connectedtoPort+"."); Simulation.addLayerInfo(TCP_Info); ! Elm.addstats(TCPptr); Elm.reset(); } *************** *** 410,414 **** */ public void TCPsetServerTimer(TCP_HashTableElement Elm, int inlocalPort) ! { System.out.println("Server Timer IN!"); if(Elm.Servertimer==null) --- 442,446 ---- */ public void TCPsetServerTimer(TCP_HashTableElement Elm, int inlocalPort) ! { System.out.println("Server Timer IN!"); if(Elm.Servertimer==null) *************** *** 416,420 **** System.out.println("Server Timer init!"); Elm.Servertimer=new Timer(); ! Elm.Servertimer.schedule(new TCPServerTask(Elm,inlocalPort,TCP_TIME),50,TCP_TIME); } --- 448,452 ---- System.out.println("Server Timer init!"); Elm.Servertimer=new Timer(); ! Elm.Servertimer.schedule(new TCPServerTask(Elm,inlocalPort,TCP_TIME,this),50,TCP_TIME); } *************** *** 429,434 **** private long repTime; private Object application; ! public TCPServerTask (TCP_HashTableElement inElm, int inlocalPort, long time) { this.Elm=inElm; --- 461,467 ---- private long repTime; private Object application; + private Tcp TCPptr; ! public TCPServerTask (TCP_HashTableElement inElm, int inlocalPort, long time, Tcp inTCP) { this.Elm=inElm; *************** *** 436,439 **** --- 469,473 ---- this.repTime=time; this.application=inElm.application; + this.TCPptr=inTCP; } *************** *** 450,453 **** --- 484,488 ---- { System.out.println("SERVER TIMEtoLIVE - OUT - awaiting connection timeout!"); + Elm.addstats(TCPptr); Elm.reset(); try{ *************** *** 625,628 **** --- 660,664 ---- { System.out.println("!!!"); + Elm.addstats(this); Elm.reset(); } else throw new TransportLayerException("TCP Error: port "+ PortToClose +" is not being LISTENED to by the application: \"" + application.toString() + "\"."); *************** *** 646,649 **** --- 682,686 ---- Elm=(TCP_HashTableElement) PortTable.get((Integer)PortToFree); System.out.println("###"); + Elm.addstats(this); Elm.reset(); System.out.println("111"); *************** *** 909,913 **** Elm.seq_number++; //inc for next segment if (!(flags[4] && a_num==0)) Elm.sent_ACK++; //inc in case this is an ACK-segment (each segment except for 1-st SYN is ACK-segment) ! this.total_sent++; //overall stats //pushing a copy into Hashtable --- 946,950 ---- Elm.seq_number++; //inc for next segment if (!(flags[4] && a_num==0)) Elm.sent_ACK++; //inc in case this is an ACK-segment (each segment except for 1-st SYN is ACK-segment) ! //this.total_sent++; //overall stats //pushing a copy into Hashtable *************** *** 977,981 **** // test if this packet is for a local Address. if(mParentStack.isInternalIP(inPacket.getDestIPAddress())){ ! this.total_received++; //overall stats // test if destination TCP port exists on this NeworkLayerDevice --- 1014,1018 ---- // test if this packet is for a local Address. if(mParentStack.isInternalIP(inPacket.getDestIPAddress())){ ! // this.total_received++; //overall stats // test if destination TCP port exists on this NeworkLayerDevice *************** *** 1348,1352 **** default: //TCP Error: unknown port status :( ! //have to disconnect listener from port throw new TransportLayerPortException("TCP Error: unknown port status! Port "+inPacket.get_destPort() +" on host \""+ mParentStack.getParentNodeName()+"\"."); } --- 1385,1389 ---- default: //TCP Error: unknown port status :( ! //have to disconnect listener from port throw new TransportLayerPortException("TCP Error: unknown port status! Port "+inPacket.get_destPort() +" on host \""+ mParentStack.getParentNodeName()+"\"."); } *************** *** 1410,1415 **** --- 1447,1624 ---- } + /*STATISTIC PART */ + + /** + * This method increments received segments counter + * @author gift (sourceforge.net user) + * @param numb the number to add + * @return Nothing + * @version v0.20 + */ + public void IncReceivedSegmentsNumber(int numb) + { + + received_segments+=numb; + } + + + /** + * This method increments sent segments counter + * @author gift (sourceforge.net user) + * @param numb the number to add + * @return Nothing + * @version v0.20 + */ + public void IncSentSegmentsNumber(int numb) + { + sent_segments+=numb; + } + + /** + * This method returns the number of received segments + * @author gift (sourceforge.net user) + * @param Unused. + * @return int the number of received segments + * @version v0.20 + */ + public int GetReceivedSegmentsNumber() + { + return received_segments; + } + + /** + * This method returns the number of sent segments + * @author gift (sourceforge.net user) + * @param Unused. + * @return int the number of sent segments + * @version v0.20 + */ + public int GetSentSegmentsNumber() + { + return sent_segments; + } + + + /** + * This method increments sent ACK segments counter + * @author gift (sourceforge.net user) + * @param numb the number to add + * @return Nothing + * @version v0.20 + */ + public void IncSentACKSegmentsNumber(int numb) + { + sent_ACK+=numb; + } + + + /** + * This method returns the number of sent ACK segments + * @author gift (sourceforge.net user) + * @param Unused. + * @return int the number of sent ACK segments + * @version v0.20 + */ + public int GetSentACKSegmentsNumber() + { + return sent_ACK; + } + + /** + * This method increments received duplicates counter + * @author gift (sourceforge.net user) + * @param numb the number to add + * @return Nothing + * @version v0.20 + */ + public void IncReceivedDuplicatesNumber(int numb) + { + received_duplicates+=numb; + } + + + /** + * This method returns the number of received duplicates + * @author gift (sourceforge.net user) + * @param Unused. + * @return int the number of received duplicates + * @version v0.20 + */ + public int GetReceivedDuplicatesNumber() + { + return received_duplicates; + } + + + /** + * This method increments sent duplicates counter + * @author gift (sourceforge.net user) + * @param numb the number to add + * @return Nothing + * @version v0.20 + */ + public void IncSentDuplicatesNumber(int numb) + { + sent_duplicates+=numb; + } + + + /** + * This method returns the number of sent duplicates + * @author gift (sourceforge.net user) + * @param Unused. + * @return int the number of sent duplicates + * @version v0.20 + */ + public int GetSentDuplicatesNumber() + { + return sent_duplicates; + } + + + /** + * This method resets TCP "receipt" counters + * @author gift (sourceforge.net user) + * @param Unused. + * @return Nothing. + * @version v0.20 + */ + public void ResetReceiptCounters() + { + received_duplicates=0; + received_segments=0; + } + + + /** + * This method resets TCP "" counters + * @author gift (sourceforge.net user) + * @param Unused. + * @return Nothing. + * @version v0.20 + */ + public void ResetSendingCounters() + { + sent_duplicates=0; + sent_ACK=0; + sent_segments=0; + } + + /** + * This method resets TCP counters + * @author gift (sourceforge.net user) + * @param Unused. + * @return Nothing. + * @version v0.20 + */ + public void ResetCounters() + { + ResetSendingCounters(); + ResetReceiptCounters(); + } + + } //EOF Index: Udp.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/core/protocolsuite/tcp_ip/Udp.java,v retrieving revision 1.30 retrieving revision 1.31 diff -C2 -d -r1.30 -r1.31 *** Udp.java 26 Nov 2005 18:20:57 -0000 1.30 --- Udp.java 7 Dec 2005 13:24:51 -0000 1.31 *************** *** 127,138 **** public class UDP_HashTableElement { ! public byte PortStatus; // 0 - free port; 1 - port is being listened to; 2 - busy. ! public Object application; //points to application that listens to this port | provided PortStatus==1 ! public String connectedtoIP; //contains IP of the other connected computer | provided PortStatus==2 ! public int connectedtoPort; //contains port number of the other connected computer | provided PortStatus==2 } private Hashtable PortTable = new Hashtable(); ! private ProtocolStack mParentStack; private static final int PORT_QUANT=100; private static final int PORT_START_NUMBER=3000; --- 127,144 ---- public class UDP_HashTableElement { ! public byte PortStatus=0; // 0 - free port; 1 - port is being listened to; 2 - busy. ! public Object application=null; //points to application that listens to this port | provided PortStatus==1 ! public String connectedtoIP=""; //contains IP of the other connected computer | provided PortStatus==2 ! public int connectedtoPort=0; //contains port number of the other connected computer | provided PortStatus==2 } private Hashtable PortTable = new Hashtable(); ! private ProtocolStack mParentStack; ! ! /*statistic block*/ ! private int received_datagramms=0; //counter inc when a datagramm is received ! private int sent_datagramm=0; //counter inc when a datagramm is sent ! /*end of statistic block*/ ! private static final int PORT_QUANT=100; private static final int PORT_START_NUMBER=3000; *************** *** 208,213 **** Elm.connectedtoIP=inPacket.getSourceIPAddress(); Elm.connectedtoPort=inPacket.get_srcPort(); //Create Layer info - LayerInfo UDP_Info = new LayerInfo(getClass().getName()); --- 214,221 ---- Elm.connectedtoIP=inPacket.getSourceIPAddress(); Elm.connectedtoPort=inPacket.get_srcPort(); + + IncReceivedDatagrammsNumber(); + //Create Layer info LayerInfo UDP_Info = new LayerInfo(getClass().getName()); *************** *** 297,301 **** UDP_Info.setDescription("Created UDP packet for " + inDestIPAddress + ":" + indestPort +"."); Simulation.addLayerInfo(UDP_Info); ! return tosend; --- 305,310 ---- UDP_Info.setDescription("Created UDP packet for " + inDestIPAddress + ":" + indestPort +"."); Simulation.addLayerInfo(UDP_Info); ! ! IncSentDatagrammsNumber(); return tosend; *************** *** 673,677 **** --- 682,750 ---- return (number); //do not change here! if you want to change here scan again the code } + + /*STATISTIC PART */ + + /** + * This method increments received datagramms counter + * @author gift (sourceforge.net user) + * @param Unused + * @return Nothing + * @version v0.20 + */ + + public void IncReceivedDatagrammsNumber() + { + received_datagramms++; + } + + + /** + * This method increments sent datagramms counter + * @author gift (sourceforge.net user) + * @param Unused + * @return Nothing + * @version v0.20 + */ + public void IncSentDatagrammsNumber() + { + sent_datagramm++; + } + + /** + * This method returns the number of received datagramms + * @author gift (sourceforge.net user) + * @param Unused. + * @return int the number of received datagramms + * @version v0.20 + */ + public int GetReceivedDatagrammsNumber() + { + return received_datagramms; + } + + /** + * This method returns the number of sent datagramms + * @author gift (sourceforge.net user) + * @param Unused. + * @return int the number of sent datagramms + * @version v0.20 + */ + public int GetSentDatagrammsNumber() + { + return sent_datagramm; + } + /** + * This method resets UDP counters + * @author gift (sourceforge.net user) + * @param Unused. + * @return Nothing. + * @version v0.20 + */ + public void ResetCounters() + { + sent_datagramm=0; + received_datagramms=0; + } } //EOF |