summaryrefslogtreecommitdiffstats
path: root/VNFs/vCGNAPT/pipeline/pipeline_cgnapt.c
blob: 239d34f9e4e8916f3495d7d544c2c978b02ec1b3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
<
.. This work is licensed under a Creative Commons Attribution 4.0 International
.. License.
.. http://creativecommons.org/licenses/by/4.0
.. (c) OPNFV, Ericsson AB, Huawei Technologies Co.,Ltd and others.

Yardstick Installation
======================

Abstract
--------

Yardstick supports installation on Ubuntu 14.04 or via a Docker image. The
installation procedure on Ubuntu 14.04 or via the docker image are detailed in
the section below.

To use Yardstick you should have access to an OpenStack environment, with at
least Nova, Neutron, Glance, Keystone and Heat installed.

The steps needed to run Yardstick are:

1. Install Yardstick.
2. Load OpenStack environment variables.
3. Create a Neutron external network.
4. Build Yardstick flavor and a guest image.
5. Load the guest image into the OpenStack environment.
6. Create the test configuration .yaml file.
7. Run the test case.


Prerequisites
-------------

The OPNFV deployment is out of the scope of this document but it can be
found in http://artifacts.opnfv.org/opnfvdocs/colorado/docs/configguide/index.html.
The OPNFV platform is considered as the System Under Test (SUT) in this
document.

Several prerequisites are needed for Yardstick:

    #. A Jumphost to run Yardstick on
    #. A Docker daemon shall be installed on the Jumphost
    #. A public/external network created on the SUT
    #. Connectivity from the Jumphost to the SUT public/external network

WARNING: Connectivity from Jumphost is essential and it is of paramount
importance to make sure it is working before even considering to install
and run Yardstick. Make also sure you understand how your networking is
designed to work.

NOTE: **Jumphost** refers to any server which meets the previous
requirements. Normally it is the same server from where the OPNFV
deployment has been triggered previously.

NOTE: If your Jumphost is operating behind a company http proxy and/or
Firewall, please consult first the section `Proxy Support`_, towards
the end of this document. The section details some tips/tricks which
*may* be of help in a proxified environment.


Installing Yardstick on Ubuntu 14.04
------------------------------------

.. _install-framework:

You can install Yardstick framework directly on Ubuntu 14.04 or in an Ubuntu
14.04 Docker image. No matter which way you choose to install Yardstick
framework, the following installation steps are identical.

If you choose to use the Ubuntu 14.04 Docker image, You can pull the Ubuntu
14.04 Docker image from Docker hub:

::

  docker pull ubuntu:14.04

Installing Yardstick framework
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Download source code and install python dependencies:

::

  git clone https://gerrit.opnfv.org/gerrit/yardstick
  cd yardstick
  ./install.sh


Installing Yardstick using Docker
---------------------------------

Yardstick has a Docker image, this Docker image (**Yardstick-stable**)
serves as a replacement for installing the Yardstick framework in a virtual
environment (for example as done in :ref:`install-framework`).
It is recommended to use this Docker image to run Yardstick test.

Pulling the Yardstick Docker image
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

.. _dockerhub: https://hub.docker.com/r/opnfv/yardstick/

Pull the Yardstick Docker image ('opnfv/yardstick') from the public dockerhub
registry under the OPNFV account: [dockerhub_], with the following docker
command::

  docker pull opnfv/yardstick:stable

After pulling the Docker image, check that it is available with the
following docker command::

  [yardsticker@jumphost ~]$ docker images
  REPOSITORY         TAG       IMAGE ID        CREATED      SIZE
  opnfv/yardstick    stable    a4501714757a    1 day ago    915.4 MB

Run the Docker image:

::

  docker run --privileged=true -it opnfv/yardstick:stable /bin/bash

In the container the Yardstick repository is located in the /home/opnfv/repos
directory.


OpenStack parameters and credentials
------------------------------------

Environment variables
^^^^^^^^^^^^^^^^^^^^^
Before running Yardstick it is necessary to export OpenStack environment variables
from the OpenStack *openrc* file (using the ``source`` command) and export the
external network name ``export EXTERNAL_NETWORK="external-network-name"``,
the default name for the external network is ``net04_ext``.

Credential environment variables in the *openrc* file have to include at least:

* OS_AUTH_URL
* OS_USERNAME
* OS_PASSWORD
* OS_TENANT_NAME

A sample openrc file may look like this:

* export OS_PASSWORD=console
* export OS_TENANT_NAME=admin
* export OS_AUTH_URL=http://172.16.1.222:35357/v2.0
* export OS_USERNAME=admin
* export OS_VOLUME_API_VERSION=2
* export EXTERNAL_NETWORK=net04_ext


Yardstick falvor and guest images
---------------------------------

Before executing Yardstick test cases, make sure that yardstick guest image and
yardstick flavor are available in OpenStack.
Detailed steps about creating yardstick flavor and building yardstick-trusty-server
image can be found below.

Yardstick-flavor
^^^^^^^^^^^^^^^^
Most of the sample test cases in Yardstick are using an OpenStack flavor called
*yardstick-flavor* which deviates from the OpenStack standard m1.tiny flavor by the
disk size - instead of 1GB it has 3GB. Other parameters are the same as in m1.tiny.

Create yardstick-flavor:

::

  nova flavor-create yardstick-flavor 100 512 3 1


.. _guest-image:

Building a guest image
^^^^^^^^^^^^^^^^^^^^^^
Most of the sample test cases in Yardstick are using a guest image called
*yardstick-trusty-server* which deviates from an Ubuntu Cloud Server image
containing all the required tools to run test cases supported by Yardstick.
Yardstick has a tool for building this custom image. It is necessary to have
sudo rights to use this tool.

Also you may need install several additional packages to use this tool, by
follwing the commands below:

::

  apt-get update && apt-get install -y \
      qemu-utils \
      kpartx

This image can be built using the following command while in the directory where
Yardstick is installed (``~/yardstick`` if the framework is installed
by following the commands above):

::

  export YARD_IMG_ARCH="amd64"
  sudo echo "Defaults env_keep += \"YARD_IMG_ARCH\"" >> /etc/sudoers
  sudo ./tools/yardstick-img-modify tools/ubuntu-server-cloudimg-modify.sh

**Warning:** the script will create files by default in:
``/tmp/workspace/yardstick`` and the files will be owned by root!

If you are building this guest image in inside a docker container make sure the
container is granted with privilege.

The created image can be added to OpenStack using the ``glance image-create`` or
via the OpenStack Dashboard.

Example command:

::

  glance --os-image-api-version 1 image-create \
  --name yardstick-image --is-public true \
  --disk-format qcow2 --container-format bare \
  --file /tmp/workspace/yardstick/yardstick-image.img

Some Yardstick test cases use a Cirros image, you can find one at
http://download.cirros-cloud.net/0.3.3/cirros-0.3.3-x86_64-disk.img


Automatic flavor and image creation
-----------------------------------
Yardstick has a script for automatic creating yardstick flavor and building
guest images. This script is mainly used in CI, but you can still use it in
your local environment.

Example command:

::

  export YARD_IMG_ARCH="amd64"
  sudo echo "Defaults env_keep += \"YARD_IMG_ARCH\"" >> /etc/sudoers
  source $YARDSTICK_REPO_DIR/tests/ci/load_images.sh


Yardstick default key pair
^^^^^^^^^^^^^^^^^^^^^^^^^^
Yardstick uses a SSH key pair to connect to the guest image. This key pair can
be found in the ``resources/files`` directory. To run the ``ping-hot.yaml`` test
sample, this key pair needs to be imported to the OpenStack environment.


Examples and verifying the install
----------------------------------

It is recommended to verify that Yardstick was installed successfully
by executing some simple commands and test samples. Before executing yardstick
test cases make sure yardstick flavor and building yardstick-trusty-server
image can be found in glance and openrc file is sourced. Below is an example
invocation of yardstick help command and ping.py test sample:
::

  yardstick –h
  yardstick task start samples/ping.yaml

