misc: remove GNU Indent directives
[vpp.git] / src / plugins / flowprobe / flowprobe.h
1 /*
2  * flowprobe.h - ipfix probe plug-in header file
3  *
4  * Copyright (c) 2016 Cisco and/or its affiliates.
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at:
8  *
9  *     http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */
17 #ifndef __included_flowprobe_h__
18 #define __included_flowprobe_h__
19
20 #include <vnet/vnet.h>
21 #include <vnet/ip/ip.h>
22 #include <vnet/ethernet/ethernet.h>
23
24 #include <vppinfra/hash.h>
25 #include <vppinfra/error.h>
26 #include <vnet/ipfix-export/flow_report.h>
27 #include <vnet/ipfix-export/flow_report_classify.h>
28 #include <vppinfra/tw_timer_2t_1w_2048sl.h>
29
30 /* Default timers in seconds */
31 #define FLOWPROBE_TIMER_ACTIVE   (15)
32 #define FLOWPROBE_TIMER_PASSIVE  120    // XXXX: FOR TESTING (30*60)
33 #define FLOWPROBE_LOG2_HASHSIZE  (18)
34
35 typedef enum
36 {
37   FLOW_RECORD_L2 = 1 << 0,
38   FLOW_RECORD_L3 = 1 << 1,
39   FLOW_RECORD_L4 = 1 << 2,
40   FLOW_RECORD_L2_IP4 = 1 << 3,
41   FLOW_RECORD_L2_IP6 = 1 << 4,
42   FLOW_N_RECORDS = 1 << 5,
43 } flowprobe_record_t;
44
45 typedef enum __attribute__ ((__packed__))
46 {
47   FLOW_VARIANT_IP4 = 0,
48   FLOW_VARIANT_IP6,
49   FLOW_VARIANT_L2,
50   FLOW_VARIANT_L2_IP4,
51   FLOW_VARIANT_L2_IP6,
52   FLOW_N_VARIANTS,
53 } flowprobe_variant_t;
54
55 typedef enum __attribute__ ((__packed__))
56 {
57   FLOW_DIRECTION_RX = 0,
58   FLOW_DIRECTION_TX,
59   FLOW_DIRECTION_BOTH,
60 } flowprobe_direction_t;
61
62 STATIC_ASSERT (sizeof (flowprobe_variant_t) == 1,
63                "flowprobe_variant_t is expected to be 1 byte, "
64                "revisit padding in flowprobe_key_t");
65
66 #define FLOW_MAXIMUM_EXPORT_ENTRIES     (1024)
67
68 typedef struct
69 {
70   /* what to collect per variant */
71   flowprobe_record_t flags;
72   /** ipfix buffers under construction, per-worker thread */
73   vlib_buffer_t **buffers_per_worker;
74   /** frames containing ipfix buffers, per-worker thread */
75   vlib_frame_t **frames_per_worker;
76   /** next record offset, per worker thread */
77   u16 *next_record_offset_per_worker;
78 } flowprobe_protocol_context_t;
79
80 typedef struct __attribute__ ((aligned (8))) {
81   u32 rx_sw_if_index;
82   u32 tx_sw_if_index;
83   u8 src_mac[6];
84   u8 dst_mac[6];
85   u16 ethertype;
86   ip46_address_t src_address;
87   ip46_address_t dst_address;
88   u8 protocol;
89   u16 src_port;
90   u16 dst_port;
91   flowprobe_variant_t which;
92   flowprobe_direction_t direction;
93 } flowprobe_key_t;
94
95 typedef struct
96 {
97   u32 sec;
98   u32 nsec;
99 } timestamp_nsec_t;
100
101 typedef struct
102 {
103   flowprobe_key_t key;
104   u64 packetcount;
105   u64 octetcount;
106   timestamp_nsec_t flow_start;
107   timestamp_nsec_t flow_end;
108   f64 last_updated;
109   f64 last_exported;
110   u32 passive_timer_handle;
111   union
112   {
113     struct
114     {
115       u16 flags;
116     } tcp;
117   } prot;
118 } flowprobe_entry_t;
119
120 /**
121  * @file
122  * @brief flow-per-packet plugin header file
123  */
124 typedef struct
125 {
126   /** API message ID base */
127   u16 msg_id_base;
128
129   flowprobe_protocol_context_t context[FLOW_N_VARIANTS];
130   u16 template_reports[FLOW_N_RECORDS];
131   u16 template_size[FLOW_N_RECORDS];
132
133   /** Time reference pair */
134   u64 nanosecond_time_0;
135   f64 vlib_time_0;
136
137   /** Per CPU flow-state */
138   u8 ht_log2len;                /* Hash table size is 2^log2len */
139   u32 **hash_per_worker;
140   flowprobe_entry_t **pool_per_worker;
141   TWT (tw_timer_wheel) ** timers_per_worker;
142   u32 **expired_passive_per_worker;
143
144   flowprobe_record_t record;
145   u32 active_timer;
146   u32 passive_timer;
147   flowprobe_entry_t *stateless_entry;
148
149   bool initialized;
150   bool disabled;
151
152   u16 template_per_flow[FLOW_N_VARIANTS];
153   u8 *flow_per_interface;
154   u8 *direction_per_interface;
155
156   /** convenience vlib_main_t pointer */
157   vlib_main_t *vlib_main;
158   /** convenience vnet_main_t pointer */
159   vnet_main_t *vnet_main;
160 } flowprobe_main_t;
161
162 extern flowprobe_main_t flowprobe_main;
163 extern vlib_node_registration_t flowprobe_walker_node;
164
165 void flowprobe_delete_by_index (u32 my_cpu_number, u32 poolindex);
166
167 void flowprobe_flush_callback_ip4 (void);
168 void flowprobe_flush_callback_ip6 (void);
169 void flowprobe_flush_callback_l2 (void);
170 u8 *format_flowprobe_entry (u8 * s, va_list * args);
171
172 #endif
173
174 /*
175  * fd.io coding-style-patch-verification: ON
176  *
177  * Local Variables:
178  * eval: (c-set-style "gnu")
179  * End:
180  */