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 shortchecksumprotected intdestinationAddressprotected bytediffServprotected byteflagsprotected shortfragmentOffsetprotected byteheaderLengthprotected shortidentificationprotected booleanisTruncatedprotected byte[]optionsprotected byteprotocolstatic java.util.Map<java.lang.Byte,Deserializer<? extends IPacket>>PROTOCOL_DESERIALIZER_MAPstatic bytePROTOCOL_ICMPstatic bytePROTOCOL_IGMPstatic bytePROTOCOL_PIMstatic bytePROTOCOL_TCPstatic bytePROTOCOL_UDPprotected intsourceAddressprotected shorttotalLengthprotected bytettlprotected byteversion-
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.booleanequals(java.lang.Object obj)static java.lang.StringfromIPv4Address(int ipAddress)Accepts an IPv4 address and returns of string of the form xxx.xxx.xxx.xxx, e.g., 192.168.0.1.static java.lang.StringfromIPv4AddressCollection(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.shortgetChecksum()intgetDestinationAddress()bytegetDiffServ()Gets the DiffServ octet (including the DSCP and ECN bits).bytegetDscp()Gets the DSCP value (6 bits).bytegetEcn()Gets the ECN value (2 bits).bytegetFlags()shortgetFragmentOffset()bytegetHeaderLength()shortgetIdentification()byte[]getOptions()bytegetProtocol()intgetSourceAddress()shortgetTotalLength()bytegetTtl()bytegetVersion()Gets IP version number.inthashCode()booleanisTruncated()voidresetChecksum()Reset any checksum as needed, and call resetChecksum on all parents.byte[]serialize()Serializes the packet.IPv4setChecksum(short checksum)IPv4setDestinationAddress(int destinationAddress)IPv4setDestinationAddress(java.lang.String destinationAddress)IPv4setDiffServ(byte diffServ)Sets the DiffServ octet (including the DSCP and ECN bits).IPv4setDscp(byte dscp)Sets the DSCP value (6 bits).IPv4setEcn(byte ecn)Sets the ECN value (2 bits).IPv4setFlags(byte flags)IPv4setFragmentOffset(short fragmentOffset)IPv4setIdentification(short identification)IPv4setOptions(byte[] options)IPv4setProtocol(byte protocol)IPv4setSourceAddress(int sourceAddress)IPv4setSourceAddress(java.lang.String sourceAddress)voidsetTruncated(boolean isTruncated)IPv4setTtl(byte ttl)IPv4setVersion(byte version)Sets IP version number.static inttoIPv4Address(byte[] ipAddress)Accepts an IPv4 address in a byte array and returns the corresponding 32-bit integer value.static inttoIPv4Address(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.java.lang.StringtoString()-
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 java.util.Map<java.lang.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:IPGets IP version number.- Specified by:
getVersionin classIP- Returns:
- IP version number
-
setVersion
public IPv4 setVersion(byte version)
Description copied from class:IPSets IP version number.- Specified by:
setVersionin 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:IPacketReset any checksum as needed, and call resetChecksum on all parents.- Specified by:
resetChecksumin interfaceIPacket- Overrides:
resetChecksumin 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(java.lang.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(java.lang.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(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- 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 java.lang.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 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:
- ip addresses in comma-separated string form
-
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:
hashCodein classBasePacket
-
equals
public boolean equals(java.lang.Object obj)
- Overrides:
equalsin classBasePacket
-
deserializer
public static Deserializer<IPv4> deserializer()
Deserializer function for IPv4 packets.- Returns:
- deserializer function
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
-