Each testing tool supported by Yardstick has a sample configuration file.
These configuration files can be found in the **samples** directory.

Default location for the output is ``/tmp/yardstick.out``.


Deploy InfluxDB and Grafana locally
------------------------------------

.. pull docker images

Pull docker images

^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

::

  docker pull tutum/influxdb
  docker pull grafana/grafana

Run influxdb and config
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Run influxdb
::

  docker run -d --name influxdb \
  -p 8083:8083 -p 8086:8086 --expose 8090 --expose 8099 \
  tutum/influxdb
  docker exec -it influxdb bash

Config influxdb
::

  influx
  >CREATE USER root WITH PASSWORD 'root' WITH ALL PRIVILEGES
  >CREATE DATABASE yardstick;
  >use yardstick;
  >show MEASUREMENTS;

Run grafana and config
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Run grafana
::

  docker run -d --name grafana -p 3000:3000 grafana/grafana

Config grafana
::

  http://{YOUR_IP_HERE}:3000
  log on using admin/admin and config database resource to be {YOUR_IP_HERE}:8086

.. image:: images/Grafana_config.png
   :width: 800px
   :alt: Grafana data source configration

Config yardstick conf
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
cp ./etc/yardstick/yardstick.conf.sample /etc/yardstick/yardstick.conf

vi /etc/yardstick/yardstick.conf
Config yardstick.conf
::

  [DEFAULT]
  debug = True
  dispatcher = influxdb

  [dispatcher_influxdb]
  timeout = 5
  target = http://{YOUR_IP_HERE}:8086
  db_name = yardstick
  username = root
  password = root

Now you can run yardstick test cases and store the results in influxdb
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^


Create a test suite for yardstick
------------------------------------

A test suite in yardstick is a yaml file which include one or more test cases.
Yardstick is able to support running test suite task, so you can customize you
own test suite and run it in one task.

"tests/opnfv/test_suites" is where yardstick put ci test-suite. A typical test
suite is like below:

fuel_test_suite.yaml

::

  ---
  # Fuel integration test task suite

  schema: "yardstick:suite:0.1"

  name: "fuel_test_suite"
  test_cases_dir: "samples/"
  test_cases:
  -
    file_name: ping.yaml
  -
    file_name: iperf3.yaml

As you can see, there are two test cases in fuel_test_suite, the syntax is simple
here, you must specify the schema and the name, then you just need to list the
test cases in the tag "test_cases" and also mark their relative directory in the
tag "test_cases_dir".

Yardstick test suite also support constraints and task args for each test case.
Here is another sample to show this, which is digested from one big test suite.

os-nosdn-nofeature-ha.yaml

::

 ---

 schema: "yardstick:suite:0.1"

 name: "os-nosdn-nofeature-ha"
 test_cases_dir: "tests/opnfv/test_cases/"
 test_cases:
 -
     file_name: opnfv_yardstick_tc002.yaml
 -
     file_name: opnfv_yardstick_tc005.yaml
 -
     file_name: opnfv_yardstick_tc043.yaml
        constraint:
           installer: compass
           pod: huawei-pod1
        task_args:
           huawei-pod1: '{"pod_info": "etc/yardstick/.../pod.yaml",
           "host": "node4.LF","target": "node5.LF"}'

As you can see in test case "opnfv_yardstick_tc043.yaml", there are two tags, "constraint" and
"task_args". "constraint" is where you can specify which installer or pod it can be run in
the ci environment. "task_args" is where you can specify the task arguments for each pod.

All in all, to create a test suite in yardstick, you just need to create a suite yaml file
and add test cases and constraint or task arguments if necessary.
'>1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518
/*
// Copyright (c) 2017 Intel Corporation
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//      http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
*/

/**
 * @file
 * Pipeline CG-NAPT FE Implementation.
 *
 * Implementation of Pipeline CG-NAPT Front End (FE).
 * Provides CLI support.
 * Runs on master core.
 *
 */

#include <cmdline_parse.h>
#include <cmdline_parse_num.h>
#include <cmdline_parse_string.h>
#include <cmdline_parse_ipaddr.h>
#include <cmdline_parse_etheraddr.h>

#include "app.h"
#include "pipeline_common_fe.h"
#include "pipeline_cgnapt.h"
#include "pipeline_cgnapt_common.h"
#include "pipeline_common_be.h"
#include "pipeline_cgnapt_be.h"
#ifdef PCP_ENABLE
#include "cgnapt_pcp_fe.h"
#endif

/**
 * A structure defining the CG-NAPT entry that is stored on
 * front end.
 */
struct app_pipeline_cgnapt_entry {
	struct pipeline_cgnapt_entry_key key;
	struct app_pipeline_cgnapt_entry_params params;
	void *entry_ptr;

	 TAILQ_ENTRY(app_pipeline_cgnapt_entry) node;
};

/**
 * A structure defining the FE representation of a CG-NAPT pipeline
 */
struct pipeline_cgnapt_t {
	/* Parameters */
	uint32_t n_ports_in;
	uint32_t n_ports_out;

	/* entries */
	 TAILQ_HEAD(, app_pipeline_cgnapt_entry) entries;
	uint32_t n_entries;

};

/**
 * Init function for CG-NAPT FE.
 *
 * @param params
 *  A pointer to the pipeline params.
 *
 */
static void *pipeline_cgnapt_init(struct pipeline_params *params,
					__rte_unused void *arg)
{
	struct pipeline_cgnapt_t *p;
	uint32_t size;

	/* Check input arguments */
	if ((params == NULL) ||
			(params->n_ports_in == 0) || (params->n_ports_out == 0))
		return NULL;

	/* Memory allocation */
	size = RTE_CACHE_LINE_ROUNDUP(sizeof(struct pipeline_cgnapt_t));
	p = rte_zmalloc(NULL, size, RTE_CACHE_LINE_SIZE);
	if (p == NULL)
		return NULL;

	/* Initialization */
	p->n_ports_in = params->n_ports_in;
	p->n_ports_out = params->n_ports_out;

	TAILQ_INIT(&p->entries);
	p->n_entries = 0;

	return p;
}

/**
 * Function for CG-NAPT FE cleanup.
 *
 * @param pipeline
 *  A pointer to the pipeline.
 *
 */
static int app_pipeline_cgnapt_free(void *pipeline)
{
	struct pipeline_cgnapt_t *p = pipeline;

	/* Check input arguments */
	if (p == NULL)
		return -1;

	/* Free resources */
	while (!TAILQ_EMPTY(&p->entries)) {
		struct app_pipeline_cgnapt_entry *entry;

		entry = TAILQ_FIRST(&p->entries);
		TAILQ_REMOVE(&p->entries, entry, node);
		rte_free(entry);
	}

	rte_free(p);
	return 0;
}

/**
 * Function to print an IPv6 address
 *
 * @param ipv6_addr
 *  A uint8_t array containing an IPv6 address
 */
static void print_ipv6_address_u8(uint8_t ipv6_addr[16])
{
	printf("Ipv6Address-%x:%x:%x:%x:%x:%x:%x:%x:%x:%x:%x:%x:%x:%x:%x:%x\n",
				 ipv6_addr[0], ipv6_addr[1], ipv6_addr[2], ipv6_addr[3],
				 ipv6_addr[4], ipv6_addr[5], ipv6_addr[6], ipv6_addr[7],
				 ipv6_addr[8], ipv6_addr[9], ipv6_addr[10], ipv6_addr[11],
				 ipv6_addr[12], ipv6_addr[13], ipv6_addr[14], ipv6_addr[15]);
}

/**
 * Function to print an IPv6 address
 *
 * @param ipv6_addr
 *  A uint16_t array containing an IPv6 address
 */
static void print_ipv6_address_u16(uint16_t ipv6_addr[8])
{
	printf("Ipv6Address-%x:%x:%x:%x:%x:%x:%x:%x\n", ipv6_addr[0],
				 ipv6_addr[1], ipv6_addr[2], ipv6_addr[3], ipv6_addr[4],
				 ipv6_addr[5], ipv6_addr[6], ipv6_addr[7]);
}

