Allow enable/disable of checksum for cgnapt
[samplevnf.git] / VNFs / vCGNAPT / pipeline / pipeline_cgnapt.c
1 /*
2 // Copyright (c) 2017 Intel Corporation
3 //
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
7 //
8 //      http://www.apache.org/licenses/LICENSE-2.0
9 //
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.
15 */
16
17 /**
18  * @file
19  * Pipeline CG-NAPT FE Implementation.
20  *
21  * Implementation of Pipeline CG-NAPT Front End (FE).
22  * Provides CLI support.
23  * Runs on master core.
24  *
25  */
26
27 #include <cmdline_parse.h>
28 #include <cmdline_parse_num.h>
29 #include <cmdline_parse_string.h>
30 #include <cmdline_parse_ipaddr.h>
31 #include <cmdline_parse_etheraddr.h>
32
33 #include "app.h"
34 #include "pipeline_common_fe.h"
35 #include "pipeline_cgnapt.h"
36 #include "pipeline_cgnapt_common.h"
37 #include "pipeline_common_be.h"
38 #include "pipeline_cgnapt_be.h"
39 #ifdef PCP_ENABLE
40 #include "cgnapt_pcp_fe.h"
41 #endif
42
43 /**
44  * A structure defining the CG-NAPT entry that is stored on
45  * front end.
46  */
47 struct app_pipeline_cgnapt_entry {
48         struct pipeline_cgnapt_entry_key key;
49         struct app_pipeline_cgnapt_entry_params params;
50         void *entry_ptr;
51
52          TAILQ_ENTRY(app_pipeline_cgnapt_entry) node;
53 };
54
55 /**
56  * A structure defining the FE representation of a CG-NAPT pipeline
57  */
58 struct pipeline_cgnapt_t {
59         /* Parameters */
60         uint32_t n_ports_in;
61         uint32_t n_ports_out;
62
63         /* entries */
64          TAILQ_HEAD(, app_pipeline_cgnapt_entry) entries;
65         uint32_t n_entries;
66
67 };
68
69 /**
70  * Init function for CG-NAPT FE.
71  *
72  * @param params
73  *  A pointer to the pipeline params.
74  *
75  */
76 static void *pipeline_cgnapt_init(struct pipeline_params *params,
77                                         __rte_unused void *arg)
78 {
79         struct pipeline_cgnapt_t *p;
80         uint32_t size;
81
82         /* Check input arguments */
83         if ((params == NULL) ||
84                         (params->n_ports_in == 0) || (params->n_ports_out == 0))
85                 return NULL;
86
87         /* Memory allocation */
88         size = RTE_CACHE_LINE_ROUNDUP(sizeof(struct pipeline_cgnapt_t));
89         p = rte_zmalloc(NULL, size, RTE_CACHE_LINE_SIZE);
90         if (p == NULL)
91                 return NULL;
92
93         /* Initialization */
94         p->n_ports_in = params->n_ports_in;
95         p->n_ports_out = params->n_ports_out;
96
97         TAILQ_INIT(&p->entries);
98         p->n_entries = 0;
99
100         return p;
101 }
102
103 /**
104  * Function for CG-NAPT FE cleanup.
105  *
106  * @param pipeline
107  *  A pointer to the pipeline.
108  *
109  */
110 static int app_pipeline_cgnapt_free(void *pipeline)
111 {
112         struct pipeline_cgnapt_t *p = pipeline;
113
114         /* Check input arguments */
115         if (p == NULL)
116                 return -1;
117
118         /* Free resources */
119         while (!TAILQ_EMPTY(&p->entries)) {
120                 struct app_pipeline_cgnapt_entry *entry;
121
122                 entry = TAILQ_FIRST(&p->entries);
123                 TAILQ_REMOVE(&p->entries, entry, node);
124                 rte_free(entry);
125         }
126
127         rte_free(p);
128         return 0;
129 }
130
131 /**
132  * Function to print an IPv6 address
133  *
134  * @param ipv6_addr
135  *  A uint8_t array containing an IPv6 address
136  */
137 static void print_ipv6_address_u8(uint8_t ipv6_addr[16])
138 {
139         printf("Ipv6Address-%x:%x:%x:%x:%x:%x:%x:%x:%x:%x:%x:%x:%x:%x:%x:%x\n",
140                                  ipv6_addr[0], ipv6_addr[1], ipv6_addr[2], ipv6_addr[3],
141                                  ipv6_addr[4], ipv6_addr[5], ipv6_addr[6], ipv6_addr[7],
142                                  ipv6_addr[8], ipv6_addr[9], ipv6_addr[10], ipv6_addr[11],
143                                  ipv6_addr[12], ipv6_addr[13], ipv6_addr[14], ipv6_addr[15]);
144 }
145
146 /**
147  * Function to print an IPv6 address
148  *
149  * @param ipv6_addr
150  *  A uint16_t array containing an IPv6 address
151  */
152 static void print_ipv6_address_u16(uint16_t ipv6_addr[8])
153 {
154         printf("Ipv6Address-%x:%x:%x:%x:%x:%x:%x:%x\n", ipv6_addr[0],
155                                  ipv6_addr[1], ipv6_addr[2], ipv6_addr[3], ipv6_addr[4],
156                                  ipv6_addr[5], ipv6_addr[6], ipv6_addr[7]);
157 }
158
159 /**
160  * Function to print an IPv6 address
161  *
162  * @param ipv6_addr
163  *  A uint32_t array containing an IPv6 address
164  */
165 static void print_ipv6_address_u32(uint32_t ipv6_addr[4])
166 {
167         printf("Ipv6Address: %x:%x:%x:%x\n", ipv6_addr[0], ipv6_addr[1],
168                 ipv6_addr[2], ipv6_addr[3]);
169 }
170
171 /**
172  * Function to print a NAPT entry
173  *
174  * @param entry
175  *  A pointer to a NAPT entry
176  */
177 static void print_entry(const struct app_pipeline_cgnapt_entry *entry)
178 {
179         const struct pipeline_cgnapt_entry_key *key = &entry->key;
180
181         if (entry->params.type == CGNAPT_ENTRY_IPV4) {
182                 printf("CGNAPT Entry: Key = %" PRIu32 ".%" PRIu32 ".%" PRIu32
183                                          ".%" PRIu32 ":%" PRIu32 ":%" PRIu16 " => Prv = %" PRIu32
184                                          ".%" PRIu32 ".%" PRIu32 ".%" PRIu32 ":%" PRIu32
185                                          " => Pub = %" PRIu32 ".%" PRIu32 ".%" PRIu32 ".%" PRIu32
186                                          ":%" PRIu32 " => ttl = %" PRIu32 "\n",
187                                          (key->ip >> 24) & 0xFF, (key->ip >> 16) & 0xFF,
188                                          (key->ip >> 8) & 0xFF, key->ip & 0xFF, key->port,
189                                          key->pid, (entry->params.u.prv_ip >> 24) & 0xFF,
190                                          (entry->params.u.prv_ip >> 16) & 0xFF,
191                                          (entry->params.u.prv_ip >> 8) & 0xFF,
192                                          entry->params.u.prv_ip & 0xFF, entry->params.prv_port,
193                                          (entry->params.pub_ip >> 24) & 0xFF,
194                                          (entry->params.pub_ip >> 16) & 0xFF,
195                                          (entry->params.pub_ip >> 8) & 0xFF,
196                                          entry->params.pub_ip & 0xFF, entry->params.pub_port,
197                                          entry->params.ttl);
198         } else {
199                 printf("CGNAPT Entry: Key = %" PRIu32 ".%" PRIu32 ".%" PRIu32
200                                          ".%" PRIu32 ":%" PRIu32 ":%" PRIu16 " => Prv = %" PRIu32
201                                          "%" PRIu32 ":%" PRIu32 "%" PRIu32 ":%" PRIu32 "%" PRIu32
202                                          ":%" PRIu32 "%" PRIu32 ":%" PRIu32 "%" PRIu32 ":%" PRIu32
203                                          "%" PRIu32 ":%" PRIu32 "%" PRIu32 ":%" PRIu32 "%" PRIu32
204                                          ":%" PRIu32 " => Pub = %" PRIu32 ".%" PRIu32 ".%"
205                                          PRIu32 ".%" PRIu32 ":%" PRIu32 " => ttl = %" PRIu32
206                                          "\n", (key->ip >> 24) & 0xFF, (key->ip >> 16) & 0xFF,
207                                          (key->ip >> 8) & 0xFF, key->ip & 0xFF, key->port,
208                                          key->pid, entry->params.u.prv_ipv6[0],
209                                          entry->params.u.prv_ipv6[1], entry->params.u.prv_ipv6[2],
210                                          entry->params.u.prv_ipv6[3], entry->params.u.prv_ipv6[4],
211                                          entry->params.u.prv_ipv6[5], entry->params.u.prv_ipv6[6],
212                                          entry->params.u.prv_ipv6[7], entry->params.u.prv_ipv6[8],
213                                          entry->params.u.prv_ipv6[9],
214                                          entry->params.u.prv_ipv6[10],
215                                          entry->params.u.prv_ipv6[11],
216                                          entry->params.u.prv_ipv6[12],
217                                          entry->params.u.prv_ipv6[13],
218                                          entry->params.u.prv_ipv6[14],
219                                          entry->params.u.prv_ipv6[15], entry->params.prv_port,
220                                          (entry->params.pub_ip >> 24) & 0xFF,
221                                          (entry->params.pub_ip >> 16) & 0xFF,
222                                          (entry->params.pub_ip >> 8) & 0xFF,
223                                          entry->params.pub_ip & 0xFF, entry->params.pub_port,
224                                          entry->params.ttl);
225
226         }
227 }
228
229 /**
230  * Function to list NAPT entries from FE storage
231  *
232  * @param app
233  *  A pointer to pipeline app
234  * @param pipeline_id
235  *  Pipeline id
236  *
237  * @return
238  *  0 on success, negative on error.
239  */
240 static int
241 app_pipeline_cgnapt_entry_ls(struct app_params *app, uint32_t pipeline_id)
242 {
243         struct pipeline_cgnapt_t *p;
244         struct app_pipeline_cgnapt_entry *it;
245
246         p = app_pipeline_data_fe(app, pipeline_id,
247                                  (struct pipeline_type *)&pipeline_cgnapt);
248         if (p == NULL)
249                 return -EINVAL;
250
251         TAILQ_FOREACH(it, &p->entries, node)
252                         print_entry(it);
253         print_static_cgnapt_entries();
254         printf(" - end of napt fe entry list -\n");
255         return 0;
256 }
257
258 /**
259  * Function to send a debug message to BE
260  *
261  * @param app
262  *  A pointer to pipeline app
263  * @param pipeline_id
264  *  Pipeline id
265  * @param msg
266  *  debug message contents
267  *
268  * @return
269  *  0 on success, negative on error.
270  */
271 static int
272 app_pipeline_cgnapt_entry_dbg(struct app_params *app,
273                                                 uint32_t pipeline_id, uint8_t *msg)
274 {
275         struct pipeline_cgnapt_t *p;
276
277         struct pipeline_cgnapt_entry_dbg_msg_req *req;
278         struct pipeline_cgnapt_entry_dbg_msg_rsp *rsp;
279
280         /* Check input arguments */
281         if (app == NULL)
282                 return -1;
283
284         p = app_pipeline_data_fe(app, pipeline_id,
285                                  (struct pipeline_type *)&pipeline_cgnapt);
286         if (p == NULL)
287                 return -1;
288
289         /* Allocate and write request */
290         req = app_msg_alloc(app);
291         if (req == NULL)
292                 return -1;
293
294         req->type = PIPELINE_MSG_REQ_CUSTOM;
295         req->subtype = PIPELINE_CGNAPT_MSG_REQ_ENTRY_DBG;
296         req->data[0] = msg[0];
297         req->data[1] = msg[1];
298         req->data[2] = msg[2];
299
300         rsp = app_msg_send_recv(app, pipeline_id, req, MSG_TIMEOUT_DEFAULT);
301         if (rsp == NULL)
302                 return -1;
303
304         /* Read response */
305         if (rsp->status) {
306                 app_msg_free(app, rsp);
307                 printf("Error rsp->status %d\n", rsp->status);
308                 return -1;
309         }
310
311         /* Free response */
312         app_msg_free(app, rsp);
313
314         return 0;
315 }
316
317 /**
318  * Function to send a NAPT entry add message to BE
319  *
320  * @param app
321  *  A pointer to pipeline app
322  * @param pipeline_id
323  *  Pipeline id
324  * @param key
325  *  A pointer to NAPT entry key
326  * @param entry_params
327  *  A pointer to NAPT entry params
328  *
329  * @return
330  *  0 on success, negative on error.
331  */
332 int app_pipeline_cgnapt_add_entry(
333         struct app_params *app,
334         uint32_t pipeline_id,
335         struct app_pipeline_cgnapt_entry_params *entry_params)
336 {
337         struct pipeline_cgnapt_t *p;
338
339         struct pipeline_cgnapt_entry_add_msg_req *req;
340         struct pipeline_cgnapt_entry_add_msg_rsp *rsp;
341
342         /* Check input arguments */
343         if ((app == NULL) || (entry_params == NULL))
344                 return -1;
345
346         p = app_pipeline_data_fe(app, pipeline_id,
347                                  (struct pipeline_type *)&pipeline_cgnapt);
348         if (p == NULL)
349                 return -2;
350
351         /* Allocate and write request */
352         req = app_msg_alloc(app);
353         if (req == NULL)
354                 return -4;
355
356         req->type = PIPELINE_MSG_REQ_CUSTOM;
357         req->subtype = PIPELINE_CGNAPT_MSG_REQ_ENTRY_ADD;
358         memcpy(&req->data, entry_params, sizeof(*entry_params));
359
360         rsp = app_msg_send_recv(app, pipeline_id, req, MSG_TIMEOUT_DEFAULT);
361         if (rsp == NULL)
362                 return -5;
363
364         /* Message buffer free */
365         app_msg_free(app, rsp);
366         return 0;
367 }
368
369 /**
370  * Function to send a multiple NAPT entry add message to BE
371  *
372  * @param app
373  *  A pointer to pipeline app
374  * @param pipeline_id
375  *  Pipeline id
376  * @param key
377  *  A pointer to NAPT entry key
378  * @param entry_params
379  *  A pointer to multiple NAPT entry params
380  *
381  * @return
382  *  0 on success, negative on error.
383  */
384 int app_pipeline_cgnapt_addm_entry(
385         struct app_params *app,
386         uint32_t pipeline_id,
387         struct app_pipeline_cgnapt_mentry_params *entry_params)
388 {
389         struct pipeline_cgnapt_t *p;
390
391         struct pipeline_cgnapt_entry_addm_msg_req *req;
392         struct pipeline_cgnapt_entry_addm_msg_rsp *rsp;
393
394         /* Check input arguments */
395         if ((app == NULL) || (entry_params == NULL))
396                 return -1;
397
398         p = app_pipeline_data_fe(app, pipeline_id,
399                                  (struct pipeline_type *)&pipeline_cgnapt);
400         if (p == NULL)
401                 return -2;
402
403         /* Allocate and write request */
404         req = app_msg_alloc(app);
405         if (req == NULL)
406                 return -4;
407
408         req->type = PIPELINE_MSG_REQ_CUSTOM;
409         req->subtype = PIPELINE_CGNAPT_MSG_REQ_ENTRY_ADDM;
410         memcpy(&req->data, entry_params, sizeof(*entry_params));
411
412         rsp = app_msg_send_recv(app, pipeline_id, req, MSG_TIMEOUT_DEFAULT);
413         if (rsp == NULL)
414                 return -5;
415
416         /* Message buffer free */
417         app_msg_free(app, rsp);
418         return 0;
419 }
420
421 /**
422  * Function to send a NAPT entry delete message to BE
423  *
424  * @param app
425  *  A pointer to pipeline app
426  * @param pipeline_id
427  *  Pipeline id
428  * @param key
429  *  A pointer to NAPT entry key
430  *
431  * @return
432  *  0 on success, negative on error.
433  */
434 int
435 app_pipeline_cgnapt_delete_entry(struct app_params *app,
436                                  uint32_t pipeline_id,
437                                  struct pipeline_cgnapt_entry_key *key)
438 {
439         struct pipeline_cgnapt_t *p;
440
441         struct pipeline_cgnapt_entry_delete_msg_req *req;
442         struct pipeline_cgnapt_entry_delete_msg_rsp *rsp;
443
444         if (CGNAPT_DEBUG) {
445                 uint8_t *KeyP = (uint8_t *) key;
446                 int i = 0;
447
448                 printf("app_pipeline_cgnapt_delete_entry - Key: ");
449                 for (i = 0; i < (int)sizeof(*key); i++)
450                         printf(" %02x", KeyP[i]);
451                 printf(" ,KeySize %u\n", (int)sizeof(*key));
452         }
453         /* Check input arguments */
454         if ((app == NULL) || (key == NULL))
455                 return -1;
456
457         p = app_pipeline_data_fe(app, pipeline_id,
458                                  (struct pipeline_type *)&pipeline_cgnapt);
459         if (p == NULL)
460                 return -1;
461
462         /* Allocate and write request */
463         req = app_msg_alloc(app);
464         if (req == NULL)
465                 return -1;
466
467         req->type = PIPELINE_MSG_REQ_CUSTOM;
468         req->subtype = PIPELINE_CGNAPT_MSG_REQ_ENTRY_DEL;
469         memcpy(&req->key, key, sizeof(*key));
470
471         rsp = app_msg_send_recv(app, pipeline_id, req, MSG_TIMEOUT_DEFAULT);
472         if (rsp == NULL)
473                 return -1;
474
475         /* Read response */
476         if (rsp->status || !rsp->key_found) {
477                 app_msg_free(app, rsp);
478                 printf("Successfully deleted the entry\n");
479                 return 0;
480         }
481
482         /* Free response */
483         app_msg_free(app, rsp);
484
485         return 0;
486 }
487
488 /**
489  * A structure defining the entry add parse arguments.
490  */
491 struct cmd_entry_add_result {
492         cmdline_fixed_string_t p_string;
493         uint32_t p;
494         cmdline_fixed_string_t entry_string;
495         cmdline_fixed_string_t add_string;
496         cmdline_ipaddr_t prv_ip;
497         uint16_t prv_port;
498         cmdline_ipaddr_t pub_ip;
499         uint16_t pub_port;
500         uint16_t pid;
501         uint32_t ttl;
502 };
503 /**
504  * Helping function for add entry
505  *
506  * @param parsed_result
507  *  A pointer parsed add arguments
508  * @param cl
509  *  unused pointer to struct cmdline
510  * @param msg
511  *  void pointer data
512  *
513  */
514 static void
515 cmd_entry_add_parsed(void *parsed_result,
516                                         __rte_unused struct cmdline *cl, void *data)
517 {
518         struct cmd_entry_add_result *params = parsed_result;
519         struct app_params *app = data;
520         struct app_pipeline_cgnapt_entry_params ent_params;
521         int status;
522
523         if (params->prv_ip.family == AF_INET) {
524                 ent_params.type = CGNAPT_ENTRY_IPV4;
525                 ent_params.u.prv_ip =
526                                 rte_bswap32((uint32_t) params->prv_ip.addr.ipv4.s_addr);
527         } else {
528                 print_ipv6_address_u8(params->prv_ip.addr.ipv6.s6_addr);
529                 print_ipv6_address_u16(params->prv_ip.addr.ipv6.s6_addr16);
530                 print_ipv6_address_u32(params->prv_ip.addr.ipv6.s6_addr32);
531                 ent_params.type = CGNAPT_ENTRY_IPV6;
532                 memcpy(ent_params.u.prv_ipv6, params->prv_ip.addr.ipv6.s6_addr,
533                                          16);
534         }
535
536         ent_params.prv_port = params->prv_port;
537         ent_params.pub_ip =
538                         rte_bswap32((uint32_t) params->pub_ip.addr.ipv4.s_addr);
539         ent_params.pub_port = params->pub_port;
540         ent_params.prv_phy_port = params->pid;
541         ent_params.ttl = params->ttl;
542
543         status = app_pipeline_cgnapt_add_entry(app, params->p, &ent_params);
544
545         if (status != 0) {
546                 printf("CG-NAPT add multiple entry command failed, %d\n",
547                                          status);
548                 return;
549         }
550 }
551
552 static cmdline_parse_token_string_t cmd_entry_add_p_string =
553 TOKEN_STRING_INITIALIZER(struct cmd_entry_add_result, p_string,
554                          "p");
555
556 static cmdline_parse_token_num_t cmd_entry_add_p =
557 TOKEN_NUM_INITIALIZER(struct cmd_entry_add_result, p, UINT32);
558
559 static cmdline_parse_token_string_t cmd_entry_add_entry_string =
560 TOKEN_STRING_INITIALIZER(struct cmd_entry_add_result, entry_string,
561                          "entry");
562
563 static cmdline_parse_token_string_t cmd_entry_add_add_string =
564 TOKEN_STRING_INITIALIZER(struct cmd_entry_add_result, add_string,
565                          "add");
566
567 static cmdline_parse_token_ipaddr_t cmd_entry_add_prv_ip =
568 TOKEN_IPADDR_INITIALIZER(struct cmd_entry_add_result, prv_ip);
569
570 static cmdline_parse_token_num_t cmd_entry_add_prv_port =
571 TOKEN_NUM_INITIALIZER(struct cmd_entry_add_result, prv_port, UINT16);
572
573 static cmdline_parse_token_ipaddr_t cmd_entry_add_pub_ip =
574 TOKEN_IPV4_INITIALIZER(struct cmd_entry_add_result, pub_ip);
575
576 static cmdline_parse_token_num_t cmd_entry_add_pub_port =
577 TOKEN_NUM_INITIALIZER(struct cmd_entry_add_result, pub_port, UINT16);
578
579 static cmdline_parse_token_num_t cmd_entry_add_pid =
580 TOKEN_NUM_INITIALIZER(struct cmd_entry_add_result, pid, UINT16);
581
582 static cmdline_parse_token_num_t cmd_entry_add_ttl =
583 TOKEN_NUM_INITIALIZER(struct cmd_entry_add_result, ttl, UINT32);
584
585 static cmdline_parse_inst_t cmd_entry_add = {
586         .f = cmd_entry_add_parsed,
587         .data = NULL,
588         .help_str = "NAPT entry add",
589         .tokens = {
590                          (void *)&cmd_entry_add_p_string,
591                          (void *)&cmd_entry_add_p,
592                          (void *)&cmd_entry_add_entry_string,
593                          (void *)&cmd_entry_add_add_string,
594                          (void *)&cmd_entry_add_prv_ip,
595                          (void *)&cmd_entry_add_prv_port,
596                          (void *)&cmd_entry_add_pub_ip,
597                          (void *)&cmd_entry_add_pub_port,
598                          (void *)&cmd_entry_add_pid,
599                          (void *)&cmd_entry_add_ttl,
600                          NULL,
601                          },
602 };
603
604 /**
605  * A structure defining the multiple entry add parse arguments.
606  */
607 struct cmd_entry_addm_result {
608         cmdline_fixed_string_t p_string;
609         uint32_t p;
610         cmdline_fixed_string_t entry_string;
611         cmdline_fixed_string_t addm_string;
612         cmdline_ipaddr_t prv_ip;
613         uint16_t prv_port;
614         cmdline_ipaddr_t pub_ip;
615         uint16_t pub_port;
616         uint16_t pid;
617         uint32_t ttl;
618         uint32_t num_ue;
619         uint16_t prv_port_max;
620         uint16_t pub_port_max;
621 };
622
623 /**
624  * Helping function for add multiple entries
625  *
626  * @param parsed_result
627  *  A pointer parsed add arguments
628  * @param cl
629  *  unused pointer to struct cmdline
630  * @param msg
631  *  void pointer data
632  */
633 static void
634 cmd_entry_addm_parsed(void *parsed_result,
635                                         __rte_unused struct cmdline *cl, void *data)
636 {
637         struct cmd_entry_addm_result *params = parsed_result;
638         struct app_params *app = data;
639         struct app_pipeline_cgnapt_mentry_params ent_params;
640         int status;
641
642         if (params->prv_ip.family == AF_INET) {
643                 ent_params.type = CGNAPT_ENTRY_IPV4;
644                 ent_params.u.prv_ip =
645                                 rte_bswap32((uint32_t) params->prv_ip.addr.ipv4.s_addr);
646         } else {
647                 print_ipv6_address_u8(params->prv_ip.addr.ipv6.s6_addr);
648                 print_ipv6_address_u16(params->prv_ip.addr.ipv6.s6_addr16);
649                 print_ipv6_address_u32(params->prv_ip.addr.ipv6.s6_addr32);
650                 ent_params.type = CGNAPT_ENTRY_IPV6;
651                 memcpy(ent_params.u.prv_ipv6, params->prv_ip.addr.ipv6.s6_addr,
652                                          16);
653         }
654
655         ent_params.prv_port = params->prv_port;
656         ent_params.pub_ip =
657                         rte_bswap32((uint32_t) params->pub_ip.addr.ipv4.s_addr);
658         ent_params.pub_port = params->pub_port;
659         ent_params.prv_phy_port = params->pid;
660         ent_params.ttl = params->ttl;
661         ent_params.num_ue = params->num_ue;
662         ent_params.prv_port_max = params->prv_port_max;
663         ent_params.pub_port_max = params->pub_port_max;
664
665         status = app_pipeline_cgnapt_addm_entry(app, params->p, &ent_params);
666
667         if (status != 0) {
668                 printf("CG-NAPT add multiple entry command failed, %d\n",
669                                          status);
670                 return;
671         }
672 }
673
674 static cmdline_parse_token_string_t cmd_entry_add_addm_string =
675 TOKEN_STRING_INITIALIZER(struct cmd_entry_addm_result, addm_string,
676                          "addm");
677
678 static cmdline_parse_token_num_t cmd_entry_addm_prv_port =
679 TOKEN_NUM_INITIALIZER(struct cmd_entry_addm_result, prv_port_max, UINT16);
680
681 static cmdline_parse_token_num_t cmd_entry_addm_pub_port =
682 TOKEN_NUM_INITIALIZER(struct cmd_entry_addm_result, pub_port_max, UINT16);
683
684 static cmdline_parse_token_num_t cmd_entry_addm_max_ue =
685 TOKEN_NUM_INITIALIZER(struct cmd_entry_addm_result, num_ue, UINT32);
686
687 static cmdline_parse_inst_t cmd_entry_addm = {
688         .f = cmd_entry_addm_parsed,
689         .data = NULL,
690         .help_str = "NAPT entry add multiple",
691         .tokens = {
692                          (void *)&cmd_entry_add_p_string,
693                          (void *)&cmd_entry_add_p,
694                          (void *)&cmd_entry_add_entry_string,
695                          (void *)&cmd_entry_add_addm_string,
696                          (void *)&cmd_entry_add_prv_ip,
697                          (void *)&cmd_entry_add_prv_port,
698                          (void *)&cmd_entry_add_pub_ip,
699                          (void *)&cmd_entry_add_pub_port,
700                          (void *)&cmd_entry_add_pid,
701                          (void *)&cmd_entry_add_ttl,
702                          (void *)&cmd_entry_addm_max_ue,
703                          (void *)&cmd_entry_addm_prv_port,
704                          (void *)&cmd_entry_addm_pub_port,
705                          NULL,
706                          },
707 };
708
709 /**
710  * A structure defining the entry delete parse arguments.
711  */
712 struct cmd_entry_del_result {
713         cmdline_fixed_string_t p_string;
714         uint32_t p;
715         cmdline_fixed_string_t entry_string;
716         cmdline_fixed_string_t del_string;
717         cmdline_ipaddr_t ip;
718         uint16_t port;
719         uint16_t pid;
720 };
721
722 /**
723  * Helping function for delete entry
724  *
725  * @param parsed_result
726  *  A pointer parsed add arguments
727  * @param cl
728  *  unused pointer to struct cmdline
729  * @param msg
730  *  void pointer data
731  */
732 static void
733 cmd_entry_del_parsed(void *parsed_result,
734                                  __rte_unused struct cmdline *cl, void *data)
735 {
736         struct cmd_entry_del_result *params = parsed_result;
737         struct app_params *app = data;
738         struct pipeline_cgnapt_entry_key key;
739
740         int status;
741
742         /* Create entry */
743         if (params->ip.family == AF_INET)
744                 key.ip = rte_bswap32((uint32_t) params->ip.addr.ipv4.s_addr);
745         else
746                 key.ip =
747                                 rte_bswap32((uint32_t) params->ip.addr.ipv6.s6_addr32[3]);
748         key.port = params->port;
749         key.pid = params->pid;
750
751         status = app_pipeline_cgnapt_delete_entry(app, params->p, &key);
752
753         if (status != 0) {
754                 printf("CG-NAPT entry del command failed\n");
755                 return;
756         }
757 }
758
759 static cmdline_parse_token_string_t cmd_entry_del_p_string =
760 TOKEN_STRING_INITIALIZER(struct cmd_entry_del_result, p_string,
761                          "p");
762
763 static cmdline_parse_token_num_t cmd_entry_del_p =
764 TOKEN_NUM_INITIALIZER(struct cmd_entry_del_result, p, UINT32);
765
766 static cmdline_parse_token_string_t cmd_entry_del_entry_string =
767 TOKEN_STRING_INITIALIZER(struct cmd_entry_del_result, entry_string,
768                          "entry");
769
770 static cmdline_parse_token_string_t cmd_entry_del_del_string =
771 TOKEN_STRING_INITIALIZER(struct cmd_entry_del_result, del_string,
772                          "del");
773
774 static cmdline_parse_token_ipaddr_t cmd_entry_del_ip =
775 TOKEN_IPADDR_INITIALIZER(struct cmd_entry_del_result, ip);
776
777 static cmdline_parse_token_num_t cmd_entry_del_port =
778 TOKEN_NUM_INITIALIZER(struct cmd_entry_del_result, port, UINT16);
779
780 static cmdline_parse_token_num_t cmd_entry_del_pid =
781 TOKEN_NUM_INITIALIZER(struct cmd_entry_del_result, pid, UINT16);
782
783 static cmdline_parse_inst_t cmd_entry_del = {
784         .f = cmd_entry_del_parsed,
785         .data = NULL,
786         .help_str = "Entry delete",
787         .tokens = {
788                          (void *)&cmd_entry_del_p_string,
789                          (void *)&cmd_entry_del_p,
790                          (void *)&cmd_entry_del_entry_string,
791                          (void *)&cmd_entry_del_del_string,
792                          (void *)&cmd_entry_del_ip,
793                          (void *)&cmd_entry_del_port,
794                          (void *)&cmd_entry_del_pid,
795                          NULL,
796                          },
797 };
798
799 /**
800  * A structure defining the list entry parse arguments.
801  */
802 struct cmd_entry_ls_result {
803         cmdline_fixed_string_t p_string;
804         uint32_t p;
805         cmdline_fixed_string_t entry_string;
806         cmdline_fixed_string_t ls_string;
807 };
808
809 /**
810  * Helping function for list entry
811  *
812  * @param parsed_result
813  *  A pointer parsed add arguments
814  * @param cl
815  *  unused pointer to struct cmdline
816  * @param msg
817  *  void pointer data
818  */
819 static void
820 cmd_entry_ls_parsed(void *parsed_result,
821                                 __rte_unused struct cmdline *cl, void *data)
822 {
823         struct cmd_entry_ls_result *params = parsed_result;
824         struct app_params *app = data;
825         int status;
826
827         status = app_pipeline_cgnapt_entry_ls(app, params->p);
828
829         if (status != 0) {
830                 printf("Ls command failed\n");
831                 return;
832         }
833 }
834
835 static cmdline_parse_token_string_t cmd_entry_ls_p_string =
836 TOKEN_STRING_INITIALIZER(struct cmd_entry_ls_result, p_string, "p");
837
838 static cmdline_parse_token_num_t cmd_entry_ls_p =
839 TOKEN_NUM_INITIALIZER(struct cmd_entry_ls_result, p, UINT32);
840
841 static cmdline_parse_token_string_t cmd_entry_ls_entry_string =
842 TOKEN_STRING_INITIALIZER(struct cmd_entry_ls_result,
843                          entry_string, "entry");
844
845 static cmdline_parse_token_string_t cmd_entry_ls_ls_string =
846 TOKEN_STRING_INITIALIZER(struct cmd_entry_ls_result, ls_string,
847                          "ls");
848
849 static cmdline_parse_inst_t cmd_entry_ls = {
850         .f = cmd_entry_ls_parsed,
851         .data = NULL,
852         .help_str = "Entry list",
853         .tokens = {
854                          (void *)&cmd_entry_ls_p_string,
855                          (void *)&cmd_entry_ls_p,
856                          (void *)&cmd_entry_ls_entry_string,
857                          (void *)&cmd_entry_ls_ls_string,
858                          NULL,
859                          },
860 };
861
862 /**
863  * A structure defining the dbg cmd parse arguments.
864  */
865 struct cmd_entry_dbg_result {
866         cmdline_fixed_string_t p_string;
867         uint32_t p;
868         cmdline_fixed_string_t entry_string;
869         cmdline_fixed_string_t dbg_string;
870         uint8_t cmd;
871         uint8_t d1;
872         uint8_t d2;
873 };
874
875 /**
876  * Helping function for dbg cmd
877  *
878  * @param parsed_result
879  *  A pointer parsed add arguments
880  * @param cl
881  *  unused pointer to struct cmdline
882  * @param msg
883  *  void pointer data
884  */
885 static void
886 cmd_entry_dbg_parsed(void *parsed_result,
887                                  __rte_unused struct cmdline *cl, void *data)
888 {
889         struct cmd_entry_dbg_result *params = parsed_result;
890         struct app_params *app = data;
891         uint8_t msg[4];
892         int status;
893
894         msg[0] = params->cmd;
895         msg[1] = params->d1;
896         msg[2] = params->d2;
897         status = app_pipeline_cgnapt_entry_dbg(app, params->p, msg);
898
899         if (status != 0) {
900                 printf("Dbg Command failed\n");
901                 return;
902         }
903 }
904
905 static cmdline_parse_token_string_t cmd_entry_dbg_p_string =
906 TOKEN_STRING_INITIALIZER(struct cmd_entry_dbg_result, p_string, "p");
907
908 static cmdline_parse_token_num_t cmd_entry_dbg_p =
909 TOKEN_NUM_INITIALIZER(struct cmd_entry_dbg_result, p, UINT32);
910
911 static cmdline_parse_token_string_t cmd_entry_dbg_entry_string =
912 TOKEN_STRING_INITIALIZER(struct cmd_entry_dbg_result,
913                          entry_string, "entry");
914
915 static cmdline_parse_token_string_t cmd_entry_dbg_dbg_string =
916 TOKEN_STRING_INITIALIZER(struct cmd_entry_dbg_result, dbg_string,
917                          "dbg");
918
919 static cmdline_parse_token_num_t cmd_entry_dbg_cmd =
920 TOKEN_NUM_INITIALIZER(struct cmd_entry_dbg_result, cmd, UINT8);
921
922 static cmdline_parse_token_num_t cmd_entry_dbg_d1 =
923 TOKEN_NUM_INITIALIZER(struct cmd_entry_dbg_result, d1, UINT8);
924
925 static cmdline_parse_token_num_t cmd_entry_dbg_d2 =
926 TOKEN_NUM_INITIALIZER(struct cmd_entry_dbg_result, d2, UINT8);
927
928 static cmdline_parse_inst_t cmd_entry_dbg = {
929         .f = cmd_entry_dbg_parsed,
930         .data = NULL,
931         .help_str = "NAPT dbg cmd",
932         .tokens = {
933                          (void *)&cmd_entry_dbg_p_string,
934                          (void *)&cmd_entry_dbg_p,
935                          (void *)&cmd_entry_dbg_entry_string,
936                          (void *)&cmd_entry_dbg_dbg_string,
937                          (void *)&cmd_entry_dbg_cmd,
938                          (void *)&cmd_entry_dbg_d1,
939                          (void *)&cmd_entry_dbg_d2,
940                          NULL,
941                          },
942 };
943
944 /**
945  * A structure defining num ip clients cmd parse arguments.
946  */
947 struct cmd_numipcli_result {
948         cmdline_fixed_string_t p_string;
949         uint32_t p;
950         cmdline_fixed_string_t numipcli_string;
951 };
952
953 /**
954  * Helping function for printing num ip clients
955  *
956  * @param parsed_result
957  *  Unused pointer parsed add arguments
958  * @param cl
959  *  unused pointer to struct cmdline
960  * @param msg
961  *  Unused void pointer data
962  */
963 static void
964 cmd_numipcli_parsed(__rte_unused void *parsed_result,
965                                 __rte_unused struct cmdline *cl, __rte_unused void *data)
966 {
967         print_num_ip_clients();
968 }
969
970 static cmdline_parse_token_string_t cmd_numipcli_p_string =
971 TOKEN_STRING_INITIALIZER(struct cmd_numipcli_result, p_string, "p");
972
973 static cmdline_parse_token_num_t cmd_numipcli_p =
974 TOKEN_NUM_INITIALIZER(struct cmd_numipcli_result, p, UINT32);
975
976 static cmdline_parse_token_string_t cmd_numipcli_string =
977 TOKEN_STRING_INITIALIZER(struct cmd_numipcli_result,
978                          numipcli_string, "numipcli");
979
980 static cmdline_parse_inst_t cmd_numipcli = {
981         .f = cmd_numipcli_parsed,
982         .data = NULL,
983         .help_str = "Num IP Clients command",
984         .tokens = {
985                          (void *)&cmd_numipcli_p_string,
986                          (void *)&cmd_numipcli_p,
987                          (void *)&cmd_numipcli_string,
988                          NULL,
989                          },
990 };
991
992 /**
993  * Function to send a ver cmd message to BE
994  *
995  * @param app
996  *  A pointer to pipeline app
997  * @param pipeline_id
998  *  Pipeline id
999  * @param msg
1000  *  debug message contents
1001  *
1002  * @return
1003  *  0 on success, negative on error.
1004  */
1005 static int
1006 app_pipeline_cgnapt_ver(struct app_params *app,
1007                         uint32_t pipeline_id, uint8_t *msg)
1008 {
1009
1010         struct pipeline_cgnapt_t *p;
1011         struct pipeline_cgnapt_entry_dbg_msg_req *req;
1012         struct pipeline_cgnapt_entry_dbg_msg_rsp *rsp;
1013
1014         /* Check input arguments */
1015         if (app == NULL)
1016                 return -1;
1017
1018         p = app_pipeline_data_fe(app, pipeline_id,
1019                                  (struct pipeline_type *)&pipeline_cgnapt);
1020         if (p == NULL)
1021                 return -1;
1022
1023         /* Allocate and write request */
1024         req = app_msg_alloc(app);
1025         if (req == NULL)
1026                 return -1;
1027
1028         req->type = PIPELINE_MSG_REQ_CUSTOM;
1029         req->subtype = PIPELINE_CGNAPT_MSG_REQ_VER;
1030         req->data[0] = msg[0];
1031         req->data[1] = msg[1];
1032
1033         rsp = app_msg_send_recv(app, pipeline_id, req, MSG_TIMEOUT_DEFAULT);
1034         if (rsp == NULL)
1035                 return -1;
1036
1037         /* Read response */
1038         if (rsp->status) {
1039                 app_msg_free(app, rsp);
1040                 printf("Error rsp->status %d\n", rsp->status);
1041                 return -1;
1042         }
1043
1044         /* Free response */
1045         app_msg_free(app, rsp);
1046
1047         return 0;
1048 }
1049
1050 /**
1051  * A structure defining ver cmd parse arguments.
1052  */
1053 struct cmd_ver_result {
1054         cmdline_fixed_string_t p_string;
1055         uint32_t p;
1056         cmdline_fixed_string_t ver_string;
1057         uint8_t cmd;
1058         uint8_t d1;
1059 };
1060
1061 /**
1062  * Helping function for ver cmd
1063  *
1064  * @param parsed_result
1065  *  A pointer parsed add arguments
1066  * @param cl
1067  *  unused pointer to struct cmdline
1068  * @param msg
1069  *  void pointer data
1070  */
1071 static void
1072 cmd_ver_parsed(void *parsed_result, __rte_unused struct cmdline *cl, void *data)
1073 {
1074         struct cmd_ver_result *params = parsed_result;
1075         struct app_params *app = data;
1076         uint8_t msg[4];
1077         int status;
1078
1079         msg[0] = params->cmd;
1080         msg[1] = params->d1;
1081         status = app_pipeline_cgnapt_ver(app, params->p, msg);
1082
1083         if (status != 0) {
1084                 printf("Version Command failed\n");
1085                 return;
1086         }
1087 }
1088
1089 static cmdline_parse_token_string_t cmd_ver_p_string =
1090 TOKEN_STRING_INITIALIZER(struct cmd_ver_result, p_string, "p");
1091
1092 static cmdline_parse_token_num_t cmd_ver_p =
1093 TOKEN_NUM_INITIALIZER(struct cmd_ver_result, p, UINT32);
1094
1095 static cmdline_parse_token_string_t cmd_ver_string =
1096 TOKEN_STRING_INITIALIZER(struct cmd_ver_result,
1097                          ver_string, "ver");
1098
1099 static cmdline_parse_token_num_t cmd_ver_cmd =
1100 TOKEN_NUM_INITIALIZER(struct cmd_ver_result, cmd, UINT8);
1101
1102 static cmdline_parse_token_num_t cmd_ver_d1 =
1103 TOKEN_NUM_INITIALIZER(struct cmd_ver_result, d1, UINT8);
1104
1105 static cmdline_parse_inst_t cmd_ver = {
1106         .f = cmd_ver_parsed,
1107         .data = NULL,
1108         .help_str = "NAPT ver cmd",
1109         .tokens = {
1110                          (void *)&cmd_ver_p_string,
1111                          (void *)&cmd_ver_p,
1112                          (void *)&cmd_ver_string,
1113                          (void *)&cmd_ver_cmd,
1114                          (void *)&cmd_ver_d1,
1115                          NULL,
1116                          },
1117 };
1118
1119 /**
1120  * Function to send a nsp add cmd message to BE
1121  *
1122  * @param app
1123  *  A pointer to pipeline app
1124  * @param pipeline_id
1125  *  Pipeline id
1126  * @param nsp
1127  *  A pointer to struct pipeline_cgnapt_nsp_t
1128  *
1129  * @return
1130  *  0 on success, negative on error.
1131  */
1132 static int
1133 app_pipeline_cgnapt_add_nsp(struct app_params *app,
1134                                         uint32_t pipeline_id,
1135                                         struct pipeline_cgnapt_nsp_t *nsp)
1136 {
1137
1138         struct pipeline_cgnapt_t *p;
1139         struct pipeline_cgnapt_nsp_add_msg_req *req;
1140         struct pipeline_cgnapt_nsp_add_msg_rsp *rsp;
1141
1142         /* Check input arguments */
1143         if (app == NULL)
1144                 return -1;
1145
1146         printf("1st if condition\n");
1147
1148         p = app_pipeline_data_fe(app, pipeline_id,
1149                                  (struct pipeline_type *)&pipeline_cgnapt);
1150         if (p == NULL)
1151                 return -1;
1152
1153         printf("2st if condition\n");
1154         /* Allocate and write request */
1155         req = app_msg_alloc(app);
1156         if (req == NULL)
1157                 return -1;
1158
1159         printf("3st if condition\n");
1160         req->type = PIPELINE_MSG_REQ_CUSTOM;
1161         req->subtype = PIPELINE_CGNAPT_MSG_REQ_NSP_ADD;
1162         memcpy(&req->nsp, nsp, sizeof(struct pipeline_cgnapt_nsp_t));
1163
1164         rsp = app_msg_send_recv(app, pipeline_id, req, MSG_TIMEOUT_DEFAULT);
1165         if (rsp == NULL)
1166                 return -1;
1167
1168         printf("4st if condition\n");
1169         /* Read response */
1170         if (rsp->status) {
1171                 app_msg_free(app, rsp);
1172                 printf("Error rsp->status %d\n", rsp->status);
1173                 return -1;
1174         }
1175
1176         /* Free response */
1177         app_msg_free(app, rsp);
1178
1179         return 0;
1180 }
1181
1182 /**
1183  * A structure defining nsp add cmd parse arguments.
1184  */
1185 struct cmd_nsp_add_result {
1186         cmdline_fixed_string_t p_string;
1187         uint32_t p;
1188         cmdline_fixed_string_t nsp_string;
1189         cmdline_fixed_string_t add_string;
1190         cmdline_ipaddr_t ip;
1191 };
1192
1193 /**
1194  * Helping function for nsp add cmd
1195  *
1196  * @param parsed_result
1197  *  A pointer parsed add arguments
1198  * @param cl
1199  *  unused pointer to struct cmdline
1200  * @param msg
1201  *  void pointer data
1202  */
1203 static void
1204 cmd_nsp_add_parsed(void *parsed_result, __rte_unused struct cmdline *cl,
1205                          void *data)
1206 {
1207         struct cmd_nsp_add_result *params = parsed_result;
1208         struct app_params *app = data;
1209         int status;
1210         struct pipeline_cgnapt_nsp_t nsp;
1211
1212         memcpy(&nsp.prefix, &params->ip.addr.ipv6.s6_addr, 16);
1213         nsp.depth = params->ip.prefixlen;
1214         status = app_pipeline_cgnapt_add_nsp(app, params->p, &nsp);
1215         if (status != 0) {
1216                 printf("NSP ADD Command failed\n");
1217                 return;
1218         }
1219 }
1220
1221 static cmdline_parse_token_string_t cmd_add_nsp_p_string =
1222 TOKEN_STRING_INITIALIZER(struct cmd_nsp_add_result, p_string, "p");
1223
1224 static cmdline_parse_token_num_t cmd_add_nsp_p =
1225 TOKEN_NUM_INITIALIZER(struct cmd_nsp_add_result, p, UINT32);
1226
1227 static cmdline_parse_token_string_t cmd_add_nsp_string =
1228 TOKEN_STRING_INITIALIZER(struct cmd_nsp_add_result,
1229                          nsp_string, "nsp");
1230
1231 static cmdline_parse_token_string_t cmd_add_nsp_add_string =
1232 TOKEN_STRING_INITIALIZER(struct cmd_nsp_add_result,
1233                          add_string, "add");
1234
1235 static cmdline_parse_token_ipaddr_t cmd_add_nsp_ip =
1236 TOKEN_IPNET_INITIALIZER(struct cmd_nsp_add_result, ip);
1237
1238 static cmdline_parse_inst_t cmd_nsp_add = {
1239         .f = cmd_nsp_add_parsed,
1240         .data = NULL,
1241         .help_str = "NAPT NSP ADD cmd",
1242         .tokens = {
1243                          (void *)&cmd_add_nsp_p_string,
1244                          (void *)&cmd_add_nsp_p,
1245                          (void *)&cmd_add_nsp_string,
1246                          (void *)&cmd_add_nsp_add_string,
1247                          (void *)&cmd_add_nsp_ip,
1248                          NULL,
1249                          },
1250 };
1251
1252 /**
1253  * Function to send a nsp del cmd message to BE
1254  *
1255  * @param app
1256  *  A pointer to pipeline app
1257  * @param pipeline_id
1258  *  Pipeline id
1259  * @param nsp
1260  *  A pointer to struct pipeline_cgnapt_nsp_t
1261  *
1262  * @return
1263  *  0 on success, negative on error.
1264  */
1265 static int
1266 app_pipeline_cgnapt_del_nsp(struct app_params *app,
1267                                         uint32_t pipeline_id,
1268                                         struct pipeline_cgnapt_nsp_t *nsp)
1269 {
1270
1271         struct pipeline_cgnapt_t *p;
1272         struct pipeline_cgnapt_nsp_del_msg_req *req;
1273         struct pipeline_cgnapt_nsp_del_msg_rsp *rsp;
1274
1275         /* Check input arguments */
1276         if (app == NULL)
1277                 return -1;
1278
1279         p = app_pipeline_data_fe(app, pipeline_id,
1280                                  (struct pipeline_type *)&pipeline_cgnapt);
1281         if (p == NULL)
1282                 return -1;
1283
1284         /* Allocate and write request */
1285         req = app_msg_alloc(app);
1286         if (req == NULL)
1287                 return -1;
1288
1289         req->type = PIPELINE_MSG_REQ_CUSTOM;
1290         req->subtype = PIPELINE_CGNAPT_MSG_REQ_NSP_DEL;
1291         memcpy(&req->nsp, nsp, sizeof(struct pipeline_cgnapt_nsp_t));
1292
1293         rsp = app_msg_send_recv(app, pipeline_id, req, MSG_TIMEOUT_DEFAULT);
1294         if (rsp == NULL)
1295                 return -1;
1296
1297         /* Read response */
1298         if (rsp->status) {
1299                 app_msg_free(app, rsp);
1300                 printf("Error rsp->status %d\n", rsp->status);
1301                 return -1;
1302         }
1303
1304         /* Free response */
1305         app_msg_free(app, rsp);
1306
1307         return 0;
1308 }
1309
1310 /**
1311  * A structure defining nsp del cmd parse arguments.
1312  */
1313 struct cmd_nsp_del_result {
1314         cmdline_fixed_string_t p_string;
1315         uint32_t p;
1316         cmdline_fixed_string_t nsp_string;
1317         cmdline_fixed_string_t del_string;
1318         cmdline_ipaddr_t ip;
1319 };
1320
1321 /**
1322  * Helping function for nsp del cmd
1323  *
1324  * @param parsed_result
1325  *  A pointer parsed add arguments
1326  * @param cl
1327  *  unused pointer to struct cmdline
1328  * @param msg
1329  *  void pointer data
1330  */
1331 static void
1332 cmd_nsp_del_parsed(void *parsed_result, __rte_unused struct cmdline *cl,
1333                          void *data)
1334 {
1335         struct cmd_nsp_del_result *params = parsed_result;
1336         struct app_params *app = data;
1337         int status;
1338         struct pipeline_cgnapt_nsp_t nsp;
1339
1340         memcpy(&nsp.prefix, &params->ip.addr.ipv6.s6_addr, 16);
1341         nsp.depth = params->ip.prefixlen;
1342         status = app_pipeline_cgnapt_del_nsp(app, params->p, &nsp);
1343
1344         if (status != 0) {
1345                 printf("NSP DEL Command failed\n");
1346                 return;
1347         }
1348 }
1349
1350 static cmdline_parse_token_string_t cmd_del_nsp_p_string =
1351 TOKEN_STRING_INITIALIZER(struct cmd_nsp_del_result, p_string, "p");
1352
1353 static cmdline_parse_token_num_t cmd_del_nsp_p =
1354 TOKEN_NUM_INITIALIZER(struct cmd_nsp_del_result, p, UINT32);
1355
1356 static cmdline_parse_token_string_t cmd_del_nsp_string =
1357 TOKEN_STRING_INITIALIZER(struct cmd_nsp_del_result,
1358                          nsp_string, "nsp");
1359
1360 static cmdline_parse_token_string_t cmd_del_nsp_del_string =
1361 TOKEN_STRING_INITIALIZER(struct cmd_nsp_del_result,
1362                          del_string, "del");
1363
1364 static cmdline_parse_token_ipaddr_t cmd_del_nsp_ip =
1365 TOKEN_IPNET_INITIALIZER(struct cmd_nsp_del_result, ip);
1366
1367 static cmdline_parse_inst_t cmd_nsp_del = {
1368         .f = cmd_nsp_del_parsed,
1369         .data = NULL,
1370         .help_str = "NAPT NSP DEL cmd",
1371         .tokens = {
1372                          (void *)&cmd_del_nsp_p_string,
1373                          (void *)&cmd_del_nsp_p,
1374                          (void *)&cmd_del_nsp_string,
1375                          (void *)&cmd_del_nsp_del_string,
1376                          (void *)&cmd_del_nsp_ip,
1377                          NULL,
1378                          },
1379 };
1380
1381 /**
1382  * A structure defining the cgnapt stats cmd parse arguments.
1383  */
1384 struct cmd_cgnapt_stats_result {
1385         cmdline_fixed_string_t p_string;
1386         cmdline_fixed_string_t cgnapt_string;
1387         cmdline_fixed_string_t stats_string;
1388 };
1389
1390 /**
1391  * Helping function for cgnapt stats cmd
1392  *
1393  * @param parsed_result
1394  *  A pointer parsed add arguments
1395  * @param cl
1396  *  unused pointer to struct cmdline
1397  * @param msg
1398  *  void pointer data
1399  */
1400 static void
1401 cmd_cgnapt_stats_parsed(
1402         __rte_unused void *parsed_result,
1403         __rte_unused struct cmdline *cl,
1404         __rte_unused void *data)
1405 {
1406         all_cgnapt_stats();
1407 }
1408
1409 static cmdline_parse_token_string_t cmd_cgnapt_stats_p_string =
1410 TOKEN_STRING_INITIALIZER(struct cmd_cgnapt_stats_result, p_string, "p");
1411
1412 static cmdline_parse_token_string_t cmd_cgnapt_stats_cgnapt_string =
1413 TOKEN_STRING_INITIALIZER(struct cmd_cgnapt_stats_result,
1414                                 cgnapt_string, "cgnapt");
1415
1416 static cmdline_parse_token_string_t cmd_cgnapt_stats_stats_string =
1417 TOKEN_STRING_INITIALIZER(struct cmd_cgnapt_stats_result, stats_string,
1418                                 "stats");
1419
1420 static cmdline_parse_inst_t cmd_stats = {
1421         .f = cmd_cgnapt_stats_parsed,
1422         .data = NULL,
1423         .help_str = "CGNAPT stats cmd",
1424         .tokens = {
1425                 (void *)&cmd_cgnapt_stats_p_string,
1426                 (void *)&cmd_cgnapt_stats_cgnapt_string,
1427                 (void *)&cmd_cgnapt_stats_stats_string,
1428                 NULL,
1429         },
1430 };
1431
1432 /**
1433  * A structure defining the cgnapt clear stats cmd parse arguments.
1434  */
1435 struct cmd_cgnapt_clear_stats_result {
1436         cmdline_fixed_string_t p_string;
1437         cmdline_fixed_string_t cgnapt_string;
1438         cmdline_fixed_string_t clear_string;
1439         cmdline_fixed_string_t stats_string;
1440 };
1441
1442 /**
1443  * Helping function for cgnapt clear stats cmd
1444  *
1445  * @param parsed_result
1446  *  A pointer parsed add arguments
1447  * @param cl
1448  *  unused pointer to struct cmdline
1449  * @param msg
1450  *  void pointer data
1451  */
1452 static void
1453 cmd_cgnapt_clear_stats_parsed(
1454         __rte_unused void *parsed_result,
1455         __rte_unused struct cmdline *cl,
1456         __rte_unused void *data)
1457 {
1458         all_cgnapt_clear_stats();
1459 }
1460
1461 static cmdline_parse_token_string_t cmd_cgnapt_clear_stats_p_string =
1462 TOKEN_STRING_INITIALIZER(struct cmd_cgnapt_clear_stats_result, p_string, "p");
1463
1464 static cmdline_parse_token_string_t cmd_cgnapt_clear_stats_cgnapt_string =
1465 TOKEN_STRING_INITIALIZER(struct cmd_cgnapt_clear_stats_result,
1466                                 cgnapt_string, "cgnapt");
1467
1468 static cmdline_parse_token_string_t cmd_cgnapt_clear_stats_clear_string =
1469 TOKEN_STRING_INITIALIZER(struct cmd_cgnapt_clear_stats_result,
1470                                 clear_string, "clear");
1471
1472 static cmdline_parse_token_string_t cmd_cgnapt_clear_stats_stats_string =
1473 TOKEN_STRING_INITIALIZER(struct cmd_cgnapt_clear_stats_result, stats_string,
1474                                 "stats");
1475
1476 static cmdline_parse_inst_t cmd_clear_stats = {
1477          .f = cmd_cgnapt_clear_stats_parsed,
1478          .data = NULL,
1479          .help_str = "CGNAPT clear stats cmd",
1480          .tokens = {
1481                                 (void *)&cmd_cgnapt_clear_stats_p_string,
1482                                 (void *)&cmd_cgnapt_clear_stats_cgnapt_string,
1483                                 (void *)&cmd_cgnapt_clear_stats_clear_string,
1484                                 (void *)&cmd_cgnapt_clear_stats_stats_string,
1485                                 NULL,
1486                                 },
1487 };
1488
1489
1490 static cmdline_parse_ctx_t pipeline_cmds[] = {
1491         (cmdline_parse_inst_t *) &cmd_entry_add,
1492         (cmdline_parse_inst_t *) &cmd_entry_del,
1493         (cmdline_parse_inst_t *) &cmd_entry_ls,
1494         (cmdline_parse_inst_t *) &cmd_entry_dbg,
1495         (cmdline_parse_inst_t *) &cmd_entry_addm,
1496         (cmdline_parse_inst_t *) &cmd_ver,
1497         (cmdline_parse_inst_t *) &cmd_nsp_add,
1498         (cmdline_parse_inst_t *) &cmd_nsp_del,
1499         (cmdline_parse_inst_t *) &cmd_numipcli,
1500         #ifdef PCP_ENABLE
1501         (cmdline_parse_inst_t *) &cmd_pcp,
1502         #endif
1503         (cmdline_parse_inst_t *) &cmd_stats,
1504         (cmdline_parse_inst_t *) &cmd_clear_stats,
1505         NULL,
1506 };
1507
1508 static struct pipeline_fe_ops pipeline_cgnapt_fe_ops = {
1509         .f_init = pipeline_cgnapt_init,
1510         .f_free = app_pipeline_cgnapt_free,
1511         .cmds = pipeline_cmds,
1512 };
1513
1514 struct pipeline_type pipeline_cgnapt = {
1515         .name = "CGNAPT",
1516         .be_ops = &pipeline_cgnapt_be_ops,
1517         .fe_ops = &pipeline_cgnapt_fe_ops,
1518 };