693d260ee2539125d7560a9e3c2da27cf89fc149
[senf.git] / Packets / IpV6Packet.hh
1 // Copyright (C) 2007 
2 // Fraunhofer Institut fuer offene Kommunikationssysteme (FOKUS)
3 // Kompetenzzentrum fuer Satelitenkommunikation (SatCom)
4 //     Stefan Bund <g0dil@berlios.de>
5 //
6 // This program is free software; you can redistribute it and/or modify
7 // it under the terms of the GNU General Public License as published by
8 // the Free Software Foundation; either version 2 of the License, or
9 // (at your option) any later version.
10 //
11 // This program is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 // GNU General Public License for more details.
15 //
16 // You should have received a copy of the GNU General Public License
17 // along with this program; if not, write to the
18 // Free Software Foundation, Inc.,
19 // 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
20
21 /** \file
22     \brief IpV6Packet public header */
23
24 #ifndef HH_IpV6Packet_
25 #define HH_IpV6Packet_ 1
26
27 // Custom includes
28 #include "Packet.hh"
29 #include "ParseInt.hh"
30 #include "ParseArray.hh"
31 #include "PacketRegistry.hh"
32 #include "IpV4Packet.hh"
33
34 //#include "IpV6Packet.mpp"
35 ///////////////////////////////hh.p////////////////////////////////////////
36
37 namespace senf {
38
39     // See RFC2460
40     template <class Iterator=nil, class IpV6Packet=nil>
41     struct Parse_IpV6 : public ParserBase<Iterator,IpV6Packet>
42     {
43         template <class I, class P=nil>
44         struct rebind { typedef Parse_IpV6<I,P> parser; };
45         typedef Iterator byte_iterator;
46
47         Parse_IpV6() {}
48         Parse_IpV6(Iterator const & i) : ParserBase<Iterator,IpV6Packet>(i) {}
49
50         static unsigned bytes() { return 40; }
51         
52         ///////////////////////////////////////////////////////////////////////////
53
54         typedef Parse_UIntField <  0,  4, Iterator > Parse_Version;
55         typedef Parse_UIntField <  4, 12, Iterator > Parse_Class;
56         typedef Parse_UIntField < 12, 32, Iterator > Parse_FlowLabel;
57         typedef Parse_UInt8     <         Iterator > Parse_8bit;
58         typedef Parse_UInt16    <         Iterator > Parse_16bit;
59
60         typedef Parse_Array < 16, Parse_8bit, Iterator > Parse_Addr;
61
62         Parse_Version    version()       const { return Parse_Version   (this->i()      ); }
63         Parse_Class      trafficClass()  const { return Parse_Class     (this->i()      ); }
64         Parse_FlowLabel  flowLabel()     const { return Parse_FlowLabel (this->i()      ); }
65         Parse_16bit      length()        const { return Parse_16bit     (this->i() +  4 ); }
66         Parse_8bit       nextHeader()    const { return Parse_8bit      (this->i() +  6 ); }
67         Parse_8bit       hopLimit()      const { return Parse_8bit      (this->i() +  7 ); }
68         Parse_Addr       source()        const { return Parse_Addr      (this->i() +  8 ); }
69         Parse_Addr       destination()   const { return Parse_Addr      (this->i() + 24 ); }
70     };
71
72     class IpV6Packet
73         : public Packet,
74           public Parse_IpV6<Packet::iterator, IpV6Packet>,
75           public PacketRegistryMixin<IpTypes, IpV6Packet>
76     {
77         using PacketRegistryMixin<IpTypes,IpV6Packet>::registerInterpreter;
78     public:
79         ///////////////////////////////////////////////////////////////////////////
80         // Types
81
82         typedef ptr_t<IpV6Packet>::ptr ptr;
83
84         ///////////////////////////////////////////////////////////////////////////
85
86     private:
87         template <class Arg>
88         IpV6Packet(Arg const & arg);
89
90         virtual void v_nextInterpreter() const;
91         virtual void v_finalize();
92         virtual void v_dump(std::ostream & os) const;
93
94         friend class Packet;
95     };
96
97 }    
98
99 ///////////////////////////////hh.e////////////////////////////////////////
100 //#include "IpV6Packet.cci"
101 //#include "IpV6Packet.ct"
102 #include "IpV6Packet.cti"
103 #endif
104
105 \f
106 // Local Variables:
107 // mode: c++
108 // fill-column: 100
109 // c-file-style: "senf"
110 // ispell-local-dictionary: "american"
111 // End: