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