Initial commit of vpp code.
[vpp.git] / vnet / vnet / vcgn / spp_platform_trace_log.h
1 /*
2  *------------------------------------------------------------------
3  * spp_platform_trace_log.h
4  *
5  * Copyright (c) 2009-2013 Cisco and/or its affiliates.
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at:
9  *
10  *     http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  *------------------------------------------------------------------
18  */
19
20 #ifndef __SPP_PLATFORM_TRACE_LOG_H__ 
21 #define __SPP_PLATFORM_TRACE_LOG_H__ 
22
23 #include <stdio.h>
24 #include <vppinfra/vec.h>
25 #include <vppinfra/bitmap.h>
26 #include <vppinfra/hash.h>
27 #include <vppinfra/pool.h>
28 #include <vppinfra/clib.h>
29
30 #include "spp_ctx.h"
31 #include "spp_timers.h"
32
33
34 typedef enum {
35     SPP_LOG_LTRACE,
36     SPP_LOG_MAX
37 } spp_log_type_t;
38
39 typedef struct {
40     u32 num_traces;
41 } spp_trace_log_hdr_t;
42
43 typedef struct {
44     u16 error_code;
45     u16 num_args;
46     u32 arg[0];
47 } spp_trace_log_t;
48
49 #define DUMP_PKT_IDX 61
50 #define OCTEON_SENSOR_READ 62
51
52 typedef enum {
53     CNAT_ERROR_SUCCESS,
54     CNAT_NO_CONFIG_ERROR,
55     CNAT_NO_VRF_RUN_ERROR,
56     CNAT_NO_POOL_FOR_ANY_ERROR,
57     CNAT_NO_PORT_FOR_ANY_ERROR,
58     CNAT_BAD_INUSE_ANY_ERROR,
59     CNAT_NOT_FOUND_ANY_ERROR,
60     CNAT_INV_PORT_FOR_DIRECT_ERROR,
61     CNAT_BAD_INUSE_DIRECT_ERROR,
62     CNAT_NOT_FOUND_DIRECT_ERROR,
63     CNAT_OUT_OF_PORT_LIMIT_ERROR,
64     CNAT_MAIN_DB_CREATE_ERROR,
65     CNAT_LOOKUP_ERROR,
66     CNAT_INDEX_MISMATCH_ERROR,
67     CNAT_PACKET_DROP_ERROR,
68     CNAT_INV_UNUSED_USR_INDEX,
69     CNAT_INVALID_VRFMAP_INDEX,
70     CNAT_USER_OUT_OF_PORTS,
71     CNAT_EXT_PORT_THRESH_EXCEEDED,
72     CNAT_EXT_PORT_THRESH_NORMAL,
73     CNAT_NO_EXT_PORT_AVAILABLE,
74     CNAT_SESSION_THRESH_EXCEEDED,
75     CNAT_SESSION_THRESH_NORMAL,
76     WQE_ALLOCATION_ERROR,
77     ERROR_PKT_DROPPED,
78     SYSMGR_PD_KEY_CREATION_ERROR,
79     SYSMGR_PD_SHMEM_ID_ERROR,
80     SYSMGR_PD_SHMEM_ATTACH_ERROR,
81     OCTEON_CKHUM_SKIPPED,
82     PK0_SEND_STATUS,
83     CMD_BUF_ALLOC_ERR,
84     SPP_CTX_ALLOC_FAILED,
85     SPP_MAX_DISPATCH_REACHED,
86     HA_SIGCHILD_RECV,
87     SIGACTION_ERR,
88     HA_INVALID_SEQ_OR_CONFIG_OR_TYPE,
89     NODE_CREATION_ERROR,
90     CNAT_CLI_INVALID_INPUT, /* new adds as part of CSCto04510, see sub codes below */
91     CNAT_DUMMY_HANDLER_HIT, /* Has sub codes , see spp_dummy_handler_sub_cdes_t */
92     CNAT_CONFIG_ERROR, /* has subcodes-see spp_config_error_sub_codes_t below */
93     CNAT_NFV9_ERROR, /* Has sub codes see spp_nfv9_error_sub_codes_t below */
94     CNAT_CMVX_TWSI_READ_WRITE_FAIL, /* Hassub codes see spp_cmvx_error_sub_codes_t */
95     CNAT_TEMP_SENSOR_TIMEOUT,
96     CNAT_TEMP_SENSOR_DATA_MISMATCH,
97     CNAT_TEMP_SENSOR_CONFIG_FAILED,
98     HA_APP_NOT_RESPONDING,
99     HA_DATA_PATH_TEST_FAILED,
100     CNAT_WRONG_PORT_ALLOC_TYPE,
101     CNAT_NEW_PORT_ALLOC_ERROR,
102     CNAT_INVALID_INDEX_TO_FREE_PORT,
103     CNAT_DELETE_DB_ENTRY_NO_PORTMAP,
104     CNAT_MAIN_DB_LIMIT_ERROR,
105     CNAT_USER_DB_LIMIT_ERROR,
106     CNAT_FRAG_DB_ERROR, /* see spp_frag_db_error_sub_codes_t below */
107
108     DROP_PKT_DUMP,
109     CNAT_NAT64_SYSTEM_LIMIT_ERROR,
110     CNAT_ERROR_MAX
111 } spp_error_codes_t;
112
113 typedef enum {
114
115     TCP_MSS_INVALID_IVRF = 10, /* 1 param - vrf id */
116     NFV9_LOG_INVALID_IP_OR_PORT = 20, /* 2 params - nfv9 server ip and port */
117     NFV9_LOG_INVALID_PARAMS_OTHERS, /* 3 params, ref rate, time out, path mtu */
118     NFV9_LOG_PATH_MTU_TOO_SMALL, /* 1 param, path mtu passed */
119     NFV9_LOG_CANNOT_ADD_VRF_NOT_FOUND, /* 1 param, in vrf id */
120
121     VRF_MAP_ADDR_POOL_START_ADDR_GT_END_ADDR = 30, /* 2 params, start and end addr */
122     VRF_MAP_ADDR_POOL_ADDR_POOL_TOO_LARGE, /* 2 params, start and end addr */
123     VRF_MAP_ADDR_POOL_INVALID_IN_OR_OUT_VRF, /* 2 params, in vrf and out vrf */
124     VRF_MAP_ADDR_POOL_TOO_LARGE_FOR_CORE, /* 2 params, pool size, core instance */
125     VRF_MAP_DEL_POOL_START_ADDR_GT_END_ADDR, /* 2 params, start and end addr */
126     VRF_MAP_DEL_POOL_ADDR_POOL_NOT_FOUND, /* 2 params, start and end addr */
127     VRF_MAP_DEL_POOL_VRF_MAP_EMPTY, /* 2 params, start and end addr */
128
129     ADD_SVI_ADDR_INVALID_VRF = 40, /* 2 params, vrf passed and ipv4 addr */
130     ADD_SVI_INDEX_INVALID_VRF, /* 2 params, vrf, uidb_index */
131
132     MAPPED_STAT_PORT_INVALID_OUTPUT_PARAMS = 50,
133     /* 3 params, out vrf, out ip, out port */
134     MAPPED_STAT_PORT_UDP_PORT_POLARITY_MISMATCH, /* 2 params, in port and out port */
135     MAPPED_STAT_PORT_IN_VRF_MAP_EMPTY, /* 1 param, in vrf id passed */
136     MAPPED_STAT_PORT_VRF_MAP_NOT_IN_S_RUN, /* 1 param, vrf map status */
137     MAPPED_STAT_PORT_INVALID_OUT_VRF_ID, /* 1 param, out vrf id passed */
138     MAPPED_STAT_PORT_FAILED_TO_ADD_STAT_PORT, /* 4 params, in vrf, in ip, in port, error code */
139
140    STAT_PORT_INVALID_IN_PARAMS = 60, /* 4 params, in vrf, in ip, in port, proto */
141    STAT_PORT_FAILED_TO_ADD_STAT_PORT, /* 4 params, in vrf, in ip, in port, error code */
142    STAT_PORT_CONFIG_IN_USE, /* 4 params, in vrf, in ip, in port, proto */
143
144    DEL_STAT_PORT_IN_VRF_MAP_EMPTY = 70, /* 1 param, in vrf id passed */
145    DEL_STAT_PORT_INVALID_IN_PARAMS, /* 4 params, in vrf, in ip, in port, proto */
146    DEL_STAT_PORT_CANNOT_DELETE_NO_ENTRY, /* 4 params, in vrf, in ip, in port, proto */
147    DEL_STAT_PORT_CANNOT_DELETE_NOT_STATIC_PORT, /* 4 params, in vrf, in ip, in port, proto*/
148
149    XLAT_SVI_CFG_INVALID_INDEX = 80,   /* 1 param - uidb_index */
150    XLAT_WRONG_V6_PREFIX_MASK, /* 1 param - v6 prefix mask */
151    XLAT_INVALID_XLAT_ID_ERROR, /* 1 param - id */
152
153    V6RD_INVALID_6RD_ID_ERROR = 90, /*1 param - id */
154    MAPE_INVALID_MAPE_ID_ERROR = 100 /* param - id */
155 } spp_config_error_sub_codes_t;
156
157 typedef enum {
158     CONFIG_DUMMY,
159     CONFIG_DUMMY_MAX,
160     SHOW_DUMMY,
161     SHOW_DUMMY_MAX,
162     DEBUG_DUMMY,
163     DEBUG_DUMMY_MAX
164 } spp_dummy_handler_sub_cdes_t;
165
166 typedef enum {
167     CMVX_READ,
168     CMVX_WRITE
169 } spp_cmvx_error_sub_codes_t;
170
171 typedef enum {
172     FRAG_DB_INVALID_BUCKET,
173     FRAG_DB_NO_ENTRY
174 } spp_frag_db_error_sub_codes_t;
175
176 typedef enum {
177     CLI_INVALID_PAYLOAD_SIZE,
178     CLI_INVALID_MSG_ID
179 } spp_cli_error_sub_codes_t;
180
181 typedef enum {
182     NFV9_DOWNSTREAM_CONGESTION,
183     NFV9_FAILED_TO_CREATE_CONTEXT
184 } spp_nfv9_error_sub_codes_t;
185
186 typedef struct spp_cnat_logger_tbl_t_ {
187     u16        error_code;      // The thread id stored by software
188     u16        num_args;
189     u16        rate_limit_time;   // If we need to rate_limit logging
190     u8         param_name[7][32];// Parameter name for debug purposes
191 } spp_cnat_logger_tbl_t;
192
193 extern spp_cnat_logger_tbl_t spp_cnat_logger_table[];
194
195 /*
196  * This corresponds to the length of the IMETRO SHIM Header for RODDICK
197  * For non-roddick cases, introduce an Ethernet header as well
198  */
199 #if defined(RODDICK)
200 #define SPP_TRACE_LOG_SHIM_HDR_OFFSET   8
201 #define SPP_TRACE_LOG_ENCAPS_OFFSET  0
202 #else
203 #define SPP_TRACE_LOG_SHIM_HDR_OFFSET   0
204 #define SPP_TRACE_LOG_ENCAPS_OFFSET 16
205 #endif
206
207 #define SPP_LOG_TRACE_HEADER_LENGTH \
208             (sizeof(spp_trace_log_hdr_t))
209
210
211 #define SPP_TRACE_LOG_IP_HDR_OFFSET \
212             (SPP_TRACE_LOG_ENCAPS_OFFSET + \
213              SPP_TRACE_LOG_SHIM_HDR_OFFSET)
214
215
216 #define SPP_TRACE_LOG_UDP_HDR_OFFSET \
217     (SPP_TRACE_LOG_IP_HDR_OFFSET + sizeof(ipv4_header))
218
219 #define SPP_TRACE_LOG_HDR_OFFSET \
220     (SPP_TRACE_LOG_UDP_HDR_OFFSET + sizeof(udp_hdr_type_t))
221
222 #define SPP_TRACE_LOG_RECORD_LENGTH  4
223
224 /*
225  * Let us put the maximum length of the log data to be 1400
226  */
227 #define SPP_TRACE_LOG_MAX_PKT_LENGTH 800
228
229 /* Structures and defines to store log info for MSC */
230 #define SPP_TRACE_LOG_INVALID_LOGGING_INDEX  0xffffffff
231
232 /*
233  * This structure stores the  Logging information on per LOG TYPE
234  *  basis. This structure is allocated from a pool and index
235  * to this structure based on log type
236  */
237 typedef struct {
238     /*
239      * This field determines the maximum size of the Netflow V9 information
240      * that can be stored in a logging packet
241      */
242     u16 max_length_minus_max_record_size;
243
244     u32 sequence_num; /* Sequence number of the logging packet */
245     u32 last_pkt_sent_count;
246     u16 pkt_length;         /* Length of the currently NFv9 information */
247     u16 log_record_length;  /* Length of add record */
248     u16 total_record_length; /* number of trace records */
249     u16 total_record_count;
250     spp_log_type_t log_type;
251     /*
252      * current logging context
253      */
254     spp_ctx_t *current_logging_context;
255
256     /*
257      * Timestamp in UNIX seconds corresponding to when the current
258      * logging packet was created
259      */
260     u32 current_logging_context_timestamp;
261
262     /*
263      * Queued logging context waiting to be sent to the l3 infra node
264      */
265     spp_ctx_t *queued_logging_context;
266
267     /*
268      * Headers corresponding to various records in this
269      * current nfv9 logging context
270      */
271     spp_trace_log_t              *log_record;
272     spp_trace_log_hdr_t          *log_header;
273     u8                            *next_data_ptr;
274
275 } spp_trace_log_info_t;
276
277 typedef struct {
278     /*
279      * spp_ctx_alloc() call failed
280      */
281     u64 spp_trace_log_context_creation_fail_count;
282
283     /*
284      * Cannot send the existing logging pkt, so cannot create
285      * any additional packets for logging purposes
286      */
287     u64 spp_trace_log_context_creation_deferred_count;
288
289     /*
290      * Cannot send the existing logging pkt due to cnat_rewrite_output
291      * superframe being full.
292      */
293     u64 spp_trace_log_downstream_constipation_count;
294 } spp_global_counters_t;
295
296
297 /*
298  * Global structure for SPP LOGS 
299  */
300 typedef struct {
301     /* A timer structure to periodically send log packets
302      * that have been waiting to be full for a long time.  This will
303      * ensure event/error logs don't get delayed too much before they
304      * are sent to the MSC.
305      */
306     spp_timer_t log_timer;
307
308     /*
309      * Node index corresponding to the infra L3 output node
310      * to which the nfv9 logging node will send the packet
311      */
312     u16 spp_trace_log_disp_node_index;
313
314     /*
315      * Whether we have initialized the NFv9 information
316      */
317     u8 spp_trace_log_init_done;
318
319     /*
320      * pool index in global pool based on log type
321      */
322     u32 spp_log_pool_index[SPP_LOG_MAX];
323
324 } spp_trace_log_global_info_t;
325
326
327 extern spp_timer_t sensor_timer; 
328 extern spp_trace_log_info_t spp_default_trace_log_info;
329 extern spp_trace_log_info_t *spp_trace_log_info_pool;
330
331 extern spp_trace_log_global_info_t  spp_trace_log_global_info;
332
333 void spp_trace_logger(u16 error_code, u16 num_args, u32 *arg);
334 void spp_trace_log_init(void);
335 void init_trace_log_buf_pool(void);
336 void spp_printf(u16 error_code, u16 num_args, u32 *arg);
337
338 /*
339  * The following 2 functions are temporary hacks until
340  * we have RTC support from the PD nodes
341  */
342 inline
343 u32 spp_trace_log_get_sys_up_time_in_ms (void);
344
345 inline
346 u32 spp_trace_log_get_unix_time_in_seconds (void);
347
348 enum {
349     TEMPERATURE_SENSOR_TEST_MODE,
350     TEMPERATURE_SENSOR_QUIET_MODE,
351 };
352
353 extern int temperature_read_blocked;
354
355 void read_octeon_sensors(u8 mode);
356 void Init_temperature_sensors();
357 #endif /* __SPP_PLATFORM_TRACE_LOG_H__ */