SunSPOT API V5.0


com.sun.spot.peripheral.radio
Class LowPanPacket

java.lang.Object
  extended by com.sun.spot.peripheral.radio.LowPanPacket

public class LowPanPacket
extends Object

LowPanPacket.java

Author:
Pete St. Pierre Created on January 23, 2007, 2:54 PM The LowPanPacket class is used to parse incoming RadioPackets to handle the flexible stacked header format defined in http://www.ietf.org/internet-drafts/draft-ietf-6lowpan-format-10.txt Headers may contain: a mesh header a broadcast header a fragmentation header The draft says they must be in this order, but we want to be flexible if possible. Not all headers are required.

Field Summary
protected static int BROADCAST_PACKET
          Indicates this LowPanPacket will use a RadioPacket of the type 'Broadcast'
protected static int DATA_PACKET
          Indicates this LowPanPacket will use a RadioPacket of the type 'Data'
protected static byte DISPATCH_MASK
          bitmask used to extract the dispatch field
 
Constructor Summary
LowPanPacket(int type)
          Create a LowPanPacket of either DATA_PACKET or BROADCAST_PACKET
LowPanPacket(RadioPacket packet)
          Parse a RadioPacket and use it to create a new instance of LowPanPacket that represents this RadioPacket.
 
Method Summary
 int getBCastSeqNo()
          return the sequence number for this mesh broadcast
 int getDestLen()
          returns the length in bytes of the destination address field 2 bytes == 16-bit addressing 8 bytes == 64-bit addressing
 long getFDestinationAddress()
          return the final destination address of this packet
 byte getFragOff()
          retrieve the offset of this fragment as related to the original datagram offsets are in multiples of 8 bytes
 short getFragSize()
          retrieve the total size of the original datagram of which this fragment is part
 short getFragTag()
          retrieve the datagram tag for this fragment
 byte getFragType()
          retrieve the fragment type bits from the fragmentation header
 int getHeaderLength()
          return the length of the LowPanPacket header
 byte getHopsLeft()
          returns the number of hops left for this packet
 int getLppPayloadOffset()
          return the starting offset of the payload section of the packet
 long getOriginatorAddress()
          return the address of the originator field of the mesh header
 int getOrigLen()
          return the length in bytes of the originator address field 2 bytes == 16-bit addressing 8 bytes == 64-bit addressing
 int getPayloadSize()
          return the actual size of the LowPanPacket payload
 byte getProtocol()
          retrieve the protocol number from this packet
 byte getProtocolFamily()
          retrieve the protocol family number from this packet
 RadioPacket getRadioPacket()
          return a representation of this LowPanPacket in an actual RadioPacket
 long getRPSourceAddress()
          return the source address of the actual radio packet
 boolean isBCast()
          determine if there is a LowPan broadcast header
 boolean isExtendedProtocol()
          determine if this packet uses the extended protocol field
 boolean isFirstFrag()
          determine whether this is a leading fragment of a packet
 boolean isFragged()
          determine whether this packet has a fragmentation header
 boolean isMeshed()
          determine if this packet has a mesh header
 void setBCast(boolean bCast)
          define this packet to have a LowPan broadcast header
 void setBCastSeqNo(int bCastSeqNo)
          set the sequence number for this mesh broadcast
 void setDestLen(int destLen)
          set the length in bytes of the destination address field 2 bytes == 16-bit addressing 8 bytes == 64-bit addressing
 void setExtendedProtocol(boolean extendedProtocol)
          define this packet to use the extended protocol byte
 void setFDestinationAddress(long destAddr)
          set the final destination for this meshed packet
 void setFragged(boolean fragged)
          define this packet to have a fragmentation header
 void setFragOff(byte fragOff)
          set the offset of this fragment as related to the original datagram offsets are in multiples of 8 bytes
 void setFragSize(short size)
          set the total size of the datagram to which this fragment belongs
 void setFragTag(short tag)
          set the datagram tag for this fragment
 void setFragType(byte type)
          define the fragment type for this packet, as defined in the 6lowpan spec
 void setHopsLeft(int hopsLeft)
          set the number of hops for this packet
 void setMeshed(boolean meshed)
          define this packet to have a mesh header
 void setOriginatorAddress(long origAddr)
          set the address of the originator field of the mesh header
 void setOrigLen(int origLen)
          set the length in bytes of the destination address field 2 bytes == 16-bit addressing 8 bytes == 64-bit addressing
 void setPayloadSize(int payloadSize)
          set the payload size in this LowPanPacket
 void setProtocol(byte protocol)
          sets the protocol number for this packet
 void setProtocol(byte family, byte protocol)
          sets the protocol number , within a specific family, for this packet
 void setProtocolFamily(byte protocolFamily)
          sets the protocol family number for this packet
 void setRPDestinationAddress(long addr)
          set the destination of the underlying radio packet
 void setRPSourceAddress(long addr)
          set the source address for this radio packet this may be over written by the packet dispatcher.
 String toString()
          create a string representation of this Object
 void writeHeaderAndPayload(LowPanHeader lph, byte[] buffer, int start, int end)
          Constructs a RadioPacket using a LowPanHeader and a data buffer.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

