Minor cleanup of radio logger verbose output

This commit is contained in:
nifi 2010-03-03 12:45:39 +00:00
parent efe8f200af
commit b59845d117
3 changed files with 49 additions and 38 deletions

View file

@ -26,7 +26,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $Id: RadioLogger.java,v 1.28 2010/02/25 23:44:16 nifi Exp $
* $Id: RadioLogger.java,v 1.29 2010/03/03 12:45:39 nifi Exp $
*/
package se.sics.cooja.plugins;
@ -397,10 +397,15 @@ public class RadioLogger extends VisPlugin {
PacketAnalyzer.Packet packet = new PacketAnalyzer.Packet(data, PacketAnalyzer.MAC_LEVEL);
if (analyzePacket(packet, brief, verbose)) {
conn.data = (data.length < 10 ? " " : "") + data.length + ": " + brief;
if (packet.hasMoreData()) {
conn.data += ": " + StringUtils.toHex(packet.getPayload(), 4);
byte[] payload = packet.getPayload();
brief.append(StringUtils.toHex(payload, 4));
verbose.append("<b>Payload (")
.append(payload.length).append(" bytes)</b><br><pre>")
.append(StringUtils.hexDump(payload))
.append("</pre>");
}
conn.data = (data.length < 10 ? " " : "") + data.length + ": " + brief;
if (verbose.length() > 0) {
conn.tooltip = verbose.toString();
}
@ -420,7 +425,8 @@ public class RadioLogger extends VisPlugin {
analyzer.analyzePacket(packet, brief, verbose);
/* continue another round if more bytes left */
analyze = packet.hasMoreData();
brief.append("|");
brief.append('|');
verbose.append("<p>");
break;
}
}

View file

@ -15,22 +15,22 @@ public class IEEE802154Analyzer extends PacketAnalyzer {
public static final int ACKFRAME = 0x02;
public static final int CMDFRAME = 0x03;
private static final byte[] BROADCAST_ADDR = {(byte)0xff, (byte)0xff};
// private static final byte[] BROADCAST_ADDR = {(byte)0xff, (byte)0xff};
private static final String[] typeS = {"-", "D", "A"};
private static final String[] typeVerbose = {"Beacon", "Data", "Ack"};
private static final String[] typeVerbose = {"BEACON", "DATA", "ACK"};
private int defaultAddressMode = LONG_ADDRESS;
private byte seqNo = 0;
// private int defaultAddressMode = LONG_ADDRESS;
// private byte seqNo = 0;
private int myPanID = 0xabcd;
// private int myPanID = 0xabcd;
public boolean matchPacket(Packet packet) {
return packet.level == MAC_LEVEL;
}
/* we need better model of this later... */
/* we need better model of this later... */
public boolean matchPacket(byte[] packet, int level) {
return false;
}
@ -45,14 +45,14 @@ public class IEEE802154Analyzer extends PacketAnalyzer {
public void analyzePacket(Packet packet, StringBuffer brief, StringBuffer verbose) {
int pos = packet.pos;
int type = packet.data[pos + 0] & 7;
int security = (packet.data[pos + 0] >> 3) & 1;
int pending = (packet.data[pos + 0] >> 4) & 1;
int ackRequired = (packet.data[pos + 0] >> 5) & 1;
// int security = (packet.data[pos + 0] >> 3) & 1;
// int pending = (packet.data[pos + 0] >> 4) & 1;
// int ackRequired = (packet.data[pos + 0] >> 5) & 1;
int panCompression = (packet.data[pos + 0]>> 6) & 1;
int destAddrMode = (packet.data[pos + 1] >> 2) & 3;
int frameVersion = (packet.data[pos + 1] >> 4) & 3;
// int frameVersion = (packet.data[pos + 1] >> 4) & 3;
int srcAddrMode = (packet.data[pos + 1] >> 6) & 3;
int seqNumber = packet.data[pos + 2];
int seqNumber = packet.data[pos + 2] & 0xff;
int destPanID = 0;
int srcPanID = 0;
byte[] sourceAddress = null;
@ -98,22 +98,32 @@ public class IEEE802154Analyzer extends PacketAnalyzer {
}
}
int payloadLen = packet.data.length - pos;
// int payloadLen = packet.data.length - pos;
brief.append("15.4 ");
brief.append(typeS[type]).append(' ');
brief.append(type < typeS.length ? typeS[type] : "?").append(' ');
printAddress(brief, srcAddrMode, sourceAddress);
brief.append(" ");
brief.append(' ');
printAddress(brief, destAddrMode, destAddress);
verbose.append("<html><b>IEEE 802.15.4</b><br>from ");
verbose.append("<html><b>IEEE 802.15.4 ")
.append(type < typeVerbose.length ? typeVerbose[type] : "?")
.append(' ').append(seqNumber)
.append("</b><br>From ");
if (srcPanID != 0) {
verbose.append(StringUtils.toHex((byte)(srcPanID >> 8)))
.append(StringUtils.toHex((byte)(srcPanID & 0xff)))
.append('/');
}
printAddress(verbose, srcAddrMode, sourceAddress);
verbose.append(" to ");
if (destPanID != 0) {
verbose.append(StringUtils.toHex((byte)(destPanID >> 8)))
.append(StringUtils.toHex((byte)(destPanID & 0xff)))
.append('/');
}
printAddress(verbose, destAddrMode, destAddress);
verbose.append("<br>FrameType: : " + typeVerbose[type]);
verbose.append("<br>Payload len: " + payloadLen);
verbose.append("<br>");
// verbose.append("<br>Payload len: ").append(payloadLen);
/* update packet */
packet.pos = pos;

View file

@ -79,7 +79,7 @@ public class IPHCPacketAnalyzer extends PacketAnalyzer {
int sci = 0;
int dci = 0;
brief.append("iphc tf=" + tf + (nh == 1 ? " nh" : "") + " hl=" + hlim + (cid == 1 ? " cid " : ""));
brief.append("IPHC tf=" + tf + (nh == 1 ? " nh" : "") + " hl=" + hlim + (cid == 1 ? " cid " : ""));
brief.append((sac == 1 ? " sac" : "") + " sam=" + sam + (m == 1 ? " M" : "") +
(dac == 1 ? " dac" : " -") + " dam=" + dam);
@ -88,12 +88,13 @@ public class IPHCPacketAnalyzer extends PacketAnalyzer {
}
/* need to decompress while analyzing - add that later... */
verbose.append("<br><b>IPHC HC-06</b><br>");
verbose.append("tf = " + tf + " nhc = " + nh + " hlim = " + hlim + " cid = " + cid);
verbose.append("sac = " + sac + " sam = " + sam + " MCast = " + m + " dac = " + dac +
" dam = " + dam + "<br>");
verbose.append("<b>IPHC HC-06</b><br>");
verbose.append("tf = " + tf + " nhc = " + nh + " hlim = " + hlim
+ " cid = " + cid + " sac = " + sac + " sam = " + sam
+ " MCast = " + m + " dac = " + dac + " dam = " + dam + "<br>");
if (cid == 1) {
verbose.append("Contexts: sci=" + (packet.get(2) >> 4) + " dci=" + (packet.get(2) & 0x0f));
verbose.append("Contexts: sci=" + (packet.get(2) >> 4) + " dci="
+ (packet.get(2) & 0x0f) + "<br>");
sci = packet.get(2) >> 4;
dci = packet.get(2) & 0x0f;
}
@ -403,20 +404,14 @@ public class IPHCPacketAnalyzer extends PacketAnalyzer {
else if (proto == PROTO_UDP) protoStr = "UDP";
else if (proto == PROTO_TCP) protoStr = "TCP";
verbose.append("<br><b>IPv6 Packet: ").append(protoStr).append("</b><br>");
verbose.append("From: ");
verbose.append("<br><b>IPv6 ").append(protoStr).append("</b><br>");
verbose.append("From ");
printAddress(verbose, srcAddress);
verbose.append(" to ");
printAddress(verbose, destAddress);
verbose.append("<br>");
brief.append("|").append(StringUtils.toHex(packet.getPayload(), 4));
verbose.append("Payload:<br><pre>").append(StringUtils.hexDump(packet.getPayload())).
append("</pre>");
packet.pos = packet.data.length;
// packet.pos = packet.data.length;
packet.level = NETWORK_LEVEL;
}
public static void printAddress(StringBuffer out, byte[] address) {