EventHelix.com: CASE Tools; Real-time and Embedded System Design; Object Oriented Design EventStudio 2.0: System Engineering CASE ToolEventStudio 2.5
Sequence diagram based system design and modeling
Home   What's New   EventStudio 2.5   Real-time Mantra   Thought Projects   Contact Us
Main Page | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | File Members

Protocol_Packet Class Reference

#include <Protocol_Packet.h>

Collaboration diagram for Protocol_Packet:

Collaboration graph
[legend]
List of all members.

Detailed Description

The Protocol Packet class supports dynamic addition and extraction of protocol layers without needing multiple copies of the messages when it is exchanged between protocol layers.

This is accomplished by defining a raw byte buffer that can hold the complete data packet when all the layers have been added. Pointers are maintained for the header, body and trailer parts of the packet. These pointers get adjusted when packets move between layer boundaries.

If a higher layer gives a packet to the lower layer, the higher layer's header, body and footer are considered as body by the lower layer. The lower layer adds its own headers and footers. To avoid multiple copies of the packet, the packet class is designed to allow the packet to grow in both directions. Space is earmarked for the header as well as the footer. Addition of layer headers uses this space. The layer addition is implemented using Add_Header and Add_Trailer methods.

In the receive direction the packet processing is reversed. So the packet body of a lower layer will be considered to be made of header, body and trailer of the higher layer. Thus when the message passes from lower to higher layers, each layer extracts its own headers/ trailers and passes the body to the next higher layer. The layer extraction is implemented by the Extract_Header and Extract_Trailer method.

Definition at line 35 of file Protocol_Packet.h.

Public Member Functions

 Protocol_Packet (int body_Length, int body_Offset)
 The Protocol_Packet constructor is initialized with the body of the message.

void Add_Header (int length)
 Adds a header of the specified length.

void Add_Trailer (int length)
 Adds a trailer of the specific length.

void Extract_Header (int length)
 Extract a header of specific length from the packet.

void Extract_Trailer (int length)
 Extract a trailer of specific length from the packet.

char * Get_Header ()
 Get a pointer to the header.

char * Get_Body ()
 Get a pointer to the body.

char * Get_Trailer ()
 Get a pointer to the trailer.

int Get_Length ()
 Get the total length of the packet.


Private Types

enum  
 The packet size limit is defined here. More...


Private Attributes

Region m_header
 The header of the packet is the first region in the packet.

Region m_body
 The body of the packet is the second region.

Region m_trailer
 The trailer is the first and the last region in the packet.

char m_buffer [MAXIMUM_PACKET_LENGTH]
 The buffer that is accessed by the regions of the packet.


Member Enumeration Documentation

anonymous enum [private]
 

The packet size limit is defined here.

Note that the size given here included the worst case headers and footers that can be added by any layer in the protocol.

Definition at line 39 of file Protocol_Packet.h.

00039 { MAXIMUM_PACKET_LENGTH = 1500};


Constructor & Destructor Documentation

Protocol_Packet::Protocol_Packet int body_Length,
int body_Offset
[inline]
 

The Protocol_Packet constructor is initialized with the body of the message.

The starting offset of the body is also specified in the message. The constructor is used in two distinct operating modes:

  • Receive Packet: In this mode, the entire received packet is passed as the body to the Packet constructor. The starting offset is specified as 0. This packet will be received by the lowest layer. As the packet is moved to the higher layers, each layer will extract the header and trailers defined for that layer. The size and the starting offset of the body will change as the different layers are extracted.
  • Transmit Packet: When transmitting a packet, the application layer data constitutes the body of the packet. The constructor should be invoked with the length of the application length. The body starting offset would be determined by the size of the total headers that will be added by the lower layers.

Parameters:
body_Length In a Receive Packet, the length is for the entire received packet should be passed. In Transmit mode, the length field is set based on the application data that needs to be transmitted.
body_Offset In a Receive Packet, the offset should be set to 0. In a Transmit packet, the offset is based on the worst case headers that might be added by the lower layers.

Definition at line 95 of file Protocol_Packet.h.

00096     {
00097         m_header.length = 0;
00098         m_trailer.length = 0;
00099         m_body.offset = body_Offset;
00100         m_body.length = body_Length;
00101     }


Member Function Documentation

void Protocol_Packet::Add_Header int length  ) [inline]
 

Adds a header of the specified length.

