flowprobe: add support for reporting on inbound packets
[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 /* *INDENT-OFF* */
46 typedef enum __attribute__ ((__packed__))
47 {
48   FLOW_VARIANT_IP4 = 0,
49   FLOW_VARIANT_IP6,
50   FLOW_VARIANT_L2,
51   FLOW_VARIANT_L2_IP4,
52   FLOW_VARIANT_L2_IP6,
53   FLOW_N_VARIANTS,
54 } flowprobe_variant_t;
55
56 typedef enum __attribute__ ((__packed__))
57 {
58   FLOW_DIRECTION_RX = 0,
59   FLOW_DIRECTION_TX,
60   FLOW_DIRECTION_BOTH,
61 } flowprobe_direction_t;
62 /* *INDENT-ON* */
63
64 STATIC_ASSERT (sizeof (flowprobe_variant_t) == 1,
65                "flowprobe_variant_t is expected to be 1 byte, "
66                "revisit padding in flowprobe_key_t");
67
68 #define FLOW_MAXIMUM_EXPORT_ENTRIES     (1024)
69
70 typedef struct
71 {
72   /* what to collect per variant */
73   flowprobe_record_t flags;
74   /** ipfix buffers under construction, per-worker thread */
75   vlib_buffer_t **buffers_per_worker;
76   /** frames containing ipfix buffers, per-worker thread */
77   vlib_frame_t **frames_per_worker;
78   /** next record offset, per worker thread */
79   u16 *next_record_offset_per_worker;
80 } flowprobe_protocol_context_t;
81
82 /* *INDENT-OFF* */
83 typedef struct __attribute__ ((aligned (8))) {
84   u32 rx_sw_if_index;
85   u32 tx_sw_if_index;
86   u8 src_mac[6];
87   u8 dst_mac[6];
88   u16 ethertype;
89   ip46_address_t src_address;
90   ip46_address_t dst_address;
91   u8 protocol;
92   u16 src_port;
93   u16 dst_port;
94   flowprobe_variant_t which;
95   flowprobe_direction_t direction;
96 } flowprobe_key_t;
97 /* *INDENT-ON* */
98
99 typedef struct
100 {
101   u32 sec;
102   u32 nsec;
103 } timestamp_nsec_t;
104
105 typedef struct
106 {
107   flowprobe_key_t key;
108   u64 packetcount;
109   u64 octetcount;
110   timestamp_nsec_t flow_start;
111   timestamp_nsec_t flow_end;
112   f64 last_updated;
113   f64 last_exported;
114   u32 passive_timer_handle;
115   union
116   {
117     struct
118     {
119       u16 flags;
120     } tcp;
121   } prot;
122 } flowprobe_entry_t;
123
124 /**
125  * @file
126  * @brief flow-per-packet plugin header file
127  */
128 typedef struct
129 {
130   /** API message ID base */
131   u16 msg_id_base;
132
133   flowprobe_protocol_context_t context[FLOW_N_VARIANTS];
134   u16 template_reports[FLOW_N_RECORDS];
135   u16 template_size[FLOW_N_RECORDS];
136
137   /** Time reference pair */
138   u64 nanosecond_time_0;
139   f64 vlib_time_0;
140
141   /** Per CPU flow-state */
142   u8 ht_log2len;                /* Hash table size is 2^log2len */
143   u32 **hash_per_worker;
144   flowprobe_entry_t **pool_per_worker;
145   /* *INDENT-OFF* */
146   TWT (tw_timer_wheel) ** timers_per_worker;
147   /* *INDENT-ON* */
148   u32 **expired_passive_per_worker;
149
150   flowprobe_record_t record;
151   u32 active_timer;
152   u32 passive_timer;
153   flowprobe_entry_t *stateless_entry;
154
155   bool initialized;
156   bool disabled;
157
158   u16 template_per_flow[FLOW_N_VARIANTS];
159   u8 *flow_per_interface;
160   u8 *direction_per_interface;
161
162   /** convenience vlib_main_t pointer */
163   vlib_main_t *vlib_main;
164   /** convenience vnet_main_t pointer */
165   vnet_main_t *vnet_main;
166 } flowprobe_main_t;
167
168 extern flowprobe_main_t flowprobe_main;
169 extern vlib_node_registration_t flowprobe_walker_node;
170
171 void flowprobe_flush_callback_ip4 (void);
172 void flowprobe_flush_callback_ip6 (void);
173 void flowprobe_flush_callback_l2 (void);
174 u8 *format_flowprobe_entry (u8 * s, va_list * args);
175
176 #endif
177
178 /*
179  * fd.io coding-style-patch-verification: ON
180  *
181  * Local Variables:
182  * eval: (c-set-style "gnu")
183  * End:
184  */