net.floodlightcontroller.packet
Class IPv4

java.lang.Object
  extended by net.floodlightcontroller.packet.BasePacket
      extended by net.floodlightcontroller.packet.IPv4
All Implemented Interfaces:
IPacket

public class IPv4
extends BasePacket

Author:
David Erickson (daviderickson@cs.stanford.edu)

Field Summary
protected  short checksum
           
protected  int destinationAddress
           
protected  byte diffServ
           
protected  byte flags
           
protected  short fragmentOffset
           
protected  byte headerLength
           
protected  short identification
           
static byte IPV4_FLAGS_DONTFRAG
           
static byte IPV4_FLAGS_MASK
           
static byte IPV4_FLAGS_MOREFRAG
           
static byte IPV4_FLAGS_SHIFT
           
static short IPV4_OFFSET_MASK
           
protected  boolean isFragment
           
protected  boolean isTruncated
           
protected  byte[] options
           
protected  byte protocol
           
static byte PROTOCOL_ICMP
           
static byte PROTOCOL_TCP
           
static byte PROTOCOL_UDP
           
static java.util.Map<java.lang.Byte,java.lang.Class<? extends IPacket>> protocolClassMap
           
protected  int sourceAddress
           
protected  short totalLength
           
protected  byte ttl
           
protected  byte version
           
 
Fields inherited from class net.floodlightcontroller.packet.BasePacket
log, parent, payload
 
Constructor Summary
IPv4()
          Default constructor that sets the version to 4.
 
Method Summary
 IPacket deserialize(byte[] data, int offset, int length)
          Deserializes this packet layer and all possible payloads
 boolean equals(java.lang.Object obj)
           
static java.lang.String fromIPv4Address(int ipAddress)
          Accepts an IPv4 address and returns of string of the form xxx.xxx.xxx.xxx ie 192.168.0.1
