[Javanetsim-cvs] javaNetSim/guiUI GuiPC.java, 1.10, 1.11 MainScreen.java, 1.94, 1.95 Terminal.java,
Status: Beta
Brought to you by:
darkkey
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 (){ |