ip.finalizeAll();
-// std::string dump (
-// "Internet protocol Version 6:\n"
-// " version : 6\n"
-// " traffic class : 0x00\n"
-// " flow label : 0x00000\n"
-// " payload length : 64\n"
-// " next header : 58\n"
-// " hop limit : 64\n"
-// " source : ::1\n"
-// " destination : ::1\n"
-// "ICMPv6 protocol:\n"
-// " type : 128\n"
-// " code : 0\n"
-// " checksum : 0xdae0\n"
-// "ICMPv6 Echo Request:\n"
-// " identifier : 40830\n"
-// " sequence nr. : 9\n"
-// "Payload data (56 bytes)\n"
-// );
-
-// {
-// std::stringstream ss;
-// ip.dump(ss);
-// BOOST_CHECK_EQUAL( ss.str(), dump );
-// }
-
SENF_CHECK_NO_THROW (ip.dump( oss ));
+ std::string dump (
+ "Internet protocol Version 6:\n"
+ " version : 6\n"
+ " traffic class : 0x00\n"
+ " flow label : 0x00000\n"
+ " payload length : 64\n"
+ " next header : 58\n"
+ " hop limit : 64\n"
+ " source : ::1\n"
+ " destination : ::1\n"
+ "ICMPv6 protocol:\n"
+ " type : 128\n"
+ " code : 0\n"
+ " checksum : 0xdae0\n"
+ "ICMPv6 Echo Request:\n"
+ " Identifier : 40830\n"
+ " SequenceNumber : 9\n"
+ "Payload data (56 bytes)\n"
+ );
+
+ {
+ std::stringstream ss;
+ ip.dump(ss);
+ BOOST_CHECK_EQUAL( ss.str(), dump );
+ }
+
SENF_CHECK_EQUAL_COLLECTIONS( ip.data().begin(), ip.data().end(),
ping, ping+sizeof(ping) );
-// senf::IPv6Packet orig (senf::IPv6Packet::create(ping));
-//
-// {
-// std::stringstream ss;
-// orig.dump(ss);
-// BOOST_CHECK_EQUAL( ss.str(), dump );
-// }
+ senf::IPv6Packet orig (senf::IPv6Packet::create(ping));
+
+ {
+ std::stringstream ss;
+ orig.dump(ss);
+ BOOST_CHECK_EQUAL( ss.str(), dump );
+ }
}
// Local Variables:
--- /dev/null
+// $Id$
+//
+// Copyright (C) 2009
+// Fraunhofer Institute for Open Communication Systems (FOKUS)
+// Competence Center NETwork research (NET), St. Augustin, GERMANY
+// Stefan Bund <g0dil@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 DumpFormat non-inline non-template implementation */
+
+#include "Packets.hh"
+#include "DumpFormat.ih"
+
+// Custom includes
+#include <iostream>
+#include <algorithm>
+
+//#include "DumpFormat.mpp"
+#define prefix_
+///////////////////////////////cc.p////////////////////////////////////////
+
+#ifndef SENF_PACKET_DUMP_COLON_COLUMN
+#define SENF_PACKET_DUMP_COLON_COLUMN 27
+#endif
+
+prefix_ std::string senf::fieldName(std::string const & s)
+{
+ std::string t (std::max(unsigned(SENF_PACKET_DUMP_COLON_COLUMN+1), s.size()+5), ' ');
+ std::copy(s.begin(), s.end(), t.begin()+2);
+ t[t.size()-2] = ':';
+ return t;
+}
+
+prefix_ std::string senf::detail::prettySignedNumber(long long v, unsigned bits)
+{
+ if (v<0) return prettyUnsignedNumber(-v,bits,-1);
+ else return prettyUnsignedNumber(v,bits,+1);
+}
+
+prefix_ std::string senf::detail::prettyUnsignedNumber(unsigned long long v, unsigned bits,
+ int sign)
+{
+ int bytes ((bits+7)/8);
+ int digs (int(2.4*bytes)+1);
+ std::stringstream ss;
+ ss << (sign ? (sign<0 ? "-" : " ") : "")
+ << "0x" << std::setw(2*bytes) << std::setfill('0') << std::hex
+ << 1u*v
+ << " (" << std::setw(digs+(sign ? 1 : 0)) << std::setfill(' ') << std::dec;
+ if (sign)
+ ss << sign*static_cast<long long>(v);
+ else
+ ss << 1u*v;
+ ss << ") (";
+ for (int i (bytes-1); i>=0; --i) {
+ char c ((v>>(8*i))&0xff);
+ ss << ((c>=32 && c<=127) ? c : '.');
+ }
+ ss << ')';
+ return ss.str();
+}
+
+
+///////////////////////////////cc.e////////////////////////////////////////
+#undef prefix_
+//#include "DumpFormat.mpp"
+
+\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:
--- /dev/null
+// $Id$
+//
+// Copyright (C) 2009
+// Fraunhofer Institute for Open Communication Systems (FOKUS)
+// Competence Center NETwork research (NET), St. Augustin, GERMANY
+// Stefan Bund <g0dil@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 DumpFormat non-inline template implementation */
+
+#include "DumpFormat.ih"
+
+// Custom includes
+#include <sstream>
+
+#define prefix_
+///////////////////////////////ct.p////////////////////////////////////////
+
+template <class T>
+prefix_ std::string
+senf::prettyNumber(T const & v, typename boost::enable_if<boost::is_signed<T> >::type *)
+{
+ return detail::prettySignedNumber(v, std::numeric_limits<T>::digits);
+}
+
+template <class T>
+prefix_ std::string
+senf::prettyNumber(T const & v, typename boost::enable_if<boost::is_unsigned<T> >::type *)
+{
+ return detail::prettyUnsignedNumber(v, std::numeric_limits<T>::digits);
+}
+
+///////////////////////////////ct.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:
--- /dev/null
+// $Id$
+//
+// Copyright (C) 2009
+// Fraunhofer Institute for Open Communication Systems (FOKUS)
+// Competence Center NETwork research (NET), St. Augustin, GERMANY
+// Stefan Bund <g0dil@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 DumpFormat public header */
+
+#ifndef HH_SENF_senf_Packets_DumpFormat_
+#define HH_SENF_senf_Packets_DumpFormat_ 1
+
+#ifndef HH_SENF_Packets_Packets_
+#error "Don't include 'DumpFormat.hh' directly, include 'Packets.hh'"
+#endif
+
+// Custom includes
+#include <boost/utility/enable_if.hpp>
+#include <boost/type_traits/is_signed.hpp>
+#include <boost/type_traits/is_unsigned.hpp>
+
+//#include "DumpFormat.mpp"
+///////////////////////////////hh.p////////////////////////////////////////
+
+namespace senf {
+
+ std::string fieldName(std::string const & s);
+
+ template <class T>
+ std::string prettyNumber(T const & v,
+ typename boost::enable_if<boost::is_signed<T> >::type * = 0);
+
+ template <class T>
+ std::string prettyNumber(T const & v,
+ typename boost::enable_if<boost::is_unsigned<T> >::type * = 0);
+}
+
+///////////////////////////////hh.e////////////////////////////////////////
+#endif
+#if !defined(HH_SENF_Packets_Packets__decls_) && !defined(HH_SENF_Packets_DumpFormat_i_)
+#define HH_SENF_Packets_DumpFormat_i_
+//#include "DumpFormat.cci"
+#include "DumpFormat.ct"
+//#include "DumpFormat.cti"
+#endif
+
+\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:
--- /dev/null
+// $Id$
+//
+// Copyright (C) 2009
+// Fraunhofer Institute for Open Communication Systems (FOKUS)
+// Competence Center NETwork research (NET), St. Augustin, GERMANY
+// Stefan Bund <g0dil@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 DumpFormat internal header */
+
+#ifndef IH_SENF_senf_Packets_DumpFormat_
+#define IH_SENF_senf_Packets_DumpFormat_ 1
+
+// Custom includes
+
+///////////////////////////////ih.p////////////////////////////////////////
+
+namespace senf {
+namespace detail {
+
+ std::string prettySignedNumber(long long v, unsigned bits);
+ std::string prettyUnsignedNumber(unsigned long long v, unsigned bits, int sign=0);
+
+}}
+
+///////////////////////////////ih.e////////////////////////////////////////
+#endif
+
+\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:
--- /dev/null
+// $Id$
+//
+// Copyright (C) 2009
+// Fraunhofer Institute for Open Communication Systems (FOKUS)
+// Competence Center NETwork research (NET), St. Augustin, GERMANY
+// Stefan Bund <g0dil@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 DumpFormat.test unit tests */
+
+//#include "DumpFormat.test.hh"
+//#include "DumpFormat.test.ih"
+
+// Custom includes
+#include "Packets.hh"
+
+#include <senf/Utils/auto_unit_test.hh>
+#include <boost/test/test_tools.hpp>
+
+#define prefix_
+///////////////////////////////cc.p////////////////////////////////////////
+
+BOOST_AUTO_UNIT_TEST(dumpFormat)
+{
+ BOOST_CHECK_EQUAL( senf::fieldName("test"), " test : " );
+ BOOST_CHECK_EQUAL( senf::fieldName("xxxxxxxxxxxxxxxxxxxxxxx"), " xxxxxxxxxxxxxxxxxxxxxxx : " );
+ BOOST_CHECK_EQUAL( senf::fieldName("xxxxxxxxxxxxxxxxxxxxxxxx"), " xxxxxxxxxxxxxxxxxxxxxxxx : " );
+
+ BOOST_CHECK_EQUAL( senf::prettyNumber<boost::int16_t>(-1), "-0x0001 ( -1) (..)" );
+ BOOST_CHECK_EQUAL( senf::prettyNumber<boost::int16_t>(1), " 0x0001 ( 1) (..)" );
+ BOOST_CHECK_EQUAL( senf::prettyNumber<boost::uint16_t>(1), "0x0001 ( 1) (..)" );
+}
+
+///////////////////////////////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:
template <class KeyType>
prefix_ void senf::detail::DumpKey<KeyType, true>::dump(KeyType const & v, std::ostream & os)
{
- int bytes ((std::numeric_limits<KeyType>::digits+7)/8);
- int digs (int(2.4*bytes)+1);
-
- os << " 0x" << std::setw(2*bytes) << std::setfill('0') << std::hex
- << typename senf::detail::CharToInt<KeyType>::type (v)
- << " (" << std::setw(digs) << std::setfill(' ') << std::dec
- << typename senf::detail::CharToInt<KeyType>::type (v)
- << ") (";
- for (int i (bytes-1); i>=0; --i) {
- char c ((v>>(8*i))&0xff);
- os << ((c>=32 && c<=127) ? c : '.');
- }
- os << ')';
+ os << " " << senf::prettyNumber(v);
}
///////////////////////////////ct.e////////////////////////////////////////
static void dump(KeyType const & v, std::ostream & os);
};
- template <class Type> struct CharToInt { typedef Type type; };
- template <> struct CharToInt<char> { typedef int type; };
- template <> struct CharToInt<signed char> { typedef int type; };
- template <> struct CharToInt<unsigned char> { typedef unsigned type; };
-
}}
///////////////////////////////ih.e////////////////////////////////////////
#include "VectorParser.hh"
#include "ParseHelpers.hh"
#include "DataPacket.hh"
+#include "DumpFormat.hh"
#undef HH_SENF_Packets_Packets__decls_
#include "VectorParser.hh"
#include "ParseHelpers.hh"
#include "DataPacket.hh"
+#include "DumpFormat.hh"
#endif
{
// Link in logger library ...
(void) senf::log::StreamRegistry::instance();
- for (unsigned i (1); i<argc; ++i) {
+ for (int i (1); i<argc; ++i) {
senf::detail::PacketRegistryImplBase::clear();
void *handle = dlopen(argv[i], RTLD_NOW | RTLD_GLOBAL);
if (handle == NULL) {