mirror of
https://github.com/oliverschmidt/contiki.git
synced 2024-08-30 04:29:11 +00:00
Merge pull request #475 from cetic/cooja-radiologger-pcap
Allow user configuration of RadioLogger pcap file
This commit is contained in:
commit
189b1535e9
@ -144,6 +144,8 @@ public class RadioLogger extends VisPlugin {
|
|||||||
private HashMap<String,Action> analyzerMap = new HashMap<String,Action>();
|
private HashMap<String,Action> analyzerMap = new HashMap<String,Action>();
|
||||||
private String analyzerName = null;
|
private String analyzerName = null;
|
||||||
private ArrayList<PacketAnalyzer> analyzers = null;
|
private ArrayList<PacketAnalyzer> analyzers = null;
|
||||||
|
private IEEE802154Analyzer analyzerWithPcap;
|
||||||
|
private File pcapFile;
|
||||||
|
|
||||||
private JTextField searchField = new JTextField(30);
|
private JTextField searchField = new JTextField(30);
|
||||||
|
|
||||||
@ -174,8 +176,9 @@ public class RadioLogger extends VisPlugin {
|
|||||||
lowpanAnalyzers.add(new IPv6PacketAnalyzer());
|
lowpanAnalyzers.add(new IPv6PacketAnalyzer());
|
||||||
lowpanAnalyzers.add(new ICMPv6Analyzer());
|
lowpanAnalyzers.add(new ICMPv6Analyzer());
|
||||||
|
|
||||||
|
analyzerWithPcap = new IEEE802154Analyzer(true);
|
||||||
ArrayList<PacketAnalyzer> lowpanAnalyzersPcap = new ArrayList<PacketAnalyzer>();
|
ArrayList<PacketAnalyzer> lowpanAnalyzersPcap = new ArrayList<PacketAnalyzer>();
|
||||||
lowpanAnalyzersPcap.add(new IEEE802154Analyzer(true));
|
lowpanAnalyzersPcap.add(analyzerWithPcap);
|
||||||
lowpanAnalyzersPcap.add(new IPHCPacketAnalyzer());
|
lowpanAnalyzersPcap.add(new IPHCPacketAnalyzer());
|
||||||
lowpanAnalyzersPcap.add(new IPv6PacketAnalyzer());
|
lowpanAnalyzersPcap.add(new IPv6PacketAnalyzer());
|
||||||
lowpanAnalyzersPcap.add(new ICMPv6Analyzer());
|
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;
|
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;
|
return true;
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package org.contikios.cooja.plugins.analyzers;
|
package org.contikios.cooja.plugins.analyzers;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.io.File;
|
||||||
|
|
||||||
import org.contikios.cooja.util.StringUtils;
|
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) {
|
public boolean matchPacket(Packet packet) {
|
||||||
return packet.level == MAC_LEVEL;
|
return packet.level == MAC_LEVEL;
|
||||||
}
|
}
|
||||||
|
@ -5,6 +5,7 @@ import java.io.FileInputStream;
|
|||||||
import java.io.FileOutputStream;
|
import java.io.FileOutputStream;
|
||||||
import java.io.FileWriter;
|
import java.io.FileWriter;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.io.File;
|
||||||
|
|
||||||
public class PcapExporter {
|
public class PcapExporter {
|
||||||
|
|
||||||
@ -13,8 +14,15 @@ public class PcapExporter {
|
|||||||
public PcapExporter() throws IOException {
|
public PcapExporter() throws IOException {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void openPcap() throws IOException {
|
public void openPcap(File pcapFile) throws IOException {
|
||||||
out = new DataOutputStream(new FileOutputStream("radiolog-" + System.currentTimeMillis() + ".pcap"));
|
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 */
|
/* pcap header */
|
||||||
out.writeInt(0xa1b2c3d4);
|
out.writeInt(0xa1b2c3d4);
|
||||||
out.writeShort(0x0002);
|
out.writeShort(0x0002);
|
||||||
@ -24,15 +32,17 @@ public class PcapExporter {
|
|||||||
out.writeInt(4096);
|
out.writeInt(4096);
|
||||||
out.writeInt(195); /* 195 for LINKTYPE_IEEE802_15_4 */
|
out.writeInt(195); /* 195 for LINKTYPE_IEEE802_15_4 */
|
||||||
out.flush();
|
out.flush();
|
||||||
System.out.println("Opened pcap file!");
|
System.out.println("Opened pcap file " + pcapFile);
|
||||||
}
|
}
|
||||||
public void closePcap() throws IOException {
|
public void closePcap() throws IOException {
|
||||||
out.close();
|
out.close();
|
||||||
|
out = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void exportPacketData(byte[] data) throws IOException {
|
public void exportPacketData(byte[] data) throws IOException {
|
||||||
if (out == null) {
|
if (out == null) {
|
||||||
openPcap();
|
/* pcap file never set, open default */
|
||||||
|
openPcap(null);
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
/* pcap packet header */
|
/* pcap packet header */
|
||||||
|
Loading…
Reference in New Issue
Block a user