[Javanetsim-cvs] javaNetSim/core CommandProcessor.java, 1.1, 1.2 DeviceConfig.java, 1.1, 1.2
Status: Beta
Brought to you by:
darkkey
From: QweR <qw...@us...> - 2007-10-14 00:22:19
|
Update of /cvsroot/javanetsim/javaNetSim/core In directory sc8-pr-cvs6.sourceforge.net:/tmp/cvs-serv25590/core Modified Files: CommandProcessor.java DeviceConfig.java Log Message: Some small bugs fixed Index: CommandProcessor.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/core/CommandProcessor.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** CommandProcessor.java 12 Oct 2007 21:06:39 -0000 1.1 --- CommandProcessor.java 14 Oct 2007 00:22:14 -0000 1.2 *************** *** 36,41 **** private NoCommandClass noCommand = new NoCommandClass(); ! private arp_add_CommandClass arp_add_Command = new arp_add_CommandClass(); ! private arp_remove_CommandClass arp_remove_Command = new arp_remove_CommandClass(); private clear_arp_CommandClass clear_arp_Command = new clear_arp_CommandClass(); private clock_set_CommandClass clock_set_Command = new clock_set_CommandClass(); --- 36,41 ---- private NoCommandClass noCommand = new NoCommandClass(); ! private arp_CommandClass arp_Command = new arp_CommandClass(); ! private no_arp_CommandClass no_arp_Command = new no_arp_CommandClass(); private clear_arp_CommandClass clear_arp_Command = new clear_arp_CommandClass(); private clock_set_CommandClass clock_set_Command = new clock_set_CommandClass(); *************** *** 80,89 **** device = dev; - - commands.addDescription("no","Negate a command or set its defaults"); ! commands.addDescription("arp","Configure arp table"); ! commands.add("arp", arp_add_Command, CONF_MODE | NETWORK_LAYER, "<IP> <MAC>", "Add record to arp table"); ! commands.add("no arp", arp_remove_Command, CONF_MODE | NETWORK_LAYER, "<IP|MAC>", "Remove record from arp table"); commands.addDescription("clear","Reset functions"); commands.add("clear arp", clear_arp_Command, STD_CONF_MODE | NETWORK_LAYER, "<cr>", "Clear the entire ARP cache"); --- 80,86 ---- device = dev; commands.addDescription("no","Negate a command or set its defaults"); ! commands.add("arp", arp_Command, CONF_MODE | NETWORK_LAYER, "<IP> <MAC>", "Add record to arp table"); ! commands.add("no arp", no_arp_Command, CONF_MODE | NETWORK_LAYER, "<IP>", "Remove record from arp table"); commands.addDescription("clear","Reset functions"); commands.add("clear arp", clear_arp_Command, STD_CONF_MODE | NETWORK_LAYER, "<cr>", "Clear the entire ARP cache"); *************** *** 166,173 **** } }; ! class arp_add_CommandClass implements CommandInterface{ public String call(Vector<String> params){ String out = ""; if(params.size()==2){ device.NodeProtocolStack.addToARPStatic(params.get(0), params.get(1)); out += "Created new static ARP entry: " + params.get(0) + " is " + params.get(1) + "\n"; --- 163,172 ---- } }; ! class arp_CommandClass implements CommandInterface{ public String call(Vector<String> params){ String out = ""; if(params.size()==2){ + device.getConfig().remove("^arp.*"+params.get(0)+".*$"); + device.getConfig().add("arp", params); device.NodeProtocolStack.addToARPStatic(params.get(0), params.get(1)); out += "Created new static ARP entry: " + params.get(0) + " is " + params.get(1) + "\n"; *************** *** 179,186 **** } }; ! class arp_remove_CommandClass implements CommandInterface{ public String call(Vector<String> params){ String out = ""; if(params.size()==1){ device.NodeProtocolStack.removeARP(params.get(0)); out += "Removed ARP entry for ip " + params.get(0) + "\n"; --- 178,186 ---- } }; ! class no_arp_CommandClass implements CommandInterface{ public String call(Vector<String> params){ String out = ""; if(params.size()==1){ + device.getConfig().remove("^arp "+params.get(0)+" "); device.NodeProtocolStack.removeARP(params.get(0)); out += "Removed ARP entry for ip " + params.get(0) + "\n"; *************** *** 261,264 **** --- 261,266 ---- try{ device.setIPAddress(params.get(0), params.get(1)); + device.getConfig().remove("^host .*"); + device.getConfig().add("host", params); } catch(InvalidNetworkInterfaceNameException e){ *************** *** 366,370 **** class show_hostname_CommandClass implements CommandInterface{ public String call(Vector<String> params){ ! return "Command not supported yet.\n"; } }; --- 368,372 ---- class show_hostname_CommandClass implements CommandInterface{ public String call(Vector<String> params){ ! return (device.NodeProtocolStack.getParentNodeName() + "\n"); } }; *************** *** 394,400 **** public String call(Vector<String> params){ String out = " Recieved IP Packets: " + Integer.valueOf(device.NodeProtocolStack.getinputIPCount()).toString() + ! "\n Sent IP Packets: " + Integer.valueOf(device.NodeProtocolStack.getoutputIPCount()).toString() + ! "\n ARP Packets: " + Integer.valueOf(device.NodeProtocolStack.getARPCount()).toString() + ! "\n Recieved TCP segments: " + Integer.valueOf(device.NodeProtocolStack.getTCPinputCount()).toString() + "\n Sent TCP segments: " + Integer.valueOf(device.NodeProtocolStack.getTCPoutputCount()).toString() + "\n Sent TCP ACK's: " + Integer.valueOf(device.NodeProtocolStack.getTCPACKCount()).toString() + --- 396,403 ---- public String call(Vector<String> params){ String out = " Recieved IP Packets: " + Integer.valueOf(device.NodeProtocolStack.getinputIPCount()).toString() + ! "\n Sent IP Packets: " + Integer.valueOf(device.NodeProtocolStack.getoutputIPCount()).toString() + ! "\n ARP Packets: " + Integer.valueOf(device.NodeProtocolStack.getARPCount()).toString(); ! if(device.getClass().equals(ApplicationLayerDevice.class)){ ! out += "\n Recieved TCP segments: " + Integer.valueOf(device.NodeProtocolStack.getTCPinputCount()).toString() + "\n Sent TCP segments: " + Integer.valueOf(device.NodeProtocolStack.getTCPoutputCount()).toString() + "\n Sent TCP ACK's: " + Integer.valueOf(device.NodeProtocolStack.getTCPACKCount()).toString() + *************** *** 402,407 **** "\n Recieved TCP Dublicates: " + Integer.valueOf(device.NodeProtocolStack.getTCPRDCount()).toString() + "\n Recieved UDP segments: " + Integer.valueOf(device.NodeProtocolStack.getUDPinputCount()).toString() + ! "\n Sent UDP segments: " + Integer.valueOf(device.NodeProtocolStack.getUDPoutputCount()).toString() + ! "\n"; return out; } --- 405,411 ---- "\n Recieved TCP Dublicates: " + Integer.valueOf(device.NodeProtocolStack.getTCPRDCount()).toString() + "\n Recieved UDP segments: " + Integer.valueOf(device.NodeProtocolStack.getUDPinputCount()).toString() + ! "\n Sent UDP segments: " + Integer.valueOf(device.NodeProtocolStack.getUDPoutputCount()).toString(); ! } ! out += "\n"; return out; } *************** *** 462,466 **** public String call(Vector<String> params){ SNMP snmpa = (SNMP) ((core.ApplicationLayerDevice)device).getApp(161); ! return (snmpa.getPassword()+"\n"); } }; --- 466,478 ---- public String call(Vector<String> params){ SNMP snmpa = (SNMP) ((core.ApplicationLayerDevice)device).getApp(161); ! String out = "SNMP Community: "; ! if(snmpa.getPassword().equals("")){ ! out += "<not set>"; ! } ! else{ ! out += snmpa.getPassword(); ! } ! out += "\n"; ! return out; } }; *************** *** 468,472 **** public String call(Vector<String> params){ SNMP snmpa = (SNMP) ((core.ApplicationLayerDevice)device).getApp(161); ! String out = ""; for(int i=0; i<snmpa.SNMPgroups.size(); i++){ SNMP.SNMPInstance gr = snmpa.SNMPgroups.get(i); --- 480,484 ---- public String call(Vector<String> params){ SNMP snmpa = (SNMP) ((core.ApplicationLayerDevice)device).getApp(161); ! String out = "SNMP mibs:\n"; for(int i=0; i<snmpa.SNMPgroups.size(); i++){ SNMP.SNMPInstance gr = snmpa.SNMPgroups.get(i); Index: DeviceConfig.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/core/DeviceConfig.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** DeviceConfig.java 12 Oct 2007 21:06:39 -0000 1.1 --- DeviceConfig.java 14 Oct 2007 00:22:14 -0000 1.2 *************** *** 12,15 **** --- 12,17 ---- import java.util.Iterator; import java.util.LinkedList; + import java.util.Vector; + import java.util.regex.Pattern; /** *************** *** 22,25 **** --- 24,29 ---- public final static int STARTUP_CONFIG = 2; + public int working_config = RUNNING_CONFIG; + private NetworkLayerDevice device; private CommandProcessor cmdproc; *************** *** 42,46 **** String nextcmd = it.next(); cmdproc.call(nextcmd, cmdproc.ALLMODE | cmdproc.APPLICATION_LAYER); ! running_config.add(nextcmd); } } --- 46,50 ---- String nextcmd = it.next(); cmdproc.call(nextcmd, cmdproc.ALLMODE | cmdproc.APPLICATION_LAYER); ! //running_config.add(nextcmd); } } *************** *** 80,152 **** * @return false if 'command' already exists */ ! public boolean add(int config_name, String command, int paramc){ boolean result = false; ! if(paramc>0){ ! String req_cmd = getCommandPart(command, paramc); ! LinkedList config = getConfig(config_name); ! Iterator<String> it = config.iterator(); ! boolean found = false; ! while(it.hasNext() && !found){ ! found = (req_cmd.compareToIgnoreCase(getCommandPart(it.next(), paramc))==0); ! } ! if(!found){ ! config.add(command); ! result = true; ! } } return result; } ! /** Replace existing elements by 'command', which contain parameters after 'paramc' argument * */ ! public boolean replace(int config_name, String command, int paramc){ boolean result = false; ! if(paramc>0){ ! String req_cmd = getCommandPart(command, paramc); ! LinkedList config = getConfig(config_name); ! boolean manyfound = false; ! int index = -1; ! for(int i=0; i<config.size() && !manyfound; i++){ ! if(req_cmd.compareToIgnoreCase(getCommandPart((String)config.get(i), paramc))==0){ ! if(index == -1){ ! index = i; ! } ! else{ ! manyfound = true; ! } ! } ! } ! if(!manyfound){ ! if(index == -1){ ! config.add(command); ! } ! else{ ! config.set(index, command); ! } result = true; } } return result; ! } ! /** Remove all elements start with 'command' and contain equal or above than 'paramc' arguments * */ ! public boolean remove(int config_name, String command, int paramc){ boolean result = false; ! if(paramc>0){ ! String req_cmd = getCommandPart(command, paramc); ! LinkedList config = getConfig(config_name); ! Iterator<String> it = config.iterator(); ! while(it.hasNext()){ ! if(req_cmd.compareToIgnoreCase(getCommandPart(it.next(), paramc))==0){ ! it.remove(); ! } } - result = true; } return result; --- 84,169 ---- * @return false if 'command' already exists */ ! public boolean add(String command, Vector<String> params){ boolean result = false; ! String fullcmd = createCommand(command, params); ! LinkedList config = getConfig(working_config); ! Iterator<String> it = config.iterator(); ! boolean found = false; ! while(it.hasNext() && !found){ ! found = (fullcmd.compareToIgnoreCase(it.next())==0); ! } ! if(!found){ ! config.add(createCommand(command, params)); ! result = true; } return result; } ! // /** Replace existing elements by 'command', which contain parameters after 'paramc' argument ! // * ! // */ ! // public boolean replace(int config_name, String command, int paramc){ ! // boolean result = false; ! // ! // if(paramc>0){ ! // String req_cmd = getCommandPart(command, paramc); ! // LinkedList config = getConfig(config_name); ! // boolean manyfound = false; ! // int index = -1; ! // for(int i=0; i<config.size() && !manyfound; i++){ ! // if(req_cmd.compareToIgnoreCase(getCommandPart((String)config.get(i), paramc))==0){ ! // if(index == -1){ ! // index = i; ! // } ! // else{ ! // manyfound = true; ! // } ! // } ! // } ! // if(!manyfound){ ! // if(index == -1){ ! // config.add(command); ! // } ! // else{ ! // config.set(index, command); ! // } ! // result = true; ! // } ! // } ! // return result; ! // } ! ! /** Remove all elements match with 'command' * */ ! public boolean remove(String command){ 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; ! } ! /** Is exists 'command' in 'config_name' ? * */ ! public boolean isExists(String command){ 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; *************** *** 165,167 **** --- 182,191 ---- } + private String createCommand(String command, Vector<String> params){ + for(int i=0; i<params.size(); i++){ + command += " " + params.get(i); + } + return command; + } + } |