[Javanetsim-cvs] javaNetSim/core ConsoleLink.java, NONE, 1.1 ConsoleNetworkInterface.java, NONE, 1
Status: Beta
Brought to you by:
darkkey
From: Alexander B. <da...@us...> - 2007-10-14 17:19:13
|
Update of /cvsroot/javanetsim/javaNetSim/core In directory sc8-pr-cvs6.sourceforge.net:/tmp/cvs-serv21615/core Modified Files: NetworkInterface.java Node.java PC.java Packet.java Router.java Simulation.java Added Files: ConsoleLink.java ConsoleNetworkInterface.java WANNetworkInterface.java WANRMI.java WANRMIServer.java WANSocket.java Removed Files: SerialLink.java SerialNetworkInterface.java Log Message: Added WAN interfaces class prototypes... Index: PC.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/core/PC.java,v retrieving revision 1.12 retrieving revision 1.13 diff -C2 -d -r1.12 -r1.13 *** PC.java 13 Oct 2007 12:57:00 -0000 1.12 --- PC.java 14 Oct 2007 17:19:07 -0000 1.13 *************** *** 60,63 **** --- 60,65 ---- import core.protocolsuite.tcp_ip.Telnet_server; import core.protocolsuite.tcp_ip.Telnet_client; + import core.protocolsuite.tcp_ip.DHCPC; + import core.protocolsuite.tcp_ip.DHCPD; import core.protocolsuite.tcp_ip.Echo_tcp; import core.protocolsuite.tcp_ip.PosixTelnetClient; *************** *** 122,125 **** --- 124,130 ---- PosixTelnetClient ptc = new PosixTelnetClient(NodeProtocolStack, core.ProtocolStack.UIDGen++); + + DHCPD dhcpd = new DHCPD(NodeProtocolStack, core.ProtocolStack.UIDGen++); + DHCPC dhcpc = new DHCPC(NodeProtocolStack, core.ProtocolStack.UIDGen++); addApp(echoServer, 7); *************** *** 138,145 **** addApp(snmpAgent, 161); addApp(snmpManager, 30161); addNetworkInterface(NetworkInterface.getIntName(NetworkInterface.Ethernet10T) + "0", NetworkInterface.Ethernet10T, true); ! addNetworkInterface(NetworkInterface.getIntName(NetworkInterface.Serial) + "0", NetworkInterface.Serial, false); ! addNetworkInterface(NetworkInterface.getIntName(NetworkInterface.Wireless) + "0", NetworkInterface.Wireless, true); } --- 143,154 ---- addApp(snmpAgent, 161); addApp(snmpManager, 30161); + + addApp(dhcpd, 67); + addApp(dhcpc, 68); addNetworkInterface(NetworkInterface.getIntName(NetworkInterface.Ethernet10T) + "0", NetworkInterface.Ethernet10T, true); ! 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); } --- NEW FILE: ConsoleLink.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.*; import core.FalseRandom; /** * ConsoleLink 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 ConsoleLink extends Link { /** * Constructor to be used by the Simulation when connecting 2 PC's * We have made a design decision to restrict a Ethernet link to only has 2 ends. * @author bevan_calliess * @author luke_hamilton * @param String Name - Node name eg: PC1 * @param inInterface1 The first Interface to connect this link to eg: eth0 * @param inInterface2 The Seceond Interface to connect this link to eg: eth1 * @throws InvalidLinkConnectionException */ public ConsoleLink(String inName, NetworkInterface inFirstNodeInterface, NetworkInterface inSecondNodeInterface)throws InvalidLinkConnectionException { super(inName); NetworkInterfaces.add(inFirstNodeInterface); NetworkInterfaces.add(inSecondNodeInterface); inFirstNodeInterface.setConnectedLink(this); inSecondNodeInterface.setConnectedLink(this); } } --- SerialNetworkInterface.java DELETED --- Index: Simulation.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/core/Simulation.java,v retrieving revision 1.14 retrieving revision 1.15 diff -C2 -d -r1.14 -r1.15 *** Simulation.java 13 Oct 2007 12:57:00 -0000 1.14 --- Simulation.java 14 Oct 2007 17:19:07 -0000 1.15 *************** *** 610,614 **** //Create link and add it to hashtable ! linkTable.put(inLinkName,new SerialLink(inLinkName, interface1, interface2)); }else{ throw new InvalidNodeNameException("Invalid node name"); --- 610,614 ---- //Create link and add it to hashtable ! linkTable.put(inLinkName,new ConsoleLink(inLinkName, interface1, interface2)); }else{ throw new InvalidNodeNameException("Invalid node name"); --- NEW FILE: WANRMIServer.java --- package core; import java.rmi.*; import java.rmi.server.*; /** * * @author key */ public class WANRMIServer extends UnicastRemoteObject implements WANRMI{ WANNetworkInterface parentInterface; /** Creates a new instance of WANRMIServer */ public WANRMIServer(WANNetworkInterface inParentInterface) throws RemoteException { super(); parentInterface = inParentInterface; } public void recievePacket(Packet inPacket) throws RemoteException{ System.out.println("TEST!!!"); } public void setServiceName(String inService) throws RemoteException{ parentInterface.setConnService(inService); } } --- NEW FILE: WANRMI.java --- (This appears to be a binary file; contents omitted.) --- SerialLink.java DELETED --- --- NEW FILE: ConsoleNetworkInterface.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.*; /** * 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. This particular Network Interface * is modelled on an Ethernet Interface Card. * * <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 * @author Bevan Calliess * @since 19 September 2004 * @version v0.20 */ class ConsoleNetworkInterface extends NetworkInterface{ /** * Constructs a NetworkInterface object with the name inName and a * reference to it's parent Node. * @author bevan_calliess * @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.20 */ protected ConsoleNetworkInterface(String inName, Node parent) { super(inName,parent); } protected void receivePacket(Packet inPacket) throws LowLinkException { } public int getType(){ return NetworkInterface.Console; } protected void sendPacket(Packet inPacket) throws LowLinkException { } public boolean isActive(){ return false; } /** * This method displays details about the current interface card * @author bevan_calliess * @return String * @version v0.20 */ protected String getDetails(){ return "Interface: "+name + "\t\t" + "\t\t"+ getConnectLinkDetails(); } } --- NEW FILE: WANSocket.java --- (This appears to be a binary file; contents omitted.) Index: Router.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/core/Router.java,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** Router.java 13 Oct 2007 12:57:00 -0000 1.3 --- Router.java 14 Oct 2007 17:19:07 -0000 1.4 *************** *** 49,53 **** addNetworkInterface(NetworkInterface.getIntName(NetworkInterface.Ethernet10T) + "0", NetworkInterface.Ethernet10T, true); addNetworkInterface(NetworkInterface.getIntName(NetworkInterface.Ethernet10T) + "1", NetworkInterface.Ethernet10T, true); ! addNetworkInterface(NetworkInterface.getIntName(NetworkInterface.Serial) + "0", NetworkInterface.Serial, false); } --- 49,53 ---- addNetworkInterface(NetworkInterface.getIntName(NetworkInterface.Ethernet10T) + "0", NetworkInterface.Ethernet10T, true); addNetworkInterface(NetworkInterface.getIntName(NetworkInterface.Ethernet10T) + "1", NetworkInterface.Ethernet10T, true); ! addNetworkInterface(NetworkInterface.getIntName(NetworkInterface.Console) + "0", NetworkInterface.Console, false); } Index: Node.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/core/Node.java,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** Node.java 13 Oct 2007 12:57:00 -0000 1.9 --- Node.java 14 Oct 2007 17:19:07 -0000 1.10 *************** *** 287,293 **** } break; ! case NetworkInterface.Serial: ! NetworkInterfacetable.put(interfaceName,new SerialNetworkInterface(interfaceName,this)); break; } } --- 287,297 ---- } break; ! case NetworkInterface.Console: ! NetworkInterfacetable.put(interfaceName,new ConsoleNetworkInterface(interfaceName,this)); break; + case NetworkInterface.WAN: + NetworkInterfacetable.put(interfaceName,new WANNetworkInterface(interfaceName,this)); + break; + } } *************** *** 508,513 **** case NetworkInterface.Ethernet10T: return "Ethernet"; ! case NetworkInterface.Serial: ! return "Serial"; case NetworkInterface.Wireless: return "Wireless"; --- 512,517 ---- case NetworkInterface.Ethernet10T: return "Ethernet"; ! case NetworkInterface.Console: ! return "Console"; case NetworkInterface.Wireless: return "Wireless"; *************** *** 522,525 **** --- 526,538 ---- } + public NetworkInterface getNIC(String inInterfaceName)throws InvalidNetworkInterfaceNameException{ + if(NetworkInterfacetable.containsKey(inInterfaceName)){ + return (NetworkInterface)NetworkInterfacetable.get(inInterfaceName); + }else{ + throw new InvalidNetworkInterfaceNameException("'"+ inInterfaceName + "' on node '"+ name +"' is an invalid Network Interface name"); + } + } + + /* public void setMACAddress(String inInterfaceName, String MAC)throws InvalidNetworkInterfaceNameException, SimulationException{ *************** *** 639,649 **** Enumeration keys = NetworkInterfacetable.keys(); ! if(keys.hasMoreElements()) { String strInterfaceName = (String) keys.nextElement(); ! ! return strInterfaceName; } ! else return null; } --- 652,665 ---- Enumeration keys = NetworkInterfacetable.keys(); ! while(keys.hasMoreElements()) { String strInterfaceName = (String) keys.nextElement(); ! ! if(((NetworkInterface)NetworkInterfacetable.get(strInterfaceName)).isActive()){ ! return strInterfaceName; ! } } ! ! return null; } Index: NetworkInterface.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/core/NetworkInterface.java,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** NetworkInterface.java 13 Oct 2007 12:57:00 -0000 1.5 --- NetworkInterface.java 14 Oct 2007 17:19:07 -0000 1.6 *************** *** 112,120 **** protected Node parentNode; public final static int Unknown = 0; public final static int Ethernet10T = 0; ! public final static int Serial = 1; public final static int Wireless = 2; public static String getIntName(int type){ --- 112,137 ---- protected Node parentNode; + + protected boolean up; + + public void UP(){ + up = true; + } + + public void DOWN(){ + up = false; + } + + public boolean isUP(){ + return up; + } + + public final static int Unknown = 0; public final static int Ethernet10T = 0; ! public final static int Console = 1; public final static int Wireless = 2; + public final static int WAN = 3; public static String getIntName(int type){ *************** *** 125,129 **** return "cua"; case 2: ! return "wifi"; default: return "unk"; --- 142,148 ---- return "cua"; case 2: ! return "wrl"; ! case 3: ! return "wan"; default: return "unk"; *************** *** 158,162 **** name = inName; ! parentNode = inParent; } --- 177,183 ---- name = inName; ! parentNode = inParent; ! ! up = true; } --- NEW FILE: WANNetworkInterface.java --- /* Java Network Simulator (javaNetSim) Copyright (c) 2007, 2006, 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 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.rmi.*; import java.rmi.Naming; public class WANNetworkInterface extends NetworkInterface{ public final static int NotSet = 0; public final static int SocketTCP = 1; public final static int SocketUDP = 2; public final static int RMI = 3; public final static int Corba = 4; protected int type; protected boolean server; // for socket connections protected String Host; protected int port; protected String Service; protected boolean connected; protected WANRMIServer RMIServer; protected WANRMI RMIClient; protected WANSocket s; public void setServer(boolean inServer){ server = inServer; } public boolean getServer(){ return server; } public int getConnType(){ return type; } public void setConnType(int inType){ type = inType; } public int getConnPort(){ return port; } public void setConnPort(int inPort){ port = inPort; } public String getConnHost(){ return Host; } public void setConnHost(String inHost){ Host = inHost; } public String getConnService(){ return Service; } public void setConnService(String inService){ Service = inService; } public void UP(){ up = listen(); up &= connect(); } public void DOWN(){ close(); up = false; } public WANNetworkInterface(String inName, Node parent) { super(inName, parent); type = 0; connected = false; Service = ""; Host = ""; if (System.getSecurityManager() == null) System.setSecurityManager ( new RMISecurityManager() ); //temp debug values Host = "127.0.0.1"; port = 18008; type = this.SocketTCP; server = true; } protected void receivePacket(Packet inPacket) throws LowLinkException { // cast the packet to an EthernetPacket //Ethernet_packet tempPacket = (Ethernet_packet)inPacket; switch(type){ case RMI: { if(!connected){ connect(); } } break; case SocketTCP: case SocketUDP: //Nothing to do... break; } parentNode.receivePacket(inPacket, name); } public int getType(){ return NetworkInterface.WAN; } protected void sendPacket(Packet inPacket) throws LowLinkException { if(!connected){ connect(); } if(connected){ try{ switch(type){ case RMI: RMIServer.recievePacket(inPacket); break; case SocketTCP: case SocketUDP: s.sendPacket(inPacket); break; } }catch(Exception e){ e.printStackTrace(); } } } protected void sendPacket(Packet inPacket, String inMacAddress) throws CommunicationException, LowLinkException { sendPacket(inPacket); } public boolean isActive(){ return true; } protected String getDetails(){ return "Interface: "+name; } protected boolean listen(){ try{ switch(type){ case RMI: { RMIServer = new WANRMIServer(this); Naming.bind (name, RMIServer); return true; } case SocketTCP: case SocketUDP: if(server){ s = new WANSocket(this, Host, port, server); return s.listen(); }else{ return false; } } }catch(Exception e){ e.printStackTrace(); } return false; } protected boolean connect(){ try{ switch(type){ case RMI: { if(Host == "" || Service == ""){ //Error return false; } RMIClient = null; RMIClient = (WANRMI) Naming.lookup ("rmi://" + Host + "/" + Service); RMIClient.setServiceName(name); connected = true; return true; } case SocketTCP: if(!server){ s = new WANSocket(this, Host, port, server); return s.connect(); }else{ return false; } case SocketUDP: //nothing to do... break; } }catch(Exception e){ e.printStackTrace(); } return false; } protected void close(){ try{ connected = false; switch(type){ case RMI: RMIClient = null; Naming.unbind(name); RMIServer = null; break; case SocketTCP: case SocketUDP: s.Close(); s = null; break; } }catch(Exception e){ e.printStackTrace(); } } } Index: Packet.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/core/Packet.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** Packet.java 20 Nov 2005 20:30:53 -0000 1.2 --- Packet.java 14 Oct 2007 17:19:07 -0000 1.3 *************** *** 48,52 **** protected int hopCount=0; ! /** * Gets the data with the table --- 48,59 ---- protected int hopCount=0; ! public String toBytes(){ ! return RawtoBytes(); ! } ! ! public String RawtoBytes(){ ! return "P|" + (int)UniqueIdentfier + "|" + hopCount + "#"; ! } ! /** * Gets the data with the table |