[Javanetsim-cvs] javaNetSim/core/protocolsuite/tcp_ip ICMP.java, 1.5, 1.6 ICMP_packet.java, 1.5, 1.
Status: Beta
Brought to you by:
darkkey
From: Alexander B. <da...@us...> - 2008-09-28 17:11:57
|
Update of /cvsroot/javanetsim/javaNetSim/core/protocolsuite/tcp_ip In directory sc8-pr-cvs17.sourceforge.net:/tmp/cvs-serv11437/core/protocolsuite/tcp_ip Modified Files: ICMP.java ICMP_packet.java ProtocolStack.java Log Message: Index: ProtocolStack.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/core/protocolsuite/tcp_ip/ProtocolStack.java,v retrieving revision 1.67 retrieving revision 1.68 diff -C2 -d -r1.67 -r1.68 *** ProtocolStack.java 25 Sep 2008 21:43:46 -0000 1.67 --- ProtocolStack.java 28 Sep 2008 17:11:47 -0000 1.68 *************** *** 1,59 **** /* ! Java Firewall Simulator (jFirewallSim) ! ! ! ! Copyright (c) 2004, jFirewallSim development team All rights reserved. [...2582 lines suppressed...] ! iface = (String) (nics.get(i)); ! if (temp.isActiveInterface(iface)) { ! IP = getIPAddress((String) nics.get(i)); ! if (IP != null) { ! return IP; ! } ! } ! } catch (InvalidNetworkInterfaceNameException e) { ! e.printStackTrace(); ! } ! } ! return ""; ! } ! ! public void intUP(String iface) { ! ! } ! ! }// EOF Index: ICMP_packet.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/core/protocolsuite/tcp_ip/ICMP_packet.java,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** ICMP_packet.java 25 Sep 2008 21:43:46 -0000 1.5 --- ICMP_packet.java 28 Sep 2008 17:11:47 -0000 1.6 *************** *** 68,72 **** public ICMP_packet(String inDestIPAddress) { ! super (inDestIPAddress); } /** --- 68,72 ---- public ICMP_packet(String inDestIPAddress) { ! super (inDestIPAddress); } /** Index: ICMP.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/core/protocolsuite/tcp_ip/ICMP.java,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** ICMP.java 25 Sep 2008 21:43:46 -0000 1.5 --- ICMP.java 28 Sep 2008 17:11:47 -0000 1.6 *************** *** 1,68 **** /* ! Java Firewall Simulator (jFirewallSim) ! ! ! ! Copyright (c) 2004, jFirewallSim development team All rights reserved. ! - Redistribution and use in source and binary forms, with or without modification, are ! permitted provided that the following conditions are met: ! - Redistributions of source code must retain the above copyright notice, this list ! of conditions and the following disclaimer. - - Redistributions in binary form must reproduce the above copyright notice, this list - of conditions and the following disclaimer in the documentation and/or other ! materials provided with the distribution. ! - Neither the name of the Canberra Institute of Technology nor the names of its ! contributors may be used to endorse or promote products derived from this software ! without specific prior written permission. ! THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY ! EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL - THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, ! EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF ! SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) ! HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR ! TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, ! EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ! */ package core.protocolsuite.tcp_ip; - - import java.io.Serializable; import java.util.Hashtable; ! //import core.protocolsuite.tcp_ip.ICMP_packet; import core.CommunicationException; --- 1,62 ---- /* ! Java Firewall Simulator (jFirewallSim) ! Copyright (c) 2004, jFirewallSim development team All rights reserved. ! Redistribution and use in source and binary forms, with or without modification, are ! permitted provided that the following conditions are met: ! - Redistributions of source code must retain the above copyright notice, this list ! of conditions and the following disclaimer. ! - Redistributions in binary form must reproduce the above copyright notice, this list ! of conditions and the following disclaimer in the documentation and/or other + materials provided with the distribution. + - Neither the name of the Canberra Institute of Technology nor the names of its ! contributors may be used to endorse or promote products derived from this software ! without specific prior written permission. ! THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY ! EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES ! OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL ! THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, ! EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF ! SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ package core.protocolsuite.tcp_ip; import java.io.Serializable; import java.util.Hashtable; ! // import core.protocolsuite.tcp_ip.ICMP_packet; import core.CommunicationException; *************** *** 74,168 **** import core.Simulation; - - - - /** ! ! * @author angela_brown ! ! * @author bevan_calliess ! * @author luke_hamilton ! * @since Sep 17, 2004 ! * @version v0.00 ! */ ! ! public class ICMP implements Serializable{ ! ! private ProtocolStack mParentStack; ! ! private Hashtable<Integer, Long> receivedMessageID; // Message ID and received time of received packets. ! ! private int lastMessageID = 0; // last packet message id was sent ! ! /** ! * Assigns the ParentStack ! * @author bevan_calliess ! * @author luke_hamilton ! ! * @param inParentStack - Protocol Stack ! * @version v0.20 ! */ ! public ICMP(ProtocolStack inParentStack){ mParentStack = inParentStack; ! receivedMessageID = new Hashtable<Integer, Long>(); } - - /** ! * Receives the ICMP packet and checks the message ! ! * code attached to it. If 8, it is an echo request and ! * pass it of. If 0, print out a message to the layer info. ! * @author bevan_calliess ! * @author angela_brown ! * @author robert_hulford ! ! * @param inPacket - A PAcket ! * @version v0.20 ! */ public void receiveICMPPacket(ICMP_packet inPacket) throws LowLinkException { ! ! ! if(inPacket.getMessageCode() == 8 ){ echoRequest(inPacket); ! } ! if(inPacket.getMessageCode() == 0 ){ ! ! receivedMessageID.put(inPacket.getMessageID(), System.currentTimeMillis()); ! //Create Layer info LayerInfo pingInfo = new LayerInfo(getClass().getName()); --- 68,151 ---- import core.Simulation; /** ! * ! * @author angela_brown ! * ! * @author bevan_calliess ! * * @author luke_hamilton ! * * @since Sep 17, 2004 ! * * @version v0.00 ! * */ + public class ICMP implements Serializable { + private ProtocolStack mParentStack; + private Hashtable<Integer, Long> receivedMessageID; // Message ID and + // received time of + // received packets. ! private int lastMessageID = 0; // last packet message id was sent /** ! * * Assigns the ParentStack ! * * @author bevan_calliess ! * * @author luke_hamilton ! * ! * @param inParentStack - ! * Protocol Stack ! * * @version v0.20 ! * */ ! public ICMP(ProtocolStack inParentStack) { mParentStack = inParentStack; ! receivedMessageID = new Hashtable<Integer, Long>(); } /** ! * * Receives the ICMP packet and checks the message ! * ! * code attached to it. If 8, it is an echo request and ! * * pass it of. If 0, print out a message to the layer info. ! * * @author bevan_calliess ! * * @author angela_brown ! * * @author robert_hulford ! * ! * @param inPacket - ! * A PAcket ! * * @version v0.20 ! * */ public void receiveICMPPacket(ICMP_packet inPacket) throws LowLinkException { ! if (inPacket.getMessageCode() == 8) { echoRequest(inPacket); ! }else if (inPacket.getMessageCode() == 0) { ! receivedMessageID.put(inPacket.getMessageID(), System ! .currentTimeMillis()); ! // Create Layer info LayerInfo pingInfo = new LayerInfo(getClass().getName()); *************** *** 174,210 **** pingInfo.setLayer("Network"); ! pingInfo.setDescription("Echo reply packet received from "+ inPacket.getSourceIPAddress()); Simulation.addLayerInfo(pingInfo); } } - - /** ! * This method will send a reply to a ping request ! * @author angela_brown ! * @author bevan_calliess ! * @author robert_hulford ! * @author luke_hamilton ! ! * @param inPacket - The original packet recived by this Node ! ! * @exception CommunicationException ! * @version v0.20 ! */ ! ! private void echoRequest(ICMP_packet inPacket) throws LowLinkException{ ! String destIPAddress = inPacket.getSourceIPAddress(); ICMP_packet pingPacket = new ICMP_packet(destIPAddress); --- 157,203 ---- pingInfo.setLayer("Network"); ! pingInfo.setDescription("Echo reply packet received from " ! + inPacket.getSourceIPAddress()); Simulation.addLayerInfo(pingInfo); + }else if (inPacket.getMessageCode() == ICMP_packet.DESTINATION_UNREACHABLE){ + Simulation.addLayerInfo(getClass().getName(), + mParentStack.getParentNodeName(), "ICMP Dst Unreach", "Network", + "Recieved ICMP Destination Unreacheable from " + + inPacket.getSourceIPAddress()); + }else if (inPacket.getMessageCode() == ICMP_packet.TIME_EXCEEDED){ + Simulation.addLayerInfo(getClass().getName(), + mParentStack.getParentNodeName(), "ICMP Time Exceeded", "Network", + "Recieved ICMP Time Exceeded from " + + inPacket.getSourceIPAddress()); } } /** ! * * This method will send a reply to a ping request ! * * @author angela_brown ! * * @author bevan_calliess ! * * @author robert_hulford ! * * @author luke_hamilton ! * ! * @param inPacket - ! * The original packet recived by this Node ! * ! * @exception CommunicationException ! * * @version v0.20 + * + */ ! private void echoRequest(ICMP_packet inPacket) throws LowLinkException { ! String destIPAddress = inPacket.getSourceIPAddress(); ICMP_packet pingPacket = new ICMP_packet(destIPAddress); *************** *** 213,219 **** pingPacket.setMessageID(inPacket.getMessageID()); ! ! ! //Create Layer info LayerInfo pingInfo = new LayerInfo(getClass().getName()); --- 206,210 ---- pingPacket.setMessageID(inPacket.getMessageID()); ! // Create Layer info LayerInfo pingInfo = new LayerInfo(getClass().getName()); *************** *** 225,278 **** pingInfo.setLayer("Network"); ! pingInfo.setDescription("Created Echo Reply packet to "+destIPAddress); Simulation.addLayerInfo(pingInfo); ! ! ! try{ ! mParentStack.sendPacket(pingPacket); ! }catch(CommunicationException e){ ! //This exception is caught but not acted upon as the ! //Echo request on any PC would not notify the user if it failed ! //TODO Once the recording of a sim process is implemented this should record the error. } ! //catch(LowLinkException e){ ! //This exception is caught but not acted upon as the ! //Echo request on any PC would not notify the user if it failed ! //TODO Once the recording of a sim process is implemented this should record the error. ! //} } - - /** ! * This method will generate an ICMP echo request and send it ! * out via the Protocol stacks send method. ! * @author angela_brown ! * @author bevan_calliess ! * @author robert_hulford ! ! * @param inDestIPAddress - Destination IP Address ! * @return ICMP_packet - Ping Packet ! ! */ public ICMP_packet sendPing(String inDestIPAddress) { --- 216,269 ---- pingInfo.setLayer("Network"); ! pingInfo ! .setDescription("Created Echo Reply packet to " + destIPAddress); Simulation.addLayerInfo(pingInfo); ! try { ! mParentStack.sendPacket(pingPacket); ! } catch (CommunicationException e) { ! // This exception is caught but not acted upon as the ! // Echo request on any PC would not notify the user if it failed ! // TODO Once the recording of a sim process is implemented this ! // should record the error. } ! // catch(LowLinkException e){ ! // This exception is caught but not acted upon as the ! // Echo request on any PC would not notify the user if it failed ! // TODO Once the recording of a sim process is implemented this should ! // record the error. ! // } } /** ! * * This method will generate an ICMP echo request and send it ! * * out via the Protocol stacks send method. ! * * @author angela_brown ! * * @author bevan_calliess ! * * @author robert_hulford ! * ! * @param inDestIPAddress - ! * Destination IP Address ! * * @return ICMP_packet - Ping Packet ! * ! */ public ICMP_packet sendPing(String inDestIPAddress) { *************** *** 281,290 **** pingPacket.setMessageCode(ICMP_packet.ECHO_REQUEST); - - pingPacket.setMessageID(++lastMessageID); ! ! //Create Layer info LayerInfo pingInfo = new LayerInfo(getClass().getName()); --- 272,279 ---- pingPacket.setMessageCode(ICMP_packet.ECHO_REQUEST); ! pingPacket.setMessageID(++lastMessageID); ! // Create Layer info LayerInfo pingInfo = new LayerInfo(getClass().getName()); *************** *** 296,316 **** pingInfo.setLayer("Network"); ! pingInfo.setDescription("Created Echo Request packet to " +inDestIPAddress ); ! ! Simulation.addLayerInfo(pingInfo); ! return pingPacket; } ! ! public long getTimeICMPPacketReceived(int messageID){ ! if(receivedMessageID.containsKey(messageID)) return receivedMessageID.get(messageID); return 0; } ! ! ! }//EOF --- 285,303 ---- pingInfo.setLayer("Network"); ! pingInfo.setDescription("Created Echo Request packet to " ! + inDestIPAddress); ! Simulation.addLayerInfo(pingInfo); return pingPacket; } ! ! public long getTimeICMPPacketReceived(int messageID) { ! if (receivedMessageID.containsKey(messageID)) ! return receivedMessageID.get(messageID); return 0; } ! }// EOF |