2 // Fraunhofer Institut fuer offene Kommunikationssysteme (FOKUS)
3 // Kompetenzzentrum NETwork research (NET)
4 // David Wagner <david.wagner@fokus.fraunhofer.de>
9 #include "../../Packets/Packets.hh"
10 #include "../../Packets/DefaultBundle/IpV4Packet.hh"
11 #include "../../Packets/DefaultBundle/IpV6Packet.hh"
15 //first we have to define some helpers
16 struct DTCPIpV4AddressListParser : public PacketParserBase {
17 # include SENF_PARSER()
18 SENF_PARSER_PRIVATE_FIELD ( num_of_fbips, Parse_UInt8 );
19 SENF_PARSER_PRIVATE_FIELD ( reserved , Parse_UInt8 ); //must be zero
20 SENF_PARSER_VEC_N ( fbiplist, num_of_fbips, Parse_INet4Address );
22 SENF_PARSER_FINALIZE(DTCPIpV4AddressListParser);
25 struct DTCPIpV6AddressListParser : public PacketParserBase {
26 # include SENF_PARSER()
27 SENF_PARSER_PRIVATE_FIELD ( num_of_fbips, Parse_UInt8 );
28 SENF_PARSER_PRIVATE_FIELD ( reserved, Parse_UInt8 ); //must be zero
29 SENF_PARSER_VEC_N ( fbiplist, num_of_fbips, Parse_INet6Address );
31 SENF_PARSER_FINALIZE(DTCPIpV6AddressListParser);
34 /** \brief Parse a DTCP packet
36 Parser implementing the DTCP packet according to RFC 3077
40 struct Parse_DTCPPacket : public PacketParserBase
42 # include SENF_PARSER()
44 SENF_PARSER_BITFIELD ( version_number, 4, unsigned ); // =1 according to rfc3077
45 SENF_PARSER_BITFIELD ( command, 4, unsigned ); // 1=JOIN 2=LEAVE
46 SENF_PARSER_FIELD ( interval, Parse_UInt8 ); // 5 according to rfc3077
47 SENF_PARSER_FIELD ( sequence_number, Parse_UInt16 );
48 SENF_PARSER_PRIVATE_BITFIELD ( reserved, 3, unsigned );
49 SENF_PARSER_BITFIELD ( receive_capable_feed, 1, bool ); // 0=send only, 1=receive_capable_feed
50 SENF_PARSER_BITFIELD ( ip_version, 4, unsigned ); // 4=IPv4, 6=IPv6
51 SENF_PARSER_FIELD ( tunnel_protocol, Parse_UInt8 );
52 /* Please consider the following comments on the implementation given in this class:
53 * 1. you could think of simply using SENF_PARSER_PRIVATE_VARIANT and List / Vectorparser like this:
54 * SENF_PARSER_PRIVATE_VARIANT ( fbiplist, ip_version,
55 * (senf::VoidPacketParser) //ip_version=0
56 * (senf::VoidPacketParser) //1
57 * (senf::VoidPacketParser) //2
58 * (senf::VoidPacketParser) //3
59 * (senf::Parse_ListB< IpV4Packet, num_of_fbips>) //4
60 * (senf::VoidPacketParser) //5
61 * (senf::Parse_ListB< IpV6Packet, num_of_fbips>) ); //6
62 * This can't work for two reasons:
63 * -SENF_PARSER_PRIVATE_VARIANT only accepts 6 templates in types but you have to start from 0.
64 * -you NEVER can use templated Parsers in these macros since the macro-preprocessor won't recognize the <> brackets and will
67 * The first problem is solved by using (actually inventing) SENF_PARSER_VARIANT_TRANS which has the same limitations
68 * concerning the number of types but isn't limited to the values used. This is achieved by a translating function
70 * The second problem is solved by introducing Helper-Parser which cover both the list and the number field. By that no
71 * templates have to be used.
74 struct ip_version_translator {
75 static unsigned fromChooser(ip_version_t::value_type in) {
81 static ip_version_t::value_type toChooser(unsigned in) {
89 SENF_PARSER_VARIANT_TRANS ( fbiplist, ip_version, ip_version_translator,
90 (senf::DTCPIpV4AddressListParser) //IPv4
91 (senf::DTCPIpV6AddressListParser) ); //IPv6
93 SENF_PARSER_FINALIZE(Parse_DTCPPacket);
96 /** \brief DTCP packet
98 \par Packet type (typedef):
102 \ref Parse_DTCPPacket
104 \ingroup protocolbundle_mpegdvb
106 struct DTCPPacketType
107 : public PacketTypeBase,
108 public PacketTypeMixin<DTCPPacketType>
110 typedef PacketTypeMixin<DTCPPacketType> mixin;
111 typedef ConcretePacket<DTCPPacketType> packet;
112 typedef Parse_DTCPPacket parser;
114 using mixin::nextPacketRange;
116 using mixin::initSize;
118 static void dump(packet p, std::ostream & os);
121 /** \brief DTCP packet typedef */
122 typedef DTCPPacketType::packet DTCPPacket;
125 #endif /*DTCPPACKET_HH_*/