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");
}
}
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;
}
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;
}
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;
}
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;
}
Aggregations