/**
 * Function to print an IPv6 address
 *
 * @param ipv6_addr
 *  A uint32_t array containing an IPv6 address
 */
static void print_ipv6_address_u32(uint32_t ipv6_addr[4])
{
	printf("Ipv6Address: %x:%x:%x:%x\n", ipv6_addr[0], ipv6_addr[1],
		ipv6_addr[2], ipv6_addr[3]);
}

/**
 * Function to print a NAPT entry
 *
 * @param entry
 *  A pointer to a NAPT entry
 */
static void print_entry(const struct app_pipeline_cgnapt_entry *entry)
{
	const struct pipeline_cgnapt_entry_key *key = &entry->key;

	if (entry->params.type == CGNAPT_ENTRY_IPV4) {
		printf("CGNAPT Entry: Key = %" PRIu32 ".%" PRIu32 ".%" PRIu32
					 ".%" PRIu32 ":%" PRIu32 ":%" PRIu16 " => Prv = %" PRIu32
					 ".%" PRIu32 ".%" PRIu32 ".%" PRIu32 ":%" PRIu32
					 " => Pub = %" PRIu32 ".%" PRIu32 ".%" PRIu32 ".%" PRIu32
					 ":%" PRIu32 " => ttl = %" PRIu32 "\n",
					 (key->ip >> 24) & 0xFF, (key->ip >> 16) & 0xFF,
					 (key->ip >> 8) & 0xFF, key->ip & 0xFF, key->port,
					 key->pid, (entry->params.u.prv_ip >> 24) & 0xFF,
					 (entry->params.u.prv_ip >> 16) & 0xFF,
					 (entry->params.u.prv_ip >> 8) & 0xFF,
					 entry->params.u.prv_ip & 0xFF, entry->params.prv_port,
					 (entry->params.pub_ip >> 24) & 0xFF,
					 (entry->params.pub_ip >> 16) & 0xFF,
					 (entry->params.pub_ip >> 8) & 0xFF,
					 entry->params.pub_ip & 0xFF, entry->params.pub_port,
					 entry->params.ttl);
	} else {
		printf("CGNAPT Entry: Key = %" PRIu32 ".%" PRIu32 ".%" PRIu32
					 ".%" PRIu32 ":%" PRIu32 ":%" PRIu16 " => Prv = %" PRIu32
					 "%" PRIu32 ":%" PRIu32 "%" PRIu32 ":%" PRIu32 "%" PRIu32
					 ":%" PRIu32 "%" PRIu32 ":%" PRIu32 "%" PRIu32 ":%" PRIu32
					 "%" PRIu32 ":%" PRIu32 "%" PRIu32 ":%" PRIu32 "%" PRIu32
					 ":%" PRIu32 " => Pub = %" PRIu32 ".%" PRIu32 ".%"
					 PRIu32 ".%" PRIu32 ":%" PRIu32 " => ttl = %" PRIu32
					 "\n", (key->ip >> 24) & 0xFF, (key->ip >> 16) & 0xFF,
					 (key->ip >> 8) & 0xFF, key->ip & 0xFF, key->port,
					 key->pid, entry->params.u.prv_ipv6[0],
					 entry->params.u.prv_ipv6[1], entry->params.u.prv_ipv6[2],
					 entry->params.u.prv_ipv6[3], entry->params.u.prv_ipv6[4],
					 entry->params.u.prv_ipv6[5], entry->params.u.prv_ipv6[6],
					 entry->params.u.prv_ipv6[7], entry->params.u.prv_ipv6[8],
					 entry->params.u.prv_ipv6[9],
					 entry->params.u.prv_ipv6[10],
					 entry->params.u.prv_ipv6[11],
					 entry->params.u.prv_ipv6[12],
					 entry->params.u.prv_ipv6[13],
					 entry->params.u.prv_ipv6[14],
					 entry->params.u.prv_ipv6[15], entry->params.prv_port,
					 (entry->params.pub_ip >> 24) & 0xFF,
					 (entry->params.pub_ip >> 16) & 0xFF,
					 (entry->params.pub_ip >> 8) & 0xFF,
					 entry->params.pub_ip & 0xFF, entry->params.pub_port,
					 entry->params.ttl);

	}
}

/**
 * Function to list NAPT entries from FE storage
 *
 * @param app
 *  A pointer to pipeline app
 * @param pipeline_id
 *  Pipeline id
 *
 * @return
 *  0 on success, negative on error.
 */
static int
app_pipeline_cgnapt_entry_ls(struct app_params *app, uint32_t pipeline_id)
{
	struct pipeline_cgnapt_t *p;
	struct app_pipeline_cgnapt_entry *it;

	p = app_pipeline_data_fe(app, pipeline_id,
				 (struct pipeline_type *)&pipeline_cgnapt);
	if (p == NULL)
		return -EINVAL;

	TAILQ_FOREACH(it, &p->entries, node)
			print_entry(it);
	print_static_cgnapt_entries();
	printf(" - end of napt fe entry list -\n");
	return 0;
}

/**
 * Function to send a debug message to BE
 *
 * @param app
 *  A pointer to pipeline app
 * @param pipeline_id
 *  Pipeline id
 * @param msg
 *  debug message contents
 *
 * @return
 *  0 on success, negative on error.
 */
static int
app_pipeline_cgnapt_entry_dbg(struct app_params *app,
						uint32_t pipeline_id, uint8_t *msg)
{
	struct pipeline_cgnapt_t *p;

	struct pipeline_cgnapt_entry_dbg_msg_req *req;
	struct pipeline_cgnapt_entry_dbg_msg_rsp *rsp;

	/* Check input arguments */
	if (app == NULL)
		return -1;

	p = app_pipeline_data_fe(app, pipeline_id,
				 (struct pipeline_type *)&pipeline_cgnapt);
	if (p == NULL)
		return -1;

	/* Allocate and write request */
	req = app_msg_alloc(app);
	if (req == NULL)
		return -1;

	req->type = PIPELINE_MSG_REQ_CUSTOM;
	req->subtype = PIPELINE_CGNAPT_MSG_REQ_ENTRY_DBG;
	req->data[0] = msg[0];
	req->data[1] = msg[1];
	req->data[2] = msg[2];

	rsp = app_msg_send_recv(app, pipeline_id, req, MSG_TIMEOUT_DEFAULT);
	if (rsp == NULL)
		return -1;

	/* Read response */
	if (rsp->status) {
		app_msg_free(app, rsp);
		printf("Error rsp->status %d\n", rsp->status);
		return -1;
	}

	/* Free response */
	app_msg_free(app, rsp);

	return 0;
}

/**
 * Function to send a NAPT entry add message to BE
 *
 * @param app
 *  A pointer to pipeline app
 * @param pipeline_id
 *  Pipeline id
 * @param key
 *  A pointer to NAPT entry key
 * @param entry_params
 *  A pointer to NAPT entry params
 *
 * @return
 *  0 on success, negative on error.
 */
int app_pipeline_cgnapt_add_entry(
	struct app_params *app,
	uint32_t pipeline_id,
	struct app_pipeline_cgnapt_entry_params *entry_params)
{
	struct pipeline_cgnapt_t *p;

	struct pipeline_cgnapt_entry_add_msg_req *req;
	struct pipeline_cgnapt_entry_add_msg_rsp *rsp;

	/* Check input arguments */
	if ((app == NULL) || (entry_params == NULL))
		return -1;

	p = app_pipeline_data_fe(app, pipeline_id,
				 (struct pipeline_type *)&pipeline_cgnapt);
	if (p == NULL)
		return -2;

	/* Allocate and write request */
	req = app_msg_alloc(app);
	if (req == NULL)
		return -4;

	req->type = PIPELINE_MSG_REQ_CUSTOM;
	req->subtype = PIPELINE_CGNAPT_MSG_REQ_ENTRY_ADD;
	memcpy(&req->data, entry_params, sizeof(*entry_params));

