[Javanetsim-cvs] javaNetSim/core ApplicationLayerDevice.java, 1.12, 1.13 CommandProcessor.java, 1.3
Status: Beta
Brought to you by:
darkkey
Update of /cvsroot/javanetsim/javaNetSim/core In directory fdv4jf1.ch3.sourceforge.com:/tmp/cvs-serv32599/core Modified Files: ApplicationLayerDevice.java CommandProcessor.java ConsoleNetworkInterface.java DeviceConfig.java Link.java NetworkInterface.java Log Message: Added commands ip name-server int * databits int * flowcontrol int * parity int * speed int * stopbits Index: DeviceConfig.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/core/DeviceConfig.java,v retrieving revision 1.26 retrieving revision 1.27 diff -C2 -d -r1.26 -r1.27 *** DeviceConfig.java 24 Oct 2008 17:46:42 -0000 1.26 --- DeviceConfig.java 26 Oct 2008 22:02:46 -0000 1.27 *************** *** 388,391 **** --- 388,392 ---- SerialNetworkInterface sni = null; NetworkInterfacePort pni = null; + ConsoleNetworkInterface cni = null; WiFiPort wfi = null; try{ *************** *** 399,402 **** --- 400,406 ---- } catch(ClassCastException e){}; try{ + cni = (ConsoleNetworkInterface) ni; + } catch(ClassCastException e){}; + try{ wfi = (WiFiPort) ni; } catch(ClassCastException e){}; *************** *** 443,446 **** --- 447,486 ---- } } + + if(cni!=null){ + if(cni.databits!=ConsoleNetworkInterface.DATABITS_DEFAULT) + conf.add("interface "+intName+" databits "+cni.databits); + if(cni.flowcontrol!=ConsoleNetworkInterface.FLOWCONTROL_DEFAULT){ + String fc = ""; + switch(cni.flowcontrol){ + case ConsoleNetworkInterface.FLOWCONTROL_NONE: fc = "none"; break; + case ConsoleNetworkInterface.FLOWCONTROL_HARDWARE: fc = "hardware"; break; + case ConsoleNetworkInterface.FLOWCONTROL_SOFTWARE: fc = "software"; break; + } + conf.add("interface "+intName+" flowcontrol "+fc); + } + if(cni.parity!=ConsoleNetworkInterface.PARITY_DEFAULT){ + String pa = ""; + switch(cni.parity){ + case ConsoleNetworkInterface.PARITY_NONE: pa = "none"; break; + case ConsoleNetworkInterface.PARITY_EVEN: pa = "even"; break; + case ConsoleNetworkInterface.PARITY_ODD: pa = "odd"; break; + case ConsoleNetworkInterface.PARITY_MARK: pa = "mark"; break; + case ConsoleNetworkInterface.PARITY_SPACE: pa = "space"; break; + } + conf.add("interface "+intName+" parity "+pa); + } + if(cni.stopbits!=ConsoleNetworkInterface.STOPBIT_DEFAULT){ + String sb = ""; + switch(cni.stopbits){ + case ConsoleNetworkInterface.STOPBIT_1: sb = "1"; break; + case ConsoleNetworkInterface.STOPBIT_15: sb = "1.5"; break; + case ConsoleNetworkInterface.STOPBIT_2: sb = "2"; break; + } + conf.add("interface "+intName+" stopbits "+sb); + } + if(cni.speed!=ConsoleNetworkInterface.SPEED_DEFAULT) + conf.add("interface "+intName+" speed "+cni.speed); + } if(ni.getACLin()!=0) conf.add("interface "+intName+" ip access-group "+ni.getACLin()+" in"); *************** *** 533,537 **** } if(device instanceof ApplicationLayerDevice){ ! DHCPD dhcpd = (DHCPD)((ApplicationLayerDevice)device).getApp(PC.DHCP_SERVER_ID); if(dhcpd!=null){ Enumeration<String> dhcppools = dhcpd.pools.keys(); --- 573,578 ---- } if(device instanceof ApplicationLayerDevice){ ! ApplicationLayerDevice adev = (ApplicationLayerDevice)device; ! DHCPD dhcpd = (DHCPD)adev.getApp(PC.DHCP_SERVER_ID); if(dhcpd!=null){ Enumeration<String> dhcppools = dhcpd.pools.keys(); *************** *** 554,557 **** --- 595,601 ---- if(device.NodeProtocolStack.TCP().getWindowSize() != Tcp.DEFAULT_WINDOW_SIZE) conf.add("ip tcp window-size "+device.NodeProtocolStack.TCP().getWindowSize()); + if(adev.getNameServer()!=""){ + conf.add("ip name-server "+adev.getNameServer()); + } } } Index: Link.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/core/Link.java,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** Link.java 24 Oct 2008 16:18:48 -0000 1.4 --- Link.java 26 Oct 2008 22:02:46 -0000 1.5 *************** *** 25,29 **** TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ! */ package core; --- 25,29 ---- TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ! */ package core; *************** *** 49,104 **** * @since 14 June 2004 * @version v0.20 ! */ - abstract class Link implements Serializable{ /** The interfaceList holds all of the NetworkInterfaces that are connected to the Link */ ! ! /** * @link aggregation <{core.NetworkInterface}> * @directed directed * @supplierCardinality 0..* */ ! java.util.Vector NetworkInterfaces = null; ! /** Name of the link */ ! protected String name; ! ! protected double sievingCoefficient; ! ! /** *TODO*: javaDoc ! * ! */ ! public double getSC(){ ! return sievingCoefficient; ! } ! ! ! /** *TODO*: javaDoc ! * ! */ ! public void setSC(double SC){ ! sievingCoefficient = SC; ! } ! ! /** ! * Constructs a Link with the specified name. Conceptually this will simply create a cable ! * not connected to anything. You need to call the addInterface() method to 'plug' the cable ! * in to NetworkInterfaces. ! * @author luke_hamilton ! * @param inName - The name to give the Link. eg: LINK1 ! * @version v0.20 ! **/ ! protected Link(String inName) { ! NetworkInterfaces = new Vector(); name = inName; ! sievingCoefficient = 100; ! } - protected String getName() - { - return name; - } - /** * This method returns true is the link is not connected to any --- 49,109 ---- * @since 14 June 2004 * @version v0.20 ! */ ! ! public class Link implements Serializable{ ! /** ! * ! */ ! private static final long serialVersionUID = 4675052404278691897L; /** The interfaceList holds all of the NetworkInterfaces that are connected to the Link */ ! ! /** * @link aggregation <{core.NetworkInterface}> * @directed directed * @supplierCardinality 0..* */ ! Vector<NetworkInterface> NetworkInterfaces = null; ! /** Name of the link */ ! protected String name; ! protected double sievingCoefficient; ! ! ! /** *TODO*: javaDoc ! * ! */ ! public double getSC(){ ! return sievingCoefficient; ! } ! ! ! /** *TODO*: javaDoc ! * ! */ ! public void setSC(double SC){ ! sievingCoefficient = SC; ! } ! ! /** ! * Constructs a Link with the specified name. Conceptually this will simply create a cable ! * not connected to anything. You need to call the addInterface() method to 'plug' the cable ! * in to NetworkInterfaces. ! * @author luke_hamilton ! * @param inName - The name to give the Link. eg: LINK1 ! * @version v0.20 ! **/ ! protected Link(String inName) { ! NetworkInterfaces = new Vector<NetworkInterface>(); name = inName; ! sievingCoefficient = 100; ! } ! ! protected String getName() ! { ! return name; ! } /** * This method returns true is the link is not connected to any *************** *** 122,146 **** */ protected void disconnectLink() { ! for (int i = 0; i < NetworkInterfaces.size(); i++) { ! NetworkInterface temp = (NetworkInterface)NetworkInterfaces.elementAt(i); temp.resetConnectedLink(); } NetworkInterfaces.removeAllElements(); ! } ! /** ! * Displays all the interfaces in the interface list through System.out.println() calls. ! * @author tristan_veness ! * @author luke_hamilton ! * @version v0.20 ! */ protected void displayDetails(){ System.out.println(name); for (int i = 0; i < NetworkInterfaces.size(); i++) { ! NetworkInterface NIC = (NetworkInterface)NetworkInterfaces.elementAt(i); System.out.println("Connection " +i+ " "+NIC.getDetails()); } } }//EOF --- 127,161 ---- */ protected void disconnectLink() { ! for (int i = 0; i < NetworkInterfaces.size(); i++) { ! NetworkInterface temp = NetworkInterfaces.elementAt(i); temp.resetConnectedLink(); } NetworkInterfaces.removeAllElements(); ! } ! /** ! * Displays all the interfaces in the interface list through System.out.println() calls. ! * @author tristan_veness ! * @author luke_hamilton ! * @version v0.20 ! */ protected void displayDetails(){ System.out.println(name); for (int i = 0; i < NetworkInterfaces.size(); i++) { ! NetworkInterface NIC = NetworkInterfaces.elementAt(i); System.out.println("Connection " +i+ " "+NIC.getDetails()); } } + + public String getLinkedNodeName(String node, String iface){ + for (int i = 0; i < NetworkInterfaces.size(); i++) { + if(NetworkInterfaces.elementAt(i).getName().equalsIgnoreCase(iface) + && NetworkInterfaces.elementAt(i).getParentNode().getName().equalsIgnoreCase(node)){ + return NetworkInterfaces.elementAt(1-i).getParentNode().getName(); + } + } + return ""; + } }//EOF Index: ConsoleNetworkInterface.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/core/ConsoleNetworkInterface.java,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** ConsoleNetworkInterface.java 24 Oct 2008 16:18:48 -0000 1.3 --- ConsoleNetworkInterface.java 26 Oct 2008 22:02:46 -0000 1.4 *************** *** 54,58 **** class ConsoleNetworkInterface extends NetworkInterface{ ! /** * --- 54,82 ---- class ConsoleNetworkInterface extends NetworkInterface{ ! public final static int STOPBIT_1 = 1; ! public final static int STOPBIT_15 = 2; ! public final static int STOPBIT_2 = 3; ! public final static int STOPBIT_DEFAULT = STOPBIT_1; ! ! public final static int PARITY_NONE = 1; ! public final static int PARITY_EVEN = 2; ! public final static int PARITY_ODD = 3; ! public final static int PARITY_MARK = 4; ! public final static int PARITY_SPACE = 5; ! public final static int PARITY_DEFAULT = PARITY_NONE; ! ! public final static int FLOWCONTROL_NONE = 1; ! public final static int FLOWCONTROL_HARDWARE = 2; ! public final static int FLOWCONTROL_SOFTWARE = 3; ! public final static int FLOWCONTROL_DEFAULT = FLOWCONTROL_NONE; ! ! public final static int SPEED_DEFAULT = 9600; ! public final static int DATABITS_DEFAULT = 8; ! ! public int speed = SPEED_DEFAULT; ! public int databits = DATABITS_DEFAULT; ! public int stopbits = STOPBIT_DEFAULT; ! public int parity = PARITY_DEFAULT; ! public int flowcontrol = FLOWCONTROL_DEFAULT; /** * Index: CommandProcessor.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/core/CommandProcessor.java,v retrieving revision 1.35 retrieving revision 1.36 diff -C2 -d -r1.35 -r1.36 *** CommandProcessor.java 24 Oct 2008 18:13:48 -0000 1.35 --- CommandProcessor.java 26 Oct 2008 22:02:46 -0000 1.36 *************** *** 66,71 **** --- 66,73 ---- private interface__channel_CommandClass interface__channel_Command = new interface__channel_CommandClass(); private interface__clock_rate_CommandClass interface__clock_rate_Command = new interface__clock_rate_CommandClass(); + private interface__databits_CommandClass interface__databits_Command = new interface__databits_CommandClass(); private interface__description_CommandClass interface__description_Command = new interface__description_CommandClass(); private interface__encryption_key_CommandClass interface__encryption_key_Command = new interface__encryption_key_CommandClass(); + private interface__flowcontrol_CommandClass interface__flowcontrol_Command = new interface__flowcontrol_CommandClass(); private interface__ip_address_CommandClass interface__ip_address_Command = new interface__ip_address_CommandClass(); private interface__ip_access_group_CommandClass interface__ip_access_group_Command = new interface__ip_access_group_CommandClass(); *************** *** 77,83 **** --- 79,88 ---- private interface__ip_dhcp_client_CommandClass interface__ip_dhcp_client_Command = new interface__ip_dhcp_client_CommandClass(); private interface__mac_address_CommandClass interface__mac_address_Command = new interface__mac_address_CommandClass(); + private interface__parity_CommandClass interface__parity_Command = new interface__parity_CommandClass(); private interface__shutdown_CommandClass interface__shutdown_Command = new interface__shutdown_CommandClass(); + private interface__speed_CommandClass interface__speed_Command = new interface__speed_CommandClass(); private interface__ssid_CommandClass interface__ssid_Command = new interface__ssid_CommandClass(); private interface__station_role_CommandClass interface__station_role_Command = new interface__station_role_CommandClass(); + private interface__stopbits_CommandClass interface__stopbits_Command = new interface__stopbits_CommandClass(); private interface__switchport_access_vlan_CommandClass interface__switchport_access_vlan_Command = new interface__switchport_access_vlan_CommandClass(); private interface__switchport_mode_access_CommandClass interface__switchport_mode_access_Command = new interface__switchport_mode_access_CommandClass(); *************** *** 93,96 **** --- 98,102 ---- private ip_host_CommandClass ip_host_Command = new ip_host_CommandClass(); private ip_host_hinfo_CommandClass ip_host_hinfo_Command = new ip_host_hinfo_CommandClass(); + private ip_name_server_CommandClass ip_name_server_Command = new ip_name_server_CommandClass(); //private ip_nat_inside_destination_list_CommandClass ip_nat_inside_destination_list_Command = new ip_nat_inside_destination_list_CommandClass(); private ip_nat_inside_source_list_CommandClass ip_nat_inside_source_list_Command = new ip_nat_inside_source_list_CommandClass(); *************** *** 170,176 **** --- 176,184 ---- commands.add("interface * channel", interface__channel_Command, "Specify channel"); commands.add("interface * clock-rate", interface__clock_rate_Command, "Specify clock-rate"); + commands.add("interface * databits", interface__databits_Command, "Set number of data bits per character"); commands.add("interface * description", interface__description_Command, "Interface specific description"); commands.addDescription("interface * encryption","Configure encryption"); commands.add("interface * encryption key", interface__encryption_key_Command, "Configure encryption key"); + commands.add("interface * flowcontrol", interface__flowcontrol_Command, "Set the flow control"); commands.addDescription("interface * ip","Configure Internet Protocol"); commands.add("interface * ip address", interface__ip_address_Command, "Set the IP address of an interface"); *************** *** 184,190 **** --- 192,201 ---- commands.add("interface * ip dhcp client", interface__ip_dhcp_client_Command, "Enable DHCP client"); commands.add("interface * mac-address", interface__mac_address_Command, "Manually set interface MAC address"); + commands.add("interface * parity", interface__parity_Command, "Set terminal parity"); commands.add("interface * shutdown", interface__shutdown_Command, "Shutdown the selected interface"); + commands.add("interface * speed", interface__speed_Command, "Set the transmit and receive speeds"); commands.add("interface * ssid", interface__ssid_Command, "Set SSID"); commands.add("interface * station-role", interface__station_role_Command, "Specify station role"); + commands.add("interface * stopbits", interface__stopbits_Command, "Set async line stop bits"); commands.addDescription("interface * switchport access","Configure a port access"); commands.add("interface * switchport access vlan", interface__switchport_access_vlan_Command, "Configure a port as a static-access port"); *************** *** 209,212 **** --- 220,224 ---- commands.add("ip host", ip_host_Command, "Add an entry to the ip hostname table"); commands.add("ip host hinfo", ip_host_hinfo_Command, "Set system information record"); + commands.add("ip name-server", ip_name_server_Command, "Specify address of name server to use"); commands.addDescription("ip nat","NAT configuration commands"); commands.addDescription("ip nat inside","Inside address translation"); *************** *** 726,739 **** int cr = Integer.parseInt(params.get(1)); if(cr>SerialNetworkInterface.MIN_CLOCKRATE || cr<=SerialNetworkInterface.MAX_CLOCKRATE){ ! if(sni!=null){ ! sni.setClockRate(cr); ! } ! else{ ! out += "unsupposed instruction for this interface\n"; ! } } else{ out += "error: invalid clock rate"; } } catch (NumberFormatException ex) { out += "error: invalid clock rate"; --- 738,748 ---- int cr = Integer.parseInt(params.get(1)); if(cr>SerialNetworkInterface.MIN_CLOCKRATE || cr<=SerialNetworkInterface.MAX_CLOCKRATE){ ! sni.setClockRate(cr); } else{ out += "error: invalid clock rate"; } + } catch (ClassCastException ex){ + out += "unsupposed instruction for this interface\n"; } catch (NumberFormatException ex) { out += "error: invalid clock rate"; *************** *** 752,761 **** try { SerialNetworkInterface sni = (SerialNetworkInterface)device.getNetworkInterface(params.get(0)); ! if(sni!=null){ ! sni.setClockRate(SerialNetworkInterface.DEFAULT_CLOCKRATE); ! } ! else{ ! out += "unsupposed instruction for this interface\n"; ! } } catch (InvalidNetworkInterfaceNameException ex) { out += "error: invalid inferface\n"; --- 761,767 ---- try { SerialNetworkInterface sni = (SerialNetworkInterface)device.getNetworkInterface(params.get(0)); ! sni.setClockRate(SerialNetworkInterface.DEFAULT_CLOCKRATE); ! } catch (ClassCastException ex){ ! out += "unsupposed instruction for this interface\n"; } catch (InvalidNetworkInterfaceNameException ex) { out += "error: invalid inferface\n"; *************** *** 807,810 **** --- 813,865 ---- } }; + class interface__databits_CommandClass extends CommandInterface{ + public interface__databits_CommandClass(){ + modes = new Modes(CommandInterface.CONF_MODE, CommandInterface.NETWORK_LAYER, CommandInterface.NO_CALL); + call_params = "<5-8>"; + no_call_params = "<cr>"; + } + public String call(Vector<String> params){ + String out = ""; + if(params.size()==2){ + try { + ConsoleNetworkInterface cni = (ConsoleNetworkInterface)device.getNetworkInterface(params.get(0)); + int val = Integer.parseInt(params.get(1)); + if(val>=5 && val<=8){ + cni.databits = val; + } + else{ + out += "error: invalid databits number\n"; + } + } catch (ClassCastException ex){ + out += "unsupposed instruction for this interface\n"; + } catch (NumberFormatException ex) { + out += "error: invalid clock rate"; + } catch (InvalidNetworkInterfaceNameException ex) { + out += "error: invalid inferface\n"; + } + } + else{ + out += "error: invalid parameters\n"; + } + return out; + } + public String no_call(Vector<String> params){ + String out = ""; + if(params.size()==1){ + try { + ConsoleNetworkInterface cni = (ConsoleNetworkInterface)device.getNetworkInterface(params.get(0)); + cni.databits = ConsoleNetworkInterface.DATABITS_DEFAULT; + } catch (ClassCastException ex){ + out += "unsupposed instruction for this interface\n"; + } catch (InvalidNetworkInterfaceNameException ex) { + out += "error: invalid inferface\n"; + } + } + else{ + out += "error: invalid parameters\n"; + } + return out; + } + }; class interface__encryption_key_CommandClass extends CommandInterface{ public interface__encryption_key_CommandClass(){ *************** *** 907,910 **** --- 962,1020 ---- } }; + class interface__flowcontrol_CommandClass extends CommandInterface{ + public interface__flowcontrol_CommandClass(){ + modes = new Modes(CommandInterface.CONF_MODE, CommandInterface.NETWORK_LAYER, CommandInterface.NO_CALL); + call_params = "(none|hardware|software)"; + no_call_params = "<cr>"; + } + public String call(Vector<String> params){ + String out = ""; + if(params.size()==2){ + try { + ConsoleNetworkInterface cni = (ConsoleNetworkInterface)device.getNetworkInterface(params.get(0)); + String val = params.get(1); + if(val.equalsIgnoreCase("none")){ + cni.flowcontrol = ConsoleNetworkInterface.FLOWCONTROL_NONE; + } + else if(val.equalsIgnoreCase("hardware")){ + cni.flowcontrol = ConsoleNetworkInterface.FLOWCONTROL_HARDWARE; + } + else if(val.equalsIgnoreCase("software")){ + cni.flowcontrol = ConsoleNetworkInterface.FLOWCONTROL_SOFTWARE; + } + else{ + out += "error: invalid flowcontrol value\n"; + } + } catch (ClassCastException ex){ + out += "unsupposed instruction for this interface\n"; + } catch (NumberFormatException ex) { + out += "error: invalid clock rate"; + } catch (InvalidNetworkInterfaceNameException ex) { + out += "error: invalid inferface\n"; + } + } + else{ + out += "error: invalid parameters\n"; + } + return out; + } + public String no_call(Vector<String> params){ + String out = ""; + if(params.size()==1){ + try { + ConsoleNetworkInterface cni = (ConsoleNetworkInterface)device.getNetworkInterface(params.get(0)); + cni.flowcontrol = ConsoleNetworkInterface.FLOWCONTROL_DEFAULT; + } catch (ClassCastException ex){ + out += "unsupposed instruction for this interface\n"; + } catch (InvalidNetworkInterfaceNameException ex) { + out += "error: invalid inferface\n"; + } + } + else{ + out += "error: invalid parameters\n"; + } + return out; + } + }; class interface__ip_access_group_CommandClass extends CommandInterface{ public interface__ip_access_group_CommandClass(){ *************** *** 1373,1376 **** --- 1483,1547 ---- } }; + class interface__parity_CommandClass extends CommandInterface{ + public interface__parity_CommandClass(){ + modes = new Modes(CommandInterface.CONF_MODE, CommandInterface.NETWORK_LAYER, CommandInterface.NO_CALL); + call_params = "(none|even|odd|mark|space)"; + no_call_params = "<cr>"; + } + public String call(Vector<String> params){ + String out = ""; + if(params.size()==2){ + try { + ConsoleNetworkInterface cni = (ConsoleNetworkInterface)device.getNetworkInterface(params.get(0)); + String val = params.get(1); + if(val.equalsIgnoreCase("none")){ + cni.parity = ConsoleNetworkInterface.PARITY_NONE; + } + else if(val.equalsIgnoreCase("even")){ + cni.parity = ConsoleNetworkInterface.PARITY_EVEN; + } + else if(val.equalsIgnoreCase("odd")){ + cni.parity = ConsoleNetworkInterface.PARITY_ODD; + } + else if(val.equalsIgnoreCase("mark")){ + cni.parity = ConsoleNetworkInterface.PARITY_MARK; + } + else if(val.equalsIgnoreCase("space")){ + cni.parity = ConsoleNetworkInterface.PARITY_SPACE; + } + else{ + out += "error: invalid parity value\n"; + } + } catch (ClassCastException ex){ + out += "unsupposed instruction for this interface\n"; + } catch (NumberFormatException ex) { + out += "error: invalid clock rate"; + } catch (InvalidNetworkInterfaceNameException ex) { + out += "error: invalid inferface\n"; + } + } + else{ + out += "error: invalid parameters\n"; + } + return out; + } + public String no_call(Vector<String> params){ + String out = ""; + if(params.size()==1){ + try { + ConsoleNetworkInterface cni = (ConsoleNetworkInterface)device.getNetworkInterface(params.get(0)); + cni.parity = ConsoleNetworkInterface.PARITY_DEFAULT; + } catch (ClassCastException ex){ + out += "unsupposed instruction for this interface\n"; + } catch (InvalidNetworkInterfaceNameException ex) { + out += "error: invalid inferface\n"; + } + } + else{ + out += "error: invalid parameters\n"; + } + return out; + } + }; class interface__shutdown_CommandClass extends CommandInterface{ public interface__shutdown_CommandClass(){ *************** *** 1408,1411 **** --- 1579,1631 ---- } }; + class interface__speed_CommandClass extends CommandInterface{ + public interface__speed_CommandClass(){ + modes = new Modes(CommandInterface.CONF_MODE, CommandInterface.NETWORK_LAYER, CommandInterface.NO_CALL); + call_params = "<1-2147483647>"; + no_call_params = "<cr>"; + } + public String call(Vector<String> params){ + String out = ""; + if(params.size()==2){ + try { + ConsoleNetworkInterface cni = (ConsoleNetworkInterface)device.getNetworkInterface(params.get(0)); + int val = Integer.parseInt(params.get(1)); + if(val>0){ + cni.speed = val; + } + else{ + out += "error: invalid speed\n"; + } + } catch (ClassCastException ex){ + out += "unsupposed instruction for this interface\n"; + } catch (NumberFormatException ex) { + out += "error: invalid clock rate"; + } catch (InvalidNetworkInterfaceNameException ex) { + out += "error: invalid inferface\n"; + } + } + else{ + out += "error: invalid parameters\n"; + } + return out; + } + public String no_call(Vector<String> params){ + String out = ""; + if(params.size()==1){ + try { + ConsoleNetworkInterface cni = (ConsoleNetworkInterface)device.getNetworkInterface(params.get(0)); + cni.speed = ConsoleNetworkInterface.SPEED_DEFAULT; + } catch (ClassCastException ex){ + out += "unsupposed instruction for this interface\n"; + } catch (InvalidNetworkInterfaceNameException ex) { + out += "error: invalid inferface\n"; + } + } + else{ + out += "error: invalid parameters\n"; + } + return out; + } + }; class interface__ssid_CommandClass extends CommandInterface{ public interface__ssid_CommandClass(){ *************** *** 1522,1525 **** --- 1742,1798 ---- } }; + class interface__stopbits_CommandClass extends CommandInterface{ + public interface__stopbits_CommandClass(){ + modes = new Modes(CommandInterface.CONF_MODE, CommandInterface.NETWORK_LAYER, CommandInterface.NO_CALL); + call_params = "(1|1.5|2)"; + no_call_params = "<cr>"; + } + public String call(Vector<String> params){ + String out = ""; + if(params.size()==2){ + try { + ConsoleNetworkInterface cni = (ConsoleNetworkInterface)device.getNetworkInterface(params.get(0)); + String val = params.get(1); + if(val.equals("1")){ + cni.stopbits = ConsoleNetworkInterface.STOPBIT_1; + } + else if(val.equals("1.5")){ + cni.stopbits = ConsoleNetworkInterface.STOPBIT_15; + } + else if(val.equals("2")){ + cni.stopbits = ConsoleNetworkInterface.STOPBIT_2; + } + else{ + out += "error: invalid stopbits value\n"; + } + } catch (ClassCastException ex){ + out += "unsupposed instruction for this interface\n"; + } catch (NumberFormatException ex) { + out += "error: invalid clock rate"; + } catch (InvalidNetworkInterfaceNameException ex) { + out += "error: invalid inferface\n"; + } + } + else{ + out += "error: invalid parameters\n"; + } + return out; + } + public String no_call(Vector<String> params){ + String out = ""; + if(params.size()==1){ + try { + ConsoleNetworkInterface cni = (ConsoleNetworkInterface)device.getNetworkInterface(params.get(0)); + cni.stopbits = ConsoleNetworkInterface.STOPBIT_DEFAULT; + } catch (InvalidNetworkInterfaceNameException ex) { + out += "error: invalid inferface\n"; + } + } + else{ + out += "error: invalid parameters\n"; + } + return out; + } + }; class interface__switchport_access_vlan_CommandClass extends CommandInterface{ public interface__switchport_access_vlan_CommandClass(){ *************** *** 2537,2540 **** --- 2810,2856 ---- } }; + class ip_name_server_CommandClass extends CommandInterface{ + public ip_name_server_CommandClass(){ + modes = new Modes(CommandInterface.CONF_MODE, CommandInterface.APPLICATION_LAYER, CommandInterface.NO_CALL); + call_params = "<name-server ip-address>"; + no_call_params = "<cr>"; + } + public String call(Vector<String> params){ + String out = ""; + if(device instanceof ApplicationLayerDevice){ + if(params.size()==1){ + String ns = params.get(0); + if(IPV4Address.validateDecIP(ns)){ + ((ApplicationLayerDevice)device).setNameServer(ns); + } + else{ + out += "error: invalid IP address\n"; + } + } + else{ + out += "error: invalid parameters\n"; + } + } + else{ + out += "This instruction not supported by device\n"; + } + return out; + } + public String no_call(Vector<String> params){ + String out = ""; + if(device instanceof ApplicationLayerDevice){ + if(params.size()==0){ + ((ApplicationLayerDevice)device).setNameServer(""); + } + else{ + out += "error: invalid parameters\n"; + } + } + else{ + out += "This instruction not supported by device\n"; + } + return out; + } + }; /*class ip_nat_inside_destination_list_CommandClass extends CommandInterface{ public ip_nat_inside_destination_list_CommandClass(){ *************** *** 3483,3486 **** --- 3799,3830 ---- out += " Clock-rate " + ((SerialNetworkInterface)ni).getClockRate() + "\n"; } + if(ni instanceof ConsoleNetworkInterface){ + ConsoleNetworkInterface cni = (ConsoleNetworkInterface)ni; + out += " Databits " + cni.databits + "\n"; + String fc = ""; + switch(cni.flowcontrol){ + case ConsoleNetworkInterface.FLOWCONTROL_NONE: fc = "none"; break; + case ConsoleNetworkInterface.FLOWCONTROL_HARDWARE: fc = "hardware"; break; + case ConsoleNetworkInterface.FLOWCONTROL_SOFTWARE: fc = "software"; break; + } + out += " Flowcontrol " + fc + "\n"; + String pa = ""; + switch(cni.parity){ + case ConsoleNetworkInterface.PARITY_NONE: pa = "none"; break; + case ConsoleNetworkInterface.PARITY_EVEN: pa = "even"; break; + case ConsoleNetworkInterface.PARITY_ODD: pa = "odd"; break; + case ConsoleNetworkInterface.PARITY_MARK: pa = "mark"; break; + case ConsoleNetworkInterface.PARITY_SPACE: pa = "space"; break; + } + out += " Parity " + pa + "\n"; + String sb = ""; + switch(cni.stopbits){ + case ConsoleNetworkInterface.STOPBIT_1: sb = "1"; break; + case ConsoleNetworkInterface.STOPBIT_15: sb = "1.5"; break; + case ConsoleNetworkInterface.STOPBIT_2: sb = "2"; break; + } + out += " Stopbits " + sb + "\n"; + out += " Speed " + cni.speed + "\n"; + } out += "\n"; } catch (InvalidNetworkInterfaceNameException ex) { Index: NetworkInterface.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/core/NetworkInterface.java,v retrieving revision 1.21 retrieving revision 1.22 diff -C2 -d -r1.21 -r1.22 *** NetworkInterface.java 24 Oct 2008 16:18:48 -0000 1.21 --- NetworkInterface.java 26 Oct 2008 22:02:46 -0000 1.22 *************** *** 51,55 **** EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ! */ package core; --- 51,55 ---- EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ! */ package core; *************** *** 95,99 **** * @version v0.20 ! */ --- 95,99 ---- * @version v0.20 ! */ *************** *** 105,245 **** protected String name; ! /** The Link that this NetworkInterface is connected to */ protected Link connectedLink; protected Node parentNode; - - protected boolean up; - - 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; - } - - public void setDHCP(boolean inDHCP){ - dhcp = inDHCP; - } - - - protected String description = ""; - - public void setUP(){ - up = true; - } - - public void UP(){ - up = true; - LayerInfo pingInfo = new LayerInfo(getClass().getName()); - pingInfo.setObjectName(parentNode.getName()); - pingInfo.setDataType("Interface"); - pingInfo.setLayer("Link"); - pingInfo.setDescription("Interface " + name + " state set to up!"); - Simulation.addLayerInfo(pingInfo); - if( parentNode.NodeProtocolStack != null){ - parentNode.NodeProtocolStack.intUP(name); - } - } - - public void DOWN(){ - up = false; - LayerInfo pingInfo = new LayerInfo(getClass().getName()); - pingInfo.setObjectName(parentNode.getName()); - pingInfo.setDataType("Interface"); - pingInfo.setLayer("Link"); - pingInfo.setDescription("Interface " + name + " state set to down!"); - Simulation.addLayerInfo(pingInfo); - } - - public boolean isUP(){ - return up; - } - - public boolean isOn(){ - return parentNode.On; - } ! public final static int Unknown = 0; ! public final static int Ethernet10T = 0; ! public final static int Console = 1; ! public final static int Wireless = 2; ! public final static int WAN = 3; ! public final static int Serial = 4; ! public final static int Ethernet100FX = 5; ! ! public static String getIntName(int type){ ! switch(type){ ! case 0: ! return "eth"; ! case 1: ! return "cua"; ! case 2: ! return "wrl"; ! case 3: ! return "wan"; ! case 4: ! return "ser"; ! case 5: ! return "fib"; ! default: ! return "unk"; ! } ! } ! ! public final static int NO_NAT = 0; ! public final static int INSIDE_NAT = 1; ! public final static int OUTSIDE_NAT = 2; ! ! private int NAT_STATUS = 0; ! ! public void setNAT(int nat){ ! NAT_STATUS = nat; ! } ! ! public int getNAT(){ ! return NAT_STATUS; ! } ! ! public boolean isActive(){ ! return false; ! } ! ! public int getType(){ ! return -1; ! } ! ! /** ! * Constructs a NetworkInterface object with the name inName and a reference to it's parent Node. ! * @author tristan_veness ! * @param inName - The name to give the NetworkInterface eg: eth0 ! * @param parent - The Node that the NetworkInterface is to be added to, it's parent. ! * @version v0.10 - */ ! protected NetworkInterface(long UID, String inName, Node inParent) { ! super(UID); ! name = inName; parentNode = inParent; - - up = false; ! } --- 105,245 ---- protected String name; ! /** The Link that this NetworkInterface is connected to */ protected Link connectedLink; protected Node parentNode; ! protected boolean up; ! 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; ! } ! public void setDHCP(boolean inDHCP){ ! dhcp = inDHCP; ! } ! protected String description = ""; ! public void setUP(){ ! up = true; ! } ! ! public void UP(){ ! up = true; ! LayerInfo pingInfo = new LayerInfo(getClass().getName()); ! pingInfo.setObjectName(parentNode.getName()); ! pingInfo.setDataType("Interface"); ! pingInfo.setLayer("Link"); ! pingInfo.setDescription("Interface " + name + " state set to up!"); ! Simulation.addLayerInfo(pingInfo); ! if( parentNode.NodeProtocolStack != null){ ! parentNode.NodeProtocolStack.intUP(name); ! } ! } ! ! public void DOWN(){ ! up = false; ! LayerInfo pingInfo = new LayerInfo(getClass().getName()); ! pingInfo.setObjectName(parentNode.getName()); ! pingInfo.setDataType("Interface"); ! pingInfo.setLayer("Link"); ! pingInfo.setDescription("Interface " + name + " state set to down!"); ! Simulation.addLayerInfo(pingInfo); ! } ! ! public boolean isUP(){ ! return up; ! } ! ! public boolean isOn(){ ! return parentNode.On; ! } ! ! public final static int Unknown = 0; ! public final static int Ethernet10T = 0; ! public final static int Console = 1; ! public final static int Wireless = 2; ! public final static int WAN = 3; ! public final static int Serial = 4; ! public final static int Ethernet100FX = 5; ! ! public static String getIntName(int type){ ! switch(type){ ! case 0: ! return "eth"; ! case 1: ! return "cua"; ! case 2: ! return "wrl"; ! case 3: ! return "wan"; ! case 4: ! return "ser"; ! case 5: ! return "fib"; ! default: ! return "unk"; ! } ! } ! ! public final static int NO_NAT = 0; ! public final static int INSIDE_NAT = 1; ! public final static int OUTSIDE_NAT = 2; ! ! private int NAT_STATUS = 0; ! ! public void setNAT(int nat){ ! NAT_STATUS = nat; ! } ! ! public int getNAT(){ ! return NAT_STATUS; ! } ! ! public boolean isActive(){ ! return false; ! } ! ! public int getType(){ ! return -1; ! } ! ! /** ! ! * Constructs a NetworkInterface object with the name inName and a reference to it's parent Node. ! ! * @author tristan_veness ! ! * @param inName - The name to give the NetworkInterface eg: eth0 ! ! * @param parent - The Node that the NetworkInterface is to be added to, it's parent. ! ! * @version v0.10 ! ! */ ! ! protected NetworkInterface(long UID, String inName, Node inParent) { ! super(UID); ! ! name = inName; parentNode = inParent; ! up = false; ! ! } *************** *** 311,315 **** protected void receivePacket(Packet inPacket) throws LowLinkException {} ! /** --- 311,315 ---- protected void receivePacket(Packet inPacket) throws LowLinkException {} ! /** *************** *** 329,381 **** ! /** ! * Returns the NetworkInterface's name. ! * @author bevan_calliess ! * @return Name - The NetworkInterface's name ! * @version v0.20 ! */ - - public String getName() { ! return name; ! } ! - /** - * This method is used by interfaces to uniquely identify themselves ! * in the simulation it will return a combination of the ! * Parent naodes name and the Interfaces name ! * eg. Node name PC1 interface eth0 will return "PC1eth0" ! * @author bevan_calliess ! * @return Name - The Source name of this Node Interface ! * @version v0.20 ! */ ! protected String getSourceName() { ! return parentNode.getName()+":"+name; ! } ! ! /** * Sets the connectedLink attribute of the NetworkInterface with Link l. --- 329,381 ---- ! /** ! * Returns the NetworkInterface's name. ! * @author bevan_calliess ! * @return Name - The NetworkInterface's name ! * @version v0.20 ! */ ! public String getName() { ! return name; ! } ! /** ! * This method is used by interfaces to uniquely identify themselves ! * in the simulation it will return a combination of the ! * Parent naodes name and the Interfaces name ! * eg. Node name PC1 interface eth0 will return "PC1eth0" ! * @author bevan_calliess ! * @return Name - The Source name of this Node Interface ! * @version v0.20 ! */ ! protected String getSourceName() { ! return parentNode.getName()+":"+name; ! } ! ! ! ! /** * Sets the connectedLink attribute of the NetworkInterface with Link l. *************** *** 393,413 **** */ ! protected void setConnectedLink(Link l)throws InvalidLinkConnectionException { ! if(connectedLink == null){ ! connectedLink = l; ! }else ! throw new InvalidLinkConnectionException("Network Interface is already connected. Delete Connected link first"); - - } ! /** * Returns the Link that this NetworkInterface is connected to. --- 393,413 ---- */ ! protected void setConnectedLink(Link l)throws InvalidLinkConnectionException { ! if(connectedLink == null){ ! connectedLink = l; ! }else ! throw new InvalidLinkConnectionException("Network Interface is already connected. Delete Connected link first"); + } ! ! /** * Returns the Link that this NetworkInterface is connected to. *************** *** 421,539 **** */ ! public Link getConnectedLink() { ! return connectedLink; ! } - - protected String getConnectedLinkName() { ! if(connectedLink!=null) return connectedLink.getName(); ! else return null; ! } ! - /** - * This method returns the name of the network interface ! * @author tristan_veness ! * @return Name ! * @version v0.10 ! */ ! protected String getDetails(){ ! return name; ! } ! ! /** - * This method returns a string of information about if the network interface is connected of not. - * <P>This method is useful for a CLI or for debugging.</P> ! * @author tristan_veness ! * @return Name - Connection: link1 ! * @version v0.10 ! */ ! protected String getConnectLinkDetails(){ ! if(connectedLink != null){ ! return "Connection: "+ connectedLink.getName(); ! } ! return "Connection: Not connected"; ! } ! ! protected String getConnectLinkName() ! { - if(connectedLink !=null) - { ! return connectedLink.getName(); ! } ! return "Not Connected"; ! } ! ! public String getDescription(){ ! return description; ! } ! ! public void setDescription(String description){ ! 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 --- 421,543 ---- */ ! public Link getConnectedLink() { ! return connectedLink; ! } ! public String getConnectedLinkName() { ! if(connectedLink!=null) return connectedLink.getName(); ! else return null; ! } ! /** ! * This method returns the name of the network interface ! * @author tristan_veness ! * @return Name ! * @version v0.10 ! */ ! protected String getDetails(){ ! return name; ! } ! /** ! * This method returns a string of information about if the network interface is connected of not. ! * <P>This method is useful for a CLI or for debugging.</P> ! * @author tristan_veness ! * @return Name - Connection: link1 ! * @version v0.10 ! */ ! protected String getConnectLinkDetails(){ ! if(connectedLink != null){ ! return "Connection: "+ connectedLink.getName(); ! } ! return "Connection: Not connected"; ! } ! public String getConnectLinkName() ! { ! if(connectedLink !=null) ! { ! ! return connectedLink.getName(); ! ! } ! ! return "Not Connected"; ! ! } ! ! public String getDescription(){ ! return description; ! } ! ! public void setDescription(String description){ ! 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; ! } ! } ! ! public Node getParentNode() { ! return parentNode; ! } }//EOF Index: ApplicationLayerDevice.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/core/ApplicationLayerDevice.java,v retrieving revision 1.12 retrieving revision 1.13 diff -C2 -d -r1.12 -r1.13 *** ApplicationLayerDevice.java 24 Oct 2008 16:18:48 -0000 1.12 --- ApplicationLayerDevice.java 26 Oct 2008 22:02:46 -0000 1.13 *************** *** 10,15 **** --- 10,19 ---- import java.util.Enumeration; import java.util.Hashtable; + import java.util.Vector; import core.protocolsuite.tcp_ip.Application; + import core.protocolsuite.tcp_ip.DNS; + import core.protocolsuite.tcp_ip.DNS_Message; + import core.protocolsuite.tcp_ip.IPV4Address; /** *************** *** 37,54 **** public final static int RIP_SERVER_ID = 520; ! protected Hashtable Apps = null; ! protected Hashtable userlist = new Hashtable(); /** Creates a new instance of ApplicationLayerDevice */ public ApplicationLayerDevice(String inName, int inProtocolStackLayers, boolean inOn) { super(inName, inProtocolStackLayers, inOn); ! Apps = new Hashtable(); if(inOn) initApplications(); } ! public void addApp(Object app, int code){ Apps.put(code, app); } ! public Object getApp(int code){ if(Apps==null) return null; return Apps.get(code); --- 41,59 ---- public final static int RIP_SERVER_ID = 520; ! protected Hashtable<Integer, Application> Apps = null; ! protected Hashtable<String,String> userlist = new Hashtable<String,String>(); ! private String nameServer = ""; /** Creates a new instance of ApplicationLayerDevice */ public ApplicationLayerDevice(String inName, int inProtocolStackLayers, boolean inOn) { super(inName, inProtocolStackLayers, inOn); ! Apps = new Hashtable<Integer, Application>(); if(inOn) initApplications(); } ! public void addApp(Application app, int code){ Apps.put(code, app); } ! public Application getApp(int code){ if(Apps==null) return null; return Apps.get(code); *************** *** 98,102 **** public String getUserPassword(String username){ if(userlist==null) return null; ! return (String)userlist.get(username); } --- 103,107 ---- public String getUserPassword(String username){ if(userlist==null) return null; ! return userlist.get(username); } *************** *** 105,108 **** --- 110,149 ---- return userlist.keys(); } + + public boolean setNameServer(String ns){ + if(IPV4Address.validateDecIP(ns)){ + nameServer = ns; + return true; + } + return false; + } + + public String getNameServer(){ + return nameServer; + } + + public Vector<String> resolve(String name){ + Vector<String> out = new Vector<String>(); + if(nameServer!=""){ + DNS dns = (DNS)this.getApp(core.ApplicationLayerDevice.DNS_CLIENT_ID); + int id; + try { + id = dns.SendMessage(nameServer, 53, name, DNS_Message.A_QUERY_TYPE); + if(dns.receivedMessages.containsKey(id)){ + DNS_Message dnsMes = dns.receivedMessages.get(id); + Vector<DNS_Message.Answer> answer = dnsMes.getAnswer(); + for(int i=0; i<answer.size(); i++){ + DNS_Message.Answer ans = answer.get(i); + out.add(ans.resource); + } + } + } catch (CommunicationException e) { + } catch (LowLinkException e) { + } catch (InvalidNetworkLayerDeviceException e) { + } catch (TransportLayerException e) { + } + } + return out; + } } |