[Javanetsim-cvs] javaNetSim/core CSUDSU.java, NONE, 1.1 NetworkInterface.java, 1.7, 1.8 Packet.java
Status: Beta
Brought to you by:
darkkey
Update of /cvsroot/javanetsim/javaNetSim/core In directory sc8-pr-cvs6.sourceforge.net:/tmp/cvs-serv24241/core Modified Files: NetworkInterface.java Packet.java Simulation.java Version.java WANNetworkInterface.java WANSocket.java Added Files: CSUDSU.java Log Message: CSU/DSU Unit added; new graphics; wan interface TCP external connection... --- NEW FILE: CSUDSU.java --- /* Java Network Simulator (jNetSim) 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 Ice Team nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ package core; import java.util.*; public class CSUDSU extends DataLinkLayerDevice { String lanPort; String wanPort; int sz = 0; public CSUDSU(String inName) { super(inName, 1); //pass name and protocolstack layer lanPort = "ser0"; wanPort = "wan0" + "_" + (int)(Math.random()*1000); addNetworkInterface(lanPort, NetworkInterface.Serial, false); addNetworkInterface(wanPort, NetworkInterface.WAN, false); } public void Reset(){ super.Reset(); } public void turnOn() { super.turnOn(); } public void turnOff() { super.turnOff(); } public int getState(){ return sz; } protected void receivePacket(Packet inPacket,String inInterfaceName) throws LowLinkException{ if(sz!=1){ if(inInterfaceName == lanPort){ NetworkInterface tempInterface = (NetworkInterface)this.NetworkInterfacetable.get(wanPort); tempInterface.sendPacket(inPacket); }else{ SerialNetworkInterface tempInterface = (SerialNetworkInterface)this.NetworkInterfacetable.get(lanPort); tempInterface.sendPacket(inPacket); } } } } Index: Simulation.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/core/Simulation.java,v retrieving revision 1.17 retrieving revision 1.18 diff -C2 -d -r1.17 -r1.18 *** Simulation.java 15 Oct 2007 12:04:32 -0000 1.17 --- Simulation.java 15 Oct 2007 18:25:54 -0000 1.18 *************** *** 1018,1021 **** --- 1018,1029 ---- } } + + public void addCSUDSU(String inNodeName) throws InvalidNodeNameException { + if (!nodeTable.containsKey(inNodeName)) { + nodeTable.put(inNodeName, new CSUDSU(inNodeName)); + } else { + throw new InvalidNodeNameException("Node already exists with same name"); + } + } /** * This method will check to see if the switch name is contained within the Index: NetworkInterface.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/core/NetworkInterface.java,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** NetworkInterface.java 15 Oct 2007 12:04:32 -0000 1.7 --- NetworkInterface.java 15 Oct 2007 18:25:54 -0000 1.8 *************** *** 117,124 **** --- 117,136 ---- public void UP(){ up = true; + LayerInfo pingInfo = new LayerInfo(getClass().getName()); + pingInfo.setObjectName(parentNode.getName()); + pingInfo.setDataType("Interface"); + pingInfo.setLayer("Link"); + pingInfo.setDescription("Interface " + name + " state set to up!"); + Simulation.addLayerInfo(pingInfo); } public void DOWN(){ up = false; + LayerInfo pingInfo = new LayerInfo(getClass().getName()); + pingInfo.setObjectName(parentNode.getName()); + pingInfo.setDataType("Interface"); + pingInfo.setLayer("Link"); + pingInfo.setDescription("Interface " + name + " state set to down!"); + Simulation.addLayerInfo(pingInfo); } Index: WANSocket.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/core/WANSocket.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** WANSocket.java 14 Oct 2007 17:19:07 -0000 1.1 --- WANSocket.java 15 Oct 2007 18:25:54 -0000 1.2 *************** *** 11,15 **** import java.io.*; import java.net.*; ! /** * --- 11,18 ---- import java.io.*; import java.net.*; ! import core.protocolsuite.tcp_ip.IP_packet; ! import core.protocolsuite.tcp_ip.ICMP_packet; ! import core.protocolsuite.tcp_ip.UDP_packet; ! import core.protocolsuite.tcp_ip.TCP_packet; /** * *************** *** 47,56 **** try{ if(server){ s = new ServerSocket(port); ! ih = new IncomeConnectionHandler(s, this); ih.start(); return true; } ! }catch(Exception e) {} return false; } --- 50,62 ---- try{ if(server){ + parentInterface.addLayerInfo("Wan interface", "Starting listening for peer..."); s = new ServerSocket(port); ! ih = new IncomeConnectionHandler(s, this, parentInterface); ih.start(); return true; } ! }catch(Exception e) { ! parentInterface.addLayerInfo("Wan interface", "Listen error: " + e.toString()); ! } return false; } *************** *** 59,68 **** try{ if(!server){ c = new Socket(Hostname, port); ! ch = new ClientConnectionHandler(c, this); ch.start(); return true; } ! }catch(Exception e){} return false; } --- 65,77 ---- try{ if(!server){ + parentInterface.addLayerInfo("Wan interface", "Starting connecting to peer..."); c = new Socket(Hostname, port); ! ch = new ClientConnectionHandler(c, this, parentInterface); ch.start(); return true; } ! }catch(Exception e){ ! parentInterface.addLayerInfo("Wan interface", "Connection error: " + e.toString()); ! } return false; } *************** *** 88,92 **** } ! public void recievePacket(String inPacket){ } --- 97,128 ---- } ! public void recievePacket(String inPacket) throws LowLinkException{ ! System.out.println(inPacket); ! ! String[] packets = inPacket.split("#"); ! ! char ptype = packets[packets.length - 1].charAt(0); ! ! System.out.println(ptype); ! ! switch(ptype){ ! case 'M': ! ICMP_packet icmp = new ICMP_packet(""); ! icmp.fromBytes(inPacket); ! parentInterface.receivePacket(icmp); ! break; ! case 'I': ! IP_packet ip = new IP_packet(""); ! ip.fromBytes(inPacket); ! parentInterface.receivePacket(ip); ! break; ! case 'T': ! break; ! case 'U': ! UDP_packet udp = new UDP_packet("","",0,0); ! udp.fromBytes(inPacket); ! parentInterface.receivePacket(udp); ! break; ! } } *************** *** 103,106 **** --- 139,143 ---- Node node; WANSocket w; + WANNetworkInterface parentInterface; private InputStream in; *************** *** 108,115 **** ! IncomeConnectionHandler(ServerSocket s, WANSocket w) { this.s = s; this.node = node; this.w = w; } --- 145,153 ---- ! IncomeConnectionHandler(ServerSocket s, WANSocket w, WANNetworkInterface parentInterface) { this.s = s; this.node = node; this.w = w; + this.parentInterface = parentInterface; } *************** *** 117,120 **** --- 155,160 ---- try{ Socket incoming = s.accept(); + parentInterface.addLayerInfo("Wan interface", "Accepted connection from peer."); + parentInterface.connected = true; w.setClientSocket(incoming, new PrintWriter(new OutputStreamWriter(incoming.getOutputStream()))); BufferedReader in = new BufferedReader( new InputStreamReader(incoming.getInputStream())); *************** *** 132,135 **** --- 172,176 ---- w.setClientSocket(null, null); }catch(Exception e){ + parentInterface.addLayerInfo("Wan interface", "Error during communication: " + e.toString()); e.printStackTrace(); } *************** *** 144,157 **** private InputStream in; private BufferedReader reader; ! ClientConnectionHandler(Socket s, WANSocket w) { this.s = s; this.node = node; this.w = w; } public void run() { try{ w.setClientSocket(s, new PrintWriter(new OutputStreamWriter(s.getOutputStream()))); BufferedReader in = new BufferedReader( new InputStreamReader(s.getInputStream())); --- 185,202 ---- private InputStream in; private BufferedReader reader; + + WANNetworkInterface parentInterface; ! ClientConnectionHandler(Socket s, WANSocket w, WANNetworkInterface parentInterface) { this.s = s; this.node = node; this.w = w; + this.parentInterface = parentInterface; } public void run() { try{ + parentInterface.addLayerInfo("Wan interface", "Connected to peer."); w.setClientSocket(s, new PrintWriter(new OutputStreamWriter(s.getOutputStream()))); BufferedReader in = new BufferedReader( new InputStreamReader(s.getInputStream())); *************** *** 169,172 **** --- 214,218 ---- w.setClientSocket(null, null); }catch(Exception e){ + parentInterface.addLayerInfo("Wan interface", "Error during communication: " + e.toString()); e.printStackTrace(); } Index: Version.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/core/Version.java,v retrieving revision 1.13 retrieving revision 1.14 diff -C2 -d -r1.13 -r1.14 *** Version.java 1 Oct 2007 04:58:11 -0000 1.13 --- Version.java 15 Oct 2007 18:25:54 -0000 1.14 *************** *** 40,48 **** */ public class Version { ! public final static String CORE_VERSION = "v0.34"; //version of the simulation core public final static String YEARS = "2005 - 2007"; public static final String TEAM_MEMBERS[] = { ! "http://sf.net/projects/javanetsim","release date: 01 Oct 2007", "", "fork of jFirewallSim project (http://sf.net/projects/jfirewallsim/)", "from 03 Nov 2005","", --- 40,48 ---- */ public class Version { ! public final static String CORE_VERSION = "v0.38"; //version of the simulation core public final static String YEARS = "2005 - 2007"; public static final String TEAM_MEMBERS[] = { ! "http://sf.net/projects/javanetsim","release date: 03 Nov 2007", "", "fork of jFirewallSim project (http://sf.net/projects/jfirewallsim/)", "from 03 Nov 2005","", Index: WANNetworkInterface.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/core/WANNetworkInterface.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** WANNetworkInterface.java 14 Oct 2007 17:19:07 -0000 1.1 --- WANNetworkInterface.java 15 Oct 2007 18:25:54 -0000 1.2 *************** *** 96,99 **** --- 96,100 ---- public void UP(){ + super.UP(); up = listen(); up &= connect(); *************** *** 101,106 **** public void DOWN(){ ! close(); ! up = false; } --- 102,107 ---- public void DOWN(){ ! super.DOWN(); ! close(); } *************** *** 138,141 **** --- 139,144 ---- } + addLayerInfo("WAN Packet","Recieved and accepted packet at interface " + name); + parentNode.receivePacket(inPacket, name); } *************** *** 150,153 **** --- 153,158 ---- } + addLayerInfo("WAN Packet", "Sending packet from interface "+ name); + if(connected){ try{ *************** *** 162,165 **** --- 167,171 ---- } }catch(Exception e){ + addLayerInfo("WAN Connection", "Error: " + e.toString()); e.printStackTrace(); } *************** *** 171,174 **** --- 177,188 ---- } + public void addLayerInfo(String DataType, String Msg){ + LayerInfo pingInfo = new LayerInfo(getClass().getName()); + pingInfo.setObjectName(parentNode.getName()); + pingInfo.setDataType(DataType); + pingInfo.setLayer("Link"); + pingInfo.setDescription(Msg); + Simulation.addLayerInfo(pingInfo); + } public boolean isActive(){ *************** *** 181,185 **** } ! protected boolean listen(){ try{ switch(type){ --- 195,199 ---- } ! protected boolean listen(){ try{ switch(type){ *************** *** 228,232 **** if(!server){ s = new WANSocket(this, Host, port, server); ! return s.connect(); }else{ return false; --- 242,247 ---- if(!server){ s = new WANSocket(this, Host, port, server); ! connected = s.connect(); ! return connected; }else{ return false; Index: Packet.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/core/Packet.java,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** Packet.java 14 Oct 2007 17:19:07 -0000 1.3 --- Packet.java 15 Oct 2007 18:25:54 -0000 1.4 *************** *** 52,57 **** } public String RawtoBytes(){ ! return "P|" + (int)UniqueIdentfier + "|" + hopCount + "#"; } --- 52,70 ---- } + public void fromBytes(String str){ + RawfromBytes(str); + } + public String RawtoBytes(){ ! return "P|" + (int)UniqueIdentfier + "|" + hopCount + "|#"; ! } ! ! public void RawfromBytes(String str){ ! String[] fields = str.split("\\|"); ! ! UniqueIdentfier = Integer.valueOf(fields[1]); ! hopCount = Integer.valueOf(fields[2]); ! ! System.out.println(UniqueIdentfier + " " + hopCount); } |