	rsp = app_msg_send_recv(app, pipeline_id, req, MSG_TIMEOUT_DEFAULT);
	if (rsp == NULL)
		return -5;

	/* Message buffer free */
	app_msg_free(app, rsp);
	return 0;
}

/**
 * Function to send a multiple NAPT entry add message to BE
 *
 * @param app
 *  A pointer to pipeline app
 * @param pipeline_id
 *  Pipeline id
 * @param key
 *  A pointer to NAPT entry key
 * @param entry_params
 *  A pointer to multiple NAPT entry params
 *
 * @return
 *  0 on success, negative on error.
 */
int app_pipeline_cgnapt_addm_entry(
	struct app_params *app,
	uint32_t pipeline_id,
	struct app_pipeline_cgnapt_mentry_params *entry_params)
{
	struct pipeline_cgnapt_t *p;

	struct pipeline_cgnapt_entry_addm_msg_req *req;
	struct pipeline_cgnapt_entry_addm_msg_rsp *rsp;

	/* Check input arguments */
	if ((app == NULL) || (entry_params == NULL))
		return -1;

	p = app_pipeline_data_fe(app, pipeline_id,
				 (struct pipeline_type *)&pipeline_cgnapt);
	if (p == NULL)
		return -2;

	/* Allocate and write request */
	req = app_msg_alloc(app);
	if (req == NULL)
		return -4;

	req->type = PIPELINE_MSG_REQ_CUSTOM;
	req->subtype = PIPELINE_CGNAPT_MSG_REQ_ENTRY_ADDM;
	memcpy(&req->data, entry_params, sizeof(*entry_params));

	rsp = app_msg_send_recv(app, pipeline_id, req, MSG_TIMEOUT_DEFAULT);
	if (rsp == NULL)
		return -5;

	/* Message buffer free */
	app_msg_free(app, rsp);
	return 0;
}

/**
 * Function to send a NAPT entry delete message to BE
 *
 * @param app
 *  A pointer to pipeline app
 * @param pipeline_id
 *  Pipeline id
 * @param key
 *  A pointer to NAPT entry key
 *
 * @return
 *  0 on success, negative on error.
 */
int
app_pipeline_cgnapt_delete_entry(struct app_params *app,
				 uint32_t pipeline_id,
				 struct pipeline_cgnapt_entry_key *key)
{
	struct pipeline_cgnapt_t *p;

	struct pipeline_cgnapt_entry_delete_msg_req *req;
	struct pipeline_cgnapt_entry_delete_msg_rsp *rsp;

	if (CGNAPT_DEBUG) {
		uint8_t *KeyP = (uint8_t *) key;
		int i = 0;

		printf("app_pipeline_cgnapt_delete_entry - Key: ");
		for (i = 0; i < (int)sizeof(*key); i++)
			printf(" %02x", KeyP[i]);
		printf(" ,KeySize %u\n", (int)sizeof(*key));
	}
	/* Check input arguments */
	if ((app == NULL) || (key == NULL))
		return -1;

	p = app_pipeline_data_fe(app, pipeline_id,
				 (struct pipeline_type *)&pipeline_cgnapt);
	if (p == NULL)
		return -1;

	/* Allocate and write request */
	req = app_msg_alloc(app);
	if (req == NULL)
		return -1;

	req->type = PIPELINE_MSG_REQ_CUSTOM;
	req->subtype = PIPELINE_CGNAPT_MSG_REQ_ENTRY_DEL;
	memcpy(&req->key, key, sizeof(*key));

	rsp = app_msg_send_recv(app, pipeline_id, req, MSG_TIMEOUT_DEFAULT);
	if (rsp == NULL)
		return -1;

	/* Read response */
	if (rsp->status || !rsp->key_found) {
		app_msg_free(app, rsp);
		printf("Successfully deleted the entry\n");
		return 0;
	}

	/* Free response */
	app_msg_free(app, rsp);

	return 0;
}

/**
 * A structure defining the entry add parse arguments.
 */
struct cmd_entry_add_result {
	cmdline_fixed_string_t p_string;
	uint32_t p;
	cmdline_fixed_string_t entry_string;
	cmdline_fixed_string_t add_string;
	cmdline_ipaddr_t prv_ip;
	uint16_t prv_port;
	cmdline_ipaddr_t pub_ip;
	uint16_t pub_port;
	uint16_t pid;
	uint32_t ttl;
};
/**
 * Helping function for add entry
 *
 * @param parsed_result
 *  A pointer parsed add arguments
 * @param cl
 *  unused pointer to struct cmdline
 * @param msg
 *  void pointer data
 *
 */
static void
cmd_entry_add_parsed(void *parsed_result,
					__rte_unused struct cmdline *cl, void *data)
{
	struct cmd_entry_add_result *params = parsed_result;
	struct app_params *app = data;
	struct app_pipeline_cgnapt_entry_params ent_params;
	int status;

	if (params->prv_ip.family == AF_INET) {
		ent_params.type = CGNAPT_ENTRY_IPV4;
		ent_params.u.prv_ip =
				rte_bswap32((uint32_t) params->prv_ip.addr.ipv4.s_addr);
	} else {
		print_ipv6_address_u8(params->prv_ip.addr.ipv6.s6_addr);
		print_ipv6_address_u16(params->prv_ip.addr.ipv6.s6_addr16);
		print_ipv6_address_u32(params->prv_ip.addr.ipv6.s6_addr32);
		ent_params.type = CGNAPT_ENTRY_IPV6;
		memcpy(ent_params.u.prv_ipv6, params->prv_ip.addr.ipv6.s6_addr,
					 16);
	}

	ent_params.prv_port = params->prv_port;
	ent_params.pub_ip =
			rte_bswap32((uint32_t) params->pub_ip.addr.ipv4.s_addr);
	ent_params.pub_port = params->pub_port;
	ent_params.prv_phy_port = params->pid;
	ent_params.ttl = params->ttl;

	status = app_pipeline_cgnapt_add_entry(app, params->p, &ent_params);

	if (status != 0) {
		printf("CG-NAPT add multiple entry command failed, %d\n",
					 status);
		return;
	}
}

static cmdline_parse_token_string_t cmd_entry_add_p_string =
TOKEN_STRING_INITIALIZER(struct cmd_entry_add_result, p_string,
			 "p");

static cmdline_parse_token_num_t cmd_entry_add_p =
TOKEN_NUM_INITIALIZER(struct cmd_entry_add_result, p, UINT32);

static cmdline_parse_token_string_t cmd_entry_add_entry_string =
TOKEN_STRING_INITIALIZER(struct cmd_entry_add_result, entry_string,
			 "entry");

static cmdline_parse_token_string_t cmd_entry_add_add_string =
TOKEN_STRING_INITIALIZER(struct cmd_entry_add_result, add_string,
			 "add");

static cmdline_parse_token_ipaddr_t cmd_entry_add_prv_ip =
TOKEN_IPADDR_INITIALIZER(struct cmd_entry_add_result, prv_ip);

static cmdline_parse_token_num_t cmd_entry_add_prv_port =
TOKEN_NUM_INITIALIZER(struct cmd_entry_add_result, prv_port, UINT16);

static cmdline_parse_token_ipaddr_t cmd_entry_add_pub_ip =
TOKEN_IPV4_INITIALIZER(struct cmd_entry_add_result, pub_ip);

static cmdline_parse_token_num_t cmd_entry_add_pub_port =
TOKEN_NUM_INITIALIZER(struct cmd_entry_add_result, pub_port, UINT16);

static cmdline_parse_token_num_t cmd_entry_add_pid =
TOKEN_NUM_INITIALIZER(struct cmd_entry_add_result, pid, UINT16);

static cmdline_parse_token_num_t cmd_entry_add_ttl =
TOKEN_NUM_INITIALIZER(struct cmd_entry_add_result, ttl, UINT32);

