update userguide alignment
[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   #ifdef CGNAPT_DBG_PRNT
479                     printf("Successfully deleted the entry\n");
480                 #endif
481                 return 0;
482         }
483
484         /* Free response */
485         app_msg_free(app, rsp);
486
487         return 0;
488 }
489
490 /**
491  * A structure defining the entry add parse arguments.
492  */
493 struct cmd_entry_add_result {
494         cmdline_fixed_string_t p_string;
495         uint32_t p;
496         cmdline_fixed_string_t entry_string;
497         cmdline_fixed_string_t add_string;
498         cmdline_ipaddr_t prv_ip;
499         uint16_t prv_port;
500         cmdline_ipaddr_t pub_ip;
501         uint16_t pub_port;
502         uint16_t pid;
503         uint32_t ttl;
504 };
505 /**
506  * Helping function for add entry
507  *
508  * @param parsed_result
509  *  A pointer parsed add arguments
510  * @param cl
511  *  unused pointer to struct cmdline
512  * @param msg
513  *  void pointer data
514  *
515  */
516 static void
517 cmd_entry_add_parsed(void *parsed_result,
518                                         __rte_unused struct cmdline *cl, void *data)
519 {
520         struct cmd_entry_add_result *params = parsed_result;
521         struct app_params *app = data;
522         struct app_pipeline_cgnapt_entry_params ent_params;
523         int status;
524
525         if (params->prv_ip.family == AF_INET) {
526                 ent_params.type = CGNAPT_ENTRY_IPV4;
527                 ent_params.u.prv_ip =
528                                 rte_bswap32((uint32_t) params->prv_ip.addr.ipv4.s_addr);
529         } else {
530                 print_ipv6_address_u8(params->prv_ip.addr.ipv6.s6_addr);
531                 print_ipv6_address_u16(params->prv_ip.addr.ipv6.s6_addr16);
532                 print_ipv6_address_u32(params->prv_ip.addr.ipv6.s6_addr32);
533                 ent_params.type = CGNAPT_ENTRY_IPV6;
534                 memcpy(ent_params.u.prv_ipv6, params->prv_ip.addr.ipv6.s6_addr,
535                                          16);
536         }
537
538         ent_params.prv_port = params->prv_port;
539         ent_params.pub_ip =
540                         rte_bswap32((uint32_t) params->pub_ip.addr.ipv4.s_addr);
541         ent_params.pub_port = params->pub_port;
542         ent_params.prv_phy_port = params->pid;
543         ent_params.ttl = params->ttl;
544
545         status = app_pipeline_cgnapt_add_entry(app, params->p, &ent_params);
546
547         if (status != 0) {
548                 printf("CG-NAPT add multiple entry command failed, %d\n",
549                                          status);
550                 return;
551         }
552 }
553
554 static cmdline_parse_token_string_t cmd_entry_add_p_string =
555 TOKEN_STRING_INITIALIZER(struct cmd_entry_add_result, p_string,
556                          "p");
557
558 static cmdline_parse_token_num_t cmd_entry_add_p =
559 TOKEN_NUM_INITIALIZER(struct cmd_entry_add_result, p, UINT32);
560
561 static cmdline_parse_token_string_t cmd_entry_add_entry_string =
562 TOKEN_STRING_INITIALIZER(struct cmd_entry_add_result, entry_string,
563                          "entry");
564
565 static cmdline_parse_token_string_t cmd_entry_add_add_string =
566 TOKEN_STRING_INITIALIZER(struct cmd_entry_add_result, add_string,
567                          "add");
568
569 static cmdline_parse_token_ipaddr_t cmd_entry_add_prv_ip =
570 TOKEN_IPADDR_INITIALIZER(struct cmd_entry_add_result, prv_ip);
571
572 static cmdline_parse_token_num_t cmd_entry_add_prv_port =
573 TOKEN_NUM_INITIALIZER(struct cmd_entry_add_result, prv_port, UINT16);
574
575 static cmdline_parse_token_ipaddr_t cmd_entry_add_pub_ip =
576 TOKEN_IPV4_INITIALIZER(struct cmd_entry_add_result, pub_ip);
577
578 static cmdline_parse_token_num_t cmd_entry_add_pub_port =
579 TOKEN_NUM_INITIALIZER(struct cmd_entry_add_result, pub_port, UINT16);
580
581 static cmdline_parse_token_num_t cmd_entry_add_pid =
582 TOKEN_NUM_INITIALIZER(struct cmd_entry_add_result, pid, UINT16);
583
584 static cmdline_parse_token_num_t cmd_entry_add_ttl =
585 TOKEN_NUM_INITIALIZER(struct cmd_entry_add_result, ttl, UINT32);
586
587 static cmdline_parse_inst_t cmd_entry_add = {
588         .f = cmd_entry_add_parsed,
589         .data = NULL,
590         .help_str = "NAPT entry add",
591         .tokens = {
592                          (void *)&cmd_entry_add_p_string,
593                          (void *)&cmd_entry_add_p,
594                          (void *)&cmd_entry_add_entry_string,
595                          (void *)&cmd_entry_add_add_string,
596                          (void *)&cmd_entry_add_prv_ip,
597                          (void *)&cmd_entry_add_prv_port,
598                          (void *)&cmd_entry_add_pub_ip,
599                          (void *)&cmd_entry_add_pub_port,
600                          (void *)&cmd_entry_add_pid,
601                          (void *)&cmd_entry_add_ttl,
602                          NULL,
603                          },
604 };
605
606 /**
607  * A structure defining the multiple entry add parse arguments.
608  */
609 struct cmd_entry_addm_result {
610         cmdline_fixed_string_t p_string;
611         uint32_t p;
612         cmdline_fixed_string_t entry_string;
613         cmdline_fixed_string_t addm_string;
614         cmdline_ipaddr_t prv_ip;
615         uint16_t prv_port;
616         cmdline_ipaddr_t pub_ip;
617         uint16_t pub_port;
618         uint16_t pid;
619         uint32_t ttl;
620         uint32_t num_ue;
621         uint16_t prv_port_max;
622         uint16_t pub_port_max;
623 };
624
625 /**
626  * Helping function for add multiple entries
627  *
628  * @param parsed_result
629  *  A pointer parsed add arguments
630  * @param cl
631  *  unused pointer to struct cmdline
632  * @param msg
633  *  void pointer data
634  */
635 static void
636 cmd_entry_addm_parsed(void *parsed_result,
637                                         __rte_unused struct cmdline *cl, void *data)
638 {
639         struct cmd_entry_addm_result *params = parsed_result;
640         struct app_params *app = data;
641         struct app_pipeline_cgnapt_mentry_params ent_params;
642         int status;
643
644         if (params->prv_ip.family == AF_INET) {
645                 ent_params.type = CGNAPT_ENTRY_IPV4;
646                 ent_params.u.prv_ip =
647                                 rte_bswap32((uint32_t) params->prv_ip.addr.ipv4.s_addr);
648         } else {
649                 print_ipv6_address_u8(params->prv_ip.addr.ipv6.s6_addr);
650                 print_ipv6_address_u16(params->prv_ip.addr.ipv6.s6_addr16);
651                 print_ipv6_address_u32(params->prv_ip.addr.ipv6.s6_addr32);
652                 ent_params.type = CGNAPT_ENTRY_IPV6;
653                 memcpy(ent_params.u.prv_ipv6, params->prv_ip.addr.ipv6.s6_addr,
654                                          16);
655         }
656
657         ent_params.prv_port = params->prv_port;
658         ent_params.pub_ip =
659                         rte_bswap32((uint32_t) params->pub_ip.addr.ipv4.s_addr);
660         ent_params.pub_port = params->pub_port;
661         ent_params.prv_phy_port = params->pid;
662         ent_params.ttl = params->ttl;
663         ent_params.num_ue = params->num_ue;
664         ent_params.prv_port_max = params->prv_port_max;
665         ent_params.pub_port_max = params->pub_port_max;
666
667         status = app_pipeline_cgnapt_addm_entry(app, params->p, &ent_params);
668
669         if (status != 0) {
670                 printf("CG-NAPT add multiple entry command failed, %d\n",
671                                          status);
672                 return;
673         }
674 }
675
676 static cmdline_parse_token_string_t cmd_entry_add_addm_string =
677 TOKEN_STRING_INITIALIZER(struct cmd_entry_addm_result, addm_string,
678                          "addm");
679
680 static cmdline_parse_token_num_t cmd_entry_addm_prv_port =
681 TOKEN_NUM_INITIALIZER(struct cmd_entry_addm_result, prv_port_max, UINT16);
682
683 static cmdline_parse_token_num_t cmd_entry_addm_pub_port =
684 TOKEN_NUM_INITIALIZER(struct cmd_entry_addm_result, pub_port_max, UINT16);
685
686 static cmdline_parse_token_num_t cmd_entry_addm_max_ue =
687 TOKEN_NUM_INITIALIZER(struct cmd_entry_addm_result, num_ue, UINT32);
688
689 static cmdline_parse_inst_t cmd_entry_addm = {
690         .f = cmd_entry_addm_parsed,
691         .data = NULL,
692         .help_str = "NAPT entry add multiple",
693         .tokens = {
694                          (void *)&cmd_entry_add_p_string,
695                          (void *)&cmd_entry_add_p,
696                          (void *)&cmd_entry_add_entry_string,
697                          (void *)&cmd_entry_add_addm_string,
698                          (void *)&cmd_entry_add_prv_ip,
699                          (void *)&cmd_entry_add_prv_port,
700                          (void *)&cmd_entry_add_pub_ip,
701                          (void *)&cmd_entry_add_pub_port,
702                          (void *)&cmd_entry_add_pid,
703                          (void *)&cmd_entry_add_ttl,
704                          (void *)&cmd_entry_addm_max_ue,
705                          (void *)&cmd_entry_addm_prv_port,
706                          (void *)&cmd_entry_addm_pub_port,
707                          NULL,
708                          },
709 };
710
711 /**
712  * A structure defining the entry delete parse arguments.
713  */
714 struct cmd_entry_del_result {
715         cmdline_fixed_string_t p_string;
716         uint32_t p;
717         cmdline_fixed_string_t entry_string;
718         cmdline_fixed_string_t del_string;
719         cmdline_ipaddr_t ip;
720         uint16_t port;
721         uint16_t pid;
722 };
723
724 /**
725  * Helping function for delete entry
726  *
727  * @param parsed_result
728  *  A pointer parsed add arguments
729  * @param cl
730  *  unused pointer to struct cmdline
731  * @param msg
732  *  void pointer data
733  */
734 static void
735 cmd_entry_del_parsed(void *parsed_result,
736                                  __rte_unused struct cmdline *cl, void *data)
737 {
738         struct cmd_entry_del_result *params = parsed_result;
739         struct app_params *app = data;
740         struct pipeline_cgnapt_entry_key key;
741
742         int status;
743
744         /* Create entry */
745         if (params->ip.family == AF_INET)
746                 key.ip = rte_bswap32((uint32_t) params->ip.addr.ipv4.s_addr);
747         else
748                 key.ip =
749                                 rte_bswap32((uint32_t) params->ip.addr.ipv6.s6_addr32[3]);
750         key.port = params->port;
751         key.pid = params->pid;
752
753         status = app_pipeline_cgnapt_delete_entry(app, params->p, &key);
754
755         if (status != 0) {
756                 printf("CG-NAPT entry del command failed\n");
757                 return;
758         }
759 }
760
761 static cmdline_parse_token_string_t cmd_entry_del_p_string =
762 TOKEN_STRING_INITIALIZER(struct cmd_entry_del_result, p_string,
763                          "p");
764
765 static cmdline_parse_token_num_t cmd_entry_del_p =
766 TOKEN_NUM_INITIALIZER(struct cmd_entry_del_result, p, UINT32);
767
768 static cmdline_parse_token_string_t cmd_entry_del_entry_string =
769 TOKEN_STRING_INITIALIZER(struct cmd_entry_del_result, entry_string,
770                          "entry");
771
772 static cmdline_parse_token_string_t cmd_entry_del_del_string =
773 TOKEN_STRING_INITIALIZER(struct cmd_entry_del_result, del_string,
774                          "del");
775
776 static cmdline_parse_token_ipaddr_t cmd_entry_del_ip =
777 TOKEN_IPADDR_INITIALIZER(struct cmd_entry_del_result, ip);
778
779 static cmdline_parse_token_num_t cmd_entry_del_port =
780 TOKEN_NUM_INITIALIZER(struct cmd_entry_del_result, port, UINT16);
781
782 static cmdline_parse_token_num_t cmd_entry_del_pid =
783 TOKEN_NUM_INITIALIZER(struct cmd_entry_del_result, pid, UINT16);
784
785 static cmdline_parse_inst_t cmd_entry_del = {
786         .f = cmd_entry_del_parsed,
787         .data = NULL,
788         .help_str = "Entry delete",
789         .tokens = {
790                          (void *)&cmd_entry_del_p_string,
791                          (void *)&cmd_entry_del_p,
792                          (void *)&cmd_entry_del_entry_string,
793                          (void *)&cmd_entry_del_del_string,
794                          (void *)&cmd_entry_del_ip,
795                          (void *)&cmd_entry_del_port,
796                          (void *)&cmd_entry_del_pid,
797                          NULL,
798                          },
799 };
800
801 /**
802  * A structure defining the list entry parse arguments.
803  */
804 struct cmd_entry_ls_result {
805         cmdline_fixed_string_t p_string;
806         uint32_t p;
807         cmdline_fixed_string_t entry_string;
808         cmdline_fixed_string_t ls_string;
809 };
810
811 /**
812  * Helping function for list entry
813  *
814  * @param parsed_result
815  *  A pointer parsed add arguments
816  * @param cl
817  *  unused pointer to struct cmdline
818  * @param msg
819  *  void pointer data
820  */
821 static void
822 cmd_entry_ls_parsed(void *parsed_result,
823                                 __rte_unused struct cmdline *cl, void *data)
824 {
825         struct cmd_entry_ls_result *params = parsed_result;
826         struct app_params *app = data;
827         int status;
828
829         status = app_pipeline_cgnapt_entry_ls(app, params->p);
830
831         if (status != 0) {
832                 printf("Ls command failed\n");
833                 return;
834         }
835 }
836
837 static cmdline_parse_token_string_t cmd_entry_ls_p_string =
838 TOKEN_STRING_INITIALIZER(struct cmd_entry_ls_result, p_string, "p");
839
840 static cmdline_parse_token_num_t cmd_entry_ls_p =
841 TOKEN_NUM_INITIALIZER(struct cmd_entry_ls_result, p, UINT32);
842
843 static cmdline_parse_token_string_t cmd_entry_ls_entry_string =
844 TOKEN_STRING_INITIALIZER(struct cmd_entry_ls_result,
845                          entry_string, "entry");
846
847 static cmdline_parse_token_string_t cmd_entry_ls_ls_string =
848 TOKEN_STRING_INITIALIZER(struct cmd_entry_ls_result, ls_string,
849                          "ls");
850
851 static cmdline_parse_inst_t cmd_entry_ls = {
852         .f = cmd_entry_ls_parsed,
853         .data = NULL,
854         .help_str = "Entry list",
855         .tokens = {
856                          (void *)&cmd_entry_ls_p_string,
857                          (void *)&cmd_entry_ls_p,
858                          (void *)&cmd_entry_ls_entry_string,
859                          (void *)&cmd_entry_ls_ls_string,
860                          NULL,
861                          },
862 };
863
864 /**
865  * A structure defining the dbg cmd parse arguments.
866  */
867 struct cmd_entry_dbg_result {
868         cmdline_fixed_string_t p_string;
869         uint32_t p;
870         cmdline_fixed_string_t entry_string;
871         cmdline_fixed_string_t dbg_string;
872         uint8_t cmd;
873         uint8_t d1;
874         uint8_t d2;
875 };
876
877 /**
878  * Helping function for dbg cmd
879  *
880  * @param parsed_result
881  *  A pointer parsed add arguments
882  * @param cl
883  *  unused pointer to struct cmdline
884  * @param msg
885  *  void pointer data
886  */
887 static void
888 cmd_entry_dbg_parsed(void *parsed_result,
889                                  __rte_unused struct cmdline *cl, void *data)
890 {
891         struct cmd_entry_dbg_result *params = parsed_result;
892         struct app_params *app = data;
893         uint8_t msg[4];
894         int status;
895
896         msg[0] = params->cmd;
897         msg[1] = params->d1;
898         msg[2] = params->d2;
899         status = app_pipeline_cgnapt_entry_dbg(app, params->p, msg);
900
901         if (status != 0) {
902                 printf("Dbg Command failed\n");
903                 return;
904         }
905 }
906
907 static cmdline_parse_token_string_t cmd_entry_dbg_p_string =
908 TOKEN_STRING_INITIALIZER(struct cmd_entry_dbg_result, p_string, "p");
909
910 static cmdline_parse_token_num_t cmd_entry_dbg_p =
911 TOKEN_NUM_INITIALIZER(struct cmd_entry_dbg_result, p, UINT32);
912
913 static cmdline_parse_token_string_t cmd_entry_dbg_entry_string =
914 TOKEN_STRING_INITIALIZER(struct cmd_entry_dbg_result,
915                          entry_string, "entry");
916
917 static cmdline_parse_token_string_t cmd_entry_dbg_dbg_string =
918 TOKEN_STRING_INITIALIZER(struct cmd_entry_dbg_result, dbg_string,
919                          "dbg");
920
921 static cmdline_parse_token_num_t cmd_entry_dbg_cmd =
922 TOKEN_NUM_INITIALIZER(struct cmd_entry_dbg_result, cmd, UINT8);
923
924 static cmdline_parse_token_num_t cmd_entry_dbg_d1 =
925 TOKEN_NUM_INITIALIZER(struct cmd_entry_dbg_result, d1, UINT8);
926
927 static cmdline_parse_token_num_t cmd_entry_dbg_d2 =
928 TOKEN_NUM_INITIALIZER(struct cmd_entry_dbg_result, d2, UINT8);
929
930 static cmdline_parse_inst_t cmd_entry_dbg = {
931         .f = cmd_entry_dbg_parsed,
932         .data = NULL,
933         .help_str = "NAPT dbg cmd",
934         .tokens = {
935                          (void *)&cmd_entry_dbg_p_string,
936                          (void *)&cmd_entry_dbg_p,
937                          (void *)&cmd_entry_dbg_entry_string,
938                          (void *)&cmd_entry_dbg_dbg_string,
939                          (void *)&cmd_entry_dbg_cmd,
940                          (void *)&cmd_entry_dbg_d1,
941                          (void *)&cmd_entry_dbg_d2,
942                          NULL,
943                          },
944 };
945
946 /**
947  * A structure defining num ip clients cmd parse arguments.
948  */
949 struct cmd_numipcli_result {
950         cmdline_fixed_string_t p_string;
951         uint32_t p;
952         cmdline_fixed_string_t numipcli_string;
953 };
954
955 /**
956  * Helping function for printing num ip clients
957  *
958  * @param parsed_result
959  *  Unused pointer parsed add arguments
960  * @param cl
961  *  unused pointer to struct cmdline
962  * @param msg
963  *  Unused void pointer data
964  */
965 static void
966 cmd_numipcli_parsed(__rte_unused void *parsed_result,
967                                 __rte_unused struct cmdline *cl, __rte_unused void *data)
968 {
969         print_num_ip_clients();
970 }
971
972 static cmdline_parse_token_string_t cmd_numipcli_p_string =
973 TOKEN_STRING_INITIALIZER(struct cmd_numipcli_result, p_string, "p");
974
975 static cmdline_parse_token_num_t cmd_numipcli_p =
976 TOKEN_NUM_INITIALIZER(struct cmd_numipcli_result, p, UINT32);
977
978 static cmdline_parse_token_string_t cmd_numipcli_string =
979 TOKEN_STRING_INITIALIZER(struct cmd_numipcli_result,
980                          numipcli_string, "numipcli");
981
982 static cmdline_parse_inst_t cmd_numipcli = {
983         .f = cmd_numipcli_parsed,
984         .data = NULL,
985         .help_str = "Num IP Clients command",
986         .tokens = {
987                          (void *)&cmd_numipcli_p_string,
988                          (void *)&cmd_numipcli_p,
989                          (void *)&cmd_numipcli_string,
990                          NULL,
991                          },
992 };
993
994 /**
995  * Function to send a ver cmd message to BE
996  *
997  * @param app
998  *  A pointer to pipeline app
999  * @param pipeline_id
1000  *  Pipeline id
1001  * @param msg
1002  *  debug message contents
1003  *
1004  * @return
1005  *  0 on success, negative on error.
1006  */
1007 static int
1008 app_pipeline_cgnapt_ver(struct app_params *app,
1009                         uint32_t pipeline_id, uint8_t *msg)
1010 {
1011
1012         struct pipeline_cgnapt_t *p;
1013         struct pipeline_cgnapt_entry_dbg_msg_req *req;
1014         struct pipeline_cgnapt_entry_dbg_msg_rsp *rsp;
1015
1016         /* Check input arguments */
1017         if (app == NULL)
1018                 return -1;
1019
1020         p = app_pipeline_data_fe(app, pipeline_id,
1021                                  (struct pipeline_type *)&pipeline_cgnapt);
1022         if (p == NULL)
1023                 return -1;
1024
1025         /* Allocate and write request */
1026         req = app_msg_alloc(app);
1027         if (req == NULL)
1028                 return -1;
1029
1030         req->type = PIPELINE_MSG_REQ_CUSTOM;
1031         req->subtype = PIPELINE_CGNAPT_MSG_REQ_VER;
1032         req->data[0] = msg[0];
1033         req->data[1] = msg[1];
1034
1035         rsp = app_msg_send_recv(app, pipeline_id, req, MSG_TIMEOUT_DEFAULT);
1036         if (rsp == NULL)
1037                 return -1;
1038
1039         /* Read response */
1040         if (rsp->status) {
1041                 app_msg_free(app, rsp);
1042                 printf("Error rsp->status %d\n", rsp->status);
1043                 return -1;
1044         }
1045
1046         /* Free response */
1047         app_msg_free(app, rsp);
1048
1049         return 0;
1050 }
1051
1052 /**
1053  * A structure defining ver cmd parse arguments.
1054  */
1055 struct cmd_ver_result {
1056         cmdline_fixed_string_t p_string;
1057         uint32_t p;
1058         cmdline_fixed_string_t ver_string;
1059         uint8_t cmd;
1060         uint8_t d1;
1061 };
1062
1063 /**
1064  * Helping function for ver cmd
1065  *
1066  * @param parsed_result
1067  *  A pointer parsed add arguments
1068  * @param cl
1069  *  unused pointer to struct cmdline
1070  * @param msg
1071  *  void pointer data
1072  */
1073 static void
1074 cmd_ver_parsed(void *parsed_result, __rte_unused struct cmdline *cl, void *data)
1075 {
1076         struct cmd_ver_result *params = parsed_result;
1077         struct app_params *app = data;
1078         uint8_t msg[4];
1079         int status;
1080
1081         msg[0] = params->cmd;
1082         msg[1] = params->d1;
1083         status = app_pipeline_cgnapt_ver(app, params->p, msg);
1084
1085         if (status != 0) {
1086                 printf("Version Command failed\n");
1087                 return;
1088         }
1089 }
1090
1091 static cmdline_parse_token_string_t cmd_ver_p_string =
1092 TOKEN_STRING_INITIALIZER(struct cmd_ver_result, p_string, "p");
1093
1094 static cmdline_parse_token_num_t cmd_ver_p =
1095 TOKEN_NUM_INITIALIZER(struct cmd_ver_result, p, UINT32);
1096
1097 static cmdline_parse_token_string_t cmd_ver_string =
1098 TOKEN_STRING_INITIALIZER(struct cmd_ver_result,
1099                          ver_string, "ver");
1100
1101 static cmdline_parse_token_num_t cmd_ver_cmd =
1102 TOKEN_NUM_INITIALIZER(struct cmd_ver_result, cmd, UINT8);
1103
1104 static cmdline_parse_token_num_t cmd_ver_d1 =
1105 TOKEN_NUM_INITIALIZER(struct cmd_ver_result, d1, UINT8);
1106
1107 static cmdline_parse_inst_t cmd_ver = {
1108         .f = cmd_ver_parsed,
1109         .data = NULL,
1110         .help_str = "NAPT ver cmd",
1111         .tokens = {
1112                          (void *)&cmd_ver_p_string,
1113                          (void *)&cmd_ver_p,
1114                          (void *)&cmd_ver_string,
1115                          (void *)&cmd_ver_cmd,
1116                          (void *)&cmd_ver_d1,
1117                          NULL,
1118                          },
1119 };
1120
1121 /**
1122  * Function to send a nsp add cmd message to BE
1123  *
1124  * @param app
1125  *  A pointer to pipeline app
1126  * @param pipeline_id
1127  *  Pipeline id
1128  * @param nsp
1129  *  A pointer to struct pipeline_cgnapt_nsp_t
1130  *
1131  * @return
1132  *  0 on success, negative on error.
1133  */
1134 static int
1135 app_pipeline_cgnapt_add_nsp(struct app_params *app,
1136                                         uint32_t pipeline_id,
1137                                         struct pipeline_cgnapt_nsp_t *nsp)
1138 {
1139
1140         struct pipeline_cgnapt_t *p;
1141         struct pipeline_cgnapt_nsp_add_msg_req *req;
1142         struct pipeline_cgnapt_nsp_add_msg_rsp *rsp;
1143
1144         /* Check input arguments */
1145         if (app == NULL)
1146                 return -1;
1147
1148         printf("1st if condition\n");
1149
1150         p = app_pipeline_data_fe(app, pipeline_id,
1151                                  (struct pipeline_type *)&pipeline_cgnapt);
1152         if (p == NULL)
1153                 return -1;
1154
1155         printf("2st if condition\n");
1156         /* Allocate and write request */
1157         req = app_msg_alloc(app);
1158         if (req == NULL)
1159                 return -1;
1160
1161         printf("3st if condition\n");
1162         req->type = PIPELINE_MSG_REQ_CUSTOM;
1163         req->subtype = PIPELINE_CGNAPT_MSG_REQ_NSP_ADD;
1164         memcpy(&req->nsp, nsp, sizeof(struct pipeline_cgnapt_nsp_t));
1165
1166         rsp = app_msg_send_recv(app, pipeline_id, req, MSG_TIMEOUT_DEFAULT);
1167         if (rsp == NULL)
1168                 return -1;
1169
1170         printf("4st if condition\n");
1171         /* Read response */
1172         if (rsp->status) {
1173                 app_msg_free(app, rsp);
1174                 printf("Error rsp->status %d\n", rsp->status);
1175                 return -1;
1176         }
1177
1178         /* Free response */
1179         app_msg_free(app, rsp);
1180
1181         return 0;
1182 }
1183
1184 /**
1185  * A structure defining nsp add cmd parse arguments.
1186  */
1187 struct cmd_nsp_add_result {
1188         cmdline_fixed_string_t p_string;
1189         uint32_t p;
1190         cmdline_fixed_string_t nsp_string;
1191         cmdline_fixed_string_t add_string;
1192         cmdline_ipaddr_t ip;
1193 };
1194
1195 /**
1196  * Helping function for nsp add cmd
1197  *
1198  * @param parsed_result
1199  *  A pointer parsed add arguments
1200  * @param cl
1201  *  unused pointer to struct cmdline
1202  * @param msg
1203  *  void pointer data
1204  */
1205 static void
1206 cmd_nsp_add_parsed(void *parsed_result, __rte_unused struct cmdline *cl,
1207                          void *data)
1208 {
1209         struct cmd_nsp_add_result *params = parsed_result;
1210         struct app_params *app = data;
1211         int status;
1212         struct pipeline_cgnapt_nsp_t nsp;
1213
1214         memcpy(&nsp.prefix, &params->ip.addr.ipv6.s6_addr, 16);
1215         nsp.depth = params->ip.prefixlen;
1216         status = app_pipeline_cgnapt_add_nsp(app, params->p, &nsp);
1217         if (status != 0) {
1218                 printf("NSP ADD Command failed\n");
1219                 return;
1220         }
1221 }
1222
1223 static cmdline_parse_token_string_t cmd_add_nsp_p_string =
1224 TOKEN_STRING_INITIALIZER(struct cmd_nsp_add_result, p_string, "p");
1225
1226 static cmdline_parse_token_num_t cmd_add_nsp_p =
1227 TOKEN_NUM_INITIALIZER(struct cmd_nsp_add_result, p, UINT32);
1228
1229 static cmdline_parse_token_string_t cmd_add_nsp_string =
1230 TOKEN_STRING_INITIALIZER(struct cmd_nsp_add_result,
1231                          nsp_string, "nsp");
1232
1233 static cmdline_parse_token_string_t cmd_add_nsp_add_string =
1234 TOKEN_STRING_INITIALIZER(struct cmd_nsp_add_result,
1235                          add_string, "add");
1236
1237 static cmdline_parse_token_ipaddr_t cmd_add_nsp_ip =
1238 TOKEN_IPNET_INITIALIZER(struct cmd_nsp_add_result, ip);
1239
1240 static cmdline_parse_inst_t cmd_nsp_add = {
1241         .f = cmd_nsp_add_parsed,
1242         .data = NULL,
1243         .help_str = "NAPT NSP ADD cmd",
1244         .tokens = {
1245                          (void *)&cmd_add_nsp_p_string,
1246                          (void *)&cmd_add_nsp_p,
1247                          (void *)&cmd_add_nsp_string,
1248                          (void *)&cmd_add_nsp_add_string,
1249                          (void *)&cmd_add_nsp_ip,
1250                          NULL,
1251                          },
1252 };
1253
1254 /**
1255  * Function to send a nsp del cmd message to BE
1256  *
1257  * @param app
1258  *  A pointer to pipeline app
1259  * @param pipeline_id
1260  *  Pipeline id
1261  * @param nsp
1262  *  A pointer to struct pipeline_cgnapt_nsp_t
1263  *
1264  * @return
1265  *  0 on success, negative on error.
1266  */
1267 static int
1268 app_pipeline_cgnapt_del_nsp(struct app_params *app,
1269                                         uint32_t pipeline_id,
1270                                         struct pipeline_cgnapt_nsp_t *nsp)
1271 {
1272
1273         struct pipeline_cgnapt_t *p;
1274         struct pipeline_cgnapt_nsp_del_msg_req *req;
1275         struct pipeline_cgnapt_nsp_del_msg_rsp *rsp;
1276
1277         /* Check input arguments */
1278         if (app == NULL)
1279                 return -1;
1280
1281         p = app_pipeline_data_fe(app, pipeline_id,
1282                                  (struct pipeline_type *)&pipeline_cgnapt);
1283         if (p == NULL)
1284                 return -1;
1285
1286         /* Allocate and write request */
1287         req = app_msg_alloc(app);
1288         if (req == NULL)
1289                 return -1;
1290
1291         req->type = PIPELINE_MSG_REQ_CUSTOM;
1292         req->subtype = PIPELINE_CGNAPT_MSG_REQ_NSP_DEL;
1293         memcpy(&req->nsp, nsp, sizeof(struct pipeline_cgnapt_nsp_t));
1294
1295         rsp = app_msg_send_recv(app, pipeline_id, req, MSG_TIMEOUT_DEFAULT);
1296         if (rsp == NULL)
1297                 return -1;
1298
1299         /* Read response */
1300         if (rsp->status) {
1301                 app_msg_free(app, rsp);
1302                 printf("Error rsp->status %d\n", rsp->status);
1303                 return -1;
1304         }
1305
1306         /* Free response */
1307         app_msg_free(app, rsp);
1308
1309         return 0;
1310 }
1311
1312 /**
1313  * A structure defining nsp del cmd parse arguments.
1314  */
1315 struct cmd_nsp_del_result {
1316         cmdline_fixed_string_t p_string;
1317         uint32_t p;
1318         cmdline_fixed_string_t nsp_string;
1319         cmdline_fixed_string_t del_string;
1320         cmdline_ipaddr_t ip;
1321 };
1322
1323 /**
1324  * Helping function for nsp del cmd
1325  *
1326  * @param parsed_result
1327  *  A pointer parsed add arguments
1328  * @param cl
1329  *  unused pointer to struct cmdline
1330  * @param msg
1331  *  void pointer data
1332  */
1333 static void
1334 cmd_nsp_del_parsed(void *parsed_result, __rte_unused struct cmdline *cl,
1335                          void *data)
1336 {
1337         struct cmd_nsp_del_result *params = parsed_result;
1338         struct app_params *app = data;
1339         int status;
1340         struct pipeline_cgnapt_nsp_t nsp;
1341
1342         memcpy(&nsp.prefix, &params->ip.addr.ipv6.s6_addr, 16);
1343         nsp.depth = params->ip.prefixlen;
1344         status = app_pipeline_cgnapt_del_nsp(app, params->p, &nsp);
1345
1346         if (status != 0) {
1347                 printf("NSP DEL Command failed\n");
1348                 return;
1349         }
1350 }
1351
1352 static cmdline_parse_token_string_t cmd_del_nsp_p_string =
1353 TOKEN_STRING_INITIALIZER(struct cmd_nsp_del_result, p_string, "p");
1354
1355 static cmdline_parse_token_num_t cmd_del_nsp_p =
1356 TOKEN_NUM_INITIALIZER(struct cmd_nsp_del_result, p, UINT32);
1357
1358 static cmdline_parse_token_string_t cmd_del_nsp_string =
1359 TOKEN_STRING_INITIALIZER(struct cmd_nsp_del_result,
1360                          nsp_string, "nsp");
1361
1362 static cmdline_parse_token_string_t cmd_del_nsp_del_string =
1363 TOKEN_STRING_INITIALIZER(struct cmd_nsp_del_result,
1364                          del_string, "del");
1365
1366 static cmdline_parse_token_ipaddr_t cmd_del_nsp_ip =
1367 TOKEN_IPNET_INITIALIZER(struct cmd_nsp_del_result, ip);
1368
1369 static cmdline_parse_inst_t cmd_nsp_del = {
1370         .f = cmd_nsp_del_parsed,
1371         .data = NULL,
1372         .help_str = "NAPT NSP DEL cmd",
1373         .tokens = {
1374                          (void *)&cmd_del_nsp_p_string,
1375                          (void *)&cmd_del_nsp_p,
1376                          (void *)&cmd_del_nsp_string,
1377                          (void *)&cmd_del_nsp_del_string,
1378                          (void *)&cmd_del_nsp_ip,
1379                          NULL,
1380                          },
1381 };
1382
1383 /**
1384  * A structure defining the cgnapt stats cmd parse arguments.
1385  */
1386 struct cmd_cgnapt_stats_result {
1387         cmdline_fixed_string_t p_string;
1388         cmdline_fixed_string_t cgnapt_string;
1389         cmdline_fixed_string_t stats_string;
1390 };
1391
1392 /**
1393  * Helping function for cgnapt stats cmd
1394  *
1395  * @param parsed_result
1396  *  A pointer parsed add arguments
1397  * @param cl
1398  *  unused pointer to struct cmdline
1399  * @param msg
1400  *  void pointer data
1401  */
1402 static void
1403 cmd_cgnapt_stats_parsed(
1404         __rte_unused void *parsed_result,
1405         __rte_unused struct cmdline *cl,
1406         __rte_unused void *data)
1407 {
1408         all_cgnapt_stats();
1409 }
1410
1411 static cmdline_parse_token_string_t cmd_cgnapt_stats_p_string =
1412 TOKEN_STRING_INITIALIZER(struct cmd_cgnapt_stats_result, p_string, "p");
1413
1414 static cmdline_parse_token_string_t cmd_cgnapt_stats_cgnapt_string =
1415 TOKEN_STRING_INITIALIZER(struct cmd_cgnapt_stats_result,
1416                                 cgnapt_string, "cgnapt");
1417
1418 static cmdline_parse_token_string_t cmd_cgnapt_stats_stats_string =
1419 TOKEN_STRING_INITIALIZER(struct cmd_cgnapt_stats_result, stats_string,
1420                                 "stats");
1421
1422 static cmdline_parse_inst_t cmd_stats = {
1423         .f = cmd_cgnapt_stats_parsed,
1424         .data = NULL,
1425         .help_str = "CGNAPT stats cmd",
1426         .tokens = {
1427                 (void *)&cmd_cgnapt_stats_p_string,
1428                 (void *)&cmd_cgnapt_stats_cgnapt_string,
1429                 (void *)&cmd_cgnapt_stats_stats_string,
1430                 NULL,
1431         },
1432 };
1433
1434 /**
1435  * A structure defining the cgnapt clear stats cmd parse arguments.
1436  */
1437 struct cmd_cgnapt_clear_stats_result {
1438         cmdline_fixed_string_t p_string;
1439         cmdline_fixed_string_t cgnapt_string;
1440         cmdline_fixed_string_t clear_string;
1441         cmdline_fixed_string_t stats_string;
1442 };
1443
1444 /**
1445  * Helping function for cgnapt clear stats cmd
1446  *
1447  * @param parsed_result
1448  *  A pointer parsed add arguments
1449  * @param cl
1450  *  unused pointer to struct cmdline
1451  * @param msg
1452  *  void pointer data
1453  */
1454 static void
1455 cmd_cgnapt_clear_stats_parsed(
1456         __rte_unused void *parsed_result,
1457         __rte_unused struct cmdline *cl,
1458         __rte_unused void *data)
1459 {
1460         all_cgnapt_clear_stats();
1461 }
1462
1463 static cmdline_parse_token_string_t cmd_cgnapt_clear_stats_p_string =
1464 TOKEN_STRING_INITIALIZER(struct cmd_cgnapt_clear_stats_result, p_string, "p");
1465
1466 static cmdline_parse_token_string_t cmd_cgnapt_clear_stats_cgnapt_string =
1467 TOKEN_STRING_INITIALIZER(struct cmd_cgnapt_clear_stats_result,
1468                                 cgnapt_string, "cgnapt");
1469
1470 static cmdline_parse_token_string_t cmd_cgnapt_clear_stats_clear_string =
1471 TOKEN_STRING_INITIALIZER(struct cmd_cgnapt_clear_stats_result,
1472                                 clear_string, "clear");
1473
1474 static cmdline_parse_token_string_t cmd_cgnapt_clear_stats_stats_string =
1475 TOKEN_STRING_INITIALIZER(struct cmd_cgnapt_clear_stats_result, stats_string,
1476                                 "stats");
1477
1478 static cmdline_parse_inst_t cmd_clear_stats = {
1479          .f = cmd_cgnapt_clear_stats_parsed,
1480          .data = NULL,
1481          .help_str = "CGNAPT clear stats cmd",
1482          .tokens = {
1483                                 (void *)&cmd_cgnapt_clear_stats_p_string,
1484                                 (void *)&cmd_cgnapt_clear_stats_cgnapt_string,
1485                                 (void *)&cmd_cgnapt_clear_stats_clear_string,
1486                                 (void *)&cmd_cgnapt_clear_stats_stats_string,
1487                                 NULL,
1488                                 },
1489 };
1490
1491
1492 static cmdline_parse_ctx_t pipeline_cmds[] = {
1493         (cmdline_parse_inst_t *) &cmd_entry_add,
1494         (cmdline_parse_inst_t *) &cmd_entry_del,
1495         (cmdline_parse_inst_t *) &cmd_entry_ls,
1496         (cmdline_parse_inst_t *) &cmd_entry_dbg,
1497         (cmdline_parse_inst_t *) &cmd_entry_addm,
1498         (cmdline_parse_inst_t *) &cmd_ver,
1499         (cmdline_parse_inst_t *) &cmd_nsp_add,
1500         (cmdline_parse_inst_t *) &cmd_nsp_del,
1501         (cmdline_parse_inst_t *) &cmd_numipcli,
1502         #ifdef PCP_ENABLE
1503         (cmdline_parse_inst_t *) &cmd_pcp,
1504         #endif
1505         (cmdline_parse_inst_t *) &cmd_stats,
1506         (cmdline_parse_inst_t *) &cmd_clear_stats,
1507         NULL,
1508 };
1509
1510 static struct pipeline_fe_ops pipeline_cgnapt_fe_ops = {
1511         .f_init = pipeline_cgnapt_init,
1512         .f_free = app_pipeline_cgnapt_free,
1513         .cmds = pipeline_cmds,
1514 };
1515
1516 struct pipeline_type pipeline_cgnapt = {
1517         .name = "CGNAPT",
1518         .be_ops = &pipeline_cgnapt_be_ops,
1519         .fe_ops = &pipeline_cgnapt_fe_ops,
1520 };