When the new header is added, header of the previous layer would be considered a part of the body. Thus the size of the body is increased to reflect this. The body start offset is also moved up.

This method will be used when a transmit packet has to be prepared. A header will be added by every layer involved in transmission of a packet.

Parameters:
length Length of the header to be added.

Definition at line 113 of file Protocol_Packet.h.

00114     {
00115         // Consider the header of the higher layer to be a part of
00116         // the body for the this layer.
00117         m_body.offset -= m_header.length;
00118         m_body.length += m_header.length;
00119 
00120         // Save the length and header offset of the new layer. Addition
00121         // of the header would move up the header offset.
00122         m_header.length = length;
00123         m_header.offset = m_body.offset - length;      
00124     }

void Protocol_Packet::Add_Trailer int length  ) [inline]
 

Adds a trailer of the specific length.

When a new trailer is added, the trailer defined by the previous layer is considered to be a part of the body. The new trailer is added at the end of the message.

This method will be used when a transmit packet has to be prepared. A trailer will be added by every layer involved in transmission of a packet.

Parameters:
length Length of the trailer to be added.

Definition at line 135 of file Protocol_Packet.h.

00136     {
00137         // Consider the trailer of the higher layer to be a part of
00138         // the body of this layer.
00139         m_body.length += m_trailer.length;
00140 
00141         // Now add the trailer at the end of the updated body.
00142         m_trailer.length = length;
00143         m_trailer.offset = m_body.offset + m_body.length;
00144     }

void Protocol_Packet::Extract_Header int length  ) [inline]
 

Extract a header of specific length from the packet.

The header is removed from the current body. Any previous header definition is lost. The method also reduces the size of the body. The body start offset and the starting point are adjusted to take care of the header that has been carved out of the body.

This method will be used when a receive packet has to be processed. Each layer will extract the header corresponding to the layer.

Parameters:
length Length of the header to be extracted.

Definition at line 157 of file Protocol_Packet.h.

00158     {
00159         // Update the new header. The header begins at current
00160         // body start offset.
00161         m_header.offset = m_body.offset;
00162         m_header.length = length;
00163 
00164         // Reduce the body size to account for the removed header.
00165         m_body.offset += length;
00166         m_body.length -= length;
00167     }

void Protocol_Packet::Extract_Trailer int length  ) [inline]
 

Extract a trailer of specific length from the packet.

The new trailer is carved out of the body. The body end is reduced in size to account for the extracted trailer.

This method will be used when a receive packet has to be processed. Each layer will extract the trailer corresponding to the layer.

Parameters:
length Length of the trailer to be extracted.

Definition at line 178 of file Protocol_Packet.h.

00179     {
00180         // Reduce the length to adjust for the extracted trailer.
00181         m_body.length -= length;
00182 
00183         // Setup the trailer to start at the end of the body.
00184         m_trailer.offset = m_body.offset + m_body.length;
00185         m_trailer.length = length;
00186     }

int Protocol_Packet::Get_Length  ) [inline]
 

Get the total length of the packet.

This includes the header, body and trailer length.

Definition at line 208 of file Protocol_Packet.h.

00209     {
00210         return (m_header.length + m_body.length + m_trailer.length);
00211     }


Member Data Documentation

Region Protocol_Packet::m_header [private]
 

The header of the packet is the first region in the packet.

Each layer in the protocol adds/extracts its own header.

Definition at line 54 of file Protocol_Packet.h.

Region Protocol_Packet::m_body [private]
 

The body of the packet is the second region.

This data is treated as the payload and just needs to be carried in a transparent fashion.

Definition at line 58 of file Protocol_Packet.h.

Region Protocol_Packet::m_trailer [private]
 

The trailer is the first and the last region in the packet.

Each layer in the protocol adds/extracts its own trailer.

Definition at line 62 of file Protocol_Packet.h.

char Protocol_Packet::m_buffer[MAXIMUM_PACKET_LENGTH] [private]
 

The buffer that is accessed by the regions of the packet.

The region definitions in the packet are changed dynamically as layers are added/extracted.

Definition at line 66 of file Protocol_Packet.h.


The documentation for this class was generated from the following file:
Generated on Sun Feb 13 21:30:35 2005 for Object Oriented Design Examples by doxygen 1.3.4
 Home   What's New   EventStudio 2.5   Real-time Mantra   Thought Projects   Contact Us
Copyright © 2000-2005 EventHelix.com Inc. All Rights Reserved.