[Javanetsim-cvs] javaNetSim/core AccessListEngine.java, 1.2, 1.3 ApplicationLayerDevice.java, 1.7,
Status: Beta
Brought to you by:
darkkey
From: QweR <qw...@us...> - 2007-11-17 21:39:06
|
Update of /cvsroot/javanetsim/javaNetSim/core In directory sc8-pr-cvs6.sourceforge.net:/tmp/cvs-serv8566/core Modified Files: AccessListEngine.java ApplicationLayerDevice.java CommandProcessor.java CommandsTree.java DeviceConfig.java EthernetNetworkInterface.java NetworkInterface.java Node.java PC.java Printer.java SerialNetworkInterface.java Simulation.java Log Message: console, ACLs and TCP fixed Index: CommandProcessor.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/core/CommandProcessor.java,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** CommandProcessor.java 23 Oct 2007 20:14:48 -0000 1.8 --- CommandProcessor.java 17 Nov 2007 21:38:57 -0000 1.9 *************** *** 289,294 **** String out = ""; if(params.size()==2){ ! device.getConfig().remove("^arp.*"+params.get(0)+".*$"); ! device.getConfig().add("arp "+ params.get(0)+" "+params.get(1)); device.addToARPStatic(params.get(0), params.get(1)); out += "Created new static ARP entry: " + params.get(0) + " is " + params.get(1) + "\n"; --- 289,295 ---- String out = ""; if(params.size()==2){ ! // device.getConfig().remove("^arp.*"+params.get(0)+".*$"); [...1379 lines suppressed...] --- 2653,2658 ---- if(params.size()==2){ appdevice.addUser(params.get(0), params.get(1)); ! // device.getConfig().remove("^username "+params.get(0)+" "); ! // device.getConfig().add("username "+params.get(0)+" "+params.get(1)); } else{ *************** *** 2375,2379 **** if(params.size()==2){ appdevice.delUser(params.get(0)); ! device.getConfig().remove("^username "+params.get(0)+" "); } else{ --- 2671,2675 ---- if(params.size()==2){ appdevice.delUser(params.get(0)); ! // device.getConfig().remove("^username "+params.get(0)+" "); } else{ Index: Node.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/core/Node.java,v retrieving revision 1.19 retrieving revision 1.20 diff -C2 -d -r1.19 -r1.20 *** Node.java 20 Oct 2007 22:54:40 -0000 1.19 --- Node.java 17 Nov 2007 21:38:58 -0000 1.20 *************** *** 765,768 **** --- 765,777 ---- name=inName; } + + public boolean setClock(String date){ + //set new date + return true; + } + + public String getClock(){ + return "00:00:00 1 1 1970"; + } }//EOF Index: SerialNetworkInterface.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/core/SerialNetworkInterface.java,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** SerialNetworkInterface.java 19 Oct 2007 08:52:26 -0000 1.4 --- SerialNetworkInterface.java 17 Nov 2007 21:38:58 -0000 1.5 *************** *** 33,41 **** * FrameRelay ClockRate * */ ! protected int ClockRate; protected SerialNetworkInterface(String inName, Node parent) { super(inName,parent); ! ClockRate = 400000; } --- 33,44 ---- * FrameRelay ClockRate * */ ! protected int ClockRate; ! public final static int DEFAULT_CLOCKRATE = 400000; ! public final static int MAX_CLOCKRATE = 400000; ! public final static int MIN_CLOCKRATE = 0; protected SerialNetworkInterface(String inName, Node parent) { super(inName,parent); ! ClockRate = DEFAULT_CLOCKRATE; } Index: Simulation.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/core/Simulation.java,v retrieving revision 1.25 retrieving revision 1.26 diff -C2 -d -r1.25 -r1.26 *** Simulation.java 20 Oct 2007 20:19:46 -0000 1.25 --- Simulation.java 17 Nov 2007 21:38:58 -0000 1.26 *************** *** 349,354 **** //nld.setCustomSubnetMask(inInterface, inCustomSubnetMask); nld.getConfig().executeCommand("interface "+inInterface+" ip address "+nld.getIPAddress(inInterface)+" "+inCustomSubnetMask); ! nld.getConfig().remove("interface "+inInterface+" ip address ", DeviceConfig.STARTUP_CONFIG); ! nld.getConfig().add("interface "+inInterface+" ip address "+nld.getIPAddress(inInterface)+" "+inCustomSubnetMask, DeviceConfig.STARTUP_CONFIG); } else --- 349,354 ---- //nld.setCustomSubnetMask(inInterface, inCustomSubnetMask); nld.getConfig().executeCommand("interface "+inInterface+" ip address "+nld.getIPAddress(inInterface)+" "+inCustomSubnetMask); ! // nld.getConfig().remove("interface "+inInterface+" ip address ", DeviceConfig.STARTUP_CONFIG); ! // nld.getConfig().add("interface "+inInterface+" ip address "+nld.getIPAddress(inInterface)+" "+inCustomSubnetMask, DeviceConfig.STARTUP_CONFIG); } else *************** *** 388,393 **** //t.setDefaultGateway(inGatewayIPAddress); t.getConfig().executeCommand("ip route 0.0.0.0 0.0.0.0 "+inGatewayIPAddress+" eth0"); ! t.getConfig().remove("^ip route 0.0.0.0 0.0.0.0 ", DeviceConfig.STARTUP_CONFIG); ! t.getConfig().add("ip route 0.0.0.0 0.0.0.0 "+inGatewayIPAddress+" eth0", DeviceConfig.STARTUP_CONFIG); //t.getConfig().executeCommand("ip route default 0.0.0.0 "+inGatewayIPAddress+" eth0"); } --- 388,393 ---- //t.setDefaultGateway(inGatewayIPAddress); t.getConfig().executeCommand("ip route 0.0.0.0 0.0.0.0 "+inGatewayIPAddress+" eth0"); ! // t.getConfig().remove("^ip route 0.0.0.0 0.0.0.0 ", DeviceConfig.STARTUP_CONFIG); ! // t.getConfig().add("ip route 0.0.0.0 0.0.0.0 "+inGatewayIPAddress+" eth0", DeviceConfig.STARTUP_CONFIG); //t.getConfig().executeCommand("ip route default 0.0.0.0 "+inGatewayIPAddress+" eth0"); } *************** *** 450,455 **** //t.setIPAddress(inNodeInterface,inIPAddress); t.getConfig().executeCommand("interface "+inNodeInterface+" ip address "+inIPAddress+" "+t.getSubnetMask(inNodeInterface)); ! t.getConfig().remove("^interface "+inNodeInterface+" ip address ", DeviceConfig.STARTUP_CONFIG); ! t.getConfig().add("interface "+inNodeInterface+" ip address "+inIPAddress+" "+t.getSubnetMask(inNodeInterface), DeviceConfig.STARTUP_CONFIG); macAddress = t.getMACAddress(inNodeInterface); updateARP(inIPAddress, macAddress, inNodeName); --- 450,455 ---- //t.setIPAddress(inNodeInterface,inIPAddress); t.getConfig().executeCommand("interface "+inNodeInterface+" ip address "+inIPAddress+" "+t.getSubnetMask(inNodeInterface)); ! // t.getConfig().remove("^interface "+inNodeInterface+" ip address ", DeviceConfig.STARTUP_CONFIG); ! // t.getConfig().add("interface "+inNodeInterface+" ip address "+inIPAddress+" "+t.getSubnetMask(inNodeInterface), DeviceConfig.STARTUP_CONFIG); macAddress = t.getMACAddress(inNodeInterface); updateARP(inIPAddress, macAddress, inNodeName); *************** *** 536,541 **** //tempNet.addToARPStatic(inIPAddress, inMACAddress); tempNet.getConfig().executeCommand("arp "+inIPAddress+" "+inMACAddress); ! tempNet.getConfig().remove("^arp "+inIPAddress+" ", DeviceConfig.STARTUP_CONFIG); ! tempNet.getConfig().add("arp "+inIPAddress+" "+inMACAddress, DeviceConfig.STARTUP_CONFIG); } --- 536,541 ---- //tempNet.addToARPStatic(inIPAddress, inMACAddress); tempNet.getConfig().executeCommand("arp "+inIPAddress+" "+inMACAddress); ! // tempNet.getConfig().remove("^arp "+inIPAddress+" ", DeviceConfig.STARTUP_CONFIG); ! // tempNet.getConfig().add("arp "+inIPAddress+" "+inMACAddress, DeviceConfig.STARTUP_CONFIG); } *************** *** 558,562 **** //tempNet.removeARP(inIPAddress); tempNet.getConfig().executeCommand("no arp "+inIPAddress); ! tempNet.getConfig().add("no arp "+inIPAddress, DeviceConfig.STARTUP_CONFIG); } --- 558,562 ---- //tempNet.removeARP(inIPAddress); tempNet.getConfig().executeCommand("no arp "+inIPAddress); ! // tempNet.getConfig().add("no arp "+inIPAddress, DeviceConfig.STARTUP_CONFIG); } Index: Printer.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/core/Printer.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** Printer.java 20 Oct 2007 20:19:46 -0000 1.1 --- Printer.java 17 Nov 2007 21:38:58 -0000 1.2 *************** *** 28,32 **** ! SNMP snmpAgent = new SNMP((ApplicationLayerDevice)this, NodeProtocolStack, 161, 0, core.ProtocolStack.UIDGen++); DHCPC dhcpc = new DHCPC(NodeProtocolStack, core.ProtocolStack.UIDGen++); --- 28,32 ---- ! SNMP snmpAgent = new SNMP((ApplicationLayerDevice)this, NodeProtocolStack, SNMP.DEFAULT_PORT, 0, core.ProtocolStack.UIDGen++); DHCPC dhcpc = new DHCPC(NodeProtocolStack, core.ProtocolStack.UIDGen++); Index: NetworkInterface.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/core/NetworkInterface.java,v retrieving revision 1.11 retrieving revision 1.12 diff -C2 -d -r1.11 -r1.12 *** NetworkInterface.java 19 Oct 2007 15:57:00 -0000 1.11 --- NetworkInterface.java 17 Nov 2007 21:38:58 -0000 1.12 *************** *** 117,120 **** --- 117,128 ---- protected boolean dhcp; + protected int acl_in = 0; + protected int acl_out = 0; + + public boolean unreachables = true; + public boolean redirects = true; + public boolean maskReplay = true; + public boolean informationReplay = true; + public boolean getDHCP(){ return dhcp; *************** *** 483,486 **** --- 491,520 ---- this.description = description; } + + public int getACLin(){ + return acl_in; + } + + public void setACLin(int acl){ + if(acl<0 || acl>2699){ + acl_in = 0; + } + else{ + acl_in = acl; + } + } + + public int getACLout(){ + return acl_out; + } + + public void setACLout(int acl){ + if(acl<0 || acl>2699){ + acl_out = 0; + } + else{ + acl_out = acl; + } + } }//EOF Index: PC.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/core/PC.java,v retrieving revision 1.17 retrieving revision 1.18 diff -C2 -d -r1.17 -r1.18 *** PC.java 19 Oct 2007 17:40:33 -0000 1.17 --- PC.java 17 Nov 2007 21:38:58 -0000 1.18 *************** *** 116,120 **** Echo_tcp echotcpClient = new Echo_tcp(NodeProtocolStack, 0, 0, core.ProtocolStack.UIDGen++); ! SNMP snmpAgent = new SNMP((ApplicationLayerDevice)this, NodeProtocolStack, 161, 0, core.ProtocolStack.UIDGen++); SNMP snmpManager = new SNMP((ApplicationLayerDevice)this, NodeProtocolStack, 0, 1, core.ProtocolStack.UIDGen++); --- 116,120 ---- Echo_tcp echotcpClient = new Echo_tcp(NodeProtocolStack, 0, 0, core.ProtocolStack.UIDGen++); ! SNMP snmpAgent = new SNMP((ApplicationLayerDevice)this, NodeProtocolStack, SNMP.DEFAULT_PORT, 0, core.ProtocolStack.UIDGen++); SNMP snmpManager = new SNMP((ApplicationLayerDevice)this, NodeProtocolStack, 0, 1, core.ProtocolStack.UIDGen++); Index: EthernetNetworkInterface.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/core/EthernetNetworkInterface.java,v retrieving revision 1.10 retrieving revision 1.11 diff -C2 -d -r1.10 -r1.11 *** EthernetNetworkInterface.java 20 Oct 2007 13:27:20 -0000 1.10 --- EthernetNetworkInterface.java 17 Nov 2007 21:38:58 -0000 1.11 *************** *** 29,32 **** --- 29,35 ---- package core; + import core.protocolsuite.tcp_ip.ARP_packet; + import core.protocolsuite.tcp_ip.IP_packet; + //import java.util.*; /** *************** *** 106,112 **** pingInfo.setDescription("Recieved and accepted packet at interface " + MACAddress); Simulation.addLayerInfo(pingInfo); ! Packet temp = tempPacket.getData(); ! ! parentNode.receivePacket(temp, name); }else{ //Packet is not for the Interface Drop Packet and record something in --- 109,123 ---- pingInfo.setDescription("Recieved and accepted packet at interface " + MACAddress); Simulation.addLayerInfo(pingInfo); ! Packet temp = tempPacket.getData(); ! ! boolean allowReceive = true; ! ! NetworkLayerDevice device = (NetworkLayerDevice) parentNode; ! if(device!=null && getACLin()!=0 && temp instanceof IP_packet && !(temp instanceof ARP_packet)){ ! allowReceive = device.getACL().passACL(getACLin(), temp); ! } ! ! if(allowReceive) ! parentNode.receivePacket(temp, name); }else{ //Packet is not for the Interface Drop Packet and record something in Index: DeviceConfig.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/core/DeviceConfig.java,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** DeviceConfig.java 23 Oct 2007 20:14:48 -0000 1.8 --- DeviceConfig.java 17 Nov 2007 21:38:58 -0000 1.9 *************** *** 10,14 **** package core; - import core.AccessListEngine.access_list; import java.util.Iterator; import java.util.LinkedList; --- 10,13 ---- *************** *** 17,24 **** import java.util.regex.PatternSyntaxException; import core.CommandInterface.Modes; - import core.protocolsuite.tcp_ip.IPV4Address; import java.util.Enumeration; import java.util.Hashtable; import core.AccessListEngine.access_list; /** --- 16,27 ---- import java.util.regex.PatternSyntaxException; import core.CommandInterface.Modes; import java.util.Enumeration; import java.util.Hashtable; import core.AccessListEngine.access_list; + import core.protocolsuite.tcp_ip.DHCPC; + import core.protocolsuite.tcp_ip.DHCPD; + import core.protocolsuite.tcp_ip.Route_entry; + import core.protocolsuite.tcp_ip.SNMP; + import core.protocolsuite.tcp_ip.Telnet_server; /** *************** *** 43,46 **** --- 46,50 ---- public DeviceConfig(NetworkLayerDevice dev) { initRunningConfig(); + //initStartupConfig(); cmdproc = new CommandProcessor(dev); device = dev; *************** *** 57,61 **** */ public void load(){ ! Iterator<String> it = startup_config.iterator(); initRunningConfig(); --- 61,65 ---- */ public void load(){ ! Iterator<String> it = prepareConfig(startup_config, true).iterator(); initRunningConfig(); *************** *** 65,68 **** --- 69,74 ---- //running_config.add(nextcmd); } + clearStartupConfig(); + writeMemory(); } *************** *** 70,74 **** LinkedList config = null; switch(config_name){ ! case RUNNING_CONFIG: config = prepareConfig(running_config); break; case STARTUP_CONFIG: config = startup_config; break; default: --- 76,90 ---- LinkedList config = null; switch(config_name){ ! case RUNNING_CONFIG: config = prepareConfig(running_config, true); break; ! case STARTUP_CONFIG: config = prepareConfig(startup_config, true); break; ! default: ! } ! return config; ! } ! ! protected LinkedList getRealConfig(int config_name){ ! LinkedList config = null; ! switch(config_name){ ! case RUNNING_CONFIG: config = running_config; break; case STARTUP_CONFIG: config = startup_config; break; default: *************** *** 85,89 **** while(!running_config.isEmpty()) running_config.removeLast(); ! running_config.add("#ACLS"); } --- 101,118 ---- while(!running_config.isEmpty()) running_config.removeLast(); ! running_config.add(EXEC+"COMMON"); ! running_config.add(EXEC+"EXTENDED"); ! running_config.add(EXEC+"ACLS"); ! running_config.add(EXEC+"INTERFACES"); ! running_config.add(EXEC+"ROUTE"); ! running_config.add(EXEC+"IP"); ! running_config.add(EXEC+"ARPS"); ! } ! ! private void initStartupConfig(){ ! clearStartupConfig(); ! startup_config.add(EXEC+"COMMON"); ! startup_config.add(EXEC+"INTERFACES"); ! startup_config.add(EXEC+"ROUTE"); } *************** *** 91,95 **** boolean result = false; if(startup_config.isEmpty()){ ! Iterator<String> it = prepareConfig(running_config).iterator(); while(it.hasNext()){ startup_config.add(it.next()); --- 120,124 ---- boolean result = false; if(startup_config.isEmpty()){ ! Iterator<String> it = prepareConfig(running_config, false).iterator(); while(it.hasNext()){ startup_config.add(it.next()); *************** *** 113,117 **** public boolean addBefore(String command, int config_name, String beforeCommand){ boolean result = false; ! LinkedList config = getConfig(config_name); boolean found = false; int index = -1; --- 142,146 ---- public boolean addBefore(String command, int config_name, String beforeCommand){ boolean result = false; ! LinkedList config = getRealConfig(config_name); boolean found = false; int index = -1; *************** *** 157,161 **** try{ Pattern p = Pattern.compile(command); ! LinkedList config = getConfig(config_name); Iterator<String> it = config.iterator(); while(it.hasNext()){ --- 186,190 ---- try{ Pattern p = Pattern.compile(command); ! LinkedList config = getRealConfig(config_name); Iterator<String> it = config.iterator(); while(it.hasNext()){ *************** *** 184,188 **** try{ Pattern p = Pattern.compile(command); ! LinkedList config = getConfig(config_name); Iterator<String> it = config.iterator(); while(it.hasNext() && !result){ --- 213,217 ---- try{ Pattern p = Pattern.compile(command); ! LinkedList config = getRealConfig(config_name); Iterator<String> it = config.iterator(); while(it.hasNext() && !result){ *************** *** 221,225 **** } ! private LinkedList prepareConfig(LinkedList in){ LinkedList out = new LinkedList(); Iterator it = in.iterator(); --- 250,254 ---- } ! private LinkedList prepareConfig(LinkedList in, boolean fullConfig){ LinkedList out = new LinkedList(); Iterator it = in.iterator(); *************** *** 231,254 **** fillConfigACLS(out); } ! // else if(nc.equalsIgnoreCase("")){ ! // ! // } ! // else if(nc.equalsIgnoreCase("")){ ! // ! // } ! // else if(nc.equalsIgnoreCase("")){ ! // ! // } ! // else if(nc.equalsIgnoreCase("")){ ! // ! // } ! // else if(nc.equalsIgnoreCase("")){ ! // ! // } ! // else if(nc.equalsIgnoreCase("")){ ! // ! // } else{ ! out.add("#ERROR: unsupported keyword #"+nc); } } --- 260,292 ---- fillConfigACLS(out); } ! else if(nc.equalsIgnoreCase("INTERFACES")){ ! if(fullConfig) ! fillInterfaces(out); ! else ! out.add(EXEC+"INTERFACES"); ! } ! else if(nc.equalsIgnoreCase("ARPS")){ ! fillARP(out); ! } ! else if(nc.equalsIgnoreCase("COMMON")){ ! if(fullConfig) ! fillCommon(out); ! else ! out.add(EXEC+"COMMON"); ! } ! else if(nc.equalsIgnoreCase("IP")){ ! fillIP(out); ! } ! else if(nc.equalsIgnoreCase("ROUTE")){ ! if(fullConfig) ! fillRoute(out); ! else ! out.add(EXEC+"ROUTE"); ! } ! else if(nc.equalsIgnoreCase("EXTENDED")){ ! fillExtended(out); ! } else{ ! out.add(EXEC+"ERROR: unsupported keyword #"+nc); } } *************** *** 260,264 **** } ! private void fillConfigACLS(LinkedList conf){ final int ERROR = 0; final int STANDART = 1; --- 298,302 ---- } ! protected void fillConfigACLS(LinkedList conf){ final int ERROR = 0; final int STANDART = 1; *************** *** 332,346 **** String port = "unsupported_port"; ! if(rule.Port1 == 0){ port = ""; } else{ ! port = "eq "+rule.Port1; } switch(itype){ ! case STANDART: conf.add("ip access-list "+type+" "+rule.number+" "+permit_deny+" "+hosts1); break; ! case EXTENDED: conf.add("ip access-list "+type+" "+rule.number+" "+permit_deny+" "+protocol+" "+hosts1+" "+hosts2+" "+port); break; ! default: conf.add("ip access-list "+type+" "+rule.number+" "+permit_deny+" "+protocol+" "+hosts1+" "+hosts2+" "+rule.Port2); } } --- 370,389 ---- String port = "unsupported_port"; ! if(rule.Port2 == 0){ port = ""; } else{ ! port = "eq "+rule.Port2; ! } ! ! String log = ""; ! if(rule.log){ ! log = "log"; } switch(itype){ ! case STANDART: conf.add("ip access-list "+type+" "+rule.number+" "+permit_deny+" "+hosts1+" "+log); break; ! case EXTENDED: conf.add("ip access-list "+type+" "+rule.number+" "+permit_deny+" "+protocol+" "+hosts1+" "+hosts2+" "+port+" "+log); break; ! default: conf.add("ip access-list "+type+" "+rule.number+" "+permit_deny+" "+protocol+" "+hosts1+" "+hosts2+" "+rule.Port2+" "+log); } } *************** *** 348,350 **** --- 391,531 ---- } + protected void fillInterfaces(LinkedList conf){ + + // commands.add("interface * ip nat", interface__ip_nat_Command, "NAT interface commands"); + + Object[] ins = device.getAllInterfaces(); + + for(int i=0; i<ins.length; i++){ + try { + NetworkInterface ni = device.getNetworkInterface((String)ins[i]); + EthernetNetworkInterface eni = null; + SerialNetworkInterface sni = null; + try{ + eni = (EthernetNetworkInterface) ni; + } catch(ClassCastException e){}; + try{ + sni = (SerialNetworkInterface) ni; + } catch(ClassCastException e){}; + + String intName = (String)ins[i]; + if(ni.getDescription()!=null && !ni.getDescription().equals("")) + conf.add("interface "+intName+" description "+ni.getDescription()); + if(ni.isUP()) + conf.add("no interface "+intName+" shutdown"); + if(eni!=null && !eni.getMACAddress().equalsIgnoreCase(eni.defaultMACAddress)) + conf.add("interface "+intName+" mac-address "+eni.getMACAddress()); + if(eni!=null && device.getIPAddress((String)ins[i])!=null && !device.getIPAddress((String)ins[i]).equals("")) + conf.add("interface "+intName+" ip address "+device.getIPAddress((String)ins[i])+" "+device.getSubnetMask((String)ins[i])); + if(sni!=null && sni.getClockRate()!=sni.DEFAULT_CLOCKRATE) + conf.add("interface "+intName+" clock-rate "+sni.getClockRate()); + if(ni.getACLin()!=0) + conf.add("interface "+intName+" ip access-group "+ni.getACLin()+" in"); + if(ni.getACLout()!=0) + conf.add("interface "+intName+" ip access-group "+ni.getACLout()+" out"); + if(!ni.unreachables) + conf.add("no interface "+intName+" ip unreachables"); + if(!ni.redirects) + conf.add("no interface "+intName+" ip redirects"); + if(!ni.maskReplay) + conf.add("no interface "+intName+" ip mask-replay"); + if(!ni.informationReplay) + conf.add("no interface "+intName+" ip information-replay"); + + if(device instanceof ApplicationLayerDevice){ + DHCPC dhcpc = (DHCPC)((ApplicationLayerDevice)device).getApp(PC.DHCP_CLIENT_ID); + if(dhcpc!=null && dhcpc.running){ + conf.add("interface "+intName+" ip dhcp client"); + } + } + } catch (InvalidNetworkInterfaceNameException ex) { + System.out.println("Internal error: "+ex.getMessage()); + ex.printStackTrace(); + } + } + } + + protected void fillARP(LinkedList conf){ + Vector<Vector<String>> ArpTable = device.getARPTable(); + if(ArpTable.size()>0){ + for(int i=0;i<ArpTable.size();i++) + { + conf.add("arp "+ArpTable.get(i).get(0)+" "+ArpTable.get(i).get(1)); + } + } + } + + protected void fillCommon(LinkedList conf){ + conf.add("hostname "+device.getName()); + if(device.location!=null && !device.location.equals("")) + conf.add("location "+device.location); + } + + protected void fillExtended(LinkedList conf){ + conf.add("clock set "+device.getClock()); + + if(device instanceof ApplicationLayerDevice){ + SNMP snmpa = (SNMP) ((core.ApplicationLayerDevice)device).getApp(core.PC.SNMP_AGENT_ID); + if(snmpa != null && snmpa.running){ + if(snmpa.getPort()!=snmpa.DEFAULT_PORT){ + conf.add("snmp-server port "+snmpa.getPort()); + } + conf.add("snmp-server community "+snmpa.getPassword()); + } + } + + if(device instanceof ApplicationLayerDevice){ + Telnet_server telnets = (Telnet_server) ((core.ApplicationLayerDevice)device).getApp(core.PC.TELNET_SERVER_ID); + if(telnets != null && telnets.running){ + conf.add("telnet-server "+telnets.getPort()); + } + } + + if(device instanceof ApplicationLayerDevice){ + core.ApplicationLayerDevice appdevice = (core.ApplicationLayerDevice)device; + Enumeration<String> users = appdevice.getUserList(); + if(users!=null){ + String username; + while(users.hasMoreElements()){ + username = users.nextElement(); + conf.add("username "+username+" "+appdevice.getUserPassword(username)); + } + } + } + } + + protected void fillRoute(LinkedList conf){ + String routes[] = device.getRouteTableEntries(); + for(int i=0; i<routes.length - 1; i++){ + Route_entry r = device.getRouteTableEntry(routes[i]); + conf.add("ip route "+routes[i]+" "+r.genMask+" "+r.gateway+" "+r.iFace); + } + } + + protected void fillIP(LinkedList conf){ + //commands.add("ip nat inside destination list", ip_nat_inside_destination_list_Command, "Specify access list describing global addresses"); + //commands.add("ip nat inside source list", ip_nat_inside_source_list_Command, "Specify access list describing local addresses"); + //commands.add("ip nat inside source static", ip_nat_inside_source_static_Command, "Specify static local->global mapping"); + //commands.add("ip nat pool", ip_nat_pool_Command, "Define pool of addresses"); + + if(device instanceof ApplicationLayerDevice){ + DHCPD dhcpd = (DHCPD)((ApplicationLayerDevice)device).getApp(PC.DHCP_SERVER_ID); + if(dhcpd!=null){ + Enumeration<String> pools = dhcpd.pools.keys(); + while(pools.hasMoreElements()){ + String poolname = pools.nextElement(); + DHCPD.pool pool = (DHCPD.pool) dhcpd.pools.get(poolname); + conf.add("ip dhcp pool "+poolname+" default-router "+pool.Gateway); + conf.add("ip dhcp pool "+poolname+" network "+pool.IP+" "+pool.Genmask); + conf.add("ip dhcp pool "+poolname+" hardware-address "+pool.MAC); + } + Vector<Pair> exclude = dhcpd.getExcludeAddresses(); + for(int i=0; i<exclude.size(); i++){ + Pair lha = exclude.get(i); + conf.add("ip dhcp pool excluded-address "+lha.getFirst()+" "+lha.getSecond()); + } + } + conf.add("ip tcp window-size "+device.NodeProtocolStack.TCP().getWindowSize()); + } + } } Index: AccessListEngine.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/core/AccessListEngine.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** AccessListEngine.java 23 Oct 2007 20:14:48 -0000 1.2 --- AccessListEngine.java 17 Nov 2007 21:38:57 -0000 1.3 *************** *** 4,7 **** --- 4,10 ---- import java.util.Hashtable; import core.protocolsuite.tcp_ip.IPV4Address; + import core.protocolsuite.tcp_ip.IP_packet; + import core.protocolsuite.tcp_ip.TCP_packet; + import core.protocolsuite.tcp_ip.UDP_packet; /** *************** *** 20,36 **** 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; } --- 23,39 ---- public final static int TCP = 3; ! public int number = 0; ! public int line = 0; ! public short action = -1; ! public int protocol = -1; ! public boolean log = false; ! public String IP1 = null; ! public String SubnetMask1 = null; ! public int Port1 = 0; ! public String IP2 = null; ! public String SubnetMask2 = null; ! public int Port2 = 0; } *************** *** 43,47 **** } ! public int addACL(int number, int line, short action, String IP1, String SubnetMask1){ Hashtable ACLl = (Hashtable)ACLs.get(Integer.valueOf(number)); boolean new_acl = false; --- 46,54 ---- } ! public int addACL(int number, int line, short action, String IP1, String SubnetMask1, boolean log){ ! return addACL(number, line, action, -1, IP1, SubnetMask1, null, null, 0, log); ! } ! ! public int addACL(int number, int line, short action, int protocol, String IP1, String SubnetMask1, String IP2, String SubnetMask2, int port, boolean log){ Hashtable ACLl = (Hashtable)ACLs.get(Integer.valueOf(number)); boolean new_acl = false; *************** *** 71,76 **** --- 78,88 ---- al.line = line; al.action = action; + al.protocol = protocol; al.IP1 = IP1; al.SubnetMask1 = SubnetMask1; + al.IP2 = IP2; + al.SubnetMask2 = SubnetMask2; + al.Port2 = port; + al.log = log; ACLl.put(Integer.valueOf(line), al); *************** *** 120,123 **** --- 132,165 ---- } + public boolean removeACL(int number, int action, int protocol, String IP1, String SubnetMask1, String IP2, String SubnetMask2, int port){ + 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 && + (protocol==-1 || temp_acl.protocol == protocol) && + temp_acl.IP1.equals(IP1) && + temp_acl.SubnetMask1.equals(SubnetMask1) && + (IP2==null || temp_acl.IP2.equals(IP2)) && + (SubnetMask2==null || SubnetMask2.equals(temp_acl.SubnetMask2)) && + (port==0 || temp_acl.Port2 == port) + ){ + 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 isACLExists(int number, int line){ Hashtable acllist = (Hashtable)ACLs.get(new Integer(number)); *************** *** 126,130 **** } ! public boolean passStandartACL(int number, String IP){ Hashtable ACLl = (Hashtable)ACLs.get(Integer.valueOf(number)); --- 168,172 ---- } ! public boolean passACL(int number, Packet packet){ Hashtable ACLl = (Hashtable)ACLs.get(Integer.valueOf(number)); *************** *** 132,151 **** 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; } } --- 174,243 ---- try{ ! int port1 = 0; ! int port2 = 0; ! int protocol = -1; ! String IP1 = null; ! String IP2 = null; ! if(packet instanceof IP_packet){ ! IP_packet ippacket = (IP_packet) packet; ! IP1 = ippacket.getSourceIPAddress(); ! IP2 = ippacket.getDestIPAddress(); ! protocol = access_list.IP; ! if(ippacket instanceof TCP_packet){ ! protocol = AccessListEngine.access_list.TCP; ! port1 = ((TCP_packet)ippacket).get_srcPort(); ! port2 = ((TCP_packet)ippacket).get_destPort(); ! } ! else if(ippacket instanceof UDP_packet){ ! protocol = AccessListEngine.access_list.UDP; ! port1 = ((UDP_packet)ippacket).get_srcPort(); ! port2 = ((UDP_packet)ippacket).get_destPort(); ! } ! String binIP1 = IPV4Address.toBinaryString(IP1); ! String binNetwork1 = ""; ! String binMask1 = ""; ! String binIP2 = null; ! if(IP2!=null){ ! binIP2 = IPV4Address.toBinaryString(IP2); ! } ! String binNetwork2 = null; ! String binMask2 = null; ! ! 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){ ! binNetwork1 = IPV4Address.toBinaryString(temp_acl.IP1); ! binMask1 = IPV4Address.toBinaryString(temp_acl.SubnetMask1); ! if(temp_acl.IP2!=null && temp_acl.SubnetMask2!=null){ ! binNetwork2 = IPV4Address.toBinaryString(temp_acl.IP2); ! binMask2 = IPV4Address.toBinaryString(temp_acl.SubnetMask2); ! } ! ! if((temp_acl.protocol==-1 || temp_acl.protocol==access_list.IP || temp_acl.protocol==protocol) && ! IPV4Address.IPandMask(binNetwork1, binMask1).equals(IPV4Address.IPandMask(binIP1,binMask1)) && ! (binNetwork2==null || (binIP2!=null || IPV4Address.IPandMask(binNetwork2, binMask2).equals(IPV4Address.IPandMask(binIP2,binMask2)))) && ! (temp_acl.Port2 == 0 || temp_acl.Port2 == port2) ! ){ ! if(temp_acl.log){ ! String src = IP1; ! String dst = IP2; ! if(port1>0 && port2>0){ ! src += ":"+port1; ! dst += ":"+port2; ! } ! if(temp_acl.action == access_list.PERMIT){ ! printLayerInfo("Packet from "+src+" to "+dst+" permited"); ! } ! else{ ! printLayerInfo("Packet from "+src+" to "+dst+" denied"); ! } ! } ! if(temp_acl.action == access_list.PERMIT) return true; ! else return false; ! } } } *************** *** 157,159 **** --- 249,260 ---- return false; } + + protected void printLayerInfo(String s) { + LayerInfo protInfo = new LayerInfo(getClass().getName()); + protInfo.setObjectName(parentNode.getName()); + protInfo.setDataType("ACL rule"); + protInfo.setLayer("ACL"); + protInfo.setDescription(s); + Simulation.addLayerInfo(protInfo); + } } Index: ApplicationLayerDevice.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/core/ApplicationLayerDevice.java,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** ApplicationLayerDevice.java 20 Oct 2007 22:54:40 -0000 1.7 --- ApplicationLayerDevice.java 17 Nov 2007 21:38:57 -0000 1.8 *************** *** 31,34 **** --- 31,35 ---- public Object getApp(int code){ + if(Apps==null) return null; return Apps.get(code); } *************** *** 72,79 **** --- 73,82 ---- public String getUserPassword(String username){ + if(userlist==null) return null; return (String)userlist.get(username); } public Enumeration<String> getUserList(){ + if(userlist==null) return null; return userlist.keys(); } Index: CommandsTree.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/core/CommandsTree.java,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** CommandsTree.java 23 Oct 2007 20:14:48 -0000 1.5 --- CommandsTree.java 17 Nov 2007 21:38:58 -0000 1.6 *************** *** 74,78 **** if(nodename.length()>cmdsize) nodename = nodename.substring(0,cmdsize); int cmp = command.compareToIgnoreCase(nodename); ! if(cmp == 0 && modes.isContain(mode)){ nodes.add((CommandNode)tree.get(i)); } --- 74,78 ---- if(nodename.length()>cmdsize) nodename = nodename.substring(0,cmdsize); int cmp = command.compareToIgnoreCase(nodename); ! if(cmp == 0 && node.modes.isContain(mode)){ nodes.add((CommandNode)tree.get(i)); } *************** *** 189,193 **** public boolean add(String command, CommandInterface function, String description){ boolean result = false; ! String cmds[] = command.split(" "); CommandNode node = root; --- 189,193 ---- public boolean add(String command, CommandInterface function, String description){ boolean result = false; ! String cmds[] = command.split(" +"); CommandNode node = root; *************** *** 237,241 **** public void addDescription(String command, String description){ ! String cmds[] = command.split(" "); CommandNode node = root; --- 237,241 ---- public void addDescription(String command, String description){ ! String cmds[] = command.split(" +"); CommandNode node = root; *************** *** 276,280 **** } else{ ! String cmds[] = command.split(" "); CommandInterface func = null; --- 276,280 ---- } else{ ! String cmds[] = command.split(" +"); CommandInterface func = null; *************** *** 307,311 **** } if(func!=null && modes.isContain(mode)){ ! //String sprms[] = params.split(" "); if(node==null) i--; for(; i<cmds.length; i++){ --- 307,311 ---- } if(func!=null && modes.isContain(mode)){ ! //String sprms[] = params.split(" +"); if(node==null) i--; for(; i<cmds.length; i++){ *************** *** 330,334 **** public String complete(String command, Modes mode){ String result = null; ! String cmds[] = command.split(" "); if(command.endsWith(" ")){ --- 330,334 ---- public String complete(String command, Modes mode){ String result = null; ! String cmds[] = command.split(" +"); if(command.endsWith(" ")){ *************** *** 357,361 **** public Vector<Pair> help(String command, Modes mode){ Vector<Pair> result = null; ! String cmds[] = command.split(" "); CommandNode node = root; --- 357,361 ---- public Vector<Pair> help(String command, Modes mode){ Vector<Pair> result = null; ! String cmds[] = command.split(" +"); CommandNode node = root; |