use of org.eclipse.tracecompass.internal.tmf.pcap.core.event.PcapRootEventField in project tracecompass by tracecompass.
the class PcapEventFieldTest method setUp.
/**
* Initialize the Packet and the Event.
*
* @throws BadPcapFileException
* Thrown when the pcap file is erroneous.
* @throws IOException
* Thrown when an IO error occurs.
* @throws BadPacketException
* Thrown when the packet is erroneous.
*/
@BeforeClass
public static void setUp() throws IOException, BadPcapFileException, BadPacketException {
ByteBuffer bb = ByteBuffer.allocate(25);
bb.order(ByteOrder.BIG_ENDIAN);
// Version + IHL
bb.put((byte) 0x46);
// DSCP + ECN
bb.put((byte) 0x9A);
// Total length - this is randomly chosen so that we verify that the
// packet handles wrong total length.
bb.put((byte) 0x00);
bb.put((byte) 0xFF);
// Identification
bb.put((byte) 0x0F);
bb.put((byte) 0xF0);
// Flags + Fragment Offset
bb.put((byte) 0x1E);
bb.put((byte) 0xE1);
// Time to live
bb.put((byte) 0xA0);
// Protocol - Unknown
bb.put((byte) 0xFE);
// Header checksum - chosen randomly
bb.put((byte) 0x33);
bb.put((byte) 0x44);
// Source IP - 4 bytes
bb.put((byte) 192);
bb.put((byte) 168);
bb.put((byte) 1);
bb.put((byte) 0);
// Destination IP - 4 bytes
bb.put((byte) 193);
bb.put((byte) 169);
bb.put((byte) 2);
bb.put((byte) 1);
// Options - 4 bytes
bb.put((byte) 0xA2);
bb.put((byte) 0x56);
bb.put((byte) 0xA2);
bb.put((byte) 0x56);
// Payload - 1 byte
bb.put((byte) 0xA6);
bb.flip();
PcapTestTrace trace = PcapTestTrace.MOSTLY_TCP;
assumeTrue(trace.exists());
try (PcapFile file = trace.getTrace()) {
IPv4Packet packet = new IPv4Packet(file, null, bb);
ITmfEventField[] fieldArray = generatePacketFields(packet);
fRegularField = new PcapEventField("Regular Field", EMPTY_STRING, fieldArray, packet);
fRootField = new PcapRootEventField(fieldArray, packet);
}
}
use of org.eclipse.tracecompass.internal.tmf.pcap.core.event.PcapRootEventField 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