Sub Headers

/**
 * Packet dump:
 * 
 * Ethernet:  ******* Ethernet (Eth) offset=0 length=14
 * Ethernet: 
 * Ethernet:      destination = 16-03-78-01-16-03
 * Ethernet:           source = 00-60-08-9F-B1-F3
 * Ethernet:         protocol = 0x800 (2048) [ip version 4]
 * Ethernet: 
 * ip4:  ******* ip4 (ip) offset=14 length=20
 * ip4: 
 * ip4:          version = 4
 * ip4:             hlen = 5 [*4 = 20 bytes]
 * ip4:            diffs = 0xC0 (192)
 * ip4:                    1100 00..  = [48] reserved bit: code point 48
 * ip4:                    .... ..0.  = [0] ECN bit: ECN capable transport: no
 * ip4:                    .... ...0  = [0] ECE bit: ECE-CE: no
 * ip4:           length = 468
 * ip4:            flags = 0x0 (0)
 * ip4:                    0..  = [0] reserved bit: not set
 * ip4:                    .0.  = [0] don't fragment: not set
 * ip4:                    ..0  = [0] more fragments: not set
 * ip4:               id = 0xE253 (57939)
 * ip4:           offset = 0
 * ip4:     time to live = 255 router hops
 * ip4:         protocol = 1 [icmp - internet message control protocol]
 * ip4:  header checksum = 0xAE96 (44694)
 * ip4:           source = 131.151.32.21
 * ip4:      destination = 131.151.1.59
 * ip4: 
 * icmp:  ******* icmp (icmp) offset=34 length=8
 * icmp: 
 * icmp:             type = 3 [destination unreachable]
 * icmp:             code = 3 [destination port unreachable]
 * icmp:         checksum = 0x2731 (10033)
 * icmp: 
 * icmp: + DestUnreachable: offset=4 length=4
 * icmp:         reserved = 0
 * icmp: 
 * ip4:  ******* ip4 (ip) offset=42 length=20
 * ip4: 
 * ip4:          version = 4
 * ip4:             hlen = 5 [*4 = 20 bytes]
 * ip4:            diffs = 0x0 (0)
 * ip4:                    0000 00..  = [0] reserved bit: not set
 * ip4:                    .... ..0.  = [0] ECN bit: ECN capable transport: no
 * ip4:                    .... ...0  = [0] ECE bit: ECE-CE: no
 * ip4:           length = 440
 * ip4:            flags = 0x2 (2)
 * ip4:                    0..  = [0] reserved bit: not set
 * ip4:                    .1.  = [1] don't fragment: set
 * ip4:                    ..0  = [0] more fragments: not set
 * ip4:               id = 0xCB91 (52113)
 * ip4:           offset = 0
 * ip4:     time to live = 254 router hops
 * ip4:         protocol = 17 [udp - unreliable datagram protocol]
 * ip4:  header checksum = 0x8724 (34596)
 * ip4:           source = 131.151.1.59
 * ip4:      destination = 131.151.32.21
 * ip4: 
 * udp:  ******* udp (udp) offset=62 length=8
 * udp: 
 * udp:           source = 7003
 * udp:      destination = 1792
 * udp:           length = 420
 * udp:         checksum = 44574
 * udp: 
 * payload:  ******* payload (data) offset=70 length=412
 * payload: 
 * payload: 0046: 382b3948 e09dbee8 00000001 00000001   8  +  9  H  \e0\9d\be\e8\0 \0 \0 \1 \0 \0 \0 \1 
 * payload: 0056: 00000002 01060000 00000034 00000072   \0 \0 \0 \2 \1 \6 \0 \0 \0 \0 \0 4  \0 \0 \0 r  
 * [truncated...]
 */
public void testIcmpDestUnreachable() {
	// Wireshark packet # 29 (1-based)
	PcapPacket packet = TestUtils.getPcapPacket("tests/test-afs.pcap", 29 - 1);
	
	Ip4 ip = new Ip4();
	Icmp icmp = new Icmp(); // Need an instance so we can check on sub header
	Icmp.DestinationUnreachable unreach = new Icmp.DestinationUnreachable();

	assertTrue(packet.hasHeader(Ethernet.ID));
	assertTrue(packet.hasHeader(Ip4.ID, 0)); // 1st IP header
	assertTrue(packet.hasHeader(icmp));
	assertTrue(icmp.hasSubHeader(IcmpType.DESTINATION_UNREACHABLE.getId()));
	assertTrue(icmp.hasSubHeader(unreach));
	assertTrue(packet.hasHeader(ip, 1)); // 2nd IP header
	assertTrue(packet.hasHeader(Udp.ID));
	assertTrue(packet.hasHeader(Payload.ID));

	// Check specific values
	assertEquals(3, icmp.type());
	assertEquals(3, icmp.code());
	assertEquals(0x2731, icmp.checksum());
	assertEquals(0, unreach.reserved());

	assertEquals(0x8724, ip.checksum());
	assertEquals(440, ip.length());

	// Devil's advocate
	assertFalse(icmp.hasSubHeader(IcmpType.ECHO_REPLY.getId()));
	assertFalse(icmp.hasSubHeader(IcmpType.PARAM_PROBLEM.getId()));

}

    PcapPacket packet = TestUtils.getPcapPacket("tests/test-afs.pcap", 29 - 1);  
tests/test-afs.pcap
	Ip4 ip = new Ip4();
	Icmp icmp = new Icmp(); // Need an instance so we can check on sub header
	Icmp.DestinationUnreachable unreach = new Icmp.DestinationUnreachable();
	assertTrue(packet.hasHeader(Ethernet.ID));
Ethernet.ID
	assertTrue(packet.hasHeader(Ip4.ID, 0)); // 1st IP header
	assertTrue(packet.hasHeader(icmp));

packet.hasHeader(Icmp.ID) && (packet.getHeader(icmp) != null)
	assertTrue(icmp.hasSubHeader(IcmpType.DESTINATION_UNREACHABLE.getId()));
	assertTrue(icmp.hasSubHeader(unreach));
	assertTrue(packet.hasHeader(ip, 1)); // 2nd IP header
	assertTrue(packet.hasHeader(Udp.ID));
	assertTrue(packet.hasHeader(Payload.ID));
JBuffer
	// Check specific values
	assertEquals(3, icmp.type());
	assertEquals(3, icmp.code());
	assertEquals(0x2731, icmp.checksum());
	assertEquals(0, unreach.reserved());

	assertEquals(0x8724, ip.checksum());
	assertEquals(440, ip.length());
	assertFalse(icmp.hasSubHeader(IcmpType.ECHO_REPLY.getId()));
	assertFalse(icmp.hasSubHeader(IcmpType.PARAM_PROBLEM.getId()));
assertFalse