[Javanetsim-cvs] javaNetSim/core/protocolsuite/tcp_ip Echo.java, 1.23, 1.24 Echo_tcp.java, 1.31, 1.
Status: Beta
Brought to you by:
darkkey
From: QweR <qw...@us...> - 2007-09-21 22:42:38
|
Update of /cvsroot/javanetsim/javaNetSim/core/protocolsuite/tcp_ip In directory sc8-pr-cvs6.sourceforge.net:/tmp/cvs-serv13173/core/protocolsuite/tcp_ip Modified Files: Echo.java Echo_tcp.java ProtocolStack.java TCP_packet.java TCP_session.java Tcp.java UDP_session.java Udp.java jnSession.java socketLayer.java Log Message: first test version of TCP Index: TCP_packet.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/core/protocolsuite/tcp_ip/TCP_packet.java,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** TCP_packet.java 20 Nov 2006 17:20:20 -0000 1.3 --- TCP_packet.java 21 Sep 2007 22:42:31 -0000 1.4 *************** *** 2,60 **** 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; --- 2,30 ---- *************** *** 62,67 **** import core.TransportLayerException; - - /** --- 32,35 ---- *************** *** 86,115 **** * that's why TCP_packet as well as UDP_packet extends IP_packet */ ! private int TCP_srcPort; ! ! private int TCP_destPort; ! ! private int TCP_MessageLength; ! ! private static final int RESERVED = 0; //not used ! ! private int sequence_number; //very very important field. It's value is used as an unique ID of each TCP_packet ! ! private int acknowledgment_number; //important field as well ;) ! ! private boolean flags[] = {false,false,false,false,false,false}; /* URG, ACK, PSH, RST, SYN, FIN */ ! ! private int TCP_window; //for future developing :) ! ! private Object URG_pointer; //for future developing :) ! ! private String TCP_message; ! ! private static final int PTCL = 6; //see RFC :) ! ! private static final int CHECK_SUM = 1; //for future developing :) ! ! private static final int HEAD_LENGTH = 22; //TCP header is 22 bytes ! private static final int MAX_LENGTH = 65535; //bytes will be maximum length --- 54,70 ---- * that's why TCP_packet as well as UDP_packet extends IP_packet */ ! private int TCP_srcPort; ! private int TCP_destPort; ! private int TCP_MessageLength; ! private static final int RESERVED = 0; //not used ! private int sequence_number; //very very important field. It's value is used as an unique ID of each TCP_packet ! private int acknowledgment_number; //important field as well ;) ! private boolean flags[] = {false,false,false,false,false,false}; /* URG, ACK, PSH, RST, SYN, FIN */ ! private int TCP_window; ! //private Object URG_pointer; //for future developing :) ! private String TCP_message; ! private static final int PTCL = 6; //see RFC :) ! private static final int CHECK_SUM = 1; //for future developing :) ! private static final int HEAD_LENGTH = 22; //TCP header is 22 bytes private static final int MAX_LENGTH = 65535; //bytes will be maximum length *************** *** 126,131 **** */ ! public TCP_packet(String inDestIPAddress, String inSourceIPAddress, int indestPort, int insrcPort) ! { super (inDestIPAddress); this.setSourceIPAddress(inSourceIPAddress); --- 81,85 ---- */ ! public TCP_packet(String inDestIPAddress, String inSourceIPAddress, int indestPort, int insrcPort){ super (inDestIPAddress); this.setSourceIPAddress(inSourceIPAddress); *************** *** 135,138 **** --- 89,106 ---- TCP_message = ""; } + + public TCP_packet(TCP_packet pack){ + super(pack.getDestIPAddress()); + setSourceIPAddress(pack.getSourceIPAddress()); + TCP_srcPort = pack.TCP_srcPort; + TCP_destPort = pack.TCP_destPort; + TCP_MessageLength = pack.TCP_MessageLength; + sequence_number = pack.sequence_number; + acknowledgment_number = pack.acknowledgment_number; + for(int i=0; i<flags.length; i++) + flags[i] = pack.flags[i]; + TCP_window = pack.TCP_window; + TCP_message = pack.TCP_message; + } /** *************** *** 444,447 **** --- 412,419 ---- flags[5]=inflg_val; } + + public Object clone(){ + return new TCP_packet(this); + } }//EOF Index: jnSession.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/core/protocolsuite/tcp_ip/jnSession.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** jnSession.java 18 Sep 2007 22:29:46 -0000 1.1 --- jnSession.java 21 Sep 2007 22:42:31 -0000 1.2 *************** *** 23,26 **** --- 23,30 ---- } + public jnSession(int sock){ + this.sock = sock; + } + public int getSocket(){ return sock; Index: Udp.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/core/protocolsuite/tcp_ip/Udp.java,v retrieving revision 1.36 retrieving revision 1.37 diff -C2 -d -r1.36 -r1.37 *** Udp.java 18 Sep 2007 22:29:46 -0000 1.36 --- Udp.java 21 Sep 2007 22:42:31 -0000 1.37 *************** *** 60,85 **** public class Udp implements Serializable ! { ! ! /* ! * UDP_HashTableElement.java ! * ! * Created on 18 November 2005, 21:09 ! */ ! ! /** ! * @author gift (sourceforge.net user) ! * @version v0.10, 18 Nov 2005 ! */ ! public class UDP_HashTableElement ! { ! public byte PortStatus=0; // 0 - free port; 1 - port is being listened to; 2 - busy. ! public Object application=null; //points to application that listens to this port | provided PortStatus==1 ! public String connectedtoIP=""; //contains IP of the other connected computer | provided PortStatus==2 ! public int connectedtoPort=0; //contains port number of the other connected computer | provided PortStatus==2 ! } ! private Hashtable sessionTable = new Hashtable(); private ProtocolStack mParentStack; /*statistic block*/ --- 60,67 ---- public class Udp implements Serializable ! { private Hashtable sessionTable = new Hashtable(); private ProtocolStack mParentStack; + private socketLayer mSL; /*statistic block*/ *************** *** 92,96 **** private static final int PORT_INIT = -1; //used in ListenPort && AlreadyListens - private socketLayer mSL; /** --- 74,77 ---- *************** *** 102,106 **** public Udp(ProtocolStack inParentStack, socketLayer inSL) { - //int i; mParentStack = inParentStack; mSL = inSL; --- 83,86 ---- *************** *** 192,196 **** if(sessionTable.get(jnSocket.genUDPkey(mSL.get_socket(sock).src_port)) == null){ // we should reserve port for it ! ReserveFreePort(sock); mSL.get_socket(sock).src_IP = mParentStack.getSrcIP(); } --- 172,176 ---- if(sessionTable.get(jnSocket.genUDPkey(mSL.get_socket(sock).src_port)) == null){ // we should reserve port for it ! reserveFreePort(sock); mSL.get_socket(sock).src_IP = mParentStack.getSrcIP(); } *************** *** 229,233 **** UDP_Info.setDescription("UDP sending error: \""+ e.toString() + "\"."); Simulation.addLayerInfo(UDP_Info); ! ClosePort(sock); //*TODO*: here we shall put some layerinfo for TransportException } catch (TransportLayerException te) --- 209,213 ---- UDP_Info.setDescription("UDP sending error: \""+ e.toString() + "\"."); Simulation.addLayerInfo(UDP_Info); ! closePort(sock); //*TODO*: here we shall put some layerinfo for TransportException } catch (TransportLayerException te) *************** *** 245,249 **** // if application tries to send, but no port binded, do it now.. ! public void ReserveFreePort(int sock) throws TransportLayerException { String sessionID; --- 225,229 ---- // if application tries to send, but no port binded, do it now.. ! public void reserveFreePort(int sock) throws TransportLayerException { String sessionID; *************** *** 252,256 **** ! UDP_session Elm = new UDP_session(); // check if socket already busy --- 232,236 ---- ! UDP_session Elm; // check if socket already busy *************** *** 278,285 **** { 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()); --- 258,265 ---- { Reserved=true; ! Elm = new UDP_session(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()); *************** *** 300,340 **** // bind port to socket ! public void BindPort(int sock_num, int in_Port) throws TransportLayerException { 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()); --- 280,296 ---- // bind port to socket ! public void bindPort(int sock_num, int in_Port) throws TransportLayerException { int lsPort=PORT_INIT; if ( mSL.get_socket(sock_num).src_port == 0 ) ! { if (in_Port>=0 && in_Port<=65535) ! { ! //create such a record in hashtable ! UDP_session newElm = new UDP_session(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()); *************** *** 345,355 **** } 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); ! } } --- 301,311 ---- } else // { ! throw new TransportLayerException("UDP 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("UDP error: can not listen to port "+ in_Port +"! Already listening to port " + lsPort); ! } } *************** *** 363,367 **** * @see TransportLayerException */ ! public void ClosePort(int sock) throws TransportLayerException //changes port status from 1 (listen) or (see proc ;) to 0 (free) { UDP_session Elm=null; --- 319,323 ---- * @see TransportLayerException */ ! public void closePort(int sock) throws TransportLayerException //changes port status from 1 (listen) or (see proc ;) to 0 (free) { UDP_session Elm=null; Index: ProtocolStack.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/core/protocolsuite/tcp_ip/ProtocolStack.java,v retrieving revision 1.55 retrieving revision 1.56 diff -C2 -d -r1.55 -r1.56 *** ProtocolStack.java 16 Sep 2007 19:38:04 -0000 1.55 --- ProtocolStack.java 21 Sep 2007 22:42:31 -0000 1.56 *************** *** 164,173 **** mICMPprotocol = new ICMP(this); - mTCPprotocol = new Tcp(this); //gift (sourceforge.net user) 25 Nov 2005 - mSL = new socketLayer(this); mUDPprotocol = new Udp(this, mSL); //gift (sourceforge.net user) 17 Nov 2005 --- 164,173 ---- mICMPprotocol = new ICMP(this); mSL = new socketLayer(this); mUDPprotocol = new Udp(this, mSL); //gift (sourceforge.net user) 17 Nov 2005 + mTCPprotocol = new Tcp(this, mSL); //gift (sourceforge.net user) 25 Nov 2005 + *************** *** 184,188 **** public void initNAT(){ ! mTCPprotocol = new Tcp(this); //gift (sourceforge.net user) 25 Nov 2005 mSL = new socketLayer(this); mUDPprotocol = new Udp(this, mSL); //gift (sourceforge.net user) 17 Nov 2005 --- 184,188 ---- public void initNAT(){ ! mTCPprotocol = new Tcp(this, mSL); //gift (sourceforge.net user) 25 Nov 2005 mSL = new socketLayer(this); mUDPprotocol = new Udp(this, mSL); //gift (sourceforge.net user) 17 Nov 2005 *************** *** 216,249 **** public void sendPacket(IP_packet inPacket) throws LowLinkException, CommunicationException{ ! ! String destMAC = null; ! String GatewayAddress = null; - String outInterface[] = new String[2]; - if(!IPV4Address.validateDecIP(inPacket.mDestIPAddress)){ throw new CommunicationException("Packet dropped host unreachable: " + inPacket.mDestIPAddress); } - try{ - - outInterface = mIPprotocol.router(inPacket.getDestIPAddress()); ! ! try{ ! if(outInterface[0] == null) - { - try{ ! ! //Create layer info ! LayerInfo protocolInfo = new LayerInfo(getClass().getName()); - protocolInfo.setObjectName(getParentNodeName()); - if(!(inPacket instanceof ARP_packet) && !(inPacket instanceof ICMP_packet)) protocolInfo.setDataType("IP_Packet"); --- 216,234 ---- public void sendPacket(IP_packet inPacket) throws LowLinkException, CommunicationException{ ! String destMAC = null; String GatewayAddress = null; String outInterface[] = new String[2]; if(!IPV4Address.validateDecIP(inPacket.mDestIPAddress)){ throw new CommunicationException("Packet dropped host unreachable: " + inPacket.mDestIPAddress); } try{ outInterface = mIPprotocol.router(inPacket.getDestIPAddress()); ! try{ if(outInterface[0] == null) { try{ ! //Create layer info LayerInfo protocolInfo = new LayerInfo(getClass().getName()); protocolInfo.setObjectName(getParentNodeName()); if(!(inPacket instanceof ARP_packet) && !(inPacket instanceof ICMP_packet)) protocolInfo.setDataType("IP_Packet"); *************** *** 252,332 **** protocolInfo.setLayer("Network"); ! ! protocolInfo.setDescription("No network interface subnet masks match default gateway provided. " + ! ! " Unabled to send"); ! Simulation.addLayerInfo(protocolInfo); - }catch(NullPointerException e){ System.out.println("ProtocolStack.java: SendPacket 1 " + e.toString()); } - } ! ! else ! ! { ! try{ ! ! String sourceIP = mIPprotocol.getIPAddress(outInterface[0]); ! ! inPacket.setSourceIPAddress(sourceIP); ! ! ! ! // test if on local of remote network ! ! if(outInterface[1]==null){ ! ! destMAC = mARPprotocol.getMACAddress(inPacket.getDestIPAddress(),outInterface[0]); ! ! }else{ ! //String GatewayAddress = mIPprotocol.getDefaultGateway(); ! GatewayAddress = mIPprotocol.getGateway(inPacket.getDestIPAddress()); - String outIface = mIPprotocol.getInterface(inPacket.getDestIPAddress()); - if(outIface!=null) outInterface[0] = outIface; if(GatewayAddress.contains("*")) GatewayAddress = inPacket.getDestIPAddress(); ! ! destMAC = mARPprotocol.getMACAddress(GatewayAddress,outInterface[0]); ! ! } ! ! ! ! if(destMAC == null){ //if there is no matching entry in arp throw an error ! ! throw new CommunicationException("Unable to Resolve Destination MAC Address"); ! ! } ! ! ! ! //Create layer info ! LayerInfo protocolInfo = new LayerInfo(getClass().getName()); ! protocolInfo.setObjectName(getParentNodeName()); ! ! if(!(inPacket instanceof ARP_packet) && !(inPacket instanceof ICMP_packet)) ! protocolInfo.setDataType("IP_Packet"); ! else ! protocolInfo.setDataType(trimClassName(inPacket.getClass().getName())); ! protocolInfo.setLayer("Network"); ! if(GatewayAddress==null) GatewayAddress=inPacket.getDestIPAddress(); ! ! protocolInfo.setDescription("Sending packet from ProtocolStack (to " + GatewayAddress + ")."); ! ! ! Simulation.addLayerInfo(protocolInfo); ! }catch(NullPointerException e){ System.out.println("ProtocolStack.java: SendPacket 1 " + e.toString()); } --- 237,284 ---- protocolInfo.setLayer("Network"); ! protocolInfo.setDescription("No network interface subnet masks match default gateway provided. " + " Unabled to send"); Simulation.addLayerInfo(protocolInfo); }catch(NullPointerException e){ System.out.println("ProtocolStack.java: SendPacket 1 " + e.toString()); } } ! else{ try{ ! String sourceIP = mIPprotocol.getIPAddress(outInterface[0]); ! inPacket.setSourceIPAddress(sourceIP); ! // test if on local of remote network ! if(outInterface[1]==null){ ! destMAC = mARPprotocol.getMACAddress(inPacket.getDestIPAddress(),outInterface[0]); ! } ! else{ ! //String GatewayAddress = mIPprotocol.getDefaultGateway(); GatewayAddress = mIPprotocol.getGateway(inPacket.getDestIPAddress()); String outIface = mIPprotocol.getInterface(inPacket.getDestIPAddress()); if(outIface!=null) outInterface[0] = outIface; if(GatewayAddress.contains("*")) GatewayAddress = inPacket.getDestIPAddress(); ! destMAC = mARPprotocol.getMACAddress(GatewayAddress,outInterface[0]); ! } ! if(destMAC == null){ //if there is no matching entry in arp throw an error ! throw new CommunicationException("Unable to Resolve Destination MAC Address"); ! } ! //Create layer info ! LayerInfo protocolInfo = new LayerInfo(getClass().getName()); ! protocolInfo.setObjectName(getParentNodeName()); ! if(!(inPacket instanceof ARP_packet) && !(inPacket instanceof ICMP_packet)) ! protocolInfo.setDataType("IP_Packet"); ! else ! protocolInfo.setDataType(trimClassName(inPacket.getClass().getName())); ! protocolInfo.setLayer("Network"); ! if(GatewayAddress==null) GatewayAddress=inPacket.getDestIPAddress(); ! protocolInfo.setDescription("Sending packet from ProtocolStack (to " + GatewayAddress + ")."); ! Simulation.addLayerInfo(protocolInfo); ! } ! catch(NullPointerException e){ System.out.println("ProtocolStack.java: SendPacket 1 " + e.toString()); } *************** *** 1680,1702 **** */ ! public int reserveTCPPort(Object application, String inDestIPAddress, int indestPort) throws InvalidNetworkLayerDeviceException, TransportLayerException, CommunicationException ! { ! ! if(IPV4Address.validateDecIP(inDestIPAddress)) ! { ! ! //lets get first network interface name ! String FirstInterfaceName; ! Node temp = (Node)mParentNode; ! FirstInterfaceName = temp.getFirstInterfaceName(); ! ! if (FirstInterfaceName!=null) ! { ! return mTCPprotocol.ReservePort(application,inDestIPAddress,indestPort); ! } else ! throw new InvalidNetworkLayerDeviceException("Network interface unavailable on host \"" + temp.getName() +"\"."); ! }else ! throw new CommunicationException("Packet dropped host unreachable: " + inDestIPAddress); ! } --- 1632,1654 ---- */ ! // public int reserveTCPPort(Object application, String inDestIPAddress, int indestPort) throws InvalidNetworkLayerDeviceException, TransportLayerException, CommunicationException ! // { ! // ! // if(IPV4Address.validateDecIP(inDestIPAddress)) ! // { ! // ! // //lets get first network interface name ! // String FirstInterfaceName; ! // Node temp = (Node)mParentNode; ! // FirstInterfaceName = temp.getFirstInterfaceName(); ! // ! // if (FirstInterfaceName!=null) ! // { ! // return mTCPprotocol.ReservePort(application,inDestIPAddress,indestPort); ! // } else ! // throw new InvalidNetworkLayerDeviceException("Network interface unavailable on host \"" + temp.getName() +"\"."); ! // }else ! // throw new CommunicationException("Packet dropped host unreachable: " + inDestIPAddress); ! // } *************** *** 1714,1728 **** public void CloseTCP(Object application) throws TransportLayerException { ! try { ! mTCPprotocol.ClosePort(application); ! } catch (TransportLayerException te) ! { ! /*LayerInfo TCP_Info = new LayerInfo(getClass().getName()); ! TCP_Info.setObjectName(getParentNodeName()); ! TCP_Info.setDataType("TCP Protocol"); ! TCP_Info.setLayer("Transport"); ! TCP_Info.setDescription("TCP port closing: \""+ te.toString() + "\"."); ! Simulation.addLayerInfo(TCP_Info); */ ! } } --- 1666,1680 ---- public void CloseTCP(Object application) throws TransportLayerException { ! // try { ! // mTCPprotocol.ClosePort(application); ! // } catch (TransportLayerException te) ! // { ! // /*LayerInfo TCP_Info = new LayerInfo(getClass().getName()); ! // TCP_Info.setObjectName(getParentNodeName()); ! // TCP_Info.setDataType("TCP Protocol"); ! // TCP_Info.setLayer("Transport"); ! // TCP_Info.setDescription("TCP port closing: \""+ te.toString() + "\"."); ! // Simulation.addLayerInfo(TCP_Info); */ ! // } } *************** *** 1738,1742 **** public void FreeTCPApplication(Object application) throws TransportLayerException { ! mTCPprotocol.FreeApplication(application); } --- 1690,1694 ---- public void FreeTCPApplication(Object application) throws TransportLayerException { ! // mTCPprotocol.FreeApplication(application); } *************** *** 1753,1775 **** public void ListenTCP(Object application, int inPort) throws TransportLayerException { ! try{ ! mTCPprotocol.ListenPort(application,inPort); ! ! LayerInfo TCP_Info = new LayerInfo(getClass().getName()); ! TCP_Info.setObjectName(getParentNodeName()); ! TCP_Info.setDataType("TCP Application"); ! TCP_Info.setLayer("Transport"); ! TCP_Info.setDescription("Application is now listening on port " + inPort + "."); ! Simulation.addLayerInfo(TCP_Info); ! ! } catch (TransportLayerException te) ! { ! LayerInfo TCP_Info = new LayerInfo(getClass().getName()); ! TCP_Info.setObjectName(getParentNodeName()); ! TCP_Info.setDataType("TCP Application"); ! TCP_Info.setLayer("Transport"); ! TCP_Info.setDescription("Error: TCP port listening: \""+ te.toString() + "\"."); ! Simulation.addLayerInfo(TCP_Info); ! } } --- 1705,1727 ---- public void ListenTCP(Object application, int inPort) throws TransportLayerException { ! // try{ ! // mTCPprotocol.ListenPort(application,inPort); ! // ! // LayerInfo TCP_Info = new LayerInfo(getClass().getName()); ! // TCP_Info.setObjectName(getParentNodeName()); ! // TCP_Info.setDataType("TCP Application"); ! // TCP_Info.setLayer("Transport"); ! // TCP_Info.setDescription("Application is now listening on port " + inPort + "."); ! // Simulation.addLayerInfo(TCP_Info); ! // ! // } catch (TransportLayerException te) ! // { ! // LayerInfo TCP_Info = new LayerInfo(getClass().getName()); ! // TCP_Info.setObjectName(getParentNodeName()); ! // TCP_Info.setDataType("TCP Application"); ! // TCP_Info.setLayer("Transport"); ! // TCP_Info.setDescription("Error: TCP port listening: \""+ te.toString() + "\"."); ! // Simulation.addLayerInfo(TCP_Info); ! // } } *************** *** 1794,1822 **** public int ConnectTCP(Object application, String inDestIPAddress, int indestPort) throws LowLinkException, CommunicationException, TransportLayerException { ! int rval; ! int ack_num=-1; ! String msg=""; ! boolean flags[]={false,false,false,false,true,false}; /* URG, ACK, PSH, RST, !SYN!, FIN */ ! rval=mTCPprotocol.ReservePort(application, inDestIPAddress, indestPort); ! byte code=0; //no status ! ! if (sendTCPSegment(application, msg, flags,ack_num)) ! { ! do ! { code = mTCPprotocol.getStatus(rval); } ! while (code==1); ! ! if(code==0 || code==3) //0 - no status; 1 - is being connected; 2 - is connected; 3 - connection error ! { ! mTCPprotocol.FreeApplication(application); ! return -1; ! } else ! ! return rval; ! ! }else{ ! mTCPprotocol.FreeApplication(application); ! return -1; ! } } --- 1746,1775 ---- public int ConnectTCP(Object application, String inDestIPAddress, int indestPort) throws LowLinkException, CommunicationException, TransportLayerException { ! // int rval; ! // int ack_num=-1; ! // String msg=""; ! // boolean flags[]={false,false,false,false,true,false}; /* URG, ACK, PSH, RST, !SYN!, FIN */ ! // rval=mTCPprotocol.ReservePort(application, inDestIPAddress, indestPort); ! // byte code=0; //no status ! // ! // if (sendTCPSegment(application, msg, flags,ack_num)) ! // { ! // do ! // { code = mTCPprotocol.getStatus(rval); } ! // while (code==1); ! // ! // if(code==0 || code==3) //0 - no status; 1 - is being connected; 2 - is connected; 3 - connection error ! // { ! // mTCPprotocol.FreeApplication(application); ! // return -1; ! // } else ! // ! // return rval; ! // ! // }else{ ! // mTCPprotocol.FreeApplication(application); ! // return -1; ! // } ! return -1; } *************** *** 1837,1843 **** public void SendTCP(Object application, String inTCPMessage, int acknow_numb) throws LowLinkException, CommunicationException { ! boolean flags[]={false,true,false,false,false,false}; /* URG, !ACK!, PSH, RST, SYN, FIN */ ! if (acknow_numb==-1) flags[1]=false; ! sendTCPSegment(application, inTCPMessage, flags, acknow_numb); } --- 1790,1796 ---- public void SendTCP(Object application, String inTCPMessage, int acknow_numb) throws LowLinkException, CommunicationException { ! // boolean flags[]={false,true,false,false,false,false}; /* URG, !ACK!, PSH, RST, SYN, FIN */ ! // if (acknow_numb==-1) flags[1]=false; ! // sendTCPSegment(application, inTCPMessage, flags, acknow_numb); } *************** *** 1858,1865 **** public void FinalizeTCP(Object application) throws LowLinkException, CommunicationException { ! int ack_num=-1; ! String msg="EMPTY STRING the problem is in FinalizeTCP"; ! boolean flags[]={false,false,false,false,false,true}; /* URG, ACK, PSH, RST, SYN, !FIN! */ ! sendTCPSegment(application, msg, flags,ack_num); } --- 1811,1818 ---- public void FinalizeTCP(Object application) throws LowLinkException, CommunicationException { ! // int ack_num=-1; ! // String msg="EMPTY STRING the problem is in FinalizeTCP"; ! // boolean flags[]={false,false,false,false,false,true}; /* URG, ACK, PSH, RST, SYN, !FIN! */ ! // sendTCPSegment(application, msg, flags,ack_num); } *************** *** 1880,1942 **** */ ! public boolean sendTCPSegment(Object application, String inTCPMessage, boolean flags[], int acknow_num) throws LowLinkException, CommunicationException ! { ! String FirstInterfaceName; ! String DestIPAddress; ! String SourceIPAddress; ! int srcPort; ! int destPort; ! ! //lets get first network interface name ! Node temp = (Node)mParentNode; ! FirstInterfaceName = temp.getFirstInterfaceName(); ! ! try{ ! //let's get a reserved local port number for this application ! srcPort = (application != null) ? mTCPprotocol.getApplicationLocalPortNumber(application) : 0 ; ! //and destination IP of the other host ! DestIPAddress=mTCPprotocol.getApplicationDestIP(srcPort); ! //and destination port of the other host ! destPort=mTCPprotocol.getApplicationDestPortNumber(srcPort); ! ! if (FirstInterfaceName!=null) ! { ! if(IPV4Address.validateDecIP(DestIPAddress)) ! { ! //let's get first interface IP address ! SourceIPAddress=getIPAddress(FirstInterfaceName); ! TCP_packet tosend = mTCPprotocol.getTCPPacket_tosend(DestIPAddress,SourceIPAddress,destPort,srcPort,inTCPMessage,flags,acknow_num); ! //and sending out ;) ! sendPacket(tosend); ! }else ! throw new CommunicationException("Packet dropped host unreachable: " + DestIPAddress); ! } //else ! //throw new InvalidNetworkLayerDeviceException("Network interface unavailable on host \"" + temp.getName() +"\"."); ! }catch(Exception e){ ! System.out.println("catch..."); ! //try { ! System.out.println("should never be here..."); ! LayerInfo TCP_Info = new LayerInfo(getClass().getName()); ! TCP_Info.setObjectName(getParentNodeName()); ! TCP_Info.setDataType("TCP Packet"); ! TCP_Info.setLayer("Transport"); ! TCP_Info.setDescription("TCP sending error: \""+ e.toString() + "\"."); ! Simulation.addLayerInfo(TCP_Info); ! Error.Report(e); ! return false; ! /* mTCPprotocol.ClosePort(application); ! } catch (TransportLayerException te) ! { ! 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 freeing: \""+ te.toString() + "\"."); ! Simulation.addLayerInfo(TCP_Info); ! } */ ! ! } ! return true; ! } /** --- 1833,1895 ---- */ ! // public boolean sendTCPSegment(Object application, String inTCPMessage, boolean flags[], int acknow_num) throws LowLinkException, CommunicationException ! // { ! // String FirstInterfaceName; ! // String DestIPAddress; ! // String SourceIPAddress; ! // int srcPort; ! // int destPort; ! // ! // //lets get first network interface name ! // Node temp = (Node)mParentNode; ! // FirstInterfaceName = temp.getFirstInterfaceName(); ! // ! // try{ ! // //let's get a reserved local port number for this application ! // srcPort = (application != null) ? mTCPprotocol.getApplicationLocalPortNumber(application) : 0 ; ! // //and destination IP of the other host ! // DestIPAddress=mTCPprotocol.getApplicationDestIP(srcPort); ! // //and destination port of the other host ! // destPort=mTCPprotocol.getApplicationDestPortNumber(srcPort); ! // ! // if (FirstInterfaceName!=null) ! // { ! // if(IPV4Address.validateDecIP(DestIPAddress)) ! // { ! // //let's get first interface IP address ! // SourceIPAddress=getIPAddress(FirstInterfaceName); ! // TCP_packet tosend = mTCPprotocol.getTCPPacket_tosend(DestIPAddress,SourceIPAddress,destPort,srcPort,inTCPMessage,flags,acknow_num); ! // //and sending out ;) ! // sendPacket(tosend); ! // }else ! // throw new CommunicationException("Packet dropped host unreachable: " + DestIPAddress); ! // } //else ! // //throw new InvalidNetworkLayerDeviceException("Network interface unavailable on host \"" + temp.getName() +"\"."); ! // }catch(Exception e){ ! // System.out.println("catch..."); ! // //try { ! // System.out.println("should never be here..."); ! // LayerInfo TCP_Info = new LayerInfo(getClass().getName()); ! // TCP_Info.setObjectName(getParentNodeName()); ! // TCP_Info.setDataType("TCP Packet"); ! // TCP_Info.setLayer("Transport"); ! // TCP_Info.setDescription("TCP sending error: \""+ e.toString() + "\"."); ! // Simulation.addLayerInfo(TCP_Info); ! // Error.Report(e); ! // return false; ! // /* mTCPprotocol.ClosePort(application); ! // } catch (TransportLayerException te) ! // { ! // 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 freeing: \""+ te.toString() + "\"."); ! // Simulation.addLayerInfo(TCP_Info); ! // } */ ! // ! // } ! // return true; ! // } /** *************** *** 1958,1988 **** */ ! public TCP_packet getTCPSegment_clone(Object application, String inTCPMessage, boolean flags[], int acknow_num) throws LowLinkException, CommunicationException, TransportLayerException ! { ! String FirstInterfaceName; ! String DestIPAddress; ! String SourceIPAddress; ! int srcPort; ! int destPort; ! ! //lets get first network interface name ! Node temp = (Node)mParentNode; ! FirstInterfaceName = temp.getFirstInterfaceName(); ! ! // try{ ! //let's get a reserved local port number for this application ! srcPort=mTCPprotocol.getApplicationLocalPortNumber(application); ! //and destination IP of the other host ! DestIPAddress=mTCPprotocol.getApplicationDestIP(srcPort); ! //and destination port of the other host ! destPort=mTCPprotocol.getApplicationDestPortNumber(srcPort); ! ! ! SourceIPAddress=getIPAddress(FirstInterfaceName); ! TCP_packet tosend = mTCPprotocol.getTCPPacket_clone(DestIPAddress,SourceIPAddress,destPort,srcPort,inTCPMessage,flags,acknow_num); ! return tosend; ! ! // }catch(Exception e){} ! } --- 1911,1941 ---- */ ! // public TCP_packet getTCPSegment_clone(Object application, String inTCPMessage, boolean flags[], int acknow_num) throws LowLinkException, CommunicationException, TransportLayerException ! // { ! // String FirstInterfaceName; ! // String DestIPAddress; ! // String SourceIPAddress; ! // int srcPort; ! // int destPort; ! // ! // //lets get first network interface name ! // Node temp = (Node)mParentNode; ! // FirstInterfaceName = temp.getFirstInterfaceName(); ! // ! // // try{ ! // //let's get a reserved local port number for this application ! // srcPort=mTCPprotocol.getApplicationLocalPortNumber(application); ! // //and destination IP of the other host ! // DestIPAddress=mTCPprotocol.getApplicationDestIP(srcPort); ! // //and destination port of the other host ! // destPort=mTCPprotocol.getApplicationDestPortNumber(srcPort); ! // ! // ! // SourceIPAddress=getIPAddress(FirstInterfaceName); ! // TCP_packet tosend = mTCPprotocol.getTCPPacket_clone(DestIPAddress,SourceIPAddress,destPort,srcPort,inTCPMessage,flags,acknow_num); ! // return tosend; ! // ! // // }catch(Exception e){} ! // } Index: Tcp.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/core/protocolsuite/tcp_ip/Tcp.java,v retrieving revision 1.89 retrieving revision 1.90 diff -C2 -d -r1.89 -r1.90 *** Tcp.java 18 Sep 2007 22:29:46 -0000 1.89 --- Tcp.java 21 Sep 2007 22:42:31 -0000 1.90 *************** *** 1,87 **** ! /* ! ! Java Network Simulator (javaNetSim) ! Copyright (c) 2006, 2005, Ice Team; All rights reserved. ! Copyright (c) 2004, jFirewallSim development team; All rights reserved. ! ! ! [...3177 lines suppressed...] + // TCP_packet to_buff=new TCP_packet(Packet.getDestIPAddress(), Packet.getSourceIPAddress(), Packet.get_destPort(), Packet.get_srcPort()); + // try { + // to_buff.setTCP_message(Packet.getTCP_message()); + // } catch(TransportLayerException e) {} //will never be thrown from here ;) + // + // to_buff.set_sequence_number(Packet.get_sequence_number()); + // to_buff.set_acknowledgment_number(Packet.get_acknowledgment_number()); + // + // to_buff.set_URG_flag(Packet.get_URG_flag()); + // to_buff.set_ACK_flag(Packet.get_ACK_flag()); + // to_buff.set_PSH_flag(Packet.get_PSH_flag()); + // to_buff.set_RST_flag(Packet.get_RST_flag()); + // to_buff.set_SYN_flag(Packet.get_SYN_flag()); + // to_buff.set_FIN_flag(Packet.get_FIN_flag()); + // + // Elm.OutputBuffer.put(new Integer(Packet.get_sequence_number()), to_buff); + // } + // } + // } //EOF Index: Echo_tcp.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/core/protocolsuite/tcp_ip/Echo_tcp.java,v retrieving revision 1.31 retrieving revision 1.32 diff -C2 -d -r1.31 -r1.32 *** Echo_tcp.java 18 Sep 2007 22:29:46 -0000 1.31 --- Echo_tcp.java 21 Sep 2007 22:42:31 -0000 1.32 *************** *** 7,25 **** 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; --- 7,17 ---- *************** *** 34,40 **** private int counts; private int crecv; ! private long ! utc1; ! public int recieved; /** Creates a new instance of Echo */ --- 26,33 ---- private int counts; private int crecv; ! private long utc1; ! public int recieved; ! ! private int sock; /** Creates a new instance of Echo */ *************** *** 42,45 **** --- 35,39 ---- super(inParentStack, listenPort, appType, UID); counts = 0; + sock = mParentStack.SL().socket(jnSocket.TCP_socket, this); } *************** *** 53,61 **** recieved = 0; try{ ! if(appType != 0) mParentStack.ListenTCP(this, listenPort); ! } catch (TransportLayerException e) ! { ! } } --- 47,59 ---- recieved = 0; try{ ! if(appType == 1){ ! mParentStack.SL().bind(sock, mParentStack.getSrcIP(), listenPort); ! } ! }catch (TransportLayerException e){ ! e.toString(); ! }catch (LowLinkException e){ ! e.toString(); } + //mParentStack.SL().listen(sock); } *************** *** 73,83 **** public void Close() throws TransportLayerException { ! mParentStack.CloseTCP(this); recieved = 0; } public void Free() throws TransportLayerException{ ! mParentStack.FreeTCPApplication(this); ! recieved = 0; } --- 71,81 ---- public void Close() throws TransportLayerException { ! mParentStack.SL().close(sock); recieved = 0; } public void Free() throws TransportLayerException{ ! Close(); ! mParentStack.SL().free(sock); } *************** *** 103,114 **** Simulation.addLayerInfo(protInfo2); ! do ! { ! ConnectionAttempts--; ! clientPort = mParentStack.ConnectTCP(this, sdHost, sdPort); ! } ! while (ConnectionAttempts>0 && clientPort==-1); ! if (clientPort>-1) return true; else return false; } --- 101,113 ---- Simulation.addLayerInfo(protInfo2); ! // do ! // { ! // ConnectionAttempts--; ! // clientPort = mParentStack.ConnectTCP(this, sdHost, sdPort); ! // } ! // while (ConnectionAttempts>0 && clientPort==-1); ! boolean isconnected = mParentStack.TCP().connect(sock, sdHost, sdPort); ! return isconnected; } *************** *** 121,152 **** public void OnConnect(int sock){ } - - /** - * 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("Echo 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); - } /** --- 120,123 ---- *************** *** 157,163 **** public void OnDisconnect(int sock) { ! try{ ! Listen(); ! }catch(Exception e){ LayerInfo protInfo = new LayerInfo(getClass().getName()); protInfo.setObjectName(mParentStack.getParentNodeName()); --- 128,134 ---- public void OnDisconnect(int sock) { ! try{ ! Listen(); ! }catch(Exception e){ LayerInfo protInfo = new LayerInfo(getClass().getName()); protInfo.setObjectName(mParentStack.getParentNodeName()); *************** *** 167,171 **** Simulation.addLayerInfo(protInfo); protInfo = null; ! } } --- 138,142 ---- Simulation.addLayerInfo(protInfo); protInfo = null; ! } } *************** *** 180,184 **** { ! mParentStack.SendTCP(this, Data,-1); //processing the protocol doings. --- 151,155 ---- { ! mParentStack.SL().write(sock, Data); //processing the protocol doings. *************** *** 218,223 **** if(this.counts==0){ ! ! Disconnect(); LayerInfo protInfo2 = new LayerInfo(getClass().getName()); protInfo2.setObjectName(mParentStack.getParentNodeName()); --- 189,193 ---- if(this.counts==0){ ! mParentStack.SL().close(sock); LayerInfo protInfo2 = new LayerInfo(getClass().getName()); protInfo2.setObjectName(mParentStack.getParentNodeName()); *************** *** 280,284 **** */ public void SendEcho(String Data, String Host, int port, int counts) throws CommunicationException, LowLinkException, InvalidNetworkLayerDeviceException, TransportLayerException{ ! mParentStack.FreeTCPApplication(this); recieved = 0; --- 250,254 ---- */ public void SendEcho(String Data, String Host, int port, int counts) throws CommunicationException, LowLinkException, InvalidNetworkLayerDeviceException, TransportLayerException{ ! mParentStack.SL().free(sock); recieved = 0; *************** *** 311,337 **** } } - - /** - * 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 - { - - } - - } --- 281,283 ---- Index: UDP_session.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/core/protocolsuite/tcp_ip/UDP_session.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** UDP_session.java 18 Sep 2007 22:29:46 -0000 1.1 --- UDP_session.java 21 Sep 2007 22:42:31 -0000 1.2 *************** *** 22,26 **** /** Creates a new instance of UDP_session */ ! public UDP_session() { } --- 22,27 ---- /** Creates a new instance of UDP_session */ ! public UDP_session(int sock) { ! super(sock); } Index: TCP_session.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/core/protocolsuite/tcp_ip/TCP_session.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** TCP_session.java 18 Sep 2007 22:29:46 -0000 1.1 --- TCP_session.java 21 Sep 2007 22:42:31 -0000 1.2 *************** *** 10,13 **** --- 10,15 ---- package core.protocolsuite.tcp_ip; + import java.util.Hashtable; + /** * *************** *** 26,31 **** /*end of statistic block*/ /** Creates a new instance of TCP_session */ ! public TCP_session() { } --- 28,198 ---- /*end of statistic block*/ + public int seq_number=0; + public int last_passed=-1; //last sequence number value of the segment that has been passed upstairs + public static int Element_id = 0; + private int state = CLOSED; + + public static final int CLOSED = 0; + public static final int LISTEN = 1; + public static final int SYN_SENT = 2; + public static final int SYB_RCVD = 3; + public static final int ESTABLISHED = 4; + public static final int FIN_WAIT_1 = 5; + public static final int FIN_WAIT_2 = 6; + public static final int CLOSING = 7; + public static final int TIME_WAIT = 8; + public static final int CLOSE_WAIT = 9; + public static final int LAST_ACK = 10; + + /** + * Contains segments that will be resent in case no ACK for them will be received + * <p>Key: Sequence number of the segment that we are se... [truncated message content] |