Merge pull request #1502 from yatch/pr-radiologger
Fix timestamps of packets recorded in pcap files
This commit is contained in:
commit
728e417e04
5 changed files with 25 additions and 8 deletions
|
@ -71,6 +71,7 @@ public class Simulation extends Observable implements Runnable {
|
|||
private long speedLimitLastSimtime;
|
||||
private long speedLimitLastRealtime;
|
||||
|
||||
private long lastStartTime;
|
||||
private long currentSimulationTime = 0;
|
||||
|
||||
private String title = null;
|
||||
|
@ -248,7 +249,7 @@ public class Simulation extends Observable implements Runnable {
|
|||
}
|
||||
|
||||
public void run() {
|
||||
long lastStartTime = System.currentTimeMillis();
|
||||
lastStartTime = System.currentTimeMillis();
|
||||
logger.info("Simulation main loop started, system time: " + lastStartTime);
|
||||
isRunning = true;
|
||||
speedLimitLastRealtime = System.currentTimeMillis();
|
||||
|
@ -1075,6 +1076,16 @@ public class Simulation extends Observable implements Runnable {
|
|||
return currentSimulationTime / MILLISECOND;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the actual time value corresponding to an argument which
|
||||
* is a simulation time value in microseconds.
|
||||
*
|
||||
* @return Actual time (microseconds)
|
||||
*/
|
||||
public long convertSimTimeToActualTime(long simTime) {
|
||||
return simTime + lastStartTime * 1000;
|
||||
}
|
||||
|
||||
/**
|
||||
* Changes radio medium of this simulation to the given.
|
||||
*
|
||||
|
|
|
@ -694,8 +694,8 @@ public class RadioLogger extends VisPlugin {
|
|||
StringBuilder verbose = new StringBuilder();
|
||||
|
||||
/* default analyzer */
|
||||
PacketAnalyzer.Packet packet = new PacketAnalyzer.Packet(data, PacketAnalyzer.MAC_LEVEL);
|
||||
|
||||
PacketAnalyzer.Packet packet = new PacketAnalyzer.Packet(data, PacketAnalyzer.MAC_LEVEL,
|
||||
simulation.convertSimTimeToActualTime(conn.startTime));
|
||||
if (analyzePacket(packet, brief, verbose)) {
|
||||
if (packet.hasMoreData()) {
|
||||
byte[] payload = packet.getPayload();
|
||||
|
|
|
@ -69,7 +69,7 @@ public class IEEE802154Analyzer extends PacketAnalyzer {
|
|||
|
||||
if (pcapExporter != null) {
|
||||
try {
|
||||
pcapExporter.exportPacketData(packet.getPayload());
|
||||
pcapExporter.exportPacketData(packet.getPayload(), packet.getTimestamp());
|
||||
} catch (IOException e) {
|
||||
logger.error("Could not export PCap data", e);
|
||||
}
|
||||
|
|
|
@ -18,6 +18,7 @@ public abstract class PacketAnalyzer {
|
|||
int level;
|
||||
/* size = length - consumed bytes at tail */
|
||||
int size;
|
||||
long ts; /* in microseconds */
|
||||
|
||||
/* L2 addresseses */
|
||||
byte[] llsender;
|
||||
|
@ -25,10 +26,11 @@ public abstract class PacketAnalyzer {
|
|||
|
||||
byte lastDispatch = 0;
|
||||
|
||||
public Packet(byte[] data, int level) {
|
||||
public Packet(byte[] data, int level, long ts) {
|
||||
this.level = level;
|
||||
this.data = data.clone();
|
||||
this.size = data.length;
|
||||
this.ts = ts;
|
||||
}
|
||||
|
||||
public void consumeBytesStart(int bytes) {
|
||||
|
@ -79,6 +81,10 @@ public abstract class PacketAnalyzer {
|
|||
public byte[] getLLReceiver() {
|
||||
return llreceiver;
|
||||
}
|
||||
|
||||
public long getTimestamp() {
|
||||
return ts;
|
||||
}
|
||||
};
|
||||
|
||||
public abstract boolean matchPacket(Packet packet);
|
||||
|
|
|
@ -41,15 +41,15 @@ public class PcapExporter {
|
|||
out = null;
|
||||
}
|
||||
|
||||
public void exportPacketData(byte[] data) throws IOException {
|
||||
public void exportPacketData(byte[] data, long ts) 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((int) (ts / 1000000));
|
||||
out.writeInt((int) (ts % 1000000));
|
||||
out.writeInt(data.length);
|
||||
out.writeInt(data.length);
|
||||
/* and the data */
|
||||
|
|
Loading…
Reference in a new issue