aboutsummaryrefslogtreecommitdiffstats
path: root/src/framework/include/nsfw_maintain_api.h
blob: 74cedf646877741c006c76b6a31eefd385cc33c7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
/*
*
* Copyright (c) 2018 Huawei Technologies Co.,Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at:
*
*     http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#ifndef _NSFW_MEM_STAT_API_H
#define _NSFW_MEM_STAT_API_H

#include "types.h"
#include "nsfw_mgr_com_api.h"
#include "compiling_check.h"

#ifdef __cplusplus
/* *INDENT-OFF* */
extern "C"{
/* *INDENT-ON* */
#endif /* __cplusplus */

/*################MEM_STAT######################*/
#define NSFW_MEM_MODULE_LEN 32
#define NSFW_MEM_NAME_LEN   64

#define OMC_PROC_MM "omc_proc_maintain"

#define MEM_STAT(module, mem_name, mem_type, mem_size)\
    nsfw_mem_stat(module, mem_name, mem_type, mem_size)

extern void nsfw_mem_stat (char *module, char *mem_name, u8 mem_type,
                           u32 mem_size);
extern void nsfw_mem_stat_print ();
/*##############################################*/

/*################SRV_CTRL######################*/
typedef enum _nsfw_srv_ctrl_state
{
  NSFW_SRV_CTRL_RESUME = 1,
  NSFW_SRV_CTRL_SUSPEND = 2
} nsfw_srv_ctrl_state;

typedef struct _nsfw_srv_ctrl_msg
{
  nsfw_srv_ctrl_state srv_state;
  u16 rsp_code;
} nsfw_srv_ctrl_msg;
extern u8 nsfw_srv_ctrl_send (nsfw_srv_ctrl_state state, u8 rsp_flag);
/*#############################################*/

/*#################RES_MGR######################*/
#define NSFW_RES_MGR_MODULE "nsfw_res_mgr"

typedef enum _nsfw_res_scan_type
{
  NSFW_RES_SCAN_ARRAY = 0,
  NSFW_RES_SCAN_SPOOL,
  NSFW_RES_SCAN_MBUF,
  NSFW_RES_SCAN_MAX
} nsfw_res_scan_type;

typedef int (*nsfw_res_free_fun) (void *pdata);

typedef struct _nsfw_res_scn_cfg
{
  u8 type;                      /*nsfw_res_scan_type */
  u8 force_free_percent;        /*if the resource free percent below this vlaue, begin to force free the element */
  u16 force_free_chk_num;       /*if the check count beyone this vlaue, call free fun release this element */
  u16 alloc_speed_factor;       /*alloc fast with higher value */

  u32 num_per_cyc;              /*define the element number in one scan cycle process and increase chk_count of every element */
  u32 total_num;                /*total number of elements */
  u32 elm_size;                 /*element size */
  u32 res_mem_offset;           /*the nsfw_res offset from the element start */

  void *data;                   /*the array addr or spool addr */
  void *mgr_ring;

  nsfw_res_free_fun free_fun;
} nsfw_res_scn_cfg;

typedef struct _nsfw_res_mgr_item_cfg
{
  nsfw_res_scn_cfg scn_cfg;
  u32 cons_head;
  u32 prod_head;
  u32 free_percent;
  u32 last_scn_idx;
  u64 force_count;
} nsfw_res_mgr_item_cfg;

#define NSFW_MAX_RES_SCAN_COUNT 256

extern u8 nsfw_res_mgr_reg (nsfw_res_scn_cfg * cfg);
extern i32 nsfw_proc_start_with_lock (u8 proc_type);
/*#############################################*/

typedef enum _nsfw_exit_code
{
  NSFW_EXIT_SUCCESS = 0,
  NSFW_EXIT_FAILED = 1,
  NSFW_EXIT_DST_ERROR = 2,
  NSFW_EXIT_TIME_OUT = 3,

  NSFW_EXIT_MAX_COM_ERR = 31,
} nsfw_exit_code;

/*#############################################*/

/*#################SOFT_PARAM##################*/
#define NSFW_SOFT_PARAM_MODULE "nsfw_soft_param"

typedef struct _nsfw_soft_param_msg
{
  u32 param_name;
  u32 rsp_code;
  u8 param_value[NSFW_MGR_MSG_BODY_LEN - sizeof (u32) - sizeof (u32)];
}
nsfw_soft_param_msg;

typedef enum _nsfw_soft_param
{
  NSFW_DBG_MODE_PARAM = 1,
  NSFW_HBT_TIMER = 2,
  NSFW_HBT_COUNT_PARAM = 3,
  NSFW_APP_EXIT_TIMER = 4,
  NSFW_SRV_RESTORE_TIMER = 5,
  NSFW_APP_RESEND_TIMER = 6,
  NSFW_APP_SEND_PER_TIME = 7,

  NSFW_MAX_SOFT_PARAM = 1024
} nsfw_soft_param;

typedef int (*nsfw_set_soft_fun) (u32 param, char *buf, u32 buf_len);
extern u8 nsfw_soft_param_reg_fun (u32 param_name, nsfw_set_soft_fun fun);
extern u8 nsfw_soft_param_reg_int (u32 param_name, u32 size, u32 min,
                                   u32 max, u64 * data);

extern void nsfw_set_soft_para (fw_poc_type proc_type, u32 para_name,
                                void *value, u32 size);

extern int nsfw_isdigitstr (const char *str);
#define NSFW_REG_SOFT_INT(_param,_data,_min, _max) nsfw_soft_param_reg_int(_param,sizeof(_data),_min,_max,(u64*)&_data)
/*#############################################*/

/*#################LOG_CONFIG##################*/
#define NSFW_LOG_CFG_MODULE "nsfw_log_cfg"

#define NSFW_MODULE_NAME_LEN 20
#define NSFW_LOG_LEVEL_LEN 10
#define NSFW_LOG_VALUE_LEN 256

typedef struct _nsfw_set_log_msg
{
  u16 rsp_code;
  char module[NSFW_MODULE_NAME_LEN];
  char log_level[NSFW_LOG_VALUE_LEN];
} nsfw_set_log_msg;
/*#############################################*/

/*################## DFX ######################*/
#define MAX_DFX_QRY_RES_LEN 28

#define SPL_DFX_RES_ALL         "all"
#define SPL_DFX_RES_QUEUE       "queue"
#define SPL_DFX_RES_CONN        "conn"
#define SPL_DFX_RES_L2TO4       "l2to4"
#define SPL_DFX_RES_UNMATCH     "version"
#define SPL_DFX_RES_SOCKT_CB    "socketcb"
#define SPL_DFX_RES_COMM_MEMPOOL "mbufpool"
#define SPL_DFX_RES_PCBLIST     "pcblist"
#define SPL_DFX_RES_ARPLIST     "arplist"

typedef enum
{
  DFX_ACTION_SNAPSHOT,
  DFX_ACTION_RST_STATS,
  DFX_ACTION_SWITCH,
  DFX_ACTION_MAX
} dfx_module_action;

typedef struct _nsfw_dfx_qry_msg
{
  dfx_module_action action;
  char resource[MAX_DFX_QRY_RES_LEN];
  char flag;                    //for snapshot print "all"
} nsfw_dfx_qry_msg;

typedef enum
{
  QUERY_ACTION_GET,
  QUERY_ACTION_MAX
} query_action;

typedef struct _nsfw_qry_msg
{
  query_action action;
  char resource[MAX_DFX_QRY_RES_LEN];
} nsfw_get_qry_msg;

/*##################DFX#########################*/

/*#################for tcpdump#####################*/

#ifndef nstack_min
#define nstack_min(a, b) (a) < (b) ? (a) : (b)
#endif

#define GET_CUR_TIME(ptime) \
    (void)clock_gettime(CLOCK_MONOTONIC, ptime);

#define TCPDUMP_MODULE "tcpdump_tool"

#define DUMP_MSG_NUM (64 * 1024)
COMPAT_PROTECT (DUMP_MSG_NUM, 64 * 1024);
#define DUMP_MSG_SIZE 128       // can not be less than 14
COMPAT_PROTECT (DUMP_MSG_SIZE, 128);

#define DEFAULT_DUMP_TIME 600
#define MAX_DUMP_TIME 86400
#define MIN_DUMP_TIME 1

#define MAX_DUMP_TASK 16
#define DUMP_HBT_INTERVAL 2
#define DUMP_HBT_CHK_INTERVAL 4
#define DUMP_TASK_HBT_TIME_OUT 30

#define DUMP_SHMEM_RIGN_NAME "tcpdump_ring"
#define DUMP_SHMEM_POOL_NAME "tcpdump_pool"

enum L2_PROTOCOL
{
  PROTOCOL_IP = 0x0800,
  PROTOCOL_ARP = 0x0806,
  PROTOCOL_RARP = 0x8035,
  PROTOCOL_OAM_LACP = 0x8809,
  INVALID_L2_PROTOCOL = 0xFFFF
};

enum L3_PROTOCOL
{
  PROTOCOL_ICMP = 1,
  PROTOCOL_TCP = 6,
  PROTOCOL_UDP = 17,
  INVALID_L3_PROTOCOL = 0xFF
};

enum DUMP_MSG_DIRECTION
{
  DUMP_SEND = 1,
  DUMP_RECV = 2,
  DUMP_SEND_RECV = 3
};

enum DUMP_MSG_TYPE
{
  START_DUMP_REQ,
  STOP_DUMP_REQ,
  TOOL_COM_HBT_REQ,

  DUMP_MSG_TYPE_RSP = 0x00010000,

  START_DUMP_RSP = START_DUMP_REQ + DUMP_MSG_TYPE_RSP,
  STOP_DUMP_RSP = STOP_DUMP_REQ + DUMP_MSG_TYPE_RSP,

  DUMP_MSG_TYPE_INVALID
};

typedef struct _nsfw_tool_hbt
{
  u32 seq;
  i16 task_id;
} nsfw_tool_hbt;

typedef struct _nsfw_tool_dump_msg
{
  u16 op_type;
  i16 task_id;
  u32 task_keep_time;
} nsfw_tool_dump_msg;

typedef struct _dump_msg_info
{
  u32 len;
  u16 direction;                // 1:SEND, 2:RECV
  u32 dump_sec;
  u32 dump_usec;
  nsfw_res res_chk;
  char buf[1];
} dump_msg_info;

typedef struct _dump_timer_info
{
  u32 seq;
  i16 task_id;
  void *interval;
  void *ptimer;
} dump_timer_info;

extern void ntcpdump_loop (void *buf, u32 buf_len, u16 direction,
                           void *eth_addr);
extern void ntcpdump (void *buf, u32 buf_len, u16 direction);

/*##############for tcpdump######################*/

#ifdef __cplusplus
/* *INDENT-OFF* */
}
/* *INDENT-ON* */
#endif /* __cplusplus */

#endif /* _NSFW_MEM_STAT_API_H  */