Thread: [Javanetsim-cvs] javaNetSim/core/protocolsuite/tcp_ip Tcp.java,1.25,1.26
Status: Beta
Brought to you by:
darkkey
From: gift <gi...@us...> - 2005-12-05 15:56:28
|
Update of /cvsroot/javanetsim/javaNetSim/core/protocolsuite/tcp_ip In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv5317/core/protocolsuite/tcp_ip Modified Files: Tcp.java Log Message: Please love and grant... TCP v0.9 !!! Index: Tcp.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/core/protocolsuite/tcp_ip/Tcp.java,v retrieving revision 1.25 retrieving revision 1.26 diff -C2 -d -r1.25 -r1.26 *** Tcp.java 4 Dec 2005 22:14:21 -0000 1.25 --- Tcp.java 5 Dec 2005 15:56:20 -0000 1.26 *************** *** 95,99 **** * @author gift (sourceforge.net user) * @since 25 Nov 2005 ! * @version v0.10 */ --- 95,99 ---- * @author gift (sourceforge.net user) * @since 25 Nov 2005 ! * @version v0.9 released 05 Dec 2005 */ *************** *** 163,167 **** public boolean isFIN_sent; public boolean isFIN_confirmed; ! public boolean isPassive; /** * 0 - no status; 1 - is being connected; 2 - is connected; 3 - connection error --- 163,167 ---- public boolean isFIN_sent; public boolean isFIN_confirmed; ! public boolean isPassive; /** * 0 - no status; 1 - is being connected; 2 - is connected; 3 - connection error *************** *** 169,174 **** --- 169,178 ---- public byte ApplicationStatus; + public boolean isServer; + public Timer timer=null; //our timer for this connection + public Timer Servertimer=null; + public void reset() { *************** *** 184,187 **** --- 188,202 ---- } + if (Servertimer!=null){ + System.out.println("Elm.reset: Servertimer cancel - part 1!"); + try{ + this.Servertimer.cancel(); + }catch(Exception e){ + System.out.println("Elm.reset: Servertimer cancel error."); + } + System.out.println("Elm.reset: Servertimer cancel - part 2!"); + this.Servertimer = null; + } + this.PortStatus=0; this.application=null; *************** *** 250,253 **** --- 265,269 ---- this.isPassive=false; this.ApplicationStatus=0; //no status + this.isServer=false; } *************** *** 383,386 **** --- 399,473 ---- } } + + + + /** + * This method defines TCP Server timer + * @author gift (sourceforge.net user) + * @param Elm TCP_HashTableElement + * @param inlocalPort int local port number + * @version v0.10 + */ + public void TCPsetServerTimer(TCP_HashTableElement Elm, int inlocalPort) + { + System.out.println("Server Timer IN!"); + if(Elm.Servertimer==null) + { + System.out.println("Server Timer init!"); + Elm.Servertimer=new Timer(); + Elm.Servertimer.schedule(new TCPServerTask(Elm,inlocalPort,TCP_TIME),50,TCP_TIME); + } + + } + + + public class TCPServerTask extends TimerTask + { + private int numRepeat=8; + private int localPort; + private TCP_HashTableElement Elm; + private long repTime; + private Object application; + + public TCPServerTask (TCP_HashTableElement inElm, int inlocalPort, long time) + { + this.Elm=inElm; + this.localPort=inlocalPort; + this.repTime=time; + this.application=inElm.application; + } + + + /** + * This methos implements TCP server timer algorithm + * @author gift (sourceforge.net user) + * @version v0.10 + */ + public void run() + { + numRepeat--; + if (numRepeat==0) + { + System.out.println("SERVER TIMEtoLIVE - OUT - awaiting connection timeout!"); + Elm.reset(); + try{ + ListenPort(application,localPort); + } catch (Exception e) + { + + } + + //Create Layer info + LayerInfo TCP_Info = new LayerInfo(getClass().getName()); + TCP_Info.setObjectName(mParentStack.getParentNodeName()); + TCP_Info.setDataType("TCP Protocol"); + TCP_Info.setLayer("Transport"); + TCP_Info.setDescription("Server awaiting connection timeout! Now server is listening to port: " + localPort + "."); + Simulation.addLayerInfo(TCP_Info); + + System.out.println("SERVER reorganized!"); + } + } + } /** *************** *** 620,623 **** --- 707,711 ---- //0 - no status; 1 - is being connected; 2 - is connected; 3 - connection error Elm.ApplicationStatus=1; //not used over here + Elm.isServer=true; break; case 1: // port is being listened to by whom? *************** *** 641,653 **** { //create such a record in hashtable ! TCP_HashTableElement newElm = new TCP_HashTableElement(); ! newElm.PortStatus=1; ! newElm.application=application; ! newElm.connectedtoIP=""; ! newElm.connectedtoPort=0; ! ! PortTable.put(new Integer (inPort),newElm); //hash table update } ! } else // { throw new TransportLayerException("error: can not listen to port "+ inPort +"! Use port range from 0 to 10000 to listen to."); --- 729,741 ---- { //create such a record in hashtable ! TCP_HashTableElement newElm = new TCP_HashTableElement(); ! newElm.PortStatus=1; ! newElm.application=application; ! newElm.connectedtoIP=""; ! newElm.connectedtoPort=0; ! newElm.isServer=true; ! PortTable.put(new Integer (inPort),newElm); //hash table update } ! } else { throw new TransportLayerException("error: can not listen to port "+ inPort +"! Use port range from 0 to 10000 to listen to."); *************** *** 966,970 **** if (inPacket.get_SYN_flag()) { ! //we have received an answer for our SYN-segment //a little test if (!(inPacket.get_ACK_flag())) throw new TransportLayerPortException("TCP Error: No ACK flag in answer for SYN packet is set in the segment!"); --- 1054,1065 ---- if (inPacket.get_SYN_flag()) { ! ! if (Elm.isServer) ! { ! //init ServerTask ! TCPsetServerTimer(Elm,inPacket.get_destPort()); ! } ! ! //we have received an answer for our SYN-segment //a little test if (!(inPacket.get_ACK_flag())) throw new TransportLayerPortException("TCP Error: No ACK flag in answer for SYN packet is set in the segment!"); |