From: Fredrik Ãs. <fro...@us...> - 2008-12-17 12:15:50
|
Update of /cvsroot/contiki/contiki-2.x/tools/cooja/apps/native_gateway/java/se/sics/cooja/plugins In directory ddv4jf1.ch3.sourceforge.com:/tmp/cvs-serv32072/tools/cooja/apps/native_gateway/java/se/sics/cooja/plugins Modified Files: NativeIPGateway.java Log Message: gateway plugin does not extend visplugin; it can be used when cooja is not visualized (such as during tests) Index: NativeIPGateway.java =================================================================== RCS file: /cvsroot/contiki/contiki-2.x/tools/cooja/apps/native_gateway/java/se/sics/cooja/plugins/NativeIPGateway.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** NativeIPGateway.java 12 Dec 2008 16:27:40 -0000 1.2 --- NativeIPGateway.java 17 Dec 2008 12:15:43 -0000 1.3 *************** *** 49,55 **** --- 49,59 ---- import javax.swing.JCheckBox; import javax.swing.JComboBox; + import javax.swing.JInternalFrame; import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.JScrollPane; + import javax.swing.event.InternalFrameEvent; + import javax.swing.event.InternalFrameListener; + import jpcap.JpcapCaptor; import jpcap.JpcapSender; *************** *** 63,74 **** import se.sics.cooja.GUI; import se.sics.cooja.Mote; import se.sics.cooja.PluginType; import se.sics.cooja.Simulation; - import se.sics.cooja.VisPlugin; import se.sics.cooja.interfaces.SerialPort; @ClassDescription("Open Native IP Gateway") @PluginType(PluginType.MOTE_PLUGIN) ! public class NativeIPGateway extends VisPlugin { private static Logger logger = Logger.getLogger(NativeIPGateway.class); --- 67,78 ---- import se.sics.cooja.GUI; import se.sics.cooja.Mote; + import se.sics.cooja.Plugin; import se.sics.cooja.PluginType; import se.sics.cooja.Simulation; import se.sics.cooja.interfaces.SerialPort; @ClassDescription("Open Native IP Gateway") @PluginType(PluginType.MOTE_PLUGIN) ! public class NativeIPGateway implements Plugin { private static Logger logger = Logger.getLogger(NativeIPGateway.class); *************** *** 85,88 **** --- 89,94 ---- private final static int LABEL_HEIGHT = 20; + private Object coojaTag = null; /* Used by Cooja for book-keeping */ + private Mote mote; private SerialPort serialPort = null; *************** *** 103,106 **** --- 109,113 ---- private int inPkts = 0, outPkts = 0; + private JInternalFrame pluginGUI = null; private JLabel gatewayLabel = null; private JLabel interfaceLabel = null; *************** *** 127,132 **** private byte[] readSlipBuffer = new byte[READ_SLIP_BUFFER_SIZE]; ! public NativeIPGateway(Mote mote, Simulation simulation, GUI gui) { ! super("Native IP Gateway (" + mote + ")", gui); this.mote = mote; --- 134,138 ---- private byte[] readSlipBuffer = new byte[READ_SLIP_BUFFER_SIZE]; ! public NativeIPGateway(Mote mote, Simulation simulation, final GUI gui) { this.mote = mote; *************** *** 242,271 **** /* GUI components */ ! JPanel mainPane = new JPanel(); ! mainPane.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10)); ! mainPane.setLayout(new BoxLayout(mainPane, BoxLayout.Y_AXIS)); ! ipLabel = addInfo(mainPane, "Mote IP Address:", moteIP); ! ipLabel.setToolTipText(null); ! addComponent(mainPane, "Route to/Capture on: ", selectNICComboBox); ! addComponent(mainPane, "Auto-register native route: ", autoRegisterRoutes); ! addInfo(mainPane, "", ""); ! interfaceLabel = addInfo(mainPane, "Network Interface:", "?"); ! gatewayLabel = addInfo(mainPane, "Network Gateway:", "?"); ! macLabel = addInfo(mainPane, "Network MAC: ", "?"); ! inLabel = addInfo(mainPane, "Packets to simulation:", "0"); ! inLabel.setToolTipText(null); ! outLabel = addInfo(mainPane, "Packets from simulation:", "0"); ! outLabel.setToolTipText(null); ! this.getContentPane().add(BorderLayout.CENTER, ! new JScrollPane(mainPane, ! JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, ! JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED)); ! pack(); ! setSize(getWidth()+10, getHeight()+10); /* Start capturing network traffic for simulated network */ --- 248,300 ---- /* GUI components */ ! if (GUI.isVisualized()) { ! pluginGUI = new JInternalFrame( ! "Native IP Gateway (" + mote + ")", ! true, true, true, true); ! pluginGUI.addInternalFrameListener(new InternalFrameListener() { ! public void internalFrameClosing(InternalFrameEvent e) { ! gui.removePlugin(NativeIPGateway.this, true); ! } ! public void internalFrameClosed(InternalFrameEvent e) { } ! public void internalFrameOpened(InternalFrameEvent e) { } ! public void internalFrameIconified(InternalFrameEvent e) { } ! public void internalFrameDeiconified(InternalFrameEvent e) { } ! public void internalFrameActivated(InternalFrameEvent e) { ! /* Highlight mote in COOJA */ ! if (NativeIPGateway.this.coojaTag != null && coojaTag instanceof Mote) { ! gui.signalMoteHighlight((Mote) coojaTag); ! } ! } ! public void internalFrameDeactivated(InternalFrameEvent e) { } ! } ! ); ! JPanel mainPane = new JPanel(); ! mainPane.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10)); ! mainPane.setLayout(new BoxLayout(mainPane, BoxLayout.Y_AXIS)); ! ipLabel = addInfo(mainPane, "Mote IP Address:", moteIP); ! ipLabel.setToolTipText(null); ! addComponent(mainPane, "Route to/Capture on: ", selectNICComboBox); ! addComponent(mainPane, "Auto-register native route: ", autoRegisterRoutes); ! addInfo(mainPane, "", ""); ! interfaceLabel = addInfo(mainPane, "Network Interface:", "?"); ! gatewayLabel = addInfo(mainPane, "Network Gateway:", "?"); ! macLabel = addInfo(mainPane, "Network MAC: ", "?"); ! inLabel = addInfo(mainPane, "Packets to simulation:", "0"); ! inLabel.setToolTipText(null); ! outLabel = addInfo(mainPane, "Packets from simulation:", "0"); ! outLabel.setToolTipText(null); ! pluginGUI.getContentPane().add(BorderLayout.CENTER, ! new JScrollPane(mainPane, ! JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, ! JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED)); ! ! pluginGUI.pack(); ! pluginGUI.setSize(pluginGUI.getWidth()+10, pluginGUI.getHeight()+10); ! } /* Start capturing network traffic for simulated network */ *************** *** 275,284 **** startCapturingPackets(networkInterfacesAll[0]); } ! try { ! setSelected(true); ! } catch (java.beans.PropertyVetoException e) { ! // Could not select ! } } --- 304,311 ---- startCapturingPackets(networkInterfacesAll[0]); } + } ! public JInternalFrame getGUI() { ! return pluginGUI; } *************** *** 367,393 **** /* Update GUI */ ! interfaceLabel.setText(networkInterface.description); ! interfaceLabel.setToolTipText(networkInterface.description); ! if (networkInterface.addresses.length > 0) { ! gatewayLabel.setText(networkInterface.addresses[0].address.getHostAddress()); ! gatewayLabel.setToolTipText(networkInterface.addresses[0].address.getHostAddress()); ! } else { ! gatewayLabel.setText("[no gateway]"); ! gatewayLabel.setToolTipText(""); ! } ! macLabel.setText(Integer.toHexString(networkInterfaceMAC[0]&0xFF) + ! ":" + Integer.toHexString(networkInterfaceMAC[1]&0xFF) + ! ":" + Integer.toHexString(networkInterfaceMAC[2]&0xFF) + ! ":" + Integer.toHexString(networkInterfaceMAC[3]&0xFF) + ! ":" + Integer.toHexString(networkInterfaceMAC[4]&0xFF) + ! ":" + Integer.toHexString(networkInterfaceMAC[5]&0xFF)); ! macLabel.setToolTipText(Integer.toHexString(networkInterfaceMAC[0]&0xFF) + ! ":" + Integer.toHexString(networkInterfaceMAC[1]&0xFF) + ! ":" + Integer.toHexString(networkInterfaceMAC[2]&0xFF) + ! ":" + Integer.toHexString(networkInterfaceMAC[3]&0xFF) + ! ":" + Integer.toHexString(networkInterfaceMAC[4]&0xFF) + ! ":" + Integer.toHexString(networkInterfaceMAC[5]&0xFF)); ! selectNICComboBox.setSelectedItem(networkInterface.description + " (" + networkInterface.name + ")"); } --- 394,422 ---- /* Update GUI */ ! if (GUI.isVisualized()) { ! interfaceLabel.setText(networkInterface.description); ! interfaceLabel.setToolTipText(networkInterface.description); ! if (networkInterface.addresses.length > 0) { ! gatewayLabel.setText(networkInterface.addresses[0].address.getHostAddress()); ! gatewayLabel.setToolTipText(networkInterface.addresses[0].address.getHostAddress()); ! } else { ! gatewayLabel.setText("[no gateway]"); ! gatewayLabel.setToolTipText(""); ! } ! macLabel.setText(Integer.toHexString(networkInterfaceMAC[0]&0xFF) + ! ":" + Integer.toHexString(networkInterfaceMAC[1]&0xFF) + ! ":" + Integer.toHexString(networkInterfaceMAC[2]&0xFF) + ! ":" + Integer.toHexString(networkInterfaceMAC[3]&0xFF) + ! ":" + Integer.toHexString(networkInterfaceMAC[4]&0xFF) + ! ":" + Integer.toHexString(networkInterfaceMAC[5]&0xFF)); ! macLabel.setToolTipText(Integer.toHexString(networkInterfaceMAC[0]&0xFF) + ! ":" + Integer.toHexString(networkInterfaceMAC[1]&0xFF) + ! ":" + Integer.toHexString(networkInterfaceMAC[2]&0xFF) + ! ":" + Integer.toHexString(networkInterfaceMAC[3]&0xFF) + ! ":" + Integer.toHexString(networkInterfaceMAC[4]&0xFF) + ! ":" + Integer.toHexString(networkInterfaceMAC[5]&0xFF)); ! selectNICComboBox.setSelectedItem(networkInterface.description + " (" + networkInterface.name + ")"); ! } } *************** *** 511,515 **** private void createTunInterface() { if (ON_WINDOWS) { ! logger.warn("Cannot create tunnel network interface on Windows. Try using VMware interfaces."); } else { createTunInterfaceLinux(); --- 540,544 ---- private void createTunInterface() { if (ON_WINDOWS) { ! /*logger.warn("Cannot create tunnel network interface on Windows. Try using VMware interfaces.");*/ } else { createTunInterfaceLinux(); *************** *** 696,702 **** writeAsSlip(packetData, serialPort); - /* Update GUI */ inPkts++; ! inLabel.setText("" + inPkts); } --- 725,734 ---- writeAsSlip(packetData, serialPort); inPkts++; ! ! /* Update GUI */ ! if (GUI.isVisualized()) { ! inLabel.setText("" + inPkts); ! } } *************** *** 745,752 **** /*logger.info("Sending packet (" + packet.len + " bytes) to native network: " + sender);*/ sender.sendPacket(packet); /* Update GUI */ ! outPkts++; ! outLabel.setText("" + outPkts); } --- 777,786 ---- /*logger.info("Sending packet (" + packet.len + " bytes) to native network: " + sender);*/ sender.sendPacket(packet); + outPkts++; /* Update GUI */ ! if (GUI.isVisualized()) { ! outLabel.setText("" + outPkts); ! } } *************** *** 870,874 **** if (!ok) { logger.warn("Network interface not available: " + element.getText()); ! logger.warn("Instead capturing on default network interface: " + selectNICComboBox.getItemAt(0)); } } else if (element.getName().equals("register_routes")) { --- 904,908 ---- if (!ok) { logger.warn("Network interface not available: " + element.getText()); ! logger.warn("Instead capturing on default network interface: " + networkInterface.name); } } else if (element.getName().equals("register_routes")) { *************** *** 928,930 **** --- 962,972 ---- } + public void tagWithObject(Object tag) { + this.coojaTag = tag; + } + + public Object getTag() { + return coojaTag; + } + } |