static cmdline_parse_inst_t cmd_entry_add = {
	.f = cmd_entry_add_parsed,
	.data = NULL,
	.help_str = "NAPT entry add",
	.tokens = {
			 (void *)&cmd_entry_add_p_string,
			 (void *)&cmd_entry_add_p,
			 (void *)&cmd_entry_add_entry_string,
			 (void *)&cmd_entry_add_add_string,
			 (void *)&cmd_entry_add_prv_ip,
			 (void *)&cmd_entry_add_prv_port,
			 (void *)&cmd_entry_add_pub_ip,
			 (void *)&cmd_entry_add_pub_port,
			 (void *)&cmd_entry_add_pid,
			 (void *)&cmd_entry_add_ttl,
			 NULL,
			 },
};

/**
 * A structure defining the multiple entry add parse arguments.
 */
struct cmd_entry_addm_result {
	cmdline_fixed_string_t p_string;
	uint32_t p;
	cmdline_fixed_string_t entry_string;
	cmdline_fixed_string_t addm_string;
	cmdline_ipaddr_t prv_ip;
	uint16_t prv_port;
	cmdline_ipaddr_t pub_ip;
	uint16_t pub_port;
	uint16_t pid;
	uint32_t ttl;
	uint32_t num_ue;
	uint16_t prv_port_max;
	uint16_t pub_port_max;
};

/**
 * Helping function for add multiple entries
 *
 * @param parsed_result
 *  A pointer parsed add arguments
 * @param cl
 *  unused pointer to struct cmdline
 * @param msg
 *  void pointer data
 */
static void
cmd_entry_addm_parsed(void *parsed_result,
					__rte_unused struct cmdline *cl, void *data)
{
	struct cmd_entry_addm_result *params = parsed_result;
	struct app_params *app = data;
	struct app_pipeline_cgnapt_mentry_params ent_params;
	int status;

	if (params->prv_ip.family == AF_INET) {
		ent_params.type = CGNAPT_ENTRY_IPV4;
		ent_params.u.prv_ip =
				rte_bswap32((uint32_t) params->prv_ip.addr.ipv4.s_addr);
	} else {
		print_ipv6_address_u8(params->prv_ip.addr.ipv6.s6_addr);
		print_ipv6_address_u16(params->prv_ip.addr.ipv6.s6_addr16);
		print_ipv6_address_u32(params->prv_ip.addr.ipv6.s6_addr32);
		ent_params.type = CGNAPT_ENTRY_IPV6;
		memcpy(ent_params.u.prv_ipv6, params->prv_ip.addr.ipv6.s6_addr,
					 16);
	}

	ent_params.prv_port = params->prv_port;
	ent_params.pub_ip =
			rte_bswap32((uint32_t) params->pub_ip.addr.ipv4.s_addr);
	ent_params.pub_port = params->pub_port;
	ent_params.prv_phy_port = params->pid;
	ent_params.ttl = params->ttl;
	ent_params.num_ue = params->num_ue;
	ent_params.prv_port_max = params->prv_port_max;
	ent_params.pub_port_max = params->pub_port_max;

	status = app_pipeline_cgnapt_addm_entry(app, params->p, &ent_params);

	if (status != 0) {
		printf("CG-NAPT add multiple entry command failed, %d\n",
					 status);
		return;
	}
}

static cmdline_parse_token_string_t cmd_entry_add_addm_string =
TOKEN_STRING_INITIALIZER(struct cmd_entry_addm_result, addm_string,
			 "addm");

static cmdline_parse_token_num_t cmd_entry_addm_prv_port =
TOKEN_NUM_INITIALIZER(struct cmd_entry_addm_result, prv_port_max, UINT16);

static cmdline_parse_token_num_t cmd_entry_addm_pub_port =
TOKEN_NUM_INITIALIZER(struct cmd_entry_addm_result, pub_port_max, UINT16);

static cmdline_parse_token_num_t cmd_entry_addm_max_ue =
TOKEN_NUM_INITIALIZER(struct cmd_entry_addm_result, num_ue, UINT32);

static cmdline_parse_inst_t cmd_entry_addm = {
	.f = cmd_entry_addm_parsed,
	.data = NULL,
	.help_str = "NAPT entry add multiple",
	.tokens = {
			 (void *)&cmd_entry_add_p_string,
			 (void *)&cmd_entry_add_p,
			 (void *)&cmd_entry_add_entry_string,
			 (void *)&cmd_entry_add_addm_string,
			 (void *)&cmd_entry_add_prv_ip,
			 (void *)&cmd_entry_add_prv_port,
			 (void *)&cmd_entry_add_pub_ip,
			 (void *)&cmd_entry_add_pub_port,
			 (void *)&cmd_entry_add_pid,
			 (void *)&cmd_entry_add_ttl,
			 (void *)&cmd_entry_addm_max_ue,
			 (void *)&cmd_entry_addm_prv_port,
			 (void *)&cmd_entry_addm_pub_port,
			 NULL,
			 },
};

/**
 * A structure defining the entry delete parse arguments.
 */
struct cmd_entry_del_result {
	cmdline_fixed_string_t p_string;
	uint32_t p;
	cmdline_fixed_string_t entry_string;
	cmdline_fixed_string_t del_string;
	cmdline_ipaddr_t ip;
	uint16_t port;
	uint16_t pid;
};

/**
 * Helping function for delete entry
 *
 * @param parsed_result
 *  A pointer parsed add arguments
 * @param cl
 *  unused pointer to struct cmdline
 * @param msg
 *  void pointer data
 */
static void
cmd_entry_del_parsed(void *parsed_result,
				 __rte_unused struct cmdline *cl, void *data)
{
	struct cmd_entry_del_result *params = parsed_result;
	struct app_params *app = data;
	struct pipeline_cgnapt_entry_key key;

	int status;

	/* Create entry */
	if (params->ip.family == AF_INET)
		key.ip = rte_bswap32((uint32_t) params->ip.addr.ipv4.s_addr);
	else
		key.ip =
				rte_bswap32((uint32_t) params->ip.addr.ipv6.s6_addr32[3]);
	key.port = params->port;
	key.pid = params->pid;

	status = app_pipeline_cgnapt_delete_entry(app, params->p, &key);

	if (status != 0) {
		printf("CG-NAPT entry del command failed\n");
		return;
	}
}

static cmdline_parse_token_string_t cmd_entry_del_p_string =
TOKEN_STRING_INITIALIZER(struct cmd_entry_del_result, p_string,
			 "p");

static cmdline_parse_token_num_t cmd_entry_del_p =
TOKEN_NUM_INITIALIZER(struct cmd_entry_del_result, p, UINT32);

static cmdline_parse_token_string_t cmd_entry_del_entry_string =
TOKEN_STRING_INITIALIZER(struct cmd_entry_del_result, entry_string,
			 "entry");

static cmdline_parse_token_string_t cmd_entry_del_del_string =
TOKEN_STRING_INITIALIZER(struct cmd_entry_del_result, del_string,
			 "del");

static cmdline_parse_token_ipaddr_t cmd_entry_del_ip =
TOKEN_IPADDR_INITIALIZER(struct cmd_entry_del_result, ip);

static cmdline_parse_token_num_t cmd_entry_del_port =
TOKEN_NUM_INITIALIZER(struct cmd_entry_del_result, port, UINT16);

static cmdline_parse_token_num_t cmd_entry_del_pid =
TOKEN_NUM_INITIALIZER(struct cmd_entry_del_result, pid, UINT16);

static cmdline_parse_inst_t cmd_entry_del = {
	.f = cmd_entry_del_parsed,
	.data = NULL,
	.help_str = "Entry delete",
	.tokens = {
			 (void *)&cmd_entry_del_p_string,
			 (void *)&cmd_entry_del_p,
			 (void *)&cmd_entry_del_entry_string,
			 (void *)&cmd_entry_del_del_string,
			 (void *)&cmd_entry_del_ip,
			 (void *)&cmd_entry_del_port,
			 (void *)&cmd_entry_del_pid,
			 NULL,
			 },
};

/**
 * A structure defining the list entry parse arguments.
 */
