From: tho Date: Fri, 16 Nov 2007 10:34:57 +0000 (+0000) Subject: added tests for LLC/SNAP X-Git-Url: http://g0dil.de/git?a=commitdiff_plain;h=edaa268609b73b4f48b28c5a7a577b6ffd4cec3b;p=senf.git added tests for LLC/SNAP git-svn-id: https://svn.berlios.de/svnroot/repos/senf/trunk@523 270642c3-0616-0410-b53a-bc976706d245 --- diff --git a/Packets/DefaultBundle/EthernetPacket.cc b/Packets/DefaultBundle/EthernetPacket.cc index eced314..5551342 100644 --- a/Packets/DefaultBundle/EthernetPacket.cc +++ b/Packets/DefaultBundle/EthernetPacket.cc @@ -100,14 +100,15 @@ prefix_ void senf::EthVLanPacketType::finalize(packet p) prefix_ void senf::EthLlcSnapPacketType::dump(packet p, std::ostream & os) { boost::io::ios_all_saver ias(os); - os << "Ethernet LLC/SNAP" + os << "Ethernet LLC/SNAP\n" + << std::hex << std::setfill('0') << " LLC\n" - << " DSAP: " << p->dsap() << "\n" - << " SSAP: " << p->ssap() << "\n" - << " SNAP\n" - << " ProtocolId: " << p->protocolId() << "\n" - << " type : 0x" - << std::hex << std::setw(4) << std::setfill('0') << p->type() << "\n"; + << " DSAP: 0x" << unsigned(p->dsap()) << "\n" + << " SSAP: 0x" << unsigned(p->ssap()) << "\n" + << " controlId: 0x" << unsigned(p->ctrl()) << "\n" + << " SNAP\n" + << " ProtocolId: 0x" << std::setw(6) << unsigned(p->protocolId()) << "\n" + << " type : 0x" << std::setw(4) << unsigned(p->type()) << "\n"; } prefix_ void senf::EthLlcSnapPacketType::finalize(packet p) diff --git a/Packets/DefaultBundle/EthernetPacket.hh b/Packets/DefaultBundle/EthernetPacket.hh index 3dcddc6..5b0856d 100644 --- a/Packets/DefaultBundle/EthernetPacket.hh +++ b/Packets/DefaultBundle/EthernetPacket.hh @@ -204,9 +204,16 @@ namespace senf { SENF_PARSER_FIELD( ctrl, Parse_UInt8 ); SENF_PARSER_FIELD( protocolId, Parse_UInt24 ); - SENF_PARSER_FIELD( type, Parse_UInt24 ); + SENF_PARSER_FIELD( type, Parse_UInt16 ); SENF_PARSER_FINALIZE(Parse_EthLlcSnapPacket); + + SENF_PARSER_INIT() { + dsap() = 0xaa; + ssap() = 0xaa; + ctrl() = 0x03; + protocolId() = 0x000000; + } }; /** \brief Ethernet LLC/SNAP header diff --git a/Packets/DefaultBundle/EthernetPacket.test.cc b/Packets/DefaultBundle/EthernetPacket.test.cc index 78d0ae9..f96049c 100644 --- a/Packets/DefaultBundle/EthernetPacket.test.cc +++ b/Packets/DefaultBundle/EthernetPacket.test.cc @@ -35,12 +35,13 @@ #define prefix_ ///////////////////////////////cc.p//////////////////////////////////////// -BOOST_AUTO_UNIT_TEST(ethernetPacket_packet) +BOOST_AUTO_UNIT_TEST(ethernetPacket_parse) { - senf::PacketData::byte data[] = - { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, // destination MAC - 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, // source MAC - 0x10, 0x11 }; // EtherType + senf::PacketData::byte data[] = { + 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, // destination MAC + 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, // source MAC + 0x10, 0x11 + }; // EtherType senf::EthernetPacket p (senf::EthernetPacket::create(data)); BOOST_CHECK_EQUAL( p->destination()[3], 0x04 ); @@ -48,15 +49,16 @@ BOOST_AUTO_UNIT_TEST(ethernetPacket_packet) BOOST_CHECK_EQUAL( p->type_length(), 0x1011 ); } -BOOST_AUTO_UNIT_TEST(ethernetPacket_chain) +BOOST_AUTO_UNIT_TEST(ethernetPacket_parse_chain) { - unsigned char data[] = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, // destination MAC - 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, // source MAC - 0x81, 0x00, // EtherType: VLan - 0x92, 0x34, // VLAN prio, cfi, id - 0xab, 0xcd, // EtherType - 0xf0, 0xf1, 0xf2, 0xf3, 0xf4 }; // Payload - + unsigned char data[] = { + 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, // destination MAC + 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, // source MAC + 0x81, 0x00, // EtherType: VLan + 0x92, 0x34, // VLAN prio, cfi, id + 0xab, 0xcd, // EtherType + 0xf0, 0xf1, 0xf2, 0xf3, 0xf4 + }; // Payload senf::EthernetPacket p (senf::EthernetPacket::create(data)); BOOST_REQUIRE( p.next().is() ); @@ -89,6 +91,47 @@ BOOST_AUTO_UNIT_TEST(ethernetPacket_create) BOOST_CHECK_EQUAL(vlan->type(), 0x0800u); } +BOOST_AUTO_UNIT_TEST(llcsnap_parse) +{ + senf::PacketData::byte data[] = { + 0xaa, // DSAP + 0xaa, // SSAP + 0x03, // ctrl + 0x00, 0x00, 0x00, // Protocol Identification Field + 0x10, 0x11 // EtherType + }; + senf::EthLlcSnapPacket p (senf::EthLlcSnapPacket::create(data)); + + BOOST_CHECK_EQUAL( p->dsap(), 0xaa ); + BOOST_CHECK_EQUAL( p->ssap(), 0xaa ); + BOOST_CHECK_EQUAL( p->ctrl(), 0x03 ); + BOOST_CHECK_EQUAL( p->protocolId(), 0x000000u ); + BOOST_CHECK_EQUAL( p->type(), 0x1011 ); +} + +BOOST_AUTO_UNIT_TEST(llcsnap_create) +{ + 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::EthLlcSnapPacket llcsnap (senf::EthLlcSnapPacket::createAfter(eth)); + senf::DataPacket payload (senf::DataPacket::createAfter( + llcsnap, std::string("Hello, world!"))); + eth.finalize(); + + BOOST_CHECK_EQUAL( eth->type_length(), 8u + 13u); + BOOST_CHECK_EQUAL( llcsnap->dsap(), 0xaa ); + BOOST_CHECK_EQUAL( llcsnap->ssap(), 0xaa ); + BOOST_CHECK_EQUAL( llcsnap->ctrl(), 0x03 ); + BOOST_CHECK_EQUAL( llcsnap->protocolId(), 0x000000u ); + BOOST_CHECK_EQUAL( llcsnap->type(), 0u); + + senf::IpV4Packet ip (senf::IpV4Packet::createAfter(llcsnap)); + eth.finalize(); + BOOST_CHECK_EQUAL(llcsnap->type(), 0x0800u); +} + ///////////////////////////////cc.e//////////////////////////////////////// #undef prefix_