| |
- Message
class Message |
|
A Diameter message (header and AVPs)
The Message is a container for the MessageHeader and the AVP s.
It supports converting to/from the on-the-wire format, and
manipulating the AVPs. The class is lean and mean, and does as little
checking as possible.
Example of building a Message:
msg = Message()
msg.hdr.application_id = ProtocolConstants.DIAMETER_APPLICATION_ACCOUNTING
msg.hdr.command_code = ProtocolConstants.DIAMETER_COMMAND_ACCOUNTING
msg.hdr.setRequest(True)
msg.hdr.setProxiable(True)
#Add AVPs
...
msg.add(AVP_UTF8String(ProtocolConstants.DI_USER_NAME,"user@example.net"))
msg.add(AVP_Unsigned64(ProtocolConstants.DI_ACCOUNTING_INPUT_OCTETS,36758373691049))
...
Example of processing a message:
msg ...
for avp in msg.subset(ProtocolConstants.DI_FRAMED_IP_ADDRESS):
try:
address = AVP_Address.narrow(avp).queryAddress()
#..do something useful with the address...
except InvalidAVPLengthError, ex:
#.. handle when peer sends garbage
except InvalidAddressTypeError, ex:
#.. handle when peer sends garbage
avp_reply_message = msg.find(ProtocolConstants.DI_REPLY_MESSAGE)
if avp:
#..do something sensible with reply-message |
|
Methods defined here:
- __delitem__(self, key)
- __getitem__(self, key)
- __init__(self, that=None)
- __iter__(self)
- __len__(self)
- __setitem__(self, key, value)
- append(self, a)
- Appends an AVP to the message
- count(self, code, vendor_id=0)
- Return the number of AVPs that matches the specified code (and vendor_id if nonzero)
- decode(self, unpacker, bytes)
- Decode a message from on-the-wire format.
The message is checked to be in valid format and the VPs to be of
the correct length etc. Invalid/reserved bits are not checked.
unpacker a xdrlib.Unpacker possibly containing a Diameter message
bytes the bytes to try to decode
Return the result for the decode operation.
- encode(self, packer)
- Encode the message in on-the-wire format to the specified byte array.
packer: xdrlib.Packer
- encodeSize(self)
- Calculate the size of the message in on-the-wire format.
Returns the number of bytes the message will use on-the-wire.
- find(self, code, vendor_id=0)
- Returns the first AVP with a matching code (and vendor_id if nonzero).
- prepareResponse(self, request)
- Prepare a response the the supplied request.
Implemented as hdr.prepareResponse(request.hdr)
See: MessageHeader.prepareResponse
- subset(self, code, vendor_id=0)
- Returns an iteratable subset of the AVPs where the code and vendor_id match
Static methods defined here:
- decodeSize(unpacker)
- Determine the complete size of the message from a on-the-wire
byte array.
There must be at least 4 bytes available in the array.
unpacker: a xdrlib.Unpacker
Returns the size (in bytes) of the message
Data and other attributes defined here:
- decode_status_decoded = 1
- decode_status_garbage = 3
- decode_status_not_enough = 2
| |