From 3e9a7807210cf9e31a276f3dfc04364f1d12fb6c Mon Sep 17 00:00:00 2001 From: Enrico Joerns Date: Fri, 11 Jul 2014 02:07:21 +0200 Subject: [PATCH 01/12] [cooja] plugins/analyzers: Indention and whitespace cleanups --- .../contikios/cooja/plugins/RadioLogger.java | 431 +++++------ .../plugins/analyzers/ICMPv6Analyzer.java | 172 +++-- .../plugins/analyzers/IEEE802154Analyzer.java | 281 ++++--- .../plugins/analyzers/IPHCPacketAnalyzer.java | 728 +++++++++--------- .../plugins/analyzers/IPv6PacketAnalyzer.java | 129 ++-- .../plugins/analyzers/PacketAnalyzer.java | 150 ++-- .../cooja/plugins/analyzers/PcapExporter.java | 98 +-- 7 files changed, 1001 insertions(+), 988 deletions(-) diff --git a/tools/cooja/java/org/contikios/cooja/plugins/RadioLogger.java b/tools/cooja/java/org/contikios/cooja/plugins/RadioLogger.java index f73a4af8c..2205f1c68 100644 --- a/tools/cooja/java/org/contikios/cooja/plugins/RadioLogger.java +++ b/tools/cooja/java/org/contikios/cooja/plugins/RadioLogger.java @@ -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 analyzerMap = new HashMap(); + private HashMap analyzerMap = new HashMap(); private String analyzerName = null; private ArrayList 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 - "" + - "Start time (us): " + conn.startTime + - "
" + - "End time (us): " + conn.endTime + - "

" + - "Duration (us): " + (conn.endTime - conn.startTime) + - ""; + return "" + + "Start time (us): " + conn.startTime + + "
" + + "End time (us): " + conn.endTime + + "

" + + "Duration (us): " + (conn.endTime - conn.startTime) + + ""; } else if (modelColumnIndex == COLUMN_FROM) { return conn.connection.getSource().getMote().toString(); } else if (modelColumnIndex == COLUMN_TO) { @@ -337,7 +336,7 @@ public class RadioLogger extends VisPlugin { } formatTimeString = !formatTimeString; dataTable.getColumnModel().getColumn(COLUMN_TIME).setHeaderValue( - dataTable.getModel().getColumnName(COLUMN_TIME)); + dataTable.getModel().getColumnName(COLUMN_TIME)); repaint(); } }); @@ -346,16 +345,16 @@ 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) { - searchField.setVisible(true); - searchField.requestFocus(); - searchField.selectAll(); - revalidate(); + } else if (e.getKeyCode() == KeyEvent.VK_F + && (e.getModifiers() & KeyEvent.CTRL_MASK) != 0) { + searchField.setVisible(true); + searchField.requestFocus(); + searchField.selectAll(); + revalidate(); } else if (e.getKeyCode() == KeyEvent.VK_ESCAPE) { - searchField.setVisible(false); - dataTable.requestFocus(); - revalidate(); + searchField.setVisible(false); + dataTable.requestFocus(); + revalidate(); } } }); @@ -367,21 +366,21 @@ public class RadioLogger extends VisPlugin { dataTable.setRowSorter(logFilter); dataTable.getSelectionModel().addListSelectionListener(new ListSelectionListener() { - public void valueChanged(ListSelectionEvent e) { - int row = dataTable.getSelectedRow(); - if (row < 0) { - return; - } - int modelRowIndex = dataTable.convertRowIndexToModel(row); - if (modelRowIndex >= 0) { - RadioConnectionLog conn = connections.get(modelRowIndex); - if (conn.tooltip == null) { - prepareTooltipString(conn); - } - verboseBox.setText(conn.tooltip); - verboseBox.setCaretPosition(0); - } + public void valueChanged(ListSelectionEvent e) { + int row = dataTable.getSelectedRow(); + if (row < 0) { + return; } + int modelRowIndex = dataTable.convertRowIndexToModel(row); + if (modelRowIndex >= 0) { + RadioConnectionLog conn = connections.get(modelRowIndex); + if (conn.tooltip == null) { + prepareTooltipString(conn); + } + verboseBox.setText(conn.tooltip); + verboseBox.setCaretPosition(0); + } + } }); // Set data column width greedy dataTable.setAutoResizeMode(JTable.AUTO_RESIZE_LAST_COLUMN); @@ -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)); @@ -426,7 +423,7 @@ public class RadioLogger extends VisPlugin { analyzerMenu.add(rbMenuItem); rbMenuItem = new JRadioButtonMenuItem(createAnalyzerAction( - "6LoWPAN Analyzer", "6lowpan", lowpanAnalyzers, false)); + "6LoWPAN Analyzer", "6lowpan", lowpanAnalyzers, false)); group.add(rbMenuItem); analyzerMenu.add(rbMenuItem); @@ -436,20 +433,20 @@ 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 suiteClass = - gui.tryLoadClass(RadioLogger.this, RadioLoggerAnalyzerSuite.class, suiteName); + Class suiteClass + = gui.tryLoadClass(RadioLogger.this, RadioLoggerAnalyzerSuite.class, suiteName); try { RadioLoggerAnalyzerSuite suite = suiteClass.newInstance(); ArrayList suiteAnalyzers = suite.getAnalyzers(); rbMenuItem = new JRadioButtonMenuItem(createAnalyzerAction( - suite.getDescription(), suiteName, suiteAnalyzers, false)); + suite.getDescription(), suiteName, suiteAnalyzers, false)); group.add(rbMenuItem); analyzerMenu.add(rbMenuItem); logger.debug("Loaded radio logger analyzers: " + suite.getDescription()); @@ -473,20 +470,20 @@ public class RadioLogger extends VisPlugin { searchField.setVisible(false); searchField.addKeyListener(new KeyAdapter() { public void keyPressed(KeyEvent e) { - if (e.getKeyCode() == KeyEvent.VK_ENTER) { - searchSelectNext( - searchField.getText(), - (e.getModifiers() & KeyEvent.SHIFT_MASK) != 0); - } else if (e.getKeyCode() == KeyEvent.VK_ESCAPE) { - searchField.setVisible(false); - dataTable.requestFocus(); - revalidate(); + if (e.getKeyCode() == KeyEvent.VK_ENTER) { + searchSelectNext( + searchField.getText(), + (e.getModifiers() & KeyEvent.SHIFT_MASK) != 0); + } else if (e.getKeyCode() == KeyEvent.VK_ESCAPE) { + searchField.setVisible(false); + dataTable.requestFocus(); + revalidate(); } } }); splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT, - new JScrollPane(dataTable), new JScrollPane(verboseBox)); + new JScrollPane(dataTable), new JScrollPane(verboseBox)); splitPane.setOneTouchExpandable(true); splitPane.setDividerLocation(150); add(BorderLayout.NORTH, searchField); @@ -528,8 +525,8 @@ public class RadioLogger extends VisPlugin { setTitle("Radio messages: showing " + dataTable.getRowCount() + "/" + connections.size() + " packets"); } }); - } - }); + } + }); setSize(500, 300); try { @@ -543,41 +540,41 @@ public class RadioLogger extends VisPlugin { super.startPlugin(); rebuildAllEntries(); } - - private void searchSelectNext(String text, boolean reverse) { - if (text.isEmpty()) { - return; - } - int row = dataTable.getSelectedRow(); + + private void searchSelectNext(String text, boolean reverse) { + if (text.isEmpty()) { + return; + } + int row = dataTable.getSelectedRow(); if (row < 0) { - row = 0; + row = 0; } if (!reverse) { - row++; + row++; } else { - row--; + row--; } int rows = dataTable.getModel().getRowCount(); - for (int i=0; i < rows; i++) { - int r; - if (!reverse) { - r = (row + i + rows)%rows; - } else { - r = (row - i + rows)%rows; - } - String val = (String) dataTable.getModel().getValueAt(r, COLUMN_DATA); - if (!val.contains(text)) { - continue; - } - dataTable.setRowSelectionInterval(r,r); - dataTable.scrollRectToVisible(dataTable.getCellRect(r, COLUMN_DATA, true)); - searchField.setBackground(Color.WHITE); - return; + for (int i = 0; i < rows; i++) { + int r; + if (!reverse) { + r = (row + i + rows) % rows; + } else { + r = (row - i + rows) % rows; + } + String val = (String) dataTable.getModel().getValueAt(r, COLUMN_DATA); + if (!val.contains(text)) { + continue; + } + dataTable.setRowSelectionInterval(r, r); + dataTable.scrollRectToVisible(dataTable.getCellRect(r, COLUMN_DATA, true)); + searchField.setBackground(Color.WHITE); + return; } - searchField.setBackground(Color.RED); - } + searchField.setBackground(Color.RED); + } /** * Selects a logged radio packet close to the given time. @@ -590,29 +587,29 @@ 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; } - + dataTable.scrollRectToVisible(dataTable.getCellRect(ai, 0, true)); 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; conn.hiddenBy = null; - } + } try { logFilter.setRowFilter(null); @@ -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(); } @@ -677,56 +674,56 @@ public class RadioLogger extends VisPlugin { PacketAnalyzer.Packet packet = new PacketAnalyzer.Packet(data, PacketAnalyzer.MAC_LEVEL); if (analyzePacket(packet, brief, verbose)) { - if (packet.hasMoreData()) { - byte[] payload = packet.getPayload(); - brief.append(StringUtils.toHex(payload, 4)); - if (verbose.length() > 0) { - verbose.append("

"); - } - verbose.append("Payload (") - .append(payload.length).append(" bytes)

