javanetsim-cvs Mailing List for javaNetSim (Page 4)
Status: Beta
Brought to you by:
darkkey
You can subscribe to this list here.
2005 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
(120) |
Dec
(62) |
---|---|---|---|---|---|---|---|---|---|---|---|---|
2006 |
Jan
(1) |
Feb
(69) |
Mar
(3) |
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
(76) |
Oct
(28) |
Nov
(77) |
Dec
(186) |
2007 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
(36) |
Oct
(61) |
Nov
(23) |
Dec
|
2008 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
(17) |
Oct
(105) |
Nov
(5) |
Dec
(1) |
2009 |
Jan
|
Feb
(4) |
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
(8) |
Oct
(9) |
Nov
|
Dec
|
From: QweR <qw...@us...> - 2008-10-19 21:40:29
|
Update of /cvsroot/javanetsim/javaNetSim/guiUI In directory fdv4jf1.ch3.sourceforge.com:/tmp/cvs-serv17182/guiUI Modified Files: Terminal.java Log Message: vlan command was added Index: Terminal.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/guiUI/Terminal.java,v retrieving revision 1.18 retrieving revision 1.19 diff -C2 -d -r1.18 -r1.19 *** Terminal.java 18 Oct 2008 19:55:31 -0000 1.18 --- Terminal.java 19 Oct 2008 21:40:19 -0000 1.19 *************** *** 490,494 **** if(dns!=null){ if(params.size()==2 || params.size()==3){ ! String host = params.get(0); String server[] = params.get(1).split(":"); int qtype = 0; --- 490,494 ---- if(dns!=null){ if(params.size()==2 || params.size()==3){ ! String host = params.get(0).toLowerCase(); String server[] = params.get(1).split(":"); int qtype = 0; |
From: QweR <qw...@us...> - 2008-10-19 21:40:29
|
Update of /cvsroot/javanetsim/javaNetSim/core/protocolsuite/tcp_ip In directory fdv4jf1.ch3.sourceforge.com:/tmp/cvs-serv17182/core/protocolsuite/tcp_ip Modified Files: DHCPD.java DNS.java IPV4Address.java Log Message: vlan command was added Index: DNS.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/core/protocolsuite/tcp_ip/DNS.java,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** DNS.java 18 Oct 2008 19:55:31 -0000 1.3 --- DNS.java 19 Oct 2008 21:40:19 -0000 1.4 *************** *** 155,159 **** if (Connect (host, port)) { ! SendData(mess+":"+Integer.toString(qType)); return last_sent_id; } --- 155,159 ---- if (Connect (host, port)) { ! SendData(mess.toLowerCase()+":"+Integer.toString(qType)); return last_sent_id; } *************** *** 355,358 **** --- 355,359 ---- public void addRecord(String dname, String value, int type){ + dname = dname.toLowerCase(); switch(type){ case DNS_Message.A_QUERY_TYPE: { *************** *** 364,373 **** } if(!found){ ! ans.add(value); } } else{ Vector<String> ans = new Vector<String>(1); ! ans.add(value); records_a.put(dname, ans); } --- 365,374 ---- } if(!found){ ! ans.add(value.toLowerCase()); } } else{ Vector<String> ans = new Vector<String>(1); ! ans.add(value.toLowerCase()); records_a.put(dname, ans); } *************** *** 382,391 **** } if(!found){ ! ans.add(value); } } else{ Vector<String> ans = new Vector<String>(1); ! ans.add(value); records_cname.put(dname, ans); } --- 383,392 ---- } if(!found){ ! ans.add(value.toLowerCase()); } } else{ Vector<String> ans = new Vector<String>(1); ! ans.add(value.toLowerCase()); records_cname.put(dname, ans); } *************** *** 400,409 **** } if(!found){ ! ans.add(value); } } else{ Vector<String> ans = new Vector<String>(1); ! ans.add(value); records_ptr.put(dname, ans); } --- 401,410 ---- } if(!found){ ! ans.add(value.toLowerCase()); } } else{ Vector<String> ans = new Vector<String>(1); ! ans.add(value.toLowerCase()); records_ptr.put(dname, ans); } *************** *** 424,436 **** } if(found){ ! ans.set(i, new Pair(mxvalue[0],Integer.valueOf(mxvalue[1]))); } else{ ! ans.add(new Pair(mxvalue[0],Integer.valueOf(mxvalue[1]))); } } else{ Vector<Pair> ans = new Vector<Pair>(1); ! ans.add(new Pair(mxvalue[0],Integer.valueOf(mxvalue[1]))); records_mx.put(dname, ans); } --- 425,437 ---- } if(found){ ! ans.set(i, new Pair(mxvalue[0].toLowerCase(),Integer.valueOf(mxvalue[1]))); } else{ ! ans.add(new Pair(mxvalue[0].toLowerCase(),Integer.valueOf(mxvalue[1]))); } } else{ Vector<Pair> ans = new Vector<Pair>(1); ! ans.add(new Pair(mxvalue[0].toLowerCase(),Integer.valueOf(mxvalue[1]))); records_mx.put(dname, ans); } *************** *** 441,444 **** --- 442,446 ---- public boolean removeRecord(String dname, String value, int type){ + dname = dname.toLowerCase(); boolean result = false; switch(type){ *************** *** 535,541 **** public static boolean isValidName(String name){ if(name.length()==0) return false; for(int i=0; i<name.length(); i++){ char c = name.charAt(i); ! if(!((c>='0' && c<='9') || (c>='a' && c<='z') || (c>='A' && c<='Z') || c=='-' || c=='.')) return false; } return (toInAddrArpa(name)==null); // name is not valid IP-address --- 537,544 ---- public static boolean isValidName(String name){ if(name.length()==0) return false; + name = name.toLowerCase(); for(int i=0; i<name.length(); i++){ char c = name.charAt(i); ! if(!((c>='0' && c<='9') || (c>='a' && c<='z') || c=='-' || c=='.')) return false; } return (toInAddrArpa(name)==null); // name is not valid IP-address *************** *** 544,550 **** public static boolean isValidMail(String name){ if(name.length()==0) return false; for(int i=0; i<name.length(); i++){ char c = name.charAt(i); ! if(!((c>='0' && c<='9') || (c>='a' && c<='z') || (c>='A' && c<='Z') || c=='-' || c=='.' || c=='@')) return false; } return true; --- 547,554 ---- public static boolean isValidMail(String name){ if(name.length()==0) return false; + name = name.toLowerCase(); for(int i=0; i<name.length(); i++){ char c = name.charAt(i); ! if(!((c>='0' && c<='9') || (c>='a' && c<='z') || c=='-' || c=='.' || c=='@')) return false; } return true; Index: DHCPD.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/core/protocolsuite/tcp_ip/DHCPD.java,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** DHCPD.java 26 Sep 2008 17:53:49 -0000 1.7 --- DHCPD.java 19 Oct 2008 21:40:19 -0000 1.8 *************** *** 57,60 **** --- 57,61 ---- } + public boolean running = false; public Hashtable pools = new Hashtable(); public Hashtable leases = new Hashtable(); *************** *** 79,82 **** --- 80,84 ---- mParentStack.SL().bind(appSock, mParentStack.getSrcIP(), 67); mParentStack.SL().listen(appSock); + running = true; printLayerInfo("DHCP server", "DHCP server starts listening in port " + 67 + "."); } catch (Exception e) *************** *** 102,105 **** --- 104,108 ---- printLayerInfo("DHCP server", "DHCPD application closed socket."); mParentStack.SL().close(appSock); + running = false; } *************** *** 108,111 **** --- 111,115 ---- printLayerInfo("DHCP server", "DHCPD application freed socket."); mParentStack.SL().free(appSock); + running = false; } Index: IPV4Address.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/core/protocolsuite/tcp_ip/IPV4Address.java,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** IPV4Address.java 13 Oct 2008 12:36:15 -0000 1.6 --- IPV4Address.java 19 Oct 2008 21:40:19 -0000 1.7 *************** *** 519,528 **** * @author luke_hamilton * @param inDecimalSubnetIp - Subnet IP address in decimal - * @param inDecIPAddress - IP address in decimal * @return boolean * @version v0.20 */ ! public static boolean validateDecSubnetMask(String inDecimalSubnetIp,String inDecIPAddress) { ! return true; /* try { --- 519,538 ---- * @author luke_hamilton * @param inDecimalSubnetIp - Subnet IP address in decimal * @return boolean * @version v0.20 */ ! public static boolean validateDecSubnetMask(String inDecimalSubnetIp) { ! String[] ipn = inDecimalSubnetIp.split("\\."); ! try{ ! if(ipn.length==4){ ! for(int i=0; i<4; i++){ ! int num = Integer.parseInt(ipn[i]); ! if(num<0 || num>255) throw new NumberFormatException(); ! } ! return true; ! } ! } ! catch(NumberFormatException e){}; ! return false; /* try { |
From: QweR <qw...@us...> - 2008-10-19 21:40:27
|
Update of /cvsroot/javanetsim/javaNetSim/core In directory fdv4jf1.ch3.sourceforge.com:/tmp/cvs-serv17182/core Modified Files: CommandProcessor.java MultilayerSwitch.java Simulation.java Log Message: vlan command was added Index: CommandProcessor.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/core/CommandProcessor.java,v retrieving revision 1.27 retrieving revision 1.28 diff -C2 -d -r1.27 -r1.28 *** CommandProcessor.java 19 Oct 2008 17:43:22 -0000 1.27 --- CommandProcessor.java 19 Oct 2008 21:40:19 -0000 1.28 *************** *** 29,32 **** --- 29,33 ---- import java.util.Hashtable; import java.util.Iterator; + import java.util.TreeSet; import java.util.Vector; import java.util.regex.Matcher; *************** *** 55,58 **** --- 56,60 ---- private copy_startup_running_CommandClass copy_startup_running_Command = new copy_startup_running_CommandClass(); private erase_startup_config_CommandClass erase_startup_config_Command = new erase_startup_config_CommandClass(); + private erase_vlan_CommandClass erase_vlan_Command = new erase_vlan_CommandClass(); private help_CommandClass help_Command = new help_CommandClass(); private hostname_CommandClass hostname_Command = new hostname_CommandClass(); *************** *** 77,80 **** --- 79,85 ---- 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__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(); + private interface__switchport_mode_trunk_CommandClass interface__switchport_mode_trunk_Command = new interface__switchport_mode_trunk_CommandClass(); private ip_access_list_standart_CommandClass ip_access_list_standart_Command = new ip_access_list_standart_CommandClass(); private ip_access_list_extended_CommandClass ip_access_list_extended_Command = new ip_access_list_extended_CommandClass(); *************** *** 124,127 **** --- 129,133 ---- private show_udp_statistics_CommandClass show_udp_statistics_Command = new show_udp_statistics_CommandClass(); private show_version_CommandClass show_version_Command = new show_version_CommandClass(); + private show_vlan_CommandClass show_vlan_Command = new show_vlan_CommandClass(); private snmp_server_community_CommandClass snmp_server_community_Command = new snmp_server_community_CommandClass(); private snmp_server_port_CommandClass snmp_server_port_Command = new snmp_server_port_CommandClass(); *************** *** 129,132 **** --- 135,139 ---- private telnet_server_CommandClass telnet_server_Command = new telnet_server_CommandClass(); private username_CommandClass username_Command = new username_CommandClass(); + private vlan_CommandClass vlan_Command = new vlan_CommandClass(); private write_memory_CommandClass write_memory_Command = new write_memory_CommandClass(); private write_terminal_CommandClass write_terminal_Command = new write_terminal_CommandClass(); *************** *** 150,153 **** --- 157,161 ---- commands.addDescription("erase","Erase a filesystem"); commands.add("erase startup-config", erase_startup_config_Command, "Erase a startup-config"); + commands.add("erase vlan.dat", erase_vlan_Command, "Erase a vlan configuration file"); commands.add("help", help_Command, "Description of the interactive help system"); commands.add("hostname", hostname_Command, "Set system's name"); *************** *** 178,182 **** commands.add("interface * ssid", interface__ssid_Command, "Set SSID"); commands.add("interface * station-role", interface__station_role_Command, "Specify station role"); ! commands.addDescription("ip","Global IP configuration subcommands"); commands.addDescription("ip access-list","Named access-list; Add an access list entry"); --- 186,195 ---- commands.add("interface * ssid", interface__ssid_Command, "Set SSID"); commands.add("interface * station-role", interface__station_role_Command, "Specify station role"); ! 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"); ! commands.addDescription("interface * switchport mode","Configure the VLAN membership mode of a port"); ! commands.add("interface * switchport mode access", interface__switchport_mode_access_Command, "Set the port to access mode"); ! commands.add("interface * switchport mode trunk", interface__switchport_mode_trunk_Command, "Set the port to trunk unconditionally"); ! commands.addDescription("ip","Global IP configuration subcommands"); commands.addDescription("ip access-list","Named access-list; Add an access list entry"); *************** *** 185,189 **** commands.addDescription("ip dhcp","Configure DHCP server"); commands.addDescription("ip dhcp pool","Configure DHCP address pools"); ! commands.addDescription("ip dhcp pool *","Configure DHCP address pools"); commands.add("ip dhcp pool * hardware-address", ip_dhcp_pool__hardware_address_Command, "Client hardware address"); commands.add("ip dhcp pool * network", ip_dhcp_pool__network_Command, "Network number and mask"); --- 198,202 ---- commands.addDescription("ip dhcp","Configure DHCP server"); commands.addDescription("ip dhcp pool","Configure DHCP address pools"); ! commands.addDescription("ip dhcp pool *","Pool name"); commands.add("ip dhcp pool * hardware-address", ip_dhcp_pool__hardware_address_Command, "Client hardware address"); commands.add("ip dhcp pool * network", ip_dhcp_pool__network_Command, "Network number and mask"); *************** *** 247,250 **** --- 260,264 ---- commands.add("show udp statistics", show_udp_statistics_Command, "UDP statistics"); commands.add("show version", show_version_Command, "System hardware and software status"); + commands.add("show vlan", show_vlan_Command, "Display the parameters for all configured VLANs"); commands.addDescription("snmp-server","Modify SNMP engine parameters"); *************** *** 255,258 **** --- 269,273 ---- commands.add("no telnet-server", telnet_server_Command, "Disable TELNET server"); commands.add("username", username_Command, "Add User"); + commands.add("vlan", vlan_Command, "Create VLAN"); commands.addDescription("write","Write running configuration to memory or terminal"); commands.add("write memory", write_memory_Command, "Write to memory"); *************** *** 421,424 **** --- 436,461 ---- } }; + class erase_vlan_CommandClass extends CommandInterface{ + public erase_vlan_CommandClass(){ + modes = new Modes(CommandInterface.STD_CONF_MODE, CommandInterface.NETWORK_LAYER, CommandInterface.CALL_ONLY); + call_params = "<cr>"; + } + public String call(Vector<String> params){ + String out = ""; + if(device instanceof MultilayerSwitch){ + MultilayerSwitch msdev = (MultilayerSwitch) device; + if(params.size()==0){ + msdev.clearVlan(); + } + else{ + out += "error: invalid parameters\n"; + } + } + else{ + out += "This instruction not supported by device\n"; + } + return out; + } + }; class help_CommandClass extends CommandInterface{ public help_CommandClass(){ *************** *** 1232,1242 **** out += "Invalid interface name\n"; } catch (CommunicationException ex) { //ex.printStackTrace(); } catch (LowLinkException ex) { //ex.printStackTrace(); } catch (TransportLayerException ex) { //ex.printStackTrace(); } catch (InvalidNetworkLayerDeviceException ex) { ! out += "internal error: Invalid network layer device\n"; //ex.printStackTrace(); } --- 1269,1282 ---- out += "Invalid interface name\n"; } catch (CommunicationException ex) { + out += "communication error\n"; //ex.printStackTrace(); } catch (LowLinkException ex) { + out += "low link error\n"; //ex.printStackTrace(); } catch (TransportLayerException ex) { + out += "transport error\n"; //ex.printStackTrace(); } catch (InvalidNetworkLayerDeviceException ex) { ! out += "network error\n"; //ex.printStackTrace(); } *************** *** 1484,1487 **** --- 1524,1644 ---- } }; + class interface__switchport_access_vlan_CommandClass extends CommandInterface{ + public interface__switchport_access_vlan_CommandClass(){ + modes = new Modes(CommandInterface.STD_CONF_MODE, CommandInterface.NETWORK_LAYER, CommandInterface.NO_CALL); + call_params = "<vlanid>"; + no_call_params = "<cr>"; + } + public String call(Vector<String> params){ + return parse(params, true); + } + public String no_call(Vector<String> params){ + return parse(params, false); + } + private String parse(Vector<String> params, boolean add){ + String out = ""; + if(device instanceof MultilayerSwitch){ + MultilayerSwitch msdev = (MultilayerSwitch) device; + if((params.size()==2 && add) || (params.size()==1 && !add)){ + try{ + NetworkInterface ni = device.getNetworkInterface(params.get(0)); + if(ni instanceof EthernetNetworkInterface){ + EthernetNetworkInterface eni = (EthernetNetworkInterface) ni; + if(add){ + try{ + int vlanid = Integer.parseInt(params.get(1)); + eni.vlan = vlanid; + } + catch(NumberFormatException e){ + out += "error: invalid vlan number\n"; + } + } + else{ + eni.vlan = 1; + } + } + else{ + out += "error: only ethernet interfaces is allowed\n"; + } + } catch (InvalidNetworkInterfaceNameException ex) { + out += "error: invalid inferface\n"; + } + } + else{ + out += "error: invalid parameters\n"; + } + } + else{ + out += "This instruction not supported by device\n"; + } + return out; + } + }; + class interface__switchport_mode_access_CommandClass extends CommandInterface{ + public interface__switchport_mode_access_CommandClass(){ + modes = new Modes(CommandInterface.STD_CONF_MODE, CommandInterface.NETWORK_LAYER, CommandInterface.CALL_ONLY); + call_params = "<cr>"; + } + public String call(Vector<String> params){ + String out = ""; + if(device instanceof MultilayerSwitch){ + MultilayerSwitch msdev = (MultilayerSwitch) device; + if(params.size()==1){ + try{ + NetworkInterface ni = device.getNetworkInterface(params.get(0)); + if(ni instanceof EthernetNetworkInterface){ + EthernetNetworkInterface eni = (EthernetNetworkInterface) ni; + eni.mode = EthernetNetworkInterface.MODE_ACCESS; + } + else{ + out += "error: only ethernet interfaces is allowed\n"; + } + } catch (InvalidNetworkInterfaceNameException ex) { + out += "error: invalid inferface\n"; + } + } + else{ + out += "error: invalid parameters\n"; + } + } + else{ + out += "This instruction not supported by device\n"; + } + return out; + } + }; + class interface__switchport_mode_trunk_CommandClass extends CommandInterface{ + public interface__switchport_mode_trunk_CommandClass(){ + modes = new Modes(CommandInterface.STD_CONF_MODE, CommandInterface.NETWORK_LAYER, CommandInterface.CALL_ONLY); + call_params = "<cr>"; + } + public String call(Vector<String> params){ + String out = ""; + if(device instanceof MultilayerSwitch){ + MultilayerSwitch msdev = (MultilayerSwitch) device; + if(params.size()==1){ + try{ + NetworkInterface ni = device.getNetworkInterface(params.get(0)); + if(ni instanceof EthernetNetworkInterface){ + EthernetNetworkInterface eni = (EthernetNetworkInterface) ni; + eni.mode = EthernetNetworkInterface.MODE_TRUNK; + } + else{ + out += "error: only ethernet interfaces is allowed\n"; + } + } catch (InvalidNetworkInterfaceNameException ex) { + out += "error: invalid inferface\n"; + } + } + else{ + out += "error: invalid parameters\n"; + } + } + else{ + out += "This instruction not supported by device\n"; + } + return out; + } + }; class ip_access_list_standart_CommandClass extends CommandInterface{ public ip_access_list_standart_CommandClass(){ *************** *** 1548,1552 **** } //device.getConfig().add("ip access-list "+iacl+" "+permit_deny+" "+hosts); ! if((IPV4Address.validateDecIP(ip) || ip.compareTo("0.0.0.0")==0) && IPV4Address.validateDecSubnetMask(mask, ip)){ if(add){ device.getACL().addACL(iacl, iline, action, ip, mask, log); --- 1705,1709 ---- } //device.getConfig().add("ip access-list "+iacl+" "+permit_deny+" "+hosts); ! if((IPV4Address.validateDecIP(ip) || ip.compareTo("0.0.0.0")==0) && IPV4Address.validateDecSubnetMask(mask)){ if(add){ device.getACL().addACL(iacl, iline, action, ip, mask, log); *************** *** 1707,1712 **** if(port >= 0){ ! if((IPV4Address.validateDecIP(ip1) || ip1.compareTo("0.0.0.0")==0) && IPV4Address.validateDecSubnetMask(mask1, ip1) && ! (IPV4Address.validateDecIP(ip2) || ip2.compareTo("0.0.0.0")==0) && IPV4Address.validateDecSubnetMask(mask2, ip2)){ if(port==0 || (protocol == AccessListEngine.access_list.TCP || protocol == AccessListEngine.access_list.UDP)){ if(add){ --- 1864,1869 ---- if(port >= 0){ ! if((IPV4Address.validateDecIP(ip1) || ip1.compareTo("0.0.0.0")==0) && IPV4Address.validateDecSubnetMask(mask1) && ! (IPV4Address.validateDecIP(ip2) || ip2.compareTo("0.0.0.0")==0) && IPV4Address.validateDecSubnetMask(mask2)){ if(port==0 || (protocol == AccessListEngine.access_list.TCP || protocol == AccessListEngine.access_list.UDP)){ if(add){ *************** *** 1835,1839 **** String poolname = params.get(0); String mac = params.get(1); ! if(mac.matches("([0-9A-F]{2}:){5}[0-9A-F]{2}")){ if(!dhcpd.pools.containsKey(poolname)){ dhcpd.pools.put(poolname, dhcpd.new_pool()); --- 1992,1996 ---- String poolname = params.get(0); String mac = params.get(1); ! if(EthernetNetworkInterface.isMacAddress(mac)){ if(!dhcpd.pools.containsKey(poolname)){ dhcpd.pools.put(poolname, dhcpd.new_pool()); *************** *** 1903,1907 **** String ip = params.get(1); String mask = params.get(2); ! if(IPV4Address.validateDecIP(ip) && IPV4Address.validateDecIP(mask)){ if(!dhcpd.pools.containsKey(poolname)){ dhcpd.pools.put(poolname, dhcpd.new_pool()); --- 2060,2064 ---- String ip = params.get(1); String mask = params.get(2); ! if(IPV4Address.validateDecSubnetMask(ip) && IPV4Address.validateDecSubnetMask(mask)){ if(!dhcpd.pools.containsKey(poolname)){ dhcpd.pools.put(poolname, dhcpd.new_pool()); *************** *** 1910,1918 **** pool.IP = ip; pool.Genmask = mask; ! try { ! dhcpd.Close(); ! dhcpd.Listen(); ! } catch (TransportLayerException ex) { ! out += "error: dhcp server has not started to listen"; } } --- 2067,2084 ---- pool.IP = ip; pool.Genmask = mask; ! if(dhcpd.running){ ! try { ! dhcpd.Close(); ! dhcpd.Listen(); ! } catch (TransportLayerException ex) { ! out += "error: dhcp server has not started to listen"; ! } ! } ! else{ ! try { ! dhcpd.Listen(); ! } catch (TransportLayerException ex) { ! out += "error: dhcp server has not started to listen"; ! } } } *************** *** 1943,1949 **** if(dhcpd.pools.containsKey(poolname)){ dhcpd.pools.remove(poolname); ! if(dhcpd.pools.isEmpty()){ try { dhcpd.Close(); } catch (TransportLayerException ex) { out += "error: dhcp server has not started to listen"; --- 2109,2123 ---- if(dhcpd.pools.containsKey(poolname)){ dhcpd.pools.remove(poolname); ! if(dhcpd.running){ try { dhcpd.Close(); + if(!dhcpd.pools.isEmpty()) dhcpd.Listen(); + } catch (TransportLayerException ex) { + out += "error: dhcp server has not started to listen"; + } + } + else{ + try { + if(!dhcpd.pools.isEmpty()) dhcpd.Listen(); } catch (TransportLayerException ex) { out += "error: dhcp server has not started to listen"; *************** *** 3230,3233 **** --- 3404,3413 ---- String mask = device.getSubnetMask((String)ins[i]); out += " Internet address " + (ip==null || ip.equals("")?"Not set":ip) + "/" + (mask==null || mask.equals("")?"Not set":mask) + "\n"; + if(ni instanceof EthernetNetworkInterface){ + EthernetNetworkInterface eni = (EthernetNetworkInterface)ni; + if(eni.vlan > 1){ + out += " VLAN ID: "+eni.vlan+"\n"; + } + } if(ni instanceof WiFiPort){ WiFiPort wfi = (WiFiPort) ni; *************** *** 3616,3619 **** --- 3796,3865 ---- } }; + class show_vlan_CommandClass extends CommandInterface{ + public show_vlan_CommandClass(){ + modes = new Modes(CommandInterface.STD_CONF_MODE, CommandInterface.NETWORK_LAYER, CommandInterface.CALL_ONLY); + call_params = "<cr>"; + } + public String call(Vector<String> params){ + String out = ""; + if(device instanceof MultilayerSwitch){ + MultilayerSwitch msdev = (MultilayerSwitch) device; + if(params.size()==0){ + Hashtable<Integer, Vector<String>> vlanport = new Hashtable<Integer, Vector<String>>(); + TreeSet<Integer> vlans = new TreeSet<Integer>(); + vlans.add(1); + Enumeration<Integer> keys = msdev.getVlans(); + while(keys.hasMoreElements()){ + vlans.add(keys.nextElement()); + } + String[] ints = (String[]) device.getAllInterfaces(); + for(int i=0; i<ints.length; i++){ + try{ + NetworkInterface ni = device.getNetworkInterface(ints[i]); + if(ni instanceof EthernetNetworkInterface){ + EthernetNetworkInterface eni = (EthernetNetworkInterface) ni; + int vlanid = eni.vlan; + if(vlanport.containsKey(vlanid)){ + vlanport.get(vlanid).add(ints[i]); + } + else{ + Vector<String> ports = new Vector<String>(1); + ports.add(ints[i]); + vlanport.put(vlanid, ports); + if(!vlans.contains(vlanid)){ + vlans.add(vlanid); + } + } + } + } catch (InvalidNetworkInterfaceNameException ex) {} + } + Iterator<Integer> vlansi = vlans.iterator(); + while(vlansi.hasNext()){ + int vlanid = vlansi.next(); + String vlanname = msdev.getVlanName(vlanid); + if(vlanname==null) vlanname = "-vlan not exists-"; + String ports = ""; + if(vlanport.containsKey(vlanid)){ + Vector<String> ps = vlanport.get(vlanid); + for(int i=0; i<ps.size(); i++){ + ports += (i==0?"":",")+ps.get(i); + } + } + else{ + ports = "no ports found"; + } + out += vlanid+"\t"+String.format("%25s", vlanname)+"\t"+ports+"\n"; + } + } + else{ + out += "error: invalid parameters\n"; + } + } + else{ + out += "This instruction not supported by device\n"; + } + return out; + } + }; class snmp_server_community_CommandClass extends CommandInterface{ public snmp_server_community_CommandClass(){ *************** *** 3876,3879 **** --- 4122,4174 ---- } }; + + class vlan_CommandClass extends CommandInterface{ + public vlan_CommandClass(){ + modes = new Modes(CommandInterface.STD_CONF_MODE, CommandInterface.NETWORK_LAYER, CommandInterface.NO_CALL); + call_params = "<vlanid> [<name>]"; + no_call_params = "<vlanid> [<name>]"; + } + public String call(Vector<String> params){ + return parse(params, true); + } + public String no_call(Vector<String> params){ + return parse(params, false); + } + private String parse(Vector<String> params, boolean add){ + String out = ""; + if(device instanceof MultilayerSwitch){ + MultilayerSwitch msdev = (MultilayerSwitch) device; + if(params.size()==2 || params.size()==3){ + try{ + int vlanid = Integer.parseInt(params.get(1)); + String name = ""; + if(params.size()==3) name = params.get(2); + if(add){ + msdev.addVlan(vlanid, name); + } + else{ + if(name.equals("")){ + msdev.removeVlan(vlanid); + } + else if(msdev.getVlanName(vlanid).equals(name)){ + msdev.removeVlan(vlanid); + } + } + } + catch(NumberFormatException e){ + out += "error: invalid vlan number\n"; + } + + } + else{ + out += "error: invalid parameters\n"; + } + } + else{ + out += "This instruction not supported by device\n"; + } + return out; + } + }; class write_memory_CommandClass extends CommandInterface{ public write_memory_CommandClass(){ Index: MultilayerSwitch.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/core/MultilayerSwitch.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** MultilayerSwitch.java 17 Oct 2008 18:59:14 -0000 1.1 --- MultilayerSwitch.java 19 Oct 2008 21:40:19 -0000 1.2 *************** *** 26,38 **** } ! public void addVlan(Integer v, String name){ Vlans.put(v, name); } ! public void removeVlan(Integer v){ Vlans.remove(v); } ! public void setVlanName(Integer v, String name){ Vlans.remove(v); Vlans.put(v, name); --- 26,52 ---- } ! public void addVlan(int v, String name){ Vlans.put(v, name); } ! public void removeVlan(int v){ Vlans.remove(v); } ! public void clearVlan(){ ! Vlans.clear(); ! } ! ! public String getVlanName(int v){ ! if(Vlans.containsKey(v)){ ! return Vlans.get(v); ! } ! else if(v == 1){ ! return "default"; ! } ! return null; ! } ! ! public void setVlanName(int v, String name){ Vlans.remove(v); Vlans.put(v, name); Index: Simulation.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/core/Simulation.java,v retrieving revision 1.32 retrieving revision 1.33 diff -C2 -d -r1.32 -r1.33 *** Simulation.java 6 Oct 2008 13:20:39 -0000 1.32 --- Simulation.java 19 Oct 2008 21:40:19 -0000 1.33 *************** *** 1291,1296 **** * @return */ ! public static boolean validateDecSubnetMask(String inDecIPAddress, String inDecSubnetMask){ ! return IPV4Address.validateDecSubnetMask(inDecSubnetMask,inDecIPAddress); } --- 1291,1296 ---- * @return */ ! public static boolean validateDecSubnetMask(String inDecSubnetMask){ ! return IPV4Address.validateDecSubnetMask(inDecSubnetMask); } |
From: QweR <qw...@us...> - 2008-10-19 17:43:30
|
Update of /cvsroot/javanetsim/javaNetSim/core In directory fdv4jf1.ch3.sourceforge.com:/tmp/cvs-serv27275/core Modified Files: CommandProcessor.java Log Message: DNS forms was removed :) Index: CommandProcessor.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/core/CommandProcessor.java,v retrieving revision 1.26 retrieving revision 1.27 diff -C2 -d -r1.26 -r1.27 *** CommandProcessor.java 18 Oct 2008 19:55:31 -0000 1.26 --- CommandProcessor.java 19 Oct 2008 17:43:22 -0000 1.27 *************** *** 47,51 **** private NetworkLayerDevice device; private CommandsTree commands = new CommandsTree(); - private Hashtable pools = new Hashtable(); private NoCommandClass noCommand = new NoCommandClass(); --- 47,50 ---- |
Update of /cvsroot/javanetsim/javaNetSim/guiUI In directory fdv4jf1.ch3.sourceforge.com:/tmp/cvs-serv27275/guiUI Removed Files: DNSClient_Dlg.form DNSClient_Dlg.java DNSServ_Dlg.form DNSServ_Dlg.java DNS_Edit.form DNS_Edit.java Log Message: DNS forms was removed :) --- DNSClient_Dlg.form DELETED --- --- DNSServ_Dlg.form DELETED --- --- DNS_Edit.java DELETED --- --- DNSServ_Dlg.java DELETED --- --- DNS_Edit.form DELETED --- --- DNSClient_Dlg.java DELETED --- |
From: QweR <qw...@us...> - 2008-10-18 20:09:19
|
Update of /cvsroot/javanetsim/javaNetSim/guiUI In directory fdv4jf1.ch3.sourceforge.com:/tmp/cvs-serv11254/guiUI Modified Files: GuiLaptop.java Log Message: Index: GuiLaptop.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/guiUI/GuiLaptop.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** GuiLaptop.java 18 Oct 2008 20:07:24 -0000 1.1 --- GuiLaptop.java 18 Oct 2008 20:09:12 -0000 1.2 *************** *** 112,117 **** private JMenuItem mnuSNMPManager = new JMenuItem("Send SNMP message"); - private JMenuItem mnuDNSSend = new JMenuItem("Send request to DNS server"); - public GuiLaptop(String inName, MainScreen inMainScreen) { --- 112,115 ---- *************** *** 160,170 **** }); - - mnuDNSSend.addActionListener(new ActionListener() { - public void actionPerformed(ActionEvent e) { - controller.DNSSendMessage(lblNodeName.getText()); - } - }); - mnuAppLayer.addSeparator(); mnuAppLayer.add(mnuEchoListen); --- 158,161 ---- *************** *** 178,183 **** mnuAppLayer.add(mnuTelnetConnect); mnuAppLayer.add(mnuPosixTelnet); - mnuAppLayer.addSeparator(); - mnuAppLayer.add(mnuDNSSend); } --- 169,172 ---- |
From: Alexander B. <da...@us...> - 2008-10-18 20:07:36
|
Update of /cvsroot/javanetsim/javaNetSim/core In directory fdv4jf1.ch3.sourceforge.com:/tmp/cvs-serv11019/core Added Files: Laptop.java Log Message: --- NEW FILE: Laptop.java --- package core; /* Java Firewall Simulator (jFirewallSim) Copyright (c) 2004, jFirewallSim development team All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: - Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. - Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. - Neither the name of the Canberra Institute of Technology nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR 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. */ import core.protocolsuite.tcp_ip.Echo; import core.protocolsuite.tcp_ip.RIP; import core.protocolsuite.tcp_ip.Telnet_server; import core.protocolsuite.tcp_ip.Telnet_client; import core.protocolsuite.tcp_ip.DHCPC; import core.protocolsuite.tcp_ip.DHCPD; import core.protocolsuite.tcp_ip.DNS; import core.protocolsuite.tcp_ip.Echo_tcp; import core.protocolsuite.tcp_ip.PosixTelnetClient; import core.protocolsuite.tcp_ip.SNMP; /** * A PC is considered to be a client PC in a network which only has one NetworkInterface. The addInterface * method of the inherited Node class is overridden to only allow one NetworkInterface to be added. * @author tristan_veness * @since 13 June 2004 * @version v0.10 */ class Laptop 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 */ public Laptop(String inName, boolean inOn) { super(inName,7, inOn); } public void initApplications(){ super.initApplications(); //RIP ripServer=new RIP(NodeProtocolStack,core.Simulation.UIDGen++); Echo echoServer = new Echo(NodeProtocolStack, 7, 1, core.Simulation.UIDGen++); Echo echoClient = new Echo(NodeProtocolStack, 0, 0, core.Simulation.UIDGen++); Echo_tcp echotcpServer = new Echo_tcp(NodeProtocolStack, 17, 1, core.Simulation.UIDGen++); Echo_tcp echotcpClient = new Echo_tcp(NodeProtocolStack, 0, 0, core.Simulation.UIDGen++); SNMP snmpManager = new SNMP((ApplicationLayerDevice)this, NodeProtocolStack, 0, 1, core.Simulation.UIDGen++); Telnet_client telnetClient = new Telnet_client((ApplicationLayerDevice)this, NodeProtocolStack, 0, 0, core.Simulation.UIDGen++); PosixTelnetClient ptc = new PosixTelnetClient(NodeProtocolStack, core.Simulation.UIDGen++); DHCPC dhcpc = new DHCPC(NodeProtocolStack, core.Simulation.UIDGen++); DNS dnsClient = new DNS(NodeProtocolStack, 91, 0, core.Simulation.UIDGen++); addApp(echoServer, ECHO_SERVER_ID); addApp(echoClient, ECHO_CLIENT_ID); addApp(echotcpServer, ECHO_TCP_SERVER_ID); addApp(echotcpClient, ECHO_TCP_CLIENT_ID); addApp(telnetClient, TELNET_CLIENT_ID); addApp(ptc, POSIX_TELNET_CLIENT_ID); addApp(snmpManager, SNMP_MANAGER_ID); addApp(dhcpc, DHCP_CLIENT_ID); addApp(dnsClient,DNS_CLIENT_ID); } }//EOF |
From: Alexander B. <da...@us...> - 2008-10-18 20:07:35
|
Update of /cvsroot/javanetsim/javaNetSim/guiUI In directory fdv4jf1.ch3.sourceforge.com:/tmp/cvs-serv11019/guiUI Added Files: GuiLaptop.java Log Message: --- NEW FILE: GuiLaptop.java --- /* Java Firewall Simulator (jFirewallSim) Copyright (c) 2004, jFirewallSim development team All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: - Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. - Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. - Neither the name of the Canberra Institute of Technology nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR 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 guiUI; import core.InvalidNodeNameException; import core.Node; import java.awt.Dimension; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.JMenuItem; import javax.swing.JMenu; /** * * <P> * The GuiPC class is used to instantiate new PC on the GUI * </P> * * * * @author VC2 Team. * * @since 15th November 2004 * * @version v0.20 * */ public class GuiLaptop extends ApplicationLayerDevice { /** * * @param inName * The name of the PC * * @param inMainscreen * The JFrame that the router will be created on * */ private JMenuItem mnuEchoListen = new JMenuItem( "Start udp echo server to listen."); private JMenuItem mnuEchoSend = new JMenuItem( "Send data via udp echo client."); private JMenuItem mnuEchotcpListen = new JMenuItem( "Start tcp echo server to listen."); private JMenuItem mnuEchotcpSend = new JMenuItem( "Send data via tcp echo client."); private JMenuItem mnuTelnetConnect = new JMenuItem("Telnet client."); private JMenuItem mnuPosixTelnet = new JMenuItem("RFC(line) telnet client."); private JMenuItem mnuSNMPManager = new JMenuItem("Send SNMP message"); private JMenuItem mnuDNSSend = new JMenuItem("Send request to DNS server"); public GuiLaptop(String inName, MainScreen inMainScreen) { super(inName, inMainScreen, "images/simulation/laptop.png"); mnuEchoListen.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { controller.EchoServerListen(lblNodeName.getText()); } }); mnuEchoSend.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { controller.EchoSend(lblNodeName.getText()); } }); mnuEchotcpListen.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { controller.EchotcpServerListen(lblNodeName.getText()); } }); mnuEchotcpSend.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { controller.EchotcpSend(lblNodeName.getText()); } }); mnuSNMPManager.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { controller.SNMPSendMessage(lblNodeName.getText()); } }); mnuTelnetConnect.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { controller.TelnetConnect(lblNodeName.getText()); } }); mnuPosixTelnet.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { controller.PosixTelnet(lblNodeName.getText()); } }); mnuDNSSend.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { controller.DNSSendMessage(lblNodeName.getText()); } }); mnuAppLayer.addSeparator(); mnuAppLayer.add(mnuEchoListen); mnuAppLayer.add(mnuEchoSend); mnuAppLayer.addSeparator(); mnuAppLayer.add(mnuEchotcpListen); mnuAppLayer.add(mnuEchotcpSend); mnuAppLayer.addSeparator(); mnuAppLayer.add(mnuSNMPManager); mnuAppLayer.addSeparator(); mnuAppLayer.add(mnuTelnetConnect); mnuAppLayer.add(mnuPosixTelnet); mnuAppLayer.addSeparator(); mnuAppLayer.add(mnuDNSSend); } public void addInterfaces(MainScreen parent, Node node) { node.addNetworkInterface(core.NetworkInterface .getIntName(core.NetworkInterface.Ethernet10T) + "0", core.NetworkInterface.Ethernet10T, true, 0); node.addNetworkInterface(core.NetworkInterface .getIntName(core.NetworkInterface.Wireless) + "0", core.NetworkInterface.Wireless, true, 0); } } |
From: Alexander B. <da...@us...> - 2008-10-18 20:07:30
|
Update of /cvsroot/javanetsim/javaNetSim/images/simulation In directory fdv4jf1.ch3.sourceforge.com:/tmp/cvs-serv11019/images/simulation Added Files: laptop.png mlswitch.jpg Log Message: --- NEW FILE: mlswitch.jpg --- (This appears to be a binary file; contents omitted.) --- NEW FILE: laptop.png --- (This appears to be a binary file; contents omitted.) |
From: QweR <qw...@us...> - 2008-10-18 19:56:01
|
Update of /cvsroot/javanetsim/javaNetSim/guiUI In directory fdv4jf1.ch3.sourceforge.com:/tmp/cvs-serv9668/guiUI Modified Files: GuiPC.java MainScreen.java Terminal.java Log Message: DNS works! Index: MainScreen.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/guiUI/MainScreen.java,v retrieving revision 1.94 retrieving revision 1.95 diff -C2 -d -r1.94 -r1.95 *** MainScreen.java 17 Oct 2008 09:10:16 -0000 1.94 --- MainScreen.java 18 Oct 2008 19:55:31 -0000 1.95 *************** *** 4005,4082 **** } - public void DNSStartServer(String inNodeName) { - DNSServ_Dlg dnsDlg = new DNSServ_Dlg(this, true); - dnsDlg.setVisible(true); - if (dnsDlg.getReturnStatus() == DNSServ_Dlg.RET_OK) { - String port = dnsDlg.getPort(); - Hashtable ht = dnsDlg.getAddressTbl(); - // String port = JOptionPane.showInputDialog(this, "port to - // listen:", "DNS server", JOptionPane.QUESTION_MESSAGE); - if (port != null) { - try { - DNS dnsS = (DNS) ((core.ApplicationLayerDevice) Sim - .getNode(inNodeName)).getApp(90); - if (ht != null) { - dnsS.SetRespondTable(ht); - } - dnsS.setPort(Integer.valueOf(port).intValue()); - dnsS.Listen(); - printLayerInfo(true); - } catch (Exception e) { - addToConsole(e.toString()); - } - printLayerInfo(true); - } - } - return; - } - - public void DNSEditTable(String inNodeName) { - try { - DNS dnsS = (DNS) ((core.ApplicationLayerDevice) Sim - .getNode(inNodeName)).getApp(90); - DNS_Edit dns_editDlg = new DNS_Edit(this, true, dnsS - .GetRespondTable()); - dns_editDlg.setVisible(true); - if (dns_editDlg.getReturnStatus() == DNS_Edit.RET_OK) { - dnsS.SetRespondTable(dns_editDlg.getAddressTbl()); - } - } catch (Exception e) { - addToConsole(e.toString()); - } - printLayerInfo(true); - } - - public void DNSSendMessage(String inNodeName) { - DNSClient_Dlg dnsClient_dlg = new DNSClient_Dlg(this, true); - dnsClient_dlg.setVisible(true); - if (dnsClient_dlg.getReturnStatus() == DNSClient_Dlg.RET_OK) - ; - { - String ip = dnsClient_dlg.getServIp(); - String port = dnsClient_dlg.getServPort(); - String mes = dnsClient_dlg.getMessage(); - int qType = dnsClient_dlg.getQType(); - if (!ip.equals("") && !port.equals("") && !mes.equals("") - && qType != 0) { - try { - printNetworkStart(); - // this.addToConsole("Trying to send echo message '" + msg + - // "' from " + inNodeName + " to " + ip + ":" + port + - // "\n"); - ((DNS) ((core.ApplicationLayerDevice) Sim - .getNode(inNodeName)).getApp(91)).SendMessage(ip, - Integer.valueOf(port).intValue(), - mes.toLowerCase(), qType); - - } catch (Exception e) { - - addToConsole(e.toString()); - } - } - } - return; - } - /* * public class TTask extends TimerTask { private MainScreen ms; private int --- 4005,4008 ---- Index: GuiPC.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/guiUI/GuiPC.java,v retrieving revision 1.10 retrieving revision 1.11 diff -C2 -d -r1.10 -r1.11 *** GuiPC.java 17 Oct 2008 09:10:16 -0000 1.10 --- GuiPC.java 18 Oct 2008 19:55:31 -0000 1.11 *************** *** 118,127 **** private JMenuItem mnuDHCPD = new JMenuItem("Start DHCP Server"); - private JMenuItem mnuDNSListen = new JMenuItem("Start DNS server"); - - private JMenuItem mnuDNSSend = new JMenuItem("Send request to DNS server"); - - private JMenuItem mnuDNSEdit = new JMenuItem("Edit DNS-table"); - public GuiPC(String inName, MainScreen inMainScreen) { --- 118,121 ---- *************** *** 186,207 **** }); - mnuDNSListen.addActionListener(new ActionListener() { - public void actionPerformed(ActionEvent e) { - controller.DNSStartServer(lblNodeName.getText()); - } - }); - - mnuDNSSend.addActionListener(new ActionListener() { - public void actionPerformed(ActionEvent e) { - controller.DNSSendMessage(lblNodeName.getText()); - } - }); - - mnuDNSEdit.addActionListener(new ActionListener() { - public void actionPerformed(ActionEvent e) { - controller.DNSEditTable(lblNodeName.getText()); - } - }); - mnuAppLayer.addSeparator(); mnuAppLayer.add(mnuEchoListen); --- 180,183 ---- *************** *** 219,226 **** mnuAppLayer.addSeparator(); mnuAppLayer.add(mnuDHCPD); - mnuAppLayer.addSeparator(); - mnuAppLayer.add(mnuDNSListen); - mnuAppLayer.add(mnuDNSSend); - mnuAppLayer.add(mnuDNSEdit); } --- 195,198 ---- Index: Terminal.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/guiUI/Terminal.java,v retrieving revision 1.17 retrieving revision 1.18 diff -C2 -d -r1.17 -r1.18 *** Terminal.java 13 Oct 2008 20:40:32 -0000 1.17 --- Terminal.java 18 Oct 2008 19:55:31 -0000 1.18 *************** *** 11,17 **** --- 11,21 ---- package guiUI; + import core.ApplicationLayerDevice; import core.CommunicationException; import core.DeviceConfig; + import core.InvalidNetworkLayerDeviceException; import core.LowLinkException; + import core.TransportLayerException; + import javax.swing.JFrame; import javax.swing.JPanel; *************** *** 34,37 **** --- 38,43 ---- import core.InvalidNetworkInterfaceNameException; import core.CommandInterface.Modes; + import core.protocolsuite.tcp_ip.DNS; + import core.protocolsuite.tcp_ip.DNS_Message; import core.protocolsuite.tcp_ip.ICMP_packet; import core.protocolsuite.tcp_ip.IPV4Address; *************** *** 74,78 **** --- 80,86 ---- private interface__exit_CommandClass interface__exit_Command = new interface__exit_CommandClass(); private interface_CommandClass interface_Command = new interface_CommandClass();private logout_CommandClass logout_Command = new logout_CommandClass(); + private nslookup_CommandClass nslookup_Command = new nslookup_CommandClass(); private ping_CommandClass ping_Command = new ping_CommandClass(); + private traceroute_CommandClass traceroute_Command = new traceroute_CommandClass(); private show_history_CommandClass show_history_Command = new show_history_CommandClass(); *************** *** 103,107 **** --- 111,117 ---- cmdproc.add("interface * exit", interface__exit_Command, "Exit from current mode"); cmdproc.add("logout", logout_Command, "Exit from the console"); + cmdproc.add("nslookup", nslookup_Command, "Resolve domain name to ip-address and vice versa"); cmdproc.add("ping", ping_Command, "Send echo messages"); + cmdproc.add("traceroute", traceroute_Command, "Trace route to destination"); cmdproc.add("show history", show_history_Command, "Display the session command history"); *************** *** 469,473 **** } }; ! class PingThread extends Thread{ int count; --- 479,564 ---- } }; ! class nslookup_CommandClass extends CommandInterface{ ! public nslookup_CommandClass(){ ! modes = new Modes(CommandInterface.STD_CONF_MODE, CommandInterface.APPLICATION_LAYER, CommandInterface.CALL_ONLY); ! call_params = "(<host name>|<ip-address>) <server>[:<port>] [<query type>]"; ! } ! public String call(Vector<String> params){ ! String out = ""; ! if(device instanceof ApplicationLayerDevice){ ! DNS dns = (DNS)((ApplicationLayerDevice)device).getApp(core.ApplicationLayerDevice.DNS_CLIENT_ID); ! if(dns!=null){ ! if(params.size()==2 || params.size()==3){ ! String host = params.get(0); ! String server[] = params.get(1).split(":"); ! int qtype = 0; ! if(IPV4Address.validateDecIP(host)){ ! host = DNS.toInAddrArpa(host); ! qtype = DNS_Message.PTR_QUERY_TYPE; ! } ! else if(DNS.isValidName(host)){ ! qtype = DNS_Message.A_QUERY_TYPE; ! } ! else{ ! out += "error: invalid name of host or IP-address\n"; ! } ! if(qtype>0){ ! int port = 53; ! if(IPV4Address.validateDecIP(server[0])){ ! try{ ! if(server.length==2) port = Integer.parseInt(server[1]); ! if(port<1 || port>65535) throw new NumberFormatException(); ! if(params.size()==3) qtype = DNS_Message.getTypeInt(params.get(2)); ! if(qtype>0){ ! try { ! int id = dns.SendMessage(server[0], port, host, qtype); ! 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 += (i==0?"":"\n")+ans.name+"\t"+DNS_Message.getTypeString(ans.type)+"\t"+ans.resource; ! } ! } ! else{ ! out += "No "+DNS_Message.getTypeString(qtype)+" record found for '"+host+"'."; ! } ! } catch (CommunicationException e) { ! out += "communitarion error\n"; ! } catch (LowLinkException e) { ! out += "low link error\n"; ! } catch (InvalidNetworkLayerDeviceException e) { ! out += "invalid network device error\n"; ! } catch (TransportLayerException e) { ! out += "transport error\n"; ! } ! } ! else{ ! out += "error: invalid query type; valid values is A,PTR,CNAME,MX,HINFO\n"; ! } ! } ! catch(NumberFormatException e){ ! out += "error: invalid port number\n"; ! } ! } ! else{ ! out += "error: invalid server IP-address\n"; ! } ! } ! } ! else{ ! out += "error: invalid parameters\n"; ! } ! } ! else{ ! out += "This instruction not supported by device\n"; ! } ! } ! else{ ! out += "This instruction not supported by device\n"; ! } ! return out; ! } ! }; class PingThread extends Thread{ int count; *************** *** 556,559 **** --- 647,659 ---- } }; + class traceroute_CommandClass extends CommandInterface{ + public traceroute_CommandClass(){ + modes = new Modes(CommandInterface.STD_CONF_MODE, CommandInterface.NETWORK_LAYER, CommandInterface.CALL_ONLY); + call_params = "<IP>"; + } + public String call(Vector<String> params){ + return "Command not supported yet.\n"; + } + }; class show_history_CommandClass extends CommandInterface{ public show_history_CommandClass (){ |
Update of /cvsroot/javanetsim/javaNetSim/core/protocolsuite/tcp_ip In directory fdv4jf1.ch3.sourceforge.com:/tmp/cvs-serv9668/core/protocolsuite/tcp_ip Modified Files: DNS.java DNS_Message.java ProtocolStack.java Telnet_server.java socketLayer.java Log Message: DNS works! Index: ProtocolStack.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/core/protocolsuite/tcp_ip/ProtocolStack.java,v retrieving revision 1.72 retrieving revision 1.73 diff -C2 -d -r1.72 -r1.73 *** ProtocolStack.java 13 Oct 2008 21:20:21 -0000 1.72 --- ProtocolStack.java 18 Oct 2008 19:55:31 -0000 1.73 *************** *** 338,341 **** --- 338,342 ---- System.out.println("ProtocolStack.java: SendPacket 1 " + e.toString()); + e.printStackTrace(); } Index: DNS_Message.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/core/protocolsuite/tcp_ip/DNS_Message.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** DNS_Message.java 6 Sep 2008 20:27:27 -0000 1.2 --- DNS_Message.java 18 Oct 2008 19:55:31 -0000 1.3 *************** *** 7,10 **** --- 7,13 ---- import java.util.Hashtable; + import java.util.Vector; + + //import javax.swing.RowSorter.SortKey; import sun.misc.Compare; *************** *** 18,38 **** public class DNS_Message { ! private static int Count = 65045; //header ! private String id; private String flags; //length = 16 - private String countOfQuery; - private String countOfRequest; - private String countOfAccess; - private String countOfAddons; //content ! private String querys; ! private String answers; ! private String answerSim; ! private String access; ! private String additional; ! private int queryType; public static final int A_QUERY_TYPE = 1; public static final int PTR_QUERY_TYPE = 12; public static final int HINFO_QUERY_TYPE = 13; --- 21,38 ---- public class DNS_Message { ! private static int Counter = 1; //header ! private int id; private String flags; //length = 16 //content ! private Vector<Query> queries; ! private Vector<Answer> answers; ! private Vector<Object> accesses; //for future realizations ! private Vector<Object> additionals; //for future realizations ! public static final int TTL_DEFAULT = 86400; // 86400s = 24h ! public static final int CLASS_IN = 1; //class of request = 1 public static final int A_QUERY_TYPE = 1; + public static final int CNAME_QUERY_TYPE = 5; public static final int PTR_QUERY_TYPE = 12; public static final int HINFO_QUERY_TYPE = 13; *************** *** 40,81 **** ! public DNS_Message(int QR, int opcode, int AA, int TC, int RD, int RA, int rcode, String query, String answer, String access, String addit) { //create DNS-message whith known simple parametres ! if (Count == 65535) ! Count = 0; ! Count++; ! //id = Count; ! id = IntToString(Count); //convert flags to 2-bytes string ! flags=IntToString((QR << 15)+(opcode << 11) + (AA << 10) + (TC << 9) + (RD << 8) + (RA << 7) + (rcode)); ! //count of Query in ver. 1.0 equals 1 ! countOfQuery = IntToString(1); ! //count of Query equals 0 or 1 ! if (QR==1) ! countOfRequest=IntToString(1); ! else ! countOfRequest=IntToString(0); ! //access and addtitional informations does not containt in package ! countOfAccess = IntToString(0); ! countOfAddons = IntToString(0); ! ! querys = ParseQuery(query); if ((QR==1) && (rcode != 3)) { ! answers = ParseAnswer(answer); ! answerSim = answer; } else { ! answers = IntToString(0); ! answerSim = ""; } //May be parse access and form like answers ! this.access = IntToString(0); ! //May be parse addit and form like answers ! this.additional = IntToString(0); } --- 40,73 ---- ! public DNS_Message(int new_id, int QR, int opcode, int AA, int TC, int RD, int RA, int rcode, Vector<Query> query, Vector<Answer> answer, Vector<Object> access, Vector<Object> addit) { //create DNS-message whith known simple parametres ! if(new_id==0){ ! if (Counter == 16777216) ! Counter = 0; ! Counter++; ! id = Counter; ! } ! else{ ! id = new_id; ! } //convert flags to 2-bytes string ! flags=IntToStr2((QR << 15)+(opcode << 11) + (AA << 10) + (TC << 9) + (RD << 8) + (RA << 7) + (rcode)); ! ! queries = query; if ((QR==1) && (rcode != 3)) { ! answers = answer; } else { ! answers = new Vector<Answer>(0); } //May be parse access and form like answers ! this.accesses = new Vector<Object>(0); ! //May be parse additional and form like answers ! this.additionals = new Vector<Object>(0); } *************** *** 84,261 **** //create object DNS-message with known header and data in string //parse input string and set fields of object ! String subStr; ! id = mess.substring(0, 2); flags = mess.substring(2, 4); ! countOfQuery = mess.substring(4, 6); ! countOfRequest = mess.substring(6, 8); ! countOfAccess = mess.substring(8, 10); ! countOfAddons = mess.substring(10, 12); ! int begIndex = 12; ! querys = StrToField(mess, begIndex); ! begIndex += querys.length(); ! try ! { ! answers = StrToField(mess, begIndex); ! begIndex += querys.length(); ! answers = answers.concat(mess.substring(begIndex, begIndex+6)); ! ! int k = Integer.valueOf(mess.codePointAt(begIndex+4)); ! k = (k << 8)+ Integer.valueOf(mess.codePointAt(begIndex+5)); ! answerSim = mess.substring(begIndex+6); ! answers = answers.concat(answerSim); ! if (queryType == MX_QUERY_TYPE) ! answerSim = MakeSimMXAnswer(answerSim); ! begIndex = begIndex+6+k; } ! catch(Exception e) ! { ! answers = new String(querys)+"0000"; ! char[] ch = new char[2]; ! ch[0]=ch[1]=0; ! answers = answers.concat(String.valueOf(ch)); } ! //additional = StrToField(mess, begIndex); } ! public String ToString() { ! String resStr = id.concat(flags).concat(countOfQuery).concat(countOfRequest).concat(countOfAccess).concat(countOfAddons); ! resStr = resStr.concat(querys).concat(answers);//.concat(access).concat(additional); return resStr; } ! public int GetRCode() { return (flags.codePointAt(1) & 15); } ! public String GetQuery() { ! //return Query and QType in String ! String hostNm = new String(); ! int i=0; ! int lenDomainNm = Integer.valueOf(querys.codePointAt(i)).intValue(); ! while(lenDomainNm !=0) ! { ! hostNm = hostNm.concat(querys.substring(i+1, i+lenDomainNm+1)); ! i += lenDomainNm+1; ! if (queryType == A_QUERY_TYPE || ! queryType == HINFO_QUERY_TYPE || ! queryType == MX_QUERY_TYPE) ! hostNm += "."; ! lenDomainNm = Integer.valueOf(querys.substring(i,i+1)).intValue(); } ! char[] qType = new char[1]; ! qType[0] = (char)querys.codePointAt(i+2); ! return (new String(qType) + hostNm); } ! public String GetAnswer() { ! return answerSim; } ! public int GetQueryType() { ! return queryType; } ! private String ParseQuery(String query) ! {//only for 0ne domain ! String resQuery = new String(""); ! String[] fields = query.split(":"); //dot is separator ! if (Integer.toString(A_QUERY_TYPE).equals(fields[1]) || ! Integer.toString(HINFO_QUERY_TYPE).equals(fields[1]) || ! Integer.toString(MX_QUERY_TYPE).equals(fields[1])) //A-type of query ! { ! queryType = Integer.valueOf(fields[1]).intValue(); ! String[] domains = fields[0].split("\\u002E"); ! for (int i = 0; i < domains.length; i++) ! { ! char[] len = new char[1]; ! len[0] = (char)domains[i].length(); ! resQuery = resQuery.concat(new String(len)); ! //resQuery = resQuery.concat(String.valueOf((char)domains[i].length())); ! resQuery = resQuery.concat(domains[i]); } - resQuery = resQuery.concat("0"); } ! else if (Integer.toString(PTR_QUERY_TYPE).equals(fields[1])) { ! char[] len = new char[1]; ! len[0] = (char)fields[0].length(); ! resQuery = resQuery.concat(new String(len)+fields[0]+"0"); } ! // resQuery = StrToBinaryStr(resQuery, 8); ! //resQuery = AddZero(resQuery, resQuery.length() + (4-(resQuery.length()%4)%4), 1); ! resQuery = resQuery.concat(IntToString(Integer.decode(fields[1]))); ! resQuery = resQuery.concat(IntToString(1));//class of request = 1 ! return resQuery; } /** ! * This method return string like DNS-format with answer for query. ! * @param value to convert ! * @author Gek ! * @version v0.01 ! */ ! private String ParseAnswer(String answer) { ! String resAnswer = new String(querys); ! char[] TTL = new char[4]; ! TTL[0] = TTL[3] = 0; ! TTL[1]=2; ! TTL[2]=163; ! resAnswer += String.valueOf(TTL); ! if (queryType == MX_QUERY_TYPE) ! { ! String[] servs = answer.split(";"); ! answer= ""; ! for (int i = 0; i<servs.length; i++) ! { ! String[] parts = servs[i].split(":"); ! String priority; ! String server; ! if (parts.length == 2) ! { ! priority = IntToString(Integer.valueOf(parts[0].trim()).intValue()); ! server = parts[1]; ! } ! else ! { ! priority = IntToString(0); ! server = parts[0]; ! } ! String len = IntToString(server.length()); ! answer += priority + len + server; ! } ! } ! resAnswer += IntToString(answer.length()); ! resAnswer += answer; ! return resAnswer; } ! //pos: ! // 0 - to begin ! // else - to end ! /* ! private String AddZero(String str, int newLength, int pos) { ! //add to begin of str '0', while length(str) is not newLength ! //or cut the tail ! while(str.length()<newLength) ! { ! if (pos==0) ! str = "0".concat(str); ! else ! str = str.concat("0"); } ! if (str.length()>newLength) ! str = str.substring(0, newLength); ! return str; } - * */ /** --- 76,286 ---- //create object DNS-message with known header and data in string //parse input string and set fields of object ! id = Str2ToInt(mess.substring(0, 2)); flags = mess.substring(2, 4); ! int countOfQuery = Str2ToInt(mess.substring(4, 6)); ! int countOfAnswers = Str2ToInt(mess.substring(6, 8)); ! // int countOfAccesses = Str2ToInt(mess.substring(8, 10)); ! // int countOfAddons = Str2ToInt(mess.substring(10, 12)); ! ! queries = new Vector<Query>(1); ! answers = new Vector<Answer>(0); ! accesses = new Vector<Object>(0); ! additionals = new Vector<Object>(0); ! int begin = 12; ! for(int i=0; i<countOfQuery; i++){ ! Query qu = parseQuery(mess, begin); ! begin += qu.length; ! queries.add(qu); } ! for(int i=0; i<countOfAnswers; i++){ ! Answer ans = parseAnswer(mess, begin); ! begin += ans.length; ! answers.add(ans); } ! // for(int i=0; i<countOfAccesses; i++){ ! // Access acc = parseAccess(mess, begin); ! // begin += acc.length; ! // accesses.add(ans); ! // } ! // for(int i=0; i<countOfAddons; i++){ ! // Addon add = parseAddon(mess, begin); ! // begin += add.length; ! // additionals.add(add); ! // } } ! public String toString() { ! String resStr = IntToStr2(id) + flags + IntToStr2(queries.size()) + IntToStr2(answers.size()) + IntToStr2(accesses.size()) + IntToStr2(additionals.size()); ! resStr += createQueries() + createAnswers(); // + creareAccess() + createAdditional(); return resStr; } ! public int getID() ! { ! return id; ! } ! ! public int getRCode() { return (flags.codePointAt(1) & 15); } ! public Vector<Query> getQuery() { ! return queries; ! } ! ! public Vector<Answer> getAnswer() ! { ! return answers; ! } ! ! private String createQueries() ! { ! String resQuery = ""; ! for(int i=0; i<queries.size(); i++){ ! resQuery += createQuery(queries.get(i)); } ! return resQuery; } ! private String createAnswers() { ! String resAnswer = ""; ! for (int i = 0; i<answers.size(); i++){ ! resAnswer += createAnswer(answers.get(i)); ! } ! return resAnswer; } ! private String createQuery(Query qu) { ! String resQuery = createDomainName(qu.name); ! resQuery += IntToStr2(qu.type); ! resQuery += IntToStr2(CLASS_IN); ! return resQuery; } ! private String createAnswer(Answer ans) ! { ! String resAnswer = createQuery(ans); ! resAnswer += IntToStr4(TTL_DEFAULT); ! switch(ans.type){ ! case A_QUERY_TYPE: { ! String[] ip = ans.resource.split("\\."); ! resAnswer += IntToStr2(4) + (char)Integer.parseInt(ip[0]) ! + (char)Integer.parseInt(ip[1]) ! + (char)Integer.parseInt(ip[2]) ! + (char)Integer.parseInt(ip[3]); ! break; ! } ! case PTR_QUERY_TYPE: ! case CNAME_QUERY_TYPE: { ! String server = createDomainName(ans.resource); ! String len = IntToStr2(server.length()); ! resAnswer += len + server; ! break; ! } ! case HINFO_QUERY_TYPE: { ! String hinfo = ans.resource.substring(0,Math.min(ans.resource.length(), 255)); ! String server = (char)hinfo.length() + hinfo; ! String len = IntToStr2(server.length()); ! resAnswer += len + server; ! break; ! } ! case MX_QUERY_TYPE: { ! String priority = IntToStr2(ans.priority); ! String server = createDomainName(ans.resource); ! String len = IntToStr2(server.length()+2); ! resAnswer += len + priority + server; ! break; } } ! return resAnswer; ! } ! ! public String createDomainName(String in){ ! String out = ""; ! String[] domains = in.split("\\u002E"); // u002E aka .(dot) ! for (int i = 0; i < domains.length; i++) { ! String dname = domains[i].substring(0,Math.min(domains[i].length(),63)); // max length of domain is 63 symbols ! out += (char)dname.length() + dname; } ! out += '\u0000'; ! return out; ! } ! ! public DName parseDomainName(String str, int begin){ ! int saveBegin = begin; ! String qName = new String(); ! int k = str.codePointAt(begin); ! while(k!=0) ! { ! int oldBegin = begin+1; ! begin += k+1; ! k = str.codePointAt(begin); ! qName += str.substring(oldBegin, begin) + (k==0?"":"."); ! } ! return new DName(qName,begin+1-saveBegin); } /** ! * This method extract from input string the queries string ! */ ! private Query parseQuery(String str, int begin) { ! int saveBegin = begin; ! DName dname = parseDomainName(str, begin); ! begin += dname.length; ! Integer qType = new Integer(Str2ToInt(str.substring(begin,begin+2))); ! return new Query(dname.name,qType,begin+4-saveBegin); } ! /** ! * This method extract from input string the answers string ! */ ! private Answer parseAnswer(String str, int begin) { ! int saveBegin = begin; ! Query qu = parseQuery(str, begin); ! begin += qu.length; ! int ttl = Str4ToInt(str.substring(begin,begin+4)); ! begin += 4; ! int len = Str2ToInt(str.substring(begin,begin+2)); ! begin += 2; ! String aRes = ""; ! int priority = 0; ! switch(qu.type){ ! case A_QUERY_TYPE:{ ! if(len==4){ ! aRes = Integer.toString(str.codePointAt(begin))+"."+Integer.toString(str.codePointAt(begin+1))+"."+Integer.toString(str.codePointAt(begin+2))+"."+Integer.toString(str.codePointAt(begin+3)); ! } ! break; ! } ! case PTR_QUERY_TYPE: ! case CNAME_QUERY_TYPE:{ ! DName dname = parseDomainName(str, begin); ! aRes = dname.name; ! break; ! } ! case HINFO_QUERY_TYPE:{ ! int hilen = str.codePointAt(begin); ! aRes = str.substring(begin+1,begin+hilen+1); ! break; ! } ! case MX_QUERY_TYPE:{ ! priority = Str2ToInt(str.substring(begin,begin+2)); ! DName dname = parseDomainName(str, begin+2); ! aRes = dname.name; ! break; ! } } ! begin += len; ! return new Answer(qu.name,qu.type,ttl,aRes,priority,begin-saveBegin); } /** *************** *** 265,337 **** * @version v0.01 */ ! private String IntToString(int value) { char[] ch = new char[2]; ! ch[0] = (char)((value & 65280)>>8); ! ch[1] = (char)(value & 255); return String.copyValueOf(ch); } ! /* ! private String StrToBinaryStr(String str, int offset) { ! char[] strCh = str.toCharArray(); ! String resStr = new String(""); ! for (int i = 0; i < strCh.length; i++) ! { ! char c = strCh[i]; ! resStr = resStr.concat(AddZero(Integer.toBinaryString((int)c),offset,0)); ! } ! return resStr; } - */ ! /** ! * This method extract from input string the querys-, answers- or additional- string ! */ ! private String StrToField(String str, int begIndex) ! { ! int saveBeg = begIndex; ! int endIndex = begIndex + 1; ! String resStr = new String(); ! resStr = resStr.concat(str.substring(begIndex,endIndex)); ! int k = resStr.codePointAt(0); ! while(k!=0) ! { ! begIndex += k+1; ! resStr = resStr.concat(str.substring(endIndex, begIndex)); ! endIndex = begIndex +1; ! k = Integer.valueOf(str.substring(begIndex,endIndex)).intValue(); ! resStr = resStr.concat(Integer.toString(k)); ! } ! //resStr = AddZero(resStr, resStr.length() + (4-(resStr.length()%4)%4), 1); ! begIndex = saveBeg+resStr.length(); ! resStr = resStr.concat(str.substring(begIndex, begIndex+4)); ! queryType = Integer.valueOf(str.substring(begIndex,begIndex+2).codePointAt(1)); ! return resStr; } ! /* ! * This method make simple answer string for MX-query from string in byte-code ! * ! */ ! private String MakeSimMXAnswer(String str) ! { ! int k =0; ! String resStr = new String(""); ! Hashtable ht = new Hashtable(); ! while (k < str.length()) ! { ! int priority = (str.codePointAt(k) << 8) + str.codePointAt(k+1); ! k+=2; ! int len = (str.codePointAt(k) << 8) + str.codePointAt(k+1); ! k+=2; ! String serv = str.substring(k, k+len); ! ht.put(priority, serv); ! resStr += Integer.toString(priority)+":"+serv+";"; ! k+=len; ! } ! return resStr.substring(0, resStr.length()-2); } }; --- 290,386 ---- * @version v0.01 */ ! private String IntToStr2(int value) { char[] ch = new char[2]; ! ch[0] = (char)((value>>8) & 0xFF); ! ch[1] = (char)(value & 0xFF); return String.copyValueOf(ch); + } + + private int Str2ToInt(String value) + { + return (value.codePointAt(0)<<8)+value.codePointAt(1); } + + private String IntToStr4(int value) + { + char[] ch = new char[4]; + ch[0] = (char)((value>>24) & 0xFF); + ch[1] = (char)((value>>16) & 0xFF); + ch[2] = (char)((value>>8) & 0xFF); + ch[3] = (char)(value & 0xFF); + return String.copyValueOf(ch); + } ! private int Str4ToInt(String value) { ! return (((((value.codePointAt(0)<<8)+value.codePointAt(1))<<8)+value.codePointAt(2))<<8)+value.codePointAt(3); } + static public int getTypeInt(String t){ + if(t.equalsIgnoreCase("a")){ + return A_QUERY_TYPE; + } + else if(t.equalsIgnoreCase("ptr")){ + return PTR_QUERY_TYPE; + } + else if(t.equalsIgnoreCase("cname")){ + return CNAME_QUERY_TYPE; + } + else if(t.equalsIgnoreCase("hinfo")){ + return HINFO_QUERY_TYPE; + } + else if(t.equalsIgnoreCase("mx")){ + return MX_QUERY_TYPE; + } + return 0; + } + + static public String getTypeString(int t){ + if(t == A_QUERY_TYPE){ + return "A"; + } + else if(t == PTR_QUERY_TYPE){ + return "PTR"; + } + else if(t == CNAME_QUERY_TYPE){ + return "CNAME"; + } + else if(t == HINFO_QUERY_TYPE){ + return "HINFO"; + } + else if(t == MX_QUERY_TYPE){ + return "MX"; + } + return ""; + } ! static public class DName { ! public String name; ! public int length; ! public DName(String m_name, int m_length){ ! name = m_name; ! length = m_length; ! } } ! static public class Query extends DName{ ! public int type; ! public Query(String m_name, int m_type, int m_length){ ! super(m_name, m_length); ! type = m_type; ! } ! } ! ! static public class Answer extends Query { ! public int ttl; ! public String resource; ! public int priority; //MX only ! public Answer(String m_name, int m_type, int m_ttl, String m_resource, int m_priority, int m_length){ ! super(m_name, m_type, m_length); ! ttl = m_ttl; ! resource = m_resource; ! priority = m_priority; ! } } }; Index: socketLayer.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/core/protocolsuite/tcp_ip/socketLayer.java,v retrieving revision 1.13 retrieving revision 1.14 diff -C2 -d -r1.13 -r1.14 *** socketLayer.java 13 Oct 2008 22:52:07 -0000 1.13 --- socketLayer.java 18 Oct 2008 19:55:31 -0000 1.14 *************** *** 17,21 **** public class socketLayer { ProtocolStack mParentStack; ! private Vector sockTable = new Vector(); int lastSock; --- 17,21 ---- public class socketLayer { ProtocolStack mParentStack; ! private Hashtable<Integer,jnSocket> sockTable = new Hashtable<Integer,jnSocket>(); int lastSock; *************** *** 28,32 **** public int socket(short type, Application app){ ! sockTable.add(new jnSocket(lastSock, app, type)); lastSock++; return (lastSock - 1); --- 28,32 ---- public int socket(short type, Application app){ ! sockTable.put(lastSock,new jnSocket(lastSock, app, type)); lastSock++; return (lastSock - 1); *************** *** 177,181 **** jnsock.src_port = 0; jnsock.src_IP = ""; ! //sockTable.remove(sock); } } --- 177,181 ---- jnsock.src_port = 0; jnsock.src_IP = ""; ! sockTable.remove(sock); } } Index: Telnet_server.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/core/protocolsuite/tcp_ip/Telnet_server.java,v retrieving revision 1.23 retrieving revision 1.24 diff -C2 -d -r1.23 -r1.24 *** Telnet_server.java 26 Sep 2008 17:53:49 -0000 1.23 --- Telnet_server.java 18 Oct 2008 19:55:31 -0000 1.24 *************** *** 24,27 **** --- 24,30 ---- public class Telnet_server extends Application{ + private String login = "root"; + private String def_pass = "javanetsim"; + public class TSession{ public String user; *************** *** 36,41 **** // private boolean isprompt=true; private boolean isnewpass=false; - private String password = "123"; - private String login = "root"; private String temp = ""; public Hashtable connections = new Hashtable(); --- 39,42 ---- *************** *** 48,51 **** --- 49,53 ---- ispass=false; appSock = mParentStack.SL().socket(jnSocket.TCP_socket, this); + mDevice.addUser(login,def_pass); } *************** *** 228,232 **** else { if(temp.compareTo(cmdline)==0) { ! password = temp; outData += "\r\n" + runcmd(""); } --- 230,234 ---- else { if(temp.compareTo(cmdline)==0) { ! mDevice.addUser(login,temp); outData += "\r\n" + runcmd(""); } *************** *** 443,456 **** public void setPassword(String s) { ! password = s; } public String getPassword() { ! return password; } private boolean isAuth(String user, String pass){ boolean auth = false; ! if((user.equals(login) && pass.equals(password)) || pass.equals(mDevice.getUserPassword(user))){ auth = true; } --- 445,458 ---- public void setPassword(String s) { ! mDevice.addUser(login, s); } public String getPassword() { ! return mDevice.getUserPassword(login); } private boolean isAuth(String user, String pass){ boolean auth = false; ! if(pass.equals(mDevice.getUserPassword(user))){ auth = true; } Index: DNS.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/core/protocolsuite/tcp_ip/DNS.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** DNS.java 26 Sep 2008 17:53:49 -0000 1.2 --- DNS.java 18 Oct 2008 19:55:31 -0000 1.3 *************** *** 8,11 **** --- 8,12 ---- package core.protocolsuite.tcp_ip; + import core.Pair; import core.TransportLayerException; import core.InvalidNetworkLayerDeviceException; *************** *** 16,19 **** --- 17,22 ---- //import java.util.Hashtable; import java.util.Hashtable; + import java.util.LinkedList; + import java.util.Vector; /** *************** *** 25,31 **** long utc1; ! public int recieved; ! private Hashtable hs; ! public Boolean listening; /** Creates a new instance of DNS */ --- 28,47 ---- long utc1; ! public int received; ! public Hashtable<String,Vector<String>> records_a = new Hashtable<String,Vector<String>>(); ! public Hashtable<String,Vector<String>> records_ptr = new Hashtable<String,Vector<String>>(); ! public Hashtable<String,Vector<String>> records_cname = new Hashtable<String,Vector<String>>(); ! public Hashtable<String,Vector<Pair>> records_mx = new Hashtable<String,Vector<Pair>>(); // pair(name,priority) ! public Hashtable<String,String> records_hinfo = new Hashtable<String,String>(); ! public String DomainName = ""; ! public String PrimaryNameServer = ""; ! public String MailboxResponsiblePerson = ""; ! public int RefreshTime = 86400; ! public int RefreshRetryTime = 3600; ! public int AuthorityExpireTime = 1209600; ! public int MinimumTTLZoneInfo = 86400; ! public boolean listening = false; ! public Hashtable<Integer,DNS_Message> receivedMessages = new Hashtable<Integer,DNS_Message>(); ! private int last_sent_id = 0; /** Creates a new instance of DNS */ *************** *** 35,39 **** appSock = mParentStack.SL().socket(jnSocket.UDP_socket, this); int fake = 0; - hs = new Hashtable(); } --- 51,54 ---- *************** *** 75,78 **** --- 90,94 ---- }else{ printLayerInfo("DNS application", "DNS server closed socket."); + listening = false; } mParentStack.SL().close(appSock); *************** *** 85,88 **** --- 101,105 ---- }else{ printLayerInfo("DNS application", "DNS server freed socket."); + listening = false; } mParentStack.SL().free(appSock); *************** *** 134,143 **** */ ! public void SendMessage(String host, int port, String mess, int qType) throws CommunicationException, LowLinkException, InvalidNetworkLayerDeviceException, TransportLayerException { if (Connect (host, port)) { SendData(mess+":"+Integer.toString(qType)); } } --- 151,162 ---- */ ! public int SendMessage(String host, int port, String mess, int qType) throws CommunicationException, LowLinkException, InvalidNetworkLayerDeviceException, TransportLayerException { if (Connect (host, port)) { SendData(mess+":"+Integer.toString(qType)); + return last_sent_id; } + return 0; } *************** *** 147,152 **** String sdHost = mParentStack.SL().get_socket(sock).dst_IP; int sdPort = mParentStack.SL().get_socket(sock).dst_port; ! DNS_Message dnsMes = new DNS_Message(0,0,1, 0, 1, 0, 0, mess, "", "", ""); ! mParentStack.SL().writeTo(sock, dnsMes.ToString(), sdHost, sdPort); //processing the protocol doings. --- 166,175 ---- String sdHost = mParentStack.SL().get_socket(sock).dst_IP; int sdPort = mParentStack.SL().get_socket(sock).dst_port; ! Vector<DNS_Message.Query> vmess = new Vector<DNS_Message.Query>(1); ! String smess[] = mess.split(":"); ! vmess.add(new DNS_Message.Query(smess[0],Integer.parseInt(smess[1]),0)); ! DNS_Message dnsMes = new DNS_Message(0, 0, 0, 1, 0, 1, 0, 0, vmess, null, null, null); ! last_sent_id = dnsMes.getID(); ! mParentStack.SL().writeTo(sock, dnsMes.toString(), sdHost, sdPort); //processing the protocol doings. *************** *** 158,166 **** String sdHost = mParentStack.SL().get_socket(sock).dst_IP; int sdPort = mParentStack.SL().get_socket(sock).dst_port; ! mParentStack.SL().writeTo(sock,dnsMes.ToString(),sdHost, sdPort); } /** ! * This method recieves DNS data from the other side. * @param data to recv * @author Gek --- 181,189 ---- String sdHost = mParentStack.SL().get_socket(sock).dst_IP; int sdPort = mParentStack.SL().get_socket(sock).dst_port; ! mParentStack.SL().writeTo(sock,dnsMes.toString(),sdHost, sdPort); } /** ! * This method receives DNS data from the other side. * @param data to recv * @author Gek *************** *** 168,175 **** */ public void RecvData(int sock, String Data) throws LowLinkException, TransportLayerException { ! recieved++; //processing the protocol doings. if(appType == 0){ ! //client processing recieve request // printing some ... LayerInfo protInfo = new LayerInfo(getClass().getName()); --- 191,198 ---- */ public void RecvData(int sock, String Data) throws LowLinkException, TransportLayerException { ! received++; //processing the protocol doings. if(appType == 0){ ! //client processing receive request // printing some ... LayerInfo protInfo = new LayerInfo(getClass().getName()); *************** *** 177,201 **** protInfo.setDataType("DNS Protocol Data"); protInfo.setLayer("Application "); ! //protInfo.setDescription("Recieving DNS message from server."); // Simulation.addLayerInfo(protInfo); DNS_Message dnsMsg = new DNS_Message(Data); ! if (dnsMsg.GetRCode()==3) { ! protInfo.setDescription("No answer records for hostname (ip-address) '"+dnsMsg.GetQuery().substring(1)+"'."); } ! else { ! String query = dnsMsg.GetQuery(); ! String answer = dnsMsg.GetAnswer(); ! int qType = dnsMsg.GetQueryType(); ! if (qType == DNS_Message.A_QUERY_TYPE) ! protInfo.setDescription("Host '"+query.substring(1, query.length()-1) + "' has IP-address '" + answer + "'."); ! else if (qType == DNS_Message.PTR_QUERY_TYPE) ! protInfo.setDescription("IP-address '"+query.substring(1) + "' conform to host '" + answer.substring(0, answer.length()-1) + "'."); ! else if (qType == DNS_Message.HINFO_QUERY_TYPE) ! protInfo.setDescription("HINFO section for host "+query.substring(1, query.length()-1)+": '"+ answer + "'."); ! else if (qType == DNS_Message.MX_QUERY_TYPE) ! protInfo.setDescription("For '"+query.substring(1, query.length()-1)+"' mail exchanger(s) = " + answer + "."); } Simulation.addLayerInfo(protInfo); //protInfo.setDescription(Data); --- 200,231 ---- protInfo.setDataType("DNS Protocol Data"); protInfo.setLayer("Application "); ! //protInfo.setDescription("Receiving DNS message from server."); // Simulation.addLayerInfo(protInfo); DNS_Message dnsMsg = new DNS_Message(Data); ! String desc = ""; ! if (dnsMsg.getRCode()==3) { ! desc = "No "+DNS_Message.getTypeString(dnsMsg.getQuery().get(0).type)+" record found for '"+dnsMsg.getQuery().get(0).name+"'."; } ! else if(dnsMsg.getRCode()==0) { ! receivedMessages.put(dnsMsg.getID(), dnsMsg); ! // Vector<DNS_Message.Query> query = dnsMsg.getQuery(); ! Vector<DNS_Message.Answer> answer = dnsMsg.getAnswer(); ! for(int i=0; i<answer.size(); i++){ ! DNS_Message.Answer ans = answer.get(i); ! desc += (i==0?"":"; ")+ans.name+" "+DNS_Message.getTypeString(ans.type)+" "+ans.resource; ! } ! // int qType = dnsMsg.getQueryType(); ! // if (qType == DNS_Message.A_QUERY_TYPE) ! // protInfo.setDescription("Host '"+query.substring(1, query.length()-1) + "' has IP-address '" + answer + "'."); ! // else if (qType == DNS_Message.PTR_QUERY_TYPE) ! // protInfo.setDescription("IP-address '"+query.substring(1) + "' conform to host '" + answer.substring(0, answer.length()-1) + "'."); ! // else if (qType == DNS_Message.HINFO_QUERY_TYPE) ! // protInfo.setDescription("HINFO section for host "+query.substring(1, query.length()-1)+": '"+ answer + "'."); ! // else if (qType == DNS_Message.MX_QUERY_TYPE) ! // protInfo.setDescription("For '"+query.substring(1, query.length()-1)+"' mail exchanger(s) = " + answer + "."); } + protInfo.setDescription(desc); Simulation.addLayerInfo(protInfo); //protInfo.setDescription(Data); *************** *** 203,207 **** }else{ ! //server processing recieve try{ String sdHost = mParentStack.SL().get_socket(sock).dst_IP; --- 233,237 ---- }else{ ! //server processing receive try{ String sdHost = mParentStack.SL().get_socket(sock).dst_IP; *************** *** 212,248 **** protInfo.setDataType("Echo Protocol Data"); protInfo.setLayer("Application "); ! protInfo.setDescription("Recieving DNS message '" + Data + "' from client " + sdHost + ":" + sdPort + "."); Simulation.addLayerInfo(protInfo); DNS_Message inputMes = new DNS_Message(Data); ! DNS_Message answerMes; //parse query and search in HashTable ! String query = inputMes.GetQuery(); ! String qType = Integer.toString(query.codePointAt(0)); ! query = query.substring(1); ! String[] answer = (String[])hs.get(query); ! String answerStr=null; ! if (answer!=null && !answer.equals("")) ! { ! if (qType.equals("1") || qType.equals("12")) ! answerStr = answer[0].trim(); ! else if (qType.equals("13")) ! answerStr = answer[1].trim(); ! else if (qType.equals("15")) ! answerStr = answer[2].trim(); ! else ! answerStr = ""; } ! if (answerStr!=null && !answerStr.equals("")) ! answerMes = new DNS_Message(1,0,1,0,1,0,0,query.concat(":"+qType),answerStr,"",""); else ! answerMes = new DNS_Message(1,0,1,0,1,0,3,query.concat(":"+qType),"","",""); LayerInfo protInfo2 = new LayerInfo(getClass().getName()); protInfo2.setObjectName(mParentStack.getParentNodeName()); protInfo2.setDataType("DNS Protocol Data"); protInfo2.setLayer("Application "); ! protInfo2.setDescription("Sending DNS message '" + answerMes.ToString() + "' to client."); Simulation.addLayerInfo(protInfo2); ! SendData(appSock,answerMes); /*LayerInfo protInfo3 = new LayerInfo(getClass().getName()); --- 242,341 ---- protInfo.setDataType("Echo Protocol Data"); protInfo.setLayer("Application "); ! protInfo.setDescription("Receiving DNS message '" + Data + "' from client " + sdHost + ":" + sdPort + "."); Simulation.addLayerInfo(protInfo); DNS_Message inputMes = new DNS_Message(Data); ! DNS_Message answerPack; //parse query and search in HashTable ! Vector<DNS_Message.Query> query = inputMes.getQuery(); ! LinkedList<DNS_Message.Query> qus = new LinkedList<DNS_Message.Query>(); ! for(int i=0; i<query.size(); i++){ ! qus.add(query.get(i)); } ! Vector<DNS_Message.Answer> answer = new Vector<DNS_Message.Answer>(0); ! while(qus.size()>0){ ! DNS_Message.Query qu = qus.getFirst(); ! qus.removeFirst(); ! switch(qu.type){ ! case DNS_Message.A_QUERY_TYPE: { ! if(records_a.containsKey(qu.name)){ ! Vector<String> ans = records_a.get(qu.name); ! for(int i=0; i<ans.size(); i++) ! answer.add(new DNS_Message.Answer(qu.name, qu.type, DNS_Message.TTL_DEFAULT, ans.get(i),0,0)); ! } ! if(records_cname.containsKey(qu.name)){ ! Vector<String> ans = records_cname.get(qu.name); ! for(int i=0; i<ans.size(); i++){ ! answer.add(new DNS_Message.Answer(qu.name, DNS_Message.CNAME_QUERY_TYPE, DNS_Message.TTL_DEFAULT, ans.get(i),0,0)); ! qus.add(0, new DNS_Message.Query(ans.get(i),DNS_Message.A_QUERY_TYPE,0)); ! } ! } ! break; ! } ! case DNS_Message.CNAME_QUERY_TYPE: { ! if(records_cname.containsKey(qu.name)){ ! Vector<String> ans = records_cname.get(qu.name); ! for(int i=0; i<ans.size(); i++){ ! answer.add(new DNS_Message.Answer(qu.name, qu.type, DNS_Message.TTL_DEFAULT, ans.get(i),0,0)); ! qus.add(0, new DNS_Message.Query(ans.get(i),DNS_Message.CNAME_QUERY_TYPE,0)); ! } ! } ! break; ! } ! case DNS_Message.PTR_QUERY_TYPE: { ! if(records_ptr.containsKey(qu.name)){ ! Vector<String> ans = records_ptr.get(qu.name); ! for(int i=0; i<ans.size(); i++) ! answer.add(new DNS_Message.Answer(qu.name, qu.type, DNS_Message.TTL_DEFAULT, ans.get(i),0,0)); ! } ! break; ! } ! case DNS_Message.HINFO_QUERY_TYPE: { ! if(records_hinfo.containsKey(qu.name)){ ! answer.add(new DNS_Message.Answer(qu.name, qu.type, DNS_Message.TTL_DEFAULT, records_hinfo.get(qu.name),0,0)); ! } ! if(records_cname.containsKey(qu.name)){ ! Vector<String> ans = records_cname.get(qu.name); ! for(int i=0; i<ans.size(); i++){ ! answer.add(new DNS_Message.Answer(qu.name, DNS_Message.CNAME_QUERY_TYPE, DNS_Message.TTL_DEFAULT, ans.get(i),0,0)); ! qus.add(0, new DNS_Message.Query(ans.get(i),DNS_Message.A_QUERY_TYPE,0)); ! } ! } ! break; ! } ! case DNS_Message.MX_QUERY_TYPE: { ! if(records_mx.containsKey(qu.name)){ ! Vector<Pair> ans = records_mx.get(qu.name); ! for(int i=0; i<ans.size(); i++) ! answer.add(new DNS_Message.Answer(qu.name, qu.type, DNS_Message.TTL_DEFAULT, (String)ans.get(i).getFirst(),((Integer)ans.get(i).getSecond()).intValue(),0)); ! } ! if(records_cname.containsKey(qu.name)){ ! Vector<String> ans = records_cname.get(qu.name); ! for(int i=0; i<ans.size(); i++){ ! answer.add(new DNS_Message.Answer(qu.name, DNS_Message.CNAME_QUERY_TYPE, DNS_Message.TTL_DEFAULT, ans.get(i),0,0)); ! qus.add(0, new DNS_Message.Query(ans.get(i),DNS_Message.A_QUERY_TYPE,0)); ! } ! } ! break; ! } ! } ! } ! if (answer.size()>0) ! answerPack = new DNS_Message(inputMes.getID(), 1,0,1,0,1,0,0,query,answer,null,null); else ! answerPack = new DNS_Message(inputMes.getID(), 1,0,1,0,1,0,3,query,answer,null,null); ! ! String answerMes = ""; ! for(int i=0; i<answer.size(); i++){ ! DNS_Message.Answer ans = answer.get(i); ! answerMes += (i==0?"":"; ")+ans.name+" "+DNS_Message.getTypeString(ans.type)+" "+ans.resource; ! } LayerInfo protInfo2 = new LayerInfo(getClass().getName()); protInfo2.setObjectName(mParentStack.getParentNodeName()); protInfo2.setDataType("DNS Protocol Data"); protInfo2.setLayer("Application "); ! protInfo2.setDescription("Sending DNS message '" + answerMes + "' to client."); Simulation.addLayerInfo(protInfo2); ! SendData(appSock,answerPack); /*LayerInfo protInfo3 = new LayerInfo(getClass().getName()); *************** *** 256,274 **** //Listen(); }catch(Exception e){ ! System.out.println(e.toString()); ! ///*TODO*: here to catch } } } ! public void SetRespondTable(Hashtable ht) ! { ! hs = ht; } ! public Hashtable GetRespondTable() ! { ! return hs; } } --- 349,552 ---- //Listen(); }catch(Exception e){ ! e.printStackTrace(); } } } ! public void addRecord(String dname, String value, int type){ ! switch(type){ ! case DNS_Message.A_QUERY_TYPE: { ! if(records_a.containsKey(dname)){ ! Vector<String> ans = records_a.get(dname); ! boolean found = false; ! for(int i=0; i<ans.size() && !found; i++){ ! found = ans.get(i).equalsIgnoreCase(value); ! } ! if(!found){ ! ans.add(value); ! } ! } ! else{ ! Vector<String> ans = new Vector<String>(1); ! ans.add(value); ! records_a.put(dname, ans); ! } ! break; ! } ! case DNS_Message.CNAME_QUERY_TYPE: { ! if(records_cname.containsKey(dname)){ ! Vector<String> ans = records_cname.get(dname); ! boolean found = false; ! for(int i=0; i<ans.size() && !found; i++){ ! found = ans.get(i).equalsIgnoreCase(value); ! } ! if(!found){ ! ans.add(value); ! } ! } ! else{ ! Vector<String> ans = new Vector<String>(1); ! ans.add(value); ! records_cname.put(dname, ans); ! } ! break; ! } ! case DNS_Message.PTR_QUERY_TYPE: { ! if(records_ptr.containsKey(dname)){ ! Vector<String> ans = records_ptr.get(dname); ! boolean found = false; ! for(int i=0; i<ans.size() && !found; i++){ ! found = ans.get(i).equalsIgnoreCase(value); ! } ! if(!found){ ! ans.add(value); ! } ! } ! else{ ! Vector<String> ans = new Vector<String>(1); ! ans.add(value); ! records_ptr.put(dname, ans); ! } ! break; ! } ! case DNS_Message.HINFO_QUERY_TYPE: { ! records_hinfo.put(dname, value); ! break; ! } ! case DNS_Message.MX_QUERY_TYPE: { ! String[] mxvalue = value.split(":"); ! if(records_mx.containsKey(dname)){ ! Vector<Pair> ans = records_mx.get(dname); ! boolean found = false; ! int i; ! for(i=0; i<ans.size() && !found; i++){ ! found = ((String)ans.get(i).getFirst()).equalsIgnoreCase(mxvalue[0]); ! } ! if(found){ ! ans.set(i, new Pair(mxvalue[0],Integer.valueOf(mxvalue[1]))); ! } ! else{ ! ans.add(new Pair(mxvalue[0],Integer.valueOf(mxvalue[1]))); ! } ! } ! else{ ! Vector<Pair> ans = new Vector<Pair>(1); ! ans.add(new Pair(mxvalue[0],Integer.valueOf(mxvalue[1]))); ! records_mx.put(dname, ans); ! } ! break; ! } ! } } ! public boolean removeRecord(String dname, String value, int type){ ! boolean result = false; ! switch(type){ ! case DNS_Message.A_QUERY_TYPE: { ! if(records_a.containsKey(dname)){ ! Vector<String> ans = records_a.get(dname); ! boolean found = false; ! for(int i=0; i<ans.size() && !found; i++){ ! found = ans.get(i).equalsIgnoreCase(value); ! if(found){ ! ans.remove(i); ! result = true; ! } ! } ! } ! break; ! } ! case DNS_Message.CNAME_QUERY_TYPE: { ! if(records_cname.containsKey(dname)){ ! Vector<String> ans = records_cname.get(dname); ! boolean found = false; ! for(int i=0; i<ans.size() && !found; i++){ ! found = ans.get(i).equalsIgnoreCase(value); ! if(found){ ! ans.remove(i); ! result = true; ! } ! } ! } ! break; ! } ! case DNS_Message.PTR_QUERY_TYPE: { ! if(records_ptr.containsKey(dname)){ ! Vector<String> ans = records_ptr.get(dname); ! boolean found = false; ! for(int i=0; i<ans.size() && !found; i++){ ! found = ans.get(i).equalsIgnoreCase(value); ! if(found){ ! ans.remove(i); ! result = true; ! } ! } ! } ! break; ! } ! case DNS_Message.HINFO_QUERY_TYPE: { ! if(records_hinfo.containsKey(dname)){ ! records_hinfo.remove(dname); ! result = true; ! } ! break; ! } ! case DNS_Message.MX_QUERY_TYPE: { ! String[] mxvalue = value.split(":"); ! if(records_mx.containsKey(dname)){ ! Vector<Pair> ans = records_mx.get(dname); ! boolean found = false; ! for(int i=0; i<ans.size() && !found; i++){ ! found = ((String)ans.get(i).getFirst()).equalsIgnoreCase(mxvalue[0]); ! if(found){ ! ans.remove(i); ! result = true; ! } ! } ! } ! break; ! } ! } ! return result; ! } ! ! public static String toInAddrArpa(String ip){ ! String[] ipn = ip.split("\\."); ! try{ ! if(ipn.length==4){ ! for(int i=0; i<4; i++){ ! int num = Integer.parseInt(ipn[i]); ! if(num<0 || num>255) throw new NumberFormatException(); ! } ! return ipn[3]+"."+ipn[2]+"."+ipn[1]+"."+ipn[0]+".in-addr.arpa"; ! } ! } ! catch(NumberFormatException e){}; ! return null; } + public static String fromInAddrArpa(String arpa){ + String[] ipn = arpa.split("\\."); + if(ipn.length==6 && ipn[4].equalsIgnoreCase("in-addr") && ipn[5].equalsIgnoreCase("arpa")) + return ipn[3]+"."+ipn[2]+"."+ipn[1]+"."+ipn[0]; + return null; + } + + public static boolean isValidName(String name){ + if(name.length()==0) return false; + for(int i=0; i<name.length(); i++){ + char c = name.charAt(i); + if(!((c>='0' && c<='9') || (c>='a' && c<='z') || (c>='A' && c<='Z') || c=='-' || c=='.')) return false; + } + return (toInAddrArpa(name)==null); // name is not valid IP-address + } + + public static boolean isValidMail(String name){ + if(name.length()==0) return false; + for(int i=0; i<name.length(); i++){ + char c = name.charAt(i); + if(!((c>='0' && c<='9') || (c>='a' && c<='z') || (c>='A' && c<='Z') || c=='-' || c=='.' || c=='@')) return false; + } + return true; + } } |
From: QweR <qw...@us...> - 2008-10-18 19:55:56
|
Update of /cvsroot/javanetsim/javaNetSim/core In directory fdv4jf1.ch3.sourceforge.com:/tmp/cvs-serv9668/core Modified Files: ApplicationLayerDevice.java CommandProcessor.java DeviceConfig.java Log Message: DNS works! Index: CommandProcessor.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/core/CommandProcessor.java,v retrieving revision 1.25 retrieving revision 1.26 diff -C2 -d -r1.25 -r1.26 *** CommandProcessor.java 13 Oct 2008 22:52:07 -0000 1.25 --- CommandProcessor.java 18 Oct 2008 19:55:31 -0000 1.26 *************** *** 12,15 **** --- 12,17 ---- import core.protocolsuite.tcp_ip.DHCPC; import core.protocolsuite.tcp_ip.DHCPD; + import core.protocolsuite.tcp_ip.DNS; + import core.protocolsuite.tcp_ip.DNS_Message; import core.protocolsuite.tcp_ip.IPV4Address; import core.protocolsuite.tcp_ip.InvalidIPAddressException; *************** *** 82,85 **** --- 84,91 ---- private ip_dhcp_pool__network_CommandClass ip_dhcp_pool__network_Command = new ip_dhcp_pool__network_CommandClass(); private ip_dhcp_excluded_address_CommandClass ip_dhcp_excluded_address_Command = new ip_dhcp_excluded_address_CommandClass(); + private ip_dns_primary_CommandClass ip_dns_primary_Command = new ip_dns_primary_CommandClass(); + private ip_dns_server_CommandClass ip_dns_server_Command = new ip_dns_server_CommandClass(); + 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_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(); *************** *** 123,127 **** private telnet_CommandClass telnet_Command = new telnet_CommandClass(); private telnet_server_CommandClass telnet_server_Command = new telnet_server_CommandClass(); - private traceroute_CommandClass traceroute_Command = new traceroute_CommandClass(); private username_CommandClass username_Command = new username_CommandClass(); private write_memory_CommandClass write_memory_Command = new write_memory_CommandClass(); --- 129,132 ---- *************** *** 186,189 **** --- 191,199 ---- commands.add("ip dhcp pool * default-router", ip_dhcp_pool__default_router_Command, "Default routers"); commands.add("ip dhcp excluded-address", ip_dhcp_excluded_address_Command, "Prevent DHCP from assigning certain addresses"); + commands.addDescription("ip dns","Configure DNS server for a zone"); + commands.add("ip dns primary", ip_dns_primary_Command, "Configure primary DNS server"); + commands.add("ip dns server", ip_dns_server_Command, "Enable DNS server"); + 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.addDescription("ip nat","NAT configuration commands"); commands.addDescription("ip nat inside","Inside address translation"); *************** *** 245,249 **** commands.add("telnet-server", telnet_server_Command, "Enable TELNET server; Specify server port"); commands.add("no telnet-server", telnet_server_Command, "Disable TELNET server"); - commands.add("traceroute", traceroute_Command, "Trace route to destination"); commands.add("username", username_Command, "Add User"); commands.addDescription("write","Write running configuration to memory or terminal"); --- 255,258 ---- *************** *** 1214,1218 **** String out = ""; if(device instanceof ApplicationLayerDevice){ ! DHCPC dhcpc = (DHCPC)((ApplicationLayerDevice)device).getApp(PC.DHCP_CLIENT_ID); if(dhcpc!=null){ if(params.size()==1){ --- 1223,1227 ---- String out = ""; if(device instanceof ApplicationLayerDevice){ ! DHCPC dhcpc = (DHCPC)((ApplicationLayerDevice)device).getApp(core.ApplicationLayerDevice.DHCP_CLIENT_ID); if(dhcpc!=null){ if(params.size()==1){ *************** *** 1250,1254 **** String out = ""; if(device instanceof ApplicationLayerDevice){ ! DHCPC dhcpc = (DHCPC)((ApplicationLayerDevice)device).getApp(PC.DHCP_CLIENT_ID); if(dhcpc!=null){ if(params.size()==1){ --- 1259,1263 ---- String out = ""; if(device instanceof ApplicationLayerDevice){ ! DHCPC dhcpc = (DHCPC)((ApplicationLayerDevice)device).getApp(core.ApplicationLayerDevice.DHCP_CLIENT_ID); if(dhcpc!=null){ if(params.size()==1){ *************** *** 1755,1759 **** String out = ""; if(device instanceof ApplicationLayerDevice){ ! DHCPD dhcpd = (DHCPD)((ApplicationLayerDevice)device).getApp(PC.DHCP_SERVER_ID); if(dhcpd!=null){ if(params.size()==2){ --- 1764,1768 ---- String out = ""; if(device instanceof ApplicationLayerDevice){ ! DHCPD dhcpd = (DHCPD)((ApplicationLayerDevice)device).getApp(core.ApplicationLayerDevice.DHCP_SERVER_ID); if(dhcpd!=null){ if(params.size()==2){ *************** *** 1787,1791 **** String out = ""; if(device instanceof ApplicationLayerDevice){ ! DHCPD dhcpd = (DHCPD)((ApplicationLayerDevice)device).getApp(PC.DHCP_SERVER_ID); if(dhcpd!=null){ if(params.size()==1){ --- 1796,1800 ---- String out = ""; if(device instanceof ApplicationLayerDevice){ ! DHCPD dhcpd = (DHCPD)((ApplicationLayerDevice)device).getApp(core.ApplicationLayerDevice.DHCP_SERVER_ID); if(dhcpd!=null){ if(params.size()==1){ *************** *** 1822,1826 **** String out = ""; if(device instanceof ApplicationLayerDevice){ ! DHCPD dhcpd = (DHCPD)((ApplicationLayerDevice)device).getApp(PC.DHCP_SERVER_ID); if(dhcpd!=null){ if(params.size()==2){ --- 1831,1835 ---- String out = ""; if(device instanceof ApplicationLayerDevice){ ! DHCPD dhcpd = (DHCPD)((ApplicationLayerDevice)device).getApp(core.ApplicationLayerDevice.DHCP_SERVER_ID); if(dhcpd!=null){ if(params.size()==2){ *************** *** 1854,1858 **** String out = ""; if(device instanceof ApplicationLayerDevice){ ! DHCPD dhcpd = (DHCPD)((ApplicationLayerDevice)device).getApp(PC.DHCP_SERVER_ID); if(dhcpd!=null){ if(params.size()==1){ --- 1863,1867 ---- String out = ""; if(device instanceof ApplicationLayerDevice){ ! DHCPD dhcpd = (DHCPD)((ApplicationLayerDevice)device).getApp(core.ApplicationLayerDevice.DHCP_SERVER_ID); if(dhcpd!=null){ if(params.size()==1){ *************** *** 1889,1893 **** String out = ""; if(device instanceof ApplicationLayerDevice){ ! DHCPD dhcpd = (DHCPD)((ApplicationLayerDevice)device).getApp(PC.DHCP_SERVER_ID); if(dhcpd!=null){ if(params.size()==3){ --- 1898,1902 ---- String out = ""; if(device instanceof ApplicationLayerDevice){ ! DHCPD dhcpd = (DHCPD)((ApplicationLayerDevice)device).getApp(core.ApplicationLayerDevice.DHCP_SERVER_ID); if(dhcpd!=null){ if(params.size()==3){ *************** *** 1929,1933 **** String out = ""; if(device instanceof ApplicationLayerDevice){ ! DHCPD dhcpd = (DHCPD)((ApplicationLayerDevice)device).getApp(PC.DHCP_SERVER_ID); if(dhcpd!=null){ if(params.size()==1){ --- 1938,1942 ---- String out = ""; if(device instanceof ApplicationLayerDevice){ ! DHCPD dhcpd = (DHCPD)((ApplicationLayerDevice)device).getApp(core.ApplicationLayerDevice.DHCP_SERVER_ID); if(dhcpd!=null){ if(params.size()==1){ *************** *** 1970,1974 **** String out = ""; if(device instanceof ApplicationLayerDevice){ ! DHCPD dhcpd = (DHCPD)((ApplicationLayerDevice)device).getApp(PC.DHCP_SERVER_ID); if(dhcpd!=null){ if(params.size()==2){ --- 1979,1983 ---- String out = ""; if(device instanceof ApplicationLayerDevice){ ! DHCPD dhcpd = (DHCPD)((ApplicationLayerDevice)device).getApp(core.ApplicationLayerDevice.DHCP_SERVER_ID); if(dhcpd!=null){ if(params.size()==2){ *************** *** 1998,2002 **** String out = ""; if(device instanceof ApplicationLayerDevice){ ! DHCPD dhcpd = (DHCPD)((ApplicationLayerDevice)device).getApp(PC.DHCP_SERVER_ID); if(dhcpd!=null){ if(params.size()==2){ --- 2007,2011 ---- String out = ""; if(device instanceof ApplicationLayerDevice){ ! DHCPD dhcpd = (DHCPD)((ApplicationLayerDevice)device).getApp(core.ApplicationLayerDevice.DHCP_SERVER_ID); if(dhcpd!=null){ if(params.size()==2){ *************** *** 2024,2027 **** --- 2033,2384 ---- } }; + class ip_dns_primary_CommandClass extends CommandInterface{ + public ip_dns_primary_CommandClass(){ + modes = new Modes(CommandInterface.CONF_MODE, CommandInterface.APPLICATION_LAYER, CommandInterface.NO_CALL); + call_params = "<DNS domain name> soa <DNS primary name server> <DNS mailbox of responsible person> <Refresh time> <Refresh retry time> <Authority expire time> <Minimum TTL for zone info>"; + no_call_params = "<cr>"; + } + public String call(Vector<String> params){ + String out = ""; + if(device instanceof ApplicationLayerDevice){ + DNS dns = (DNS)((ApplicationLayerDevice)device).getApp(core.ApplicationLayerDevice.DNS_SERVER_ID); + if(dns!=null){ + if(params.size()==8){ + String DomainName = params.get(0); + String soa = params.get(1); + String PrimaryNameServer = params.get(2); + String MailboxResponsiblePerson = params.get(3); + int RefreshTime = 0; + int RefreshRetryTime = 0; + int AuthorityExpireTime = 0; + int MinimumTTLZoneInfo = 0; + try{RefreshTime = Integer.parseInt(params.get(4));}catch(NumberFormatException e){} + try{RefreshRetryTime = Integer.parseInt(params.get(5));}catch(NumberFormatException e){} + try{AuthorityExpireTime = Integer.parseInt(params.get(6));}catch(NumberFormatException e){} + try{MinimumTTLZoneInfo = Integer.parseInt(params.get(7));}catch(NumberFormatException e){} + if(DNS.isValidName(DomainName)){ + if(soa.equalsIgnoreCase("soa")){ + if(DNS.isValidName(PrimaryNameServer)){ + if(DNS.isValidMail(MailboxResponsiblePerson)){ + if(DNS.isValidMail(MailboxResponsiblePerson)){ + if(RefreshTime>0){ + if(RefreshRetryTime>0){ + if(AuthorityExpireTime>0){ + if(MinimumTTLZoneInfo>0){ + dns.DomainName = DomainName; + dns.PrimaryNameServer = PrimaryNameServer; + dns.MailboxResponsiblePerson = MailboxResponsiblePerson; + dns.RefreshTime = RefreshTime; + dns.RefreshRetryTime = RefreshRetryTime; + dns.AuthorityExpireTime = AuthorityExpireTime; + dns.MinimumTTLZoneInfo = MinimumTTLZoneInfo; + } + else{ + out += "error: invalid Minimum TTL for zone info (must be between 1 and 2147483647)\n"; + } + } + else{ + out += "error: invalid Authority expire time (must be between 1 and 2147483647)\n"; + } + } + else{ + out += "error: invalid Refresh retry time (must be between 1 and 2147483647)\n"; + } + } + else{ + out += "error: invalid Refresh time (must be between 1 and 2147483647)\n"; + } + } + else{ + out += "error: invalid DNS mailbox of responsible person\n"; + } + } + else{ + out += "error: invalid DNS mailbox of responsible person\n"; + } + } + else{ + out += "error: invalid DNS primary name server\n"; + } + } + else{ + out += "error: keyword 'soa' expected\n"; + } + } + else{ + out += "error: invalid DNS domain name\n"; + } + } + else{ + out += "error: invalid parameters\n"; + } + } + else{ + out += "This instruction not supported by device\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){ + DNS dns = (DNS)((ApplicationLayerDevice)device).getApp(core.ApplicationLayerDevice.DNS_SERVER_ID); + if(dns!=null){ + if(params.size()==0){ + dns.DomainName = ""; + dns.PrimaryNameServer = ""; + dns.MailboxResponsiblePerson = ""; + dns.RefreshTime = 86400; + dns.RefreshRetryTime = 3600; + dns.AuthorityExpireTime = 1209600; + dns.MinimumTTLZoneInfo = 86400; + } + else{ + out += "error: invalid parameters\n"; + } + } + else{ + out += "This instruction not supported by device\n"; + } + } + else{ + out += "This instruction not supported by device\n"; + } + return out; + } + }; + class ip_dns_server_CommandClass extends CommandInterface{ + public ip_dns_server_CommandClass(){ + modes = new Modes(CommandInterface.CONF_MODE, CommandInterface.APPLICATION_LAYER, CommandInterface.NO_CALL); + call_params = "(<port>|<cr>)"; + no_call_params = "<cr>"; + } + public String call(Vector<String> params){ + String out = ""; + if(device instanceof ApplicationLayerDevice){ + DNS dns = (DNS)((ApplicationLayerDevice)device).getApp(core.ApplicationLayerDevice.DNS_SERVER_ID); + if(dns!=null){ + if(params.size()==0 || params.size()==1){ + int port = 53; + if(params.size()==1) port = Integer.parseInt(params.get(0)); + dns.setPort(port); + try { + dns.Listen(); + } catch (TransportLayerException e) { + out += "error: DNS server couldn't stated\n"; + } + } + else{ + out += "error: invalid parameters\n"; + } + } + else{ + out += "This instruction not supported by device\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){ + DNS dns = (DNS)((ApplicationLayerDevice)device).getApp(core.ApplicationLayerDevice.DNS_SERVER_ID); + if(dns!=null){ + if(params.size()==0){ + try { + dns.Close(); + } catch (TransportLayerException e) { + out += "error: DNS server couldn't stopped\n"; + } + } + else{ + out += "error: invalid parameters\n"; + } + } + else{ + out += "This instruction not supported by device\n"; + } + } + else{ + out += "This instruction not supported by device\n"; + } + return out; + } + }; + class ip_host_CommandClass extends CommandInterface{ + public ip_host_CommandClass(){ + modes = new Modes(CommandInterface.CONF_MODE, CommandInterface.APPLICATION_LAYER, CommandInterface.NO_CALL); + call_params = "(<name of host> <IP address>|<IP address> <name of host>|<name of domain> mx <priority> <name of host>|<name of host> cname <name of host>)"; + no_call_params = "(<name of host> <IP address>|<IP address> <name of host>|<name of domain> mx <priority> <name of host>|<name of host> cname <name of host>)"; + } + public String call(Vector<String> params){ + return parse(params,true); + } + public String no_call(Vector<String> params){ + return parse(params,false); + } + private String parse(Vector<String> params, boolean add){ + String out = ""; + if(device instanceof ApplicationLayerDevice){ + DNS dns = (DNS)((ApplicationLayerDevice)device).getApp(core.ApplicationLayerDevice.DNS_SERVER_ID); + if(dns!=null){ + if(params.size()>=2 && params.size()<=4){ + switch(params.size()){ + case 2:{ + String first = params.get(0); + String second = params.get(1); + if(IPV4Address.validateDecIP(first) && DNS.isValidName(second)){ + if(add) + dns.addRecord(DNS.toInAddrArpa(first), second, DNS_Message.PTR_QUERY_TYPE); + else + dns.removeRecord(DNS.toInAddrArpa(first), second, DNS_Message.PTR_QUERY_TYPE); + } + else if(IPV4Address.validateDecIP(second) && DNS.isValidName(first)){ + if(add) + dns.addRecord(first, second, DNS_Message.A_QUERY_TYPE); + else + dns.removeRecord(first, second, DNS_Message.A_QUERY_TYPE); + } + else{ + out += "error: invalid A or PTR record\n"; + } + break; + } + case 3:{ + String host1 = params.get(0); + String cname = params.get(1); + String host2 = params.get(2); + if(cname.equalsIgnoreCase("cname")){ + if(DNS.isValidName(host1) && DNS.isValidName(host2)){ + if(add) + dns.addRecord(host1, host2, DNS_Message.CNAME_QUERY_TYPE); + else + dns.removeRecord(host1, host2, DNS_Message.CNAME_QUERY_TYPE); + } + else{ + out += "error: invalid host name\n"; + } + } + else{ + out += "error: keyword 'cname' expected\n"; + } + break; + } + case 4:{ + String domain = params.get(0); + String mx = params.get(1); + String priority = params.get(2); + String host = params.get(3); + if(mx.equalsIgnoreCase("mx")){ + if(DNS.isValidName(domain) && DNS.isValidName(host)){ + try{ + int pr = Integer.parseInt(priority); + if(pr>0 && pr<65536) + if(add) + dns.addRecord(domain, host+":"+priority, DNS_Message.MX_QUERY_TYPE); + else + dns.removeRecord(domain, host, DNS_Message.MX_QUERY_TYPE); + else + out += "error: priority must be between 1 and 65535\n"; + } + catch(NumberFormatException e){ + out += "error: priority must be between 1 and 65535\n"; + } + } + else{ + out += "error: invalid host name\n"; + } + } + else{ + out += "error: keyword 'mx' expected\n"; + } + break; + } + } + } + else{ + out += "error: invalid parameters\n"; + } + } + else{ + out += "This instruction not supported by device\n"; + } + } + else{ + out += "This instruction not supported by device\n"; + } + return out; + } + }; + class ip_host_hinfo_CommandClass extends CommandInterface{ + public ip_host_hinfo_CommandClass(){ + modes = new Modes(CommandInterface.CONF_MODE, CommandInterface.APPLICATION_LAYER, CommandInterface.NO_CALL); + call_params = "<name of host> <description>"; + no_call_params = "<name of host>"; + } + public String call(Vector<String> params){ + String out = ""; + if(device instanceof ApplicationLayerDevice){ + DNS dns = (DNS)((ApplicationLayerDevice)device).getApp(core.ApplicationLayerDevice.DNS_SERVER_ID); + if(dns!=null){ + if(params.size()>1){ + String dname = params.get(0); + if(DNS.isValidName(dname)){ + String info = params.get(1); + for(int i=2; i<params.size(); i++){ + info += " "+params.get(i); + } + dns.addRecord(dname, info, DNS_Message.HINFO_QUERY_TYPE); + } + else{ + out += "error: invalid domain name\n"; + } + } + else{ + out += "error: invalid parameters\n"; + } + } + else{ + out += "This instruction not supported by device\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){ + DNS dns = (DNS)((ApplicationLayerDevice)device).getApp(core.ApplicationLayerDevice.DNS_SERVER_ID); + if(dns!=null){ + if(params.size()==1){ + String dname = params.get(0); + if(DNS.isValidName(dname)){ + dns.removeRecord(dname, null, DNS_Message.HINFO_QUERY_TYPE); + } + else{ + out += "error: invalid domain name\n"; + } + } + else{ + out += "error: invalid parameters\n"; + } + } + else{ + out += "This instruction not supported by device\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(){ *************** *** 3032,3036 **** String out = ""; if(device instanceof ApplicationLayerDevice){ ! Telnet_server telser = (Telnet_server) ((core.ApplicationLayerDevice)device).getApp(core.PC.TELNET_SERVER_ID); if(telser != null){ if(params.size()==0){ --- 3389,3393 ---- String out = ""; if(device instanceof ApplicationLayerDevice){ ! Telnet_server telser = (Telnet_server) ((core.ApplicationLayerDevice)device).getApp(core.ApplicationLayerDevice.TELNET_SERVER_ID); if(telser != null){ if(params.size()==0){ *************** *** 3070,3074 **** String out = ""; if(device instanceof ApplicationLayerDevice){ ! SNMP snmpa = (SNMP) ((core.ApplicationLayerDevice)device).getApp(core.PC.SNMP_AGENT_ID); if(snmpa != null){ out += "SNMP Community: "; --- 3427,3431 ---- String out = ""; if(device instanceof ApplicationLayerDevice){ ! SNMP snmpa = (SNMP) ((core.ApplicationLayerDevice)device).getApp(core.ApplicationLayerDevice.SNMP_AGENT_ID); if(snmpa != null){ out += "SNMP Community: "; *************** *** 3099,3103 **** String out = ""; if(device instanceof ApplicationLayerDevice){ ! SNMP snmpa = (SNMP) ((core.ApplicationLayerDevice)device).getApp(core.PC.SNMP_AGENT_ID); if(snmpa != null){ out += "SNMP mibs:\n"; --- 3456,3460 ---- String out = ""; if(device instanceof ApplicationLayerDevice){ ! SNMP snmpa = (SNMP) ((core.ApplicationLayerDevice)device).getApp(core.ApplicationLayerDevice.SNMP_AGENT_ID); if(snmpa != null){ out += "SNMP mibs:\n"; *************** *** 3269,3273 **** String out = ""; if(device instanceof ApplicationLayerDevice){ ! SNMP snmpa = (SNMP) ((core.ApplicationLayerDevice)device).getApp(core.PC.SNMP_AGENT_ID); if(snmpa != null){ if(params.size()==1){ --- 3626,3630 ---- String out = ""; if(device instanceof ApplicationLayerDevice){ ! SNMP snmpa = (SNMP) ((core.ApplicationLayerDevice)device).getApp(core.ApplicationLayerDevice.SNMP_AGENT_ID); if(snmpa != null){ if(params.size()==1){ *************** *** 3299,3303 **** String out = ""; if(device instanceof ApplicationLayerDevice){ ! SNMP snmpa = (SNMP) ((core.ApplicationLayerDevice)device).getApp(core.PC.SNMP_AGENT_ID); if(snmpa != null){ if(params.size() == 0){ --- 3656,3660 ---- String out = ""; if(device instanceof ApplicationLayerDevice){ ! SNMP snmpa = (SNMP) ((core.ApplicationLayerDevice)device).getApp(core.ApplicationLayerDevice.SNMP_AGENT_ID); if(snmpa != null){ if(params.size() == 0){ *************** *** 3329,3333 **** String out = ""; if(device instanceof ApplicationLayerDevice){ ! SNMP snmpa = (SNMP) ((core.ApplicationLayerDevice)device).getApp(core.PC.SNMP_AGENT_ID); if(snmpa != null){ if(params.size()==1){ --- 3686,3690 ---- String out = ""; if(device instanceof ApplicationLayerDevice){ ! SNMP snmpa = (SNMP) ((core.ApplicationLayerDevice)device).getApp(core.ApplicationLayerDevice.SNMP_AGENT_ID); if(snmpa != null){ if(params.size()==1){ *************** *** 3366,3370 **** String out = ""; if(device instanceof ApplicationLayerDevice){ ! SNMP snmpa = (SNMP) ((core.ApplicationLayerDevice)device).getApp(core.PC.SNMP_AGENT_ID); if(snmpa != null){ if(params.size()==0){ --- 3723,3727 ---- String out = ""; if(device instanceof ApplicationLayerDevice){ ! SNMP snmpa = (SNMP) ((core.ApplicationLayerDevice)device).getApp(core.ApplicationLayerDevice.SNMP_AGENT_ID); if(snmpa != null){ if(params.size()==0){ *************** *** 3425,3429 **** String out = ""; if(device instanceof ApplicationLayerDevice){ ! Telnet_server telnets = (Telnet_server) ((core.ApplicationLayerDevice)device).getApp(core.PC.TELNET_SERVER_ID); if(telnets != null){ if(params.size()==1){ --- 3782,3786 ---- String out = ""; if(device instanceof ApplicationLayerDevice){ ! Telnet_server telnets = (Telnet_server) ((core.ApplicationLayerDevice)device).getApp(core.ApplicationLayerDevice.TELNET_SERVER_ID); if(telnets != null){ if(params.size()==1){ *************** *** 3460,3464 **** String out = ""; if(device instanceof ApplicationLayerDevice){ ! Telnet_server telnets = (Telnet_server) ((core.ApplicationLayerDevice)device).getApp(core.PC.TELNET_SERVER_ID); if(telnets != null){ if(params.size()==0){ --- 3817,3821 ---- String out = ""; if(device instanceof ApplicationLayerDevice){ ! Telnet_server telnets = (Telnet_server) ((core.ApplicationLayerDevice)device).getApp(core.ApplicationLayerDevice.TELNET_SERVER_ID); if(telnets != null){ if(params.size()==0){ *************** *** 3481,3493 **** } }; - class traceroute_CommandClass extends CommandInterface{ - public traceroute_CommandClass(){ - modes = new Modes(CommandInterface.STD_CONF_MODE, CommandInterface.NETWORK_LAYER, CommandInterface.CALL_ONLY); - call_params = "<IP>"; - } - public String call(Vector<String> params){ - return "Command not supported yet.\n"; - } - }; class username_CommandClass extends CommandInterface{ public username_CommandClass(){ --- 3838,3841 ---- Index: DeviceConfig.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/core/DeviceConfig.java,v retrieving revision 1.21 retrieving revision 1.22 diff -C2 -d -r1.21 -r1.22 *** DeviceConfig.java 13 Oct 2008 20:04:25 -0000 1.21 --- DeviceConfig.java 18 Oct 2008 19:55:31 -0000 1.22 *************** *** 23,26 **** --- 23,27 ---- import core.protocolsuite.tcp_ip.DHCPC; import core.protocolsuite.tcp_ip.DHCPD; + import core.protocolsuite.tcp_ip.DNS; import core.protocolsuite.tcp_ip.RIP; import core.protocolsuite.tcp_ip.Route_entry; *************** *** 510,569 **** conf.add("location "+device.location); } - protected void fillExtended(LinkedList conf){ - conf.add("clock set "+device.getClock()); - - if(device instanceof ApplicationLayerDevice){ - core.ApplicationLayerDevice appdevice = (core.ApplicationLayerDevice)device; - //SNMP - SNMP snmpa = (SNMP) appdevice.getApp(core.ApplicationLayerDevice.SNMP_AGENT_ID); - if(snmpa != null && snmpa.running){ - if(snmpa.getPort()!=snmpa.DEFAULT_PORT){ - conf.add("snmp-server port "+snmpa.getPort()); - } - conf.add("snmp-server community "+snmpa.getPassword()); - } - - //TELNET - Telnet_server telnets = (Telnet_server) appdevice.getApp(core.ApplicationLayerDevice.TELNET_SERVER_ID); - if(telnets != null && telnets.running){ - conf.add("telnet-server "+telnets.getPort()); - } - - //username - Enumeration<String> users = appdevice.getUserList(); - if(users!=null){ - String username; - while(users.hasMoreElements()){ - username = users.nextElement(); - conf.add("username "+username+" "+appdevice.getUserPassword(username)); - } - } - - //router rip - RIP rip = (RIP) appdevice.getApp(core.ApplicationLayerDevice.RIP_SERVER_ID); - if(rip != null){ - Enumeration<String> rip_ifaces = rip.getInterfaces().elements(); - if(rip_ifaces.hasMoreElements()){ - conf.add("router rip"); - while(rip_ifaces.hasMoreElements()){ - String riface = rip_ifaces.nextElement(); - conf.add("router rip network "+riface); - } - } - else conf.add("no router rip"); - } - } - } - - protected void fillRoute(LinkedList conf){ - if(device instanceof NetworkLayerDevice){ - String routes[] = device.getRouteTableEntries(); - for(int i=0; i<routes.length - 1; i++){ - Route_entry r = device.getRouteTableEntry(routes[i]); - conf.add("ip route "+routes[i]+" "+r.genMask+" "+r.gateway+" "+r.iFace); - } - } - } --- 511,516 ---- conf.add("location "+device.location); } + *************** *** 623,625 **** --- 570,681 ---- } } + + protected void fillExtended(LinkedList conf){ + conf.add("clock set "+device.getClock()); + + if(device instanceof ApplicationLayerDevice){ + core.ApplicationLayerDevice appdevice = (core.ApplicationLayerDevice)device; + //SNMP + SNMP snmpa = (SNMP) appdevice.getApp(core.ApplicationLayerDevice.SNMP_AGENT_ID); + if(snmpa != null && snmpa.running){ + if(snmpa.getPort()!=snmpa.DEFAULT_PORT){ + conf.add("snmp-server port "+snmpa.getPort()); + } + conf.add("snmp-server community "+snmpa.getPassword()); + } + + //TELNET + Telnet_server telnets = (Telnet_server) appdevice.getApp(core.ApplicationLayerDevice.TELNET_SERVER_ID); + if(telnets != null && telnets.running){ + conf.add("telnet-server "+telnets.getPort()); + } + + //username + Enumeration<String> users = appdevice.getUserList(); + if(users!=null){ + String username; + while(users.hasMoreElements()){ + username = users.nextElement(); + conf.add("username "+username+" "+appdevice.getUserPassword(username)); + } + } + + //router rip + RIP rip = (RIP) appdevice.getApp(core.ApplicationLayerDevice.RIP_SERVER_ID); + if(rip != null){ + Enumeration<String> rip_ifaces = rip.getInterfaces().elements(); + if(rip_ifaces.hasMoreElements()){ + conf.add("router rip"); + while(rip_ifaces.hasMoreElements()){ + String riface = rip_ifaces.nextElement(); + conf.add("router rip network "+riface); + } + } + else conf.add("no router rip"); + } + + //DNS + DNS dns = (DNS) appdevice.getApp(core.ApplicationLayerDevice.DNS_SERVER_ID); + if(dns != null){ + if(dns.listening){ + conf.add("ip dns server "+dns.getPort()); + } + if(DNS.isValidName(dns.DomainName) + && DNS.isValidName(dns.PrimaryNameServer) + && DNS.isValidMail(dns.MailboxResponsiblePerson)){ + conf.add("ip dns primary "+dns.DomainName+" soa "+dns.PrimaryNameServer+" " + +dns.MailboxResponsiblePerson+" "+dns.RefreshTime+" "+dns.RefreshRetryTime+" " + +dns.AuthorityExpireTime+" "+dns.MinimumTTLZoneInfo); + } + Hashtable<String,Vector<String>> rec = dns.records_a; + Enumeration<String> domains = rec.keys(); + while(domains.hasMoreElements()){ + String dname = domains.nextElement(); + Vector<String> vals = rec.get(dname); + for(int i=0; i<vals.size(); i++) + conf.add("ip host "+dname+" "+vals.get(i)); + } + rec = dns.records_ptr; + domains = rec.keys(); + while(domains.hasMoreElements()){ + String dname = domains.nextElement(); + Vector<String> vals = rec.get(dname); + for(int i=0; i<vals.size(); i++) + conf.add("ip host "+DNS.fromInAddrArpa(dname)+" "+vals.get(i)); + } + rec = dns.records_cname; + domains = rec.keys(); + while(domains.hasMoreElements()){ + String dname = domains.nextElement(); + Vector<String> vals = rec.get(dname); + for(int i=0; i<vals.size(); i++) + conf.add("ip host "+dname+" cname "+vals.get(i)); + } + Hashtable<String,Vector<Pair>> recm = dns.records_mx; + domains = recm.keys(); + while(domains.hasMoreElements()){ + String dname = domains.nextElement(); + Vector<Pair> vals = recm.get(dname); + for(int i=0; i<vals.size(); i++) + conf.add("ip host "+dname+" mx "+vals.get(i).getSecond()+" "+vals.get(i).getFirst()); + } + Hashtable<String,String> rech = dns.records_hinfo; + domains = rech.keys(); + while(domains.hasMoreElements()){ + String dname = domains.nextElement(); + conf.add("ip host hinfo "+dname+" "+rech.get(dname)); + } + } + } + } + + protected void fillRoute(LinkedList conf){ + if(device instanceof NetworkLayerDevice){ + String routes[] = device.getRouteTableEntries(); + for(int i=0; i<routes.length - 1; i++){ + Route_entry r = device.getRouteTableEntry(routes[i]); + conf.add("ip route "+routes[i]+" "+r.genMask+" "+r.gateway+" "+r.iFace); + } + } + } } Index: ApplicationLayerDevice.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/core/ApplicationLayerDevice.java,v retrieving revision 1.10 retrieving revision 1.11 diff -C2 -d -r1.10 -r1.11 *** ApplicationLayerDevice.java 13 Oct 2008 22:52:07 -0000 1.10 --- ApplicationLayerDevice.java 18 Oct 2008 19:55:31 -0000 1.11 *************** *** 69,72 **** --- 69,73 ---- // } } + userlist.clear(); super.turnOff(); } |
From: Alexander B. <da...@us...> - 2008-10-17 18:59:24
|
Update of /cvsroot/javanetsim/javaNetSim/images/simulation In directory fdv4jf1.ch3.sourceforge.com:/tmp/cvs-serv31175/images/simulation Added Files: mlswitch.png Log Message: --- NEW FILE: mlswitch.png --- (This appears to be a binary file; contents omitted.) |
From: Alexander B. <da...@us...> - 2008-10-17 18:59:21
|
Update of /cvsroot/javanetsim/javaNetSim/guiUI In directory fdv4jf1.ch3.sourceforge.com:/tmp/cvs-serv31175/guiUI Added Files: GuiMultilayerSwitch.java Log Message: --- NEW FILE: GuiMultilayerSwitch.java --- /* Java Firewall Simulator (jFirewallSim) Copyright (c) 2004, jFirewallSim development team All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: - Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. - Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. - Neither the name of the Canberra Institute of Technology nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR 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 guiUI; import core.Node; /** * <P>The GuiSwitch class is used to instantiate new Switches on the GUI</P> * * @author luke_hamilton * @since 15th November 2004 * @version v0.20 */ public class GuiMultilayerSwitch extends NetworkLayerDevice { /** * @param inName The name of the switch * @param inMainscreen The JFrame that the Switch will be created on */ public GuiMultilayerSwitch(String inName, MainScreen inMainScreen) { super(inName, inMainScreen,"images/simulation/mlswitch.png"); } public void addInterfaces(MainScreen parent, Node node){ String[] choices = {"24 Ethernet-TX ports switch.", "12 Ethernet-TX ports with 2 Ethernet-FX switch.", "24 Ethernet-TX ports with 2 Ethernet-FX switch.", "48 Ethernet-TX ports with 2 Ethernet-FX switch.", "12 Ethernet-FX ports with 2 Ethernet-TX switch." }; String choice = parent.getDeviceTypeDialog("Create new switch", "Please choose switch type", choices); int tx=0, fx=0; if(choice.contains(choices[0])){ tx = 24; fx = 0; }else if(choice.contains(choices[1])){ tx = 12; fx = 2; }else if(choice.contains(choices[2])){ tx = 24; fx = 2; }else if(choice.contains(choices[3])){ tx = 48; fx = 2; }else if(choice.contains(choices[4])){ tx = 2; fx = 12; } for(int i = 0; i < tx; i++){ node.addNetworkInterface(core.NetworkInterface.getIntName(core.NetworkInterface.Ethernet10T) + String.valueOf(i), core.NetworkInterface.Ethernet10T, false); } for(int i = 0; i < fx; i++){ node.addNetworkInterface(core.NetworkInterface.getIntName(core.NetworkInterface.Ethernet100FX) + String.valueOf(i), core.NetworkInterface.Ethernet100FX, false); } } } |
From: Alexander B. <da...@us...> - 2008-10-17 18:59:21
|
Update of /cvsroot/javanetsim/javaNetSim/core In directory fdv4jf1.ch3.sourceforge.com:/tmp/cvs-serv31175/core Added Files: MultilayerSwitch.java Log Message: --- NEW FILE: MultilayerSwitch.java --- package core; import java.util.Enumeration; import java.util.Hashtable; public class MultilayerSwitch extends NetworkLayerDevice { int sz = 0; int buffSize = 255; Hashtable<String, Hashtable<String, Long>> IntCaches; Hashtable<Integer, String> Vlans; public MultilayerSwitch(String inName, boolean inOn) { super(inName, 3, inOn); // pass name and protocolstack layer IntCaches = new Hashtable<String, Hashtable<String, Long>>(); Vlans = new Hashtable<Integer, String>(); } public Enumeration<Integer> getVlans(){ return Vlans.keys(); } public void addVlan(Integer v, String name){ Vlans.put(v, name); } public void removeVlan(Integer v){ Vlans.remove(v); } public void setVlanName(Integer v, String name){ Vlans.remove(v); Vlans.put(v, name); } public String getAllData(){ String file = ""; file += "vlan.dat\n"; file += "1\n"; Enumeration<Integer> it; Integer v; it = Vlans.keys(); while (it.hasMoreElements()) { v = it.nextElement(); file = file + v + "," + Vlans.get(v) + "|"; } file += "\n"; return file; } public void loadDataFile(String name, int lines, String Data){ if(name.equals("vlan.dat")){ Vlans.clear(); String[] vlans = Data.split("\\|"); for(int i = 0; i<vlans.length; i++){ if(vlans[i].length() > 1){ String[] vlan = vlans[i].split(","); Vlans.put(Integer.valueOf(vlan[0]), vlan[1]); } } } return; } public void addNetworkInterface(String name, int type, boolean active) { if (!active) { super.addNetworkInterface(name, type, false, 0); IntCaches.put(name, new Hashtable<String, Long>()); } } public void Reset() { sz = 0; Enumeration it; String nic = ""; it = NetworkInterfacetable.elements(); while (it.hasMoreElements()) { NetworkInterface tempInterface = (NetworkInterface) it .nextElement(); nic = tempInterface.getName(); Hashtable outInt = IntCaches.get(nic); outInt.clear(); } } public int getState() { return sz; } public String getCache() { Enumeration it, it2; String nic = ""; String result = ""; it = NetworkInterfacetable.elements(); while (it.hasMoreElements()) { NetworkInterface tempInterface = (NetworkInterface) it .nextElement(); nic = tempInterface.getName(); Hashtable outInt = IntCaches.get(nic); result = result + nic + ": "; it2 = outInt.keys(); while (it2.hasMoreElements()) { String mac = (String) it2.nextElement(); result = result + mac + "\t"; } result = result + "\n"; } return result; } /** * This method will recieve a packet from any of the connected links and the * copy the Packet and distribute a copy to each of the other connected * links. * * @author bevan_calliess * @param inPacket - * The packet to be transported * @param inLinkName - * The name of the link that sent the packet eg: eth0 */ public void receivePacket(Packet inPacket, String inInterfaceName) throws LowLinkException { if (sz != 1) { Ethernet_packet tempPacket = (Ethernet_packet) inPacket; Enumeration it; boolean intFound = false; String nic = ""; try { Hashtable<String, Long> inInt = IntCaches.get(inInterfaceName); inInt.put(tempPacket.getSourceMACAddress(), Long.valueOf(System.currentTimeMillis())); Ethernet_packet copyPacket = new Ethernet_packet(tempPacket .getData(), tempPacket.getDestinationMACAddress(), tempPacket.getSourceMACAddress()); it = NetworkInterfacetable.elements(); while (it.hasMoreElements()) { EthernetNetworkInterface tempInterface = (EthernetNetworkInterface) it .nextElement(); nic = tempInterface.getName(); Hashtable<String, Long> outInt = IntCaches.get(nic); if (outInt.get(tempPacket.getDestinationMACAddress()) != null) { intFound = true; try { if(tempInterface.mode == EthernetNetworkInterface.MODE_TRUNK || tempInterface.vlan == copyPacket.vlan_id) tempInterface.sendPacket(copyPacket); } catch (NullPointerException e) { System.out.println("MultilayerSwitch.java: " + e.toString()); } } } it = NetworkInterfacetable.elements(); while (it.hasMoreElements() && !intFound) { // Test to see if the current Interface is the Interface // that sent in the packet // if it is skip that interface EthernetNetworkInterface tempInterface = (EthernetNetworkInterface) it .nextElement(); if (!tempInterface.getName().equals(inInterfaceName)) { try { if(tempInterface.mode == EthernetNetworkInterface.MODE_TRUNK || tempInterface.vlan == copyPacket.vlan_id) tempInterface.sendPacket(copyPacket); } catch (NullPointerException e) { System.out.println("Switch.java: " + e.toString()); } } } } catch (Throwable th) { if (th.toString().contains( "Packet lost due to physical link problems!")) { throw new LowLinkException(th.toString()); } else { sz = 1; System.out.println(th.toString()); throw new LowLinkException( "Switch buffer overflow (packet loop flood?)."); } } } } public void turnOn(){ init(ProtocolStackLayers); initApplications(); ifacesLinkUP(); // up all before loading config config.load(); } } |
From: Alexander B. <da...@us...> - 2008-10-17 10:17:25
|
Update of /cvsroot/javanetsim/javaNetSim/images/simulation In directory fdv4jf1.ch3.sourceforge.com:/tmp/cvs-serv18066/images/simulation Modified Files: network_local.png Log Message: Index: network_local.png =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/images/simulation/network_local.png,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 Binary files /tmp/cvsMQUoTg and /tmp/cvsSJxmUX differ |
From: Alexander B. <da...@us...> - 2008-10-17 10:17:10
|
Update of /cvsroot/javanetsim/javaNetSim/core In directory fdv4jf1.ch3.sourceforge.com:/tmp/cvs-serv18066/core Modified Files: EthernetNetworkInterface.java Ethernet_packet.java NetworkLayerDevice.java Node.java Log Message: Index: NetworkLayerDevice.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/core/NetworkLayerDevice.java,v retrieving revision 1.25 retrieving revision 1.26 diff -C2 -d -r1.25 -r1.26 *** NetworkLayerDevice.java 13 Oct 2008 22:52:07 -0000 1.25 --- NetworkLayerDevice.java 17 Oct 2008 09:10:16 -0000 1.26 *************** *** 51,55 **** public abstract class NetworkLayerDevice extends Node { ! private DeviceConfig config = new DeviceConfig(this); private AccessListEngine acls = new AccessListEngine(this); private NATEngine nat = new NATEngine(this); --- 51,55 ---- public abstract class NetworkLayerDevice extends Node { ! protected DeviceConfig config = new DeviceConfig(this); private AccessListEngine acls = new AccessListEngine(this); private NATEngine nat = new NATEngine(this); Index: EthernetNetworkInterface.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/core/EthernetNetworkInterface.java,v retrieving revision 1.17 retrieving revision 1.18 diff -C2 -d -r1.17 -r1.18 *** EthernetNetworkInterface.java 5 Oct 2008 19:12:30 -0000 1.17 --- EthernetNetworkInterface.java 17 Oct 2008 09:10:16 -0000 1.18 *************** *** 64,67 **** --- 64,71 ---- protected String MACAddress; public String defaultMACAddress; + public int vlan = 1; + final static int MODE_ACCESS = 0; + final static int MODE_TRUNK = 1; + public int mode = MODE_ACCESS; /** *************** *** 101,110 **** // cast the packet to an EthernetPacket Ethernet_packet tempPacket = (Ethernet_packet)inPacket; if(!parentNode.On || !up) return; //Test if this packet is for this interface or a broadcast ! if(MACAddress.equals(tempPacket.getDestinationMACAddress()) ! || tempPacket.getDestinationMACAddress().equals("FF:FF:FF:FF:FF:FF")){ //Packet is For this Interface or is broadcast so send it to the Parent Node --- 105,123 ---- // cast the packet to an EthernetPacket Ethernet_packet tempPacket = (Ethernet_packet)inPacket; + + boolean drop = false; if(!parentNode.On || !up) return; + + if(!(MACAddress.equals(tempPacket.getDestinationMACAddress()) + || tempPacket.getDestinationMACAddress().equals("FF:FF:FF:FF:FF:FF"))) + drop = true; + + if(mode == MODE_ACCESS && (tempPacket.vlan_id != vlan)) + drop = true; + //Test if this packet is for this interface or a broadcast ! if(!drop){ //Packet is For this Interface or is broadcast so send it to the Parent Node Index: Node.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/core/Node.java,v retrieving revision 1.27 retrieving revision 1.28 diff -C2 -d -r1.27 -r1.28 *** Node.java 5 Oct 2008 19:12:31 -0000 1.27 --- Node.java 17 Oct 2008 09:10:16 -0000 1.28 *************** *** 131,135 **** public String location = ""; ! private int ProtocolStackLayers; --- 131,135 ---- public String location = ""; ! protected int ProtocolStackLayers; *************** *** 244,248 **** } ! private void init(int inProtocolStackLayers){ On = true; if(inProtocolStackLayers != 1){ --- 244,248 ---- } ! protected void init(int inProtocolStackLayers){ On = true; if(inProtocolStackLayers != 1){ *************** *** 262,265 **** --- 262,273 ---- } } + + public String getAllData(){ + return ""; + } + + public void loadDataFile(String name, int lines, String Data){ + return; + } /** *************** *** 455,461 **** NetworkInterface temp = (NetworkInterface)NetworkInterfacetable.get(str); ! if(temp.isActive() && temp.isUP() == false){ temp.UP(); ! } } } --- 463,470 ---- NetworkInterface temp = (NetworkInterface)NetworkInterfacetable.get(str); ! if(temp.isActive() && temp.isUP() == false) temp.UP(); ! else ! temp.setUP(); } } Index: Ethernet_packet.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/core/Ethernet_packet.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** Ethernet_packet.java 20 Nov 2005 20:30:53 -0000 1.2 --- Ethernet_packet.java 17 Oct 2008 09:10:16 -0000 1.3 *************** *** 36,39 **** --- 36,40 ---- private String sourceMACAddress; private String destMACAddress; + public int vlan_id = 1; /** |
From: Alexander B. <da...@us...> - 2008-10-17 09:14:42
|
Update of /cvsroot/javanetsim/javaNetSim/guiUI In directory fdv4jf1.ch3.sourceforge.com:/tmp/cvs-serv18066/guiUI Modified Files: GuiPC.java MainScreen.java Log Message: Index: MainScreen.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/guiUI/MainScreen.java,v retrieving revision 1.93 retrieving revision 1.94 diff -C2 -d -r1.93 -r1.94 *** MainScreen.java 13 Oct 2008 22:52:07 -0000 1.93 --- MainScreen.java 17 Oct 2008 09:10:16 -0000 1.94 *************** *** 133,147 **** private static final String HTM_PREFIX = "htm"; - private int Rcnt = 0, SWcnt = 0, PCcnt = 0, PRINTcnt = 0, HUBcnt = 0, - APcnt = 0; - // File used to save simulation private File simSaveFile; - // File used to save GUI object - - private File guiSaveFile; - // Simulation object --- 133,140 ---- *************** *** 467,474 **** --- 460,471 ---- nodeTemplates.put("PC", new nodeTemplate("PC", "PC", "images/simulation/mymac.png", "PC")); + nodeTemplates.put("Laptop", new nodeTemplate("Laptop", "Laptop", "images/simulation/laptop.png", "Laptop")); + nodeTemplates.put("Router", new nodeTemplate("Router", "Router", "images/simulation/router.png", "Router")); nodeTemplates.put("Switch", new nodeTemplate("Switch", "Switch", "images/simulation/switch.png", "Switch")); + nodeTemplates.put("MultilayerSwitch", new nodeTemplate("MultilayerSwitch", "Multilayer Switch", "images/simulation/mlswitch.png", "Multilayer Switch")); + nodeTemplates.put("Hub", new nodeTemplate("Hub", "Hub", "images/simulation/hub.png", "Hub")); *************** *** 755,759 **** String result = JOptionPane.showInputDialog(this, "Please enter a name for new " + className + ":", className ! + SWcnt); if (result != null) { --- 752,756 ---- String result = JOptionPane.showInputDialog(this, "Please enter a name for new " + className + ":", className ! + nodeTemplates.get(className).getCnt()); if (result != null) { *************** *** 765,769 **** try { ! SWcnt++; Sim.addNode(className, result, true); --- 762,766 ---- try { ! nodeTemplates.get(className).Inc(); Sim.addNode(className, result, true); *************** *** 1178,1197 **** if (Layer.contains("Network")) { colorRenderer.setRowColor(mConsole.getRowCount() - 1, ! this.NETWORK_LAYER_COLOR); } else if (Layer.contains("Link")) { colorRenderer.setRowColor(mConsole.getRowCount() - 1, ! this.LINK_LAYER_COLOR); } else if (Layer.contains("Transport")) { colorRenderer.setRowColor(mConsole.getRowCount() - 1, ! this.TRANSPORT_LAYER_COLOR); } else if (Layer.contains("Application")) { colorRenderer.setRowColor(mConsole.getRowCount() - 1, ! this.APPLICATION_LAYER_COLOR); } else if (Layer.contains("Hardware")) { colorRenderer.setRowColor(mConsole.getRowCount() - 1, ! this.HARDWARE_LAYER_COLOR); } else if (Layer.contains("*SYSTEM*")) { colorRenderer.setRowColor(mConsole.getRowCount() - 1, ! this.SYSTEM_LAYER_COLOR); } --- 1175,1194 ---- if (Layer.contains("Network")) { colorRenderer.setRowColor(mConsole.getRowCount() - 1, ! MainScreen.NETWORK_LAYER_COLOR); } else if (Layer.contains("Link")) { colorRenderer.setRowColor(mConsole.getRowCount() - 1, ! MainScreen.LINK_LAYER_COLOR); } else if (Layer.contains("Transport")) { colorRenderer.setRowColor(mConsole.getRowCount() - 1, ! MainScreen.TRANSPORT_LAYER_COLOR); } else if (Layer.contains("Application")) { colorRenderer.setRowColor(mConsole.getRowCount() - 1, ! MainScreen.APPLICATION_LAYER_COLOR); } else if (Layer.contains("Hardware")) { colorRenderer.setRowColor(mConsole.getRowCount() - 1, ! MainScreen.HARDWARE_LAYER_COLOR); } else if (Layer.contains("*SYSTEM*")) { colorRenderer.setRowColor(mConsole.getRowCount() - 1, ! MainScreen.SYSTEM_LAYER_COLOR); } *************** *** 1820,1823 **** --- 1817,1823 ---- strSave += "#data\n"; + + strSave += ((core.NetworkLayerDevice) Sim + .getNode(key)).getAllData(); strSave += "#enddata\n"; *************** *** 2300,2308 **** line = input.readLine(); if (line.contains("#data")) { ! line = input.readLine(); ! while (!line.contains("#enddata")) { line = input.readLine(); ! if (line == null) break; } } --- 2300,2330 ---- line = input.readLine(); if (line.contains("#data")) { ! ! boolean more_data = true; ! ! while(more_data){ ! String file; ! int lines; ! String data = ""; ! line = input.readLine(); ! if(line.contains("#enddata")){ ! more_data = false; break; + } + + file = line; + + lines = Integer.valueOf(input.readLine()); + + for(int i = 0; i<lines; i++){ + line = input.readLine(); + if (line == null || line.contains("#enddata")) + break; + data += line; + } + + ((core.NetworkLayerDevice) Sim + .getNode(strNodeName)).loadDataFile(file, lines, data); } } *************** *** 2670,2673 **** --- 2692,2701 ---- try { + + if(Sim.getNode(strNodeName) instanceof core.DataLinkLayerDevice) + Sim.getNode(strNodeName).ifacesLinkUP(); + else + Sim.getNode(strNodeName).ifacesUP(); + Route_entry r; *************** *** 2685,2694 **** Sim.addRoute(strNodeName, r); } ! ! Sim.getNode(strNodeName).ifacesUP(); Sim.execCmd(strNodeName, "write mem"); } catch (Exception e) { } } --- 2713,2723 ---- Sim.addRoute(strNodeName, r); } ! Sim.execCmd(strNodeName, "write mem"); } catch (Exception e) { } + + } Index: GuiPC.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/guiUI/GuiPC.java,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** GuiPC.java 6 Oct 2008 13:20:39 -0000 1.9 --- GuiPC.java 17 Oct 2008 09:10:16 -0000 1.10 *************** *** 236,242 **** + "0", core.NetworkInterface.Console, false, 0); ! node.addNetworkInterface(core.NetworkInterface .getIntName(core.NetworkInterface.Wireless) ! + "0", core.NetworkInterface.Wireless, true, 0); } --- 236,242 ---- + "0", core.NetworkInterface.Console, false, 0); ! /*node.addNetworkInterface(core.NetworkInterface .getIntName(core.NetworkInterface.Wireless) ! + "0", core.NetworkInterface.Wireless, true, 0);*/ } |
From: Alexander B. <da...@us...> - 2008-10-17 09:14:39
|
Update of /cvsroot/javanetsim/javaNetSim In directory fdv4jf1.ch3.sourceforge.com:/tmp/cvs-serv18066 Modified Files: README.txt Log Message: Index: README.txt =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/README.txt,v retrieving revision 1.17 retrieving revision 1.18 diff -C2 -d -r1.17 -r1.18 *** README.txt 6 Oct 2008 13:20:39 -0000 1.17 --- README.txt 17 Oct 2008 09:10:16 -0000 1.18 *************** *** 1,3 **** ! ################################### ##### Java Network Simulator ##### ################################### --- 1,3 ---- ! Ó################################### ##### Java Network Simulator ##### ################################### *************** *** 48,51 **** --- 48,53 ---- 3. New application protocols: RIP, DNS (with server and client). 4. New link type: fiber. + 5. Dynamic and Static NAT added. + 6. New device: laptop. *************** *** 92,96 **** GUI Issues - ! 1. Fixed Java 6 related bugs with some diaglogs. New Features --- 94,98 ---- GUI Issues - ! 1. Fixed Java 6 related bugs with some dialogs. New Features |
From: Alexander B. <da...@us...> - 2008-10-17 09:14:39
|
Update of /cvsroot/javanetsim/javaNetSim/core/protocolsuite/tcp_ip In directory fdv4jf1.ch3.sourceforge.com:/tmp/cvs-serv18066/core/protocolsuite/tcp_ip Modified Files: ARP.java Log Message: Index: ARP.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/core/protocolsuite/tcp_ip/ARP.java,v retrieving revision 1.12 retrieving revision 1.13 diff -C2 -d -r1.12 -r1.13 *** ARP.java 13 Oct 2008 12:36:15 -0000 1.12 --- ARP.java 17 Oct 2008 09:10:16 -0000 1.13 *************** *** 113,123 **** private String mLastIpRequest = "0.0.0.0"; ! public int ARP_MAXTRY; public ARP(ProtocolStack inParentStack){ mParentStack = inParentStack; ! ARP_MAXTRY = 5; ! } --- 113,122 ---- private String mLastIpRequest = "0.0.0.0"; ! public final int ARP_MAXTRY = 5; public ARP(ProtocolStack inParentStack){ mParentStack = inParentStack; ! } |
From: QweR <qw...@us...> - 2008-10-13 22:52:21
|
Update of /cvsroot/javanetsim/javaNetSim/core/protocolsuite/tcp_ip In directory fdv4jf1.ch3.sourceforge.com:/tmp/cvs-serv15402/core/protocolsuite/tcp_ip Modified Files: socketLayer.java Log Message: telnet-server Index: socketLayer.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/core/protocolsuite/tcp_ip/socketLayer.java,v retrieving revision 1.12 retrieving revision 1.13 diff -C2 -d -r1.12 -r1.13 *** socketLayer.java 15 Oct 2007 12:04:33 -0000 1.12 --- socketLayer.java 13 Oct 2008 22:52:07 -0000 1.13 *************** *** 177,180 **** --- 177,181 ---- jnsock.src_port = 0; jnsock.src_IP = ""; + //sockTable.remove(sock); } } |
From: QweR <qw...@us...> - 2008-10-13 22:52:13
|
Update of /cvsroot/javanetsim/javaNetSim/guiUI In directory fdv4jf1.ch3.sourceforge.com:/tmp/cvs-serv15402/guiUI Modified Files: MainScreen.java Log Message: telnet-server Index: MainScreen.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/guiUI/MainScreen.java,v retrieving revision 1.92 retrieving revision 1.93 diff -C2 -d -r1.92 -r1.93 *** MainScreen.java 13 Oct 2008 19:49:15 -0000 1.92 --- MainScreen.java 13 Oct 2008 22:52:07 -0000 1.93 *************** *** 793,797 **** if (Sim.getNode(result) instanceof core.NetworkLayerDevice) ((core.NetworkLayerDevice) Sim.getNode(result)) ! .getConfig().add("write mem"); isDirty = true; --- 793,797 ---- if (Sim.getNode(result) instanceof core.NetworkLayerDevice) ((core.NetworkLayerDevice) Sim.getNode(result)) ! .getConfig().executeCommand("write mem"); isDirty = true; |
From: QweR <qw...@us...> - 2008-10-13 22:52:13
|
Update of /cvsroot/javanetsim/javaNetSim/core In directory fdv4jf1.ch3.sourceforge.com:/tmp/cvs-serv15402/core Modified Files: ApplicationLayerDevice.java CommandProcessor.java NetworkLayerDevice.java Log Message: telnet-server Index: NetworkLayerDevice.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/core/NetworkLayerDevice.java,v retrieving revision 1.24 retrieving revision 1.25 diff -C2 -d -r1.24 -r1.25 *** NetworkLayerDevice.java 13 Oct 2008 21:20:21 -0000 1.24 --- NetworkLayerDevice.java 13 Oct 2008 22:52:07 -0000 1.25 *************** *** 76,79 **** --- 76,80 ---- public void turnOn(){ super.turnOn(); + initApplications(); config.load(); } *************** *** 84,87 **** --- 85,92 ---- super.turnOff(); } + + public void initApplications(){ + + } /** Index: CommandProcessor.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/core/CommandProcessor.java,v retrieving revision 1.24 retrieving revision 1.25 diff -C2 -d -r1.24 -r1.25 *** CommandProcessor.java 13 Oct 2008 19:36:35 -0000 1.24 --- CommandProcessor.java 13 Oct 2008 22:52:07 -0000 1.25 *************** *** 997,1009 **** try { NetworkInterface ni = device.getNetworkInterface(params.get(0)); ! String natt = params.get(1); ! if(natt.equalsIgnoreCase("inside")){ ! ni.setNAT(NetworkInterface.INSIDE_NAT); ! } ! else if(natt.equalsIgnoreCase("outside")){ ! ni.setNAT(NetworkInterface.OUTSIDE_NAT); } else{ ! out += "error: invalid parameter '"+natt+"'\n"; } } catch (InvalidNetworkInterfaceNameException ex) { --- 997,1014 ---- try { NetworkInterface ni = device.getNetworkInterface(params.get(0)); ! if(device.isActiveInterface(params.get(0))){ ! String natt = params.get(1); ! if(natt.equalsIgnoreCase("inside")){ ! ni.setNAT(NetworkInterface.INSIDE_NAT); ! } ! else if(natt.equalsIgnoreCase("outside")){ ! ni.setNAT(NetworkInterface.OUTSIDE_NAT); ! } ! else{ ! out += "error: invalid parameter '"+natt+"'\n"; ! } } else{ ! out += "error: interface "+params.get(0)+" is not active\n"; } } catch (InvalidNetworkInterfaceNameException ex) { *************** *** 1026,1044 **** try { NetworkInterface ni = device.getNetworkInterface(params.get(0)); ! if(params.size()==1){ ! ni.setNAT(NetworkInterface.NO_NAT); ! } ! else{ ! String natt = params.get(1); ! if(natt.equalsIgnoreCase("inside") && ni.getNAT()==NetworkInterface.INSIDE_NAT){ ! ni.setNAT(NetworkInterface.NO_NAT); ! } ! else if(natt.equalsIgnoreCase("outside") && ni.getNAT()==NetworkInterface.OUTSIDE_NAT){ ni.setNAT(NetworkInterface.NO_NAT); } else{ ! out += "error: invalid parameter '"+natt+"'\n"; } } } catch (InvalidNetworkInterfaceNameException ex) { out += "error: invalid inferface\n"; --- 1031,1054 ---- try { NetworkInterface ni = device.getNetworkInterface(params.get(0)); ! if(device.isActiveInterface(params.get(0))){ ! if(params.size()==1){ ni.setNAT(NetworkInterface.NO_NAT); } else{ ! String natt = params.get(1); ! if(natt.equalsIgnoreCase("inside") && ni.getNAT()==NetworkInterface.INSIDE_NAT){ ! ni.setNAT(NetworkInterface.NO_NAT); ! } ! else if(natt.equalsIgnoreCase("outside") && ni.getNAT()==NetworkInterface.OUTSIDE_NAT){ ! ni.setNAT(NetworkInterface.NO_NAT); ! } ! else{ ! out += "error: invalid parameter '"+natt+"'\n"; ! } } } + else{ + out += "error: interface "+params.get(0)+" is not active\n"; + } } catch (InvalidNetworkInterfaceNameException ex) { out += "error: invalid inferface\n"; Index: ApplicationLayerDevice.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/core/ApplicationLayerDevice.java,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** ApplicationLayerDevice.java 22 Sep 2008 16:13:15 -0000 1.9 --- ApplicationLayerDevice.java 13 Oct 2008 22:52:07 -0000 1.10 *************** *** 52,56 **** public void turnOn(){ super.turnOn(); ! initApplications(); } --- 52,56 ---- public void turnOn(){ super.turnOn(); ! //initApplications(); } |
From: Alexander B. <da...@us...> - 2008-10-13 21:20:33
|
Update of /cvsroot/javanetsim/javaNetSim/core/protocolsuite/tcp_ip In directory fdv4jf1.ch3.sourceforge.com:/tmp/cvs-serv7082/core/protocolsuite/tcp_ip Modified Files: IP_packet.java ProtocolStack.java Log Message: NAT now works. (may be :P) Index: ProtocolStack.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/core/protocolsuite/tcp_ip/ProtocolStack.java,v retrieving revision 1.71 retrieving revision 1.72 diff -C2 -d -r1.71 -r1.72 *** ProtocolStack.java 13 Oct 2008 12:36:15 -0000 1.71 --- ProtocolStack.java 13 Oct 2008 21:20:21 -0000 1.72 *************** *** 796,800 **** IPV4Address ip = new IPV4Address(destIPAddress); ! if (mIPprotocol.isInternalIP(destIPAddress) || ip.isBroadcast()) { // Create layer info LayerInfo protInfo = new LayerInfo(getClass().getName()); --- 796,800 ---- IPV4Address ip = new IPV4Address(destIPAddress); ! if ((mIPprotocol.isInternalIP(destIPAddress) && !ipPacket.NatOutsideMark) || ip.isBroadcast()) { // Create layer info LayerInfo protInfo = new LayerInfo(getClass().getName()); Index: IP_packet.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/core/protocolsuite/tcp_ip/IP_packet.java,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** IP_packet.java 13 Oct 2008 12:36:15 -0000 1.6 --- IP_packet.java 13 Oct 2008 21:20:21 -0000 1.7 *************** *** 89,93 **** String mDestIPAddress; ! public boolean NatMark = false; --- 89,94 ---- String mDestIPAddress; ! public boolean NatInsideMark = false; ! public boolean NatOutsideMark = false; *************** *** 112,116 **** mDestIPAddress = inDestIPAddress; ! NatMark = false; } --- 113,118 ---- mDestIPAddress = inDestIPAddress; ! NatInsideMark = false; ! NatOutsideMark = false; } |
From: Alexander B. <da...@us...> - 2008-10-13 21:20:33
|
Update of /cvsroot/javanetsim/javaNetSim/core In directory fdv4jf1.ch3.sourceforge.com:/tmp/cvs-serv7082/core Modified Files: NATEngine.java NetworkLayerDevice.java Log Message: NAT now works. (may be :P) Index: NetworkLayerDevice.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/core/NetworkLayerDevice.java,v retrieving revision 1.23 retrieving revision 1.24 diff -C2 -d -r1.23 -r1.24 *** NetworkLayerDevice.java 13 Oct 2008 20:04:25 -0000 1.23 --- NetworkLayerDevice.java 13 Oct 2008 21:20:21 -0000 1.24 *************** *** 135,142 **** if(this.getNetworkInterface(inInterface).getNAT() == NetworkInterface.INSIDE_NAT){ // mark packet ! ((IP_packet) inPacket).NatMark = true; Simulation.addLayerInfo(getClass().getName(), getName(), "IP Packet", "Network", "Marked packet as possible inside NAT candidate."); ! }else if(this.getNetworkInterface(inInterface).getNAT() == NetworkInterface.OUTSIDE_NAT){ inPacket = nat.NAT_outside((IP_packet) inPacket); } --- 135,143 ---- if(this.getNetworkInterface(inInterface).getNAT() == NetworkInterface.INSIDE_NAT){ // mark packet ! ((IP_packet) inPacket).NatInsideMark = true; Simulation.addLayerInfo(getClass().getName(), getName(), "IP Packet", "Network", "Marked packet as possible inside NAT candidate."); ! }else if(this.getNetworkInterface(inInterface).getNAT() == NetworkInterface.OUTSIDE_NAT){ ! ((IP_packet) inPacket).NatOutsideMark = true; inPacket = nat.NAT_outside((IP_packet) inPacket); } *************** *** 151,161 **** public Packet preparePacket(Packet inPacket){ if(inPacket instanceof IP_packet && !(inPacket instanceof ARP_packet)){ ! if(((IP_packet) inPacket).NatMark){ inPacket = nat.NAT_inside((IP_packet) inPacket); } - - ((IP_packet) inPacket).NatMark = false; } return inPacket; } --- 152,163 ---- public Packet preparePacket(Packet inPacket){ if(inPacket instanceof IP_packet && !(inPacket instanceof ARP_packet)){ ! if(((IP_packet) inPacket).NatInsideMark){ inPacket = nat.NAT_inside((IP_packet) inPacket); } } + ((IP_packet) inPacket).NatInsideMark = false; + ((IP_packet) inPacket).NatOutsideMark = false; + return inPacket; } Index: NATEngine.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/core/NATEngine.java,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** NATEngine.java 13 Oct 2008 20:04:25 -0000 1.7 --- NATEngine.java 13 Oct 2008 21:20:21 -0000 1.8 *************** *** 4,7 **** --- 4,8 ---- import java.util.Hashtable; import java.util.Vector; + import java.util.ArrayList; import core.protocolsuite.tcp_ip.*; *************** *** 34,37 **** --- 35,51 ---- Vector<NAT_session> sessions; + public void clearExpiredSessions(){ + ArrayList toRemove = new ArrayList(); + long time_now = System.currentTimeMillis(); + + for(int i = 0; i<sessions.size(); i++){ + if((time_now - sessions.get(i).last_time) > 360 * 1000) + toRemove.add(i); + } + + if(toRemove.size() > 0) + sessions.removeAll(toRemove); + } + public class NAT_rule{ public boolean dynamic = false; // false -- static, true -- dymanic *************** *** 58,61 **** --- 72,76 ---- Vector<NAT_rule> dynamic_rules; Hashtable<String, Pair> pools; + java.security.SecureRandom rng; public NATEngine(NetworkLayerDevice node){ *************** *** 66,69 **** --- 81,85 ---- sessions = new Vector<NAT_session>(); pools = new Hashtable<String, Pair>(); + rng = new java.security.SecureRandom(); } *************** *** 121,129 **** public IP_packet NAT_inside(IP_packet p){ IP_packet rp = p; for(int i=0; i<static_rules.size(); i++){ NAT_rule rule = static_rules.get(i); ! String NewIP = ""; ! int NewPort = 0; if(rule.in_ip.equals(p.getSourceIPAddress()) && parentNode.getACL().passACL(rule.acl, p)){ --- 137,148 ---- public IP_packet NAT_inside(IP_packet p){ IP_packet rp = p; + String NewIP = ""; + int NewPort = 0; + + clearExpiredSessions(); for(int i=0; i<static_rules.size(); i++){ NAT_rule rule = static_rules.get(i); ! if(rule.in_ip.equals(p.getSourceIPAddress()) && parentNode.getACL().passACL(rule.acl, p)){ *************** *** 143,147 **** rp.setSourceIPAddress(NewIP); ! break; }else if(rule.protocol == NAT_rule.TCP && p instanceof TCP_packet){ if(((TCP_packet)p).get_srcPort() == rule.in_port){ --- 162,166 ---- rp.setSourceIPAddress(NewIP); ! return rp; }else if(rule.protocol == NAT_rule.TCP && p instanceof TCP_packet){ if(((TCP_packet)p).get_srcPort() == rule.in_port){ *************** *** 158,162 **** ((TCP_packet)rp).setSrcPort(NewPort); rp.setSourceIPAddress(NewIP); ! } }else if(rule.protocol == NAT_rule.UDP && p instanceof UDP_packet){ if(((UDP_packet)p).get_srcPort() == rule.in_port){ --- 177,183 ---- ((TCP_packet)rp).setSrcPort(NewPort); rp.setSourceIPAddress(NewIP); ! ! return rp; ! } }else if(rule.protocol == NAT_rule.UDP && p instanceof UDP_packet){ if(((UDP_packet)p).get_srcPort() == rule.in_port){ *************** *** 173,176 **** --- 194,199 ---- ((UDP_packet)rp).setSrcPort(NewPort); rp.setSourceIPAddress(NewIP); + + return rp; } } *************** *** 178,191 **** } ! return p; } public IP_packet NAT_outside(IP_packet p){ IP_packet rp = p; for(int i=0; i<static_rules.size(); i++){ NAT_rule rule = static_rules.get(i); - String NewIP = ""; - int NewPort = 0; if(rule.out_ip.equals(p.getDestIPAddress()) && parentNode.getACL().passACL(rule.acl, p)){ --- 201,302 ---- } ! String OldIP = ""; ! int OldPort = 0; ! /*String NewIP = ""; ! int NewPort = 0;*/ ! int type = NAT_session.UNKNOWN; ! String proto = "unk"; ! int s = -1; ! ! OldIP = p.getSourceIPAddress(); ! ! if(p instanceof TCP_packet){ ! type = NAT_session.TCP; ! OldPort = ((TCP_packet)p).get_srcPort(); ! proto = "tcp"; ! }else if(p instanceof UDP_packet){ ! type = NAT_session.UDP; ! OldPort = ((UDP_packet)p).get_srcPort(); ! proto = "udp"; ! }else if(p instanceof ICMP_packet){ ! type = NAT_session.ICMP; ! OldPort = ((ICMP_packet)p).UniqueIdentfier; ! proto = "icmp"; ! } ! ! for(int i=0; i<dynamic_rules.size(); i++){ ! NAT_rule rule = dynamic_rules.get(i); ! ! if(parentNode.getACL().passACL(rule.acl, p)){ ! s = findInsideSession(type, OldIP, OldPort); ! ! if(s>=0){ ! sessions.get(s).last_time = System.currentTimeMillis(); ! ! NewPort = sessions.get(s).out_port; ! NewIP = sessions.get(s).out_ip; ! ! }else{ ! NewPort = rng.nextInt(40000) + 20000; ! if(rule.pool){ ! NewIP = (String)pools.get(rule.out_int).getFirst(); ! }else{ ! NewIP = parentNode.getIPAddress(rule.out_int); ! } ! ! NAT_session new_s = new NAT_session(); ! new_s.in_ip = OldIP; new_s.in_port = OldPort; ! new_s.protocol = type; ! new_s.out_ip = NewIP; new_s.out_port = NewPort; ! sessions.add(new_s); ! } ! ! Simulation.addLayerInfo(getClass().getName(), parentNode.getName(), "IP Packet", "Network", ! "Inside dynamic NAT(" + proto + ") for ip packet applied: changed src from " + OldIP + ":" + OldPort + " to " + NewIP + ":" + NewPort + "."); ! ! rp.setSourceIPAddress(NewIP); ! ! if(p instanceof TCP_packet){ ! ((TCP_packet)rp).setSrcPort(NewPort); ! }else if(p instanceof UDP_packet){ ! ((UDP_packet)rp).setSrcPort(NewPort); ! } ! ! return rp; ! } ! } ! ! return rp; ! } ! ! private int findInsideSession(int protocol, String ip, int port){ ! for(int i = 0; i < sessions.size(); i++){ ! NAT_session s = sessions.get(i); ! ! if(s.in_ip.equals(ip) && s.in_port == port && s.protocol == protocol) ! return i; ! } ! ! return -1; ! } ! ! private int findOutsideSession(int protocol, String ip, int port){ ! for(int i = 0; i < sessions.size(); i++){ ! NAT_session s = sessions.get(i); ! ! if(s.out_ip.equals(ip) && s.out_port == port && s.protocol == protocol) ! return i; ! } ! ! return -1; } public IP_packet NAT_outside(IP_packet p){ IP_packet rp = p; + String NewIP = ""; + int NewPort = 0; for(int i=0; i<static_rules.size(); i++){ NAT_rule rule = static_rules.get(i); if(rule.out_ip.equals(p.getDestIPAddress()) && parentNode.getACL().passACL(rule.acl, p)){ *************** *** 201,205 **** rp.setDestIPAddress(NewIP); ! break; }else if(rule.protocol == NAT_rule.TCP && p instanceof TCP_packet){ if(((TCP_packet)p).get_destPort() == rule.out_port){ --- 312,316 ---- rp.setDestIPAddress(NewIP); ! return rp; }else if(rule.protocol == NAT_rule.TCP && p instanceof TCP_packet){ if(((TCP_packet)p).get_destPort() == rule.out_port){ *************** *** 212,215 **** --- 323,328 ---- ((TCP_packet)rp).setDestPort(NewPort); rp.setDestIPAddress(NewIP); + + return rp; } }else if(rule.protocol == NAT_rule.UDP && p instanceof UDP_packet){ *************** *** 223,226 **** --- 336,341 ---- ((UDP_packet)rp).setDestPort(NewPort); rp.setDestIPAddress(NewIP); + + return rp; } } *************** *** 228,232 **** } ! return p; } --- 343,402 ---- } ! String OldIP = ""; ! int OldPort = 0; ! /*String NewIP = ""; ! int NewPort = 0;*/ ! int type = NAT_session.UNKNOWN; ! String proto = "unk"; ! int s = -1; ! ! OldIP = p.getDestIPAddress(); ! ! if(p instanceof TCP_packet){ ! type = NAT_session.TCP; ! OldPort = ((TCP_packet)p).get_destPort(); ! proto = "tcp"; ! }else if(p instanceof UDP_packet){ ! type = NAT_session.UDP; ! OldPort = ((UDP_packet)p).get_destPort(); ! proto = "udp"; ! }else if(p instanceof ICMP_packet){ ! type = NAT_session.ICMP; ! OldPort = ((ICMP_packet)p).UniqueIdentfier; ! proto = "icmp"; ! } ! ! for(int i=0; i<dynamic_rules.size(); i++){ ! NAT_rule rule = dynamic_rules.get(i); ! ! if(parentNode.getACL().passACL(rule.acl, p)){ ! s = findOutsideSession(type, OldIP, OldPort); ! ! if(s>=0){ ! sessions.get(s).last_time = System.currentTimeMillis(); ! ! NewPort = sessions.get(s).in_port; ! NewIP = sessions.get(s).in_ip; ! ! Simulation.addLayerInfo(getClass().getName(), parentNode.getName(), "IP Packet", "Network", ! "Outside dynamic NAT(" + proto + ") for ip packet applied: changed dst from " + OldIP + ":" + OldPort + " to " + NewIP + ":" + NewPort + "."); ! ! rp.setDestIPAddress(NewIP); ! ! if(p instanceof TCP_packet){ ! ((TCP_packet)rp).setDestPort(NewPort); ! }else if(p instanceof UDP_packet){ ! ((UDP_packet)rp).setDestPort(NewPort); ! } ! ! return rp; ! }else{ ! Simulation.addLayerInfo(getClass().getName(), parentNode.getName(), "IP Packet", "Network", ! "Outside dynamic NAT(" + proto + ") for ip packet failed: no session for " + OldIP + ":" + OldPort + "."); ! } ! } ! } ! ! return rp; } |