[Javanetsim-cvs] javaNetSim/core ApplicationLayerDevice.java, 1.4, 1.5 CommandProcessor.java, 1.3,
Status: Beta
Brought to you by:
darkkey
Update of /cvsroot/javanetsim/javaNetSim/core In directory sc8-pr-cvs6.sourceforge.net:/tmp/cvs-serv17243/core Modified Files: ApplicationLayerDevice.java CommandProcessor.java CommandsTree.java DeviceConfig.java Node.java PC.java Log Message: add interface commands into console fixed TCP.closePort & UDP.closePort Index: CommandProcessor.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/core/CommandProcessor.java,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** CommandProcessor.java 14 Oct 2007 22:14:52 -0000 1.3 --- CommandProcessor.java 15 Oct 2007 21:41:42 -0000 1.4 *************** *** 14,17 **** --- 14,18 ---- import core.protocolsuite.tcp_ip.SNMP; import core.protocolsuite.tcp_ip.TCP_session; + import core.protocolsuite.tcp_ip.Telnet_server; import core.protocolsuite.tcp_ip.UDP_session; import core.protocolsuite.tcp_ip.jnSocket; *************** *** 51,54 **** --- 52,79 ---- private host_CommandClass host_Command = new host_CommandClass(); private reload_CommandClass reload_Command = new reload_CommandClass(); + private interface__description_CommandClass interface__description_Command = new interface__description_CommandClass(); + private interface__clock_rate_CommandClass interface__clock_rate_Command = new interface__clock_rate_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(); + private interface__ip_nat_CommandClass interface__ip_nat_Command = new interface__ip_nat_CommandClass(); + private interface__ip_unreachables_CommandClass interface__ip_unreachables_Command = new interface__ip_unreachables_CommandClass(); + private interface__ip_redirects_CommandClass interface__ip_redirects_Command = new interface__ip_redirects_CommandClass(); + private interface__ip_mask_replay_CommandClass interface__ip_mask_replay_Command = new interface__ip_mask_replay_CommandClass(); + private interface__ip_information_replay_CommandClass interface__ip_information_replay_Command = new interface__ip_information_replay_CommandClass(); + 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__shutdown_CommandClass interface__shutdown_Command = new interface__shutdown_CommandClass(); + private no_interface__description_CommandClass no_interface__description_Command = new no_interface__description_CommandClass(); + private no_interface__clock_rate_CommandClass no_interface__clock_rate_Command = new no_interface__clock_rate_CommandClass(); + private no_interface__ip_address_CommandClass no_interface__ip_address_Command = new no_interface__ip_address_CommandClass(); + private no_interface__ip_access_group_CommandClass no_interface__ip_access_group_Command = new no_interface__ip_access_group_CommandClass(); + private no_interface__ip_nat_CommandClass no_interface__ip_nat_Command = new no_interface__ip_nat_CommandClass(); + private no_interface__ip_unreachables_CommandClass no_interface__ip_unreachables_Command = new no_interface__ip_unreachables_CommandClass(); + private no_interface__ip_redirects_CommandClass no_interface__ip_redirects_Command = new no_interface__ip_redirects_CommandClass(); + private no_interface__ip_mask_replay_CommandClass no_interface__ip_mask_replay_Command = new no_interface__ip_mask_replay_CommandClass(); + private no_interface__ip_information_replay_CommandClass no_interface__ip_information_replay_Command = new no_interface__ip_information_replay_CommandClass(); + private no_interface__ip_dhcp_client_CommandClass no_interface__ip_dhcp_client_Command = new no_interface__ip_dhcp_client_CommandClass(); + private no_interface__mac_address_CommandClass no_interface__mac_address_Command = new no_interface__mac_address_CommandClass(); + private no_interface__shutdown_CommandClass no_interface__shutdown_Command = new no_interface__shutdown_CommandClass(); private ip_route_CommandClass ip_route_Command = new ip_route_CommandClass(); private no_ip_route_CommandClass no_ip_route_Command = new no_ip_route_CommandClass(); *************** *** 86,89 **** --- 111,115 ---- private telnet_CommandClass telnet_Command = new telnet_CommandClass(); private telnet_server_CommandClass telnet_server_Command = new telnet_server_CommandClass(); + private no_telnet_server_CommandClass no_telnet_server_Command = new no_telnet_server_CommandClass(); private traceroute_CommandClass traceroute_Command = new traceroute_CommandClass(); private write_memory_CommandClass write_memory_Command = new write_memory_CommandClass(); *************** *** 101,104 **** --- 127,131 ---- commands.addDescription("clock","Manage the system clock"); commands.add("clock set", clock_set_Command, STD_CONF_MODE | NO_LAYER, "<hh:mm:ss> <1-31> <1-12> <1970-2100>", "Set the time and date"); + commands.addDescription("copy","Copy confuguration files"); commands.add("copy running-config startup-config", copy_running_startup_Command, STD_CONF_MODE | NO_LAYER, "<src-config> <dest-config>", "Copy from one file to another"); commands.add("copy startup-config running-config", copy_startup_running_Command, STD_CONF_MODE | NO_LAYER, "<src-config> <dest-config>", "Copy from one file to another"); *************** *** 109,112 **** --- 136,175 ---- commands.add("host", host_Command, CONF_MODE | NETWORK_LAYER, "(<interface> <ip> | <hostname>)", "Set system's network name or IP-address"); commands.add("reload", reload_Command, STD_MODE | NO_LAYER, "<cr>", "Halt and perform a cold restart"); + + + commands.addDescription("interface","Select an interface to configure"); + commands.addDescription("interface *","Any available interface name"); + commands.add("interface * description", interface__description_Command, CONF_MODE | NETWORK_LAYER, "<description>", "Interface specific description"); + commands.add("interface * clock-rate", interface__clock_rate_Command, CONF_MODE | NETWORK_LAYER, "<1-4000000>", "Specify clock-rate"); + commands.addDescription("interface * ip","Configure Internet Protocol"); + commands.add("interface * ip address", interface__ip_address_Command, CONF_MODE | NETWORK_LAYER, "<ip address> <net mask>", "Set the IP address of an interface"); + commands.add("interface * ip access-group", interface__ip_access_group_Command, CONF_MODE | NETWORK_LAYER, "<acl name> (in|out)", "Specify access control for packets"); + commands.add("interface * ip nat", interface__ip_nat_Command, CONF_MODE | NETWORK_LAYER, "(inside|outside)", "NAT interface commands"); + commands.add("interface * ip unreachables", interface__ip_unreachables_Command, CONF_MODE | NETWORK_LAYER, "<cr>", "Enable sending ICMP Unreachable messages"); + commands.add("interface * ip redirects", interface__ip_redirects_Command, CONF_MODE | NETWORK_LAYER, "<cr>", "Enable sending ICMP Redirect messages"); + commands.add("interface * ip mask-replay", interface__ip_mask_replay_Command, CONF_MODE | NETWORK_LAYER, "<cr>", "Enable sending ICMP Mask Reply messages"); + commands.add("interface * ip information-replay", interface__ip_information_replay_Command, CONF_MODE | NETWORK_LAYER, "<cr>", "Enable sending ICMP Information Reply messages"); + commands.addDescription("interface * dhcp","Configure DHCP parameters for this interface"); + commands.add("interface * ip dhcp client", interface__ip_dhcp_client_Command, CONF_MODE | NETWORK_LAYER, "<cr>", "Enable DHCP client"); + commands.add("interface * mac-address", interface__mac_address_Command, CONF_MODE | NETWORK_LAYER, "<MAC>", "Manually set interface MAC address"); + commands.add("interface * shutdown", interface__shutdown_Command, CONF_MODE | NETWORK_LAYER, "<cr>", "Shutdown the selected interface"); + + commands.addDescription("no interface","Select an interface to configure"); + commands.addDescription("no interface *","Any available interface name"); + commands.add("no interface * description", no_interface__description_Command, CONF_MODE | NETWORK_LAYER, "<cr>", "Clear interface description"); + commands.add("no interface * clock-rate", no_interface__clock_rate_Command, CONF_MODE | NETWORK_LAYER, "<cr>", "Set clock-rate to default"); + commands.addDescription("no interface * ip","Configure Internet Protocol"); + commands.add("no interface * ip address", no_interface__ip_address_Command, CONF_MODE | NETWORK_LAYER, "<cr>", "Set the IP address of an interface to default"); + commands.add("no interface * ip access-group", no_interface__ip_access_group_Command, CONF_MODE | NETWORK_LAYER, "<acl name> (in|out)", "Disable access control for packets"); + commands.add("no interface * ip nat", no_interface__ip_nat_Command, CONF_MODE | NETWORK_LAYER, "(inside|outside)", "Disable NAT on interface"); + commands.add("no interface * ip unreachables", no_interface__ip_unreachables_Command, CONF_MODE | NETWORK_LAYER, "<cr>", "Disable sending ICMP Unreachable messages"); + commands.add("no interface * ip redirects", no_interface__ip_redirects_Command, CONF_MODE | NETWORK_LAYER, "<cr>", "Disable sending ICMP Redirect messages"); + commands.add("no interface * ip mask-replay", no_interface__ip_mask_replay_Command, CONF_MODE | NETWORK_LAYER, "<cr>", "Disable sending ICMP Mask Reply messages"); + commands.add("no interface * ip information-replay", no_interface__ip_information_replay_Command, CONF_MODE | NETWORK_LAYER, "<cr>", "Disable sending ICMP Information Reply messages"); + commands.addDescription("no interface * dhcp","Configure DHCP parameters for this interface"); + commands.add("no interface * ip dhcp client", no_interface__ip_dhcp_client_Command, CONF_MODE | NETWORK_LAYER, "<cr>", "Disable DHCP client"); + commands.add("no interface * mac-address", no_interface__mac_address_Command, CONF_MODE | NETWORK_LAYER, "<cr>", "Set interface MAC address to default"); + commands.add("no interface * shutdown", no_interface__shutdown_Command, CONF_MODE | NETWORK_LAYER, "<cr>", "Up the selected interface"); + commands.addDescription("ip","Global IP configuration subcommands"); commands.addDescription("no ip","Global IP configuration subcommands"); *************** *** 152,156 **** commands.add("snmp-server port", snmp_server_port_Command, CONF_MODE | APPLICATION_LAYER, "<port>", "Specify server port"); commands.add("telnet", telnet_Command, STD_CONF_MODE | APPLICATION_LAYER, "<IP>", "Open a telnet connection"); ! commands.add("telnet-server", telnet_server_Command, CONF_MODE | APPLICATION_LAYER, "<port>", "Enable TELNET; Specify server port"); commands.add("traceroute", traceroute_Command, STD_CONF_MODE | NETWORK_LAYER, "<IP>", "Trace route to destination"); commands.addDescription("write","Write running configuration to memory or terminal"); --- 215,220 ---- commands.add("snmp-server port", snmp_server_port_Command, CONF_MODE | APPLICATION_LAYER, "<port>", "Specify server port"); commands.add("telnet", telnet_Command, STD_CONF_MODE | APPLICATION_LAYER, "<IP>", "Open a telnet connection"); ! commands.add("telnet-server", telnet_server_Command, CONF_MODE | APPLICATION_LAYER, "<port>", "Enable TELNET server; Specify server port"); ! commands.add("no telnet-server", no_telnet_server_Command, CONF_MODE | APPLICATION_LAYER, "<cr>", "Disable TELNET server"); commands.add("traceroute", traceroute_Command, STD_CONF_MODE | NETWORK_LAYER, "<IP>", "Trace route to destination"); commands.addDescription("write","Write running configuration to memory or terminal"); *************** *** 315,318 **** --- 379,526 ---- } }; + class interface__description_CommandClass implements CommandInterface{ + public String call(Vector<String> params){ + String out = ""; + return out; + } + }; + class interface__clock_rate_CommandClass implements CommandInterface{ + public String call(Vector<String> params){ + String out = ""; + return out; + } + }; + class interface__ip_access_group_CommandClass implements CommandInterface{ + public String call(Vector<String> params){ + String out = ""; + return out; + } + }; + class interface__ip_address_CommandClass implements CommandInterface{ + public String call(Vector<String> params){ + String out = ""; + return out; + } + }; + class interface__ip_nat_CommandClass implements CommandInterface{ + public String call(Vector<String> params){ + String out = ""; + return out; + } + }; + class interface__ip_unreachables_CommandClass implements CommandInterface{ + public String call(Vector<String> params){ + String out = ""; + return out; + } + }; + class interface__ip_redirects_CommandClass implements CommandInterface{ + public String call(Vector<String> params){ + String out = ""; + return out; + } + }; + class interface__ip_mask_replay_CommandClass implements CommandInterface{ + public String call(Vector<String> params){ + String out = ""; + return out; + } + }; + class interface__ip_information_replay_CommandClass implements CommandInterface{ + public String call(Vector<String> params){ + String out = ""; + return out; + } + }; + class interface__ip_dhcp_client_CommandClass implements CommandInterface{ + public String call(Vector<String> params){ + String out = ""; + return out; + } + }; + class interface__mac_address_CommandClass implements CommandInterface{ + public String call(Vector<String> params){ + String out = ""; + return out; + } + }; + class interface__shutdown_CommandClass implements CommandInterface{ + public String call(Vector<String> params){ + String out = ""; + return out; + } + }; + class no_interface__description_CommandClass implements CommandInterface{ + public String call(Vector<String> params){ + String out = ""; + return out; + } + }; + class no_interface__clock_rate_CommandClass implements CommandInterface{ + public String call(Vector<String> params){ + String out = ""; + return out; + } + }; + class no_interface__ip_address_CommandClass implements CommandInterface{ + public String call(Vector<String> params){ + String out = ""; + return out; + } + }; + class no_interface__ip_access_group_CommandClass implements CommandInterface{ + public String call(Vector<String> params){ + String out = ""; + return out; + } + }; + class no_interface__ip_nat_CommandClass implements CommandInterface{ + public String call(Vector<String> params){ + String out = ""; + return out; + } + }; + class no_interface__ip_unreachables_CommandClass implements CommandInterface{ + public String call(Vector<String> params){ + String out = ""; + return out; + } + }; + class no_interface__ip_redirects_CommandClass implements CommandInterface{ + public String call(Vector<String> params){ + String out = ""; + return out; + } + }; + class no_interface__ip_mask_replay_CommandClass implements CommandInterface{ + public String call(Vector<String> params){ + String out = ""; + return out; + } + }; + class no_interface__ip_information_replay_CommandClass implements CommandInterface{ + public String call(Vector<String> params){ + String out = ""; + return out; + } + }; + class no_interface__ip_dhcp_client_CommandClass implements CommandInterface{ + public String call(Vector<String> params){ + String out = ""; + return out; + } + }; + class no_interface__mac_address_CommandClass implements CommandInterface{ + public String call(Vector<String> params){ + String out = ""; + return out; + } + }; + class no_interface__shutdown_CommandClass implements CommandInterface{ + public String call(Vector<String> params){ + String out = ""; + return out; + } + }; class ip_route_CommandClass implements CommandInterface{ public String call(Vector<String> params){ *************** *** 629,637 **** class snmp_server_community_CommandClass implements CommandInterface{ public String call(Vector<String> params){ ! return "Command not supported yet.\n"; } }; class no_snmp_server_community_CommandClass implements CommandInterface{ public String call(Vector<String> params){ return "Command not supported yet.\n"; } --- 837,869 ---- class snmp_server_community_CommandClass implements CommandInterface{ public String call(Vector<String> params){ ! String out = ""; ! if(params.size()==1){ ! SNMP snmpa = (SNMP) ((core.ApplicationLayerDevice)device).getApp(core.PC.SNMP_AGENT_ID); ! try{ ! snmpa.Close(); ! }catch(TransportLayerException e) { } ! snmpa.setPassword(params.get(0)); ! try{ ! snmpa.Listen(); ! } ! catch(TransportLayerException e) { ! out+="SNMP agent: unable to listen\n"; ! } ! device.getConfig().remove("^snmp server community .*"); ! device.getConfig().add("snmp server community",params); ! } ! return out; } }; class no_snmp_server_community_CommandClass implements CommandInterface{ public String call(Vector<String> params){ + String out = ""; + if(params.size() == 0){ + SNMP snmpa = (SNMP) ((core.ApplicationLayerDevice)device).getApp(core.PC.SNMP_AGENT_ID); + try{ + snmpa.Close(); + }catch(TransportLayerException e) { } + device.getConfig().remove("^snmp server community .*"); + } return "Command not supported yet.\n"; } *************** *** 639,643 **** class snmp_server_port_CommandClass implements CommandInterface{ public String call(Vector<String> params){ ! return "Command not supported yet.\n"; } }; --- 871,896 ---- class snmp_server_port_CommandClass implements CommandInterface{ public String call(Vector<String> params){ ! String out = ""; ! if(params.size()==1){ ! SNMP snmpa = (SNMP) ((core.ApplicationLayerDevice)device).getApp(core.PC.SNMP_AGENT_ID); ! try{ ! snmpa.Close(); ! }catch(TransportLayerException e) { } ! try{ ! int port = Integer.parseInt(params.get(0)); ! snmpa.setPort(port); ! try{ ! snmpa.Listen(); ! } ! catch(TransportLayerException e) { ! out+="SNMP agent: unable to listen\n"; ! } ! device.getConfig().remove("^snmp server port .*"); ! device.getConfig().add("snmp server port",params); ! }catch(NumberFormatException e){ ! out += "Invalid parameters\n"; ! } ! } ! return out; } }; *************** *** 649,653 **** class telnet_server_CommandClass implements CommandInterface{ public String call(Vector<String> params){ ! return "Command not supported yet.\n"; } }; --- 902,940 ---- class telnet_server_CommandClass implements CommandInterface{ public String call(Vector<String> params){ ! String out = ""; ! if(params.size()==1){ ! Telnet_server snmpa = (Telnet_server) ((core.ApplicationLayerDevice)device).getApp(core.PC.TELNET_SERVER_ID); ! try{ ! snmpa.Close(); ! }catch(TransportLayerException e) { } ! try{ ! int port = Integer.parseInt(params.get(0)); ! snmpa.setPort(port); ! try{ ! snmpa.Listen(); ! } ! catch(TransportLayerException e) { ! out+="Telnet server: unable to listen\n"; ! } ! device.getConfig().remove("^telnet server .*"); ! device.getConfig().add("telnet server",params); ! }catch(NumberFormatException e){ ! out += "Invalid parameters\n"; ! } ! } ! return out; ! } ! }; ! class no_telnet_server_CommandClass implements CommandInterface{ ! public String call(Vector<String> params){ ! String out = ""; ! if(params.size()==0){ ! Telnet_server snmpa = (Telnet_server) ((core.ApplicationLayerDevice)device).getApp(core.PC.TELNET_SERVER_ID); ! try{ ! snmpa.Close(); ! }catch(TransportLayerException e) { } ! device.getConfig().remove("^telnet server .*"); ! } ! return out; } }; Index: DeviceConfig.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/core/DeviceConfig.java,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** DeviceConfig.java 14 Oct 2007 22:14:52 -0000 1.3 --- DeviceConfig.java 15 Oct 2007 21:41:42 -0000 1.4 *************** *** 85,90 **** */ public boolean add(String command, Vector<String> params){ String fullcmd = createCommand(command, params); ! return add(fullcmd); } --- 85,94 ---- */ 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); } *************** *** 93,105 **** */ public boolean add(String command){ boolean result = false; LinkedList config = getConfig(working_config); - Iterator<String> it = config.iterator(); boolean found = false; ! while(it.hasNext() && !found){ ! found = (command.compareToIgnoreCase(it.next())==0); } if(!found){ ! config.add(command); result = true; } --- 97,124 ---- */ public boolean add(String command){ + return addBefore(command, null); + } + + public boolean addBefore(String command, String beforeCommand){ boolean result = false; LinkedList config = getConfig(working_config); 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; ! } ! if(command.compareToIgnoreCase((String)config.get(i))==0){ ! found = true; ! } } if(!found){ ! if(beforeCommand==null){ ! config.add(command); ! } ! else{ ! config.add(index, command); ! } result = true; } *************** *** 107,144 **** } - // /** 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' * --- 126,129 ---- Index: CommandsTree.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/core/CommandsTree.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** CommandsTree.java 12 Oct 2007 21:06:39 -0000 1.1 --- CommandsTree.java 15 Oct 2007 21:41:42 -0000 1.2 *************** *** 30,33 **** --- 30,34 ---- public static final int LAYERS = APPLICATION_LAYER; public static final int ALLMODE = MODES | LAYERS; + public static final String ANYWORD = "*"; CommandNode root = new CommandNode("."); *************** *** 73,88 **** boolean allFounds = false; int cmdsize = command.length(); for(int i=0; i<tree.size() && !allFounds; i++){ CommandNode node = (CommandNode)tree.get(i); String nodename = node.getName(); ! 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)); } ! else if(cmp < 0){ ! allFounds = true; } } } return nodes; --- 74,98 ---- boolean allFounds = false; int cmdsize = command.length(); + CommandNode anywordNode = null; for(int i=0; i<tree.size() && !allFounds; i++){ CommandNode node = (CommandNode)tree.get(i); String nodename = node.getName(); ! if(!nodename.equals(ANYWORD)){ ! 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)); ! } ! else if(cmp < 0){ ! allFounds = true; ! } } ! else{ ! anywordNode = (CommandNode)tree.get(i);; } } + if(nodes.size()==0 && anywordNode!=null){ + nodes.add(anywordNode); + } } return nodes; Index: PC.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/core/PC.java,v retrieving revision 1.14 retrieving revision 1.15 diff -C2 -d -r1.14 -r1.15 *** PC.java 15 Oct 2007 12:04:32 -0000 1.14 --- PC.java 15 Oct 2007 21:41:42 -0000 1.15 *************** *** 86,117 **** class PC extends ApplicationLayerDevice { ! ! - /** - * Constructs a PC with the specified name. - * @author tristan_veness - * @param inName - A name to give the new PC Node. eg: PC1 - * @version v0.10 - */ - protected PC(String inName) { - super(inName,7); ! ! Echo echoServer = new Echo(NodeProtocolStack, 7, 1, core.ProtocolStack.UIDGen++); - Echo echoClient = new Echo(NodeProtocolStack, 0, 0, core.ProtocolStack.UIDGen++); - Echo_tcp echotcpServer = new Echo_tcp(NodeProtocolStack, 17, 1, core.ProtocolStack.UIDGen++); - Echo_tcp echotcpClient = new Echo_tcp(NodeProtocolStack, 0, 0, core.ProtocolStack.UIDGen++); --- 86,123 ---- class PC extends ApplicationLayerDevice { ! public final static int ECHO_SERVER_ID = 7; ! public final static int ECHO_CLIENT_ID = 30007; ! public final static int ECHO_TCP_SERVER_ID = 17; ! public final static int ECHO_TCP_CLIENT_ID = 30017; ! public final static int TELNET_SERVER_ID = 23; ! public final static int TELNET_CLIENT_ID = 30023; ! public final static int POSIX_TELNET_CLIENT_ID = 10023; ! public final static int SNMP_AGENT_ID = 161; ! public final static int SNMP_MANAGER_ID = 30161; ! public final static int DHCP_SERVER_ID = 67; ! public final static int DHCP_CLIENT_ID = 68; /** * Constructs a PC with the specified name. * @author tristan_veness * @param inName - A name to give the new PC Node. eg: PC1 * @version v0.10 */ protected PC(String inName) { super(inName,7); + //initApplications() have been called in ApplicaitonLayerDevice + addNetworkInterface(NetworkInterface.getIntName(NetworkInterface.Ethernet10T) + "0", NetworkInterface.Ethernet10T, true); + addNetworkInterface(NetworkInterface.getIntName(NetworkInterface.Console) + "0", NetworkInterface.Console, false); + //addNetworkInterface(NetworkInterface.getIntName(NetworkInterface.Wireless) + "0", NetworkInterface.Wireless, true); + //addNetworkInterface(NetworkInterface.getIntName(NetworkInterface.WAN) + "0" + "_" + (int)(Math.random()*1000), NetworkInterface.WAN, true); ! } ! ! public void initApplications(){ ! super.initApplications(); ! Echo echoServer = new Echo(NodeProtocolStack, 7, 1, core.ProtocolStack.UIDGen++); Echo echoClient = new Echo(NodeProtocolStack, 0, 0, core.ProtocolStack.UIDGen++); Echo_tcp echotcpServer = new Echo_tcp(NodeProtocolStack, 17, 1, core.ProtocolStack.UIDGen++); Echo_tcp echotcpClient = new Echo_tcp(NodeProtocolStack, 0, 0, core.ProtocolStack.UIDGen++); *************** *** 120,124 **** Telnet_server telnetServer = new Telnet_server((ApplicationLayerDevice)this, NodeProtocolStack, 23, 1, core.ProtocolStack.UIDGen++); - Telnet_client telnetClient = new Telnet_client((ApplicationLayerDevice)this, NodeProtocolStack, 0, 0, core.ProtocolStack.UIDGen++); --- 126,129 ---- *************** *** 128,155 **** DHCPC dhcpc = new DHCPC(NodeProtocolStack, core.ProtocolStack.UIDGen++); ! addApp(echoServer, 7); ! ! addApp(ptc, 10023); ! ! addApp(echoClient, 30007); ! addApp(echotcpServer, 17); ! addApp(echotcpClient, 30017); ! addApp(telnetServer, 23); ! addApp(telnetClient, 30023); ! addApp(snmpAgent, 161); ! addApp(snmpManager, 30161); ! addApp(dhcpd, 67); ! addApp(dhcpc, 68); ! ! addNetworkInterface(NetworkInterface.getIntName(NetworkInterface.Ethernet10T) + "0", NetworkInterface.Ethernet10T, true); ! addNetworkInterface(NetworkInterface.getIntName(NetworkInterface.Console) + "0", NetworkInterface.Console, false); ! //addNetworkInterface(NetworkInterface.getIntName(NetworkInterface.Wireless) + "0", NetworkInterface.Wireless, true); ! //addNetworkInterface(NetworkInterface.getIntName(NetworkInterface.WAN) + "0" + "_" + (int)(Math.random()*1000), NetworkInterface.WAN, true); ! } --- 133,152 ---- DHCPC dhcpc = new DHCPC(NodeProtocolStack, core.ProtocolStack.UIDGen++); ! addApp(echoServer, ECHO_SERVER_ID); ! addApp(echoClient, ECHO_CLIENT_ID); ! addApp(echotcpServer, ECHO_TCP_SERVER_ID); ! addApp(echotcpClient, ECHO_TCP_CLIENT_ID); ! addApp(telnetServer, TELNET_SERVER_ID); ! addApp(telnetClient, TELNET_CLIENT_ID); + addApp(ptc, POSIX_TELNET_CLIENT_ID); ! addApp(snmpAgent, SNMP_AGENT_ID); ! addApp(snmpManager, SNMP_MANAGER_ID); ! addApp(dhcpd, DHCP_SERVER_ID); ! addApp(dhcpc, DHCP_CLIENT_ID); } Index: Node.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/core/Node.java,v retrieving revision 1.12 retrieving revision 1.13 diff -C2 -d -r1.12 -r1.13 *** Node.java 15 Oct 2007 12:04:32 -0000 1.12 --- Node.java 15 Oct 2007 21:41:42 -0000 1.13 *************** *** 169,173 **** //Creates a protocolstack of that type. if(Simulation.getProtocolType() == ProtocolStack.TCP_IP){ ! NodeProtocolStack = new core.protocolsuite.tcp_ip.ProtocolStack(this,inProtocolStackLayers); }else if(Simulation.getProtocolType() == ProtocolStack.APPLETALK){ //NodeProtocolStack = new core.protocolsuite.appletalk.ProtocolStack(this); //Not implemented --- 169,173 ---- //Creates a protocolstack of that type. if(Simulation.getProtocolType() == ProtocolStack.TCP_IP){ ! NodeProtocolStack = new core.protocolsuite.tcp_ip.ProtocolStack(this,inProtocolStackLayers); }else if(Simulation.getProtocolType() == ProtocolStack.APPLETALK){ //NodeProtocolStack = new core.protocolsuite.appletalk.ProtocolStack(this); //Not implemented Index: ApplicationLayerDevice.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/core/ApplicationLayerDevice.java,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** ApplicationLayerDevice.java 15 Oct 2007 12:04:32 -0000 1.4 --- ApplicationLayerDevice.java 15 Oct 2007 21:41:42 -0000 1.5 *************** *** 20,26 **** /** Creates a new instance of ApplicationLayerDevice */ public ApplicationLayerDevice(String inName, int inProtocolStackLayers) { ! super(inName, inProtocolStackLayers); ! Apps = new Hashtable(); ! } public void addApp(Object app, int code){ --- 20,27 ---- /** Creates a new instance of ApplicationLayerDevice */ public ApplicationLayerDevice(String inName, int inProtocolStackLayers) { ! super(inName, inProtocolStackLayers); ! Apps = new Hashtable(); ! initApplications(); ! } public void addApp(Object app, int code){ *************** *** 34,37 **** --- 35,39 ---- public void turnOn(){ super.turnOn(); + initApplications(); } *************** *** 39,51 **** Enumeration<Application> ap = Apps.elements(); while(ap.hasMoreElements()){ try{ ! ap.nextElement().Free(); }catch(TransportLayerException e){ e.printStackTrace(); - } } super.turnOff(); } } --- 41,61 ---- Enumeration<Application> ap = Apps.elements(); while(ap.hasMoreElements()){ + Application appl = ap.nextElement(); try{ ! appl.Free(); }catch(TransportLayerException e){ e.printStackTrace(); } + // catch(Exception e){ + // System.out.println("Application "+appl.getUID()+" throws exception"); + // e.printStackTrace(); + // } } super.turnOff(); } + + public void initApplications(){ + + } } |