updated unittest
[senf.git] / senf / Packets / DefaultBundle / IPv6ExtOptionType.ct
1 // $Id: IPv6ExtOptionType.ct 869 2008-06-09 13:57:27Z pug $
2 //
3 // Copyright (C) 2009
4 // Fraunhofer Institute for Open Communication Systems (FOKUS)
5 // Competence Center NETwork research (NET), St. Augustin, GERMANY
6 //     Philipp.Batroff@fokus.fraunhofer.de
7 //
8 // This program is free software; you can redistribute it and/or modify
9 // it under the terms of the GNU General Public License as published by
10 // the Free Software Foundation; either version 2 of the License, or
11 // (at your option) any later version.
12 //
13 // This program is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 // GNU General Public License for more details.
17 //
18 // You should have received a copy of the GNU General Public License
19 // along with this program; if not, write to the
20 // Free Software Foundation, Inc.,
21 // 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
22
23 /** \file
24     \brief IPv6Extension-Options non-inline template implementation  */
25
26 //#include "IPv6ExtOptionType.ih"
27
28 // Custom includes
29
30 #define prefix_
31 ///////////////////////////////ct.p////////////////////////////////////////
32
33 template <class ForwardReadableRange>
34 prefix_ void senf::IPv6GenericOptionTLVParser::value(ForwardReadableRange const &range)
35 {
36     unsigned int rangeSize = boost::size(range);
37     
38     if ( (rangeSize-2) != optionLength() )
39         resize(optionLength()+2, rangeSize);
40     std::copy(boost::next(boost::begin(range), 2), boost::next(boost::end(range)), boost::next(i(), 2 + optionLength() ));
41     unsigned int val = *(boost::begin(range));
42     unsigned int mask = 192u;
43     altAction() = (val & mask) >> 6;
44     mask = 32u;
45     changeFlag() = (val & mask) >> 5;
46     mask = 31u;
47     optionType() = (val & mask);
48     optionLength() = *(boost::next( boost::begin(range), 1));
49 }
50
51 template <class ForwardReadableRange>
52 prefix_ void senf::IPv6GenericOptionTLVParser::setPayload(ForwardReadableRange const &range)
53 {
54     unsigned int rangeSize = boost::size(range);
55     if ( rangeSize != optionLength() )
56         resize( (optionLength() + 2), (rangeSize + 2) );
57     std::copy( boost::begin(range), boost::end(range), boost::next( i(), 2));
58     optionLength() = rangeSize;
59 }
60
61
62 template <class Parser>
63 prefix_ Parser& senf::IPv6GenericOptionTLVParser::init()
64 {
65     size_type oldSize ( bytes() );
66     resize( oldSize, senf::init_bytes<Parser>::value);
67     data_iterator j = i();
68     std::advance(j, senf::init_bytes<Parser>::value);
69     std::fill(i() , j, 0u);
70     Parser::init();
71     Parser::optionType() = Parser::typeCode;
72     return *(this);
73 }
74
75 // template <class Parser>
76 // prefix_ Parser& senf::GenericOptTypeTLVParser::get()
77 // {
78 //     SENF_ASSERT (optionType() == typeCode);
79 //     return *(this);
80 // }
81
82
83 ///////////////////////////////ct.e////////////////////////////////////////
84 #undef prefix_
85
86
87 // Local Variables:
88 // mode: c++
89 // fill-column: 100
90 // c-file-style: "senf"
91 // indent-tabs-mode: nil
92 // ispell-local-dictionary: "american"
93 // compile-command: "scons -u test"
94 // comment-column: 40
95 // End: