[Javanetsim-cvs] javaNetSim/core AccessListEngine.java, NONE, 1.1 FiberEthernetLink.java, NONE, 1.
Status: Beta
Brought to you by:
darkkey
From: Alexander B. <da...@us...> - 2007-10-19 15:57:10
|
Update of /cvsroot/javanetsim/javaNetSim/core In directory sc8-pr-cvs6.sourceforge.net:/tmp/cvs-serv22802/core Modified Files: NetworkInterface.java Node.java Router.java Simulation.java Switch.java Added Files: AccessListEngine.java FiberEthernetLink.java FiberEthernetNetworkInterface.java FiberNetworkInterfacePort.java Log Message: New link type -- FX, Fiber Ethernet. Small changes in interface properties dialogs; added serial network interface properties dialog. Index: Node.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/core/Node.java,v retrieving revision 1.15 retrieving revision 1.16 diff -C2 -d -r1.15 -r1.16 *** Node.java 19 Oct 2007 08:52:26 -0000 1.15 --- Node.java 19 Oct 2007 15:57:00 -0000 1.16 *************** *** 280,283 **** --- 280,290 ---- } break; + case NetworkInterface.Ethernet100FX: + if(active){ + NetworkInterfacetable.put(interfaceName,new FiberEthernetNetworkInterface(interfaceName,this)); + }else{ + NetworkInterfacetable.put(interfaceName,new FiberNetworkInterfacePort(interfaceName,this)); + } + break; case NetworkInterface.Console: NetworkInterfacetable.put(interfaceName,new ConsoleNetworkInterface(interfaceName,this)); *************** *** 467,471 **** //"Not Applicable" ! if(((NetworkInterface)(NetworkInterfacetable.get(inInterfaceName))).getType() == NetworkInterface.Ethernet10T){ EthernetNetworkInterface temp =(EthernetNetworkInterface)NetworkInterfacetable.get(inInterfaceName); return temp.getMACAddress(); --- 474,479 ---- //"Not Applicable" ! if(((NetworkInterface)(NetworkInterfacetable.get(inInterfaceName))).getType() == NetworkInterface.Ethernet10T || ! ((NetworkInterface)(NetworkInterfacetable.get(inInterfaceName))).getType() == NetworkInterface.Ethernet100FX){ EthernetNetworkInterface temp =(EthernetNetworkInterface)NetworkInterfacetable.get(inInterfaceName); return temp.getMACAddress(); *************** *** 518,526 **** switch(temp.getType()){ case NetworkInterface.Ethernet10T: ! return "Ethernet"; case NetworkInterface.Console: return "Console"; case NetworkInterface.Wireless: return "Wireless"; default: return "Unknown"; --- 526,538 ---- switch(temp.getType()){ case NetworkInterface.Ethernet10T: ! return "Copper Ethernet"; case NetworkInterface.Console: return "Console"; case NetworkInterface.Wireless: return "Wireless"; + case NetworkInterface.Ethernet100FX: + return "Fiber Ethernet"; + case NetworkInterface.Serial: + return "Serial"; default: return "Unknown"; Index: Simulation.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/core/Simulation.java,v retrieving revision 1.21 retrieving revision 1.22 diff -C2 -d -r1.21 -r1.22 *** Simulation.java 19 Oct 2007 08:52:26 -0000 1.21 --- Simulation.java 19 Oct 2007 15:57:00 -0000 1.22 *************** *** 696,700 **** //Create link and add it to hashtable ! linkTable.put(inLinkName,new EthernetLink(inLinkName, interface1, interface2, Double.valueOf(sieveCoeff).doubleValue())); }else{ throw new InvalidNodeNameException("Invalid node name"); --- 696,704 ---- //Create link and add it to hashtable ! if(interface1 instanceof FiberEthernetNetworkInterface){ ! linkTable.put(inLinkName,new FiberEthernetLink(inLinkName, interface1, interface2, Double.valueOf(sieveCoeff).doubleValue())); ! }else{ ! linkTable.put(inLinkName,new EthernetLink(inLinkName, interface1, interface2, Double.valueOf(sieveCoeff).doubleValue())); ! } }else{ throw new InvalidNodeNameException("Invalid node name"); *************** *** 719,723 **** //Create link and add it to hashtable ! linkTable.put(inLinkName,new EthernetLink(inLinkName, interface1, interface2)); }else{ throw new InvalidNodeNameException("Invalid node name"); --- 723,731 ---- //Create link and add it to hashtable ! if(interface1 instanceof FiberEthernetNetworkInterface){ ! linkTable.put(inLinkName,new FiberEthernetLink(inLinkName, interface1, interface2)); ! }else{ ! linkTable.put(inLinkName,new EthernetLink(inLinkName, interface1, interface2)); ! } }else{ throw new InvalidNodeNameException("Invalid node name"); *************** *** 1050,1056 **** * @version v0.20 **/ ! public void addSwitch(String inNodeName, boolean inOn) throws InvalidNodeNameException { if(!nodeTable.containsKey(inNodeName)){ ! nodeTable.put(inNodeName, new Switch(inNodeName, inOn)); }else{ throw new InvalidNodeNameException("Node already exists with same name"); --- 1058,1064 ---- * @version v0.20 **/ ! public void addSwitch(String inNodeName, boolean inOn, int c, int p) throws InvalidNodeNameException { if(!nodeTable.containsKey(inNodeName)){ ! nodeTable.put(inNodeName, new Switch(inNodeName, inOn, c, p)); }else{ throw new InvalidNodeNameException("Node already exists with same name"); Index: NetworkInterface.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/core/NetworkInterface.java,v retrieving revision 1.10 retrieving revision 1.11 diff -C2 -d -r1.10 -r1.11 *** NetworkInterface.java 19 Oct 2007 08:52:26 -0000 1.10 --- NetworkInterface.java 19 Oct 2007 15:57:00 -0000 1.11 *************** *** 162,165 **** --- 162,166 ---- public final static int WAN = 3; public final static int Serial = 4; + public final static int Ethernet100FX = 5; public static String getIntName(int type){ *************** *** 175,178 **** --- 176,181 ---- case 4: return "ser"; + case 5: + return "fib"; default: return "unk"; Index: Router.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/core/Router.java,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** Router.java 19 Oct 2007 08:52:26 -0000 1.6 --- Router.java 19 Oct 2007 15:57:00 -0000 1.7 *************** *** 51,54 **** --- 51,55 ---- addNetworkInterface(NetworkInterface.getIntName(NetworkInterface.Console) + "0", NetworkInterface.Console, false); addNetworkInterface(NetworkInterface.getIntName(NetworkInterface.Serial) + "0", NetworkInterface.Serial, true); + addNetworkInterface(NetworkInterface.getIntName(NetworkInterface.Ethernet100FX) + "0", NetworkInterface.Ethernet100FX, true); } Index: Switch.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/core/Switch.java,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** Switch.java 19 Oct 2007 08:52:26 -0000 1.7 --- Switch.java 19 Oct 2007 15:57:01 -0000 1.8 *************** *** 55,61 **** Hashtable IntCaches; ! public Switch(String inName, boolean inOn) { super(inName, 1, inOn); //pass name and protocolstack layer --- 55,64 ---- Hashtable IntCaches; + + public int Copper_ports; + public int Fiber_ports; ! public Switch(String inName, boolean inOn, int cports, int fports) { super(inName, 1, inOn); //pass name and protocolstack layer *************** *** 63,98 **** String name = NetworkInterface.getIntName(NetworkInterface.Ethernet10T); ! addNetworkInterface(name + "0", NetworkInterface.Ethernet10T, false); ! Hashtable iceth0 = new Hashtable(); ! IntCaches.put(name, iceth0); ! ! addNetworkInterface(name + "1", NetworkInterface.Ethernet10T, false); ! Hashtable iceth1 = new Hashtable(); ! IntCaches.put(name + "1", iceth1); ! ! addNetworkInterface(name + "2", NetworkInterface.Ethernet10T, false); ! Hashtable iceth2 = new Hashtable(); ! IntCaches.put(name + "2", iceth2); ! ! addNetworkInterface(name + "3", NetworkInterface.Ethernet10T, false); ! Hashtable iceth3 = new Hashtable(); ! IntCaches.put(name + "3", iceth3); ! ! addNetworkInterface(name + "4", NetworkInterface.Ethernet10T, false); ! Hashtable iceth4 = new Hashtable(); ! IntCaches.put(name + "4", iceth4); ! ! addNetworkInterface(name + "5", NetworkInterface.Ethernet10T, false); ! Hashtable iceth5 = new Hashtable(); ! IntCaches.put(name + "5", iceth5); ! addNetworkInterface(name + "6", NetworkInterface.Ethernet10T, false); ! Hashtable iceth6 = new Hashtable(); ! IntCaches.put(name + "6", iceth6); ! addNetworkInterface(name + "7", NetworkInterface.Ethernet10T, false); ! Hashtable iceth7 = new Hashtable(); ! IntCaches.put(name + "7", iceth7); } --- 66,83 ---- String name = NetworkInterface.getIntName(NetworkInterface.Ethernet10T); ! Copper_ports = cports; ! Fiber_ports = fports; ! for(int j = 0; j < cports; j++){ ! addNetworkInterface(name + j, NetworkInterface.Ethernet10T, false); ! IntCaches.put(name + j, new Hashtable()); ! } ! name = NetworkInterface.getIntName(NetworkInterface.Ethernet100FX); + for(int j = 0; j < fports; j++){ + addNetworkInterface(name + j, NetworkInterface.Ethernet100FX, false); + IntCaches.put(name + j, new Hashtable()); + } } --- NEW FILE: FiberEthernetNetworkInterface.java --- package core; class FiberEthernetNetworkInterface extends EthernetNetworkInterface{ protected FiberEthernetNetworkInterface(String inName, Node parent) { super(inName,parent); } public int getType(){ return NetworkInterface.Ethernet100FX; } } --- NEW FILE: FiberEthernetLink.java --- package core; import java.util.*; public class FiberEthernetLink extends EthernetLink { public FiberEthernetLink(String inName, NetworkInterface inFirstNodeInterface, NetworkInterface inSecondNodeInterface)throws InvalidLinkConnectionException { super(inName, inFirstNodeInterface, inSecondNodeInterface); } public FiberEthernetLink(String inName, NetworkInterface inFirstNodeInterface, NetworkInterface inSecondNodeInterface, double sieveCoeff)throws InvalidLinkConnectionException { super(inName, inFirstNodeInterface, inSecondNodeInterface, sieveCoeff); } } --- NEW FILE: FiberNetworkInterfacePort.java --- package core; import java.io.Serializable; public class FiberNetworkInterfacePort extends NetworkInterfacePort{ protected FiberNetworkInterfacePort(String inName, Node inParent) { super(inName,inParent); } public int getType(){ return NetworkInterface.Ethernet100FX; } }//EOF --- NEW FILE: AccessListEngine.java --- package core; import java.util.Enumeration; import java.util.Hashtable; import core.protocolsuite.tcp_ip.IPV4Address; /** * * @author key */ public class AccessListEngine { public class access_list{ public final static int PERMIT = 1; public final static int DENY = 2; public final static int REMARK = 0; public final static int IP = 0; public final static int ICMP = 1; public final static int UDP = 2; public final static int TCP = 3; public int number; public int line; public short action; public String IP1; public String SubnetMask1; public int Port1; public String IP2; public String SubnetMask2; public int Port2; public short protocol; } Node parentNode; Hashtable ACLs; public AccessListEngine(Node inParentNode){ parentNode = inParentNode; } public boolean addACL(int number, int line, short action, String IP1, String SubnetMask1){ Hashtable ACLl = (Hashtable)ACLs.get(Integer.valueOf(number)); boolean new_acl = false; if(ACLl == null){ ACLl = new Hashtable(); new_acl = true; } if(ACLl.get(Integer.valueOf(line)) == null) return false; if(line < 0){ line = 0; Integer temp; Enumeration e = ACLl.keys(); while(e.hasMoreElements()){ temp = (Integer)e.nextElement(); if(line < Integer.valueOf(temp)){ line = Integer.valueOf(temp); } } line += 10; } access_list al = new access_list(); al.number = number; al.line = line; al.action = action; al.IP1 = IP1; al.SubnetMask1 = SubnetMask1; ACLl.put(Integer.valueOf(line), al); if(new_acl) ACLs.put(Integer.valueOf(number), ACLl); return true; } public boolean removeACL(int number, int line){ Hashtable ACLl = (Hashtable)ACLs.get(Integer.valueOf(number)); if(ACLl == null) return false; if(ACLl.get(Integer.valueOf(line)) == null) return false; ACLl.remove(Integer.valueOf(line)); if(ACLl.size() < 1) ACLs.remove(Integer.valueOf(number)); return true; } public boolean removeACL(int number, int action, String IP1, String SubnetMask1){ Hashtable ACLl = (Hashtable)ACLs.get(Integer.valueOf(number)); boolean found = false; if(ACLl == null) return false; access_list temp_acl = null; Enumeration e = ACLl.keys(); while(e.hasMoreElements()){ temp_acl = (access_list)ACLl.get((Integer)e.nextElement()); if(temp_acl.action == action && temp_acl.IP1.equals(IP1) && temp_acl.SubnetMask1.equals(SubnetMask1)){ found = true; break; } } if(found) ACLl.remove(Integer.valueOf(temp_acl.line)); if(ACLl.size() < 1) ACLs.remove(Integer.valueOf(number)); return found; } public boolean passStandartACL(int number, String IP){ Hashtable ACLl = (Hashtable)ACLs.get(Integer.valueOf(number)); if(ACLl == null) return false; try{ String binIP = IPV4Address.toBinaryString(IP); String binNetwork = ""; String binMask = ""; access_list temp_acl = null; Enumeration e = ACLl.keys(); while(e.hasMoreElements()){ temp_acl = (access_list)ACLl.get((Integer)e.nextElement()); if(temp_acl.action>0){ binNetwork = IPV4Address.toBinaryString(temp_acl.IP1); binMask = IPV4Address.toBinaryString(temp_acl.SubnetMask1); if(IPV4Address.IPandMask(binNetwork, binMask).equals(IPV4Address.IPandMask(binIP,binMask))){ if(temp_acl.action == access_list.PERMIT) return true; else return false; } } } }catch(Exception ex){ ex.printStackTrace(); } return false; } } |