[Javanetsim-cvs] javaNetSim/core SerialLink.java, 1.2, 1.3 SerialNetworkInterface.java, 1.2, 1.3 Se
Status: Beta
Brought to you by:
darkkey
From: Alexander B. <da...@us...> - 2007-10-15 12:04:37
|
Update of /cvsroot/javanetsim/javaNetSim/core In directory sc8-pr-cvs6.sourceforge.net:/tmp/cvs-serv5217/core Modified Files: ApplicationLayerDevice.java NetworkInterface.java NetworkLayerDevice.java Node.java PC.java Router.java Simulation.java Added Files: SerialLink.java SerialNetworkInterface.java Serial_packet.java Log Message: Serial(FrameRelay) NICS + minor fixes in socket layer/protocol stack... Index: PC.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/core/PC.java,v retrieving revision 1.13 retrieving revision 1.14 diff -C2 -d -r1.13 -r1.14 *** PC.java 14 Oct 2007 17:19:07 -0000 1.13 --- PC.java 15 Oct 2007 12:04:32 -0000 1.14 *************** *** 150,154 **** addNetworkInterface(NetworkInterface.getIntName(NetworkInterface.Console) + "0", NetworkInterface.Console, false); //addNetworkInterface(NetworkInterface.getIntName(NetworkInterface.Wireless) + "0", NetworkInterface.Wireless, true); ! addNetworkInterface(NetworkInterface.getIntName(NetworkInterface.WAN) + "0" + "_" + (int)(Math.random()*1000), NetworkInterface.WAN, true); } --- 150,154 ---- addNetworkInterface(NetworkInterface.getIntName(NetworkInterface.Console) + "0", NetworkInterface.Console, false); //addNetworkInterface(NetworkInterface.getIntName(NetworkInterface.Wireless) + "0", NetworkInterface.Wireless, true); ! //addNetworkInterface(NetworkInterface.getIntName(NetworkInterface.WAN) + "0" + "_" + (int)(Math.random()*1000), NetworkInterface.WAN, true); } Index: Node.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/core/Node.java,v retrieving revision 1.11 retrieving revision 1.12 diff -C2 -d -r1.11 -r1.12 *** Node.java 14 Oct 2007 22:14:52 -0000 1.11 --- Node.java 15 Oct 2007 12:04:32 -0000 1.12 *************** *** 284,288 **** NetworkInterfacetable.put(interfaceName,new WANNetworkInterface(interfaceName,this)); break; ! } } --- 284,290 ---- NetworkInterfacetable.put(interfaceName,new WANNetworkInterface(interfaceName,this)); break; ! case NetworkInterface.Serial: ! NetworkInterfacetable.put(interfaceName,new SerialNetworkInterface(interfaceName,this)); ! break; } } --- NEW FILE: SerialNetworkInterface.java --- /* 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; class SerialNetworkInterface extends NetworkInterface{ /** * FrameRelay ClockRate * */ protected int ClockRate; protected SerialNetworkInterface(String inName, Node parent) { super(inName,parent); ClockRate = 400000; } protected void receivePacket(Packet inPacket) throws LowLinkException { Serial_packet tempPacket = (Serial_packet)inPacket; if(tempPacket.getClockRate() == ClockRate ){ LayerInfo pingInfo = new LayerInfo(getClass().getName()); pingInfo.setObjectName(parentNode.getName()); pingInfo.setDataType("FrameRelay Packet"); pingInfo.setLayer("Link"); pingInfo.setDescription("Recieved and accepted packet at interface " + name); Simulation.addLayerInfo(pingInfo); Packet temp = tempPacket.getData(); parentNode.receivePacket(temp, name); }else{ LayerInfo pingInfo = new LayerInfo(getClass().getName()); pingInfo.setObjectName(parentNode.getName()); pingInfo.setDataType("FrameRelay Packet"); pingInfo.setLayer("Link"); pingInfo.setDescription("Recieved signal at interface " + name + " dropped due to invalid Clock rate."); Simulation.addLayerInfo(pingInfo); } } public int getType(){ return NetworkInterface.Serial; } protected void sendPacket(Packet inPacket) throws LowLinkException { Serial_packet Packet = new Serial_packet(inPacket, ClockRate); SerialLink temp = (SerialLink)connectedLink; // Create Layer info LayerInfo pingInfo = new LayerInfo(getClass().getName()); pingInfo.setObjectName(parentNode.getName()); pingInfo.setDataType("FrameRelay Packet"); pingInfo.setLayer("Link"); pingInfo.setDescription("Sending packet from interface "+ name); Simulation.addLayerInfo(pingInfo); if(temp!=null){ try{ temp.transportPacket(Packet, getSourceName()); }catch(LowLinkException ex){ LayerInfo frameErrInfo = new LayerInfo(getClass().getName()); frameErrInfo.setObjectName(parentNode.getName()); frameErrInfo.setDataType("FrameRelay Packet"); frameErrInfo.setLayer("Link"); frameErrInfo.setDescription(ex.toString()); Simulation.addLayerInfo(frameErrInfo); //throw new LowLinkException(ex.toString()); } } } /** * Returns the NetworkInterface's MAC Address. * @author bevan_calliess * @return MACAddress * @version v0.20 */ protected int getClockRate() { return ClockRate; } public boolean isActive(){ return true; } protected final void setClockRate(int ClockRate){ this.ClockRate = ClockRate; } /** * This method displays details about the current interface card * @author bevan_calliess * @return String * @version v0.20 */ protected String getDetails(){ return "Interface: "+name + "\t\tClock Rate: " + ClockRate +"\t\t"+ getConnectLinkDetails(); } } Index: Simulation.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/core/Simulation.java,v retrieving revision 1.16 retrieving revision 1.17 diff -C2 -d -r1.16 -r1.17 *** Simulation.java 14 Oct 2007 22:14:52 -0000 1.16 --- Simulation.java 15 Oct 2007 12:04:32 -0000 1.17 *************** *** 606,610 **** } ! public void addSerialLink(String inLinkName,String inFirstNodeName,String inFirstNodeInterface,String inSecondNodeName,String inSecondNodeInterface) throws InvalidLinkNameException, InvalidLinkConnectionException, InvalidNetworkInterfaceNameException, InvalidNodeNameException { --- 606,610 ---- } ! public void addConsoleLink(String inLinkName,String inFirstNodeName,String inFirstNodeInterface,String inSecondNodeName,String inSecondNodeInterface) throws InvalidLinkNameException, InvalidLinkConnectionException, InvalidNetworkInterfaceNameException, InvalidNodeNameException { *************** *** 629,632 **** --- 629,655 ---- } + public void addSerialLink(String inLinkName,String inFirstNodeName,String inFirstNodeInterface,String inSecondNodeName,String inSecondNodeInterface) + throws InvalidLinkNameException, InvalidLinkConnectionException, InvalidNetworkInterfaceNameException, InvalidNodeNameException { + + if (!linkTable.containsKey(inLinkName)) { + + //test if node's exist within hashtable + if(nodeTable.containsKey(inFirstNodeName) && nodeTable.containsKey(inSecondNodeName)){ + Node tempNode1 = (Node) nodeTable.get(inFirstNodeName); + Node tempNode2 = (Node) nodeTable.get(inSecondNodeName); + + //Return NetworkInterface from Node objects + NetworkInterface interface1 = tempNode1.getNetworkInterface(inFirstNodeInterface); + NetworkInterface interface2 = tempNode2.getNetworkInterface(inSecondNodeInterface); + + //Create link and add it to hashtable + linkTable.put(inLinkName,new SerialLink(inLinkName, interface1, interface2)); + }else{ + throw new InvalidNodeNameException("Invalid node name"); + } + } else + throw new InvalidLinkNameException("Link already exists with same name."); + } + /** * This method checks to see if inLinkName is contained within the has table(linkTable).If so, *************** *** 1174,1182 **** if(tempIP != null) { ! vecInterfaceInfo.add((String)tempNetwork.getIPAddress(strInterfaceName)); } else { ! vecInterfaceInfo.add((String)"IP Address not set"); } vecInterfaceInfo.add((String)tempNetwork.getSubnetMask(strInterfaceName)); --- 1197,1205 ---- if(tempIP != null) { ! vecInterfaceInfo.add((String)tempNetwork.getIPAddress(strInterfaceName)); } else { ! vecInterfaceInfo.add((String)"IP Address not set"); } vecInterfaceInfo.add((String)tempNetwork.getSubnetMask(strInterfaceName)); Index: NetworkLayerDevice.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/core/NetworkLayerDevice.java,v retrieving revision 1.10 retrieving revision 1.11 diff -C2 -d -r1.10 -r1.11 *** NetworkLayerDevice.java 14 Oct 2007 22:14:52 -0000 1.10 --- NetworkLayerDevice.java 15 Oct 2007 12:04:32 -0000 1.11 *************** *** 89,93 **** //TODO This should maybe check the inInterface exists within the Interface hashtable first -luke hamilton public String getSubnetMask(String inInterface) { ! if(((NetworkInterface)(NetworkInterfacetable.get(inInterface))).getType() == NetworkInterface.Ethernet10T){ return NodeProtocolStack.getSubnetMask(inInterface); }else{ --- 89,93 ---- //TODO This should maybe check the inInterface exists within the Interface hashtable first -luke hamilton public String getSubnetMask(String inInterface) { ! if(((NetworkInterface)(NetworkInterfacetable.get(inInterface))).isActive()){ return NodeProtocolStack.getSubnetMask(inInterface); }else{ *************** *** 107,111 **** //TODO This should maybe check the inInterface exists within the Interface hashtable first -luke hamilton public String getIPAddress(String inInterface){ ! if(((NetworkInterface)(NetworkInterfacetable.get(inInterface))).getType() == NetworkInterface.Ethernet10T){ return NodeProtocolStack.getIPAddress(inInterface); }else{ --- 107,111 ---- //TODO This should maybe check the inInterface exists within the Interface hashtable first -luke hamilton public String getIPAddress(String inInterface){ ! if(((NetworkInterface)(NetworkInterfacetable.get(inInterface))).isActive() ){ return NodeProtocolStack.getIPAddress(inInterface); }else{ *************** *** 163,166 **** --- 163,178 ---- } } + + public void sendPacket(Packet inPacket, String inInterfaceKey) throws InvalidNetworkInterfaceNameException, CommunicationException, LowLinkException{ + if (NetworkInterfacetable.containsKey(inInterfaceKey)) + { + NetworkInterface temp = (NetworkInterface)NetworkInterfacetable.get(inInterfaceKey); + temp.sendPacket(inPacket); + } + else + { + throw new InvalidNetworkInterfaceNameException("Inteface does not exist."); + } + } *************** *** 235,242 **** if (NetworkInterfacetable.containsKey(inInterface)) { NodeProtocolStack.setIPAddress(inInterface, inIPAddress); ! EthernetNetworkInterface tempNic = (EthernetNetworkInterface) NetworkInterfacetable.get( inInterface); ! macAddress = tempNic.getMACAddress(); } else { --- 247,256 ---- if (NetworkInterfacetable.containsKey(inInterface)) { NodeProtocolStack.setIPAddress(inInterface, inIPAddress); ! if(NetworkInterfacetable.get(inInterface) instanceof EthernetNetworkInterface){ ! EthernetNetworkInterface tempNic = (EthernetNetworkInterface) NetworkInterfacetable.get( inInterface); ! macAddress = tempNic.getMACAddress(); ! } } else { --- NEW FILE: Serial_packet.java --- /* 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; public class Serial_packet extends Packet { private int ClockRate; public Serial_packet(Packet inPacket, int inClockRate) { Data = inPacket; ClockRate = inClockRate; } public int getClockRate(){ return ClockRate; } public void setClockRate(int inClockRate){ ClockRate = inClockRate; } } --- NEW FILE: SerialLink.java --- /* 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.util.*; /** * SerialLink extends Link. It sets two Interface links to a pc. * @author luke_hamilton * @author bevan_calliess * @since Sep 17, 2004 * @version v0.20 */ public class SerialLink extends Link { public SerialLink(String inName, NetworkInterface inFirstNodeInterface, NetworkInterface inSecondNodeInterface)throws InvalidLinkConnectionException { super(inName); NetworkInterfaces.add(inFirstNodeInterface); NetworkInterfaces.add(inSecondNodeInterface); inFirstNodeInterface.setConnectedLink(this); inSecondNodeInterface.setConnectedLink(this); } public SerialLink(String inName, NetworkInterface inFirstNodeInterface, NetworkInterface inSecondNodeInterface, double sieveCoeff)throws InvalidLinkConnectionException { super(inName); NetworkInterfaces.add(inFirstNodeInterface); NetworkInterfaces.add(inSecondNodeInterface); inFirstNodeInterface.setConnectedLink(this); inSecondNodeInterface.setConnectedLink(this); this.setSC(sieveCoeff); } public void transportPacket(Serial_packet inPacket,String inSourceName) throws LowLinkException { Iterator it = NetworkInterfaces.iterator(); while (it.hasNext()) { NetworkInterface temp = (NetworkInterface) it.next(); if (!temp.getSourceName().equals(inSourceName)) { temp.receivePacket(inPacket); } } } } Index: NetworkInterface.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/core/NetworkInterface.java,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** NetworkInterface.java 14 Oct 2007 17:19:07 -0000 1.6 --- NetworkInterface.java 15 Oct 2007 12:04:32 -0000 1.7 *************** *** 134,137 **** --- 134,138 ---- public final static int Wireless = 2; public final static int WAN = 3; + public final static int Serial = 4; public static String getIntName(int type){ *************** *** 145,148 **** --- 146,151 ---- case 3: return "wan"; + case 4: + return "ser"; default: return "unk"; Index: Router.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/core/Router.java,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** Router.java 14 Oct 2007 17:19:07 -0000 1.4 --- Router.java 15 Oct 2007 12:04:32 -0000 1.5 *************** *** 50,53 **** --- 50,54 ---- addNetworkInterface(NetworkInterface.getIntName(NetworkInterface.Ethernet10T) + "1", NetworkInterface.Ethernet10T, true); addNetworkInterface(NetworkInterface.getIntName(NetworkInterface.Console) + "0", NetworkInterface.Console, false); + addNetworkInterface(NetworkInterface.getIntName(NetworkInterface.Serial) + "0", NetworkInterface.Serial, true); } Index: ApplicationLayerDevice.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/core/ApplicationLayerDevice.java,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** ApplicationLayerDevice.java 14 Oct 2007 22:14:52 -0000 1.3 --- ApplicationLayerDevice.java 15 Oct 2007 12:04:32 -0000 1.4 *************** *** 38,49 **** public void turnOff(){ Enumeration<Application> ap = Apps.elements(); ! // while(ap.hasMoreElements()){ ! // try{ ! // ap.nextElement().Free(); ! // }catch(TransportLayerException e){ ! // e.printStackTrace(); ! // } ! // } ! super.turnOn(); } } --- 38,50 ---- public void turnOff(){ Enumeration<Application> ap = Apps.elements(); ! while(ap.hasMoreElements()){ ! try{ ! ap.nextElement().Free(); ! }catch(TransportLayerException e){ ! e.printStackTrace(); ! ! } ! } ! super.turnOff(); } } |