[Javanetsim-cvs] javaNetSim/core/protocolsuite/tcp_ip ARP.java,1.2,1.3 Application.java,1.6,1.7 Echo
Status: Beta
Brought to you by:
darkkey
From: gift <gi...@us...> - 2005-11-19 20:13:16
|
Update of /cvsroot/javanetsim/javaNetSim/core/protocolsuite/tcp_ip In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv20327/core/protocolsuite/tcp_ip Modified Files: ARP.java Application.java Echo.java ICMP.java ProtocolStack.java Udp.java Log Message: ...ohhh Index: Udp.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/core/protocolsuite/tcp_ip/Udp.java,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** Udp.java 19 Nov 2005 11:16:51 -0000 1.5 --- Udp.java 19 Nov 2005 20:13:07 -0000 1.6 *************** *** 71,74 **** --- 71,76 ---- import core.TransportLayerException; + import core.InvalidNetworkLayerDeviceException; + import core.protocolsuite.tcp_ip.ProtocolStack; *************** *** 128,135 **** public class UDP_HashTableElement { ! public byte PortStatus; // 0 - free port; 1 - port is being listened to; 2 - closed; 3 - busy. public Object application; //points to application that listens to this port | provided PortStatus==1 public String connectedtoIP; //contains IP of the other connected computer | provided PortStatus==3 ! public int connectedtoPort; //contains port number of the other connected computer | provided PortStatus==3 } --- 130,137 ---- public class UDP_HashTableElement { ! public byte PortStatus; // 0 - free port; 1 - port is being listened to; 2 - busy. public Object application; //points to application that listens to this port | provided PortStatus==1 public String connectedtoIP; //contains IP of the other connected computer | provided PortStatus==3 ! public int connectedtoPort; //contains port number of the other connected computer | provided PortStatus==3 } *************** *** 142,146 **** * This method assigns the ParentStack * @author gift (sourceforge.net user) ! * @param Protocol Stack * @version v0.20 */ --- 144,148 ---- * This method assigns the ParentStack * @author gift (sourceforge.net user) ! * @param inParentStack protocol stack * @version v0.20 */ *************** *** 161,165 **** } } ! /** --- 163,167 ---- } } ! /** *************** *** 170,178 **** * @return Nothing. * @exception TransportLayerException If UDP CHECK_SUM != 1 * @version v0.20 * @see TransportLayerException ! */ ! public void receiveUDPPacket(UDP_packet inPacket) throws TransportLayerException { --- 172,186 ---- * @return Nothing. * @exception TransportLayerException If UDP CHECK_SUM != 1 + * @exception CommunicationException + * @exception LowLinkException + * @exception InvalidNetworkLayerDeviceException * @version v0.20 * @see TransportLayerException ! * @see CommunicationException ! * @see LowLinkException ! * @see InvalidNetworkLayerDeviceException ! */ ! public void receiveUDPPacket(UDP_packet inPacket) throws TransportLayerException, CommunicationException, LowLinkException, InvalidNetworkLayerDeviceException { *************** *** 192,202 **** { case 0: //port is free => Error: no application to receive UDP ! throw new TransportLayerException("UDP Error: no 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=3; //port will be busy from now Elm.connectedtoIP=inPacket.getSourceIPAddress(); Elm.connectedtoPort=inPacket.get_srcPort(); //now we decompose UDP datagram --- 200,213 ---- { case 0: //port is free => Error: no application to receive UDP ! throw new TransportLayerException("UDP Error: no 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((inPacket.get_destPort()),Elm); //hash table update + //now we decompose UDP datagram *************** *** 217,230 **** Simulation.addLayerInfo(UDP_Info); } else { ! throw new TransportLayerException("UDP Error: Incorrect checksum on receiving."); } break; ! ! case 2: //port is closed ! throw new TransportLayerException("UDP Error: port is closed! Port "+inPacket.get_destPort() +" on host \""+ mParentStack.getParentNodeName()+"\"." ); ! // no "break" needed ;) ! case 3: //busy port, let's check whether it's busy by us (sender) ;) ! if ((Elm.connectedtoIP==inPacket.getSourceIPAddress()) && (Elm.connectedtoPort==inPacket.get_srcPort())) //temporary { //now we decompose UDP datagram --- 228,244 ---- 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())) //temporary { //now we decompose UDP datagram *************** *** 246,254 **** Simulation.addLayerInfo(UDP_Info); } else { ! throw new TransportLayerException("UDP Error: Incorrect checksum on receiving."); } } else { ! throw new TransportLayerException("UDP Error: Port is connected to another host or/and port. \r\n" + "Port "+inPacket.get_destPort() +" on host \""+ mParentStack.getParentNodeName()+"\"."); } break; --- 260,273 ---- 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 { ! throw new TransportLayerException("UDP Error: port is busy! Port is connected to another host or/and port and is busy by another application. \r\n" + "Port "+inPacket.get_destPort() +" on host \""+ mParentStack.getParentNodeName()+"\"."); } break; *************** *** 258,262 **** } } else { ! throw new TransportLayerException("UDP Error: Port " + inPacket.get_destPort() + " does not exist. Host \"" + mParentStack.getParentNodeName()+"\"."); } } --- 277,281 ---- } } else { ! throw new TransportLayerException("UDP Error: port " + inPacket.get_destPort() + " does not exist. Host \"" + mParentStack.getParentNodeName()+"\"."); } } *************** *** 269,282 **** * @param inDestIPAddress destination IP address * @param FirstInterfaceName name of the first network intarface of the node that sends UDP e.g. "eth0" ! * @param indestPort destination port number ! * @param insrcPort sorce port number * @return UDP_packet ! * @version v0.20 */ ! public UDP_packet sendUDPPacket(String inDestIPAddress,String FirstInterfaceName,int indestPort, int insrcPort) { ! ! UDP_packet tosend = new UDP_packet(inDestIPAddress,mParentStack.getIPAddress(FirstInterfaceName),indestPort,insrcPort); //Create Layer info --- 288,315 ---- * @param inDestIPAddress destination IP address * @param FirstInterfaceName name of the first network intarface of the node that sends UDP e.g. "eth0" ! * @param indestPort destination port number ! * @param application application that uses port ! * @param inMessage UDP message to send * @return UDP_packet ! * @exception TransportLayerException ! * @version v0.30 ! * @see TransportLayerException */ ! public UDP_packet sendUDPPacket(Object application,String inDestIPAddress,String inFirstInterfaceName, int indestPort, String inMessage) throws TransportLayerException { ! int srcPort; ! String SrcIP; ! ! //let's get first interface IP address ! SrcIP=mParentStack.getIPAddress(inFirstInterfaceName); ! ! //let's get a reserved local port number for this application ! srcPort=getApplicationLocalPortNumber(application); ! ! ! UDP_packet tosend = new UDP_packet(inDestIPAddress,SrcIP,indestPort,srcPort); ! ! tosend.setUDP_message(inMessage); //Create Layer info *************** *** 290,294 **** UDP_Info.setLayer("Transport"); ! UDP_Info.setDescription("Created UDP packet to " + inDestIPAddress + ":" + insrcPort +"."); Simulation.addLayerInfo(UDP_Info); --- 323,327 ---- UDP_Info.setLayer("Transport"); ! UDP_Info.setDescription("Created UDP packet to " + inDestIPAddress + ":" + srcPort +"."); Simulation.addLayerInfo(UDP_Info); *************** *** 296,300 **** --- 329,657 ---- return tosend; } + + + /** + * 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 getDefinitePortNumber(Object application,String inDestIPAddress, int indestPort) throws TransportLayerException + { + int number=0; + boolean Found=false; + boolean Reserved=false; + Enumeration LocalPorts = PortTable.keys(); + + + UDP_HashTableElement Elm = new UDP_HashTableElement(); + + while ( (LocalPorts.hasMoreElements()) && !(Found) ) + { + number = Integer.valueOf( (String)LocalPorts.nextElement() ); + + Elm = (UDP_HashTableElement) PortTable.get(number); + + if (Elm.application == application) + { + 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("UDP Error: application is already connected to another port number! Connected to host: " + Elm.connectedtoIP + ":" + Elm.connectedtoPort + "."); + } + } else { + throw new TransportLayerException("UDP 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=0; + while ( (number<PORT_QUANT) && !(Reserved) ) + { + Elm = (UDP_HashTableElement) PortTable.get(number+PORT_START_NUMBER); + + if (Elm.PortStatus == 0) //free port + { + Reserved=true; + Elm.PortStatus=2; //port will be busy from now + Elm.connectedtoIP=inDestIPAddress; + Elm.connectedtoPort=indestPort; + PortTable.remove(number+PORT_START_NUMBER); //delete old element + PortTable.put(number+PORT_START_NUMBER,Elm); //hash table update + } + number++; + } + + if (!Reserved) //all ports are busy :( + { + throw new TransportLayerException("UDP Error: all ports are busy! Can not send UDP datagram to host " + inDestIPAddress + ":" + indestPort +"."); + } + number+=PORT_START_NUMBER; //to get the real number + } + + return (number); //do not change here! if you want to change here scan again the code + } + + /** + * This method reserves LOCAL UDP 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 TransportLayerException + * @version v0.30 + * @see TransportLayerException + */ + public int ReservePort(Object application, String inDestIPAddress, int indestPort) throws TransportLayerException + { + //let's get a proper port number for this application + return getDefinitePortNumber(application,inDestIPAddress,indestPort); + } + + /** + * 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 application + * @return int port number that has been reserved for application + * @exception TransportLayerException + * @version v0.10 + * @see TransportLayerException + */ + public int getApplicationDestPortNumber(Object application) throws TransportLayerException + { + int number=0; + boolean Found=false; + Set set = PortTable.keySet(); + Iterator itr = set.iterator(); + UDP_HashTableElement Elm = new UDP_HashTableElement(); + + while ( (itr.hasNext()) && !(Found) ) + { + Elm = (UDP_HashTableElement) itr.next(); + + if (Elm.application == application) + { + Found=true; + //we have found our application + number=Elm.connectedtoPort; + } + } + + //in case we have not found our application in hash table..... + if (!Found) + { + throw new TransportLayerException("UDP Error: no local port reserved for the application: \"" + application.toString() + "\"! Can not find destination port."); + } + return number; + } + + /** + * This method closes the UDP 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) to 0 (free) + { + UDP_HashTableElement Elm = new UDP_HashTableElement(); + int PortToClose=getApplicationLocalPortNumber(application); + + if (Elm.PortStatus==1) + { + 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() + "\"."); + } + + /** + * This method sets the UDP 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 3 (listen) to 0 (free) + { + UDP_HashTableElement Elm = new UDP_HashTableElement(); + int PortToFree=getApplicationLocalPortNumber(application); + + if (Elm.PortStatus==2) + { + 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() + "\"."); + } + + + /** + * This method sets the UDP port status to 1 (is being listened to) + * NOTE: server must listen to UDP port numbers from 0 to 10000 + * @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 + */ + + // else throw new TransportLayerException("UDP Error: port "+ PortToFree +" is not BUSY by the application: \"" + application.toString() + "\"."); + + public void ListenPort(Object application, int inPort) throws TransportLayerException + { + if (inPort>=0 && inPort<=10000) + { + UDP_HashTableElement Elm = new UDP_HashTableElement(); + + if ( (Elm = (UDP_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; + + PortTable.remove(inPort); //delete old element + PortTable.put(inPort,Elm); //hash table update + break; + case 1: // port is being listened to by whom? + if (Elm.application==application) + { + throw new TransportLayerException("UDP Error: already listening to port "+ inPort +"!"); + } else throw new TransportLayerException("UDP 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("UDP Error: port "+ inPort +" is busy! Can listen only to free ports." ); + // no "break" needed ;) + default: //unknown port status + throw new TransportLayerException("UDP Error: unknown port status! Port "+ inPort +" on host \""+ mParentStack.getParentNodeName()+"\"."); + } + + } else + { + //create such a record in hashtable + Elm.PortStatus=1; + Elm.application=application; + Elm.connectedtoIP=""; + Elm.connectedtoPort=0; + + PortTable.put(inPort,Elm); //hash table update + } + } else throw new TransportLayerException("UDP Error: can not listen to port "+ inPort +"! Use port range from 0 to 10000 to listen to."); + } + + /** + * This method finds destination IP (host) for an application. + * @author gift (sourceforge.net user) + * @param application + * @return String destination IP that has been reserved for application + * @exception TransportLayerException + * @version v0.10 + * @see TransportLayerException + */ + public String getApplicationDestIP(Object application) throws TransportLayerException + { + String dIP=null; + boolean Found=false; + Set set = PortTable.keySet(); + Iterator itr = set.iterator(); + UDP_HashTableElement Elm = new UDP_HashTableElement(); + + while ( (itr.hasNext()) && !(Found) ) + { + Elm = (UDP_HashTableElement) itr.next(); + + if (Elm.application == application) + { + Found=true; + //we have found our application + dIP=Elm.connectedtoIP; + } + } + + //in case we have not found our application in hash table..... + if (!Found) + { + throw new TransportLayerException("UDP Error: no local port reserved for the application: \"" + application.toString() + "\"! Can not find destination IP."); + } + 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 that will: take free port or take already occupied port (only by itself) or tell that all ports are busy :( + * @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 + { + int number=0; + boolean Found=false; + boolean Reserved=false; + Enumeration LocalPorts = PortTable.keys(); + UDP_HashTableElement Elm = new UDP_HashTableElement(); + + while ( (LocalPorts.hasMoreElements()) && !(Found) ) + { + number = Integer.valueOf( (String)LocalPorts.nextElement() ); + Elm = (UDP_HashTableElement) PortTable.get(number); + + if (Elm.application == application) + { + 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("UDP 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 + } } //EOF Index: ProtocolStack.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/core/protocolsuite/tcp_ip/ProtocolStack.java,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** ProtocolStack.java 19 Nov 2005 17:54:33 -0000 1.6 --- ProtocolStack.java 19 Nov 2005 20:13:07 -0000 1.7 *************** *** 191,195 **** */ ! public void sendPacket(IP_packet inPacket) throws LowLinkException, CommunicationException{ String destMAC = null; --- 191,195 ---- */ ! public void sendPacket(IP_packet inPacket) throws TransportLayerException, CommunicationException, LowLinkException, InvalidNetworkLayerDeviceException{ String destMAC = null; *************** *** 324,328 **** */ ! public void forwardPacket(IP_packet inPacket) throws CommunicationException, LowLinkException{ String destMAC = null; --- 324,328 ---- */ ! public void forwardPacket(IP_packet inPacket) throws TransportLayerException, CommunicationException, LowLinkException, InvalidNetworkLayerDeviceException{ String destMAC = null; *************** *** 416,420 **** */ ! public void broadcastPacket(IP_packet inPacket, String interfaceName) throws CommunicationException, LowLinkException{ String destMAC = "FF:FF:FF:FF:FF:FF"; --- 416,420 ---- */ ! public void broadcastPacket(IP_packet inPacket, String interfaceName) throws TransportLayerException, CommunicationException, LowLinkException, InvalidNetworkLayerDeviceException{ String destMAC = "FF:FF:FF:FF:FF:FF"; *************** *** 530,534 **** */ ! public void sendPing(String inDestIPAddress) throws CommunicationException, LowLinkException { if(IPV4Address.validateDecIP(inDestIPAddress)){ --- 530,534 ---- */ ! public void sendPing(String inDestIPAddress) throws TransportLayerException, CommunicationException, LowLinkException, InvalidNetworkLayerDeviceException { if(IPV4Address.validateDecIP(inDestIPAddress)){ *************** *** 686,690 **** */ ! public void receivePacket(Packet inPacket) throws LowLinkException{ --- 686,690 ---- */ ! public void receivePacket(Packet inPacket) throws TransportLayerException, CommunicationException, LowLinkException, InvalidNetworkLayerDeviceException{ *************** *** 750,755 **** mARPprotocol.receiveARPPacket(temp); ! }else{ //need to insert tests for all other packet types --- 750,760 ---- mARPprotocol.receiveARPPacket(temp); ! }else if(ipPacket instanceof UDP_packet){ ! ! UDP_packet temp = (UDP_packet)inPacket; ! ! mUDPprotocol.receiveUDPPacket(temp); + }else{ //need to insert tests for all other packet types *************** *** 1209,1249 **** /** ! * This method sends the UDP packet * @author gift (sourceforge.net user) * @param inDestIPAddress destination IP address ! * @param InterfaceName name of the intarface that sends UDP e.g. "eth0" ! * @param indestPort destination port number ! * @param insrcPort sorce port number * @return Nothing * @exception CommunicationException * @exception LowLinkException * @exception InvalidNetworkLayerDeviceException ! * @version v0.20 * @see CommunicationException * @see LowLinkException * @see InvalidNetworkLayerDeviceException */ ! public void sendUDP(String inDestIPAddress, int indestPort, int insrcPort) throws CommunicationException, LowLinkException, InvalidNetworkLayerDeviceException { //lets get first network interface name //will be used when resolving source IP of UDP sender ! String FirstInterfaceName; Node temp = (Node)mParentNode; FirstInterfaceName = temp.getFirstInterfaceName(); if (FirstInterfaceName!=null) { ! if(IPV4Address.validateDecIP(inDestIPAddress)) ! { ! UDP_packet tosend = mUDPprotocol.sendUDPPacket(inDestIPAddress,FirstInterfaceName,indestPort,insrcPort); ! sendPacket(tosend); }else ! throw new CommunicationException("Packet dropped host unreachable: " + inDestIPAddress); } else throw new InvalidNetworkLayerDeviceException("Network interface unavailable on host \"" + temp.getName() +"\"."); ! } }//EOF --- 1214,1337 ---- /** ! * This method reserves the UDP 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 ! * @version v0.30 ! * @see InvalidNetworkLayerDeviceException ! * @see TransportLayerException ! */ ! ! public int reserveUDPPort(Object application, String inDestIPAddress, int indestPort) throws InvalidNetworkLayerDeviceException, TransportLayerException ! { ! ! //lets get first network interface name ! //will be used when resolving source IP of UDP sender ! String FirstInterfaceName; ! Node temp = (Node)mParentNode; ! FirstInterfaceName = temp.getFirstInterfaceName(); ! ! if (FirstInterfaceName!=null) ! { ! return mUDPprotocol.ReservePort(application,inDestIPAddress,indestPort); ! } else ! throw new InvalidNetworkLayerDeviceException("Network interface unavailable on host \"" + temp.getName() +"\"."); ! ! } ! ! ! ! /** ! * This method closes the UDP 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 CloseUDP(Object application) throws TransportLayerException ! { ! mUDPprotocol.ClosePort(application); ! } ! ! ! /** ! * This method sets the UDP port free ! * @author gift (sourceforge.net user) ! * @param application application that uses port ! * @return Nothing ! * @exception TransportLayerException ! * @version v0.10 ! * @see TransportLayerException ! */ ! public void freeUDPPort(Object application) throws TransportLayerException ! { ! mUDPprotocol.FreePort(application); ! } ! ! /** ! * This method sets the UDP 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 ListenUDP(Object application, int inPort) throws TransportLayerException ! { ! mUDPprotocol.ListenPort(application,inPort); ! } ! ! /** ! * This method sends the UDP packet ! * @author gift (sourceforge.net user) ! * @param application the application that sends the message ! * @param inUDPMessage UDP message to send * @return Nothing * @exception CommunicationException * @exception LowLinkException * @exception InvalidNetworkLayerDeviceException ! * @exception TransportLayerException ! * @version v0.30 * @see CommunicationException * @see LowLinkException * @see InvalidNetworkLayerDeviceException + * @see TransportLayerException */ ! public void sendUDP(Object application, String inUDPMessage) throws CommunicationException, LowLinkException, InvalidNetworkLayerDeviceException, TransportLayerException { //lets get first network interface name //will be used when resolving source IP of UDP sender ! String FirstInterfaceName; ! String DestIPAddress; ! int destPort; Node temp = (Node)mParentNode; FirstInterfaceName = temp.getFirstInterfaceName(); + + DestIPAddress=mUDPprotocol.getApplicationDestIP(application); + destPort=mUDPprotocol.getApplicationDestPortNumber(application); if (FirstInterfaceName!=null) { ! if(IPV4Address.validateDecIP(DestIPAddress)) ! { ! UDP_packet tosend = mUDPprotocol.sendUDPPacket(application, DestIPAddress,FirstInterfaceName,destPort,inUDPMessage); ! sendPacket(tosend); }else ! throw new CommunicationException("Packet dropped host unreachable: " + DestIPAddress); } else throw new InvalidNetworkLayerDeviceException("Network interface unavailable on host \"" + temp.getName() +"\"."); ! } }//EOF Index: ARP.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/core/protocolsuite/tcp_ip/ARP.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** ARP.java 17 Nov 2005 20:13:56 -0000 1.2 --- ARP.java 19 Nov 2005 20:13:07 -0000 1.3 *************** *** 75,78 **** --- 75,82 ---- import core.LayerInfo; + import core.TransportLayerException; + + import core.InvalidNetworkLayerDeviceException; + *************** *** 317,321 **** */ ! public String getMACAddress(String IPAddress, String inInterfaceKey) throws LowLinkException { --- 321,325 ---- */ ! public String getMACAddress(String IPAddress, String inInterfaceKey) throws TransportLayerException, CommunicationException, LowLinkException, InvalidNetworkLayerDeviceException { *************** *** 425,429 **** ! public void receiveARPPacket(ARP_packet inARPpacket) throws LowLinkException{ // test if this packet is for a local Address. --- 429,433 ---- ! public void receiveARPPacket(ARP_packet inARPpacket) throws TransportLayerException, CommunicationException, LowLinkException, InvalidNetworkLayerDeviceException{ // test if this packet is for a local Address. Index: Application.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/core/protocolsuite/tcp_ip/Application.java,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** Application.java 19 Nov 2005 16:16:32 -0000 1.6 --- Application.java 19 Nov 2005 20:13:07 -0000 1.7 *************** *** 9,12 **** --- 9,18 ---- import core.TransportLayerException; + import core.InvalidNetworkLayerDeviceException; + + import core.CommunicationException; + + import core.LowLinkException; + /** * *************** *** 47,51 **** * @version v0.01 */ ! public void Close(){} /** --- 53,57 ---- * @version v0.01 */ ! public void Close() throws TransportLayerException{} /** *************** *** 65,69 **** */ ! public void Disconnect(){} /** --- 71,75 ---- */ ! public void Disconnect()throws TransportLayerException{} /** *************** *** 74,78 **** */ ! public void SendData(String Data) throws TransportLayerException {} /** --- 80,84 ---- */ ! public void SendData(String Data) throws CommunicationException, LowLinkException, InvalidNetworkLayerDeviceException, TransportLayerException {} /** *************** *** 82,86 **** * @version v0.01 */ ! public void RecvData(String Data) throws TransportLayerException {} public void setPort(int port){ --- 88,92 ---- * @version v0.01 */ ! public void RecvData(String Data) throws CommunicationException, LowLinkException, InvalidNetworkLayerDeviceException, TransportLayerException {} public void setPort(int port){ Index: ICMP.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/core/protocolsuite/tcp_ip/ICMP.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** ICMP.java 17 Nov 2005 20:13:56 -0000 1.2 --- ICMP.java 19 Nov 2005 20:13:07 -0000 1.3 *************** *** 73,76 **** --- 73,82 ---- import core.Simulation; + import core.TransportLayerException; + + import core.InvalidNetworkLayerDeviceException; + + + *************** *** 143,147 **** */ ! public void receiveICMPPacket(ICMP_packet inPacket) throws LowLinkException { --- 149,153 ---- */ ! public void receiveICMPPacket(ICMP_packet inPacket) throws TransportLayerException, CommunicationException, LowLinkException, InvalidNetworkLayerDeviceException { *************** *** 195,199 **** */ ! private void echoRequest(ICMP_packet inPacket) throws LowLinkException{ String destIPAddress = inPacket.getSourceIPAddress(); --- 201,205 ---- */ ! private void echoRequest(ICMP_packet inPacket) throws TransportLayerException, CommunicationException, LowLinkException, InvalidNetworkLayerDeviceException{ String destIPAddress = inPacket.getSourceIPAddress(); Index: Echo.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/core/protocolsuite/tcp_ip/Echo.java,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** Echo.java 19 Nov 2005 14:26:02 -0000 1.5 --- Echo.java 19 Nov 2005 20:13:07 -0000 1.6 *************** *** 10,13 **** --- 10,20 ---- import core.TransportLayerException; + import core.InvalidNetworkLayerDeviceException; + + import core.CommunicationException; + + import core.LowLinkException; + + /** * *************** *** 27,32 **** */ public void Listen() throws TransportLayerException{ ! //throw new TransportLayerException("Cannot bind port " + listenPort + "."); ! //mParentStack.ListenUDP(this, listenPort); } --- 34,39 ---- */ public void Listen() throws TransportLayerException{ ! //throw new TransportLayerException("Cannot bind port " + listenPort + "."); ! mParentStack.ListenUDP(this, listenPort); } *************** *** 38,43 **** * @version v0.01 */ ! public void Close(){ ! //mParentStack.CloseUDP(this); } --- 45,51 ---- * @version v0.01 */ ! public void Close() throws TransportLayerException ! { ! mParentStack.CloseUDP(this); } *************** *** 49,57 **** * @version v0.01 */ ! ! public void ClientConnect(String Host, int port) throws TransportLayerException { sdHost = Host; ! sdPort = port; ! //clientPort = mParentStack.reserveUDPPort(this, sdHost, sdPort); } --- 57,65 ---- * @version v0.01 */ ! ! public void ClientConnect(String Host, int port) throws TransportLayerException, InvalidNetworkLayerDeviceException { sdHost = Host; ! sdPort = port; ! clientPort = mParentStack.reserveUDPPort(this, sdHost, sdPort); } *************** *** 73,78 **** */ ! public void Disconnect(){ ! //mParentStack.freeUDPPort(this); } --- 81,86 ---- */ ! public void Disconnect() throws TransportLayerException { ! mParentStack.freeUDPPort(this); } *************** *** 84,89 **** */ ! public void SendData(String Data) throws TransportLayerException { ! //mParentStack.sendUDP(this, Data); //processing the protocol doings. } --- 92,98 ---- */ ! public void SendData(String Data) throws CommunicationException, LowLinkException, InvalidNetworkLayerDeviceException, TransportLayerException ! { ! mParentStack.sendUDP(this, Data); //processing the protocol doings. } *************** *** 97,101 **** * @version v0.01 */ ! public void RecvData(String Data) throws TransportLayerException { //processing the protocol doings. if(appType == 0){ --- 106,110 ---- * @version v0.01 */ ! public void RecvData(String Data) throws CommunicationException, LowLinkException, InvalidNetworkLayerDeviceException, TransportLayerException { //processing the protocol doings. if(appType == 0){ *************** *** 119,123 **** * @version v0.01 */ ! public void SendEcho(String Data, String Host, int port) throws TransportLayerException{ ClientConnect(Host, port); SendData(Data); --- 128,132 ---- * @version v0.01 */ ! public void SendEcho(String Data, String Host, int port) throws CommunicationException, LowLinkException, InvalidNetworkLayerDeviceException, TransportLayerException{ ClientConnect(Host, port); SendData(Data); |