DISPATCH_MASK

protected static final byte DISPATCH_MASK
bitmask used to extract the dispatch field

See Also:
Constant Field Values

DATA_PACKET

protected static final int DATA_PACKET
Indicates this LowPanPacket will use a RadioPacket of the type 'Data'

See Also:
Constant Field Values

BROADCAST_PACKET

protected static final int BROADCAST_PACKET
Indicates this LowPanPacket will use a RadioPacket of the type 'Broadcast'

See Also:
Constant Field Values
Constructor Detail

LowPanPacket

public LowPanPacket(int type)
Create a LowPanPacket of either DATA_PACKET or BROADCAST_PACKET

Parameters:
type - the type of underlying RadioPacket to use either a DATA_PACKET or BROADCAST_PACKET

LowPanPacket

public LowPanPacket(RadioPacket packet)
Parse a RadioPacket and use it to create a new instance of LowPanPacket that represents this RadioPacket. The packet must be a valid radio DATA packet. Passing ACK packets will cause an IllegalStateException to be thrown. This can be avoided by calling RadioPacket#isAck() to verify radio packet type.

Parameters:
packet - the RadioPacket to parse
Method Detail

writeHeaderAndPayload

public void writeHeaderAndPayload(LowPanHeader lph,
                                  byte[] buffer,
                                  int start,
                                  int end)
Constructs a RadioPacket using a LowPanHeader and a data buffer. Will only send the segment of the data buffer as bounded by start and end indicies

Parameters:
lph - the lowpan header for this packet
buffer - data buffer to send
start - index of first byte to send from buffer
end - index of last byte to send from buffer

getHopsLeft

public byte getHopsLeft()
returns the number of hops left for this packet

Returns:
the number of hops remaining for this packet

setHopsLeft

public void setHopsLeft(int hopsLeft)
set the number of hops for this packet

Parameters:
hopsLeft - number of hops remaining

getDestLen

public int getDestLen()
returns the length in bytes of the destination address field 2 bytes == 16-bit addressing 8 bytes == 64-bit addressing

Returns:
number of bytes in the destination address

setDestLen

public void setDestLen(int destLen)
set the length in bytes of the destination address field 2 bytes == 16-bit addressing 8 bytes == 64-bit addressing

Parameters:
destLen - number of bytes in the destination address

getOrigLen

public int getOrigLen()
return the length in bytes of the originator address field 2 bytes == 16-bit addressing 8 bytes == 64-bit addressing

Returns:
number of bytes in the originator address

setOrigLen

public void setOrigLen(int origLen)
set the length in bytes of the destination address field 2 bytes == 16-bit addressing 8 bytes == 64-bit addressing

Parameters:
origLen - number of bytes in the originator address

getOriginatorAddress

public long getOriginatorAddress()
return the address of the originator field of the mesh header

Returns:
the originator address of this packet

setOriginatorAddress

public void setOriginatorAddress(long origAddr)
set the address of the originator field of the mesh header

Parameters:
origAddr - address of the originator of this packet

getFDestinationAddress

public long getFDestinationAddress()
return the final destination address of this packet

Returns:
the final destination of this mesh packet

setFDestinationAddress

public void setFDestinationAddress(long destAddr)
set the final destination for this meshed packet

Parameters:
destAddr - new final destination address for this meshed packet

getBCastSeqNo

public int getBCastSeqNo()
return the sequence number for this mesh broadcast

Returns:
the sequence number of this broadcast

setBCastSeqNo

public void setBCastSeqNo(int bCastSeqNo)
set the sequence number for this mesh broadcast

Parameters:
bCastSeqNo - the mesh broadcast sequence number

setFragType

public void setFragType(byte type)
define the fragment type for this packet, as defined in the 6lowpan spec

Parameters:
type - set the fragment type bits in this header

getFragType

public byte getFragType()
retrieve the fragment type bits from the fragmentation header

