[Javanetsim-cvs] javaNetSim/core/protocolsuite/tcp_ip Echo.java,1.13,1.14 ProtocolStack.java,1.15,1.
Status: Beta
Brought to you by:
darkkey
From: gift <gi...@us...> - 2005-11-25 21:22:02
|
Update of /cvsroot/javanetsim/javaNetSim/core/protocolsuite/tcp_ip In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv14517/core/protocolsuite/tcp_ip Modified Files: Echo.java ProtocolStack.java Tcp.java Udp.java Log Message: TCP v0.0000000000001 Index: ProtocolStack.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/core/protocolsuite/tcp_ip/ProtocolStack.java,v retrieving revision 1.15 retrieving revision 1.16 diff -C2 -d -r1.15 -r1.16 *** ProtocolStack.java 25 Nov 2005 16:57:35 -0000 1.15 --- ProtocolStack.java 25 Nov 2005 21:21:53 -0000 1.16 *************** *** 1293,1297 **** LayerInfo UDP_Info = new LayerInfo(getClass().getName()); UDP_Info.setObjectName(getParentNodeName()); ! UDP_Info.setDataType("UDP Packet"); UDP_Info.setLayer("Transport"); UDP_Info.setDescription("UDP port closing: \""+ te.toString() + "\"."); --- 1293,1297 ---- LayerInfo UDP_Info = new LayerInfo(getClass().getName()); UDP_Info.setObjectName(getParentNodeName()); ! UDP_Info.setDataType("UDP Protocol"); UDP_Info.setLayer("Transport"); UDP_Info.setDescription("UDP port closing: \""+ te.toString() + "\"."); *************** *** 1318,1322 **** LayerInfo UDP_Info = new LayerInfo(getClass().getName()); UDP_Info.setObjectName(getParentNodeName()); ! UDP_Info.setDataType("UDP Packet"); UDP_Info.setLayer("Transport"); UDP_Info.setDescription("UDP port freeing: \""+ te.toString() + "\"."); --- 1318,1322 ---- LayerInfo UDP_Info = new LayerInfo(getClass().getName()); UDP_Info.setObjectName(getParentNodeName()); ! UDP_Info.setDataType("UDP Protocol"); UDP_Info.setLayer("Transport"); UDP_Info.setDescription("UDP port freeing: \""+ te.toString() + "\"."); *************** *** 1442,1445 **** --- 1442,1582 ---- } } + + + + /** + * This method reserves the TCP port + * @author gift (sourceforge.net user) + * @param application application that uses port + * @param inDestIPAddress destination IP address + * @param indestPort destination port number + * @return int port number that has been reserved for application + * @exception InvalidNetworkLayerDeviceException + * @exception TransportLayerException + * @exception CommunicationException + * @version v0.30 + * @see InvalidNetworkLayerDeviceException + * @see TransportLayerException + * @see CommunicationException + */ + + 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); + } + + + + /** + * This method closes the TCP port for an application + * @author gift (sourceforge.net user) + * @param application application that uses port + * @return Nothing + * @exception TransportLayerException + * @version v0.10 + * @see TransportLayerException + */ + + 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); + } + } + + + /** + * This method sets the TCP port free + * @author gift (sourceforge.net user) + * @param application application that uses port + * @return Nothing + * @exception TransportLayerException + * @version v0.10 + * @see TransportLayerException + */ + public void freeTCPPort(Object application) throws TransportLayerException + { + try { + mTCPprotocol.FreePort(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 freeing: \""+ te.toString() + "\"."); + Simulation.addLayerInfo(TCP_Info); + } + } + + /** + * This method sets the TCP port totally free + * @author gift (sourceforge.net user) + * @param application application that uses port + * @return Nothing + * @exception TransportLayerException + * @version v0.10 + * @see TransportLayerException + */ + public void FreeTCPApplication(Object application) throws TransportLayerException + { + mTCPprotocol.FreeApplication(application); + } + + /** + * This method sets the TCP port status to 1 (is being listened to) + * @author gift (sourceforge.net user) + * @param application application that uses port + * @param inPort port that the application want to listen to + * @return Nothing + * @exception TransportLayerException + * @version v0.10 + * @see TransportLayerException + */ + 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); + } + } }//EOF Index: Tcp.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/core/protocolsuite/tcp_ip/Tcp.java,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** Tcp.java 25 Nov 2005 16:57:35 -0000 1.3 --- Tcp.java 25 Nov 2005 21:21:53 -0000 1.4 *************** *** 118,124 **** public String connectedtoIP; //contains IP of the other connected computer | provided PortStatus==2 public int connectedtoPort; //contains port number of the other connected computer | provided PortStatus==2 ! public Vector ReceivedSegments; //contains received segments ONLY sequence_number for each segment is stored ! public Vector ReceivedACKs; //contains received acknowledgments from destination computer ONLY sequence_number for each ACK segment is stored ! public Hashtable SegmentsToResend; //contains segments that will be resend in case no ACK for them will be received } --- 118,159 ---- public String connectedtoIP; //contains IP of the other connected computer | provided PortStatus==2 public int connectedtoPort; //contains port number of the other connected computer | provided PortStatus==2 ! /*statistic block*/ ! public int received_segments; //counter inc when a segment is received ! public int sent_segments; //counter inc when a segment is sent ! public int sent_ACK; //counter inc when an ACK is sent ! public int received_duplicates;//counter inc when a duplicate of a received segment is received again ! public int sent_duplicates; //counter inc when a duplicate of a segment is resent ! /*end of statistic block*/ ! /*database*/ ! public Vector ReceivedSegments = new Vector(); //contains received segments ONLY sequence_number for each segment is stored ! //Integer type is used NOTE: Do remember about special "Integer" use by "Vector" ! public Vector ReceivedACKs = new Vector(); //contains received acknowledgments from destination computer ONLY sequence_number for each ACK segment is stored ! //Integer type is used NOTE: Do remember about special "Integer" use by "Vector" ! public Hashtable SegmentsToResend = new Hashtable(); //contains segments that will be resent in case no ACK for them will be received ! /*end of database*/ ! ! public void reset() ! { ! this.PortStatus=0; ! this.application=null; ! this.connectedtoIP=""; ! this.connectedtoPort=0; ! this.received_segments=0; ! this.sent_segments=0; ! this.sent_ACK=0; ! this.received_duplicates=0; ! this.sent_duplicates=0; ! if (!this.ReceivedSegments.isEmpty()) this.ReceivedSegments.removeAllElements(); ! if (!this.ReceivedACKs.isEmpty()) this.ReceivedACKs.removeAllElements(); ! if (!this.SegmentsToResend.isEmpty()) ! { ! Set set = this.SegmentsToResend.keySet(); ! Iterator itr = set.iterator(); ! while (itr.hasNext()) ! { ! this.SegmentsToResend.remove(itr.next()); ! } ! } ! } } *************** *** 137,156 **** public Tcp(ProtocolStack inParentStack) { ! int i; for(i=0;i<PORT_QUANT;i++) { TCP_HashTableElement Elm = new TCP_HashTableElement(); ! Elm.PortStatus=0; ! Elm.application=null; ! Elm.connectedtoIP=""; ! Elm.connectedtoPort=0; ! mParentStack = inParentStack; ! ! PortTable.put(new Integer((PORT_START_NUMBER+i)),Elm); // DANGEROUS PLACE! Check before change. } ! } } --- 172,528 ---- public Tcp(ProtocolStack inParentStack) { ! int i; ! mParentStack = inParentStack; for(i=0;i<PORT_QUANT;i++) { + TCP_HashTableElement Elm = new TCP_HashTableElement(); + Elm.reset(); + PortTable.put(new Integer((PORT_START_NUMBER+i)),Elm); // DANGEROUS PLACE! Check before change. + } + } + + + /** + * This method reserves LOCAL port number for an application in case reserved. Port number range: [PORT_START_NUMBER; PORT_START_NUMBER+PORT_QUANT] + * if not found then we reserve a new number + * @author gift (sourceforge.net user) + * @param application that will: take free port or take already occupied port (only by itself) or tell that all ports are busy :( + * @param inDestIPAddress destination IP address + * @param indestPort destination port number + * @return int port number that has been reserved for application + * @exception TransportLayerException in several cases + * @version v0.10 + * @see TransportLayerException + */ + public int ReservePort(Object application,String inDestIPAddress, int indestPort) throws TransportLayerException + { + Integer number = new Integer(0); + boolean Found=false; + boolean Reserved=false; + Enumeration LocalPorts = PortTable.keys(); + + TCP_HashTableElement Elm = new TCP_HashTableElement(); ! while ( (LocalPorts.hasMoreElements()) && !(Found) ) ! { ! number = (Integer) LocalPorts.nextElement(); ! ! ! Elm = (TCP_HashTableElement) PortTable.get(number); ! ! int UID1 = -2; ! int UID2 = -1; ! ! if(Elm.application!=null && application!=null){ ! UID1 = ((Application)Elm.application).getUID(); ! UID2 = ((Application)application).getUID(); ! } ! ! if ( UID1 == UID2) ! { ! Found=true; ! //we have found our application; let's check whom we are connected to ! if (Elm.connectedtoIP.equals(inDestIPAddress)) ! { ! //now goes port number ! if (Elm.connectedtoPort==indestPort) ! { ! //everything is OK, need to return "number" ! ! } else { ! throw new TransportLayerException("TCP Error: application is already connected to another port number! Connected to host: " + Elm.connectedtoIP + ":" + Elm.connectedtoPort + "."); ! } ! } else { ! throw new TransportLayerException("TCP Error: application is already connected to another IP! Connected to host: " + Elm.connectedtoIP + "."); ! } ! ! } ! } ! //in case we have not found our application in hash table..... ! if (!Found) ! { ! //lets try to reserve any free port ! number=PORT_START_NUMBER; ! while ( (number<PORT_START_NUMBER+PORT_QUANT) && !(Reserved) ) ! { ! Elm = (TCP_HashTableElement) PortTable.get((Integer)number); ! ! if (Elm.PortStatus == 0) //free port ! { ! Reserved=true; ! Elm.PortStatus=2; //port will be busy from now ! Elm.connectedtoIP=inDestIPAddress; ! Elm.connectedtoPort=indestPort; ! Elm.application = application; ! } ! if (!Reserved) number++; ! } ! ! if (!Reserved) //all ports are busy :( ! { ! throw new TransportLayerException("TCP Error: all ports are busy! Can not send TCP segments to host " + inDestIPAddress + ":" + indestPort +"."); ! } ! ! } ! ! //For debugging ! // UDP_HashTableElement Elm2 = new UDP_HashTableElement();//For debugging ! // Elm2 = (UDP_HashTableElement) PortTable.get((Integer)number+1);//For debugging ! ! return (number); //do not change here! if you want to change here scan again the code ! ! ! } ! ! ! /** ! * This method finds port number for an application. Port number range: [PORT_START_NUMBER; PORT_START_NUMBER+PORT_QUANT] ! * @author gift (sourceforge.net user) ! * @param inSrcPort port number that has been reserved for the applicaion ! * @return int port number of the other host (that the application is connected to) ! * @exception TransportLayerException ! * @version v0.20 ! * @see TransportLayerException ! */ ! public int getApplicationDestPortNumber(int inSrcPort) throws TransportLayerException ! { ! int number=0; ! TCP_HashTableElement Elm = null; ! ! Elm=(TCP_HashTableElement)PortTable.get((Integer)inSrcPort); ! number=Elm.connectedtoPort; ! return number; ! } ! ! /** ! * This method closes the TCP port for an application ! * @author gift (sourceforge.net user) ! * @param application application that uses port ! * @return Nothing ! * @exception TransportLayerException ! * @version v0.10 ! * @see TransportLayerException ! */ ! public void ClosePort(Object application) throws TransportLayerException //changes port status from 1 (listen) or (see proc ;) to 0 (free) ! { ! TCP_HashTableElement Elm=null; ! Integer PortToClose=getApplicationLocalPortNumber(application); ! ! Elm=(TCP_HashTableElement) PortTable.get((Integer)PortToClose); ! ! if (Elm.PortStatus==1 || (Elm.PortStatus==2 && PortToClose<PORT_START_NUMBER)) ! { ! Elm.reset(); ! } else throw new TransportLayerException("TCP Error: port "+ PortToClose +" is not being LISTENED to by the application: \"" + application.toString() + "\"."); ! } ! ! /** ! * This method sets the TCP port free ! * @author gift (sourceforge.net user) ! * @param application application that uses port ! * @return Nothing ! * @exception TransportLayerException ! * @version v0.10 ! * @see TransportLayerException ! */ ! public void FreePort(Object application) throws TransportLayerException //changes port status from 2 (busy) to 0 (free) ! { ! TCP_HashTableElement Elm=null; ! Integer PortToFree=getApplicationLocalPortNumber(application); ! ! Elm=(TCP_HashTableElement) PortTable.get((Integer)PortToFree); ! ! if (Elm.PortStatus==2) ! { ! Elm.reset(); ! } else throw new TransportLayerException("TCP Error: port "+ PortToFree +" is not BUSY by the application: \"" + application.toString() + "\"."); ! } ! ! /** ! * This method sets the TCP port totally free ! * @author gift (sourceforge.net user) ! * @param application application that uses port ! * @return Nothing ! * @exception TransportLayerException ! * @version v0.10 ! * @see TransportLayerException ! */ ! public void FreeApplication(Object application) throws TransportLayerException //changes any port status to 0 (free) ! { ! TCP_HashTableElement Elm=null; ! ! try{ ! Integer PortToFree=getApplicationLocalPortNumber(application); ! Elm=(TCP_HashTableElement) PortTable.get((Integer)PortToFree); ! Elm.reset(); ! }catch(Exception e){} ! } ! ! /** ! * This method checks whether server is already listening to port ! * @author gift (sourceforge.net user) ! * @param application application that uses port ! * @return int - port number if listens or PORT_INIT if not listens ! * @version v0.10 ! */ ! public int AlreadyListens(Object application) ! { ! boolean bo=false; ! int listensto=PORT_INIT; ! int localPort; ! ! try { ! localPort=getApplicationLocalPortNumber(application); ! listensto=localPort; ! } catch (TransportLayerException e) ! {} ! ! return listensto; ! } ! ! ! /** ! * This method sets the TCP port status to 1 (is being listened to) ! * NOTE: server must listen to TCP port numbers from 0 to 10000 ! * @author gift (sourceforge.net user) ! * @param application application that uses port ! * @param in_Port port that the application want to listen to ! * @return Nothing ! * @exception TransportLayerException ! * @version v0.10 ! * @see TransportLayerException ! */ ! 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 ) ! { ! if (inPort>=0 && inPort<=10000) ! { ! TCP_HashTableElement Elm = null; ! ! if ( (Elm =(TCP_HashTableElement)PortTable.get(inPort)) !=null ) ! { ! switch(Elm.PortStatus) ! { ! case 0: //port is free => update such a record in hashtable ! Elm.PortStatus=1; ! Elm.application=application; ! Elm.connectedtoIP=""; ! Elm.connectedtoPort=0; ! break; ! case 1: // port is being listened to by whom? ! int UID1=-2; ! int UID2=-1; ! UID1=((Application)Elm.application).getUID(); ! UID2=((Application)application).getUID(); ! ! if (UID1==UID2) ! { ! throw new TransportLayerException("error: already listening to port "+ inPort +"!"); ! } else throw new TransportLayerException("error: port "+ inPort +" is being listened to by another application! Can listen only to free ports." ); ! case 2: //port is busy => error ! throw new TransportLayerException("error: port "+ inPort +" is busy! Can listen only to free ports." ); ! // no "break" needed ;) ! default: //unknown port status ! throw new TransportLayerException("error: unknown port status! Port "+ inPort +" on host \""+ mParentStack.getParentNodeName()+"\"."); ! } ! ! } else ! { ! //create such a record in hashtable ! TCP_HashTableElement newElm = new TCP_HashTableElement(); ! newElm.PortStatus=1; ! newElm.application=application; ! newElm.connectedtoIP=""; ! newElm.connectedtoPort=0; ! ! PortTable.put(inPort,newElm); //hash table update ! } ! } else // ! { ! throw new TransportLayerException("error: can not listen to port "+ inPort +"! Use port range from 0 to 10000 to listen to."); ! } ! } else // ! { ! if (lsPort==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); ! } ! } ! ! ! /** ! * This method finds destination IP (host) for an application. ! * @author gift (sourceforge.net user) ! * @param inSrcPort port number that has been reserved for the applicaion ! * @return String destination IP (other host IP that the application is connected to) ! * @exception TransportLayerException ! * @version v0.20 ! * @see TransportLayerException ! */ ! public String getApplicationDestIP(int inSrcPort) throws TransportLayerException ! { ! String dIP=null; ! TCP_HashTableElement Elm = null; ! ! Elm=(TCP_HashTableElement)PortTable.get((Integer)inSrcPort); ! dIP=Elm.connectedtoIP; ! ! return dIP; ! } ! ! ! /** ! * This method finds LOCAL port number for an application. Port number range: [PORT_START_NUMBER; PORT_START_NUMBER+PORT_QUANT] ! * @author gift (sourceforge.net user) ! * @param application which local port will be returned ! * @return int port number that has been reserved for application ! * @exception TransportLayerException in several cases ! * @version v0.10 ! * @see TransportLayerException ! */ ! public int getApplicationLocalPortNumber(Object application) throws TransportLayerException ! { ! Integer number= new Integer(0); ! boolean Found=false; ! boolean Reserved=false; ! Enumeration LocalPorts = PortTable.keys(); ! TCP_HashTableElement Elm = null; ! ! while ( (LocalPorts.hasMoreElements()) && !(Found) ) ! { ! number = (Integer)LocalPorts.nextElement(); ! Elm = (TCP_HashTableElement) PortTable.get(number); ! ! int UID1 = -2; ! int UID2 = -1; ! ! if(Elm.application!=null && application!=null){ ! UID1 = ((Application)Elm.application).getUID(); ! UID2 = ((Application)application).getUID(); ! } ! ! if ( UID1 == UID2 ) ! { ! Found=true; ! //we have found our application ! //everything is OK, need to return "number" ! } } ! ! //in case we have not found our application in hash table..... ! if (!Found) ! { ! throw new TransportLayerException("TCP Error: no local port reserved for the application: \"" + application.toString() + "\"! Can not get local reserved port number."); ! } ! ! return (number); //do not change here! if you want to change here scan again the code ! } ! } Index: Udp.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/core/protocolsuite/tcp_ip/Udp.java,v retrieving revision 1.25 retrieving revision 1.26 diff -C2 -d -r1.25 -r1.26 *** Udp.java 25 Nov 2005 16:57:35 -0000 1.25 --- Udp.java 25 Nov 2005 21:21:53 -0000 1.26 *************** *** 148,163 **** { int i; ! for(i=0;i<PORT_QUANT;i++) { ! UDP_HashTableElement Elm = new UDP_HashTableElement(); ! ! Elm.PortStatus=0; ! Elm.application=null; ! Elm.connectedtoIP=""; ! Elm.connectedtoPort=0; ! mParentStack = inParentStack; ! ! PortTable.put(new Integer((PORT_START_NUMBER+i)),Elm); // DANGEROUS PLACE! Check before change. } --- 148,160 ---- { int i; ! mParentStack = inParentStack; for(i=0;i<PORT_QUANT;i++) { ! UDP_HashTableElement Elm = new UDP_HashTableElement(); ! ! Elm.PortStatus=0; ! Elm.application=null; ! Elm.connectedtoIP=""; ! Elm.connectedtoPort=0; PortTable.put(new Integer((PORT_START_NUMBER+i)),Elm); // DANGEROUS PLACE! Check before change. } *************** *** 321,325 **** ! /** * This method reserves LOCAL port number for an application in case reserved. Port number range: [PORT_START_NUMBER; PORT_START_NUMBER+PORT_QUANT] * if not found then we reserve a new number --- 318,322 ---- ! /** * This method reserves LOCAL port number for an application in case reserved. Port number range: [PORT_START_NUMBER; PORT_START_NUMBER+PORT_QUANT] * if not found then we reserve a new number *************** *** 407,412 **** //For debugging ! UDP_HashTableElement Elm2 = new UDP_HashTableElement();//For debugging ! Elm2 = (UDP_HashTableElement) PortTable.get((Integer)number+1);//For debugging return (number); //do not change here! if you want to change here scan again the code --- 404,409 ---- //For debugging ! // UDP_HashTableElement Elm2 = new UDP_HashTableElement();//For debugging ! // Elm2 = (UDP_HashTableElement) PortTable.get((Integer)number+1);//For debugging return (number); //do not change here! if you want to change here scan again the code *************** *** 444,448 **** * @see TransportLayerException */ ! public void ClosePort(Object application) throws TransportLayerException //changes port status from 1 (listen) to 0 (free) { UDP_HashTableElement Elm=null; --- 441,445 ---- * @see TransportLayerException */ ! public void ClosePort(Object application) throws TransportLayerException //changes port status from 1 (listen) or (see proc ;) to 0 (free) { UDP_HashTableElement Elm=null; *************** *** 452,464 **** if (Elm.PortStatus==1 || (Elm.PortStatus==2 && PortToClose<PORT_START_NUMBER)) ! { ! //UDP_HashTableElement Elm = new UDP_HashTableElement(); Elm.PortStatus=0; Elm.application=null; Elm.connectedtoIP=""; ! Elm.connectedtoPort=0; ! ! //PortTable.remove(PortToClose); //delete old element ! //PortTable.put(PortToClose,Elm); //hash table update } else throw new TransportLayerException("UDP Error: port "+ PortToClose +" is not being LISTENED to by the application: \"" + application.toString() + "\"."); } --- 449,457 ---- if (Elm.PortStatus==1 || (Elm.PortStatus==2 && PortToClose<PORT_START_NUMBER)) ! { Elm.PortStatus=0; Elm.application=null; Elm.connectedtoIP=""; ! Elm.connectedtoPort=0; } else throw new TransportLayerException("UDP Error: port "+ PortToClose +" is not being LISTENED to by the application: \"" + application.toString() + "\"."); } *************** *** 473,477 **** * @see TransportLayerException */ ! public void FreePort(Object application) throws TransportLayerException //changes port status from 3 (listen) to 0 (free) { UDP_HashTableElement Elm=null; --- 466,470 ---- * @see TransportLayerException */ ! public void FreePort(Object application) throws TransportLayerException //changes port status from 2 (busy) to 0 (free) { UDP_HashTableElement Elm=null; *************** *** 482,493 **** if (Elm.PortStatus==2) { - //UDP_HashTableElement Elm = new UDP_HashTableElement(); Elm.PortStatus=0; Elm.application=null; Elm.connectedtoIP=""; Elm.connectedtoPort=0; - - //PortTable.remove(PortToFree); //delete old element - //PortTable.put(PortToFree,Elm); //hash table update } else throw new TransportLayerException("UDP Error: port "+ PortToFree +" is not BUSY by the application: \"" + application.toString() + "\"."); } --- 475,482 ---- *************** *** 551,558 **** * @version v0.10 * @see TransportLayerException ! */ ! ! // else throw new TransportLayerException("UDP Error: port "+ PortToFree +" is not BUSY by the application: \"" + application.toString() + "\"."); ! public void ListenPort(Object application, int in_Port) throws TransportLayerException { --- 540,544 ---- * @version v0.10 * @see TransportLayerException ! */ public void ListenPort(Object application, int in_Port) throws TransportLayerException { *************** *** 563,568 **** { if (inPort>=0 && inPort<=10000) ! { ! //UDP_HashTableElement oldElm = null; UDP_HashTableElement Elm = null; --- 549,553 ---- { if (inPort>=0 && inPort<=10000) ! { UDP_HashTableElement Elm = null; *************** *** 572,584 **** { case 0: //port is free => update such a record in hashtable - - //UDP_HashTableElement Elm = new UDP_HashTableElement(); Elm.PortStatus=1; Elm.application=application; Elm.connectedtoIP=""; Elm.connectedtoPort=0; - - //PortTable.remove(inPort); //delete old element - //PortTable.put(inPort,Elm); //hash table update break; case 1: // port is being listened to by whom? --- 557,564 ---- Index: Echo.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/core/protocolsuite/tcp_ip/Echo.java,v retrieving revision 1.13 retrieving revision 1.14 diff -C2 -d -r1.13 -r1.14 *** Echo.java 21 Nov 2005 14:56:01 -0000 1.13 --- Echo.java 25 Nov 2005 21:21:53 -0000 1.14 *************** *** 41,45 **** //throw new TransportLayerException("Cannot bind port " + listenPort + "."); try{ ! mParentStack.ListenUDP(this, listenPort); } catch (TransportLayerException e) { --- 41,45 ---- //throw new TransportLayerException("Cannot bind port " + listenPort + "."); try{ ! mParentStack.ListenUDP(this, listenPort); } catch (TransportLayerException e) { |