Packets documentation updates
[senf.git] / Packets / DefaultBundle / IPv4Packet.hh
index c047b96..e124ee4 100644 (file)
@@ -1,9 +1,9 @@
 // $Id$
 //
 // Copyright (C) 2006
-// Fraunhofer Institut fuer offene Kommunikationssysteme (FOKUS)
-// Kompetenzzentrum fuer Satelitenkommunikation (SatCom)
-//     Stefan Bund <stefan.bund@fokus.fraunhofer.de>
+// Fraunhofer Institute for Open Communication Systems (FOKUS)
+// Competence Center NETwork research (NET), St. Augustin, GERMANY
+//     Stefan Bund <g0dil@berlios.de>
 //
 // This program is free software; you can redistribute it and/or modify
 // it under the terms of the GNU General Public License as published by
@@ -23,8 +23,8 @@
 /** \file
     \brief IPv4Packet public header */
 
-#ifndef HH_IPv4Packet_
-#define HH_IPv4Packet_ 1
+#ifndef HH_SENF_Packets_DefaultBundle_IPv4Packet_
+#define HH_SENF_Packets_DefaultBundle_IPv4Packet_ 1
 
 // Custom includes
 #include "../../Socket/Protocols/INet/INet4Address.hh"
@@ -39,9 +39,9 @@ namespace senf {
 
         \see INet4Address
      */
-    struct Parse_INet4Address : public PacketParserBase
+    struct INet4AddressParser : public PacketParserBase
     {
-        Parse_INet4Address(data_iterator i, state_type s) : PacketParserBase(i,s,fixed_bytes) {}
+        INet4AddressParser(data_iterator i, state_type s) : PacketParserBase(i,s,fixed_bytes) {}
 
         ///////////////////////////////////////////////////////////////////////////
 
@@ -50,9 +50,9 @@ namespace senf {
 
         value_type value() const { return value_type::from_data(i()); }
         void value(value_type const & v) { std::copy(v.begin(), v.end(), i()); }
-        operator value_type() { return value(); }
-        byte & operator[](size_type index) { return *boost::next(i(),index); }
-        Parse_INet4Address const & operator= (value_type const & other) 
+        operator value_type() const { return value(); }
+        byte & operator[](size_type index) const { return *boost::next(i(),index); }
+        INet4AddressParser const & operator= (value_type const & other) 
             { value(other); return *this; }
     };
 
@@ -60,32 +60,34 @@ namespace senf {
 
         Parser implementing the IPv4 header.
         
+        \image html IPv4Packet.png
+                
         \see IPv4PacketType \n
             <a href="http://tools.ietf.org/html/rfc791">RFC 791</a>
 
         \todo Implement options
      */
-    struct Parse_IPv4 : public PacketParserBase
+    struct IPv4PacketParser : public PacketParserBase
     {
 #       include SENF_FIXED_PARSER()
 
         SENF_PARSER_BITFIELD( version,   4, unsigned );
         SENF_PARSER_BITFIELD( ihl,       4, unsigned );
 
-        SENF_PARSER_FIELD( tos,         Parse_UInt8        );
-        SENF_PARSER_FIELD( length,      Parse_UInt16       );
-        SENF_PARSER_FIELD( identifier,  Parse_UInt16       );
+        SENF_PARSER_FIELD( tos,         UInt8Parser        );
+        SENF_PARSER_FIELD( length,      UInt16Parser       );
+        SENF_PARSER_FIELD( identifier,  UInt16Parser       );
 
-        SENF_PARSER_BITFIELD( reserved,  1, bool     );
-        SENF_PARSER_BITFIELD( df,        1, bool     );
-        SENF_PARSER_BITFIELD( mf,        1, bool     );
-        SENF_PARSER_BITFIELD( frag,     13, unsigned );
+        SENF_PARSER_PRIVATE_BITFIELD( reserved,  1, bool     );
+        SENF_PARSER_BITFIELD        ( df,        1, bool     );
+        SENF_PARSER_BITFIELD        ( mf,        1, bool     );
+        SENF_PARSER_BITFIELD        ( frag,     13, unsigned );
 
-        SENF_PARSER_FIELD( ttl,         Parse_UInt8        );
-        SENF_PARSER_FIELD( protocol,    Parse_UInt8        );
-        SENF_PARSER_FIELD( checksum,    Parse_UInt16       );
-        SENF_PARSER_FIELD( source,      Parse_INet4Address );
-        SENF_PARSER_FIELD( destination, Parse_INet4Address );
+        SENF_PARSER_FIELD( ttl,         UInt8Parser        );
+        SENF_PARSER_FIELD( protocol,    UInt8Parser        );
+        SENF_PARSER_FIELD( checksum,    UInt16Parser       );
+        SENF_PARSER_FIELD( source,      INet4AddressParser );
+        SENF_PARSER_FIELD( destination, INet4AddressParser );
 
         SENF_PARSER_INIT() {
             version() = 4;
@@ -93,13 +95,18 @@ namespace senf {
             ihl() = 5;
         }
 
-        SENF_PARSER_FINALIZE(Parse_IPv4);
+        SENF_PARSER_FINALIZE(IPv4PacketParser);
         
-        boost::uint16_t calcChecksum() const;
+        boost::uint16_t calcChecksum() const; ///< calculate header checksum
+                                              /**< calculate and return the checksum of the header
+                                                   \see \ref senf::IpChecksum */
 
         bool validateChecksum() const {
             return checksum() == calcChecksum();
-        }
+        }                               ///< validate header checksum
+                                        /**< return \c true if the \ref checksum() "checksum" 
+                                             field is equal to the \ref calcChecksum() 
+                                             "calculated checksum" */
     };
 
     /** \brief IP protocol number registry
@@ -114,6 +121,12 @@ namespace senf {
     };
 
     /** \brief IPv4 packet
+        
+        \par Packet type (typedef):
+            \ref IPv4Packet
+
+        \par Fields:
+            see \ref IPv4PacketParser
 
         <table class="packet" cellpadding="5" cellspacing="1" border="1">
           <tr>
@@ -123,41 +136,33 @@ namespace senf {
             <th width="12%">20</th> <th width="12%">24</th> <th width="6%">28</th>
             <th style="text-align:right" width="6%">31</th>
           </tr><tr>
-            <td>\ref Parse_IPv4::version() "Version"</td>
-            <td>\ref Parse_IPv4::ihl() "IHL"</td>
-            <td colspan="2">\ref Parse_IPv4::tos() "TOS"</td>
-            <td colspan="8">\ref Parse_IPv4::length() "Length"</td> 
+            <td>\ref IPv4PacketParser::version() "Version"</td>
+            <td>\ref IPv4PacketParser::ihl() "IHL"</td>
+            <td colspan="2">\ref IPv4PacketParser::tos() "TOS"</td>
+            <td colspan="8">\ref IPv4PacketParser::length() "Length"</td> 
           </tr><tr>
-            <td colspan="4">\ref Parse_IPv4::identifier() "Identifier"</td>
-            <td>\ref Parse_IPv4::reserved() "R"</td>
-            <td>\ref Parse_IPv4::df() "DF"</td>
-            <td>\ref Parse_IPv4::mf() "MF"</td>
-            <td colspan="5">\ref Parse_IPv4::frag() "Fragment Offset"</td>
+            <td colspan="4">\ref IPv4PacketParser::identifier() "Identifier"</td>
+            <td>R</td>
+            <td>\ref IPv4PacketParser::df() "DF"</td>
+            <td>\ref IPv4PacketParser::mf() "MF"</td>
+            <td colspan="5">\ref IPv4PacketParser::frag() "Fragment Offset"</td>
           </tr><tr>
-            <td colspan="2">\ref Parse_IPv4::ttl() "Time to Live (ttl)"</td>
-            <td colspan="2">\ref Parse_IPv4::protocol() "Protocol"</td>
-            <td colspan="8">\ref Parse_IPv4::checksum() "Header Checksum"</td>
+            <td colspan="2">\ref IPv4PacketParser::ttl() "Time to Live (ttl)"</td>
+            <td colspan="2">\ref IPv4PacketParser::protocol() "Protocol"</td>
+            <td colspan="8">\ref IPv4PacketParser::checksum() "Header Checksum"</td>
           </tr><tr>
-            <td colspan="12">\ref Parse_IPv4::source() "Source Address"</td>
+            <td colspan="12">\ref IPv4PacketParser::source() "Source Address"</td>
           </tr><tr>
-            <td colspan="12">\ref Parse_IPv4::destination() "Destination Address"</td>
+            <td colspan="12">\ref IPv4PacketParser::destination() "Destination Address"</td>
           </tr>
         </table>
-        
-        \par Packet type (typedef):
-            \ref IPv4Packet
-
-        \par Fields:
-            \ref Parse_IPv4
 
         \par Associated registries:
             \ref IpTypes
 
         \par Finalize action:
-            Set \a length from payload size\n
-            Set \a protocol from type of next packet if found in \ref IpTypes\n
-            Calculate \a checksum
-
+            \copydetails finalize()
         \ingroup protocolbundle_default
      */
     struct IPv4PacketType
@@ -166,21 +171,30 @@ namespace senf {
     {
 #ifndef DOXYGEN
         typedef PacketTypeMixin<IPv4PacketType, IpTypes> mixin;
-        typedef ConcretePacket<IPv4PacketType> packet;
-        typedef Parse_IPv4 parser;
 #endif
+        typedef ConcretePacket<IPv4PacketType> packet;  ///< IPv4 packet typedef
+        typedef IPv4PacketParser parser;                ///< typedef to the parser of IPv4 packet
+
         using mixin::nextPacketRange;
         using mixin::nextPacketType;
         using mixin::initSize;
         using mixin::init;
 
-        static registry_key_t nextPacketKey(packet p) 
+        static key_t nextPacketKey(packet p) 
             { return p->protocol(); }
-
-        static void dump(packet p, std::ostream & os);
-        static void finalize(packet p);
-    };
         
+        /** \brief Dump given IPv4Packet in readable form to given output stream */
+        static void dump(packet p, std::ostream & os); 
+        
+        static void finalize(packet p); ///< Finalize packet.
+                                        /**< \li set \ref IPv4PacketParser::length() "length" 
+                                               from payload size
+                                             \li set \ref IPv4PacketParser::protocol() "protocol" 
+                                               from type of next packet if found in \ref IpTypes
+                                             \li calculate and set 
+                                               \ref IPv4PacketParser::checksum() "checksum" */
+    };
+
     /** \brief IPv4 packet typedef */
     typedef ConcretePacket<IPv4PacketType> IPv4Packet;
 }
@@ -189,7 +203,7 @@ namespace senf {
 ///////////////////////////////hh.e////////////////////////////////////////
 #endif
 #ifndef SENF_PACKETS_DECL_ONLY
-//#include IPv4Packet.cci"
+//#include "IPv4Packet.cci"
 //#include "IPv4Packet.ct"
 //#include "IPv4Packet.cti"
 #endif