struct cmd_entry_ls_result {
	cmdline_fixed_string_t p_string;
	uint32_t p;
	cmdline_fixed_string_t entry_string;
	cmdline_fixed_string_t ls_string;
};

/**
 * Helping function for list entry
 *
 * @param parsed_result
 *  A pointer parsed add arguments
 * @param cl
 *  unused pointer to struct cmdline
 * @param msg
 *  void pointer data
 */
static void
cmd_entry_ls_parsed(void *parsed_result,
				__rte_unused struct cmdline *cl, void *data)
{
	struct cmd_entry_ls_result *params = parsed_result;
	struct app_params *app = data;
	int status;

	status = app_pipeline_cgnapt_entry_ls(app, params->p);

	if (status != 0) {
		printf("Ls command failed\n");
		return;
	}
}

static cmdline_parse_token_string_t cmd_entry_ls_p_string =
TOKEN_STRING_INITIALIZER(struct cmd_entry_ls_result, p_string, "p");

static cmdline_parse_token_num_t cmd_entry_ls_p =
TOKEN_NUM_INITIALIZER(struct cmd_entry_ls_result, p, UINT32);

static cmdline_parse_token_string_t cmd_entry_ls_entry_string =
TOKEN_STRING_INITIALIZER(struct cmd_entry_ls_result,
			 entry_string, "entry");

static cmdline_parse_token_string_t cmd_entry_ls_ls_string =
TOKEN_STRING_INITIALIZER(struct cmd_entry_ls_result, ls_string,
			 "ls");

static cmdline_parse_inst_t cmd_entry_ls = {
	.f = cmd_entry_ls_parsed,
	.data = NULL,
	.help_str = "Entry list",
	.tokens = {
			 (void *)&cmd_entry_ls_p_string,
			 (void *)&cmd_entry_ls_p,
			 (void *)&cmd_entry_ls_entry_string,
			 (void *)&cmd_entry_ls_ls_string,
			 NULL,
			 },
};

/**
 * A structure defining the dbg cmd parse arguments.
 */
struct cmd_entry_dbg_result {
	cmdline_fixed_string_t p_string;
	uint32_t p;
	cmdline_fixed_string_t entry_string;
	cmdline_fixed_string_t dbg_string;
	uint8_t cmd;
	uint8_t d1;
	uint8_t d2;
};

/**
 * Helping function for dbg cmd
 *
 * @param parsed_result
 *  A pointer parsed add arguments
 * @param cl
 *  unused pointer to struct cmdline
 * @param msg
 *  void pointer data
 */
static void
cmd_entry_dbg_parsed(void *parsed_result,
				 __rte_unused struct cmdline *cl, void *data)
{
	struct cmd_entry_dbg_result *params = parsed_result;
	struct app_params *app = data;
	uint8_t msg[4];
	int status;

	msg[0] = params->cmd;
	msg[1] = params->d1;
	msg[2] = params->d2;
	status = app_pipeline_cgnapt_entry_dbg(app, params->p, msg);

	if (status != 0) {
		printf("Dbg Command failed\n");
		return;
	}
}

static cmdline_parse_token_string_t cmd_entry_dbg_p_string =
TOKEN_STRING_INITIALIZER(struct cmd_entry_dbg_result, p_string, "p");

static cmdline_parse_token_num_t cmd_entry_dbg_p =
TOKEN_NUM_INITIALIZER(struct cmd_entry_dbg_result, p, UINT32);

static cmdline_parse_token_string_t cmd_entry_dbg_entry_string =
TOKEN_STRING_INITIALIZER(struct cmd_entry_dbg_result,
			 entry_string, "entry");

static cmdline_parse_token_string_t cmd_entry_dbg_dbg_string =
TOKEN_STRING_INITIALIZER(struct cmd_entry_dbg_result, dbg_string,
			 "dbg");

static cmdline_parse_token_num_t cmd_entry_dbg_cmd =
TOKEN_NUM_INITIALIZER(struct cmd_entry_dbg_result, cmd, UINT8);

static cmdline_parse_token_num_t cmd_entry_dbg_d1 =
TOKEN_NUM_INITIALIZER(struct cmd_entry_dbg_result, d1, UINT8);

static cmdline_parse_token_num_t cmd_entry_dbg_d2 =
TOKEN_NUM_INITIALIZER(struct cmd_entry_dbg_result, d2, UINT8);

static cmdline_parse_inst_t cmd_entry_dbg = {
	.f = cmd_entry_dbg_parsed,
	.data = NULL,
	.help_str = "NAPT dbg cmd",
	.tokens = {
			 (void *)&cmd_entry_dbg_p_string,
			 (void *)&cmd_entry_dbg_p,
			 (void *)&cmd_entry_dbg_entry_string,
			 (void *)&cmd_entry_dbg_dbg_string,
			 (void *)&cmd_entry_dbg_cmd,
			 (void *)&cmd_entry_dbg_d1,
			 (void *)&cmd_entry_dbg_d2,
			 NULL,
			 },
};

/**
 * A structure defining num ip clients cmd parse arguments.
 */
struct cmd_numipcli_result {
	cmdline_fixed_string_t p_string;
	uint32_t p;
	cmdline_fixed_string_t numipcli_string;
};

/**
 * Helping function for printing num ip clients
 *
 * @param parsed_result
 *  Unused pointer parsed add arguments
 * @param cl
 *  unused pointer to struct cmdline
 * @param msg
 *  Unused void pointer data
 */
static void
cmd_numipcli_parsed(__rte_unused void *parsed_result,
				__rte_unused struct cmdline *cl, __rte_unused void *data)
{
	print_num_ip_clients();
}

static cmdline_parse_token_string_t cmd_numipcli_p_string =
TOKEN_STRING_INITIALIZER(struct cmd_numipcli_result, p_string, "p");

static cmdline_parse_token_num_t cmd_numipcli_p =
TOKEN_NUM_INITIALIZER(struct cmd_numipcli_result, p, UINT32);

static cmdline_parse_token_string_t cmd_numipcli_string =
TOKEN_STRING_INITIALIZER(struct cmd_numipcli_result,
			 numipcli_string, "numipcli");

static cmdline_parse_inst_t cmd_numipcli = {
	.f = cmd_numipcli_parsed,
	.data = NULL,
	.help_str = "Num IP Clients command",
	.tokens = {
			 (void *)&cmd_numipcli_p_string,
			 (void *)&cmd_numipcli_p,
			 (void *)&cmd_numipcli_string,
			 NULL,
			 },
};

/**
 * Function to send a ver cmd message to BE
 *
 * @param app
 *  A pointer to pipeline app
 * @param pipeline_id
 *  Pipeline id
 * @param msg
 *  debug message contents
 *
 * @return
 *  0 on success, negative on error.
 */
static int
app_pipeline_cgnapt_ver(struct app_params *app,
			uint32_t pipeline_id, uint8_t *msg)
{

	struct pipeline_cgnapt_t *p;
	struct pipeline_cgnapt_entry_dbg_msg_req *req;
	struct pipeline_cgnapt_entry_dbg_msg_rsp *rsp;

	/* Check input arguments */
	if (app == NULL)
		return -1;

	p = app_pipeline_data_fe(app, pipeline_id,
				 (struct pipeline_type *)&pipeline_cgnapt);
	if (p == NULL)
		return -1;

	/* Allocate and write request */
	req = app_msg_alloc(app);
	if (req == NULL)
		return -1;

	req->type = PIPELINE_MSG_REQ_CUSTOM;
	req->subtype = PIPELINE_CGNAPT_MSG_REQ_VER;
	req->data[0] = msg[0];
	req->data[1] = msg[1];

	rsp = app_msg_send_recv(app, pipeline_id, req, MSG_TIMEOUT_DEFAULT);
	if (rsp == NULL)
		return -1;

	/* Read response */
	if (rsp->status) {
		app_msg_free(app, rsp);
		printf("Error rsp->status %d\n", rsp->status);
		return -1;
	}

	/* Free response */
	app_msg_free(app, rsp);

	return 0;
}

/**
 * A structure defining ver cmd parse arguments.
 */
