Skip to content
Snippets Groups Projects
Commit 46036729 authored by tho's avatar tho
Browse files

Packets/80221Bundle: added MIHFId class

Packets/DefaultBundle: removed obsoleted SENF_PACKETS_DECL_ONLY ifdefs
parent c56d94fe
No related branches found
No related tags found
No related merge requests found
......@@ -32,13 +32,12 @@
#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)
{
......@@ -50,46 +49,55 @@ 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);
......@@ -144,6 +152,7 @@ prefix_ void senf::MIHPayloadPacketType::dump(packet p, std::ostream &os)
<< " ToDo!\n";
}
///////////////////////////////cc.e////////////////////////////////////////
#undef prefix_
......
// $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_
// 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:
......@@ -34,21 +34,74 @@
#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
......@@ -77,7 +130,12 @@ namespace senf {
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 {
......@@ -223,9 +281,7 @@ namespace senf {
///////////////////////////////hh.e////////////////////////////////////////
#endif
#ifndef SENF_PACKETS_DECL_ONLY
//#include "MIHPacket.cci"
#include "MIHPacket.cci"
//#include "MIHPacket.ct"
//#include "MIHPacket.cti"
#endif
......
......@@ -36,6 +36,17 @@
///////////////////////////////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());
......
......@@ -195,8 +195,6 @@ namespace senf {
}
///////////////////////////////hh.e////////////////////////////////////////
#endif
#ifndef SENF_PACKETS_DECL_ONLY
//#include "EthernetPacket.cci"
//#include "EthernetPacket.ct"
//#include "EthernetPacket.cti"
......
......@@ -93,8 +93,6 @@ namespace senf
}
///////////////////////////////hh.e////////////////////////////////////////
#endif
#ifndef SENF_PACKETS_DECL_ONLY
//#include "IPv4Packet.cci"
//#include "IPv4Packet.ct"
//#include "IPv4Packet.cti"
......
......@@ -201,8 +201,6 @@ namespace senf {
///////////////////////////////hh.e////////////////////////////////////////
#endif
#ifndef SENF_PACKETS_DECL_ONLY
//#include "IPv4Packet.cci"
//#include "IPv4Packet.ct"
//#include "IPv4Packet.cti"
......
......@@ -351,8 +351,6 @@ The Type 0 Routing header has the following format: (RFC 2460)
} //namespace senf
///////////////////////////////hh.e////////////////////////////////////////
#endif
#ifndef SENF_PACKETS_DECL_ONLY
//#include "IPv6Extensions.cci"
//#include "IPv6Extensions.ct"
//#include "IPv6Extensions.cti"
......
......@@ -159,8 +159,6 @@ namespace senf {
}
///////////////////////////////hh.e////////////////////////////////////////
#endif
#ifndef SENF_PACKETS_DECL_ONLY
//#include "IPv6Packet.cci"
//#include "IPv6Packet.ct"
//#include "IPv6Packet.cti"
......
......@@ -106,8 +106,6 @@ namespace senf {
///////////////////////////////hh.e////////////////////////////////////////
#endif
#ifndef SENF_PACKETS_DECL_ONLY
//#include "LlcSnapPacket.cci"
//#include "LlcSnapPacket.ct"
//#include "LlcSnapPacket.cti"
......
......@@ -119,8 +119,6 @@ namespace senf {
///////////////////////////////hh.e////////////////////////////////////////
#endif
#ifndef SENF_PACKETS_DECL_ONLY
//#include "UDPPacket.cci"
//#include "UDPPacket.ct"
//#include "UDPPacket.cti"
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment