[Javanetsim-cvs] javaNetSim/core/protocolsuite/tcp_ip Application.java,1.8,1.9 Echo.java,1.9,1.10 Pr
Status: Beta
Brought to you by:
darkkey
From: gift <gi...@us...> - 2005-11-20 19:13:13
|
Update of /cvsroot/javanetsim/javaNetSim/core/protocolsuite/tcp_ip In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv13819/core/protocolsuite/tcp_ip Modified Files: Application.java Echo.java ProtocolStack.java Udp.java Log Message: Index: ProtocolStack.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/core/protocolsuite/tcp_ip/ProtocolStack.java,v retrieving revision 1.11 retrieving revision 1.12 diff -C2 -d -r1.11 -r1.12 *** ProtocolStack.java 20 Nov 2005 16:20:56 -0000 1.11 --- ProtocolStack.java 20 Nov 2005 19:13:04 -0000 1.12 *************** *** 764,773 **** }else if(ipPacket instanceof UDP_packet){ ! UDP_packet temp = (UDP_packet)inPacket; ! System.out.println("UDP packet here Receiving!!!! Message from ProtocolStack."); try{ mUDPprotocol.receiveUDPPacket(temp); ! }catch(TransportLayerException e){ ! //here *TODO*: insert catcher here } --- 764,779 ---- }else if(ipPacket instanceof UDP_packet){ ! UDP_packet temp = (UDP_packet)inPacket; try{ mUDPprotocol.receiveUDPPacket(temp); ! }catch(TransportLayerException te){ ! //here *TODO*: disconnect sender from port!!! ! ! 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 packet receiving: \""+ te.toString() + "\"."); ! Simulation.addLayerInfo(UDP_Info); } *************** *** 1238,1261 **** * @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() +"\"."); ! } --- 1244,1272 ---- * @exception InvalidNetworkLayerDeviceException * @exception TransportLayerException + * @exception CommunicationException * @version v0.30 * @see InvalidNetworkLayerDeviceException * @see TransportLayerException + * @see CommunicationException */ ! public int reserveUDPPort(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 mUDPprotocol.ReservePort(application,inDestIPAddress,indestPort); ! } else ! throw new InvalidNetworkLayerDeviceException("Network interface unavailable on host \"" + temp.getName() +"\"."); ! }else ! throw new CommunicationException("Packet dropped host unreachable: " + inDestIPAddress); } *************** *** 1273,1278 **** public void CloseUDP(Object application) throws TransportLayerException ! { mUDPprotocol.ClosePort(application); } --- 1284,1299 ---- public void CloseUDP(Object application) throws TransportLayerException ! { ! try { mUDPprotocol.ClosePort(application); + } catch (TransportLayerException te) + { + 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() + "\"."); + Simulation.addLayerInfo(UDP_Info); + } } *************** *** 1288,1293 **** */ public void freeUDPPort(Object application) throws TransportLayerException ! { mUDPprotocol.FreePort(application); } --- 1309,1324 ---- */ public void freeUDPPort(Object application) throws TransportLayerException ! { ! try { mUDPprotocol.FreePort(application); + } catch (TransportLayerException te) + { + 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() + "\"."); + Simulation.addLayerInfo(UDP_Info); + } } *************** *** 1304,1308 **** --- 1335,1350 ---- public void ListenUDP(Object application, int inPort) throws TransportLayerException { + try{ mUDPprotocol.ListenPort(application,inPort); + + } catch (TransportLayerException te) + { + 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 listening: \""+ te.toString() + "\"."); + Simulation.addLayerInfo(UDP_Info); + } } *************** *** 1354,1358 **** --- 1396,1420 ---- //throw new InvalidNetworkLayerDeviceException("Network interface unavailable on host \"" + temp.getName() +"\"."); }catch(Exception e){ + + try { + mUDPprotocol.FreePort(application); + + LayerInfo UDP_Info = new LayerInfo(getClass().getName()); + UDP_Info.setObjectName(getParentNodeName()); + UDP_Info.setDataType("UDP Packet"); + UDP_Info.setLayer("Transport"); + UDP_Info.setDescription("UDP sending error: \""+ e.toString() + "\"."); + Simulation.addLayerInfo(UDP_Info); //*TODO*: here we shall put some layerinfo for TransportException + } catch (TransportLayerException te) + { + 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() + "\"."); + Simulation.addLayerInfo(UDP_Info); + } + } } Index: Application.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/core/protocolsuite/tcp_ip/Application.java,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** Application.java 19 Nov 2005 21:53:51 -0000 1.8 --- Application.java 20 Nov 2005 19:13:04 -0000 1.9 *************** *** 65,69 **** */ ! public abstract void ClientConnect(String Host, int port) throws TransportLayerException, InvalidNetworkLayerDeviceException; /** --- 65,69 ---- */ ! public abstract void ClientConnect(String Host, int port) throws TransportLayerException, InvalidNetworkLayerDeviceException, CommunicationException; /** Index: Udp.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/core/protocolsuite/tcp_ip/Udp.java,v retrieving revision 1.18 retrieving revision 1.19 diff -C2 -d -r1.18 -r1.19 *** Udp.java 20 Nov 2005 16:05:19 -0000 1.18 --- Udp.java 20 Nov 2005 19:13:04 -0000 1.19 *************** *** 203,209 **** switch(Elm.PortStatus) { ! 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 --- 203,213 ---- switch(Elm.PortStatus) { ! case 0: //port is free => Error: no application to receive UDP ! //have to disconnect listener from port ! Application listener; ! listener = (Application)Elm.application; ! listener.Disconnect(); ! throw new TransportLayerException("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 *************** *** 233,237 **** Simulation.addLayerInfo(UDP_Info); ! Application listener; listener = (Application)Elm.application; listener.RecvData(inPacket.getUDP_message()); --- 237,241 ---- Simulation.addLayerInfo(UDP_Info); ! listener = (Application)Elm.application; listener.RecvData(inPacket.getUDP_message()); *************** *** 265,269 **** Simulation.addLayerInfo(UDP_Info); ! Application listener; listener = (Application)Elm.application; listener.RecvData(inPacket.getUDP_message()); --- 269,273 ---- Simulation.addLayerInfo(UDP_Info); ! listener = (Application)Elm.application; listener.RecvData(inPacket.getUDP_message()); *************** *** 272,284 **** 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." + "Port "+inPacket.get_destPort() +" on host \""+ mParentStack.getParentNodeName()+"\"."); } break; default: //UDP Error: unknown port status :( throw new TransportLayerException("UDP Error: unknown port status! Port "+inPacket.get_destPort() +" on host \""+ mParentStack.getParentNodeName()+"\"."); } } else { throw new TransportLayerException("UDP Error: port " + inPacket.get_destPort() + " does not exist. Host \"" + mParentStack.getParentNodeName()+"\"."); } --- 276,303 ---- throw new TransportLayerException("UDP Error: incorrect checksum on receiving!"); } ! } else { ! //have to disconnect listener from port ! ! listener = (Application)Elm.application; ! listener.Disconnect(); throw new TransportLayerException("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 + + listener = (Application)Elm.application; + listener.Disconnect(); throw new TransportLayerException("UDP Error: unknown port status! Port "+inPacket.get_destPort() +" on host \""+ mParentStack.getParentNodeName()+"\"."); } } else { + //have to disconnect listener from port + UDP_HashTableElement Elm = null; + Elm=(UDP_HashTableElement)PortTable.get(inPacket.get_destPort()); + Application listener; + listener = (Application)Elm.application; + listener.Disconnect(); /* throw new TransportLayerException("UDP Error: port " + inPacket.get_destPort() + " does not exist. Host \"" + mParentStack.getParentNodeName()+"\"."); } Index: Echo.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/core/protocolsuite/tcp_ip/Echo.java,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** Echo.java 20 Nov 2005 16:36:59 -0000 1.9 --- Echo.java 20 Nov 2005 19:13:04 -0000 1.10 *************** *** 63,67 **** */ ! public void ClientConnect(String Host, int port) throws TransportLayerException, InvalidNetworkLayerDeviceException { sdHost = Host; sdPort = port; --- 63,67 ---- */ ! public void ClientConnect(String Host, int port) throws TransportLayerException, InvalidNetworkLayerDeviceException, CommunicationException { sdHost = Host; sdPort = port; |