Allow user configuration of RadioLogger pcap file

This commit is contained in:
Laurent Deru 2013-11-25 14:22:33 +01:00
parent fa2dd5baec
commit 957be0a9be
3 changed files with 28 additions and 1 deletions

View file

@ -144,6 +144,8 @@ public class RadioLogger extends VisPlugin {
private HashMap<String,Action> analyzerMap = new HashMap<String,Action>();
private String analyzerName = null;
private ArrayList<PacketAnalyzer> analyzers = null;
private IEEE802154Analyzer analyzerWithPcap;
private File pcapFile;
private JTextField searchField = new JTextField(30);
@ -174,8 +176,9 @@ public class RadioLogger extends VisPlugin {
lowpanAnalyzers.add(new IPv6PacketAnalyzer());
lowpanAnalyzers.add(new ICMPv6Analyzer());
analyzerWithPcap = new IEEE802154Analyzer(true);
ArrayList<PacketAnalyzer> lowpanAnalyzersPcap = new ArrayList<PacketAnalyzer>();
lowpanAnalyzersPcap.add(new IEEE802154Analyzer(true));
lowpanAnalyzersPcap.add(analyzerWithPcap);
lowpanAnalyzersPcap.add(new IPHCPacketAnalyzer());
lowpanAnalyzersPcap.add(new IPv6PacketAnalyzer());
lowpanAnalyzersPcap.add(new ICMPv6Analyzer());
@ -801,6 +804,14 @@ public class RadioLogger extends VisPlugin {
}
}
if (pcapFile != null) {
element = new Element("pcap_file");
File file = simulation.getCooja().createPortablePath(pcapFile);
element.setText(pcapFile.getPath().replaceAll("\\\\", "/"));
element.setAttribute("EXPORT", "discard");
config.add(element);
}
return config;
}
@ -833,6 +844,9 @@ public class RadioLogger extends VisPlugin {
}
});
}
} else if (name.equals("pcap_file")) {
pcapFile = simulation.getCooja().restorePortablePath(new File(element.getText()));
analyzerWithPcap.setPcapFile(pcapFile);
}
}
return true;

View file

@ -1,6 +1,7 @@
package org.contikios.cooja.plugins.analyzers;
import java.io.IOException;
import java.io.File;
import org.contikios.cooja.util.StringUtils;
@ -36,6 +37,17 @@ public class IEEE802154Analyzer extends PacketAnalyzer {
}
}
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;
}

View file

@ -41,6 +41,7 @@ public class PcapExporter {
public void exportPacketData(byte[] data) throws IOException {
if (out == null) {
/* pcap file never set, open default */
openPcap(null);
}
try {