Search:

SENF Extensible Network Framework

  • Home
  • Download
  • Wiki
  • BerliOS
  • ChangeLog
  • Browse SVN
  • Bug Tracker
  • Overview
  • Examples
  • HowTos
  • Glossary
  • PPI
  • Packets
  • Scheduler
  • Socket
  • Utils
  • Console
  • Daemon
  • Logger
  • Termlib
  • Main Page
  • Related Pages
  • Modules
  • Namespaces
  • Classes
  • Files
  • File List
  • File Members

80221Bundle/MIHPacket.cc

Go to the documentation of this file.
00001 // $Id: MIHPacket.cc 1787 2011-05-12 11:02:50Z tho $
00002 //
00003 // Copyright (C) 2009
00004 // Fraunhofer (FOKUS)
00005 // Competence Center NETwork research (NET), St. Augustin, GERMANY
00006 //     Thorsten Horstmann <tho@berlios.de>
00007 //
00008 // This program is free software; you can redistribute it and/or modify
00009 // it under the terms of the GNU General Public License as published by
00010 // the Free Software Foundation; either version 2 of the License, or
00011 // (at your option) any later version.
00012 //
00013 // This program is distributed in the hope that it will be useful,
00014 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00015 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00016 // GNU General Public License for more details.
00017 //
00018 // You should have received a copy of the GNU General Public License
00019 // along with this program; if not, write to the
00020 // Free Software Foundation, Inc.,
00021 // 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00022 
00026 #include "MIHPacket.hh"
00027 //#include "MIHPacket.ih"
00028 
00029 // Custom includes
00030 #include <boost/io/ios_state.hpp>
00031 #include <senf/Utils/String.hh>
00032 #include <senf/Packets/DefaultBundle/EthernetPacket.hh>
00033 
00034 #define prefix_
00035 //-/////////////////////////////////////////////////////////////////////////////////////////////////
00036 
00037 SENF_PACKET_REGISTRY_REGISTER( senf::EtherTypes, senf::MIHPacketType::etherType, senf::MIHPacket);
00038 
00039 
00040 //-/////////////////////////////////////////////////////////////////////////////////////////////////
00041 // MIHPacketType
00042 
00043 prefix_ void senf::MIHPacketType::dump(packet p, std::ostream & os)
00044 {
00045     boost::io::ios_all_saver ias(os);
00046     os << "MIH Packet:\n"
00047        << "  protocol header:\n"
00048        << senf::fieldName("  version")           << unsigned( p->version()) << "\n"
00049        << senf::fieldName("  ack request")       << p->ackRequest() << "\n"
00050        << senf::fieldName("  ack response")      << p->ackResponse() << "\n"
00051        << senf::fieldName("  UIR")               << p->uir() << "\n"
00052        << senf::fieldName("  more fragments")    << p->moreFragment() << "\n"
00053        << senf::fieldName("  fragment number")   << p->fragmentNr() << "\n"
00054        << senf::fieldName("  message ID (MID)")  << unsigned( p->messageId()) << "\n"
00055        << senf::fieldName("    sid")             << unsigned( p->sid()) << "\n"
00056        << senf::fieldName("    opcode")          << unsigned( p->opcode()) << "\n"
00057        << senf::fieldName("    aid")             << unsigned( p->aid()) << "\n"
00058        << senf::fieldName("  transaction id")    << unsigned( p->transactionId()) << "\n"
00059        << senf::fieldName("  payload length")    << unsigned( p->payloadLength()) << "\n";
00060     p->src_mihfId().dump( os);
00061     p->dst_mihfId().dump( os);
00062 }
00063 
00064 prefix_ void senf::MIHPacketType::finalize(packet p)
00065 {
00066     p->src_mihfId().finalize();
00067     p->dst_mihfId().finalize();
00068     p->payloadLength_() << p.size() - 8;
00069     p->messageId() << key(p.next(nothrow));
00070 }
00071 
00072 prefix_ senf::PacketInterpreterBase::factory_t senf::MIHPacketType::nextPacketType(packet p)
00073 {
00074     if (p.data().size() < initSize())
00075         return no_factory();
00076     PacketRegistry<MIHMessageRegistry>::Entry const * e (
00077         PacketRegistry<MIHMessageRegistry>::lookup( p->messageId(), nothrow ));
00078     return e ? e->factory() : MIHGenericPayloadPacket::factory();
00079 }
00080 
00081 prefix_ void senf::MIHPacketType::validate(packet p)
00082 {
00083     try {
00084         if (p.data().size() < initSize())
00085             throw InvalidMIHPacketException("truncated MIH message");
00086         if (p->version() != 1)
00087             throw InvalidMIHPacketException("invalid MIH version: ") << senf::str(p->version());
00088         if (p->payloadLength() != p.size()-8)
00089             throw InvalidMIHPacketException("wrong MIH length: ") << senf::str(p->payloadLength());
00090         if (p.next(senf::nothrow))
00091             MIHMessageRegistry::instance().validate( p->messageId(), p.next());
00092     } catch (TruncatedPacketException & e) {
00093         throw InvalidMIHPacketException("truncated MIH message");
00094     }
00095 }
00096 
00097 //-/////////////////////////////////////////////////////////////////////////////////////////////////
00098 // MIHGenericPayloadPacketType
00099 
00100 prefix_ void senf::MIHGenericPayloadPacketType::dump(packet p, std::ostream & os)
00101 {
00102     boost::io::ios_all_saver ias(os);
00103     os << "MIH Payload (service specific TLVs):\n";
00104     typedef parser::tlvList_t::container tlvListContainer_t;
00105     tlvListContainer_t tlvListContainer (p->tlvList());
00106     for (tlvListContainer_t::const_iterator i = tlvListContainer.begin(); i != tlvListContainer.end(); ++i)
00107         i->dump( os);
00108 }
00109 
00110 prefix_ void senf::MIHGenericPayloadPacketType::finalize(packet p)
00111 {
00112     typedef parser::tlvList_t::container tlvContainer_t;
00113     tlvContainer_t tlvs (p->tlvList() );
00114     for (tlvContainer_t::iterator i (tlvs.begin()); i != tlvs.end(); ++i) {
00115         MIHGenericTLVParser p (*i);
00116         p.finalize();
00117     }
00118 }
00119 
00120 
00121 //-/////////////////////////////////////////////////////////////////////////////////////////////////
00122 #undef prefix_
00123 
00124 
00125 // Local Variables:
00126 // mode: c++
00127 // fill-column: 100
00128 // c-file-style: "senf"
00129 // indent-tabs-mode: nil
00130 // ispell-local-dictionary: "american"
00131 // compile-command: "scons -u test"
00132 // comment-column: 40
00133 // End:

Contact: senf-dev@lists.berlios.de | © 2006-2010 Fraunhofer Institute for Open Communication Systems, Network Research