From: tho Date: Tue, 24 Aug 2010 12:38:14 +0000 (+0000) Subject: Packet: some (802.11) packet optimizations X-Git-Url: http://g0dil.de/git?a=commitdiff_plain;h=ec082e2ded82e26d02f7aa72da519cbadcb601ec;p=senf.git Packet: some (802.11) packet optimizations git-svn-id: https://svn.berlios.de/svnroot/repos/senf/trunk@1697 270642c3-0616-0410-b53a-bc976706d245 --- diff --git a/senf/Packets/80211Bundle/RadiotapPacket.cc b/senf/Packets/80211Bundle/RadiotapPacket.cc index 70a3c27..8632f3d 100644 --- a/senf/Packets/80211Bundle/RadiotapPacket.cc +++ b/senf/Packets/80211Bundle/RadiotapPacket.cc @@ -4,6 +4,7 @@ // Fraunhofer Institute for Open Communication Systems (FOKUS) // Competence Center NETwork research (NET), St. Augustin, GERMANY // Christian Niephaus +// Stefan Bund // // 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 @@ -306,8 +307,9 @@ prefix_ senf::PacketInterpreterBase::factory_t senf::RadiotapPacketType::nextPac prefix_ senf::RadiotapPacketType::optional_range senf::RadiotapPacketType::nextPacketRange(packet p) { - size_type h (senf::bytes(p.parser())); - size_type t (p->flagsPresent() && p->flags().fcsAtEnd() ? 4 : 0); + parser rtParser (p.parser()); + size_type h (senf::bytes(rtParser)); + size_type t (rtParser.flagsPresent() && rtParser.flags().fcsAtEnd() ? 4 : 0); return p.size() <= h+t ? no_range() : optional_range( range(p.data().begin() + h, p.data().end() - t) ); diff --git a/senf/Packets/80211Bundle/RadiotapPacket.hh b/senf/Packets/80211Bundle/RadiotapPacket.hh index bd932ca..e59f02d 100644 --- a/senf/Packets/80211Bundle/RadiotapPacket.hh +++ b/senf/Packets/80211Bundle/RadiotapPacket.hh @@ -4,6 +4,7 @@ // Fraunhofer Institute for Open Communication Systems (FOKUS) // Competence Center NETwork research (NET), St. Augustin, GERMANY // Christian Niephaus +// Stefan Bund // // 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 diff --git a/senf/Packets/80211Bundle/RadiotapPacket.test.cc b/senf/Packets/80211Bundle/RadiotapPacket.test.cc index ed8d123..93051e3 100644 --- a/senf/Packets/80211Bundle/RadiotapPacket.test.cc +++ b/senf/Packets/80211Bundle/RadiotapPacket.test.cc @@ -4,6 +4,7 @@ // Fraunhofer Institute for Open Communication Systems (FOKUS) // Competence Center NETwork research (NET), St. Augustin, GERMANY // Christian Niephaus +// Stefan Bund // // 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 diff --git a/senf/Packets/80211Bundle/WLANPacket.hh b/senf/Packets/80211Bundle/WLANPacket.hh index ddbe46c..814263e 100644 --- a/senf/Packets/80211Bundle/WLANPacket.hh +++ b/senf/Packets/80211Bundle/WLANPacket.hh @@ -197,27 +197,36 @@ namespace senf SENF_PARSER_INHERIT(WLANPacketParser); - SENF_PARSER_GOTO(subtype); - SENF_PARSER_SKIP_BITS(14); // dsBits_t; + dsBits_t::value_type dsBits() const { return parse( 1); } - SENF_PARSER_PRIVATE_FIELD ( addr1, MACAddressParser ); - SENF_PARSER_PRIVATE_FIELD ( addr2, MACAddressParser ); - SENF_PARSER_PRIVATE_FIELD ( addr3, MACAddressParser ); + MACAddressParser addr1() const { return parse( 4); } + MACAddressParser addr2() const { return parse( 10); } + MACAddressParser addr3() const { return parse( 16); } //sequence Number and fragment number //shift bits manually due to LSB - SENF_PARSER_PRIVATE_BITFIELD ( seqNumber_1, 4, unsigned ); - SENF_PARSER_BITFIELD ( fragmentNumber, 4, unsigned ); - SENF_PARSER_PRIVATE_FIELD ( seqNumber_2, UInt8Parser ); + typedef UIntFieldParser<0, 0+4> seqNumber_1_t; + seqNumber_1_t seqNumber_1() const { return parse( 22); } + + public: + typedef UIntFieldParser<4, 4+4> fragmentNumber_t; + fragmentNumber_t fragmentNumber() const { return parse( 22); } + + protected: + UInt8Parser seqNumber_2() const { return parse( 23); } + + public: boost::uint16_t sequenceNumber() const { return (uint16_t)(seqNumber_2()) << 4 | seqNumber_1(); }; void sequenceNumber(boost::uint16_t sn); + SENF_PARSER_GOTO_OFFSET( 24, 24); + // TODO fourth address field in case of WDS // SENF_PARSER_PRIVATE_VARIANT (wds_, dsBits, // ( novalue ( disable_addr4, VoidPacketParser )) diff --git a/senf/Packets/Packet.cc b/senf/Packets/Packet.cc index 06d6463..9c22dd6 100644 --- a/senf/Packets/Packet.cc +++ b/senf/Packets/Packet.cc @@ -32,21 +32,17 @@ #define prefix_ ///////////////////////////////cc.p//////////////////////////////////////// -prefix_ senf::Packet senf::Packet::checkNext() +prefix_ senf::Packet senf::Packet::getNext() const { - PacketInterpreterBase::optional_range r (ptr()->nextPacketRange()); - if (r && ! r->empty()) { - factory_t factory (ptr()->nextPacketType()); - if (factory) - return parseNextAs(factory); - else - return parseNextAs(); - } - return Packet(); + factory_t factory (ptr()->nextPacketType()); + if (factory) + return parseNextAs(factory); + else + return parseNextAs(); } -prefix_ senf::Packet senf::Packet::checkLast() +prefix_ senf::Packet senf::Packet::getLast() const { Packet p (*this); diff --git a/senf/Packets/Packet.cci b/senf/Packets/Packet.cci index 54b65f1..e5f9f4d 100644 --- a/senf/Packets/Packet.cci +++ b/senf/Packets/Packet.cci @@ -64,7 +64,9 @@ prefix_ senf::Packet senf::Packet::next(NoThrow_t) const { PacketInterpreterBase::ptr p (ptr()->next()); - return !p && ptr()->nextPacketRange() ? checkNext() : Packet(p); + if (p) return Packet(p); + PacketInterpreterBase::optional_range r (ptr()->nextPacketRange()); + return (r && ! r->empty()) ? getNext() : Packet(); } prefix_ senf::Packet senf::Packet::next() @@ -99,7 +101,7 @@ prefix_ senf::Packet senf::Packet::last() const { Packet p (ptr()->last()); - return p.next(nothrow) ? checkLast() : p; + return p.next(nothrow) ? getLast() : p; } prefix_ senf::Packet senf::Packet::parseNextAs(factory_t factory) diff --git a/senf/Packets/Packet.hh b/senf/Packets/Packet.hh index 4698dd3..43c88d2 100644 --- a/senf/Packets/Packet.hh +++ b/senf/Packets/Packet.hh @@ -495,8 +495,8 @@ namespace senf { PacketInterpreterBase::ptr const & ptr() const; private: - Packet checkNext() const; - Packet checkLast() const; + Packet getNext() const; + Packet getLast() const; PacketInterpreterBase::ptr packet_; diff --git a/senf/Packets/PacketType.ct b/senf/Packets/PacketType.ct index ab69324..0210288 100644 --- a/senf/Packets/PacketType.ct +++ b/senf/Packets/PacketType.ct @@ -38,7 +38,7 @@ prefix_ senf::PacketInterpreterBase::optional_range senf::PacketTypeMixin::nextPacketRange(ConcretePacket const & p) { typename Self::size_type sz (Self::initHeadSize()); - ///\idea This if condition could be replaced with a compile time switch by checking, wether + ///\idea This if condition could be replaced with a compile time switch by checking, whether /// (the function address) Self::initHeadSize is different from PacketTypeBase::initHeadSize if (sz == PacketTypeBase::size_type(-1)) { typename Self::size_type headsz (bytes(p.parser()));