[Javanetsim-cvs] javaNetSim/core/protocolsuite/tcp_ip Application.java, 1.21, 1.22 Echo_tcp.java, 1
Status: Beta
Brought to you by:
darkkey
Update of /cvsroot/javanetsim/javaNetSim/core/protocolsuite/tcp_ip In directory sc8-pr-cvs6.sourceforge.net:/tmp/cvs-serv21244/core/protocolsuite/tcp_ip Modified Files: Application.java Echo_tcp.java Tcp.java Telnet_client.java Telnet_server.java socketLayer.java Log Message: TCP again Index: Telnet_client.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/core/protocolsuite/tcp_ip/Telnet_client.java,v retrieving revision 1.13 retrieving revision 1.14 diff -C2 -d -r1.13 -r1.14 *** Telnet_client.java 25 Sep 2007 22:34:09 -0000 1.13 --- Telnet_client.java 29 Sep 2007 20:33:36 -0000 1.14 *************** *** 28,34 **** private ApplicationLayerDevice mDevice; private TelnetEmulator terminal; - private int counts; private boolean already_closed = false; - private boolean connected; /** Creates a new instance of Telnet Server */ --- 28,32 ---- *************** *** 36,41 **** super(inParentStack, listenPort, appType, UID); mDevice = dev; ! counts = 0; ! connected = false; } --- 34,38 ---- super(inParentStack, listenPort, appType, UID); mDevice = dev; ! appSock = mParentStack.SL().socket(jnSocket.TCP_socket, this); } *************** *** 62,76 **** public void Close() throws TransportLayerException { ! if(!already_closed){ ! mParentStack.CloseTCP(this); ! already_closed = true; ! } } public void Free() throws TransportLayerException{ ! if(!already_closed){ ! mParentStack.FreeTCPApplication(this); ! already_closed = true; ! } } --- 59,67 ---- public void Close() throws TransportLayerException { ! mParentStack.SL().close(appSock); } public void Free() throws TransportLayerException{ ! mParentStack.SL().free(appSock); } *************** *** 86,103 **** public boolean Connect(String Host, int port) throws TransportLayerException, InvalidNetworkLayerDeviceException, CommunicationException, LowLinkException { ! sdHost = Host; ! sdPort = port; ! ! printInfo("Client: connecting to host " + Host + ":"+ port +". Please wait..."); ! do ! { ! ConnectionAttempts--; ! clientPort = mParentStack.ConnectTCP(this, sdHost, sdPort); ! } ! while (ConnectionAttempts>0 && clientPort==-1); ! if (clientPort>-1){ connected = true; return true; }else{ connected = false; return false; } ! } --- 77,91 ---- 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; ! } ! ! public boolean Disconnect() throws LowLinkException, CommunicationException, TransportLayerException ! { ! return mParentStack.SL().disconnect(appSock); ! } *************** *** 117,168 **** public void OnDisconnect(int sock){ ! connected = false; ! printInfo("Client: receive disconnect event"); ! terminal.recvData("\r\nServer closed connection.\r\n"); ! terminal.recvData("\r\nQUIT"); ! // try{ ! // printInfo("Client: receive disconnect event"); ! // Disconnect(); ! // } ! // catch(TransportLayerException e) { ! // printInfo("Client: can not disconnected: transport problem"); ! // } ! // catch(LowLinkException e) { ! // printInfo("Client: can not disconnected: low link problem"); ! // } ! // try{ ! // mParentStack.CloseTCP(this); ! // } ! // catch(TransportLayerException e){ ! // printInfo("Client: can not close port"); ! // } } public void OnError(int sock, int error){ ! ! } ! ! /** ! * This method disconnects from server. ! * @author key ! * @version v0.01 ! */ ! ! public void Disconnect() throws TransportLayerException, LowLinkException{ ! if(connected){ ! try{ ! mParentStack.FinalizeTCP(this); //will close client connection } - catch(CommunicationException e){ - printInfo("Client: can not disconnected: communication problem"); - } - printInfo("Client: closing connection."); - mParentStack.CloseTCP(this); - //mParentStack.freeTCPPort(this); - connected = false; } } - /** * This method sends data to the other side. --- 105,124 ---- 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; } } } /** * This method sends data to the other side. *************** *** 174,181 **** public void SendData(int sock, String Data) throws LowLinkException, TransportLayerException, CommunicationException { ! ! mParentStack.SendTCP(this, Data,-1); ! ! //processing the protocol doings. } --- 130,134 ---- public void SendData(int sock, String Data) throws LowLinkException, TransportLayerException, CommunicationException { ! mParentStack.SL().write(sock, Data); } *************** *** 190,213 **** */ public void RecvData(int sock, String Data) throws LowLinkException, TransportLayerException { ! //processing the protocol doings. ! // if(appType == 0){ ! //client processing recieve ! // printing some ... ! printInfo("Client: Recieving message '" + Data + "' from server."); ! ! if(Data.compareTo("\r\nQUIT")==0) { ! //System.out.println("\n\n\n-----------------------\nTelnet: RecvData: QUIT\n-------------------------------\n\n\n"); ! // connected = false; ! // Disconnect(); ! // terminal.recvData("Client: closing connection\n"); ! } ! terminal.recvData(Data); // } } - public void telnetCommand(String cmd){ - - } - /** * This method processes a telnet sending by client --- 143,151 ---- */ public void RecvData(int sock, String Data) throws LowLinkException, TransportLayerException { ! printLayerInfo("Client: Recieving message '" + Data + "' from server."); ! terminal.recvData(Data); // } } /** * This method processes a telnet sending by client *************** *** 220,275 **** */ public void TelnetConnect(TelnetEmulator emul, String Host, int port) throws CommunicationException, LowLinkException, InvalidNetworkLayerDeviceException, TransportLayerException{ - int i = 0; - i++; - mParentStack.FreeTCPApplication(this); - this.counts = counts; this.terminal = emul; if (Connect(Host, port)) { ! ! SendData("\r\n"); ! //SendData("!"); ! //terminal.recvData("Connected!\n"); ! //connected.... } else { ! printInfo("Client: error: can not connect to " + Host + ":" + port + "!"); terminal.recvData("Client: error: cannot connect to " + Host + ":" + port + "!"); - this.counts=0; } } ! /** ! * 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 ! { ! ! } ! ! public void printInfo(String s) { ! LayerInfo protInfo2 = new LayerInfo(getClass().getName()); ! protInfo2.setObjectName(mParentStack.getParentNodeName()); ! protInfo2.setDataType("Telnet Protocol Data"); ! protInfo2.setLayer("Application "); ! protInfo2.setDescription(s); ! Simulation.addLayerInfo(protInfo2); } --- 158,177 ---- */ public void TelnetConnect(TelnetEmulator emul, String Host, int port) throws CommunicationException, LowLinkException, InvalidNetworkLayerDeviceException, TransportLayerException{ this.terminal = emul; if (Connect(Host, port)) { ! //SendData("\r\n"); } else { ! printLayerInfo("Client: error: can not connect to " + Host + ":" + port + "!"); terminal.recvData("Client: error: cannot connect to " + Host + ":" + port + "!"); } } ! public void printLayerInfo(String s) { ! super.printLayerInfo("Telnet Protocol Data", s); } Index: socketLayer.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/core/protocolsuite/tcp_ip/socketLayer.java,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** socketLayer.java 28 Sep 2007 22:15:51 -0000 1.8 --- socketLayer.java 29 Sep 2007 20:33:36 -0000 1.9 *************** *** 73,77 **** result = mParentStack.TCP().connect(sock, ipaddr, port); } ! else if(jnsock.type == jnsock.TCP_socket){ result = true; } --- 73,90 ---- result = mParentStack.TCP().connect(sock, ipaddr, port); } ! else if(jnsock.type == jnsock.UDP_socket){ ! result = true; ! } ! return result; ! } ! ! public boolean disconnect(int sock) throws LowLinkException, CommunicationException, TransportLayerException{ ! boolean result = false; ! jnSocket jnsock = get_socket(sock); ! if(jnsock.type == jnsock.TCP_socket){ ! result = mParentStack.TCP().disconnect(sock); ! } ! else if(jnsock.type == jnsock.UDP_socket){ ! close(sock); result = true; } Index: Telnet_server.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/core/protocolsuite/tcp_ip/Telnet_server.java,v retrieving revision 1.15 retrieving revision 1.16 diff -C2 -d -r1.15 -r1.16 *** Telnet_server.java 25 Sep 2007 22:34:09 -0000 1.15 --- Telnet_server.java 29 Sep 2007 20:33:36 -0000 1.16 *************** *** 7,26 **** 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.ApplicationLayerDevice; - import core.Simulation; import java.util.regex.*; import core.Error; /** --- 7,17 ---- package core.protocolsuite.tcp_ip; import core.TransportLayerException; import core.CommunicationException; import core.LowLinkException; import core.ApplicationLayerDevice; import java.util.regex.*; import core.Error; + import java.util.Vector; /** *************** *** 31,39 **** public class Telnet_server extends Application{ - private int ConnectionAttempts=1; private ApplicationLayerDevice mDevice; ! private int counts; ! private String cmdline=""; ! private boolean isenter=true; private boolean islogin=false; private boolean ispass=false; --- 22,27 ---- public class Telnet_server extends Application{ private ApplicationLayerDevice mDevice; ! private String cmdline = ""; private boolean islogin=false; private boolean ispass=false; *************** *** 43,47 **** private String login = "root"; private String temp = ""; ! private boolean connected; /** Creates a new instance of Telnet Server */ --- 31,35 ---- private String login = "root"; private String temp = ""; ! private Vector<Integer> connections = new Vector<Integer>(1); /** Creates a new instance of Telnet Server */ *************** *** 49,57 **** super(inParentStack, listenPort, appType, UID); mDevice = dev; - counts = 0; - connected = false; - isenter=true; islogin=false; ispass=false; } --- 37,43 ---- super(inParentStack, listenPort, appType, UID); mDevice = dev; islogin=false; ispass=false; + appSock = mParentStack.SL().socket(jnSocket.TCP_socket, this); } *************** *** 63,68 **** public void Listen() throws TransportLayerException{ //throw new TransportLayerException("Cannot bind port " + listenPort + "."); ! mParentStack.ListenTCP(this, listenPort); ! isenter=true; islogin=false; ispass=false; --- 49,58 ---- public void Listen() throws TransportLayerException{ //throw new TransportLayerException("Cannot bind port " + listenPort + "."); ! try{ ! mParentStack.SL().bind(appSock, mParentStack.getSrcIP(), listenPort); ! mParentStack.SL().listen(appSock); ! }catch (TransportLayerException e){ ! System.out.println(e.toString());; ! } islogin=false; ispass=false; *************** *** 70,74 **** public void Accept(int listenSock, int sessionSock){ ! } --- 60,64 ---- public void Accept(int listenSock, int sessionSock){ ! connections.add(new Integer(sessionSock)); } *************** *** 82,87 **** public void Close() throws TransportLayerException { ! mParentStack.CloseTCP(this); ! isenter=true; islogin=false; ispass=false; --- 72,79 ---- public void Close() throws TransportLayerException { ! mParentStack.SL().close(appSock); ! for(int i=0; i<connections.size(); i++){ ! mParentStack.SL().close(connections.get(i).intValue()); ! } islogin=false; ispass=false; *************** *** 90,95 **** public void Free() throws TransportLayerException { ! mParentStack.FreeTCPApplication(this); ! isenter=true; islogin=false; ispass=false; --- 82,89 ---- public void Free() throws TransportLayerException { ! mParentStack.SL().free(appSock); ! for(int i=0; i<connections.size(); i++){ ! mParentStack.SL().free(connections.get(i).intValue()); ! } islogin=false; ispass=false; *************** *** 107,111 **** */ public void OnConnect(int sock){ ! connected = true; } --- 101,116 ---- */ public void OnConnect(int sock){ ! islogin = true; ! temp = ""; ! cmdline = ""; ! try{ ! SendData(sock, "\r\nlogin: "); ! }catch(LowLinkException e){ ! printLayerInfo(e.toString()); ! }catch(TransportLayerException e){ ! printLayerInfo(e.toString()); ! }catch(CommunicationException e){ ! printLayerInfo(e.toString()); ! } } *************** *** 117,165 **** public void OnDisconnect(int sock){ ! connected = false; ! ! printInfo("Server: client closed connection"); ! try{ ! Listen(); ! }catch(Exception e){ ! LayerInfo protInfo = new LayerInfo(getClass().getName()); ! protInfo.setObjectName(mParentStack.getParentNodeName()); ! protInfo.setDataType("Echo Protocol Data"); ! protInfo.setLayer("Application "); ! protInfo.setDescription("Cannot listen on port: " + e.toString()); ! Simulation.addLayerInfo(protInfo); ! protInfo = null; ! } } public void OnError(int sock, int error){ ! ! } ! ! /** ! * This method disconnects from server. ! * @author key ! * @version v0.01 ! */ ! ! public void Disconnect() throws TransportLayerException, LowLinkException{ ! connected = false; ! try { ! mParentStack.FinalizeTCP(this); //will close client connection ! }catch(CommunicationException e){ ! printInfo("Server: can not finalize TCP connection"); ! } ! Close(); ! Listen(); ! if(appType==0){ ! printInfo("Server: closing connection."); ! }else{ ! printInfo("Server: closing connection. Now listening on port " + listenPort + "."); } ! // mParentStack.CloseTCP(this); ! // mParentStack.freeTCPPort(this); ! } ! ! /** * This method sends data to the other side. --- 122,150 ---- public void OnDisconnect(int sock){ ! printLayerInfo("Server: client closed connection"); ! islogin=false; ! ispass=false; ! temp = ""; ! cmdline = ""; ! try{ ! connections.remove(new Integer(sock)); ! }catch(Exception e){ ! printLayerInfo("Cannot listen on port: " + e.toString()); ! } } 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; ! } } ! } ! /** * This method sends data to the other side. *************** *** 171,178 **** public void SendData(int sock, String Data) throws LowLinkException, TransportLayerException, CommunicationException { ! ! mParentStack.SendTCP(this, Data,-1); ! ! //processing the protocol doings. } --- 156,160 ---- public void SendData(int sock, String Data) throws LowLinkException, TransportLayerException, CommunicationException { ! mParentStack.SL().write(sock,Data); } *************** *** 187,337 **** */ public void RecvData(int sock, String Data) throws LowLinkException, TransportLayerException { ! //processing the protocol doings. ! //server processing recieve ! ! printInfo("Server: recieving message '" + Data + "' from client."); while(Data.length()>0) { String outData=""; ! if(isenter && Data.compareTo("\r\n")==0) { ! outData = "\r\nlogin: "; ! islogin = true; ! isenter = false; ! Data = Data.substring(1); ! } ! else ! { ! int ch = (char)Data.charAt(0); ! switch(ch) { ! case 0x04: { ! outData = "\r\nQUIT"; ! break; } ! case 0x08: { ! if(cmdline.length() > 0) { ! outData="\b"; ! cmdline = cmdline.substring(0,cmdline.length()-1); ! } ! break; ! } ! case 0xA: ! case 0xD: { ! if(islogin) { ! islogin = false; ! 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 { ! try { ! SendData("\r\nLogin or password is incorrect"); ! outData = "\r\nQUIT"; ! } ! catch(Exception e) { ! Error.Report(e); ! } } } ! else if(isnewpass) { ! 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; ! temp=""; } } ! else { ! outData = "\r\n" + runcmd(removeSpaces(cmdline)); ! } ! cmdline = ""; ! if(ch==0xD && (char)Data.charAt(1)==0xA) ! Data = Data.substring(1); ! break; ! } // case 0x1B: outData="ESC"; break; ! default: ! if(ch>=0x20 && ch<0x80) ! { ! 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) + ">"; } ! } ! } ! if(outData.compareTo("\r\nQUIT")==0) { ! Disconnect(); ! // try{ ! // Close(); ! // } ! // catch(TransportLayerException e){ ! // printInfo("Server: can not close application port"); ! // } ! // printInfo("Server: closed connection"); ! // try{ ! // Listen(); ! // } ! // catch(TransportLayerException e){ ! // printInfo("Server: can not listen on application port"); ! // } ! // printInfo("Server: listening on port " + listenPort); ! isenter = true; } ! else{ ! printInfo("Server: sending message '" + outData + "' to client."); ! try{ ! SendData(outData); } ! catch(CommunicationException e){ ! printInfo("Server: can not send data packet: communication error"); } } Data = Data.substring(1); } } - - /** - * 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 - { - - } - private String runcmd(String cmd) { String out=""; --- 169,266 ---- */ public void RecvData(int sock, String Data) throws LowLinkException, TransportLayerException { ! ! 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); } ! break; ! } ! case 0xA: ! case 0xD: { ! if(islogin) { ! islogin = false; ! 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 { ! try { ! SendData(sock,"\r\nLogin or password is incorrect"); ! outData = ""; } ! catch(Exception e) { ! Error.Report(e); } } ! } ! else if(isnewpass) { ! 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; + temp=""; } ! } ! else { ! outData = "\r\n" + runcmd(removeSpaces(cmdline)); ! } ! cmdline = ""; ! if(ch==0xD && (char)Data.charAt(1)==0xA) ! Data = Data.substring(1); ! break; ! } // case 0x1B: outData="ESC"; break; ! default: ! if(ch>=0x20 && ch<0x80) ! { ! 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); } } private String runcmd(String cmd) { String out=""; *************** *** 349,353 **** } else if(cmd.compareToIgnoreCase("quit")==0) { ! return "QUIT"; } else { --- 278,282 ---- } else if(cmd.compareToIgnoreCase("quit")==0) { ! return ""; } else { *************** *** 488,498 **** } ! private void printInfo(String s) { ! LayerInfo protInfo3 = new LayerInfo(getClass().getName()); ! protInfo3.setObjectName(mParentStack.getParentNodeName()); ! protInfo3.setDataType("Telnet Protocol Data"); ! protInfo3.setLayer("Application "); ! protInfo3.setDescription(s); ! Simulation.addLayerInfo(protInfo3); } --- 417,422 ---- } ! protected void printLayerInfo(String s) { ! super.printLayerInfo("Telnet Protocol Data", s); } Index: Tcp.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/core/protocolsuite/tcp_ip/Tcp.java,v retrieving revision 1.96 retrieving revision 1.97 diff -C2 -d -r1.96 -r1.97 *** Tcp.java 28 Sep 2007 22:15:51 -0000 1.96 --- Tcp.java 29 Sep 2007 20:33:35 -0000 1.97 *************** *** 536,541 **** public void sendTCPData(int sock, String data) throws TransportLayerException, LowLinkException, CommunicationException { ! boolean flags[] = genFlags(NOFLAGS); ! sendTCPSegment(sock, data, flags, -1, resendtimes_DEFAULT); } --- 536,543 ---- public void sendTCPData(int sock, String data) throws TransportLayerException, LowLinkException, CommunicationException { ! if(data.length()>0){ ! boolean flags[] = genFlags(NOFLAGS); ! sendTCPSegment(sock, data, flags, -1, resendtimes_DEFAULT); ! } } *************** *** 557,563 **** private boolean sendTCPSegment(int sock, String inTCPMessage, boolean flags[], int acknow_num, int resendtimes[]) throws TransportLayerException, LowLinkException, CommunicationException ! { TCP_packet tosend = getTCPPacket_tosend(sock,inTCPMessage,flags,acknow_num, -1); ! jnSocket jnsock = mSL.get_socket(sock); int srcPort = jnsock.src_port; --- 559,565 ---- private boolean sendTCPSegment(int sock, String inTCPMessage, boolean flags[], int acknow_num, int resendtimes[]) throws TransportLayerException, LowLinkException, CommunicationException ! { TCP_packet tosend = getTCPPacket_tosend(sock,inTCPMessage,flags,acknow_num, -1); ! jnSocket jnsock = mSL.get_socket(sock); int srcPort = jnsock.src_port; *************** *** 565,569 **** int dstPort = jnsock.dst_port; TCP_session Elm = getSession(jnsock.genKey()); ! Elm.addSendingSegment(tosend, resendtimes); trySendSegments(Elm); --- 567,571 ---- int dstPort = jnsock.dst_port; TCP_session Elm = getSession(jnsock.genKey()); ! Elm.addSendingSegment(tosend, resendtimes); trySendSegments(Elm); *************** *** 624,649 **** TCP_packet tosend = new TCP_packet(dstIP,srcIP,dstPort,srcPort); ! //s_num = (flags[1] && !flags[4] && !flags[5]) ? -1 : Elm.seq_number; //getting sequence number 0-for SYN, -1 for ACK ! if(seq_num == -1 || seq_num > Elm.seq_number) seq_num = Elm.seq_number; //getting sequence number 0-for SYN, -1 for ACK ! if(acknow_num==-1) acknow_num = Elm.getLastACK(); ! //now we set all the flags ! /* URG, ACK, PSH, RST, SYN, FIN */ ! tosend.set_URG_flag(flags[URG_flag]); ! tosend.set_ACK_flag(flags[ACK_flag]); ! tosend.set_PSH_flag(flags[PSH_flag]); ! tosend.set_RST_flag(flags[RST_flag]); ! tosend.set_SYN_flag(flags[SYN_flag]); ! tosend.set_FIN_flag(flags[FIN_flag]); ! tosend.set_sequence_number(seq_num); ! tosend.set_acknowledgment_number(acknow_num); ! tosend.setTCP_message(inMessage); ! //counters inc ! Elm.inc_sent_segments(); ! if(seq_num == Elm.seq_number && (!(flags[ACK_flag] || flags[RST_flag]) || flags[SYN_flag] || flags[FIN_flag])) ! Elm.seq_number++; ! 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) --- 626,655 ---- 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(); ! //now we set all the flags ! /* URG, ACK, PSH, RST, SYN, FIN */ ! tosend.set_URG_flag(flags[URG_flag]); ! tosend.set_ACK_flag(flags[ACK_flag]); ! tosend.set_PSH_flag(flags[PSH_flag]); ! tosend.set_RST_flag(flags[RST_flag]); ! tosend.set_SYN_flag(flags[SYN_flag]); ! tosend.set_FIN_flag(flags[FIN_flag]); ! tosend.set_sequence_number(seq_num); ! tosend.set_acknowledgment_number(acknow_num); ! tosend.setTCP_message(inMessage); ! //counters inc ! Elm.inc_sent_segments(); ! if(seq_num == Elm.seq_number && (!(flags[ACK_flag] || flags[RST_flag]) || flags[SYN_flag] || flags[FIN_flag])) ! Elm.seq_number++; ! 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()); ! // } *************** *** 705,708 **** --- 711,717 ---- Elm.setState(Elm.LISTEN); } + else{ + int i = 0; + } } if (Elm !=null) Index: Application.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/core/protocolsuite/tcp_ip/Application.java,v retrieving revision 1.21 retrieving revision 1.22 diff -C2 -d -r1.21 -r1.22 *** Application.java 25 Sep 2007 22:34:09 -0000 1.21 --- Application.java 29 Sep 2007 20:33:35 -0000 1.22 *************** *** 94,98 **** public void SendData(String Data) throws LowLinkException, TransportLayerException, CommunicationException { ! SendData(appSock, Data); } --- 94,99 ---- public void SendData(String Data) throws LowLinkException, TransportLayerException, CommunicationException { ! if(Data.length() > 0) ! SendData(appSock, Data); } Index: Echo_tcp.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/core/protocolsuite/tcp_ip/Echo_tcp.java,v retrieving revision 1.37 retrieving revision 1.38 diff -C2 -d -r1.37 -r1.38 *** Echo_tcp.java 28 Sep 2007 22:15:51 -0000 1.37 --- Echo_tcp.java 29 Sep 2007 20:33:35 -0000 1.38 *************** *** 60,64 **** public void Accept(int listenSock, int sessionSock){ connections.add(new Integer(sessionSock)); ! System.out.println("Accepted socket="+sessionSock+" for listen socket="+listenSock); } --- 60,64 ---- public void Accept(int listenSock, int sessionSock){ connections.add(new Integer(sessionSock)); ! //System.out.println("Accepted socket="+sessionSock+" for listen socket="+listenSock); } *************** *** 160,164 **** } } - } --- 160,163 ---- *************** *** 203,207 **** printLayerInfo("Connection time: " + (long)(System.currentTimeMillis () - utc1) + " ms. Total recieved messages: " + recieved + "."); try{ ! mParentStack.TCP().disconnect(sock); }catch(CommunicationException e){ System.out.println(e.toString()); --- 202,206 ---- printLayerInfo("Connection time: " + (long)(System.currentTimeMillis () - utc1) + " ms. Total recieved messages: " + recieved + "."); try{ ! mParentStack.SL().disconnect(sock); }catch(CommunicationException e){ System.out.println(e.toString()); |