2006-08-21 14:11:16 +02:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2006, Swedish Institute of Computer Science.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. 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.
|
|
|
|
* 3. Neither the name of the Institute 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 INSTITUTE 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 INSTITUTE 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.
|
|
|
|
*
|
2008-10-15 11:00:52 +02:00
|
|
|
* $Id: VisUAODV.java,v 1.2 2008/10/15 09:00:52 nifi Exp $
|
2006-08-21 14:11:16 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
import java.awt.*;
|
|
|
|
import se.sics.cooja.*;
|
2007-02-28 10:47:45 +01:00
|
|
|
import se.sics.cooja.interfaces.*;
|
2006-08-21 14:11:16 +02:00
|
|
|
import se.sics.cooja.plugins.*;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* VisUAODV is a 2D graphical visualizer for simulations with motes running
|
|
|
|
* UAODV protocol.
|
|
|
|
* RREQs are painted red, and RREPs green.
|
|
|
|
* The rest of sent data is painted black.
|
|
|
|
*
|
|
|
|
* Interactions with motes are available via registered mote plugins.
|
|
|
|
*
|
|
|
|
* @author Fredrik Osterlind
|
|
|
|
*/
|
|
|
|
@ClassDescription("uAODV Visualizer")
|
2007-01-09 11:09:59 +01:00
|
|
|
@PluginType(PluginType.SIM_PLUGIN)
|
2006-08-21 14:11:16 +02:00
|
|
|
public class VisUAODV extends VisTraffic {
|
|
|
|
private static final long serialVersionUID = 1L;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates a new VisUAODV visualizer.
|
|
|
|
* @param simulationToVisualize Simulation to visualize
|
|
|
|
*/
|
2007-01-09 11:09:59 +01:00
|
|
|
public VisUAODV(Simulation simulationToVisualize, GUI gui) {
|
|
|
|
super(simulationToVisualize, gui);
|
2006-08-21 14:11:16 +02:00
|
|
|
setTitle("uAODV Visualizer");
|
|
|
|
}
|
|
|
|
|
|
|
|
protected void paintConnection(RadioConnection connection, Graphics g2d) {
|
2007-02-28 10:47:45 +01:00
|
|
|
Point sourcePixelPosition = transformPositionToPixel(connection.getSource().getPosition());
|
|
|
|
for (Radio destRadio: connection.getDestinations()) {
|
|
|
|
Position destPosition = destRadio.getPosition();
|
2006-08-21 14:11:16 +02:00
|
|
|
Point destPixelPosition = transformPositionToPixel(destPosition);
|
|
|
|
g2d.setColor(getColorOf(connection));
|
|
|
|
|
2008-10-15 11:00:52 +02:00
|
|
|
RadioPacket radioPacket = destRadio.getLastPacketReceived();
|
|
|
|
if (radioPacket != null) {
|
|
|
|
byte[] packet = radioPacket.getPacketData();
|
|
|
|
if (isRouteReply(packet)) {
|
|
|
|
((Graphics2D) g2d).setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 1.0f));
|
|
|
|
}
|
2006-08-21 14:11:16 +02:00
|
|
|
|
2008-10-15 11:00:52 +02:00
|
|
|
g2d.drawLine(sourcePixelPosition.x, sourcePixelPosition.y,
|
2006-08-21 14:11:16 +02:00
|
|
|
destPixelPosition.x, destPixelPosition.y);
|
|
|
|
|
2008-10-15 11:00:52 +02:00
|
|
|
int hopCount = getHopCount(packet);
|
|
|
|
if (hopCount >= 0)
|
|
|
|
g2d.drawString("" + hopCount, sourcePixelPosition.x, sourcePixelPosition.y);
|
|
|
|
}
|
2006-08-21 14:11:16 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
protected Color getColorOf(RadioConnection conn) {
|
2008-10-15 11:00:52 +02:00
|
|
|
RadioPacket radioPacket = conn.getSource().getLastPacketReceived();
|
|
|
|
if (radioPacket != null) {
|
|
|
|
byte[] packet = radioPacket.getPacketData();
|
|
|
|
if (isRouteRequest(packet))
|
|
|
|
return Color.RED;
|
|
|
|
else if (isRouteReply(packet))
|
|
|
|
return Color.GREEN;
|
|
|
|
}
|
|
|
|
return Color.BLACK;
|
2006-08-21 14:11:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
private boolean isRouteRequest(byte[] data) {
|
|
|
|
if (data.length > 28)
|
|
|
|
return data[28] == 1;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
private boolean isRouteReply(byte[] data) {
|
|
|
|
if (data.length > 28)
|
|
|
|
return data[28] == 2;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
private int getHopCount(byte[] data) {
|
|
|
|
if (data.length > 31)
|
2008-10-15 11:00:52 +02:00
|
|
|
return data[31];
|
2006-08-21 14:11:16 +02:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|