[Javanetsim-cvs] javaNetSim/guiUI Terminal.java,1.3,1.4
Status: Beta
Brought to you by:
darkkey
From: QweR <qw...@us...> - 2007-10-15 21:41:49
|
Update of /cvsroot/javanetsim/javaNetSim/guiUI In directory sc8-pr-cvs6.sourceforge.net:/tmp/cvs-serv17243/guiUI Modified Files: Terminal.java Log Message: add interface commands into console fixed TCP.closePort & UDP.closePort Index: Terminal.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/guiUI/Terminal.java,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** Terminal.java 14 Oct 2007 22:14:52 -0000 1.3 --- Terminal.java 15 Oct 2007 21:41:43 -0000 1.4 *************** *** 146,307 **** //!!!!!: add more headers here } - - private String runcmd(String cmd) { - String out=""; - if(cmd.compareTo("")==0) { - //nothing - } - else if(cmd.compareTo("?")==0 || cmd.compareToIgnoreCase("help")==0) { - out += " route \t show/edit route table\n"; - out += " arp \t show/edit arp table\n"; - out += " snmp \t on/off snmp agent\n"; - out += " counters\t show network counters\n"; - out += " quit \t close terminal session\n"; - out += " ? or help\tshow this screen\n"; - } - else if(cmd.compareToIgnoreCase("quit")==0) { - this.dispose(); - } - else { - String tokens[]=cmd.split(" "); - Matcher m; - if(tokens[0].compareTo("route")==0){ - if((m=Pattern.compile(" +print$").matcher(cmd)).find()) { - - String routes[] = device.NodeProtocolStack.getRouteTableEntries(); - out += "IP routing table:\n" + "Destination" + "\t" + "Gateway" + "\t" + "Genmask" + "\t" + "Type" + "\t" + "Iface\n"; - for(int i=0; i<routes.length - 1; i++){ - Route_entry r = device.NodeProtocolStack.getRouteTableEntry(routes[i]); - out += routes[i] + "\t" + r.gateway + "\t" + r.genMask + "\t" + r.Type + "\t" + r.iFace + "\n"; - } - } - else if((m=Pattern.compile(" +add +([^ ]+) +([^ ]+) +([^ ]+)( +([^ ]+|\\*))?$").matcher(cmd)).find()) { - if(m.group(5)!=null) { - device.NodeProtocolStack.addRoute(new Route_entry(m.group(1), m.group(5), m.group(3), m.group(2), 0)); - } - else { - device.NodeProtocolStack.addRoute(new Route_entry(m.group(1), "", m.group(3), m.group(2), 0)); - } - out+="Route added.\n"; - } - else if((m=Pattern.compile(" +del +([^ ]+)$").matcher(cmd)).find()) { - device.NodeProtocolStack.removeRoute(m.group(1)); - out+="Route to " + tokens[2] + " removed.\n"; - } - else{ - out+="Unknown route command. Usage:\n"; - out+=" route add (<host ip>|<network ip>) <target interface> <netmask> [<gateway>|*]\n" + - " add new route record\n"; - out+=" route del (<host ip>|<network ip>) delete route record\n"; - out+=" route print print route table\n"; - } - } - else if(tokens[0].compareTo("snmp")==0){ - if(device instanceof core.ApplicationLayerDevice) { - if((m=Pattern.compile(" +(on|\\d+)( +([^ ]+))?$").matcher(cmd)).find()) { - int l_port=161; - String l_pass="public"; - if(m.group(1).compareTo("on")!=0) l_port = Integer.parseInt(m.group(1)); - if(m.group(3)!=null) { - if(m.group(3).compareTo("")!=0) l_pass = m.group(3); - } - SNMP snmpa = (SNMP) ((core.ApplicationLayerDevice)device).getApp(161); - try{ - snmpa.Close(); - snmpa.Disconnect(); - out+="SNMP agent stoped\n"; - snmpa.setPassword(l_pass); - snmpa.setPort(l_port); - try{ - snmpa.Listen(); - out+="Now SNMP agent listen on port " + String.valueOf(l_port) + "\n"; - } - catch(TransportLayerException e) { - out+="Unable to open connection on SNMP agent\n"; - } - } - catch(TransportLayerException e) { - out+="Unable to close connection on SNMP agent\n"; - } - } - else if((m=Pattern.compile(" +off$").matcher(cmd)).find()) { - SNMP snmpa = (SNMP) ((core.ApplicationLayerDevice)device).getApp(161); - try{ - snmpa.Close(); - out+="SNMP agent stoped\n"; - } - catch(TransportLayerException e) { - out+="Unable to close connection on SNMP agent\n"; - } - } - else { - out+="Unknown snmp command. Usage:\n"; - out+=" snmp (on|<port number>) [community name] Start SNMP agent\n"; - out+=" snmp off Stop SNMP agent\n"; - } - } - else { - out += "Sorry, but this device not supported SNMP.\n"; - } - } - else if(tokens[0].compareTo("counters")==0){ - 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() + - "\n Sent TCP Dublicates: " + Integer.valueOf(device.NodeProtocolStack.getTCPSDCount()).toString() + - "\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"; - } - else if(tokens[0].compareTo("arp")==0){ - if((m=Pattern.compile(" +-a$").matcher(cmd)).find()) { - try{ - Vector<Vector<String>> ArpTable = device.NodeProtocolStack.getARPTable(); - if(ArpTable.size()>0){ - out += "Internet Address\tPhysical Address\t\tType\n"; - for(int i=0;i<ArpTable.size();i++) - { - out += ArpTable.get(i).get(0) + "\t\t" + ArpTable.get(i).get(1) + "\t\t" + ArpTable.get(i).get(2) + "\n"; - } - } - else{ - out += "No ARP Entries Found\n"; - } - } - catch(Exception e) - { - //Should never get here. - } - } - else if((m=Pattern.compile(" +-d +([^ ]+)$").matcher(cmd)).find()) { - device.NodeProtocolStack.removeARP(m.group(1)); - out += "Removed ARP entry for ip " + m.group(1) + "\n"; - } - else if((m=Pattern.compile(" +-s +([^ ]+) +([^ ]+)$").matcher(cmd)).find()) { - device.NodeProtocolStack.addToARPStatic(m.group(1), m.group(2)); - out += "Created new static ARP entry: " + m.group(1) + " is " + m.group(2) + "\n"; - } - else { - out+="Unknown arp command. Usage:\n"; - out+=" arp -a print ARP table\n"; - out+=" arp -d <ip address> delete record from ARP table\n"; - out+=" arp -s <ip address> <MAC address> add new ARP record\n"; - } - } - else out = tokens[0] + ": command not found\n"; - } - addToTerminal(out); - return out; - } - // - // private String removeSpaces(String s) { - // while(s.startsWith(" ")) s = s.substring(1); - // while(s.endsWith(" ")) s = s.substring(0, s.length()-1); - // return s; - // } /** Add text and prompt to terminal --- 146,149 ---- |