[Javanetsim-cvs] javaNetSim/core CommandProcessor.java, 1.4, 1.5 CommandsTree.java, 1.2, 1.3 Device
Status: Beta
Brought to you by:
darkkey
Update of /cvsroot/javanetsim/javaNetSim/core In directory sc8-pr-cvs6.sourceforge.net:/tmp/cvs-serv24483/core Modified Files: CommandProcessor.java CommandsTree.java DeviceConfig.java NetworkInterface.java Node.java Simulation.java Log Message: config saving partially works Index: DeviceConfig.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/core/DeviceConfig.java,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** DeviceConfig.java 15 Oct 2007 21:41:42 -0000 1.4 --- DeviceConfig.java 16 Oct 2007 23:02:31 -0000 1.5 *************** *** 14,17 **** --- 14,18 ---- import java.util.Vector; import java.util.regex.Pattern; + import java.util.regex.PatternSyntaxException; /** *************** *** 30,37 **** --- 31,44 ---- private LinkedList running_config = new LinkedList(); private LinkedList startup_config = new LinkedList(); + int device_type; /** Creates a new instance of DeviceConfig */ public DeviceConfig(NetworkLayerDevice dev) { + cmdproc = new CommandProcessor(dev); device = dev; + device_type = CommandsTree.NETWORK_LAYER; + if(device instanceof ApplicationLayerDevice){ + device_type = CommandsTree.APPLICATION_LAYER; + } } *************** *** 45,49 **** while(it.hasNext()){ String nextcmd = it.next(); ! cmdproc.call(nextcmd, cmdproc.ALLMODE | cmdproc.APPLICATION_LAYER); //running_config.add(nextcmd); } --- 52,56 ---- while(it.hasNext()){ String nextcmd = it.next(); ! executeCommand(nextcmd); //running_config.add(nextcmd); } *************** *** 81,96 **** } - /** Add 'command', which contain parameters 'params' - * @return false if 'command' already exists - */ - public boolean add(String command, Vector<String> params){ - return addBefore(command, params, null); - } - - public boolean addBefore(String command, Vector<String> params, String beforeCommand){ - String fullcmd = createCommand(command, params); - return addBefore(fullcmd, beforeCommand); - } - /** Add full 'command' * @return false if 'command' already exists --- 88,91 ---- *************** *** 105,111 **** boolean found = false; int index = -1; ! Pattern p = Pattern.compile(beforeCommand); for(int i=0; i<config.size() && !found; i++){ ! if(p.matcher((String)config.get(i)).find()){ index = i; } --- 100,114 ---- boolean found = false; int index = -1; ! Pattern p = null; ! try { ! if(beforeCommand!=null){ ! p = Pattern.compile(beforeCommand); ! } ! } catch(PatternSyntaxException e) { ! System.out.println("addBefore: pattern "+beforeCommand+" have incorrent syntax\n"); ! e.printStackTrace(); ! } for(int i=0; i<config.size() && !found; i++){ ! if(beforeCommand!=null && p.matcher((String)config.get(i)).find()){ index = i; } *************** *** 132,143 **** boolean result = false; ! Pattern p = Pattern.compile(command); ! LinkedList config = getConfig(working_config); ! Iterator<String> it = config.iterator(); ! while(it.hasNext()){ ! if(p.matcher(it.next()).find()){ ! it.remove(); ! result = true; } } return result; --- 135,151 ---- boolean result = false; ! try{ ! Pattern p = Pattern.compile(command); ! LinkedList config = getConfig(working_config); ! Iterator<String> it = config.iterator(); ! while(it.hasNext()){ ! if(p.matcher(it.next()).find()){ ! it.remove(); ! result = true; ! } } + } catch(PatternSyntaxException e) { + System.out.println("remove: pattern "+command+" have incorrent syntax\n"); + e.printStackTrace(); } return result; *************** *** 150,164 **** boolean result = false; ! Pattern p = Pattern.compile(command); ! LinkedList config = getConfig(working_config); ! Iterator<String> it = config.iterator(); ! while(it.hasNext() && !result){ ! if(p.matcher(it.next()).find()){ ! result = true; } } return result; } private String getCommandPart(String command, int paramc){ String result = ""; --- 158,181 ---- boolean result = false; ! try{ ! Pattern p = Pattern.compile(command); ! LinkedList config = getConfig(working_config); ! Iterator<String> it = config.iterator(); ! while(it.hasNext() && !result){ ! if(p.matcher(it.next()).find()){ ! result = true; ! } } + } catch(PatternSyntaxException e) { + System.out.println("isExists: pattern "+command+" have incorrent syntax\n"); + e.printStackTrace(); } return result; } + public String executeCommand(String command){ + return cmdproc.call(command, cmdproc.ALLMODE | device_type, ""); + } + private String getCommandPart(String command, int paramc){ String result = ""; Index: CommandsTree.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/core/CommandsTree.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** CommandsTree.java 15 Oct 2007 21:41:42 -0000 1.2 --- CommandsTree.java 16 Oct 2007 23:02:31 -0000 1.3 *************** *** 121,124 **** --- 121,128 ---- } + public void setFunction(CommandInterface function){ + this.function = function; + } + public int getModes(){ return modes; *************** *** 212,216 **** if(nextnode != null && nextnode.getName().compareTo(cmds[i])==0){ if(i == cmds.length-1){ ! existed = true; // exit from cycle } } --- 216,230 ---- if(nextnode != null && nextnode.getName().compareTo(cmds[i])==0){ if(i == cmds.length-1){ ! if(nextnode.getFunction()==null){ ! nextnode.setModes(nextnode.getModes() | modes); ! nextnode.setParameters(params); ! nextnode.setFunction(function); ! if(nextnode.getDescription().equals("") && !description.equals("")){ ! nextnode.setDescription(description); ! } ! } ! else{ ! existed = true; // exit from cycle ! } } } *************** *** 277,280 **** --- 291,295 ---- int modes = 0; String params = ""; + Vector<String> vprms = new Vector<String>(0); CommandNode node = root; *************** *** 283,286 **** --- 298,304 ---- node = node.getNode(cmds[i], mode); if(node != null){ + if(node.getName().equals(ANYWORD)){ + vprms.add(cmds[i]); + } func = node.getFunction(); modes = node.getModes(); *************** *** 289,294 **** } if(func!=null && (modes & mode & MODES)!=0 && (modes & mode & LAYERS)!=0){ ! String sprms[] = params.split(" "); ! Vector<String> vprms = new Vector<String>(0); if(node==null) i--; for(; i<cmds.length; i++){ --- 307,311 ---- } if(func!=null && (modes & mode & MODES)!=0 && (modes & mode & LAYERS)!=0){ ! //String sprms[] = params.split(" "); if(node==null) i--; for(; i<cmds.length; i++){ *************** *** 352,367 **** node = node.getNode(cmds[i], mode); if(node!=null){ if(node.getFunction()!=null){ - result = new Vector<Pair>(1); result.add(new Pair(node.getParameters(), "")); } - else{ - Vector<String> nodecmds = node.getCommands("", mode); - result = new Vector<Pair>(nodecmds.size()); - for(int j=0; j<nodecmds.size(); j++){ - String nodename = nodecmds.get(j); - result.add(new Pair(nodename, node.getNode(nodename,mode).getDescription())); - } - } } } --- 369,381 ---- node = node.getNode(cmds[i], mode); if(node!=null){ + Vector<String> nodecmds = node.getCommands("", mode); + result = new Vector<Pair>(nodecmds.size()+1); + for(int j=0; j<nodecmds.size(); j++){ + String nodename = nodecmds.get(j); + result.add(new Pair(nodename, node.getNode(nodename,mode).getDescription())); + } if(node.getFunction()!=null){ result.add(new Pair(node.getParameters(), "")); } } } Index: Simulation.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/core/Simulation.java,v retrieving revision 1.18 retrieving revision 1.19 diff -C2 -d -r1.18 -r1.19 *** Simulation.java 15 Oct 2007 18:25:54 -0000 1.18 --- Simulation.java 16 Oct 2007 23:02:31 -0000 1.19 *************** *** 343,352 **** public void setCustomSubnetMask(String inNodeName,String inInterface,String inCustomSubnetMask)throws InvalidNetworkLayerDeviceException, InvalidNodeNameException, InvalidNetworkInterfaceNameException,InvalidSubnetMaskException { if (nodeTable.containsKey(inNodeName)){ ! try{ Node temp = (Node)nodeTable.get(inNodeName); if (temp instanceof NetworkLayerDevice)//test if device is a network layer device { NetworkLayerDevice nld = (NetworkLayerDevice)temp; ! nld.setCustomSubnetMask(inInterface, inCustomSubnetMask); } else --- 343,353 ---- public void setCustomSubnetMask(String inNodeName,String inInterface,String inCustomSubnetMask)throws InvalidNetworkLayerDeviceException, InvalidNodeNameException, InvalidNetworkInterfaceNameException,InvalidSubnetMaskException { if (nodeTable.containsKey(inNodeName)){ ! // try{ Node temp = (Node)nodeTable.get(inNodeName); if (temp instanceof NetworkLayerDevice)//test if device is a network layer device { NetworkLayerDevice nld = (NetworkLayerDevice)temp; ! //nld.setCustomSubnetMask(inInterface, inCustomSubnetMask); ! nld.getConfig().executeCommand("interface "+inInterface+" ip address "+nld.getIPAddress(inInterface)+" "+inCustomSubnetMask); } else *************** *** 354,360 **** throw new InvalidNetworkLayerDeviceException("This device is not a network layered device"); } ! }catch (InvalidNetworkInterfaceNameException e){ ! throw e; ! } }else{ throw new InvalidNodeNameException("Node does not exist"); --- 355,361 ---- throw new InvalidNetworkLayerDeviceException("This device is not a network layered device"); } ! // }catch (InvalidNetworkInterfaceNameException e){ ! // throw e; ! // } }else{ throw new InvalidNodeNameException("Node does not exist"); *************** *** 384,388 **** { //test if device is a network layer device NetworkLayerDevice t = (NetworkLayerDevice)temp; ! t.setDefaultGateway(inGatewayIPAddress); } else --- 385,391 ---- { //test if device is a network layer device NetworkLayerDevice t = (NetworkLayerDevice)temp; ! t.setDefaultGateway(inGatewayIPAddress); ! //t.getConfig().executeCommand("ip route 0.0.0.0 0.0.0.0 "+inGatewayIPAddress+" eth0"); ! //t.getConfig().executeCommand("ip route default 0.0.0.0 "+inGatewayIPAddress+" eth0"); } else *************** *** 442,447 **** if (temp instanceof NetworkLayerDevice){ //test if device is a network layer device NetworkLayerDevice t = (NetworkLayerDevice)temp; ! ! macAddress = t.setIPAddress(inNodeInterface,inIPAddress); updateARP(inIPAddress, macAddress, inNodeName); //t.addToARP(inIPAddress, macAddress); --- 445,451 ---- if (temp instanceof NetworkLayerDevice){ //test if device is a network layer device NetworkLayerDevice t = (NetworkLayerDevice)temp; ! //t.setIPAddress(inNodeInterface,inIPAddress); ! t.getConfig().executeCommand("interface "+inNodeInterface+" ip address "+inIPAddress+" "+t.getSubnetMask(inNodeInterface)); ! macAddress = t.getMACAddress(inNodeInterface); updateARP(inIPAddress, macAddress, inNodeName); //t.addToARP(inIPAddress, macAddress); *************** *** 525,529 **** { NetworkLayerDevice tempNet = (NetworkLayerDevice)temp; ! tempNet.addToARPStatic(inIPAddress, inMACAddress); } --- 529,534 ---- { NetworkLayerDevice tempNet = (NetworkLayerDevice)temp; ! //tempNet.addToARPStatic(inIPAddress, inMACAddress); ! tempNet.getConfig().executeCommand("arp "+inIPAddress+" "+inMACAddress); } *************** *** 544,548 **** { NetworkLayerDevice tempNet = (NetworkLayerDevice)temp; ! tempNet.removeARP(inIPAddress); } --- 549,554 ---- { NetworkLayerDevice tempNet = (NetworkLayerDevice)temp; ! //tempNet.removeARP(inIPAddress); ! tempNet.getConfig().executeCommand("no arp "+inIPAddress); } Index: NetworkInterface.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/core/NetworkInterface.java,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** NetworkInterface.java 15 Oct 2007 18:25:54 -0000 1.8 --- NetworkInterface.java 16 Oct 2007 23:02:31 -0000 1.9 *************** *** 115,118 **** --- 115,120 ---- protected boolean up; + protected String description = ""; + public void UP(){ up = true; *************** *** 457,460 **** --- 459,470 ---- } + + public String getDescription(){ + return description; + } + + public void setDescription(String description){ + this.description = description; + } }//EOF Index: CommandProcessor.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/core/CommandProcessor.java,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** CommandProcessor.java 15 Oct 2007 21:41:42 -0000 1.4 --- CommandProcessor.java 16 Oct 2007 23:02:31 -0000 1.5 *************** *** 11,14 **** --- 11,15 ---- import core.protocolsuite.tcp_ip.InvalidIPAddressException; + import core.protocolsuite.tcp_ip.InvalidSubnetMaskException; import core.protocolsuite.tcp_ip.Route_entry; import core.protocolsuite.tcp_ip.SNMP; *************** *** 50,54 **** private erase_startup_config_CommandClass erase_startup_config_Command = new erase_startup_config_CommandClass(); private help_CommandClass help_Command = new help_CommandClass(); [...1312 lines suppressed...] ! Telnet_server telnets = (Telnet_server) ((core.ApplicationLayerDevice)device).getApp(core.PC.TELNET_SERVER_ID); ! if(telnets != null){ ! if(params.size()==0){ ! try{ ! telnets.Close(); ! }catch(TransportLayerException e) { } ! device.getConfig().remove("^telnet server .*"); ! } ! else{ ! out += "Invalid parameters\n"; ! } ! } ! else{ ! out += "This instruction not supported by device\n"; ! } ! } ! else{ ! out += "This instruction not supported by device\n"; } return out; Index: Node.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/core/Node.java,v retrieving revision 1.13 retrieving revision 1.14 diff -C2 -d -r1.13 -r1.14 *** Node.java 15 Oct 2007 21:41:42 -0000 1.13 --- Node.java 16 Oct 2007 23:02:31 -0000 1.14 *************** *** 422,426 **** */ ! protected NetworkInterface getNetworkInterface(String interfaceName) throws InvalidNetworkInterfaceNameException{ if(NetworkInterfacetable.containsKey(interfaceName)){ --- 422,426 ---- */ ! public NetworkInterface getNetworkInterface(String interfaceName) throws InvalidNetworkInterfaceNameException{ if(NetworkInterfacetable.containsKey(interfaceName)){ |