From: tho Date: Fri, 16 Oct 2009 10:23:39 +0000 (+0000) Subject: Packets/80211Bundle: integrated GenericTLVRegistry X-Git-Url: http://g0dil.de/git?a=commitdiff_plain;h=9ffdaae4804503c4f36a53747c852a87ee626b9e;p=senf.git Packets/80211Bundle: integrated GenericTLVRegistry git-svn-id: https://svn.berlios.de/svnroot/repos/senf/trunk@1499 270642c3-0616-0410-b53a-bc976706d245 --- diff --git a/senf/Packets/80211Bundle/InformationElements.cc b/senf/Packets/80211Bundle/InformationElements.cc new file mode 100644 index 0000000..e4530df --- /dev/null +++ b/senf/Packets/80211Bundle/InformationElements.cc @@ -0,0 +1,79 @@ +// $Id$ +// +// Copyright (C) 2009 +// Fraunhofer Institute for Open Communication Systems (FOKUS) +// Competence Center NETwork research (NET), St. Augustin, GERMANY +// Thorsten Horstmann +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the +// Free Software Foundation, Inc., +// 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + +/** \file + \brief InformationElements non-inline non-template implementation */ + +#include "InformationElements.hh" +//#include "InformationElements.ih" + +// Custom includes + +//#include "InformationElements.cc.mpp" +#define prefix_ +///////////////////////////////cc.p//////////////////////////////////////// + +SENF_PACKET_TLV_REGISTRY_REGISTER( senf::WLANInfoElementParser, senf::WLANSSIDInfoElementParser); +SENF_PACKET_TLV_REGISTRY_REGISTER( senf::WLANInfoElementParser, senf::WLANPowerConstraintInfoElementParser); +SENF_PACKET_TLV_REGISTRY_REGISTER( senf::WLANInfoElementParser, senf::WLANSupportedRatesInfoElementParser); + + +prefix_ void senf::WLANPowerConstraintInfoElementParser::dump(std::ostream & os) + const +{ + os << " WLAN PowerConstraint Information Element\n" + << " type: " << unsigned(type()) << "\n" + << " length: " << unsigned(length()) << "\n" + << " value: " << unsigned(value()) << "\n"; +} + +prefix_ void senf::WLANSSIDInfoElementParser::dump(std::ostream & os) + const +{ + os << " WLAN SSID Information Element\n" + << " type: " << unsigned(type()) << "\n" + << " length: " << unsigned(length()) << "\n" + << " value: " << value() << "\n"; +} + +prefix_ void senf::WLANSupportedRatesInfoElementParser::dump(std::ostream & os) + const +{ + os << " WLAN SupportedRates Information Element\n" + << " type: " << unsigned(type()) << "\n" + << " length: " << unsigned(length()) << "\n" + << " value: ToDo!\n"; +} + +///////////////////////////////cc.e//////////////////////////////////////// +#undef prefix_ + + +// Local Variables: +// mode: c++ +// fill-column: 100 +// comment-column: 40 +// c-file-style: "senf" +// indent-tabs-mode: nil +// ispell-local-dictionary: "american" +// compile-command: "scons -u test" +// End: diff --git a/senf/Packets/80211Bundle/InformationElements.hh b/senf/Packets/80211Bundle/InformationElements.hh index 69fa2a9..af497b2 100644 --- a/senf/Packets/80211Bundle/InformationElements.hh +++ b/senf/Packets/80211Bundle/InformationElements.hh @@ -59,6 +59,8 @@ namespace senf { type() = typeId; } static const type_t::value_type typeId = 0x00u; + + void dump(std::ostream & os) const; }; struct WLANSupportedRatesInfoElementParser @@ -75,6 +77,8 @@ namespace senf { type() = typeId; } static const type_t::value_type typeId = 0x01u; + + void dump(std::ostream & os) const; }; struct WLANPowerConstraintInfoElementParser @@ -90,6 +94,8 @@ namespace senf { length() = 1; } static const type_t::value_type typeId = 0x20u; + + void dump(std::ostream & os) const; }; } diff --git a/senf/Packets/80211Bundle/WLANBeaconPacket.cc b/senf/Packets/80211Bundle/WLANBeaconPacket.cc index 327a838..ad49dbc 100644 --- a/senf/Packets/80211Bundle/WLANBeaconPacket.cc +++ b/senf/Packets/80211Bundle/WLANBeaconPacket.cc @@ -35,8 +35,16 @@ prefix_ void senf::WLANBeaconPacketType::dump(packet p, std::ostream &os) { boost::io::ios_all_saver ias(os); - os << "WLAN Beacon:\n" - << senf::fieldName("timestamp") << unsigned( p->timestamp()) << "\n"; + os << "WLAN beacon frame:\n" + << senf::fieldName("timestamp") << unsigned( p->timestamp()) << "\n" + << senf::fieldName("beaconInterval") << unsigned( p->beaconInterval()) << "\n"; + p->ssidIE().dump( os); + p->supportedRatesIE().dump( os); + os << " Optional Information Elements:\n"; + typedef parser::ieList_t::container ieListContainer_t; + ieListContainer_t ieListContainer (p->ieList()); + for (ieListContainer_t::iterator i = ieListContainer.begin(); i != ieListContainer.end(); ++i) + (*i).dump( os); } ///////////////////////////////cc.e//////////////////////////////////////// diff --git a/senf/Packets/80211Bundle/WLANBeaconPacket.hh b/senf/Packets/80211Bundle/WLANBeaconPacket.hh index a8accfa..d82ed1a 100644 --- a/senf/Packets/80211Bundle/WLANBeaconPacket.hh +++ b/senf/Packets/80211Bundle/WLANBeaconPacket.hh @@ -76,6 +76,9 @@ namespace senf { static void dump(packet p, std::ostream &os); }; + /** \brief WLAN Beacon frame packet typedef + \ingroup protocolbundle_80211 + */ typedef ConcretePacket WLANBeaconPacket; } diff --git a/senf/Packets/80211Bundle/WLANBeaconPacket.test.cc b/senf/Packets/80211Bundle/WLANBeaconPacket.test.cc index 13dce87..7e7e727 100644 --- a/senf/Packets/80211Bundle/WLANBeaconPacket.test.cc +++ b/senf/Packets/80211Bundle/WLANBeaconPacket.test.cc @@ -78,7 +78,8 @@ BOOST_AUTO_UNIT_TEST(WLANBeaconPacket_parse) ++i; BOOST_CHECK_EQUAL( i->type(), 0xdd); //vendor specific BOOST_CHECK_EQUAL( i->length(), 0x18); - BOOST_CHECK_EQUAL( boost::size(i->value()), 0x18); + BOOST_CHECK_EQUAL( boost::size(i->value()), 0x18); + unsigned char value[] = { 0x00, 0x50, 0xf2, 0x02, 0x01, 0x01, 0x88, 0x00, 0x02, 0xa3, 0x00, 0x00, 0x27, 0xa4, 0x00, 0x00, @@ -86,6 +87,8 @@ BOOST_AUTO_UNIT_TEST(WLANBeaconPacket_parse) }; SENF_CHECK_EQUAL_COLLECTIONS( value, value+sizeof(value), boost::begin(i->value()), boost::end(i->value()) ); + + p.dump(std::cout); } BOOST_AUTO_UNIT_TEST(WLANBeaconPacket_create) diff --git a/senf/Packets/80211Bundle/WLANPacket.hh b/senf/Packets/80211Bundle/WLANPacket.hh index 69c25a7..c323afc 100644 --- a/senf/Packets/80211Bundle/WLANPacket.hh +++ b/senf/Packets/80211Bundle/WLANPacket.hh @@ -121,6 +121,9 @@ namespace senf static void dump(packet p, std::ostream &os); }; + /** \brief WLAN Management frame packet typedef + \ingroup protocolbundle_80211 + */ typedef WLANPacket_MgtFrameType::packet WLANPacket_MgtFrame; /////////////////////////////////////////////////////////////////////////// @@ -176,6 +179,9 @@ namespace senf static void dump(packet p, std::ostream &os); }; + /** \brief WLAN Control frame packet typedef + \ingroup protocolbundle_80211 + */ typedef WLANPacket_CtrlFrameType::packet WLANPacket_CtrlFrame; /////////////////////////////////////////////////////////////////////////// @@ -266,6 +272,9 @@ namespace senf static void dump(packet p, std::ostream &os); }; + /** \brief WLAN Data frame packet typedef + \ingroup protocolbundle_80211 + */ typedef WLANPacket_DataFrameType::packet WLANPacket_DataFrame; } diff --git a/senf/Packets/GenericTLV.ct b/senf/Packets/GenericTLV.ct index 9c36431..44b748d 100644 --- a/senf/Packets/GenericTLV.ct +++ b/senf/Packets/GenericTLV.ct @@ -60,18 +60,6 @@ prefix_ senf::PacketInterpreterBase::range senf::GenericTLVParserBase::va } template -prefix_ void senf::GenericTLVParserBase::dump(std::ostream & os) - const -{ - boost::io::ios_all_saver ias(os); - os << "GenericTLVParser<" << prettyName(typeid(Base)) << ">\n" - << " type: " << senf::format::dumpint(this->type()) << "\n" - << " length: " << senf::format::dumpint(this->length()) << "\n" - << " value:\n"; - hexdump(value().begin(), value().end(), os); -} - -template template prefix_ void senf::GenericTLVParserBase::value_(ForwardReadableRange const &range) { @@ -92,22 +80,27 @@ template template prefix_ void senf::GenericTLVParserRegistry::registerParser() { - typename Map::iterator i (map_.find( Parser::typeId )); - if (i == map_.end() ) { - typename BaseParser::type_t::value_type k (Parser::typeId); - map_.insert(k , new detail::GenericTLVParserRegistry_Entry() ); - } + typename BaseParser::type_t::value_type key (Parser::typeId+0); + typename Map::iterator i (map_.find( key )); + if (i == map_.end() ) + map_.insert(key, new detail::GenericTLVParserRegistry_Entry() ); } template prefix_ void senf::GenericTLVParserRegistry::dump( - std::ostream & os, GenericTLVParserBase const & parser) + GenericTLVParserBase const & parser, std::ostream & os) { typename Map::iterator i (map_.find( parser.type())); - if (i == map_.end()) - parser.dump(os); + if (i == map_.end()) { + boost::io::ios_all_saver ias(os); + os << " GenericTLVParser<" << prettyName(typeid(BaseParser)) << ">\n" + << " type: " << senf::format::dumpint(parser.type()) << "\n" + << " length: " << senf::format::dumpint(parser.length()) << "\n" + << " value:\n"; + hexdump(parser.value().begin(), parser.value().end(), os); + } else - (i->second)->dump(os, parser); + (i->second)->dump(parser, os); } ///////////////////////////////ct.e//////////////////////////////////////// diff --git a/senf/Packets/GenericTLV.cti b/senf/Packets/GenericTLV.cti index 82adea3..5500516 100644 --- a/senf/Packets/GenericTLV.cti +++ b/senf/Packets/GenericTLV.cti @@ -75,6 +75,13 @@ prefix_ Base const & senf::GenericTLVParserBase::self() return *static_cast(this); } +template +prefix_ void senf::GenericTLVParserBase::dump(std::ostream & os) + const +{ + GenericTLVParserRegistry::instance().dump(*this, os); +} + #ifndef DOXYGEN template @@ -113,11 +120,22 @@ prefix_ void senf::GenericTLVParserBase::value( template prefix_ void senf::detail::GenericTLVParserRegistry_Entry::dump( - std::ostream & os, GenericTLVParserBase const & parser) + GenericTLVParserBase const & parser, std::ostream & os) { (parser.template as()).dump(os); } + +/////////////////////////////////////////////////////////////////////////// +// senf::GenericTLVParserRegistry::RegistrationProxy + +template +template +prefix_ senf::GenericTLVParserRegistry::RegistrationProxy::RegistrationProxy() +{ + GenericTLVParserRegistry::instance().registerParser(); +}; + ///////////////////////////////cti.e/////////////////////////////////////// #undef prefix_ diff --git a/senf/Packets/GenericTLV.hh b/senf/Packets/GenericTLV.hh index e8e1bb5..b0dab34 100644 --- a/senf/Packets/GenericTLV.hh +++ b/senf/Packets/GenericTLV.hh @@ -183,14 +183,14 @@ namespace senf { namespace detail { template struct GenericTLVParserRegistry_EntryBase { - virtual void dump(std::ostream & os, GenericTLVParserBase const & parser) = 0; + virtual void dump(GenericTLVParserBase const & parser, std::ostream & os) = 0; }; template struct GenericTLVParserRegistry_Entry : GenericTLVParserRegistry_EntryBase { - virtual void dump(std::ostream & os, GenericTLVParserBase const & parser); + virtual void dump(GenericTLVParserBase const & parser, std::ostream & os); }; } @@ -208,14 +208,26 @@ namespace senf { using senf::singleton >::instance; friend class senf::singleton >; + template + struct RegistrationProxy { + RegistrationProxy(); + }; + template void registerParser(); - void dump(std::ostream & os, GenericTLVParserBase const & parser); + void dump(GenericTLVParserBase const & parser, std::ostream & os); }; + +# define SENF_PACKET_TLV_REGISTRY_REGISTER( BaseTLVParser, ConreteTLVParser ) \ + namespace { \ + senf::GenericTLVParserRegistry \ + ::RegistrationProxy \ + BOOST_PP_CAT(tlvparserRegistration_, __LINE__); \ + } + } - ///////////////////////////////hh.e//////////////////////////////////////// //#include "GenericTLV.cci" #include "GenericTLV.ct" diff --git a/senf/Packets/GenericTLV.test.cc b/senf/Packets/GenericTLV.test.cc index d35523c..5a1d3d6 100644 --- a/senf/Packets/GenericTLV.test.cc +++ b/senf/Packets/GenericTLV.test.cc @@ -1,9 +1,9 @@ // $Id$ // -// Copyright (C) 2008 +// Copyright (C) 2009 // Fraunhofer Institute for Open Communication Systems (FOKUS) // Competence Center NETwork research (NET), St. Augustin, GERMANY -// @AUTHOR@ +// Thorsten Horstmann // // This program is free software; you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by @@ -25,7 +25,6 @@ // Custom includes #include "GenericTLV.hh" -#include #include #include @@ -62,17 +61,16 @@ namespace { type() = typeId; length_() = 4; } - static type_t::value_type const typeId; + static type_t::value_type const typeId = 0x42; void dump(std::ostream & os) const { boost::io::ios_all_saver ias(os); - os << "MyConcreteTLVParser\n" - << " type: " << senf::format::dumpint(type()) << "\n" - << " length: " << senf::format::dumpint(length()) << "\n" - << " value: " << senf::format::dumpint(myValue()) << "\n"; + os << " MyConcreteTLVParser\n" + << " type: " << senf::format::dumpint(type()) << "\n" + << " length: " << senf::format::dumpint(length()) << "\n" + << " value: " << senf::format::dumpint(myValue()) << "\n"; } }; - MyConcreteTLVParser::type_t::value_type const MyConcreteTLVParser::typeId = 0x42; class MyTestPacketParser : public senf::PacketParserBase @@ -159,17 +157,17 @@ BOOST_AUTO_UNIT_TEST(GenericTLV_registry) conreteTLVParser.myValue() << 0xffff; p.finalizeThis(); - typedef senf::GenericTLVParserRegistry MyTLVParserRegistry; - std::stringstream ss; - MyTLVParserRegistry::instance().dump(ss, *tlvContainer.begin()); - BOOST_CHECK_EQUAL( ss.str().substr(0,56), "GenericTLVParser<(anonymous namespace)::MyTLVParserBase>" ); + (*tlvContainer.begin()).dump( ss); + BOOST_CHECK_EQUAL( ss.str().substr(0,58), + " GenericTLVParser<(anonymous namespace)::MyTLVParserBase>" ); - MyTLVParserRegistry::instance().registerParser(); + senf::GenericTLVParserRegistry::instance() + .registerParser(); ss.str(""); ss.clear(); - MyTLVParserRegistry::instance().dump(ss, *tlvContainer.begin()); - BOOST_CHECK_EQUAL( ss.str().substr(0,19), "MyConcreteTLVParser" ); + (*tlvContainer.begin()).dump( ss); + BOOST_CHECK_EQUAL( ss.str().substr(0,21), " MyConcreteTLVParser" ); }