[Javanetsim-cvs] javaNetSim/core ApplicationLayerDevice.java, 1.6, 1.7 CommandInterface.java, 1.1,
Status: Beta
Brought to you by:
darkkey
Update of /cvsroot/javanetsim/javaNetSim/core In directory sc8-pr-cvs6.sourceforge.net:/tmp/cvs-serv10516/core Modified Files: ApplicationLayerDevice.java CommandInterface.java CommandProcessor.java CommandsTree.java DeviceConfig.java Node.java Log Message: new mechanism for "no" processing was developed; some console commands was added & fixed Index: DeviceConfig.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/core/DeviceConfig.java,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** DeviceConfig.java 18 Oct 2007 22:22:09 -0000 1.6 --- DeviceConfig.java 20 Oct 2007 22:54:40 -0000 1.7 *************** *** 15,18 **** --- 15,19 ---- import java.util.regex.Pattern; import java.util.regex.PatternSyntaxException; + import core.CommandInterface.Modes; /** *************** *** 31,35 **** private LinkedList running_config = new LinkedList(); private LinkedList startup_config = new LinkedList(); ! int device_type; /** Creates a new instance of DeviceConfig */ --- 32,36 ---- private LinkedList running_config = new LinkedList(); private LinkedList startup_config = new LinkedList(); ! Modes mode; /** Creates a new instance of DeviceConfig */ *************** *** 37,43 **** cmdproc = new CommandProcessor(dev); device = dev; - device_type = CommandsTree.NETWORK_LAYER; if(device instanceof ApplicationLayerDevice){ ! device_type = CommandsTree.APPLICATION_LAYER; } } --- 38,46 ---- cmdproc = new CommandProcessor(dev); device = dev; if(device instanceof ApplicationLayerDevice){ ! mode = new Modes(CommandInterface.ALL_MODES, CommandInterface.APPLICATION_LAYER, CommandInterface.CALLS); ! } ! else{ ! mode = new Modes(CommandInterface.ALL_MODES, CommandInterface.NETWORK_LAYER, CommandInterface.CALLS); } } *************** *** 187,191 **** public String executeCommand(String command){ ! return cmdproc.call(command, cmdproc.ALLMODE | device_type, ""); } --- 190,194 ---- public String executeCommand(String command){ ! return cmdproc.call(command, mode, ""); } Index: CommandsTree.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/core/CommandsTree.java,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** CommandsTree.java 16 Oct 2007 23:02:31 -0000 1.3 --- CommandsTree.java 20 Oct 2007 22:54:40 -0000 1.4 *************** *** 12,15 **** --- 12,16 ---- import java.util.LinkedList; import java.util.Vector; + import core.CommandInterface.Modes; /** *************** *** 19,33 **** public class CommandsTree { - public static final int NO_MODE = 0x01; - public static final int STD_MODE = 0x02; - public static final int CONF_MODE = 0x04; - public static final int STD_CONF_MODE = STD_MODE | CONF_MODE; - public static final int MODES = NO_MODE | STD_MODE | CONF_MODE; - public static final int NO_LAYER = 0x10; - public static final int NETWORK_LAYER = 0x20 | NO_LAYER; - public static final int TRANSPORT_LAYER = 0x40 | NETWORK_LAYER; - public static final int APPLICATION_LAYER = 0x80 | TRANSPORT_LAYER; - public static final int LAYERS = APPLICATION_LAYER; - public static final int ALLMODE = MODES | LAYERS; public static final String ANYWORD = "*"; --- 20,23 ---- *************** *** 39,44 **** private LinkedList tree; private CommandInterface function; ! private int modes; ! private String params; private String description; --- 29,33 ---- private LinkedList tree; private CommandInterface function; ! public Modes modes; private String description; *************** *** 47,64 **** */ public CommandNode(String name){ this.name = name; tree = null; function = null; - modes = NO_MODE | NO_LAYER; - params = ""; description = ""; } ! public CommandNode(String name, CommandInterface function, int modes, String params, String description){ this.name = name; tree = null; this.function = function; - this.modes = modes; - this.params = params; this.description = description; } --- 36,56 ---- */ public CommandNode(String name){ + modes = new Modes(); this.name = name; tree = null; function = null; description = ""; } ! public CommandNode(String name, CommandInterface function, String description){ ! if(function != null){ ! this.modes = function.modes; ! } ! else{ ! this.modes = new Modes(); ! } this.name = name; tree = null; this.function = function; this.description = description; } *************** *** 68,72 **** } ! private Vector<CommandNode> getNodes(String command, int mode){ Vector<CommandNode> nodes = new Vector<CommandNode>(0); --- 60,64 ---- } ! private Vector<CommandNode> getNodes(String command, Modes mode){ Vector<CommandNode> nodes = new Vector<CommandNode>(0); *************** *** 81,85 **** if(nodename.length()>cmdsize) nodename = nodename.substring(0,cmdsize); int cmp = command.compareToIgnoreCase(nodename); ! if(cmp == 0 && (node.getModes() & mode & MODES)!=0 && (node.getModes() & mode & LAYERS)!=0){ nodes.add((CommandNode)tree.get(i)); } --- 73,77 ---- 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)); } *************** *** 99,103 **** } ! public Vector<String> getCommands(String command, int mode){ Vector<CommandNode> nodes = getNodes(command, mode); Vector<String> nodenames = new Vector<String>(nodes.size()); --- 91,95 ---- } ! public Vector<String> getCommands(String command, Modes mode){ Vector<CommandNode> nodes = getNodes(command, mode); Vector<String> nodenames = new Vector<String>(nodes.size()); *************** *** 108,112 **** } ! public CommandNode getNode(String nodename, int mode){ Vector<CommandNode> nodes = getNodes(nodename, mode); CommandNode node = null; --- 100,104 ---- } ! public CommandNode getNode(String nodename, Modes mode){ Vector<CommandNode> nodes = getNodes(nodename, mode); CommandNode node = null; *************** *** 125,144 **** } - public int getModes(){ - return modes; - } - - public void setModes(int modes){ - this.modes = modes; - } - - public String getParameters(){ - return params; - } - - public void setParameters(String params){ - this.params = params; - } - public String getDescription(){ return description; --- 117,120 ---- *************** *** 199,202 **** --- 175,182 ---- } + private Modes allModes(){ + return new Modes(CommandInterface.ALL_MODES, CommandInterface.LAYERS, CommandInterface.CALLS); + } + /** Bind 'command' with 'params' to 'function' working in 'modes' * @param command full command line without parameters *************** *** 206,210 **** * @return true command was executed, false otherwise */ ! public boolean add(String command, CommandInterface function, int modes, String params, String description){ boolean result = false; String cmds[] = command.split(" "); --- 186,190 ---- * @return true command was executed, false otherwise */ ! public boolean add(String command, CommandInterface function, String description){ boolean result = false; String cmds[] = command.split(" "); *************** *** 213,222 **** boolean existed = false; for(int i=0; i<cmds.length && !existed ; i++){ ! CommandNode nextnode = node.getNode(cmds[i], ALLMODE); 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("")){ --- 193,201 ---- boolean existed = false; for(int i=0; i<cmds.length && !existed ; i++){ ! CommandNode nextnode = node.getNode(cmds[i], allModes()); if(nextnode != null && nextnode.getName().compareTo(cmds[i])==0){ if(i == cmds.length-1){ if(nextnode.getFunction()==null){ ! nextnode.modes.or(function.modes); nextnode.setFunction(function); if(nextnode.getDescription().equals("") && !description.equals("")){ *************** *** 231,239 **** else{ if(i == cmds.length-1){ ! nextnode = new CommandNode(cmds[i], function, modes, params, description); } else{ nextnode = new CommandNode(cmds[i]); ! nextnode.setModes(modes); } node.add(nextnode); --- 210,218 ---- else{ if(i == cmds.length-1){ ! nextnode = new CommandNode(cmds[i], function, description); } else{ nextnode = new CommandNode(cmds[i]); ! nextnode.modes.set(function.modes); } node.add(nextnode); *************** *** 245,263 **** node = root; for(int i=0; i<cmds.length && node!=null ; i++){ ! node.setModes(node.getModes() | modes); ! node = node.getNode(cmds[i], ALLMODE); } result = true; } return result; } ! public boolean addDescription(String command, String description){ ! boolean result = false; String cmds[] = command.split(" "); CommandNode node = root; for(int i=0; i<cmds.length; i++){ ! CommandNode nextnode = node.getNode(cmds[i], ALLMODE); if(nextnode != null && nextnode.getName().compareTo(cmds[i])==0){ if(i == cmds.length-1){ --- 224,244 ---- node = root; for(int i=0; i<cmds.length && node!=null ; i++){ ! node.modes.or(function.modes); ! node = node.getNode(cmds[i], allModes()); } result = true; } + if(function.modes.cmd_mode==CommandInterface.NO_CALL && !cmds[0].equalsIgnoreCase("no")){ + result = result && add("no "+command, function, description); + } return result; } ! public void addDescription(String command, String description){ String cmds[] = command.split(" "); CommandNode node = root; for(int i=0; i<cmds.length; i++){ ! CommandNode nextnode = node.getNode(cmds[i], allModes()); if(nextnode != null && nextnode.getName().compareTo(cmds[i])==0){ if(i == cmds.length-1){ *************** *** 267,271 **** else{ if(i == cmds.length-1){ ! nextnode = new CommandNode(cmds[i], null, NO_MODE | NO_LAYER, "", description); } else{ --- 248,252 ---- else{ if(i == cmds.length-1){ ! nextnode = new CommandNode(cmds[i], null, description); } else{ *************** *** 276,280 **** node = nextnode; } ! return result; } --- 257,263 ---- node = nextnode; } ! if(!cmds[0].equalsIgnoreCase("no")){ ! addDescription("no "+command, description); ! } } *************** *** 284,293 **** * @return true if command was executed, false otherwise */ ! public String call(String command, int mode){ String result = null; String cmds[] = command.split(" "); CommandInterface func = null; ! int modes = 0; String params = ""; Vector<String> vprms = new Vector<String>(0); --- 267,276 ---- * @return true if command was executed, false otherwise */ ! public String call(String command, Modes mode){ String result = null; String cmds[] = command.split(" "); CommandInterface func = null; ! Modes modes = new Modes(0,0,0); String params = ""; Vector<String> vprms = new Vector<String>(0); *************** *** 295,299 **** CommandNode node = root; int i; ! for(i=0; i<cmds.length && node!=null && (node.getModes() & mode & MODES)!=0 && (node.getModes() & mode & LAYERS)!=0; i++){ node = node.getNode(cmds[i], mode); if(node != null){ --- 278,282 ---- CommandNode node = root; int i; ! for(i=0; i<cmds.length && node!=null && node.modes.isContain(mode); i++){ node = node.getNode(cmds[i], mode); if(node != null){ *************** *** 302,310 **** } func = node.getFunction(); ! modes = node.getModes(); ! params = node.getParameters(); } } ! if(func!=null && (modes & mode & MODES)!=0 && (modes & mode & LAYERS)!=0){ //String sprms[] = params.split(" "); if(node==null) i--; --- 285,303 ---- } func = node.getFunction(); ! modes = node.modes; ! if(func!=null){ ! if(cmds[0].equalsIgnoreCase("no")){ ! params = node.getFunction().no_call_params; ! } ! else{ ! params = node.getFunction().call_params; ! } ! } ! else{ ! params = ""; ! } } } ! if(func!=null && modes.isContain(mode)){ //String sprms[] = params.split(" "); if(node==null) i--; *************** *** 312,316 **** vprms.add(cmds[i]); } ! result = func.call(vprms); } return result; --- 305,314 ---- vprms.add(cmds[i]); } ! if(cmds[0].equalsIgnoreCase("no")){ ! result = func.no_call(vprms); ! } ! else{ ! result = func.call(vprms); ! } } return result; *************** *** 322,326 **** * @return complete command, or "" if completing is impossible */ ! public String complete(String command, int mode){ String result = null; String cmds[] = command.split(" "); --- 320,324 ---- * @return complete command, or "" if completing is impossible */ ! public String complete(String command, Modes mode){ String result = null; String cmds[] = command.split(" "); *************** *** 331,335 **** else{ CommandNode node = root; ! for(int i=0; i<cmds.length && node!=null && (node.getModes() & mode & MODES)!=0 && (node.getModes() & mode & LAYERS)!=0; i++){ node = node.getNode(cmds[i], mode); if(node != null && i==cmds.length-1){ --- 329,333 ---- else{ CommandNode node = root; ! for(int i=0; i<cmds.length && node!=null && node.modes.isContain(mode); i++){ node = node.getNode(cmds[i], mode); if(node != null && i==cmds.length-1){ *************** *** 349,353 **** * @return complete command, or "" if helping is impossible */ ! public Vector<Pair> help(String command, int mode){ Vector<Pair> result = null; String cmds[] = command.split(" "); --- 347,351 ---- * @return complete command, or "" if helping is impossible */ ! public Vector<Pair> help(String command, Modes mode){ Vector<Pair> result = null; String cmds[] = command.split(" "); *************** *** 356,365 **** CommandInterface func = null; int modes = 0; ! for(int i=0; i<cmds.length && node!=null && (node.getModes() & mode & MODES)!=0 && (node.getModes() & mode & LAYERS)!=0; i++){ if(i<cmds.length-1){ CommandNode nextnode = node.getNode(cmds[i], mode); if(nextnode==null && node.getFunction()!=null){ result = new Vector<Pair>(1); ! result.add(new Pair(node.getParameters(), "")); } node = nextnode; --- 354,368 ---- CommandInterface func = null; int modes = 0; ! for(int i=0; i<cmds.length && node!=null && node.modes.isContain(mode); i++){ if(i<cmds.length-1){ CommandNode nextnode = node.getNode(cmds[i], mode); if(nextnode==null && node.getFunction()!=null){ result = new Vector<Pair>(1); ! if(cmds[0].equalsIgnoreCase("no")){ ! result.add(new Pair(node.getFunction().no_call_params, "")); ! } ! else{ ! result.add(new Pair(node.getFunction().call_params, "")); ! } } node = nextnode; *************** *** 376,380 **** } if(node.getFunction()!=null){ ! result.add(new Pair(node.getParameters(), "")); } } --- 379,388 ---- } if(node.getFunction()!=null){ ! if(cmds[0].equalsIgnoreCase("no")){ ! result.add(new Pair(node.getFunction().no_call_params, "")); ! } ! else{ ! result.add(new Pair(node.getFunction().call_params, "")); ! } } } Index: CommandInterface.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/core/CommandInterface.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** CommandInterface.java 12 Oct 2007 21:06:39 -0000 1.1 --- CommandInterface.java 20 Oct 2007 22:54:40 -0000 1.2 *************** *** 15,23 **** * @author QweR */ ! public interface CommandInterface { ! /** Execute fucntion ! * @return true if command was executed, false otherwise ! */ ! public String call(Vector<String> params); } --- 15,80 ---- * @author QweR */ ! abstract public class CommandInterface { ! ! public static final int NO_MODE = 0x01; ! public static final int STD_MODE = 0x02; ! public static final int CONF_MODE = 0x04; ! public static final int STD_CONF_MODE = STD_MODE | CONF_MODE; ! public static final int ALL_MODES = NO_MODE | STD_MODE | CONF_MODE; ! public static final int NO_LAYER = 0x01; ! public static final int NETWORK_LAYER = 0x02 | NO_LAYER; ! public static final int TRANSPORT_LAYER = 0x04 | NETWORK_LAYER; ! public static final int APPLICATION_LAYER = 0x08 | TRANSPORT_LAYER; ! public static final int LAYERS = APPLICATION_LAYER; ! ! public static final int CALL_ONLY = 0x01; ! public static final int NO_CALL = 0x02; ! public static final int CALLS = CALL_ONLY | NO_CALL; ! ! ! static public class Modes{ ! public int conf_mode; ! public int layer_mode; ! public int cmd_mode; ! ! public Modes(){ ! conf_mode = NO_MODE; ! layer_mode = NO_LAYER; ! cmd_mode = CALL_ONLY; ! } ! public Modes(int conf, int layer, int cmd){ ! conf_mode = conf; ! layer_mode = layer; ! cmd_mode = cmd; ! } ! public void set(Modes mode){ ! conf_mode = mode.conf_mode; ! layer_mode = mode.layer_mode; ! cmd_mode = mode.cmd_mode; ! } ! public void or(Modes mode){ ! conf_mode |= mode.conf_mode; ! layer_mode |= mode.layer_mode; ! cmd_mode |= mode.cmd_mode; ! } ! public boolean isContain(Modes mode){ ! return ((conf_mode & mode.conf_mode)!=0 && (layer_mode & mode.layer_mode)!=0 && (cmd_mode & mode.cmd_mode)!=0); ! } ! } ! ! public Modes modes; ! public String call_params; ! public String no_call_params; ! ! ! public CommandInterface(){ ! modes = new Modes(NO_MODE, NO_LAYER, CALL_ONLY); ! } ! ! abstract public String call(Vector<String> params); ! ! public String no_call(Vector<String> params){ ! return "Function not implemented!!!"; ! } } Index: CommandProcessor.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/core/CommandProcessor.java,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** CommandProcessor.java 18 Oct 2007 22:22:09 -0000 1.6 --- CommandProcessor.java 20 Oct 2007 22:54:40 -0000 1.7 *************** *** 25,28 **** --- 25,29 ---- import java.util.Iterator; import java.util.Vector; + import core.CommandInterface.Modes; /** *************** *** 32,45 **** public class CommandProcessor { [...2587 lines suppressed...] ! } public String call(Vector<String> params){ device.getConfig().clear(DeviceConfig.STARTUP_CONFIG); *************** *** 1506,1510 **** } }; ! class write_terminal_CommandClass implements CommandInterface{ public String call(Vector<String> params){ String out = ""; --- 2289,2297 ---- } }; ! class write_terminal_CommandClass extends CommandInterface{ ! public write_terminal_CommandClass(){ ! modes = new Modes(CommandInterface.STD_CONF_MODE, CommandInterface.NETWORK_LAYER, CommandInterface.CALL_ONLY); ! call_params = "<cr>"; ! } public String call(Vector<String> params){ String out = ""; Index: Node.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/core/Node.java,v retrieving revision 1.18 retrieving revision 1.19 diff -C2 -d -r1.18 -r1.19 *** Node.java 20 Oct 2007 13:27:20 -0000 1.18 --- Node.java 20 Oct 2007 22:54:40 -0000 1.19 *************** *** 129,132 **** --- 129,134 ---- public boolean On; + public String location = ""; + private int ProtocolStackLayers; Index: ApplicationLayerDevice.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/core/ApplicationLayerDevice.java,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** ApplicationLayerDevice.java 19 Oct 2007 08:52:24 -0000 1.6 --- ApplicationLayerDevice.java 20 Oct 2007 22:54:40 -0000 1.7 *************** *** 18,21 **** --- 18,22 ---- public class ApplicationLayerDevice extends NetworkLayerDevice{ protected Hashtable Apps = null; + protected Hashtable userlist = new Hashtable(); /** Creates a new instance of ApplicationLayerDevice */ public ApplicationLayerDevice(String inName, int inProtocolStackLayers, boolean inOn) { *************** *** 58,61 **** --- 59,81 ---- } + + public void addUser(String username, String password){ + if(userlist.containsKey(username)){ + userlist.remove(username); + } + userlist.put(username, password); + } + + public void delUser(String username){ + userlist.remove(username); + } + + public String getUserPassword(String username){ + return (String)userlist.get(username); + } + + public Enumeration<String> getUserList(){ + return userlist.keys(); + } } |