[Javanetsim-cvs] javaNetSim/core/protocolsuite/tcp_ip NATEcho_tcp.java, NONE, 1.1 PosixTelnetClient
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-serv1984/core/protocolsuite/tcp_ip Modified Files: Echo_tcp.java ProtocolStack.java Tcp.java Telnet_server.java Added Files: NATEcho_tcp.java PosixTelnetClient.java Log Message: --- NEW FILE: NATEcho_tcp.java --- (This appears to be a binary file; contents omitted.) Index: Telnet_server.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/core/protocolsuite/tcp_ip/Telnet_server.java,v retrieving revision 1.10 retrieving revision 1.11 diff -C2 -d -r1.10 -r1.11 *** Telnet_server.java 5 Sep 2006 21:04:36 -0000 1.10 --- Telnet_server.java 8 Nov 2006 14:27:29 -0000 1.11 *************** *** 100,118 **** public void DisconnectEvent(){ connected = false; printInfo("Server: client closed connection"); ! // try{ ! // printInfo("Server: closing connection"); ! // Close(); ! // try{ ! // Listen(); ! // printInfo("Server: listening on port " + listenPort); ! // } ! // catch(TransportLayerException e){ ! // printInfo("Server: can not listen on port " + listenPort); ! // } ! // } ! // catch(TransportLayerException e){ ! // printInfo("Server: can not close connection"); ! // } } --- 100,116 ---- public void DisconnectEvent(){ 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; ! } } Index: ProtocolStack.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/core/protocolsuite/tcp_ip/ProtocolStack.java,v retrieving revision 1.52 retrieving revision 1.53 diff -C2 -d -r1.52 -r1.53 *** ProtocolStack.java 26 Oct 2006 17:06:11 -0000 1.52 --- ProtocolStack.java 8 Nov 2006 14:27:29 -0000 1.53 *************** *** 147,151 **** if(inProtocolStackLayers == 3){//create a layer 3 protocol stack ! mRARPprotocol = new RARP(); --- 147,151 ---- if(inProtocolStackLayers == 3){//create a layer 3 protocol stack ! mRARPprotocol = new RARP(); *************** *** 181,184 **** --- 181,191 ---- } + + public void initNAT(){ + mTCPprotocol = new Tcp(this); //gift (sourceforge.net user) 25 Nov 2005 + + mUDPprotocol = new Udp(this); //gift (sourceforge.net user) 17 Nov 2005 + } + /** *************** *** 1025,1029 **** } ! /** --- 1032,1054 ---- } ! public void recieveTCP_packet(TCP_packet temp) throws LowLinkException{ ! try{ ! mTCPprotocol.receiveTCPPacket(temp); ! }catch(TransportLayerException te){} ! catch(NullPointerException e){ ! System.out.println("ProtocolStack.java: " + e.toString()); ! } ! catch (CommunicationException ce) {} ! catch(TransportLayerPortException tpe){ ! ! LayerInfo TCP_Info = new LayerInfo(getClass().getName()); ! TCP_Info.setObjectName(getParentNodeName()); ! TCP_Info.setDataType("TCP Packet"); ! TCP_Info.setLayer("Transport"); ! TCP_Info.setDescription("TCP port packet receiving: \""+ tpe.toString() + "\"."); ! Simulation.addLayerInfo(TCP_Info); ! ! } ! } /** *************** *** 1695,1704 **** } catch (TransportLayerException te) { ! LayerInfo TCP_Info = new LayerInfo(getClass().getName()); TCP_Info.setObjectName(getParentNodeName()); TCP_Info.setDataType("TCP Protocol"); TCP_Info.setLayer("Transport"); TCP_Info.setDescription("TCP port closing: \""+ te.toString() + "\"."); ! Simulation.addLayerInfo(TCP_Info); } } --- 1720,1729 ---- } catch (TransportLayerException te) { ! /*LayerInfo TCP_Info = new LayerInfo(getClass().getName()); TCP_Info.setObjectName(getParentNodeName()); TCP_Info.setDataType("TCP Protocol"); TCP_Info.setLayer("Transport"); TCP_Info.setDescription("TCP port closing: \""+ te.toString() + "\"."); ! Simulation.addLayerInfo(TCP_Info); */ } } Index: Tcp.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/core/protocolsuite/tcp_ip/Tcp.java,v retrieving revision 1.87 retrieving revision 1.88 diff -C2 -d -r1.87 -r1.88 *** Tcp.java 23 Sep 2006 07:31:48 -0000 1.87 --- Tcp.java 8 Nov 2006 14:27:29 -0000 1.88 *************** *** 582,586 **** public void ListenPort(Object application, int in_Port) throws TransportLayerException { int lsPort=PORT_INIT; ! Integer inPort = new Integer(in_Port); if ( (lsPort=AlreadyListens(application)) == PORT_INIT ) { --- 582,586 ---- public void ListenPort(Object application, int in_Port) throws TransportLayerException { int lsPort=PORT_INIT; ! Integer inPort = new Integer(in_Port); if ( (lsPort=AlreadyListens(application)) == PORT_INIT ) { *************** *** 1261,1267 **** Application serv; serv=(Application)Elm.application; ! ClosePort(serv); //FIN sent and confirmed!!! Closing connection in case isPassive==true serv.DisconnectEvent(); - serv.Listen(); } --- 1261,1267 ---- Application serv; serv=(Application)Elm.application; ! ClosePort(serv); //FIN sent and confirmed!!! Closing connection in case isPassive==true ! //serv.Listen(); serv.DisconnectEvent(); } --- NEW FILE: PosixTelnetClient.java --- 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.Error; import core.Simulation; import guiUI.PosixTelnetClientGUI; /** * * @author key * @author gift (sourceforge.net user) */ public class PosixTelnetClient extends Application{ private byte ConnectionAttempts=1; private PosixTelnetClientGUI ptcGUI; /** Creates a new instance of Echo */ public PosixTelnetClient(ProtocolStack inParentStack, int UID) { super(inParentStack, 0, 0, UID); } /** * This method start to listen on application port * @author key * @version v0.01 */ public void Listen() throws TransportLayerException{ } /** * This method stop listening on application port * @author key * @param Protocol Stack * @return Nothing. * @version v0.01 */ public void Close() throws TransportLayerException { mParentStack.FreeTCPApplication(this); } /** * This method connects to server on the other side (imaginations from the other side.... :+) * @author key * @author gift (sourceforge.net user) * @param Host - hostname or ip of server. * @param port - server's port * @version v0.03 */ public boolean ClientConnect(String Host, int port) throws TransportLayerException, InvalidNetworkLayerDeviceException, CommunicationException, LowLinkException { sdHost = Host; sdPort = port; LayerInfo protInfo2 = new LayerInfo(getClass().getName()); protInfo2.setObjectName(mParentStack.getParentNodeName()); protInfo2.setDataType("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; } /** * 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; } /** * This method disconnects from server. * @author key * @version v0.01 */ 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); } /** * This method is called when client disconnected from server. * @author key * @version v0.01 */ public void DisconnectEvent() { } /** * This method sends data to the other side. * @param data to send * @author key * @version v0.01 */ public void SendData(String Data) throws LowLinkException, TransportLayerException, CommunicationException { mParentStack.SendTCP(this, Data,-1); //processing the protocol doings. } /** * This method recieves data from the other side. * @param data to recv * @author key * @author gift (sourceforge.net user) * @version v0.02 */ public void RecvData(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); ptcGUI.recvData(Data); } /** * This method processes a echo sending by client * @param data to send * @param server host * @param server port * @author key * @author gift (sourceforge.net user) * @version v0.02 */ public void Telnet(PosixTelnetClientGUI ptcGUI, String Host, int port) throws CommunicationException, LowLinkException, InvalidNetworkLayerDeviceException, TransportLayerException{ this.ptcGUI = ptcGUI; mParentStack.FreeTCPApplication(this); if (ClientConnect(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 { } } Index: Echo_tcp.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/core/protocolsuite/tcp_ip/Echo_tcp.java,v retrieving revision 1.29 retrieving revision 1.30 diff -C2 -d -r1.29 -r1.30 *** Echo_tcp.java 9 Sep 2006 13:43:58 -0000 1.29 --- Echo_tcp.java 8 Nov 2006 14:27:29 -0000 1.30 *************** *** 149,153 **** */ ! public void DisconnectEvent() { } /** --- 149,165 ---- */ ! public void DisconnectEvent() { ! 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; ! } ! } /** |