|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--edu.uiuc.cs.net.DPRPManager.DPRPMessage
This class represents an individual DPRP Message. Interestingly, this class is actually the cornerstone of this entire piece of software. Not only does it lay down the format of the messages passed in the protocol, but it also includes key code for serializing message objects into byte streams (and also deserializing them back out again). It also overrides the 'equals()' and 'hashcode()' methods from class 'Object' (the only class to do so). Furthermore, this class contains many support methods that make dealing with messages easier for both the client and the server. Finally, this file contains a series of custom exceptions for the DPRPManager.
Field Summary | |
static byte |
CLI_OFFER_ACK
Code for DPRP_OFFER_ACK Message. |
static byte |
CLI_OFFER_NACK
Code for DPRP_CLI_OFFER_NACK Message. |
static byte |
CLI_RENEW_REQUEST
Code for DPRP_CLI_RENEW_REQUEST Message. |
static byte |
CLI_REQUEST
Code for DPRP_CLI_REQUEST Message. |
static byte |
CLI_TERMINATE_LEASE
Sent by the client, when the the user wishes to immediately terminate a lease. |
static int |
DEFAULT_PORT
The default port that the server listens on. |
private java.net.InetAddress |
dstAddr
The destination IP address of the message. |
private int |
dstPort
The destination port for the message. |
private int |
duration
The proposed lease duration, in seconds. |
static byte |
ERROR
Code for DPRP_ERROR Message. |
private java.net.InetAddress |
extAddr
The external IP address of the gateway. |
private int |
extPort
The external Port reserved by the Gateway. |
private short |
flags
The flags, which can represent control options. |
private byte |
messageType
The message type, defines the intended nature of the message. |
private static byte[] |
nullIPAddr
An IP address of all zeros, in byte array format. |
private byte |
protocol
The protocol, either TCP (6) or UDP (17). |
private static java.util.Random |
rando
The Random object singleton instance. |
private java.net.InetAddress |
srcAddr
The source IP address of the sender. |
private int |
srcPort
The source port on the sender. |
static byte |
SRV_COMMIT_OFFER
Code for DPRP_SRV_COMMIT_OFFER Message. |
static byte |
SRV_OFFER
Code for DPRP_SRV_OFFER Message. |
static byte |
SRV_OFFER_NACK_ACK
Code for DPRP_SRV_OFFER_NACK_ACK Message. |
static byte |
SRV_RENEW_ACK
Code for DPRP_SRV_RENEW_ACK Message. |
static byte |
SRV_RENEW_NACK
Code for DPRP_SRV_RENEW_NACK Message. |
static byte |
SRV_TERMINATE_ACK
Sent by the server, responding to a termination request. |
static java.lang.String[] |
supportedProtocols
Return the supported protocols, in text format. |
static byte |
TCP_PROTOCOL
The numeric representation of the TCP protocol, as found in "/etc/services". |
static byte |
UDP_PROTOCOL
The numeric representation of the UDP protocol, as found in "/etc/services". |
private int |
xid
The session identifier, ala DHCP. |
Constructor Summary | |
DPRPMessage()
Constructor for DPRPMessage. |
|
DPRPMessage(java.net.InetAddress inServerIP,
int inServerPort)
Constructor for DPRPMessage. |
Method Summary | |
protected java.lang.Object |
clone()
Overloaded from class Object, creates a copy of this message. |
private void |
defaultValues()
Fills in various variables with default values. |
DPRPMessage |
deserialize(byte[] inBytes)
This method converts a byte array representation of a DPRPMessage into an actual DPRPMessage object. |
boolean |
equals(DPRPMessage cmp)
Compares two DPRPMessage objects for equality. |
boolean |
equals(java.lang.Object o)
Compares this message to another object for equality. |
static int[] |
fixupSigned(byte[] byteAry)
Gets the unsigned equivalent of each byte in an array. |
void |
flipSendRecv()
Flips the source and destination addresses in place. |
java.net.InetAddress |
getDestinationAddress()
Get the destination address. |
int |
getDestinationPort()
Get the destination port. |
int |
getDuration()
Get the duration, in seconds. |
java.net.InetAddress |
getExternalIP()
Get the external IP address. |
int |
getExternalPort()
Get the external port. |
short |
getFlags()
Get the flags. |
java.lang.String |
getMessageStr()
Converts a messageType to a human-readable string equivalent. |
byte |
getMessageType()
Get the message type. |
private int |
getNextXid()
Returns the next xid. |
java.lang.String |
getPrimaryKey()
Returns the primary key for this message: "externalIPAddr:externalPort:protocol". |
byte |
getProtocol()
Get the protocol, as a byte. |
java.lang.String |
getProtocolStr()
Get the protocol, as a string. |
java.net.InetAddress |
getSourceAddress()
Get the source IP address. |
java.lang.String |
getSourceKey()
Returns the source key, which is "sourceIPAddr:sourcePort". |
int |
getSourcePort()
Get the source port. |
int |
getXid()
Get the session ID. |
int |
hashCode()
Overloaded from Object, once again. |
static java.lang.String |
IParyToString(byte[] ba)
Converts a byte[4] array into dotted-quad IP address notation. |
static java.lang.String |
IParyToString(int[] ba)
Converts an int[4] array into dotted-quad IP address notation. |
void |
printDump()
Prints a human-readable version of the message to stdout. |
static java.lang.String |
protToString(byte p)
Converts a IP protocol identifier into a human-readable string. |
byte[] |
serialize()
Converts a DPRPMessage into a byte stream. |
void |
setDestinationAddress(java.net.InetAddress dip)
Set the destination IP address. |
void |
setDestinationPort(int dp)
Set the destination port. |
void |
setDuration(int id)
Set the duration this message. |
void |
setExternalIP(java.net.InetAddress eip)
Set the external IP address. |
void |
setExternalPort(int ep)
Set the external port for this message. |
void |
setFlags(short ifl)
Set the flags for this message. |
void |
setMessageType(byte mt)
Set the message type (constants in this class). |
void |
setProtocol(byte inp)
Set the IP protocol. |
void |
setSourceAddress(java.net.InetAddress cip)
Set the source IP address. |
void |
setSourcePort(int cp)
Set the source port. |
void |
setXid(int xxx)
Sets the xid. |
static byte |
stringToProt(java.lang.String str)
Converts a protocol string to its numeric representation. |
Methods inherited from class java.lang.Object |
|
Field Detail |
private byte messageType
private byte protocol
private short flags
private int xid
private int duration
private java.net.InetAddress srcAddr
private int srcPort
private java.net.InetAddress dstAddr
private int dstPort
private java.net.InetAddress extAddr
private int extPort
private static java.util.Random rando
private static byte[] nullIPAddr
public static final byte ERROR
public static final byte CLI_REQUEST
public static final byte SRV_OFFER
public static final byte CLI_OFFER_NACK
public static final byte SRV_OFFER_NACK_ACK
public static final byte CLI_OFFER_ACK
public static final byte SRV_COMMIT_OFFER
public static final byte CLI_RENEW_REQUEST
public static final byte SRV_RENEW_ACK
public static final byte SRV_RENEW_NACK
public static final byte CLI_TERMINATE_LEASE
public static final byte SRV_TERMINATE_ACK
public static final int DEFAULT_PORT
public static final byte TCP_PROTOCOL
public static final byte UDP_PROTOCOL
public static final java.lang.String[] supportedProtocols
Constructor Detail |
public DPRPMessage(java.net.InetAddress inServerIP, int inServerPort)
inServerName
- the destination IP addressinServerPort
- the destination portpublic DPRPMessage()
Method Detail |
private void defaultValues()
public byte[] serialize()
public DPRPMessage deserialize(byte[] inBytes)
This method works by plucking out a series of bytes, and
attempting to convert them into a more complex data
type. Assuming all of these conversions, these complex objects
are stuffed into a DPRPMessage, which is then
returned. In case the decoding does not proceed properly, this
method returns an generic message of type
DPRP_ERROR
, with the
INVALID_PACKET_FMT
errorcode set. Receivers will
treat this as any other error, and notify the sender
appropriately.
inBytes
- An array of bytes, containing the key bits of a
DPRPMessage object.private int getNextXid()
public void setMessageType(byte mt)
public void setProtocol(byte inp)
public void setDestinationAddress(java.net.InetAddress dip)
public void setDestinationPort(int dp)
public void setSourceAddress(java.net.InetAddress cip)
public void setSourcePort(int cp)
public void setExternalIP(java.net.InetAddress eip)
public void setExternalPort(int ep)
public void setFlags(short ifl)
public void setDuration(int id)
public void setXid(int xxx)
xxx
- Moonshine just like mom used to make.public byte getMessageType()
public byte getProtocol()
public java.lang.String getProtocolStr()
public java.net.InetAddress getSourceAddress()
public int getSourcePort()
public java.net.InetAddress getDestinationAddress()
public int getDestinationPort()
public java.net.InetAddress getExternalIP()
public int getExternalPort()
public short getFlags()
public int getDuration()
public int getXid()
public static int[] fixupSigned(byte[] byteAry)
byteAry
- An array of bytes to be de-signed.public static java.lang.String IParyToString(byte[] ba)
ba
- A byte array.public static java.lang.String IParyToString(int[] ba)
ba
- An array of ints (to capture the unsigned byte properties)public static java.lang.String protToString(byte p)
p
- A byte, representing the protocol (as found in
'/etc/protocols').public static byte stringToProt(java.lang.String str) throws DPRPInvalidProtocolException
str
- A string to be converted.DPRPInvalidProtocolException
- If we don't know what the
hell this string is supposed to represent.public java.lang.String getPrimaryKey()
public java.lang.String getSourceKey()
public void flipSendRecv()
protected java.lang.Object clone()
clone
in class java.lang.Object
public int hashCode()
hashCode
in class java.lang.Object
public boolean equals(java.lang.Object o)
equals
in class java.lang.Object
o
- A generic object.public boolean equals(DPRPMessage cmp)
cmp
- The DPRPMessage to compare against.public java.lang.String getMessageStr()
public void printDump()
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |