[Javanetsim-cvs] javaNetSim/core/protocolsuite/tcp_ip Echo_tcp.java,1.5,1.6 ProtocolStack.java,1.18,
Status: Beta
Brought to you by:
darkkey
From: gift <gi...@us...> - 2005-11-27 18:17:47
|
Update of /cvsroot/javanetsim/javaNetSim/core/protocolsuite/tcp_ip In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv21159/core/protocolsuite/tcp_ip Modified Files: Echo_tcp.java ProtocolStack.java Tcp.java Log Message: UUUUUUUUUUUUUU TCP's working. TCP v1.0 :) Index: ProtocolStack.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/core/protocolsuite/tcp_ip/ProtocolStack.java,v retrieving revision 1.18 retrieving revision 1.19 diff -C2 -d -r1.18 -r1.19 *** ProtocolStack.java 26 Nov 2005 18:20:57 -0000 1.18 --- ProtocolStack.java 27 Nov 2005 18:17:34 -0000 1.19 *************** *** 1522,1554 **** Simulation.addLayerInfo(TCP_Info); } ! } ! ! ! /** ! * This method sets the TCP port free ! * @author gift (sourceforge.net user) ! * @param application application that uses port ! * @return Nothing ! * @exception TransportLayerException ! * @version v0.10 ! * @see TransportLayerException ! */ ! public void freeTCPPort(Object application) throws TransportLayerException ! { ! try { ! mTCPprotocol.FreePort(application); ! } catch (TransportLayerException te) ! { ! LayerInfo TCP_Info = new LayerInfo(getClass().getName()); ! TCP_Info.setObjectName(getParentNodeName()); ! TCP_Info.setDataType("TCP Protocol"); ! TCP_Info.setLayer("Transport"); ! TCP_Info.setDescription("TCP port freeing: \""+ te.toString() + "\"."); ! Simulation.addLayerInfo(TCP_Info); ! } ! } /** ! * This method sets the TCP port totally free * @author gift (sourceforge.net user) * @param application application that uses port --- 1522,1529 ---- Simulation.addLayerInfo(TCP_Info); } ! } /** ! * This method sets the TCP port totally free (undepending on it's status) * @author gift (sourceforge.net user) * @param application application that uses port *************** *** 1723,1727 **** Simulation.addLayerInfo(TCP_Info); ! mTCPprotocol.FreePort(application); } catch (TransportLayerException te) { --- 1698,1702 ---- Simulation.addLayerInfo(TCP_Info); ! mTCPprotocol.ClosePort(application); } catch (TransportLayerException te) { Index: Tcp.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/core/protocolsuite/tcp_ip/Tcp.java,v retrieving revision 1.12 retrieving revision 1.13 diff -C2 -d -r1.12 -r1.13 *** Tcp.java 27 Nov 2005 09:34:22 -0000 1.12 --- Tcp.java 27 Nov 2005 18:17:34 -0000 1.13 *************** *** 134,137 **** --- 134,141 ---- /*end of database*/ + public boolean isFIN_sent; + public boolean isFIN_confirmed; + public boolean isPassive; + public void reset() { *************** *** 157,160 **** --- 161,167 ---- } } + this.isFIN_sent=false; + this.isFIN_confirmed=false; + this.isPassive=false; } } *************** *** 325,351 **** Elm.reset(); } else throw new TransportLayerException("TCP Error: port "+ PortToClose +" is not being LISTENED to by the application: \"" + application.toString() + "\"."); ! } ! ! /** ! * This method sets the TCP port free ! * @author gift (sourceforge.net user) ! * @param application application that uses port ! * @return Nothing ! * @exception TransportLayerException ! * @version v0.10 ! * @see TransportLayerException ! */ ! public void FreePort(Object application) throws TransportLayerException //changes port status from 2 (busy) to 0 (free) ! { ! TCP_HashTableElement Elm=null; ! Integer PortToFree=getApplicationLocalPortNumber(application); ! ! Elm=(TCP_HashTableElement) PortTable.get((Integer)PortToFree); ! ! if (Elm.PortStatus==2) ! { ! Elm.reset(); ! } else throw new TransportLayerException("TCP Error: port "+ PortToFree +" is not BUSY by the application: \"" + application.toString() + "\"."); ! } /** --- 332,336 ---- Elm.reset(); } else throw new TransportLayerException("TCP Error: port "+ PortToClose +" is not being LISTENED to by the application: \"" + application.toString() + "\"."); ! } /** *************** *** 608,612 **** tosend_clone.set_SYN_flag(flags[4]); tosend_clone.set_FIN_flag(flags[5]); ! //here we push out segment in Hashtable SegmentsToResend and increment counters s_num=Elm.seq_number; //getting sequence number 0-for SYN --- 593,597 ---- tosend_clone.set_SYN_flag(flags[4]); tosend_clone.set_FIN_flag(flags[5]); ! //here we push out segment in Hashtable SegmentsToResend and increment counters s_num=Elm.seq_number; //getting sequence number 0-for SYN *************** *** 635,641 **** } ! Elm=null; ! /* URG, ACK, PSH, RST, SYN, FIN */ //Create Layer info LayerInfo TCP_Info = new LayerInfo(getClass().getName()); --- 620,627 ---- } ! if (flags[5]) Elm.isFIN_sent=true; ! Elm=null; ! /* URG, ACK, PSH, RST, SYN, FIN */ //Create Layer info LayerInfo TCP_Info = new LayerInfo(getClass().getName()); *************** *** 830,852 **** TCP_Info.setLayer("Transport"); ! TCP_Info.setDescription("TCP FIN-packet with ACK received from "+ inPacket.getSourceIPAddress() + ":" + inPacket.get_srcPort() + "."); Simulation.addLayerInfo(TCP_Info); ! //deleting from SegmentsToResend the segmet with the acknowledgment number we have received NOTE: dec by 1 is used see RFC Elm.SegmentsToResend.remove((Integer)our_ack-1); //now we have to send ACK-segment (with SYN=false, seq_num=XX, ack_num=XX) ! //we have one received segment so everything we have to do is just to call "mParentStack.sendTCPSegment(listener,msg,flags);" ! String msg=""; ! boolean flags[]={false,true,false,false,false,false}; /* URG, !ACK!, PSH, RST, SYN, FIN */ ! Application listener; ! listener = (Application)Elm.application; ! listener.RecvData(inPacket.getTCP_message()); ! //if (!Elm.SegmentsToResend.isEmpty()) ! // mParentStack.sendTCPSegment(listener,msg,flags); //we have sent last ACK and we can close TCP port now ! ! ! /*NOTE!!!! MAYBE USEFUL TO COMMENT THIS LINE DUE TO THE STATISTIC*/ // FreePort(listener); } else { //we have already received this segment --- 816,871 ---- TCP_Info.setLayer("Transport"); ! String s; ! if (!Elm.isFIN_sent) ! s="TCP FIN-packet received from "+ inPacket.getSourceIPAddress() + ":" + inPacket.get_srcPort() + ". Now safe closing connection!"; ! else ! { ! if (!Elm.isFIN_confirmed) ! s="TCP FIN-packet ACK received from "+ inPacket.getSourceIPAddress() + ":" + inPacket.get_srcPort() + ". Now sending our FIN confirmation!"; ! else s="TCP FIN-packet ACK confirmation received from "+ inPacket.getSourceIPAddress() + ":" + inPacket.get_srcPort() + ". Now closing connection!"; ! } ! ! TCP_Info.setDescription(s); Simulation.addLayerInfo(TCP_Info); ! //deleting from SegmentsToResend the segmet with the acknowledgment number we have received NOTE: dec by 1 is used see RFC Elm.SegmentsToResend.remove((Integer)our_ack-1); //now we have to send ACK-segment (with SYN=false, seq_num=XX, ack_num=XX) ! //we have one received segment so everything we have to do is just to call "mParentStack.sendTCPSegment(listener,msg,flags);" ! if (Elm.isFIN_sent==false) ! { ! Elm.isPassive=true; ! String msg=""; ! boolean flags[]={false,true,false,false,false,true}; /* URG, !ACK!, PSH, RST, SYN, !FIN! */ //maybe not like in RFC page 37 p3.5 ! Application listener; ! listener = (Application)Elm.application; ! //Elm.isFIN_sent=true; - will be set in "sendTCPSegment" ! mParentStack.sendTCPSegment(listener,msg,flags); ! } else ! { ! if (Elm.isFIN_confirmed==false) ! { ! String msg=""; ! boolean flags[]={false,true,false,false,false,true}; /* URG, !ACK!, PSH, RST, SYN, !FIN! */ //maybe not like in RFC page 37 p3.5 ! Application listener; ! listener = (Application)Elm.application; ! Elm.isFIN_confirmed=true; ! mParentStack.sendTCPSegment(listener,msg,flags); ! } else ! { ! if (!Elm.isPassive) ! { ! String msg=""; ! boolean flags[]={false,true,false,false,false,true}; /* URG, !ACK!, PSH, RST, SYN, !FIN! */ //maybe not like in RFC page 37 p3.5 ! Application listener; ! listener = (Application)Elm.application; ! mParentStack.sendTCPSegment(listener,msg,flags); ! } ! ClosePort((Application)Elm.application); //FIN sent and confirmed!!! Closing connection ! } ! ! } } else { //we have already received this segment *************** *** 901,905 **** if (rs>2) listener.RecvData(inPacket.getTCP_message()); ! if (our_ack!=2 || Elm.sent_segments!=2) mParentStack.sendTCPSegment(listener,msg,flags); //our_ack==2 when connection is established //we have sent last ACK and we can close TCP port now --- 920,924 ---- if (rs>2) listener.RecvData(inPacket.getTCP_message()); ! if ((our_ack!=2 || Elm.sent_segments!=2) && Elm.PortStatus!=1) mParentStack.sendTCPSegment(listener,msg,flags); //our_ack==2 when connection is established //we have sent last ACK and we can close TCP port now Index: Echo_tcp.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/core/protocolsuite/tcp_ip/Echo_tcp.java,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** Echo_tcp.java 27 Nov 2005 14:28:22 -0000 1.5 --- Echo_tcp.java 27 Nov 2005 18:17:34 -0000 1.6 *************** *** 138,142 **** protInfo.setDescription("Recieving echo message '" + Data + "' from server."); Simulation.addLayerInfo(protInfo);*/ ! Disconnect(); //if FIN message in TCP then no call to Disconnect(); }else{ //server processing recieve --- 138,142 ---- protInfo.setDescription("Recieving echo message '" + Data + "' from server."); Simulation.addLayerInfo(protInfo);*/ ! //Disconnect(); }else{ //server processing recieve *************** *** 158,162 **** //SendData(Data); ! mParentStack.SendFinalTCP(this, Data); LayerInfo protInfo3 = new LayerInfo(getClass().getName()); --- 158,162 ---- //SendData(Data); ! mParentStack.SendFinalTCP(this, Data); //will close both connections LayerInfo protInfo3 = new LayerInfo(getClass().getName()); *************** *** 167,171 **** Simulation.addLayerInfo(protInfo3); ! Disconnect(); Listen(); }catch(Exception e){ --- 167,171 ---- Simulation.addLayerInfo(protInfo3); ! // Disconnect(); Listen(); }catch(Exception e){ |