static java.lang.String fromIPv4AddressCollection(java.util.Collection<java.lang.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()
           
 byte getFlags()
           
 short getFragmentOffset()
           
 byte getHeaderLength()
           
 short getIdentification()
           
 byte[] getOptions()
           
 byte getProtocol()
           
 int getSourceAddress()
           
 short getTotalLength()
           
 byte getTtl()
           
 byte getVersion()
           
 int hashCode()
           
 boolean isFragment()
           
 boolean isTruncated()
           
 void resetChecksum()
          Reset any checksums as needed, and call resetChecksum on all parents
 byte[] serialize()
          Serializes the packet.
 IPv4 setChecksum(short checksum)
           
 IPv4 setDestinationAddress(int destinationAddress)
           
 IPv4 setDestinationAddress(java.lang.String destinationAddress)
           
 IPv4 setDiffServ(byte diffServ)
           
 IPv4 setFlags(byte flags)
           
 void setFragment(boolean isFrag)
           
 IPv4 setFragmentOffset(short fragmentOffset)
           
 IPv4 setIdentification(short identification)
           
 IPv4 setOptions(byte[] options)
           
 IPv4 setProtocol(byte protocol)
           
 IPv4 setSourceAddress(int sourceAddress)
           
 IPv4 setSourceAddress(java.lang.String sourceAddress)
           
 void setTruncated(boolean isTruncated)
           
 IPv4 setTtl(byte ttl)
           
 IPv4 setVersion(byte version)
           
static int toIPv4Address(byte[] ipAddress)
          Accepts an IPv4 address in a byte array and returns the corresponding 32-bit integer value.
static int toIPv4Address(java.lang.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(java.lang.String ipAddress)
          Accepts an IPv4 address of the form xxx.xxx.xxx.xxx, ie 192.168.0.1 and returns the corresponding byte array.
 
Methods inherited from class net.floodlightcontroller.packet.BasePacket
clone, getParent, getPayload, setParent, setPayload
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

PROTOCOL_ICMP

public static final byte PROTOCOL_ICMP
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

protocolClassMap

public static java.util.Map<java.lang.Byte,java.lang.Class<? extends IPacket>> protocolClassMap

IPV4_FLAGS_MOREFRAG

public static final byte IPV4_FLAGS_MOREFRAG
See Also:
Constant Field Values

IPV4_FLAGS_DONTFRAG

public static final byte IPV4_FLAGS_DONTFRAG
See Also:
Constant Field Values

IPV4_FLAGS_MASK

public static final byte IPV4_FLAGS_MASK
See Also:
Constant Field Values

IPV4_FLAGS_SHIFT

public static final byte IPV4_FLAGS_SHIFT
See Also:
Constant Field Values

IPV4_OFFSET_MASK

public static final short IPV4_OFFSET_MASK
See Also:
Constant Field Values

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

isFragment

protected boolean isFragment
Constructor Detail

IPv4

public IPv4()
Default constructor that sets the version to 4.

Method Detail

getVersion

public byte getVersion()
Returns:
the version

setVersion

public IPv4 setVersion(byte version)
Parameters:
version - the version to set

getHeaderLength

public byte getHeaderLength()
Returns:
the headerLength

getDiffServ

public byte getDiffServ()
Returns:
the diffServ

setDiffServ

public IPv4 setDiffServ(byte diffServ)
Parameters:
diffServ - the diffServ to set

getTotalLength

public short getTotalLength()
Returns:
the totalLength

getIdentification

public short getIdentification()
Returns:
the identification

isTruncated

public boolean isTruncated()

setTruncated

public void setTruncated(boolean isTruncated)

isFragment

public boolean isFragment()

setFragment

public void setFragment(boolean isFrag)

setIdentification

public IPv4 setIdentification(short identification)
Parameters:
identification - the identification to set

getFlags

public byte getFlags()
Returns:
the flags

setFlags

public IPv4 setFlags(byte flags)
Parameters:
flags - the flags to set

getFragmentOffset

public short getFragmentOffset()
Returns:
the fragmentOffset

setFragmentOffset

public IPv4 setFragmentOffset(short fragmentOffset)
Parameters:
fragmentOffset - the fragmentOffset to set

getTtl

public byte getTtl()
Returns:
the ttl

setTtl

public IPv4 setTtl(byte ttl)
Parameters:
ttl - the ttl to set

getProtocol

public byte getProtocol()
Returns:
the protocol

setProtocol

public IPv4 setProtocol(byte protocol)
Parameters:
protocol - the protocol to set

getChecksum

public short getChecksum()
Returns:
the checksum

setChecksum

public IPv4 setChecksum(short checksum)
Parameters:
checksum - the checksum to set

resetChecksum

public void resetChecksum()
Description copied from interface: IPacket
Reset any checksums as needed, and call resetChecksum on all parents

Specified by:
resetChecksum in interface IPacket
Overrides:
resetChecksum in class BasePacket

getSourceAddress

public int getSourceAddress()
Returns:
the sourceAddress

setSourceAddress

public IPv4 setSourceAddress(int sourceAddress)
Parameters:
sourceAddress - the sourceAddress to set

setSourceAddress

public IPv4 setSourceAddress(java.lang.String sourceAddress)
Parameters:
sourceAddress - the sourceAddress to set

getDestinationAddress

public int getDestinationAddress()
Returns:
the destinationAddress

setDestinationAddress

public IPv4 setDestinationAddress(int destinationAddress)
Parameters:
destinationAddress - the destinationAddress to set

setDestinationAddress

public IPv4 setDestinationAddress(java.lang.String destinationAddress)
Parameters:
destinationAddress - the destinationAddress to set

getOptions

public byte[] getOptions()
Returns:
the options

setOptions

public IPv4 setOptions(byte[] options)
Parameters:
options - the options to set

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

deserialize

public IPacket deserialize(byte[] data,
                           int offset,
                           int length)
                    throws PacketParsingException
Description copied from interface: IPacket
Deserializes this packet layer and all possible payloads

offset - offset to start deserializing from
length - length of the data to deserialize
Returns:
the deserialized data
Throws:
PacketParsingException

toIPv4Address

public static int toIPv4Address(java.lang.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 -
Returns:

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 -
Returns:

fromIPv4Address

public static java.lang.String fromIPv4Address(int ipAddress)
Accepts an IPv4 address and returns of string of the form xxx.xxx.xxx.xxx ie 192.168.0.1

Parameters:
ipAddress -
Returns:

fromIPv4AddressCollection

public static java.lang.String fromIPv4AddressCollection(java.util.Collection<java.lang.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:

toIPv4AddressBytes

public static byte[] toIPv4AddressBytes(java.lang.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 class BasePacket

equals

public boolean equals(java.lang.Object obj)
Overrides:
equals in class BasePacket