BOOST_CHECK_EQUAL( p->channelOptions().staticTurbo(), false);
BOOST_CHECK_EQUAL( p->channelOptions().halfRateChannel(), false);
BOOST_CHECK_EQUAL( p->channelOptions().quarterRateChannel(), false);
+
+ std::ostringstream oss (std::ostringstream::out);
+ SENF_CHECK_NO_THROW( p.dump( oss));
}
BOOST_AUTO_UNIT_TEST(RadiotapPacket_create)
BOOST_CHECK_EQUAL( p->duration(), 0u );
- BOOST_CHECK_EQUAL(
+ BOOST_CHECK_EQUAL(
p->dataFrame().destinationAddress().value(),
senf::MACAddress::from_string("00:18:4d:6e:78:48") );
- BOOST_CHECK_EQUAL(
+ BOOST_CHECK_EQUAL(
p->dataFrame().sourceAddress().value(),
senf::MACAddress::from_string("00:0b:6b:57:06:b0") );
- BOOST_CHECK_EQUAL(
+ BOOST_CHECK_EQUAL(
p->dataFrame().bssid().value(),
senf::MACAddress::from_string("00:1a:4d:3e:c7:5c") );
- BOOST_CHECK_EQUAL(
- p->dataFrame().bssid().value(),
+ BOOST_CHECK_EQUAL(
+ p->dataFrame().bssid().value(),
p->dataFrame().receiverAddress().value() );
- BOOST_CHECK_EQUAL(
- p->dataFrame().transmitterAddress().value(),
+ BOOST_CHECK_EQUAL(
+ p->dataFrame().transmitterAddress().value(),
p->dataFrame().sourceAddress().value() );
BOOST_CHECK_EQUAL( p->dataFrame().sequenceNumber(), 3u );
BOOST_CHECK_EQUAL( p->dataFrame().fragmentNumber(), 0u );
+
+ std::ostringstream oss (std::ostringstream::out);
+ SENF_CHECK_NO_THROW( p.dump( oss));
}
BOOST_CHECK_EQUAL( p->is_mgtFrame(), true );
- BOOST_CHECK_EQUAL(
+ BOOST_CHECK_EQUAL(
p->mgtFrame().destinationAddress().value(),
senf::MACAddress::from_string("ff:ff:ff:ff:ff:ff") );
- BOOST_CHECK_EQUAL(
+ BOOST_CHECK_EQUAL(
p->mgtFrame().sourceAddress().value(),
senf::MACAddress::from_string("00:1a:4d:3e:c7:5c") );
- BOOST_CHECK_EQUAL(
+ BOOST_CHECK_EQUAL(
p->mgtFrame().bssid().value(),
senf::MACAddress::from_string("00:1a:4d:3e:c7:5c") );
-
+
BOOST_CHECK_EQUAL( p->mgtFrame().sequenceNumber(), 302u );
BOOST_CHECK_EQUAL( p->mgtFrame().fragmentNumber(), 0u );
BOOST_CHECK_EQUAL( p->duration(), 0u );
- BOOST_CHECK_EQUAL(
+ BOOST_CHECK_EQUAL(
p->ctrlFrame().receiverAddress().value(),
senf::MACAddress::from_string("00:0b:6b:57:06:b0") );
}
namespace senf {
- // the maximum length of a MIHF_ID is 253 octets (see F.3.11 in 802.21)
- // we could set maxLengthValue in INIT, but for the most MIHF_IDs the default
- // maximum length of 127 should be enough.
- // The user must call mihPacket->src_mihfId().maxLengthValue( 253) before
- // setting longer MIHF_IDs
+ /** \brief Parse a MIHF_ID
+
+ the maximum length of a MIHF_ID is 253 octets (see F.3.11 in 802.21)
+ we could set maxLengthValue in init(), but for the most MIHF_IDs the default
+ maximum length of 127 should be enough.
+
+ \note you must call mihfIdPacket.maxLengthValue( 253) *before*
+ setting longer MIHF_IDs values.
+ */
class MIHFId_TLVParser : public BaseTLVPacketParser
{
- # include SENF_PARSER()
+ # include SENF_PARSER()
SENF_PARSER_INHERIT ( BaseTLVPacketParser );
SENF_PARSER_SKIP ( length(), 0 );
SENF_PARSER_FINALIZE ( MIHFId_TLVParser );
-
+
std::string asString() const;
void setString(std::string const &id);
-
+
senf::MACAddress asMACAddress() const;
void setMACAddress(senf::MACAddress const &mac);
senf::INet4Address asINet4Address() const;
void setINet4Address(senf::INet4Address const &addr);
-
+
senf::INet6Address asINet6Address() const;
void setINet6Address(senf::INet6Address const &addr);
struct binaryNAIEncoder {
binaryNAIEncoder(OutputIterator &i) : i_(i) {}
void operator()(const boost::uint8_t &v) const {
- *i_++ = '\\';
+ *i_++ = '\\';
*i_++ = v;
}
OutputIterator &i_;
static boost::function_output_iterator<binaryNAIEncoder<OutputIterator> > getNAIEncodedOutputIterator(OutputIterator i) {
return boost::make_function_output_iterator(binaryNAIEncoder<OutputIterator>(i));
}
-
+
struct binaryNAIDecoder {
binaryNAIDecoder() : readNextByte_(true) {}
- bool operator()(const boost::uint8_t &v) {
+ bool operator()(const boost::uint8_t &v) {
readNextByte_ = readNextByte_ ? false : true;
return readNextByte_;
}
Parser implementing the MIH header. The fields implemented are:
\image html MIHPacket.png
-
+
\see MIHPacketType
*/
struct MIHPacketParser : public PacketParserBase
{
# include SENF_PARSER()
-
+
SENF_PARSER_BITFIELD_RO ( version, 4, unsigned );
SENF_PARSER_BITFIELD ( ackRequest, 1, bool );
SENF_PARSER_BITFIELD ( ackResponse, 1, bool );
SENF_PARSER_BITFIELD ( moreFragment, 1, bool );
SENF_PARSER_BITFIELD ( fragmentNr, 7, unsigned );
SENF_PARSER_SKIP_BITS ( 1 );
-
+
// MIH message ID (MID)
SENF_PARSER_BITFIELD ( sid, 4, unsigned );
SENF_PARSER_BITFIELD ( opcode, 2, unsigned );
SENF_PARSER_BITFIELD ( aid, 10, unsigned );
-
+
SENF_PARSER_SKIP_BITS ( 4 );
SENF_PARSER_BITFIELD ( transactionId, 12, unsigned );
SENF_PARSER_FIELD_RO ( payloadLength, UInt16Parser );
-
+
// Source MIHF Id
SENF_PARSER_FIELD ( src_mihfId, MIHFId_TLVParser );
// Destination MIHF Id
SENF_PARSER_FIELD ( dst_mihfId, MIHFId_TLVParser );
-
+
SENF_PARSER_FINALIZE ( MIHPacketParser );
-
+
SENF_PARSER_INIT() {
version_() = 1;
src_mihfId().type() = 1;
dst_mihfId().type() = 2;
}
-
+
friend class MIHPacketType;
};
-
+
/** \brief MIH packet
\par Packet type (typedef):
\par Fields:
\ref MIHPacketParser
-
+
\ingroup protocolbundle_80221
*/
struct MIHPacketType
/** \brief MIH packet typedef */
typedef ConcretePacket<MIHPacketType> MIHPacket;
-
-
+
+
struct MIHPayloadPacketParser : public PacketParserBase
{
# include SENF_PARSER()
SENF_PARSER_LIST ( tlv_list, packetSize(), GenericTLVPacketParser );
-
+
SENF_PARSER_FINALIZE ( MIHPayloadPacketParser );
};
-
+
struct MIHPayloadPacketType
: public PacketTypeBase,
public PacketTypeMixin<MIHPayloadPacketType>
#ifndef DOXYGEN
typedef PacketTypeMixin<MIHPayloadPacketType> mixin;
#endif
- typedef ConcretePacket<MIHPayloadPacketType> packet; ///< MIH Payload packet typedef
+ typedef ConcretePacket<MIHPayloadPacketType> packet; ///< MIH Payload packet typedef
typedef MIHPayloadPacketParser parser; ///< typedef to the parser of MIH Payload packet
using mixin::nextPacketRange;
/** \brief Dump given MIHPayload in readable form to given output stream */
static void dump(packet p, std::ostream &os);
};
-
+
/** \brief MIH Payload packet typedef */
typedef ConcretePacket<MIHPayloadPacketType> MIHPayloadPacket;
}
//#include "MIHPacket.cti"
#endif
-\f
+
// Local Variables:
// mode: c++
// fill-column: 100
mihPacket->src_mihfId().setString( "senf@berlios.de");
mihPacket->dst_mihfId().setString( "test");
mihPacket.finalizeThis();
-
- unsigned char data[] = {
+
+ unsigned char data[] = {
// MIH header
0x10, 0x54, 0x00, 0x00, 0x00, 0x15, 0x00, 0x17,
// source MIHF_ID TLV:
0x01, 0x0f, // type, length
- 0x73, 0x65, 0x6e, 0x66, 0x40, 0x62, 0x65, 0x72, 0x6c,
+ 0x73, 0x65, 0x6e, 0x66, 0x40, 0x62, 0x65, 0x72, 0x6c,
0x69, 0x6f, 0x73, 0x2e, 0x64, 0x65, // value
// destination MIHF_ID TLV:
0x02, 0x04, 0x74, 0x65, 0x73, 0x74
BOOST_CHECK(equal( mihPacket.data().begin(), mihPacket.data().end(), data ));
BOOST_CHECK_EQUAL( mihPacket->src_mihfId().asString(), "senf@berlios.de");
BOOST_CHECK_EQUAL( mihPacket->dst_mihfId().asString(), "test");
-
+
// now expand a MIHF_ID
mihPacket->dst_mihfId().maxLengthValue(253);
mihPacket->dst_mihfId().setString( std::string(200, 'x'));
mihPacket.finalizeThis();
-
+
BOOST_CHECK_EQUAL( mihPacket.size(), unsigned(8 + 17 + 203));
BOOST_CHECK_EQUAL( mihPacket->payloadLength(), 17 + 203);
BOOST_CHECK_EQUAL( mihPacket->dst_mihfId().length(), 200u);
BOOST_CHECK_EQUAL( senf::bytes(mihPacket->dst_mihfId()), 203u);
+
+ std::ostringstream oss (std::ostringstream::out);
+ SENF_CHECK_NO_THROW( mihPacket.dump( oss));
}
mihPacket->src_mihfId().setMACAddress( MACAddress::from_string("01:02:03:04:05:06"));
mihPacket->dst_mihfId().setMACAddress( MACAddress::from_string("07:08:09:0a:0b:0c"));
mihPacket.finalizeThis();
-
- unsigned char data[] = {
+
+ unsigned char data[] = {
// MIH header
0x10, 0x54, 0x00, 0x00, 0x00, 0x15, 0x00, 0x1c,
// source MIHF_ID TLV:
0x5c, 0x07, 0x5c, 0x08, 0x5c, 0x09, 0x5c, 0x0a, 0x5c, 0x0b, 0x5c, 0x0c // value (nai-encoded)
};
BOOST_CHECK(equal( mihPacket.data().begin(), mihPacket.data().end(), data ));
- BOOST_CHECK_EQUAL(
- mihPacket->src_mihfId().asMACAddress(),
+ BOOST_CHECK_EQUAL(
+ mihPacket->src_mihfId().asMACAddress(),
MACAddress::from_string("01:02:03:04:05:06"));
- BOOST_CHECK_EQUAL(
- mihPacket->dst_mihfId().asMACAddress(),
+ BOOST_CHECK_EQUAL(
+ mihPacket->dst_mihfId().asMACAddress(),
MACAddress::from_string("07:08:09:0a:0b:0c"));
}
mihPacket->src_mihfId().setINet4Address( INet4Address::from_string("128.129.130.131"));
mihPacket->dst_mihfId().setINet4Address( INet4Address::from_string("132.133.134.135"));
mihPacket.finalizeThis();
-
- unsigned char data[] = {
+
+ unsigned char data[] = {
// MIH header
0x10, 0x54, 0x00, 0x00, 0x00, 0x15, 0x00, 0x14,
// source MIHF_ID TLV:
0x5c, 0x84, 0x5c, 0x85, 0x5c, 0x86, 0x5c, 0x87 // value (nai-encoded)
};
BOOST_CHECK(equal( mihPacket.data().begin(), mihPacket.data().end(), data ));
- BOOST_CHECK_EQUAL(
- mihPacket->src_mihfId().asINet4Address(),
+ BOOST_CHECK_EQUAL(
+ mihPacket->src_mihfId().asINet4Address(),
INet4Address::from_string("128.129.130.131"));
- BOOST_CHECK_EQUAL(
- mihPacket->dst_mihfId().asINet4Address(),
+ BOOST_CHECK_EQUAL(
+ mihPacket->dst_mihfId().asINet4Address(),
INet4Address::from_string("132.133.134.135"));
}
mihPacket->src_mihfId().setINet6Address( INet6Address::from_string("::ffff:1.2.3.4"));
mihPacket->dst_mihfId().setINet6Address( INet6Address::from_string("::ffff:5.6.7.8"));
mihPacket.finalizeThis();
-
- unsigned char data[] = {
+
+ unsigned char data[] = {
// MIH header
0x10, 0x54, 0x00, 0x00, 0x00, 0x15, 0x00, 0x44,
// source MIHF_ID TLV:
0x5c, 0x05, 0x5c, 0x06, 0x5c, 0x07, 0x5c, 0x08
};
BOOST_CHECK(equal( mihPacket.data().begin(), mihPacket.data().end(), data ));
- BOOST_CHECK_EQUAL(
- mihPacket->src_mihfId().asINet6Address(),
+ BOOST_CHECK_EQUAL(
+ mihPacket->src_mihfId().asINet6Address(),
INet6Address::from_string("::ffff:1.2.3.4"));
- BOOST_CHECK_EQUAL(
- mihPacket->dst_mihfId().asINet6Address(),
+ BOOST_CHECK_EQUAL(
+ mihPacket->dst_mihfId().asINet6Address(),
INet6Address::from_string("::ffff:5.6.7.8") );
}
BOOST_AUTO_UNIT_TEST(MIHPayload_parse)
{
- unsigned char data[] = {
+ unsigned char data[] = {
// MIH header
- 0x10, 0x54, 0x00, 0x00, 0x00, 0x15,
+ 0x10, 0x54, 0x00, 0x00, 0x00, 0x15,
// variable payload length:
0x00, 0x2a,
// source MIHF_ID TLV:
0x01, 0x0f, // type, length
- 0x73, 0x65, 0x6e, 0x66, 0x40, 0x62, 0x65, 0x72, 0x6c,
+ 0x73, 0x65, 0x6e, 0x66, 0x40, 0x62, 0x65, 0x72, 0x6c,
0x69, 0x6f, 0x73, 0x2e, 0x64, 0x65, // value ("senf@berlios.de")
// destination MIHF_ID TLV:
0x02, 0x04, 0x74, 0x65, 0x73, 0x74, // type, length, value ("test")
0x05, // first bit not set, length=5
0x1a, 0x2b, 0x3c, 0x4d, 0x5e // value
};
-
+
MIHPacket mihPacket (MIHPacket::create(data));
BOOST_CHECK_EQUAL( mihPacket->payloadLength(), 42u);
-
+
BOOST_REQUIRE( mihPacket.next().is<MIHPayloadPacket>() );
MIHPayloadPacket mihPayload (mihPacket.next().as<MIHPayloadPacket>());
BOOST_CHECK_EQUAL( mihPayload->tlv_list().size(), 2u);
MIHPayloadPacketParser::tlv_list_t::container tlv_list_container (mihPayload->tlv_list());
-
+
GenericTLVPacket::Parser tlv1 = *tlv_list_container.begin();
BOOST_CHECK_EQUAL( tlv1.type(), 0x42);
BOOST_CHECK_EQUAL( tlv1.length(), 0x0au);
BOOST_CHECK_EQUAL( tlv1.value().size(), 0x0a);
-
+
GenericTLVPacket::Parser tlv2 = *boost::next(tlv_list_container.begin());
BOOST_CHECK_EQUAL( tlv2.type(), 0x43);
BOOST_CHECK_EQUAL( tlv2.length(), 0x05u);
- BOOST_CHECK_EQUAL( tlv2.value().size(), 0x05);
+ BOOST_CHECK_EQUAL( tlv2.value().size(), 0x05);
}
mihPacket->transactionId() = 21;
mihPacket->src_mihfId().setString( "senf@berlios.de");
mihPacket->dst_mihfId().setString( "test");
-
+
MIHPayloadPacket mihPayload (MIHPayloadPacket::createAfter(mihPacket));
-
- unsigned char tlv1_value[] = {
+
+ unsigned char tlv1_value[] = {
0x1a, 0x2b, 0x3c, 0x4d, 0x5e };
GenericTLVPacket tlv2 = (GenericTLVPacket::create());
tlv2->type() = 0x43;
tlv2->value( tlv1_value);
- tlv2.finalizeThis();
+ tlv2.finalizeThis();
mihPayload->tlv_list().push_front( tlv2.parser());
- unsigned char tlv2_value[] = {
+ unsigned char tlv2_value[] = {
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09 };
GenericTLVPacket tlv1 (GenericTLVPacket::create());
tlv1->type() = 0x42;
tlv1->value( tlv2_value);
tlv1.finalizeThis();
mihPayload->tlv_list().push_front( tlv1.parser());
-
+
mihPacket.finalizeAll();
-
- unsigned char data[] = {
+
+ unsigned char data[] = {
// MIH header
- 0x10, 0x54, 0x00, 0x00, 0x00, 0x15,
+ 0x10, 0x54, 0x00, 0x00, 0x00, 0x15,
// variable payload length:
0x00, 0x2a,
// source MIHF_ID TLV:
0x01, 0x0f, // type, length
- 0x73, 0x65, 0x6e, 0x66, 0x40, 0x62, 0x65, 0x72, 0x6c,
+ 0x73, 0x65, 0x6e, 0x66, 0x40, 0x62, 0x65, 0x72, 0x6c,
0x69, 0x6f, 0x73, 0x2e, 0x64, 0x65, // value ("senf@berlios.de")
// destination MIHF_ID TLV:
0x02, 0x04, 0x74, 0x65, 0x73, 0x74, // type, length, value ("test")
0x05, // first bit not set, length=5
0x1a, 0x2b, 0x3c, 0x4d, 0x5e // value
};
-
+
BOOST_CHECK(equal( mihPacket.data().begin(), mihPacket.data().end(), data ));
}
///////////////////////////////cc.e////////////////////////////////////////
#undef prefix_
-\f
+
// Local Variables:
// mode: c++
// fill-column: 100
// Custom includes
#include "TLVPacket.hh"
-#include <senf/Packets.hh>
#include "../DefaultBundle/EthernetPacket.hh"
-#include <senf/Utils/hexdump.hh>
#include "../../Utils/auto_unit_test.hh"
#include <boost/test/test_tools.hpp>
BOOST_AUTO_UNIT_TEST(GenericTLVPacket_parse_packet_with_simple_length)
{
- unsigned char data[] = {
+ unsigned char data[] = {
0x01, // type
0x0A, // first bit not set, length=10
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09 // value
BOOST_AUTO_UNIT_TEST(GenericTLVPacket_parse_packet_with_extended_length)
{
- unsigned char data[] = {
+ unsigned char data[] = {
0x01, // type
0x81, // first and last bit set => one byte length following
0x0A, // length (10 bytes value)
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09 // value
- };
+ };
GenericTLVPacket tlvPacket (GenericTLVPacket::create(data));
check_TLVPacket( tlvPacket, 0x01, 0x0Au );
}
BOOST_AUTO_UNIT_TEST(GenericTLVPacket_create_packet_with_simple_length)
{
- unsigned char value[] = {
+ unsigned char value[] = {
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09
};
GenericTLVPacket tlvPacket (GenericTLVPacket::create());
tlvPacket.finalizeThis();
check_TLVPacket( tlvPacket, 42u, 0x0Au );
-
- unsigned char data[] = {
+
+ unsigned char data[] = {
0x2a, // type
0x0A, // first bit not set, length=10
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09 // value
tlvPacket.finalizeThis();
check_TLVPacket( tlvPacket, 42u, sizeof(value) );
-
- unsigned char data[] = {
+
+ unsigned char data[] = {
0x2a, // type
0x81, // first and last bit set => one byte length following
0xff, // length (255 bytes value)
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09 // first bytes of value
};
- BOOST_CHECK( equal(
- tlvPacket.data().begin(),
+ BOOST_CHECK( equal(
+ tlvPacket.data().begin(),
boost::next( tlvPacket.data().begin(), sizeof(data)),
data ));
}
GenericTLVPacket tlvPacket (GenericTLVPacket::create());
tlvPacket->type() = 42u;
tlvPacket.finalizeThis();
-
+
unsigned char value[255];
for (unsigned i=0; i<sizeof(value); i++)
value[i] = i;
-
+
BOOST_CHECK_THROW( tlvPacket->value( value), TLVLengthException);
tlvPacket->maxLengthValue( sizeof(value));
tlvPacket->value( value);
struct TestMacAddressTLVPacketParser : public BaseTLVPacketParser
{
- # include SENF_PARSER()
+ # include SENF_PARSER()
SENF_PARSER_INHERIT ( BaseTLVPacketParser );
SENF_PARSER_VECTOR ( value, bytes(length), senf::MACAddressParser );
SENF_PARSER_FINALIZE( TestMacAddressTLVPacketParser );
};
-
+
struct TestMacAddressTLVPacketType
: public PacketTypeBase,
public PacketTypeMixin<TestMacAddressTLVPacketType>
using mixin::nextPacketRange;
using mixin::init;
using mixin::initSize;
-
- static void finalize(ConcretePacket<TestMacAddressTLVPacketType> p) {
+
+ static void finalize(ConcretePacket<TestMacAddressTLVPacketType> p) {
p->shrinkLength();
}
};
tlvPacket->value().push_back( senf::MACAddress::from_string("01:23:45:67:89:ab") );
tlvPacket->value().push_back( senf::MACAddress::from_string("cd:ef:01:23:45:67") );
tlvPacket.finalizeThis();
-
- unsigned char data[] = {
+
+ unsigned char data[] = {
0x2a, // type
0x0c, // length
0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef, 0x01, 0x23, 0x45, 0x67 // value
///////////////////////////////cc.e////////////////////////////////////////
#undef prefix_
-\f
+
// Local Variables:
// mode: c++
// fill-column: 100
BOOST_AUTO_UNIT_TEST(ethernetPacket_parse)
{
- senf::PacketData::byte data[] = {
+ senf::PacketData::byte data[] = {
0x01, 0x02, 0x03, 0x04, 0x05, 0x06, // destination MAC
0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, // source MAC
- 0x10, 0x11
+ 0x10, 0x11
}; // EtherType
senf::EthernetPacket p (senf::EthernetPacket::create(data));
BOOST_CHECK_EQUAL( p->destination()[3], 0x04 );
BOOST_CHECK_EQUAL( p->source()[0], 0x07 );
BOOST_CHECK_EQUAL( p->type_length(), 0x1011 );
+
+ std::ostringstream oss (std::ostringstream::out);
+ SENF_CHECK_NO_THROW( p.dump( oss));
}
BOOST_AUTO_UNIT_TEST(ethernetPacket_parse_chain)
0x81, 0x00, // EtherType: VLan
0x92, 0x34, // VLAN prio, cfi, id
0xab, 0xcd, // EtherType
- 0xf0, 0xf1, 0xf2, 0xf3, 0xf4
+ 0xf0, 0xf1, 0xf2, 0xf3, 0xf4
}; // Payload
senf::EthernetPacket p (senf::EthernetPacket::create(data));
senf::EthernetPacket eth (senf::EthernetPacket::create());
eth->source() = senf::MACAddress::from_string("01:02:03:04:05:06");
eth->destination() = senf::MACAddress::from_string("07:08:09:0a:0b:0c");
-
+
senf::EthVLanPacket vlan (senf::EthVLanPacket::createAfter(eth));
vlan->priority() = 9u;
vlan->cfi() = true;
senf::EthernetPacket eth (senf::EthernetPacket::create());
eth->source() = senf::MACAddress::from_string("01:02:03:04:05:06");
eth->destination() = senf::MACAddress::from_string("07:08:09:0a:0b:0c");
-
+
senf::LlcSnapPacket llcsnap (senf::LlcSnapPacket::createAfter(eth));
senf::DataPacket payload (senf::DataPacket::createAfter(
llcsnap, std::string("Hello, world!")));
eth.finalizeAll();
-
+
BOOST_CHECK_EQUAL( eth->type_length(), 8u + 13u);
BOOST_CHECK_EQUAL( llcsnap->dsap(), 0xaa );
BOOST_CHECK_EQUAL( llcsnap->ssap(), 0xaa );
///////////////////////////////cc.e////////////////////////////////////////
#undef prefix_
-\f
+
// Local Variables:
// mode: c++
// fill-column: 100
BOOST_AUTO_UNIT_TEST(ICMPv6Packet_packet)
{
- unsigned char data[] = {
+ unsigned char data[] = {
0x8f, 0x00, 0x8d, 0x54, 0x00, 0x00, 0x00, 0x01,
0x04, 0x00, 0x00, 0x00, 0xff, 0x15, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
};
senf::ICMPv6Packet p ( senf::ICMPv6Packet::create(data) );
-
+
BOOST_CHECK_EQUAL( p->type(), 0x8f );
BOOST_CHECK_EQUAL( p->code(), 0x00 );
BOOST_CHECK_EQUAL( p->checksum(), 0x8d54 );
BOOST_CHECK( p.next().is<senf::MLDv2ListenerReport>() );
BOOST_CHECK_EQUAL( p.next().size(), 24u );
+ std::ostringstream oss (std::ostringstream::out);
+ SENF_CHECK_NO_THROW( p.dump( oss));
}
BOOST_CHECK_EQUAL( p->checksum(), 0x0B0Cu );
BOOST_CHECK_EQUAL( p->source().value(), senf::INet4Address(0x11121314u) );
BOOST_CHECK_EQUAL( p->destination().value(), senf::INet4Address(0x15161718u) );
+
+ std::ostringstream oss (std::ostringstream::out);
+ SENF_CHECK_NO_THROW( p.dump( oss));
}
BOOST_AUTO_UNIT_TEST(ipV4Packet_create)
///////////////////////////////cc.e////////////////////////////////////////
#undef prefix_
-\f
+
// Local Variables:
// mode: c++
// fill-column: 100
BOOST_CHECK_EQUAL( p->nextHeader(), 44u );
BOOST_CHECK_EQUAL( p->source().value(), senf::INet6Address::from_string("2001::1") );
BOOST_CHECK_EQUAL( p->destination().value(), senf::INet6Address::from_string("2001::2") );
+
+ std::ostringstream oss (std::ostringstream::out);
+ SENF_CHECK_NO_THROW( p.dump( oss));
+
BOOST_CHECK( p.next().is<senf::IPv6Extension_Fragment>() );
senf::IPv6Extension_Fragment f (p.next().as<senf::IPv6Extension_Fragment>());
///////////////////////////////cc.e////////////////////////////////////////
#undef prefix_
-\f
+
// Local Variables:
// mode: c++
// fill-column: 100
BOOST_CHECK( p.next() );
BOOST_CHECK( p.next().is<senf::DataPacket>() );
BOOST_CHECK_EQUAL( p.next().size(), 1u );
+
+ std::ostringstream oss (std::ostringstream::out);
+ SENF_CHECK_NO_THROW( p.dump( oss));
}
///////////////////////////////cc.e////////////////////////////////////////
#undef prefix_
-\f
+
// Local Variables:
// mode: c++
// fill-column: 100
0xaa, // SSAP
0x03, // ctrl
0x00, 0x00, 0x00, // Protocol Identification Field
- 0x10, 0x11 // EtherType / Length
+ 0x10, 0x11 // EtherType / Length
};
senf::LlcSnapPacket p (senf::LlcSnapPacket::create(data));
BOOST_CHECK_EQUAL( p->ctrl(), 0x03 );
BOOST_CHECK_EQUAL( p->protocolId(), 0x000000u );
BOOST_CHECK_EQUAL( p->type_length(), 0x1011 );
+
+ std::ostringstream oss (std::ostringstream::out);
+ SENF_CHECK_NO_THROW( p.dump( oss));
}
BOOST_AUTO_UNIT_TEST(llcSnapPacket_ethernet)
senf::LlcSnapPacket llcsnap (senf::LlcSnapPacket::create());
senf::EthernetPacket eth (senf::EthernetPacket::createAfter(llcsnap));
senf::DataPacket payload (senf::DataPacket::createAfter(
- eth, std::string("Hello, world!")));
+ eth, std::string("Hello, world!")));
llcsnap.finalizeAll();
BOOST_CHECK_EQUAL( llcsnap->dsap(), 0xaa );
///////////////////////////////cc.e////////////////////////////////////////
#undef prefix_
-\f
+
// Local Variables:
// mode: c++
// fill-column: 100
BOOST_CHECK_EQUAL( p->seqNumber(), 0x1bbbu);
BOOST_CHECK_EQUAL( p->timeStamp(), 0x2cbad80u);
BOOST_CHECK_EQUAL( p->synSourceId(), 0x5048a78cu);
+
+ std::ostringstream oss (std::ostringstream::out);
+ SENF_CHECK_NO_THROW( p.dump( oss));
}
BOOST_CHECK_EQUAL( p->destination(), 0x0304 );
BOOST_CHECK_EQUAL( p->length(), 0x0506 );
BOOST_CHECK_EQUAL( p->checksum(), 0x0708 );
+
+ std::ostringstream oss (std::ostringstream::out);
+ SENF_CHECK_NO_THROW( p.dump( oss));
}
BOOST_AUTO_UNIT_TEST(udpPacket_create)
ip->destination() = senf::INet4Address::Loopback;
ip->df() = true;
ip->ttl() = 64;
-
+
senf::UDPPacket udp (senf::UDPPacket::createAfter(ip));
udp->source() = 23456;
udp->destination() = 12345;
-
+
senf::DataPacket::createAfter(udp,std::string("TEST-WRITE"));
// validates, since the checksum is 0 and thus ignored !
///////////////////////////////cc.e////////////////////////////////////////
#undef prefix_
-\f
+
// Local Variables:
// mode: c++
// fill-column: 100
#include "../../Packets/DefaultBundle/EthernetPacket.hh"
#include "../../Packets/DefaultBundle/IPv4Packet.hh"
#include <boost/test/test_tools.hpp>
-#include <senf/Utils/hexdump.hh>
#define prefix_
///////////////////////////////cc.p////////////////////////////////////////
BOOST_AUTO_UNIT_TEST(MPESection_parse_chain)
{
// MPE section captured with dvbsnoop
- unsigned char data[] = {
+ unsigned char data[] = {
// MPE Header
0x3e, 0xb0, 0x77, 0x00, 0x00, 0xc3, 0x00, 0x00,
0x04, 0xd8, 0x12, 0x0c,
0xaa, 0xaa, 0x03, 0x00, 0x00, 0x00, 0x00, 0x62,
// Ethernet Header
0x01, 0x00, 0x5e, 0x01, 0x02, 0x03, 0x12, 0xb0,
- 0x43, 0x61, 0x5d, 0x99, 0x08, 0x00,
+ 0x43, 0x61, 0x5d, 0x99, 0x08, 0x00,
// IPv4 Header
0x45, 0x00, 0x00, 0x54, 0x00, 0x00, 0x40, 0x00,
0x01, 0x01, 0xc6, 0xfb, 0xc0, 0xa8, 0x01, 0x01,
- 0xef, 0x01, 0x02, 0x03,
+ 0xef, 0x01, 0x02, 0x03,
// Payload (ICMP)
- 0x08, 0x00, 0x0e, 0xa3, 0xf2, 0x72, 0x55, 0xea,
- 0xa2, 0xae, 0x56, 0x47, 0xbb, 0x06, 0x02, 0x00,
+ 0x08, 0x00, 0x0e, 0xa3, 0xf2, 0x72, 0x55, 0xea,
+ 0xa2, 0xae, 0x56, 0x47, 0xbb, 0x06, 0x02, 0x00,
0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
- 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
- 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f,
- 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27,
- 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f,
+ 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
+ 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f,
+ 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27,
+ 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f,
0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
// MPE Trailer (crc)
0xb5, 0x77, 0x4c, 0x3c
};
-
+
senf::MPESection sec (senf::MPESection::create(data));
-
+
BOOST_CHECK_EQUAL( sec->table_id(), 0x3eu );
BOOST_CHECK( sec->section_syntax_indicator() );
BOOST_CHECK( ! sec->private_indicator() );
BOOST_CHECK_EQUAL( sec->real_time_parameters().address(), 0x120cu );
BOOST_CHECK_EQUAL( sec->crc(), 3044494396u );
BOOST_CHECK_EQUAL( sec->crc(), sec->calcCrc() );
-
+
+ std::ostringstream oss (std::ostringstream::out);
+ SENF_CHECK_NO_THROW( sec.dump( oss));
+
BOOST_REQUIRE( sec.next().is<senf::LlcSnapPacket>() );
senf::LlcSnapPacket llcsnap (sec.next().as<senf::LlcSnapPacket>());
BOOST_CHECK_EQUAL( llcsnap->ssap(), 0xaau );
BOOST_CHECK_EQUAL( llcsnap->ctrl(), 0x3u );
BOOST_CHECK_EQUAL( llcsnap->protocolId(), 0x0u );
- // in the captured section the llcsnap type/length field was set to the
+ // in the captured section the llcsnap type/length field was set to the
// length of the following ethernet packet; the ethertype 0x6558 (Trans
// Ether Bridging [RFC1701]) would be possible as well (see next test)
BOOST_CHECK_EQUAL( llcsnap->type_length(), 0x62u );
BOOST_REQUIRE( llcsnap.next().is<senf::EthernetPacket>() );
senf::EthernetPacket eth (llcsnap.next().as<senf::EthernetPacket>());
-
+
BOOST_CHECK_EQUAL( eth->destination().value(), senf::MACAddress::from_string("01:00:5e:01:02:03") );
BOOST_CHECK_EQUAL( eth->source().value(), senf::MACAddress::from_string("12:b0:43:61:5d:99") );
BOOST_CHECK_EQUAL( eth->type_length(), 0x800u );
BOOST_REQUIRE( eth.next().is<senf::IPv4Packet>() );
senf::IPv4Packet ip (eth.next().as<senf::IPv4Packet>());
-
+
BOOST_CHECK_EQUAL( ip->version(), 0x4u );
BOOST_CHECK_EQUAL( ip->ihl(), 0x5u );
BOOST_CHECK_EQUAL( ip->tos(), 0x0u );
sec->real_time_parameters().table_boundary() = 1;
sec->real_time_parameters().frame_boundary() = 0;
sec->real_time_parameters().address() = 0xfffffu;
-
+
// the type/length field will be set to the ethertype 0x6558 (Trans
- // Ether Bridging [RFC1701]) on finalize()
+ // Ether Bridging [RFC1701]) on finalize()
senf::LlcSnapPacket llcsnap (senf::LlcSnapPacket::createAfter(sec));
-
+
senf::EthernetPacket eth (senf::EthernetPacket::createAfter(llcsnap));
eth->destination() = senf::MACAddress::from_string("01:00:5e:01:02:03");
eth->source() = senf::MACAddress::from_string("92:4c:a2:1c:da:81");
-
+
senf::IPv4Packet ip (senf::IPv4Packet::createAfter(eth));
ip->df() = 1;
ip->ttl() = 1;
ip->protocol() = 1;
ip->source() = senf::INet4Address::from_string("10.1.2.2");
ip->destination() = senf::INet4Address::from_string("239.1.2.3");
-
- unsigned char payload_data[] = {
+
+ unsigned char payload_data[] = {
// Payload (ICMP)
0x08, 0x00, 0x52, 0x73, 0x0e, 0x02, 0x00, 0x20,
0xa4, 0x3a, 0xb4, 0x47, 0x4f, 0xe5, 0x04, 0x00,
0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37
};
senf::DataPacket payload (senf::DataPacket::createAfter(ip, payload_data));
-
+
sec.finalizeAll();
-
+
unsigned char sec_data[] = {
0x3e, 0xb0, 0x77, 0x00, 0x00, 0xc3, 0x00, 0x00,
0x02, 0x7b, 0xff, 0xff, 0xaa, 0xaa, 0x03, 0x00,
0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f, 0x30, 0x31,
0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x52, 0xdf,
0x6a, 0x1d
- };
+ };
BOOST_CHECK( equal( sec.data().begin(), sec.data().end(), sec_data ));
}
///////////////////////////////cc.e////////////////////////////////////////
#undef prefix_
-\f
+
// Local Variables:
// mode: c++
// fill-column: 100
#include "../../Utils/auto_unit_test.hh"
#include <boost/test/test_tools.hpp>
-#include <senf/Utils/hexdump.hh>
#define prefix_
///////////////////////////////cc.p////////////////////////////////////////
{
// TransportStream-Packet containing a ULE encoded IPv6 ping packet,
// captured with dvbsnoop
- unsigned char data[] = {
+ unsigned char data[] = {
// Transport Packet Header
- 0x47, 0x41, 0x0f, 0x1e,
+ 0x47, 0x41, 0x0f, 0x1e,
// Payload Pointer
- 0x00,
+ 0x00,
// SNDU Header
0x80, 0x4c, 0x86, 0xdd,
// IPv6 Packet
0x60, 0x00, 0x00, 0x00, 0x00, 0x20, 0x11, 0x40,
0xfe, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x48, 0x7c, 0x7e, 0xff, 0xfe, 0x23, 0x68, 0xaf,
- 0xff, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0xff, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x04,
0x02, 0x8c, 0x02, 0x8c, 0x00, 0x20, 0x58, 0xe1,
0x11, 0x05, 0x12, 0x67, 0x06, 0x2f, 0x01, 0x00,
0x20, 0x01, 0x06, 0x38, 0x04, 0x09, 0x10, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x11, 0x00,
// SNDU footer (crc-32)
- 0x1d, 0xc4, 0xe8, 0xc1,
+ 0x1d, 0xc4, 0xe8, 0xc1,
// Transport Packet stuffing
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff
};
-
+
TransportPacket p (TransportPacket::create(data));
BOOST_CHECK_EQUAL( p->sync_byte(), TransportPacketType::SYNC_BYTE+0 );
BOOST_CHECK_EQUAL( p->transport_scrmbl_ctrl(), 0x0u );
BOOST_CHECK_EQUAL( p->adaptation_field_ctrl(), 0x1u );
BOOST_CHECK_EQUAL( p->continuity_counter(), 0x0eu );
- BOOST_CHECK_EQUAL( p->pointer_field(), 0x0u );
+ BOOST_CHECK_EQUAL( p->pointer_field(), 0x0u );
+
+ std::ostringstream oss (std::ostringstream::out);
+ SENF_CHECK_NO_THROW( p.dump( oss));
}
ts_packet->setPUSI(true);
ts_packet->pid() = 0x010fu;
ts_packet->continuity_counter() = 0x0eu;
-
- unsigned char payload_data[] = { // see test above
+
+ unsigned char payload_data[] = { // see test above
// SNDU Header
0x80, 0x4c, 0x86, 0xdd,
// IPv6 Packet
0x60, 0x00, 0x00, 0x00, 0x00, 0x20, 0x11, 0x40,
0xfe, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x48, 0x7c, 0x7e, 0xff, 0xfe, 0x23, 0x68, 0xaf,
- 0xff, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0xff, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x04,
0x02, 0x8c, 0x02, 0x8c, 0x00, 0x20, 0x58, 0xe1,
0x11, 0x05, 0x12, 0x67, 0x06, 0x2f, 0x01, 0x00,
0x1d, 0xc4, 0xe8, 0xc1
};
senf::DataPacket payload (senf::DataPacket::createAfter( ts_packet, payload_data));
-
- //TransportPacketType::addStuffingPacketAfter( ts_packet);
-
- //senf::hexdump(ts_packet.data().begin(), ts_packet.data().end(), std::cout);
}
///////////////////////////////cc.e////////////////////////////////////////
#undef prefix_
-\f
+
// Local Variables:
// mode: c++
// fill-column: 100