dk.i1.diameter
Class AVP

Object
  extended by dk.i1.diameter.AVP
Direct Known Subclasses:
AVP_Float32, AVP_Float64, AVP_Grouped, AVP_Integer32, AVP_Integer64, AVP_OctetString, AVP_Unsigned32, AVP_Unsigned64, AVP_UTF8String

public class AVP
extends Object

A Diameter AVP. See RFC3588 section 4 for details. An AVP consists of a code, some flags, an optional vendor ID, and a payload.

The payload is not checked for correct size and content until you try to construct one of its subclasses from it. Eg

 AVP avp = ...
 try {
     int application_id = new AVP_Unsigned32(avp).queryValue());
     ...
 } catch(InvalidAVPLengthException ex) {
     ..
 }
 

See Also:
ProtocolConstants

Field Summary
 int code
          The AVP code
 int vendor_id
          The vendor ID.
 
Constructor Summary
AVP()
          Default constructor The code and vendor_id are initialized to 0, no flags are set, and the payload is null.
AVP(AVP a)
          Copy constructor (deep copy)
AVP(int code, byte[] payload)
          Create AVP with code and payload
AVP(int code, int vendor_id, byte[] payload)
          Create AVP with code and payload
 
Method Summary
 boolean isMandatory()
          Returns if the mandatory (M) flag is set
 boolean isPrivate()
          Returns if the private (P) flag is set
 boolean isVendorSpecific()
          Returns if the AVP is vendor-specific (has non-zero vendor_id)
 byte[] queryPayload()
          Returns the payload of the AVP Returns a copy of the (unpadded) payload of the AVP in network byte order.
 AVP setM()
          Sets the M-bit and returns the instance.
 void setMandatory(boolean b)
          Sets/unsets the mandatory (M) flag
 void setPrivate(boolean b)
          Sets/unsets the private (P) flag
 
Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

code

public int code
The AVP code


vendor_id

public int vendor_id
The vendor ID. Assigning directly to this has the delayed effect of of setting/unsetting the vendor flag bit

Constructor Detail

AVP

public AVP()
Default constructor The code and vendor_id are initialized to 0, no flags are set, and the payload is null.


AVP

public AVP(AVP a)
Copy constructor (deep copy)


AVP

public AVP(int code,
           byte[] payload)
Create AVP with code and payload

Parameters:
code -
payload -

AVP

public AVP(int code,
           int vendor_id,
           byte[] payload)
Create AVP with code and payload

Parameters:
code -
vendor_id -
payload -
Method Detail

queryPayload

public byte[] queryPayload()
Returns the payload of the AVP Returns a copy of the (unpadded) payload of the AVP in network byte order. This is normally not what you want. The subclasses have much nicer interfaces.

Since:
0.9.6.5

isVendorSpecific

public boolean isVendorSpecific()
Returns if the AVP is vendor-specific (has non-zero vendor_id)


isMandatory

public boolean isMandatory()
Returns if the mandatory (M) flag is set


isPrivate

public boolean isPrivate()
Returns if the private (P) flag is set


setMandatory

public void setMandatory(boolean b)
Sets/unsets the mandatory (M) flag


setPrivate

public void setPrivate(boolean b)
Sets/unsets the private (P) flag


setM

public AVP setM()
Sets the M-bit and returns the instance. The M-bit (mandatory) is set and the instance is returned. While this is very very simple, it can be useful when constructing grouped AVPs and you need to set the M-bit on embedded AVPs, as in the following example:
          ccr.add(new AVP_Grouped(ProtocolConstants.DI_REQUESTED_SERVICE_UNIT,
                                  new AVP[] {new AVP_Unsigned64(ProtocolConstants.DI_CC_SERVICE_SPECIFIC_UNITS,42).setM()}
                                 )
                 );
          
where the alternative would have been more cumbersome:
          AVP tmp-avp = new AVP_Unsigned64(ProtocolConstants.DI_CC_SERVICE_SPECIFIC_UNITS,42);
          tmp_avp.setMandatory(true);
          ccr.add(new AVP_Grouped(ProtocolConstants.DI_REQUESTED_SERVICE_UNIT,
                                  new AVP[] {tmp_avp}
                                 )
                 );
          

Since:
0.9.2