2 // Copyright (c) 2017 Intel Corporation
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
8 // http://www.apache.org/licenses/LICENSE-2.0
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.
19 * Pipeline CG-NAPT FE Implementation.
21 * Implementation of Pipeline CG-NAPT Front End (FE).
22 * Provides CLI support.
23 * Runs on master core.
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>
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"
40 #include "cgnapt_pcp_fe.h"
44 * A structure defining the CG-NAPT entry that is stored on
47 struct app_pipeline_cgnapt_entry {
48 struct pipeline_cgnapt_entry_key key;
49 struct app_pipeline_cgnapt_entry_params params;
52 TAILQ_ENTRY(app_pipeline_cgnapt_entry) node;
56 * A structure defining the FE representation of a CG-NAPT pipeline
58 struct pipeline_cgnapt_t {
64 TAILQ_HEAD(, app_pipeline_cgnapt_entry) entries;
70 * Init function for CG-NAPT FE.
73 * A pointer to the pipeline params.
76 static void *pipeline_cgnapt_init(struct pipeline_params *params,
77 __rte_unused void *arg)
79 struct pipeline_cgnapt_t *p;
82 /* Check input arguments */
83 if ((params == NULL) ||
84 (params->n_ports_in == 0) || (params->n_ports_out == 0))
87 /* Memory allocation */
88 size = RTE_CACHE_LINE_ROUNDUP(sizeof(struct pipeline_cgnapt_t));
89 p = rte_zmalloc(NULL, size, RTE_CACHE_LINE_SIZE);
94 p->n_ports_in = params->n_ports_in;
95 p->n_ports_out = params->n_ports_out;
97 TAILQ_INIT(&p->entries);
104 * Function for CG-NAPT FE cleanup.
107 * A pointer to the pipeline.
110 static int app_pipeline_cgnapt_free(void *pipeline)
112 struct pipeline_cgnapt_t *p = pipeline;
114 /* Check input arguments */
119 while (!TAILQ_EMPTY(&p->entries)) {
120 struct app_pipeline_cgnapt_entry *entry;
122 entry = TAILQ_FIRST(&p->entries);
123 TAILQ_REMOVE(&p->entries, entry, node);
132 * Function to print an IPv6 address
135 * A uint8_t array containing an IPv6 address
137 static void print_ipv6_address_u8(uint8_t ipv6_addr[16])
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]);
147 * Function to print an IPv6 address
150 * A uint16_t array containing an IPv6 address
152 static void print_ipv6_address_u16(uint16_t ipv6_addr[8])
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]);
160 * Function to print an IPv6 address
163 * A uint32_t array containing an IPv6 address
165 static void print_ipv6_address_u32(uint32_t ipv6_addr[4])
167 printf("Ipv6Address: %x:%x:%x:%x\n", ipv6_addr[0], ipv6_addr[1],
168 ipv6_addr[2], ipv6_addr[3]);
172 * Function to print a NAPT entry
175 * A pointer to a NAPT entry
177 static void print_entry(const struct app_pipeline_cgnapt_entry *entry)
179 const struct pipeline_cgnapt_entry_key *key = &entry->key;
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,
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,
230 * Function to list NAPT entries from FE storage
233 * A pointer to pipeline app
238 * 0 on success, negative on error.
241 app_pipeline_cgnapt_entry_ls(struct app_params *app, uint32_t pipeline_id)
243 struct pipeline_cgnapt_t *p;
244 struct app_pipeline_cgnapt_entry *it;
246 p = app_pipeline_data_fe(app, pipeline_id,
247 (struct pipeline_type *)&pipeline_cgnapt);
251 TAILQ_FOREACH(it, &p->entries, node)
253 print_static_cgnapt_entries();
254 printf(" - end of napt fe entry list -\n");
259 * Function to send a debug message to BE
262 * A pointer to pipeline app
266 * debug message contents
269 * 0 on success, negative on error.
272 app_pipeline_cgnapt_entry_dbg(struct app_params *app,
273 uint32_t pipeline_id, uint8_t *msg)
275 struct pipeline_cgnapt_t *p;
277 struct pipeline_cgnapt_entry_dbg_msg_req *req;
278 struct pipeline_cgnapt_entry_dbg_msg_rsp *rsp;
280 /* Check input arguments */
284 p = app_pipeline_data_fe(app, pipeline_id,
285 (struct pipeline_type *)&pipeline_cgnapt);
289 /* Allocate and write request */
290 req = app_msg_alloc(app);
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];
300 rsp = app_msg_send_recv(app, pipeline_id, req, MSG_TIMEOUT_DEFAULT);
306 app_msg_free(app, rsp);
307 printf("Error rsp->status %d\n", rsp->status);
312 app_msg_free(app, rsp);
318 * Function to send a NAPT entry add message to BE
321 * A pointer to pipeline app
325 * A pointer to NAPT entry key
326 * @param entry_params
327 * A pointer to NAPT entry params
330 * 0 on success, negative on error.
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)
337 struct pipeline_cgnapt_t *p;
339 struct pipeline_cgnapt_entry_add_msg_req *req;
340 struct pipeline_cgnapt_entry_add_msg_rsp *rsp;
342 /* Check input arguments */
343 if ((app == NULL) || (entry_params == NULL))
346 p = app_pipeline_data_fe(app, pipeline_id,
347 (struct pipeline_type *)&pipeline_cgnapt);
351 /* Allocate and write request */
352 req = app_msg_alloc(app);
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));
360 rsp = app_msg_send_recv(app, pipeline_id, req, MSG_TIMEOUT_DEFAULT);
364 /* Message buffer free */
365 app_msg_free(app, rsp);
370 * Function to send a multiple NAPT entry add message to BE
373 * A pointer to pipeline app
377 * A pointer to NAPT entry key
378 * @param entry_params
379 * A pointer to multiple NAPT entry params
382 * 0 on success, negative on error.
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)
389 struct pipeline_cgnapt_t *p;
391 struct pipeline_cgnapt_entry_addm_msg_req *req;
392 struct pipeline_cgnapt_entry_addm_msg_rsp *rsp;
394 /* Check input arguments */
395 if ((app == NULL) || (entry_params == NULL))
398 p = app_pipeline_data_fe(app, pipeline_id,
399 (struct pipeline_type *)&pipeline_cgnapt);
403 /* Allocate and write request */
404 req = app_msg_alloc(app);
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));
412 rsp = app_msg_send_recv(app, pipeline_id, req, MSG_TIMEOUT_DEFAULT);
416 /* Message buffer free */
417 app_msg_free(app, rsp);
422 * Function to send a NAPT entry delete message to BE
425 * A pointer to pipeline app
429 * A pointer to NAPT entry key
432 * 0 on success, negative on error.
435 app_pipeline_cgnapt_delete_entry(struct app_params *app,
436 uint32_t pipeline_id,
437 struct pipeline_cgnapt_entry_key *key)
439 struct pipeline_cgnapt_t *p;
441 struct pipeline_cgnapt_entry_delete_msg_req *req;
442 struct pipeline_cgnapt_entry_delete_msg_rsp *rsp;
445 uint8_t *KeyP = (uint8_t *) key;
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));
453 /* Check input arguments */
454 if ((app == NULL) || (key == NULL))
457 p = app_pipeline_data_fe(app, pipeline_id,
458 (struct pipeline_type *)&pipeline_cgnapt);
462 /* Allocate and write request */
463 req = app_msg_alloc(app);
467 req->type = PIPELINE_MSG_REQ_CUSTOM;
468 req->subtype = PIPELINE_CGNAPT_MSG_REQ_ENTRY_DEL;
469 memcpy(&req->key, key, sizeof(*key));
471 rsp = app_msg_send_recv(app, pipeline_id, req, MSG_TIMEOUT_DEFAULT);
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");
485 app_msg_free(app, rsp);
491 * A structure defining the entry add parse arguments.
493 struct cmd_entry_add_result {
494 cmdline_fixed_string_t p_string;
496 cmdline_fixed_string_t entry_string;
497 cmdline_fixed_string_t add_string;
498 cmdline_ipaddr_t prv_ip;
500 cmdline_ipaddr_t pub_ip;
506 * Helping function for add entry
508 * @param parsed_result
509 * A pointer parsed add arguments
511 * unused pointer to struct cmdline
517 cmd_entry_add_parsed(void *parsed_result,
518 __rte_unused struct cmdline *cl, void *data)
520 struct cmd_entry_add_result *params = parsed_result;
521 struct app_params *app = data;
522 struct app_pipeline_cgnapt_entry_params ent_params;
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);
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,
538 ent_params.prv_port = params->prv_port;
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;
545 status = app_pipeline_cgnapt_add_entry(app, params->p, &ent_params);
548 printf("CG-NAPT add multiple entry command failed, %d\n",
554 static cmdline_parse_token_string_t cmd_entry_add_p_string =
555 TOKEN_STRING_INITIALIZER(struct cmd_entry_add_result, p_string,
558 static cmdline_parse_token_num_t cmd_entry_add_p =
559 TOKEN_NUM_INITIALIZER(struct cmd_entry_add_result, p, UINT32);
561 static cmdline_parse_token_string_t cmd_entry_add_entry_string =
562 TOKEN_STRING_INITIALIZER(struct cmd_entry_add_result, entry_string,
565 static cmdline_parse_token_string_t cmd_entry_add_add_string =
566 TOKEN_STRING_INITIALIZER(struct cmd_entry_add_result, add_string,
569 static cmdline_parse_token_ipaddr_t cmd_entry_add_prv_ip =
570 TOKEN_IPADDR_INITIALIZER(struct cmd_entry_add_result, prv_ip);
572 static cmdline_parse_token_num_t cmd_entry_add_prv_port =
573 TOKEN_NUM_INITIALIZER(struct cmd_entry_add_result, prv_port, UINT16);
575 static cmdline_parse_token_ipaddr_t cmd_entry_add_pub_ip =
576 TOKEN_IPV4_INITIALIZER(struct cmd_entry_add_result, pub_ip);
578 static cmdline_parse_token_num_t cmd_entry_add_pub_port =
579 TOKEN_NUM_INITIALIZER(struct cmd_entry_add_result, pub_port, UINT16);
581 static cmdline_parse_token_num_t cmd_entry_add_pid =
582 TOKEN_NUM_INITIALIZER(struct cmd_entry_add_result, pid, UINT16);
584 static cmdline_parse_token_num_t cmd_entry_add_ttl =
585 TOKEN_NUM_INITIALIZER(struct cmd_entry_add_result, ttl, UINT32);
587 static cmdline_parse_inst_t cmd_entry_add = {
588 .f = cmd_entry_add_parsed,
590 .help_str = "NAPT entry add",
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,
607 * A structure defining the multiple entry add parse arguments.
609 struct cmd_entry_addm_result {
610 cmdline_fixed_string_t p_string;
612 cmdline_fixed_string_t entry_string;
613 cmdline_fixed_string_t addm_string;
614 cmdline_ipaddr_t prv_ip;
616 cmdline_ipaddr_t pub_ip;
621 uint16_t prv_port_max;
622 uint16_t pub_port_max;
626 * Helping function for add multiple entries
628 * @param parsed_result
629 * A pointer parsed add arguments
631 * unused pointer to struct cmdline
636 cmd_entry_addm_parsed(void *parsed_result,
637 __rte_unused struct cmdline *cl, void *data)
639 struct cmd_entry_addm_result *params = parsed_result;
640 struct app_params *app = data;
641 struct app_pipeline_cgnapt_mentry_params ent_params;
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);
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,
657 ent_params.prv_port = params->prv_port;
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;
667 status = app_pipeline_cgnapt_addm_entry(app, params->p, &ent_params);
670 printf("CG-NAPT add multiple entry command failed, %d\n",
676 static cmdline_parse_token_string_t cmd_entry_add_addm_string =
677 TOKEN_STRING_INITIALIZER(struct cmd_entry_addm_result, addm_string,
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);
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);
686 static cmdline_parse_token_num_t cmd_entry_addm_max_ue =
687 TOKEN_NUM_INITIALIZER(struct cmd_entry_addm_result, num_ue, UINT32);
689 static cmdline_parse_inst_t cmd_entry_addm = {
690 .f = cmd_entry_addm_parsed,
692 .help_str = "NAPT entry add multiple",
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,
712 * A structure defining the entry delete parse arguments.
714 struct cmd_entry_del_result {
715 cmdline_fixed_string_t p_string;
717 cmdline_fixed_string_t entry_string;
718 cmdline_fixed_string_t del_string;
725 * Helping function for delete entry
727 * @param parsed_result
728 * A pointer parsed add arguments
730 * unused pointer to struct cmdline
735 cmd_entry_del_parsed(void *parsed_result,
736 __rte_unused struct cmdline *cl, void *data)
738 struct cmd_entry_del_result *params = parsed_result;
739 struct app_params *app = data;
740 struct pipeline_cgnapt_entry_key key;
745 if (params->ip.family == AF_INET)
746 key.ip = rte_bswap32((uint32_t) params->ip.addr.ipv4.s_addr);
749 rte_bswap32((uint32_t) params->ip.addr.ipv6.s6_addr32[3]);
750 key.port = params->port;
751 key.pid = params->pid;
753 status = app_pipeline_cgnapt_delete_entry(app, params->p, &key);
756 printf("CG-NAPT entry del command failed\n");
761 static cmdline_parse_token_string_t cmd_entry_del_p_string =
762 TOKEN_STRING_INITIALIZER(struct cmd_entry_del_result, p_string,
765 static cmdline_parse_token_num_t cmd_entry_del_p =
766 TOKEN_NUM_INITIALIZER(struct cmd_entry_del_result, p, UINT32);
768 static cmdline_parse_token_string_t cmd_entry_del_entry_string =
769 TOKEN_STRING_INITIALIZER(struct cmd_entry_del_result, entry_string,
772 static cmdline_parse_token_string_t cmd_entry_del_del_string =
773 TOKEN_STRING_INITIALIZER(struct cmd_entry_del_result, del_string,
776 static cmdline_parse_token_ipaddr_t cmd_entry_del_ip =
777 TOKEN_IPADDR_INITIALIZER(struct cmd_entry_del_result, ip);
779 static cmdline_parse_token_num_t cmd_entry_del_port =
780 TOKEN_NUM_INITIALIZER(struct cmd_entry_del_result, port, UINT16);
782 static cmdline_parse_token_num_t cmd_entry_del_pid =
783 TOKEN_NUM_INITIALIZER(struct cmd_entry_del_result, pid, UINT16);
785 static cmdline_parse_inst_t cmd_entry_del = {
786 .f = cmd_entry_del_parsed,
788 .help_str = "Entry delete",
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,
802 * A structure defining the list entry parse arguments.
804 struct cmd_entry_ls_result {
805 cmdline_fixed_string_t p_string;
807 cmdline_fixed_string_t entry_string;
808 cmdline_fixed_string_t ls_string;
812 * Helping function for list entry
814 * @param parsed_result
815 * A pointer parsed add arguments
817 * unused pointer to struct cmdline
822 cmd_entry_ls_parsed(void *parsed_result,
823 __rte_unused struct cmdline *cl, void *data)
825 struct cmd_entry_ls_result *params = parsed_result;
826 struct app_params *app = data;
829 status = app_pipeline_cgnapt_entry_ls(app, params->p);
832 printf("Ls command failed\n");
837 static cmdline_parse_token_string_t cmd_entry_ls_p_string =
838 TOKEN_STRING_INITIALIZER(struct cmd_entry_ls_result, p_string, "p");
840 static cmdline_parse_token_num_t cmd_entry_ls_p =
841 TOKEN_NUM_INITIALIZER(struct cmd_entry_ls_result, p, UINT32);
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");
847 static cmdline_parse_token_string_t cmd_entry_ls_ls_string =
848 TOKEN_STRING_INITIALIZER(struct cmd_entry_ls_result, ls_string,
851 static cmdline_parse_inst_t cmd_entry_ls = {
852 .f = cmd_entry_ls_parsed,
854 .help_str = "Entry list",
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,
865 * A structure defining the dbg cmd parse arguments.
867 struct cmd_entry_dbg_result {
868 cmdline_fixed_string_t p_string;
870 cmdline_fixed_string_t entry_string;
871 cmdline_fixed_string_t dbg_string;
878 * Helping function for dbg cmd
880 * @param parsed_result
881 * A pointer parsed add arguments
883 * unused pointer to struct cmdline
888 cmd_entry_dbg_parsed(void *parsed_result,
889 __rte_unused struct cmdline *cl, void *data)
891 struct cmd_entry_dbg_result *params = parsed_result;
892 struct app_params *app = data;
896 msg[0] = params->cmd;
899 status = app_pipeline_cgnapt_entry_dbg(app, params->p, msg);
902 printf("Dbg Command failed\n");
907 static cmdline_parse_token_string_t cmd_entry_dbg_p_string =
908 TOKEN_STRING_INITIALIZER(struct cmd_entry_dbg_result, p_string, "p");
910 static cmdline_parse_token_num_t cmd_entry_dbg_p =
911 TOKEN_NUM_INITIALIZER(struct cmd_entry_dbg_result, p, UINT32);
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");
917 static cmdline_parse_token_string_t cmd_entry_dbg_dbg_string =
918 TOKEN_STRING_INITIALIZER(struct cmd_entry_dbg_result, dbg_string,
921 static cmdline_parse_token_num_t cmd_entry_dbg_cmd =
922 TOKEN_NUM_INITIALIZER(struct cmd_entry_dbg_result, cmd, UINT8);
924 static cmdline_parse_token_num_t cmd_entry_dbg_d1 =
925 TOKEN_NUM_INITIALIZER(struct cmd_entry_dbg_result, d1, UINT8);
927 static cmdline_parse_token_num_t cmd_entry_dbg_d2 =
928 TOKEN_NUM_INITIALIZER(struct cmd_entry_dbg_result, d2, UINT8);
930 static cmdline_parse_inst_t cmd_entry_dbg = {
931 .f = cmd_entry_dbg_parsed,
933 .help_str = "NAPT dbg cmd",
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,
947 * A structure defining num ip clients cmd parse arguments.
949 struct cmd_numipcli_result {
950 cmdline_fixed_string_t p_string;
952 cmdline_fixed_string_t numipcli_string;
956 * Helping function for printing num ip clients
958 * @param parsed_result
959 * Unused pointer parsed add arguments
961 * unused pointer to struct cmdline
963 * Unused void pointer data
966 cmd_numipcli_parsed(__rte_unused void *parsed_result,
967 __rte_unused struct cmdline *cl, __rte_unused void *data)
969 print_num_ip_clients();
972 static cmdline_parse_token_string_t cmd_numipcli_p_string =
973 TOKEN_STRING_INITIALIZER(struct cmd_numipcli_result, p_string, "p");
975 static cmdline_parse_token_num_t cmd_numipcli_p =
976 TOKEN_NUM_INITIALIZER(struct cmd_numipcli_result, p, UINT32);
978 static cmdline_parse_token_string_t cmd_numipcli_string =
979 TOKEN_STRING_INITIALIZER(struct cmd_numipcli_result,
980 numipcli_string, "numipcli");
982 static cmdline_parse_inst_t cmd_numipcli = {
983 .f = cmd_numipcli_parsed,
985 .help_str = "Num IP Clients command",
987 (void *)&cmd_numipcli_p_string,
988 (void *)&cmd_numipcli_p,
989 (void *)&cmd_numipcli_string,
995 * Function to send a ver cmd message to BE
998 * A pointer to pipeline app
1002 * debug message contents
1005 * 0 on success, negative on error.
1008 app_pipeline_cgnapt_ver(struct app_params *app,
1009 uint32_t pipeline_id, uint8_t *msg)
1012 struct pipeline_cgnapt_t *p;
1013 struct pipeline_cgnapt_entry_dbg_msg_req *req;
1014 struct pipeline_cgnapt_entry_dbg_msg_rsp *rsp;
1016 /* Check input arguments */
1020 p = app_pipeline_data_fe(app, pipeline_id,
1021 (struct pipeline_type *)&pipeline_cgnapt);
1025 /* Allocate and write request */
1026 req = app_msg_alloc(app);
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];
1035 rsp = app_msg_send_recv(app, pipeline_id, req, MSG_TIMEOUT_DEFAULT);
1041 app_msg_free(app, rsp);
1042 printf("Error rsp->status %d\n", rsp->status);
1047 app_msg_free(app, rsp);
1053 * A structure defining ver cmd parse arguments.
1055 struct cmd_ver_result {
1056 cmdline_fixed_string_t p_string;
1058 cmdline_fixed_string_t ver_string;
1064 * Helping function for ver cmd
1066 * @param parsed_result
1067 * A pointer parsed add arguments
1069 * unused pointer to struct cmdline
1074 cmd_ver_parsed(void *parsed_result, __rte_unused struct cmdline *cl, void *data)
1076 struct cmd_ver_result *params = parsed_result;
1077 struct app_params *app = data;
1081 msg[0] = params->cmd;
1082 msg[1] = params->d1;
1083 status = app_pipeline_cgnapt_ver(app, params->p, msg);
1086 printf("Version Command failed\n");
1091 static cmdline_parse_token_string_t cmd_ver_p_string =
1092 TOKEN_STRING_INITIALIZER(struct cmd_ver_result, p_string, "p");
1094 static cmdline_parse_token_num_t cmd_ver_p =
1095 TOKEN_NUM_INITIALIZER(struct cmd_ver_result, p, UINT32);
1097 static cmdline_parse_token_string_t cmd_ver_string =
1098 TOKEN_STRING_INITIALIZER(struct cmd_ver_result,
1101 static cmdline_parse_token_num_t cmd_ver_cmd =
1102 TOKEN_NUM_INITIALIZER(struct cmd_ver_result, cmd, UINT8);
1104 static cmdline_parse_token_num_t cmd_ver_d1 =
1105 TOKEN_NUM_INITIALIZER(struct cmd_ver_result, d1, UINT8);
1107 static cmdline_parse_inst_t cmd_ver = {
1108 .f = cmd_ver_parsed,
1110 .help_str = "NAPT ver cmd",
1112 (void *)&cmd_ver_p_string,
1114 (void *)&cmd_ver_string,
1115 (void *)&cmd_ver_cmd,
1116 (void *)&cmd_ver_d1,
1122 * Function to send a nsp add cmd message to BE
1125 * A pointer to pipeline app
1126 * @param pipeline_id
1129 * A pointer to struct pipeline_cgnapt_nsp_t
1132 * 0 on success, negative on error.
1135 app_pipeline_cgnapt_add_nsp(struct app_params *app,
1136 uint32_t pipeline_id,
1137 struct pipeline_cgnapt_nsp_t *nsp)
1140 struct pipeline_cgnapt_t *p;
1141 struct pipeline_cgnapt_nsp_add_msg_req *req;
1142 struct pipeline_cgnapt_nsp_add_msg_rsp *rsp;
1144 /* Check input arguments */
1148 printf("1st if condition\n");
1150 p = app_pipeline_data_fe(app, pipeline_id,
1151 (struct pipeline_type *)&pipeline_cgnapt);
1155 printf("2st if condition\n");
1156 /* Allocate and write request */
1157 req = app_msg_alloc(app);
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));
1166 rsp = app_msg_send_recv(app, pipeline_id, req, MSG_TIMEOUT_DEFAULT);
1170 printf("4st if condition\n");
1173 app_msg_free(app, rsp);
1174 printf("Error rsp->status %d\n", rsp->status);
1179 app_msg_free(app, rsp);
1185 * A structure defining nsp add cmd parse arguments.
1187 struct cmd_nsp_add_result {
1188 cmdline_fixed_string_t p_string;
1190 cmdline_fixed_string_t nsp_string;
1191 cmdline_fixed_string_t add_string;
1192 cmdline_ipaddr_t ip;
1196 * Helping function for nsp add cmd
1198 * @param parsed_result
1199 * A pointer parsed add arguments
1201 * unused pointer to struct cmdline
1206 cmd_nsp_add_parsed(void *parsed_result, __rte_unused struct cmdline *cl,
1209 struct cmd_nsp_add_result *params = parsed_result;
1210 struct app_params *app = data;
1212 struct pipeline_cgnapt_nsp_t nsp;
1214 memcpy(&nsp.prefix, ¶ms->ip.addr.ipv6.s6_addr, 16);
1215 nsp.depth = params->ip.prefixlen;
1216 status = app_pipeline_cgnapt_add_nsp(app, params->p, &nsp);
1218 printf("NSP ADD Command failed\n");
1223 static cmdline_parse_token_string_t cmd_add_nsp_p_string =
1224 TOKEN_STRING_INITIALIZER(struct cmd_nsp_add_result, p_string, "p");
1226 static cmdline_parse_token_num_t cmd_add_nsp_p =
1227 TOKEN_NUM_INITIALIZER(struct cmd_nsp_add_result, p, UINT32);
1229 static cmdline_parse_token_string_t cmd_add_nsp_string =
1230 TOKEN_STRING_INITIALIZER(struct cmd_nsp_add_result,
1233 static cmdline_parse_token_string_t cmd_add_nsp_add_string =
1234 TOKEN_STRING_INITIALIZER(struct cmd_nsp_add_result,
1237 static cmdline_parse_token_ipaddr_t cmd_add_nsp_ip =
1238 TOKEN_IPNET_INITIALIZER(struct cmd_nsp_add_result, ip);
1240 static cmdline_parse_inst_t cmd_nsp_add = {
1241 .f = cmd_nsp_add_parsed,
1243 .help_str = "NAPT NSP ADD cmd",
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,
1255 * Function to send a nsp del cmd message to BE
1258 * A pointer to pipeline app
1259 * @param pipeline_id
1262 * A pointer to struct pipeline_cgnapt_nsp_t
1265 * 0 on success, negative on error.
1268 app_pipeline_cgnapt_del_nsp(struct app_params *app,
1269 uint32_t pipeline_id,
1270 struct pipeline_cgnapt_nsp_t *nsp)
1273 struct pipeline_cgnapt_t *p;
1274 struct pipeline_cgnapt_nsp_del_msg_req *req;
1275 struct pipeline_cgnapt_nsp_del_msg_rsp *rsp;
1277 /* Check input arguments */
1281 p = app_pipeline_data_fe(app, pipeline_id,
1282 (struct pipeline_type *)&pipeline_cgnapt);
1286 /* Allocate and write request */
1287 req = app_msg_alloc(app);
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));
1295 rsp = app_msg_send_recv(app, pipeline_id, req, MSG_TIMEOUT_DEFAULT);
1301 app_msg_free(app, rsp);
1302 printf("Error rsp->status %d\n", rsp->status);
1307 app_msg_free(app, rsp);
1313 * A structure defining nsp del cmd parse arguments.
1315 struct cmd_nsp_del_result {
1316 cmdline_fixed_string_t p_string;
1318 cmdline_fixed_string_t nsp_string;
1319 cmdline_fixed_string_t del_string;
1320 cmdline_ipaddr_t ip;
1324 * Helping function for nsp del cmd
1326 * @param parsed_result
1327 * A pointer parsed add arguments
1329 * unused pointer to struct cmdline
1334 cmd_nsp_del_parsed(void *parsed_result, __rte_unused struct cmdline *cl,
1337 struct cmd_nsp_del_result *params = parsed_result;
1338 struct app_params *app = data;
1340 struct pipeline_cgnapt_nsp_t nsp;
1342 memcpy(&nsp.prefix, ¶ms->ip.addr.ipv6.s6_addr, 16);
1343 nsp.depth = params->ip.prefixlen;
1344 status = app_pipeline_cgnapt_del_nsp(app, params->p, &nsp);
1347 printf("NSP DEL Command failed\n");
1352 static cmdline_parse_token_string_t cmd_del_nsp_p_string =
1353 TOKEN_STRING_INITIALIZER(struct cmd_nsp_del_result, p_string, "p");
1355 static cmdline_parse_token_num_t cmd_del_nsp_p =
1356 TOKEN_NUM_INITIALIZER(struct cmd_nsp_del_result, p, UINT32);
1358 static cmdline_parse_token_string_t cmd_del_nsp_string =
1359 TOKEN_STRING_INITIALIZER(struct cmd_nsp_del_result,
1362 static cmdline_parse_token_string_t cmd_del_nsp_del_string =
1363 TOKEN_STRING_INITIALIZER(struct cmd_nsp_del_result,
1366 static cmdline_parse_token_ipaddr_t cmd_del_nsp_ip =
1367 TOKEN_IPNET_INITIALIZER(struct cmd_nsp_del_result, ip);
1369 static cmdline_parse_inst_t cmd_nsp_del = {
1370 .f = cmd_nsp_del_parsed,
1372 .help_str = "NAPT NSP DEL cmd",
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,
1384 * A structure defining the cgnapt stats cmd parse arguments.
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;
1393 * Helping function for cgnapt stats cmd
1395 * @param parsed_result
1396 * A pointer parsed add arguments
1398 * unused pointer to struct cmdline
1403 cmd_cgnapt_stats_parsed(
1404 __rte_unused void *parsed_result,
1405 __rte_unused struct cmdline *cl,
1406 __rte_unused void *data)
1411 static cmdline_parse_token_string_t cmd_cgnapt_stats_p_string =
1412 TOKEN_STRING_INITIALIZER(struct cmd_cgnapt_stats_result, p_string, "p");
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");
1418 static cmdline_parse_token_string_t cmd_cgnapt_stats_stats_string =
1419 TOKEN_STRING_INITIALIZER(struct cmd_cgnapt_stats_result, stats_string,
1422 static cmdline_parse_inst_t cmd_stats = {
1423 .f = cmd_cgnapt_stats_parsed,
1425 .help_str = "CGNAPT stats cmd",
1427 (void *)&cmd_cgnapt_stats_p_string,
1428 (void *)&cmd_cgnapt_stats_cgnapt_string,
1429 (void *)&cmd_cgnapt_stats_stats_string,
1435 * A structure defining the cgnapt clear stats cmd parse arguments.
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;
1445 * Helping function for cgnapt clear stats cmd
1447 * @param parsed_result
1448 * A pointer parsed add arguments
1450 * unused pointer to struct cmdline
1455 cmd_cgnapt_clear_stats_parsed(
1456 __rte_unused void *parsed_result,
1457 __rte_unused struct cmdline *cl,
1458 __rte_unused void *data)
1460 all_cgnapt_clear_stats();
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");
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");
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");
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,
1478 static cmdline_parse_inst_t cmd_clear_stats = {
1479 .f = cmd_cgnapt_clear_stats_parsed,
1481 .help_str = "CGNAPT clear stats cmd",
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,
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,
1503 (cmdline_parse_inst_t *) &cmd_pcp,
1505 (cmdline_parse_inst_t *) &cmd_stats,
1506 (cmdline_parse_inst_t *) &cmd_clear_stats,
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,
1516 struct pipeline_type pipeline_cgnapt = {
1518 .be_ops = &pipeline_cgnapt_be_ops,
1519 .fe_ops = &pipeline_cgnapt_fe_ops,