com.sun.multicast.reliable.applications.tree
Class TreeSTPDataPacket

java.lang.Object
  |
  +--com.sun.multicast.reliable.applications.tree.TreeSTPPacket
        |
        +--com.sun.multicast.reliable.applications.tree.TreeSTPDataPacket

public class TreeSTPDataPacket
extends com.sun.multicast.reliable.applications.tree.TreeSTPPacket

The STPDataPacket defines the format of data packets in STP. It extends the base class STPPacket which defines the common elements of all STP packets. A users buffer (byte array) is required to create an outbound data packet. The users buffer is copied into a new buffer large enough to hold the users data and the STP headers. The headers are filled in and the users buffer is released. A DatagramPacket is required to create an inbound data packet. The buffer in the DatagramPacket is saved and the headers are parsed. The header information is stored in local variables and the DatagramPacket is released.


Field Summary
static int CHECKSUM
           
static byte FLAGBIT_CONGESTION
           
static byte FLAGBIT_PRUNE
           
static int HAINTERVAL
           
static int PAYLOAD
           
static int SEQUENCENUMBER
           
static int STP_VERSION
           
static int STPDATA
           
static int STPDATAHEADERLENGTH
           
static int STPFLAGS
           
static int STPHEADERLENGTH
           
static int STPLENGTH
           
static int STPMAXPKT
           
static int STPMESSAGETYPE
           
static int STPSUBTYPE
           
static int STPVERSION
           
 
Constructor Summary
TreeSTPDataPacket(byte[] buff, int length)
          Create an outbound STPDataPacket.
 
Method Summary
 int computeChecksum()
          The compute checksum method is called from any class that requires a checksum field.
 java.net.DatagramPacket createDatagramPacket()
          Create a DatagramPacket from the existing data in this class.
 void setAddress(java.net.InetAddress address)
          The the address for this packet.
 void setFlags(byte flags)
          Set the packet flags field.
 void setMessageType(int type)
          Set the message type field.
 void setPort(int port)
          Set the port for this packet.
 void setSequenceNumber(int i)
          Set the sequence number for this packet.
 void setSubType(int type)
          Set the message subtype field.
 void setTTL(byte ttl)
          Set the TTL value for this packet.
 void writeBuffer(byte[] buffer, int length, int offset)
          Write a byte array to the buffer.
 void writeByte(byte value, int offset)
          Write a byte to the buffer.
 void writeInt(int value, int offset)
          Write an int to the buffer.
 void writeShort(short value, int offset)
          Write a short to the buffer.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

FLAGBIT_CONGESTION

public static final byte FLAGBIT_CONGESTION

FLAGBIT_PRUNE

public static final byte FLAGBIT_PRUNE

CHECKSUM

public static final int CHECKSUM

SEQUENCENUMBER

public static final int SEQUENCENUMBER

HAINTERVAL

public static final int HAINTERVAL

PAYLOAD

public static final int PAYLOAD

STPDATAHEADERLENGTH

public static final int STPDATAHEADERLENGTH

STPMAXPKT

public static final int STPMAXPKT

STPVERSION

public static final int STPVERSION

STPMESSAGETYPE

public static final int STPMESSAGETYPE

STPSUBTYPE

public static final int STPSUBTYPE

STPFLAGS

public static final int STPFLAGS

STPLENGTH

public static final int STPLENGTH

STPDATA

public static final int STPDATA

STPHEADERLENGTH

public static final int STPHEADERLENGTH

STP_VERSION

public static final int STP_VERSION
Constructor Detail

TreeSTPDataPacket

public TreeSTPDataPacket(byte[] buff,
                         int length)
Create an outbound STPDataPacket. The user buffer is handed to the STPPacket class where it is copied into a buffer large enough for both the standard STPPacket header and the STPDataPacket specific header. The STPPacket header information is stored in the buffer before returning.
Parameters:
buff[] - a byte array of user data to be sent on the network.
Method Detail

setSequenceNumber

public void setSequenceNumber(int i)
Set the sequence number for this packet. The STPDataPacket class does not set the sequence number for outbound packets. This is typically done in the transmitter when the packet is actually sent.
Parameters:
i - the sequence number for this packet. (integer greater than 0)

setTTL

public void setTTL(byte ttl)
Set the TTL value for this packet. This is the time-to-live value to set when we send this packet. Use this option when the TTL needs to be something other than the default.
Parameters:
ttl - a byte containing the TTL value for this packet.

createDatagramPacket

public java.net.DatagramPacket createDatagramPacket()
Create a DatagramPacket from the existing data in this class. A CRC is computed for the packet including the data. It is added to the DataPacket header. Once calculated we let the STPPacket parent actually create the DatagramPacket. NOTE: In the future we may want to change the CRC32 algoritim to a CRC16 and possibly just checksum our header and not the data.
Overrides:
createDatagramPacket in class com.sun.multicast.reliable.applications.tree.TreeSTPPacket
Returns:
a DatagramPacket with the current STPDataPacket contents.

setMessageType

public void setMessageType(int type)
Set the message type field.
Parameters:
type - an integer message type value.

setSubType

public void setSubType(int type)
Set the message subtype field.
Parameters:
type - an integer message subtype value.

setAddress

public void setAddress(java.net.InetAddress address)
The the address for this packet.
Parameters:
address - the InetAddress for this packet.

setPort

public void setPort(int port)
Set the port for this packet.
Parameters:
port - the port number for this packet.

setFlags

public void setFlags(byte flags)
Set the packet flags field.
Parameters:
the - packet flags field.

writeByte

public void writeByte(byte value,
                      int offset)
Write a byte to the buffer. The offset specified is that of the child class and does not include the header in the common STPPacket class. Add in the our offset and put the data at this location.
Parameters:
value - the data to be written.
offset - the offset into the buffer to write the data. This offset is relative to the childs view of the packet and does not include this layers header.

writeShort

public void writeShort(short value,
                       int offset)
Write a short to the buffer. The offset specified is that of the child class and does not include the header in the common STPPacket class. Add in the our offset and put the data at this location.
Parameters:
value - the data to be written.
offset - the offset into the buffer to write the data. This offset is relative to the childs view of the packet and does not include this layers header.

writeInt

public void writeInt(int value,
                     int offset)
Write an int to the buffer. The offset specified is that of the child class and does not include the header in the common STPPacket class. Add in the our offset and put the data at this location.
Parameters:
value - the data to be written.
offset - the offset into the buffer to write the data. This offset is relative to the childs view of the packet and does not include this layers header.

writeBuffer

public void writeBuffer(byte[] buffer,
                        int length,
                        int offset)
Write a byte array to the buffer. The offset specified is that of the child class and does not include the header in the common STPPacket class. Add in the our offset and put the data at this location.
Parameters:
value - the data to be written.
offset - the offset into the buffer to write the data. This offset is relative to the childs view of the packet and does not include this layers header.

computeChecksum

public int computeChecksum()
The compute checksum method is called from any class that requires a checksum field. The checksum is calculated upon the entire buffer that this class has constructed. The crc is returned to the caller and can then be placed into the buffer or checked against an existing checksum.


JavaTM Reliable MulticastTM Service version 1.1
Copyright (c) 2001, Sun Microsystems Laboratories, All rights reserved.