[Javanetsim-cvs] javaNetSim/guiUI LinkProperties.java,NONE,1.1 ApplicationLayerDevice.java,1.2,1.3 M
Status: Beta
Brought to you by:
darkkey
From: Alexander B. <da...@us...> - 2005-11-19 16:16:40
|
Update of /cvsroot/javanetsim/javaNetSim/guiUI In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv28569/guiUI Modified Files: ApplicationLayerDevice.java MainScreen.java NetworkLayerDevice.java breakLinkDialog.java Added Files: LinkProperties.java Log Message: Index: NetworkLayerDevice.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/guiUI/NetworkLayerDevice.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** NetworkLayerDevice.java 8 Nov 2005 20:58:14 -0000 1.2 --- NetworkLayerDevice.java 19 Nov 2005 16:16:32 -0000 1.3 *************** *** 34,37 **** --- 34,38 ---- import javax.swing.JMenuItem; + import javax.swing.JMenu; /** *************** *** 49,56 **** --- 50,60 ---- private JMenuItem mnuSendPing = new JMenuItem("Send Ping ..."); private JMenuItem mnuProperties = new JMenuItem("Properties ..."); + private JMenu mnuARPMenu = new JMenu("ARP"); + private JMenuItem mnuArpStaticAdd = new JMenuItem("Add static entry to ARP table..."); private JMenuItem mnuArpRemove = new JMenuItem("Remove entry from ARP table..."); private JMenuItem mnuRunCmd = new JMenuItem("Run low-level command..."); private JMenuItem mnuArp = new JMenuItem("Print ARP Table"); + private JMenuItem mnuLink = new JMenuItem("Links properties"); private JMenuItem mnuBreakLink = new JMenuItem("Break link"); *************** *** 108,120 **** } }); GuiNodePopMenu.add(mnuSetTCPIPProperties); GuiNodePopMenu.add(mnuSendPing); ! GuiNodePopMenu.add(mnuArpStaticAdd); ! GuiNodePopMenu.add(mnuArpRemove); ! GuiNodePopMenu.add(mnuArp); GuiNodePopMenu.add(mnuRunCmd); GuiNodePopMenu.add(mnuBreakLink); GuiNodePopMenu.add(mnuProperties); --- 112,131 ---- } }); + mnuLink.addActionListener(new ActionListener(){ + public void actionPerformed(ActionEvent e){ + controller.showLinkDialog(lblNodeName.getText()); + } + }); GuiNodePopMenu.add(mnuSetTCPIPProperties); GuiNodePopMenu.add(mnuSendPing); ! GuiNodePopMenu.add(mnuARPMenu); ! mnuARPMenu.add(mnuArpStaticAdd); ! mnuARPMenu.add(mnuArpRemove); ! mnuARPMenu.add(mnuArp); GuiNodePopMenu.add(mnuRunCmd); GuiNodePopMenu.add(mnuBreakLink); + GuiNodePopMenu.add(mnuLink); GuiNodePopMenu.add(mnuProperties); Index: MainScreen.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/guiUI/MainScreen.java,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** MainScreen.java 19 Nov 2005 14:26:02 -0000 1.3 --- MainScreen.java 19 Nov 2005 16:16:32 -0000 1.4 *************** *** 46,49 **** --- 46,50 ---- import java.util.Arrays; + import javax.swing.*; import javax.swing.filechooser.FileFilter; *************** *** 55,61 **** --- 56,64 ---- import core.Simulation; import core.Node; + import core.protocolsuite.tcp_ip.Route_entry; import core.protocolsuite.tcp_ip.Echo; + /** * This class is the GUI's main screen. *************** *** 569,573 **** --- 572,615 ---- } + + /** + * Creates a Link Properties Dialog on the specific Node + * @param String inNodeName The name node to show properties on + */ + + public void showLinkDialog(String inNodeName) + { + Object[] nodesArray = null; + int selectedIndex = -1; + //if null is passed from the menubar item + //Get array of nodes from within the simulation + if(inNodeName == null){ + ArrayList Values = new ArrayList(); + Enumeration enum1 = GUInodeTable.keys(); + while(enum1.hasMoreElements()){ + String key = (String)enum1.nextElement(); + GuiNode tempNode = (GuiNode)GUInodeTable.get(key); + if(tempNode instanceof NetworkLayerDevice){ + Values.add(key); + } + } + nodesArray = Values.toArray(); + + //Else pass the selected node name + }else{ + nodesArray = new Object[1]; + nodesArray[0] = inNodeName; + selectedIndex = 0; + } + + //test that there are any node within the simulation + if(nodesArray.length != 0){ + new LinkProperties(this,nodesArray,selectedIndex,Sim,Sandbox); + this.refreshNodeInformationTab(); + }else + JOptionPane.showMessageDialog(this,"There are currently no node's within the simulation","Warning!",JOptionPane.WARNING_MESSAGE); + } + /** *************** *** 1737,1740 **** --- 1779,1802 ---- /** + * Send echo message to server + * @author Key + * @param String inNodeName Name of node to server listen + */ + + public void EchoSend(String inNodeName){ + String ip = JOptionPane.showInputDialog(this, "Server IP:", "Send msg over Echo.", JOptionPane.QUESTION_MESSAGE); + String port = JOptionPane.showInputDialog(this, "Server Port:", "Send msg over Echo.", JOptionPane.QUESTION_MESSAGE); + String msg = JOptionPane.showInputDialog(this, "Message:", "Message.", JOptionPane.QUESTION_MESSAGE); + if(port!=null && ip!=null && msg!=null){ + try{ + ((Echo)((core.ApplicationLayerDevice)Sim.getNode(inNodeName)).getApp(7)).SendEcho(msg, ip, Integer.valueOf(port).intValue()); + this.addToConsole("Trying to send echo message '" + msg + "' from " + inNodeName + " to " + ip + ":" + port + "\n"); + }catch(Exception e){ + addToConsole(e.toString()); + } + } + } + + /** * Runs network configure command on the target host. (route, et cetera) * Need for: *************** *** 1751,1767 **** if(tokens[0].contains("route")){ ! //only tests ! this.addToConsole("You enter route command.\n"); ! ! try{ if(tokens[1].contains("print")){ ! }else if(tokens[1].contains("add")){ ! }else if(tokens[1].contains("del")){ ! }else{ this.addToConsole("Unknown route command. Usage:\n"); ! this.addToConsole("route add (host_ip|network_ip) target_interface [netmask] [gateway] \n"); this.addToConsole("route del (host_ip|network_ip) \n"); this.addToConsole("route print \n"); --- 1813,1836 ---- if(tokens[0].contains("route")){ ! try{ if(tokens[1].contains("print")){ ! String routes[] = Sim.getRouteTableEntries(inNodeName); ! this.addToConsole("IP routing table:\n" + "Destination" + "\t" + "Gateway" + "\t" + "Genmask" + "\t" + "Type" + "\t" + "Iface"); ! for(int i=0; i<routes.length - 1; i++){ ! Route_entry r = Sim.getRouteEntry(inNodeName, routes[i]); ! this.addToConsole(routes[i] + "\t" + r.gateway + "\t" + r.genMask + "\t" + r.Type + "\t" + r.iFace + "\n"); ! } }else if(tokens[1].contains("add")){ ! String gw = ""; ! if(tokens.length > 5) gw = tokens[5]; ! Route_entry r = new Route_entry(tokens[2], gw, tokens[4], tokens[3], 0); ! Sim.addRoute(inNodeName, r); ! this.addToConsole("Route added.\n"); }else if(tokens[1].contains("del")){ ! Sim.removeRoute(inNodeName, tokens[2]); ! this.addToConsole("Route to " + tokens[2] + "removed.\n"); }else{ this.addToConsole("Unknown route command. Usage:\n"); ! this.addToConsole("route add (host_ip|network_ip) target_interface netmask [gateway] \n"); this.addToConsole("route del (host_ip|network_ip) \n"); this.addToConsole("route print \n"); *************** *** 1769,1773 **** }catch(ArrayIndexOutOfBoundsException e){ this.addToConsole("Unknown route command. Usage:\n"); ! this.addToConsole("route add (host_ip|network_ip) target_interface [netmask] [gateway] \n"); this.addToConsole("route del (host_ip|network_ip) \n"); this.addToConsole("route print \n"); --- 1838,1842 ---- }catch(ArrayIndexOutOfBoundsException e){ this.addToConsole("Unknown route command. Usage:\n"); ! this.addToConsole("route add (host_ip|network_ip) target_interface netmask [gateway] \n"); this.addToConsole("route del (host_ip|network_ip) \n"); this.addToConsole("route print \n"); *************** *** 1775,1779 **** }else{ ! this.addToConsole("Unknown command.\n"); } } --- 1844,1848 ---- }else{ ! this.addToConsole("Unknown or invalid command.\n"); } } Index: ApplicationLayerDevice.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/guiUI/ApplicationLayerDevice.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** ApplicationLayerDevice.java 19 Nov 2005 14:26:02 -0000 1.2 --- ApplicationLayerDevice.java 19 Nov 2005 16:16:32 -0000 1.3 *************** *** 37,41 **** mnuEchoSend.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e){ ! //controller.EchoSend(lblNodeName.getText()); } }); --- 37,41 ---- mnuEchoSend.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e){ ! controller.EchoSend(lblNodeName.getText()); } }); Index: breakLinkDialog.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/guiUI/breakLinkDialog.java,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -C2 -d -r1.1.1.1 -r1.2 *** breakLinkDialog.java 8 Nov 2005 04:04:23 -0000 1.1.1.1 --- breakLinkDialog.java 19 Nov 2005 16:16:32 -0000 1.2 *************** *** 87,91 **** this.Sim = Sim; this.SBox = SBox; ! //setTitle("Internet Protocol (TCP/IP) Properties"); initGUI(nodeArray,selectedIndex); --- 87,91 ---- this.Sim = Sim; this.SBox = SBox; ! setTitle("Break link"); initGUI(nodeArray,selectedIndex); --- NEW FILE: LinkProperties.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 javax.swing.JFrame; import javax.swing.JPanel; import java.awt.GridBagLayout; import javax.swing.JDialog; import javax.swing.JLabel; import javax.swing.JTextField; import java.awt.Insets; import java.awt.GridBagConstraints; import java.awt.BorderLayout; import javax.swing.JButton; import java.awt.Dimension; import java.awt.event.ActionListener; import java.awt.event.ActionEvent; import javax.swing.JComboBox; import core.Simulation; import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; import java.awt.Color; import java.awt.event.KeyAdapter; import java.awt.event.KeyEvent; import java.awt.event.FocusAdapter; import java.awt.event.FocusEvent; import java.util.Arrays; import java.awt.Component; import javax.swing.SwingConstants; /** * * @author Key * * This class is a dialog that enables to set link properties * */ public class LinkProperties extends javax.swing.JDialog { private JPanel backpanel; private JLabel lblInterface; private JLabel lblNodeName; private JComboBox cmbNodeName; private JComboBox cmbInterface; private JLabel lblError; private JLabel lblProp; private JButton btnOk; private JTextField txtProp; private MainScreen controller; private Simulation Sim; private SandBox SBox; private String NodeName; private String Interface; private boolean ErrorFlag = true; public LinkProperties(JFrame frame, Object nodeArray[], int selectedIndex, Simulation Sim, SandBox SBox) { super(frame); setResizable(false); controller = (MainScreen)frame; this.Sim = Sim; this.SBox = SBox; setTitle("Link Properties (Ahtung: NOT WORKING!!!!!)"); initGUI(nodeArray,selectedIndex); final JPanel panel = new JPanel(); getContentPane().add(panel, BorderLayout.SOUTH); btnOk = new JButton(); btnOk.setEnabled(true); btnOk.setToolTipText("Set options!"); btnOk.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { okButton(); } }); btnOk.setName("btnOK"); panel.add(btnOk); btnOk.setText("OK"); final JButton btnCancel = new JButton(); btnCancel.setToolTipText("Cancel changes"); btnCancel.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { cancelButton(); } }); btnCancel.setName("btnCancel"); panel.add(btnCancel); btnCancel.setText("Cancel"); this.getRootPane().setDefaultButton(btnOk); this.setDefaultCloseOperation(JDialog.EXIT_ON_CLOSE); this.setLocationRelativeTo(null); this.setModal(true); this.setVisible(true); } private void initGUI(Object nodeArray[], int selectedIndex) { try { setSize(350, 225); { backpanel = new JPanel(); backpanel.setMinimumSize(new Dimension(200, 10)); this.getContentPane().add(backpanel, BorderLayout.CENTER); GridBagLayout backpanelLayout = new GridBagLayout(); backpanel.setPreferredSize(new java.awt.Dimension(264, 213)); backpanelLayout.columnWeights = new double[] {}; backpanelLayout.columnWidths = new int[] {}; backpanelLayout.rowWeights = new double[] {0.0}; backpanelLayout.rowHeights = new int[] {5,5,5,5}; backpanel.setLayout(backpanelLayout); { lblNodeName = new JLabel(); backpanel.add(lblNodeName, new GridBagConstraints( 0, 0, 1, 1, 0.0, 1.0, GridBagConstraints.LINE_END, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 21, 0)); lblNodeName.setText("Node Name:"); } { lblInterface = new JLabel(); backpanel.add(lblInterface, new GridBagConstraints( 0, 1, 1, 1, 0.0, 1.0, GridBagConstraints.LINE_END, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 27), 0, 0)); lblInterface.setText("Interface:"); } { lblProp = new JLabel(); backpanel.add(lblProp, new GridBagConstraints( 0, 2, 1, 1, 0.0, 1.0, GridBagConstraints.LINE_END, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 16), 0, 0)); lblProp.setText("Packet passthrough(%) (0 - 100):"); } cmbNodeName = new JComboBox(nodeArray); cmbNodeName.setMinimumSize(new Dimension(100, 0)); cmbNodeName.setSelectedIndex(selectedIndex); cmbNodeName.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { selectNode(); } }); final GridBagConstraints gridBagConstraints = new GridBagConstraints(); gridBagConstraints.fill = GridBagConstraints.HORIZONTAL; gridBagConstraints.anchor = GridBagConstraints.LINE_START; gridBagConstraints.gridy = 0; gridBagConstraints.gridx = 1; backpanel.add(cmbNodeName, gridBagConstraints); cmbInterface = new JComboBox(); cmbInterface.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { selectInterface(); } }); cmbInterface.setEnabled(false); final GridBagConstraints gridBagConstraints_1 = new GridBagConstraints(); gridBagConstraints_1.fill = GridBagConstraints.HORIZONTAL; gridBagConstraints_1.anchor = GridBagConstraints.LINE_START; gridBagConstraints_1.gridy = 1; gridBagConstraints_1.gridx = 1; backpanel.add(cmbInterface, gridBagConstraints_1); txtProp = new JTextField(); txtProp.addFocusListener(new FocusAdapter() { public void focusLost(FocusEvent e) { //ipAddressEntered(); } }); txtProp.setEnabled(false); final GridBagConstraints gridBagConstraints_3 = new GridBagConstraints(); gridBagConstraints_3.fill = GridBagConstraints.HORIZONTAL; gridBagConstraints_3.anchor = GridBagConstraints.LINE_START; gridBagConstraints_3.gridy = 2; gridBagConstraints_3.gridx = 1; backpanel.add(txtProp, gridBagConstraints_3); txtProp.setText("Enter %% 0-100"); lblError = new JLabel(); lblError.setHorizontalTextPosition(SwingConstants.CENTER); lblError.setHorizontalAlignment(SwingConstants.CENTER); lblError.setAlignmentX(Component.CENTER_ALIGNMENT); lblError.setMinimumSize(new Dimension(100, 20)); lblError.setMaximumSize(new Dimension(100, 20)); lblError.setPreferredSize(new Dimension(100, 20)); lblError.setVisible(false); final GridBagConstraints gridBagConstraints_5 = new GridBagConstraints(); gridBagConstraints_5.anchor = GridBagConstraints.WEST; gridBagConstraints_5.insets = new Insets(0, 1, 0, 0); gridBagConstraints_5.fill = GridBagConstraints.BOTH; gridBagConstraints_5.gridwidth = 2; gridBagConstraints_5.gridy = 5; gridBagConstraints_5.gridx = 0; backpanel.add(lblError, gridBagConstraints_5); lblError.setText("Error Message!!!! Error"); if(selectedIndex == 0){ selectNode(); } } } catch (Exception e) { e.printStackTrace(); } } /** * This method is executed when the user hit's the enter button. * It will delete the link on selected interface. * * @author Key * */ private void okButton(){ try { if(NodeName != null && Interface != null){ //String str = Sim.disconnectLink(NodeName, Interface); //SBox.removeLine(str); //controller.addToConsole(NodeName +"'s link on interface "+Interface+" has been disconnected!\n"); } this.dispose(); } catch (Exception e) { e.printStackTrace(); } } /** * This method is executed when the user hits the cancel button * @author luke_hamilton * @author Key * */ private void cancelButton(){ this.dispose(); } /** * This method will generate the data within the Interface combobox based * on the node that is selected. It will also get the default gateway if there is one set * for the node and add the text to the text field * * @author luke_hamilton * @author Key * */ private void selectNode(){ //Remove all items before regenerating the combobox. //This is because if a users selects the node twice, it would add the interfaces twice. cmbInterface.removeAllItems(); NodeName = (String)cmbNodeName.getSelectedItem(); try { Object nics[] = Sim.getAllInterfaces(NodeName); //Get object array of interface names //Sort the array Arrays.sort(nics); for (int i = 0; i < nics.length; i++) { //Add them to the combobox cmbInterface.addItem(nics[i]); } cmbInterface.setEnabled(true); } catch (Exception e) { //This should never happen e.printStackTrace(); } } /** * This method enabled's the IP Address text field once the interface has been selected. * This will also check the selected interface to see if the ip address has already been set * if so entering that ip address into the text field and then getting the set subnet mask for that * ip address. * @author Key */ private void selectInterface(){ Interface = (String)cmbInterface.getSelectedItem(); try{ String lnk = Sim.getLinkName(NodeName, Interface); //txtProp.setText(Sim.getLinkProb(lnk)); }catch(Exception e){ } } } |