00001 // $Id: MPESection.cc 1742 2010-11-04 14:51:56Z g0dil $ 00002 // 00003 // Copyright (C) 2007 00004 // Fraunhofer (FOKUS) 00005 // Competence Center NETwork research (NET), St. Augustin, GERMANY 00006 // Thorsten Horstmann <tho@berlios.de> 00007 // 00008 // This program is free software; you can redistribute it and/or modify 00009 // it under the terms of the GNU General Public License as published by 00010 // the Free Software Foundation; either version 2 of the License, or 00011 // (at your option) any later version. 00012 // 00013 // This program is distributed in the hope that it will be useful, 00014 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00015 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00016 // GNU General Public License for more details. 00017 // 00018 // You should have received a copy of the GNU General Public License 00019 // along with this program; if not, write to the 00020 // Free Software Foundation, Inc., 00021 // 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 00022 00026 #include "MPESection.hh" 00027 //#include "MPESection.ih" 00028 00029 // Custom includes 00030 #include <iomanip> 00031 #include <boost/io/ios_state.hpp> 00032 #include <senf/Packets/DefaultBundle/LlcSnapPacket.hh> 00033 #include <senf/Packets/DefaultBundle/IPv4Packet.hh> 00034 #include <senf/Packets/DefaultBundle/IPv6Packet.hh> 00035 00036 #define prefix_ 00037 //-///////////////////////////////////////////////////////////////////////////////////////////////// 00038 00039 00040 prefix_ boost::uint32_t senf::MPESectionParser::calcCrc() 00041 const 00042 { 00043 return std::for_each( 00044 data().begin(), 00045 boost::prior(data().end(), 4), 00046 crc32_t() ).checksum(); 00047 } 00048 00049 00050 prefix_ void senf::MPESectionType::dump(packet p, std::ostream & os) 00051 { 00052 boost::io::ios_all_saver ias(os); 00053 os << "MPE Section:\n" 00054 << std::hex 00055 << senf::fieldName("table_id") << "0x" << unsigned(p->table_id()) << "\n" 00056 << senf::fieldName("section syntax indicator") << p->section_syntax_indicator() << "\n" 00057 << senf::fieldName("private indicator") << p->private_indicator() << "\n" 00058 << std::dec 00059 << senf::fieldName("section length") << p->section_length() << "\n" 00060 << std::hex 00061 << senf::fieldName("MAC address 6") << "0x" << unsigned(p->mac_addr_6()) << "\n" 00062 << senf::fieldName("MAC address 5") << "0x" << unsigned(p->mac_addr_5()) << "\n" 00063 << senf::fieldName("payload scrambling ctrl") << "0x" << p->payload_scrmbl_ctrl() << "\n" 00064 << senf::fieldName("address scrambling ctrl") << "0x" << p-> addr_scrmbl_ctrl() << "\n" 00065 << senf::fieldName("LLC/SNAP flag") << "0x" << p->llc_snap_flag() << "\n" 00066 << senf::fieldName("current next indicator") << "0x" << p->curr_next_indicator() << "\n" 00067 << senf::fieldName("section number") << "0x" << unsigned(p->section_num()) << "\n" 00068 << senf::fieldName("last section number") << "0x" << unsigned(p->last_section_num()) << "\n" 00069 << senf::fieldName("real time parameters") << "\n" 00070 << senf::fieldName(" delta_t") << "0x" << unsigned(p->real_time_parameters().delta_t()) << "\n" 00071 << senf::fieldName(" table boundary") << "0x" << unsigned(p->real_time_parameters().table_boundary()) << "\n" 00072 << senf::fieldName(" frame boundary") << "0x" << unsigned(p->real_time_parameters().frame_boundary()) << "\n" 00073 << senf::fieldName(" address") << "0x" << unsigned(p->real_time_parameters().address()) << "\n" 00074 << std::dec 00075 << senf::fieldName("crc") << unsigned(p->crc()) << "\n"; 00076 } 00077 00078 prefix_ senf::PacketParserBase::size_type senf::MPESectionType::initSize() 00079 { 00080 return parser::fixed_bytes + 32/8; 00081 } 00082 00083 prefix_ senf::PacketParserBase::size_type senf::MPESectionType::initHeadSize() 00084 { 00085 return parser::fixed_bytes; 00086 } 00087 00088 prefix_ senf::PacketInterpreterBase::factory_t senf::MPESectionType::nextPacketType(packet p) 00089 { 00090 if (p.data().size() > initSize()+1) { 00091 if (p->llc_snap_flag()) 00092 return LlcSnapPacket::factory(); 00093 if (p->ip_datagram_version().value() == 4) 00094 return IPv4Packet::factory(); 00095 if (p->ip_datagram_version().value() == 6) 00096 return IPv6Packet::factory(); 00097 } 00098 return no_factory(); 00099 } 00100 00101 prefix_ void senf::MPESectionType::finalize(packet p) 00102 { 00103 p->llc_snap_flag() = p.next(nothrow) && p.next().is<LlcSnapPacket>() ? 1 : 0; 00104 p->section_length() = p.data().size() - 3; 00105 p->crc() = p->calcCrc(); 00106 } 00107 00108 //-///////////////////////////////////////////////////////////////////////////////////////////////// 00109 #undef prefix_ 00110 00111 00112 // Local Variables: 00113 // mode: c++ 00114 // fill-column: 100 00115 // c-file-style: "senf" 00116 // indent-tabs-mode: nil 00117 // ispell-local-dictionary: "american" 00118 // compile-command: "scons -u test" 00119 // comment-column: 40 00120 // End: