#include <boost/io/ios_state.hpp>
#define prefix_
+///////////////////////////////cc.p////////////////////////////////////////
-prefix_ std::string senf::MIHFId_TLVParser::asString()
- const
-{
- return std::string( i(1+length_bytes()), i(1+length_bytes()+length()) );
-}
+
+///////////////////////////////////////////////////////////////////////////
+// MIHFId_TLVParser
prefix_ void senf::MIHFId_TLVParser::setString(std::string const &id)
{
std::copy( id.begin(), id.end(), si);
}
-prefix_ senf::MACAddress senf::MIHFId_TLVParser::asMACAddress()
- const
-{
- return MACAddress::from_data(
- getNAIDecodedIterator( i(1+length_bytes()), i(1+length_bytes()+12) ));
-}
-
prefix_ void senf::MIHFId_TLVParser::setMACAddress(senf::MACAddress const &mac)
{
safe_data_iterator si = resizeValueField(12);
std::copy( mac.begin(), mac.end(), getNAIEncodedOutputIterator(si));
}
-
-prefix_ senf::INet4Address senf::MIHFId_TLVParser::asINet4Address()
- const
-{
- return INet4Address::from_data(
- getNAIDecodedIterator( i(1+length_bytes()), i(1+length_bytes()+8) ));
-}
-
prefix_ void senf::MIHFId_TLVParser::setINet4Address(senf::INet4Address const &addr)
{
safe_data_iterator si = resizeValueField(8);
std::copy( addr.begin(), addr.end(), getNAIEncodedOutputIterator(si));
}
-prefix_ senf::INet6Address senf::MIHFId_TLVParser::asINet6Address()
- const
+prefix_ void senf::MIHFId_TLVParser::setINet6Address(senf::INet6Address const &addr)
{
- return INet6Address::from_data(
- getNAIDecodedIterator( i(1+length_bytes()), i(1+length_bytes()+32) ));
+ safe_data_iterator si = resizeValueField(32);
+ std::copy( addr.begin(), addr.end(), getNAIEncodedOutputIterator(si));
}
-prefix_ void senf::MIHFId_TLVParser::setINet6Address(senf::INet6Address const &addr)
+prefix_ void senf::MIHFId_TLVParser::setEUI64(senf::EUI64 const &addr)
{
- safe_data_iterator si = resizeValueField(32);
+ safe_data_iterator si = resizeValueField(16);
std::copy( addr.begin(), addr.end(), getNAIEncodedOutputIterator(si));
}
+prefix_ senf::MIHFId senf::MIHFId_TLVParser::valueAs(MIHFId::Type type)
+ const
+{
+ if (length() == 0) return MIHFId();
+ switch (type) {
+ case MIHFId::Empty:
+ return MIHFId();
+ case MIHFId::MACAddress:
+ return MIHFId( asMACAddress());
+ case MIHFId::INet4Address:
+ return MIHFId( asINet4Address());
+ case MIHFId::INet6Address:
+ return MIHFId( asINet6Address());
+ case MIHFId::String:
+ return MIHFId( asINet6Address());
+ case MIHFId::EUI64:
+ return MIHFId( asINet6Address());
+ }
+ return MIHFId();
+}
+
+
+///////////////////////////////////////////////////////////////////////////
+// MIHPacketType
+
prefix_ void senf::MIHPacketType::dump(packet p, std::ostream &os)
{
boost::io::ios_all_saver ias(os);
<< " ToDo!\n";
}
+///////////////////////////////cc.e////////////////////////////////////////
#undef prefix_
\f
--- /dev/null
+// $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 MIH protocol inline non-template implementation */
+
+//#include "MIHPacket.ih"
+
+// Custom includes
+
+#define prefix_ inline
+///////////////////////////////cci.p////////////////////////////////////////
+
+///////////////////////////////////////////////////////////////////////////
+// MIHFId
+prefix_ senf::MIHFId::MIHFId()
+ : boost::variant< boost::blank, senf::MACAddress, senf::INet4Address,
+ senf::INet6Address, std::string, senf::EUI64 > ( boost::blank())
+{ }
+
+prefix_ senf::MIHFId::MIHFId(senf::MACAddress const & addr)
+ : boost::variant< boost::blank, senf::MACAddress, senf::INet4Address,
+ senf::INet6Address, std::string, senf::EUI64 > ( addr)
+{ }
+
+prefix_ senf::MIHFId::MIHFId(senf::INet4Address const & addr)
+ : boost::variant< boost::blank, senf::MACAddress, senf::INet4Address,
+ senf::INet6Address, std::string, senf::EUI64 > ( addr)
+{ }
+
+prefix_ senf::MIHFId::MIHFId(senf::INet6Address const & addr)
+ : boost::variant< boost::blank, senf::MACAddress, senf::INet4Address,
+ senf::INet6Address, std::string, senf::EUI64 > ( addr)
+{ }
+
+prefix_ senf::MIHFId::MIHFId(std::string const & addr)
+ : boost::variant< boost::blank, senf::MACAddress, senf::INet4Address,
+ senf::INet6Address, std::string, senf::EUI64 > ( addr)
+{ }
+
+prefix_ senf::MIHFId::MIHFId(senf::EUI64 const & addr)
+ : boost::variant< boost::blank, senf::MACAddress, senf::INet4Address,
+ senf::INet6Address, std::string, senf::EUI64 > ( addr)
+{ }
+
+prefix_ senf::MIHFId::Type senf::MIHFId::type()
+ const
+{
+ return boost::apply_visitor( GetTypeVisitor(), *this );
+}
+
+prefix_ bool senf::MIHFId::operator==(senf::MIHFId const & other)
+ const
+{
+ return boost::apply_visitor( EqualsVisitor(), *this, other);
+}
+
+prefix_ bool senf::MIHFId::operator<(senf::MIHFId const & other)
+ const
+{
+ if (type() != other.type()) return type() < other.type();
+ return boost::apply_visitor( LessThanVisitor(), *this, other);
+}
+
+///////////////////////////////////////////////////////////////////////////
+// MIHFId_TLVParser
+
+prefix_ std::string senf::MIHFId_TLVParser::asString()
+ const
+{
+ return std::string( i(1+length_bytes()), i(1+length_bytes()+length()) );
+}
+
+prefix_ senf::MACAddress senf::MIHFId_TLVParser::asMACAddress()
+ const
+{
+ return MACAddress::from_data(
+ getNAIDecodedIterator( i(1+length_bytes()), i(1+length_bytes()+12) ));
+}
+
+prefix_ senf::INet4Address senf::MIHFId_TLVParser::asINet4Address()
+ const
+{
+ return INet4Address::from_data(
+ getNAIDecodedIterator( i(1+length_bytes()), i(1+length_bytes()+8) ));
+}
+
+prefix_ senf::INet6Address senf::MIHFId_TLVParser::asINet6Address()
+ const
+{
+ return INet6Address::from_data(
+ getNAIDecodedIterator( i(1+length_bytes()), i(1+length_bytes()+32) ));
+}
+
+prefix_ senf::EUI64 senf::MIHFId_TLVParser::asEUI64()
+ const
+{
+ return EUI64::from_data(
+ getNAIDecodedIterator( i(1+length_bytes()), i(1+length_bytes()+16) ));
+}
+
+///////////////////////////////cci.e////////////////////////////////////////
+#undef prefix_
+
+\f
+// Local Variables:
+// mode: c++
+// fill-column: 100
+// c-file-style: "senf"
+// indent-tabs-mode: nil
+// ispell-local-dictionary: "american"
+// compile-command: "scons -u test"
+// comment-column: 40
+// End:
#include "TLVPacket.hh"
#include <boost/function_output_iterator.hpp>
#include <boost/iterator/filter_iterator.hpp>
+#include "boost/variant.hpp"
//#include "MIHPacket.mpp"
///////////////////////////////hh.p////////////////////////////////////////
namespace senf {
-
+
struct MIHMessageRegistry {
// MIH messages registry
typedef boost::uint16_t key_t;
};
+
+# define SENF_MIH_PACKET_REGISTRY_REGISTER( packet ) \
+ SENF_PACKET_REGISTRY_REGISTER( \
+ senf::MIHMessageRegistry, packet::type::MESSAGE_ID, packet )
+
+ class MIHFId
+ : public boost::variant< boost::blank, senf::MACAddress, senf::INet4Address,
+ senf::INet6Address, std::string, senf::EUI64 >,
+ public boost::less_than_comparable<MIHFId>,
+ public boost::equality_comparable<MIHFId>
+ {
+ public:
+ enum Type { Empty, MACAddress, INet4Address, INet6Address, String, EUI64 };
+
+ MIHFId();
+ MIHFId(senf::MACAddress const & addr);
+ MIHFId(senf::INet4Address const & addr);
+ MIHFId(senf::INet6Address const & addr);
+ MIHFId(std::string const & addr);
+ MIHFId(senf::EUI64 const & addr);
+
+ Type type() const;
+ bool operator==(MIHFId const & other) const;
+ bool operator<(MIHFId const & other) const;
+
+ private:
+ struct GetTypeVisitor : public boost::static_visitor<Type> {
+ Type operator()(boost::blank const &) const { return Empty; }
+ Type operator()(senf::MACAddress const &) const { return MACAddress; }
+ Type operator()(senf::INet4Address const &) const { return INet4Address; }
+ Type operator()(senf::INet6Address const &) const { return INet6Address; }
+ Type operator()(std::string const & ) const { return String; }
+ Type operator()(senf::EUI64 const &) const { return EUI64; }
+ };
+ struct EqualsVisitor : public boost::static_visitor<bool> {
+ template <typename T, typename U>
+ bool operator()(T const &, U const &) const {
+ return false;
+ }
+ template <typename T>
+ bool operator()( const T & lhs, const T & rhs ) const {
+ return lhs == rhs;
+ }
+ };
+ struct LessThanVisitor : public boost::static_visitor<bool> {
+ template <typename T, typename U>
+ bool operator()(T const &, U const &) const {
+ return false;
+ }
+ template <typename T>
+ bool operator()( const T & lhs, const T & rhs ) const {
+ return lhs < rhs;
+ }
+ };
+ };
-# define SENF_MIH_PACKET_REGISTRY_REGISTER( packetType ) \
- SENF_PACKET_REGISTRY_REGISTER( \
- senf::MIHMessageRegistry, packetType::type::MESSAGE_ID, packetType )
/** \brief Parse a MIHF_ID
senf::INet6Address asINet6Address() const;
void setINet6Address(senf::INet6Address const &addr);
+
+ senf::EUI64 asEUI64() const;
+ void setEUI64(senf::EUI64 const &addr);
+ MIHFId valueAs(MIHFId::Type type) const;
+
private:
template <class OutputIterator>
struct binaryNAIEncoder {
///////////////////////////////hh.e////////////////////////////////////////
-#endif
-#ifndef SENF_PACKETS_DECL_ONLY
-//#include "MIHPacket.cci"
+#include "MIHPacket.cci"
//#include "MIHPacket.ct"
//#include "MIHPacket.cti"
#endif
///////////////////////////////cc.p////////////////////////////////////////
using namespace senf;
+BOOST_AUTO_UNIT_TEST(MIHPacket_MIHFId)
+{
+ MIHFId id ( MACAddress::from_string("01:02:03:04:05:06"));
+ BOOST_CHECK_EQUAL( id.type(), MIHFId::MACAddress);
+ BOOST_CHECK_EQUAL( id, MIHFId( MACAddress::from_string("01:02:03:04:05:06")));
+ BOOST_CHECK( id != MIHFId( MACAddress::from_string("01:02:03:04:05:07")));
+ BOOST_CHECK( id != MIHFId( INet4Address::from_string("128.129.130.131")));
+ BOOST_CHECK( id < MIHFId( MACAddress::from_string("01:02:03:04:05:07")));
+ BOOST_CHECK( id < MIHFId( INet4Address::from_string("128.129.130.131")));
+}
+
BOOST_AUTO_UNIT_TEST(MIHPacket_msgId)
{
MIHPacket mihPacket (MIHPacket::create());
}
///////////////////////////////hh.e////////////////////////////////////////
-#endif
-#ifndef SENF_PACKETS_DECL_ONLY
//#include "EthernetPacket.cci"
//#include "EthernetPacket.ct"
//#include "EthernetPacket.cti"
}
///////////////////////////////hh.e////////////////////////////////////////
-#endif
-#ifndef SENF_PACKETS_DECL_ONLY
//#include "IPv4Packet.cci"
//#include "IPv4Packet.ct"
//#include "IPv4Packet.cti"
///////////////////////////////hh.e////////////////////////////////////////
-#endif
-#ifndef SENF_PACKETS_DECL_ONLY
//#include "IPv4Packet.cci"
//#include "IPv4Packet.ct"
//#include "IPv4Packet.cti"
} //namespace senf
///////////////////////////////hh.e////////////////////////////////////////
-#endif
-#ifndef SENF_PACKETS_DECL_ONLY
//#include "IPv6Extensions.cci"
//#include "IPv6Extensions.ct"
//#include "IPv6Extensions.cti"
}
///////////////////////////////hh.e////////////////////////////////////////
-#endif
-#ifndef SENF_PACKETS_DECL_ONLY
//#include "IPv6Packet.cci"
//#include "IPv6Packet.ct"
//#include "IPv6Packet.cti"
///////////////////////////////hh.e////////////////////////////////////////
-#endif
-#ifndef SENF_PACKETS_DECL_ONLY
//#include "LlcSnapPacket.cci"
//#include "LlcSnapPacket.ct"
//#include "LlcSnapPacket.cti"
///////////////////////////////hh.e////////////////////////////////////////
-#endif
-#ifndef SENF_PACKETS_DECL_ONLY
//#include "UDPPacket.cci"
//#include "UDPPacket.ct"
//#include "UDPPacket.cti"