[Javanetsim-cvs] javaNetSim/core/protocolsuite/tcp_ip Application.java, 1.22, 1.23 Echo.java, 1.27,
Status: Beta
Brought to you by:
darkkey
From: QweR <qw...@us...> - 2007-10-01 04:58:23
|
Update of /cvsroot/javanetsim/javaNetSim/core/protocolsuite/tcp_ip In directory sc8-pr-cvs6.sourceforge.net:/tmp/cvs-serv20979/core/protocolsuite/tcp_ip Modified Files: Application.java Echo.java ExternalProxyApp.java PosixTelnetClient.java SNMP.java TCP_session.java Tcp.java Telnet_client.java Telnet_server.java Udp.java socketLayer.java Log Message: Applications was corrected Index: Telnet_client.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/core/protocolsuite/tcp_ip/Telnet_client.java,v retrieving revision 1.14 retrieving revision 1.15 diff -C2 -d -r1.14 -r1.15 *** Telnet_client.java 29 Sep 2007 20:33:36 -0000 1.14 --- Telnet_client.java 1 Oct 2007 04:58:12 -0000 1.15 *************** *** 62,66 **** } ! public void Free() throws TransportLayerException{ mParentStack.SL().free(appSock); } --- 62,67 ---- } ! public void Free() throws TransportLayerException ! { mParentStack.SL().free(appSock); } *************** *** 105,108 **** --- 106,111 ---- public void OnDisconnect(int sock){ + terminal.recvData("Connection refused"); + terminal.close(); printLayerInfo("Client: disconnected"); } *************** *** 130,134 **** public void SendData(int sock, String Data) throws LowLinkException, TransportLayerException, CommunicationException { ! mParentStack.SL().write(sock, Data); } --- 133,137 ---- public void SendData(int sock, String Data) throws LowLinkException, TransportLayerException, CommunicationException { ! mParentStack.SL().write(sock, Data); } Index: socketLayer.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/core/protocolsuite/tcp_ip/socketLayer.java,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** socketLayer.java 29 Sep 2007 20:33:36 -0000 1.9 --- socketLayer.java 1 Oct 2007 04:58:13 -0000 1.10 *************** *** 41,45 **** jnsock.src_IP = srcIP; //((jnSocket)sockTable.get(sock)).src_port = srcPort; <-- WRONG! ! //jnsock.open_state = true; //bind or connect or listen if(jnsock.type == jnsock.UDP_socket){ mParentStack.UDP().bindPort(sock, srcPort); --- 41,45 ---- jnsock.src_IP = srcIP; //((jnSocket)sockTable.get(sock)).src_port = srcPort; <-- WRONG! ! //jnsock.open_state = true; //call listen(sock) to open socket if(jnsock.type == jnsock.UDP_socket){ mParentStack.UDP().bindPort(sock, srcPort); *************** *** 56,60 **** //((jnSocket)sockTable.get(sock)).src_port = srcPort; <-- WRONG! if(jnsock.type == jnsock.UDP_socket){ ! //mParentStack.UDP().bindPort(sock, srcPort); } else if(jnsock.type == jnsock.TCP_socket){ --- 56,60 ---- //((jnSocket)sockTable.get(sock)).src_port = srcPort; <-- WRONG! if(jnsock.type == jnsock.UDP_socket){ ! mParentStack.UDP().listen(sock); } else if(jnsock.type == jnsock.TCP_socket){ *************** *** 74,77 **** --- 74,79 ---- } else if(jnsock.type == jnsock.UDP_socket){ + jnsock.dst_IP = ipaddr; + jnsock.dst_port = port; result = true; } *************** *** 131,135 **** if(((jnSocket)sockTable.get(sock)).open_state == true){ //DEPRECATED IN SOON ! if(((jnSocket)sockTable.get(sock)).type != jnSocket.TCP_socket){ ((jnSocket)sockTable.get(sock)).dst_IP = IP; ((jnSocket)sockTable.get(sock)).dst_port = port; --- 133,137 ---- if(((jnSocket)sockTable.get(sock)).open_state == true){ //DEPRECATED IN SOON ! if(((jnSocket)sockTable.get(sock)).type == jnSocket.UDP_socket){ ((jnSocket)sockTable.get(sock)).dst_IP = IP; ((jnSocket)sockTable.get(sock)).dst_port = port; *************** *** 142,146 **** //^^^^^^^^^^^^^^^^ ! ((jnSocket)sockTable.get(sock)).app.OnConnect(sock); ((jnSocket)sockTable.get(sock)).app.RecvData(sock, data); } --- 144,148 ---- //^^^^^^^^^^^^^^^^ ! //((jnSocket)sockTable.get(sock)).app.OnConnect(sock); ((jnSocket)sockTable.get(sock)).app.RecvData(sock, data); } Index: Udp.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/core/protocolsuite/tcp_ip/Udp.java,v retrieving revision 1.38 retrieving revision 1.39 diff -C2 -d -r1.38 -r1.39 *** Udp.java 22 Sep 2007 23:06:44 -0000 1.38 --- Udp.java 1 Oct 2007 04:58:12 -0000 1.39 *************** *** 281,300 **** if ( mSL.get_socket(sock_num).src_port == 0 ) { ! if (in_Port>=0 && in_Port<=65535) ! { ! //create such a record in hashtable ! mSL.get_socket(sock_num).src_port = in_Port; ! addSession(jnSocket.genUDPkey(in_Port), sock_num); //hash table update ! ! LayerInfo UDP_Info = new LayerInfo(getClass().getName()); ! UDP_Info.setObjectName(mParentStack.getParentNodeName()); ! UDP_Info.setDataType("UDP Protocol"); ! UDP_Info.setLayer("Transport"); ! UDP_Info.setDescription("Local port " + in_Port + " binded."); ! Simulation.addLayerInfo(UDP_Info); ! } else // ! { ! throw new TransportLayerException("UDP error: can not listen to port "+ in_Port +"! Use port range from 1 to 65535 to listen to."); ! } } else // { --- 281,293 ---- if ( mSL.get_socket(sock_num).src_port == 0 ) { ! if (in_Port>=0 && in_Port<=65535) ! { ! //create such a record in hashtable ! mSL.get_socket(sock_num).src_port = in_Port; ! printLayerInfo("Local port " + in_Port + " binded."); ! } else // ! { ! throw new TransportLayerException("UDP error: can not listen to port "+ in_Port +"! Use port range from 1 to 65535 to listen to."); ! } } else // { *************** *** 304,307 **** --- 297,329 ---- } + // bind port to socket + public void listen(int sock_num) throws TransportLayerException + { + int in_Port = mSL.get_socket(sock_num).src_port; + if( in_Port != 0 ) { + if (in_Port>0 && in_Port<=65535){ + if(!mSL.get_socket(sock_num).open_state){ + addSession(jnSocket.genUDPkey(in_Port), sock_num); //hash table update + printLayerInfo("Local port " + in_Port + " is listening."); + } + else{ + if (mSL.get_socket(sock_num).src_port==in_Port){ + printLayerInfo("UDP error: can not double listen to port "+ in_Port +"! Server is already listening to this port"); + throw new TransportLayerException("error: can not double listen to port "+ in_Port +"! Server is already listening to this port"); + } + else{ + printLayerInfo("UDP error: can not listen to port "+ in_Port +"! Already listening to port " + mSL.get_socket(sock_num).src_port); + throw new TransportLayerException("TCP error: can not listen to port "+ in_Port +"! Already listening to port " + mSL.get_socket(sock_num).src_port); + } + } + } else { + throw new TransportLayerException("UDP error: can not listen to port "+ in_Port +"! Use port range from 1 to 65535 to listen to."); + } + } else + { + throw new TransportLayerException("UDP error: can not listen to port 0! Use bind before to call listen!"); + } + } + /** * This method closes the UDP port for an application *************** *** 401,405 **** public int GetReceivedDatagrammsNumber() { ! return received_datagramms; } --- 423,427 ---- public int GetReceivedDatagrammsNumber() { ! return received_datagramms; } *************** *** 413,417 **** public int GetSentDatagrammsNumber() { ! return sent_datagramm; } --- 435,439 ---- public int GetSentDatagrammsNumber() { ! return sent_datagramm; } *************** *** 425,430 **** public void ResetCounters() { ! sent_datagramm=0; ! received_datagramms=0; } } //EOF --- 447,461 ---- public void ResetCounters() { ! sent_datagramm=0; ! received_datagramms=0; ! } ! ! protected void printLayerInfo(String s) { ! LayerInfo protInfo = new LayerInfo(getClass().getName()); ! protInfo.setObjectName(mParentStack.getParentNodeName()); ! protInfo.setDataType("UDP Protocol"); ! protInfo.setLayer("Transport "); ! protInfo.setDescription(s); ! Simulation.addLayerInfo(protInfo); } } //EOF Index: Telnet_server.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/core/protocolsuite/tcp_ip/Telnet_server.java,v retrieving revision 1.16 retrieving revision 1.17 diff -C2 -d -r1.16 -r1.17 *** Telnet_server.java 29 Sep 2007 20:33:36 -0000 1.16 --- Telnet_server.java 1 Oct 2007 04:58:12 -0000 1.17 *************** *** 171,182 **** printLayerInfo("Server: recieving message '" + Data + "' from client."); while(Data.length()>0) { - String outData=""; int ch = (char)Data.charAt(0); switch(ch) { case 0x08: { if(cmdline.length() > 0) { ! outData="\b"; cmdline = cmdline.substring(0,cmdline.length()-1); } --- 171,182 ---- printLayerInfo("Server: recieving message '" + Data + "' from client."); + String outData=""; while(Data.length()>0) { int ch = (char)Data.charAt(0); switch(ch) { case 0x08: { if(cmdline.length() > 0) { ! outData += "\b"; cmdline = cmdline.substring(0,cmdline.length()-1); } *************** *** 189,198 **** temp = cmdline; ispass = true; ! outData = "\r\npassword: "; } else if(ispass) { ispass = false; if(temp.compareTo(login)==0 && cmdline.compareTo(password)==0) { ! outData = "\r\nWelcome to " + mParentStack.getParentNodeName() + "\r\n" + runcmd(""); } else { --- 189,198 ---- temp = cmdline; ispass = true; ! outData += "\r\npassword: "; } else if(ispass) { ispass = false; if(temp.compareTo(login)==0 && cmdline.compareTo(password)==0) { ! outData += "\r\nWelcome to " + mParentStack.getParentNodeName() + "\r\n" + runcmd(""); } else { *************** *** 209,221 **** if(temp.compareTo("")==0) { temp = cmdline; ! outData = "\r\nRetype new password: "; } else { if(temp.compareTo(cmdline)==0) { password = temp; ! outData = "\r\n" + runcmd(""); } else { ! outData = "\r\n Password is not identical\r\n" + runcmd(""); } isnewpass = false; --- 209,221 ---- if(temp.compareTo("")==0) { temp = cmdline; ! outData += "\r\nRetype new password: "; } else { if(temp.compareTo(cmdline)==0) { password = temp; ! outData += "\r\n" + runcmd(""); } else { ! outData += "\r\n Password is not identical\r\n" + runcmd(""); } isnewpass = false; *************** *** 224,228 **** } else { ! outData = "\r\n" + runcmd(removeSpaces(cmdline)); } cmdline = ""; --- 224,228 ---- } else { ! outData += "\r\n" + runcmd(removeSpaces(cmdline)); } cmdline = ""; *************** *** 236,263 **** { if(ispass || isnewpass) { ! outData = "*"; } else { ! outData = String.valueOf(Data.charAt(0)); } cmdline+=String.valueOf(Data.charAt(0)); } else { ! // outData = "<" + ( ch < 16 ? "0" : "" ) + Integer.toHexString(ch) + ">"; } } ! try{ ! if(outData.compareTo("")==0){ ! mParentStack.SL().disconnect(sock); ! } ! else{ ! printLayerInfo("Server: sending message '" + outData + "' to client."); ! SendData(sock, outData); ! } } ! catch(CommunicationException e){ ! printLayerInfo("Server: can not send data packet: communication error"); } ! Data = Data.substring(1); } } --- 236,263 ---- { if(ispass || isnewpass) { ! outData += "*"; } else { ! outData += String.valueOf(Data.charAt(0)); } cmdline+=String.valueOf(Data.charAt(0)); } else { ! // outData += "<" + ( ch < 16 ? "0" : "" ) + Integer.toHexString(ch) + ">"; } } ! Data = Data.substring(1); ! } ! try{ ! if(outData.compareTo("")==0){ ! mParentStack.SL().disconnect(sock); } ! else{ ! printLayerInfo("Server: sending message '" + outData + "' to client."); ! SendData(sock, outData); } ! } ! catch(CommunicationException e){ ! printLayerInfo("Server: can not send data packet: communication error"); } } Index: PosixTelnetClient.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/core/protocolsuite/tcp_ip/PosixTelnetClient.java,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** PosixTelnetClient.java 25 Sep 2007 22:34:09 -0000 1.5 --- PosixTelnetClient.java 1 Oct 2007 04:58:12 -0000 1.6 *************** *** 3,21 **** import core.TransportLayerException; - import core.InvalidNetworkLayerDeviceException; - import core.CommunicationException; - import core.LowLinkException; - import core.LayerInfo; - - import core.Packet; - - import core.Error; - import core.Simulation; - import guiUI.PosixTelnetClientGUI; --- 3,11 ---- *************** *** 33,37 **** /** Creates a new instance of Echo */ public PosixTelnetClient(ProtocolStack inParentStack, int UID) { ! super(inParentStack, 0, 0, UID); } --- 23,28 ---- /** Creates a new instance of Echo */ public PosixTelnetClient(ProtocolStack inParentStack, int UID) { ! super(inParentStack, 0, 0, UID); ! appSock = mParentStack.SL().socket(jnSocket.TCP_socket, this); } *************** *** 57,67 **** */ public void Close() throws TransportLayerException ! { ! mParentStack.CloseTCP(this); } public void Free() throws TransportLayerException ! { ! mParentStack.FreeTCPApplication(this); } --- 48,58 ---- */ public void Close() throws TransportLayerException ! { ! mParentStack.SL().close(appSock); } public void Free() throws TransportLayerException ! { ! mParentStack.SL().free(appSock); } *************** *** 77,98 **** public boolean Connect(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("Telnet Protocol Data"); ! protInfo2.setLayer("Application "); ! protInfo2.setDescription("Connecting to host " + Host + ":"+ port +". Please wait..."); ! Simulation.addLayerInfo(protInfo2); ! do ! { ! ConnectionAttempts--; ! clientPort = mParentStack.ConnectTCP(this, sdHost, sdPort); ! } ! while (ConnectionAttempts>0 && clientPort==-1); ! if (clientPort>-1) return true; else return false; } --- 68,76 ---- public boolean Connect(String Host, int port) throws TransportLayerException, InvalidNetworkLayerDeviceException, CommunicationException, LowLinkException { ! printLayerInfo("Connecting to host " + Host + ":"+ port +". Please wait..."); ! boolean isconnected = mParentStack.SL().connect(appSock, Host, port); ! return isconnected; } *************** *** 112,135 **** */ ! public void Disconnect() throws TransportLayerException, LowLinkException{ ! try { ! mParentStack.FinalizeTCP(this); //will close client connection ! }catch(Exception e){ ! ///*TODO*: here to catch ! } ! ! LayerInfo protInfo3 = new LayerInfo(getClass().getName()); ! protInfo3.setObjectName(mParentStack.getParentNodeName()); ! protInfo3.setDataType("Telnet Protocol Data"); ! protInfo3.setLayer("Application "); ! if(appType==0){ ! protInfo3.setDescription("Application closing connection."); ! }else{ ! protInfo3.setDescription("Application closing connection. Now listening on " + listenPort + "."); ! } ! Simulation.addLayerInfo(protInfo3); ! ! mParentStack.CloseTCP(this); ! //mParentStack.freeTCPPort(this); } --- 90,96 ---- */ ! public boolean Disconnect() throws LowLinkException, CommunicationException, TransportLayerException ! { ! return mParentStack.SL().disconnect(appSock); } *************** *** 141,149 **** public void OnDisconnect(int sock) { ! } public void OnError(int sock, int error){ ! } --- 102,119 ---- public void OnDisconnect(int sock) { ! printLayerInfo("Client: disconnected"); } public void OnError(int sock, int error){ ! switch(error){ ! case -1: { ! printLayerInfo("Error: can not connect to " + mParentStack.SL().get_socket(sock).dst_IP + ":" + mParentStack.SL().get_socket(sock).dst_port); ! break; ! } ! case -2 :{ ! OnDisconnect(sock); ! break; ! } ! } } *************** *** 157,164 **** public void SendData(int sock, String Data) throws LowLinkException, TransportLayerException, CommunicationException { ! ! mParentStack.SendTCP(this, Data,-1); ! ! //processing the protocol doings. } --- 127,131 ---- public void SendData(int sock, String Data) throws LowLinkException, TransportLayerException, CommunicationException { ! mParentStack.SL().write(sock, Data); } *************** *** 172,187 **** * @version v0.02 */ ! public void RecvData(int sock, String Data) throws LowLinkException, TransportLayerException { ! //processing the protocol doings. ! ! //client processing recieve ! // printing some ... ! LayerInfo protInfo = new LayerInfo(getClass().getName()); ! protInfo.setObjectName(mParentStack.getParentNodeName()); ! protInfo.setDataType("Telnet Protocol Data"); ! protInfo.setLayer("Application "); ! protInfo.setDescription("Recieving telnet data '" + Data + "' from server."); ! Simulation.addLayerInfo(protInfo); ! protInfo = null; while(ptcGUI.busy); --- 139,145 ---- * @version v0.02 */ ! public void RecvData(int sock, String Data) throws LowLinkException, TransportLayerException ! { ! printLayerInfo("Recieving telnet data '" + Data + "' from server."); while(ptcGUI.busy); *************** *** 200,249 **** */ public void Telnet(PosixTelnetClientGUI ptcGUI, String Host, int port) throws CommunicationException, LowLinkException, InvalidNetworkLayerDeviceException, TransportLayerException{ ! this.ptcGUI = ptcGUI; ! mParentStack.FreeTCPApplication(this); if (Connect(Host, port)) { ! LayerInfo protInfo = new LayerInfo(getClass().getName()); ! protInfo.setObjectName(mParentStack.getParentNodeName()); ! protInfo.setDataType("Telnet Protocol Data"); ! protInfo.setLayer("Application "); ! protInfo.setDescription("Starting telnet connection to " + Host + ":" + port); ! Simulation.addLayerInfo(protInfo); ! ! ! } else { ! LayerInfo protInfo = new LayerInfo(getClass().getName()); ! protInfo.setObjectName(mParentStack.getParentNodeName()); ! protInfo.setDataType("Telnet Protocol Data"); ! protInfo.setLayer("Application "); ! protInfo.setDescription("Error: can not connect to " + Host + ":" + port + "!"); ! Simulation.addLayerInfo(protInfo); } } - - /** - * This method recieves source IP of a packet - * @param data to receive - * @author gift (sourceforge.net user) - * @version v0.01 - */ - public void RecvIP(String IP) throws LowLinkException, TransportLayerException - { - - } - - /** - * This method recieves source port number of a packet - * @param data to receive - * @author gift (sourceforge.net user) - * @version v0.01 - */ - public void RecvPrt(int port_num) throws LowLinkException, TransportLayerException - { } - } --- 158,175 ---- */ public void Telnet(PosixTelnetClientGUI ptcGUI, String Host, int port) throws CommunicationException, LowLinkException, InvalidNetworkLayerDeviceException, TransportLayerException{ ! this.ptcGUI = ptcGUI; if (Connect(Host, port)) { ! printLayerInfo("Starting telnet connection to " + Host + ":" + port); ! }else { ! printLayerInfo("Error: can not connect to " + Host + ":" + port + "!"); } } + public void printLayerInfo(String s) { + super.printLayerInfo("Posix Telnet Protocol Data", s); } } Index: Tcp.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/core/protocolsuite/tcp_ip/Tcp.java,v retrieving revision 1.97 retrieving revision 1.98 diff -C2 -d -r1.97 -r1.98 *** Tcp.java 29 Sep 2007 20:33:35 -0000 1.97 --- Tcp.java 1 Oct 2007 04:58:12 -0000 1.98 *************** *** 132,136 **** if(nt>=0){ try{ ! mParentStack.sendPacket(packet); }catch(LowLinkException e){ System.out.println(e.toString()); --- 132,140 ---- if(nt>=0){ try{ ! IncSentDuplicatesNumber(1); ! getSession(mParentStack.SL().get_socket(sock).genKey()).inc_sent_duplicates(); ! sendPacket(packet, getSession(mParentStack.SL().get_socket(sock).genKey())); ! }catch(TransportLayerException e){ ! System.out.println(e.toString()); }catch(LowLinkException e){ System.out.println(e.toString()); *************** *** 152,157 **** try{ removeTimer(getSession(mSL.get_socket(sock).genKey()).last_timer); ! mSL.get_socket(sock).app.OnDisconnect(sock); mSL.close(sock); }catch(TransportLayerException e){ System.out.println(e.toString()); --- 156,162 ---- try{ removeTimer(getSession(mSL.get_socket(sock).genKey()).last_timer); ! Application app = mSL.get_socket(sock).app; mSL.close(sock); + app.OnDisconnect(sock); }catch(TransportLayerException e){ System.out.println(e.toString()); *************** *** 160,166 **** } case -2:{ - mSL.get_socket(sock).app.OnError(sock, -1); //connect error try{ mSL.close(sock); }catch(TransportLayerException e){ System.out.println(e.toString()); --- 165,172 ---- } case -2:{ try{ + Application app = mSL.get_socket(sock).app; //connect error mSL.close(sock); + app.OnError(sock, -1); }catch(TransportLayerException e){ System.out.println(e.toString()); *************** *** 170,177 **** case -3:{ //acknowledgment have not recieved, close connection // send RST segment try{ boolean flags[] = genFlags(RST); TCP_packet rstpack = getTCPPacket_tosend(sock, "", flags, packet.get_acknowledgment_number(), packet.get_sequence_number()+1); ! mParentStack.sendPacket(rstpack); }catch(TransportLayerException e){ System.out.println(e.toString()); --- 176,184 ---- case -3:{ //acknowledgment have not recieved, close connection // send RST segment + printLayerInfo(">>> Sending RST segment"); try{ boolean flags[] = genFlags(RST); TCP_packet rstpack = getTCPPacket_tosend(sock, "", flags, packet.get_acknowledgment_number(), packet.get_sequence_number()+1); ! sendPacket(rstpack, getSession(mParentStack.SL().get_socket(sock).genKey())); }catch(TransportLayerException e){ System.out.println(e.toString()); *************** *** 183,188 **** // close seession try{ ! mSL.get_socket(sock).app.OnError(sock, -2); //disconnect on timeout, sending RST mSL.close(sock); }catch(TransportLayerException e){ System.out.println(e.toString()); --- 190,196 ---- // close seession try{ ! Application app = mSL.get_socket(sock).app; //disconnect on timeout, sending RST mSL.close(sock); + app.OnError(sock, -2); }catch(TransportLayerException e){ System.out.println(e.toString()); *************** *** 246,250 **** // private static final int resendtimes_SYNC_CLOSE[] = {75000, -1}; // synchronous closing private static final int resendtimes_SYN_ACK[] = {1000,1000,1000,1000,1000,1000,-2}; ! private static final int resendtimes_SYN[] = {1000,1000,1000,-2}; private static final int resendtimes_DEFAULT[] = {1000,1000,1000,1000,1000,1000,1000,1000,1000,1000,1000,1000,-3}; private static final int resendtimes_NULL[] = {}; --- 254,258 ---- // private static final int resendtimes_SYNC_CLOSE[] = {75000, -1}; // synchronous closing private static final int resendtimes_SYN_ACK[] = {1000,1000,1000,1000,1000,1000,-2}; ! private static final int resendtimes_SYN[] = {1000,1000,1000,1000,1000,1000,1000,-2}; private static final int resendtimes_DEFAULT[] = {1000,1000,1000,1000,1000,1000,1000,1000,1000,1000,1000,1000,-3}; private static final int resendtimes_NULL[] = {}; *************** *** 509,513 **** * @see TransportLayerException */ ! public void closePort(int sock) throws TransportLayerException //changes port status from 1 (listen) or (see proc ;) to 0 (free) { int portToClose=mSL.get_socket(sock).src_port; --- 517,521 ---- * @see TransportLayerException */ ! public void closePort(int sock) throws TransportLayerException { int portToClose=mSL.get_socket(sock).src_port; *************** *** 526,532 **** } removeSession(mSL.get_socket(sock).genKey()); ! mSL.close(Elm.sock); ! printLayerInfo("Local port " + portToClose + " closed and set to free."); } else --- 534,540 ---- } removeSession(mSL.get_socket(sock).genKey()); ! //mSL.close(Elm.sock); ! printLayerInfo("Local port " + portToClose + " closed."); } else *************** *** 587,598 **** } ! String pack_src = tosend.getSourceIPAddress()+":"+tosend.get_srcPort(); ! String pack_dst = tosend.getDestIPAddress()+":"+tosend.get_destPort(); ! String pack_flags = (tosend.get_ACK_flag()?"ACK,":"")+(tosend.get_SYN_flag()?"SYN,":"")+(tosend.get_FIN_flag()?"FIN,":"")+(tosend.get_RST_flag()?"RST":""); ! System.out.println("|| <<< TCP send pack: src="+pack_src+" dst="+pack_dst+" flags="+pack_flags+" seq="+tosend.get_sequence_number()+" ack="+tosend.get_acknowledgment_number()+" data='"+tosend.getTCP_message()+"'"); ! System.out.println("|| <<<< Host="+mParentStack.getHostName()+" IP="+mParentStack.getSrcIP()+" sock="+sock+" state="+Elm.getState()); ! printLayerInfo("TCP packet send to "+pack_dst+" flags="+pack_flags+" seq="+tosend.get_sequence_number()+" ack="+tosend.get_acknowledgment_number()+" data='"+tosend.getTCP_message()+"'"); ! ! mParentStack.sendPacket(tosend); sended_at_last_one_packet = true; } --- 595,599 ---- } ! sendPacket(tosend, Elm); sended_at_last_one_packet = true; } *************** *** 600,603 **** --- 601,622 ---- } + private void sendPacket(TCP_packet packet, TCP_session Elm) throws TransportLayerException, LowLinkException, CommunicationException + { + String pack_src = packet.getSourceIPAddress()+":"+packet.get_srcPort(); + String pack_dst = packet.getDestIPAddress()+":"+packet.get_destPort(); + String pack_flags = (packet.get_ACK_flag()?"ACK,":"")+(packet.get_SYN_flag()?"SYN,":"")+(packet.get_FIN_flag()?"FIN,":"")+(packet.get_RST_flag()?"RST":""); + System.out.println("|| <<< TCP send pack: src="+pack_src+" dst="+pack_dst+" flags="+pack_flags+" seq="+packet.get_sequence_number()+" ack="+packet.get_acknowledgment_number()+" data='"+packet.getTCP_message()+"'"); + System.out.println("|| <<<< Host="+mParentStack.getHostName()+" IP="+mParentStack.getSrcIP()+" sock="+Elm.getSocket()+" state="+Elm.getState()); + printLayerInfo("TCP packet send to "+pack_dst+" flags="+pack_flags+" seq="+packet.get_sequence_number()+" ack="+packet.get_acknowledgment_number()+" data='"+packet.getTCP_message()+"'"); + + IncSentSegmentsNumber(1); + Elm.inc_sent_segments(); + if(packet.get_ACK_flag()){ + IncSentACKSegmentsNumber(1); + Elm.inc_sent_ACK(); + } + mParentStack.sendPacket(packet); + } + /** * This method returns the TCP packet to send *************** *** 626,630 **** TCP_packet tosend = new TCP_packet(dstIP,srcIP,dstPort,srcPort); ! // try{ if(seq_num == -1 || seq_num > Elm.seq_number) seq_num = Elm.seq_number; if(acknow_num==-1) acknow_num = Elm.getLastACK(); --- 645,649 ---- TCP_packet tosend = new TCP_packet(dstIP,srcIP,dstPort,srcPort); ! try{ if(seq_num == -1 || seq_num > Elm.seq_number) seq_num = Elm.seq_number; if(acknow_num==-1) acknow_num = Elm.getLastACK(); *************** *** 648,655 **** if (!(flags[SYN_flag] && acknow_num==0) && flags[ACK_flag]) Elm.inc_sent_ACK(); //inc in case this is an ACK-segment (this is statistic) ! // } ! // catch(Exception e){ ! // System.out.println(e.toString()); ! // } --- 667,674 ---- if (!(flags[SYN_flag] && acknow_num==0) && flags[ACK_flag]) Elm.inc_sent_ACK(); //inc in case this is an ACK-segment (this is statistic) ! } ! catch(Exception e){ ! System.out.println(e.toString()); ! } *************** *** 712,716 **** } else{ ! int i = 0; } } --- 731,735 ---- } else{ ! //printLayerInfo(">>> Session not existed: "+jnSocket.genTCPkey(inPacket.get_destPort(), "0.0.0.0", 0)); } } *************** *** 719,722 **** --- 738,745 ---- //int sock = Elm.getSocket(); if(!inPacket.get_ACK_flag() || inPacket.get_acknowledgment_number() > Elm.getLastACK() || inPacket.get_SYN_flag() || inPacket.get_FIN_flag()){ + if((inPacket.get_ACK_flag() && (inPacket.get_SYN_flag() || inPacket.get_FIN_flag() || inPacket.get_RST_flag())) || !inPacket.get_ACK_flag()) { + IncReceivedSegmentsNumber(1); + Elm.inc_received_segments(); + } if(inPacket.get_ACK_flag() && inPacket.get_acknowledgment_number() > Elm.getLastACK()){ long tid = Elm.removeSegmentToResend(inPacket.get_acknowledgment_number()-1); *************** *** 726,731 **** } if(inPacket.get_RST_flag() && !(inPacket.get_ACK_flag() || inPacket.get_SYN_flag() || inPacket.get_FIN_flag())){ // add chech flags ONLY RST ! mSL.get_socket(Elm.getSocket()).app.OnDisconnect(Elm.getSocket()); mSL.close(Elm.getSocket()); } else{ --- 749,755 ---- } if(inPacket.get_RST_flag() && !(inPacket.get_ACK_flag() || inPacket.get_SYN_flag() || inPacket.get_FIN_flag())){ // add chech flags ONLY RST ! Application app = mSL.get_socket(Elm.getSocket()).app; mSL.close(Elm.getSocket()); + app.OnDisconnect(Elm.getSocket()); } else{ *************** *** 809,816 **** } else if(inPacket.get_SYN_flag() && !(inPacket.get_ACK_flag() || inPacket.get_FIN_flag())){ ! //do nothing, resending works :) } else if(!(inPacket.get_ACK_flag() || inPacket.get_SYN_flag() || inPacket.get_FIN_flag())){ ! Elm.addReceivedSegment(inPacket); // save received segments, although connection have not established yet } else --- 833,846 ---- } else if(inPacket.get_SYN_flag() && !(inPacket.get_ACK_flag() || inPacket.get_FIN_flag())){ ! IncReceivedDuplicatesNumber(1); ! Elm.inc_received_duplicates(); ! // boolean flags[] = genFlags(ACK | SYN); ! // sendTCPSegment(Elm.getSocket(), "", flags, inPacket.get_sequence_number()+1, resendtimes_SYN_ACK); } else if(!(inPacket.get_ACK_flag() || inPacket.get_SYN_flag() || inPacket.get_FIN_flag())){ ! if(!Elm.addReceivedSegment(inPacket)){ // save received segments, although connection have not established yet ! IncReceivedDuplicatesNumber(1); ! Elm.inc_received_duplicates(); ! } } else *************** *** 830,833 **** --- 860,865 ---- } else if(inPacket.get_SYN_flag() && inPacket.get_ACK_flag()){ + IncReceivedDuplicatesNumber(1); + Elm.inc_received_duplicates(); boolean flags[] = genFlags(ACK); sendTCPSegment(Elm.getSocket(), "", flags, inPacket.get_sequence_number()+1, resendtimes_NULL); *************** *** 854,861 **** { if(inPacket.get_ACK_flag()){ ! mSL.get_socket(Elm.getSocket()).app.OnDisconnect(Elm.getSocket()); mSL.close(Elm.getSocket()); } else if(inPacket.get_FIN_flag()){ boolean flags[] = genFlags(ACK); sendTCPSegment(Elm.getSocket(), "", flags, inPacket.get_sequence_number()+1, resendtimes_NULL); --- 886,896 ---- { if(inPacket.get_ACK_flag()){ ! Application app = mSL.get_socket(Elm.getSocket()).app; mSL.close(Elm.getSocket()); + app.OnDisconnect(Elm.getSocket()); } else if(inPacket.get_FIN_flag()){ + IncReceivedDuplicatesNumber(1); + Elm.inc_received_duplicates(); boolean flags[] = genFlags(ACK); sendTCPSegment(Elm.getSocket(), "", flags, inPacket.get_sequence_number()+1, resendtimes_NULL); *************** *** 875,880 **** sendTCPSegment(Elm.getSocket(), "", flags, inPacket.get_sequence_number()+1, resendtimes_NULL); if(!USE_2MSL){ ! mSL.get_socket(Elm.getSocket()).app.OnDisconnect(Elm.getSocket()); mSL.close(Elm.getSocket()); } } --- 910,916 ---- sendTCPSegment(Elm.getSocket(), "", flags, inPacket.get_sequence_number()+1, resendtimes_NULL); if(!USE_2MSL){ ! Application app = mSL.get_socket(Elm.getSocket()).app; mSL.close(Elm.getSocket()); + app.OnDisconnect(Elm.getSocket()); } } *************** *** 907,912 **** sendTCPSegment(Elm.getSocket(), "", flags, inPacket.get_sequence_number()+1, resendtimes_NULL); if(!USE_2MSL){ ! mSL.get_socket(Elm.getSocket()).app.OnDisconnect(Elm.getSocket()); mSL.close(Elm.getSocket()); } } --- 943,949 ---- sendTCPSegment(Elm.getSocket(), "", flags, inPacket.get_sequence_number()+1, resendtimes_NULL); if(!USE_2MSL){ ! Application app = mSL.get_socket(Elm.getSocket()).app; mSL.close(Elm.getSocket()); + app.OnDisconnect(Elm.getSocket()); } } *************** *** 927,932 **** } else{ ! mSL.get_socket(Elm.getSocket()).app.OnDisconnect(Elm.getSocket()); mSL.close(Elm.getSocket()); } } --- 964,970 ---- } else{ ! Application app = mSL.get_socket(Elm.getSocket()).app; mSL.close(Elm.getSocket()); + app.OnDisconnect(Elm.getSocket()); } } *************** *** 943,947 **** { if(packet!=null && !(packet.get_SYN_flag() || packet.get_FIN_flag())) { ! Elm.addReceivedSegment(packet); } String out = ""; --- 981,988 ---- { if(packet!=null && !(packet.get_SYN_flag() || packet.get_FIN_flag())) { ! if(!Elm.addReceivedSegment(packet)){ ! IncReceivedDuplicatesNumber(1); ! Elm.inc_received_duplicates(); ! } } String out = ""; *************** *** 999,1002 **** --- 1040,1044 ---- sessionTable.put(key, tcps); } + //printLayerInfo(">>> Session added: "+key+" sock="+sock); return tcps; } *************** *** 1007,1010 **** --- 1049,1053 ---- tcps = (TCP_session) sessionTable.remove(key); } + //printLayerInfo(">>> Session removed: "+key); return tcps; } Index: Application.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/core/protocolsuite/tcp_ip/Application.java,v retrieving revision 1.22 retrieving revision 1.23 diff -C2 -d -r1.22 -r1.23 *** Application.java 29 Sep 2007 20:33:35 -0000 1.22 --- Application.java 1 Oct 2007 04:58:12 -0000 1.23 *************** *** 24,29 **** protected ProtocolStack mParentStack; - protected String sdHost; - protected int sdPort; protected int appType; protected int appSock; --- 24,27 ---- Index: TCP_session.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/core/protocolsuite/tcp_ip/TCP_session.java,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** TCP_session.java 28 Sep 2007 22:15:51 -0000 1.8 --- TCP_session.java 1 Oct 2007 04:58:12 -0000 1.9 *************** *** 214,217 **** --- 214,220 ---- } } + else{ + Found = true; + } return !Found; } *************** *** 283,287 **** sent_ACK++; } ! public void inv_received_duplicates(){ received_duplicates++; } --- 286,290 ---- sent_ACK++; } ! public void inc_received_duplicates(){ received_duplicates++; } Index: Echo.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/core/protocolsuite/tcp_ip/Echo.java,v retrieving revision 1.27 retrieving revision 1.28 diff -C2 -d -r1.27 -r1.28 *** Echo.java 25 Sep 2007 22:34:09 -0000 1.27 --- Echo.java 1 Oct 2007 04:58:12 -0000 1.28 *************** *** 7,23 **** package core.protocolsuite.tcp_ip; - import core.TransportLayerException; - import core.InvalidNetworkLayerDeviceException; - import core.CommunicationException; - import core.LowLinkException; - import core.LayerInfo; - - import core.Packet; - import core.Simulation; --- 7,15 ---- *************** *** 46,50 **** // try{ ! mParentStack.SL().bind(appSock, mParentStack.getSrcIP(), listenPort); printLayerInfo("Echo app", "Echo server starts listening in port " + listenPort + "."); } catch (Exception e) --- 38,43 ---- // try{ ! mParentStack.SL().bind(appSock, mParentStack.getSrcIP(), listenPort); ! mParentStack.SL().listen(appSock); printLayerInfo("Echo app", "Echo server starts listening in port " + listenPort + "."); } catch (Exception e) *************** *** 69,73 **** public void Close() throws TransportLayerException { ! printLayerInfo("Echo app", "Echo app closed socket."); mParentStack.SL().close(appSock); } --- 62,66 ---- public void Close() throws TransportLayerException { ! printLayerInfo("Echo application", "Echo application closed socket."); mParentStack.SL().close(appSock); } *************** *** 75,79 **** public void Free() throws TransportLayerException { ! printLayerInfo("Echo app", "Echo app freed socket."); mParentStack.SL().free(appSock); } --- 68,72 ---- public void Free() throws TransportLayerException { ! printLayerInfo("Echo application", "Echo application freed socket."); mParentStack.SL().free(appSock); } *************** *** 88,97 **** */ ! public boolean Connect(String Host, int port) throws TransportLayerException, InvalidNetworkLayerDeviceException, CommunicationException, LowLinkException { ! sdHost = Host; ! sdPort = port; //clientPort = mParentStack.SL().reserveUDPPort(this, sdHost, sdPort); //if (clientPort>0) return true; else return false; ! return true; } --- 81,88 ---- */ ! public boolean Connect(String Host, int port) throws TransportLayerException, InvalidNetworkLayerDeviceException, CommunicationException, LowLinkException { //clientPort = mParentStack.SL().reserveUDPPort(this, sdHost, sdPort); //if (clientPort>0) return true; else return false; ! return mParentStack.SL().connect(appSock, Host, port); } *************** *** 103,108 **** */ public void OnConnect(int sock){ - sdHost = mParentStack.SL().get_socket(sock).dst_IP; - sdPort = mParentStack.SL().get_socket(sock).dst_port; } --- 94,97 ---- *************** *** 130,133 **** --- 119,124 ---- public void SendData(int sock, String Data) throws LowLinkException, TransportLayerException, CommunicationException { + String sdHost = mParentStack.SL().get_socket(sock).dst_IP; + int sdPort = mParentStack.SL().get_socket(sock).dst_port; mParentStack.SL().writeTo(sock, Data, sdHost, sdPort); *************** *** 156,164 **** Simulation.addLayerInfo(protInfo); ! mParentStack.UDP().closePort(sock); }else{ //server processing recieve try{ LayerInfo protInfo = new LayerInfo(getClass().getName()); protInfo.setObjectName(mParentStack.getParentNodeName()); --- 147,158 ---- Simulation.addLayerInfo(protInfo); ! //mParentStack.UDP().closePort(sock); }else{ //server processing recieve try{ + String sdHost = mParentStack.SL().get_socket(sock).dst_IP; + int sdPort = mParentStack.SL().get_socket(sock).dst_port; + LayerInfo protInfo = new LayerInfo(getClass().getName()); protInfo.setObjectName(mParentStack.getParentNodeName()); *************** *** 235,261 **** Simulation.addLayerInfo(protInfo2); } - - /** - * This method recieves source IP of a packet - * @param data to receive - * @author gift (sourceforge.net user) - * @version v0.01 - * WARNING: Soon this 'll be DEPRECATED! - */ - public void RecvIP(String IP) throws LowLinkException, TransportLayerException - { - sdHost = IP; - } - - /** - * This method recieves source port number of a packet - * @param data to receive - * @author gift (sourceforge.net user) - * @version v0.01 - * WARNING: Soon this 'll be DEPRECATED! - */ - public void RecvPrt(int port_num) throws LowLinkException, TransportLayerException { - - sdPort = port_num; - } } --- 229,231 ---- Index: ExternalProxyApp.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/core/protocolsuite/tcp_ip/ExternalProxyApp.java,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** ExternalProxyApp.java 25 Sep 2007 22:34:09 -0000 1.5 --- ExternalProxyApp.java 1 Oct 2007 04:58:12 -0000 1.6 *************** *** 113,127 **** public boolean Connect(String s, int i){ return false; } - - - /** - * This method should be called from UDP when client connects to server - * @author key - * @version v0.01 - */ - public void Connected(String Host, int port){ - sdHost = Host; - sdPort = port; - } /** --- 113,116 ---- Index: SNMP.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/core/protocolsuite/tcp_ip/SNMP.java,v retrieving revision 1.20 retrieving revision 1.21 diff -C2 -d -r1.20 -r1.21 *** SNMP.java 25 Sep 2007 22:34:09 -0000 1.20 --- SNMP.java 1 Oct 2007 04:58:12 -0000 1.21 *************** *** 94,98 **** private String lastPacket=""; //last recieved packet private Vector<String> tVectorString = new Vector<String>(0); - int sock; public SNMP(ApplicationLayerDevice device,ProtocolStack inParentStack, int listenPort, int appType, int UID) { --- 94,97 ---- *************** *** 131,135 **** SNMPgroups.get(i).add("revision","0"); //ro SNMPgroups.get(i).add("version","2"); //ro ! sock = mParentStack.SL().socket(jnSocket.UDP_socket, this); } /** --- 130,134 ---- SNMPgroups.get(i).add("revision","0"); //ro SNMPgroups.get(i).add("version","2"); //ro ! appSock = mParentStack.SL().socket(jnSocket.UDP_socket, this); } /** *************** *** 141,145 **** try{ //mParentStack.ListenUDP(this, listenPort); ! mParentStack.SL().bind(sock, mParentStack.getSrcIP(), listenPort); printInfo("SNMP agent starts listening on port " + listenPort); //<<-- FIXME!!! } --- 140,145 ---- try{ //mParentStack.ListenUDP(this, listenPort); ! mParentStack.SL().bind(appSock, mParentStack.getSrcIP(), listenPort); ! mParentStack.SL().listen(appSock); printInfo("SNMP agent starts listening on port " + listenPort); //<<-- FIXME!!! } *************** *** 161,170 **** public void Close() throws TransportLayerException { //mParentStack.CloseUDP(this); ! mParentStack.SL().close(sock); printInfo("SNMP agent closed socket."); //<--- FIXME!!! } public void Free() throws TransportLayerException{ ! mParentStack.SL().free(sock); printInfo("SNMP agent freed socket."); //<--- FIXME!!! } --- 161,170 ---- public void Close() throws TransportLayerException { //mParentStack.CloseUDP(this); ! mParentStack.SL().close(appSock); printInfo("SNMP agent closed socket."); //<--- FIXME!!! } public void Free() throws TransportLayerException{ ! mParentStack.SL().free(appSock); printInfo("SNMP agent freed socket."); //<--- FIXME!!! } *************** *** 177,210 **** * @version v0.01 */ ! public boolean Connect(String Host, int port) throws TransportLayerException, InvalidNetworkLayerDeviceException, CommunicationException, LowLinkException { ! sdHost = Host; ! sdPort = port; //clientPort = mParentStack.reserveUDPPort(this, sdHost, sdPort); //if (clientPort>0) return true; //else return false; ! return true; ! } ! ! ! /** ! * This method recieves source IP of a packet ! * @param data to receive ! * @author QweR ! * @version v0.01 ! */ ! public void RecvIP(String IP) throws LowLinkException, TransportLayerException { ! retIP = IP; ! sdHost = IP; ! } ! ! /** ! * This method recieves source port number of a packet ! * @param data to receive ! * @author QweR ! * @version v0.01 ! */ ! public void RecvPrt(int port_num) throws LowLinkException, TransportLayerException { ! retPort = port_num; ! sdPort = port_num; } --- 177,185 ---- * @version v0.01 */ ! public boolean Connect(String Host, int port) throws TransportLayerException, InvalidNetworkLayerDeviceException, CommunicationException, LowLinkException { //clientPort = mParentStack.reserveUDPPort(this, sdHost, sdPort); //if (clientPort>0) return true; //else return false; ! return mParentStack.SL().connect(appSock, Host, port); } *************** *** 236,240 **** public void Disconnect()throws TransportLayerException { //mParentStack.freeUDPPort(this); ! mParentStack.SL().close(sock); } --- 211,215 ---- public void Disconnect()throws TransportLayerException { //mParentStack.freeUDPPort(this); ! mParentStack.SL().close(appSock); } *************** *** 247,251 **** public void SendData(int sock, String Data) throws LowLinkException, TransportLayerException, CommunicationException { //mParentStack.sendUDP(this, Data); ! mParentStack.SL().writeTo(sock, Data, sdHost, sdPort); } --- 222,228 ---- public void SendData(int sock, String Data) throws LowLinkException, TransportLayerException, CommunicationException { //mParentStack.sendUDP(this, Data); ! String sdHost = mParentStack.SL().get_socket(sock).dst_IP; ! int sdPort = mParentStack.SL().get_socket(sock).dst_port; ! mParentStack.SL().writeTo(sock, Data, sdHost, sdPort); } |