Search in sources :

Example 1 with Packet

use of org.eclipse.tracecompass.internal.pcap.core.packet.Packet in project tracecompass by tracecompass.

the class PacketTest method GenericPacketTest.

/**
 * Test that verify the correctness of the Packet's methods.
 * @throws BadPcapFileException
 *             Thrown when the file is erroneous. Fails the test.
 * @throws IOException
 *             Thrown when an IO error occurs. Fails the test.
 * @throws BadPacketException
 *             Thrown when a packet is erroneous. Fails the test.
 */
@Test
public void GenericPacketTest() throws BadPacketException, IOException, BadPcapFileException {
    PcapTestTrace trace = PcapTestTrace.MOSTLY_TCP;
    assumeTrue(trace.exists());
    // Get a right pcap/pcapNg trace
    try (PcapFile dummy = trace.getTrace()) {
        ByteBuffer byteBuffer = fEthernetPacket;
        if (byteBuffer == null) {
            fail("GenericPacketTest has failed!");
            return;
        }
        Packet packet = new EthernetIIPacket(dummy, null, byteBuffer);
        assertTrue(packet.hasProtocol(PcapProtocol.ETHERNET_II));
        assertTrue(packet.hasProtocol(PcapProtocol.UNKNOWN));
        assertFalse(packet.hasProtocol(PcapProtocol.TCP));
        assertEquals(PcapProtocol.ETHERNET_II, packet.getProtocol());
        assertEquals(packet, packet.getPacket(PcapProtocol.ETHERNET_II));
        assertNull(packet.getPacket(PcapProtocol.TCP));
        assertEquals(packet.getChildPacket(), packet.getPacket(PcapProtocol.UNKNOWN));
        assertEquals(packet.getPacket(PcapProtocol.ETHERNET_II), packet.getMostEcapsulatedPacket());
        assertNull(packet.getParentPacket());
        assertFalse(packet.getPcapFile().equals(null));
        Packet child = packet.getChildPacket();
        if (child == null) {
            fail("GenericPacketTest has failed!");
            return;
        }
        assertEquals(packet.getPayload(), child.getPayload());
        assertEquals(packet.getGlobalSummaryString(), "Source MAC: 10:f8:82:b3:44:78 , Destination MAC: 34:67:0c:d2:91:51");
    }
}
Also used : Packet(org.eclipse.tracecompass.internal.pcap.core.packet.Packet) EthernetIIPacket(org.eclipse.tracecompass.internal.pcap.core.protocol.ethernet2.EthernetIIPacket) EthernetIIPacket(org.eclipse.tracecompass.internal.pcap.core.protocol.ethernet2.EthernetIIPacket) PcapFile(org.eclipse.tracecompass.internal.pcap.core.trace.PcapFile) PcapTestTrace(org.eclipse.tracecompass.pcap.core.tests.shared.PcapTestTrace) ByteBuffer(java.nio.ByteBuffer) Test(org.junit.Test)

Example 2 with Packet

use of org.eclipse.tracecompass.internal.pcap.core.packet.Packet in project tracecompass by tracecompass.

the class EthernetIIPacket method hashCode.

@Override
public int hashCode() {
    final int prime = 31;
    int result = 1;
    final Packet child = fChildPacket;
    if (child != null) {
        result = prime * result + child.hashCode();
    } else {
        result = prime * result;
    }
    result = prime * result + Arrays.hashCode(fDestinationMacAddress);
    if (child == null) {
        result = prime * result + payloadHashCode(fPayload);
    }
    result = prime * result + Arrays.hashCode(fSourceMacAddress);
    result = prime * result + fType;
    return result;
}
Also used : IPv4Packet(org.eclipse.tracecompass.internal.pcap.core.protocol.ipv4.IPv4Packet) Packet(org.eclipse.tracecompass.internal.pcap.core.packet.Packet) UnknownPacket(org.eclipse.tracecompass.internal.pcap.core.protocol.unknown.UnknownPacket)

Example 3 with Packet

use of org.eclipse.tracecompass.internal.pcap.core.packet.Packet in project tracecompass by tracecompass.

the class EthernetIIPacket method toString.

@Override
public String toString() {
    String string = // $NON-NLS-1$
    getProtocol().getName() + ", Source: " + ConversionHelper.toMacAddress(fSourceMacAddress) + ", Destination: " + ConversionHelper.toMacAddress(fDestinationMacAddress) + // $NON-NLS-1$ //$NON-NLS-2$
    ", Type: " + EthertypeHelper.toEtherType(fType) + // $NON-NLS-1$
    "\n";
    final Packet child = fChildPacket;
    if (child != null) {
        return string + child.toString();
    }
    return string;
}
Also used : IPv4Packet(org.eclipse.tracecompass.internal.pcap.core.protocol.ipv4.IPv4Packet) Packet(org.eclipse.tracecompass.internal.pcap.core.packet.Packet) UnknownPacket(org.eclipse.tracecompass.internal.pcap.core.protocol.unknown.UnknownPacket)

