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 printf("Successfully deleted the entry\n");
483 app_msg_free(app, rsp);
489 * A structure defining the entry add parse arguments.
491 struct cmd_entry_add_result {
492 cmdline_fixed_string_t p_string;
494 cmdline_fixed_string_t entry_string;
495 cmdline_fixed_string_t add_string;
496 cmdline_ipaddr_t prv_ip;
498 cmdline_ipaddr_t pub_ip;
504 * Helping function for add entry
506 * @param parsed_result
507 * A pointer parsed add arguments
509 * unused pointer to struct cmdline
515 cmd_entry_add_parsed(void *parsed_result,
516 __rte_unused struct cmdline *cl, void *data)
518 struct cmd_entry_add_result *params = parsed_result;
519 struct app_params *app = data;
520 struct app_pipeline_cgnapt_entry_params ent_params;
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);
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,
536 ent_params.prv_port = params->prv_port;
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;
543 status = app_pipeline_cgnapt_add_entry(app, params->p, &ent_params);
546 printf("CG-NAPT add multiple entry command failed, %d\n",
552 static cmdline_parse_token_string_t cmd_entry_add_p_string =
553 TOKEN_STRING_INITIALIZER(struct cmd_entry_add_result, p_string,
556 static cmdline_parse_token_num_t cmd_entry_add_p =
557 TOKEN_NUM_INITIALIZER(struct cmd_entry_add_result, p, UINT32);
559 static cmdline_parse_token_string_t cmd_entry_add_entry_string =
560 TOKEN_STRING_INITIALIZER(struct cmd_entry_add_result, entry_string,
563 static cmdline_parse_token_string_t cmd_entry_add_add_string =
564 TOKEN_STRING_INITIALIZER(struct cmd_entry_add_result, add_string,
567 static cmdline_parse_token_ipaddr_t cmd_entry_add_prv_ip =
568 TOKEN_IPADDR_INITIALIZER(struct cmd_entry_add_result, prv_ip);
570 static cmdline_parse_token_num_t cmd_entry_add_prv_port =
571 TOKEN_NUM_INITIALIZER(struct cmd_entry_add_result, prv_port, UINT16);
573 static cmdline_parse_token_ipaddr_t cmd_entry_add_pub_ip =
574 TOKEN_IPV4_INITIALIZER(struct cmd_entry_add_result, pub_ip);
576 static cmdline_parse_token_num_t cmd_entry_add_pub_port =
577 TOKEN_NUM_INITIALIZER(struct cmd_entry_add_result, pub_port, UINT16);
579 static cmdline_parse_token_num_t cmd_entry_add_pid =
580 TOKEN_NUM_INITIALIZER(struct cmd_entry_add_result, pid, UINT16);
582 static cmdline_parse_token_num_t cmd_entry_add_ttl =
583 TOKEN_NUM_INITIALIZER(struct cmd_entry_add_result, ttl, UINT32);
585 static cmdline_parse_inst_t cmd_entry_add = {
586 .f = cmd_entry_add_parsed,
588 .help_str = "NAPT entry add",
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,
605 * A structure defining the multiple entry add parse arguments.
607 struct cmd_entry_addm_result {
608 cmdline_fixed_string_t p_string;
610 cmdline_fixed_string_t entry_string;
611 cmdline_fixed_string_t addm_string;
612 cmdline_ipaddr_t prv_ip;
614 cmdline_ipaddr_t pub_ip;
619 uint16_t prv_port_max;
620 uint16_t pub_port_max;
624 * Helping function for add multiple entries
626 * @param parsed_result
627 * A pointer parsed add arguments
629 * unused pointer to struct cmdline
634 cmd_entry_addm_parsed(void *parsed_result,
635 __rte_unused struct cmdline *cl, void *data)
637 struct cmd_entry_addm_result *params = parsed_result;
638 struct app_params *app = data;
639 struct app_pipeline_cgnapt_mentry_params ent_params;
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);
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,
655 ent_params.prv_port = params->prv_port;
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;
665 status = app_pipeline_cgnapt_addm_entry(app, params->p, &ent_params);
668 printf("CG-NAPT add multiple entry command failed, %d\n",
674 static cmdline_parse_token_string_t cmd_entry_add_addm_string =
675 TOKEN_STRING_INITIALIZER(struct cmd_entry_addm_result, addm_string,
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);
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);
684 static cmdline_parse_token_num_t cmd_entry_addm_max_ue =
685 TOKEN_NUM_INITIALIZER(struct cmd_entry_addm_result, num_ue, UINT32);
687 static cmdline_parse_inst_t cmd_entry_addm = {
688 .f = cmd_entry_addm_parsed,
690 .help_str = "NAPT entry add multiple",
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,
710 * A structure defining the entry delete parse arguments.
712 struct cmd_entry_del_result {
713 cmdline_fixed_string_t p_string;
715 cmdline_fixed_string_t entry_string;
716 cmdline_fixed_string_t del_string;
723 * Helping function for delete entry
725 * @param parsed_result
726 * A pointer parsed add arguments
728 * unused pointer to struct cmdline
733 cmd_entry_del_parsed(void *parsed_result,
734 __rte_unused struct cmdline *cl, void *data)
736 struct cmd_entry_del_result *params = parsed_result;
737 struct app_params *app = data;
738 struct pipeline_cgnapt_entry_key key;
743 if (params->ip.family == AF_INET)
744 key.ip = rte_bswap32((uint32_t) params->ip.addr.ipv4.s_addr);
747 rte_bswap32((uint32_t) params->ip.addr.ipv6.s6_addr32[3]);
748 key.port = params->port;
749 key.pid = params->pid;
751 status = app_pipeline_cgnapt_delete_entry(app, params->p, &key);
754 printf("CG-NAPT entry del command failed\n");
759 static cmdline_parse_token_string_t cmd_entry_del_p_string =
760 TOKEN_STRING_INITIALIZER(struct cmd_entry_del_result, p_string,
763 static cmdline_parse_token_num_t cmd_entry_del_p =
764 TOKEN_NUM_INITIALIZER(struct cmd_entry_del_result, p, UINT32);
766 static cmdline_parse_token_string_t cmd_entry_del_entry_string =
767 TOKEN_STRING_INITIALIZER(struct cmd_entry_del_result, entry_string,
770 static cmdline_parse_token_string_t cmd_entry_del_del_string =
771 TOKEN_STRING_INITIALIZER(struct cmd_entry_del_result, del_string,
774 static cmdline_parse_token_ipaddr_t cmd_entry_del_ip =
775 TOKEN_IPADDR_INITIALIZER(struct cmd_entry_del_result, ip);
777 static cmdline_parse_token_num_t cmd_entry_del_port =
778 TOKEN_NUM_INITIALIZER(struct cmd_entry_del_result, port, UINT16);
780 static cmdline_parse_token_num_t cmd_entry_del_pid =
781 TOKEN_NUM_INITIALIZER(struct cmd_entry_del_result, pid, UINT16);
783 static cmdline_parse_inst_t cmd_entry_del = {
784 .f = cmd_entry_del_parsed,
786 .help_str = "Entry delete",
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,
800 * A structure defining the list entry parse arguments.
802 struct cmd_entry_ls_result {
803 cmdline_fixed_string_t p_string;
805 cmdline_fixed_string_t entry_string;
806 cmdline_fixed_string_t ls_string;
810 * Helping function for list entry
812 * @param parsed_result
813 * A pointer parsed add arguments
815 * unused pointer to struct cmdline
820 cmd_entry_ls_parsed(void *parsed_result,
821 __rte_unused struct cmdline *cl, void *data)
823 struct cmd_entry_ls_result *params = parsed_result;
824 struct app_params *app = data;
827 status = app_pipeline_cgnapt_entry_ls(app, params->p);
830 printf("Ls command failed\n");
835 static cmdline_parse_token_string_t cmd_entry_ls_p_string =
836 TOKEN_STRING_INITIALIZER(struct cmd_entry_ls_result, p_string, "p");
838 static cmdline_parse_token_num_t cmd_entry_ls_p =
839 TOKEN_NUM_INITIALIZER(struct cmd_entry_ls_result, p, UINT32);
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");
845 static cmdline_parse_token_string_t cmd_entry_ls_ls_string =
846 TOKEN_STRING_INITIALIZER(struct cmd_entry_ls_result, ls_string,
849 static cmdline_parse_inst_t cmd_entry_ls = {
850 .f = cmd_entry_ls_parsed,
852 .help_str = "Entry list",
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,
863 * A structure defining the dbg cmd parse arguments.
865 struct cmd_entry_dbg_result {
866 cmdline_fixed_string_t p_string;
868 cmdline_fixed_string_t entry_string;
869 cmdline_fixed_string_t dbg_string;
876 * Helping function for dbg cmd
878 * @param parsed_result
879 * A pointer parsed add arguments
881 * unused pointer to struct cmdline
886 cmd_entry_dbg_parsed(void *parsed_result,
887 __rte_unused struct cmdline *cl, void *data)
889 struct cmd_entry_dbg_result *params = parsed_result;
890 struct app_params *app = data;
894 msg[0] = params->cmd;
897 status = app_pipeline_cgnapt_entry_dbg(app, params->p, msg);
900 printf("Dbg Command failed\n");
905 static cmdline_parse_token_string_t cmd_entry_dbg_p_string =
906 TOKEN_STRING_INITIALIZER(struct cmd_entry_dbg_result, p_string, "p");
908 static cmdline_parse_token_num_t cmd_entry_dbg_p =
909 TOKEN_NUM_INITIALIZER(struct cmd_entry_dbg_result, p, UINT32);
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");
915 static cmdline_parse_token_string_t cmd_entry_dbg_dbg_string =
916 TOKEN_STRING_INITIALIZER(struct cmd_entry_dbg_result, dbg_string,
919 static cmdline_parse_token_num_t cmd_entry_dbg_cmd =
920 TOKEN_NUM_INITIALIZER(struct cmd_entry_dbg_result, cmd, UINT8);
922 static cmdline_parse_token_num_t cmd_entry_dbg_d1 =
923 TOKEN_NUM_INITIALIZER(struct cmd_entry_dbg_result, d1, UINT8);
925 static cmdline_parse_token_num_t cmd_entry_dbg_d2 =
926 TOKEN_NUM_INITIALIZER(struct cmd_entry_dbg_result, d2, UINT8);
928 static cmdline_parse_inst_t cmd_entry_dbg = {
929 .f = cmd_entry_dbg_parsed,
931 .help_str = "NAPT dbg cmd",
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,
945 * A structure defining num ip clients cmd parse arguments.
947 struct cmd_numipcli_result {
948 cmdline_fixed_string_t p_string;
950 cmdline_fixed_string_t numipcli_string;
954 * Helping function for printing num ip clients
956 * @param parsed_result
957 * Unused pointer parsed add arguments
959 * unused pointer to struct cmdline
961 * Unused void pointer data
964 cmd_numipcli_parsed(__rte_unused void *parsed_result,
965 __rte_unused struct cmdline *cl, __rte_unused void *data)
967 print_num_ip_clients();
970 static cmdline_parse_token_string_t cmd_numipcli_p_string =
971 TOKEN_STRING_INITIALIZER(struct cmd_numipcli_result, p_string, "p");
973 static cmdline_parse_token_num_t cmd_numipcli_p =
974 TOKEN_NUM_INITIALIZER(struct cmd_numipcli_result, p, UINT32);
976 static cmdline_parse_token_string_t cmd_numipcli_string =
977 TOKEN_STRING_INITIALIZER(struct cmd_numipcli_result,
978 numipcli_string, "numipcli");
980 static cmdline_parse_inst_t cmd_numipcli = {
981 .f = cmd_numipcli_parsed,
983 .help_str = "Num IP Clients command",
985 (void *)&cmd_numipcli_p_string,
986 (void *)&cmd_numipcli_p,
987 (void *)&cmd_numipcli_string,
993 * Function to send a ver cmd message to BE
996 * A pointer to pipeline app
1000 * debug message contents
1003 * 0 on success, negative on error.
1006 app_pipeline_cgnapt_ver(struct app_params *app,
1007 uint32_t pipeline_id, uint8_t *msg)
1010 struct pipeline_cgnapt_t *p;
1011 struct pipeline_cgnapt_entry_dbg_msg_req *req;
1012 struct pipeline_cgnapt_entry_dbg_msg_rsp *rsp;
1014 /* Check input arguments */
1018 p = app_pipeline_data_fe(app, pipeline_id,
1019 (struct pipeline_type *)&pipeline_cgnapt);
1023 /* Allocate and write request */
1024 req = app_msg_alloc(app);
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];
1033 rsp = app_msg_send_recv(app, pipeline_id, req, MSG_TIMEOUT_DEFAULT);
1039 app_msg_free(app, rsp);
1040 printf("Error rsp->status %d\n", rsp->status);
1045 app_msg_free(app, rsp);
1051 * A structure defining ver cmd parse arguments.
1053 struct cmd_ver_result {
1054 cmdline_fixed_string_t p_string;
1056 cmdline_fixed_string_t ver_string;
1062 * Helping function for ver cmd
1064 * @param parsed_result
1065 * A pointer parsed add arguments
1067 * unused pointer to struct cmdline
1072 cmd_ver_parsed(void *parsed_result, __rte_unused struct cmdline *cl, void *data)
1074 struct cmd_ver_result *params = parsed_result;
1075 struct app_params *app = data;
1079 msg[0] = params->cmd;
1080 msg[1] = params->d1;
1081 status = app_pipeline_cgnapt_ver(app, params->p, msg);
1084 printf("Version Command failed\n");
1089 static cmdline_parse_token_string_t cmd_ver_p_string =
1090 TOKEN_STRING_INITIALIZER(struct cmd_ver_result, p_string, "p");
1092 static cmdline_parse_token_num_t cmd_ver_p =
1093 TOKEN_NUM_INITIALIZER(struct cmd_ver_result, p, UINT32);
1095 static cmdline_parse_token_string_t cmd_ver_string =
1096 TOKEN_STRING_INITIALIZER(struct cmd_ver_result,
1099 static cmdline_parse_token_num_t cmd_ver_cmd =
1100 TOKEN_NUM_INITIALIZER(struct cmd_ver_result, cmd, UINT8);
1102 static cmdline_parse_token_num_t cmd_ver_d1 =
1103 TOKEN_NUM_INITIALIZER(struct cmd_ver_result, d1, UINT8);
1105 static cmdline_parse_inst_t cmd_ver = {
1106 .f = cmd_ver_parsed,
1108 .help_str = "NAPT ver cmd",
1110 (void *)&cmd_ver_p_string,
1112 (void *)&cmd_ver_string,
1113 (void *)&cmd_ver_cmd,
1114 (void *)&cmd_ver_d1,
1120 * Function to send a nsp add cmd message to BE
1123 * A pointer to pipeline app
1124 * @param pipeline_id
1127 * A pointer to struct pipeline_cgnapt_nsp_t
1130 * 0 on success, negative on error.
1133 app_pipeline_cgnapt_add_nsp(struct app_params *app,
1134 uint32_t pipeline_id,
1135 struct pipeline_cgnapt_nsp_t *nsp)
1138 struct pipeline_cgnapt_t *p;
1139 struct pipeline_cgnapt_nsp_add_msg_req *req;
1140 struct pipeline_cgnapt_nsp_add_msg_rsp *rsp;
1142 /* Check input arguments */
1146 printf("1st if condition\n");
1148 p = app_pipeline_data_fe(app, pipeline_id,
1149 (struct pipeline_type *)&pipeline_cgnapt);
1153 printf("2st if condition\n");
1154 /* Allocate and write request */
1155 req = app_msg_alloc(app);
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));
1164 rsp = app_msg_send_recv(app, pipeline_id, req, MSG_TIMEOUT_DEFAULT);
1168 printf("4st if condition\n");
1171 app_msg_free(app, rsp);
1172 printf("Error rsp->status %d\n", rsp->status);
1177 app_msg_free(app, rsp);
1183 * A structure defining nsp add cmd parse arguments.
1185 struct cmd_nsp_add_result {
1186 cmdline_fixed_string_t p_string;
1188 cmdline_fixed_string_t nsp_string;
1189 cmdline_fixed_string_t add_string;
1190 cmdline_ipaddr_t ip;
1194 * Helping function for nsp add cmd
1196 * @param parsed_result
1197 * A pointer parsed add arguments
1199 * unused pointer to struct cmdline
1204 cmd_nsp_add_parsed(void *parsed_result, __rte_unused struct cmdline *cl,
1207 struct cmd_nsp_add_result *params = parsed_result;
1208 struct app_params *app = data;
1210 struct pipeline_cgnapt_nsp_t nsp;
1212 memcpy(&nsp.prefix, ¶ms->ip.addr.ipv6.s6_addr, 16);
1213 nsp.depth = params->ip.prefixlen;
1214 status = app_pipeline_cgnapt_add_nsp(app, params->p, &nsp);
1216 printf("NSP ADD Command failed\n");
1221 static cmdline_parse_token_string_t cmd_add_nsp_p_string =
1222 TOKEN_STRING_INITIALIZER(struct cmd_nsp_add_result, p_string, "p");
1224 static cmdline_parse_token_num_t cmd_add_nsp_p =
1225 TOKEN_NUM_INITIALIZER(struct cmd_nsp_add_result, p, UINT32);
1227 static cmdline_parse_token_string_t cmd_add_nsp_string =
1228 TOKEN_STRING_INITIALIZER(struct cmd_nsp_add_result,
1231 static cmdline_parse_token_string_t cmd_add_nsp_add_string =
1232 TOKEN_STRING_INITIALIZER(struct cmd_nsp_add_result,
1235 static cmdline_parse_token_ipaddr_t cmd_add_nsp_ip =
1236 TOKEN_IPNET_INITIALIZER(struct cmd_nsp_add_result, ip);
1238 static cmdline_parse_inst_t cmd_nsp_add = {
1239 .f = cmd_nsp_add_parsed,
1241 .help_str = "NAPT NSP ADD cmd",
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,
1253 * Function to send a nsp del cmd message to BE
1256 * A pointer to pipeline app
1257 * @param pipeline_id
1260 * A pointer to struct pipeline_cgnapt_nsp_t
1263 * 0 on success, negative on error.
1266 app_pipeline_cgnapt_del_nsp(struct app_params *app,
1267 uint32_t pipeline_id,
1268 struct pipeline_cgnapt_nsp_t *nsp)
1271 struct pipeline_cgnapt_t *p;
1272 struct pipeline_cgnapt_nsp_del_msg_req *req;
1273 struct pipeline_cgnapt_nsp_del_msg_rsp *rsp;
1275 /* Check input arguments */
1279 p = app_pipeline_data_fe(app, pipeline_id,
1280 (struct pipeline_type *)&pipeline_cgnapt);
1284 /* Allocate and write request */
1285 req = app_msg_alloc(app);
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));
1293 rsp = app_msg_send_recv(app, pipeline_id, req, MSG_TIMEOUT_DEFAULT);
1299 app_msg_free(app, rsp);
1300 printf("Error rsp->status %d\n", rsp->status);
1305 app_msg_free(app, rsp);
1311 * A structure defining nsp del cmd parse arguments.
1313 struct cmd_nsp_del_result {
1314 cmdline_fixed_string_t p_string;
1316 cmdline_fixed_string_t nsp_string;
1317 cmdline_fixed_string_t del_string;
1318 cmdline_ipaddr_t ip;
1322 * Helping function for nsp del cmd
1324 * @param parsed_result
1325 * A pointer parsed add arguments
1327 * unused pointer to struct cmdline
1332 cmd_nsp_del_parsed(void *parsed_result, __rte_unused struct cmdline *cl,
1335 struct cmd_nsp_del_result *params = parsed_result;
1336 struct app_params *app = data;
1338 struct pipeline_cgnapt_nsp_t nsp;
1340 memcpy(&nsp.prefix, ¶ms->ip.addr.ipv6.s6_addr, 16);
1341 nsp.depth = params->ip.prefixlen;
1342 status = app_pipeline_cgnapt_del_nsp(app, params->p, &nsp);
1345 printf("NSP DEL Command failed\n");
1350 static cmdline_parse_token_string_t cmd_del_nsp_p_string =
1351 TOKEN_STRING_INITIALIZER(struct cmd_nsp_del_result, p_string, "p");
1353 static cmdline_parse_token_num_t cmd_del_nsp_p =
1354 TOKEN_NUM_INITIALIZER(struct cmd_nsp_del_result, p, UINT32);
1356 static cmdline_parse_token_string_t cmd_del_nsp_string =
1357 TOKEN_STRING_INITIALIZER(struct cmd_nsp_del_result,
1360 static cmdline_parse_token_string_t cmd_del_nsp_del_string =
1361 TOKEN_STRING_INITIALIZER(struct cmd_nsp_del_result,
1364 static cmdline_parse_token_ipaddr_t cmd_del_nsp_ip =
1365 TOKEN_IPNET_INITIALIZER(struct cmd_nsp_del_result, ip);
1367 static cmdline_parse_inst_t cmd_nsp_del = {
1368 .f = cmd_nsp_del_parsed,
1370 .help_str = "NAPT NSP DEL cmd",
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,
1382 * A structure defining the cgnapt stats cmd parse arguments.
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;
1391 * Helping function for cgnapt stats cmd
1393 * @param parsed_result
1394 * A pointer parsed add arguments
1396 * unused pointer to struct cmdline
1401 cmd_cgnapt_stats_parsed(
1402 __rte_unused void *parsed_result,
1403 __rte_unused struct cmdline *cl,
1404 __rte_unused void *data)
1409 static cmdline_parse_token_string_t cmd_cgnapt_stats_p_string =
1410 TOKEN_STRING_INITIALIZER(struct cmd_cgnapt_stats_result, p_string, "p");
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");
1416 static cmdline_parse_token_string_t cmd_cgnapt_stats_stats_string =
1417 TOKEN_STRING_INITIALIZER(struct cmd_cgnapt_stats_result, stats_string,
1420 static cmdline_parse_inst_t cmd_stats = {
1421 .f = cmd_cgnapt_stats_parsed,
1423 .help_str = "CGNAPT stats cmd",
1425 (void *)&cmd_cgnapt_stats_p_string,
1426 (void *)&cmd_cgnapt_stats_cgnapt_string,
1427 (void *)&cmd_cgnapt_stats_stats_string,
1433 * A structure defining the cgnapt clear stats cmd parse arguments.
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;
1443 * Helping function for cgnapt clear stats cmd
1445 * @param parsed_result
1446 * A pointer parsed add arguments
1448 * unused pointer to struct cmdline
1453 cmd_cgnapt_clear_stats_parsed(
1454 __rte_unused void *parsed_result,
1455 __rte_unused struct cmdline *cl,
1456 __rte_unused void *data)
1458 all_cgnapt_clear_stats();
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");
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");
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");
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,
1476 static cmdline_parse_inst_t cmd_clear_stats = {
1477 .f = cmd_cgnapt_clear_stats_parsed,
1479 .help_str = "CGNAPT clear stats cmd",
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,
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,
1501 (cmdline_parse_inst_t *) &cmd_pcp,
1503 (cmdline_parse_inst_t *) &cmd_stats,
1504 (cmdline_parse_inst_t *) &cmd_clear_stats,
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,
1514 struct pipeline_type pipeline_cgnapt = {
1516 .be_ops = &pipeline_cgnapt_be_ops,
1517 .fe_ops = &pipeline_cgnapt_fe_ops,