2 * Copyright (c) 2012, 2013, 2014, 2015, 2016, 2017 Nicira, Inc.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at:
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
18 #include "ofproto-dpif-ipfix.h"
20 #include "byte-order.h"
21 #include "collectors.h"
24 #include "openvswitch/hmap.h"
26 #include "openvswitch/list.h"
27 #include "openvswitch/ofp-ipfix.h"
28 #include "openvswitch/ofpbuf.h"
30 #include "ofproto-dpif.h"
31 #include "dp-packet.h"
33 #include "openvswitch/poll-loop.h"
37 #include "openvswitch/vlog.h"
39 VLOG_DEFINE_THIS_MODULE(ipfix
);
41 static struct vlog_rate_limit rl
= VLOG_RATE_LIMIT_INIT(1, 5);
42 static struct ovs_mutex mutex
= OVS_MUTEX_INITIALIZER
;
44 /* This variable represents a number of exporters that have been created
45 * throughout OvS lifecycle. It's used to identify Exporting Process. Since
46 * it's NOT decreased when exporter is destroyed, it will eventually overflow.
47 * Considering the maximum value it can hold and the fact that Exporting
48 * Process may be re-started with a different ID, this shouldn't be a problem.
50 static uint32_t exporter_total_count
;
52 /* Cf. IETF RFC 5101 Section 10.3.4. */
53 #define IPFIX_DEFAULT_COLLECTOR_PORT 4739
55 /* Cf. IETF RFC 5881 Setion 8. */
56 #define BFD_CONTROL_DEST_PORT 3784
57 #define BFD_ECHO_DEST_PORT 3785
59 enum ipfix_sampled_packet_type
{
60 IPFIX_SAMPLED_PKT_UNKNOWN
= 0x00,
61 IPFIX_SAMPLED_PKT_IPV4_OK
= 0x01,
62 IPFIX_SAMPLED_PKT_IPV6_OK
= 0x02,
63 IPFIX_SAMPLED_PKT_IPV4_ERROR
= 0x03,
64 IPFIX_SAMPLED_PKT_IPV6_ERROR
= 0x04,
65 IPFIX_SAMPLED_PKT_OTHERS
= 0x05
68 /* The standard layer2SegmentId (ID 351) element is included in vDS to send
69 * the VxLAN tunnel's VNI. It is 64-bit long, the most significant byte is
70 * used to indicate the type of tunnel (0x01 = VxLAN, 0x02 = GRE) and the three
71 * least significant bytes hold the value of the layer 2 overlay network
72 * segment identifier: a 24-bit VxLAN tunnel's VNI or a 24-bit GRE tunnel's
73 * TNI. This is not compatible with STT, as implemented in OVS, as
74 * its tunnel IDs is 64-bit.
76 * Two new enterprise information elements are defined which are similar to
77 * laryerSegmentId but support 64-bit IDs:
78 * tunnelType (ID 891) and tunnelKey (ID 892).
80 * The enum dpif_ipfix_tunnel_type is to declare the types supported in the
82 * The number of ipfix tunnel types includes two reserverd types: 0x04 and 0x06.
84 enum dpif_ipfix_tunnel_type
{
85 DPIF_IPFIX_TUNNEL_UNKNOWN
= 0x00,
86 DPIF_IPFIX_TUNNEL_VXLAN
= 0x01,
87 DPIF_IPFIX_TUNNEL_GRE
= 0x02,
88 DPIF_IPFIX_TUNNEL_LISP
= 0x03,
89 DPIF_IPFIX_TUNNEL_STT
= 0x04,
90 DPIF_IPFIX_TUNNEL_GENEVE
= 0x07,
94 typedef struct ofputil_ipfix_stats ofproto_ipfix_stats
;
96 struct dpif_ipfix_global_stats
{
97 uint64_t dropped_packet_total_count
;
98 uint64_t dropped_octet_total_count
;
99 uint64_t packet_total_count
;
100 uint64_t octet_total_count
;
101 uint64_t octet_total_sum_of_squares
;
102 uint64_t layer2_octet_total_count
;
103 uint64_t tcp_ack_total_count
;
104 uint64_t tcp_fin_total_count
;
105 uint64_t tcp_psh_total_count
;
106 uint64_t tcp_rst_total_count
;
107 uint64_t tcp_syn_total_count
;
108 uint64_t tcp_urg_total_count
;
109 uint64_t post_mcast_packet_total_count
;
110 uint64_t post_mcast_octet_total_count
;
111 uint64_t in_ucast_packet_total_count
;
112 uint64_t in_mcast_packet_total_count
;
113 uint64_t in_bcast_packet_total_count
;
114 uint64_t out_ucast_packet_total_count
;
115 uint64_t out_bcast_packet_total_count
;
118 struct dpif_ipfix_port
{
119 struct hmap_node hmap_node
; /* In struct dpif_ipfix's "ports" hmap. */
120 struct ofport
*ofport
; /* To retrieve port stats. */
122 enum dpif_ipfix_tunnel_type tunnel_type
;
123 uint8_t tunnel_key_length
;
127 struct dpif_ipfix_exporter
{
128 uint32_t exporter_id
; /* Exporting Process identifier */
129 struct collectors
*collectors
;
131 time_t last_template_set_time
;
132 struct hmap cache_flow_key_map
; /* ipfix_flow_cache_entry. */
133 struct ovs_list cache_flow_start_timestamp_list
; /* ipfix_flow_cache_entry. */
134 uint32_t cache_active_timeout
; /* In seconds. */
135 uint32_t cache_max_flows
;
136 char *virtual_obs_id
;
137 uint8_t virtual_obs_len
;
139 ofproto_ipfix_stats ofproto_stats
;
140 struct dpif_ipfix_global_stats ipfix_global_stats
;
143 struct dpif_ipfix_bridge_exporter
{
144 struct dpif_ipfix_exporter exporter
;
145 struct ofproto_ipfix_bridge_exporter_options
*options
;
146 uint32_t probability
;
149 struct dpif_ipfix_flow_exporter
{
150 struct dpif_ipfix_exporter exporter
;
151 struct ofproto_ipfix_flow_exporter_options
*options
;
154 struct dpif_ipfix_flow_exporter_map_node
{
155 struct hmap_node node
;
156 struct dpif_ipfix_flow_exporter exporter
;
160 struct dpif_ipfix_bridge_exporter bridge_exporter
;
161 struct hmap flow_exporter_map
; /* dpif_ipfix_flow_exporter_map_node. */
162 struct hmap ports
; /* Contains "struct dpif_ipfix_port"s.
163 * It makes port lookups faster in sampling
165 struct ovs_refcount ref_cnt
;
168 #define IPFIX_VERSION 0x000a
170 /* When using UDP, IPFIX Template Records must be re-sent regularly.
171 * The standard default interval is 10 minutes (600 seconds).
172 * Cf. IETF RFC 5101 Section 10.3.6. */
173 #define IPFIX_TEMPLATE_INTERVAL 600
175 /* Cf. IETF RFC 5101 Section 3.1. */
177 struct ipfix_header
{
178 ovs_be16 version
; /* IPFIX_VERSION. */
179 ovs_be16 length
; /* Length in bytes including this header. */
180 ovs_be32 export_time
; /* Seconds since the epoch. */
181 ovs_be32 seq_number
; /* Message sequence number. */
182 ovs_be32 obs_domain_id
; /* Observation Domain ID. */
184 BUILD_ASSERT_DECL(sizeof(struct ipfix_header
) == 16);
186 #define IPFIX_SET_ID_TEMPLATE 2
187 #define IPFIX_SET_ID_OPTION_TEMPLATE 3
189 enum ipfix_options_template
{
190 IPFIX_OPTIONS_TEMPLATE_EXPORTER_STATS
= 0,
191 NUM_IPFIX_OPTIONS_TEMPLATE
194 /* Cf. IETF RFC 5101 Section 3.3.2. */
196 struct ipfix_set_header
{
197 ovs_be16 set_id
; /* IPFIX_SET_ID_* or valid template ID for Data Sets. */
198 ovs_be16 length
; /* Length of the set in bytes including header. */
200 BUILD_ASSERT_DECL(sizeof(struct ipfix_set_header
) == 4);
202 /* Alternatives for templates at each layer. A template is defined by
203 * a combination of one value for each layer. */
204 enum ipfix_proto_l2
{
205 IPFIX_PROTO_L2_ETH
= 0, /* No VLAN. */
209 enum ipfix_proto_l3
{
210 IPFIX_PROTO_L3_UNKNOWN
= 0,
215 enum ipfix_proto_l4
{
216 IPFIX_PROTO_L4_UNKNOWN
= 0,
223 enum ipfix_proto_tunnel
{
224 IPFIX_PROTO_NOT_TUNNELED
= 0,
225 IPFIX_PROTO_TUNNELED
, /* Support gre, lisp and vxlan. */
226 NUM_IPFIX_PROTO_TUNNEL
229 /* Any Template ID > 255 is usable for Template Records. */
230 #define IPFIX_TEMPLATE_ID_MIN 256
232 /* Cf. IETF RFC 5101 Section 3.4.1. */
234 struct ipfix_template_record_header
{
235 ovs_be16 template_id
;
236 ovs_be16 field_count
;
238 BUILD_ASSERT_DECL(sizeof(struct ipfix_template_record_header
) == 4);
240 /* Cf. IETF RFC 5101 Section 3.4.2.2. */
242 struct ipfix_options_template_record_header
{
243 ovs_be16 template_id
; /* Template ID of Data Set is within 256-65535
245 ovs_be16 field_count
; /* Number of all fields in this Options
246 * Template Record, including the Scope
248 ovs_be16 scope_field_count
; /* Number of scope fields. The number MUST BE
251 BUILD_ASSERT_DECL(sizeof(struct ipfix_options_template_record_header
) == 6);
254 enum ipfix_entity_id
{
255 /* standard IPFIX elements */
256 #define IPFIX_ENTITY(ENUM, ID, SIZE, NAME) IPFIX_ENTITY_ID_##ENUM = ID,
257 #include "ofproto/ipfix-entities.def"
258 /* non-standard IPFIX elements */
259 #define IPFIX_SET_ENTERPRISE(v) (((v) | 0x8000))
260 #define IPFIX_ENTERPRISE_ENTITY(ENUM, ID, SIZE, NAME, ENTERPRISE) \
261 IPFIX_ENTITY_ID_##ENUM = IPFIX_SET_ENTERPRISE(ID),
262 #include "ofproto/ipfix-enterprise-entities.def"
265 enum ipfix_entity_size
{
266 /* standard IPFIX elements */
267 #define IPFIX_ENTITY(ENUM, ID, SIZE, NAME) IPFIX_ENTITY_SIZE_##ENUM = SIZE,
268 #include "ofproto/ipfix-entities.def"
269 /* non-standard IPFIX elements */
270 #define IPFIX_ENTERPRISE_ENTITY(ENUM, ID, SIZE, NAME, ENTERPRISE) \
271 IPFIX_ENTITY_SIZE_##ENUM = SIZE,
272 #include "ofproto/ipfix-enterprise-entities.def"
275 enum ipfix_entity_enterprise
{
276 /* standard IPFIX elements */
277 #define IPFIX_ENTITY(ENUM, ID, SIZE, NAME) IPFIX_ENTITY_ENTERPRISE_##ENUM = 0,
278 #include "ofproto/ipfix-entities.def"
279 /* non-standard IPFIX elements */
280 #define IPFIX_ENTERPRISE_ENTITY(ENUM, ID, SIZE, NAME, ENTERPRISE) \
281 IPFIX_ENTITY_ENTERPRISE_##ENUM = ENTERPRISE,
282 #include "ofproto/ipfix-enterprise-entities.def"
286 struct ipfix_template_field_specifier
{
287 ovs_be16 element_id
; /* IPFIX_ENTITY_ID_*. */
288 ovs_be16 field_length
; /* Length of the field's value, in bytes.
289 * For Variable-Length element, it should be 65535.
291 ovs_be32 enterprise
; /* Enterprise number */
293 BUILD_ASSERT_DECL(sizeof(struct ipfix_template_field_specifier
) == 8);
295 /* Cf. IETF RFC 5102 Section 5.11.6. */
296 enum ipfix_flow_direction
{
299 NUM_IPFIX_FLOW_DIRECTION
302 /* Part of data record flow key for common metadata and Ethernet entities. */
304 struct ipfix_data_record_flow_key_common
{
305 ovs_be32 observation_point_id
; /* OBSERVATION_POINT_ID */
306 uint8_t flow_direction
; /* FLOW_DIRECTION */
307 struct eth_addr source_mac_address
; /* SOURCE_MAC_ADDRESS */
308 struct eth_addr destination_mac_address
; /* DESTINATION_MAC_ADDRESS */
309 ovs_be16 ethernet_type
; /* ETHERNET_TYPE */
310 uint8_t ethernet_header_length
; /* ETHERNET_HEADER_LENGTH */
312 BUILD_ASSERT_DECL(sizeof(struct ipfix_data_record_flow_key_common
) == 20);
314 /* Part of data record flow key for interface information. Since some of the
315 * elements have variable length, members of this structure should be appended
316 * to the 'struct dp_packet' one by one. */
318 struct ipfix_data_record_flow_key_iface
{
319 ovs_be32 if_index
; /* (INGRESS | EGRESS)_INTERFACE */
320 ovs_be32 if_type
; /* (INGRESS | EGRESS)_INTERFACE_TYPE */
321 uint8_t if_name_len
; /* Variable length element: INTERFACE_NAME */
323 uint8_t if_descr_len
; /* Variable length element: INTERFACE_DESCRIPTION */
326 BUILD_ASSERT_DECL(sizeof(struct ipfix_data_record_flow_key_iface
) ==
327 10 + 2 * sizeof(char *));
329 /* Part of data record flow key for VLAN entities. */
331 struct ipfix_data_record_flow_key_vlan
{
332 ovs_be16 vlan_id
; /* VLAN_ID */
333 ovs_be16 dot1q_vlan_id
; /* DOT1Q_VLAN_ID */
334 uint8_t dot1q_priority
; /* DOT1Q_PRIORITY */
336 BUILD_ASSERT_DECL(sizeof(struct ipfix_data_record_flow_key_vlan
) == 5);
338 /* Part of data record flow key for IP entities. */
339 /* XXX: Replace IP_TTL with MINIMUM_TTL and MAXIMUM_TTL? */
341 struct ipfix_data_record_flow_key_ip
{
342 uint8_t ip_version
; /* IP_VERSION */
343 uint8_t ip_ttl
; /* IP_TTL */
344 uint8_t protocol_identifier
; /* PROTOCOL_IDENTIFIER */
345 uint8_t ip_diff_serv_code_point
; /* IP_DIFF_SERV_CODE_POINT */
346 uint8_t ip_precedence
; /* IP_PRECEDENCE */
347 uint8_t ip_class_of_service
; /* IP_CLASS_OF_SERVICE */
349 BUILD_ASSERT_DECL(sizeof(struct ipfix_data_record_flow_key_ip
) == 6);
351 /* Part of data record flow key for IPv4 entities. */
353 struct ipfix_data_record_flow_key_ipv4
{
354 ovs_be32 source_ipv4_address
; /* SOURCE_IPV4_ADDRESS */
355 ovs_be32 destination_ipv4_address
; /* DESTINATION_IPV4_ADDRESS */
357 BUILD_ASSERT_DECL(sizeof(struct ipfix_data_record_flow_key_ipv4
) == 8);
359 /* Part of data record flow key for IPv6 entities. */
361 struct ipfix_data_record_flow_key_ipv6
{
362 uint8_t source_ipv6_address
[16]; /* SOURCE_IPV6_ADDRESS */
363 uint8_t destination_ipv6_address
[16]; /* DESTINATION_IPV6_ADDRESS */
364 ovs_be32 flow_label_ipv6
; /* FLOW_LABEL_IPV6 */
366 BUILD_ASSERT_DECL(sizeof(struct ipfix_data_record_flow_key_ipv6
) == 36);
368 /* Part of data record flow key for TCP/UDP/SCTP entities. */
370 struct ipfix_data_record_flow_key_transport
{
371 ovs_be16 source_transport_port
; /* SOURCE_TRANSPORT_PORT */
372 ovs_be16 destination_transport_port
; /* DESTINATION_TRANSPORT_PORT */
374 BUILD_ASSERT_DECL(sizeof(struct ipfix_data_record_flow_key_transport
) == 4);
376 /* Part of data record flow key for ICMP entities. */
378 struct ipfix_data_record_flow_key_icmp
{
379 uint8_t icmp_type
; /* ICMP_TYPE_IPV4 / ICMP_TYPE_IPV6 */
380 uint8_t icmp_code
; /* ICMP_CODE_IPV4 / ICMP_CODE_IPV6 */
382 BUILD_ASSERT_DECL(sizeof(struct ipfix_data_record_flow_key_icmp
) == 2);
384 static uint8_t tunnel_protocol
[NUM_DPIF_IPFIX_TUNNEL
] = {
386 IPPROTO_UDP
, /* DPIF_IPFIX_TUNNEL_VXLAN */
387 IPPROTO_GRE
, /* DPIF_IPFIX_TUNNEL_GRE */
388 IPPROTO_UDP
, /* DPIF_IPFIX_TUNNEL_LISP*/
389 IPPROTO_TCP
, /* DPIF_IPFIX_TUNNEL_STT*/
391 IPPROTO_UDP
, /* DPIF_IPFIX_TUNNEL_GENEVE*/
395 struct ipfix_data_record_flow_key_tunnel
{
396 ovs_be32 tunnel_source_ipv4_address
; /* TUNNEL_SOURCE_IPV4_ADDRESS */
397 ovs_be32 tunnel_destination_ipv4_address
; /* TUNNEL_DESTINATION_IPV4_ADDRESS */
398 uint8_t tunnel_protocol_identifier
; /* TUNNEL_PROTOCOL_IDENTIFIER */
399 ovs_be16 tunnel_source_transport_port
; /* TUNNEL_SOURCE_TRANSPORT_PORT */
400 ovs_be16 tunnel_destination_transport_port
; /* TUNNEL_DESTINATION_TRANSPORT_PORT */
401 uint8_t tunnel_type
; /* TUNNEL_TYPE */
402 uint8_t tunnel_key_length
; /* length of TUNNEL_KEY */
403 uint8_t tunnel_key
[]; /* data of TUNNEL_KEY */
405 BUILD_ASSERT_DECL(sizeof(struct ipfix_data_record_flow_key_tunnel
) == 15);
407 /* Cf. IETF RFC 5102 Section 5.11.3. */
408 enum ipfix_flow_end_reason
{
410 ACTIVE_TIMEOUT
= 0x02,
411 END_OF_FLOW_DETECTED
= 0x03,
413 LACK_OF_RESOURCES
= 0x05
416 /* Exporting Process Reliability Statistics data record. */
418 struct ipfix_data_record_exporter_stats
{
420 ovs_be32 exporting_process_id
; /* EXPORTING_PROCESS_ID */
423 ovs_be64 not_sent_packet_total_count
; /* NOT_SENT_PACKET_TOTAL_COUNT */
425 BUILD_ASSERT_DECL(sizeof(struct ipfix_data_record_exporter_stats
) == 12);
427 /* Part of data record for common aggregated elements. */
429 struct ipfix_data_record_aggregated_common
{
430 ovs_be32 flow_start_delta_microseconds
; /* FLOW_START_DELTA_MICROSECONDS */
431 ovs_be32 flow_end_delta_microseconds
; /* FLOW_END_DELTA_MICROSECONDS */
432 ovs_be64 dropped_packet_delta_count
; /* DROPPED_PACKET_DELTA_COUNT */
433 ovs_be64 dropped_packet_total_count
; /* DROPPED_PACKET_TOTAL_COUNT */
434 ovs_be64 packet_delta_count
; /* PACKET_DELTA_COUNT */
435 ovs_be64 packet_total_count
; /* PACKET_TOTAL_COUNT */
436 /* INGRESS_UNICAST_PACKET_TOTAL_COUNT */
437 ovs_be64 in_ucast_packet_total_count
;
438 /* INGRESS_MULTICAST_PACKET_TOTAL_COUNT */
439 ovs_be64 in_mcast_packet_total_count
;
440 /* INGRESS_BROADCAST_PACKET_TOTAL_COUNT */
441 ovs_be64 in_bcast_packet_total_count
;
442 /* EGRESS_UNICAST_PACKET_TOTAL_COUNT */
443 ovs_be64 out_ucast_packet_total_count
;
444 /* EGRESS_BROADCAST_PACKET_TOTAL_COUNT */
445 ovs_be64 out_bcast_packet_total_count
;
446 ovs_be64 post_mcast_packet_delta_count
; /* POST_MCAST_PACKET_DELTA_COUNT */
447 ovs_be64 post_mcast_packet_total_count
; /* POST_MCAST_PACKET_TOTAL_COUNT */
448 ovs_be64 layer2_octet_delta_count
; /* LAYER2_OCTET_DELTA_COUNT */
449 ovs_be64 layer2_octet_total_count
; /* LAYER2_OCTET_TOTAL_COUNT */
450 uint8_t flow_end_reason
; /* FLOW_END_REASON */
452 BUILD_ASSERT_DECL(sizeof(struct ipfix_data_record_aggregated_common
) == 113);
454 /* Part of data record for IP aggregated elements. */
456 struct ipfix_data_record_aggregated_ip
{
457 ovs_be64 dropped_octet_delta_count
; /* DROPPED_OCTET_DELTA_COUNT */
458 ovs_be64 dropped_octet_total_count
; /* DROPPED_OCTET_TOTAL_COUNT */
459 ovs_be64 octet_delta_count
; /* OCTET_DELTA_COUNT */
460 ovs_be64 octet_total_count
; /* OCTET_TOTAL_COUNT */
461 ovs_be64 octet_delta_sum_of_squares
; /* OCTET_DELTA_SUM_OF_SQUARES */
462 ovs_be64 octet_total_sum_of_squares
; /* OCTET_TOTAL_SUM_OF_SQUARES */
463 ovs_be64 minimum_ip_total_length
; /* MINIMUM_IP_TOTAL_LENGTH */
464 ovs_be64 maximum_ip_total_length
; /* MAXIMUM_IP_TOTAL_LENGTH */
465 ovs_be64 post_mcast_octet_delta_count
; /* POST_MCAST_OCTET_DELTA_COUNT */
466 ovs_be64 post_mcast_octet_total_count
; /* POST_MCAST_OCTET_TOTAL_COUNT */
468 BUILD_ASSERT_DECL(sizeof(struct ipfix_data_record_aggregated_ip
) == 80);
470 /* Part of data record for TCP aggregated elements. */
472 struct ipfix_data_record_aggregated_tcp
{
473 ovs_be64 tcp_ack_total_count
; /* TCP_ACK_TOTAL_COUNT */
474 ovs_be64 tcp_fin_total_count
; /* TCP_FIN_TOTAL_COUNT */
475 ovs_be64 tcp_psh_total_count
; /* TCP_PSH_TOTAL_COUNT */
476 ovs_be64 tcp_rst_total_count
; /* TCP_RST_TOTAL_COUNT */
477 ovs_be64 tcp_syn_total_count
; /* TCP_SYN_TOTAL_COUNT */
478 ovs_be64 tcp_urg_total_count
; /* TCP_URG_TOTAL_COUNT */
480 BUILD_ASSERT_DECL(sizeof(struct ipfix_data_record_aggregated_tcp
) == 48);
483 * Refer to RFC 7011, the length of Variable length element is 0~65535:
484 * In most case, it should be less than 255 octets:
486 * 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
487 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
488 * | Length (< 255)| Information Element |
489 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
490 * | ... continuing as needed |
491 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
493 * When it is greater than or equeal to 255 octets:
495 * 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
496 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
497 * | 255 | Length (0 to 65535) | IE |
498 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
499 * | ... continuing as needed |
500 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
503 * Now, only the virtual_obs_id whose length < 255 is implemented.
506 #define IPFIX_VIRTUAL_OBS_MAX_LEN 254
509 * support tunnel key for:
512 * LISP: 24-bit instance ID
515 #define MAX_TUNNEL_KEY_LEN 8
517 #define MAX_IF_NAME_LEN 64
518 #define MAX_IF_DESCR_LEN 128
521 * Calculate interface information length in flow key.
522 * This is used to calculate max flow key length.
524 #define FLOW_KEY_IFACE_LEN \
525 (sizeof(struct ipfix_data_record_flow_key_iface) \
526 - 2 * sizeof(char *) \
527 + MAX_IF_NAME_LEN + MAX_IF_DESCR_LEN)
529 #define MAX_FLOW_KEY_LEN \
530 (sizeof(struct ipfix_data_record_flow_key_common) \
531 + FLOW_KEY_IFACE_LEN \
532 + sizeof(struct ipfix_data_record_flow_key_vlan) \
533 + sizeof(struct ipfix_data_record_flow_key_ip) \
534 + MAX(sizeof(struct ipfix_data_record_flow_key_ipv4), \
535 sizeof(struct ipfix_data_record_flow_key_ipv6)) \
536 + MAX(sizeof(struct ipfix_data_record_flow_key_icmp), \
537 sizeof(struct ipfix_data_record_flow_key_transport)) \
538 + sizeof(struct ipfix_data_record_flow_key_tunnel) \
539 + MAX_TUNNEL_KEY_LEN)
541 #define MAX_DATA_RECORD_LEN \
543 + sizeof(struct ipfix_data_record_aggregated_common) \
544 + sizeof(struct ipfix_data_record_aggregated_ip) \
545 + sizeof(struct ipfix_data_record_aggregated_tcp))
547 #define MAX_OPTIONS_DATA_RECORD_LEN \
548 (sizeof(struct ipfix_data_record_exporter_stats))
551 /* Max length of a data set. To simplify the implementation, each
552 * data record is sent in a separate data set, so each data set
553 * contains at most one data record. */
554 #define MAX_DATA_SET_LEN \
555 (sizeof(struct ipfix_set_header) \
556 + MAX(MAX_DATA_RECORD_LEN, \
557 MAX_OPTIONS_DATA_RECORD_LEN))
559 /* Max length of an IPFIX message. Arbitrarily set to accommodate low
561 #define MAX_MESSAGE_LEN 1024
563 /* Cache structures. */
566 struct ipfix_flow_key
{
567 uint32_t obs_domain_id
;
568 uint16_t template_id
;
569 size_t flow_key_msg_part_size
;
570 uint64_t flow_key_msg_part
[DIV_ROUND_UP(MAX_FLOW_KEY_LEN
, 8)];
573 /* Flow cache entry. */
574 struct ipfix_flow_cache_entry
{
575 struct hmap_node flow_key_map_node
;
576 struct ovs_list cache_flow_start_timestamp_list_node
;
577 struct ipfix_flow_key flow_key
;
578 /* Common aggregated elements. */
579 uint64_t flow_start_timestamp_usec
;
580 uint64_t flow_end_timestamp_usec
;
581 uint64_t dropped_packet_delta_count
;
582 uint64_t dropped_packet_total_count
;
583 uint64_t packet_delta_count
;
584 uint64_t packet_total_count
;
585 uint64_t in_ucast_packet_total_count
;
586 uint64_t in_mcast_packet_total_count
;
587 uint64_t in_bcast_packet_total_count
;
588 uint64_t out_ucast_packet_total_count
;
589 uint64_t out_bcast_packet_total_count
;
590 uint64_t post_mcast_packet_total_count
;
591 uint64_t post_mcast_packet_delta_count
;
592 uint64_t post_mcast_octet_total_count
;
593 uint64_t post_mcast_octet_delta_count
;
594 uint64_t layer2_octet_delta_count
;
595 uint64_t layer2_octet_total_count
;
596 uint64_t dropped_octet_delta_count
;
597 uint64_t dropped_octet_total_count
;
598 uint64_t octet_delta_count
;
599 uint64_t octet_total_count
;
600 uint64_t octet_delta_sum_of_squares
; /* 0 if not IP. */
601 uint64_t octet_total_sum_of_squares
; /* 0 if not IP. */
602 uint16_t minimum_ip_total_length
; /* 0 if not IP. */
603 uint16_t maximum_ip_total_length
; /* 0 if not IP. */
604 uint64_t tcp_packet_delta_count
;
605 uint64_t tcp_ack_total_count
;
606 uint64_t tcp_fin_total_count
;
607 uint64_t tcp_psh_total_count
;
608 uint64_t tcp_rst_total_count
;
609 uint64_t tcp_syn_total_count
;
610 uint64_t tcp_urg_total_count
;
613 static void dpif_ipfix_cache_expire(struct dpif_ipfix_exporter
*, bool,
614 const uint64_t, const uint32_t);
616 static void get_export_time_now(uint64_t *, uint32_t *);
618 static void dpif_ipfix_cache_expire_now(struct dpif_ipfix_exporter
*, bool);
621 ofproto_ipfix_bridge_exporter_options_equal(
622 const struct ofproto_ipfix_bridge_exporter_options
*a
,
623 const struct ofproto_ipfix_bridge_exporter_options
*b
)
625 return (a
->obs_domain_id
== b
->obs_domain_id
626 && a
->obs_point_id
== b
->obs_point_id
627 && a
->sampling_rate
== b
->sampling_rate
628 && a
->cache_active_timeout
== b
->cache_active_timeout
629 && a
->cache_max_flows
== b
->cache_max_flows
630 && a
->enable_tunnel_sampling
== b
->enable_tunnel_sampling
631 && a
->enable_input_sampling
== b
->enable_input_sampling
632 && a
->enable_output_sampling
== b
->enable_output_sampling
633 && sset_equals(&a
->targets
, &b
->targets
)
634 && nullable_string_is_equal(a
->virtual_obs_id
, b
->virtual_obs_id
));
637 static struct ofproto_ipfix_bridge_exporter_options
*
638 ofproto_ipfix_bridge_exporter_options_clone(
639 const struct ofproto_ipfix_bridge_exporter_options
*old
)
641 struct ofproto_ipfix_bridge_exporter_options
*new =
642 xmemdup(old
, sizeof *old
);
643 sset_clone(&new->targets
, &old
->targets
);
644 new->virtual_obs_id
= nullable_xstrdup(old
->virtual_obs_id
);
649 ofproto_ipfix_bridge_exporter_options_destroy(
650 struct ofproto_ipfix_bridge_exporter_options
*options
)
653 sset_destroy(&options
->targets
);
654 free(options
->virtual_obs_id
);
660 ofproto_ipfix_flow_exporter_options_equal(
661 const struct ofproto_ipfix_flow_exporter_options
*a
,
662 const struct ofproto_ipfix_flow_exporter_options
*b
)
664 return (a
->collector_set_id
== b
->collector_set_id
665 && a
->cache_active_timeout
== b
->cache_active_timeout
666 && a
->cache_max_flows
== b
->cache_max_flows
667 && a
->enable_tunnel_sampling
== b
->enable_tunnel_sampling
668 && sset_equals(&a
->targets
, &b
->targets
)
669 && nullable_string_is_equal(a
->virtual_obs_id
, b
->virtual_obs_id
));
672 static struct ofproto_ipfix_flow_exporter_options
*
673 ofproto_ipfix_flow_exporter_options_clone(
674 const struct ofproto_ipfix_flow_exporter_options
*old
)
676 struct ofproto_ipfix_flow_exporter_options
*new =
677 xmemdup(old
, sizeof *old
);
678 sset_clone(&new->targets
, &old
->targets
);
679 new->virtual_obs_id
= nullable_xstrdup(old
->virtual_obs_id
);
684 ofproto_ipfix_flow_exporter_options_destroy(
685 struct ofproto_ipfix_flow_exporter_options
*options
)
688 sset_destroy(&options
->targets
);
689 free(options
->virtual_obs_id
);
695 dpif_ipfix_exporter_init(struct dpif_ipfix_exporter
*exporter
)
697 exporter
->exporter_id
= ++exporter_total_count
;
698 exporter
->collectors
= NULL
;
699 exporter
->seq_number
= 1;
700 exporter
->last_template_set_time
= 0;
701 hmap_init(&exporter
->cache_flow_key_map
);
702 ovs_list_init(&exporter
->cache_flow_start_timestamp_list
);
703 exporter
->cache_active_timeout
= 0;
704 exporter
->cache_max_flows
= 0;
705 exporter
->virtual_obs_id
= NULL
;
706 exporter
->virtual_obs_len
= 0;
708 memset(&exporter
->ipfix_global_stats
, 0,
709 sizeof(struct dpif_ipfix_global_stats
));
713 dpif_ipfix_exporter_clear(struct dpif_ipfix_exporter
*exporter
)
715 /* Flush the cache with flow end reason "forced end." */
716 dpif_ipfix_cache_expire_now(exporter
, true);
718 collectors_destroy(exporter
->collectors
);
719 exporter
->exporter_id
= 0;
720 exporter
->collectors
= NULL
;
721 exporter
->seq_number
= 1;
722 exporter
->last_template_set_time
= 0;
723 exporter
->cache_active_timeout
= 0;
724 exporter
->cache_max_flows
= 0;
725 free(exporter
->virtual_obs_id
);
726 exporter
->virtual_obs_id
= NULL
;
727 exporter
->virtual_obs_len
= 0;
729 memset(&exporter
->ipfix_global_stats
, 0,
730 sizeof(struct dpif_ipfix_global_stats
));
734 dpif_ipfix_exporter_destroy(struct dpif_ipfix_exporter
*exporter
)
736 dpif_ipfix_exporter_clear(exporter
);
737 hmap_destroy(&exporter
->cache_flow_key_map
);
741 dpif_ipfix_exporter_set_options(struct dpif_ipfix_exporter
*exporter
,
742 const struct sset
*targets
,
743 const uint32_t cache_active_timeout
,
744 const uint32_t cache_max_flows
,
745 const char *virtual_obs_id
)
747 size_t virtual_obs_len
;
748 collectors_destroy(exporter
->collectors
);
749 collectors_create(targets
, IPFIX_DEFAULT_COLLECTOR_PORT
,
750 &exporter
->collectors
);
751 if (exporter
->collectors
== NULL
) {
752 VLOG_WARN_RL(&rl
, "no collectors could be initialized, "
753 "IPFIX exporter disabled");
754 dpif_ipfix_exporter_clear(exporter
);
757 exporter
->cache_active_timeout
= cache_active_timeout
;
758 exporter
->cache_max_flows
= cache_max_flows
;
759 virtual_obs_len
= virtual_obs_id
? strlen(virtual_obs_id
) : 0;
760 if (virtual_obs_len
> IPFIX_VIRTUAL_OBS_MAX_LEN
) {
761 VLOG_WARN_RL(&rl
, "Virtual obsevation ID too long (%d bytes), "
762 "should not be longer than %d bytes.",
763 exporter
->virtual_obs_len
, IPFIX_VIRTUAL_OBS_MAX_LEN
);
764 dpif_ipfix_exporter_clear(exporter
);
767 exporter
->virtual_obs_len
= virtual_obs_len
;
768 exporter
->virtual_obs_id
= nullable_xstrdup(virtual_obs_id
);
772 static struct dpif_ipfix_port
*
773 dpif_ipfix_find_port(const struct dpif_ipfix
*di
,
774 odp_port_t odp_port
) OVS_REQUIRES(mutex
)
776 struct dpif_ipfix_port
*dip
;
778 HMAP_FOR_EACH_IN_BUCKET (dip
, hmap_node
, hash_odp_port(odp_port
),
780 if (dip
->odp_port
== odp_port
) {
788 dpif_ipfix_del_port__(struct dpif_ipfix
*di
,
789 struct dpif_ipfix_port
*dip
)
792 hmap_remove(&di
->ports
, &dip
->hmap_node
);
796 static enum dpif_ipfix_tunnel_type
797 dpif_ipfix_tunnel_type(const struct ofport
*ofport
)
799 const char *type
= netdev_get_type(ofport
->netdev
);
802 return DPIF_IPFIX_TUNNEL_UNKNOWN
;
804 if (strcmp(type
, "gre") == 0) {
805 return DPIF_IPFIX_TUNNEL_GRE
;
806 } else if (strcmp(type
, "vxlan") == 0) {
807 return DPIF_IPFIX_TUNNEL_VXLAN
;
808 } else if (strcmp(type
, "lisp") == 0) {
809 return DPIF_IPFIX_TUNNEL_LISP
;
810 } else if (strcmp(type
, "geneve") == 0) {
811 return DPIF_IPFIX_TUNNEL_GENEVE
;
812 } else if (strcmp(type
, "stt") == 0) {
813 return DPIF_IPFIX_TUNNEL_STT
;
816 return DPIF_IPFIX_TUNNEL_UNKNOWN
;
820 dpif_ipfix_tunnel_key_length(enum dpif_ipfix_tunnel_type tunnel_type
)
823 switch (tunnel_type
) {
824 case DPIF_IPFIX_TUNNEL_GRE
:
827 case DPIF_IPFIX_TUNNEL_VXLAN
:
828 case DPIF_IPFIX_TUNNEL_LISP
:
829 case DPIF_IPFIX_TUNNEL_GENEVE
:
831 case DPIF_IPFIX_TUNNEL_STT
:
833 case DPIF_IPFIX_TUNNEL_UNKNOWN
:
834 case NUM_DPIF_IPFIX_TUNNEL
:
841 dpif_ipfix_add_port(struct dpif_ipfix
*di
, struct ofport
*ofport
,
842 odp_port_t odp_port
) OVS_EXCLUDED(mutex
)
844 struct dpif_ipfix_port
*dip
;
847 ovs_mutex_lock(&mutex
);
848 dip
= dpif_ipfix_find_port(di
, odp_port
);
850 dpif_ipfix_del_port__(di
, dip
);
853 ifindex
= netdev_get_ifindex(ofport
->netdev
);
858 /* Add to table of ports. */
859 dip
= xmalloc(sizeof *dip
);
860 dip
->ofport
= ofport
;
861 dip
->odp_port
= odp_port
;
862 dip
->tunnel_type
= dpif_ipfix_tunnel_type(ofport
);
863 dip
->tunnel_key_length
= dpif_ipfix_tunnel_key_length(dip
->tunnel_type
);
864 dip
->ifindex
= ifindex
;
865 hmap_insert(&di
->ports
, &dip
->hmap_node
, hash_odp_port(odp_port
));
867 ovs_mutex_unlock(&mutex
);
871 dpif_ipfix_del_port(struct dpif_ipfix
*di
, odp_port_t odp_port
)
874 struct dpif_ipfix_port
*dip
;
875 ovs_mutex_lock(&mutex
);
876 dip
= dpif_ipfix_find_port(di
, odp_port
);
878 dpif_ipfix_del_port__(di
, dip
);
880 ovs_mutex_unlock(&mutex
);
883 static struct dpif_ipfix_port
*
884 dpif_ipfix_find_tunnel_port(const struct dpif_ipfix
*di
, odp_port_t odp_port
)
887 struct dpif_ipfix_port
*dip
= dpif_ipfix_find_port(di
, odp_port
);
888 return (dip
&& dip
->tunnel_type
!= DPIF_IPFIX_TUNNEL_UNKNOWN
) ? dip
: NULL
;
892 dpif_ipfix_is_tunnel_port(const struct dpif_ipfix
*di
, odp_port_t odp_port
)
895 struct dpif_ipfix_port
*dip
;
896 ovs_mutex_lock(&mutex
);
897 dip
= dpif_ipfix_find_tunnel_port(di
, odp_port
);
898 ovs_mutex_unlock(&mutex
);
903 dpif_ipfix_bridge_exporter_init(struct dpif_ipfix_bridge_exporter
*exporter
)
905 dpif_ipfix_exporter_init(&exporter
->exporter
);
906 exporter
->options
= NULL
;
907 exporter
->probability
= 0;
911 dpif_ipfix_bridge_exporter_clear(struct dpif_ipfix_bridge_exporter
*exporter
)
913 dpif_ipfix_exporter_clear(&exporter
->exporter
);
914 ofproto_ipfix_bridge_exporter_options_destroy(exporter
->options
);
915 exporter
->options
= NULL
;
916 exporter
->probability
= 0;
920 dpif_ipfix_bridge_exporter_destroy(struct dpif_ipfix_bridge_exporter
*exporter
)
922 dpif_ipfix_bridge_exporter_clear(exporter
);
923 dpif_ipfix_exporter_destroy(&exporter
->exporter
);
927 dpif_ipfix_bridge_exporter_set_options(
928 struct dpif_ipfix_bridge_exporter
*exporter
,
929 const struct ofproto_ipfix_bridge_exporter_options
*options
)
931 bool options_changed
;
933 if (!options
|| sset_is_empty(&options
->targets
)) {
934 /* No point in doing any work if there are no targets. */
935 dpif_ipfix_bridge_exporter_clear(exporter
);
941 || !ofproto_ipfix_bridge_exporter_options_equal(
942 options
, exporter
->options
));
944 /* Configure collectors if options have changed or if we're
945 * shortchanged in collectors (which indicates that opening one or
946 * more of the configured collectors failed, so that we should
949 || collectors_count(exporter
->exporter
.collectors
)
950 < sset_count(&options
->targets
)) {
951 if (!dpif_ipfix_exporter_set_options(
952 &exporter
->exporter
, &options
->targets
,
953 options
->cache_active_timeout
, options
->cache_max_flows
,
954 options
->virtual_obs_id
)) {
959 /* Avoid reconfiguring if options didn't change. */
960 if (!options_changed
) {
964 ofproto_ipfix_bridge_exporter_options_destroy(exporter
->options
);
965 exporter
->options
= ofproto_ipfix_bridge_exporter_options_clone(options
);
966 exporter
->probability
=
967 MAX(1, UINT32_MAX
/ exporter
->options
->sampling_rate
);
969 /* Run over the cache as some entries might have expired after
970 * changing the timeouts. */
971 dpif_ipfix_cache_expire_now(&exporter
->exporter
, false);
974 static struct dpif_ipfix_flow_exporter_map_node
*
975 dpif_ipfix_find_flow_exporter_map_node(
976 const struct dpif_ipfix
*di
, const uint32_t collector_set_id
)
979 struct dpif_ipfix_flow_exporter_map_node
*exporter_node
;
981 HMAP_FOR_EACH_WITH_HASH (exporter_node
, node
,
982 hash_int(collector_set_id
, 0),
983 &di
->flow_exporter_map
) {
984 if (exporter_node
->exporter
.options
->collector_set_id
985 == collector_set_id
) {
986 return exporter_node
;
994 dpif_ipfix_flow_exporter_init(struct dpif_ipfix_flow_exporter
*exporter
)
996 dpif_ipfix_exporter_init(&exporter
->exporter
);
997 exporter
->options
= NULL
;
1001 dpif_ipfix_flow_exporter_clear(struct dpif_ipfix_flow_exporter
*exporter
)
1003 dpif_ipfix_exporter_clear(&exporter
->exporter
);
1004 ofproto_ipfix_flow_exporter_options_destroy(exporter
->options
);
1005 exporter
->options
= NULL
;
1009 dpif_ipfix_flow_exporter_destroy(struct dpif_ipfix_flow_exporter
*exporter
)
1011 dpif_ipfix_flow_exporter_clear(exporter
);
1012 dpif_ipfix_exporter_destroy(&exporter
->exporter
);
1016 dpif_ipfix_flow_exporter_set_options(
1017 struct dpif_ipfix_flow_exporter
*exporter
,
1018 const struct ofproto_ipfix_flow_exporter_options
*options
)
1020 bool options_changed
;
1022 if (sset_is_empty(&options
->targets
)) {
1023 /* No point in doing any work if there are no targets. */
1024 dpif_ipfix_flow_exporter_clear(exporter
);
1030 || !ofproto_ipfix_flow_exporter_options_equal(
1031 options
, exporter
->options
));
1033 /* Configure collectors if options have changed or if we're
1034 * shortchanged in collectors (which indicates that opening one or
1035 * more of the configured collectors failed, so that we should
1038 || collectors_count(exporter
->exporter
.collectors
)
1039 < sset_count(&options
->targets
)) {
1040 if (!dpif_ipfix_exporter_set_options(
1041 &exporter
->exporter
, &options
->targets
,
1042 options
->cache_active_timeout
, options
->cache_max_flows
,
1043 options
->virtual_obs_id
)) {
1048 /* Avoid reconfiguring if options didn't change. */
1049 if (!options_changed
) {
1053 ofproto_ipfix_flow_exporter_options_destroy(exporter
->options
);
1054 exporter
->options
= ofproto_ipfix_flow_exporter_options_clone(options
);
1056 /* Run over the cache as some entries might have expired after
1057 * changing the timeouts. */
1058 dpif_ipfix_cache_expire_now(&exporter
->exporter
, false);
1064 remove_flow_exporter(struct dpif_ipfix
*di
,
1065 struct dpif_ipfix_flow_exporter_map_node
*node
)
1067 hmap_remove(&di
->flow_exporter_map
, &node
->node
);
1068 dpif_ipfix_flow_exporter_destroy(&node
->exporter
);
1073 dpif_ipfix_set_options(
1074 struct dpif_ipfix
*di
,
1075 const struct ofproto_ipfix_bridge_exporter_options
*bridge_exporter_options
,
1076 const struct ofproto_ipfix_flow_exporter_options
*flow_exporters_options
,
1077 size_t n_flow_exporters_options
) OVS_EXCLUDED(mutex
)
1080 struct ofproto_ipfix_flow_exporter_options
*options
;
1081 struct dpif_ipfix_flow_exporter_map_node
*node
, *next
;
1083 ovs_mutex_lock(&mutex
);
1084 dpif_ipfix_bridge_exporter_set_options(&di
->bridge_exporter
,
1085 bridge_exporter_options
);
1087 /* Add new flow exporters and update current flow exporters. */
1088 options
= (struct ofproto_ipfix_flow_exporter_options
*)
1089 flow_exporters_options
;
1090 for (i
= 0; i
< n_flow_exporters_options
; i
++) {
1091 node
= dpif_ipfix_find_flow_exporter_map_node(
1092 di
, options
->collector_set_id
);
1094 node
= xzalloc(sizeof *node
);
1095 dpif_ipfix_flow_exporter_init(&node
->exporter
);
1096 hmap_insert(&di
->flow_exporter_map
, &node
->node
,
1097 hash_int(options
->collector_set_id
, 0));
1099 if (!dpif_ipfix_flow_exporter_set_options(&node
->exporter
, options
)) {
1100 remove_flow_exporter(di
, node
);
1105 /* Remove dropped flow exporters, if any needs to be removed. */
1106 HMAP_FOR_EACH_SAFE (node
, next
, node
, &di
->flow_exporter_map
) {
1107 /* This is slow but doesn't take any extra memory, and
1108 * this table is not supposed to contain many rows anyway. */
1109 options
= (struct ofproto_ipfix_flow_exporter_options
*)
1110 flow_exporters_options
;
1111 for (i
= 0; i
< n_flow_exporters_options
; i
++) {
1112 if (node
->exporter
.options
->collector_set_id
1113 == options
->collector_set_id
) {
1118 if (i
== n_flow_exporters_options
) { /* Not found. */
1119 remove_flow_exporter(di
, node
);
1123 ovs_mutex_unlock(&mutex
);
1127 dpif_ipfix_create(void)
1129 struct dpif_ipfix
*di
;
1130 di
= xzalloc(sizeof *di
);
1131 dpif_ipfix_bridge_exporter_init(&di
->bridge_exporter
);
1132 hmap_init(&di
->flow_exporter_map
);
1133 hmap_init(&di
->ports
);
1134 ovs_refcount_init(&di
->ref_cnt
);
1139 dpif_ipfix_ref(const struct dpif_ipfix
*di_
)
1141 struct dpif_ipfix
*di
= CONST_CAST(struct dpif_ipfix
*, di_
);
1143 ovs_refcount_ref(&di
->ref_cnt
);
1149 dpif_ipfix_get_bridge_exporter_probability(const struct dpif_ipfix
*di
)
1153 ovs_mutex_lock(&mutex
);
1154 ret
= di
->bridge_exporter
.probability
;
1155 ovs_mutex_unlock(&mutex
);
1160 dpif_ipfix_get_bridge_exporter_input_sampling(const struct dpif_ipfix
*di
)
1164 ovs_mutex_lock(&mutex
);
1165 if (di
->bridge_exporter
.options
) {
1166 ret
= di
->bridge_exporter
.options
->enable_input_sampling
;
1168 ovs_mutex_unlock(&mutex
);
1173 dpif_ipfix_get_bridge_exporter_output_sampling(const struct dpif_ipfix
*di
)
1177 ovs_mutex_lock(&mutex
);
1178 if (di
->bridge_exporter
.options
) {
1179 ret
= di
->bridge_exporter
.options
->enable_output_sampling
;
1181 ovs_mutex_unlock(&mutex
);
1186 dpif_ipfix_get_bridge_exporter_tunnel_sampling(const struct dpif_ipfix
*di
)
1190 ovs_mutex_lock(&mutex
);
1191 if (di
->bridge_exporter
.options
) {
1192 ret
= di
->bridge_exporter
.options
->enable_tunnel_sampling
;
1194 ovs_mutex_unlock(&mutex
);
1199 dpif_ipfix_get_flow_exporter_tunnel_sampling(const struct dpif_ipfix
*di
,
1200 const uint32_t collector_set_id
)
1203 ovs_mutex_lock(&mutex
);
1204 struct dpif_ipfix_flow_exporter_map_node
*node
1205 = dpif_ipfix_find_flow_exporter_map_node(di
, collector_set_id
);
1207 && node
->exporter
.options
1208 && node
->exporter
.options
->enable_tunnel_sampling
);
1209 ovs_mutex_unlock(&mutex
);
1215 dpif_ipfix_clear(struct dpif_ipfix
*di
) OVS_REQUIRES(mutex
)
1217 struct dpif_ipfix_flow_exporter_map_node
*exp_node
;
1218 struct dpif_ipfix_port
*dip
, *next
;
1220 dpif_ipfix_bridge_exporter_clear(&di
->bridge_exporter
);
1222 HMAP_FOR_EACH_POP (exp_node
, node
, &di
->flow_exporter_map
) {
1223 dpif_ipfix_flow_exporter_destroy(&exp_node
->exporter
);
1227 HMAP_FOR_EACH_SAFE (dip
, next
, hmap_node
, &di
->ports
) {
1228 dpif_ipfix_del_port__(di
, dip
);
1233 dpif_ipfix_unref(struct dpif_ipfix
*di
) OVS_EXCLUDED(mutex
)
1235 if (di
&& ovs_refcount_unref_relaxed(&di
->ref_cnt
) == 1) {
1236 ovs_mutex_lock(&mutex
);
1237 dpif_ipfix_clear(di
);
1238 dpif_ipfix_bridge_exporter_destroy(&di
->bridge_exporter
);
1239 hmap_destroy(&di
->flow_exporter_map
);
1240 hmap_destroy(&di
->ports
);
1242 ovs_mutex_unlock(&mutex
);
1247 ipfix_init_header(uint32_t export_time_sec
, uint32_t seq_number
,
1248 uint32_t obs_domain_id
, struct dp_packet
*msg
)
1250 struct ipfix_header
*hdr
;
1252 hdr
= dp_packet_put_zeros(msg
, sizeof *hdr
);
1253 hdr
->version
= htons(IPFIX_VERSION
);
1254 hdr
->length
= htons(sizeof *hdr
); /* Updated in ipfix_send_msg. */
1255 hdr
->export_time
= htonl(export_time_sec
);
1256 hdr
->seq_number
= htonl(seq_number
);
1257 hdr
->obs_domain_id
= htonl(obs_domain_id
);
1261 ipfix_send_msg(const struct collectors
*collectors
, struct dp_packet
*msg
)
1263 struct ipfix_header
*hdr
;
1266 /* Adjust the length in the header. */
1267 hdr
= dp_packet_data(msg
);
1268 hdr
->length
= htons(dp_packet_size(msg
));
1270 tx_errors
= collectors_send(collectors
,
1271 dp_packet_data(msg
), dp_packet_size(msg
));
1272 dp_packet_set_size(msg
, 0);
1278 ipfix_get_template_id(enum ipfix_proto_l2 l2
, enum ipfix_proto_l3 l3
,
1279 enum ipfix_proto_l4 l4
, enum ipfix_proto_tunnel tunnel
,
1280 enum ipfix_flow_direction flow_direction
)
1282 uint16_t template_id
;
1284 template_id
= template_id
* NUM_IPFIX_PROTO_L3
+ l3
;
1285 template_id
= template_id
* NUM_IPFIX_PROTO_L4
+ l4
;
1286 template_id
= template_id
* NUM_IPFIX_PROTO_TUNNEL
+ tunnel
;
1287 template_id
= template_id
* NUM_IPFIX_FLOW_DIRECTION
+ flow_direction
;
1288 return IPFIX_TEMPLATE_ID_MIN
+ template_id
;
1292 ipfix_get_options_template_id(enum ipfix_options_template opt_tmpl_type
)
1294 /* Check what is the maximum possible Template ID for Template Record and
1295 * use it as a base number for Template ID in Options Template Record. */
1296 uint16_t max_tmpl_id
= ipfix_get_template_id(NUM_IPFIX_PROTO_L2
,
1299 NUM_IPFIX_PROTO_TUNNEL
,
1300 NUM_IPFIX_FLOW_DIRECTION
);
1302 return max_tmpl_id
+ opt_tmpl_type
;
1307 ipfix_define_template_entity(enum ipfix_entity_id id
,
1308 enum ipfix_entity_size size
,
1309 enum ipfix_entity_enterprise enterprise
,
1310 struct dp_packet
*msg
)
1312 struct ipfix_template_field_specifier
*field
;
1316 field_size
= sizeof *field
;
1318 /* No enterprise number */
1319 field_size
= sizeof *field
- sizeof(ovs_be32
);
1321 field
= dp_packet_put_zeros(msg
, field_size
);
1322 field
->element_id
= htons(id
);
1324 field
->field_length
= htons(size
);
1326 /* RFC 5101, Section 7. Variable-Length Information Element */
1327 field
->field_length
= OVS_BE16_MAX
;
1330 field
->enterprise
= htonl(enterprise
);
1337 ipfix_define_template_entity(IPFIX_ENTITY_ID_##ID, \
1338 IPFIX_ENTITY_SIZE_##ID, \
1339 IPFIX_ENTITY_ENTERPRISE_##ID, msg); \
1343 /* Defines The Exporting Process Reliability Statistics Options Template
1344 * fields, including scope fields. Updates 'scope_field_count' and
1345 * 'field_count' in Options Template Record Header. */
1347 ipfix_def_exporter_options_template_fields(size_t opt_tmpl_hdr_offset
,
1348 struct dp_packet
*msg
)
1351 struct ipfix_options_template_record_header
*opt_tmpl_hdr
;
1353 /* 1. Scope Fields Specifiers */
1354 DEF(EXPORTING_PROCESS_ID
);
1356 /* Update 'scope_field_count' in options template header. */
1357 opt_tmpl_hdr
= (struct ipfix_options_template_record_header
*)
1358 ((uint8_t *)dp_packet_data(msg
) + opt_tmpl_hdr_offset
);
1359 opt_tmpl_hdr
->scope_field_count
= htons(count
);
1361 /* 2. Fields Specifiers */
1362 DEF(NOT_SENT_PACKET_TOTAL_COUNT
);
1364 /* Update 'field_count' in options template header. */
1365 opt_tmpl_hdr
= (struct ipfix_options_template_record_header
*)
1366 ((uint8_t *)dp_packet_data(msg
) + opt_tmpl_hdr_offset
);
1367 opt_tmpl_hdr
->field_count
= htons(count
);
1373 ipfix_def_options_template_fields(enum ipfix_options_template opt_tmpl_type
,
1374 size_t opt_tmpl_hdr_offset
,
1375 struct dp_packet
*msg
)
1377 switch (opt_tmpl_type
) {
1378 case IPFIX_OPTIONS_TEMPLATE_EXPORTER_STATS
:
1379 return ipfix_def_exporter_options_template_fields(opt_tmpl_hdr_offset
,
1382 case NUM_IPFIX_OPTIONS_TEMPLATE
:
1390 /* Defines fields in Template Record. Updates 'field_count' in Template Record
1393 ipfix_define_template_fields(enum ipfix_proto_l2 l2
, enum ipfix_proto_l3 l3
,
1394 enum ipfix_proto_l4 l4
, enum ipfix_proto_tunnel tunnel
,
1395 enum ipfix_flow_direction flow_direction
,
1396 bool virtual_obs_id_set
,
1397 size_t tmpl_hdr_offset
,
1398 struct dp_packet
*msg
)
1401 struct ipfix_template_record_header
*tmpl_hdr
;
1406 DEF(OBSERVATION_POINT_ID
);
1407 DEF(FLOW_DIRECTION
);
1409 /* Common Ethernet entities. */
1410 DEF(SOURCE_MAC_ADDRESS
);
1411 DEF(DESTINATION_MAC_ADDRESS
);
1413 DEF(ETHERNET_HEADER_LENGTH
);
1415 /* Interface Information Elements */
1416 DEF(INGRESS_INTERFACE
);
1417 DEF(INGRESS_INTERFACE_TYPE
);
1418 DEF(INTERFACE_NAME
);
1419 DEF(INTERFACE_DESCRIPTION
);
1421 if (flow_direction
== EGRESS_FLOW
) {
1422 DEF(EGRESS_INTERFACE
);
1423 DEF(EGRESS_INTERFACE_TYPE
);
1424 DEF(INTERFACE_NAME
);
1425 DEF(INTERFACE_DESCRIPTION
);
1428 if (l2
== IPFIX_PROTO_L2_VLAN
) {
1431 DEF(DOT1Q_PRIORITY
);
1434 if (l3
!= IPFIX_PROTO_L3_UNKNOWN
) {
1437 DEF(PROTOCOL_IDENTIFIER
);
1438 DEF(IP_DIFF_SERV_CODE_POINT
);
1440 DEF(IP_CLASS_OF_SERVICE
);
1442 if (l3
== IPFIX_PROTO_L3_IPV4
) {
1443 DEF(SOURCE_IPV4_ADDRESS
);
1444 DEF(DESTINATION_IPV4_ADDRESS
);
1445 if (l4
== IPFIX_PROTO_L4_TCP
1446 || l4
== IPFIX_PROTO_L4_UDP
1447 || l4
== IPFIX_PROTO_L4_SCTP
) {
1448 DEF(SOURCE_TRANSPORT_PORT
);
1449 DEF(DESTINATION_TRANSPORT_PORT
);
1450 } else if (l4
== IPFIX_PROTO_L4_ICMP
) {
1451 DEF(ICMP_TYPE_IPV4
);
1452 DEF(ICMP_CODE_IPV4
);
1454 } else { /* l3 == IPFIX_PROTO_L3_IPV6 */
1455 DEF(SOURCE_IPV6_ADDRESS
);
1456 DEF(DESTINATION_IPV6_ADDRESS
);
1457 DEF(FLOW_LABEL_IPV6
);
1458 if (l4
== IPFIX_PROTO_L4_TCP
1459 || l4
== IPFIX_PROTO_L4_UDP
1460 || l4
== IPFIX_PROTO_L4_SCTP
) {
1461 DEF(SOURCE_TRANSPORT_PORT
);
1462 DEF(DESTINATION_TRANSPORT_PORT
);
1463 } else if (l4
== IPFIX_PROTO_L4_ICMP
) {
1464 DEF(ICMP_TYPE_IPV6
);
1465 DEF(ICMP_CODE_IPV6
);
1470 if (tunnel
!= IPFIX_PROTO_NOT_TUNNELED
) {
1471 DEF(TUNNEL_SOURCE_IPV4_ADDRESS
);
1472 DEF(TUNNEL_DESTINATION_IPV4_ADDRESS
);
1473 DEF(TUNNEL_PROTOCOL_IDENTIFIER
);
1474 DEF(TUNNEL_SOURCE_TRANSPORT_PORT
);
1475 DEF(TUNNEL_DESTINATION_TRANSPORT_PORT
);
1480 /* 2. Virtual observation ID, which is not a part of flow key. */
1481 if (virtual_obs_id_set
) {
1482 DEF(VIRTUAL_OBS_ID
);
1485 /* 3. Flow aggregated data. */
1487 DEF(FLOW_START_DELTA_MICROSECONDS
);
1488 DEF(FLOW_END_DELTA_MICROSECONDS
);
1489 DEF(DROPPED_PACKET_DELTA_COUNT
);
1490 DEF(DROPPED_PACKET_TOTAL_COUNT
);
1491 DEF(PACKET_DELTA_COUNT
);
1492 DEF(PACKET_TOTAL_COUNT
);
1493 DEF(INGRESS_UNICAST_PACKET_TOTAL_COUNT
);
1494 DEF(INGRESS_MULTICAST_PACKET_TOTAL_COUNT
);
1495 DEF(INGRESS_BROADCAST_PACKET_TOTAL_COUNT
);
1496 DEF(EGRESS_UNICAST_PACKET_TOTAL_COUNT
);
1497 DEF(EGRESS_BROADCAST_PACKET_TOTAL_COUNT
);
1498 DEF(POST_MCAST_PACKET_DELTA_COUNT
);
1499 DEF(POST_MCAST_PACKET_TOTAL_COUNT
);
1500 DEF(LAYER2_OCTET_DELTA_COUNT
);
1501 DEF(LAYER2_OCTET_TOTAL_COUNT
);
1502 DEF(FLOW_END_REASON
);
1504 if (l3
!= IPFIX_PROTO_L3_UNKNOWN
) {
1505 DEF(DROPPED_OCTET_DELTA_COUNT
);
1506 DEF(DROPPED_OCTET_TOTAL_COUNT
);
1507 DEF(OCTET_DELTA_COUNT
);
1508 DEF(OCTET_TOTAL_COUNT
);
1509 DEF(OCTET_DELTA_SUM_OF_SQUARES
);
1510 DEF(OCTET_TOTAL_SUM_OF_SQUARES
);
1511 DEF(MINIMUM_IP_TOTAL_LENGTH
);
1512 DEF(MAXIMUM_IP_TOTAL_LENGTH
);
1513 DEF(POST_MCAST_OCTET_DELTA_COUNT
);
1514 DEF(POST_MCAST_OCTET_TOTAL_COUNT
);
1517 if (l4
== IPFIX_PROTO_L4_TCP
) {
1518 DEF(TCP_ACK_TOTAL_COUNT
);
1519 DEF(TCP_FIN_TOTAL_COUNT
);
1520 DEF(TCP_PSH_TOTAL_COUNT
);
1521 DEF(TCP_RST_TOTAL_COUNT
);
1522 DEF(TCP_SYN_TOTAL_COUNT
);
1523 DEF(TCP_URG_TOTAL_COUNT
);
1526 /* Update 'field_count' in template header. */
1527 tmpl_hdr
= (struct ipfix_template_record_header
*)
1528 ((uint8_t *)dp_packet_data(msg
) + tmpl_hdr_offset
);
1529 tmpl_hdr
->field_count
= htons(count
);
1537 ipfix_init_template_msg(uint32_t export_time_sec
,
1538 uint32_t seq_number
, uint32_t obs_domain_id
,
1539 uint16_t set_id
, struct dp_packet
*msg
,
1540 size_t *set_hdr_offset
)
1542 struct ipfix_set_header
*set_hdr
;
1544 dp_packet_clear(msg
);
1546 ipfix_init_header(export_time_sec
, seq_number
, obs_domain_id
, msg
);
1547 *set_hdr_offset
= dp_packet_size(msg
);
1549 /* Add a Set Header. */
1550 set_hdr
= dp_packet_put_zeros(msg
, sizeof *set_hdr
);
1551 set_hdr
->set_id
= htons(set_id
);
1555 ipfix_send_template_msg(const struct collectors
*collectors
,
1556 struct dp_packet
*msg
, size_t set_hdr_offset
)
1558 struct ipfix_set_header
*set_hdr
;
1561 /* Send template message. */
1562 set_hdr
= (struct ipfix_set_header
*)
1563 ((uint8_t*)dp_packet_data(msg
) + set_hdr_offset
);
1564 set_hdr
->length
= htons(dp_packet_size(msg
) - set_hdr_offset
);
1566 tx_errors
= ipfix_send_msg(collectors
, msg
);
1572 ipfix_add_options_template_record(enum ipfix_options_template opt_tmpl_type
,
1573 struct dp_packet
*msg
)
1575 struct ipfix_options_template_record_header
*opt_tmpl_hdr
;
1576 size_t opt_tmpl_hdr_offset
;
1578 opt_tmpl_hdr_offset
= dp_packet_size(msg
);
1579 opt_tmpl_hdr
= dp_packet_put_zeros(msg
, sizeof *opt_tmpl_hdr
);
1580 opt_tmpl_hdr
->template_id
=
1581 htons(ipfix_get_options_template_id(opt_tmpl_type
));
1582 ipfix_def_options_template_fields(opt_tmpl_type
, opt_tmpl_hdr_offset
, msg
);
1586 ipfix_send_options_template_msgs(struct dpif_ipfix_exporter
*exporter
,
1587 uint32_t export_time_sec
,
1588 uint32_t obs_domain_id
,
1589 struct dp_packet
*msg
)
1591 size_t set_hdr_offset
;
1592 size_t tx_packets
= 0;
1593 size_t tx_errors
= 0, error_pkts
;
1594 enum ipfix_options_template opt_tmpl_type
;
1596 ipfix_init_template_msg(export_time_sec
, exporter
->seq_number
,
1597 obs_domain_id
, IPFIX_SET_ID_OPTION_TEMPLATE
, msg
,
1600 for (opt_tmpl_type
= 0; opt_tmpl_type
< NUM_IPFIX_OPTIONS_TEMPLATE
;
1602 if (dp_packet_size(msg
) >= MAX_MESSAGE_LEN
) {
1603 /* Send template message. */
1604 error_pkts
= ipfix_send_template_msg(exporter
->collectors
, msg
,
1606 tx_errors
+= error_pkts
;
1607 tx_packets
+= collectors_count(exporter
->collectors
) - error_pkts
;
1609 /* Reinitialize the template msg. */
1610 ipfix_init_template_msg(export_time_sec
, exporter
->seq_number
,
1612 IPFIX_SET_ID_OPTION_TEMPLATE
,
1617 ipfix_add_options_template_record(opt_tmpl_type
, msg
);
1620 error_pkts
= ipfix_send_template_msg(exporter
->collectors
, msg
,
1622 tx_errors
+= error_pkts
;
1623 tx_packets
+= collectors_count(exporter
->collectors
) - error_pkts
;
1624 exporter
->ofproto_stats
.tx_pkts
+= tx_packets
;
1625 exporter
->ofproto_stats
.tx_errors
+= tx_errors
;
1629 ipfix_add_template_record(enum ipfix_proto_l2 l2
, enum ipfix_proto_l3 l3
,
1630 enum ipfix_proto_l4 l4
,
1631 enum ipfix_proto_tunnel tunnel
,
1632 enum ipfix_flow_direction flow_direction
,
1633 bool virtual_obs_id_set
,
1634 struct dp_packet
*msg
)
1636 struct ipfix_template_record_header
*tmpl_hdr
;
1637 size_t tmpl_hdr_offset
= dp_packet_size(msg
);
1639 tmpl_hdr
= dp_packet_put_zeros(msg
, sizeof *tmpl_hdr
);
1640 tmpl_hdr
->template_id
=
1641 htons(ipfix_get_template_id(l2
, l3
, l4
, tunnel
, flow_direction
));
1642 ipfix_define_template_fields(l2
, l3
, l4
, tunnel
, flow_direction
,
1643 virtual_obs_id_set
, tmpl_hdr_offset
, msg
);
1647 ipfix_send_template_msgs(struct dpif_ipfix_exporter
*exporter
,
1648 uint32_t export_time_sec
, uint32_t obs_domain_id
)
1650 uint64_t msg_stub
[DIV_ROUND_UP(MAX_MESSAGE_LEN
, 8)];
1651 struct dp_packet msg
;
1652 dp_packet_use_stub(&msg
, msg_stub
, sizeof msg_stub
);
1654 size_t set_hdr_offset
, error_pkts
;
1655 size_t tx_packets
= 0;
1656 size_t tx_errors
= 0;
1657 enum ipfix_proto_l2 l2
;
1658 enum ipfix_proto_l3 l3
;
1659 enum ipfix_proto_l4 l4
;
1660 enum ipfix_proto_tunnel tunnel
;
1661 enum ipfix_flow_direction flow_direction
;
1663 ipfix_init_template_msg(export_time_sec
, exporter
->seq_number
,
1664 obs_domain_id
, IPFIX_SET_ID_TEMPLATE
, &msg
,
1666 /* Define one template for each possible combination of
1668 for (l2
= 0; l2
< NUM_IPFIX_PROTO_L2
; l2
++) {
1669 for (l3
= 0; l3
< NUM_IPFIX_PROTO_L3
; l3
++) {
1670 for (l4
= 0; l4
< NUM_IPFIX_PROTO_L4
; l4
++) {
1671 if (l3
== IPFIX_PROTO_L3_UNKNOWN
&&
1672 l4
!= IPFIX_PROTO_L4_UNKNOWN
) {
1675 for (tunnel
= 0; tunnel
< NUM_IPFIX_PROTO_TUNNEL
; tunnel
++) {
1676 for (flow_direction
= 0;
1677 flow_direction
< NUM_IPFIX_FLOW_DIRECTION
;
1679 /* When the size of the template packet reaches
1680 * MAX_MESSAGE_LEN(1024), send it out.
1681 * And then reinitialize the msg to construct a new
1682 * packet for the following templates.
1684 if (dp_packet_size(&msg
) >= MAX_MESSAGE_LEN
) {
1685 /* Send template message. */
1687 ipfix_send_template_msg(exporter
->collectors
,
1688 &msg
, set_hdr_offset
);
1689 tx_errors
+= error_pkts
;
1691 collectors_count(exporter
->collectors
)
1694 /* Reinitialize the template msg. */
1695 ipfix_init_template_msg(export_time_sec
,
1696 exporter
->seq_number
,
1698 IPFIX_SET_ID_TEMPLATE
,
1699 &msg
, &set_hdr_offset
);
1702 ipfix_add_template_record(l2
, l3
, l4
, tunnel
,
1704 exporter
->virtual_obs_id
!= NULL
, &msg
);
1711 /* Send template message. */
1712 error_pkts
= ipfix_send_template_msg(exporter
->collectors
, &msg
,
1714 tx_errors
+= error_pkts
;
1715 tx_packets
+= collectors_count(exporter
->collectors
) - error_pkts
;
1717 exporter
->ofproto_stats
.tx_pkts
+= tx_packets
;
1718 exporter
->ofproto_stats
.tx_errors
+= tx_errors
;
1720 /* XXX: Add Options Template Sets, at least to define a Flow Keys
1721 * Option Template. */
1723 /* At the moment only a single Options Template Set is used, which contains
1724 * Exporting Process Statistics. It means that there is no specific
1725 * Observation Domain ID relevant for the entire IPFIX message and it
1726 * should be set to 0. */
1727 ipfix_send_options_template_msgs(exporter
, export_time_sec
, 0U, &msg
);
1729 dp_packet_uninit(&msg
);
1732 static inline uint32_t
1733 ipfix_hash_flow_key(const struct ipfix_flow_key
*flow_key
, uint32_t basis
)
1736 hash
= hash_int(flow_key
->obs_domain_id
, basis
);
1737 hash
= hash_int(flow_key
->template_id
, hash
);
1738 hash
= hash_bytes(flow_key
->flow_key_msg_part
,
1739 flow_key
->flow_key_msg_part_size
, hash
);
1744 ipfix_flow_key_equal(const struct ipfix_flow_key
*a
,
1745 const struct ipfix_flow_key
*b
)
1747 /* The template ID determines the flow key size, so not need to
1749 return (a
->obs_domain_id
== b
->obs_domain_id
1750 && a
->template_id
== b
->template_id
1751 && memcmp(a
->flow_key_msg_part
, b
->flow_key_msg_part
,
1752 a
->flow_key_msg_part_size
) == 0);
1755 static struct ipfix_flow_cache_entry
*
1756 ipfix_cache_find_entry(const struct dpif_ipfix_exporter
*exporter
,
1757 const struct ipfix_flow_key
*flow_key
)
1759 struct ipfix_flow_cache_entry
*entry
;
1761 HMAP_FOR_EACH_WITH_HASH (entry
, flow_key_map_node
,
1762 ipfix_hash_flow_key(flow_key
, 0),
1763 &exporter
->cache_flow_key_map
) {
1764 if (ipfix_flow_key_equal(&entry
->flow_key
, flow_key
)) {
1773 ipfix_cache_next_timeout_msec(const struct dpif_ipfix_exporter
*exporter
,
1774 long long int *next_timeout_msec
)
1776 struct ipfix_flow_cache_entry
*entry
;
1778 LIST_FOR_EACH (entry
, cache_flow_start_timestamp_list_node
,
1779 &exporter
->cache_flow_start_timestamp_list
) {
1780 *next_timeout_msec
= entry
->flow_start_timestamp_usec
/ 1000LL
1781 + 1000LL * exporter
->cache_active_timeout
;
1789 ipfix_cache_aggregate_entries(struct ipfix_flow_cache_entry
*from_entry
,
1790 struct ipfix_flow_cache_entry
*to_entry
)
1792 uint64_t *to_start
, *to_end
, *from_start
, *from_end
;
1793 uint16_t *to_min_len
, *to_max_len
, *from_min_len
, *from_max_len
;
1795 to_start
= &to_entry
->flow_start_timestamp_usec
;
1796 to_end
= &to_entry
->flow_end_timestamp_usec
;
1797 from_start
= &from_entry
->flow_start_timestamp_usec
;
1798 from_end
= &from_entry
->flow_end_timestamp_usec
;
1800 if (*to_start
> *from_start
) {
1801 *to_start
= *from_start
;
1803 if (*to_end
< *from_end
) {
1804 *to_end
= *from_end
;
1808 to_entry
->dropped_packet_delta_count
+=
1809 from_entry
->dropped_packet_delta_count
;
1810 to_entry
->packet_delta_count
+= from_entry
->packet_delta_count
;
1811 to_entry
->layer2_octet_delta_count
+= from_entry
->layer2_octet_delta_count
;
1813 to_entry
->dropped_packet_total_count
=
1814 from_entry
->dropped_packet_total_count
;
1815 to_entry
->packet_total_count
= from_entry
->packet_total_count
;
1816 to_entry
->in_ucast_packet_total_count
=
1817 from_entry
->in_ucast_packet_total_count
;
1818 to_entry
->in_mcast_packet_total_count
=
1819 from_entry
->in_mcast_packet_total_count
;
1820 to_entry
->in_bcast_packet_total_count
=
1821 from_entry
->in_bcast_packet_total_count
;
1822 to_entry
->out_ucast_packet_total_count
=
1823 from_entry
->out_ucast_packet_total_count
;
1824 to_entry
->out_bcast_packet_total_count
=
1825 from_entry
->out_bcast_packet_total_count
;
1826 to_entry
->layer2_octet_total_count
= from_entry
->layer2_octet_total_count
;
1827 to_entry
->post_mcast_packet_delta_count
+=
1828 from_entry
->post_mcast_packet_delta_count
;
1829 to_entry
->post_mcast_octet_delta_count
+=
1830 from_entry
->post_mcast_octet_delta_count
;
1832 to_entry
->dropped_octet_delta_count
+=
1833 from_entry
->dropped_octet_delta_count
;
1834 to_entry
->octet_delta_count
+= from_entry
->octet_delta_count
;
1835 to_entry
->octet_delta_sum_of_squares
+=
1836 from_entry
->octet_delta_sum_of_squares
;
1838 to_entry
->dropped_octet_total_count
=
1839 from_entry
->dropped_octet_total_count
;
1840 to_entry
->octet_total_count
= from_entry
->octet_total_count
;
1841 to_entry
->octet_total_sum_of_squares
=
1842 from_entry
->octet_total_sum_of_squares
;
1844 to_entry
->post_mcast_packet_total_count
=
1845 from_entry
->post_mcast_packet_total_count
;
1846 to_entry
->post_mcast_octet_total_count
=
1847 from_entry
->post_mcast_octet_total_count
;
1849 to_min_len
= &to_entry
->minimum_ip_total_length
;
1850 to_max_len
= &to_entry
->maximum_ip_total_length
;
1851 from_min_len
= &from_entry
->minimum_ip_total_length
;
1852 from_max_len
= &from_entry
->maximum_ip_total_length
;
1854 if (!*to_min_len
|| (*from_min_len
&& *to_min_len
> *from_min_len
)) {
1855 *to_min_len
= *from_min_len
;
1857 if (*to_max_len
< *from_max_len
) {
1858 *to_max_len
= *from_max_len
;
1861 to_entry
->tcp_packet_delta_count
+= from_entry
->tcp_packet_delta_count
;
1862 to_entry
->tcp_ack_total_count
= from_entry
->tcp_ack_total_count
;
1863 to_entry
->tcp_fin_total_count
= from_entry
->tcp_fin_total_count
;
1864 to_entry
->tcp_psh_total_count
= from_entry
->tcp_psh_total_count
;
1865 to_entry
->tcp_rst_total_count
= from_entry
->tcp_rst_total_count
;
1866 to_entry
->tcp_syn_total_count
= from_entry
->tcp_syn_total_count
;
1867 to_entry
->tcp_urg_total_count
= from_entry
->tcp_urg_total_count
;
1870 /* Get statistics */
1872 ipfix_get_stats__(const struct dpif_ipfix_exporter
*exporter
,
1873 ofproto_ipfix_stats
*stats
)
1875 memset(stats
, 0xff, sizeof *stats
);
1881 *stats
= exporter
->ofproto_stats
;
1885 ipfix_get_bridge_stats(const struct dpif_ipfix_bridge_exporter
*exporter
,
1886 ofproto_ipfix_stats
*stats
)
1888 ipfix_get_stats__(&exporter
->exporter
, stats
);
1892 ipfix_get_flow_stats(const struct dpif_ipfix_flow_exporter
*exporter
,
1893 ofproto_ipfix_stats
*stats
)
1895 ipfix_get_stats__(&exporter
->exporter
, stats
);
1896 stats
->collector_set_id
= exporter
->options
->collector_set_id
;
1900 dpif_ipfix_get_stats(const struct dpif_ipfix
*di
,
1902 struct ovs_list
*replies
)
1905 struct dpif_ipfix_flow_exporter_map_node
*flow_exporter_node
;
1906 struct ofputil_ipfix_stats ois
;
1908 ovs_mutex_lock(&mutex
);
1910 if (!di
->bridge_exporter
.options
) {
1911 ovs_mutex_unlock(&mutex
);
1912 return OFPERR_NXST_NOT_CONFIGURED
;
1915 ipfix_get_bridge_stats(&di
->bridge_exporter
, &ois
);
1916 ofputil_append_ipfix_stat(replies
, &ois
);
1918 if (hmap_count(&di
->flow_exporter_map
) == 0) {
1919 ovs_mutex_unlock(&mutex
);
1920 return OFPERR_NXST_NOT_CONFIGURED
;
1923 HMAP_FOR_EACH (flow_exporter_node
, node
,
1924 &di
->flow_exporter_map
) {
1925 ipfix_get_flow_stats(&flow_exporter_node
->exporter
, &ois
);
1926 ofputil_append_ipfix_stat(replies
, &ois
);
1929 ovs_mutex_unlock(&mutex
);
1934 /* Update partial ipfix stats */
1936 ipfix_update_stats(struct dpif_ipfix_exporter
*exporter
,
1938 size_t current_flows
,
1939 enum ipfix_sampled_packet_type sampled_pkt_type
)
1942 exporter
->ofproto_stats
.total_flows
++;
1943 exporter
->ofproto_stats
.current_flows
= current_flows
;
1945 exporter
->ofproto_stats
.pkts
++;
1947 switch (sampled_pkt_type
) {
1948 case IPFIX_SAMPLED_PKT_IPV4_OK
:
1949 exporter
->ofproto_stats
.ipv4_pkts
++;
1951 case IPFIX_SAMPLED_PKT_IPV6_OK
:
1952 exporter
->ofproto_stats
.ipv6_pkts
++;
1954 case IPFIX_SAMPLED_PKT_IPV4_ERROR
:
1955 exporter
->ofproto_stats
.ipv4_error_pkts
++;
1956 exporter
->ofproto_stats
.error_pkts
++;
1958 case IPFIX_SAMPLED_PKT_IPV6_ERROR
:
1959 exporter
->ofproto_stats
.ipv6_error_pkts
++;
1960 exporter
->ofproto_stats
.error_pkts
++;
1962 case IPFIX_SAMPLED_PKT_UNKNOWN
:
1963 exporter
->ofproto_stats
.error_pkts
++;
1965 case IPFIX_SAMPLED_PKT_OTHERS
:
1971 /* Returns the current time in the form used by IPFIX (microseconds since the
1976 return time_wall_msec() * 1000ULL;
1979 /* Add an entry into a flow cache. The entry is either aggregated into
1980 * an existing entry with the same flow key and free()d, or it is
1981 * inserted into the cache. And IPFIX stats will be updated */
1983 ipfix_cache_update(struct dpif_ipfix_exporter
*exporter
,
1984 struct ipfix_flow_cache_entry
*entry
,
1985 enum ipfix_sampled_packet_type sampled_pkt_type
)
1987 struct ipfix_flow_cache_entry
*old_entry
;
1988 size_t current_flows
= 0;
1990 old_entry
= ipfix_cache_find_entry(exporter
, &entry
->flow_key
);
1992 if (old_entry
== NULL
) {
1993 hmap_insert(&exporter
->cache_flow_key_map
, &entry
->flow_key_map_node
,
1994 ipfix_hash_flow_key(&entry
->flow_key
, 0));
1996 /* As the latest entry added into the cache, it should
1997 * logically have the highest flow_start_timestamp_usec, so
1998 * append it at the tail. */
1999 ovs_list_push_back(&exporter
->cache_flow_start_timestamp_list
,
2000 &entry
->cache_flow_start_timestamp_list_node
);
2002 /* Enforce exporter->cache_max_flows limit. */
2003 current_flows
= hmap_count(&exporter
->cache_flow_key_map
);
2004 ipfix_update_stats(exporter
, true, current_flows
, sampled_pkt_type
);
2005 if (current_flows
> exporter
->cache_max_flows
) {
2006 dpif_ipfix_cache_expire_now(exporter
, false);
2009 ipfix_cache_aggregate_entries(entry
, old_entry
);
2011 ipfix_update_stats(exporter
, false, current_flows
, sampled_pkt_type
);
2016 ipfix_destroy_iface_data_record(struct ipfix_data_record_flow_key_iface
*data
)
2018 free(data
->if_descr
);
2019 free(data
->if_name
);
2022 /* Fills '*data' structure based on port number 'port_no'. Caller must destroy
2023 * 'data' with ipfix_destroy_iface_data_record(). */
2025 ipfix_get_iface_data_record(const struct dpif_ipfix
*di
, odp_port_t port_no
,
2026 struct ipfix_data_record_flow_key_iface
*data
)
2029 struct dpif_ipfix_port
*port
;
2030 struct smap netdev_status
;
2032 port
= dpif_ipfix_find_port(di
, port_no
);
2037 smap_init(&netdev_status
);
2038 if (!netdev_get_status(port
->ofport
->netdev
, &netdev_status
)) {
2039 data
->if_type
= htonl(smap_get_ullong(&netdev_status
, "if_type", 0));
2040 data
->if_descr
= nullable_xstrdup(smap_get(&netdev_status
,
2044 data
->if_descr
= NULL
;
2047 smap_destroy(&netdev_status
);
2048 data
->if_index
= htonl(port
->ifindex
);
2049 data
->if_descr_len
= data
->if_descr
? strnlen(data
->if_descr
,
2050 MAX_IF_DESCR_LEN
) : 0;
2051 data
->if_name
= nullable_xstrdup(netdev_get_name(port
->ofport
->netdev
));
2052 data
->if_name_len
= data
->if_name
? strnlen(data
->if_name
,
2053 MAX_IF_NAME_LEN
) : 0;
2059 ipfix_put_iface_data_record(const struct dpif_ipfix
*di
, odp_port_t port_no
,
2060 struct dp_packet
*msg
)
2063 struct ipfix_data_record_flow_key_iface data
;
2066 memset(&data
, 0, sizeof(struct ipfix_data_record_flow_key_iface
));
2067 err
= ipfix_get_iface_data_record(di
, port_no
, &data
);
2069 dp_packet_put(msg
, &data
.if_index
, sizeof data
.if_index
);
2070 dp_packet_put(msg
, &data
.if_type
, sizeof data
.if_type
);
2071 dp_packet_put(msg
, &data
.if_name_len
, sizeof data
.if_name_len
);
2072 if (data
.if_name_len
) {
2073 dp_packet_put(msg
, data
.if_name
, data
.if_name_len
);
2075 dp_packet_put(msg
, &data
.if_descr_len
, sizeof data
.if_descr_len
);
2076 if (data
.if_descr_len
) {
2077 dp_packet_put(msg
, data
.if_descr
, data
.if_descr_len
);
2079 ipfix_destroy_iface_data_record(&data
);
2081 dp_packet_put_zeros(msg
, sizeof data
.if_index
);
2082 dp_packet_put_zeros(msg
, sizeof data
.if_type
);
2083 dp_packet_put_zeros(msg
, sizeof data
.if_name_len
);
2084 dp_packet_put_zeros(msg
, sizeof data
.if_descr_len
);
2088 static enum ipfix_sampled_packet_type
2089 ipfix_cache_entry_init(const struct dpif_ipfix
*di
,
2090 struct ipfix_flow_cache_entry
*entry
,
2091 const struct dp_packet
*packet
, const struct flow
*flow
,
2092 uint64_t packet_delta_count
, uint32_t obs_domain_id
,
2093 uint32_t obs_point_id
, odp_port_t output_odp_port
,
2094 enum nx_action_sample_direction direction
,
2095 const struct dpif_ipfix_port
*tunnel_port
,
2096 const struct flow_tnl
*tunnel_key
,
2097 struct dpif_ipfix_global_stats
*stats
,
2098 const struct dpif_ipfix_actions
*ipfix_actions
)
2101 struct ipfix_flow_key
*flow_key
;
2102 struct dp_packet msg
;
2103 enum ipfix_proto_l2 l2
;
2104 enum ipfix_proto_l3 l3
;
2105 enum ipfix_proto_l4 l4
;
2106 enum ipfix_proto_tunnel tunnel
= IPFIX_PROTO_NOT_TUNNELED
;
2107 enum ipfix_sampled_packet_type sampled_pkt_type
= IPFIX_SAMPLED_PKT_UNKNOWN
;
2108 uint8_t ethernet_header_length
;
2109 uint16_t ethernet_total_length
;
2110 bool is_multicast
= false;
2111 bool is_broadcast
= false;
2113 flow_key
= &entry
->flow_key
;
2114 dp_packet_use_stub(&msg
, flow_key
->flow_key_msg_part
,
2115 sizeof flow_key
->flow_key_msg_part
);
2117 /* Choose the right template ID matching the protocols in the
2118 * sampled packet. */
2119 l2
= (flow
->vlans
[0].tci
== 0) ? IPFIX_PROTO_L2_ETH
: IPFIX_PROTO_L2_VLAN
;
2121 switch(ntohs(flow
->dl_type
)) {
2123 l3
= IPFIX_PROTO_L3_IPV4
;
2124 sampled_pkt_type
= IPFIX_SAMPLED_PKT_IPV4_OK
;
2125 switch(flow
->nw_proto
) {
2127 l4
= IPFIX_PROTO_L4_TCP
;
2130 l4
= IPFIX_PROTO_L4_UDP
;
2133 l4
= IPFIX_PROTO_L4_SCTP
;
2136 l4
= IPFIX_PROTO_L4_ICMP
;
2139 l4
= IPFIX_PROTO_L4_UNKNOWN
;
2140 sampled_pkt_type
= IPFIX_SAMPLED_PKT_IPV4_ERROR
;
2144 l3
= IPFIX_PROTO_L3_IPV6
;
2145 sampled_pkt_type
= IPFIX_SAMPLED_PKT_IPV6_OK
;
2146 switch(flow
->nw_proto
) {
2148 l4
= IPFIX_PROTO_L4_TCP
;
2151 l4
= IPFIX_PROTO_L4_UDP
;
2154 l4
= IPFIX_PROTO_L4_SCTP
;
2156 case IPPROTO_ICMPV6
:
2157 l4
= IPFIX_PROTO_L4_ICMP
;
2160 l4
= IPFIX_PROTO_L4_UNKNOWN
;
2161 sampled_pkt_type
= IPFIX_SAMPLED_PKT_IPV6_ERROR
;
2165 l3
= IPFIX_PROTO_L3_UNKNOWN
;
2166 l4
= IPFIX_PROTO_L4_UNKNOWN
;
2167 sampled_pkt_type
= IPFIX_SAMPLED_PKT_OTHERS
;
2170 if (tunnel_port
&& tunnel_key
) {
2171 tunnel
= IPFIX_PROTO_TUNNELED
;
2174 uint8_t flow_direction
=
2175 (direction
== NX_ACTION_SAMPLE_INGRESS
? INGRESS_FLOW
2176 : direction
== NX_ACTION_SAMPLE_EGRESS
? EGRESS_FLOW
2177 : output_odp_port
== ODPP_NONE
? INGRESS_FLOW
: EGRESS_FLOW
);
2179 flow_key
->obs_domain_id
= obs_domain_id
;
2180 flow_key
->template_id
= ipfix_get_template_id(l2
, l3
, l4
, tunnel
,
2183 /* The fields defined in the ipfix_data_record_* structs and sent
2184 * below must match exactly the templates defined in
2185 * ipfix_define_template_fields. */
2187 ethernet_header_length
= (l2
== IPFIX_PROTO_L2_VLAN
)
2188 ? VLAN_ETH_HEADER_LEN
: ETH_HEADER_LEN
;
2189 ethernet_total_length
= dp_packet_size(packet
);
2191 /* Common Ethernet entities. */
2193 struct ipfix_data_record_flow_key_common
*data_common
;
2195 data_common
= dp_packet_put_zeros(&msg
, sizeof *data_common
);
2196 data_common
->observation_point_id
= htonl(obs_point_id
);
2197 data_common
->flow_direction
= flow_direction
;
2198 data_common
->source_mac_address
= flow
->dl_src
;
2199 data_common
->destination_mac_address
= flow
->dl_dst
;
2200 data_common
->ethernet_type
= flow
->dl_type
;
2201 data_common
->ethernet_header_length
= ethernet_header_length
;
2204 /* Interface Information Elements */
2205 ipfix_put_iface_data_record(di
, flow
->in_port
.odp_port
, &msg
);
2207 if (flow_direction
== EGRESS_FLOW
) {
2208 ipfix_put_iface_data_record(di
, output_odp_port
, &msg
);
2211 if (l2
== IPFIX_PROTO_L2_VLAN
) {
2212 struct ipfix_data_record_flow_key_vlan
*data_vlan
;
2213 uint16_t vlan_id
= vlan_tci_to_vid(flow
->vlans
[0].tci
);
2214 uint8_t priority
= vlan_tci_to_pcp(flow
->vlans
[0].tci
);
2216 data_vlan
= dp_packet_put_zeros(&msg
, sizeof *data_vlan
);
2217 data_vlan
->vlan_id
= htons(vlan_id
);
2218 data_vlan
->dot1q_vlan_id
= htons(vlan_id
);
2219 data_vlan
->dot1q_priority
= priority
;
2222 if (l3
!= IPFIX_PROTO_L3_UNKNOWN
) {
2223 struct ipfix_data_record_flow_key_ip
*data_ip
;
2225 data_ip
= dp_packet_put_zeros(&msg
, sizeof *data_ip
);
2226 data_ip
->ip_version
= (l3
== IPFIX_PROTO_L3_IPV4
) ? 4 : 6;
2227 data_ip
->ip_ttl
= flow
->nw_ttl
;
2228 data_ip
->protocol_identifier
= flow
->nw_proto
;
2229 data_ip
->ip_diff_serv_code_point
= flow
->nw_tos
>> 2;
2230 data_ip
->ip_precedence
= flow
->nw_tos
>> 5;
2231 data_ip
->ip_class_of_service
= flow
->nw_tos
;
2233 if (l3
== IPFIX_PROTO_L3_IPV4
) {
2234 struct ipfix_data_record_flow_key_ipv4
*data_ipv4
;
2236 data_ipv4
= dp_packet_put_zeros(&msg
, sizeof *data_ipv4
);
2237 data_ipv4
->source_ipv4_address
= flow
->nw_src
;
2238 data_ipv4
->destination_ipv4_address
= flow
->nw_dst
;
2239 } else { /* l3 == IPFIX_PROTO_L3_IPV6 */
2240 struct ipfix_data_record_flow_key_ipv6
*data_ipv6
;
2242 data_ipv6
= dp_packet_put_zeros(&msg
, sizeof *data_ipv6
);
2243 memcpy(data_ipv6
->source_ipv6_address
, &flow
->ipv6_src
,
2244 sizeof flow
->ipv6_src
);
2245 memcpy(data_ipv6
->destination_ipv6_address
, &flow
->ipv6_dst
,
2246 sizeof flow
->ipv6_dst
);
2247 data_ipv6
->flow_label_ipv6
= flow
->ipv6_label
;
2251 if (l4
== IPFIX_PROTO_L4_TCP
2252 || l4
== IPFIX_PROTO_L4_UDP
2253 || l4
== IPFIX_PROTO_L4_SCTP
) {
2254 struct ipfix_data_record_flow_key_transport
*data_transport
;
2256 data_transport
= dp_packet_put_zeros(&msg
, sizeof *data_transport
);
2257 data_transport
->source_transport_port
= flow
->tp_src
;
2258 data_transport
->destination_transport_port
= flow
->tp_dst
;
2259 } else if (l4
== IPFIX_PROTO_L4_ICMP
) {
2260 struct ipfix_data_record_flow_key_icmp
*data_icmp
;
2262 data_icmp
= dp_packet_put_zeros(&msg
, sizeof *data_icmp
);
2263 data_icmp
->icmp_type
= ntohs(flow
->tp_src
) & 0xff;
2264 data_icmp
->icmp_code
= ntohs(flow
->tp_dst
) & 0xff;
2267 if (tunnel
== IPFIX_PROTO_TUNNELED
) {
2268 struct ipfix_data_record_flow_key_tunnel
*data_tunnel
;
2269 const uint8_t *tun_id
;
2271 data_tunnel
= dp_packet_put_zeros(&msg
, sizeof *data_tunnel
+
2272 tunnel_port
->tunnel_key_length
);
2273 data_tunnel
->tunnel_source_ipv4_address
= tunnel_key
->ip_src
;
2274 data_tunnel
->tunnel_destination_ipv4_address
= tunnel_key
->ip_dst
;
2275 /* The tunnel_protocol_identifier is from tunnel_proto array, which
2276 * contains protocol_identifiers of each tunnel type.
2278 data_tunnel
->tunnel_protocol_identifier
=
2279 tunnel_protocol
[tunnel_port
->tunnel_type
];
2280 data_tunnel
->tunnel_source_transport_port
= tunnel_key
->tp_src
;
2281 data_tunnel
->tunnel_destination_transport_port
= tunnel_key
->tp_dst
;
2282 data_tunnel
->tunnel_type
= tunnel_port
->tunnel_type
;
2283 data_tunnel
->tunnel_key_length
= tunnel_port
->tunnel_key_length
;
2284 /* tun_id is in network order, and tunnel key is in low bits. */
2285 tun_id
= (const uint8_t *) &tunnel_key
->tun_id
;
2286 memcpy(data_tunnel
->tunnel_key
,
2287 &tun_id
[8 - tunnel_port
->tunnel_key_length
],
2288 tunnel_port
->tunnel_key_length
);
2291 flow_key
->flow_key_msg_part_size
= dp_packet_size(&msg
);
2293 if (eth_addr_is_broadcast(flow
->dl_dst
)) {
2294 is_broadcast
= true;
2295 } else if (eth_addr_is_multicast(flow
->dl_dst
)) {
2296 is_multicast
= true;
2300 uint64_t layer2_octet_delta_count
;
2302 /* Calculate the total matched octet count by considering as
2303 * an approximation that all matched packets have the same
2305 layer2_octet_delta_count
= packet_delta_count
* ethernet_total_length
;
2307 entry
->flow_end_timestamp_usec
= ipfix_now();
2308 entry
->flow_start_timestamp_usec
= entry
->flow_end_timestamp_usec
;
2310 if (ipfix_actions
&& ipfix_actions
->output_action
) {
2311 entry
->dropped_packet_delta_count
= 0;
2313 entry
->dropped_packet_delta_count
= packet_delta_count
;
2316 entry
->packet_delta_count
= packet_delta_count
;
2317 entry
->layer2_octet_delta_count
= layer2_octet_delta_count
;
2319 stats
->dropped_packet_total_count
+= entry
->dropped_packet_delta_count
;
2320 stats
->packet_total_count
+= packet_delta_count
;
2321 stats
->layer2_octet_total_count
+= layer2_octet_delta_count
;
2323 entry
->post_mcast_packet_delta_count
= 0;
2325 if (flow_direction
== INGRESS_FLOW
) {
2326 stats
->in_bcast_packet_total_count
+= packet_delta_count
;
2327 } else if (flow_direction
== EGRESS_FLOW
) {
2328 stats
->out_bcast_packet_total_count
+= packet_delta_count
;
2330 } else if (is_multicast
) {
2331 if (flow_direction
== INGRESS_FLOW
) {
2332 stats
->in_mcast_packet_total_count
+= packet_delta_count
;
2333 } else if (flow_direction
== EGRESS_FLOW
) {
2334 entry
->post_mcast_packet_delta_count
= packet_delta_count
;
2335 stats
->post_mcast_packet_total_count
+= packet_delta_count
;
2338 if (flow_direction
== INGRESS_FLOW
) {
2339 stats
->in_ucast_packet_total_count
+= packet_delta_count
;
2340 } else if (flow_direction
== EGRESS_FLOW
) {
2341 stats
->out_ucast_packet_total_count
+= packet_delta_count
;
2345 entry
->dropped_packet_total_count
= stats
->dropped_packet_total_count
;
2346 entry
->packet_total_count
= stats
->packet_total_count
;
2347 entry
->in_ucast_packet_total_count
=
2348 stats
->in_ucast_packet_total_count
;
2349 entry
->in_mcast_packet_total_count
=
2350 stats
->in_mcast_packet_total_count
;
2351 entry
->in_bcast_packet_total_count
=
2352 stats
->in_bcast_packet_total_count
;
2353 entry
->out_ucast_packet_total_count
=
2354 stats
->out_ucast_packet_total_count
;
2355 entry
->out_bcast_packet_total_count
=
2356 stats
->out_bcast_packet_total_count
;
2357 entry
->post_mcast_packet_total_count
=
2358 stats
->post_mcast_packet_total_count
;
2359 entry
->layer2_octet_total_count
= stats
->layer2_octet_total_count
;
2362 if (l3
!= IPFIX_PROTO_L3_UNKNOWN
) {
2363 uint16_t ip_total_length
=
2364 ethernet_total_length
- ethernet_header_length
;
2365 uint64_t octet_delta_count
;
2367 /* Calculate the total matched octet count by considering as
2368 * an approximation that all matched packets have the same
2370 octet_delta_count
= packet_delta_count
* ip_total_length
;
2372 if (ipfix_actions
&& ipfix_actions
->output_action
) {
2373 entry
->dropped_octet_delta_count
= 0;
2375 entry
->dropped_octet_delta_count
= octet_delta_count
;
2378 entry
->octet_delta_count
= octet_delta_count
;
2379 entry
->octet_delta_sum_of_squares
= octet_delta_count
* ip_total_length
;
2380 entry
->minimum_ip_total_length
= ip_total_length
;
2381 entry
->maximum_ip_total_length
= ip_total_length
;
2383 stats
->dropped_octet_total_count
+= entry
->dropped_octet_delta_count
;
2384 stats
->octet_total_count
+= octet_delta_count
;
2385 stats
->octet_total_sum_of_squares
+= entry
->octet_delta_sum_of_squares
;
2387 if (is_multicast
&& flow_direction
== EGRESS_FLOW
) {
2388 entry
->post_mcast_octet_delta_count
= octet_delta_count
;
2389 stats
->post_mcast_octet_total_count
+= octet_delta_count
;
2391 entry
->post_mcast_octet_delta_count
= 0;
2394 entry
->octet_delta_sum_of_squares
= 0;
2395 entry
->minimum_ip_total_length
= 0;
2396 entry
->maximum_ip_total_length
= 0;
2399 entry
->dropped_octet_total_count
= stats
->dropped_octet_total_count
;
2400 entry
->octet_total_sum_of_squares
= stats
->octet_total_sum_of_squares
;
2401 entry
->octet_total_count
= stats
->octet_total_count
;
2402 entry
->post_mcast_octet_total_count
=
2403 stats
->post_mcast_octet_total_count
;
2405 if (l4
== IPFIX_PROTO_L4_TCP
) {
2406 uint16_t tcp_flags
= ntohs(flow
->tcp_flags
);
2407 entry
->tcp_packet_delta_count
= packet_delta_count
;
2409 if (tcp_flags
& TCP_ACK
) {
2410 stats
->tcp_ack_total_count
+= packet_delta_count
;
2412 if (tcp_flags
& TCP_FIN
) {
2413 stats
->tcp_fin_total_count
+= packet_delta_count
;
2415 if (tcp_flags
& TCP_PSH
) {
2416 stats
->tcp_psh_total_count
+= packet_delta_count
;
2418 if (tcp_flags
& TCP_RST
) {
2419 stats
->tcp_rst_total_count
+= packet_delta_count
;
2421 if (tcp_flags
& TCP_SYN
) {
2422 stats
->tcp_syn_total_count
+= packet_delta_count
;
2424 if (tcp_flags
& TCP_URG
) {
2425 stats
->tcp_urg_total_count
+= packet_delta_count
;
2428 entry
->tcp_packet_delta_count
= 0;
2431 entry
->tcp_ack_total_count
= stats
->tcp_ack_total_count
;
2432 entry
->tcp_fin_total_count
= stats
->tcp_fin_total_count
;
2433 entry
->tcp_psh_total_count
= stats
->tcp_psh_total_count
;
2434 entry
->tcp_rst_total_count
= stats
->tcp_rst_total_count
;
2435 entry
->tcp_syn_total_count
= stats
->tcp_syn_total_count
;
2436 entry
->tcp_urg_total_count
= stats
->tcp_urg_total_count
;
2438 return sampled_pkt_type
;
2441 /* Send each single data record in its own data set, to simplify the
2442 * implementation by avoiding having to group record by template ID
2443 * before sending. */
2445 ipfix_put_data_set(uint32_t export_time_sec
,
2446 struct ipfix_flow_cache_entry
*entry
,
2447 enum ipfix_flow_end_reason flow_end_reason
,
2448 const char *virtual_obs_id
,
2449 uint8_t virtual_obs_len
,
2450 struct dp_packet
*msg
)
2452 size_t set_hdr_offset
;
2453 struct ipfix_set_header
*set_hdr
;
2455 set_hdr_offset
= dp_packet_size(msg
);
2457 /* Put a Data Set. */
2458 set_hdr
= dp_packet_put_zeros(msg
, sizeof *set_hdr
);
2459 set_hdr
->set_id
= htons(entry
->flow_key
.template_id
);
2461 /* Copy the flow key part of the data record. */
2462 dp_packet_put(msg
, entry
->flow_key
.flow_key_msg_part
,
2463 entry
->flow_key
.flow_key_msg_part_size
);
2465 /* Export virtual observation ID. */
2466 if (virtual_obs_id
) {
2467 dp_packet_put(msg
, &virtual_obs_len
, sizeof(virtual_obs_len
));
2468 dp_packet_put(msg
, virtual_obs_id
, virtual_obs_len
);
2471 /* Put the non-key part of the data record. */
2474 struct ipfix_data_record_aggregated_common
*data_aggregated_common
;
2475 uint64_t export_time_usec
, flow_start_delta_usec
, flow_end_delta_usec
;
2477 /* Calculate the negative deltas relative to the export time
2478 * in seconds sent in the header, not the exact export
2480 export_time_usec
= 1000000LL * export_time_sec
;
2481 flow_start_delta_usec
= export_time_usec
2482 - entry
->flow_start_timestamp_usec
;
2483 flow_end_delta_usec
= export_time_usec
2484 - entry
->flow_end_timestamp_usec
;
2486 data_aggregated_common
= dp_packet_put_zeros(
2487 msg
, sizeof *data_aggregated_common
);
2488 data_aggregated_common
->flow_start_delta_microseconds
= htonl(
2489 flow_start_delta_usec
);
2490 data_aggregated_common
->flow_end_delta_microseconds
= htonl(
2491 flow_end_delta_usec
);
2492 data_aggregated_common
->dropped_packet_delta_count
= htonll(
2493 entry
->dropped_packet_delta_count
);
2494 data_aggregated_common
->dropped_packet_total_count
= htonll(
2495 entry
->dropped_packet_total_count
);
2496 data_aggregated_common
->packet_delta_count
= htonll(
2497 entry
->packet_delta_count
);
2498 data_aggregated_common
->packet_total_count
= htonll(
2499 entry
->packet_total_count
);
2500 data_aggregated_common
->in_ucast_packet_total_count
= htonll(
2501 entry
->in_ucast_packet_total_count
);
2502 data_aggregated_common
->in_mcast_packet_total_count
= htonll(
2503 entry
->in_mcast_packet_total_count
);
2504 data_aggregated_common
->in_bcast_packet_total_count
= htonll(
2505 entry
->in_bcast_packet_total_count
);
2506 data_aggregated_common
->out_ucast_packet_total_count
= htonll(
2507 entry
->out_ucast_packet_total_count
);
2508 data_aggregated_common
->out_bcast_packet_total_count
= htonll(
2509 entry
->out_bcast_packet_total_count
);
2510 data_aggregated_common
->layer2_octet_delta_count
= htonll(
2511 entry
->layer2_octet_delta_count
);
2512 data_aggregated_common
->layer2_octet_total_count
= htonll(
2513 entry
->layer2_octet_total_count
);
2514 data_aggregated_common
->flow_end_reason
= flow_end_reason
;
2515 data_aggregated_common
->post_mcast_packet_delta_count
= htonll(
2516 entry
->post_mcast_packet_delta_count
);
2517 data_aggregated_common
->post_mcast_packet_total_count
= htonll(
2518 entry
->post_mcast_packet_total_count
);
2521 if (entry
->octet_delta_sum_of_squares
) { /* IP packet. */
2522 struct ipfix_data_record_aggregated_ip
*data_aggregated_ip
;
2524 data_aggregated_ip
= dp_packet_put_zeros(
2525 msg
, sizeof *data_aggregated_ip
);
2526 data_aggregated_ip
->dropped_octet_delta_count
= htonll(
2527 entry
->dropped_octet_delta_count
);
2528 data_aggregated_ip
->dropped_octet_total_count
= htonll(
2529 entry
->dropped_octet_total_count
);
2530 data_aggregated_ip
->octet_delta_count
= htonll(
2531 entry
->octet_delta_count
);
2532 data_aggregated_ip
->octet_total_count
= htonll(
2533 entry
->octet_total_count
);
2534 data_aggregated_ip
->octet_delta_sum_of_squares
= htonll(
2535 entry
->octet_delta_sum_of_squares
);
2536 data_aggregated_ip
->octet_total_sum_of_squares
= htonll(
2537 entry
->octet_total_sum_of_squares
);
2538 data_aggregated_ip
->minimum_ip_total_length
= htonll(
2539 entry
->minimum_ip_total_length
);
2540 data_aggregated_ip
->maximum_ip_total_length
= htonll(
2541 entry
->maximum_ip_total_length
);
2542 data_aggregated_ip
->post_mcast_octet_delta_count
= htonll(
2543 entry
->post_mcast_octet_delta_count
);
2544 data_aggregated_ip
->post_mcast_octet_total_count
= htonll(
2545 entry
->post_mcast_octet_total_count
);
2548 if (entry
->tcp_packet_delta_count
) {
2549 struct ipfix_data_record_aggregated_tcp
*data_aggregated_tcp
;
2551 data_aggregated_tcp
= dp_packet_put_zeros(
2552 msg
, sizeof *data_aggregated_tcp
);
2553 data_aggregated_tcp
->tcp_ack_total_count
= htonll(
2554 entry
->tcp_ack_total_count
);
2555 data_aggregated_tcp
->tcp_fin_total_count
= htonll(
2556 entry
->tcp_fin_total_count
);
2557 data_aggregated_tcp
->tcp_psh_total_count
= htonll(
2558 entry
->tcp_psh_total_count
);
2559 data_aggregated_tcp
->tcp_rst_total_count
= htonll(
2560 entry
->tcp_rst_total_count
);
2561 data_aggregated_tcp
->tcp_syn_total_count
= htonll(
2562 entry
->tcp_syn_total_count
);
2563 data_aggregated_tcp
->tcp_urg_total_count
= htonll(
2564 entry
->tcp_urg_total_count
);
2567 set_hdr
= (struct ipfix_set_header
*)((uint8_t*)dp_packet_data(msg
) + set_hdr_offset
);
2568 set_hdr
->length
= htons(dp_packet_size(msg
) - set_hdr_offset
);
2572 ipfix_put_exporter_data_set(uint32_t exporting_process_id
,
2573 const ofproto_ipfix_stats
*ofproto_stats
,
2574 struct dp_packet
*msg
)
2576 size_t set_hdr_offset
;
2577 struct ipfix_set_header
*set_hdr
;
2579 set_hdr_offset
= dp_packet_size(msg
);
2581 /* Put a Data Set. */
2582 set_hdr
= dp_packet_put_zeros(msg
, sizeof *set_hdr
);
2583 set_hdr
->set_id
= htons(
2584 ipfix_get_options_template_id(IPFIX_OPTIONS_TEMPLATE_EXPORTER_STATS
));
2587 struct ipfix_data_record_exporter_stats
*data_exporter_stats
;
2589 data_exporter_stats
= dp_packet_put_zeros(
2590 msg
, sizeof *data_exporter_stats
);
2592 data_exporter_stats
->exporting_process_id
=
2593 htonl(exporting_process_id
);
2594 data_exporter_stats
->not_sent_packet_total_count
= htonll(
2595 ofproto_stats
->tx_errors
);
2598 set_hdr
= (struct ipfix_set_header
*)
2599 ((uint8_t *)dp_packet_data(msg
) + set_hdr_offset
);
2600 set_hdr
->length
= htons(dp_packet_size(msg
) - set_hdr_offset
);
2603 /* Send an IPFIX message with a single data set containing Exporting Process
2604 * Reliability Statistics. */
2606 ipfix_send_exporter_data_msg(struct dpif_ipfix_exporter
*exporter
,
2607 uint32_t export_time_sec
)
2609 uint64_t msg_stub
[DIV_ROUND_UP(MAX_MESSAGE_LEN
, 8)];
2610 struct dp_packet msg
;
2613 dp_packet_use_stub(&msg
, msg_stub
, sizeof msg_stub
);
2615 /* In case of Exporting Process Statistics, Observation Domain ID should
2617 ipfix_init_header(export_time_sec
, exporter
->seq_number
++, 0U, &msg
);
2618 ipfix_put_exporter_data_set(exporter
->exporter_id
,
2619 &exporter
->ofproto_stats
, &msg
);
2620 tx_errors
= ipfix_send_msg(exporter
->collectors
, &msg
);
2622 dp_packet_uninit(&msg
);
2624 exporter
->ofproto_stats
.tx_pkts
+=
2625 collectors_count(exporter
->collectors
) - tx_errors
;
2626 exporter
->ofproto_stats
.tx_errors
+= tx_errors
;
2629 /* Send an IPFIX message with a single data record. */
2631 ipfix_send_data_msg(struct dpif_ipfix_exporter
*exporter
,
2632 uint32_t export_time_sec
,
2633 struct ipfix_flow_cache_entry
*entry
,
2634 enum ipfix_flow_end_reason flow_end_reason
)
2636 uint64_t msg_stub
[DIV_ROUND_UP(MAX_MESSAGE_LEN
, 8)];
2637 struct dp_packet msg
;
2640 dp_packet_use_stub(&msg
, msg_stub
, sizeof msg_stub
);
2642 ipfix_init_header(export_time_sec
, exporter
->seq_number
++,
2643 entry
->flow_key
.obs_domain_id
, &msg
);
2644 ipfix_put_data_set(export_time_sec
, entry
, flow_end_reason
,
2645 exporter
->virtual_obs_id
, exporter
->virtual_obs_len
,
2647 tx_errors
= ipfix_send_msg(exporter
->collectors
, &msg
);
2649 dp_packet_uninit(&msg
);
2651 exporter
->ofproto_stats
.current_flows
--;
2652 exporter
->ofproto_stats
.tx_pkts
+=
2653 collectors_count(exporter
->collectors
) - tx_errors
;
2654 exporter
->ofproto_stats
.tx_errors
+= tx_errors
;
2658 dpif_ipfix_sample(const struct dpif_ipfix
*di
,
2659 struct dpif_ipfix_exporter
*exporter
,
2660 const struct dp_packet
*packet
, const struct flow
*flow
,
2661 uint64_t packet_delta_count
, uint32_t obs_domain_id
,
2662 uint32_t obs_point_id
, odp_port_t output_odp_port
,
2663 enum nx_action_sample_direction direction
,
2664 const struct dpif_ipfix_port
*tunnel_port
,
2665 const struct flow_tnl
*tunnel_key
,
2666 const struct dpif_ipfix_actions
*ipfix_actions
)
2669 struct ipfix_flow_cache_entry
*entry
;
2670 enum ipfix_sampled_packet_type sampled_packet_type
;
2672 /* Create a flow cache entry from the sample. */
2673 entry
= xmalloc(sizeof *entry
);
2674 sampled_packet_type
=
2675 ipfix_cache_entry_init(di
, entry
, packet
,
2676 flow
, packet_delta_count
,
2677 obs_domain_id
, obs_point_id
,
2678 output_odp_port
, direction
,
2679 tunnel_port
, tunnel_key
,
2680 &exporter
->ipfix_global_stats
,
2683 ipfix_cache_update(exporter
, entry
, sampled_packet_type
);
2687 bridge_exporter_enabled(struct dpif_ipfix
*di
)
2689 return di
->bridge_exporter
.probability
> 0;
2693 dpif_ipfix_bridge_sample(struct dpif_ipfix
*di
, const struct dp_packet
*packet
,
2694 const struct flow
*flow
,
2695 odp_port_t input_odp_port
, odp_port_t output_odp_port
,
2696 const struct flow_tnl
*output_tunnel_key
,
2697 const struct dpif_ipfix_actions
*ipfix_actions
)
2700 uint64_t packet_delta_count
;
2701 const struct flow_tnl
*tunnel_key
= NULL
;
2702 struct dpif_ipfix_port
* tunnel_port
= NULL
;
2704 ovs_mutex_lock(&mutex
);
2705 if (!bridge_exporter_enabled(di
)) {
2706 ovs_mutex_unlock(&mutex
);
2710 /* Skip BFD packets:
2711 * Bidirectional Forwarding Detection(BFD) packets are for monitoring
2712 * the tunnel link status and consumed by ovs itself. No need to
2714 * CF IETF RFC 5881, BFD control packet is the UDP packet with
2715 * destination port 3784, and BFD echo packet is the UDP packet with
2716 * destination port 3785.
2718 if (is_ip_any(flow
) &&
2719 flow
->nw_proto
== IPPROTO_UDP
&&
2720 (flow
->tp_dst
== htons(BFD_CONTROL_DEST_PORT
) ||
2721 flow
->tp_dst
== htons(BFD_ECHO_DEST_PORT
))) {
2722 ovs_mutex_unlock(&mutex
);
2726 /* Use the sampling probability as an approximation of the number
2727 * of matched packets. */
2728 packet_delta_count
= UINT32_MAX
/ di
->bridge_exporter
.probability
;
2729 if (di
->bridge_exporter
.options
->enable_tunnel_sampling
) {
2730 if (output_odp_port
== ODPP_NONE
&& flow
->tunnel
.ip_dst
) {
2732 tunnel_key
= &flow
->tunnel
;
2733 tunnel_port
= dpif_ipfix_find_tunnel_port(di
, input_odp_port
);
2735 if (output_odp_port
!= ODPP_NONE
&& output_tunnel_key
) {
2736 /* Output tunnel, output_tunnel_key must be valid. */
2737 tunnel_key
= output_tunnel_key
;
2738 tunnel_port
= dpif_ipfix_find_tunnel_port(di
, output_odp_port
);
2742 dpif_ipfix_sample(di
, &di
->bridge_exporter
.exporter
, packet
, flow
,
2744 di
->bridge_exporter
.options
->obs_domain_id
,
2745 di
->bridge_exporter
.options
->obs_point_id
,
2746 output_odp_port
, NX_ACTION_SAMPLE_DEFAULT
,
2747 tunnel_port
, tunnel_key
, ipfix_actions
);
2748 ovs_mutex_unlock(&mutex
);
2752 dpif_ipfix_flow_sample(struct dpif_ipfix
*di
, const struct dp_packet
*packet
,
2753 const struct flow
*flow
,
2754 const struct user_action_cookie
*cookie
,
2755 odp_port_t input_odp_port
,
2756 const struct flow_tnl
*output_tunnel_key
,
2757 const struct dpif_ipfix_actions
*ipfix_actions
)
2760 struct dpif_ipfix_flow_exporter_map_node
*node
;
2761 const struct flow_tnl
*tunnel_key
= NULL
;
2762 struct dpif_ipfix_port
* tunnel_port
= NULL
;
2763 odp_port_t output_odp_port
= cookie
->flow_sample
.output_odp_port
;
2764 uint32_t collector_set_id
= cookie
->flow_sample
.collector_set_id
;
2765 uint16_t probability
= cookie
->flow_sample
.probability
;
2767 /* Use the sampling probability as an approximation of the number
2768 * of matched packets. */
2769 uint64_t packet_delta_count
= USHRT_MAX
/ probability
;
2771 ovs_mutex_lock(&mutex
);
2772 node
= dpif_ipfix_find_flow_exporter_map_node(di
, collector_set_id
);
2774 if (node
->exporter
.options
->enable_tunnel_sampling
) {
2775 if (output_odp_port
== ODPP_NONE
&& flow
->tunnel
.ip_dst
) {
2777 tunnel_key
= &flow
->tunnel
;
2778 tunnel_port
= dpif_ipfix_find_tunnel_port(di
, input_odp_port
);
2780 if (output_odp_port
!= ODPP_NONE
&& output_tunnel_key
) {
2781 /* Output tunnel, output_tunnel_key must be valid. */
2782 tunnel_key
= output_tunnel_key
;
2783 tunnel_port
= dpif_ipfix_find_tunnel_port(di
, output_odp_port
);
2787 dpif_ipfix_sample(di
, &node
->exporter
.exporter
, packet
, flow
,
2789 cookie
->flow_sample
.obs_domain_id
,
2790 cookie
->flow_sample
.obs_point_id
,
2791 output_odp_port
, cookie
->flow_sample
.direction
,
2792 tunnel_port
, tunnel_key
, ipfix_actions
);
2794 ovs_mutex_unlock(&mutex
);
2798 dpif_ipfix_cache_expire(struct dpif_ipfix_exporter
*exporter
,
2799 bool forced_end
, const uint64_t export_time_usec
,
2800 const uint32_t export_time_sec
)
2802 struct ipfix_flow_cache_entry
*entry
, *next_entry
;
2803 uint64_t max_flow_start_timestamp_usec
;
2804 bool template_msg_sent
= false;
2805 enum ipfix_flow_end_reason flow_end_reason
;
2807 if (ovs_list_is_empty(&exporter
->cache_flow_start_timestamp_list
)) {
2811 max_flow_start_timestamp_usec
= export_time_usec
-
2812 1000000LL * exporter
->cache_active_timeout
;
2814 LIST_FOR_EACH_SAFE (entry
, next_entry
, cache_flow_start_timestamp_list_node
,
2815 &exporter
->cache_flow_start_timestamp_list
) {
2817 flow_end_reason
= FORCED_END
;
2818 } else if (entry
->flow_start_timestamp_usec
2819 <= max_flow_start_timestamp_usec
) {
2820 flow_end_reason
= ACTIVE_TIMEOUT
;
2821 } else if (hmap_count(&exporter
->cache_flow_key_map
)
2822 > exporter
->cache_max_flows
) {
2823 /* Enforce exporter->cache_max_flows. */
2824 flow_end_reason
= LACK_OF_RESOURCES
;
2826 /* Remaining flows haven't expired yet. */
2830 ovs_list_remove(&entry
->cache_flow_start_timestamp_list_node
);
2831 hmap_remove(&exporter
->cache_flow_key_map
,
2832 &entry
->flow_key_map_node
);
2834 /* XXX: Make frequency of the (Options) Template and Exporter Process
2835 * Statistics transmission configurable.
2836 * Cf. IETF RFC 5101 Section 4.3. and 10.3.6. */
2837 if (!template_msg_sent
2838 && (exporter
->last_template_set_time
+ IPFIX_TEMPLATE_INTERVAL
)
2839 <= export_time_sec
) {
2840 ipfix_send_template_msgs(exporter
, export_time_sec
,
2841 entry
->flow_key
.obs_domain_id
);
2842 exporter
->last_template_set_time
= export_time_sec
;
2843 template_msg_sent
= true;
2845 /* Send Exporter Process Statistics. */
2846 ipfix_send_exporter_data_msg(exporter
, export_time_sec
);
2849 /* XXX: Group multiple data records for the same obs domain id
2850 * into the same message. */
2851 ipfix_send_data_msg(exporter
, export_time_sec
, entry
, flow_end_reason
);
2857 get_export_time_now(uint64_t *export_time_usec
, uint32_t *export_time_sec
)
2859 *export_time_usec
= ipfix_now();
2861 /* The IPFIX start and end deltas are negative deltas relative to
2862 * the export time, so set the export time 1 second off to
2863 * calculate those deltas. */
2864 *export_time_sec
= DIV_ROUND_UP(*export_time_usec
, 1000000);
2868 dpif_ipfix_cache_expire_now(struct dpif_ipfix_exporter
*exporter
,
2871 uint64_t export_time_usec
;
2872 uint32_t export_time_sec
;
2874 get_export_time_now(&export_time_usec
, &export_time_sec
);
2875 dpif_ipfix_cache_expire(exporter
, forced_end
, export_time_usec
,
2880 dpif_ipfix_run(struct dpif_ipfix
*di
) OVS_EXCLUDED(mutex
)
2882 uint64_t export_time_usec
;
2883 uint32_t export_time_sec
;
2884 struct dpif_ipfix_flow_exporter_map_node
*flow_exporter_node
;
2886 ovs_mutex_lock(&mutex
);
2887 get_export_time_now(&export_time_usec
, &export_time_sec
);
2888 if (bridge_exporter_enabled(di
)) {
2889 dpif_ipfix_cache_expire(
2890 &di
->bridge_exporter
.exporter
, false, export_time_usec
,
2893 HMAP_FOR_EACH (flow_exporter_node
, node
, &di
->flow_exporter_map
) {
2894 dpif_ipfix_cache_expire(
2895 &flow_exporter_node
->exporter
.exporter
, false, export_time_usec
,
2898 ovs_mutex_unlock(&mutex
);
2902 dpif_ipfix_wait(struct dpif_ipfix
*di
) OVS_EXCLUDED(mutex
)
2904 long long int next_timeout_msec
= LLONG_MAX
;
2905 struct dpif_ipfix_flow_exporter_map_node
*flow_exporter_node
;
2907 ovs_mutex_lock(&mutex
);
2908 if (bridge_exporter_enabled(di
)) {
2909 if (ipfix_cache_next_timeout_msec(
2910 &di
->bridge_exporter
.exporter
, &next_timeout_msec
)) {
2911 poll_timer_wait_until(next_timeout_msec
);
2914 HMAP_FOR_EACH (flow_exporter_node
, node
, &di
->flow_exporter_map
) {
2915 if (ipfix_cache_next_timeout_msec(
2916 &flow_exporter_node
->exporter
.exporter
, &next_timeout_msec
)) {
2917 poll_timer_wait_until(next_timeout_msec
);
2920 ovs_mutex_unlock(&mutex
);
2924 dpif_ipfix_read_sample_actions(const struct flow
*flow
,
2925 const struct nlattr
*actions
,
2927 struct dpif_ipfix_actions
*ipfix_actions
)
2929 const struct nlattr
*a
;
2931 uint32_t probability
= 0;
2932 struct dpif_ipfix_actions sample_actions
= {0};
2934 if (actions_len
== 0) {
2938 NL_ATTR_FOR_EACH (a
, left
, actions
, actions_len
) {
2940 enum ovs_sample_attr type
= nl_attr_type(a
);
2942 case OVS_SAMPLE_ATTR_PROBABILITY
:
2943 probability
= nl_attr_get_u32(a
);
2946 case OVS_SAMPLE_ATTR_ACTIONS
:
2947 dpif_ipfix_read_actions(flow
, nl_attr_get(a
), nl_attr_get_size(a
),
2951 case OVS_SAMPLE_ATTR_UNSPEC
:
2952 case __OVS_SAMPLE_ATTR_MAX
:
2958 /* An output action inside sample action is truly an output if the sampling
2959 * probability is set to 100% */
2960 if (probability
== UINT32_MAX
&& sample_actions
.output_action
== true) {
2961 ipfix_actions
->output_action
= true;
2966 dpif_ipfix_read_actions(const struct flow
*flow
,
2967 const struct nlattr
*actions
,
2969 struct dpif_ipfix_actions
*ipfix_actions
)
2971 const struct nlattr
*a
;
2974 if (actions_len
== 0) {
2978 NL_ATTR_FOR_EACH (a
, left
, actions
, actions_len
) {
2979 enum ovs_action_attr type
= nl_attr_type(a
);
2981 case OVS_ACTION_ATTR_OUTPUT
:
2982 ipfix_actions
->output_action
= true;
2984 case OVS_ACTION_ATTR_SAMPLE
:
2985 dpif_ipfix_read_sample_actions(flow
, nl_attr_get(a
),
2986 nl_attr_get_size(a
), ipfix_actions
);
2988 case OVS_ACTION_ATTR_CLONE
:
2989 dpif_ipfix_read_actions(flow
, nl_attr_get(a
), nl_attr_get_size(a
),
2993 /* OVS_ACTION_ATTR_USERSPACE and OVS_ACTION_ATTR_RECIRC actions can
2994 * yield absolutely any kind of behavior. Let's assume that flow drops
2995 * the packet if there isn't another clear OVS_ACTION_ATTR_OUTPUT
2996 * action associated with packet */
2997 case OVS_ACTION_ATTR_USERSPACE
:
2998 case OVS_ACTION_ATTR_RECIRC
:
3000 case OVS_ACTION_ATTR_TUNNEL_POP
:
3001 case OVS_ACTION_ATTR_TUNNEL_PUSH
:
3002 case OVS_ACTION_ATTR_TRUNC
:
3003 case OVS_ACTION_ATTR_HASH
:
3004 case OVS_ACTION_ATTR_CT
:
3005 case OVS_ACTION_ATTR_CT_CLEAR
:
3006 case OVS_ACTION_ATTR_METER
:
3007 case OVS_ACTION_ATTR_SET_MASKED
:
3008 case OVS_ACTION_ATTR_SET
:
3009 case OVS_ACTION_ATTR_PUSH_VLAN
:
3010 case OVS_ACTION_ATTR_POP_VLAN
:
3011 case OVS_ACTION_ATTR_PUSH_MPLS
:
3012 case OVS_ACTION_ATTR_POP_MPLS
:
3013 case OVS_ACTION_ATTR_PUSH_ETH
:
3014 case OVS_ACTION_ATTR_POP_ETH
:
3015 case OVS_ACTION_ATTR_PUSH_NSH
:
3016 case OVS_ACTION_ATTR_POP_NSH
:
3017 case OVS_ACTION_ATTR_CHECK_PKT_LEN
:
3018 case OVS_ACTION_ATTR_UNSPEC
:
3019 case __OVS_ACTION_ATTR_MAX
: