[Javanetsim-cvs] javaNetSim/core/protocolsuite/tcp_ip Echo_tcp.java,1.13,1.14 ProtocolStack.java,1.3
Status: Beta
Brought to you by:
darkkey
From: gift <gi...@us...> - 2005-12-04 12:19:41
|
Update of /cvsroot/javanetsim/javaNetSim/core/protocolsuite/tcp_ip In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv5657/core/protocolsuite/tcp_ip Modified Files: Echo_tcp.java ProtocolStack.java Tcp.java Log Message: TCpppppppppppppppppppppppppppizzzzzz(d)aaaa Index: ProtocolStack.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/core/protocolsuite/tcp_ip/ProtocolStack.java,v retrieving revision 1.30 retrieving revision 1.31 diff -C2 -d -r1.30 -r1.31 *** ProtocolStack.java 3 Dec 2005 19:23:19 -0000 1.30 --- ProtocolStack.java 4 Dec 2005 12:19:30 -0000 1.31 *************** *** 1672,1675 **** --- 1672,1676 ---- boolean flags[]={false,false,false,false,true,false}; /* URG, ACK, PSH, RST, !SYN!, FIN */ rval=mTCPprotocol.ReservePort(application, inDestIPAddress, indestPort); + if (sendTCPSegment(application, msg, flags,ack_num)) { return rval; Index: Tcp.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/core/protocolsuite/tcp_ip/Tcp.java,v retrieving revision 1.20 retrieving revision 1.21 diff -C2 -d -r1.20 -r1.21 *** Tcp.java 3 Dec 2005 19:23:19 -0000 1.20 --- Tcp.java 4 Dec 2005 12:19:30 -0000 1.21 *************** *** 170,180 **** { if (timer!=null){ ! System.out.println("Timer cancel - part1!"); try{ this.timer.cancel(); }catch(Exception e){ ! System.out.println("Timer cancel error."); } ! System.out.println("Timer cancel -part 2!"); this.timer = null; } --- 170,180 ---- { if (timer!=null){ ! System.out.println("Elm.reset: Timer cancel - part 1!"); try{ this.timer.cancel(); }catch(Exception e){ ! System.out.println("Elm.reset: Timer cancel error."); } ! System.out.println("Elm.reset: Timer cancel - part 2!"); this.timer = null; } *************** *** 259,264 **** private static final int TOTAL_TIME = 10; //seconds to send all data private static final int ACCELER_KOEFF=2; //coeff depends on line quality, in practise >=2 ! private static final double TCP_TIME= 0.1; //sec ! /** * This method assigns the ParentStack --- 259,267 ---- private static final int TOTAL_TIME = 10; //seconds to send all data private static final int ACCELER_KOEFF=2; //coeff depends on line quality, in practise >=2 ! /** ! * Used in timer ! */ ! private static final long TCP_TIME = 400; //msec ! /** * This method assigns the ParentStack *************** *** 289,297 **** { ! if(Elm.timer==null){ System.out.println("Timer init!"); Elm.timer=new Timer(); ! Elm.timer.schedule(new TCPTask(Elm),0,500); } --- 292,300 ---- { ! if(Elm.timer==null){ System.out.println("Timer init!"); Elm.timer=new Timer(); ! Elm.timer.schedule(new TCPTask(Elm,TCP_TIME),TCP_TIME,TCP_TIME); } *************** *** 301,309 **** public class TCPTask extends TimerTask { private TCP_HashTableElement Elm; ! public TCPTask (TCP_HashTableElement inElm) { this.Elm=inElm; } --- 304,315 ---- public class TCPTask extends TimerTask { + private int numRepeat=8; private TCP_HashTableElement Elm; + private long repTime; ! public TCPTask (TCP_HashTableElement inElm, long time) { this.Elm=inElm; + this.repTime=time; } *************** *** 318,326 **** { // System.out.println("Timer start!"); ! if(!Elm.SegmentsToResend.isEmpty()) { // this.cancel(); // Elm.timer.cancel(); ! Enumeration HTkeys; Integer curkey; HTkeys = Elm.SegmentsToResend.keys(); --- 324,333 ---- { // System.out.println("Timer start!"); ! if(!Elm.SegmentsToResend.isEmpty() && numRepeat>0) { // this.cancel(); // Elm.timer.cancel(); ! numRepeat--; ! Enumeration HTkeys; Integer curkey; HTkeys = Elm.SegmentsToResend.keys(); *************** *** 329,332 **** --- 336,347 ---- curkey= (Integer) HTkeys.nextElement(); try{ + //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("Resending packet due to timer out: " + repTime + " msec has passed."); + Simulation.addLayerInfo(TCP_Info); + mParentStack.sendPacket((TCP_packet)Elm.SegmentsToResend.get(curkey)); } catch (Exception e) {} *************** *** 334,346 **** } else { ! System.out.println("Timer cancel - part1!"); ! try{ ! Elm.timer.cancel(); ! this.cancel(); ! Elm.timer = null; ! }catch(Exception e){ ! System.out.println("Timer cancel error."); } - System.out.println("Timer cancel - part2!"); } } --- 349,378 ---- } else { ! if (numRepeat==0) ! { ! System.out.println("TIMEtoLIVE - OUT - connection timeout!"); ! ! //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("Connection timeout! Closing connection to host: "+ Elm.connectedtoIP + ":" + Elm.connectedtoPort+"."); ! Simulation.addLayerInfo(TCP_Info); ! ! Elm.reset(); ! } ! else ! { ! System.out.println("Timer cancel - part1!"); ! try{ ! Elm.timer.cancel(); ! this.cancel(); ! Elm.timer = null; ! }catch(Exception e){ ! System.out.println("Timer cancel error."); ! } ! System.out.println("Timer cancel - part2!"); } } } *************** *** 948,954 **** } else { //we have already received this segment ! Elm.received_duplicates++; ! //now we have to resend our ACK again ! mParentStack.sendPacket((TCP_packet) Elm.SentACKs.get((Integer)inPacket.get_sequence_number())); } --- 980,993 ---- } else { //we have already received this segment ! Elm.received_duplicates++; ! //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("Resending ACK packet due to duplicate arrival. Total duplicates received: " + Elm.received_duplicates + "."); ! Simulation.addLayerInfo(TCP_Info); ! //now we have to resend our ACK again ! mParentStack.sendPacket((TCP_packet) Elm.SentACKs.get((Integer)inPacket.get_sequence_number())); } *************** *** 1050,1054 **** } else { //we have already received this segment ! Elm.received_duplicates++; //now we have to resend our ACK again mParentStack.sendPacket((TCP_packet) Elm.SentACKs.get((Integer)inPacket.get_sequence_number())); --- 1089,1100 ---- } else { //we have already received this segment ! Elm.received_duplicates++; ! //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("Resending ACK packet due to duplicate arrival. Total duplicates received: " + Elm.received_duplicates + "."); ! Simulation.addLayerInfo(TCP_Info); //now we have to resend our ACK again mParentStack.sendPacket((TCP_packet) Elm.SentACKs.get((Integer)inPacket.get_sequence_number())); *************** *** 1137,1142 **** } else { //we have already received this segment ! Elm.received_duplicates++; ! //now we have to resend our ACK again mParentStack.sendPacket((TCP_packet) Elm.SentACKs.get((Integer)inPacket.get_sequence_number())); } --- 1183,1195 ---- } else { //we have already received this segment ! Elm.received_duplicates++; ! //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("Resending ACK packet due to duplicate arrival. Total duplicates received: " + Elm.received_duplicates + "."); ! Simulation.addLayerInfo(TCP_Info); ! //now we have to resend our ACK again mParentStack.sendPacket((TCP_packet) Elm.SentACKs.get((Integer)inPacket.get_sequence_number())); } Index: Echo_tcp.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/core/protocolsuite/tcp_ip/Echo_tcp.java,v retrieving revision 1.13 retrieving revision 1.14 diff -C2 -d -r1.13 -r1.14 *** Echo_tcp.java 3 Dec 2005 19:23:19 -0000 1.13 --- Echo_tcp.java 4 Dec 2005 12:19:30 -0000 1.14 *************** *** 29,32 **** --- 29,34 ---- public class Echo_tcp extends Application{ + private byte ConnectionAttempts=5; + /** Creates a new instance of Echo */ public Echo_tcp(ProtocolStack inParentStack, int listenPort, int appType, int UID) { *************** *** 64,76 **** * This method connects to server on the other side (imaginations from the other side.... :+) * @author key * @param Host - hostname or ip of server. * @param port - server's port ! * @version v0.01 */ public boolean ClientConnect(String Host, int port) throws TransportLayerException, InvalidNetworkLayerDeviceException, CommunicationException, LowLinkException { sdHost = Host; ! sdPort = port; ! clientPort = mParentStack.ConnectTCP(this, sdHost, sdPort); if (clientPort>-1) return true; else return false; } --- 66,86 ---- * This method connects to server on the other side (imaginations from the other side.... :+) * @author key + * @author gift (sourceforge.net user) * @param Host - hostname or ip of server. * @param port - server's port ! * @version v0.03 */ public boolean ClientConnect(String Host, int port) throws TransportLayerException, InvalidNetworkLayerDeviceException, CommunicationException, LowLinkException { sdHost = Host; ! sdPort = port; ! ! do ! { ! ConnectionAttempts--; ! clientPort = mParentStack.ConnectTCP(this, sdHost, sdPort); ! } ! while (ConnectionAttempts>0 && clientPort==-1); ! if (clientPort>-1) return true; else return false; } *************** *** 120,124 **** * @param data to recv * @author key ! * @version v0.01 */ public void RecvData(String Data) throws LowLinkException, TransportLayerException { --- 130,135 ---- * @param data to recv * @author key ! * @author gift (sourceforge.net user) ! * @version v0.02 */ public void RecvData(String Data) throws LowLinkException, TransportLayerException { *************** *** 185,189 **** * @param server port * @author key ! * @version v0.01 */ public void SendEcho(String Data, String Host, int port) throws CommunicationException, LowLinkException, InvalidNetworkLayerDeviceException, TransportLayerException{ --- 196,201 ---- * @param server port * @author key ! * @author gift (sourceforge.net user) ! * @version v0.02 */ public void SendEcho(String Data, String Host, int port) throws CommunicationException, LowLinkException, InvalidNetworkLayerDeviceException, TransportLayerException{ |