xorp

Packet Class Reference

An OLSR packet containing Messages. More...

#include <message.hh>

Inheritance diagram for Packet:
DataDescriptionPacket HelloPacket LinkStateAcknowledgementPacket LinkStateRequestPacket LinkStateUpdatePacket

List of all members.

Public Member Functions

 Packet (MessageDecoder &md, OlsrTypes::FaceID faceid=0)
size_t length () const
size_t mtu_bound () const
size_t bounded_length () const
void decode (uint8_t *ptr, size_t len) throw (InvalidPacket)
size_t decode_packet_header (uint8_t *ptr, size_t len) throw (InvalidPacket)
 Decode an OLSR packet header.
bool encode (vector< uint8_t > &pkt)
 Encode a packet, including any nested messages.
void update_encoded_seqno (vector< uint8_t > &pkt)
uint16_t seqno () const
void set_seqno (uint16_t seqno)
OlsrTypes::FaceID faceid () const
uint32_t mtu () const
void set_mtu (const uint32_t mtu)
void set_faceid (OlsrTypes::FaceID faceid)
string str () const
void add_message (Message *m)
void clear ()
const vector< Message * > & messages ()
vector< Message * > & get_messages ()
 Get a non-const reference to a packet's messages.
bool valid () const
vector< uint8_t > & get ()
void store (uint8_t *ptr, size_t len)
 Packet (OspfTypes::Version version)
size_t decode_standard_header (uint8_t *ptr, size_t &len) throw (InvalidPacket)
 Decode standard header.
virtual Packetdecode (uint8_t *ptr, size_t len) const =0 throw (InvalidPacket)
 Decode the packet.
size_t encode_standard_header (uint8_t *ptr, size_t len)
 Encode standard header.
virtual bool encode (vector< uint8_t > &pkt)=0
 Encode the packet.
void store (uint8_t *ptr, size_t len)
 Store the original packet, required for authentication.
vector< uint8_t > & get ()
 Get a reference to the original packet data, required for authentication.
OspfTypes::Version get_version () const
virtual OspfTypes::Type get_type () const =0
 It is the responsibilty of the derived type to return this information.
OspfTypes::RouterID get_router_id () const
 Get the Router ID.
void set_router_id (OspfTypes::RouterID id)
 Set the Router ID.
OspfTypes::AreaID get_area_id () const
 Get the Area ID.
void set_area_id (OspfTypes::AreaID id)
 Set the Area ID.
uint16_t get_auth_type () const
 Get the Auth Type.
void set_auth_type (uint16_t auth_type)
 Set the Auth Type.
uint8_t get_instance_id () const
 Get the Instance ID.
void set_instance_id (uint8_t instance_id)
 Set the Instance ID.
size_t get_standard_header_length ()
size_t decode_point () const
 Decode Point.
string standard () const
 Generate a printable representation of the standard header.
virtual string str () const =0
 Generate a printable representation of the packet.

Static Public Member Functions

static size_t get_packet_header_length ()

Static Public Attributes

static const size_t STANDARD_HEADER_V2 = 24
static const size_t STANDARD_HEADER_V3 = 16
static const size_t VERSION_OFFSET = 0
static const size_t TYPE_OFFSET = 1
static const size_t LEN_OFFSET = 2
static const size_t ROUTER_ID_OFFSET = 4
static const size_t AREA_ID_OFFSET = 8
static const size_t CHECKSUM_OFFSET = 12
static const size_t AUTH_TYPE_OFFSET = 14
static const size_t AUTH_PAYLOAD_OFFSET = 16
static const size_t AUTH_PAYLOAD_SIZE = 8
static const size_t INSTANCE_ID_OFFSET = 14

Private Attributes

MessageDecoder_message_decoder
bool _is_valid
OlsrTypes::FaceID _faceid
uint16_t _seqno
uint32_t _mtu
vector< Message * > _messages
vector< uint8_t > _pkt
const OspfTypes::Version _version
bool _valid
 Set to true when the standard header fields are set.
OspfTypes::RouterID _router_id
 Standard header.
