java.net
Class ANEPPacket

java.lang.Object
  |
  +--java.net.ANEPPacket
All Implemented Interfaces:
ANEPPacketType

public class ANEPPacket
extends java.lang.Object
implements ANEPPacketType

This class define an ANEP packet, and is used to send or receive data.

When receiving data, you need to specified the length of data you expect to receive, if there is less data the length will be changed, if there is more the data will be truncated.

There is not fundamental difference between constructors used for sending or receiving packet, except the fact that when receiving packet you need to specify less information.

For information the ANEP packet header looks like:

   0                   1                   2                   3
   0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
  +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  |   Version     |     Flags     |            Type ID            |
  +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  |      ANEP Header Length       |     ANEP Packet Length        |
  +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  ~                            Options                            ~
  +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  |                               .                               |
  ~                            Payload                            ~
  |                               .                               |
  +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
 


Field Summary
static int FLAG_DISCARD
          Flag to discard the packet if the receiving node is not able to deal with the packet type, otherwise if able, the node will try to forward it.
static int MAX_TYPE
          Maximal TypeId for a packet
static int USE_DEFAULT_FLAGS
          This is used to indicate to use the system default value for the ANEP packet flag.
 
Fields inherited from interface java.net.ANEPPacketType
ANAIS_Data, ANAIS_Management1, ANAIS_Management2, ANAIS_Multicast, ANAIS_Reserved, ANCORS_daemon, Anet, Anet_simulation, ANTS, DAN, MO_messengers, NetScript_ManagementTraffic, NetScript_PacketTraffic, NetScript_ProgramDeploymentPackets, PLAN, Spanner
 
Constructor Summary
ANEPPacket(byte[] payload, int offset, int length)
          Constructs an ANEP packet for receiving packets of length length to the specified host.
ANEPPacket(byte[] payload, int offset, int length, ANEPOption[] options)
          Constructs an ANEP packet for receiving packets of length length to the specified host.
ANEPPacket(int type, byte[] payload, int offset, int length, ANEPOption[] options, InetAddress addr)
          Constructs an ANEP packet for sending packets of length length to the specified host.
ANEPPacket(int type, byte[] payload, int offset, int length, InetAddress addr)
          Constructs an ANEP packet for sending packets of length length to the specified host.
ANEPPacket(int type, int flags, byte[] payload, int offset, int length, ANEPOption[] options, InetAddress address)
          Constructs an ANEP packet for sending packets of length length to the specified host.
 
Method Summary
 InetAddress getAddress()
          Get the address of the destination.
 byte[] getData()
          Get the packet payload.
 int getFlags()
          Get the ANEP packet flags which are defined here as FLAG_*.
 int getLength()
          Returns the length of the data to be sent or the length of the data received.
 int getOffset()
          Returns the offset of the data to be sent or the offset of the data received.
 ANEPOption[] getOptions()
          Get the ANEP packet options.
 int getType()
          Get the packet type Id.
 void setAddress(InetAddress iaddr)
          Set the address of the receiver.
 void setData(byte[] payload, int offset, int length)
          Set the data buffer for this packet.
 void setFlags(int flags)
          Set the flags for the ANEP packet.
 void setOptions(ANEPOption[] options)
          Specify the options to be send with the main data.
 void setType(int type)
          Set the ANEP type of the packet.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

FLAG_DISCARD

public static final int FLAG_DISCARD
Flag to discard the packet if the receiving node is not able to deal with the packet type, otherwise if able, the node will try to forward it.

MAX_TYPE

public static final int MAX_TYPE
Maximal TypeId for a packet

USE_DEFAULT_FLAGS

public static final int USE_DEFAULT_FLAGS
This is used to indicate to use the system default value for the ANEP packet flag. This is not a flag, but a special value.
Constructor Detail

ANEPPacket

public ANEPPacket(int type,
                  int flags,
                  byte[] payload,
                  int offset,
                  int length,
                  ANEPOption[] options,
                  InetAddress address)
Constructs an ANEP packet for sending packets of length length to the specified host. The offset combined with the length should not exced the size of the payload buffer (payload.length).

Due to implementation constraints the only value accepted (for now) for flags is USE_DEFAULT_FLAGS

