Packets/DefaultBundle: added as<>() member to IPv6GenericOptionTLVParser
tho [Thu, 1 Oct 2009 09:29:27 +0000 (09:29 +0000)]
git-svn-id: https://svn.berlios.de/svnroot/repos/senf/trunk@1472 270642c3-0616-0410-b53a-bc976706d245

senf/Packets/DefaultBundle/IPv6ExtOptionType.ct
senf/Packets/DefaultBundle/IPv6ExtOptionType.hh
senf/Packets/DefaultBundle/IPv6Extensions.test.cc
senf/Packets/MPEGDVBBundle/SNDUPacket.cc

index c6fc9d2..ca43a48 100644 (file)
@@ -26,7 +26,6 @@
 //#include "IPv6ExtOptionType.ih"
 
 // Custom includes
-#include <senf/Utils/hexdump.hh>
 
 #define prefix_
 ///////////////////////////////ct.p////////////////////////////////////////
@@ -38,7 +37,8 @@ prefix_ void senf::IPv6GenericOptionTLVParser::value(ForwardReadableRange const
     
     if ( (rangeSize-2) != optionLength() )
         resize(optionLength()+2, rangeSize);
-    std::copy(boost::next(boost::begin(range), 2), boost::next(boost::end(range)), boost::next(i(), 2 + optionLength() ));
+    std::copy(boost::next(boost::begin(range), 2), boost::next(boost::end(range)), 
+            boost::next(i(), 2 + optionLength() ));
     unsigned int val = *(boost::begin(range));
     unsigned int mask = 192u;
     altAction() = (val & mask) >> 6;
@@ -59,7 +59,6 @@ prefix_ void senf::IPv6GenericOptionTLVParser::setPayload(ForwardReadableRange c
     optionLength() = rangeSize;
 }
 
-
 template <class Parser>
 prefix_ Parser senf::IPv6GenericOptionTLVParser::init()
 {  
@@ -73,13 +72,11 @@ prefix_ Parser senf::IPv6GenericOptionTLVParser::init()
     return concreteParser;
 }
 
-
-// template <class Parser>
-// prefix_ Parser& senf::GenericOptTypeTLVParser::get()
-// {
-//     SENF_ASSERT (optionType() == typeCode);
-//     return *(this);
-// }
+template <class Parser>
+prefix_ Parser senf::IPv6GenericOptionTLVParser::as()
+{
+    return Parser(i(), state() );
+}
 
 
 ///////////////////////////////ct.e////////////////////////////////////////
index b9b4a46..e992efd 100644 (file)
@@ -57,8 +57,8 @@ namespace senf {
         template <class Parser>
         Parser init();
 
-    //     template <class Parser>
-    //     Parser& get();
+        template <class Parser>
+        Parser as();
 
         static const unsigned int typeCode = 7u;
 
index 635fba2..a51d254 100644 (file)
@@ -223,6 +223,7 @@ BOOST_AUTO_UNIT_TEST(ipv6Extensions_hopByHop_parse)
     BOOST_CHECK_EQUAL( pICMPv6->checksum(), 0x50cc);
 }
 
+
 BOOST_AUTO_UNIT_TEST(ipv6Extensions_hopByHop_create)
 {
     std::ostringstream oss (std::ostringstream::out);
@@ -306,6 +307,7 @@ BOOST_AUTO_UNIT_TEST(ipv6Extensions_hopByHop_create)
             eth.data().begin(), eth.data().end() );
 }
 