struct cmd_ver_result {
	cmdline_fixed_string_t p_string;
	uint32_t p;
	cmdline_fixed_string_t ver_string;
	uint8_t cmd;
	uint8_t d1;
};

/**
 * Helping function for ver cmd
 *
 * @param parsed_result
 *  A pointer parsed add arguments
 * @param cl
 *  unused pointer to struct cmdline
 * @param msg
 *  void pointer data
 */
static void
cmd_ver_parsed(void *parsed_result, __rte_unused struct cmdline *cl, void *data)
{
	struct cmd_ver_result *params = parsed_result;
	struct app_params *app = data;
	uint8_t msg[4];
	int status;

	msg[0] = params->cmd;
	msg[1] = params->d1;
	status = app_pipeline_cgnapt_ver(app, params->p, msg);

	if (status != 0) {
		printf("Version Command failed\n");
		return;
	}
}

static cmdline_parse_token_string_t cmd_ver_p_string =
TOKEN_STRING_INITIALIZER(struct cmd_ver_result, p_string, "p");

static cmdline_parse_token_num_t cmd_ver_p =
TOKEN_NUM_INITIALIZER(struct cmd_ver_result, p, UINT32);

static cmdline_parse_token_string_t cmd_ver_string =
TOKEN_STRING_INITIALIZER(struct cmd_ver_result,
			 ver_string, "ver");

static cmdline_parse_token_num_t cmd_ver_cmd =
TOKEN_NUM_INITIALIZER(struct cmd_ver_result, cmd, UINT8);

static cmdline_parse_token_num_t cmd_ver_d1 =
TOKEN_NUM_INITIALIZER(struct cmd_ver_result, d1, UINT8);

static cmdline_parse_inst_t cmd_ver = {
	.f = cmd_ver_parsed,
	.data = NULL,
	.help_str = "NAPT ver cmd",
	.tokens = {
			 (void *)&cmd_ver_p_string,
			 (void *)&cmd_ver_p,
			 (void *)&cmd_ver_string,
			 (void *)&cmd_ver_cmd,
			 (void *)&cmd_ver_d1,
			 NULL,
			 },
};

/**
 * Function to send a nsp add cmd message to BE
 *
 * @param app
 *  A pointer to pipeline app
 * @param pipeline_id
 *  Pipeline id
 * @param nsp
 *  A pointer to struct pipeline_cgnapt_nsp_t
 *
 * @return
 *  0 on success, negative on error.
 */
static int
app_pipeline_cgnapt_add_nsp(struct app_params *app,
					uint32_t pipeline_id,
					struct pipeline_cgnapt_nsp_t *nsp)
{

	struct pipeline_cgnapt_t *p;
	struct pipeline_cgnapt_nsp_add_msg_req *req;
	struct pipeline_cgnapt_nsp_add_msg_rsp *rsp;

	/* Check input arguments */
	if (app == NULL)
		return -1;

	printf("1st if condition\n");

	p = app_pipeline_data_fe(app, pipeline_id,
				 (struct pipeline_type *)&pipeline_cgnapt);
	if (p == NULL)
		return -1;

	printf("2st if condition\n");
	/* Allocate and write request */
	req = app_msg_alloc(app);
	if (req == NULL)
		return -1;

	printf("3st if condition\n");
	req->type = PIPELINE_MSG_REQ_CUSTOM;
	req->subtype = PIPELINE_CGNAPT_MSG_REQ_NSP_ADD;
	memcpy(&req->nsp, nsp, sizeof(struct pipeline_cgnapt_nsp_t));

	rsp = app_msg_send_recv(app, pipeline_id, req, MSG_TIMEOUT_DEFAULT);
	if (rsp == NULL)
		return -1;

	printf("4st if condition\n");
	/* Read response */
	if (rsp->status) {
		app_msg_free(app, rsp);
		printf("Error rsp->status %d\n", rsp->status);
		return -1;
	}

	/* Free response */
	app_msg_free(app, rsp);

	return 0;
}

/**
 * A structure defining nsp add cmd parse arguments.
 */
struct cmd_nsp_add_result {
	cmdline_fixed_string_t p_string;
	uint32_t p;
	cmdline_fixed_string_t nsp_string;
	cmdline_fixed_string_t add_string;
	cmdline_ipaddr_t ip;
};

/**
 * Helping function for nsp add cmd
 *
 * @param parsed_result
 *  A pointer parsed add arguments
 * @param cl
 *  unused pointer to struct cmdline
 * @param msg
 *  void pointer data
 */
static void
cmd_nsp_add_parsed(void *parsed_result, __rte_unused struct cmdline *cl,
			 void *data)
{
	struct cmd_nsp_add_result *params = parsed_result;
	struct app_params *app = data;
	int status;
	struct pipeline_cgnapt_nsp_t nsp;

	memcpy(&nsp.prefix, &params->ip.addr.ipv6.s6_addr, 16);
	nsp.depth = params->ip.prefixlen;
	status = app_pipeline_cgnapt_add_nsp(app, params->p, &nsp);
	if (status != 0) {
		printf("NSP ADD Command failed\n");
		return;
	}
}

static cmdline_parse_token_string_t cmd_add_nsp_p_string =
TOKEN_STRING_INITIALIZER(struct cmd_nsp_add_result, p_string, "p");

static cmdline_parse_token_num_t cmd_add_nsp_p =
TOKEN_NUM_INITIALIZER(struct cmd_nsp_add_result, p, UINT32);

static cmdline_parse_token_string_t cmd_add_nsp_string =
TOKEN_STRING_INITIALIZER(struct cmd_nsp_add_result,
			 nsp_string, "nsp");

static cmdline_parse_token_string_t cmd_add_nsp_add_string =
TOKEN_STRING_INITIALIZER(struct cmd_nsp_add_result,
			 add_string, "add");

static cmdline_parse_token_ipaddr_t cmd_add_nsp_ip =
TOKEN_IPNET_INITIALIZER(struct cmd_nsp_add_result, ip);

static cmdline_parse_inst_t cmd_nsp_add = {
	.f = cmd_nsp_add_parsed,
	.data = NULL,
	.help_str = "NAPT NSP ADD cmd",
	.tokens = {
			 (void *)&cmd_add_nsp_p_string,
			 (void *)&cmd_add_nsp_p,
			 (void *)&cmd_add_nsp_string,
			 (void *)&cmd_add_nsp_add_string,
			 (void *)&cmd_add_nsp_ip,
			 NULL,
			 },
};

/**
 * Function to send a nsp del cmd message to BE
 *
 * @param app
 *  A pointer to pipeline app
 * @param pipeline_id
 *  Pipeline id
 * @param nsp
 *  A pointer to struct pipeline_cgnapt_nsp_t
 *
 * @return
 *  0 on success, negative on error.
 */
static int
app_pipeline_cgnapt_del_nsp(struct app_params *app,
					uint32_t pipeline_id,
					struct pipeline_cgnapt_nsp_t *nsp)
{

	struct pipeline_cgnapt_t *p;
	struct pipeline_cgnapt_nsp_del_msg_req *req;
	struct pipeline_cgnapt_nsp_del_msg_rsp *rsp;

	/* Check input arguments */
	if (app == NULL)
		return -1;

	p = app_pipeline_data_fe(app, pipeline_id,
				 (struct pipeline_type *)&pipeline_cgnapt);
	if (p == NULL)
		return -1;

	/* Allocate and write request */
	req = app_msg_alloc(app);
	if (req == NULL)
		return -1;

	req->type = PIPELINE_MSG_REQ_CUSTOM;
	req->subtype = PIPELINE_CGNAPT_MSG_REQ_NSP_DEL;
	memcpy(&req->nsp, nsp, sizeof(struct pipeline_cgnapt_nsp_t));

	rsp = app_msg_send_recv(app, pipeline_id, req, MSG_TIMEOUT_DEFAULT);
	if (rsp == NULL)
		return -1;

