[cooja] plugins/analyzers: Indention and whitespace cleanups

This commit is contained in:
Enrico Joerns 2014-07-11 02:07:21 +02:00
parent 01bd045570
commit 3e9a780721
7 changed files with 1001 additions and 988 deletions

View file

@ -27,7 +27,6 @@
* SUCH DAMAGE.
*
*/
package org.contikios.cooja.plugins;
import java.awt.BorderLayout;
@ -111,6 +110,7 @@ import org.contikios.cooja.util.StringUtils;
@ClassDescription("Radio messages")
@PluginType(PluginType.SIM_PLUGIN)
public class RadioLogger extends VisPlugin {
private static Logger logger = Logger.getLogger(RadioLogger.class);
private static final long serialVersionUID = -6927091711697081353L;
@ -141,7 +141,7 @@ public class RadioLogger extends VisPlugin {
private Observer radioMediumObserver;
private AbstractTableModel model;
private HashMap<String,Action> analyzerMap = new HashMap<String,Action>();
private HashMap<String, Action> analyzerMap = new HashMap<String, Action>();
private String analyzerName = null;
private ArrayList<PacketAnalyzer> analyzers = null;
private IEEE802154Analyzer analyzerWithPcap;
@ -290,14 +290,13 @@ public class RadioLogger extends VisPlugin {
/* TODO This entry may represent several hidden connections */
RadioConnectionLog conn = connections.get(modelRowIndex);
if (modelColumnIndex == COLUMN_TIME) {
return
"<html>" +
"Start time (us): " + conn.startTime +
"<br>" +
"End time (us): " + conn.endTime +
"<br><br>" +
"Duration (us): " + (conn.endTime - conn.startTime) +
"</html>";
return "<html>"
+ "Start time (us): " + conn.startTime
+ "<br>"
+ "End time (us): " + conn.endTime
+ "<br><br>"
+ "Duration (us): " + (conn.endTime - conn.startTime)
+ "</html>";
} else if (modelColumnIndex == COLUMN_FROM) {
return conn.connection.getSource().getMote().toString();
} else if (modelColumnIndex == COLUMN_TO) {
@ -346,8 +345,8 @@ public class RadioLogger extends VisPlugin {
public void keyPressed(KeyEvent e) {
if (e.getKeyCode() == KeyEvent.VK_SPACE) {
showInAllAction.actionPerformed(null);
} else if (e.getKeyCode() == KeyEvent.VK_F &&
(e.getModifiers() & KeyEvent.CTRL_MASK) != 0) {
} else if (e.getKeyCode() == KeyEvent.VK_F
&& (e.getModifiers() & KeyEvent.CTRL_MASK) != 0) {
searchField.setVisible(true);
searchField.requestFocus();
searchField.selectAll();
@ -407,7 +406,6 @@ public class RadioLogger extends VisPlugin {
fileMenu.add(new JMenuItem(saveAction));
JPopupMenu popupMenu = new JPopupMenu();
JMenu focusMenu = new JMenu("Show in");
@ -418,7 +416,6 @@ public class RadioLogger extends VisPlugin {
popupMenu.add(focusMenu);
//a group of radio button menu items
ButtonGroup group = new ButtonGroup();
JRadioButtonMenuItem rbMenuItem = new JRadioButtonMenuItem(
createAnalyzerAction("No Analyzer", "none", null, true));
@ -436,15 +433,15 @@ public class RadioLogger extends VisPlugin {
analyzerMenu.add(rbMenuItem);
/* Load additional analyzers specified by projects (cooja.config) */
String[] projectAnalyzerSuites =
gui.getProjectConfig().getStringArrayValue(RadioLogger.class, "ANALYZERS");
String[] projectAnalyzerSuites
= gui.getProjectConfig().getStringArrayValue(RadioLogger.class, "ANALYZERS");
if (projectAnalyzerSuites != null) {
for (String suiteName: projectAnalyzerSuites) {
if (suiteName == null || suiteName.trim().isEmpty()) {
continue;
}
Class<? extends RadioLoggerAnalyzerSuite> suiteClass =
gui.tryLoadClass(RadioLogger.this, RadioLoggerAnalyzerSuite.class, suiteName);
Class<? extends RadioLoggerAnalyzerSuite> suiteClass
= gui.tryLoadClass(RadioLogger.this, RadioLoggerAnalyzerSuite.class, suiteName);
try {
RadioLoggerAnalyzerSuite suite = suiteClass.newInstance();
ArrayList<PacketAnalyzer> suiteAnalyzers = suite.getAnalyzers();
@ -560,18 +557,18 @@ public class RadioLogger extends VisPlugin {
}
int rows = dataTable.getModel().getRowCount();
for (int i=0; i < rows; i++) {
for (int i = 0; i < rows; i++) {
int r;
if (!reverse) {
r = (row + i + rows)%rows;
r = (row + i + rows) % rows;
} else {
r = (row - i + rows)%rows;
r = (row - i + rows) % rows;
}
String val = (String) dataTable.getModel().getValueAt(r, COLUMN_DATA);
if (!val.contains(text)) {
continue;
}
dataTable.setRowSelectionInterval(r,r);
dataTable.setRowSelectionInterval(r, r);
dataTable.scrollRectToVisible(dataTable.getCellRect(r, COLUMN_DATA, true));
searchField.setBackground(Color.WHITE);
return;
@ -590,7 +587,7 @@ public class RadioLogger extends VisPlugin {
if (dataTable.getRowCount() == 0) {
return;
}
for (int ai=0; ai < model.getRowCount(); ai++) {
for (int ai = 0; ai < model.getRowCount(); ai++) {
int index = dataTable.convertRowIndexToModel(ai);
if (connections.get(index).endTime < time) {
continue;
@ -600,14 +597,14 @@ public class RadioLogger extends VisPlugin {
dataTable.setRowSelectionInterval(ai, ai);
return;
}
dataTable.scrollRectToVisible(dataTable.getCellRect(dataTable.getRowCount()-1, 0, true));
dataTable.setRowSelectionInterval(dataTable.getRowCount()-1, dataTable.getRowCount()-1);
dataTable.scrollRectToVisible(dataTable.getCellRect(dataTable.getRowCount() - 1, 0, true));
dataTable.setRowSelectionInterval(dataTable.getRowCount() - 1, dataTable.getRowCount() - 1);
}
});
}
private void applyFilter() {
for(RadioConnectionLog conn: connections) {
for (RadioConnectionLog conn: connections) {
conn.data = null;
conn.tooltip = null;
conn.hides = 0;
@ -623,18 +620,18 @@ public class RadioLogger extends VisPlugin {
byte[] currentData = current.packet.getPacketData();
if (!showDuplicates && row > 0) {
RadioConnectionLog previous = connections.get(row-1);
RadioConnectionLog previous = connections.get(row - 1);
byte[] previousData = previous.packet.getPacketData();
if (!showDuplicates &&
Arrays.equals(previousData, currentData) &&
previous.connection.getSource() == current.connection.getSource() &&
Arrays.equals(previous.connection.getAllDestinations(), current.connection.getAllDestinations())) {
if (connections.get(row-1).hiddenBy == null) {
connections.get(row-1).hides++;
connections.get(row).hiddenBy = connections.get(row-1);
if (!showDuplicates
&& Arrays.equals(previousData, currentData)
&& previous.connection.getSource() == current.connection.getSource()
&& Arrays.equals(previous.connection.getAllDestinations(), current.connection.getAllDestinations())) {
if (connections.get(row - 1).hiddenBy == null) {
connections.get(row - 1).hides++;
connections.get(row).hiddenBy = connections.get(row - 1);
} else {
connections.get(row-1).hiddenBy.hides++;
connections.get(row).hiddenBy = connections.get(row-1).hiddenBy;
connections.get(row - 1).hiddenBy.hides++;
connections.get(row).hiddenBy = connections.get(row - 1).hiddenBy;
}
return false;
}
@ -661,7 +658,7 @@ public class RadioLogger extends VisPlugin {
if (conn.packet == null) {
data = null;
} else if (conn.packet instanceof ConvertedRadioPacket) {
data = ((ConvertedRadioPacket)conn.packet).getOriginalPacketData();
data = ((ConvertedRadioPacket) conn.packet).getOriginalPacketData();
} else {
data = conn.packet.getPacketData();
}
@ -737,29 +734,29 @@ public class RadioLogger extends VisPlugin {
}
if (packet instanceof ConvertedRadioPacket && packet.getPacketData().length > 0) {
byte[] original = ((ConvertedRadioPacket)packet).getOriginalPacketData();
byte[] converted = ((ConvertedRadioPacket)packet).getPacketData();
conn.tooltip = "<html><font face=\"Monospaced\">" +
"<b>Packet data (" + original.length + " bytes)</b><br>" +
"<pre>" + StringUtils.hexDump(original) + "</pre>" +
"</font><font face=\"Monospaced\">" +
"<b>Cross-level packet data (" + converted.length + " bytes)</b><br>" +
"<pre>" + StringUtils.hexDump(converted) + "</pre>" +
"</font></html>";
byte[] original = ((ConvertedRadioPacket) packet).getOriginalPacketData();
byte[] converted = ((ConvertedRadioPacket) packet).getPacketData();
conn.tooltip = "<html><font face=\"Monospaced\">"
+ "<b>Packet data (" + original.length + " bytes)</b><br>"
+ "<pre>" + StringUtils.hexDump(original) + "</pre>"
+ "</font><font face=\"Monospaced\">"
+ "<b>Cross-level packet data (" + converted.length + " bytes)</b><br>"
+ "<pre>" + StringUtils.hexDump(converted) + "</pre>"
+ "</font></html>";
} else if (packet instanceof ConvertedRadioPacket) {
byte[] original = ((ConvertedRadioPacket)packet).getOriginalPacketData();
conn.tooltip = "<html><font face=\"Monospaced\">" +
"<b>Packet data (" + original.length + " bytes)</b><br>" +
"<pre>" + StringUtils.hexDump(original) + "</pre>" +
"</font><font face=\"Monospaced\">" +
"<b>No cross-level conversion available</b><br>" +
"</font></html>";
byte[] original = ((ConvertedRadioPacket) packet).getOriginalPacketData();
conn.tooltip = "<html><font face=\"Monospaced\">"
+ "<b>Packet data (" + original.length + " bytes)</b><br>"
+ "<pre>" + StringUtils.hexDump(original) + "</pre>"
+ "</font><font face=\"Monospaced\">"
+ "<b>No cross-level conversion available</b><br>"
+ "</font></html>";
} else {
byte[] data = packet.getPacketData();
conn.tooltip = "<html><font face=\"Monospaced\">" +
"<b>Packet data (" + data.length + " bytes)</b><br>" +
"<pre>" + StringUtils.hexDump(data) + "</pre>" +
"</font></html>";
conn.tooltip = "<html><font face=\"Monospaced\">"
+ "<b>Packet data (" + data.length + " bytes)</b><br>"
+ "<pre>" + StringUtils.hexDump(data) + "</pre>"
+ "</font></html>";
}
}
@ -796,7 +793,7 @@ public class RadioLogger extends VisPlugin {
}
if (aliases != null) {
for (Object key: aliases.keySet()) {
for (Object key : aliases.keySet()) {
element = new Element("alias");
element.setAttribute("payload", (String) key);
element.setAttribute("alias", (String) aliases.get(key));
@ -853,6 +850,7 @@ public class RadioLogger extends VisPlugin {
}
private class RadioConnectionLog {
long startTime;
long endTime;
RadioConnection connection;
@ -868,11 +866,10 @@ public class RadioLogger extends VisPlugin {
if (data == null) {
RadioLogger.this.prepareDataString(this);
}
return
Long.toString(startTime / Simulation.MILLISECOND) + "\t" +
connection.getSource().getMote().getID() + "\t" +
getDestString(this) + "\t" +
data;
return Long.toString(startTime / Simulation.MILLISECOND) + "\t"
+ connection.getSource().getMote().getID() + "\t"
+ getDestString(this) + "\t"
+ data;
}
}
@ -888,7 +885,7 @@ public class RadioLogger extends VisPlugin {
for (Radio dest: dests) {
sb.append(dest.getMote().getID()).append(',');
}
sb.setLength(sb.length()-1);
sb.setLength(sb.length() - 1);
return sb.toString();
}
@ -961,7 +958,7 @@ public class RadioLogger extends VisPlugin {
Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
StringBuilder sb = new StringBuilder();
for(int i=0; i < connections.size(); i++) {
for (int i = 0; i < connections.size(); i++) {
sb.append(connections.get(i).toString() + "\n");
}
@ -984,7 +981,7 @@ public class RadioLogger extends VisPlugin {
if (saveFile.exists()) {
String s1 = "Overwrite";
String s2 = "Cancel";
Object[] options = { s1, s2 };
Object[] options = {s1, s2};
int n = JOptionPane.showOptionDialog(
Cooja.getTopParentContainer(),
"A file with the same name already exists.\nDo you want to remove it?",
@ -1002,7 +999,7 @@ public class RadioLogger extends VisPlugin {
try {
PrintWriter outStream = new PrintWriter(new FileWriter(saveFile));
for(int i=0; i < connections.size(); i++) {
for (int i = 0; i < connections.size(); i++) {
outStream.print(connections.get(i).toString() + "\n");
}
outStream.close();
@ -1016,6 +1013,7 @@ public class RadioLogger extends VisPlugin {
private Action timeLineAction = new AbstractAction("Timeline") {
private static final long serialVersionUID = -4035633464748224192L;
public void actionPerformed(ActionEvent e) {
int selectedRow = dataTable.getSelectedRow();
if (selectedRow < 0) return;
@ -1039,6 +1037,7 @@ public class RadioLogger extends VisPlugin {
private Action logListenerAction = new AbstractAction("Mote output") {
private static final long serialVersionUID = 1985006491187878651L;
public void actionPerformed(ActionEvent e) {
int selectedRow = dataTable.getSelectedRow();
if (selectedRow < 0) return;
@ -1062,9 +1061,11 @@ public class RadioLogger extends VisPlugin {
private Action showInAllAction = new AbstractAction("Timeline and mote output") {
private static final long serialVersionUID = -3888292108886138128L;
{
putValue(ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_SPACE, 0, true));
}
public void actionPerformed(ActionEvent e) {
timeLineAction.actionPerformed(null);
logListenerAction.actionPerformed(null);
@ -1088,9 +1089,9 @@ public class RadioLogger extends VisPlugin {
String alias = (String) JOptionPane.showInputDialog(
Cooja.getTopParentContainer(),
"Enter alias for all packets with identical payload.\n" +
"An empty string removes the current alias.\n\n" +
connections.get(selectedRow).data + "\n",
"Enter alias for all packets with identical payload.\n"
+ "An empty string removes the current alias.\n\n"
+ connections.get(selectedRow).data + "\n",
"Create packet payload alias",
JOptionPane.QUESTION_MESSAGE,
null,
@ -1143,14 +1144,14 @@ public class RadioLogger extends VisPlugin {
public String getConnectionsString() {
StringBuilder sb = new StringBuilder();
RadioConnectionLog[] cs = connections.toArray(new RadioConnectionLog[0]);
for(RadioConnectionLog c: cs) {
for (RadioConnectionLog c : cs) {
sb.append(c.toString() + "\n");
}
return sb.toString();
};
}
public void saveConnectionsToFile(String fileName) {
StringUtils.saveToFile(new File(fileName), getConnectionsString());
};
}
}

View file

@ -31,14 +31,13 @@ public class ICMPv6Analyzer extends PacketAnalyzer {
public static final int PREFIX_INFO = 3;
public static final int MTU_INFO = 5;
public static final String[] TYPE_NAME = new String[] {
public static final String[] TYPE_NAME = new String[]{
"ECHO_REQUEST", "ECHO_REPLY",
"GROUP_QUERY", "GROUP_REPORT", "GROUP_REDUCTION",
"ROUTER_SOLICITATION", "ROUTER_ADVERTISEMENT",
"NEIGHBOR_SOLICITATION", "NEIGHBOR_ADVERTISEMENT", "REDIRECT",
"ROUTER RENUMBER", "NODE INFORMATION QUERY", "NODE INFORMATION RESPONSE"};
public int analyzePacket(Packet packet, StringBuffer brief,
StringBuffer verbose) {
int type = packet.get(0) & 0xff;
@ -54,7 +53,7 @@ public class ICMPv6Analyzer extends PacketAnalyzer {
/* RPL */
brief.append("RPL ");
verbose.append("Type: RPL Code: ");
switch(code) {
switch (code) {
case RPL_CODE_DIS:
brief.append("DIS");
verbose.append("DIS");
@ -69,8 +68,11 @@ public class ICMPv6Analyzer extends PacketAnalyzer {
int mop = (packet.get(8) >> 3) & 0x07;
int dtsn = packet.get(9);
verbose.append(" InstanceID: " + instanceID + " Version: " + version +
" Rank:" + rank + " MOP: " + mop + " DTSN: " + dtsn);
verbose.append(" InstanceID: " + instanceID
+ " Version: " + version
+ " Rank:" + rank
+ " MOP: " + mop
+ " DTSN: " + dtsn);
packet.consumeBytesStart(8);
break;

View file

@ -19,23 +19,22 @@ public class IEEE802154Analyzer extends PacketAnalyzer {
public static final int CMDFRAME = 0x03;
// 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 PcapExporter pcapExporter;
// private int defaultAddressMode = LONG_ADDRESS;
// private byte seqNo = 0;
// private int myPanID = 0xabcd;
public IEEE802154Analyzer(boolean pcap) {
if (pcap) try {
if (pcap) {
try {
pcapExporter = new PcapExporter();
} catch (IOException e) {
e.printStackTrace();
}
}
}
public void setPcapFile(File pcapFile) {
if (pcapExporter != null) {
@ -59,6 +58,7 @@ public class IEEE802154Analyzer extends PacketAnalyzer {
/* create a 802.15.4 packet of the bytes and "dispatch" to the
* next handler
*/
public int analyzePacket(Packet packet, StringBuffer brief, StringBuffer verbose) {
if (pcapExporter != null) {
@ -75,7 +75,7 @@ public class IEEE802154Analyzer extends PacketAnalyzer {
// 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 panCompression = (packet.data[pos + 0] >> 6) & 1;
int destAddrMode = (packet.data[pos + 1] >> 2) & 3;
// int frameVersion = (packet.data[pos + 1] >> 4) & 3;
int srcAddrMode = (packet.data[pos + 1] >> 6) & 3;
@ -105,7 +105,7 @@ public class IEEE802154Analyzer extends PacketAnalyzer {
}
if (srcAddrMode > 0) {
if (panCompression == 0){
if (panCompression == 0) {
srcPanID = (packet.data[pos] & 0xff) + ((packet.data[pos + 1] & 0xff) << 8);
pos += 2;
} else {
@ -126,7 +126,6 @@ public class IEEE802154Analyzer extends PacketAnalyzer {
}
// int payloadLen = packet.data.length - pos;
brief.append("15.4 ");
brief.append(type < typeS.length ? typeS[type] : "?").append(' ');
@ -140,15 +139,15 @@ public class IEEE802154Analyzer extends PacketAnalyzer {
verbose.append("</b><br>From ");
if (srcPanID != 0) {
verbose.append(StringUtils.toHex((byte)(srcPanID >> 8)))
.append(StringUtils.toHex((byte)(srcPanID & 0xff)))
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)))
verbose.append(StringUtils.toHex((byte) (destPanID >> 8)))
.append(StringUtils.toHex((byte) (destPanID & 0xff)))
.append('/');
}
printAddress(verbose, destAddrMode, destAddress);
@ -172,10 +171,10 @@ public class IEEE802154Analyzer extends PacketAnalyzer {
if (type == SHORT_ADDRESS) {
sb.append(StringUtils.toHex(addr));
} else if (type == LONG_ADDRESS) {
sb.append(StringUtils.toHex(addr[0]) + StringUtils.toHex(addr[1]) + ":" +
StringUtils.toHex(addr[2]) + StringUtils.toHex(addr[3]) + ":" +
StringUtils.toHex(addr[4]) + StringUtils.toHex(addr[5]) + ":" +
StringUtils.toHex(addr[6]) + StringUtils.toHex(addr[7]));
sb.append(StringUtils.toHex(addr[0]) + StringUtils.toHex(addr[1]) + ":"
+ StringUtils.toHex(addr[2]) + StringUtils.toHex(addr[3]) + ":"
+ StringUtils.toHex(addr[4]) + StringUtils.toHex(addr[5]) + ":"
+ StringUtils.toHex(addr[6]) + StringUtils.toHex(addr[7]));
}
}
}

View file

@ -51,12 +51,11 @@ public class IPHCPacketAnalyzer extends PacketAnalyzer {
public final static int PROTO_TCP = 6;
public final static int PROTO_ICMP = 58;
public final static byte[] UNSPECIFIED_ADDRESS
= {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
public final static byte[] UNSPECIFIED_ADDRESS =
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
private static byte[][] addrContexts = new byte[][] {
{(byte)0xaa, (byte)0xaa, 0, 0, 0, 0, 0, 0}
private static byte[][] addrContexts = new byte[][]{
{(byte) 0xaa, (byte) 0xaa, 0, 0, 0, 0, 0, 0}
};
private static final int IPHC_DISPATCH = 0x60;
@ -89,7 +88,6 @@ public class IPHCPacketAnalyzer extends PacketAnalyzer {
brief.append("IPHC");
/* need to decompress while analyzing - add that later... */
verbose.append("<b>IPHC HC-06</b><br>");
verbose.append("tf = " + tf + " nhc = " + nhc + " hlim = " + hlim
+ " cid = " + cid + " sac = " + sac + " sam = " + sam
@ -115,12 +113,11 @@ public class IPHCPacketAnalyzer extends PacketAnalyzer {
int srcPort = 0;
int destPort = 0;
try {
/* Traffic class and flow label */
if((packet.get(0) & SICSLOWPAN_IPHC_FL_C) == 0) {
if ((packet.get(0) & SICSLOWPAN_IPHC_FL_C) == 0) {
/* Flow label are carried inline */
if((packet.get(0) & SICSLOWPAN_IPHC_TC_C) == 0) {
if ((packet.get(0) & SICSLOWPAN_IPHC_TC_C) == 0) {
/* Traffic class is carried inline */
flowLabel = packet.getInt(hc06_ptr + 1, 3);
int tmp = packet.get(hc06_ptr);
@ -138,23 +135,23 @@ public class IPHCPacketAnalyzer extends PacketAnalyzer {
} else {
/* Version is always 6! */
/* Version and flow label are compressed */
if((packet.get(0) & SICSLOWPAN_IPHC_TC_C) == 0) {
if ((packet.get(0) & SICSLOWPAN_IPHC_TC_C) == 0) {
/* Traffic class is inline */
trafficClass =((packet.get(hc06_ptr) >> 6) & 0x03);
trafficClass = ((packet.get(hc06_ptr) >> 6) & 0x03);
trafficClass |= (packet.get(hc06_ptr) << 2);
hc06_ptr += 1;
}
}
/* Next Header */
if((packet.get(0) & SICSLOWPAN_IPHC_NH_C) == 0) {
if ((packet.get(0) & SICSLOWPAN_IPHC_NH_C) == 0) {
/* Next header is carried inline */
proto = packet.get(hc06_ptr);
hc06_ptr += 1;
}
/* Hop limit */
switch(packet.get(0) & 0x03) {
switch (packet.get(0) & 0x03) {
case SICSLOWPAN_IPHC_TTL_1:
ttl = 1;
break;
@ -171,20 +168,21 @@ public class IPHCPacketAnalyzer extends PacketAnalyzer {
}
/* context based compression */
if((packet.get(1) & SICSLOWPAN_IPHC_SAC) > 0) {
if ((packet.get(1) & SICSLOWPAN_IPHC_SAC) > 0) {
/* Source address */
byte[] context = null;
if((packet.get(1) & SICSLOWPAN_IPHC_SAM_11) != SICSLOWPAN_IPHC_SAM_00) {
if ((packet.get(1) & SICSLOWPAN_IPHC_SAM_11) != SICSLOWPAN_IPHC_SAM_00) {
context = addrContexts[sci];
}
switch(packet.get(1) & SICSLOWPAN_IPHC_SAM_11) {
switch (packet.get(1) & SICSLOWPAN_IPHC_SAM_11) {
case SICSLOWPAN_IPHC_SAM_00:
/* copy the unspecificed address */
srcAddress = UNSPECIFIED_ADDRESS;
break;
case SICSLOWPAN_IPHC_SAM_01: /* 64 bits */
/* copy prefix from context */
System.arraycopy(context, 0, srcAddress, 0, 8);
/* copy IID from packet */
packet.copy(hc06_ptr, srcAddress, 8, 8);
@ -192,6 +190,7 @@ public class IPHCPacketAnalyzer extends PacketAnalyzer {
break;
case SICSLOWPAN_IPHC_SAM_10: /* 16 bits */
/* unicast address */
System.arraycopy(context, 0, srcAddress, 0, 8);
/* copy 6 NULL bytes then 2 last bytes of IID */
packet.copy(hc06_ptr, srcAddress, 14, 2);
@ -199,6 +198,7 @@ public class IPHCPacketAnalyzer extends PacketAnalyzer {
break;
case SICSLOWPAN_IPHC_SAM_11: /* 0-bits */
/* copy prefix from context */
System.arraycopy(context, 0, srcAddress, 0, 8);
/* infer IID from L2 address */
System.arraycopy(packet.llsender, 0, srcAddress,
@ -208,13 +208,15 @@ public class IPHCPacketAnalyzer extends PacketAnalyzer {
/* end context based compression */
} else {
/* no compression and link local */
switch(packet.get(1) & SICSLOWPAN_IPHC_SAM_11) {
switch (packet.get(1) & SICSLOWPAN_IPHC_SAM_11) {
case SICSLOWPAN_IPHC_SAM_00: /* 128 bits */
/* copy whole address from packet */
packet.copy(hc06_ptr, srcAddress, 0, 16);
hc06_ptr += 16;
break;
case SICSLOWPAN_IPHC_SAM_01: /* 64 bits */
srcAddress[0] = (byte) 0xfe;
srcAddress[1] = (byte) 0x80;
/* copy IID from packet */
@ -222,6 +224,7 @@ public class IPHCPacketAnalyzer extends PacketAnalyzer {
hc06_ptr += 8;
break;
case SICSLOWPAN_IPHC_SAM_10: /* 16 bits */
srcAddress[0] = (byte) 0xfe;
srcAddress[1] = (byte) 0x80;
packet.copy(hc06_ptr, srcAddress, 14, 2);
@ -229,6 +232,7 @@ public class IPHCPacketAnalyzer extends PacketAnalyzer {
break;
case SICSLOWPAN_IPHC_SAM_11: /* 0 bits */
/* setup link-local address */
srcAddress[0] = (byte) 0xfe;
srcAddress[1] = (byte) 0x80;
/* infer IID from L2 address */
@ -241,31 +245,35 @@ public class IPHCPacketAnalyzer extends PacketAnalyzer {
/* Destination address */
/* multicast compression */
if((packet.get(1) & SICSLOWPAN_IPHC_M) != 0) {
if ((packet.get(1) & SICSLOWPAN_IPHC_M) != 0) {
/* context based multicast compression */
if((packet.get(1) & SICSLOWPAN_IPHC_DAC) != 0) {
if ((packet.get(1) & SICSLOWPAN_IPHC_DAC) != 0) {
/* TODO: implement this */
} else {
/* non-context based multicast compression */
switch (packet.get(1) & SICSLOWPAN_IPHC_DAM_11) {
case SICSLOWPAN_IPHC_DAM_00: /* 128 bits */
/* copy whole address from packet */
packet.copy(hc06_ptr, destAddress, 0, 16);
hc06_ptr += 16;
break;
case SICSLOWPAN_IPHC_DAM_01: /* 48 bits FFXX::00XX:XXXX:XXXX */
destAddress[0] = (byte) 0xff;
destAddress[1] = packet.get(hc06_ptr);
packet.copy(hc06_ptr + 1, destAddress, 11, 5);
hc06_ptr += 6;
break;
case SICSLOWPAN_IPHC_DAM_10: /* 32 bits FFXX::00XX:XXXX */
destAddress[0] = (byte) 0xff;
destAddress[1] = packet.get(hc06_ptr);
packet.copy(hc06_ptr + 1, destAddress, 13, 3);
hc06_ptr += 4;
break;
case SICSLOWPAN_IPHC_DAM_11: /* 8 bits FF02::00XX */
destAddress[0] = (byte) 0xff;
destAddress[1] = (byte) 0x02;
destAddress[15] = packet.get(hc06_ptr);
@ -276,11 +284,12 @@ public class IPHCPacketAnalyzer extends PacketAnalyzer {
} else {
/* no multicast */
/* Context based */
if((packet.get(1) & SICSLOWPAN_IPHC_DAC) != 0) {
if ((packet.get(1) & SICSLOWPAN_IPHC_DAC) != 0) {
byte[] context = addrContexts[dci];
switch (packet.get(1) & SICSLOWPAN_IPHC_DAM_11) {
case SICSLOWPAN_IPHC_DAM_01: /* 64 bits */
System.arraycopy(context, 0, destAddress, 0, 8);
/* copy IID from packet */
packet.copy(hc06_ptr, destAddress, 8, 8);
@ -288,6 +297,7 @@ public class IPHCPacketAnalyzer extends PacketAnalyzer {
break;
case SICSLOWPAN_IPHC_DAM_10: /* 16 bits */
/* unicast address */
System.arraycopy(context, 0, destAddress, 0, 8);
/* copy IID from packet */
packet.copy(hc06_ptr, destAddress, 14, 2);
@ -295,6 +305,7 @@ public class IPHCPacketAnalyzer extends PacketAnalyzer {
break;
case SICSLOWPAN_IPHC_DAM_11: /* 0 bits */
/* unicast address */
System.arraycopy(context, 0, destAddress, 0, 8);
/* infer IID from L2 address */
System.arraycopy(packet.llreceiver, 0, destAddress,
@ -305,22 +316,26 @@ public class IPHCPacketAnalyzer extends PacketAnalyzer {
/* not context based => link local M = 0, DAC = 0 - same as SAC */
switch (packet.get(1) & SICSLOWPAN_IPHC_DAM_11) {
case SICSLOWPAN_IPHC_DAM_00: /* 128 bits */
packet.copy(hc06_ptr, destAddress, 0, 16);
hc06_ptr += 16;
break;
case SICSLOWPAN_IPHC_DAM_01: /* 64 bits */
destAddress[0] = (byte) 0xfe;
destAddress[1] = (byte) 0x80;
packet.copy(hc06_ptr, destAddress, 8, 8);
hc06_ptr += 8;
break;
case SICSLOWPAN_IPHC_DAM_10: /* 16 bits */
destAddress[0] = (byte) 0xfe;
destAddress[1] = (byte) 0x80;
packet.copy(hc06_ptr, destAddress, 14, 2);
hc06_ptr += 2;
break;
case SICSLOWPAN_IPHC_DAM_11: /* 0 bits */
destAddress[0] = (byte) 0xfe;
destAddress[1] = (byte) 0x80;
System.arraycopy(packet.llreceiver, 0, destAddress,
@ -331,12 +346,12 @@ public class IPHCPacketAnalyzer extends PacketAnalyzer {
}
/* Next header processing - continued */
if(nhc) {
if (nhc) {
/* TODO: check if this is correct in hc-06 */
/* The next header is compressed, NHC is following */
if((packet.get(hc06_ptr) & SICSLOWPAN_NDC_UDP_MASK) == SICSLOWPAN_NHC_UDP_ID) {
if ((packet.get(hc06_ptr) & SICSLOWPAN_NDC_UDP_MASK) == SICSLOWPAN_NHC_UDP_ID) {
proto = PROTO_UDP;
switch(packet.get(hc06_ptr)) {
switch (packet.get(hc06_ptr)) {
case (byte) SICSLOWPAN_NHC_UDP_C:
/* 1 byte for NHC, 1 byte for ports, 2 bytes chksum */
srcPort = SICSLOWPAN_UDP_PORT_MIN + (packet.get(hc06_ptr + 1) >> 4);
@ -363,7 +378,6 @@ public class IPHCPacketAnalyzer extends PacketAnalyzer {
}
}
// /* IP length field. */
// if(ip_len == 0) {
// /* This is not a fragmented packet */
@ -374,14 +388,12 @@ public class IPHCPacketAnalyzer extends PacketAnalyzer {
// SICSLOWPAN_IP_BUF->len[0] = (ip_len - UIP_IPH_LEN) >> 8;
// SICSLOWPAN_IP_BUF->len[1] = (ip_len - UIP_IPH_LEN) & 0x00FF;
// }
// /* length field in UDP header */
// if(SICSLOWPAN_IP_BUF->proto == UIP_PROTO_UDP) {
// memcpy(&SICSLOWPAN_UDP_BUF->udplen, ipBuf + len[0], 2);
// }
/*--------------------------------------------- */
} catch (Exception e) {
// some kind of unexpected error...
error = " error during IPHC parsing: " + e.getMessage();
@ -391,11 +403,15 @@ public class IPHCPacketAnalyzer extends PacketAnalyzer {
String protoStr = "" + proto;
if (proto == PROTO_ICMP) {
protoStr = "ICMPv6";
} else if (proto == PROTO_UDP) protoStr = "UDP";
else if (proto == PROTO_TCP) protoStr = "TCP";
} else if (proto == PROTO_UDP) {
protoStr = "UDP";
} else if (proto == PROTO_TCP) {
protoStr = "TCP";
}
verbose.append("<br><b>IPv6 ").append(protoStr).append("</b> TC = " + trafficClass +
" FL: " + flowLabel + "<br>");
verbose.append("<br><b>IPv6 ").append(protoStr)
.append("</b> TC = " + trafficClass
+ " FL: " + flowLabel + "<br>");
verbose.append("From ");
printAddress(verbose, srcAddress);
verbose.append(" to ");
@ -403,8 +419,8 @@ public class IPHCPacketAnalyzer extends PacketAnalyzer {
if (error != null) verbose.append(" " + error);
packet.lastDispatch = (byte) (proto & 0xff);
if (proto == PROTO_UDP || proto == PROTO_ICMP ||
proto == PROTO_TCP) {
if (proto == PROTO_UDP || proto == PROTO_ICMP
|| proto == PROTO_TCP) {
packet.level = APPLICATION_LEVEL;
return ANALYSIS_OK_CONTINUE;
} else {
@ -414,14 +430,12 @@ public class IPHCPacketAnalyzer extends PacketAnalyzer {
}
public static void printAddress(StringBuffer out, byte[] address) {
for (int i = 0; i < 16; i+=2) {
out.append(StringUtils.toHex((byte) (address[i] & 0xff)) +
StringUtils.toHex((byte) (address[i + 1] & 0xff)));
for (int i = 0; i < 16; i += 2) {
out.append(StringUtils.toHex((byte) (address[i] & 0xff))
+ StringUtils.toHex((byte) (address[i + 1] & 0xff)));
if (i < 14) {
out.append(":");
}
}
}
}

View file

@ -4,14 +4,12 @@ import org.contikios.cooja.util.StringUtils;
public class IPv6PacketAnalyzer extends PacketAnalyzer {
public final static int PROTO_UDP = 17;
public final static int PROTO_TCP = 6;
public final static int PROTO_ICMP = 58;
public final static byte[] UNSPECIFIED_ADDRESS =
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
public final static byte[] UNSPECIFIED_ADDRESS
= {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
private static final int IPV6_DISPATCH = 0x41;
@ -25,11 +23,9 @@ public class IPv6PacketAnalyzer extends PacketAnalyzer {
/* if packet has less than 40 bytes it is not interesting ... */
if (packet.size() < 40) return ANALYSIS_FAILED;
brief.append("IPv6");
/* need to decompress while analyzing - add that later... */
verbose.append("<b>IPv6</b><br>");
int pos = 1;
@ -49,14 +45,18 @@ public class IPv6PacketAnalyzer extends PacketAnalyzer {
String protoStr = "" + proto;
if (proto == PROTO_ICMP) {
protoStr = "ICMPv6";
} else if (proto == PROTO_UDP) protoStr = "UDP";
else if (proto == PROTO_TCP) protoStr = "TCP";
} else if (proto == PROTO_UDP) {
protoStr = "UDP";
} else if (proto == PROTO_TCP) {
protoStr = "TCP";
}
/* consume dispatch + IP header */
packet.pos += 41;
verbose.append("<br><b>IPv6 ").append(protoStr).append("</b> TC = " + trafficClass +
" FL: " + flowLabel + "<br>");
verbose.append("<br><b>IPv6 ").append(protoStr)
.append("</b> TC = " + trafficClass
+ " FL: " + flowLabel + "<br>");
verbose.append("From ");
printAddress(verbose, srcAddress);
verbose.append(" to ");
@ -68,14 +68,13 @@ public class IPv6PacketAnalyzer extends PacketAnalyzer {
}
public static void printAddress(StringBuffer out, byte[] address) {
for (int i = 0; i < 16; i+=2) {
out.append(StringUtils.toHex((byte) (address[i] & 0xff)) +
StringUtils.toHex((byte) (address[i + 1] & 0xff)));
for (int i = 0; i < 16; i += 2) {
out.append(StringUtils.toHex((byte) (address[i] & 0xff))
+ StringUtils.toHex((byte) (address[i + 1] & 0xff)));
if (i < 14) {
out.append(":");
}
}
}
}

View file

@ -12,6 +12,7 @@ public abstract class PacketAnalyzer {
public static final int APPLICATION_LEVEL = 3;
public static class Packet {
byte[] data;
int pos;
int level;
@ -30,7 +31,6 @@ public abstract class PacketAnalyzer {
this.size = data.length;
}
public void consumeBytesStart(int bytes) {
pos += bytes;
}
@ -39,7 +39,6 @@ public abstract class PacketAnalyzer {
size -= bytes;
}
public boolean hasMoreData() {
return size > pos;
}
@ -61,7 +60,6 @@ public abstract class PacketAnalyzer {
return value;
}
public byte[] getPayload() {
byte[] pload = new byte[size - pos];
System.arraycopy(data, pos, pload, 0, pload.length);

View file

@ -15,10 +15,10 @@ public class PcapExporter {
}
public void openPcap(File pcapFile) throws IOException {
if ( out != null ) {
if (out != null) {
closePcap();
}
if ( pcapFile == null ) {
if (pcapFile == null) {
/* pcap file not specified, use default file name */
pcapFile = new File("radiolog-" + System.currentTimeMillis() + ".pcap");
}
@ -31,9 +31,11 @@ public class PcapExporter {
out.writeInt(0);
out.writeInt(4096);
out.writeInt(195); /* 195 for LINKTYPE_IEEE802_15_4 */
out.flush();
System.out.println("Opened pcap file " + pcapFile);
}
public void closePcap() throws IOException {
out.close();
out = null;
@ -58,6 +60,4 @@ public class PcapExporter {
}
}
}