Packet.HeaderField
Modifier and Type | Field and Description |
---|---|
static int |
CKSUM_BYTES
The number of octets in IP checksum.
|
static byte |
IPV4_VERSION
The IPv4 version number.
|
Constructor and Description |
---|
IPv4()
Construct a new instance.
|
Modifier and Type | Method and Description |
---|---|
IPv4 |
clone()
Return a deep copy of this packet.
|
protected boolean |
equalsField(String name,
byte[] value1,
byte[] value2)
Compare the given header field values.
|
short |
getChecksum()
Gets the checksum value stored.
|
Ip4Network |
getDestinationAddress()
Gets the destination IP address stored.
|
byte |
getDiffServ()
Gets the differential services value stored.
|
byte |
getECN()
Gets the ECN bits stored.
|
protected int |
getFieldNumBits(String name,
Packet.HeaderField entry)
Gets the number of bits for the specified field.
|
byte |
getFlags()
Gets the flag values stored.
|
short |
getFragmentOffset()
Gets the fragment offset stored.
|
protected Map<String,Packet.HeaderField> |
getHeaderFormat()
Return a map that determines the format of the packet.
|
int |
getHeaderLen()
Gets the IP header length stored.
|
int |
getHeaderSize()
Gets the header size in bits.
|
short |
getIdentification()
Gets the identification value stored.
|
byte[] |
getOptions()
Gets the Options stored.
|
byte |
getProtocol()
Gets the protocol value stored.
|
Ip4Network |
getSourceAddress()
Gets the source IP address stored.
|
short |
getTotalLength()
Gets the total length of the IPv4 packe in bytes.
|
byte |
getTtl()
Gets the TTL value stored.
|
byte |
getVersion()
Gets the IP version stored.
|
protected void |
postDeserializeCustomOperation(byte[] data,
int offset)
This method re-computes the checksum of the bits received on the wire
and validates it with the checksum in the bits received.
|
protected void |
postSerializeCustomOperation(byte[] myBytes)
This method gets called at the end of the serialization process.
|
IPv4 |
setChecksum(short cksum)
Set the IP checksum value.
|
IPv4 |
setDestinationAddress(Ip4Network addr)
Stores the IP destination address from the header.
|
IPv4 |
setDiffServ(byte dserv)
Stores the differential services value from the IP header.
|
IPv4 |
setECN(byte ecn)
Stores the ECN bits from the header.
|
IPv4 |
setFlags(byte flags)
Stores the IP flags value.
|
IPv4 |
setFragmentOffset(short off)
Stores the IP fragmentation offset value.
|
protected void |
setHeaderField(String name,
byte[] value)
Stores the value of fields read from data stream.
|
IPv4 |
setHeaderLength(byte len)
Stores the length of IP header in words (4 bytes).
|
IPv4 |
setIdentification(short id)
Stores the identification number from the header.
|
IPv4 |
setOptions(byte[] options)
Store the options from IP header.
|
void |
setPayload(Packet p)
Set the packet encapsulated by this IPv4 packet.
|
IPv4 |
setProtocol(byte proto)
Stores the protocol value of the IP payload.
|
IPv4 |
setSourceAddress(Ip4Network addr)
Stores the IP source address from the header.
|
IPv4 |
setTotalLength(short len)
Stores the total length of IPv4 packet in bytes.
|
IPv4 |
setTtl(byte ttl)
Stores the TTL value.
|
IPv4 |
setVersion(byte version)
Stores the IP version from the header.
|
deserialize, equals, getByte, getBytes, getFieldNumBits, getFieldOffset, getFieldOffset, getHeaderFieldMap, getInt, getIp4Network, getPayload, getRawPayload, getRawPayloadSize, getShort, hashCode, isCorrupted, isZeroShort, serialize, setCorrupted, setPayloadClass, setRawPayload, toString
public static final byte IPV4_VERSION
public static final int CKSUM_BYTES
public IPv4()
This constructor sets the version to 4, headerLength to 5, and flags to 2.
public byte getVersion()
public int getHeaderLen()
public byte getDiffServ()
public byte getECN()
public short getTotalLength()
public short getIdentification()
public byte getFlags()
public byte getTtl()
public byte getProtocol()
public short getChecksum()
public short getFragmentOffset()
public Ip4Network getSourceAddress()
Ip4Network
instance that represents the source
IP address.public Ip4Network getDestinationAddress()
Ip4Network
instance that represents the destination
IP address.public byte[] getOptions()
null
if no option is present.public IPv4 setVersion(byte version)
version
- The version to setpublic IPv4 setHeaderLength(byte len)
len
- The headerLength to set.public IPv4 setDiffServ(byte dserv)
dserv
- The differential services value.public IPv4 setECN(byte ecn)
ecn
- The ECN bits to set.public IPv4 setTotalLength(short len)
len
- The total length of the IPv4 packet.public IPv4 setIdentification(short id)
id
- The identification to set.public IPv4 setFlags(byte flags)
flags
- The flags to set.public IPv4 setFragmentOffset(short off)
off
- The fragmentation offset.public IPv4 setTtl(byte ttl)
ttl
- The ttl to set.public IPv4 setProtocol(byte proto)
proto
- The protocol to set.public IPv4 setChecksum(short cksum)
This method is only for testing. IP checksum will be updated on serialization.
cksum
- The IP checksum.public IPv4 setSourceAddress(Ip4Network addr)
The network prefix in the given paramter is always ignored.
addr
- The source IP address.public IPv4 setDestinationAddress(Ip4Network addr)
The network prefix in the given paramter is always ignored.
addr
- The destination IP address.public IPv4 setOptions(byte[] options)
options
- The IP options.public int getHeaderSize()
getHeaderSize
in class Packet
protected int getFieldNumBits(String name, Packet.HeaderField entry)
If the fieldname has variable length like "Options", then this value is computed using the header length.
getFieldNumBits
in class Packet
name
- The name of the header field.entry
- The header field entry associated with name
.protected Map<String,Packet.HeaderField> getHeaderFormat()
getHeaderFormat
in class Packet
protected void setHeaderField(String name, byte[] value)
Variable header value like payload protocol, is stored here.
setHeaderField
in class Packet
name
- The name of the header field.value
- The value to be associated with the specified header
field. null
cannot be specified.protected boolean equalsField(String name, byte[] value1, byte[] value2)
equalsField
in class Packet
name
- The name of the header field.value1
- The first header field value to be compared.value2
- The second header field value to be compared.true
only if the given two header field values are
identical.public void setPayload(Packet p)
This method updates the total length of the IPv4 packet.
setPayload
in class Packet
p
- The packet encapsulated by this IPv4 packet.protected void postSerializeCustomOperation(byte[] myBytes) throws PacketException
This method computes the IP checksum and stores it into the IP header.
postSerializeCustomOperation
in class Packet
myBytes
- Serialized bytes.PacketException
- An error occurred.protected void postDeserializeCustomOperation(byte[] data, int offset)
postDeserializeCustomOperation
in class Packet
data
- The byte stream representing the Ethernet frame.offset
- The bit offset from where the byte array corresponding to
this Packet starts in the frameCopyright © 2018 OpenDaylight. All rights reserved.