OspfTypes::AreaID _area_id
OspfTypes::AuType _auth_type
uint8_t _auth [AUTH_PAYLOAD_SIZE]
uint8_t _instance_id

Detailed Description

An OLSR packet containing Messages.

All packet decode routines must inherit from this interface.

Packets contain Messages. They are coalesced up up to the available MTU size, to save power on devices where transmission may have a high energy cost.

Also provides some utility routines to perform common packet processing.


Member Function Documentation

size_t Packet::bounded_length ( ) const
Returns:
the size of the packet payload which will fit inside the MTU without splitting any messages. If no MTU is set, returns length().
virtual Packet* Packet::decode ( uint8_t *  ptr,
size_t  len 
) const throw (InvalidPacket) [pure virtual]

Decode the packet.

The returned packet must be free'd.

Implemented in HelloPacket, DataDescriptionPacket, LinkStateRequestPacket, LinkStateUpdatePacket, and LinkStateAcknowledgementPacket.

size_t Packet::decode_packet_header ( uint8_t *  ptr,
size_t  len 
) throw (InvalidPacket)

Decode an OLSR packet header.

An OLSR packet is considered valid if its length is greater than the size of a standard packet header. The host IP stack takes care of UDP checksums, IP fragmentation and reassembly, and MTU size checks for us.

size_t Packet::decode_point ( ) const

Decode Point.

If a packet is being decoded the standard header has already been processed. This method returns the offset at which the specific data starts.

Returns:
The offset at which a derived class should start decoding.
size_t Packet::decode_standard_header ( uint8_t *  ptr,
size_t &  len 
) throw (InvalidPacket)

Decode standard header.

Used by the derived classes to extract the standard header and options field.

Parameters:
lenif the frame is larger than what is specified by the header length field drop the length down to the header length.
Returns:
the offset where the specific header starts.
virtual bool Packet::encode ( vector< uint8_t > &  pkt) [pure virtual]

Encode the packet.

Parameters:
pktvector into which the packet should be placed.
Returns:
true if the encoding suceeded.

Implemented in HelloPacket, DataDescriptionPacket, LinkStateRequestPacket, LinkStateUpdatePacket, and LinkStateAcknowledgementPacket.

size_t Packet::encode_standard_header ( uint8_t *  ptr,
size_t  len 
)

Encode standard header.

Used by the derived classes to put the standard header in the packet. Which includes the checksum so all other fields should already be in the packet.

Parameters:
ptrlocation to start writing header.
lensize of the buffer.
Returns:
The offset that the header has been written to. Returns 0 on failure, such as the buffer is too small.
vector<Message*>& Packet::get_messages ( ) [inline]

Get a non-const reference to a packet's messages.

For debugging use only, ie in simulation of multiple hops.

Returns:
reference to the messages contained within the packet.
size_t Packet::get_standard_header_length ( ) [inline]
Returns:
the standard header length for this version of OSPF.
virtual OspfTypes::Type Packet::get_type ( ) const [pure virtual]

It is the responsibilty of the derived type to return this information.

Returns:
The type this packet represents.

Implemented in HelloPacket, DataDescriptionPacket, LinkStateRequestPacket, LinkStateUpdatePacket, and LinkStateAcknowledgementPacket.

OspfTypes::Version Packet::get_version ( ) const [inline]
Returns:
The version this packet represents.
size_t Packet::length ( ) const
Returns:
the size of the packet payload.
size_t Packet::mtu_bound ( ) const
Returns:
the amount of free space in this packet for an OLSR packet payload, after MTU is taken into account.
string Packet::standard ( ) const

Generate a printable representation of the standard header.

Used by the derived classes implementing str().

string Packet::str ( ) const
Returns:
a string representation of the entire packet.

Reimplemented in HelloPacket, DataDescriptionPacket, LinkStateRequestPacket, LinkStateUpdatePacket, and LinkStateAcknowledgementPacket.


Member Data Documentation

Standard header.

Version and Type information are constant so therefore not present.


The documentation for this class was generated from the following files:
 All Classes Namespaces Functions Variables Typedefs Enumerations