	/* Read response */
	if (rsp->status) {
		app_msg_free(app, rsp);
		printf("Error rsp->status %d\n", rsp->status);
		return -1;
	}

	/* Free response */
	app_msg_free(app, rsp);

	return 0;
}

/**
 * A structure defining nsp del cmd parse arguments.
 */
struct cmd_nsp_del_result {
	cmdline_fixed_string_t p_string;
	uint32_t p;
	cmdline_fixed_string_t nsp_string;
	cmdline_fixed_string_t del_string;
	cmdline_ipaddr_t ip;
};

/**
 * Helping function for nsp del cmd
 *
 * @param parsed_result
 *  A pointer parsed add arguments
 * @param cl
 *  unused pointer to struct cmdline
 * @param msg
 *  void pointer data
 */
static void
cmd_nsp_del_parsed(void *parsed_result, __rte_unused struct cmdline *cl,
			 void *data)
{
	struct cmd_nsp_del_result *params = parsed_result;
	struct app_params *app = data;
	int status;
	struct pipeline_cgnapt_nsp_t nsp;

	memcpy(&nsp.prefix, &params->ip.addr.ipv6.s6_addr, 16);
	nsp.depth = params->ip.prefixlen;
	status = app_pipeline_cgnapt_del_nsp(app, params->p, &nsp);

	if (status != 0) {
		printf("NSP DEL Command failed\n");
		return;
	}
}

static cmdline_parse_token_string_t cmd_del_nsp_p_string =
TOKEN_STRING_INITIALIZER(struct cmd_nsp_del_result, p_string, "p");

static cmdline_parse_token_num_t cmd_del_nsp_p =
TOKEN_NUM_INITIALIZER(struct cmd_nsp_del_result, p, UINT32);

static cmdline_parse_token_string_t cmd_del_nsp_string =
TOKEN_STRING_INITIALIZER(struct cmd_nsp_del_result,
			 nsp_string, "nsp");

static cmdline_parse_token_string_t cmd_del_nsp_del_string =
TOKEN_STRING_INITIALIZER(struct cmd_nsp_del_result,
			 del_string, "del");

static cmdline_parse_token_ipaddr_t cmd_del_nsp_ip =
TOKEN_IPNET_INITIALIZER(struct cmd_nsp_del_result, ip);

static cmdline_parse_inst_t cmd_nsp_del = {
	.f = cmd_nsp_del_parsed,
	.data = NULL,
	.help_str = "NAPT NSP DEL cmd",
	.tokens = {
			 (void *)&cmd_del_nsp_p_string,
			 (void *)&cmd_del_nsp_p,
			 (void *)&cmd_del_nsp_string,
			 (void *)&cmd_del_nsp_del_string,
			 (void *)&cmd_del_nsp_ip,
			 NULL,
			 },
};

/**
 * A structure defining the cgnapt stats cmd parse arguments.
 */
struct cmd_cgnapt_stats_result {
	cmdline_fixed_string_t p_string;
	cmdline_fixed_string_t cgnapt_string;
	cmdline_fixed_string_t stats_string;
};

/**
 * Helping function for cgnapt stats cmd
 *
 * @param parsed_result
 *  A pointer parsed add arguments
 * @param cl
 *  unused pointer to struct cmdline
 * @param msg
 *  void pointer data
 */
static void
cmd_cgnapt_stats_parsed(
	__rte_unused void *parsed_result,
	__rte_unused struct cmdline *cl,
	__rte_unused void *data)
{
	all_cgnapt_stats();
}

static cmdline_parse_token_string_t cmd_cgnapt_stats_p_string =
TOKEN_STRING_INITIALIZER(struct cmd_cgnapt_stats_result, p_string, "p");

static cmdline_parse_token_string_t cmd_cgnapt_stats_cgnapt_string =
TOKEN_STRING_INITIALIZER(struct cmd_cgnapt_stats_result,
				cgnapt_string, "cgnapt");

static cmdline_parse_token_string_t cmd_cgnapt_stats_stats_string =
TOKEN_STRING_INITIALIZER(struct cmd_cgnapt_stats_result, stats_string,
				"stats");

static cmdline_parse_inst_t cmd_stats = {
	.f = cmd_cgnapt_stats_parsed,
	.data = NULL,
	.help_str = "CGNAPT stats cmd",
	.tokens = {
		(void *)&cmd_cgnapt_stats_p_string,
		(void *)&cmd_cgnapt_stats_cgnapt_string,
		(void *)&cmd_cgnapt_stats_stats_string,
		NULL,
	},
};

/**
 * A structure defining the cgnapt clear stats cmd parse arguments.
 */
struct cmd_cgnapt_clear_stats_result {
	cmdline_fixed_string_t p_string;
	cmdline_fixed_string_t cgnapt_string;
	cmdline_fixed_string_t clear_string;
	cmdline_fixed_string_t stats_string;
};

/**
 * Helping function for cgnapt clear stats cmd
 *
 * @param parsed_result
 *  A pointer parsed add arguments
 * @param cl
 *  unused pointer to struct cmdline
 * @param msg
 *  void pointer data
 */
static void
cmd_cgnapt_clear_stats_parsed(
	__rte_unused void *parsed_result,
	__rte_unused struct cmdline *cl,
	__rte_unused void *data)
{
	all_cgnapt_clear_stats();
}

static cmdline_parse_token_string_t cmd_cgnapt_clear_stats_p_string =
TOKEN_STRING_INITIALIZER(struct cmd_cgnapt_clear_stats_result, p_string, "p");

static cmdline_parse_token_string_t cmd_cgnapt_clear_stats_cgnapt_string =
TOKEN_STRING_INITIALIZER(struct cmd_cgnapt_clear_stats_result,
				cgnapt_string, "cgnapt");

static cmdline_parse_token_string_t cmd_cgnapt_clear_stats_clear_string =
TOKEN_STRING_INITIALIZER(struct cmd_cgnapt_clear_stats_result,
				clear_string, "clear");

static cmdline_parse_token_string_t cmd_cgnapt_clear_stats_stats_string =
TOKEN_STRING_INITIALIZER(struct cmd_cgnapt_clear_stats_result, stats_string,
				"stats");

static cmdline_parse_inst_t cmd_clear_stats = {
	 .f = cmd_cgnapt_clear_stats_parsed,
	 .data = NULL,
	 .help_str = "CGNAPT clear stats cmd",
	 .tokens = {
				(void *)&cmd_cgnapt_clear_stats_p_string,
				(void *)&cmd_cgnapt_clear_stats_cgnapt_string,
				(void *)&cmd_cgnapt_clear_stats_clear_string,
				(void *)&cmd_cgnapt_clear_stats_stats_string,
				NULL,
				},
};


static cmdline_parse_ctx_t pipeline_cmds[] = {
	(cmdline_parse_inst_t *) &cmd_entry_add,
	(cmdline_parse_inst_t *) &cmd_entry_del,
	(cmdline_parse_inst_t *) &cmd_entry_ls,
	(cmdline_parse_inst_t *) &cmd_entry_dbg,
	(cmdline_parse_inst_t *) &cmd_entry_addm,
	(cmdline_parse_inst_t *) &cmd_ver,
	(cmdline_parse_inst_t *) &cmd_nsp_add,
	(cmdline_parse_inst_t *) &cmd_nsp_del,
	(cmdline_parse_inst_t *) &cmd_numipcli,
	#ifdef PCP_ENABLE
	(cmdline_parse_inst_t *) &cmd_pcp,
	#endif
	(cmdline_parse_inst_t *) &cmd_stats,
	(cmdline_parse_inst_t *) &cmd_clear_stats,
	NULL,
};

static struct pipeline_fe_ops pipeline_cgnapt_fe_ops = {
	.f_init = pipeline_cgnapt_init,
	.f_free = app_pipeline_cgnapt_free,
	.cmds = pipeline_cmds,
};

struct pipeline_type pipeline_cgnapt = {
	.name = "CGNAPT",
	.be_ops = &pipeline_cgnapt_be_ops,
	.fe_ops = &pipeline_cgnapt_fe_ops,
};