+
 namespace {
     struct IPv6ChecksumOptionTLVParser : public senf::IPv6OptionTLVParser
     {
@@ -325,20 +327,12 @@ namespace {
     };
 }
 
-BOOST_AUTO_UNIT_TEST(ipv6Extensions_hopByHop_create_SN) {    
-    unsigned char data[] = { 
-            0x3a, 0x01,  // Hop-By-Hop Header (nextHeader, length) 
-            0x0d, 0x05,  // option type, length
-            // option value: slfNetType, checksum
-            0x01, 0x01, 0x23, 0x45, 0x67,
-            // padding (PadN option: type, length, 0-padding)
-            0x01, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00
-    };
-    
+BOOST_AUTO_UNIT_TEST(ipv6Extensions_hopByHop_create_SN)
+{    
     senf::IPv6HopByHopOptionsPacket p ( senf::IPv6HopByHopOptionsPacket::create() );
     p->nextHeader() = 0x3a;
     {
-        senf::IPv6HopByHopOptionsPacket::Parser::options_t::container optC(p->options() );
+        senf::IPv6HopByHopOptionsPacket::Parser::options_t::container optC (p->options() );
         {
             IPv6ChecksumOptionTLVParser opt ( 
                     optC.push_back_space().init<IPv6ChecksumOptionTLVParser>());
@@ -347,10 +341,43 @@ BOOST_AUTO_UNIT_TEST(ipv6Extensions_hopByHop_create_SN) {
         }
     }
 
+    unsigned char data[] = { 
+            0x3a, 0x01,  // Hop-By-Hop Header (nextHeader, length) 
+            0x0d, 0x05,  // option type, length
+            // option value: slfNetType, checksum
+            0x01, 0x01, 0x23, 0x45, 0x67,
+            // padding (PadN option: type, length, 0-padding)
+            0x01, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00
+    };
     SENF_CHECK_EQUAL_COLLECTIONS( data, data+sizeof(data),
                                  p.data().begin(), p.data().end() );    
 }
 
+
+BOOST_AUTO_UNIT_TEST(ipv6Extensions_hopByHop_parse_SN)
+{
+    unsigned char data[] = { 
+            0x3a, 0x01,  // Hop-By-Hop Header (nextHeader, length) 
+            0x0d, 0x05,  // option type, length
+            // option value: slfNetType, checksum
+            0x01, 0x01, 0x23, 0x45, 0x67,
+            // padding (PadN option: type, length, 0-padding)
+            0x01, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00
+    };
+    
+    senf::IPv6HopByHopOptionsPacket p ( senf::IPv6HopByHopOptionsPacket::create(data) );
+    BOOST_CHECK_EQUAL( p->nextHeader(), 0x3a);
+    
+    typedef senf::IPv6HopByHopOptionsPacket::Parser::options_t::container optContainer_t; 
+    optContainer_t optC (p->options() );
+    optContainer_t::iterator listIter (optC.begin());
+    
+    BOOST_CHECK_EQUAL( listIter->optionType(), 0x0d);
+    IPv6ChecksumOptionTLVParser opt ( listIter->as<IPv6ChecksumOptionTLVParser>());
+    BOOST_CHECK_EQUAL( opt.slfNetType(), 0x01);
+    BOOST_CHECK_EQUAL( opt.checksum(), 0x01234567);
+}
+
 ///////////////////////////////cc.e////////////////////////////////////////
 #undef prefix_
 
index c9e40ab..e6761b3 100644 (file)
@@ -28,7 +28,6 @@
 
 // Custom includes
 #include <iomanip>
-#include <senf/Utils/hexdump.hh>
 #include <senf/Packets/DefaultBundle/EthernetPacket.hh>
 
 
@@ -84,12 +83,12 @@ prefix_ void senf::SNDUPacketType::dump(packet p, std::ostream & os)
 {
     os << "SNDUPacket:\n"
        << std::dec
-       << senf::fieldName("d_bit")                     << p->d_bit() << "\n"
-       << senf::fieldName("length")                    << unsigned(p->length()) << "\n"
+       << senf::fieldName("d_bit")  << p->d_bit() << "\n"
+       << senf::fieldName("length") << unsigned(p->length()) << "\n"
        << std::hex
-       << senf::fieldName("type")                      << "0x" << unsigned(p->type()) << "\n"
+       << senf::fieldName("type")   << "0x" << unsigned(p->type()) << "\n"
        << std::dec
-       << senf::fieldName("crc")                       << unsigned(p->crc()) << "\n";
+       << senf::fieldName("crc")    << unsigned(p->crc()) << "\n";
 }
 
 prefix_ senf::PacketParserBase::size_type senf::SNDUPacketType::initSize()