[Javanetsim-cvs] javaNetSim/core/protocolsuite/tcp_ip Echo_tcp.java,1.14,1.15 ProtocolStack.java,1.3
Status: Beta
Brought to you by:
darkkey
From: gift <gi...@us...> - 2005-12-04 22:14:32
|
Update of /cvsroot/javanetsim/javaNetSim/core/protocolsuite/tcp_ip In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv25978/core/protocolsuite/tcp_ip Modified Files: Echo_tcp.java ProtocolStack.java Tcp.java Log Message: TCP server timeout needs correction ;) Index: ProtocolStack.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/core/protocolsuite/tcp_ip/ProtocolStack.java,v retrieving revision 1.31 retrieving revision 1.32 diff -C2 -d -r1.31 -r1.32 *** ProtocolStack.java 4 Dec 2005 12:19:30 -0000 1.31 --- ProtocolStack.java 4 Dec 2005 22:14:21 -0000 1.32 *************** *** 73,76 **** --- 73,80 ---- import core.*; + import java.util.Timer; + + import java.util.TimerTask; + *************** *** 1672,1684 **** 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; ! }else{ mTCPprotocol.FreeApplication(application); return -1; } ! } ! /** --- 1676,1699 ---- boolean flags[]={false,false,false,false,true,false}; /* URG, ACK, PSH, RST, !SYN!, FIN */ rval=mTCPprotocol.ReservePort(application, inDestIPAddress, indestPort); + byte code=0; //no status ! if (sendTCPSegment(application, msg, flags,ack_num)) ! { ! do ! { code = mTCPprotocol.getStatus(rval); } ! while (code==1); ! ! if(code==0 || code==3) //0 - no status; 1 - is being connected; 2 - is connected; 3 - connection error ! { ! mTCPprotocol.FreeApplication(application); ! return -1; ! } else return rval; ! ! }else{ mTCPprotocol.FreeApplication(application); return -1; } ! } /** Index: Tcp.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/core/protocolsuite/tcp_ip/Tcp.java,v retrieving revision 1.24 retrieving revision 1.25 diff -C2 -d -r1.24 -r1.25 *** Tcp.java 4 Dec 2005 20:37:17 -0000 1.24 --- Tcp.java 4 Dec 2005 22:14:21 -0000 1.25 *************** *** 163,167 **** public boolean isFIN_sent; public boolean isFIN_confirmed; ! public boolean isPassive; public Timer timer=null; //our timer for this connection --- 163,171 ---- 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 Timer timer=null; //our timer for this connection *************** *** 245,248 **** --- 249,253 ---- this.isFIN_confirmed=false; this.isPassive=false; + this.ApplicationStatus=0; //no status } *************** *** 262,266 **** * Used in timer */ ! private static final long TCP_TIME = 100; //msec /** --- 267,271 ---- * Used in timer */ ! private static final long TCP_TIME = 400; //msec /** *************** *** 316,322 **** /** ! * This methos implements TCP timer ! * @author gift (sourceforge.net user) ! * @param Elm TCP_HashTableElement * @version v0.10 */ --- 321,326 ---- /** ! * This methos implements TCP timer algorithm ! * @author gift (sourceforge.net user) * @version v0.10 */ *************** *** 494,497 **** --- 498,522 ---- } + + /** + * This method finds status for an application. + * @author gift (sourceforge.net user) + * @param inSrcPort port number that has been reserved for the applicaion + * @return byte application status 0 - no status; 1 - is being connected; 2 - is connected; 3 - connection error + * @exception TransportLayerException + * @version v0.20 + * @see TransportLayerException + */ + public byte getStatus(int inSrcPort) throws TransportLayerException + { + byte status=0; + TCP_HashTableElement Elm = null; + + Elm=(TCP_HashTableElement)PortTable.get((Integer)inSrcPort); + status=Elm.ApplicationStatus; + + return status; + } + /** * This method closes the TCP port for an application *************** *** 593,596 **** --- 618,623 ---- Elm.connectedtoIP=""; Elm.connectedtoPort=0; + //0 - no status; 1 - is being connected; 2 - is connected; 3 - connection error + Elm.ApplicationStatus=1; //not used over here break; case 1: // port is being listened to by whom? *************** *** 652,656 **** return dIP; ! } --- 679,683 ---- return dIP; ! } *************** *** 803,807 **** Elm.PortStatus=2; Elm.connectedtoIP=inDestIPAddress; ! Elm.connectedtoPort=indestPort; } --- 830,835 ---- Elm.PortStatus=2; Elm.connectedtoIP=inDestIPAddress; ! Elm.connectedtoPort=indestPort; ! Elm.ApplicationStatus=1; //is being connected } *************** *** 875,879 **** case 0: //port is free => Error: no application to receive TCP //have to disconnect listener from port ! throw new TransportLayerPortException("TCP Error: no server application listening to port "+inPacket.get_destPort() +" on host \""+ mParentStack.getParentNodeName()+"\"!"); //no break needed ;) case 1: // port is being listened to by a new application. --- 903,907 ---- case 0: //port is free => Error: no application to receive TCP //have to disconnect listener from port ! throw new TransportLayerPortException("TCP Error: no application listening to port "+inPacket.get_destPort() +" on host \""+ mParentStack.getParentNodeName()+"\"!"); //no break needed ;) case 1: // port is being listened to by a new application. *************** *** 890,894 **** Elm.PortStatus=2; //port will be busy from now Elm.connectedtoIP=inPacket.getSourceIPAddress(); ! Elm.connectedtoPort=inPacket.get_srcPort(); Elm.received_segments++; Elm.ReceivedSegments.addElement(chk); //adding seq_number that we have received --- 918,925 ---- Elm.PortStatus=2; //port will be busy from now Elm.connectedtoIP=inPacket.getSourceIPAddress(); ! Elm.connectedtoPort=inPacket.get_srcPort(); ! //0 - no status; 1 - is being connected; 2 - is connected; 3 - connection error ! Elm.ApplicationStatus=2; ! Elm.received_segments++; Elm.ReceivedSegments.addElement(chk); //adding seq_number that we have received *************** *** 949,952 **** --- 980,985 ---- // everything is OK now we decompose TCP datagram + Elm.ApplicationStatus=2; + //Create Layer info LayerInfo TCP_Info = new LayerInfo(getClass().getName()); *************** *** 981,985 **** } else { //we have already received this segment ! Elm.received_duplicates++; //Create Layer info LayerInfo TCP_Info = new LayerInfo(getClass().getName()); --- 1014,1019 ---- } else { //we have already received this segment ! System.out.println("tttttttt"); ! Elm.received_duplicates++; //Create Layer info LayerInfo TCP_Info = new LayerInfo(getClass().getName()); *************** *** 1091,1095 **** } else { //we have already received this segment ! Elm.received_duplicates++; //Create Layer info LayerInfo TCP_Info = new LayerInfo(getClass().getName()); --- 1125,1130 ---- } else { //we have already received this segment ! Elm.received_duplicates++; ! System.out.println("t+++++++++t"); //Create Layer info LayerInfo TCP_Info = new LayerInfo(getClass().getName()); *************** *** 1136,1142 **** String s; if (Elm.received_segments>2) s="TCP packet with data ACK received from "+ inPacket.getSourceIPAddress() + ":" + inPacket.get_srcPort() + "."; ! else s="TCP packet with establishing connection ACK received from "+ inPacket.getSourceIPAddress() + ":" + inPacket.get_srcPort() + ". Connection confirmed!"; ! if (our_ack==1 && (Integer)inPacket.get_sequence_number()==1) s=s + " New TCP connection established!"; TCP_Info.setDescription(s); --- 1171,1185 ---- String s; if (Elm.received_segments>2) s="TCP packet with data ACK received from "+ inPacket.getSourceIPAddress() + ":" + inPacket.get_srcPort() + "."; ! else ! { ! s="TCP packet with establishing connection ACK received from "+ inPacket.getSourceIPAddress() + ":" + inPacket.get_srcPort() + ". Connection confirmed!"; ! Elm.ApplicationStatus=2; ! } ! if (our_ack==1 && (Integer)inPacket.get_sequence_number()==1) ! { ! s=s + " New TCP connection established!"; ! Elm.ApplicationStatus=2; ! } TCP_Info.setDescription(s); *************** *** 1186,1190 **** } else { //we have already received this segment ! Elm.received_duplicates++; //Create Layer info LayerInfo TCP_Info = new LayerInfo(getClass().getName()); --- 1229,1234 ---- } else { //we have already received this segment ! Elm.received_duplicates++; ! System.out.println("t------t"); //Create Layer info LayerInfo TCP_Info = new LayerInfo(getClass().getName()); Index: Echo_tcp.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/core/protocolsuite/tcp_ip/Echo_tcp.java,v retrieving revision 1.14 retrieving revision 1.15 diff -C2 -d -r1.14 -r1.15 *** Echo_tcp.java 4 Dec 2005 12:19:30 -0000 1.14 --- Echo_tcp.java 4 Dec 2005 22:14:21 -0000 1.15 *************** *** 72,79 **** */ ! public boolean ClientConnect(String Host, int port) throws TransportLayerException, InvalidNetworkLayerDeviceException, CommunicationException, LowLinkException { sdHost = Host; sdPort = port; do { --- 72,87 ---- */ ! public boolean ClientConnect(String Host, int port) throws TransportLayerException, InvalidNetworkLayerDeviceException, CommunicationException, LowLinkException ! { sdHost = Host; sdPort = port; + LayerInfo protInfo2 = new LayerInfo(getClass().getName()); + protInfo2.setObjectName(mParentStack.getParentNodeName()); + protInfo2.setDataType("Echo Protocol Data"); + protInfo2.setLayer("Application "); + protInfo2.setDescription("Connecting to host " + Host + ":"+ port +". Please wait..."); + Simulation.addLayerInfo(protInfo2); + do { |