Search in sources :

Example 6 with PcapEvent

use of org.eclipse.tracecompass.internal.tmf.pcap.core.event.PcapEvent 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);
}
Also used : Path(java.nio.file.Path) PcapRootEventField(org.eclipse.tracecompass.internal.tmf.pcap.core.event.PcapRootEventField) Packet(org.eclipse.tracecompass.internal.pcap.core.packet.Packet) PcapPacket(org.eclipse.tracecompass.internal.pcap.core.protocol.pcap.PcapPacket) PcapEventType(org.eclipse.tracecompass.internal.tmf.pcap.core.event.PcapEventType) PcapEvent(org.eclipse.tracecompass.internal.tmf.pcap.core.event.PcapEvent) PcapTimestampScale(org.eclipse.tracecompass.internal.pcap.core.util.PcapTimestampScale) ITmfEventField(org.eclipse.tracecompass.tmf.core.event.ITmfEventField) ITmfTimestamp(org.eclipse.tracecompass.tmf.core.timestamp.ITmfTimestamp) NonNull(org.eclipse.jdt.annotation.NonNull) TmfEventType(org.eclipse.tracecompass.tmf.core.event.TmfEventType) Nullable(org.eclipse.jdt.annotation.Nullable)

Aggregations

PcapEvent (org.eclipse.tracecompass.internal.tmf.pcap.core.event.PcapEvent)6 Nullable (org.eclipse.jdt.annotation.Nullable)4 TmfPcapProtocol (org.eclipse.tracecompass.internal.tmf.pcap.core.protocol.TmfPcapProtocol)3 Path (java.nio.file.Path)1 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)1 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)1 NonNull (org.eclipse.jdt.annotation.NonNull)1 Packet (org.eclipse.tracecompass.internal.pcap.core.packet.Packet)1 PcapPacket (org.eclipse.tracecompass.internal.pcap.core.protocol.pcap.PcapPacket)1 PcapTimestampScale (org.eclipse.tracecompass.internal.pcap.core.util.PcapTimestampScale)1 PcapEventType (org.eclipse.tracecompass.internal.tmf.pcap.core.event.PcapEventType)1 PcapRootEventField (org.eclipse.tracecompass.internal.tmf.pcap.core.event.PcapRootEventField)1 ITmfEvent (org.eclipse.tracecompass.tmf.core.event.ITmfEvent)1 ITmfEventField (org.eclipse.tracecompass.tmf.core.event.ITmfEventField)1 TmfEventType (org.eclipse.tracecompass.tmf.core.event.TmfEventType)1 ITmfEventRequest (org.eclipse.tracecompass.tmf.core.request.ITmfEventRequest)1 TmfEventRequest (org.eclipse.tracecompass.tmf.core.request.TmfEventRequest)1 ITmfTimestamp (org.eclipse.tracecompass.tmf.core.timestamp.ITmfTimestamp)1 ITmfContext (org.eclipse.tracecompass.tmf.core.trace.ITmfContext)1 ITmfTrace (org.eclipse.tracecompass.tmf.core.trace.ITmfTrace)1