")
-            .append(StringUtils.hexDump(payload))
-            .append("
"); - } - conn.data = (data.length < 100 ? (data.length < 10 ? " " : " ") : "") - + data.length + ": " + brief; + if (packet.hasMoreData()) { + byte[] payload = packet.getPayload(); + brief.append(StringUtils.toHex(payload, 4)); if (verbose.length() > 0) { - conn.tooltip = verbose.toString(); + verbose.append("

"); } + verbose.append("Payload (") + .append(payload.length).append(" bytes)

")
+                .append(StringUtils.hexDump(payload))
+                .append("
"); + } + conn.data = (data.length < 100 ? (data.length < 10 ? " " : " ") : "") + + data.length + ": " + brief; + if (verbose.length() > 0) { + conn.tooltip = verbose.toString(); + } } else { - conn.data = data.length + ": 0x" + StringUtils.toHex(data, 4); + conn.data = data.length + ": 0x" + StringUtils.toHex(data, 4); } } private boolean analyzePacket(PacketAnalyzer.Packet packet, StringBuffer brief, StringBuffer verbose) { - if (analyzers == null) return false; - try { - boolean analyze = true; - while (analyze) { - analyze = false; - for (int i = 0; i < analyzers.size(); i++) { - PacketAnalyzer analyzer = analyzers.get(i); - if (analyzer.matchPacket(packet)) { - int res = analyzer.analyzePacket(packet, brief, verbose); - if (packet.hasMoreData() && brief.length() > 0) { - brief.append('|'); - verbose.append("
"); - } - if (res != PacketAnalyzer.ANALYSIS_OK_CONTINUE) { - /* this was the final or the analysis failed - no analyzable payload possible here... */ - return brief.length() > 0; - } - /* continue another round if more bytes left */ - analyze = packet.hasMoreData(); - break; - } + if (analyzers == null) return false; + try { + boolean analyze = true; + while (analyze) { + analyze = false; + for (int i = 0; i < analyzers.size(); i++) { + PacketAnalyzer analyzer = analyzers.get(i); + if (analyzer.matchPacket(packet)) { + int res = analyzer.analyzePacket(packet, brief, verbose); + if (packet.hasMoreData() && brief.length() > 0) { + brief.append('|'); + verbose.append("
"); + } + if (res != PacketAnalyzer.ANALYSIS_OK_CONTINUE) { + /* this was the final or the analysis failed - no analyzable payload possible here... */ + return brief.length() > 0; + } + /* continue another round if more bytes left */ + analyze = packet.hasMoreData(); + break; } + } } - } catch (Exception e) { - logger.debug("Error when analyzing packet: " + e.getMessage(), e); - return false; - } - return brief.length() > 0; + } catch (Exception e) { + logger.debug("Error when analyzing packet: " + e.getMessage(), e); + return false; + } + return brief.length() > 0; } private void prepareTooltipString(RadioConnectionLog conn) { @@ -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 = "" + - "Packet data (" + original.length + " bytes)
" + - "
" + StringUtils.hexDump(original) + "
" + - "
" + - "Cross-level packet data (" + converted.length + " bytes)
" + - "
" + StringUtils.hexDump(converted) + "
" + - "
"; + byte[] original = ((ConvertedRadioPacket) packet).getOriginalPacketData(); + byte[] converted = ((ConvertedRadioPacket) packet).getPacketData(); + conn.tooltip = "" + + "Packet data (" + original.length + " bytes)
" + + "
" + StringUtils.hexDump(original) + "
" + + "
" + + "Cross-level packet data (" + converted.length + " bytes)
" + + "
" + StringUtils.hexDump(converted) + "
" + + "
"; } else if (packet instanceof ConvertedRadioPacket) { - byte[] original = ((ConvertedRadioPacket)packet).getOriginalPacketData(); - conn.tooltip = "" + - "Packet data (" + original.length + " bytes)
" + - "
" + StringUtils.hexDump(original) + "
" + - "
" + - "No cross-level conversion available
" + - "
"; + byte[] original = ((ConvertedRadioPacket) packet).getOriginalPacketData(); + conn.tooltip = "" + + "Packet data (" + original.length + " bytes)
" + + "
" + StringUtils.hexDump(original) + "
" + + "
" + + "No cross-level conversion available
" + + "
"; } else { byte[] data = packet.getPacketData(); - conn.tooltip = "" + - "Packet data (" + data.length + " bytes)
" + - "
" + StringUtils.hexDump(data) + "
" + - "
"; + conn.tooltip = "" + + "Packet data (" + data.length + " bytes)
" + + "
" + StringUtils.hexDump(data) + "
" + + "
"; } } @@ -784,7 +781,7 @@ public class RadioLogger extends VisPlugin { element = new Element("showdups"); element.addContent(Boolean.toString(showDuplicates)); config.add(element); - + element = new Element("hidenodests"); element.addContent(Boolean.toString(hideNoDestinationPackets)); config.add(element); @@ -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,11 +850,12 @@ public class RadioLogger extends VisPlugin { } private class RadioConnectionLog { + long startTime; long endTime; RadioConnection connection; RadioPacket packet; - + RadioConnectionLog hiddenBy = null; int hides = 0; @@ -865,14 +863,13 @@ public class RadioLogger extends VisPlugin { String tooltip = null; public String toString() { - if (data == null) { - RadioLogger.this.prepareDataString(this); - } - return - Long.toString(startTime / Simulation.MILLISECOND) + "\t" + - connection.getSource().getMote().getID() + "\t" + - getDestString(this) + "\t" + - data; + if (data == null) { + RadioLogger.this.prepareDataString(this); + } + return Long.toString(startTime / Simulation.MILLISECOND) + "\t" + + connection.getSource().getMote().getID() + "\t" + + getDestString(this) + "\t" + + data; } } @@ -888,13 +885,13 @@ 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(); } private void rebuildAllEntries() { applyFilter(); - + if (connections.size() > 0) { model.fireTableRowsUpdated(0, connections.size() - 1); } @@ -903,23 +900,23 @@ public class RadioLogger extends VisPlugin { setTitle("Radio messages: showing " + dataTable.getRowCount() + "/" + connections.size() + " packets"); simulation.getCooja().getDesktopPane().repaint(); } - - private Action createAnalyzerAction(String name, final String actionName, - final ArrayList analyzerList, boolean selected) { - Action action = new AbstractAction(name) { - private static final long serialVersionUID = -608913700422638454L; - public void actionPerformed(ActionEvent event) { - if (analyzers != analyzerList) { - analyzers = analyzerList; - analyzerName = actionName; - rebuildAllEntries(); - } + private Action createAnalyzerAction(String name, final String actionName, + final ArrayList analyzerList, boolean selected) { + Action action = new AbstractAction(name) { + private static final long serialVersionUID = -608913700422638454L; + + public void actionPerformed(ActionEvent event) { + if (analyzers != analyzerList) { + analyzers = analyzerList; + analyzerName = actionName; + rebuildAllEntries(); } - }; - action.putValue(Action.SELECTED_KEY, selected ? Boolean.TRUE : Boolean.FALSE); - analyzerMap.put(actionName, action); - return action; + } + }; + action.putValue(Action.SELECTED_KEY, selected ? Boolean.TRUE : Boolean.FALSE); + analyzerMap.put(actionName, action); + return action; } private Action clearAction = new AbstractAction("Clear") { @@ -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,12 +981,12 @@ 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?", - "Overwrite existing file?", JOptionPane.YES_NO_OPTION, - JOptionPane.QUESTION_MESSAGE, null, options, s1); + Cooja.getTopParentContainer(), + "A file with the same name already exists.\nDo you want to remove it?", + "Overwrite existing file?", JOptionPane.YES_NO_OPTION, + JOptionPane.QUESTION_MESSAGE, null, options, s1); if (n != JOptionPane.YES_OPTION) { return; } @@ -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; @@ -1026,12 +1024,12 @@ public class RadioLogger extends VisPlugin { Plugin[] plugins = simulation.getCooja().getStartedPlugins(); for (Plugin p: plugins) { - if (!(p instanceof TimeLine)) { - continue; - } + if (!(p instanceof TimeLine)) { + continue; + } /* Select simulation time */ - TimeLine plugin = (TimeLine) p; + TimeLine plugin = (TimeLine) p; plugin.trySelectTime(time); } } @@ -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; @@ -1049,12 +1048,12 @@ public class RadioLogger extends VisPlugin { Plugin[] plugins = simulation.getCooja().getStartedPlugins(); for (Plugin p: plugins) { - if (!(p instanceof LogListener)) { - continue; - } + if (!(p instanceof LogListener)) { + continue; + } /* Select simulation time */ - LogListener plugin = (LogListener) p; + LogListener plugin = (LogListener) p; plugin.trySelectTime(time); } } @@ -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)); + putValue(ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_SPACE, 0, true)); } + public void actionPerformed(ActionEvent e) { timeLineAction.actionPerformed(null); logListenerAction.actionPerformed(null); @@ -1087,15 +1088,15 @@ 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", - "Create packet payload alias", - JOptionPane.QUESTION_MESSAGE, - null, - null, - current); + 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", + "Create packet payload alias", + JOptionPane.QUESTION_MESSAGE, + null, + null, + current); if (alias == null) { /* Cancelled */ return; @@ -1141,16 +1142,16 @@ public class RadioLogger extends VisPlugin { }; public String getConnectionsString() { - StringBuilder sb = new StringBuilder(); - RadioConnectionLog[] cs = connections.toArray(new RadioConnectionLog[0]); - for(RadioConnectionLog c: cs) { + StringBuilder sb = new StringBuilder(); + RadioConnectionLog[] cs = connections.toArray(new RadioConnectionLog[0]); + for (RadioConnectionLog c : cs) { sb.append(c.toString() + "\n"); } return sb.toString(); - }; + } public void saveConnectionsToFile(String fileName) { StringUtils.saveToFile(new File(fileName), getConnectionsString()); - }; + } } diff --git a/tools/cooja/java/org/contikios/cooja/plugins/analyzers/ICMPv6Analyzer.java b/tools/cooja/java/org/contikios/cooja/plugins/analyzers/ICMPv6Analyzer.java index a8ea5e8b0..f1e3b0aa0 100644 --- a/tools/cooja/java/org/contikios/cooja/plugins/analyzers/ICMPv6Analyzer.java +++ b/tools/cooja/java/org/contikios/cooja/plugins/analyzers/ICMPv6Analyzer.java @@ -2,99 +2,101 @@ package org.contikios.cooja.plugins.analyzers; public class ICMPv6Analyzer extends PacketAnalyzer { - public static final byte ICMPv6_DISPATCH = 58; - - public static final int ECHO_REQUEST = 128; - public static final int ECHO_REPLY = 129; - public static final int GROUP_QUERY = 130; - public static final int GROUP_REPORT = 131; - public static final int GROUP_REDUCTION = 132; - public static final int ROUTER_SOLICITATION = 133; - public static final int ROUTER_ADVERTISEMENT = 134; - public static final int NEIGHBOR_SOLICITATION = 135; - public static final int NEIGHBOR_ADVERTISEMENT = 136; + public static final byte ICMPv6_DISPATCH = 58; - public static final int RPL_CODE_DIS = 0; /* DIS message */ - public static final int RPL_CODE_DIO = 1; /* DIO message */ - public static final int RPL_CODE_DAO = 2;/* DAO message */ - public static final int RPL_CODE_DAO_ACK = 3;/* DAO ACK message */ - - public static final int FLAG_ROUTER = 0x80; - public static final int FLAG_SOLICITED = 0x40; - public static final int FLAG_OVERRIDE = 0x20; + public static final int ECHO_REQUEST = 128; + public static final int ECHO_REPLY = 129; + public static final int GROUP_QUERY = 130; + public static final int GROUP_REPORT = 131; + public static final int GROUP_REDUCTION = 132; + public static final int ROUTER_SOLICITATION = 133; + public static final int ROUTER_ADVERTISEMENT = 134; + public static final int NEIGHBOR_SOLICITATION = 135; + public static final int NEIGHBOR_ADVERTISEMENT = 136; - public static final int ON_LINK = 0x80; - public static final int AUTOCONFIG = 0x40; + public static final int RPL_CODE_DIS = 0; /* DIS message */ + public static final int RPL_CODE_DIO = 1; /* DIO message */ + public static final int RPL_CODE_DAO = 2;/* DAO message */ + public static final int RPL_CODE_DAO_ACK = 3;/* DAO ACK message */ - public static final int SOURCE_LINKADDR = 1; - public static final int TARGET_LINKADDR = 2; - public static final int PREFIX_INFO = 3; - public static final int MTU_INFO = 5; - - 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 static final int FLAG_ROUTER = 0x80; + public static final int FLAG_SOLICITED = 0x40; + public static final int FLAG_OVERRIDE = 0x20; - - public int analyzePacket(Packet packet, StringBuffer brief, - StringBuffer verbose) { - int type = packet.get(0) & 0xff; - int code = packet.get(1) & 0xff; + public static final int ON_LINK = 0x80; + public static final int AUTOCONFIG = 0x40; + + public static final int SOURCE_LINKADDR = 1; + public static final int TARGET_LINKADDR = 2; + public static final int PREFIX_INFO = 3; + public static final int MTU_INFO = 5; + + 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; + int code = packet.get(1) & 0xff; // int checksum = ((packet.get(2) & 0xff) << 8) | packet.get(3) & 0xff; - brief.append("ICMPv6 "); - if (type >= 128 && (type - 128) < TYPE_NAME.length) { - brief.append(TYPE_NAME[type - 128]).append(' ').append(code); - verbose.append("Type: ").append(TYPE_NAME[type - 128]); - verbose.append(" Code:").append(code); - } else if (type == 155) { - /* RPL */ - brief.append("RPL "); - verbose.append("Type: RPL Code: "); - switch(code) { - case RPL_CODE_DIS: - brief.append("DIS"); - verbose.append("DIS"); - break; - case RPL_CODE_DIO: - brief.append("DIO"); - verbose.append("DIO
"); - - int instanceID = packet.get(4) & 0xff; - int version = packet.get(5) & 0xff; - int rank = ((packet.get(6) & 0xff) << 8) + (packet.get(7) & 0xff); - int mop = (packet.get(8) >> 3) & 0x07; - int dtsn = packet.get(9); - - verbose.append(" InstanceID: " + instanceID + " Version: " + version + - " Rank:" + rank + " MOP: " + mop + " DTSN: " + dtsn); - packet.consumeBytesStart(8); + brief.append("ICMPv6 "); + if (type >= 128 && (type - 128) < TYPE_NAME.length) { + brief.append(TYPE_NAME[type - 128]).append(' ').append(code); + verbose.append("Type: ").append(TYPE_NAME[type - 128]); + verbose.append(" Code:").append(code); + } else if (type == 155) { + /* RPL */ + brief.append("RPL "); + verbose.append("Type: RPL Code: "); + switch (code) { + case RPL_CODE_DIS: + brief.append("DIS"); + verbose.append("DIS"); + break; + case RPL_CODE_DIO: + brief.append("DIO"); + verbose.append("DIO
"); - break; - case RPL_CODE_DAO: - brief.append("DAO"); - verbose.append("DAO"); - break; - case RPL_CODE_DAO_ACK: - brief.append("DAO ACK"); - verbose.append("DAO ACK"); - break; - default: - brief.append(code); - verbose.append(code); - } - } + int instanceID = packet.get(4) & 0xff; + int version = packet.get(5) & 0xff; + int rank = ((packet.get(6) & 0xff) << 8) + (packet.get(7) & 0xff); + int mop = (packet.get(8) >> 3) & 0x07; + int dtsn = packet.get(9); - /* remove type, code, crc */ - packet.consumeBytesStart(4); - return ANALYSIS_OK_FINAL; + verbose.append(" InstanceID: " + instanceID + + " Version: " + version + + " Rank:" + rank + + " MOP: " + mop + + " DTSN: " + dtsn); + packet.consumeBytesStart(8); + + break; + case RPL_CODE_DAO: + brief.append("DAO"); + verbose.append("DAO"); + break; + case RPL_CODE_DAO_ACK: + brief.append("DAO ACK"); + verbose.append("DAO ACK"); + break; + default: + brief.append(code); + verbose.append(code); + } } - @Override - public boolean matchPacket(Packet packet) { - return packet.level == APPLICATION_LEVEL && packet.lastDispatch == ICMPv6_DISPATCH; - } + /* remove type, code, crc */ + packet.consumeBytesStart(4); + return ANALYSIS_OK_FINAL; + } + + @Override + public boolean matchPacket(Packet packet) { + return packet.level == APPLICATION_LEVEL && packet.lastDispatch == ICMPv6_DISPATCH; + } } diff --git a/tools/cooja/java/org/contikios/cooja/plugins/analyzers/IEEE802154Analyzer.java b/tools/cooja/java/org/contikios/cooja/plugins/analyzers/IEEE802154Analyzer.java index d15903d51..4175a2be4 100644 --- a/tools/cooja/java/org/contikios/cooja/plugins/analyzers/IEEE802154Analyzer.java +++ b/tools/cooja/java/org/contikios/cooja/plugins/analyzers/IEEE802154Analyzer.java @@ -7,175 +7,174 @@ import org.contikios.cooja.util.StringUtils; public class IEEE802154Analyzer extends PacketAnalyzer { - /* TODO: fix this to be correct */ - public static final int NO_ADDRESS = 0; - public static final int RSV_ADDRESS = 1; - public static final int SHORT_ADDRESS = 2; - public static final int LONG_ADDRESS = 3; + /* TODO: fix this to be correct */ + public static final int NO_ADDRESS = 0; + public static final int RSV_ADDRESS = 1; + public static final int SHORT_ADDRESS = 2; + public static final int LONG_ADDRESS = 3; - public static final int BEACONFRAME = 0x00; - public static final int DATAFRAME = 0x01; - public static final int ACKFRAME = 0x02; - public static final int CMDFRAME = 0x03; + public static final int BEACONFRAME = 0x00; + public static final int DATAFRAME = 0x01; + 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 String[] typeS = {"-", "D", "A"}; - private static final String[] typeVerbose = {"BEACON", "DATA", "ACK"}; - private PcapExporter pcapExporter; + 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 { - pcapExporter = new PcapExporter(); - } catch (IOException e) { - e.printStackTrace(); - } + public IEEE802154Analyzer(boolean pcap) { + if (pcap) { + try { + pcapExporter = new PcapExporter(); + } catch (IOException e) { + e.printStackTrace(); + } } + } - public void setPcapFile(File pcapFile) { - if (pcapExporter != null) { - try { - pcapExporter.openPcap(pcapFile); - } catch (IOException e) { - System.err.println("Could not open pcap file"); - e.printStackTrace(); - } + public void setPcapFile(File pcapFile) { + if (pcapExporter != null) { + try { + pcapExporter.openPcap(pcapFile); + } catch (IOException e) { + System.err.println("Could not open pcap file"); + e.printStackTrace(); + } + } + } + + public boolean matchPacket(Packet packet) { + return packet.level == MAC_LEVEL; + } + + /* this protocol always have network level packets as payload */ + public int nextLevel(byte[] packet, int level) { + return NETWORK_LEVEL; + } + /* 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) { + try { + pcapExporter.exportPacketData(packet.getPayload()); + } catch (IOException e) { + System.err.println("Could not export PCap data"); + e.printStackTrace(); } } - public boolean matchPacket(Packet packet) { - return packet.level == MAC_LEVEL; - } - - /* this protocol always have network level packets as payload */ - public int nextLevel(byte[] packet, int level) { - return NETWORK_LEVEL; - } - /* 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) { - try { - pcapExporter.exportPacketData(packet.getPayload()); - } catch (IOException e) { - System.err.println("Could not export PCap data"); - e.printStackTrace(); - } - } - - int pos = packet.pos; - int type = packet.data[pos + 0] & 7; + 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 panCompression = (packet.data[pos + 0]>> 6) & 1; - int destAddrMode = (packet.data[pos + 1] >> 2) & 3; + 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; - int seqNumber = packet.data[pos + 2] & 0xff; - int destPanID = 0; - int srcPanID = 0; - byte[] sourceAddress = null; - byte[] destAddress = null; + int srcAddrMode = (packet.data[pos + 1] >> 6) & 3; + int seqNumber = packet.data[pos + 2] & 0xff; + int destPanID = 0; + int srcPanID = 0; + byte[] sourceAddress = null; + byte[] destAddress = null; - pos += 3; + pos += 3; - if (destAddrMode > 0) { - destPanID = (packet.data[pos] & 0xff) + ((packet.data[pos + 1] & 0xff) << 8); - pos += 2; - if (destAddrMode == SHORT_ADDRESS) { - destAddress = new byte[2]; - destAddress[1] = packet.data[pos]; - destAddress[0] = packet.data[pos + 1]; - pos += 2; - } else if (destAddrMode == LONG_ADDRESS) { - destAddress = new byte[8]; - for (int i = 0; i < 8; i++) { - destAddress[i] = packet.data[pos + 7 - i]; - } - pos += 8; - } + if (destAddrMode > 0) { + destPanID = (packet.data[pos] & 0xff) + ((packet.data[pos + 1] & 0xff) << 8); + pos += 2; + if (destAddrMode == SHORT_ADDRESS) { + destAddress = new byte[2]; + destAddress[1] = packet.data[pos]; + destAddress[0] = packet.data[pos + 1]; + pos += 2; + } else if (destAddrMode == LONG_ADDRESS) { + destAddress = new byte[8]; + for (int i = 0; i < 8; i++) { + destAddress[i] = packet.data[pos + 7 - i]; } + pos += 8; + } + } - if (srcAddrMode > 0) { - if (panCompression == 0){ - srcPanID = (packet.data[pos] & 0xff) + ((packet.data[pos + 1] & 0xff) << 8); - pos += 2; - } else { - srcPanID = destPanID; - } - if (srcAddrMode == SHORT_ADDRESS) { - sourceAddress = new byte[2]; - sourceAddress[1] = packet.data[pos]; - sourceAddress[0] = packet.data[pos + 1]; - pos += 2; - } else if (srcAddrMode == LONG_ADDRESS) { - sourceAddress = new byte[8]; - for (int i = 0; i < 8; i++) { - sourceAddress[i] = packet.data[pos + 7 - i]; - } - pos += 8; - } + if (srcAddrMode > 0) { + if (panCompression == 0) { + srcPanID = (packet.data[pos] & 0xff) + ((packet.data[pos + 1] & 0xff) << 8); + pos += 2; + } else { + srcPanID = destPanID; + } + if (srcAddrMode == SHORT_ADDRESS) { + sourceAddress = new byte[2]; + sourceAddress[1] = packet.data[pos]; + sourceAddress[0] = packet.data[pos + 1]; + pos += 2; + } else if (srcAddrMode == LONG_ADDRESS) { + sourceAddress = new byte[8]; + for (int i = 0; i < 8; i++) { + sourceAddress[i] = packet.data[pos + 7 - i]; } + pos += 8; + } + } // int payloadLen = packet.data.length - pos; + brief.append("15.4 "); + brief.append(type < typeS.length ? typeS[type] : "?").append(' '); - brief.append("15.4 "); - brief.append(type < typeS.length ? typeS[type] : "?").append(' '); + verbose.append("IEEE 802.15.4 ") + .append(type < typeVerbose.length ? typeVerbose[type] : "?") + .append(' ').append(seqNumber); + if (type != ACKFRAME) { + printAddress(brief, srcAddrMode, sourceAddress); + brief.append(' '); + printAddress(brief, destAddrMode, destAddress); - verbose.append("IEEE 802.15.4 ") - .append(type < typeVerbose.length ? typeVerbose[type] : "?") - .append(' ').append(seqNumber); - if (type != ACKFRAME) { - printAddress(brief, srcAddrMode, sourceAddress); - brief.append(' '); - printAddress(brief, destAddrMode, destAddress); - - verbose.append("
From "); - if (srcPanID != 0) { - verbose.append(StringUtils.toHex((byte)(srcPanID >> 8))) - .append(StringUtils.toHex((byte)(srcPanID & 0xff))) + verbose.append("

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))) + } + 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); - } else { - /* got ack - no more to do ... */ - return ANALYSIS_OK_FINAL; - } - - /* update packet */ - packet.pos = pos; - packet.level = NETWORK_LEVEL; - /* remove CRC from the packet */ - packet.consumeBytesEnd(2); - - packet.llsender = sourceAddress; - packet.llreceiver = destAddress; - return ANALYSIS_OK_CONTINUE; + } + printAddress(verbose, destAddrMode, destAddress); + } else { + /* got ack - no more to do ... */ + return ANALYSIS_OK_FINAL; } - private void printAddress(StringBuffer sb, int type, byte[] addr) { - 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])); - } + /* update packet */ + packet.pos = pos; + packet.level = NETWORK_LEVEL; + /* remove CRC from the packet */ + packet.consumeBytesEnd(2); + + packet.llsender = sourceAddress; + packet.llreceiver = destAddress; + return ANALYSIS_OK_CONTINUE; + } + + private void printAddress(StringBuffer sb, int type, byte[] addr) { + 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])); } + } } diff --git a/tools/cooja/java/org/contikios/cooja/plugins/analyzers/IPHCPacketAnalyzer.java b/tools/cooja/java/org/contikios/cooja/plugins/analyzers/IPHCPacketAnalyzer.java index 0860b98cc..9b77a6ed7 100644 --- a/tools/cooja/java/org/contikios/cooja/plugins/analyzers/IPHCPacketAnalyzer.java +++ b/tools/cooja/java/org/contikios/cooja/plugins/analyzers/IPHCPacketAnalyzer.java @@ -4,365 +4,379 @@ import org.contikios.cooja.util.StringUtils; public class IPHCPacketAnalyzer extends PacketAnalyzer { - public final static int SICSLOWPAN_UDP_PORT_MIN = 0xF0B0; - public final static int SICSLOWPAN_UDP_PORT_MAX = 0xF0BF; /* F0B0 + 15 */ + public final static int SICSLOWPAN_UDP_PORT_MIN = 0xF0B0; + public final static int SICSLOWPAN_UDP_PORT_MAX = 0xF0BF; /* F0B0 + 15 */ - public final static int SICSLOWPAN_DISPATCH_IPV6 = 0x41; /* 01000001 = 65 */ - public final static int SICSLOWPAN_DISPATCH_HC1 = 0x42; /* 01000010 = 66 */ - public final static int SICSLOWPAN_DISPATCH_IPHC = 0x60; /* 011xxxxx = ... */ - public final static int SICSLOWPAN_DISPATCH_FRAG1 = 0xc0; /* 1100= 0xxx */ - public final static int SICSLOWPAN_DISPATCH_FRAGN = 0xe0; /* 1110= 0xxx */ + public final static int SICSLOWPAN_DISPATCH_IPV6 = 0x41; /* 01000001 = 65 */ + public final static int SICSLOWPAN_DISPATCH_HC1 = 0x42; /* 01000010 = 66 */ + public final static int SICSLOWPAN_DISPATCH_IPHC = 0x60; /* 011xxxxx = ... */ + public final static int SICSLOWPAN_DISPATCH_FRAG1 = 0xc0; /* 1100= 0xxx */ + public final static int SICSLOWPAN_DISPATCH_FRAGN = 0xe0; /* 1110= 0xxx */ - /* - * Values of fields within the IPHC encoding first byte - * (C stands for compressed and I for inline) - */ - public final static int SICSLOWPAN_IPHC_FL_C = 0x10; - public final static int SICSLOWPAN_IPHC_TC_C = 0x08; - public final static int SICSLOWPAN_IPHC_NH_C = 0x04; - public final static int SICSLOWPAN_IPHC_TTL_1 = 0x01; - public final static int SICSLOWPAN_IPHC_TTL_64 = 0x02; - public final static int SICSLOWPAN_IPHC_TTL_255 = 0x03; - public final static int SICSLOWPAN_IPHC_TTL_I = 0x00; + /* + * Values of fields within the IPHC encoding first byte + * (C stands for compressed and I for inline) + */ + public final static int SICSLOWPAN_IPHC_FL_C = 0x10; + public final static int SICSLOWPAN_IPHC_TC_C = 0x08; + public final static int SICSLOWPAN_IPHC_NH_C = 0x04; + public final static int SICSLOWPAN_IPHC_TTL_1 = 0x01; + public final static int SICSLOWPAN_IPHC_TTL_64 = 0x02; + public final static int SICSLOWPAN_IPHC_TTL_255 = 0x03; + public final static int SICSLOWPAN_IPHC_TTL_I = 0x00; - /* Values of fields within the IPHC encoding second byte */ - public final static int SICSLOWPAN_IPHC_CID = 0x80; + /* Values of fields within the IPHC encoding second byte */ + public final static int SICSLOWPAN_IPHC_CID = 0x80; - public final static int SICSLOWPAN_IPHC_SAC = 0x40; - public final static int SICSLOWPAN_IPHC_SAM_00 = 0x00; - public final static int SICSLOWPAN_IPHC_SAM_01 = 0x10; - public final static int SICSLOWPAN_IPHC_SAM_10 = 0x20; - public final static int SICSLOWPAN_IPHC_SAM_11 = 0x30; + public final static int SICSLOWPAN_IPHC_SAC = 0x40; + public final static int SICSLOWPAN_IPHC_SAM_00 = 0x00; + public final static int SICSLOWPAN_IPHC_SAM_01 = 0x10; + public final static int SICSLOWPAN_IPHC_SAM_10 = 0x20; + public final static int SICSLOWPAN_IPHC_SAM_11 = 0x30; - public final static int SICSLOWPAN_IPHC_M = 0x08; - public final static int SICSLOWPAN_IPHC_DAC = 0x04; - public final static int SICSLOWPAN_IPHC_DAM_00 = 0x00; - public final static int SICSLOWPAN_IPHC_DAM_01 = 0x01; - public final static int SICSLOWPAN_IPHC_DAM_10 = 0x02; - public final static int SICSLOWPAN_IPHC_DAM_11 = 0x03; + public final static int SICSLOWPAN_IPHC_M = 0x08; + public final static int SICSLOWPAN_IPHC_DAC = 0x04; + public final static int SICSLOWPAN_IPHC_DAM_00 = 0x00; + public final static int SICSLOWPAN_IPHC_DAM_01 = 0x01; + public final static int SICSLOWPAN_IPHC_DAM_10 = 0x02; + public final static int SICSLOWPAN_IPHC_DAM_11 = 0x03; - private static final int SICSLOWPAN_NDC_UDP_MASK = 0xf8; - private static final int SICSLOWPAN_NHC_UDP_ID = 0xf0; - private static final int SICSLOWPAN_NHC_UDP_C = 0xf3; - private static final int SICSLOWPAN_NHC_UDP_I = 0xf0; - - 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}; + private static final int SICSLOWPAN_NDC_UDP_MASK = 0xf8; + private static final int SICSLOWPAN_NHC_UDP_ID = 0xf0; + private static final int SICSLOWPAN_NHC_UDP_C = 0xf3; + private static final int SICSLOWPAN_NHC_UDP_I = 0xf0; - private static byte[][] addrContexts = new byte[][] { - {(byte)0xaa, (byte)0xaa, 0, 0, 0, 0, 0, 0} - }; + public final static int PROTO_UDP = 17; + public final static int PROTO_TCP = 6; + public final static int PROTO_ICMP = 58; - private static final int IPHC_DISPATCH = 0x60; + public final static byte[] UNSPECIFIED_ADDRESS + = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; - /* packet must be on network level && have a IPHC dispatch */ - public boolean matchPacket(Packet packet) { - return packet.level == NETWORK_LEVEL && (packet.get(0) & 0xe0) == IPHC_DISPATCH; + private static byte[][] addrContexts = new byte[][]{ + {(byte) 0xaa, (byte) 0xaa, 0, 0, 0, 0, 0, 0} + }; + + private static final int IPHC_DISPATCH = 0x60; + + /* packet must be on network level && have a IPHC dispatch */ + public boolean matchPacket(Packet packet) { + return packet.level == NETWORK_LEVEL && (packet.get(0) & 0xe0) == IPHC_DISPATCH; + } + + public int analyzePacket(Packet packet, StringBuffer brief, + StringBuffer verbose) { + + /* if packet has less than 3 bytes it is not interesting ... */ + if (packet.size() < 3) return ANALYSIS_FAILED; + + int tf = (packet.get(0) >> 3) & 0x03; + boolean nhc = (packet.get(0) & SICSLOWPAN_IPHC_NH_C) > 0; + int hlim = (packet.get(0) & 0x03); + int cid = (packet.get(1) >> 7) & 0x01; + int sac = (packet.get(1) >> 6) & 0x01; + int sam = (packet.get(1) >> 4) & 0x03; + int m = (packet.get(1) >> 3) & 0x01; + int dac = (packet.get(1) >> 2) & 0x01; + int dam = packet.get(1) & 0x03; + int sci = 0; + int dci = 0; + + String error = null; + + brief.append("IPHC"); + + /* need to decompress while analyzing - add that later... */ + verbose.append("IPHC HC-06
"); + verbose.append("tf = " + tf + " nhc = " + nhc + " hlim = " + hlim + + " cid = " + cid + " sac = " + sac + " sam = " + sam + + " MCast = " + m + " dac = " + dac + " dam = " + dam); + if (cid == 1) { + verbose.append("
Contexts: sci=" + (packet.get(2) >> 4) + " dci=" + + (packet.get(2) & 0x0f)); + sci = packet.get(2) >> 4; + dci = packet.get(2) & 0x0f; } - public int analyzePacket(Packet packet, StringBuffer brief, - StringBuffer verbose) { + int hc06_ptr = 2 + cid; - /* if packet has less than 3 bytes it is not interesting ... */ - if (packet.size() < 3) return ANALYSIS_FAILED; - - int tf = (packet.get(0) >> 3) & 0x03; - boolean nhc = (packet.get(0) & SICSLOWPAN_IPHC_NH_C) > 0; - int hlim = (packet.get(0) & 0x03); - int cid = (packet.get(1) >> 7) & 0x01; - int sac = (packet.get(1) >> 6) & 0x01; - int sam = (packet.get(1) >> 4) & 0x03; - int m = (packet.get(1) >> 3) & 0x01; - int dac = (packet.get(1) >> 2) & 0x01; - int dam = packet.get(1) & 0x03; - int sci = 0; - int dci = 0; + int version = 6; + int trafficClass = 0; + int flowLabel = 0; + int len = 0; + int proto = 0; + int ttl = 0; + byte[] srcAddress = new byte[16]; + byte[] destAddress = new byte[16]; - String error = null; - - brief.append("IPHC"); + int srcPort = 0; + int destPort = 0; - /* need to decompress while analyzing - add that later... */ - - verbose.append("IPHC HC-06
"); - verbose.append("tf = " + tf + " nhc = " + nhc + " hlim = " + hlim - + " cid = " + cid + " sac = " + sac + " sam = " + sam - + " MCast = " + m + " dac = " + dac + " dam = " + dam); - if (cid == 1) { - verbose.append("
Contexts: sci=" + (packet.get(2) >> 4) + " dci=" - + (packet.get(2) & 0x0f)); - sci = packet.get(2) >> 4; - dci = packet.get(2) & 0x0f; - } - - int hc06_ptr = 2 + cid; - - int version = 6; - int trafficClass = 0; - int flowLabel = 0; - int len = 0; - int proto = 0; - int ttl = 0; - byte[] srcAddress = new byte[16]; - byte[] destAddress = new byte[16]; - - int srcPort = 0; - int destPort = 0; - - - try { - /* Traffic class and flow label */ - if((packet.get(0) & SICSLOWPAN_IPHC_FL_C) == 0) { - /* Flow label are carried inline */ - 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); - hc06_ptr += 4; - /* hc06 format of tc is ECN | DSCP , original is DSCP | ECN */ - trafficClass = ((tmp >> 2) & 0x3f) | (tmp << 6) & (0x80 + 0x40); - /* ECN rolled down two steps + lowest DSCP bits at top two bits */ - } else { - /* highest flow label bits + ECN bits */ - int tmp = packet.get(hc06_ptr); - trafficClass = (tmp >> 6) & 0x0f; - flowLabel = packet.getInt(hc06_ptr + 1, 2); - hc06_ptr += 3; - } + try { + /* Traffic class and flow label */ + if ((packet.get(0) & SICSLOWPAN_IPHC_FL_C) == 0) { + /* Flow label are carried inline */ + 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); + hc06_ptr += 4; + /* hc06 format of tc is ECN | DSCP , original is DSCP | ECN */ + trafficClass = ((tmp >> 2) & 0x3f) | (tmp << 6) & (0x80 + 0x40); + /* ECN rolled down two steps + lowest DSCP bits at top two bits */ } else { - /* Version is always 6! */ - /* Version and flow label are compressed */ - 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) << 2); - hc06_ptr += 1; - } + /* highest flow label bits + ECN bits */ + int tmp = packet.get(hc06_ptr); + trafficClass = (tmp >> 6) & 0x0f; + flowLabel = packet.getInt(hc06_ptr + 1, 2); + hc06_ptr += 3; } - - /* Next Header */ - if((packet.get(0) & SICSLOWPAN_IPHC_NH_C) == 0) { - /* Next header is carried inline */ - proto = packet.get(hc06_ptr); - hc06_ptr += 1; + } else { + /* Version is always 6! */ + /* Version and flow label are compressed */ + 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) << 2); + hc06_ptr += 1; } + } - /* Hop limit */ - switch(packet.get(0) & 0x03) { + /* Next Header */ + 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) { case SICSLOWPAN_IPHC_TTL_1: - ttl = 1; - break; + ttl = 1; + break; case SICSLOWPAN_IPHC_TTL_64: - ttl = 2; - break; + ttl = 2; + break; case SICSLOWPAN_IPHC_TTL_255: - ttl = 255; - break; + ttl = 255; + break; case SICSLOWPAN_IPHC_TTL_I: - ttl = packet.get(hc06_ptr); - hc06_ptr += 1; + ttl = packet.get(hc06_ptr); + hc06_ptr += 1; + break; + } + + /* context based compression */ + 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) { + context = addrContexts[sci]; + } + + 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); + hc06_ptr += 8; + 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); + hc06_ptr += 2; + 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, + 16 - packet.llsender.length, packet.llsender.length); break; } + /* end context based compression */ + } else { + /* no compression and link local */ + switch (packet.get(1) & SICSLOWPAN_IPHC_SAM_11) { + case SICSLOWPAN_IPHC_SAM_00: /* 128 bits */ + /* copy whole address from packet */ - /* context based compression */ - 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) { - context = addrContexts[sci]; - } + packet.copy(hc06_ptr, srcAddress, 0, 16); + hc06_ptr += 16; + break; + case SICSLOWPAN_IPHC_SAM_01: /* 64 bits */ - 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); - hc06_ptr += 8; - 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); - hc06_ptr += 2; - 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, - 16 - packet.llsender.length, packet.llsender.length); - break; - } - /* end context based compression */ - } else { - /* no compression and link local */ - 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 */ - packet.copy(hc06_ptr, srcAddress, 8, 8); - 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); - hc06_ptr += 2; - 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 */ - System.arraycopy(packet.llsender, 0, srcAddress, - 16 - packet.llsender.length, packet.llsender.length); - break; - } + srcAddress[0] = (byte) 0xfe; + srcAddress[1] = (byte) 0x80; + /* copy IID from packet */ + packet.copy(hc06_ptr, srcAddress, 8, 8); + 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); + hc06_ptr += 2; + 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 */ + System.arraycopy(packet.llsender, 0, srcAddress, + 16 - packet.llsender.length, packet.llsender.length); + break; } + } - /* Destination address */ + /* Destination address */ - /* multicast compression */ - if((packet.get(1) & SICSLOWPAN_IPHC_M) != 0) { - /* context based multicast compression */ - 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); - hc06_ptr++; - break; - } - } + /* multicast compression */ + if ((packet.get(1) & SICSLOWPAN_IPHC_M) != 0) { + /* context based multicast compression */ + if ((packet.get(1) & SICSLOWPAN_IPHC_DAC) != 0) { + /* TODO: implement this */ } else { - /* no multicast */ - /* Context based */ - if((packet.get(1) & SICSLOWPAN_IPHC_DAC) != 0) { - byte[] context = addrContexts[dci]; + /* 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 */ - 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); - hc06_ptr += 8; - 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); - hc06_ptr += 2; - 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, - 16 - packet.llreceiver.length, packet.llreceiver.length); - break; - } - } else { - /* 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, - 16 - packet.llreceiver.length, packet.llreceiver.length); - break; - } - } + 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); + hc06_ptr++; + break; + } } + } else { + /* no multicast */ + /* Context based */ + if ((packet.get(1) & SICSLOWPAN_IPHC_DAC) != 0) { + byte[] context = addrContexts[dci]; - /* Next header processing - continued */ - 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) { - proto = PROTO_UDP; - 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); - destPort = SICSLOWPAN_UDP_PORT_MIN + (packet.get(hc06_ptr + 1) & 0x0F); + 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); + hc06_ptr += 8; + 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); + hc06_ptr += 2; + 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, + 16 - packet.llreceiver.length, packet.llreceiver.length); + break; + } + } else { + /* 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, + 16 - packet.llreceiver.length, packet.llreceiver.length); + break; + } + } + } + + /* Next header processing - continued */ + 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) { + proto = PROTO_UDP; + 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); + destPort = SICSLOWPAN_UDP_PORT_MIN + (packet.get(hc06_ptr + 1) & 0x0F); // memcpy(&SICSLOWPAN_UDP_BUF->udpchksum, hc06_ptr + 2, 2); // PRINTF("IPHC: Uncompressed UDP ports (4): %x, %x\n", // SICSLOWPAN_UDP_BUF->srcport, SICSLOWPAN_UDP_BUF->destport); - hc06_ptr += 4; - break; - case (byte) SICSLOWPAN_NHC_UDP_I: - /* 1 byte for NHC, 4 byte for ports, 2 bytes chksum */ - srcPort = packet.getInt(hc06_ptr + 1, 2); - destPort = packet.getInt(hc06_ptr + 3, 2); + hc06_ptr += 4; + break; + case (byte) SICSLOWPAN_NHC_UDP_I: + /* 1 byte for NHC, 4 byte for ports, 2 bytes chksum */ + srcPort = packet.getInt(hc06_ptr + 1, 2); + destPort = packet.getInt(hc06_ptr + 3, 2); // memcpy(&SICSLOWPAN_UDP_BUF->udpchksum, hc06_ptr + 5, 2); // PRINTF("IPHC: Uncompressed UDP ports (7): %x, %x\n", // SICSLOWPAN_UDP_BUF->srcport, SICSLOWPAN_UDP_BUF->destport); - hc06_ptr += 7; - break; - default: + hc06_ptr += 7; + break; + default: // PRINTF("sicslowpan uncompress_hdr: error unsupported UDP compression\n"); - return ANALYSIS_FAILED; - } - } + return ANALYSIS_FAILED; + } } - + } // /* IP length field. */ // if(ip_len == 0) { @@ -374,54 +388,54 @@ 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(); + } + packet.pos += hc06_ptr; - } catch (Exception e) { - // some kind of unexpected error... - error = " error during IPHC parsing: " + e.getMessage(); - } - packet.pos += hc06_ptr; - - String protoStr = "" + proto; - if (proto == PROTO_ICMP) { - protoStr = "ICMPv6"; - } else if (proto == PROTO_UDP) protoStr = "UDP"; - else if (proto == PROTO_TCP) protoStr = "TCP"; - - verbose.append("
IPv6 ").append(protoStr).append(" TC = " + trafficClass + - " FL: " + flowLabel + "
"); - verbose.append("From "); - printAddress(verbose, srcAddress); - verbose.append(" to "); - printAddress(verbose, destAddress); - if (error != null) verbose.append(" " + error); - - packet.lastDispatch = (byte) (proto & 0xff); - if (proto == PROTO_UDP || proto == PROTO_ICMP || - proto == PROTO_TCP) { - packet.level = APPLICATION_LEVEL; - return ANALYSIS_OK_CONTINUE; - } else { - packet.level = NETWORK_LEVEL; - return ANALYSIS_OK_CONTINUE; - } + String protoStr = "" + proto; + if (proto == PROTO_ICMP) { + protoStr = "ICMPv6"; + } else if (proto == PROTO_UDP) { + protoStr = "UDP"; + } else if (proto == PROTO_TCP) { + protoStr = "TCP"; } - 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))); - if (i < 14) { - out.append(":"); - } - } - } + verbose.append("
IPv6 ").append(protoStr) + .append(" TC = " + trafficClass + + " FL: " + flowLabel + "
"); + verbose.append("From "); + printAddress(verbose, srcAddress); + verbose.append(" to "); + printAddress(verbose, destAddress); + if (error != null) verbose.append(" " + error); - + packet.lastDispatch = (byte) (proto & 0xff); + if (proto == PROTO_UDP || proto == PROTO_ICMP + || proto == PROTO_TCP) { + packet.level = APPLICATION_LEVEL; + return ANALYSIS_OK_CONTINUE; + } else { + packet.level = NETWORK_LEVEL; + return ANALYSIS_OK_CONTINUE; + } + } + + 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))); + if (i < 14) { + out.append(":"); + } + } + } } diff --git a/tools/cooja/java/org/contikios/cooja/plugins/analyzers/IPv6PacketAnalyzer.java b/tools/cooja/java/org/contikios/cooja/plugins/analyzers/IPv6PacketAnalyzer.java index 4ca371c8d..421014418 100644 --- a/tools/cooja/java/org/contikios/cooja/plugins/analyzers/IPv6PacketAnalyzer.java +++ b/tools/cooja/java/org/contikios/cooja/plugins/analyzers/IPv6PacketAnalyzer.java @@ -4,78 +4,77 @@ 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 int PROTO_UDP = 17; + public final static int PROTO_TCP = 6; + public final static int PROTO_ICMP = 58; - private static final int IPV6_DISPATCH = 0x41; + public final static byte[] UNSPECIFIED_ADDRESS + = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; - public boolean matchPacket(Packet packet) { - return packet.level == NETWORK_LEVEL && packet.get(0) == IPV6_DISPATCH; + private static final int IPV6_DISPATCH = 0x41; + + public boolean matchPacket(Packet packet) { + return packet.level == NETWORK_LEVEL && packet.get(0) == IPV6_DISPATCH; + } + + public int analyzePacket(Packet packet, StringBuffer brief, + StringBuffer verbose) { + + /* 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("IPv6
"); + + int pos = 1; + + int version = 6; + int trafficClass = 0; + int flowLabel = 0; + int len = packet.getInt(pos + 4, 2); + int proto = packet.getInt(pos + 6, 1); + int ttl = packet.getInt(pos + 7, 1); + byte[] srcAddress = new byte[16]; + byte[] destAddress = new byte[16]; + + packet.copy(pos + 8, srcAddress, 0, 16); + packet.copy(pos + 24, destAddress, 0, 16); + + String protoStr = "" + proto; + if (proto == PROTO_ICMP) { + protoStr = "ICMPv6"; + } else if (proto == PROTO_UDP) { + protoStr = "UDP"; + } else if (proto == PROTO_TCP) { + protoStr = "TCP"; } - public int analyzePacket(Packet packet, StringBuffer brief, - StringBuffer verbose) { + /* consume dispatch + IP header */ + packet.pos += 41; - /* if packet has less than 40 bytes it is not interesting ... */ - if (packet.size() < 40) return ANALYSIS_FAILED; - + verbose.append("
IPv6 ").append(protoStr) + .append(" TC = " + trafficClass + + " FL: " + flowLabel + "
"); + verbose.append("From "); + printAddress(verbose, srcAddress); + verbose.append(" to "); + printAddress(verbose, destAddress); - brief.append("IPv6"); + packet.lastDispatch = (byte) (proto & 0xff); + packet.level = APPLICATION_LEVEL; + return ANALYSIS_OK_CONTINUE; + } - /* need to decompress while analyzing - add that later... */ - - verbose.append("IPv6
"); - - int pos = 1; - - int version = 6; - int trafficClass = 0; - int flowLabel = 0; - int len = packet.getInt(pos + 4, 2); - int proto = packet.getInt(pos + 6, 1); - int ttl = packet.getInt(pos + 7, 1); - byte[] srcAddress = new byte[16]; - byte[] destAddress = new byte[16]; - - packet.copy(pos + 8, srcAddress, 0, 16); - packet.copy(pos + 24, destAddress, 0, 16); - - String protoStr = "" + proto; - if (proto == PROTO_ICMP) { - protoStr = "ICMPv6"; - } else if (proto == PROTO_UDP) protoStr = "UDP"; - else if (proto == PROTO_TCP) protoStr = "TCP"; - - /* consume dispatch + IP header */ - packet.pos += 41; - - verbose.append("
IPv6 ").append(protoStr).append(" TC = " + trafficClass + - " FL: " + flowLabel + "
"); - verbose.append("From "); - printAddress(verbose, srcAddress); - verbose.append(" to "); - printAddress(verbose, destAddress); - - packet.lastDispatch = (byte) (proto & 0xff); - packet.level = APPLICATION_LEVEL; - return ANALYSIS_OK_CONTINUE; - } - - 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))); - if (i < 14) { - out.append(":"); - } - } + 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))); + if (i < 14) { + out.append(":"); } + } + } - } diff --git a/tools/cooja/java/org/contikios/cooja/plugins/analyzers/PacketAnalyzer.java b/tools/cooja/java/org/contikios/cooja/plugins/analyzers/PacketAnalyzer.java index 45d656863..73549cce3 100644 --- a/tools/cooja/java/org/contikios/cooja/plugins/analyzers/PacketAnalyzer.java +++ b/tools/cooja/java/org/contikios/cooja/plugins/analyzers/PacketAnalyzer.java @@ -2,88 +2,86 @@ package org.contikios.cooja.plugins.analyzers; public abstract class PacketAnalyzer { - public static final int ANALYSIS_FAILED = -1; - public static final int ANALYSIS_OK_CONTINUE = 1; - public static final int ANALYSIS_OK_FINAL = 2; - - public static final int RADIO_LEVEL = 0; - public static final int MAC_LEVEL = 1; - public static final int NETWORK_LEVEL = 2; - public static final int APPLICATION_LEVEL = 3; - - public static class Packet { - byte[] data; - int pos; - int level; - /* size = length - consumed bytes at tail */ - int size; - - /* L2 addresseses */ - byte[] llsender; - byte[] llreceiver; + public static final int ANALYSIS_FAILED = -1; + public static final int ANALYSIS_OK_CONTINUE = 1; + public static final int ANALYSIS_OK_FINAL = 2; - byte lastDispatch = 0; - - public Packet(byte[] data, int level) { - this.level = level; - this.data = data; - this.size = data.length; - } + public static final int RADIO_LEVEL = 0; + public static final int MAC_LEVEL = 1; + public static final int NETWORK_LEVEL = 2; + public static final int APPLICATION_LEVEL = 3; + public static class Packet { - public void consumeBytesStart(int bytes) { - pos += bytes; - } + byte[] data; + int pos; + int level; + /* size = length - consumed bytes at tail */ + int size; - public void consumeBytesEnd(int bytes) { - size -= bytes; - } - - - public boolean hasMoreData() { - return size > pos; - } - - public int size() { - return size - pos; - } - - public byte get(int index) { - if (index >= size) return 0; - return data[pos + index]; - } + /* L2 addresseses */ + byte[] llsender; + byte[] llreceiver; - public int getInt(int index, int size) { - int value = 0; - for (int i = 0; i < size; i++) { - value = (value << 8) + get(index + i); - } - return value; - } + byte lastDispatch = 0; - - public byte[] getPayload() { - byte[] pload = new byte[size - pos]; - System.arraycopy(data, pos, pload, 0, pload.length); - return pload; - } + public Packet(byte[] data, int level) { + this.level = level; + this.data = data; + this.size = data.length; + } - public void copy(int srcpos, byte[] arr, int pos, int len) { - for (int i = 0; i < len; i++) { - arr[pos + i] = get(srcpos + i); - } - } + public void consumeBytesStart(int bytes) { + pos += bytes; + } - public byte[] getLLSender() { - return llsender; - } + public void consumeBytesEnd(int bytes) { + size -= bytes; + } - public byte[] getLLReceiver() { - return llreceiver; - } - }; - - public abstract boolean matchPacket(Packet packet); - - public abstract int analyzePacket(Packet packet, StringBuffer brief, StringBuffer verbose); -} \ No newline at end of file + public boolean hasMoreData() { + return size > pos; + } + + public int size() { + return size - pos; + } + + public byte get(int index) { + if (index >= size) return 0; + return data[pos + index]; + } + + public int getInt(int index, int size) { + int value = 0; + for (int i = 0; i < size; i++) { + value = (value << 8) + get(index + i); + } + return value; + } + + public byte[] getPayload() { + byte[] pload = new byte[size - pos]; + System.arraycopy(data, pos, pload, 0, pload.length); + return pload; + } + + public void copy(int srcpos, byte[] arr, int pos, int len) { + for (int i = 0; i < len; i++) { + arr[pos + i] = get(srcpos + i); + } + } + + public byte[] getLLSender() { + return llsender; + } + + public byte[] getLLReceiver() { + return llreceiver; + } + }; + + public abstract boolean matchPacket(Packet packet); + + public abstract int analyzePacket(Packet packet, StringBuffer brief, StringBuffer verbose); +} diff --git a/tools/cooja/java/org/contikios/cooja/plugins/analyzers/PcapExporter.java b/tools/cooja/java/org/contikios/cooja/plugins/analyzers/PcapExporter.java index d0fa0624f..64bf5069c 100644 --- a/tools/cooja/java/org/contikios/cooja/plugins/analyzers/PcapExporter.java +++ b/tools/cooja/java/org/contikios/cooja/plugins/analyzers/PcapExporter.java @@ -9,55 +9,55 @@ import java.io.File; public class PcapExporter { - DataOutputStream out; - - public PcapExporter() throws IOException { - } - - public void openPcap(File pcapFile) throws IOException { - if ( out != null ) { - closePcap(); - } - if ( pcapFile == null ) { - /* pcap file not specified, use default file name */ - pcapFile = new File("radiolog-" + System.currentTimeMillis() + ".pcap"); - } - out = new DataOutputStream(new FileOutputStream(pcapFile)); - /* pcap header */ - out.writeInt(0xa1b2c3d4); - out.writeShort(0x0002); - out.writeShort(0x0004); - out.writeInt(0); - 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; - } + DataOutputStream out; - public void exportPacketData(byte[] data) throws IOException { - if (out == null) { - /* pcap file never set, open default */ - openPcap(null); - } - try { - /* pcap packet header */ - out.writeInt((int) (System.currentTimeMillis() / 1000)); - out.writeInt((int) ((System.currentTimeMillis() % 1000) * 1000)); - out.writeInt(data.length); - out.writeInt(data.length); - /* and the data */ - out.write(data); - out.flush(); - } catch (Exception e) { - e.printStackTrace(); - } + public PcapExporter() throws IOException { + } + + public void openPcap(File pcapFile) throws IOException { + if (out != null) { + closePcap(); } - - - + if (pcapFile == null) { + /* pcap file not specified, use default file name */ + pcapFile = new File("radiolog-" + System.currentTimeMillis() + ".pcap"); + } + out = new DataOutputStream(new FileOutputStream(pcapFile)); + /* pcap header */ + out.writeInt(0xa1b2c3d4); + out.writeShort(0x0002); + out.writeShort(0x0004); + out.writeInt(0); + 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; + } + + public void exportPacketData(byte[] data) throws IOException { + if (out == null) { + /* pcap file never set, open default */ + openPcap(null); + } + try { + /* pcap packet header */ + out.writeInt((int) (System.currentTimeMillis() / 1000)); + out.writeInt((int) ((System.currentTimeMillis() % 1000) * 1000)); + out.writeInt(data.length); + out.writeInt(data.length); + /* and the data */ + out.write(data); + out.flush(); + } catch (Exception e) { + e.printStackTrace(); + } + } + } From e16a5d65dfae1b9f0bda12ab6611355e522ab588 Mon Sep 17 00:00:00 2001 From: Enrico Joerns Date: Fri, 11 Jul 2014 02:14:46 +0200 Subject: [PATCH 02/12] [cooja] plugins/analyzers: Added @Override annotations --- .../contikios/cooja/plugins/RadioLogger.java | 34 +++++++++++++++++++ .../plugins/analyzers/ICMPv6Analyzer.java | 1 + .../plugins/analyzers/IEEE802154Analyzer.java | 2 ++ .../plugins/analyzers/IPHCPacketAnalyzer.java | 2 ++ .../plugins/analyzers/IPv6PacketAnalyzer.java | 2 ++ 5 files changed, 41 insertions(+) diff --git a/tools/cooja/java/org/contikios/cooja/plugins/RadioLogger.java b/tools/cooja/java/org/contikios/cooja/plugins/RadioLogger.java index 2205f1c68..70eba23bb 100644 --- a/tools/cooja/java/org/contikios/cooja/plugins/RadioLogger.java +++ b/tools/cooja/java/org/contikios/cooja/plugins/RadioLogger.java @@ -187,6 +187,7 @@ public class RadioLogger extends VisPlugin { private static final long serialVersionUID = 1692207305977527004L; + @Override public String getColumnName(int col) { if (col == COLUMN_TIME && formatTimeString) { return "Time"; @@ -194,14 +195,17 @@ public class RadioLogger extends VisPlugin { return COLUMN_NAMES[col]; } + @Override public int getRowCount() { return connections.size(); } + @Override public int getColumnCount() { return COLUMN_NAMES.length; } + @Override public Object getValueAt(int row, int col) { if (row < 0 || row >= connections.size()) { return ""; @@ -247,6 +251,7 @@ public class RadioLogger extends VisPlugin { return null; } + @Override public boolean isCellEditable(int row, int col) { if (col == COLUMN_FROM) { /* Highlight source */ @@ -265,6 +270,7 @@ public class RadioLogger extends VisPlugin { return false; } + @Override public Class getColumnClass(int c) { return getValueAt(0, c).getClass(); } @@ -274,6 +280,7 @@ public class RadioLogger extends VisPlugin { private static final long serialVersionUID = -2199726885069809686L; + @Override public String getToolTipText(MouseEvent e) { java.awt.Point p = e.getPoint(); int rowIndex = rowAtPoint(p); @@ -328,6 +335,7 @@ public class RadioLogger extends VisPlugin { /* Toggle time format */ dataTable.getTableHeader().addMouseListener(new MouseAdapter() { + @Override public void mouseClicked(MouseEvent e) { int colIndex = dataTable.columnAtPoint(e.getPoint()); int columnIndex = dataTable.convertColumnIndexToModel(colIndex); @@ -342,6 +350,7 @@ public class RadioLogger extends VisPlugin { }); dataTable.addKeyListener(new KeyAdapter() { + @Override public void keyPressed(KeyEvent e) { if (e.getKeyCode() == KeyEvent.VK_SPACE) { showInAllAction.actionPerformed(null); @@ -366,6 +375,7 @@ public class RadioLogger extends VisPlugin { dataTable.setRowSorter(logFilter); dataTable.getSelectionModel().addListSelectionListener(new ListSelectionListener() { + @Override public void valueChanged(ListSelectionEvent e) { int row = dataTable.getSelectedRow(); if (row < 0) { @@ -394,11 +404,13 @@ public class RadioLogger extends VisPlugin { payloadMenu.add(new JMenuItem(aliasAction)); payloadMenu.add(new JCheckBoxMenuItem(showDuplicatesAction) { + @Override public boolean isSelected() { return showDuplicates; } }); payloadMenu.add(new JCheckBoxMenuItem(hideNoDestinationAction) { + @Override public boolean isSelected() { return hideNoDestinationPackets; } @@ -469,6 +481,7 @@ public class RadioLogger extends VisPlugin { /* Search text field */ searchField.setVisible(false); searchField.addKeyListener(new KeyAdapter() { + @Override public void keyPressed(KeyEvent e) { if (e.getKeyCode() == KeyEvent.VK_ENTER) { searchSelectNext( @@ -494,6 +507,7 @@ public class RadioLogger extends VisPlugin { adjuster.packColumns(); radioMedium.addRadioMediumObserver(radioMediumObserver = new Observer() { + @Override public void update(Observable obs, Object obj) { RadioConnection conn = radioMedium.getLastConnection(); if (conn == null) { @@ -505,6 +519,7 @@ public class RadioLogger extends VisPlugin { loggedConn.connection = conn; loggedConn.packet = conn.getSource().getLastPacketTransmitted(); java.awt.EventQueue.invokeLater(new Runnable() { + @Override public void run() { int lastSize = connections.size(); // Check if the last row is visible @@ -536,6 +551,7 @@ public class RadioLogger extends VisPlugin { } } + @Override public void startPlugin() { super.startPlugin(); rebuildAllEntries(); @@ -583,6 +599,7 @@ public class RadioLogger extends VisPlugin { */ public void trySelectTime(final long time) { java.awt.EventQueue.invokeLater(new Runnable() { + @Override public void run() { if (dataTable.getRowCount() == 0) { return; @@ -614,6 +631,7 @@ public class RadioLogger extends VisPlugin { try { logFilter.setRowFilter(null); RowFilter filter = new RowFilter() { + @Override public boolean include(RowFilter.Entry entry) { int row = (Integer) entry.getIdentifier(); RadioConnectionLog current = connections.get(row); @@ -760,12 +778,14 @@ public class RadioLogger extends VisPlugin { } } + @Override public void closePlugin() { if (radioMediumObserver != null) { radioMedium.deleteRadioMediumObserver(radioMediumObserver); } } + @Override public Collection getConfigXML() { ArrayList config = new ArrayList(); @@ -812,6 +832,7 @@ public class RadioLogger extends VisPlugin { return config; } + @Override public boolean setConfigXML(Collection configXML, boolean visAvailable) { for (Element element : configXML) { String name = element.getName(); @@ -835,6 +856,7 @@ public class RadioLogger extends VisPlugin { final Action action; if (analyzerName != null && ((action = analyzerMap.get(analyzerName)) != null)) { java.awt.EventQueue.invokeLater(new Runnable() { + @Override public void run() { action.putValue(Action.SELECTED_KEY, Boolean.TRUE); action.actionPerformed(null); @@ -862,6 +884,7 @@ public class RadioLogger extends VisPlugin { String data = null; String tooltip = null; + @Override public String toString() { if (data == null) { RadioLogger.this.prepareDataString(this); @@ -906,6 +929,7 @@ public class RadioLogger extends VisPlugin { Action action = new AbstractAction(name) { private static final long serialVersionUID = -608913700422638454L; + @Override public void actionPerformed(ActionEvent event) { if (analyzers != analyzerList) { analyzers = analyzerList; @@ -922,6 +946,7 @@ public class RadioLogger extends VisPlugin { private Action clearAction = new AbstractAction("Clear") { private static final long serialVersionUID = -6135583266684643117L; + @Override public void actionPerformed(ActionEvent e) { int size = connections.size(); if (size > 0) { @@ -935,6 +960,7 @@ public class RadioLogger extends VisPlugin { private Action copyAction = new AbstractAction("Copy selected") { private static final long serialVersionUID = 8412062977916108054L; + @Override public void actionPerformed(ActionEvent e) { Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard(); @@ -954,6 +980,7 @@ public class RadioLogger extends VisPlugin { private Action copyAllAction = new AbstractAction("Copy all") { private static final long serialVersionUID = 1905586689441157304L; + @Override public void actionPerformed(ActionEvent e) { Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard(); @@ -970,6 +997,7 @@ public class RadioLogger extends VisPlugin { private Action saveAction = new AbstractAction("Save to file...") { private static final long serialVersionUID = -3942984643211482179L; + @Override public void actionPerformed(ActionEvent e) { JFileChooser fc = new JFileChooser(); int returnVal = fc.showSaveDialog(Cooja.getTopParentContainer()); @@ -1014,6 +1042,7 @@ public class RadioLogger extends VisPlugin { private Action timeLineAction = new AbstractAction("Timeline") { private static final long serialVersionUID = -4035633464748224192L; + @Override public void actionPerformed(ActionEvent e) { int selectedRow = dataTable.getSelectedRow(); if (selectedRow < 0) return; @@ -1038,6 +1067,7 @@ public class RadioLogger extends VisPlugin { private Action logListenerAction = new AbstractAction("Mote output") { private static final long serialVersionUID = 1985006491187878651L; + @Override public void actionPerformed(ActionEvent e) { int selectedRow = dataTable.getSelectedRow(); if (selectedRow < 0) return; @@ -1066,6 +1096,7 @@ public class RadioLogger extends VisPlugin { putValue(ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_SPACE, 0, true)); } + @Override public void actionPerformed(ActionEvent e) { timeLineAction.actionPerformed(null); logListenerAction.actionPerformed(null); @@ -1076,6 +1107,7 @@ public class RadioLogger extends VisPlugin { private Action aliasAction = new AbstractAction("Payload alias...") { private static final long serialVersionUID = -1678771087456128721L; + @Override public void actionPerformed(ActionEvent e) { int selectedRow = dataTable.getSelectedRow(); if (selectedRow < 0) return; @@ -1127,6 +1159,7 @@ public class RadioLogger extends VisPlugin { private boolean showDuplicates = false; private AbstractAction showDuplicatesAction = new AbstractAction("Show duplicates") { + @Override public void actionPerformed(ActionEvent e) { showDuplicates = !showDuplicates; rebuildAllEntries(); @@ -1135,6 +1168,7 @@ public class RadioLogger extends VisPlugin { private boolean hideNoDestinationPackets = false; private AbstractAction hideNoDestinationAction = new AbstractAction("Hide airshots") { + @Override public void actionPerformed(ActionEvent e) { hideNoDestinationPackets = !hideNoDestinationPackets; rebuildAllEntries(); diff --git a/tools/cooja/java/org/contikios/cooja/plugins/analyzers/ICMPv6Analyzer.java b/tools/cooja/java/org/contikios/cooja/plugins/analyzers/ICMPv6Analyzer.java index f1e3b0aa0..7b1d03fd0 100644 --- a/tools/cooja/java/org/contikios/cooja/plugins/analyzers/ICMPv6Analyzer.java +++ b/tools/cooja/java/org/contikios/cooja/plugins/analyzers/ICMPv6Analyzer.java @@ -38,6 +38,7 @@ public class ICMPv6Analyzer extends PacketAnalyzer { "NEIGHBOR_SOLICITATION", "NEIGHBOR_ADVERTISEMENT", "REDIRECT", "ROUTER RENUMBER", "NODE INFORMATION QUERY", "NODE INFORMATION RESPONSE"}; + @Override public int analyzePacket(Packet packet, StringBuffer brief, StringBuffer verbose) { int type = packet.get(0) & 0xff; diff --git a/tools/cooja/java/org/contikios/cooja/plugins/analyzers/IEEE802154Analyzer.java b/tools/cooja/java/org/contikios/cooja/plugins/analyzers/IEEE802154Analyzer.java index 4175a2be4..ce94e8e14 100644 --- a/tools/cooja/java/org/contikios/cooja/plugins/analyzers/IEEE802154Analyzer.java +++ b/tools/cooja/java/org/contikios/cooja/plugins/analyzers/IEEE802154Analyzer.java @@ -47,6 +47,7 @@ public class IEEE802154Analyzer extends PacketAnalyzer { } } + @Override public boolean matchPacket(Packet packet) { return packet.level == MAC_LEVEL; } @@ -59,6 +60,7 @@ public class IEEE802154Analyzer extends PacketAnalyzer { * next handler */ + @Override public int analyzePacket(Packet packet, StringBuffer brief, StringBuffer verbose) { if (pcapExporter != null) { diff --git a/tools/cooja/java/org/contikios/cooja/plugins/analyzers/IPHCPacketAnalyzer.java b/tools/cooja/java/org/contikios/cooja/plugins/analyzers/IPHCPacketAnalyzer.java index 9b77a6ed7..7cbb97935 100644 --- a/tools/cooja/java/org/contikios/cooja/plugins/analyzers/IPHCPacketAnalyzer.java +++ b/tools/cooja/java/org/contikios/cooja/plugins/analyzers/IPHCPacketAnalyzer.java @@ -61,10 +61,12 @@ public class IPHCPacketAnalyzer extends PacketAnalyzer { private static final int IPHC_DISPATCH = 0x60; /* packet must be on network level && have a IPHC dispatch */ + @Override public boolean matchPacket(Packet packet) { return packet.level == NETWORK_LEVEL && (packet.get(0) & 0xe0) == IPHC_DISPATCH; } + @Override public int analyzePacket(Packet packet, StringBuffer brief, StringBuffer verbose) { diff --git a/tools/cooja/java/org/contikios/cooja/plugins/analyzers/IPv6PacketAnalyzer.java b/tools/cooja/java/org/contikios/cooja/plugins/analyzers/IPv6PacketAnalyzer.java index 421014418..0dc34896e 100644 --- a/tools/cooja/java/org/contikios/cooja/plugins/analyzers/IPv6PacketAnalyzer.java +++ b/tools/cooja/java/org/contikios/cooja/plugins/analyzers/IPv6PacketAnalyzer.java @@ -13,10 +13,12 @@ public class IPv6PacketAnalyzer extends PacketAnalyzer { private static final int IPV6_DISPATCH = 0x41; + @Override public boolean matchPacket(Packet packet) { return packet.level == NETWORK_LEVEL && packet.get(0) == IPV6_DISPATCH; } + @Override public int analyzePacket(Packet packet, StringBuffer brief, StringBuffer verbose) { From 649a447c9aafc0542ecef1c23e39aecc1ccc029f Mon Sep 17 00:00:00 2001 From: Enrico Joerns Date: Fri, 11 Jul 2014 02:33:57 +0200 Subject: [PATCH 03/12] [cooja] plugins/analyzers: Replace StringBuffer with lightweight StringBuilder StringBuffer is a thread-safe version of StringBuilder that introduces unnecessary overhead. Additional replaced concatenations with .append() --- .../contikios/cooja/plugins/RadioLogger.java | 6 ++-- .../plugins/analyzers/ICMPv6Analyzer.java | 14 ++++---- .../plugins/analyzers/IEEE802154Analyzer.java | 32 +++++++++++++------ .../plugins/analyzers/IPHCPacketAnalyzer.java | 27 ++++++++++------ .../plugins/analyzers/IPv6PacketAnalyzer.java | 10 +++--- .../plugins/analyzers/PacketAnalyzer.java | 2 +- 6 files changed, 56 insertions(+), 35 deletions(-) diff --git a/tools/cooja/java/org/contikios/cooja/plugins/RadioLogger.java b/tools/cooja/java/org/contikios/cooja/plugins/RadioLogger.java index 70eba23bb..546b66566 100644 --- a/tools/cooja/java/org/contikios/cooja/plugins/RadioLogger.java +++ b/tools/cooja/java/org/contikios/cooja/plugins/RadioLogger.java @@ -685,8 +685,8 @@ public class RadioLogger extends VisPlugin { return; } - StringBuffer brief = new StringBuffer(); - StringBuffer verbose = new StringBuffer(); + StringBuilder brief = new StringBuilder(); + StringBuilder verbose = new StringBuilder(); /* default analyzer */ PacketAnalyzer.Packet packet = new PacketAnalyzer.Packet(data, PacketAnalyzer.MAC_LEVEL); @@ -713,7 +713,7 @@ public class RadioLogger extends VisPlugin { } } - private boolean analyzePacket(PacketAnalyzer.Packet packet, StringBuffer brief, StringBuffer verbose) { + private boolean analyzePacket(PacketAnalyzer.Packet packet, StringBuilder brief, StringBuilder verbose) { if (analyzers == null) return false; try { boolean analyze = true; diff --git a/tools/cooja/java/org/contikios/cooja/plugins/analyzers/ICMPv6Analyzer.java b/tools/cooja/java/org/contikios/cooja/plugins/analyzers/ICMPv6Analyzer.java index 7b1d03fd0..e5b9f3681 100644 --- a/tools/cooja/java/org/contikios/cooja/plugins/analyzers/ICMPv6Analyzer.java +++ b/tools/cooja/java/org/contikios/cooja/plugins/analyzers/ICMPv6Analyzer.java @@ -39,8 +39,8 @@ public class ICMPv6Analyzer extends PacketAnalyzer { "ROUTER RENUMBER", "NODE INFORMATION QUERY", "NODE INFORMATION RESPONSE"}; @Override - public int analyzePacket(Packet packet, StringBuffer brief, - StringBuffer verbose) { + public int analyzePacket(Packet packet, StringBuilder brief, + StringBuilder verbose) { int type = packet.get(0) & 0xff; int code = packet.get(1) & 0xff; // int checksum = ((packet.get(2) & 0xff) << 8) | packet.get(3) & 0xff; @@ -69,11 +69,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: ").append(instanceID) + .append(", Version: ").append(version) + .append(", Rank: ").append(rank) + .append(", MOP: ").append(mop) + .append(", DTSN: ").append(dtsn); packet.consumeBytesStart(8); break; diff --git a/tools/cooja/java/org/contikios/cooja/plugins/analyzers/IEEE802154Analyzer.java b/tools/cooja/java/org/contikios/cooja/plugins/analyzers/IEEE802154Analyzer.java index ce94e8e14..68049c367 100644 --- a/tools/cooja/java/org/contikios/cooja/plugins/analyzers/IEEE802154Analyzer.java +++ b/tools/cooja/java/org/contikios/cooja/plugins/analyzers/IEEE802154Analyzer.java @@ -61,7 +61,7 @@ public class IEEE802154Analyzer extends PacketAnalyzer { */ @Override - public int analyzePacket(Packet packet, StringBuffer brief, StringBuffer verbose) { + public int analyzePacket(Packet packet, StringBuilder brief, StringBuilder verbose) { if (pcapExporter != null) { try { @@ -141,14 +141,16 @@ public class IEEE802154Analyzer extends PacketAnalyzer { verbose.append("
From "); if (srcPanID != 0) { - verbose.append(StringUtils.toHex((byte) (srcPanID >> 8))) + verbose.append("0x") + .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))) + verbose.append("0x") + .append(StringUtils.toHex((byte) (destPanID >> 8))) .append(StringUtils.toHex((byte) (destPanID & 0xff))) .append('/'); } @@ -169,14 +171,26 @@ public class IEEE802154Analyzer extends PacketAnalyzer { return ANALYSIS_OK_CONTINUE; } - private void printAddress(StringBuffer sb, int type, byte[] addr) { + private void printAddress(StringBuilder sb, int type, byte[] addr) { if (type == SHORT_ADDRESS) { - sb.append(StringUtils.toHex(addr)); + sb.append("0x").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])) + .append(':') + .append(StringUtils.toHex(addr[1])) + .append(':') + .append(StringUtils.toHex(addr[2])) + .append(':') + .append(StringUtils.toHex(addr[3])) + .append(':') + .append(StringUtils.toHex(addr[4])) + .append(':') + .append(StringUtils.toHex(addr[5])) + .append(':') + .append(StringUtils.toHex(addr[6])) + .append(':') + .append(StringUtils.toHex(addr[7])); + } } } diff --git a/tools/cooja/java/org/contikios/cooja/plugins/analyzers/IPHCPacketAnalyzer.java b/tools/cooja/java/org/contikios/cooja/plugins/analyzers/IPHCPacketAnalyzer.java index 7cbb97935..2a70fea6f 100644 --- a/tools/cooja/java/org/contikios/cooja/plugins/analyzers/IPHCPacketAnalyzer.java +++ b/tools/cooja/java/org/contikios/cooja/plugins/analyzers/IPHCPacketAnalyzer.java @@ -67,8 +67,8 @@ public class IPHCPacketAnalyzer extends PacketAnalyzer { } @Override - public int analyzePacket(Packet packet, StringBuffer brief, - StringBuffer verbose) { + public int analyzePacket(Packet packet, StringBuilder brief, + StringBuilder verbose) { /* if packet has less than 3 bytes it is not interesting ... */ if (packet.size() < 3) return ANALYSIS_FAILED; @@ -91,12 +91,18 @@ public class IPHCPacketAnalyzer extends PacketAnalyzer { /* need to decompress while analyzing - add that later... */ verbose.append("IPHC HC-06
"); - verbose.append("tf = " + tf + " nhc = " + nhc + " hlim = " + hlim - + " cid = " + cid + " sac = " + sac + " sam = " + sam - + " MCast = " + m + " dac = " + dac + " dam = " + dam); + verbose.append("TF = ").append(tf) + .append(", NH = ").append(nhc) + .append(", HLIM = ").append(hlim) + .append(", CID = ").append(cid) + .append(", SAC = ").append(sac) + .append(", SAM = ").append(sam) + .append(", MCast = ").append(m) + .append(", DAC = ").append(dac) + .append(", DAM = ").append(dam); if (cid == 1) { - verbose.append("
Contexts: sci=" + (packet.get(2) >> 4) + " dci=" - + (packet.get(2) & 0x0f)); + verbose.append("
Contexts: sci=").append(packet.get(2) >> 4). + append(" dci=").append(packet.get(2) & 0x0f); sci = packet.get(2) >> 4; dci = packet.get(2) & 0x0f; } @@ -412,8 +418,9 @@ public class IPHCPacketAnalyzer extends PacketAnalyzer { } verbose.append("
IPv6 ").append(protoStr) - .append(" TC = " + trafficClass - + " FL: " + flowLabel + "
"); + .append(" TC = ").append(trafficClass) + .append(" FL: ").append(flowLabel) + .append("
"); verbose.append("From "); printAddress(verbose, srcAddress); verbose.append(" to "); @@ -431,7 +438,7 @@ public class IPHCPacketAnalyzer extends PacketAnalyzer { } } - public static void printAddress(StringBuffer out, byte[] address) { + public static void printAddress(StringBuilder 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))); diff --git a/tools/cooja/java/org/contikios/cooja/plugins/analyzers/IPv6PacketAnalyzer.java b/tools/cooja/java/org/contikios/cooja/plugins/analyzers/IPv6PacketAnalyzer.java index 0dc34896e..0d33b0bd3 100644 --- a/tools/cooja/java/org/contikios/cooja/plugins/analyzers/IPv6PacketAnalyzer.java +++ b/tools/cooja/java/org/contikios/cooja/plugins/analyzers/IPv6PacketAnalyzer.java @@ -19,8 +19,8 @@ public class IPv6PacketAnalyzer extends PacketAnalyzer { } @Override - public int analyzePacket(Packet packet, StringBuffer brief, - StringBuffer verbose) { + public int analyzePacket(Packet packet, StringBuilder brief, + StringBuilder verbose) { /* if packet has less than 40 bytes it is not interesting ... */ if (packet.size() < 40) return ANALYSIS_FAILED; @@ -57,8 +57,8 @@ public class IPv6PacketAnalyzer extends PacketAnalyzer { packet.pos += 41; verbose.append("
IPv6 ").append(protoStr) - .append(" TC = " + trafficClass - + " FL: " + flowLabel + "
"); + .append(" TC = ").append(trafficClass) + .append(" FL: ").append(flowLabel).append("
"); verbose.append("From "); printAddress(verbose, srcAddress); verbose.append(" to "); @@ -69,7 +69,7 @@ public class IPv6PacketAnalyzer extends PacketAnalyzer { return ANALYSIS_OK_CONTINUE; } - public static void printAddress(StringBuffer out, byte[] address) { + public static void printAddress(StringBuilder 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))); diff --git a/tools/cooja/java/org/contikios/cooja/plugins/analyzers/PacketAnalyzer.java b/tools/cooja/java/org/contikios/cooja/plugins/analyzers/PacketAnalyzer.java index 73549cce3..3be8a8284 100644 --- a/tools/cooja/java/org/contikios/cooja/plugins/analyzers/PacketAnalyzer.java +++ b/tools/cooja/java/org/contikios/cooja/plugins/analyzers/PacketAnalyzer.java @@ -83,5 +83,5 @@ public abstract class PacketAnalyzer { public abstract boolean matchPacket(Packet packet); - public abstract int analyzePacket(Packet packet, StringBuffer brief, StringBuffer verbose); + public abstract int analyzePacket(Packet packet, StringBuilder brief, StringBuilder verbose); } From dbebd123a52ce619344ddd4c779f3a0ce9150fa2 Mon Sep 17 00:00:00 2001 From: Enrico Joerns Date: Wed, 18 Jun 2014 19:21:13 +0200 Subject: [PATCH 04/12] [cooja] plugins/analyzers/IEEE802154Analyzer: More verbose printout including FCF information --- .../plugins/analyzers/IEEE802154Analyzer.java | 88 +++++++++++-------- 1 file changed, 52 insertions(+), 36 deletions(-) diff --git a/tools/cooja/java/org/contikios/cooja/plugins/analyzers/IEEE802154Analyzer.java b/tools/cooja/java/org/contikios/cooja/plugins/analyzers/IEEE802154Analyzer.java index 68049c367..74408b363 100644 --- a/tools/cooja/java/org/contikios/cooja/plugins/analyzers/IEEE802154Analyzer.java +++ b/tools/cooja/java/org/contikios/cooja/plugins/analyzers/IEEE802154Analyzer.java @@ -7,20 +7,22 @@ import org.contikios.cooja.util.StringUtils; public class IEEE802154Analyzer extends PacketAnalyzer { - /* TODO: fix this to be correct */ + // Addressing modes public static final int NO_ADDRESS = 0; public static final int RSV_ADDRESS = 1; public static final int SHORT_ADDRESS = 2; public static final int LONG_ADDRESS = 3; + // Frame types public static final int BEACONFRAME = 0x00; public static final int DATAFRAME = 0x01; 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 String[] typeS = {"-", "D", "A"}; - private static final String[] typeVerbose = {"BEACON", "DATA", "ACK"}; + private static final String[] typeS = {"-", "D", "A", "C"}; + private static final String[] typeVerbose = {"BEACON", "DATA", "ACK", "CMD"}; + private static final String[] addrModeNames = {"None", "Reserved", "Short", "Long"}; private PcapExporter pcapExporter; // private int defaultAddressMode = LONG_ADDRESS; @@ -73,15 +75,18 @@ public class IEEE802154Analyzer extends PacketAnalyzer { } 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 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; + // FCF field + int fcfType = packet.data[pos + 0] & 0x07; + boolean fcfSecurity = ((packet.data[pos + 0] >> 3) & 0x01) != 0; + boolean fcfPending = ((packet.data[pos + 0] >> 4) & 0x01) != 0; + boolean fcfAckRequested = ((packet.data[pos + 0] >> 5) & 0x01) != 0; + boolean fcfIntraPAN = ((packet.data[pos + 0] >> 6) & 0x01) != 0; + int fcfDestAddrMode = (packet.data[pos + 1] >> 2) & 0x03; + int fcfFrameVersion = (packet.data[pos + 1] >> 4) & 0x03; + int fcfSrcAddrMode = (packet.data[pos + 1] >> 6) & 0x03; + // Sequence number int seqNumber = packet.data[pos + 2] & 0xff; + // Addressing Fields int destPanID = 0; int srcPanID = 0; byte[] sourceAddress = null; @@ -89,15 +94,15 @@ public class IEEE802154Analyzer extends PacketAnalyzer { pos += 3; - if (destAddrMode > 0) { + if (fcfDestAddrMode > 0) { destPanID = (packet.data[pos] & 0xff) + ((packet.data[pos + 1] & 0xff) << 8); pos += 2; - if (destAddrMode == SHORT_ADDRESS) { + if (fcfDestAddrMode == SHORT_ADDRESS) { destAddress = new byte[2]; destAddress[1] = packet.data[pos]; destAddress[0] = packet.data[pos + 1]; pos += 2; - } else if (destAddrMode == LONG_ADDRESS) { + } else if (fcfDestAddrMode == LONG_ADDRESS) { destAddress = new byte[8]; for (int i = 0; i < 8; i++) { destAddress[i] = packet.data[pos + 7 - i]; @@ -106,19 +111,19 @@ public class IEEE802154Analyzer extends PacketAnalyzer { } } - if (srcAddrMode > 0) { - if (panCompression == 0) { + if (fcfSrcAddrMode > 0) { + if (fcfIntraPAN) { + srcPanID = destPanID; + } else { srcPanID = (packet.data[pos] & 0xff) + ((packet.data[pos + 1] & 0xff) << 8); pos += 2; - } else { - srcPanID = destPanID; } - if (srcAddrMode == SHORT_ADDRESS) { + if (fcfSrcAddrMode == SHORT_ADDRESS) { sourceAddress = new byte[2]; sourceAddress[1] = packet.data[pos]; sourceAddress[0] = packet.data[pos + 1]; pos += 2; - } else if (srcAddrMode == LONG_ADDRESS) { + } else if (fcfSrcAddrMode == LONG_ADDRESS) { sourceAddress = new byte[8]; for (int i = 0; i < 8; i++) { sourceAddress[i] = packet.data[pos + 7 - i]; @@ -129,24 +134,25 @@ public class IEEE802154Analyzer extends PacketAnalyzer { // int payloadLen = packet.data.length - pos; brief.append("15.4 "); - brief.append(type < typeS.length ? typeS[type] : "?").append(' '); + brief.append(fcfType < typeS.length ? typeS[fcfType] : "?").append(' '); verbose.append("IEEE 802.15.4 ") - .append(type < typeVerbose.length ? typeVerbose[type] : "?") - .append(' ').append(seqNumber); - if (type != ACKFRAME) { - printAddress(brief, srcAddrMode, sourceAddress); - brief.append(' '); - printAddress(brief, destAddrMode, destAddress); + .append(fcfType < typeVerbose.length ? typeVerbose[fcfType] : "?") + .append(" #").append(seqNumber); - verbose.append("
From "); + if (fcfType != ACKFRAME) { + printAddress(brief, fcfSrcAddrMode, sourceAddress); + brief.append(' '); + printAddress(brief, fcfDestAddrMode, destAddress); + + verbose.append("
From "); if (srcPanID != 0) { verbose.append("0x") .append(StringUtils.toHex((byte) (srcPanID >> 8))) .append(StringUtils.toHex((byte) (srcPanID & 0xff))) .append('/'); } - printAddress(verbose, srcAddrMode, sourceAddress); + printAddress(verbose, fcfSrcAddrMode, sourceAddress); verbose.append(" to "); if (destPanID != 0) { verbose.append("0x") @@ -154,18 +160,28 @@ public class IEEE802154Analyzer extends PacketAnalyzer { .append(StringUtils.toHex((byte) (destPanID & 0xff))) .append('/'); } - printAddress(verbose, destAddrMode, destAddress); - } else { + printAddress(verbose, fcfDestAddrMode, destAddress); + } + + verbose.append("
Sec = ").append(fcfSecurity) + .append(", Pend = ").append(fcfPending) + .append(", ACK = ").append(fcfAckRequested) + .append(", iPAN = ").append(fcfIntraPAN) + .append(", DestAddr = ").append(addrModeNames[fcfDestAddrMode]) + .append(", Vers. = ").append(fcfFrameVersion) + .append(", SrcAddr = ").append(addrModeNames[fcfSrcAddrMode]); + + /* update packet */ + packet.pos = pos; + /* remove CRC from the packet */ + packet.consumeBytesEnd(2); + + if (fcfType == ACKFRAME) { /* got ack - no more to do ... */ return ANALYSIS_OK_FINAL; } - /* update packet */ - packet.pos = pos; packet.level = NETWORK_LEVEL; - /* remove CRC from the packet */ - packet.consumeBytesEnd(2); - packet.llsender = sourceAddress; packet.llreceiver = destAddress; return ANALYSIS_OK_CONTINUE; From 9f70a6f3272e38224d40798aee4e4653a085b4d0 Mon Sep 17 00:00:00 2001 From: Enrico Joerns Date: Thu, 19 Jun 2014 04:21:23 +0200 Subject: [PATCH 05/12] [cooja] plugins/analyzers/IPHCPacketAnalyzer: fixed ttl encoding, addded hlim decoding --- .../plugins/analyzers/IPHCPacketAnalyzer.java | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/tools/cooja/java/org/contikios/cooja/plugins/analyzers/IPHCPacketAnalyzer.java b/tools/cooja/java/org/contikios/cooja/plugins/analyzers/IPHCPacketAnalyzer.java index 2a70fea6f..6d3665d32 100644 --- a/tools/cooja/java/org/contikios/cooja/plugins/analyzers/IPHCPacketAnalyzer.java +++ b/tools/cooja/java/org/contikios/cooja/plugins/analyzers/IPHCPacketAnalyzer.java @@ -76,6 +76,20 @@ public class IPHCPacketAnalyzer extends PacketAnalyzer { int tf = (packet.get(0) >> 3) & 0x03; boolean nhc = (packet.get(0) & SICSLOWPAN_IPHC_NH_C) > 0; int hlim = (packet.get(0) & 0x03); + switch (hlim) { + case 0x00: + hlim = 0; + break; + case 0x01: + hlim = 1; + break; + case 0x02: + hlim = 64; + break; + case 0x03: + hlim = 255; + break; + } int cid = (packet.get(1) >> 7) & 0x01; int sac = (packet.get(1) >> 6) & 0x01; int sam = (packet.get(1) >> 4) & 0x03; @@ -164,7 +178,7 @@ public class IPHCPacketAnalyzer extends PacketAnalyzer { ttl = 1; break; case SICSLOWPAN_IPHC_TTL_64: - ttl = 2; + ttl = 64; break; case SICSLOWPAN_IPHC_TTL_255: ttl = 255; From a88328c8db9f2e1f798c44e8c70445153d150615 Mon Sep 17 00:00:00 2001 From: Enrico Joerns Date: Thu, 19 Jun 2014 04:22:31 +0200 Subject: [PATCH 06/12] [cooja] plugins/analyzers/PacketAnalyzer: Fixed integer assembly from bytes in getInt() method --- .../org/contikios/cooja/plugins/analyzers/PacketAnalyzer.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/cooja/java/org/contikios/cooja/plugins/analyzers/PacketAnalyzer.java b/tools/cooja/java/org/contikios/cooja/plugins/analyzers/PacketAnalyzer.java index 3be8a8284..7f4002960 100644 --- a/tools/cooja/java/org/contikios/cooja/plugins/analyzers/PacketAnalyzer.java +++ b/tools/cooja/java/org/contikios/cooja/plugins/analyzers/PacketAnalyzer.java @@ -55,7 +55,7 @@ public abstract class PacketAnalyzer { public int getInt(int index, int size) { int value = 0; for (int i = 0; i < size; i++) { - value = (value << 8) + get(index + i); + value = (value << 8) + (get(index + i) & 0xFF); } return value; } From 3b60d96f39bf99153e3183f1ed2a082958d7f1ee Mon Sep 17 00:00:00 2001 From: Enrico Joerns Date: Thu, 19 Jun 2014 04:26:30 +0200 Subject: [PATCH 07/12] [cooja] plugins/analyzers/IPHCPacketAnalyzer: Full port decompression for UDP header compression --- .../plugins/analyzers/IPHCPacketAnalyzer.java | 54 ++++++++++--------- 1 file changed, 30 insertions(+), 24 deletions(-) diff --git a/tools/cooja/java/org/contikios/cooja/plugins/analyzers/IPHCPacketAnalyzer.java b/tools/cooja/java/org/contikios/cooja/plugins/analyzers/IPHCPacketAnalyzer.java index 6d3665d32..786da0595 100644 --- a/tools/cooja/java/org/contikios/cooja/plugins/analyzers/IPHCPacketAnalyzer.java +++ b/tools/cooja/java/org/contikios/cooja/plugins/analyzers/IPHCPacketAnalyzer.java @@ -4,8 +4,10 @@ import org.contikios.cooja.util.StringUtils; public class IPHCPacketAnalyzer extends PacketAnalyzer { - public final static int SICSLOWPAN_UDP_PORT_MIN = 0xF0B0; - public final static int SICSLOWPAN_UDP_PORT_MAX = 0xF0BF; /* F0B0 + 15 */ + public final static int SICSLOWPAN_UDP_4_BIT_PORT_MIN = 0xF0B0; + public final static int SICSLOWPAN_UDP_4_BIT_PORT_MAX = 0xF0BF; /* F0B0 + 15 */ + public final static int SICSLOWPAN_UDP_8_BIT_PORT_MIN = 0xF000; + public final static int SICSLOWPAN_UDP_8_BIT_PORT_MAX = 0xF0FF; /* F000 + 255 */ public final static int SICSLOWPAN_DISPATCH_IPV6 = 0x41; /* 01000001 = 65 */ public final static int SICSLOWPAN_DISPATCH_HC1 = 0x42; /* 01000010 = 66 */ @@ -44,8 +46,10 @@ public class IPHCPacketAnalyzer extends PacketAnalyzer { private static final int SICSLOWPAN_NDC_UDP_MASK = 0xf8; private static final int SICSLOWPAN_NHC_UDP_ID = 0xf0; - private static final int SICSLOWPAN_NHC_UDP_C = 0xf3; - private static final int SICSLOWPAN_NHC_UDP_I = 0xf0; + private static final int SICSLOWPAN_NHC_UDP_00 = 0xf0; + private static final int SICSLOWPAN_NHC_UDP_01 = 0xf1; + private static final int SICSLOWPAN_NHC_UDP_10 = 0xf2; + private static final int SICSLOWPAN_NHC_UDP_11 = 0xf3; public final static int PROTO_UDP = 17; public final static int PROTO_TCP = 6; @@ -373,29 +377,31 @@ public class IPHCPacketAnalyzer extends PacketAnalyzer { /* The next header is compressed, NHC is following */ if ((packet.get(hc06_ptr) & SICSLOWPAN_NDC_UDP_MASK) == SICSLOWPAN_NHC_UDP_ID) { proto = PROTO_UDP; - 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); - destPort = SICSLOWPAN_UDP_PORT_MIN + (packet.get(hc06_ptr + 1) & 0x0F); -// memcpy(&SICSLOWPAN_UDP_BUF->udpchksum, hc06_ptr + 2, 2); -// PRINTF("IPHC: Uncompressed UDP ports (4): %x, %x\n", -// SICSLOWPAN_UDP_BUF->srcport, SICSLOWPAN_UDP_BUF->destport); - hc06_ptr += 4; - break; - case (byte) SICSLOWPAN_NHC_UDP_I: + switch (packet.get(hc06_ptr) & (byte) SICSLOWPAN_NHC_UDP_11) { + case (byte) SICSLOWPAN_NHC_UDP_00: /* 1 byte for NHC, 4 byte for ports, 2 bytes chksum */ - srcPort = packet.getInt(hc06_ptr + 1, 2); - destPort = packet.getInt(hc06_ptr + 3, 2); -// memcpy(&SICSLOWPAN_UDP_BUF->udpchksum, hc06_ptr + 5, 2); -// PRINTF("IPHC: Uncompressed UDP ports (7): %x, %x\n", -// SICSLOWPAN_UDP_BUF->srcport, SICSLOWPAN_UDP_BUF->destport); - + srcPort = packet.getInt(hc06_ptr + 1, 2) & 0xFFFF; + destPort = packet.getInt(hc06_ptr + 3, 2) & 0xFFFF; hc06_ptr += 7; break; - default: -// PRINTF("sicslowpan uncompress_hdr: error unsupported UDP compression\n"); - return ANALYSIS_FAILED; + case (byte) SICSLOWPAN_NHC_UDP_01: + /* 1 byte for NHC, 3 byte for ports, 2 bytes chksum */ + srcPort = packet.getInt(hc06_ptr + 1, 2); + destPort = SICSLOWPAN_UDP_8_BIT_PORT_MIN + (packet.get(hc06_ptr + 3) & 0xFF); + hc06_ptr += 6; + break; + case (byte) SICSLOWPAN_NHC_UDP_10: + /* 1 byte for NHC, 3 byte for ports, 2 bytes chksum */ + srcPort = SICSLOWPAN_UDP_8_BIT_PORT_MIN + (packet.get(hc06_ptr + 1) & 0xFF); + destPort = packet.getInt(hc06_ptr + 2, 2); + hc06_ptr += 6; + break; + case (byte) SICSLOWPAN_NHC_UDP_11: + /* 1 byte for NHC, 1 byte for ports, 2 bytes chksum */ + srcPort = SICSLOWPAN_UDP_4_BIT_PORT_MIN + (packet.get(hc06_ptr + 1) >> 4); + destPort = SICSLOWPAN_UDP_4_BIT_PORT_MIN + (packet.get(hc06_ptr + 1) & 0x0F); + hc06_ptr += 4; + break; } } } From 5ee8c7e178faefa9aaf30e4f63698165d6192466 Mon Sep 17 00:00:00 2001 From: Enrico Joerns Date: Thu, 19 Jun 2014 04:28:37 +0200 Subject: [PATCH 08/12] [cooja] plugins/analyzers/IPHCPacketAnalyzer: Hack for basic Hop-by-hop extension header handling --- .../plugins/analyzers/IPHCPacketAnalyzer.java | 23 +++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/tools/cooja/java/org/contikios/cooja/plugins/analyzers/IPHCPacketAnalyzer.java b/tools/cooja/java/org/contikios/cooja/plugins/analyzers/IPHCPacketAnalyzer.java index 786da0595..800fdf848 100644 --- a/tools/cooja/java/org/contikios/cooja/plugins/analyzers/IPHCPacketAnalyzer.java +++ b/tools/cooja/java/org/contikios/cooja/plugins/analyzers/IPHCPacketAnalyzer.java @@ -12,8 +12,10 @@ public class IPHCPacketAnalyzer extends PacketAnalyzer { public final static int SICSLOWPAN_DISPATCH_IPV6 = 0x41; /* 01000001 = 65 */ public final static int SICSLOWPAN_DISPATCH_HC1 = 0x42; /* 01000010 = 66 */ public final static int SICSLOWPAN_DISPATCH_IPHC = 0x60; /* 011xxxxx = ... */ - public final static int SICSLOWPAN_DISPATCH_FRAG1 = 0xc0; /* 1100= 0xxx */ - public final static int SICSLOWPAN_DISPATCH_FRAGN = 0xe0; /* 1110= 0xxx */ + + public final static int EXT_HDR_HOP_BY_HOP = 0; + public final static int EXT_HDR_ROUTING = 43; + public final static int EXT_HDR_FRAGMENT = 44; /* * Values of fields within the IPHC encoding first byte @@ -404,6 +406,23 @@ public class IPHCPacketAnalyzer extends PacketAnalyzer { break; } } + } else { + // Skip extension header + // XXX TODO: Handle others, too? + if (proto == EXT_HDR_HOP_BY_HOP) { + proto = packet.get(hc06_ptr) & 0xFF; + + // header length is length specified in field, rounded up to 64 bit + int hdr_len = ((packet.get(hc06_ptr + 1) / 8) + 1) * 8; + hc06_ptr += hdr_len; + + // UDP hadling + if (proto == PROTO_UDP) { + srcPort = packet.getInt(hc06_ptr, 2) & 0xFFFF; + destPort = packet.getInt(hc06_ptr + 2, 2) & 0xFFFF; + hc06_ptr += 4; + } + } } // /* IP length field. */ From e556419e37569d5ea8a63fe74795d599683972c6 Mon Sep 17 00:00:00 2001 From: Enrico Joerns Date: Thu, 19 Jun 2014 04:29:49 +0200 Subject: [PATCH 09/12] [cooja] plugins/analyzers/IPHCPacketAnalyzer: More verbose output of IPHC options --- .../cooja/plugins/analyzers/IPHCPacketAnalyzer.java | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/tools/cooja/java/org/contikios/cooja/plugins/analyzers/IPHCPacketAnalyzer.java b/tools/cooja/java/org/contikios/cooja/plugins/analyzers/IPHCPacketAnalyzer.java index 800fdf848..a3576efac 100644 --- a/tools/cooja/java/org/contikios/cooja/plugins/analyzers/IPHCPacketAnalyzer.java +++ b/tools/cooja/java/org/contikios/cooja/plugins/analyzers/IPHCPacketAnalyzer.java @@ -99,7 +99,7 @@ public class IPHCPacketAnalyzer extends PacketAnalyzer { int cid = (packet.get(1) >> 7) & 0x01; int sac = (packet.get(1) >> 6) & 0x01; int sam = (packet.get(1) >> 4) & 0x03; - int m = (packet.get(1) >> 3) & 0x01; + boolean m = ((packet.get(1) >> 3) & 0x01) != 0; int dac = (packet.get(1) >> 2) & 0x01; int dam = packet.get(1) & 0x03; int sci = 0; @@ -112,13 +112,13 @@ public class IPHCPacketAnalyzer extends PacketAnalyzer { /* need to decompress while analyzing - add that later... */ verbose.append("IPHC HC-06
"); verbose.append("TF = ").append(tf) - .append(", NH = ").append(nhc) - .append(", HLIM = ").append(hlim) + .append(", NH = ").append(nhc ? "compressed" : "inline") + .append(", HLIM = ").append(hlim == 0 ? "inline" : hlim) .append(", CID = ").append(cid) - .append(", SAC = ").append(sac) + .append(", SAC = ").append(sac == 1 ? "stateless" : "stateful") .append(", SAM = ").append(sam) .append(", MCast = ").append(m) - .append(", DAC = ").append(dac) + .append(", DAC = ").append(dac == 1 ? "stateless" : "stateful") .append(", DAM = ").append(dam); if (cid == 1) { verbose.append("
Contexts: sci=").append(packet.get(2) >> 4). From ab0be0b150da4f9c3e0ca99bdf63f6f90fd19f3e Mon Sep 17 00:00:00 2001 From: Enrico Joerns Date: Thu, 19 Jun 2014 04:31:08 +0200 Subject: [PATCH 10/12] [cooja] plugins/analyzers/ICMPv6Analyzer: DTSN field is unsigned --- .../org/contikios/cooja/plugins/analyzers/ICMPv6Analyzer.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/cooja/java/org/contikios/cooja/plugins/analyzers/ICMPv6Analyzer.java b/tools/cooja/java/org/contikios/cooja/plugins/analyzers/ICMPv6Analyzer.java index e5b9f3681..10252da7a 100644 --- a/tools/cooja/java/org/contikios/cooja/plugins/analyzers/ICMPv6Analyzer.java +++ b/tools/cooja/java/org/contikios/cooja/plugins/analyzers/ICMPv6Analyzer.java @@ -67,7 +67,7 @@ public class ICMPv6Analyzer extends PacketAnalyzer { int version = packet.get(5) & 0xff; int rank = ((packet.get(6) & 0xff) << 8) + (packet.get(7) & 0xff); int mop = (packet.get(8) >> 3) & 0x07; - int dtsn = packet.get(9); + int dtsn = packet.get(9) & 0xFF; verbose.append(" InstanceID: ").append(instanceID) .append(", Version: ").append(version) From 70a44031bff17db909f6af155c9d6c217d703ca8 Mon Sep 17 00:00:00 2001 From: Enrico Joerns Date: Thu, 19 Jun 2014 04:33:44 +0200 Subject: [PATCH 11/12] [cooja] plugins/analyzers/ICMPv6Analyzer: Short names for ICMP types in brief output and more reader-friendly long names --- .../plugins/analyzers/ICMPv6Analyzer.java | 25 ++++++++++++------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/tools/cooja/java/org/contikios/cooja/plugins/analyzers/ICMPv6Analyzer.java b/tools/cooja/java/org/contikios/cooja/plugins/analyzers/ICMPv6Analyzer.java index 10252da7a..3dd1d80f6 100644 --- a/tools/cooja/java/org/contikios/cooja/plugins/analyzers/ICMPv6Analyzer.java +++ b/tools/cooja/java/org/contikios/cooja/plugins/analyzers/ICMPv6Analyzer.java @@ -32,11 +32,18 @@ public class ICMPv6Analyzer extends PacketAnalyzer { public static final int MTU_INFO = 5; 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"}; + "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 static final String[] BRIEF_TYPE_NAME = new String[]{ + "ECHO REQ", "ECHO RPLY", + "GRP QUERY", "GRP REPORT", "GRP REDUCTION", + "RS", "RA", + "NS", "NA", "REDIRECT", + "ROUTER RENUMBER", "NODE INFO QUERY", "NODE INFO RESP"}; @Override public int analyzePacket(Packet packet, StringBuilder brief, @@ -47,13 +54,13 @@ public class ICMPv6Analyzer extends PacketAnalyzer { brief.append("ICMPv6 "); if (type >= 128 && (type - 128) < TYPE_NAME.length) { - brief.append(TYPE_NAME[type - 128]).append(' ').append(code); - verbose.append("Type: ").append(TYPE_NAME[type - 128]); - verbose.append(" Code:").append(code); + brief.append(BRIEF_TYPE_NAME[type - 128]).append(' ').append(code); + verbose.append("
Type: ").append(TYPE_NAME[type - 128]); + verbose.append(", Code:").append(code); } else if (type == 155) { /* RPL */ brief.append("RPL "); - verbose.append("Type: RPL Code: "); + verbose.append("
Type: RPL Code: "); switch (code) { case RPL_CODE_DIS: brief.append("DIS"); From d894390f3ed8be1c8f9fd23789a5c7d094cb9c61 Mon Sep 17 00:00:00 2001 From: Enrico Joerns Date: Thu, 19 Jun 2014 04:38:19 +0200 Subject: [PATCH 12/12] [cooja] plugins/analyzers: printout of UDP ports and clearer layer separation --- .../plugins/analyzers/ICMPv6Analyzer.java | 1 + .../plugins/analyzers/IPHCPacketAnalyzer.java | 27 ++++++++++++++++--- 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/tools/cooja/java/org/contikios/cooja/plugins/analyzers/ICMPv6Analyzer.java b/tools/cooja/java/org/contikios/cooja/plugins/analyzers/ICMPv6Analyzer.java index 3dd1d80f6..29ea423c8 100644 --- a/tools/cooja/java/org/contikios/cooja/plugins/analyzers/ICMPv6Analyzer.java +++ b/tools/cooja/java/org/contikios/cooja/plugins/analyzers/ICMPv6Analyzer.java @@ -53,6 +53,7 @@ public class ICMPv6Analyzer extends PacketAnalyzer { // int checksum = ((packet.get(2) & 0xff) << 8) | packet.get(3) & 0xff; brief.append("ICMPv6 "); + verbose.append("ICMPv6"); if (type >= 128 && (type - 128) < TYPE_NAME.length) { brief.append(BRIEF_TYPE_NAME[type - 128]).append(' ').append(code); verbose.append("
Type: ").append(TYPE_NAME[type - 128]); diff --git a/tools/cooja/java/org/contikios/cooja/plugins/analyzers/IPHCPacketAnalyzer.java b/tools/cooja/java/org/contikios/cooja/plugins/analyzers/IPHCPacketAnalyzer.java index a3576efac..b6121c6ce 100644 --- a/tools/cooja/java/org/contikios/cooja/plugins/analyzers/IPHCPacketAnalyzer.java +++ b/tools/cooja/java/org/contikios/cooja/plugins/analyzers/IPHCPacketAnalyzer.java @@ -454,17 +454,36 @@ public class IPHCPacketAnalyzer extends PacketAnalyzer { protoStr = "UDP"; } else if (proto == PROTO_TCP) { protoStr = "TCP"; + } else { + protoStr = String.valueOf(proto); } - verbose.append("
IPv6 ").append(protoStr) - .append(" TC = ").append(trafficClass) - .append(" FL: ").append(flowLabel) + // IPv6 Information + + brief.append("|IPv6"); + verbose.append("
IPv6") + .append(" TC = ").append(trafficClass) + .append(", FL = ").append(flowLabel) .append("
"); verbose.append("From "); printAddress(verbose, srcAddress); verbose.append(" to "); printAddress(verbose, destAddress); - if (error != null) verbose.append(" " + error); + if (error != null) { + verbose.append(" ").append(error); + } + + // Application Layer Information + + if (proto != PROTO_ICMP) { + brief.append('|').append(protoStr); + verbose.append("
").append(protoStr).append(""); + } + if (proto == PROTO_UDP) { + brief.append(' ').append(srcPort).append(' ').append(destPort); + verbose.append("
Src Port: ").append(srcPort); + verbose.append(", Dst Port: ").append(destPort); + } packet.lastDispatch = (byte) (proto & 0xff); if (proto == PROTO_UDP || proto == PROTO_ICMP