use of org.eclipse.tracecompass.internal.pcap.core.util.PcapTimestampScale in project tracecompass by tracecompass.
the class PcapEventFactory method createEvent.
/**
* Method that create a PcapEvent from a packet.
*
* @param pcapPacket
* The packet to generate the event from.
* @param pcap
* The pcap file to which the packet belongs.
* @param trace
* The trace to which this packet belongs.
* @return The generated PcapEvent.
*/
@Nullable
public static PcapEvent createEvent(PcapPacket pcapPacket, PcapFile pcap, PcapTrace trace) {
long rank = pcapPacket.getIndex();
long timestamp = pcapPacket.getTimestamp();
PcapTimestampScale scale = pcapPacket.getTimestampScale();
ITmfTimestamp tmfTimestamp;
switch(scale) {
case MICROSECOND:
long us = trace.getTimestampTransform().transform(timestamp * 1000) / 1000;
tmfTimestamp = TmfTimestamp.fromMicros(us);
break;
case NANOSECOND:
long ns = trace.getTimestampTransform().transform(timestamp);
tmfTimestamp = TmfTimestamp.fromNanos(ns);
break;
default:
// $NON-NLS-1$
throw new IllegalArgumentException("The timestamp precision is not valid!");
}
Path filePath = pcap.getPath().getFileName();
@NonNull String fileName = (filePath == null ? EMPTY_STRING : checkNotNull(filePath.toString()));
String dataLink = Messages.PcapEventFactory_LinkType + ':' + LinkTypeHelper.toString((int) pcapPacket.getDataLinkType());
ITmfEventField[] fields = generatePacketFields(pcapPacket);
ITmfEventField field = new PcapRootEventField(fields, pcapPacket);
Packet packet = pcapPacket.getMostEcapsulatedPacket();
if (!fEventTypes.containsKey(packet.getProtocol())) {
String typeIdString = PcapEventType.DEFAULT_PCAP_TYPE_ID + ':' + packet.getProtocol().getShortName();
fEventTypes.put(packet.getProtocol(), new PcapEventType(typeIdString, null));
}
TmfEventType eventType = fEventTypes.get(packet.getProtocol());
if (eventType == null) {
eventType = new TmfEventType();
}
return new PcapEvent(trace, rank, tmfTimestamp, dataLink, eventType, field, fileName, packet);
}
Aggregations