df35a31b42f1c8251420eba15bc483cf690d27c3
[senf.git] / senf / Packets / MPEGDVBBundle / SNDUPacket.cc
1 // $Id$
2 //
3 // Copyright (C) 2007
4 // Fraunhofer Institute for Open Communication Systems (FOKUS)
5 // Competence Center NETwork research (NET), St. Augustin, GERMANY
6 //     Thorsten Horstmann <tho@berlios.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 DSMCCSection non-inline non-template implementation */
25
26 #include "SNDUPacket.hh"
27 //#include "SNDUPacket.ih"
28
29 // Custom includes
30 #include <iomanip>
31 #include <senf/Packets/DefaultBundle/EthernetPacket.hh>
32
33
34 #define prefix_
35 //-/////////////////////////////////////////////////////////////////////////////////////////////////
36
37 prefix_ boost::uint32_t senf::SNDUPacketParser::calcCrc()
38     const
39 {
40     return std::for_each(
41             data().begin(),
42             boost::prior(data().end(), 4),
43             ule_crc32() ).checksum();
44 }
45
46 //prefix_ senf::SNDUPacketType::key_t senf::SNDUPacketType::nextPacketKey(packet p)
47 //{
48 //    return p->type();
49 //}
50
51 prefix_ void senf::SNDUPacketType::init(packet p)
52 {
53     p->init();
54 }
55
56 prefix_ senf::PacketInterpreterBase::factory_t senf::SNDUPacketType::nextPacketType(packet p)
57 {
58     if (p.data().size() < 8)
59         return no_factory();
60     senf::PacketInterpreterBase::factory_t f (no_factory());
61     if (p->type() < 1536) {
62         PacketRegistry<senf::ULEExtHeaderTypes>::Entry const * e (
63             PacketRegistry<senf::ULEExtHeaderTypes>::lookup( p->type(), nothrow ));
64         if (e) f = e->factory();
65     }
66     else {
67         PacketRegistry<senf::EtherTypes>::Entry const * e (
68             PacketRegistry<senf::ULEExtHeaderTypes>::lookup( p->type(), nothrow ));
69         if (e) f = e->factory();
70     }
71     return f;
72 }
73
74 prefix_ senf::PacketInterpreterBase::optional_range
75 senf::SNDUPacketType::nextPacketRange(packet p)
76 {
77     if (p.data().size() < 8)
78         return no_range();
79
80     size_type sz = 2 + 2;  // D-Bit + 15 bits length + 16 bits type field
81     if (! p->d_bit() )
82         sz += 6;  // + 6 Byte NPA destination address
83     return range(
84             boost::next(p.data().begin(), sz),
85             boost::prior(p.data().end(), 4));  // - 32 bits crc
86 }
87
88 prefix_ void senf::SNDUPacketType::dump(packet p, std::ostream & os)
89 {
90     os << "SNDUPacket:\n"
91        << std::dec
92        << senf::fieldName("d_bit")  << p->d_bit() << "\n"
93        << senf::fieldName("length") << unsigned(p->length()) << "\n"
94        << std::hex
95        << senf::fieldName("type")   << "0x" << unsigned(p->type()) << "\n"
96        << std::dec
97        << senf::fieldName("crc")    << unsigned(p->crc()) << "\n";
98 }
99
100 prefix_ senf::PacketParserBase::size_type senf::SNDUPacketType::initSize()
101 {
102     return 2 + 2 + 4;  // D-Bit + 15 bits length + 16 bits type field + 32 bits crc
103 }
104
105 prefix_ senf::PacketParserBase::size_type senf::SNDUPacketType::initHeadSize()
106 {
107     return 2 + 2;  // D-Bit + 15 bits length + 16 bits type field
108 }
109
110 //-/////////////////////////////////////////////////////////////////////////////////////////////////
111 #undef prefix_
112
113 \f
114 // Local Variables:
115 // mode: c++
116 // fill-column: 100
117 // c-file-style: "senf"
118 // indent-tabs-mode: nil
119 // ispell-local-dictionary: "american"
120 // compile-command: "scons -u test"
121 // comment-column: 40
122 // End: