00001 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ 00002 /* 00003 * Copyright (c) 2005 INRIA 00004 * 00005 * This program is free software; you can redistribute it and/or modify 00006 * it under the terms of the GNU General Public License version 2 as 00007 * published by the Free Software Foundation; 00008 * 00009 * This program is distributed in the hope that it will be useful, 00010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00012 * GNU General Public License for more details. 00013 * 00014 * You should have received a copy of the GNU General Public License 00015 * along with this program; if not, write to the Free Software 00016 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00017 * 00018 * Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr> 00019 */ 00020 00021 #ifndef TRAILER_H 00022 #define TRAILER_H 00023 00024 #include "chunk.h" 00025 #include "buffer.h" 00026 #include <stdint.h> 00027 00028 00029 namespace ns3 { 00030 00031 /** 00032 * \ingroup packet 00033 * 00034 * \brief Protocol trailer serialization and deserialization. 00035 * 00036 * Every Protocol trailer which needs to be inserted or removed 00037 * from a Packet instance must derive from this base class and 00038 * implement the pure virtual methods defined here. 00039 */ 00040 class Trailer : public Chunk 00041 { 00042 public: 00043 static TypeId GetTypeId (void); 00044 virtual ~Trailer (); 00045 /** 00046 * \returns the expected size of the trailer. 00047 * 00048 * This method is used by Packet::AddTrailer 00049 * to store a trailer into the byte buffer of a packet. This method 00050 * should return the number of bytes which are needed to store 00051 * the full trailer data by Serialize. 00052 */ 00053 virtual uint32_t GetSerializedSize (void) const = 0; 00054 /** 00055 * \param start an iterator which points to where the trailer 00056 * should be written. 00057 * 00058 * This method is used by Packet::AddTrailer to 00059 * store a header into the byte buffer of a packet. 00060 * The data written is expected to match bit-for-bit the 00061 * representation of this trailer in real networks. 00062 * The input iterator points to the end of the area where the 00063 * data shall be written. This method is thus expected to call 00064 * Buffer::Iterator::Prev prior to actually writing any data. 00065 */ 00066 virtual void Serialize (Buffer::Iterator start) const = 0; 00067 /** 00068 * \param end an iterator which points to the end of the buffer 00069 * where the trailer should be read from. 00070 * \returns the number of bytes read. 00071 * 00072 * This method is used by Packet::RemoveTrailer to 00073 * re-create a trailer from the byte buffer of a packet. 00074 * The data read is expected to match bit-for-bit the 00075 * representation of this trailer in real networks. 00076 * The input iterator points to the end of the area where the 00077 * data shall be written. This method is thus expected to call 00078 * Buffer::Iterator::Prev prio to actually reading any data. 00079 */ 00080 virtual uint32_t Deserialize (Buffer::Iterator end) = 0; 00081 /** 00082 * This method is used by Packet::Print to print the 00083 * content of a trailer as ascii data to a c++ output stream. 00084 * Although the trailer is free to format its output as it 00085 * wishes, it is recommended to follow a few rules to integrate 00086 * with the packet pretty printer: start with flags, small field 00087 * values located between a pair of parens. Values should be separated 00088 * by whitespace. Follow the parens with the important fields, 00089 * separated by whitespace. 00090 * i.e.: (field1 val1 field2 val2 field3 val3) field4 val4 field5 val5 00091 */ 00092 virtual void Print (std::ostream &os) const = 0; 00093 }; 00094 00095 std::ostream & operator << (std::ostream &os, const Trailer &trailer); 00096 00097 } // namespace ns3 00098 00099 #endif /* TRAILER_H */