| EventStudio 2.5 Sequence diagram based system design and modeling | |
#include <Protocol_Packet.h> Collaboration diagram for Protocol_Packet:

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. | |
|
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};
|
| ||||||||||||
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:
Definition at line 95 of file Protocol_Packet.h. |
|
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.
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 }
|
|
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.
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 }
|
|
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.
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 }
|
|
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.
Definition at line 178 of file Protocol_Packet.h. |
|
Get the total length of the packet. This includes the header, body and trailer length. Definition at line 208 of file Protocol_Packet.h. |
|
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. |
|
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. |
|
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. |
|
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. |
1.3.4 | |
| Copyright © 2000-2005 EventHelix.com Inc. All Rights Reserved. |