Parameters:
type - the packet type.
flags - the packet flags
payload - the packet data.
length - the length for the buffer.
offset - the offset for the buffer.
options - the ANEP options.
addr - the destination address.
See Also:
ANEPPacketType, InetAddress

ANEPPacket

public ANEPPacket(int type,
                  byte[] payload,
                  int offset,
                  int length,
                  InetAddress addr)
Constructs an ANEP packet for sending packets of length length to the specified host. The offset combined with the length should not exced the size of the payload buffer (payload.length).

Parameters:
type - the packet type.
payload - the packet data.
length - the length for the buffer.
offset - the offset for the buffer.
addr - the destination address.
See Also:
ANEPPacketType, InetAddress

ANEPPacket

public ANEPPacket(int type,
                  byte[] payload,
                  int offset,
                  int length,
                  ANEPOption[] options,
                  InetAddress addr)
Constructs an ANEP packet for sending packets of length length to the specified host. The offset combined with the length should not exced the size of the payload buffer (payload.length).

Parameters:
type - the packet type.
payload - the packet data.
length - the length for the buffer.
offset - the offset for the buffer.
options - the ANEP options.
addr - the destination address.
See Also:
ANEPPacketType, InetAddress

ANEPPacket

public ANEPPacket(byte[] payload,
                  int offset,
                  int length,
                  ANEPOption[] options)
Constructs an ANEP packet for receiving packets of length length to the specified host. The offset combined with the length should not exced the size of the payload buffer (payload.length).

Parameters:
payload - the packet data.
length - the length for the buffer.
offset - the offset for the buffer.
options - the ANEP options.
See Also:
InetAddress

ANEPPacket

public ANEPPacket(byte[] payload,
                  int offset,
                  int length)
Constructs an ANEP packet for receiving packets of length length to the specified host. The offset combined with the length should not exced the size of the payload buffer (payload.length).

Parameters:
payload - the packet data.
length - the length for the buffer.
offset - the offset for the buffer.
See Also:
InetAddress
Method Detail

setData

public void setData(byte[] payload,
                    int offset,
                    int length)
Set the data buffer for this packet. This sets the payload, length and offset of the packet. The offset combined with the length should not exced the size of the payload buffer (payload.length).

Parameters:
payload - the buffer to set for this packet
offset - the offset into the data
length - the length of the data
Throws:
NullPointerException - if the argument is null
See Also:
getData(), getOffset(), getLength()

setAddress

public void setAddress(InetAddress iaddr)
Set the address of the receiver.
Parameters:
iaddr - address of the receiver

setType

public void setType(int type)
Set the ANEP type of the packet.
Parameters:
type - ANEP type Id

setFlags

public void setFlags(int flags)
Set the flags for the ANEP packet. Ony the FLAG_DISCARD is supported.

For performance, it is better to set the flags on the socket level, and use the default value for the packet than setting the flags for every packet.

Due to implementation constraints the only value accepted (for now) is USE_DEFAULT_FLAGS

Parameters:
flags - flags to use
See Also:
SocketOptions.ANEP_DISCARD, USE_DEFAULT_FLAGS, FLAG_DISCARD

setOptions

public void setOptions(ANEPOption[] options)
Specify the options to be send with the main data. The same option type should not appear more than once in the list, otherwise the behaviour is unspecified. (this could in a futur version throw an exception)
Parameters:
options - an array of options to send.

getFlags

public int getFlags()
Get the ANEP packet flags which are defined here as FLAG_*. This information is not available when a packet has been received, so calling this method will return a meaningless information.
Returns:
the ANEP packet flags or the USE_DEFAULT_FLAGS value.
See Also:
ANEPSocket.receive(java.net.ANEPPacket)

getOptions

public ANEPOption[] getOptions()
Get the ANEP packet options.
Returns:
the ANEP options

getType

public int getType()
Get the packet type Id.
Returns:
packet type Id
See Also:
ANEPPacketType

getAddress

public InetAddress getAddress()
Get the address of the destination.
Returns:
address of the packet destination

getData

public byte[] getData()
Get the packet payload.
Returns:
packet payload

getLength

public int getLength()
Returns the length of the data to be sent or the length of the data received.
Returns:
the length of the data to be sent or the length of the data received.

getOffset

public int getOffset()
Returns the offset of the data to be sent or the offset of the data received.
Returns:
the offset of the data to be sent or the offset of the data received.