[Javanetsim-cvs] javaNetSim/core/protocolsuite/tcp_ip ARP.java,1.1,1.2 ICMP.java,1.1,1.2 IP_packet.j
Status: Beta
Brought to you by:
darkkey
From: gift <gi...@us...> - 2005-11-17 20:14:07
|
Update of /cvsroot/javanetsim/javaNetSim/core/protocolsuite/tcp_ip In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv28923/core/protocolsuite/tcp_ip Modified Files: ARP.java ICMP.java IP_packet.java ProtocolStack.java UDP_packet.java Udp.java Log Message: UDP.java implementation v0.01 ;) arrival Index: Udp.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/core/protocolsuite/tcp_ip/Udp.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** Udp.java 8 Nov 2005 16:10:47 -0000 1.1 --- Udp.java 17 Nov 2005 20:13:56 -0000 1.2 *************** *** 1,53 **** ! /* ! 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; ! ! /** ! * This UDP class is constructed in a way that it represents its real world cousin (the UDP protocol) as accurately ! * as possible. ! ! * <P>This class contains methods which allow the transfer of packets to and from the lower layer. (Network Layer - IP ! * only at this stage). During a packets stay in this class, UDP headers are added, removed and examined ! * depending on wether the packet is in compilation or decompilation. During compilation, a packet is created, headers are added (all based ! * on real world UDP specification) and the packet is passed onto NetworkLayer (IP). During decompilation ! * UDP headers are removed and the data that was contained in the packet is passed onto the ProtocolStack. Relavent ! * information about what is happening in this class is added to the LayerInfo object so that it can be displayed ! * to the user in a clear and concise way.</P> ! * ! * @author james_nikolaidis ! * @since 10/06/2004 ! * @version v0.10 ! */ ! ! class Udp implements Serializable{ ! ! ! ! } --- 1,206 ---- ! /* ! ! 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 core.CommunicationException; ! ! import core.LowLinkException; ! ! import core.LayerInfo; ! ! import core.Simulation; ! ! import core.TransportLayerException; ! ! import core.protocolsuite.tcp_ip.ProtocolStack; ! ! ! ! ! /** ! ! * This UDP class is constructed in a way that it represents its real world cousin (the UDP protocol) as accurately ! ! * as possible. ! ! ! ! * <P>This class contains methods which allow the transfer of packets to and from the lower layer. (Network Layer - IP ! ! * only at this stage). During a packets stay in this class, UDP headers are added, removed and examined ! ! * depending on wether the packet is in compilation or decompilation. During compilation, a packet is created, headers are added (all based ! ! * on real world UDP specification) and the packet is passed onto NetworkLayer (IP). During decompilation ! ! * UDP headers are removed and the data that was contained in the packet is passed onto the ProtocolStack. Relavent ! ! * information about what is happening in this class is added to the LayerInfo object so that it can be displayed ! ! * to the user in a clear and concise way.</P> ! ! * ! ! * @author james_nikolaidis ! ! * @since 10/06/2004 ! ! * @author gift (sourceforge.net user) ! ! * @since 17 Nov 2005 ! ! * @version v0.10 ! ! */ ! ! ! ! class Udp implements Serializable ! { ! ! private ProtocolStack mParentStack; ! ! ! /** ! * This method assigns the ParentStack ! * @author gift (sourceforge.net user) ! * @param Protocol Stack ! * @return Nothing. ! * @version v0.20 ! */ ! public Udp(ProtocolStack inParentStack) ! { ! mParentStack = inParentStack; ! } ! ! ! /** ! * This method receives the UDP packet, checks CHECK_SUM ! * and prints out a message to the layer info. ! * @author gift (sourceforge.net user) ! * @param Protocol Stack ! * @return Nothing. ! * @exception TransportLayerException If UDP CHECK_SUM != 1 ! * @version v0.20 ! * @see TransportLayerException ! */ ! ! public void receiveUDPPacket(UDP_packet inPacket) throws TransportLayerException ! { ! ! // test if this packet is for a local Address. ! ! if(mParentStack.isInternalIP(inPacket.getDestIPAddress())){ ! ! // 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 Packet"); ! ! UDP_Info.setLayer("Transport"); ! ! UDP_Info.setDescription("UDP packet received from "+ inPacket.getSourceIPAddress() + " message length " +inPacket.getUDP_MessageLength() + " bytes."); ! ! Simulation.addLayerInfo(UDP_Info); ! } else { ! throw new TransportLayerException("UDP Error: Incorrect checksum on receiving."); ! } ! } ! } ! ! /** ! * This method sends the UDP packet ! * and prints out a message to the layer info. ! * @author gift (sourceforge.net user) ! * @param inDestIPAddress ! * @param InterfaceName name of the intarface that sends UDP e.g. "eth0" ! * @return UDP_packet ! * @version v0.20 ! */ ! ! public UDP_packet sendUDPPacket(String inDestIPAddress, String InterfaceName) ! { ! UDP_packet tosend = new UDP_packet(inDestIPAddress, mParentStack.getIPAddress(InterfaceName)); ! ! //Create Layer info ! ! LayerInfo UDP_Info = new LayerInfo(getClass().getName()); ! ! UDP_Info.setObjectName(mParentStack.getParentNodeName()); ! ! UDP_Info.setDataType("UDP Packet"); ! ! UDP_Info.setLayer("Transport"); ! ! UDP_Info.setDescription("Created UDP packet to " + inDestIPAddress); ! ! Simulation.addLayerInfo(UDP_Info); ! ! return tosend; ! } ! ! ! } //EOF \ No newline at end of file Index: ProtocolStack.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/core/protocolsuite/tcp_ip/ProtocolStack.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** ProtocolStack.java 8 Nov 2005 20:58:14 -0000 1.2 --- ProtocolStack.java 17 Nov 2005 20:13:56 -0000 1.3 *************** *** 1,597 **** ! /* ! 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. [...1762 lines suppressed...] ! } ! ! ! ! public String[] getRouteTableEntries(){ ! ! return mIPprotocol.getRouteTableEntries(); ! ! } ! ! ! ! public Route_entry getRouteTableEntry(String destIP){ ! ! return mIPprotocol.getRouteTableEntry(destIP); ! ! } ! ! }//EOF ! Index: IP_packet.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/core/protocolsuite/tcp_ip/IP_packet.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** IP_packet.java 8 Nov 2005 16:10:47 -0000 1.1 --- IP_packet.java 17 Nov 2005 20:13:56 -0000 1.2 *************** *** 1,126 **** ! /* ! 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 core.Packet; ! ! /** ! * IP_Packet extends the packet class. It set the IP_Packet Source address ! * and the destination IP address ! * @author luke_hamilton ! * @since Sep 17, 2004 ! * @version v0.20 ! */ ! ! public class IP_packet extends Packet{ ! ! String mSourceIPAddress; ! String mDestIPAddress; ! ! /** ! * Sets a IP packet ! * @author angela_brown ! * @author bevan_calliess ! * @param inDestIPAddress - Destination IP address ! * @version v0.20 ! */ ! public IP_packet(String inDestIPAddress) ! { ! mDestIPAddress = inDestIPAddress; ! } ! /** ! * Sets the destination IP address ! * @author angela_brown ! * @author bevan_calliess ! * @param inDestIPAddress - Destination IP address eg: 192.168.10.1 ! * @version v0.20 ! */ ! public void setDestIPAddress(String inDestIPAddress) ! { ! mDestIPAddress = inDestIPAddress; ! } ! /** ! * Sets the source IP address ! * @author angela_brown ! * @author bevan_calliess ! * @param inSourceIPAddress - Source IP address ! * @version v0.20 ! */ ! public void setSourceIPAddress(String inSourceIPAddress) ! { ! mSourceIPAddress = inSourceIPAddress; ! } ! ! /** ! * Sets the Data within the Packet ! * @author bevan_calliess ! * @author angela_brown ! * @param inData ! * @version v0.20 ! */ ! public void setData(Packet inData) ! { ! Data = inData; ! } ! /** ! * Gets the source IP Address ! * @author angela_brown ! * @author bevan_calliess ! * @return mSourceIPAddress - Source IP address ! * @version v0.20 ! */ ! public String getSourceIPAddress() ! { ! return mSourceIPAddress; ! } ! /** ! * Gets the destination IP address ! * @author bevan_calliess ! * @author angela_brown ! * @return mDestIPAddress - Destination IP Address ! * @version v0.20 ! */ ! public String getDestIPAddress() ! { ! return mDestIPAddress; ! } ! ! /** ! * Gets the Data packet ! * @author bevan_calliess ! * @author angela_brown ! * @return Data - The data packet ! * @version v0.20 ! **/ ! public Packet getData() ! { ! return Data; ! } ! }//EOF --- 1,252 ---- ! /* ! ! 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 core.Packet; ! ! ! ! /** ! ! * IP_Packet extends the packet class. It set the IP_Packet Source address ! ! * and the destination IP address ! ! * @author luke_hamilton ! ! * @since Sep 17, 2004 ! ! * @version v0.20 ! ! */ ! ! ! ! public class IP_packet extends Packet{ ! ! ! ! String mSourceIPAddress; ! ! String mDestIPAddress; ! ! ! ! /** ! ! * Sets a IP packet ! ! * @author angela_brown ! ! * @author bevan_calliess ! ! * @param inDestIPAddress - Destination IP address ! ! * @version v0.20 ! ! */ ! ! public IP_packet(String inDestIPAddress) ! ! { ! ! mDestIPAddress = inDestIPAddress; ! ! } ! ! /** ! ! * Sets the destination IP address ! ! * @author angela_brown ! ! * @author bevan_calliess ! ! * @param inDestIPAddress - Destination IP address eg: 192.168.10.1 ! ! * @version v0.20 ! ! */ ! ! public void setDestIPAddress(String inDestIPAddress) ! ! { ! ! mDestIPAddress = inDestIPAddress; ! ! } ! ! /** ! ! * Sets the source IP address ! ! * @author angela_brown ! ! * @author bevan_calliess ! ! * @param inSourceIPAddress - Source IP address ! ! * @version v0.20 ! ! */ ! ! public void setSourceIPAddress(String inSourceIPAddress) ! ! { ! ! mSourceIPAddress = inSourceIPAddress; ! ! } ! ! ! ! /** ! ! * Sets the Data within the Packet ! ! * @author bevan_calliess ! ! * @author angela_brown ! ! * @param inData ! ! * @version v0.20 ! ! */ ! ! public void setData(Packet inData) ! ! { ! ! Data = inData; ! ! } ! ! /** ! ! * Gets the source IP Address ! ! * @author angela_brown ! ! * @author bevan_calliess ! ! * @return mSourceIPAddress - Source IP address ! ! * @version v0.20 ! ! */ ! ! public String getSourceIPAddress() ! ! { ! ! return mSourceIPAddress; ! ! } ! ! /** ! ! * Gets the destination IP address ! ! * @author bevan_calliess ! ! * @author angela_brown ! ! * @return mDestIPAddress - Destination IP Address ! ! * @version v0.20 ! ! */ ! ! public String getDestIPAddress() ! ! { ! ! return mDestIPAddress; ! ! } ! ! ! ! /** ! ! * Gets the Data packet ! ! * @author bevan_calliess ! ! * @author angela_brown ! ! * @return Data - The data packet ! ! * @version v0.20 ! ! **/ ! ! public Packet getData() ! ! { ! ! return Data; ! ! } ! ! }//EOF ! Index: ARP.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/core/protocolsuite/tcp_ip/ARP.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** ARP.java 8 Nov 2005 16:10:47 -0000 1.1 --- ARP.java 17 Nov 2005 20:13:56 -0000 1.2 *************** *** 1,295 **** ! /* ! Java Network Simulator (jNetSim) ! ! Copyright (c) 2005, Ice Team; All rights reserved. ! 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 Ice Team 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.*; ! import core.CommunicationException; ! import core.LowLinkException; ! import core.Simulation; ! import core.LayerInfo; ! ! /** ! * Currently the ARP protocol is implemented using a ststic method. This ! * means that each time the IP address is set for a node in the simulation the ! * IP address and MAC address are sent to all computers and the ARP table ! * is then updated for any entries that are local. This leaves a BIG WHOLE in the ! * protocol because any new nodes added to the simulation do not have the ARP table ! * for any of the older computers in the Simulation. This issue will need to be ! * covered in later versions of the Protocol. ! * @author bevan_calliess ! * @author robert_hulford ! * @author luke_hamilton ! * @since Sep 17, 2004 ! * @version v0.20 ! */ ! public class ARP implements Serializable{ ! private ProtocolStack mParentStack; ! private Vector ARPTable = new Vector(); ! private String mLastIpRequest = "0.0.0.0"; ! ! public ARP(ProtocolStack inParentStack){ ! mParentStack = inParentStack; ! } ! ! /** ! * This method will add a new entry to the ARP table ! * @author robert_hulford ! * @author bevan_calliess ! * @author Key ! * @param IPAddress - The IP address of the new entry ! * @param MacAddress - The Mac address of the new entry ! * @param inEntryType - The type of the new entry : Static or Dynamic ! * @version v0.22 ! */ ! public void addToArpTable(String inIPAddress, String inMacAddress, String inEntryType) { ! //look for an entry with this MAC address in the table ! Iterator it = ARPTable.iterator(); ! while(it.hasNext()) ! { ! ARPTableEntry currEnt = (ARPTableEntry)it.next(); ! if (currEnt.getMACAddress().equals(inMacAddress)) ! { ! it.remove(); ! } ! } ! ARPTableEntry newEntry = new ARPTableEntry(inIPAddress,inMacAddress,inEntryType); ! ARPTable.add(newEntry); ! } ! ! /** ! * This method will remove all entries from the ARP table that match ! * nay IP Address in the String Array. ! * @author bevan_calliess ! * @author robert_calliess ! * @param IPAddress - An array of IP addreses that need to be removed ! * @version v0.20 ! */ ! public void removeFromArpTable(String[] IPAddress){ ! ARPTableEntry currentEntry; ! ! Iterator it = ARPTable.iterator(); ! while(it.hasNext()) ! { ! currentEntry = (ARPTableEntry)it.next(); ! for(int y=0; y < IPAddress.length; y++) ! { ! if(IPAddress[y].equals(currentEntry.getIPAddress())) ! { ! it.remove(); ! } ! } ! } ! } ! ! /** ! * This method will generate a String array containing all ! * the entries from the ARP table ! * @author robert_hulford ! * @author bevan_calliess ! * @return String Array - An array of strings that can be used to display the ARP table. ! * @version v0.20 ! */ ! public String[] getARPTable() ! { ! // first clean out the ARP table so that there are no old entries ! cleanARPTable(); ! ! String output[] = new String[ARPTable.size()+1]; ! int counter = 0; ! String ipAddress; ! char padding = ' '; ! ! if(ARPTable.size()>0){ ! output[0] = "Internet Address Physical Address Type"; ! ! Iterator it = ARPTable.iterator(); ! while(it.hasNext()) ! { ! counter++; ! ARPTableEntry currEnt = (ARPTableEntry)it.next(); ! ipAddress = pad(currEnt.getIPAddress(),20,padding); ! output[counter] = ipAddress + currEnt.getMACAddress() + " " + currEnt.getEntryType(); ! } ! }else{ ! output[0] = "No ARP Entries Found"; ! } ! ! return output; ! } ! ! /** ! * This method will generate a String containing the Mac address ! * of the IP address passed in or null if it is not in the ARP table ! * the entries from the ARP table are cleaned out after two minutes ! * as they are in the real protocol. ! * @author bevan_calliess ! * @author robert_hulford ! * @param String - The IP address to search for in the ARP table ! * @return String - Either the MAC of the ip passed in or null. ! * @version v0.20 ! */ ! public String getMACAddress(String IPAddress, String inInterfaceKey) throws LowLinkException ! { ! String output= null; ! //this cleans out any entries older than 2 minutes ! cleanARPTable(); ! ! Iterator it = ARPTable.iterator(); ! while(it.hasNext()){ ! ARPTableEntry currEnt = (ARPTableEntry)it.next(); ! if (currEnt.getIPAddress().equals(IPAddress)){ ! output = currEnt.getMACAddress(); ! } ! } ! if(output == null){ ! //then send ARP Packet to try and find out about IP Address ! mLastIpRequest = IPAddress; ! String srcMAC = mParentStack.getMACAddress(inInterfaceKey); ! ARP_packet ArpDisc = new ARP_packet(IPAddress); ! ArpDisc.setMessageCode(ARP_packet.ARP_REQUEST); ! ArpDisc.setSourceMAC(srcMAC); ! //Create layer info object ! LayerInfo arpInfo = new LayerInfo(getClass().getName()); ! arpInfo.setObjectName(mParentStack.getParentNodeName()); ! arpInfo.setDataType("ARP Discovery Packet"); ! arpInfo.setLayer("DataLink"); ! arpInfo.setDescription("Created ARP discovery packet to source MAC address for IP "+IPAddress); ! Simulation.addLayerInfo(arpInfo); ! try{ ! mParentStack.broadcastPacket(ArpDisc,inInterfaceKey); ! }catch(CommunicationException e){ ! // no need to throw this. method will return null ! } ! Iterator it1 = ARPTable.iterator(); ! while(it1.hasNext()) ! { ! ARPTableEntry currEnt = (ARPTableEntry)it1.next(); ! if (currEnt.getIPAddress().equals(IPAddress)) ! { ! output = currEnt.getMACAddress(); ! } ! } ! } ! return output; ! } ! ! /** ! * This method will recieve a packet and determind the type ! * Then deal with the packet depending on the required response. ! * @author bevan_calliess ! * @author robert_hulford ! * @param temp - The packet to be processed ! * @version v0.20 ! */ ! ! public void receiveARPPacket(ARP_packet inARPpacket) throws LowLinkException{ ! // test if this packet is for a local Address. ! if(mParentStack.isInternalIP(inARPpacket.getDestIPAddress())){ ! // test the type of ARP packet ! if(inARPpacket.getMessageCode()==1){ ! //If its an ARP Request add the entry to the arp table ! // and send response ! try{ ! addToArpTable(inARPpacket.getSourceIPAddress(),inARPpacket.getSourceMAC(),"Dynamic"); ! ARP_packet ArpResponse = new ARP_packet(inARPpacket.getSourceIPAddress()); ! ArpResponse.setMessageCode(ARP_packet.ARP_REPLY); ! String outInterface = mParentStack.getRouteInfo(inARPpacket.getSourceIPAddress()); ! String srcMAC = mParentStack.getMACAddress(outInterface); ! ArpResponse.setSourceMAC(srcMAC); ! //Create Layer info ! LayerInfo arpInfo = new LayerInfo(getClass().getName()); ! arpInfo.setObjectName(mParentStack.getParentNodeName()); ! arpInfo.setDataType("ARP Response Packet"); ! arpInfo.setLayer("DataLink"); ! arpInfo.setDescription("Created ARP Response packet to "+inARPpacket.getSourceIPAddress() ); ! Simulation.addLayerInfo(arpInfo); ! //Send packet ! mParentStack.sendPacket(ArpResponse); ! }catch(CommunicationException e){ ! // no need to throw this. method will return null ! }catch(LowLinkException e){ ! // no need to throw this. method will return null ! throw e; ! } ! }else{ ! //if its an ARP response Add the entry to the ARP table. ! addToArpTable(inARPpacket.getSourceIPAddress(),inARPpacket.getSourceMAC(),"Dynamic"); ! } ! } ! } ! ! /** ! * This method is used to create a fixed length string ! * If the string is already greater than the length no action is taken ! * and the original string is returned. ! * @author bevan_calliess ! * @author robert_hulford ! * @param inString - The string that you want padded to the fixed length. ! * @param length - The length you would like to string to be. ! * @param pad - The character you would like to use to pad the String. ! * @return String - Returns a gap lenght ! * @version v0.20 ! */ ! private String pad(String inString, int length, char pad) { ! StringBuffer buffer = new StringBuffer(inString); ! while (buffer.length() < length) { ! buffer.append(pad); ! } ! return buffer.toString(); ! } ! /** ! * This method will iterate through the ARP table and clean out ! * any ARP entries that have been here for more than 2 minutes. ! * Note: This is a simplified version of the Real ARP ! * The Real ARP process that will only keep an entry for 2 minutes ! * unless it is used again. It will retain the entries that are ! * reused up to a maximum of 20 Minutes. ! */ ! private void cleanARPTable(){ ! GregorianCalendar tempTime = new GregorianCalendar(); ! tempTime.add(Calendar.MINUTE,-2); ! Iterator it = ARPTable.iterator(); ! ! while(it.hasNext()){ ! ARPTableEntry tempEntry = (ARPTableEntry)it.next(); ! GregorianCalendar entryTime = tempEntry.getEntryTime(); ! if(entryTime.getTimeInMillis()<tempTime.getTimeInMillis()){ ! if(tempEntry.getIPAddress().equals(mLastIpRequest)){ ! mLastIpRequest = "0.0.0.0"; ! } ! if(tempEntry.getEntryType().contains("Dynamic")) it.remove(); ! } ! } ! } ! ! ! }//EOF --- 1,590 ---- ! /* ! ! Java Network Simulator (jNetSim) ! ! ! ! Copyright (c) 2005, Ice Team; All rights reserved. ! ! 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 Ice Team 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.*; ! ! import core.CommunicationException; ! ! import core.LowLinkException; ! ! import core.Simulation; ! ! import core.LayerInfo; ! ! ! ! /** ! ! * Currently the ARP protocol is implemented using a ststic method. This ! ! * means that each time the IP address is set for a node in the simulation the ! ! * IP address and MAC address are sent to all computers and the ARP table ! ! * is then updated for any entries that are local. This leaves a BIG WHOLE in the ! ! * protocol because any new nodes added to the simulation do not have the ARP table ! ! * for any of the older computers in the Simulation. This issue will need to be ! ! * covered in later versions of the Protocol. ! ! * @author bevan_calliess ! ! * @author robert_hulford ! ! * @author luke_hamilton ! ! * @since Sep 17, 2004 ! ! * @version v0.20 ! ! */ ! ! public class ARP implements Serializable{ ! ! private ProtocolStack mParentStack; ! ! private Vector ARPTable = new Vector(); ! ! private String mLastIpRequest = "0.0.0.0"; ! ! ! ! public ARP(ProtocolStack inParentStack){ ! ! mParentStack = inParentStack; ! ! } ! ! ! ! /** ! ! * This method will add a new entry to the ARP table ! ! * @author robert_hulford ! ! * @author bevan_calliess ! ! * @author Key ! ! * @param IPAddress - The IP address of the new entry ! ! * @param MacAddress - The Mac address of the new entry ! ! * @param inEntryType - The type of the new entry : Static or Dynamic ! ! * @version v0.22 ! ! */ ! ! public void addToArpTable(String inIPAddress, String inMacAddress, String inEntryType) { ! ! //look for an entry with this MAC address in the table ! ! Iterator it = ARPTable.iterator(); ! ! while(it.hasNext()) ! ! { ! ! ARPTableEntry currEnt = (ARPTableEntry)it.next(); ! ! if (currEnt.getMACAddress().equals(inMacAddress)) ! ! { ! ! it.remove(); ! ! } ! ! } ! ! ARPTableEntry newEntry = new ARPTableEntry(inIPAddress,inMacAddress,inEntryType); ! ! ARPTable.add(newEntry); ! ! } ! ! ! ! /** ! ! * This method will remove all entries from the ARP table that match ! ! * nay IP Address in the String Array. ! ! * @author bevan_calliess ! ! * @author robert_calliess ! ! * @param IPAddress - An array of IP addreses that need to be removed ! ! * @version v0.20 ! ! */ ! ! public void removeFromArpTable(String[] IPAddress){ ! ! ARPTableEntry currentEntry; ! ! ! ! Iterator it = ARPTable.iterator(); ! ! while(it.hasNext()) ! ! { ! ! currentEntry = (ARPTableEntry)it.next(); ! ! for(int y=0; y < IPAddress.length; y++) ! ! { ! ! if(IPAddress[y].equals(currentEntry.getIPAddress())) ! ! { ! ! it.remove(); ! ! } ! ! } ! ! } ! ! } ! ! ! ! /** ! ! * This method will generate a String array containing all ! ! * the entries from the ARP table ! ! * @author robert_hulford ! ! * @author bevan_calliess ! ! * @return String Array - An array of strings that can be used to display the ARP table. ! ! * @version v0.20 ! ! */ ! ! public String[] getARPTable() ! ! { ! ! // first clean out the ARP table so that there are no old entries ! ! cleanARPTable(); ! ! ! ! String output[] = new String[ARPTable.size()+1]; ! ! int counter = 0; ! ! String ipAddress; ! ! char padding = ' '; ! ! ! ! if(ARPTable.size()>0){ ! ! output[0] = "Internet Address Physical Address Type"; ! ! ! ! Iterator it = ARPTable.iterator(); ! ! while(it.hasNext()) ! ! { ! ! counter++; ! ! ARPTableEntry currEnt = (ARPTableEntry)it.next(); ! ! ipAddress = pad(currEnt.getIPAddress(),20,padding); ! ! output[counter] = ipAddress + currEnt.getMACAddress() + " " + currEnt.getEntryType(); ! ! } ! ! }else{ ! ! output[0] = "No ARP Entries Found"; ! ! } ! ! ! ! return output; ! ! } ! ! ! ! /** ! ! * This method will generate a String containing the Mac address ! ! * of the IP address passed in or null if it is not in the ARP table ! ! * the entries from the ARP table are cleaned out after two minutes ! ! * as they are in the real protocol. ! ! * @author bevan_calliess ! ! * @author robert_hulford ! ! * @param String - The IP address to search for in the ARP table ! ! * @return String - Either the MAC of the ip passed in or null. ! ! * @version v0.20 ! ! */ ! ! public String getMACAddress(String IPAddress, String inInterfaceKey) throws LowLinkException ! ! { ! ! String output= null; ! ! //this cleans out any entries older than 2 minutes ! ! cleanARPTable(); ! ! ! ! Iterator it = ARPTable.iterator(); ! ! while(it.hasNext()){ ! ! ARPTableEntry currEnt = (ARPTableEntry)it.next(); ! ! if (currEnt.getIPAddress().equals(IPAddress)){ ! ! output = currEnt.getMACAddress(); ! ! } ! ! } ! ! if(output == null){ ! ! //then send ARP Packet to try and find out about IP Address ! ! mLastIpRequest = IPAddress; ! ! String srcMAC = mParentStack.getMACAddress(inInterfaceKey); ! ! ARP_packet ArpDisc = new ARP_packet(IPAddress); ! ! ArpDisc.setMessageCode(ARP_packet.ARP_REQUEST); ! ! ArpDisc.setSourceMAC(srcMAC); ! ! //Create layer info object ! ! LayerInfo arpInfo = new LayerInfo(getClass().getName()); ! ! arpInfo.setObjectName(mParentStack.getParentNodeName()); ! ! arpInfo.setDataType("ARP Discovery Packet"); ! ! arpInfo.setLayer("DataLink"); ! ! arpInfo.setDescription("Created ARP discovery packet to source MAC address for IP "+IPAddress); ! ! Simulation.addLayerInfo(arpInfo); ! ! try{ ! ! mParentStack.broadcastPacket(ArpDisc,inInterfaceKey); ! ! }catch(CommunicationException e){ ! ! // no need to throw this. method will return null ! ! } ! ! Iterator it1 = ARPTable.iterator(); ! ! while(it1.hasNext()) ! ! { ! ! ARPTableEntry currEnt = (ARPTableEntry)it1.next(); ! ! if (currEnt.getIPAddress().equals(IPAddress)) ! ! { ! ! output = currEnt.getMACAddress(); ! ! } ! ! } ! ! } ! ! return output; ! ! } ! ! ! ! /** ! ! * This method will recieve a packet and determind the type ! ! * Then deal with the packet depending on the required response. ! ! * @author bevan_calliess ! ! * @author robert_hulford ! ! * @param temp - The packet to be processed ! ! * @version v0.20 ! ! */ ! ! ! ! public void receiveARPPacket(ARP_packet inARPpacket) throws LowLinkException{ ! ! // test if this packet is for a local Address. ! ! if(mParentStack.isInternalIP(inARPpacket.getDestIPAddress())){ ! ! // test the type of ARP packet ! ! if(inARPpacket.getMessageCode()==1){ ! ! //If its an ARP Request add the entry to the arp table ! ! // and send response ! ! try{ ! ! addToArpTable(inARPpacket.getSourceIPAddress(),inARPpacket.getSourceMAC(),"Dynamic"); ! ! ARP_packet ArpResponse = new ARP_packet(inARPpacket.getSourceIPAddress()); ! ! ArpResponse.setMessageCode(ARP_packet.ARP_REPLY); ! ! String outInterface = mParentStack.getRouteInfo(inARPpacket.getSourceIPAddress()); ! ! String srcMAC = mParentStack.getMACAddress(outInterface); ! ! ArpResponse.setSourceMAC(srcMAC); ! ! //Create Layer info ! ! LayerInfo arpInfo = new LayerInfo(getClass().getName()); ! ! arpInfo.setObjectName(mParentStack.getParentNodeName()); ! ! arpInfo.setDataType("ARP Response Packet"); ! ! arpInfo.setLayer("DataLink"); ! ! arpInfo.setDescription("Created ARP Response packet to "+inARPpacket.getSourceIPAddress() ); ! ! Simulation.addLayerInfo(arpInfo); ! ! //Send packet ! ! mParentStack.sendPacket(ArpResponse); ! ! }catch(CommunicationException e){ ! ! // no need to throw this. method will return null ! ! }catch(LowLinkException e){ ! ! // no need to throw this. method will return null ! ! throw e; ! ! } ! ! }else{ ! ! //if its an ARP response Add the entry to the ARP table. ! ! addToArpTable(inARPpacket.getSourceIPAddress(),inARPpacket.getSourceMAC(),"Dynamic"); ! ! } ! ! } ! ! } ! ! ! ! /** ! ! * This method is used to create a fixed length string ! ! * If the string is already greater than the length no action is taken ! ! * and the original string is returned. ! ! * @author bevan_calliess ! ! * @author robert_hulford ! ! * @param inString - The string that you want padded to the fixed length. ! ! * @param length - The length you would like to string to be. ! ! * @param pad - The character you would like to use to pad the String. ! ! * @return String - Returns a gap lenght ! ! * @version v0.20 ! ! */ ! ! private String pad(String inString, int length, char pad) { ! ! StringBuffer buffer = new StringBuffer(inString); ! ! while (buffer.length() < length) { ! ! buffer.append(pad); ! ! } ! ! return buffer.toString(); ! ! } ! ! /** ! ! * This method will iterate through the ARP table and clean out ! ! * any ARP entries that have been here for more than 2 minutes. ! ! * Note: This is a simplified version of the Real ARP ! ! * The Real ARP process that will only keep an entry for 2 minutes ! ! * unless it is used again. It will retain the entries that are ! ! * reused up to a maximum of 20 Minutes. ! ! */ ! ! private void cleanARPTable(){ ! ! GregorianCalendar tempTime = new GregorianCalendar(); ! ! tempTime.add(Calendar.MINUTE,-2); ! ! Iterator it = ARPTable.iterator(); ! ! ! ! while(it.hasNext()){ ! ! ARPTableEntry tempEntry = (ARPTableEntry)it.next(); ! ! GregorianCalendar entryTime = tempEntry.getEntryTime(); ! ! if(entryTime.getTimeInMillis()<tempTime.getTimeInMillis()){ ! ! if(tempEntry.getIPAddress().equals(mLastIpRequest)){ ! ! mLastIpRequest = "0.0.0.0"; ! ! } ! ! if(tempEntry.getEntryType().contains("Dynamic")) it.remove(); ! ! } ! ! } ! ! } ! ! ! ! ! ! }//EOF ! Index: ICMP.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/core/protocolsuite/tcp_ip/ICMP.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** ICMP.java 8 Nov 2005 16:10:47 -0000 1.1 --- ICMP.java 17 Nov 2005 20:13:56 -0000 1.2 *************** *** 1,149 **** ! /* ! 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 core.protocolsuite.tcp_ip.ICMP_packet; ! import core.CommunicationException; ! import core.LowLinkException; ! import core.LayerInfo; ! 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; ! ! /** ! * Assigns the ParentStack ! * @author bevan_calliess ! * @author luke_hamilton ! * @param inParentStack - Protocol Stack ! * @version v0.20 ! */ ! public ICMP(ProtocolStack inParentStack){ ! mParentStack = inParentStack; ! } ! ! /** ! * 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 ){ ! //Create Layer info ! LayerInfo pingInfo = new LayerInfo(getClass().getName()); ! pingInfo.setObjectName(mParentStack.getParentNodeName()); ! pingInfo.setDataType("Echo Reply Packet"); ! 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); ! pingPacket.setMessageCode(ICMP_packet.ECHO_REPLY); ! ! //Create Layer info ! LayerInfo pingInfo = new LayerInfo(getClass().getName()); ! pingInfo.setObjectName(mParentStack.getParentNodeName()); ! pingInfo.setDataType("Echo Reply Packet"); ! 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) { ! ICMP_packet pingPacket = new ICMP_packet(inDestIPAddress); ! pingPacket.setMessageCode(ICMP_packet.ECHO_REQUEST); ! ! //Create Layer info ! LayerInfo pingInfo = new LayerInfo(getClass().getName()); ! pingInfo.setObjectName(mParentStack.getParentNodeName()); ! pingInfo.setDataType("Echo Request Packet"); ! pingInfo.setLayer("Network"); ! pingInfo.setDescription("Created Echo Request packet to " +inDestIPAddress ); ! Simulation.addLayerInfo(pingInfo); ! ! return pingPacket; ! } ! ! }//EOF --- 1,298 ---- ! /* ! ! 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 core.protocolsuite.tcp_ip.ICMP_packet; ! ! import core.CommunicationException; ! ! import core.LowLinkException; ! ! import core.LayerInfo; ! ! 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; ! ! ! ! /** ! ! * Assigns the ParentStack ! ! * @author bevan_calliess ! ! * @author luke_hamilton ! ! * @param inParentStack - Protocol Stack ! ! * @version v0.20 ! ! */ ! ! public ICMP(ProtocolStack inParentStack){ ! ! mParentStack = inParentStack; ! ! } ! ! ! ! /** ! ! * 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 ){ ! ! //Create Layer info ! ! LayerInfo pingInfo = new LayerInfo(getClass().getName()); ! ! pingInfo.setObjectName(mParentStack.getParentNodeName()); ! ! pingInfo.setDataType("Echo Reply Packet"); ! ! 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); ! ! pingPacket.setMessageCode(ICMP_packet.ECHO_REPLY); ! ! ! ! //Create Layer info ! ! LayerInfo pingInfo = new LayerInfo(getClass().getName()); ! ! pingInfo.setObjectName(mParentStack.getParentNodeName()); ! ! pingInfo.setDataType("Echo Reply Packet"); ! ! 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) { ! ! ICMP_packet pingPacket = new ICMP_packet(inDestIPAddress); ! ! pingPacket.setMessageCode(ICMP_packet.ECHO_REQUEST); ! ! ! ! //Create Layer info ! ! LayerInfo pingInfo = new LayerInfo(getClass().getName()); ! ! pingInfo.setObjectName(mParentStack.getParentNodeName()); ! ! pingInfo.setDataType("Echo Request Packet"); ! ! pingInfo.setLayer("Network"); ! ! pingInfo.setDescription("Created Echo Request packet to " +inDestIPAddress ); ! ! Simulation.addLayerInfo(pingInfo); ! ! ! ! return pingPacket; ! ! } ! ! ! ! }//EOF ! Index: UDP_packet.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/core/protocolsuite/tcp_ip/UDP_packet.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** UDP_packet.java 16 Nov 2005 20:25:40 -0000 1.2 --- UDP_packet.java 17 Nov 2005 20:13:56 -0000 1.3 *************** *** 68,72 **** * Design and implementation of UDP_packet ! * @author gift * @since Nov 16, 2005 * @version v0.20 --- 68,72 ---- * Design and implementation of UDP_packet ! * @author gift (sourceforge.net user) * @since Nov 16, 2005 * @version v0.20 *************** *** 76,86 **** { ! private int UDP_MessageLength; ! private int mMessageCode; private String UDP_message; ! private static final int CHECK_SUM = 1; //for future developing :) private static final int HEAD_LENGTH = 8; //UDP header is 8 bytes --- 76,93 ---- { ! /* DO NOT forget about pseudo UDP header fields ! * - mSourceIPAddress (implemented) ! * - mDestIPAddress (implemented) ! * - PTCL (protocol type code) (implemented) ! * - UDP length - not needed (not implemented) ! * that's why UDP_packet extends IP_packet */ ! private int UDP_MessageLength; private String UDP_message; ! private static final int PTCL = 17; //see RFC :) ! ! private static final int CHECK_SUM = 1; //for future developing :) private static final int HEAD_LENGTH = 8; //UDP header is 8 bytes *************** *** 91,104 **** /** ! * This method passes the destination address into the super class ! * @author gift ! * @param destination IP address * @return Nothing. * @version v0.20 */ ! public UDP_packet(String inDestIPAddress) { ! super (inDestIPAddress); UDP_MessageLength = HEAD_LENGTH; UDP_message = ""; --- 98,112 ---- /** ! * This method passes the destination and source addresses into the super class ! * @author gift (sourceforge.net user) ! * @param destination IP address, source IP address * @return Nothing. * @version v0.20 */ ! public UDP_packet(String inDestIPAddress, String inSourceIPAddress) { ! super (inDestIPAddress); ! this.setSourceIPAddress(inSourceIPAddress); UDP_MessageLength = HEAD_LENGTH; UDP_message = ""; *************** *** 107,112 **** /** * This method sets the UDP_message and calculates UDP_message length ! * @author gift ! * @param a string to be set as a UDP message * @return Nothing. * @exception TransportLayerException If UDP message exceeds maximum size of UDP message. --- 115,120 ---- /** * This method sets the UDP_message and calculates UDP_message length ! * @author gift (sourceforge.net user) ! * @param inUDP_message a string to be set as a UDP message * @return Nothing. * @exception TransportLayerException If UDP message exceeds maximum size of UDP message. *************** *** 134,138 **** /** * This method returns the string describing UDP message ! * @author gift * @param Unused. * @return the UDP message --- 142,146 ---- /** * This method returns the string describing UDP message ! * @author gift (sourceforge.net user) * @param Unused. * @return the UDP message *************** *** 147,151 **** /** * This method returns integer describing UDP message length ! * @author gift * @param Unused. * @return the length of UDP message. --- 155,159 ---- /** * This method returns integer describing UDP message length ! * @author gift (sourceforge.net user) * @param Unused. * @return the length of UDP message. *************** *** 158,185 **** } /** ! * This method sets mMessageCode ! * @author gift ! * @param the value to be set as mMessageCode * @return Nothing. * @version v0.20 */ ! public void setMessageCode(int inCode) { ! mMessageCode = inCode; } /** ! * This method gets mMessageCode ! * @author gift * @param Unused. ! * @return message code. * @version v0.20 */ ! public int getMessageCode() { ! return mMessageCode; } }//EOF --- 166,206 ---- } + /** ! * This if for design and future implementation of UDP_packet ! * @author gift (sourceforge.net user) ! * @param Nothing. * @return Nothing. * @version v0.20 */ ! public void calculateCheck_Sum() { ! } /** ! * This method gets Check_Sum ! * can be used for design and future implementation of UDP_packet ! * @author gift (sourceforge.net user) * @param Unused. ! * @return CHECK_SUM. * @version v0.20 */ ! public int getCheck_Sum() { ! return CHECK_SUM; } + /** + * This method gets protocol code (17 for UDP) + * @author gift (sourceforge.net user) + * @param Unused. + * @return protocol code PTCL. + * @version v0.20 + */ + public int getProtocolCode() + { + return PTCL; + } }//EOF |