switch to new MPL based Fraunhofer FOKUS Public License
[senf.git] / senf / Packets / DefaultBundle / NDPOptions.hh
1 // $Id$
2 //
3 // Copyright (C) 2010
4 // Fraunhofer Institute for Open Communication Systems (FOKUS)
5 //
6 // The contents of this file are subject to the Fraunhofer FOKUS Public License
7 // Version 1.0 (the "License"); you may not use this file except in compliance
8 // with the License. You may obtain a copy of the License at 
9 // http://senf.berlios.de/license.html
10 //
11 // The Fraunhofer FOKUS Public License Version 1.0 is based on, 
12 // but modifies the Mozilla Public License Version 1.1.
13 // See the full license text for the amendments.
14 //
15 // Software distributed under the License is distributed on an "AS IS" basis, 
16 // WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License 
17 // for the specific language governing rights and limitations under the License.
18 //
19 // The Original Code is Fraunhofer FOKUS code.
20 //
21 // The Initial Developer of the Original Code is Fraunhofer-Gesellschaft e.V. 
22 // (registered association), Hansastraße 27 c, 80686 Munich, Germany.
23 // All Rights Reserved.
24 //
25 // Contributor(s):
26 //   Stefan Sauer <ssauer@berlios.de>
27
28 // Definition of non-inline non-template functions
29
30 #ifndef HH_SENF_Packets_DefaultBundle_NDPOptions_
31 #define HH_SENF_Packets_DefaultBundle_NDPOptions_ 1
32
33 // Custom includes
34 #include <senf/Packets/Packets.hh>
35 #include <senf/Packets/DefaultBundle/EthernetPacket.hh>
36 #include <senf/Packets/DefaultBundle/IPv6Packet.hh>
37
38 //-/////////////////////////////////////////////////////////////////////////////////////////////////
39 namespace senf {
40
41     //#############################################################
42     //ICMPv6 Neighbor Discovery (RFC 4861) Options
43     //#############################################################
44     struct NDPOptionParser : public PacketParserBase
45     {
46     public:
47 #       include SENF_PARSER()
48         SENF_PARSER_FIELD    ( type, UInt8Parser );
49         SENF_PARSER_FIELD    ( length, UInt8Parser );
50         SENF_PARSER_FINALIZE ( NDPOptionParser );
51
52         typedef GenericTLVParserRegistry<NDPOptionParser> Registry;
53     };
54
55     struct NDPGenericOptionParser : public GenericTLVParserBase<NDPOptionParser>
56     {
57         typedef GenericTLVParserBase<NDPOptionParser> base;
58         NDPGenericOptionParser(data_iterator i, state_type s) : base(i,s) {}
59
60         senf::PacketParserBase::size_type bytes() const
61         {
62             return length()*8;
63         }
64     };
65
66     struct NDPSourceLLAddressTLVParser : public NDPOptionParser
67     {
68 #       include SENF_PARSER()
69         SENF_PARSER_INHERIT  ( NDPOptionParser );
70         SENF_PARSER_FIELD    ( source, MACAddressParser);
71         SENF_PARSER_FINALIZE ( NDPSourceLLAddressTLVParser);
72
73         SENF_PARSER_INIT() {
74             defaultInit();
75             type() = typeId;
76             length() = 1;
77         }
78         static const type_t::value_type typeId = 0x01;
79         void dump(std::ostream & os) const;
80     };
81
82     struct NDPTargetLLAddressTLVParser : public NDPOptionParser
83     {
84 #       include SENF_PARSER()
85         SENF_PARSER_INHERIT  ( NDPOptionParser );
86         SENF_PARSER_FIELD    ( target, MACAddressParser );
87         SENF_PARSER_FINALIZE ( NDPTargetLLAddressTLVParser );
88
89         SENF_PARSER_INIT() {
90             defaultInit();
91             type() = typeId;
92             length() = 1;
93         }
94
95         senf::PacketParserBase::size_type bytes(NDPTargetLLAddressTLVParser p) {
96                     return length()*8;
97         }
98         static const type_t::value_type typeId = 0x02;
99         void dump(std::ostream & os) const;
100     };
101
102     struct NDPPrefixInformationTLVParser : public NDPOptionParser
103     {
104 #       include SENF_PARSER()
105         SENF_PARSER_INHERIT          ( NDPOptionParser );
106         SENF_PARSER_FIELD            ( prefixLength, UInt8Parser );
107         SENF_PARSER_BITFIELD         ( l, 1, bool );
108         SENF_PARSER_BITFIELD         ( a, 1, bool );
109         SENF_PARSER_PRIVATE_BITFIELD ( reserved1, 6, unsigned );
110         SENF_PARSER_FIELD            ( validLifetime, UInt32Parser );
111         SENF_PARSER_FIELD            ( preferredLifetime, UInt32Parser );
112         SENF_PARSER_PRIVATE_BITFIELD ( reserved2, 32, unsigned );
113         SENF_PARSER_FIELD            ( prefix, INet6AddressParser );
114         SENF_PARSER_FINALIZE         ( NDPPrefixInformationTLVParser );
115
116         SENF_PARSER_INIT() {
117             defaultInit();
118             type() = typeId;
119             length() = 4;
120             reserved1() = 0;
121             reserved2() = 0;
122         }
123         senf::PacketParserBase::size_type bytes(NDPPrefixInformationTLVParser p) {
124             return length()*8;
125         }
126         static const UInt8Parser::value_type typeId = 0x03;
127         void dump(std::ostream & os) const;
128     };
129
130     struct NDPMTUTLVParser : public NDPOptionParser
131     {
132 #       include SENF_PARSER()
133         SENF_PARSER_INHERIT          ( NDPOptionParser );
134         SENF_PARSER_PRIVATE_BITFIELD ( reserved, 16, unsigned );
135         SENF_PARSER_FIELD            ( mtu, UInt32Parser );
136         SENF_PARSER_FINALIZE         ( NDPMTUTLVParser );
137
138         SENF_PARSER_INIT() {
139             defaultInit();
140             type() = typeId;
141             length() = 1;
142             reserved() = 0;
143         }
144         static const UInt8Parser::value_type typeId = 0x05;
145         void dump(std::ostream & os) const;
146     };
147 }
148
149 //-/////////////////////////////////////////////////////////////////////////////////////////////////
150 //#include "NDPOptions.cci"
151 //#include "NDPOptions.ct"
152 //#include "NDPOptions.cti"
153 #endif
154
155 \f
156 // Local Variables:
157 // mode: c++
158 // fill-column: 100
159 // c-file-style: "senf"
160 // indent-tabs-mode: nil
161 // ispell-local-dictionary: "american"
162 // compile-command: "scons -u test"
163 // comment-column: 40
164 // End:
165