Example 4 with Packet

use of org.eclipse.tracecompass.internal.pcap.core.packet.Packet in project tracecompass by tracecompass.

the class PcapPacket method toString.

@Override
public String toString() {
    // TODO Decide if first capture is 0 or 1. Right now, it is 0.
    String string = // $NON-NLS-1$
    getProtocol().getName() + " " + fPacketIndex + ": " + fOriginalLength + // $NON-NLS-1$ //$NON-NLS-2$
    " bytes on wire, " + fIncludedLength + // $NON-NLS-1$
    " bytes captured.\nArrival time: " + ConversionHelper.toGMTTime(fTimestamp, getTimestampScale()) + // $NON-NLS-1$
    "\n";
    final Packet child = fChildPacket;
    if (child != null) {
        return string + child.toString();
    }
    return string;
}
Also used : Packet(org.eclipse.tracecompass.internal.pcap.core.packet.Packet) UnknownPacket(org.eclipse.tracecompass.internal.pcap.core.protocol.unknown.UnknownPacket) EthernetIIPacket(org.eclipse.tracecompass.internal.pcap.core.protocol.ethernet2.EthernetIIPacket)

Example 5 with Packet

use of org.eclipse.tracecompass.internal.pcap.core.packet.Packet in project tracecompass by tracecompass.

the class PcapPacket method hashCode.

@Override
public int hashCode() {
    final int prime = 31;
    int result = 1;
    Packet child = fChildPacket;
    if (child == null) {
        result = prime * result;
    } else {
        result = prime * result + child.hashCode();
    }
    result = prime * result + (int) (fIncludedLength ^ (fIncludedLength >>> 32));
    result = prime * result + (int) (fOriginalLength ^ (fOriginalLength >>> 32));
    result = prime * result + (int) (fPacketIndex ^ (fPacketIndex >>> 32));
    if (child == null) {
        result = prime * result + payloadHashCode(fPayload);
    }
    result = prime * result + (int) (fTimestamp ^ (fTimestamp >>> 32));
    return result;
}
Also used : Packet(org.eclipse.tracecompass.internal.pcap.core.packet.Packet) UnknownPacket(org.eclipse.tracecompass.internal.pcap.core.protocol.unknown.UnknownPacket) EthernetIIPacket(org.eclipse.tracecompass.internal.pcap.core.protocol.ethernet2.EthernetIIPacket)

Aggregations

Packet (org.eclipse.tracecompass.internal.pcap.core.packet.Packet)26 UnknownPacket (org.eclipse.tracecompass.internal.pcap.core.protocol.unknown.UnknownPacket)10 Nullable (org.eclipse.jdt.annotation.Nullable)7 TmfPcapProtocol (org.eclipse.tracecompass.internal.tmf.pcap.core.protocol.TmfPcapProtocol)6 PcapProtocol (org.eclipse.tracecompass.internal.pcap.core.protocol.PcapProtocol)5 PcapPacket (org.eclipse.tracecompass.internal.pcap.core.protocol.pcap.PcapPacket)5 EthernetIIPacket (org.eclipse.tracecompass.internal.pcap.core.protocol.ethernet2.EthernetIIPacket)3 IPv4Packet (org.eclipse.tracecompass.internal.pcap.core.protocol.ipv4.IPv4Packet)3 ITmfEventField (org.eclipse.tracecompass.tmf.core.event.ITmfEventField)3 ByteBuffer (java.nio.ByteBuffer)2 ArrayList (java.util.ArrayList)2 Map (java.util.Map)2 TCPPacket (org.eclipse.tracecompass.internal.pcap.core.protocol.tcp.TCPPacket)2 UDPPacket (org.eclipse.tracecompass.internal.pcap.core.protocol.udp.UDPPacket)2 PcapFile (org.eclipse.tracecompass.internal.pcap.core.trace.PcapFile)2 PcapEventField (org.eclipse.tracecompass.internal.tmf.pcap.core.event.PcapEventField)2 TmfEventField (org.eclipse.tracecompass.tmf.core.event.TmfEventField)2 ImmutableList (com.google.common.collect.ImmutableList)1 IOException (java.io.IOException)1 Path (java.nio.file.Path)1