dpdk: Add support for Mellanox ConnectX-4 devices
[vpp.git] / src / vnet / flow / ipfix_packet.h
1 /*
2  * Copyright (c) 2015 Cisco and/or its affiliates.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at:
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 #ifndef __included_ipfix_packet_h__
16 #define __included_ipfix_packet_h__
17
18 #include <vnet/flow/ipfix_info_elements.h>
19
20 /* From RFC-7011:
21  * https://tools.ietf.org/html/rfc7011
22  */
23
24 typedef struct {
25   u32 version_length;
26   u32 export_time;
27   u32 sequence_number;
28   u32 domain_id;
29 } ipfix_message_header_t;
30
31 static inline u32 version_length (u16 length)
32 {
33   return clib_host_to_net_u32 (0x000a0000 | length);
34 }
35
36
37 /*
38  *   The Field Specifier format is shown in Figure G.
39  *
40  *     0                   1                   2                   3
41  *     0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
42  *     +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
43  *     |E|  Information Element ident. |        Field Length           |
44  *     +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
45  *     |                      Enterprise Number                        |
46  *     +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
47  *
48  *                     Figure G: Field Specifier Format
49  *
50  *   Where:
51  *
52  *   E
53  *
54  *      Enterprise bit.  This is the first bit of the Field Specifier.  If
55  *      this bit is zero, the Information Element identifier identifies an
56  *      Information Element in [IANA-IPFIX], and the four-octet Enterprise
57  *      Number field MUST NOT be present.  If this bit is one, the
58  *      Information Element identifier identifies an enterprise-specific
59  *      Information Element, and the Enterprise Number field MUST be
60  *      present.
61  */
62
63 typedef struct {
64   u32 e_id_length;
65   u32 enterprise;
66 } ipfix_enterprise_field_specifier_t;
67
68 typedef struct {
69   u32 e_id_length;
70 } ipfix_field_specifier_t;
71
72 static inline u32 ipfix_e_id_length (int e, u16 id, u16 length)
73 {
74   u32 value;
75   value = (e<<31) | ((id&0x7FFF) <<16) | length;
76   return clib_host_to_net_u32 (value);
77 }
78
79 /* 
80  *   Every Set contains a common header.  This header is defined in
81  *   Figure I.
82  *
83  *      0                   1                   2                   3
84  *      0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
85  *     +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
86  *     |          Set ID               |          Length               |
87  *     +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
88  *
89  *                        Figure I: Set Header Format
90  *
91  *   Each Set Header field is exported in network format.  The fields are
92  *   defined as follows:
93  *
94  *   Set ID
95  *
96  *      Identifies the Set.  A value of 2 is reserved for Template Sets.
97  *      A value of 3 is reserved for Options Template Sets.  Values from 4
98  *      to 255 are reserved for future use.  Values 256 and above are used
99  *      for Data Sets.  The Set ID values of 0 and 1 are not used, for
100  *      historical reasons [RFC3954].
101  *
102  *   Length
103  *
104  *      Total length of the Set, in octets, including the Set Header, all
105  *      records, and the optional padding.  Because an individual Set MAY
106  *      contain multiple records, the Length value MUST be used to
107  *      determine the position of the next Set.
108  */
109
110 typedef struct {
111   u32 set_id_length;
112 } ipfix_set_header_t;
113
114 static inline u32 ipfix_set_id_length (u16 set_id, u16 length)
115 {
116   return clib_host_to_net_u32 ((set_id<<16) | length);
117 }
118
119 /* 
120  *   The format of the Template Record is shown in Figure J.  It consists
121  *   of a Template Record Header and one or more Field Specifiers.  Field
122  *   Specifiers are defined in Figure G above.
123  *
124  *           +--------------------------------------------------+
125  *           | Template Record Header                           |
126  *           +--------------------------------------------------+
127  *           | Field Specifier                                  |
128  *           +--------------------------------------------------+
129  *           | Field Specifier                                  |
130  *           +--------------------------------------------------+
131  *            ...
132  *           +--------------------------------------------------+
133  *           | Field Specifier                                  |
134  *           +--------------------------------------------------+
135  *
136  *                     Figure J: Template Record Format
137  *
138  *   The format of the Template Record Header is shown in Figure K.
139  *
140  *     0                   1                   2                   3
141  *     0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
142  *    +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
143  *    |      Template ID (> 255)      |         Field Count           |
144  *    +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
145  *
146  *                  Figure K: Template Record Header Format
147  *
148  *   The Template Record Header Field definitions are as follows:
149  *
150  *   Template ID
151  *
152  *      Each Template Record is given a unique Template ID in the range
153  *      256 to 65535.  This uniqueness is local to the Transport Session
154  *      and Observation Domain that generated the Template ID.  Since
155  *      Template IDs are used as Set IDs in the Sets they describe (see
156  *      Section 3.4.3), values 0-255 are reserved for special Set types
157  *      (e.g., Template Sets themselves), and Templates and Options
158  *      Templates (see Section 3.4.2) cannot share Template IDs within a
159  *      Transport Session and Observation Domain.  There are no
160  *      constraints regarding the order of the Template ID allocation.  As
161  *      Exporting Processes are free to allocate Template IDs as they see
162  *      fit, Collecting Processes MUST NOT assume incremental Template
163  *      IDs, or anything about the contents of a Template based on its
164  *      Template ID alone.
165  *
166  *   Field Count
167  *
168  *      Number of fields in this Template Record.
169  */
170
171 typedef struct {
172   u32 id_count;
173 } ipfix_template_header_t;
174
175 static inline u32 ipfix_id_count (u16 id, u16 count)
176 {
177   return clib_host_to_net_u32 ((id<<16) | count);
178 }
179
180 /* Template packet */
181 typedef struct {
182   ipfix_message_header_t h;
183   ipfix_set_header_t s;
184   ipfix_template_header_t t;
185   ipfix_field_specifier_t fields[0];
186 } ipfix_template_packet_t;
187
188 #endif /* __included_ipfix_packet_h__ */