Returns:
the fragmentation type bits of this header

setFragTag

public void setFragTag(short tag)
set the datagram tag for this fragment

Parameters:
tag - the datagram tag to which this fragment belongs

getFragTag

public short getFragTag()
retrieve the datagram tag for this fragment

Returns:
the datagram tag

setFragSize

public void setFragSize(short size)
set the total size of the datagram to which this fragment belongs

Parameters:
size - total size of the original datagram

getFragSize

public short getFragSize()
retrieve the total size of the original datagram of which this fragment is part

Returns:
total size of original datagram

getFragOff

public byte getFragOff()
retrieve the offset of this fragment as related to the original datagram offsets are in multiples of 8 bytes

Returns:
offset of this fragment

setFragOff

public void setFragOff(byte fragOff)
set the offset of this fragment as related to the original datagram offsets are in multiples of 8 bytes

Parameters:
fragOff - offset within the original datagram

isFirstFrag

public boolean isFirstFrag()
determine whether this is a leading fragment of a packet

Returns:
true if the header indicates this is a first fragment of a set

getProtocolFamily

public byte getProtocolFamily()
retrieve the protocol family number from this packet

Returns:
the 8 bit protocol family number

setProtocolFamily

public void setProtocolFamily(byte protocolFamily)
sets the protocol family number for this packet

Parameters:
protocolFamily - the 8-bit protocol family number

getProtocol

public byte getProtocol()
retrieve the protocol number from this packet

Returns:
the 8 bit protocol number

setProtocol

public void setProtocol(byte protocol)
sets the protocol number for this packet

Parameters:
protocol - the 8-bit protocol number

setProtocol

public void setProtocol(byte family,
                        byte protocol)
sets the protocol number , within a specific family, for this packet

Parameters:
family - the protocol family
protocol - the 8-bit protocol number

isMeshed

public boolean isMeshed()
determine if this packet has a mesh header

Returns:
true if a mesh header is present

setMeshed

public void setMeshed(boolean meshed)
define this packet to have a mesh header

Parameters:
meshed - true if there will be a mesh header in this packet

isBCast

public boolean isBCast()
determine if there is a LowPan broadcast header

Returns:
true if a LowPan broadcast header is present

setBCast

public void setBCast(boolean bCast)
define this packet to have a LowPan broadcast header

Parameters:
bCast - true if this packet will have a LowPan broadcast header

isFragged

public boolean isFragged()
determine whether this packet has a fragmentation header

Returns:
true if there is a fragmentation header

setFragged

public void setFragged(boolean fragged)
define this packet to have a fragmentation header

Parameters:
fragged - true if there will be a fragmentation header

getRPSourceAddress

public long getRPSourceAddress()
return the source address of the actual radio packet

Returns:
Radio Packet source address

getRadioPacket

public RadioPacket getRadioPacket()
return a representation of this LowPanPacket in an actual RadioPacket

Returns:
a RadioPacket suitable for sending via the RadioPacketDispatcher

setRPDestinationAddress

public void setRPDestinationAddress(long addr)
set the destination of the underlying radio packet

Parameters:
addr - the destination address

setRPSourceAddress

public void setRPSourceAddress(long addr)
set the source address for this radio packet this may be over written by the packet dispatcher. It is used predominantly for testing

Parameters:
addr - source address for this radio packet

getPayloadSize

public int getPayloadSize()
return the actual size of the LowPanPacket payload

Returns:
number of bytes in this LowPanPacket that are payload (non-header)

setPayloadSize

public void setPayloadSize(int payloadSize)
set the payload size in this LowPanPacket

Parameters:
payloadSize - number of bytes that are payload

getHeaderLength

public int getHeaderLength()
return the length of the LowPanPacket header

Returns:
actual length of the LowPan header

isExtendedProtocol

public boolean isExtendedProtocol()
determine if this packet uses the extended protocol field

Returns:
true if we are using SPOT protocol numbers

setExtendedProtocol

public void setExtendedProtocol(boolean extendedProtocol)
define this packet to use the extended protocol byte

Parameters:
extendedProtocol - true if this is a SPOT protocol number

getLppPayloadOffset

public int getLppPayloadOffset()
return the starting offset of the payload section of the packet

Returns:
starting offset for data within this packet

toString

public String toString()
create a string representation of this Object

Overrides:
toString in class Object
Returns:
this object as a string

SunSPOT API V5.0


Copyright � 2006-2008 Sun Microsystems, Inc. All Rights Reserved.