e7fba5c663dd369e0e93fa012283d34d291a671b
[senf.git] / senf / Packets / 80221Bundle / MIHPacket.cc
1 // $Id$
2 //
3 // Copyright (C) 2009
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 MIH protocol non-inline non-template implementation */
25
26 #include "MIHPacket.hh"
27 //#include "MIHPacket.ih"
28
29 // Custom includes
30 #include <boost/io/ios_state.hpp>
31 #include <senf/Packets/DefaultBundle/EthernetPacket.hh>
32
33 #define prefix_
34 ///////////////////////////////cc.p////////////////////////////////////////
35
36 SENF_PACKET_REGISTRY_REGISTER( senf::EtherTypes, 0x8917, senf::MIHPacket);
37
38
39 ///////////////////////////////////////////////////////////////////////////
40 // MIHPacketType
41
42 prefix_ void senf::MIHPacketType::dump(packet p, std::ostream &os)
43 {
44     boost::io::ios_all_saver ias(os);
45     os << "MIH Packet:\n"
46        << "  protocol header:\n"
47        << senf::fieldName("  version")           << unsigned( p->version()) << "\n"
48        << senf::fieldName("  ack request")       << p->ackRequest() << "\n"
49        << senf::fieldName("  ack response")      << p->ackResponse() << "\n"
50        << senf::fieldName("  UIR")               << p->uir() << "\n"
51        << senf::fieldName("  more fragments")    << p->moreFragment() << "\n"
52        << senf::fieldName("  fragment number")   << p->fragmentNr() << "\n"
53        << senf::fieldName("  message ID (MID)")  << unsigned( p->messageId()) << "\n"
54        << senf::fieldName("    sid")             << unsigned( p->sid()) << "\n"        
55        << senf::fieldName("    opcode")          << unsigned( p->opcode()) << "\n"
56        << senf::fieldName("    aid")             << unsigned( p->aid()) << "\n"      
57        << senf::fieldName("  transaction id")    << unsigned( p->transactionId()) << "\n"
58        << senf::fieldName("  payload length")    << unsigned( p->payloadLength()) << "\n";
59     p->src_mihfId().dump( os);
60     p->dst_mihfId().dump( os);
61 }
62
63 prefix_ void senf::MIHPacketType::finalize(packet p)
64 {
65     p->src_mihfId().finalize();
66     p->dst_mihfId().finalize();
67     p->payloadLength_() << p.size() - 8;
68     p->messageId() << key(p.next(nothrow));
69 }
70
71 prefix_ senf::PacketInterpreterBase::factory_t senf::MIHPacketType::nextPacketType(packet p)
72 {
73     if (p.data().size() < initSize())
74         return no_factory();
75     PkReg_Entry const * e (PacketRegistry<MIHMessageRegistry>::lookup( p->messageId(), nothrow ));
76     return e ? e->factory() : MIHGenericPayloadPacket::factory();
77 }
78
79 ///////////////////////////////////////////////////////////////////////////
80 // MIHGenericPayloadPacketType
81
82 prefix_ void senf::MIHGenericPayloadPacketType::dump(packet p, std::ostream &os)
83 {
84     boost::io::ios_all_saver ias(os);
85     os << "MIH Payload (service specific TLVs):\n";
86     typedef parser::tlvList_t::container tlvListContainer_t;
87     tlvListContainer_t tlvListContainer (p->tlvList());
88     for (tlvListContainer_t::const_iterator i = tlvListContainer.begin(); i != tlvListContainer.end(); ++i)
89         i->dump( os);
90 }
91
92 prefix_ void senf::MIHGenericPayloadPacketType::finalize(packet p)
93 {
94     typedef parser::tlvList_t::container tlvContainer_t;
95     tlvContainer_t tlvs (p->tlvList() );
96     for (tlvContainer_t::iterator i (tlvs.begin()); i != tlvs.end(); ++i)
97         i->finalize();
98 }
99
100
101 ///////////////////////////////cc.e////////////////////////////////////////
102 #undef prefix_
103
104 \f
105 // Local Variables:
106 // mode: c++
107 // fill-column: 100
108 // c-file-style: "senf"
109 // indent-tabs-mode: nil
110 // ispell-local-dictionary: "american"
111 // compile-command: "scons -u test"
112 // comment-column: 40
113 // End: