Package org.onlab.packet
Class IPv4
- java.lang.Object
-
- org.onlab.packet.BasePacket
-
- org.onlab.packet.IP
-
- org.onlab.packet.IPv4
-
-
Field Summary
Fields Modifier and Type Field Description protected short
checksum
protected int
destinationAddress
protected byte
diffServ
protected byte
flags
protected short
fragmentOffset
protected byte
headerLength
protected short
identification
protected boolean
isTruncated
protected byte[]
options
protected byte
protocol
static Map<Byte,Deserializer<? extends IPacket>>
PROTOCOL_DESERIALIZER_MAP
static byte
PROTOCOL_ICMP
static byte
PROTOCOL_IGMP
static byte
PROTOCOL_PIM
static byte
PROTOCOL_TCP
static byte
PROTOCOL_UDP
protected int
sourceAddress
protected short
totalLength
protected byte
ttl
protected byte
version
-
Fields inherited from class org.onlab.packet.BasePacket
parent, payload
-
-
Constructor Summary
Constructors Constructor Description IPv4()
Default constructor that sets the version to 4.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static Deserializer<IPv4>
deserializer()
Deserializer function for IPv4 packets.boolean
equals(Object obj)
static String
fromIPv4Address(int ipAddress)
Accepts an IPv4 address and returns of string of the form xxx.xxx.xxx.xxx, e.g., 192.168.0.1.static String
fromIPv4AddressCollection(Collection<Integer> ipAddresses)
Accepts a collection of IPv4 addresses as integers and returns a single String useful in toString method's containing collections of IP addresses.short
getChecksum()
int
getDestinationAddress()
byte
getDiffServ()
Gets the DiffServ octet (including the DSCP and ECN bits).byte
getDscp()
Gets the DSCP value (6 bits).byte
getEcn()
Gets the ECN value (2 bits).byte
getFlags()
short
getFragmentOffset()
byte
getHeaderLength()
short
getIdentification()
byte[]
getOptions()
byte
getProtocol()
int
getSourceAddress()
short
getTotalLength()
byte
getTtl()
byte
getVersion()
Gets IP version number.int
hashCode()
boolean
isTruncated()
void
resetChecksum()
Reset any checksum as needed, and call resetChecksum on all parents.byte[]
serialize()
Serializes the packet.IPv4
setChecksum(short checksum)
IPv4
setDestinationAddress(int destinationAddress)
IPv4
setDestinationAddress(String destinationAddress)
IPv4
setDiffServ(byte diffServ)
Sets the DiffServ octet (including the DSCP and ECN bits).IPv4
setDscp(byte dscp)
Sets the DSCP value (6 bits).IPv4
setEcn(byte ecn)
Sets the ECN value (2 bits).IPv4
setFlags(byte flags)
IPv4
setFragmentOffset(short fragmentOffset)
IPv4
setIdentification(short identification)
IPv4
setOptions(byte[] options)
IPv4
setProtocol(byte protocol)
IPv4
setSourceAddress(int sourceAddress)
IPv4
setSourceAddress(String sourceAddress)
void
setTruncated(boolean isTruncated)
IPv4
setTtl(byte ttl)
IPv4
setVersion(byte version)
Sets IP version number.static int
toIPv4Address(byte[] ipAddress)
Accepts an IPv4 address in a byte array and returns the corresponding 32-bit integer value.static int
toIPv4Address(String ipAddress)
Accepts an IPv4 address of the form xxx.xxx.xxx.xxx, ie 192.168.0.1 and returns the corresponding 32 bit integer.static byte[]
toIPv4AddressBytes(int ipAddress)
Accepts an IPv4 address in the form of an integer and returns the corresponding byte array.static byte[]
toIPv4AddressBytes(String ipAddress)
Accepts an IPv4 address of the form xxx.xxx.xxx.xxx, ie 192.168.0.1 and returns the corresponding byte array.String
toString()
-
Methods inherited from class org.onlab.packet.BasePacket
clone, getParent, getPayload, setParent, setPayload
-
-
-
-
Field Detail
-
PROTOCOL_ICMP
public static final byte PROTOCOL_ICMP
- See Also:
- Constant Field Values
-
PROTOCOL_IGMP
public static final byte PROTOCOL_IGMP
- See Also:
- Constant Field Values
-
PROTOCOL_TCP
public static final byte PROTOCOL_TCP
- See Also:
- Constant Field Values
-
PROTOCOL_UDP
public static final byte PROTOCOL_UDP
- See Also:
- Constant Field Values
-
PROTOCOL_PIM
public static final byte PROTOCOL_PIM
- See Also:
- Constant Field Values
-
PROTOCOL_DESERIALIZER_MAP
public static final Map<Byte,Deserializer<? extends IPacket>> PROTOCOL_DESERIALIZER_MAP
-
version
protected byte version
-
headerLength
protected byte headerLength
-
diffServ
protected byte diffServ
-
totalLength
protected short totalLength
-
identification
protected short identification
-
flags
protected byte flags
-
fragmentOffset
protected short fragmentOffset
-
ttl
protected byte ttl
-
protocol
protected byte protocol
-
checksum
protected short checksum
-
sourceAddress
protected int sourceAddress
-
destinationAddress
protected int destinationAddress
-
options
protected byte[] options
-
isTruncated
protected boolean isTruncated
-
-
Method Detail
-
getVersion
public byte getVersion()
Description copied from class:IP
Gets IP version number.- Specified by:
getVersion
in classIP
- Returns:
- IP version number
-
setVersion
public IPv4 setVersion(byte version)
Description copied from class:IP
Sets IP version number.- Specified by:
setVersion
in classIP
- Parameters:
version
- the version to set- Returns:
- IP class
-
getHeaderLength
public byte getHeaderLength()
- Returns:
- the headerLength
-
getDscp
public byte getDscp()
Gets the DSCP value (6 bits).- Returns:
- the DSCP value (6 bits)
-
setDscp
public IPv4 setDscp(byte dscp)
Sets the DSCP value (6 bits).- Parameters:
dscp
- the DSCP value (6 bits)- Returns:
- this
-
getEcn
public byte getEcn()
Gets the ECN value (2 bits).- Returns:
- the ECN value (2 bits)
-
setEcn
public IPv4 setEcn(byte ecn)
Sets the ECN value (2 bits).- Parameters:
ecn
- the ECN value (2 bits)- Returns:
- this
-
getDiffServ
public byte getDiffServ()
Gets the DiffServ octet (including the DSCP and ECN bits).- Returns:
- the diffServ octet (including the DSCP and ECN bits)
-
setDiffServ
public IPv4 setDiffServ(byte diffServ)
Sets the DiffServ octet (including the DSCP and ECN bits).- Parameters:
diffServ
- the diffServ octet to set (including the DSCP and ECN bits)- Returns:
- this
-
getTotalLength
public short getTotalLength()
- Returns:
- the totalLength
-
getIdentification
public short getIdentification()
- Returns:
- the identification
-
isTruncated
public boolean isTruncated()
-
setTruncated
public void setTruncated(boolean isTruncated)
-
setIdentification
public IPv4 setIdentification(short identification)
- Parameters:
identification
- the identification to set- Returns:
- this
-
getFlags
public byte getFlags()
- Returns:
- the flags
-
setFlags
public IPv4 setFlags(byte flags)
- Parameters:
flags
- the flags to set- Returns:
- this s
-
getFragmentOffset
public short getFragmentOffset()
- Returns:
- the fragmentOffset
-
setFragmentOffset
public IPv4 setFragmentOffset(short fragmentOffset)
- Parameters:
fragmentOffset
- the fragmentOffset to set- Returns:
- this
-
getTtl
public byte getTtl()
- Returns:
- the ttl
-
setTtl
public IPv4 setTtl(byte ttl)
- Parameters:
ttl
- the ttl to set- Returns:
- this
-
getProtocol
public byte getProtocol()
- Returns:
- the protocol
-
setProtocol
public IPv4 setProtocol(byte protocol)
- Parameters:
protocol
- the protocol to set- Returns:
- this
-
getChecksum
public short getChecksum()
- Returns:
- the checksum
-
setChecksum
public IPv4 setChecksum(short checksum)
- Parameters:
checksum
- the checksum to set- Returns:
- this
-
resetChecksum
public void resetChecksum()
Description copied from interface:IPacket
Reset any checksum as needed, and call resetChecksum on all parents.- Specified by:
resetChecksum
in interfaceIPacket
- Overrides:
resetChecksum
in classBasePacket
-
getSourceAddress
public int getSourceAddress()
- Returns:
- the sourceAddress
-
setSourceAddress
public IPv4 setSourceAddress(int sourceAddress)
- Parameters:
sourceAddress
- the sourceAddress to set- Returns:
- this
-
setSourceAddress
public IPv4 setSourceAddress(String sourceAddress)
- Parameters:
sourceAddress
- the sourceAddress to set- Returns:
- this
-
getDestinationAddress
public int getDestinationAddress()
- Returns:
- the destinationAddress
-
setDestinationAddress
public IPv4 setDestinationAddress(int destinationAddress)
- Parameters:
destinationAddress
- the destinationAddress to set- Returns:
- this
-
setDestinationAddress
public IPv4 setDestinationAddress(String destinationAddress)
- Parameters:
destinationAddress
- the destinationAddress to set- Returns:
- this
-
getOptions
public byte[] getOptions()
- Returns:
- the options
-
setOptions
public IPv4 setOptions(byte[] options)
- Parameters:
options
- the options to set- Returns:
- this
-
serialize
public byte[] serialize()
Serializes the packet. Will compute and set the following fields if they are set to specific values at the time serialize is called: -checksum : 0 -headerLength : 0 -totalLength : 0- Returns:
- a byte[] containing this packet and payloads
-
toIPv4Address
public static int toIPv4Address(String ipAddress)
Accepts an IPv4 address of the form xxx.xxx.xxx.xxx, ie 192.168.0.1 and returns the corresponding 32 bit integer.- Parameters:
ipAddress
- ip address in string form- Returns:
- int ip address value
-
toIPv4Address
public static int toIPv4Address(byte[] ipAddress)
Accepts an IPv4 address in a byte array and returns the corresponding 32-bit integer value.- Parameters:
ipAddress
- ip address in byte form- Returns:
- int ip address value
-
fromIPv4Address
public static String fromIPv4Address(int ipAddress)
Accepts an IPv4 address and returns of string of the form xxx.xxx.xxx.xxx, e.g., 192.168.0.1.- Parameters:
ipAddress
- ip address in form- Returns:
- string form of ip address
-
fromIPv4AddressCollection
public static String fromIPv4AddressCollection(Collection<Integer> ipAddresses)
Accepts a collection of IPv4 addresses as integers and returns a single String useful in toString method's containing collections of IP addresses.- Parameters:
ipAddresses
- collection- Returns:
- ip addresses in comma-separated string form
-
toIPv4AddressBytes
public static byte[] toIPv4AddressBytes(String ipAddress)
Accepts an IPv4 address of the form xxx.xxx.xxx.xxx, ie 192.168.0.1 and returns the corresponding byte array.- Parameters:
ipAddress
- The IP address in the form xx.xxx.xxx.xxx.- Returns:
- The IP address separated into bytes
-
toIPv4AddressBytes
public static byte[] toIPv4AddressBytes(int ipAddress)
Accepts an IPv4 address in the form of an integer and returns the corresponding byte array.- Parameters:
ipAddress
- The IP address as an integer.- Returns:
- The IP address separated into bytes.
-
hashCode
public int hashCode()
- Overrides:
hashCode
in classBasePacket
-
equals
public boolean equals(Object obj)
- Overrides:
equals
in classBasePacket
-
deserializer
public static Deserializer<IPv4> deserializer()
Deserializer function for IPv4 packets.- Returns:
- deserializer function
-
-