//
// 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.
+// The contents of this file are subject to the Fraunhofer FOKUS Public License
+// Version 1.0 (the "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+// http://senf.berlios.de/license.html
//
-// 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.
+// The Fraunhofer FOKUS Public License Version 1.0 is based on,
+// but modifies the Mozilla Public License Version 1.1.
+// See the full license text for the amendments.
//
-// 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.
+// Software distributed under the License is distributed on an "AS IS" basis,
+// WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
+// for the specific language governing rights and limitations under the License.
+//
+// The Original Code is Fraunhofer FOKUS code.
+//
+// The Initial Developer of the Original Code is Fraunhofer-Gesellschaft e.V.
+// (registered association), Hansastraße 27 c, 80686 Munich, Germany.
+// All Rights Reserved.
+//
+// Contributor(s):
+// Thorsten Horstmann <tho@berlios.de>
/** \file
\brief MIHPacket unit tests */
#include <boost/test/test_tools.hpp>
#define prefix_
-///////////////////////////////cc.p////////////////////////////////////////
+//-/////////////////////////////////////////////////////////////////////////////////////////////////
using namespace senf;
-BOOST_AUTO_UNIT_TEST(MIHPacket_msgId)
+SENF_AUTO_UNIT_TEST(MIHPacket_msgId)
{
MIHPacket mihPacket (MIHPacket::create());
mihPacket->sid() = 4;
mihPacket->opcode() = 3;
mihPacket->aid() = 42;
- BOOST_CHECK_EQUAL( mihPacket->messageId(), 0x4c2a );
+ BOOST_CHECK_EQUAL( mihPacket->messageId(), 0x4c2a );
}
-BOOST_AUTO_UNIT_TEST(MIHPacket_create_eth)
+SENF_AUTO_UNIT_TEST(MIHPacket_create_eth)
{
EthernetPacket eth (EthernetPacket::create());
MIHPacket mihPacket (MIHPacket::createAfter(eth));
SENF_CHECK_NO_THROW( eth.dump( oss));
}
-BOOST_AUTO_UNIT_TEST(MIHPacket_create_string)
+SENF_AUTO_UNIT_TEST(MIHPacket_create_string)
{
MIHPacket mihPacket (MIHPacket::create());
// set some fields
mihPacket->src_mihfId().value( "senf@berlios.de");
mihPacket->dst_mihfId().value( "test");
mihPacket.finalizeThis();
-
+
unsigned char data[] = {
// MIH header
0x10, 0x54, 0x00, 0x00, 0x00, 0x15, 0x00, 0x19,
mihPacket->dst_mihfId().maxIdLength(128);
mihPacket->dst_mihfId().value( std::string(128, 'x'));
mihPacket.finalizeThis();
- // packet size is now MIH header (8 bytes) + src MIHIFId TLV (18 bytes) +
- // dst MIHIFId TLV (1 byte type + 2 byte TLV length + 1 byte id length + 128 id value)
- BOOST_CHECK_EQUAL( mihPacket.size(), unsigned(8 + 18 + 1+2+1+128));
+ // packet size is now MIH header (8 bytes) + src MIHIFId TLV (18 bytes) +
+ // dst MIHIFId TLV (1 byte type + 2 byte TLV length + 1 byte id length + 128 id value)
+ BOOST_CHECK_EQUAL( mihPacket.size(), unsigned(8 + 18 + 1+2+1+128));
BOOST_CHECK_EQUAL( mihPacket->payloadLength(), 18 + 1+2+1+128);
BOOST_CHECK_EQUAL( mihPacket->dst_mihfId().length(), 1+128);
BOOST_CHECK_EQUAL( senf::bytes(mihPacket->dst_mihfId()), 1+2+1+128);
mihPacket->dst_mihfId().maxIdLength(129);
mihPacket->dst_mihfId().value( std::string(129, 'x'));
mihPacket.finalizeThis();
- // packet size is now MIH header (8 bytes) + src MIHIFId TLV (18 bytes) +
- // dst MIHIFId TLV (1 byte type + 2 byte TLV length + 2 byte id length + 128 id value)
- BOOST_CHECK_EQUAL( mihPacket.size(), unsigned(8 + 18 + 1+2+2+129));
+ // packet size is now MIH header (8 bytes) + src MIHIFId TLV (18 bytes) +
+ // dst MIHIFId TLV (1 byte type + 2 byte TLV length + 2 byte id length + 128 id value)
+ BOOST_CHECK_EQUAL( mihPacket.size(), unsigned(8 + 18 + 1+2+2+129));
BOOST_CHECK_EQUAL( mihPacket->payloadLength(), 18 + 1+2+2+129);
BOOST_CHECK_EQUAL( mihPacket->dst_mihfId().length(), 2+129);
BOOST_CHECK_EQUAL( senf::bytes(mihPacket->dst_mihfId()), 1+2+2+129);
mihPacket.finalizeThis();
SENF_CHECK_EQUAL_COLLECTIONS( data, data+sizeof(data),
mihPacket.data().begin(), mihPacket.data().end() );
-
+
std::ostringstream oss (std::ostringstream::out);
SENF_CHECK_NO_THROW( mihPacket.dump( oss));
}
-BOOST_AUTO_UNIT_TEST(MIHPacket_create_mac)
+SENF_AUTO_UNIT_TEST(MIHPacket_create_mac)
{
MACAddress srcMac ( MACAddress::from_string("01:02:03:04:05:06"));
MACAddress dstMac ( MACAddress::from_string("07:08:09:0a:0b:0c"));
}
-BOOST_AUTO_UNIT_TEST(MIHPacket_create_inet4)
+SENF_AUTO_UNIT_TEST(MIHPacket_create_inet4)
{
MIHPacket mihPacket (MIHPacket::create());
// set some fields
}
-BOOST_AUTO_UNIT_TEST(MIHPacket_create_inet6)
+SENF_AUTO_UNIT_TEST(MIHPacket_create_inet6)
{
MIHPacket mihPacket (MIHPacket::create());
// set some fields
}
-BOOST_AUTO_UNIT_TEST(MIHPayload_parse)
+SENF_AUTO_UNIT_TEST(MIHPayload_parse)
{
unsigned char data[] = {
// MIH header
BOOST_CHECK_EQUAL( tlv2.type(), 0x0c);
BOOST_CHECK_EQUAL( tlv2.length(), 0x04u);
BOOST_CHECK_EQUAL( tlv2.value().size(), 0x04);
-
+
std::ostringstream oss (std::ostringstream::out);
SENF_CHECK_NO_THROW( mihPayload.dump( oss));
}
-BOOST_AUTO_UNIT_TEST(MIHPayload_create)
+SENF_AUTO_UNIT_TEST(MIHPayload_create)
{
MIHPacket mihPacket (MIHPacket::create());
mihPacket->fragmentNr() = 42;
MIHGenericPayloadPacket mihPayload (MIHGenericPayloadPacket::createAfter(mihPacket));
MIHGenericPayloadPacket::Parser::tlvList_t::container tlvListContainer (
mihPayload->tlvList() );
-
+
unsigned char tlv1_value[] = {
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09 };
MIHGenericTLVParser tlv1 ( tlvListContainer.push_back_space());
unsigned char tlv2_value[] = {
0x1a, 0x2b, 0x3c, 0x4d };
MIHGenericTLVParser tlv2 ( tlvListContainer.push_back_space());
- tlv2.type() = 0x0c;
+ tlv2.type() = 0x43;
tlv2.value( tlv2_value);
mihPacket.finalizeAll();
0x0a, // first bit not set, length=10
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, // value
// second test tlv
- 0x0c, // type
+ 0x43, // type
0x04, // first bit not set, length=4
0x1a, 0x2b, 0x3c, 0x4d // value
};
SENF_CHECK_EQUAL_COLLECTIONS( data, data+sizeof(data),
- mihPacket.data().begin(), mihPacket.data().end() );
+ mihPacket.data().begin(), mihPacket.data().end() );
}
+SENF_AUTO_UNIT_TEST(Test_MIHFIdTLV)
+{
+ unsigned char data[] = {
+ // MIH header
+ 0x10, 0x54, 0x00, 0x00, 0x00, 0x15, 0x00, 0x06,
+ // source MIHF_ID TLV:
+ 0x01, 0x01, // type, length
+ 0x00, // value-length
+ // destination MIHF_ID TLV:
+ 0x02, 0x01, // type, length
+ 0x00 // value-length
+ };
+
+ MIHPacket mihPacket (MIHPacket::create(data));
+ BOOST_CHECK( mihPacket->src_mihfId().valueEquals( MIHFId::Multicast) );
+ BOOST_CHECK( mihPacket->dst_mihfId().valueEquals( MIHFId::Multicast) );
+}
-///////////////////////////////cc.e////////////////////////////////////////
+//-/////////////////////////////////////////////////////////////////////////////////////////////////
#undef prefix_
\f