From 13b6fe2cd558fa5f0badad71b4f8ad5e94f60264 Mon Sep 17 00:00:00 2001 From: fros4943 Date: Thu, 26 Mar 2009 16:24:31 +0000 Subject: [PATCH] added experimental packet counters --- .../plugins/skins/UDGMVisualizerSkin.java | 32 +++++++++++++++++-- .../radiomediums/AbstractRadioMedium.java | 10 +++++- 2 files changed, 39 insertions(+), 3 deletions(-) diff --git a/tools/cooja/java/se/sics/cooja/plugins/skins/UDGMVisualizerSkin.java b/tools/cooja/java/se/sics/cooja/plugins/skins/UDGMVisualizerSkin.java index 0b262546e..da3ad6334 100644 --- a/tools/cooja/java/se/sics/cooja/plugins/skins/UDGMVisualizerSkin.java +++ b/tools/cooja/java/se/sics/cooja/plugins/skins/UDGMVisualizerSkin.java @@ -26,7 +26,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $Id: UDGMVisualizerSkin.java,v 1.2 2009/03/24 16:07:44 fros4943 Exp $ + * $Id: UDGMVisualizerSkin.java,v 1.3 2009/03/26 16:24:31 fros4943 Exp $ */ package se.sics.cooja.plugins.skins; @@ -38,6 +38,8 @@ import java.awt.event.MouseEvent; import java.awt.event.MouseListener; import java.util.Observable; import java.util.Observer; + +import javax.swing.JLabel; import javax.swing.JSpinner; import javax.swing.SpinnerNumberModel; import javax.swing.event.ChangeEvent; @@ -81,6 +83,10 @@ public class UDGMVisualizerSkin implements VisualizerSkin { private UDGM radioMedium = null; private Observer radioMediumObserver; + private JLabel txCounter = null; + private JLabel rxCounter = null; + private JLabel interferedCounter = null; + private JSpinner txRangeSpinner = null; private JSpinner interferenceRangeSpinner = null; private JSpinner successRatioTxSpinner = null; @@ -207,6 +213,13 @@ public class UDGMVisualizerSkin implements VisualizerSkin { visualizer.registerSimulationMenuAction(SuccessRatioMenuAction.class); /* Add (currently invisible) spinners */ + txCounter = new JLabel("TX: " + radioMedium.COUNTER_TX); + rxCounter = new JLabel("RX: " + radioMedium.COUNTER_RX); + interferedCounter = new JLabel("INT: " + + radioMedium.COUNTER_INTERFERED); + visualizer.getCurrentCanvas().add(txCounter); + visualizer.getCurrentCanvas().add(rxCounter); + visualizer.getCurrentCanvas().add(interferedCounter); + visualizer.getCurrentCanvas().add(txRangeSpinner); visualizer.getCurrentCanvas().add(interferenceRangeSpinner); visualizer.getCurrentCanvas().add(successRatioTxSpinner); @@ -215,6 +228,16 @@ public class UDGMVisualizerSkin implements VisualizerSkin { /* Start observing radio medium */ radioMedium.addRadioMediumObserver(radioMediumObserver = new Observer() { public void update(Observable obs, Object obj) { + if (txCounter != null) { + txCounter.setText("TX: " + radioMedium.COUNTER_TX); + } + if (rxCounter != null) { + rxCounter.setText("RX: " + radioMedium.COUNTER_RX); + } + if (interferedCounter != null) { + interferedCounter.setText("INT: " + + radioMedium.COUNTER_INTERFERED); + } + visualizer.repaint(); } }); @@ -229,6 +252,10 @@ public class UDGMVisualizerSkin implements VisualizerSkin { radioMediumObserver = null; radioMedium = null; + visualizer.getCurrentCanvas().remove(txCounter); + visualizer.getCurrentCanvas().remove(rxCounter); + visualizer.getCurrentCanvas().remove(interferedCounter); + /* Remove spinners */ visualizer.getCurrentCanvas().remove(txRangeSpinner); visualizer.getCurrentCanvas().remove(interferenceRangeSpinner); @@ -329,7 +356,8 @@ public class UDGMVisualizerSkin implements VisualizerSkin { if (conns != null) { g.setColor(Color.BLACK); for (RadioConnection conn : conns) { - Point sourcePoint = visualizer.transformPositionToPixel(conn.getSource().getPosition()); + Radio source = conn.getSource(); + Point sourcePoint = visualizer.transformPositionToPixel(source.getPosition()); for (Radio destRadio : conn.getDestinations()) { Position destPos = destRadio.getPosition(); Point destPoint = visualizer.transformPositionToPixel(destPos); diff --git a/tools/cooja/java/se/sics/cooja/radiomediums/AbstractRadioMedium.java b/tools/cooja/java/se/sics/cooja/radiomediums/AbstractRadioMedium.java index 37ea51d25..3d0fdd2d6 100644 --- a/tools/cooja/java/se/sics/cooja/radiomediums/AbstractRadioMedium.java +++ b/tools/cooja/java/se/sics/cooja/radiomediums/AbstractRadioMedium.java @@ -26,7 +26,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $Id: AbstractRadioMedium.java,v 1.7 2009/02/24 15:12:22 fros4943 Exp $ + * $Id: AbstractRadioMedium.java,v 1.8 2009/03/26 16:24:31 fros4943 Exp $ */ package se.sics.cooja.radiomediums; @@ -59,6 +59,11 @@ public abstract class AbstractRadioMedium extends RadioMedium { private Simulation simulation = null; + /* Book-keeping */ + public int COUNTER_TX = 0; + public int COUNTER_RX = 0; + public int COUNTER_INTERFERED = 0; + public class RadioMediumObservable extends Observable { public void setRadioMediumChanged() { setChanged(); @@ -243,7 +248,9 @@ public abstract class AbstractRadioMedium extends RadioMedium { } else { activeConnections.remove(connection); finishedConnections.add(connection); + COUNTER_TX++; for (Radio dstRadio : connection.getDestinations()) { + COUNTER_RX++; if (connection.getDestinationDelay(dstRadio) == 0) { dstRadio.signalReceptionEnd(); } else { @@ -262,6 +269,7 @@ public abstract class AbstractRadioMedium extends RadioMedium { } } for (Radio dstRadio : connection.getInterfered()) { + COUNTER_INTERFERED++; dstRadio.signalReceptionEnd(); } }