[Javanetsim-cvs] javaNetSim/core/protocolsuite/tcp_ip TCP_session.java, NONE, 1.1 UDP_session.java,
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-serv29666/core/protocolsuite/tcp_ip Modified Files: Application.java Echo.java Echo_tcp.java ExternalProxyApp.java PosixTelnetClient.java SNMP.java Tcp.java Telnet_client.java Telnet_server.java Udp.java jnSocket.java socketLayer.java Added Files: TCP_session.java UDP_session.java jnSession.java Log Message: sessions was added partially Index: Telnet_client.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/core/protocolsuite/tcp_ip/Telnet_client.java,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** Telnet_client.java 5 Sep 2006 21:04:36 -0000 1.9 --- Telnet_client.java 18 Sep 2007 22:29:46 -0000 1.10 *************** *** 46,50 **** */ public void Listen() throws TransportLayerException{ ! throw new TransportLayerException("Cannot bind port " + listenPort + "."); } --- 46,54 ---- */ public void Listen() throws TransportLayerException{ ! throw new TransportLayerException("Cannot bind port " + listenPort + "."); ! } ! ! public void Accept(int listenSock, int sessionSock) throws TransportLayerException{ ! } *************** *** 59,62 **** --- 63,73 ---- { if(!already_closed){ + mParentStack.CloseTCP(this); + already_closed = true; + } + } + + public void Free() throws TransportLayerException{ + if(!already_closed){ mParentStack.FreeTCPApplication(this); already_closed = true; *************** *** 73,77 **** */ ! public boolean ClientConnect(String Host, int port) throws TransportLayerException, InvalidNetworkLayerDeviceException, CommunicationException, LowLinkException { sdHost = Host; --- 84,88 ---- */ ! public boolean Connect(String Host, int port) throws TransportLayerException, InvalidNetworkLayerDeviceException, CommunicationException, LowLinkException { sdHost = Host; *************** *** 96,102 **** * @version v0.01 */ ! public void Connected(String Host, int port){ ! sdHost = Host; ! sdPort = port; } --- 107,111 ---- * @version v0.01 */ ! public void OnConnect(int sock){ } *************** *** 107,115 **** */ ! public void DisconnectEvent(){ connected = false; printInfo("Client: receive disconnect event"); ! terminal.recvData("\nServer closed connection.\n"); ! terminal.recvData("\nQUIT"); // try{ // printInfo("Client: receive disconnect event"); --- 116,124 ---- */ ! 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"); *************** *** 183,188 **** printInfo("Client: Recieving message '" + Data + "' from server."); ! if(Data.compareTo("\nQUIT")==0) { ! System.out.println("\n\n\n-----------------------\nTelnet: RecvData: QUIT\n-------------------------------\n\n\n"); // connected = false; // Disconnect(); --- 192,197 ---- 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(); *************** *** 214,221 **** this.terminal = emul; ! if (ClientConnect(Host, port)) { ! SendData("\n"); //SendData("!"); //terminal.recvData("Connected!\n"); --- 223,230 ---- this.terminal = emul; ! if (Connect(Host, port)) { ! SendData("\r\n"); //SendData("!"); //terminal.recvData("Connected!\n"); Index: socketLayer.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/core/protocolsuite/tcp_ip/socketLayer.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** socketLayer.java 16 Sep 2007 19:39:35 -0000 1.1 --- socketLayer.java 18 Sep 2007 22:29:46 -0000 1.2 *************** *** 2,22 **** import java.io.Serializable; - import java.util.*; - import core.CommunicationException; - import core.LowLinkException; - import core.LayerInfo; - import core.Simulation; - import core.TransportLayerException; - import core.TransportLayerPortException; - import core.InvalidNetworkLayerDeviceException; - import core.protocolsuite.tcp_ip.ProtocolStack; /** --- 2,13 ---- *************** *** 29,34 **** int lastSock; - - /** Creates a new instance of socketLayer */ public socketLayer(ProtocolStack inParentStack) { --- 20,23 ---- *************** *** 80,83 **** --- 69,80 ---- } + public void recv(int sock, String data) throws LowLinkException, TransportLayerException{ + if(sock < lastSock){ + if(((jnSocket)sockTable.get(sock)).open_state == true){ + ((jnSocket)sockTable.get(sock)).app.RecvData(data); + } + } + } + public void recvFrom(int sock, String IP, int port, String data) throws LowLinkException, TransportLayerException{ if(sock < lastSock){ *************** *** 91,98 **** //DEPRECATED IN SOON ! ((jnSocket)sockTable.get(sock)).app.RecvIP(IP); ! ((jnSocket)sockTable.get(sock)).app.RecvPrt(port); //^^^^^^^^^^^^^^^^ ((jnSocket)sockTable.get(sock)).app.RecvData(data); } --- 88,96 ---- //DEPRECATED IN SOON ! //((jnSocket)sockTable.get(sock)).app.RecvIP(IP); ! //((jnSocket)sockTable.get(sock)).app.RecvPrt(port); //^^^^^^^^^^^^^^^^ + ((jnSocket)sockTable.get(sock)).app.OnConnect(sock); ((jnSocket)sockTable.get(sock)).app.RecvData(data); } *************** *** 112,115 **** ((jnSocket)sockTable.get(sock)).app = null; ((jnSocket)sockTable.get(sock)).open_state = false; ! } } --- 110,113 ---- ((jnSocket)sockTable.get(sock)).app = null; ((jnSocket)sockTable.get(sock)).open_state = false; ! } } Index: Udp.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/core/protocolsuite/tcp_ip/Udp.java,v retrieving revision 1.35 retrieving revision 1.36 diff -C2 -d -r1.35 -r1.36 *** Udp.java 16 Sep 2007 19:38:04 -0000 1.35 --- Udp.java 18 Sep 2007 22:29:46 -0000 1.36 *************** *** 1,108 **** /* - Java Firewall Simulator (jFirewallSim) - - Copyright (c) 2004, jFirewallSim development team All rights reserved. - - Redistribution and use in source and binary forms, with or without modification, are - permitted provided that the following conditions are met: - - - Redistributions of source code must retain the above copyright notice, this list - of conditions and the following disclaimer. - - Redistributions in binary form must reproduce the above copyright notice, this list - of conditions and the following disclaimer in the documentation and/or other - materials provided with the distribution. - - Neither the name of the Canberra Institute of Technology nor the names of its - contributors may be used to endorse or promote products derived from this software - without specific prior written permission. - - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY - EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL - THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR - TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, - EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ package core.protocolsuite.tcp_ip; - - import java.io.Serializable; - import java.util.*; - import core.CommunicationException; - import core.LowLinkException; - import core.LayerInfo; - import core.Simulation; - import core.TransportLayerException; - import core.TransportLayerPortException; - import core.InvalidNetworkLayerDeviceException; - import core.protocolsuite.tcp_ip.ProtocolStack; /** - * This UDP class is constructed in a way that it represents its real world cousin (the UDP protocol) as accurately - * as possible. - - * <P>This class contains methods which allow the transfer of packets to and from the lower layer. (Network Layer - IP - * only at this stage). During a packets stay in this class, UDP headers are added, removed and examined - * depending on wether the packet is in compilation or decompilation. During compilation, a packet is created, headers are added (all based - * on real world UDP specification) and the packet is passed onto NetworkLayer (IP). During decompilation - * UDP headers are removed and the data that was contained in the packet is passed onto the ProtocolStack. Relavent - * information about what is happening in this class is added to the LayerInfo object so that it can be displayed - * to the user in a clear and concise way.</P> - * - * @author james_nikolaidis - * @since 10/06/2004 - * @author gift (sourceforge.net user) * @since 17 Nov 2005 --- 1,57 ---- *************** *** 110,115 **** */ - - public class Udp implements Serializable { --- 59,62 ---- *************** *** 133,142 **** } ! public class UDP_session{ ! public byte PortStatus=0; // 0 - free port; 1 - port is being listened to; 2 - busy. ! public int sock=-1; // socket... ! } ! ! private Hashtable PortTable = new Hashtable(); private ProtocolStack mParentStack; --- 80,84 ---- } ! private Hashtable sessionTable = new Hashtable(); private ProtocolStack mParentStack; *************** *** 192,196 **** // test if destination UDP port exists on this NeworkLayerDevice ! if (PortTable.get((Integer)inPacket.get_destPort()) !=null) { --- 134,138 ---- // test if destination UDP port exists on this NeworkLayerDevice ! if (sessionTable.get(jnSocket.genUDPkey(inPacket.get_destPort())) !=null) { *************** *** 198,237 **** //UDP_HashTableElement Elm = null; UDP_session Elm = null; ! Elm=(UDP_session)PortTable.get(inPacket.get_destPort()); int sock = Elm.sock; ! switch(Elm.PortStatus) ! { ! case 0: //port is free => Error: no application to receive UDP ! //have to disconnect listener from port ! throw new TransportLayerPortException("UDP Error: no application binded port "+inPacket.get_destPort() +" on host \""+ mParentStack.getParentNodeName()+"\"!"); ! //no break needed ;) ! case 1: // port is binded ! //now we decompose UDP datagram ! ! IncReceivedDatagrammsNumber(); ! ! //Create Layer info ! LayerInfo UDP_Info = new LayerInfo(getClass().getName()); ! ! UDP_Info.setObjectName(mParentStack.getParentNodeName()); ! ! UDP_Info.setDataType("UDP Protocol"); ! ! UDP_Info.setLayer("Transport"); ! ! UDP_Info.setDescription("UDP packet received from "+ inPacket.getSourceIPAddress() + ":" + inPacket.get_srcPort() + " message: \"" +inPacket.getUDP_message() + "\"."); // + " UDP Port " + inPacket.get_destPort() + " has status \"busy\" from now."); ! ! Simulation.addLayerInfo(UDP_Info); ! mSL.recvFrom(sock, inPacket.getSourceIPAddress(), inPacket.get_srcPort(), inPacket.getUDP_message()); ! break; ! default: //UDP Error: unknown port status :( ! //have to disconnect listener from port ! throw new TransportLayerPortException("UDP Error: unknown port status! Port "+inPacket.get_destPort() +" on host \""+ mParentStack.getParentNodeName()+"\"."); ! } } else { ! throw new TransportLayerPortException("UDP Error: port " + inPacket.get_destPort() + " does not exist. Host \"" + mParentStack.getParentNodeName()+"\"."); } } --- 140,162 ---- //UDP_HashTableElement Elm = null; UDP_session Elm = null; ! Elm=(UDP_session) sessionTable.get(jnSocket.genUDPkey(inPacket.get_destPort())); int sock = Elm.sock; ! //now we decompose UDP datagram ! IncReceivedDatagrammsNumber(); ! Elm.IncReceivedDatagrammsNumber(); ! //Create Layer info ! LayerInfo UDP_Info = new LayerInfo(getClass().getName()); ! UDP_Info.setObjectName(mParentStack.getParentNodeName()); ! UDP_Info.setDataType("UDP Protocol"); ! UDP_Info.setLayer("Transport"); ! UDP_Info.setDescription("UDP packet received from "+ inPacket.getSourceIPAddress() + ":" + inPacket.get_srcPort() + " message: \"" +inPacket.getUDP_message() + "\"."); // + " UDP Port " + inPacket.get_destPort() + " has status \"busy\" from now."); ! Simulation.addLayerInfo(UDP_Info); ! mSL.recvFrom(sock, inPacket.getSourceIPAddress(), inPacket.get_srcPort(), inPacket.getUDP_message()); } else { ! //throw new TransportLayerPortException("UDP Error: port " + inPacket.get_destPort() + " does not exist. Host \"" + mParentStack.getParentNodeName()+"\"."); ! throw new TransportLayerPortException("UDP Error: no application binded port "+inPacket.get_destPort() +" on host \""+ mParentStack.getParentNodeName()+"\"!"); } } *************** *** 265,269 **** try{ ! if(mSL.get_socket(sock).src_port == 0){ // we should reserve port for it ReserveFreePort(sock); --- 190,194 ---- try{ ! if(sessionTable.get(jnSocket.genUDPkey(mSL.get_socket(sock).src_port)) == null){ // we should reserve port for it ReserveFreePort(sock); *************** *** 286,290 **** Simulation.addLayerInfo(UDP_Info); ! IncSentDatagrammsNumber(); mParentStack.sendPacket(tosend); --- 211,219 ---- Simulation.addLayerInfo(UDP_Info); ! IncSentDatagrammsNumber(); ! if (sessionTable.get(jnSocket.genUDPkey(insrcPort)) !=null) ! { ! ((UDP_session)sessionTable.get(jnSocket.genUDPkey(insrcPort))).IncSentDatagrammsNumber(); ! } mParentStack.sendPacket(tosend); *************** *** 318,325 **** public void ReserveFreePort(int sock) throws TransportLayerException { ! Integer number = new Integer(0); boolean Found=false; ! boolean Reserved=false; ! Enumeration LocalPorts = PortTable.keys(); --- 247,253 ---- public void ReserveFreePort(int sock) throws TransportLayerException { ! String sessionID; boolean Found=false; ! Enumeration LocalSessions = sessionTable.keys(); *************** *** 327,343 **** // check if socket already busy ! while ( (LocalPorts.hasMoreElements()) && !(Found) ) { ! number = (Integer) LocalPorts.nextElement(); ! ! ! Elm = (UDP_session) PortTable.get(number); ! ! if ( sock == Elm.sock && Elm.sock >=0 ) { Found=true; throw new TransportLayerException("UDP Error: socket is already busy (have port)!"); ! } } --- 255,267 ---- // check if socket already busy ! while ( (LocalSessions.hasMoreElements()) && !(Found) ) { ! sessionID = (String)LocalSessions.nextElement(); ! Elm = (UDP_session) sessionTable.get(sessionID); if ( sock == Elm.sock && Elm.sock >=0 ) { Found=true; throw new TransportLayerException("UDP Error: socket is already busy (have port)!"); ! } } *************** *** 346,362 **** { //lets try to reserve any free port ! number=PORT_START_NUMBER; while ( (number<PORT_START_NUMBER+PORT_QUANT) && !(Reserved) ) { ! Elm = (UDP_session) PortTable.get((Integer)number); ! if (Elm == null) //free port { Reserved=true; ! Elm = new UDP_session(); ! Elm.PortStatus=1; //port will be busy from now Elm.sock = sock; mSL.get_socket(sock).src_port = number; ! PortTable.put(new Integer(number),Elm); LayerInfo UDP_Info = new LayerInfo(getClass().getName()); UDP_Info.setObjectName(mParentStack.getParentNodeName()); --- 270,285 ---- { //lets try to reserve any free port ! int number=PORT_START_NUMBER; ! boolean Reserved=false; while ( (number<PORT_START_NUMBER+PORT_QUANT) && !(Reserved) ) { ! Elm = (UDP_session) sessionTable.get(jnSocket.genUDPkey(number)); if (Elm == null) //free port { Reserved=true; ! Elm = new UDP_session(); Elm.sock = sock; mSL.get_socket(sock).src_port = number; ! sessionTable.put(jnSocket.genUDPkey(number),Elm); LayerInfo UDP_Info = new LayerInfo(getClass().getName()); UDP_Info.setObjectName(mParentStack.getParentNodeName()); *************** *** 365,371 **** UDP_Info.setDescription("Local port " + number + " reserved for client app."); Simulation.addLayerInfo(UDP_Info); ! } ! ! if (!Reserved) number++; } --- 288,293 ---- UDP_Info.setDescription("Local port " + number + " reserved for client app."); Simulation.addLayerInfo(UDP_Info); ! } ! number++; } *************** *** 381,420 **** { int lsPort=PORT_INIT; - Integer inPort = new Integer(in_Port); if ( mSL.get_socket(sock_num).src_port == 0 ) { ! if (inPort>=0 && inPort<=10000) { ! UDP_session Elm = null; ! ! if ( (Elm =(UDP_session)PortTable.get(inPort)) !=null ) ! { ! switch(Elm.PortStatus) ! { ! case 0: //port is free => update such a record in hashtable ! Elm.PortStatus=1; ! Elm.sock = sock_num; ! mSL.get_socket(sock_num).src_port = in_Port; ! break; ! case 1: // port is being listened to by whom? ! if (sock_num==Elm.sock) ! { ! throw new TransportLayerException("error: already binded to port "+ inPort +"!"); ! } else throw new TransportLayerException("error: port "+ inPort +" is binded by another application! Can bind only to free ports." ); ! default: //unknown port status ! throw new TransportLayerException("error: unknown port status! Port "+ inPort +" on host \""+ mParentStack.getParentNodeName()+"\"."); ! } ! ! } else ! { //create such a record in hashtable UDP_session newElm = new UDP_session(); - newElm.PortStatus=1; newElm.sock = sock_num; mSL.get_socket(sock_num).src_port = in_Port; ! PortTable.put(inPort,newElm); //hash table update ! } LayerInfo UDP_Info = new LayerInfo(getClass().getName()); UDP_Info.setObjectName(mParentStack.getParentNodeName()); --- 303,340 ---- { int lsPort=PORT_INIT; if ( mSL.get_socket(sock_num).src_port == 0 ) { ! if (in_Port>=0 && in_Port<=65535) { ! // UDP_session Elm = null; ! // ! // if ( (Elm =(UDP_session)sessionTable.get(jnSocket.genUDPkey(inPort))) !=null ) ! // { ! // switch(Elm.PortStatus) ! // { ! // case 0: //port is free => update such a record in hashtable ! // Elm.PortStatus=1; ! // Elm.sock = sock_num; ! // mSL.get_socket(sock_num).src_port = in_Port; ! // break; ! // case 1: // port is being listened to by whom? ! // if (sock_num==Elm.sock) ! // { ! // throw new TransportLayerException("error: already binded to port "+ inPort +"!"); ! // } else throw new TransportLayerException("error: port "+ inPort +" is binded by another application! Can bind only to free ports." ); ! // default: //unknown port status ! // throw new TransportLayerException("error: unknown port status! Port "+ inPort +" on host \""+ mParentStack.getParentNodeName()+"\"."); ! // } ! // ! // } else ! // { //create such a record in hashtable UDP_session newElm = new UDP_session(); newElm.sock = sock_num; mSL.get_socket(sock_num).src_port = in_Port; ! sessionTable.put(jnSocket.genUDPkey(in_Port),newElm); //hash table update ! // } LayerInfo UDP_Info = new LayerInfo(getClass().getName()); UDP_Info.setObjectName(mParentStack.getParentNodeName()); *************** *** 425,434 **** } else // { ! throw new TransportLayerException("error: can not listen to port "+ inPort +"! Use port range from 0 to 10000 to listen to."); } } else // { ! if (mSL.get_socket(sock_num).src_port==inPort) throw new TransportLayerException("error: can not double listen to port "+ inPort +"! Server is already listening to this port"); ! throw new TransportLayerException("error: can not listen to port "+ inPort +"! Already listening to port " + lsPort); } } --- 345,354 ---- } else // { ! throw new TransportLayerException("error: can not listen to port "+ in_Port +"! Use port range from 1 to 65535 to listen to."); } } else // { ! if (mSL.get_socket(sock_num).src_port==in_Port) throw new TransportLayerException("error: can not double listen to port "+ in_Port +"! Server is already listening to this port"); ! throw new TransportLayerException("error: can not listen to port "+ in_Port +"! Already listening to port " + lsPort); } } *************** *** 446,466 **** { UDP_session Elm=null; ! Integer PortToClose=mSL.get_socket(sock).src_port; ! Elm=(UDP_session) PortTable.get((Integer)PortToClose); ! if(PortToClose!=0 && Elm!=null){ ! if (Elm.PortStatus==1) ! { ! Elm.PortStatus=0; ! Elm.sock = -1; 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 " + PortToClose + " closed and set to free."); Simulation.addLayerInfo(UDP_Info); ! PortTable.remove((Integer)PortToClose); ! } else throw new TransportLayerException("UDP Error: port "+ PortToClose +" is not being LISTENED to by the application: \"" + mSL.get_socket(sock).app.toString() + "\"."); ! } else throw new TransportLayerException("UDP Error: port "+ PortToClose +" is not being LISTENED to by the application: \"" + mSL.get_socket(sock).app.toString() + "\"."); } /*STATISTIC PART */ --- 366,382 ---- { UDP_session Elm=null; ! int portToClose=mSL.get_socket(sock).src_port; ! Elm=(UDP_session) sessionTable.get(jnSocket.genUDPkey(portToClose)); ! if(portToClose!=0 && Elm!=null){ 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 " + portToClose + " closed and set to free."); Simulation.addLayerInfo(UDP_Info); ! sessionTable.remove(jnSocket.genUDPkey(portToClose)); ! mSL.close(Elm.sock); ! } else throw new TransportLayerException("UDP Error: port "+ portToClose +" is not being LISTENED to by the application: \"" + mSL.get_socket(sock).app.toString() + "\"."); } /*STATISTIC PART */ *************** *** 476,480 **** public void IncReceivedDatagrammsNumber() { ! received_datagramms++; } --- 392,396 ---- public void IncReceivedDatagrammsNumber() { ! received_datagramms++; } *************** *** 489,493 **** public void IncSentDatagrammsNumber() { ! sent_datagramm++; } --- 405,409 ---- public void IncSentDatagrammsNumber() { ! sent_datagramm++; } Index: Telnet_server.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/core/protocolsuite/tcp_ip/Telnet_server.java,v retrieving revision 1.11 retrieving revision 1.12 diff -C2 -d -r1.11 -r1.12 *** Telnet_server.java 8 Nov 2006 14:27:29 -0000 1.11 --- Telnet_server.java 18 Sep 2007 22:29:46 -0000 1.12 *************** *** 51,54 **** --- 51,57 ---- counts = 0; connected = false; + isenter=true; + islogin=false; + ispass=false; } *************** *** 61,65 **** //throw new TransportLayerException("Cannot bind port " + listenPort + "."); mParentStack.ListenTCP(this, listenPort); ! isenter = true; } --- 64,74 ---- //throw new TransportLayerException("Cannot bind port " + listenPort + "."); mParentStack.ListenTCP(this, listenPort); ! isenter=true; ! islogin=false; ! ispass=false; ! } ! ! public void Accept(int listenSock, int sessionSock) throws TransportLayerException{ ! } *************** *** 73,84 **** public void Close() throws TransportLayerException { mParentStack.FreeTCPApplication(this); ! isenter = true; } ! public boolean ClientConnect(String temp1, int temp2){ return false; } /** * This method should be called from TCP when client connects to server --- 82,104 ---- public void Close() throws TransportLayerException { + mParentStack.CloseTCP(this); + isenter=true; + islogin=false; + ispass=false; + } + + public void Free() throws TransportLayerException + { mParentStack.FreeTCPApplication(this); ! isenter=true; ! islogin=false; ! ispass=false; } ! public boolean Connect(String temp1, int temp2){ return false; } + /** * This method should be called from TCP when client connects to server *************** *** 86,92 **** * @version v0.01 */ ! public void Connected(String Host, int port){ ! sdHost = Host; ! sdPort = port; connected = true; } --- 106,110 ---- * @version v0.01 */ ! public void OnConnect(int sock){ connected = true; } *************** *** 98,102 **** */ ! public void DisconnectEvent(){ connected = false; --- 116,120 ---- */ ! public void OnDisconnect(int sock){ connected = false; *************** *** 172,179 **** while(Data.length()>0) { String outData=""; ! if(isenter && Data.compareTo("\n")==0) { ! outData = "login: "; islogin = true; isenter = false; } else --- 190,198 ---- 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 *************** *** 182,186 **** switch(ch) { case 0x04: { ! outData = "\nQUIT"; break; } --- 201,205 ---- switch(ch) { case 0x04: { ! outData = "\r\nQUIT"; break; } *************** *** 192,211 **** break; } ! case 0xA: { if(islogin) { islogin = false; temp = cmdline; ispass = true; ! outData = "\npassword: "; } else if(ispass) { ispass = false; if(temp.compareTo(login)==0 && cmdline.compareTo(password)==0) { ! outData = "\nWelcome to " + mParentStack.getParentNodeName() + "\n" + runcmd(""); } else { try { ! SendData("\nLogin or password is incorrect"); ! outData = "\nQUIT"; } catch(Exception e) { --- 211,231 ---- 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) { *************** *** 217,229 **** if(temp.compareTo("")==0) { temp = cmdline; ! outData = "\nRetype new password: "; } else { if(temp.compareTo(cmdline)==0) { password = temp; ! outData = "\n" + runcmd(""); } else { ! outData = "\n Password is not identical\n" + runcmd(""); } isnewpass = false; --- 237,249 ---- 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; *************** *** 232,238 **** } else { ! outData = "\n" + runcmd(removeSpaces(cmdline)); } cmdline = ""; break; } --- 252,260 ---- } else { ! outData = "\r\n" + runcmd(removeSpaces(cmdline)); } cmdline = ""; + if(ch==0xD && (char)Data.charAt(1)==0xA) + Data = Data.substring(1); break; } *************** *** 254,258 **** } } ! if(outData.compareTo("\nQUIT")==0) { Disconnect(); // try{ --- 276,280 ---- } } ! if(outData.compareTo("\r\nQUIT")==0) { Disconnect(); // try{ *************** *** 314,324 **** } else if(cmd.compareTo("?")==0 || cmd.compareToIgnoreCase("help")==0) { ! out += " route \t show/edit route table\n"; ! out += " arp \t show/edit arp table\n"; ! out += " snmp \t on/off snmp agent\n"; ! out += " counters\t show network counters\n"; ! out += " passwd \t change password\n"; ! out += " quit \t close terminal session\n"; ! out += " ? or help\tshow this screen\n"; } else if(cmd.compareToIgnoreCase("quit")==0) { --- 336,346 ---- } else if(cmd.compareTo("?")==0 || cmd.compareToIgnoreCase("help")==0) { ! out += " route \t show/edit route table\r\n"; ! out += " arp \t show/edit arp table\r\n"; ! out += " snmp \t on/off snmp agent\r\n"; ! out += " counters\t show network counters\r\n"; ! out += " passwd \t change password\r\n"; ! out += " quit \t close terminal session\r\n"; ! out += " ? or help\tshow this screen\r\n"; } else if(cmd.compareToIgnoreCase("quit")==0) { *************** *** 332,339 **** String routes[] = mParentStack.getRouteTableEntries(); ! out += "IP routing table:\n" + "Destination" + "\t" + "Gateway" + "\t" + "Genmask" + "\t" + "Type" + "\t" + "Iface\n"; for(int i=0; i<routes.length - 1; i++){ Route_entry r = mParentStack.getRouteTableEntry(routes[i]); ! out += routes[i] + "\t" + r.gateway + "\t" + r.genMask + "\t" + r.Type + "\t" + r.iFace + "\n"; } } --- 354,361 ---- String routes[] = mParentStack.getRouteTableEntries(); ! out += "IP routing table:\r\n" + "Destination" + "\t" + "Gateway" + "\t" + "Genmask" + "\t" + "Type" + "\t" + "Iface\r\n"; for(int i=0; i<routes.length - 1; i++){ Route_entry r = mParentStack.getRouteTableEntry(routes[i]); ! out += routes[i] + "\t" + r.gateway + "\t" + r.genMask + "\t" + r.Type + "\t" + r.iFace + "\r\n"; } } *************** *** 345,360 **** mParentStack.addRoute(new Route_entry(m.group(1), "", m.group(3), m.group(2), 0)); } ! out+="Route added.\n"; } else if((m=Pattern.compile(" +del +([^ ]+)$").matcher(cmd)).find()) { mParentStack.removeRoute(m.group(1)); ! out+="Route to " + tokens[2] + "removed.\n"; } else{ ! out+="Unknown route command. Usage:\n"; ! out+=" route add (<host ip>|<network ip>) <target interface> <netmask> [<gateway>|*]\n" + ! " add new route record\n"; ! out+=" route del (<host ip>|<network ip>) delete route record\n"; ! out+=" route print print route table\n"; } } --- 367,382 ---- mParentStack.addRoute(new Route_entry(m.group(1), "", m.group(3), m.group(2), 0)); } ! out+="Route added.\r\n"; } else if((m=Pattern.compile(" +del +([^ ]+)$").matcher(cmd)).find()) { mParentStack.removeRoute(m.group(1)); ! out+="Route to " + tokens[2] + "removed.\r\n"; } else{ ! out+="Unknown route command. Usage:\r\n"; ! out+=" route add (<host ip>|<network ip>) <target interface> <netmask> [<gateway>|*]\r\n" + ! " add new route record\r\n"; ! out+=" route del (<host ip>|<network ip>) delete route record\r\n"; ! out+=" route print print route table\r\n"; } } *************** *** 371,387 **** snmpa.Close(); snmpa.Disconnect(); ! out+="SNMP agent stoped\n"; snmpa.setPassword(l_pass); snmpa.setPort(l_port); try{ snmpa.Listen(); ! out+="Now SNMP agent listen on port " + String.valueOf(l_port) + "\n"; } catch(TransportLayerException e) { ! out+="Unable to open connection on SNMP agent\n"; } } catch(TransportLayerException e) { ! out+="Unable to close connection on SNMP agent\n"; } } --- 393,409 ---- snmpa.Close(); snmpa.Disconnect(); ! out+="SNMP agent stoped\r\n"; snmpa.setPassword(l_pass); snmpa.setPort(l_port); try{ snmpa.Listen(); ! out+="Now SNMP agent listen on port " + String.valueOf(l_port) + "\r\n"; } catch(TransportLayerException e) { ! out+="Unable to open connection on SNMP agent\r\n"; } } catch(TransportLayerException e) { ! out+="Unable to close connection on SNMP agent\r\n"; } } *************** *** 390,403 **** try{ snmpa.Close(); ! out+="SNMP agent stoped\n"; } catch(TransportLayerException e) { ! out+="Unable to close connection on SNMP agent\n"; } } else { ! out+="Unknown snmp command. Usage:\n"; ! out+=" snmp (on|<port number>) [community name] Start SNMP agent\n"; ! out+=" snmp off Stop SNMP agent\n"; } } --- 412,425 ---- try{ snmpa.Close(); ! out+="SNMP agent stoped\r\n"; } catch(TransportLayerException e) { ! out+="Unable to close connection on SNMP agent\r\n"; } } else { ! out+="Unknown snmp command. Usage:\r\n"; ! out+=" snmp (on|<port number>) [community name] Start SNMP agent\r\n"; ! out+=" snmp off Stop SNMP agent\r\n"; } } *************** *** 410,423 **** else if(tokens[0].compareTo("counters")==0){ out += " Recieved IP Packets: " + Integer.valueOf(mParentStack.getinputIPCount()).toString() + ! "\n Sent IP Packets: " + Integer.valueOf(mParentStack.getoutputIPCount()).toString() + ! "\n ARP Packets: " + Integer.valueOf(mParentStack.getARPCount()).toString() + ! "\n Recieved TCP segments: " + Integer.valueOf(mParentStack.getTCPinputCount()).toString() + ! "\n Sent TCP segments: " + Integer.valueOf(mParentStack.getTCPoutputCount()).toString() + ! "\n Sent TCP ACK's: " + Integer.valueOf(mParentStack.getTCPACKCount()).toString() + ! "\n Sent TCP Dublicates: " + Integer.valueOf(mParentStack.getTCPSDCount()).toString() + ! "\n Recieved TCP Dublicates: " + Integer.valueOf(mParentStack.getTCPRDCount()).toString() + ! "\n Recieved UDP segments: " + Integer.valueOf(mParentStack.getUDPinputCount()).toString() + ! "\n Sent UDP segments: " + Integer.valueOf(mParentStack.getUDPoutputCount()).toString() + ! "\n"; } else if(tokens[0].compareTo("arp")==0){ --- 432,445 ---- else if(tokens[0].compareTo("counters")==0){ out += " Recieved IP Packets: " + Integer.valueOf(mParentStack.getinputIPCount()).toString() + ! "\r\n Sent IP Packets: " + Integer.valueOf(mParentStack.getoutputIPCount()).toString() + ! "\r\n ARP Packets: " + Integer.valueOf(mParentStack.getARPCount()).toString() + ! "\r\n Recieved TCP segments: " + Integer.valueOf(mParentStack.getTCPinputCount()).toString() + ! "\r\n Sent TCP segments: " + Integer.valueOf(mParentStack.getTCPoutputCount()).toString() + ! "\r\n Sent TCP ACK's: " + Integer.valueOf(mParentStack.getTCPACKCount()).toString() + ! "\r\n Sent TCP Dublicates: " + Integer.valueOf(mParentStack.getTCPSDCount()).toString() + ! "\r\n Recieved TCP Dublicates: " + Integer.valueOf(mParentStack.getTCPRDCount()).toString() + ! "\r\n Recieved UDP segments: " + Integer.valueOf(mParentStack.getUDPinputCount()).toString() + ! "\r\n Sent UDP segments: " + Integer.valueOf(mParentStack.getUDPoutputCount()).toString() + ! "\r\n"; } else if(tokens[0].compareTo("arp")==0){ *************** *** 427,431 **** for(int i=0;i<ArpTable.length;i++) { ! out += ArpTable[i] + "\n"; } } --- 449,453 ---- for(int i=0;i<ArpTable.length;i++) { ! out += ArpTable[i] + "\r\n"; } } *************** *** 437,454 **** else if((m=Pattern.compile(" +-d +([^ ]+)$").matcher(cmd)).find()) { mParentStack.removeARP(m.group(1)); ! out += "Removed ARP entry for ip " + m.group(1) + "\n"; } else if((m=Pattern.compile(" +-s +([^ ]+) +([^ ]+)$").matcher(cmd)).find()) { mParentStack.addToARPStatic(m.group(1), m.group(2)); ! out += "Created new static ARP entry: " + m.group(1) + " is " + m.group(2) + "\n"; } else { ! out+="Unknown arp command. Usage:\n"; ! out+=" arp -a print ARP table\n"; ! out+=" arp -d <ip address> delete record from ARP table\n"; ! out+=" arp -s <ip address> <MAC address> add new ARP record\n"; } } ! else out = tokens[0] + ": command not found\n"; } out+=mParentStack.getParentNodeName() + " # "; --- 459,476 ---- else if((m=Pattern.compile(" +-d +([^ ]+)$").matcher(cmd)).find()) { mParentStack.removeARP(m.group(1)); ! out += "Removed ARP entry for ip " + m.group(1) + "\r\n"; } else if((m=Pattern.compile(" +-s +([^ ]+) +([^ ]+)$").matcher(cmd)).find()) { mParentStack.addToARPStatic(m.group(1), m.group(2)); ! out += "Created new static ARP entry: " + m.group(1) + " is " + m.group(2) + "\r\n"; } else { ! out+="Unknown arp command. Usage:\r\n"; ! out+=" arp -a print ARP table\r\n"; ! out+=" arp -d <ip address> delete record from ARP table\r\n"; ! out+=" arp -s <ip address> <MAC address> add new ARP record\r\n"; } } ! else out = tokens[0] + ": command not found\r\n"; } out+=mParentStack.getParentNodeName() + " # "; Index: PosixTelnetClient.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/core/protocolsuite/tcp_ip/PosixTelnetClient.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** PosixTelnetClient.java 8 Nov 2006 14:27:29 -0000 1.1 --- PosixTelnetClient.java 18 Sep 2007 22:29:46 -0000 1.2 *************** *** 45,48 **** --- 45,52 ---- } + public void Accept(int listenSock, int sessionSock) throws TransportLayerException{ + + } + /** * This method stop listening on application port *************** *** 54,57 **** --- 58,66 ---- public void Close() throws TransportLayerException { + mParentStack.CloseTCP(this); + } + + public void Free() throws TransportLayerException + { mParentStack.FreeTCPApplication(this); } *************** *** 66,70 **** */ ! public boolean ClientConnect(String Host, int port) throws TransportLayerException, InvalidNetworkLayerDeviceException, CommunicationException, LowLinkException { sdHost = Host; --- 75,79 ---- */ ! public boolean Connect(String Host, int port) throws TransportLayerException, InvalidNetworkLayerDeviceException, CommunicationException, LowLinkException { sdHost = Host; *************** *** 94,100 **** * @version v0.01 */ ! public void Connected(String Host, int port){ ! sdHost = Host; ! sdPort = port; } --- 103,107 ---- * @version v0.01 */ ! public void OnConnect(int sock){ } *************** *** 133,137 **** */ ! public void DisconnectEvent() { } --- 140,144 ---- */ ! public void OnDisconnect(int sock) { } *************** *** 192,196 **** mParentStack.FreeTCPApplication(this); ! if (ClientConnect(Host, port)) { LayerInfo protInfo = new LayerInfo(getClass().getName()); --- 199,203 ---- mParentStack.FreeTCPApplication(this); ! if (Connect(Host, port)) { LayerInfo protInfo = new LayerInfo(getClass().getName()); Index: Tcp.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/core/protocolsuite/tcp_ip/Tcp.java,v retrieving revision 1.88 retrieving revision 1.89 diff -C2 -d -r1.88 -r1.89 *** Tcp.java 8 Nov 2006 14:27:29 -0000 1.88 --- Tcp.java 18 Sep 2007 22:29:46 -0000 1.89 *************** *** 272,276 **** Simulation.addLayerInfo(TCP_Info); Elm.addstats(TCPptr); ! if(Elm.application != null) ((Application)Elm.application).DisconnectEvent(); Elm.reset(); } else { //nothing to resend, but numRepeat>0 --- 272,276 ---- Simulation.addLayerInfo(TCP_Info); Elm.addstats(TCPptr); ! if(Elm.application != null) ((Application)Elm.application).OnDisconnect(-1); // <<-- FIXME!!! Elm.reset(); } else { //nothing to resend, but numRepeat>0 *************** *** 353,357 **** // System.out.println("SERVER TIMEtoLIVE - OUT - awaiting connection timeout!"); Elm.addstats(TCPptr); ! ((Application)Elm.application).DisconnectEvent(); Elm.reset(); try{ --- 353,357 ---- // System.out.println("SERVER TIMEtoLIVE - OUT - awaiting connection timeout!"); Elm.addstats(TCPptr); ! ((Application)Elm.application).OnDisconnect(-1); // <<-- FIXME!!! Elm.reset(); try{ *************** *** 1263,1267 **** ClosePort(serv); //FIN sent and confirmed!!! Closing connection in case isPassive==true //serv.Listen(); ! serv.DisconnectEvent(); } --- 1263,1267 ---- ClosePort(serv); //FIN sent and confirmed!!! Closing connection in case isPassive==true //serv.Listen(); ! serv.OnDisconnect(-1); // <<-- FIXME!!! } *************** *** 1287,1291 **** Application client; client=(Application)Elm.application; ! client.DisconnectEvent(); } } --- 1287,1291 ---- Application client; client=(Application)Elm.application; ! client.OnDisconnect(-1); // <<-- FIXME!!! } } Index: Echo_tcp.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/core/protocolsuite/tcp_ip/Echo_tcp.java,v retrieving revision 1.30 retrieving revision 1.31 diff -C2 -d -r1.30 -r1.31 *** Echo_tcp.java 8 Nov 2006 14:27:29 -0000 1.30 --- Echo_tcp.java 18 Sep 2007 22:29:46 -0000 1.31 *************** *** 60,63 **** --- 60,67 ---- } + public void Accept(int listenSock, int sessionSock) throws TransportLayerException{ + + } + /** * This method stop listening on application port *************** *** 69,72 **** --- 73,81 ---- public void Close() throws TransportLayerException { + mParentStack.CloseTCP(this); + recieved = 0; + } + + public void Free() throws TransportLayerException{ mParentStack.FreeTCPApplication(this); recieved = 0; *************** *** 82,86 **** */ ! public boolean ClientConnect(String Host, int port) throws TransportLayerException, InvalidNetworkLayerDeviceException, CommunicationException, LowLinkException { sdHost = Host; --- 91,95 ---- */ ! public boolean Connect(String Host, int port) throws TransportLayerException, InvalidNetworkLayerDeviceException, CommunicationException, LowLinkException { sdHost = Host; *************** *** 110,116 **** * @version v0.01 */ ! public void Connected(String Host, int port){ ! sdHost = Host; ! sdPort = port; } --- 119,123 ---- * @version v0.01 */ ! public void OnConnect(int sock){ } *************** *** 149,153 **** */ ! public void DisconnectEvent() { try{ Listen(); --- 156,160 ---- */ ! public void OnDisconnect(int sock) { try{ Listen(); *************** *** 281,285 **** utc1 = System.currentTimeMillis (); ! if (ClientConnect(Host, port)) { LayerInfo protInfo = new LayerInfo(getClass().getName()); -... [truncated message content] |