Packets/80211Bundle: integrated GenericTLVRegistry
tho [Fri, 16 Oct 2009 10:23:39 +0000 (10:23 +0000)]
git-svn-id: https://svn.berlios.de/svnroot/repos/senf/trunk@1499 270642c3-0616-0410-b53a-bc976706d245

senf/Packets/80211Bundle/InformationElements.cc [new file with mode: 0644]
senf/Packets/80211Bundle/InformationElements.hh
senf/Packets/80211Bundle/WLANBeaconPacket.cc
senf/Packets/80211Bundle/WLANBeaconPacket.hh
senf/Packets/80211Bundle/WLANBeaconPacket.test.cc
senf/Packets/80211Bundle/WLANPacket.hh
senf/Packets/GenericTLV.ct
senf/Packets/GenericTLV.cti
senf/Packets/GenericTLV.hh
senf/Packets/GenericTLV.test.cc

diff --git a/senf/Packets/80211Bundle/InformationElements.cc b/senf/Packets/80211Bundle/InformationElements.cc
new file mode 100644 (file)
index 0000000..e4530df
--- /dev/null
@@ -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 <tho@berlios.de>
+//
+// 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_
+
+\f
+// 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:
index 69fa2a9..af497b2 100644 (file)
@@ -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;
     };
 }
 
index 327a838..ad49dbc 100644 (file)
 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////////////////////////////////////////
index a8accfa..d82ed1a 100644 (file)
@@ -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<WLANBeaconPacketType> WLANBeaconPacket;
 
 }
index 13dce87..7e7e727 100644 (file)
@@ -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)
index 69c25a7..c323afc 100644 (file)
@@ -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;
 }
 
index 9c36431..44b748d 100644 (file)
@@ -60,18 +60,6 @@ prefix_  senf::PacketInterpreterBase::range senf::GenericTLVParserBase<Base>::va
 }
 
 template <class Base>
-prefix_  void senf::GenericTLVParserBase<Base>::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 <class Base>
 template <class ForwardReadableRange>
 prefix_ void senf::GenericTLVParserBase<Base>::value_(ForwardReadableRange const &range)
 {
@@ -92,22 +80,27 @@ template <class BaseParser>
 template <typename Parser>
 prefix_ void senf::GenericTLVParserRegistry<BaseParser>::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<BaseParser, Parser>() );
-    }
+    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<BaseParser, Parser>() );
 }
 
 template <class BaseParser>
 prefix_ void senf::GenericTLVParserRegistry<BaseParser>::dump(
-        std::ostream & os, GenericTLVParserBase<BaseParser> const & parser)
+        GenericTLVParserBase<BaseParser> 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////////////////////////////////////////
index 82adea3..5500516 100644 (file)
@@ -75,6 +75,13 @@ prefix_ Base const & senf::GenericTLVParserBase<Base>::self()
     return *static_cast<Base const *>(this);
 }
 
+template <class Base>
+prefix_  void senf::GenericTLVParserBase<Base>::dump(std::ostream & os)
+    const 
+{
+    GenericTLVParserRegistry<Base>::instance().dump(*this, os);
+}
+
 #ifndef DOXYGEN
 
 template <class Base>
@@ -113,11 +120,22 @@ prefix_ void senf::GenericTLVParserBase<Base>::value(
 
 template <class BaseParser, class Parser>
 prefix_ void senf::detail::GenericTLVParserRegistry_Entry<BaseParser, Parser>::dump(
-        std::ostream & os, GenericTLVParserBase<BaseParser> const & parser)
+        GenericTLVParserBase<BaseParser> const & parser, std::ostream & os)
 {
     (parser.template as<Parser>()).dump(os);
 }
 
+
+///////////////////////////////////////////////////////////////////////////
+// senf::GenericTLVParserRegistry<BaseParser>::RegistrationProxy<PacketParser>
+
+template <class BaseParser>
+template <class PacketParser>
+prefix_ senf::GenericTLVParserRegistry<BaseParser>::RegistrationProxy<PacketParser>::RegistrationProxy()
+{
+    GenericTLVParserRegistry<BaseParser>::instance().registerParser<PacketParser>();
+};
+
 ///////////////////////////////cti.e///////////////////////////////////////
 #undef prefix_
 
index e8e1bb5..b0dab34 100644 (file)
@@ -183,14 +183,14 @@ namespace senf {
     namespace detail {
         template <class BaseParser>
         struct GenericTLVParserRegistry_EntryBase {
-            virtual void dump(std::ostream & os, GenericTLVParserBase<BaseParser> const & parser) = 0;
+            virtual void dump(GenericTLVParserBase<BaseParser> const & parser, std::ostream & os) = 0;
         };
     
         template <class BaseParser, class Parser>
         struct GenericTLVParserRegistry_Entry
             : GenericTLVParserRegistry_EntryBase<BaseParser>
         {
-            virtual void dump(std::ostream & os, GenericTLVParserBase<BaseParser> const & parser);
+            virtual void dump(GenericTLVParserBase<BaseParser> const & parser, std::ostream & os);
         };
     }
     
@@ -208,14 +208,26 @@ namespace senf {
         using senf::singleton<GenericTLVParserRegistry<BaseParser> >::instance;
         friend class senf::singleton<GenericTLVParserRegistry<BaseParser> >;
         
+        template <class PacketParser>
+        struct RegistrationProxy {
+            RegistrationProxy();
+        };
+
         template <typename Parser>
         void registerParser();
         
-        void dump(std::ostream & os, GenericTLVParserBase<BaseParser> const & parser);
+        void dump(GenericTLVParserBase<BaseParser> const & parser, std::ostream & os);
     };
+        
+#   define SENF_PACKET_TLV_REGISTRY_REGISTER( BaseTLVParser, ConreteTLVParser )     \
+        namespace {                                                                 \
+            senf::GenericTLVParserRegistry<BaseTLVParser>                           \
+                ::RegistrationProxy<ConreteTLVParser>                               \
+                    BOOST_PP_CAT(tlvparserRegistration_, __LINE__);                 \
+        }
+        
 }
 
-
 ///////////////////////////////hh.e////////////////////////////////////////
 //#include "GenericTLV.cci"
 #include "GenericTLV.ct"
index d35523c..5a1d3d6 100644 (file)
@@ -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 <tho@berlios.de>
 //
 // 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 <senf/Utils/hexdump.hh>
 
 #include <senf/Utils/auto_unit_test.hh>
 #include <boost/test/test_tools.hpp>
@@ -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<MyTLVParserBase> 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<MyConcreteTLVParser>();
+    senf::GenericTLVParserRegistry<MyTLVParserBase>::instance()
+            .registerParser<MyConcreteTLVParser>();
     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" );
 }