[Javanetsim-cvs] javaNetSim/core EthernetNetworkInterface.java,1.2,1.3 NetworkInterface.java,1.2,1.3
Status: Beta
Brought to you by:
darkkey
From: Alexander B. <da...@us...> - 2005-11-19 21:53:58
|
Update of /cvsroot/javanetsim/javaNetSim/core In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv5833/core Modified Files: EthernetNetworkInterface.java NetworkInterface.java NetworkInterfacePort.java NetworkLayerDevice.java Node.java ProtocolStack.java Log Message: Index: Node.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/core/Node.java,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** Node.java 19 Nov 2005 20:13:07 -0000 1.4 --- Node.java 19 Nov 2005 21:53:51 -0000 1.5 *************** *** 233,237 **** */ ! protected void receivePacket(Packet inPacket) throws TransportLayerException, CommunicationException, LowLinkException, InvalidNetworkLayerDeviceException { return; --- 233,237 ---- */ ! protected void receivePacket(Packet inPacket) throws LowLinkException { return; Index: EthernetNetworkInterface.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/core/EthernetNetworkInterface.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** EthernetNetworkInterface.java 19 Nov 2005 17:54:33 -0000 1.2 --- EthernetNetworkInterface.java 19 Nov 2005 21:53:51 -0000 1.3 *************** *** 148,152 **** frameErrInfo.setDescription(ex.toString()); Simulation.addLayerInfo(frameErrInfo); - System.out.println("!!!"); //throw new LowLinkException(ex.toString()); } --- 148,151 ---- Index: ProtocolStack.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/core/ProtocolStack.java,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** ProtocolStack.java 19 Nov 2005 20:13:07 -0000 1.3 --- ProtocolStack.java 19 Nov 2005 21:53:51 -0000 1.4 *************** *** 1,154 **** ! /* ! ! 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. ! ! /* ! ! 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; ! ! ! ! /** ! ! * @author luke_hamilton ! ! * @since Sep 17, 2004 ! ! * @version v0.20 ! ! */ ! ! ! ! public abstract class ProtocolStack { ! ! public static final int TCP_IP = 0; ! ! public static final int IPX_SPX = 1; ! ! public static final int IBM_SNA = 2; ! ! public static final int APPLETALK = 3; ! ! ! ! public static int UIDGen; ! ! /** ! ! * Future use. All protocol stacks regardless of type must implement ! ! * recievepacket! ! ! * @author bevan_calliess ! ! * @param inPacket ! ! */ ! ! public abstract void receivePacket(Packet inPacket) throws TransportLayerException, CommunicationException, LowLinkException, InvalidNetworkLayerDeviceException; ! ! ! ! }//EOF ! --- 1,77 ---- ! /* ! 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. ! /* ! 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; ! ! /** ! * @author luke_hamilton ! * @since Sep 17, 2004 ! * @version v0.20 ! */ ! ! public abstract class ProtocolStack { ! public static final int TCP_IP = 0; ! public static final int IPX_SPX = 1; ! public static final int IBM_SNA = 2; ! public static final int APPLETALK = 3; ! ! public static int UIDGen; ! /** ! * Future use. All protocol stacks regardless of type must implement ! * recievepacket! ! * @author bevan_calliess ! * @param inPacket ! */ ! public abstract void receivePacket(Packet inPacket) throws LowLinkException; ! ! }//EOF Index: NetworkInterfacePort.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/core/NetworkInterfacePort.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** NetworkInterfacePort.java 19 Nov 2005 20:13:07 -0000 1.2 --- NetworkInterfacePort.java 19 Nov 2005 21:53:51 -0000 1.3 *************** *** 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; ! ! import java.io.Serializable; ! ! /** ! ! * A NetworkInterfacePort represents the physical interface between ! ! * a DataLinkLayerDevice and a physical Link (network cable). Think of it as a port ! ! * ! ! * <P>Different DataLinkLayerDevices can contain different numbers of NetworkInterfacesPorts. ! ! * A Hub often has 4 or 8 and a switch has 8, 16 or 32.</P> ! ! * ! ! * <P>In order for a DataLinkLayerDevice to be able to send or receive network information (packets), ! ! * there must be a Link (network cable) between at least 2 NetworkInterfaces.</P> ! ! * ! ! * <P>NetworkInterfacePotrs receive and send packets to and from DatalinkProtocols and ! ! * the Link object they are connected to.</P> ! ! * ! ! * @author bevan_valliess ! ! * @since 13 Nov 2004 ! ! * @version v0.20 ! ! */ ! ! ! ! public class NetworkInterfacePort extends NetworkInterface{ ! ! ! ! /** ! ! * Constructs a NetworkInterfacePort object with the name inName ! ! * and a reference to it's parent Node. ! ! * @author baven_calliess ! ! * @param inName - The name to give the NetworkInterface eg: eth0 ! ! * @param inParent - The Node that the NetworkInterface is to be added to, it's parent. ! ! * @version v0.20 ! ! */ ! ! protected NetworkInterfacePort(String inName, Node inParent) { ! ! super(inName,inParent); ! ! } ! ! ! ! ! ! /** ! ! * This method recevie a packet from a connected link and then pass it ! ! * to the node's protocolstack. Depending on the network any ! ! * testing of the packets headers may need to be inserted here. ! ! * @author bevan_calliess ! ! * @param inPacket - The packet being recived by this port ! ! * @version v0.20 ! ! */ ! ! protected void receivePacket(Packet inPacket) throws LowLinkException { ! ! parentNode.receivePacket(inPacket, name); ! ! return; ! ! } ! ! ! ! /** ! ! * This method sends a packet to a connected link Depending ! ! * it is used by the datalinkLayer devices to tansport ! ! * packets without any validation or data checking. ! ! * @author bevan_calliess ! ! * @author angela_brown ! ! * @param outPacket - A Packet ! ! * @version v0.20 ! ! */ ! ! protected void sendPacket(Packet outPacket) throws TransportLayerException, CommunicationException, LowLinkException, InvalidNetworkLayerDeviceException{ ! ! Ethernet_packet tempPacket = (Ethernet_packet)outPacket; ! ! EthernetLink temp = (EthernetLink)connectedLink; ! ! ! ! if(temp!=null){ ! ! temp.transportPacket(tempPacket,getSourceName()); ! ! } ! ! } ! ! ! ! /** ! ! * This method returns information about this InterfacePort ! ! * @author bevan_calliess ! ! * @return String - The details of Interface name Mac and Links ! ! * @version v0.20 ! ! */ ! ! protected String getDetails(){ ! ! return "Interface: "+name+"\t\tMAC: Not Applicable \t\t"+ getConnectLinkDetails(); ! ! } ! ! }//EOF ! --- 1,103 ---- ! /* ! 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; ! import java.io.Serializable; ! /** ! * A NetworkInterfacePort represents the physical interface between ! * a DataLinkLayerDevice and a physical Link (network cable). Think of it as a port ! * ! * <P>Different DataLinkLayerDevices can contain different numbers of NetworkInterfacesPorts. ! * A Hub often has 4 or 8 and a switch has 8, 16 or 32.</P> ! * ! * <P>In order for a DataLinkLayerDevice to be able to send or receive network information (packets), ! * there must be a Link (network cable) between at least 2 NetworkInterfaces.</P> ! * ! * <P>NetworkInterfacePotrs receive and send packets to and from DatalinkProtocols and ! * the Link object they are connected to.</P> ! * ! * @author bevan_valliess ! * @since 13 Nov 2004 ! * @version v0.20 ! */ ! ! public class NetworkInterfacePort extends NetworkInterface{ ! ! /** ! * Constructs a NetworkInterfacePort object with the name inName ! * and a reference to it's parent Node. ! * @author baven_calliess ! * @param inName - The name to give the NetworkInterface eg: eth0 ! * @param inParent - The Node that the NetworkInterface is to be added to, it's parent. ! * @version v0.20 ! */ ! protected NetworkInterfacePort(String inName, Node inParent) { ! super(inName,inParent); ! } ! ! ! /** ! * This method recevie a packet from a connected link and then pass it ! * to the node's protocolstack. Depending on the network any ! * testing of the packets headers may need to be inserted here. ! * @author bevan_calliess ! * @param inPacket - The packet being recived by this port ! * @version v0.20 ! */ ! protected void receivePacket(Packet inPacket) throws LowLinkException { ! parentNode.receivePacket(inPacket, name); ! return; ! } ! ! /** ! * This method sends a packet to a connected link Depending ! * it is used by the datalinkLayer devices to tansport ! * packets without any validation or data checking. ! * @author bevan_calliess ! * @author angela_brown ! * @param outPacket - A Packet ! * @version v0.20 ! */ ! protected void sendPacket(Packet outPacket) throws LowLinkException{ ! Ethernet_packet tempPacket = (Ethernet_packet)outPacket; ! EthernetLink temp = (EthernetLink)connectedLink; ! ! if(temp!=null){ ! temp.transportPacket(tempPacket,getSourceName()); ! } ! } ! ! /** ! * This method returns information about this InterfacePort ! * @author bevan_calliess ! * @return String - The details of Interface name Mac and Links ! * @version v0.20 ! */ ! protected String getDetails(){ ! return "Interface: "+name+"\t\tMAC: Not Applicable \t\t"+ getConnectLinkDetails(); ! } ! }//EOF Index: NetworkInterface.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/core/NetworkInterface.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** NetworkInterface.java 19 Nov 2005 20:13:07 -0000 1.2 --- NetworkInterface.java 19 Nov 2005 21:53:51 -0000 1.3 *************** *** 1,400 **** ! /* ! ! 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; ! ! import java.io.Serializable; ! ! /** ! ! * A NetworkInterface represents the physical interface between ! ! * a Node and a physical Link (network cable). Think of it as the NIC ! ! * (Network Interface Card) of a Node. ! ! * ! ! * <P>Different Nodes can contain different numbers of NetworkInterfaces. ! ! * A client PC usually only has one NetworkInterface, whereas a Router contains ! ! * at least two. A Hub or a Switch often has 8 or 16.</P> ! ! * ! ! * <P>In order for a Node to be able to send or receive network information (packets), ! ! * there must be a Link (network cable) between at least 2 NetworkInterfaces.</P> ! ! * ! ! * <P>NetworkInterfaces receive and send packets to and from DatalinkProtocols and ! ! * the Link object they are connected to.</P> ! ! * ! ! * @author tristan_veness (Original Author) ! ! * @author bevan_calliess ! ! * @author luke_hamilton ! ! * @since 19 September 2004 ! ! * @version v0.20 ! ! */ ! ! ! ! abstract class NetworkInterface implements Serializable{ ! ! /** The NetworkInterface's name, eg "eth0" */ ! ! protected String name; ! ! /** The Link that this NetworkInterface is connected to */ ! ! protected Link connectedLink; ! ! protected Node parentNode; ! ! ! ! /** ! ! * Constructs a NetworkInterface object with the name inName and a reference to it's parent Node. ! ! * @author tristan_veness ! ! * @param inName - The name to give the NetworkInterface eg: eth0 ! ! * @param parent - The Node that the NetworkInterface is to be added to, it's parent. ! ! * @version v0.10 ! ! */ ! ! protected NetworkInterface(String inName, Node inParent) { ! ! name = inName; ! ! parentNode = inParent; ! ! } ! ! ! ! /** ! ! * This method reset the connected link to null ! ! * @author luke_hamilton ! ! * @version v0.20 ! ! */ ! ! protected void resetConnectedLink() { ! ! connectedLink = null; ! ! } ! ! ! ! /** ! ! * This method will call the disconnectLink method on the ! ! * Connected link, and then set the connected link to null ! ! * @author luke_hamilton ! ! * @version v0.20 ! ! */ ! ! protected void removeConnectedLink() { ! ! if(connectedLink != null){ ! ! connectedLink.disconnectLink(); ! ! connectedLink = null; ! ! } ! ! } ! ! ! ! /** ! ! * This method recevie a packet from a connected link and then pass it ! ! * to the node's protocolstack. Depending on the network any ! ! * testing of the packets headers may need to be inserted here. ! ! * This method is overridded by the subclasses on interface to suite ! ! * there requirements ! ! * @author baven_calliess ! ! * @param inPacket - A packet ! ! * @version v0.20 ! ! */ ! ! protected void receivePacket(Packet inPacket) throws TransportLayerException, CommunicationException, LowLinkException, InvalidNetworkLayerDeviceException {} ! ! ! ! /** ! ! * This method sends a packet to a connected link Depending on ! ! * @author bevan_calliess ! ! * @param inPacket ! ! * @version v0.20 ! ! */ ! ! protected void sendPacket(Packet outPacket) throws TransportLayerException, CommunicationException, LowLinkException, InvalidNetworkLayerDeviceException {} ! ! ! ! /** ! ! * Returns the NetworkInterface's name. ! ! * @author bevan_calliess ! ! * @return Name - The NetworkInterface's name ! ! * @version v0.20 ! ! */ ! ! ! ! protected String getName() { ! ! return name; ! ! } ! ! ! ! /** ! ! * This method is used by interfaces to uniquely identify themselves ! ! * in the simulation it will return a combination of the ! ! * Parent naodes name and the Interfaces name ! ! * eg. Node name PC1 interface eth0 will return "PC1eth0" ! ! * @author bevan_calliess ! ! * @return Name - The Source name of this Node Interface ! ! * @version v0.20 ! ! */ ! ! protected String getSourceName() { ! ! return parentNode.getName()+name; ! ! } ! ! ! ! /** ! ! * Sets the connectedLink attribute of the NetworkInterface with Link l. ! ! * ! ! * <P>This method should only be called by the Link class when an Interface is added or removed from the Link.</P> ! ! * @author tristan_veness ! ! * @param l - The Link connected with this NetworkInterface. ! ! * @version v0.10 ! ! */ ! ! protected void setConnectedLink(Link l)throws InvalidLinkConnectionException { ! ! if(connectedLink == null){ ! ! connectedLink = l; ! ! }else ! ! throw new InvalidLinkConnectionException("Network Interface is already connected. Delete Connected link first"); ! ! ! ! } ! ! ! ! /** ! ! * Returns the Link that this NetworkInterface is connected to. ! ! * @author tristan_veness ! ! * @return The Link object that this NetworkInterface is connected to. null if it is not connected. ! ! * @version v0.10 ! ! */ ! ! protected Link getConnectedLink() { ! ! return connectedLink; ! ! } ! ! ! ! protected String getConnectedLinkName() { ! ! if(connectedLink!=null) return connectedLink.getName(); ! ! else return null; ! ! } ! ! ! ! /** ! ! * This method returns the name of the network interface ! ! * @author tristan_veness ! ! * @return Name ! ! * @version v0.10 ! ! */ ! ! protected String getDetails(){ ! ! return name; ! ! } ! ! ! ! /** ! ! * This method returns a string of information about if the network interface is connected of not. ! ! * <P>This method is useful for a CLI or for debugging.</P> ! ! * @author tristan_veness ! ! * @return Name - Connection: link1 ! ! * @version v0.10 ! ! */ ! ! protected String getConnectLinkDetails(){ ! ! if(connectedLink != null){ ! ! return "Connection: "+ connectedLink.getName(); ! ! } ! ! return "Connection: Not connected"; ! ! } ! ! ! ! protected String getConnectLinkName() ! ! { ! ! if(connectedLink !=null) ! ! { ! ! return (String)connectedLink.getName(); ! ! } ! ! return "Not Connected"; ! ! } ! ! }//EOF ! --- 1,200 ---- ! /* ! 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; ! import java.io.Serializable; ! /** ! * A NetworkInterface represents the physical interface between ! * a Node and a physical Link (network cable). Think of it as the NIC ! * (Network Interface Card) of a Node. ! * ! * <P>Different Nodes can contain different numbers of NetworkInterfaces. ! * A client PC usually only has one NetworkInterface, whereas a Router contains ! * at least two. A Hub or a Switch often has 8 or 16.</P> ! * ! * <P>In order for a Node to be able to send or receive network information (packets), ! * there must be a Link (network cable) between at least 2 NetworkInterfaces.</P> ! * ! * <P>NetworkInterfaces receive and send packets to and from DatalinkProtocols and ! * the Link object they are connected to.</P> ! * ! * @author tristan_veness (Original Author) ! * @author bevan_calliess ! * @author luke_hamilton ! * @since 19 September 2004 ! * @version v0.20 ! */ ! ! abstract class NetworkInterface implements Serializable{ ! /** The NetworkInterface's name, eg "eth0" */ ! protected String name; ! /** The Link that this NetworkInterface is connected to */ ! protected Link connectedLink; ! protected Node parentNode; ! ! /** ! * Constructs a NetworkInterface object with the name inName and a reference to it's parent Node. ! * @author tristan_veness ! * @param inName - The name to give the NetworkInterface eg: eth0 ! * @param parent - The Node that the NetworkInterface is to be added to, it's parent. ! * @version v0.10 ! */ ! protected NetworkInterface(String inName, Node inParent) { ! name = inName; ! parentNode = inParent; ! } ! ! /** ! * This method reset the connected link to null ! * @author luke_hamilton ! * @version v0.20 ! */ ! protected void resetConnectedLink() { ! connectedLink = null; ! } ! ! /** ! * This method will call the disconnectLink method on the ! * Connected link, and then set the connected link to null ! * @author luke_hamilton ! * @version v0.20 ! */ ! protected void removeConnectedLink() { ! if(connectedLink != null){ ! connectedLink.disconnectLink(); ! connectedLink = null; ! } ! } ! ! /** ! * This method recevie a packet from a connected link and then pass it ! * to the node's protocolstack. Depending on the network any ! * testing of the packets headers may need to be inserted here. ! * This method is overridded by the subclasses on interface to suite ! * there requirements ! * @author baven_calliess ! * @param inPacket - A packet ! * @version v0.20 ! */ ! protected void receivePacket(Packet inPacket) throws LowLinkException {} ! ! /** ! * This method sends a packet to a connected link Depending on ! * @author bevan_calliess ! * @param inPacket ! * @version v0.20 ! */ ! protected void sendPacket(Packet outPacket) throws LowLinkException {} ! ! /** ! * Returns the NetworkInterface's name. ! * @author bevan_calliess ! * @return Name - The NetworkInterface's name ! * @version v0.20 ! */ ! ! protected String getName() { ! return name; ! } ! ! /** ! * This method is used by interfaces to uniquely identify themselves ! * in the simulation it will return a combination of the ! * Parent naodes name and the Interfaces name ! * eg. Node name PC1 interface eth0 will return "PC1eth0" ! * @author bevan_calliess ! * @return Name - The Source name of this Node Interface ! * @version v0.20 ! */ ! protected String getSourceName() { ! return parentNode.getName()+name; ! } ! ! /** ! * Sets the connectedLink attribute of the NetworkInterface with Link l. ! * ! * <P>This method should only be called by the Link class when an Interface is added or removed from the Link.</P> ! * @author tristan_veness ! * @param l - The Link connected with this NetworkInterface. ! * @version v0.10 ! */ ! protected void setConnectedLink(Link l)throws InvalidLinkConnectionException { ! if(connectedLink == null){ ! connectedLink = l; ! }else ! throw new InvalidLinkConnectionException("Network Interface is already connected. Delete Connected link first"); ! ! } ! ! /** ! * Returns the Link that this NetworkInterface is connected to. ! * @author tristan_veness ! * @return The Link object that this NetworkInterface is connected to. null if it is not connected. ! * @version v0.10 ! */ ! protected Link getConnectedLink() { ! return connectedLink; ! } ! ! protected String getConnectedLinkName() { ! if(connectedLink!=null) return connectedLink.getName(); ! else return null; ! } ! ! /** ! * This method returns the name of the network interface ! * @author tristan_veness ! * @return Name ! * @version v0.10 ! */ ! protected String getDetails(){ ! return name; ! } ! ! /** ! * This method returns a string of information about if the network interface is connected of not. ! * <P>This method is useful for a CLI or for debugging.</P> ! * @author tristan_veness ! * @return Name - Connection: link1 ! * @version v0.10 ! */ ! protected String getConnectLinkDetails(){ ! if(connectedLink != null){ ! return "Connection: "+ connectedLink.getName(); ! } ! return "Connection: Not connected"; ! } ! ! protected String getConnectLinkName() ! { ! if(connectedLink !=null) ! { ! return (String)connectedLink.getName(); ! } ! return "Not Connected"; ! } ! }//EOF Index: NetworkLayerDevice.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/core/NetworkLayerDevice.java,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** NetworkLayerDevice.java 19 Nov 2005 20:13:07 -0000 1.3 --- NetworkLayerDevice.java 19 Nov 2005 21:53:51 -0000 1.4 *************** *** 1,578 **** ! /* ! ! 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; ! ! import core.EthernetNetworkInterface; ! ! import core.protocolsuite.tcp_ip.InvalidIPAddressException; ! ! import core.InvalidNetworkInterfaceNameException; ! ! import core.protocolsuite.tcp_ip.InvalidSubnetMaskException; ! ! import core.protocolsuite.tcp_ip.Route_entry; ! ! import java.util.*; ! ! ! ! /** ! ! * NetworkLayerDevice extends Node. This class adds network layer devices ! ! * sets IPAddress, defaultgateway, sends a ping and a few more options ! ! * @author luke_hamilton ! ! * @author angela_brown ! ! * @author michael_reith ! ! * @author robert_hulford ! ! * @author bevan_calliess ! ! * @since Oct 9, 2004 ! ! * @version v0.20 ! ! */ ! ! public abstract class NetworkLayerDevice extends Node { ! ! ! ! /** ! ! * calls the super class (Node) and passes it inName and inProtocolStack ! ! * @author luke_hamilton ! ! * @author bevan_calliess ! ! * @param inName - Node Name eg: PC1 ! ! * @param inProtocolStackLayers - ProtocolStack Layer ! ! * @version v0.20 ! ! */ ! ! public NetworkLayerDevice(String inName, int inProtocolStackLayers) { ! ! super(inName, inProtocolStackLayers); ! ! } ! ! ! ! /** ! ! * This method will get the subnetMask of the Interface that was ! ! * passed in ! ! * @author bevan_callies ! ! * @author robert_hulford ! ! * @param inInteface - The Name of the Inteface eg: eth0 ! ! * @return The subnetMask ! ! * @version v0.20 ! ! */ ! ! //TODO This should maybe check the inInterface exists within the Interface hashtable first -luke hamilton ! ! public String getSubnetMask(String inInterface) { ! ! return NodeProtocolStack.getSubnetMask(inInterface); ! ! } ! ! ! ! /** ! ! * This method will get the ipaddress of the Interface that was passed in ! ! * ! ! * @author luke_hamilton ! ! * @param inInteface - The Name of the Inteface eg: eth0 ! ! * @return The subnetMask ! ! * @version v0.20 ! ! ! ! */ ! ! //TODO This should maybe check the inInterface exists within the Interface hashtable first -luke hamilton ! ! public String getIPAddress(String inInterface){ ! ! return NodeProtocolStack.getIPAddress(inInterface); ! ! } ! ! ! ! /** ! ! * This method will pass in a packet and send it off to the ! ! * nodeProtocolStack ! ! * @author angela_brown ! ! * @author bevan_calliess ! ! * @param inPacket - A Packet ! ! * @version v0.20 ! ! */ ! ! public void receivePacket(Packet inPacket) throws TransportLayerException, CommunicationException, LowLinkException, InvalidNetworkLayerDeviceException { ! ! NodeProtocolStack.receivePacket(inPacket); ! ! } ! ! ! ! /** ! ! * This method will send a ping to the specified Destination ! ! * Address passing it up to the NodeProtocolStack ! ! * @author angela_brown ! ! * @author bevna_calliess ! ! * @param inDestIPAddress - The Destination IP Addres eg: 192.168.0.2 ! ! * @throws CommunicationException ! ! * @version v0.20 ! ! */ ! ! public void sendPing(String inDestIPAddress) throws TransportLayerException, CommunicationException, LowLinkException, InvalidNetworkLayerDeviceException{ ! ! NodeProtocolStack.sendPing(inDestIPAddress); ! ! } ! ! ! ! ! ! /** ! ! * This method will check to see if the Interface key is contained within the ! ! * NetworkInterfacetable (hash table) if so typecast it into a EthernetNetworkInterface Object ! ! * and send the packet and Destination MAC address up to the EthernetNetworkInterface layer ! ! * @author bevan_calliess ! ! * @author angela_brown ! ! * @param inDestMACAddress - Destination MAC address eg: AA:A1:BC:34:65 ! ! * @param inPacket - A Packet ! ! * @param inInterfaceKey - The Inteface Key ! ! * @throws InvalidNetworkInterfaceNameException ! ! * @version v0.20 ! ! */ ! ! public void sendPacket(String inDestMACAddress, Packet inPacket, String inInterfaceKey) throws InvalidNetworkInterfaceNameException, TransportLayerException, CommunicationException, LowLinkException, InvalidNetworkLayerDeviceException{ ! ! if (NetworkInterfacetable.containsKey(inInterfaceKey)) ! ! { ! ! EthernetNetworkInterface temp = (EthernetNetworkInterface)NetworkInterfacetable.get(inInterfaceKey); ! ! temp.sendPacket(inPacket,inDestMACAddress); ! ! } ! ! else ! ! { ! ! throw new InvalidNetworkInterfaceNameException("Inteface does not exist."); ! ! } ! ! } ! ! ! ! ! ! /** ! ! * This method will get the defaultgateway when called from the NodeProtocolStack ! ! * @author angela_brown ! ! * @author michael_reith ! ! * @return Defaultgateway ! ! * @version v0.20 ! ! */ ! ! public String getDefaultGateway() { ! ! return NodeProtocolStack.getDefaultGateway(); ! ! } ! ! ! ! /** ! ! * gets a string array from the arp protocol and returns it ! ! * @author robert_hulford ! ! * @author bevan_calliess ! ! * @return String[] - The arp table entries ! ! */ ! ! public String[] getARPTable() { ! ! return NodeProtocolStack.getARPTable(); ! ! } ! ! ! ! /** ! ! * This method will pass inIterface, incustomeSubnetMask up to the NodeProtocolStack ! ! * with the aim to set the CustomSubnetMask ! ! * @author bevan_calliess ! ! * @author robert_hulford ! ! * @param inInterface ! ! * @param inCustomSubnetMask ! ! * @throws InvalidNetworkInterfaceNameException ! ! * @throws InvalidSubnetMaskException ! ! * @version v0.20 ! ! */ ! ! ! ! public void setCustomSubnetMask(String inInterface, String inCustomSubnetMask)throws InvalidNetworkInterfaceNameException,InvalidSubnetMaskException { ! ! if(NetworkInterfacetable.containsKey(inInterface)){ ! ! NodeProtocolStack.setCustomSubnetMask(inInterface, inCustomSubnetMask); ! ! }else{ ! ! throw new InvalidNetworkInterfaceNameException("Interface does not exsist"); ! ! } ! ! } ! ! ! ! /** ! ! * This method will call the setDefaultgatway method within the NodeProtocolStack passing it ! ! * the inGatewayIPAddress ! ! * @author angela_brown ! ! * @author michael_reith ! ! * @param inGatewayIPAddress ! ! * @throws InvalidNodeNameException ! ! * @throws InvalidDefaultGatewayException ! ! * @version v0.20 ! ! */ ! ! ! ! public void setDefaultGateway(String inGatewayIPAddress) throws InvalidNodeNameException, InvalidDefaultGatewayException{ ! ! NodeProtocolStack.setDefaultGateway(inGatewayIPAddress); ! ! } ! ! ! ! /** ! ! * This method will set the ip address for a network interface. ! ! * It will test if the inInterface exists and returns the MAC address of the netwokInterface set. ! ! * @param inInterface - The Interface name eg: eth0 ! ! * @param inIPAddress - The IP address eg: 192.168.0.2 ! ! * @return macAddress - The MAC address on the Interface card that the IP address was set for. ! ! * @throws InvalidNetworkInterfaceNameException ! ! * @throws InvalidIPAddressException ! ! */ ! ! ! ! protected String setIPAddress(String inInterface, String inIPAddress) throws InvalidNetworkInterfaceNameException,InvalidIPAddressException { ! ! String macAddress = null; ! ! if (NetworkInterfacetable.containsKey(inInterface)) { ! ! NodeProtocolStack.setIPAddress(inInterface, inIPAddress); ! ! EthernetNetworkInterface tempNic = ! ! (EthernetNetworkInterface) NetworkInterfacetable.get( ! ! inInterface); ! ! macAddress = tempNic.getMACAddress(); ! ! ! ! } else { ! ! throw new InvalidNetworkInterfaceNameException("Interface does not exist"); ! ! } ! ! return macAddress; ! ! } ! ! ! ! /** ! ! * This method will call the protocol stacks' add to ARP method ! ! * passing the ip address and the mac address ! ! * @author bevan_calliess ! ! * @author robert_hulford ! ! * @param inMACAddress - The MAC Address eg: ab:ab:ab:ab:ab:ab ! ! * @param inIPAddress - The IPAddress eg: 192.168.0.2 ! ! * @version v0.20 ! ! */ ! ! public void addToARP(String inIPAddress, String inMACAddress){ ! ! NodeProtocolStack.addToARP(inIPAddress, inMACAddress); ! ! } ! ! ! ! /** ! ! * ARP functions... ! ! * Shall be documented as well. ! ! * @author Key ! ! * @version v0.21 ! ! */ ! ! public void addToARPStatic(String inIPAddress, String inMACAddress){ ! ! NodeProtocolStack.addToARPStatic(inIPAddress, inMACAddress); ! ! } ! ! ! ! public void removeARP(String inIPAddress){ ! ! NodeProtocolStack.removeARP(inIPAddress); ! ! } ! ! ! ! /** ! ! * ! ! * @return ! ! */ ! ! public Object[] getAllInterfaces(){ ! ! ! ! ArrayList interfaceArray = new ArrayList(); ! ! Enumeration keys = NetworkInterfacetable.keys(); ! ! while(keys.hasMoreElements()){ ! ! String str = (String) keys.nextElement(); ! ! NetworkInterface x = (NetworkInterface)NetworkInterfacetable.get(str); ! ! interfaceArray.add(x.getName()); ! ! } ! ! ! ! return interfaceArray.toArray(); ! ! } ! ! ! ! /** ! ! * Routing tables functions... Use carefully! ! ! * Shall be documented as well. ! ! * @author Key ! ! * @version v0.21 ! ! */ ! ! ! ! public void addRoute(Route_entry r){ ! ! NodeProtocolStack.addRoute(r); ! ! } ! ! ! ! public void removeRoute(String destIP){ ! ! NodeProtocolStack.removeRoute(destIP); ! ! } ! ! ! ! public String[] getRouteTableEntries(){ ! ! return NodeProtocolStack.getRouteTableEntries(); ! ! } ! ! ! ! public Route_entry getRouteTableEntry(String destIP){ ! ! return NodeProtocolStack.getRouteTableEntry(destIP); ! ! } ! ! ! ! }//EOF ! --- 1,289 ---- ! /* ! 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; ! import core.EthernetNetworkInterface; ! import core.protocolsuite.tcp_ip.InvalidIPAddressException; ! import core.InvalidNetworkInterfaceNameException; ! import core.protocolsuite.tcp_ip.InvalidSubnetMaskException; ! import core.protocolsuite.tcp_ip.Route_entry; ! import java.util.*; ! ! /** ! * NetworkLayerDevice extends Node. This class adds network layer devices ! * sets IPAddress, defaultgateway, sends a ping and a few more options ! * @author luke_hamilton ! * @author angela_brown ! * @author michael_reith ! * @author robert_hulford ! * @author bevan_calliess ! * @since Oct 9, 2004 ! * @version v0.20 ! */ ! public abstract class NetworkLayerDevice extends Node { ! ! /** ! * calls the super class (Node) and passes it inName and inProtocolStack ! * @author luke_hamilton ! * @author bevan_calliess ! * @param inName - Node Name eg: PC1 ! * @param inProtocolStackLayers - ProtocolStack Layer ! * @version v0.20 ! */ ! public NetworkLayerDevice(String inName, int inProtocolStackLayers) { ! super(inName, inProtocolStackLayers); ! } ! ! /** ! * This method will get the subnetMask of the Interface that was ! * passed in ! * @author bevan_callies ! * @author robert_hulford ! * @param inInteface - The Name of the Inteface eg: eth0 ! * @return The subnetMask ! * @version v0.20 ! */ ! //TODO This should maybe check the inInterface exists within the Interface hashtable first -luke hamilton ! public String getSubnetMask(String inInterface) { ! return NodeProtocolStack.getSubnetMask(inInterface); ! } ! ! /** ! * This method will get the ipaddress of the Interface that was passed in ! * ! * @author luke_hamilton ! * @param inInteface - The Name of the Inteface eg: eth0 ! * @return The subnetMask ! * @version v0.20 ! ! */ ! //TODO This should maybe check the inInterface exists within the Interface hashtable first -luke hamilton ! public String getIPAddress(String inInterface){ ! return NodeProtocolStack.getIPAddress(inInterface); ! } ! ! /** ! * This method will pass in a packet and send it off to the ! * nodeProtocolStack ! * @author angela_brown ! * @author bevan_calliess ! * @param inPacket - A Packet ! * @version v0.20 ! */ ! public void receivePacket(Packet inPacket) throws LowLinkException { ! NodeProtocolStack.receivePacket(inPacket); ! } ! ! /** ! * This method will send a ping to the specified Destination ! * Address passing it up to the NodeProtocolStack ! * @author angela_brown ! * @author bevna_calliess ! * @param inDestIPAddress - The Destination IP Addres eg: 192.168.0.2 ! * @throws CommunicationException ! * @version v0.20 ! */ ! public void sendPing(String inDestIPAddress) throws CommunicationException, LowLinkException{ ! NodeProtocolStack.sendPing(inDestIPAddress); ! } ! ! ! /** ! * This method will check to see if the Interface key is contained within the ! * NetworkInterfacetable (hash table) if so typecast it into a EthernetNetworkInterface Object ! * and send the packet and Destination MAC address up to the EthernetNetworkInterface layer ! * @author bevan_calliess ! * @author angela_brown ! * @param inDestMACAddress - Destination MAC address eg: AA:A1:BC:34:65 ! * @param inPacket - A Packet ! * @param inInterfaceKey - The Inteface Key ! * @throws InvalidNetworkInterfaceNameException ! * @version v0.20 ! */ ! public void sendPacket(String inDestMACAddress, Packet inPacket, String inInterfaceKey) throws InvalidNetworkInterfaceNameException, CommunicationException, LowLinkException{ ! if (NetworkInterfacetable.containsKey(inInterfaceKey)) ! { ! EthernetNetworkInterface temp = (EthernetNetworkInterface)NetworkInterfacetable.get(inInterfaceKey); ! temp.sendPacket(inPacket,inDestMACAddress); ! } ! else ! { ! throw new InvalidNetworkInterfaceNameException("Inteface does not exist."); ! } ! } ! ! ! /** ! * This method will get the defaultgateway when called from the NodeProtocolStack ! * @author angela_brown ! * @author michael_reith ! * @return Defaultgateway ! * @version v0.20 ! */ ! public String getDefaultGateway() { ! return NodeProtocolStack.getDefaultGateway(); ! } ! ! /** ! * gets a string array from the arp protocol and returns it ! * @author robert_hulford ! * @author bevan_calliess ! * @return String[] - The arp table entries ! */ ! public String[] getARPTable() { ! return NodeProtocolStack.getARPTable(); ! } ! ! /** ! * This method will pass inIterface, incustomeSubnetMask up to the NodeProtocolStack ! * with the aim to set the CustomSubnetMask ! * @author bevan_calliess ! * @author robert_hulford ! * @param inInterface ! * @param inCustomSubnetMask ! * @throws InvalidNetworkInterfaceNameException ! * @throws InvalidSubnetMaskException ! * @version v0.20 ! */ ! ! public void setCustomSubnetMask(String inInterface, String inCustomSubnetMask)throws InvalidNetworkInterfaceNameException,InvalidSubnetMaskException { ! if(NetworkInterfacetable.containsKey(inInterface)){ ! NodeProtocolStack.setCustomSubnetMask(inInterface, inCustomSubnetMask); ! }else{ ! throw new InvalidNetworkInterfaceNameException("Interface does not exsist"); ! } ! } ! ! /** ! * This method will call the setDefaultgatway method within the NodeProtocolStack passing it ! * the inGatewayIPAddress ! * @author angela_brown ! * @author michael_reith ! * @param inGatewayIPAddress ! * @throws InvalidNodeNameException ! * @throws InvalidDefaultGatewayException ! * @version v0.20 ! */ ! ! public void setDefaultGateway(String inGatewayIPAddress) throws InvalidNodeNameException, InvalidDefaultGatewayException{ ! NodeProtocolStack.setDefaultGateway(inGatewayIPAddress); ! } ! ! /** ! * This method will set the ip address for a network interface. ! * It will test if the inInterface exists and returns the MAC address of the netwokInterface set. ! * @param inInterface - The Interface name eg: eth0 ! * @param inIPAddress - The IP address eg: 192.168.0.2 ! * @return macAddress - The MAC address on the Interface card that the IP address was set for. ! * @throws InvalidNetworkInterfaceNameException ! * @throws InvalidIPAddressException ! */ ! ! protected String setIPAddress(String inInterface, String inIPAddress) throws InvalidNetworkInterfaceNameException,InvalidIPAddressException { ! String macAddress = null; ! if (NetworkInterfacetable.containsKey(inInterface)) { ! NodeProtocolStack.setIPAddress(inInterface, inIPAddress); ! EthernetNetworkInterface tempNic = ! (EthernetNetworkInterface) NetworkInterfacetable.get( ! inInterface); ! macAddress = tempNic.getMACAddress(); ! ! } else { ! throw new InvalidNetworkInterfaceNameException("Interface does not exist"); ! } ! return macAddress; ! } ! ! /** ! * This method will call the protocol stacks' add to ARP method ! * passing the ip address and the mac address ! * @author bevan_calliess ! * @author robert_hulford ! * @param inMACAddress - The MAC Address eg: ab:ab:ab:ab:ab:ab ! * @param inIPAddress - The IPAddress eg: 192.168.0.2 ! * @version v0.20 ! */ ! public void addToARP(String inIPAddress, String inMACAddress){ ! NodeProtocolStack.addToARP(inIPAddress, inMACAddress); ! } ! ! /** ! * ARP functions... ! * Shall be documented as well. ! * @author Key ! * @version v0.21 ! */ ! public void addToARPStatic(String inIPAddress, String inMACAddress){ ! NodeProtocolStack.addToARPStatic(inIPAddress, inMACAddress); ! } ! ! public void removeARP(String inIPAddress){ ! NodeProtocolStack.removeARP(inIPAddress); ! } ! ! /** ! * ! * @return ! */ ! public Object[] getAllInterfaces(){ ! ! ArrayList interfaceArray = new ArrayList(); ! Enumeration keys = NetworkInterfacetable.keys(); ! while(keys.hasMoreElements()){ ! String str = (String) keys.nextElement(); ! NetworkInterface x = (NetworkInterface)NetworkInterfacetable.get(str); ! interfaceArray.add(x.getName()); ! } ! ! return interfaceArray.toArray(); ! } ! ! /** ! * Routing tables functions... Use carefully! ! * Shall be documented as well. ! * @author Key ! * @version v0.21 ! */ ! ! public void addRoute(Route_entry r){ ! NodeProtocolStack.addRoute(r); ! } ! ! public void removeRoute(String destIP){ ! NodeProtocolStack.removeRoute(destIP); ! } ! ! public String[] getRouteTableEntries(){ ! return NodeProtocolStack.getRouteTableEntries(); ! } ! ! public Route_entry getRouteTableEntry(String destIP){ ! return NodeProtocolStack.getRouteTableEntry(destIP); ! } ! ! }//EOF |