[Javanetsim-cvs] javaNetSim/core Switch.java, 1.2, 1.3 Version.java, 1.5, 1.6
Status: Beta
Brought to you by:
darkkey
From: Alexander B. <da...@us...> - 2006-10-12 17:26:29
|
Update of /cvsroot/javanetsim/javaNetSim/core In directory sc8-pr-cvs6.sourceforge.net:/tmp/cvs-serv11183/core Modified Files: Switch.java Version.java Log Message: Index: Switch.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/core/Switch.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** Switch.java 20 Nov 2005 20:30:53 -0000 1.2 --- Switch.java 12 Oct 2006 17:26:26 -0000 1.3 *************** *** 1,6 **** /* ! 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 --- 1,7 ---- /* ! Java Network Simulator (jNetSim) ! Copyright (c) 2005, Ice Team; All rights reserved. ! Copyright (c) 2004, jFirewallSim development team; All rights reserved. Redistribution and use in source and binary forms, with or without modification, are *************** *** 12,16 **** 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. --- 13,17 ---- 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. *************** *** 26,59 **** EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ - package core; ! /** ! * This clas holds a List of calls to the addNetworkInterface method ! * within Node.java ! * @author luke_hamilton ! * @since Oct 9, 2004 ! * @version v0.20 ! */ public class Switch extends DataLinkLayerDevice { /** ! * This method creates a switch with eight Network Interfaces * @author luke_hamilton ! * @param inName - The name of the Node eg: Switch1 * @param inProtocolStackLayers * @version v0.20 */ ! public Switch(String inName) { ! super(inName, 2); //pass name and protocolstack layer addNetworkInterface("eth0"); addNetworkInterface("eth1"); addNetworkInterface("eth2"); ! addNetworkInterface("eth3"); ! addNetworkInterface("eth4"); ! addNetworkInterface("eth5"); ! addNetworkInterface("eth6"); ! addNetworkInterface("eth7"); } ! }//EOF --- 27,186 ---- EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ package core; ! import java.util.*; ! ! /** ! * This class extends of the DataLinkLayerDevice and allows the ! * creation of switches ! * @author bevan_calliess ! * @author luke_hamilton ! * @author Key ! * @since Nov 8, 2005 ! * @version v0.22 ! **/ ! public class Switch extends DataLinkLayerDevice { /** ! * This creates a layer 2 switch with a default of 5 interface (ports) * @author luke_hamilton ! * @param inName The name of the Switch * @param inProtocolStackLayers * @version v0.20 */ ! ! int sz = 0; ! ! int buffSize = 255; ! ! Hashtable IntCaches; ! ! public Switch(String inName) { ! super(inName, 1); //pass name and protocolstack layer ! ! IntCaches = new Hashtable(); ! addNetworkInterface("eth0"); + Hashtable iceth0 = new Hashtable(); + IntCaches.put("eth0", iceth0); + addNetworkInterface("eth1"); + Hashtable iceth1 = new Hashtable(); + IntCaches.put("eth1", iceth1); + addNetworkInterface("eth2"); ! Hashtable iceth2 = new Hashtable(); ! IntCaches.put("eth2", iceth2); ! ! addNetworkInterface("eth3"); ! Hashtable iceth3 = new Hashtable(); ! IntCaches.put("eth3", iceth3); ! ! addNetworkInterface("eth4"); ! Hashtable iceth4 = new Hashtable(); ! IntCaches.put("eth4", iceth4); } ! ! public void Reset(){ ! sz = 0; ! } ! ! public int getState(){ ! return sz; ! } ! ! public String getSwitchCache(){ ! Enumeration it, it2; ! String nic = ""; ! String result = ""; ! ! it = NetworkInterfacetable.elements(); ! ! while(it.hasMoreElements()){ ! NetworkInterface tempInterface = (NetworkInterface)it.nextElement(); ! nic = tempInterface.getName(); ! Hashtable outInt = (Hashtable) IntCaches.get(nic); ! ! result = result + nic + ": "; ! ! it2 = outInt.keys(); ! ! while(it2.hasMoreElements()){ ! String mac = (String)it2.nextElement(); ! result = result + mac + "\t"; ! } ! ! result = result + "\n"; ! } ! ! return result; ! } ! ! /** ! * This method will recieve a packet from any of the connected links and the copy ! * the Packet and distribute a copy to each of the other connected links. ! * @author bevan_calliess ! * @param inPacket - The packet to be transported ! * @param inLinkName - The name of the link that sent the packet eg: eth0 ! */ ! ! protected void receivePacket(Packet inPacket,String inInterfaceName) throws LowLinkException{ ! if(sz!=1){ ! Ethernet_packet tempPacket = (Ethernet_packet)inPacket; ! Enumeration it; ! boolean intFound = false; ! String nic = ""; ! ! try{ ! Hashtable inInt = (Hashtable) IntCaches.get(inInterfaceName); ! inInt.put(tempPacket.getSourceMACAddress(), "1"); ! Ethernet_packet copyPacket = new Ethernet_packet(tempPacket.getData(), tempPacket.getDestinationMACAddress(),tempPacket.getSourceMACAddress()); ! ! it = NetworkInterfacetable.elements(); ! while(it.hasMoreElements()){ ! NetworkInterface tempInterface = (NetworkInterface)it.nextElement(); ! nic = tempInterface.getName(); ! Hashtable outInt = (Hashtable) IntCaches.get(nic); ! if(outInt.get(tempPacket.getDestinationMACAddress()) != null){ ! intFound = true; ! try{ ! tempInterface.sendPacket(copyPacket); ! System.out.println("\n\n" + getSwitchCache() + "\n\n"); ! }catch(NullPointerException e){ ! System.out.println("Switch.java: " + e.toString()); ! } ! } ! } ! ! it = NetworkInterfacetable.elements(); ! while(it.hasMoreElements() && !intFound){ ! //Test to see if the current Interface is the Interface that sent in the packet ! // if it is skip that interface ! NetworkInterface tempInterface = (NetworkInterface)it.nextElement(); ! if(!tempInterface.getName().equals(inInterfaceName)){ ! ! try{ ! tempInterface.sendPacket(copyPacket); ! System.out.println("\n\n" + getSwitchCache() + "\n\n"); ! }catch(NullPointerException e){ ! System.out.println("Switch.java: " + e.toString()); ! } ! } ! ! } ! ! }catch(Throwable th) ! { ! if(th.toString().contains("Packet lost due to physical link problems!")){ ! throw new LowLinkException(th.toString()); ! }else{ ! sz=1; ! System.out.println(th.toString()); ! throw new LowLinkException("Switch buffer overflow (packet loop flood?)."); ! } ! } ! } ! } ! } Index: Version.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/core/Version.java,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** Version.java 12 Oct 2006 16:14:14 -0000 1.5 --- Version.java 12 Oct 2006 17:26:26 -0000 1.6 *************** *** 40,44 **** public class Version { public final static String CORE_VERSION = "v0.32"; //version of the simulation core ! public static final String TEAM_MEMBERS[] = { "http://sf.net/projects/javanetsim","release date: 25 Sep 2006", "", --- 40,45 ---- public class Version { public final static String CORE_VERSION = "v0.32"; //version of the simulation core ! public final static String YEARS = "2005 - 2006"; ! public static final String TEAM_MEMBERS[] = { "http://sf.net/projects/javanetsim","release date: 25 Sep 2006", "", |