[Javanetsim-cvs] javaNetSim/core/protocolsuite/tcp_ip ProtocolStack.java,1.16,1.17 Tcp.java,1.5,1.6
Status: Beta
Brought to you by:
darkkey
From: gift <gi...@us...> - 2005-11-26 14:44:13
|
Update of /cvsroot/javanetsim/javaNetSim/core/protocolsuite/tcp_ip In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv18123/core/protocolsuite/tcp_ip Modified Files: ProtocolStack.java Tcp.java Udp.java Log Message: Have to do something more.... Index: ProtocolStack.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/core/protocolsuite/tcp_ip/ProtocolStack.java,v retrieving revision 1.16 retrieving revision 1.17 diff -C2 -d -r1.16 -r1.17 *** ProtocolStack.java 25 Nov 2005 21:21:53 -0000 1.16 --- ProtocolStack.java 26 Nov 2005 14:44:02 -0000 1.17 *************** *** 71,76 **** import core.Simulation; - - import core.*; --- 71,74 ---- *************** *** 779,782 **** --- 777,797 ---- // throw tpe; } + + }else if(ipPacket instanceof TCP_packet){ + + TCP_packet temp = (TCP_packet)inPacket; + try{ + mTCPprotocol.receiveTCPPacket(temp); + }catch(TransportLayerException te){} + catch (CommunicationException ce) {} + catch(TransportLayerPortException tpe){ + //here *TODO*: disconnect sender from port!!! + 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); + } }else{ *************** *** 1578,1582 **** Simulation.addLayerInfo(TCP_Info); } ! } }//EOF --- 1593,1734 ---- Simulation.addLayerInfo(TCP_Info); } ! } ! ! ! /** ! * This method sets the TCP connection ! * NOTE: call this method from application to set up the TCP connection ! * @author gift (sourceforge.net user) ! * @param application the application that sets the connection ! * @param inDestIPAddress destination IP address ! * @param indestPort destination port number ! * @return Nothing ! * @exception CommunicationException ! * @exception LowLinkException ! * @exception TransportLayerException ! * @version v0.10 ! * @see CommunicationException ! * @see LowLinkException ! * @see TransportLayerException ! */ ! ! public void ConnectTCP(Object application, String inDestIPAddress, int indestPort) throws LowLinkException, CommunicationException, TransportLayerException ! { ! String msg=""; ! boolean flags[]={false,false,false,false,true,false}; /* URG, ACK, PSH, RST, !SYN!, FIN */ ! mTCPprotocol.ReservePort(application, inDestIPAddress, indestPort); ! sendTCPSegment(application, msg, flags); ! } ! ! ! /** ! * This method sends the TCP segments ! * NOTE: call this method from application to send TCP segment ! * @author gift (sourceforge.net user) ! * @param application the application that sets the connection ! * @return Nothing ! * @exception CommunicationException ! * @exception LowLinkException ! * @version v0.10 ! * @see CommunicationException ! * @see LowLinkException ! */ ! ! public void SendTCP(Object application, String inTCPMessage) throws LowLinkException, CommunicationException ! { ! boolean flags[]={false,true,false,false,false,false}; /* URG, !ACK!, PSH, RST, SYN, FIN */ ! sendTCPSegment(application, inTCPMessage, flags); ! } ! ! ! /** ! * This method sends the TCP segments ! * NOTE: call this method from application to send last TCP segment ! * @author gift (sourceforge.net user) ! * @param application the application that sets the connection ! * @return Nothing ! * @exception CommunicationException ! * @exception LowLinkException ! * @version v0.10 ! * @see CommunicationException ! * @see LowLinkException ! */ ! ! public void SendFinalTCP(Object application, String inTCPMessage) throws LowLinkException, CommunicationException ! { ! boolean flags[]={false,true,false,false,false,true}; /* URG, !ACK!, PSH, RST, SYN, !FIN! */ ! sendTCPSegment(application, inTCPMessage, flags); ! } ! ! /** ! * This method sends the TCP segments with certain flags ! * NOTE: DO <b>NOT</b> CALL this method from application use only <i>SendTCP(Object application, String inTCPMessage)</i> in the application to send TCP segments ! * @author gift (sourceforge.net user) ! * @param application the application that sends the message ! * @param inTCPMessage TCP message to send ! * @param flags[] 6 flags to set in segment ! * @return Nothing ! * @exception CommunicationException ! * @exception LowLinkException ! * @version v0.40 ! * @see CommunicationException ! * @see LowLinkException ! */ ! ! public void sendTCPSegment(Object application, String inTCPMessage, boolean flags[]) 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=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); ! ! if (FirstInterfaceName!=null) ! { ! if(IPV4Address.validateDecIP(DestIPAddress)) ! { ! //let's get first interface IP address ! SourceIPAddress=getIPAddress(FirstInterfaceName); ! TCP_packet tosend = mTCPprotocol.sendTCPPacket(DestIPAddress,SourceIPAddress,destPort,srcPort,inTCPMessage,flags); ! //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){ ! ! try { ! mTCPprotocol.FreePort(application); ! 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); ! } 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); ! } ! ! } ! } }//EOF Index: Udp.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/core/protocolsuite/tcp_ip/Udp.java,v retrieving revision 1.27 retrieving revision 1.28 diff -C2 -d -r1.27 -r1.28 *** Udp.java 25 Nov 2005 22:54:02 -0000 1.27 --- Udp.java 26 Nov 2005 14:44:02 -0000 1.28 *************** *** 169,173 **** * @return Nothing. * @exception TransportLayerException If UDP CHECK_SUM != 1 - * @exception CommunicationException * @exception LowLinkException * @exception InvalidNetworkLayerDeviceException --- 169,172 ---- *************** *** 175,179 **** * @version v0.20 * @see TransportLayerException - * @see CommunicationException * @see LowLinkException * @see InvalidNetworkLayerDeviceException --- 174,177 ---- *************** *** 183,249 **** public void receiveUDPPacket(UDP_packet inPacket) throws TransportLayerPortException, TransportLayerException, LowLinkException { ! // test if this packet is for a local Address. ! if(mParentStack.isInternalIP(inPacket.getDestIPAddress())){ ! ! // test if destination UDP port exists on this NeworkLayerDevice ! if (PortTable.get(inPacket.get_destPort()) !=null) ! { ! ! //let's check all the things dealing with destination port number ! UDP_HashTableElement Elm = null; ! Elm=(UDP_HashTableElement)PortTable.get(inPacket.get_destPort()); ! ! 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 server application listening to port "+inPacket.get_destPort() +" on host \""+ mParentStack.getParentNodeName()+"\"!"); - //no break needed ;) - case 1: // port is being listened to by a new application. Have to "establish" (in UDP no connections are being established) a new connection by replacing hashtable element - Elm.PortStatus=2; //port will be busy from now - Elm.connectedtoIP=inPacket.getSourceIPAddress(); - Elm.connectedtoPort=inPacket.get_srcPort(); - - //PortTable.remove(inPacket.get_destPort()); //delete old element - //PortTable.put(new Integer(inPacket.get_destPort()),Elm); //hash table update - - //now we decompose UDP datagram - - // everything is OK, one more test: check sum of UDP packet - if (inPacket.getCheck_Sum() == 1) - { - //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); ! ! Application listener; ! listener = (Application)Elm.application; ! listener.RecvData(inPacket.getUDP_message()); ! ! ! } else { ! throw new TransportLayerException("UDP Error: incorrect checksum on receiving!"); ! } ! break; ! ! case 2: //busy port, let's check whether it's busy by us (sender) ;) ! if ((Elm.connectedtoIP.equals(inPacket.getSourceIPAddress())) && (Elm.connectedtoPort==inPacket.get_srcPort())) ! { //now we decompose UDP datagram ! ! // everything is OK, one more test: check sum of UDP packet ! if (inPacket.getCheck_Sum() == 1) ! { //Create Layer info --- 181,211 ---- public void receiveUDPPacket(UDP_packet inPacket) throws TransportLayerPortException, TransportLayerException, LowLinkException { + //test: check sum of UDP packet + if (inPacket.getCheck_Sum() == 1) + { + // test if this packet is for a local Address. + if(mParentStack.isInternalIP(inPacket.getDestIPAddress())){ ! // test if destination UDP port exists on this NeworkLayerDevice ! if (PortTable.get(inPacket.get_destPort()) !=null) { ! //let's check all the things dealing with destination port number ! UDP_HashTableElement Elm = null; ! Elm=(UDP_HashTableElement)PortTable.get(inPacket.get_destPort()); ! 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 server application listening to port "+inPacket.get_destPort() +" on host \""+ mParentStack.getParentNodeName()+"\"!"); ! //no break needed ;) ! case 1: // port is being listened to by a new application. Have to "establish" (in UDP no connections are being established) a new connection by updating hashtable element information //now we decompose UDP datagram ! ! // everything is OK, one more ! Elm.PortStatus=2; //port will be busy from now ! Elm.connectedtoIP=inPacket.getSourceIPAddress(); ! Elm.connectedtoPort=inPacket.get_srcPort(); //Create Layer info *************** *** 256,288 **** UDP_Info.setLayer("Transport"); ! UDP_Info.setDescription("UDP packet received from "+ inPacket.getSourceIPAddress() + ":" + inPacket.get_srcPort() + " message: \"" +inPacket.getUDP_message() + "\"."); ! Simulation.addLayerInfo(UDP_Info); ! ! Application listener; ! listener = (Application)Elm.application; ! listener.RecvData(inPacket.getUDP_message()); ! ! } else { ! throw new TransportLayerException("UDP Error: incorrect checksum on receiving!"); ! } ! } else { ! //have to disconnect listener from port ! throw new TransportLayerPortException("UDP Error: port is busy! Port is connected to another host or/and port and is busy by another application." + "Port "+inPacket.get_destPort() +" on host \""+ mParentStack.getParentNodeName()+"\"."); ! } ! 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()+"\"."); ! } ! } } /** ! * This method sends the UDP packet * and prints out a message to the layer info. * @author gift (sourceforge.net user) --- 218,273 ---- 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); ! ! Application listener; ! listener = (Application)Elm.application; ! listener.RecvData(inPacket.getUDP_message()); ! break; ! ! case 2: //busy port, let's check whether it's busy by sender ;) ! if ((Elm.connectedtoIP.equals(inPacket.getSourceIPAddress())) && (Elm.connectedtoPort==inPacket.get_srcPort())) ! { ! //now we decompose UDP datagram ! // everything is OK, one more test: check sum of UDP packet ! //Create Layer info ! ! 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() + "\"."); ! ! Simulation.addLayerInfo(UDP_Info); ! ! listener = (Application)Elm.application; ! listener.RecvData(inPacket.getUDP_message()); ! ! } else { ! //have to disconnect listener from port ! throw new TransportLayerPortException("UDP Error: port is busy! Port is connected to another host or/and port and is busy by another application." + "Port "+inPacket.get_destPort() +" on host \""+ mParentStack.getParentNodeName()+"\"."); ! } ! 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()+"\"."); ! } ! } ! } else { ! throw new TransportLayerException("UDP Error: incorrect checksum on receiving!"); //comment this line if you have implemented check sum tests :) ! } } /** ! * This method returns the UDP packet to send * and prints out a message to the layer info. * @author gift (sourceforge.net user) Index: Tcp.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/core/protocolsuite/tcp_ip/Tcp.java,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** Tcp.java 25 Nov 2005 22:54:02 -0000 1.5 --- Tcp.java 26 Nov 2005 14:44:02 -0000 1.6 *************** *** 125,128 **** --- 125,129 ---- public int sent_duplicates; //counter inc when a duplicate of a segment is resent /*end of statistic block*/ + public int seq_number; /*database*/ public Vector ReceivedSegments = new Vector(); //contains received segments ONLY sequence_number for each segment is stored *************** *** 144,147 **** --- 145,149 ---- this.received_duplicates=0; this.sent_duplicates=0; + this.seq_number=0; if (!this.ReceivedSegments.isEmpty()) this.ReceivedSegments.removeAllElements(); if (!this.ReceivedACKs.isEmpty()) this.ReceivedACKs.removeAllElements(); *************** *** 161,169 **** private ProtocolStack mParentStack; private int window_size=10; private static final int PORT_QUANT=100; private static final int PORT_START_NUMBER=3000; private static final int PORT_INIT = -1; //used in ListenPort && AlreadyListens private static final int TOTAL_TIME = 10; //seconds to send all data ! private static final int AXELER_KOEFF=2; //coeff depends on line quality, in practise >=2 /** --- 163,173 ---- private ProtocolStack mParentStack; private int window_size=10; + private int total_received=0; + private int total_sent=0; private static final int PORT_QUANT=100; private static final int PORT_START_NUMBER=3000; private static final int PORT_INIT = -1; //used in ListenPort && AlreadyListens private static final int TOTAL_TIME = 10; //seconds to send all data ! private static final int ACCELER_KOEFF=2; //coeff depends on line quality, in practise >=2 /** *************** *** 550,556 **** public void setWindowSize(int inSeg) { ! window_size=(int)AXELER_KOEFF*inSeg/TOTAL_TIME; } } //EOF --- 554,783 ---- public void setWindowSize(int inSeg) { ! window_size=(int)ACCELER_KOEFF*inSeg/TOTAL_TIME; } + /** + * This method returns the TCP packet to send + * and prints out a message to the layer info. + * @author gift (sourceforge.net user) + * @param inDestIPAddress destination IP address + * @param inSourceIPAddress our IP address + * @param indestPort destination port number + * @param insrcPort our port number + * @param inMessage TCP message to send + * @param flags[] 6 flags to set in segment + * @return TCP_packet to send in Network Layer + * @exception TransportLayerException + * @version v0.30 + * @see TransportLayerException + */ + + public TCP_packet sendTCPPacket(String inDestIPAddress,String inSourceIPAddress, int indestPort, int insrcPort, String inMessage, boolean flags[]) throws TransportLayerException, LowLinkException + { + //check if window is available + TCP_HashTableElement Elm; + Elm = (TCP_HashTableElement) PortTable.get(insrcPort); + + if (Elm.seq_number <= (Integer)Elm.ReceivedACKs.lastElement()+window_size) + { + + int s_num; + int a_num; + TCP_packet tosend_clone = new TCP_packet(inDestIPAddress,inSourceIPAddress,indestPort,insrcPort); + TCP_packet tosend = new TCP_packet(inDestIPAddress,inSourceIPAddress,indestPort,insrcPort); + + tosend.setTCP_message(inMessage); + //now we set all the flags + /* URG, ACK, PSH, RST, SYN, FIN */ + tosend.set_URG_flag(flags[0]); + tosend.set_ACK_flag(flags[1]); + tosend.set_PSH_flag(flags[2]); + tosend.set_RST_flag(flags[3]); + tosend.set_SYN_flag(flags[4]); + tosend.set_FIN_flag(flags[5]); + + tosend_clone.set_URG_flag(flags[0]); + tosend_clone.set_ACK_flag(flags[1]); + tosend_clone.set_PSH_flag(flags[2]); + tosend_clone.set_RST_flag(flags[3]); + tosend_clone.set_SYN_flag(flags[4]); + tosend_clone.set_FIN_flag(flags[5]); + + //here we push out segment in Hashtable SegmentsToResend and increment counters + s_num=Elm.seq_number; //getting sequence number 0-for SYN + if (Elm.ReceivedSegments.isEmpty()) a_num=0; else a_num=(Integer)Elm.ReceivedSegments.lastElement()+1; //getting ACK number 0 - for SYN, 1 - as a reply for SYN ... so on + + tosend.set_sequence_number(s_num); + tosend.set_acknowledgment_number(a_num); + + tosend_clone.set_sequence_number(s_num); + tosend_clone.set_acknowledgment_number(a_num); + + //counters inc + Elm.sent_segments++; //UNIQUE ID + Elm.seq_number++; //inc for next segment + if (!(flags[4] && a_num==0)) Elm.sent_ACK++; //inc in case this is an ACK-segment (each segment except for 1-st SYN is ACK-segment) + this.total_sent++; //overall stats + + //pushing a copy into Hashtable + Elm.SegmentsToResend.put((Integer)s_num, tosend_clone); + + if (a_num==0 && flags[4]) //first SYN packet was sent => now he have to change port status to busy, as we will get reply to this port + { + Elm.PortStatus=2; + Elm.connectedtoIP=inDestIPAddress; + Elm.connectedtoPort=indestPort; + } + + + Elm=null; + + //Create Layer info + LayerInfo TCP_Info = new LayerInfo(getClass().getName()); + TCP_Info.setObjectName(mParentStack.getParentNodeName()); + TCP_Info.setDataType("TCP Protocol"); + TCP_Info.setLayer("Transport"); + TCP_Info.setDescription("Created TCP packet for " + inDestIPAddress + ":" + insrcPort +"."); + Simulation.addLayerInfo(TCP_Info); + + return tosend; + } else{ + throw new TransportLayerException("TCP Error: window size limit reached! Can not send segments. Wait for acknowledgenemts. Current window size is \"" + window_size +"\"."); + } + } + + + + /** + * This method receives the TCP packet, checks CHECK_SUM + * and prints out a message to the layer info. + * @author gift (sourceforge.net user) + * @param inPacket a packet to receive (decompilate) + * @return Nothing. + * @exception TransportLayerException If TCP CHECK_SUM != 1 + * @exception CommunicationException + * @exception LowLinkException + * @exception InvalidNetworkLayerDeviceException + * @exception TransportLayerPortException + * @version v0.20 + * @see TransportLayerException + * @see CommunicationException + * @see LowLinkException + * @see InvalidNetworkLayerDeviceException + * @see TransportLayerPortException + */ + + public void receiveTCPPacket(TCP_packet inPacket) throws TransportLayerPortException, TransportLayerException, LowLinkException, CommunicationException + { + //test: check sum of TCP packet + if (inPacket.getCheck_Sum() == 1) + { + + // test if this packet is for a local Address. + if(mParentStack.isInternalIP(inPacket.getDestIPAddress())){ + this.total_received++; //overall stats + // test if destination TCP port exists on this NeworkLayerDevice + if (PortTable.get(inPacket.get_destPort()) !=null) + { + + //let's check all the things dealing with destination port number + TCP_HashTableElement Elm = null; + Elm=(TCP_HashTableElement)PortTable.get(inPacket.get_destPort()); + + switch(Elm.PortStatus) + { + case 0: //port is free => Error: no application to receive TCP + //have to disconnect listener from port + throw new TransportLayerPortException("TCP Error: no server application listening to port "+inPacket.get_destPort() +" on host \""+ mParentStack.getParentNodeName()+"\"!"); + //no break needed ;) + case 1: // port is being listened to by a new application. + //Check for SYN + if (inPacket.get_SYN_flag()) + { + //Have to "establish" a new TCP connection by updating hashtable element information + //and sending out + + //in case this is not duplicate + Integer chk = (Integer)inPacket.get_sequence_number(); + if (Elm.ReceivedSegments.contains(chk)) + { + Elm.PortStatus=2; //port will be busy from now + Elm.connectedtoIP=inPacket.getSourceIPAddress(); + Elm.connectedtoPort=inPacket.get_srcPort(); + Elm.received_segments++; + Elm.ReceivedSegments.addElement(chk); //adding seq_number that we have received + // everything is OK now we decompose TCP datagram + + //Create Layer info + LayerInfo TCP_Info = new LayerInfo(getClass().getName()); + + TCP_Info.setObjectName(mParentStack.getParentNodeName()); + + TCP_Info.setDataType("TCP Protocol"); + + TCP_Info.setLayer("Transport"); + + TCP_Info.setDescription("TCP SYN-packet received from "+ inPacket.getSourceIPAddress() + ":" + inPacket.get_srcPort() + "." + " TCP Port " + inPacket.get_destPort() + " has status \"busy\" from now."); + + Simulation.addLayerInfo(TCP_Info); + + //now we have to send ACK-segment (with SYN=true, seq_num=0, ack_num=1) + //we have one received segment so everything we have to do is just to call "mParentStack.sendTCPSegment(listener,msg,flags);" + String msg=""; + boolean flags[]={false,true,false,false,true,false}; /* URG, !ACK!, PSH, RST, !SYN!, FIN */ + Application listener; + listener = (Application)Elm.application; + mParentStack.sendTCPSegment(listener,msg,flags); + + } else { //we have already received this segment + Elm.received_duplicates++; + } + } else { //not a SYN packet - have to wait until SYN packet will come + } + break; + + case 2: //busy port, let's check whether it's busy by sender ;) + if ((Elm.connectedtoIP.equals(inPacket.getSourceIPAddress())) && (Elm.connectedtoPort==inPacket.get_srcPort())) + { + //now we decompose TCP datagram + + // everything is OK, one more test: check sum of TCP packet + //Create Layer info + + LayerInfo TCP_Info = new LayerInfo(getClass().getName()); + + TCP_Info.setObjectName(mParentStack.getParentNodeName()); + + TCP_Info.setDataType("TCP Protocol"); + + TCP_Info.setLayer("Transport"); + + TCP_Info.setDescription("TCP packet received from "+ inPacket.getSourceIPAddress() + ":" + inPacket.get_srcPort() + " message: \"" +inPacket.getTCP_message() + "\"."); + + Simulation.addLayerInfo(TCP_Info); + + Application listener; + listener = (Application)Elm.application; + listener.RecvData(inPacket.getTCP_message()); + } else { + //have to disconnect listener from port + throw new TransportLayerPortException("TCP Error: port is busy! Port is connected to another host or/and port and is busy by another application." + "Port "+inPacket.get_destPort() +" on host \""+ mParentStack.getParentNodeName()+"\"."); + } + break; + + default: //TCP Error: unknown port status :( + //have to disconnect listener from port + throw new TransportLayerPortException("TCP Error: unknown port status! Port "+inPacket.get_destPort() +" on host \""+ mParentStack.getParentNodeName()+"\"."); + } + } else { + throw new TransportLayerPortException("TCP Error: port " + inPacket.get_destPort() + " does not exist. Host \"" + mParentStack.getParentNodeName()+"\"."); + } + } + } else { + throw new TransportLayerException("TCP Error: incorrect checksum on receiving!"); //comment this line if you have implemented check sum tests :) + } + } + + } //EOF |