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 HEADER_H 00022 #define HEADER_H 00023 00024 #include "chunk.h" 00025 #include "buffer.h" 00026 #include <stdint.h> 00027 00028 namespace ns3 { 00029 00030 /** 00031 * \ingroup packet 00032 * 00033 * \brief Protocol header serialization and deserialization. 00034 * 00035 * Every Protocol header which needs to be inserted or removed 00036 * from a Packet instance must derive from this base class and 00037 * implement the pure virtual methods defined here. 00038 * 00039 * Sample code which shows how to create a new type of Header, and how to use it, 00040 * is shown in the sample file samples/main-packet-header.cc 00041 */ 00042 class Header : public Chunk 00043 { 00044 public: 00045 static TypeId GetTypeId (void); 00046 virtual ~Header (); 00047 /** 00048 * \returns the expected size of the header. 00049 * 00050 * This method is used by Packet::AddHeader 00051 * to store a header into the byte buffer of a packet. This method 00052 * should return the number of bytes which are needed to store 00053 * the full header data by Serialize. 00054 */ 00055 virtual uint32_t GetSerializedSize (void) const = 0; 00056 /** 00057 * \param start an iterator which points to where the header should 00058 * be written. 00059 * 00060 * This method is used by Packet::AddHeader to 00061 * store a header into the byte buffer of a packet. 00062 * The data written 00063 * is expected to match bit-for-bit the representation of this 00064 * header in a real network. 00065 */ 00066 virtual void Serialize (Buffer::Iterator start) const = 0; 00067 /** 00068 * \param start an iterator which points to where the header should 00069 * written. 00070 * \returns the number of bytes read. 00071 * 00072 * This method is used by Packet::RemoveHeader to 00073 * re-create a header from the byte buffer of a packet. 00074 * The data read is expected to 00075 * match bit-for-bit the representation of this header in real 00076 * networks. 00077 */ 00078 virtual uint32_t Deserialize (Buffer::Iterator start) = 0; 00079 /** 00080 * This method is used by Packet::Print to print the 00081 * content of a trailer as ascii data to a c++ output stream. 00082 * Although the trailer is free to format its output as it 00083 * wishes, it is recommended to follow a few rules to integrate 00084 * with the packet pretty printer: start with flags, small field 00085 * values located between a pair of parens. Values should be separated 00086 * by whitespace. Follow the parens with the important fields, 00087 * separated by whitespace. 00088 * i.e.: (field1 val1 field2 val2 field3 val3) field4 val4 field5 val5 00089 */ 00090 virtual void Print (std::ostream &os) const = 0; 00091 }; 00092 00093 std::ostream & operator << (std::ostream &os, const Header &header); 00094 00095 } // namespace ns3 00096 00097 #endif /* HEADER_H */