summaryrefslogtreecommitdiff
path: root/src/vf/command_dec.c
blob: 23e818e73dc229e512c704b72d630c8cebe51f98 (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
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
/*
 *   BSD LICENSE
 *
 *   Copyright(c) 2017 Nippon Telegraph and Telephone Corporation
 *   All rights reserved.
 *
 *   Redistribution and use in source and binary forms, with or without
 *   modification, are permitted provided that the following conditions
 *   are met:
 *
 *     * Redistributions of source code must retain the above copyright
 *       notice, this list of conditions and the following disclaimer.
 *     * Redistributions in binary form must reproduce the above copyright
 *       notice, this list of conditions and the following disclaimer in
 *       the documentation and/or other materials provided with the
 *       distribution.
 *     * Neither the name of Nippon Telegraph and Telephone Corporation
 *       nor the names of its contributors may be used to endorse or
 *       promote products derived from this software without specific
 *       prior written permission.
 *
 *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
 *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
 *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
 *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
 *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
 *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */

#include <unistd.h>
#include <string.h>

#include <rte_log.h>
#include <rte_branch_prediction.h>

#include "spp_vf.h"
#include "command_dec.h"

#define RTE_LOGTYPE_SPP_COMMAND_PROC RTE_LOGTYPE_USER1

/*
 * classifier type string list
 * do it same as the order of enum spp_classifier_type (spp_vf.h)
 */
const char *CLASSIFILER_TYPE_STRINGS[] = {
	"none",
	"mac",

	/* termination */ "",
};

/*
 * command action type string list
 * do it same as the order of enum spp_command_action (spp_vf.h)
 */
const char *COMMAND_ACTION_STRINGS[] = {
	"none",
	"start",
	"stop",
	"add",
	"del",

	/* termination */ "",
};

/*
 * port rxtx string list
 * do it same as the order of enum spp_port_rxtx (spp_vf.h)
 */
const char *PORT_RXTX_STRINGS[] = {
	"none",
	"rx",
	"tx",

	/* termination */ "",
};

/* set decode error */
inline int
set_decode_error(struct spp_command_decode_error *error,
		const int error_code, const char *error_name)
{
	error->code = error_code;

	if (likely(error_name != NULL))
		strcpy(error->value_name, error_name);

	return error->code;
}

/* set decode error */
inline int
set_string_value_decode_error(struct spp_command_decode_error *error,
		const char *value, const char *error_name)
{
	strcpy(error->value, value);
	return set_decode_error(error, SPP_CMD_DERR_BAD_VALUE, error_name);
}

/* Split command line parameter with spaces */
static int
decode_parameter_value(char *string, int max, int *argc, char *argv[])
{
	int cnt = 0;
	const char *delim = " ";
	char *argv_tok = NULL;
	char *saveptr = NULL;

	argv_tok = strtok_r(string, delim, &saveptr);
	while (argv_tok != NULL) {
		if (cnt >= max)
			return -1;
		argv[cnt] = argv_tok;
		cnt++;
		argv_tok = strtok_r(NULL, delim, &saveptr);
	}
	*argc = cnt;

	return 0;
}

/* Get index of array */
static int
get_arrary_index(const char *match, const char *list[])
{
	int i;
	for (i = 0; list[i][0] != '\0'; i++) {
		if (strcmp(list[i], match) == 0)
			return i;
	}
	return -1;
}

/* Get unsigned int type value */
static int
get_uint_value(
		unsigned int *output,
		const char *arg_val,
		unsigned int min,
		unsigned int max)
{
	unsigned int ret = 0;
	char *endptr = NULL;
	ret = strtoul(arg_val, &endptr, 0);
	if (unlikely(endptr == arg_val) || unlikely(*endptr != '\0'))
		return -1;

	if (unlikely(ret < min) || unlikely(ret > max))
		return -1;

	*output = ret;
	return 0;
}

/* decoding procedure of string */
static int
decode_str_value(char *output, const char *arg_val)
{
	if (strlen(arg_val) >= SPP_CMD_VALUE_BUFSZ)
		return -1;

	strcpy(output, arg_val);
	return 0;
}

/* decoding procedure of port */
static int
decode_port_value(void *output, const char *arg_val)
{
	int ret = 0;
	struct spp_port_index *port = output;
	ret = spp_get_iface_index(arg_val, &port->iface_type, &port->iface_no);
	if (unlikely(ret != 0)) {
		RTE_LOG(ERR, SPP_COMMAND_PROC, "Bad port. val=%s\n", arg_val);
		return -1;
	}

	return 0;
}

/* decoding procedure of core */
static int
decode_core_value(void *output, const char *arg_val)
{
	int ret = 0;
	ret = get_uint_value(output, arg_val, 0, RTE_MAX_LCORE-1);
	if (unlikely(ret < 0)) {
		RTE_LOG(ERR, SPP_COMMAND_PROC, "Bad core id. val=%s\n",
				arg_val);
		return -1;
	}

	return 0;
}

/* decoding procedure of action for component command */
static int
decode_component_action_value(void *output, const char *arg_val)
{
	int ret = 0;
	ret = get_arrary_index(arg_val, COMMAND_ACTION_STRINGS);
	if (unlikely(ret <= 0)) {
		RTE_LOG(ERR, SPP_COMMAND_PROC,
				"Unknown component action. val=%s\n",
				arg_val);
		return -1;
	}

	if (unlikely(ret != SPP_CMD_ACTION_START) &&
			unlikely(ret != SPP_CMD_ACTION_STOP)) {
		RTE_LOG(ERR, SPP_COMMAND_PROC,
				"Unknown component action. val=%s\n",
				arg_val);
		return -1;
	}

	*(int *)output = ret;
	return 0;
}

/* decoding procedure of action for component command */
static int
decode_component_name_value(void *output, const char *arg_val)
{
	int ret = 0;
	struct spp_command_component *component = output;

	/* "stop" has no core ID parameter. */
	if (component->action == SPP_CMD_ACTION_START) {
		ret = spp_get_component_id(arg_val);
		if (unlikely(ret >= 0)) {
			RTE_LOG(ERR, SPP_COMMAND_PROC,
					"Component name in used. val=%s\n",
					arg_val);
			return -1;
		}
	}

	return decode_str_value(component->name, arg_val);
}

/* decoding procedure of core id for component command */
static int
decode_component_core_value(void *output, const char *arg_val)
{
	struct spp_command_component *component = output;

	/* "stop" has no core ID parameter. */
	if (component->action != SPP_CMD_ACTION_START)
		return 0;

	return decode_core_value(&component->core, arg_val);
}

/* decoding procedure of type for component command */
static int
decode_component_type_value(void *output, const char *arg_val)
{
	enum spp_component_type org_type, set_type;
	struct spp_command_component *component = output;

	/* "stop" has no type parameter. */
	if (component->action != SPP_CMD_ACTION_START)
		return 0;

	set_type = spp_change_component_type(arg_val);
	if (unlikely(set_type <= 0)) {
		RTE_LOG(ERR, SPP_COMMAND_PROC,
				"Unknown component type. val=%s\n",
				arg_val);
		return -1;
	}

	org_type = spp_get_component_type_update(component->core);
	if ((org_type != SPP_COMPONENT_UNUSE) && (org_type != set_type)) {
		RTE_LOG(ERR, SPP_COMMAND_PROC,
				"Component type does not match. val=%s (org=%d, new=%d)\n",
				arg_val, org_type, set_type);
		return -1;
	}

	component->type = set_type;
	return 0;
}

/* decoding procedure of action for port command */
static int
decode_port_action_value(void *output, const char *arg_val)
{
	int ret = 0;
	ret = get_arrary_index(arg_val, COMMAND_ACTION_STRINGS);
	if (unlikely(ret <= 0)) {
		RTE_LOG(ERR, SPP_COMMAND_PROC,
				"Unknown port action. val=%s\n",
				arg_val);
		return -1;
	}

	if (unlikely(ret != SPP_CMD_ACTION_ADD) &&
			unlikely(ret != SPP_CMD_ACTION_DEL)) {
		RTE_LOG(ERR, SPP_COMMAND_PROC,
				"Unknown port action. val=%s\n",
				arg_val);
		return -1;
	}

	*(int *)output = ret;
	return 0;
}

/* decoding procedure of port for port command */
static int
decode_port_port_value(void *output, const char *arg_val)
{
	int ret = -1;
	struct spp_port_index tmp_port;
	struct spp_command_port *port = output;

	ret = decode_port_value(&tmp_port, arg_val);
	if (ret < 0)
		return -1;

	if ((port->action == SPP_CMD_ACTION_ADD) &&
			(spp_check_used_port(tmp_port.iface_type,
					tmp_port.iface_no,
					SPP_PORT_RXTX_RX) >= 0) &&
			(spp_check_used_port(tmp_port.iface_type,
					tmp_port.iface_no,
					SPP_PORT_RXTX_TX) >= 0)) {
		RTE_LOG(ERR, SPP_COMMAND_PROC,
				"Port in used. (port command) val=%s\n",
				arg_val);
		return -1;
	}

	port->port.iface_type = tmp_port.iface_type;
	port->port.iface_no   = tmp_port.iface_no;
	return 0;
}

/* decoding procedure of rxtx type for port command */
static int
decode_port_rxtx_value(void *output, const char *arg_val)
{
	int ret = 0;
	struct spp_command_port *port = output;

	ret = get_arrary_index(arg_val, PORT_RXTX_STRINGS);
	if (unlikely(ret <= 0)) {
		RTE_LOG(ERR, SPP_COMMAND_PROC, "Unknown port rxtx. val=%s\n",
				arg_val);
		return -1;
	}

	if ((port->action == SPP_CMD_ACTION_ADD) &&
			(spp_check_used_port(port->port.iface_type,
					port->port.iface_no, ret) >= 0)) {
		RTE_LOG(ERR, SPP_COMMAND_PROC,
				"Port in used. (port command) val=%s\n",
				arg_val);
		return -1;
	}

	port->rxtx = ret;
	return 0;
}

/* decoding procedure of component name for port command */
static int
decode_port_name_value(void *output, const char *arg_val)
{
	int ret = 0;

	ret = spp_get_component_id(arg_val);
	if (unlikely(ret < 0)) {
		RTE_LOG(ERR, SPP_COMMAND_PROC, "Unknown component name. val=%s\n",
				arg_val);
		return -1;
	}

	return decode_str_value(output, arg_val);
}

/* decoding procedure of mac address string */
static int
decode_mac_addr_str_value(void *output, const char *arg_val)
{
	int64_t ret = 0;
	const char *str_val = arg_val;

	/* if default specification, convert to internal dummy address */
	if (unlikely(strcmp(str_val, SPP_DEFAULT_CLASSIFIED_SPEC_STR) == 0))
		str_val = SPP_DEFAULT_CLASSIFIED_DMY_ADDR_STR;

	ret = spp_change_mac_str_to_int64(str_val);
	if (unlikely(ret < 0)) {
		RTE_LOG(ERR, SPP_COMMAND_PROC, "Bad mac address string. val=%s\n",
				str_val);
		return -1;
	}

	strcpy((char *)output, str_val);
	return 0;
}

/* decoding procedure of action for classifier_table command */
static int
decode_classifier_action_value(void *output, const char *arg_val)
{
	int ret = 0;
	ret = get_arrary_index(arg_val, COMMAND_ACTION_STRINGS);
	if (unlikely(ret <= 0)) {
		RTE_LOG(ERR, SPP_COMMAND_PROC, "Unknown port action. val=%s\n",
				arg_val);
		return -1;
	}

	if (unlikely(ret != SPP_CMD_ACTION_ADD) &&
			unlikely(ret != SPP_CMD_ACTION_DEL)) {
		RTE_LOG(ERR, SPP_COMMAND_PROC, "Unknown port action. val=%s\n",
				arg_val);
		return -1;
	}

	*(int *)output = ret;
	return 0;
}

/* decoding procedure of type for classifier_table command */
static int
decode_classifier_type_value(void *output, const char *arg_val)
{
	int ret = 0;
	ret = get_arrary_index(arg_val, CLASSIFILER_TYPE_STRINGS);
	if (unlikely(ret <= 0)) {
		RTE_LOG(ERR, SPP_COMMAND_PROC,
				"Unknown classifier type. val=%s\n",
				arg_val);
		return -1;
	}

	*(int *)output = ret;
	return 0;
}

/* decoding procedure of value for classifier_table command */
static int
decode_classifier_value_value(void *output, const char *arg_val)
{
	int ret = -1;
	struct spp_command_classifier_table *classifier_table = output;
	switch (classifier_table->type) {
	case SPP_CLASSIFIER_TYPE_MAC:
		ret = decode_mac_addr_str_value(classifier_table->value,
				arg_val);
		break;
	default:
		break;
	}
	return ret;
}

/* decoding procedure of port for classifier_table command */
static int
decode_classifier_port_value(void *output, const char *arg_val)
{
	int ret = 0;
	struct spp_command_classifier_table *classifier_table = output;
	struct spp_port_index tmp_port;
	int64_t mac_addr = 0;

	ret = decode_port_value(&tmp_port, arg_val);
	if (ret < 0)
		return -1;

	if (spp_check_added_port(tmp_port.iface_type, tmp_port.iface_no) == 0) {
		RTE_LOG(ERR, SPP_COMMAND_PROC, "Port not added. val=%s\n",
				arg_val);
		return -1;
	}

	if (unlikely(classifier_table->action == SPP_CMD_ACTION_ADD)) {
		if (!spp_check_mac_used_port(0, tmp_port.iface_type,
				tmp_port.iface_no)) {
			RTE_LOG(ERR, SPP_COMMAND_PROC,
					"Port in used. (classifier_table command) val=%s\n",
					arg_val);
			return -1;
		}
	} else if (unlikely(classifier_table->action == SPP_CMD_ACTION_DEL)) {
		mac_addr = spp_change_mac_str_to_int64(classifier_table->value);
		if (mac_addr < 0)
			return -1;

		if (!spp_check_mac_used_port((uint64_t)mac_addr,
				tmp_port.iface_type, tmp_port.iface_no)) {
			RTE_LOG(ERR, SPP_COMMAND_PROC,
					"Port in used. (classifier_table command) val=%s\n",
					arg_val);
			return -1;
		}
	}

	classifier_table->port.iface_type = tmp_port.iface_type;
	classifier_table->port.iface_no   = tmp_port.iface_no;
	return 0;
}

#define DECODE_PARAMETER_LIST_EMPTY { NULL, 0, NULL }

/* parameter list for decoding */
struct decode_parameter_list {
	const char *name;       /* Parameter name */
	size_t offset;          /* Offset value of struct spp_command */
	int (*func)(void *output, const char *arg_val);
				/* Pointer to parameter handling function */
};

/* parameter list for each command */
static struct decode_parameter_list parameter_list[][SPP_CMD_MAX_PARAMETERS] = {
	{                                /* classifier_table */
		{
			.name = "action",
			.offset = offsetof(struct spp_command,
					spec.classifier_table.action),
			.func = decode_classifier_action_value
		},
		{
			.name = "type",
			.offset = offsetof(struct spp_command,
					spec.classifier_table.type),
			.func = decode_classifier_type_value
		},
		{
			.name = "value",
			.offset = offsetof(struct spp_command,
					spec.classifier_table),
			.func = decode_classifier_value_value
		},
		{
			.name = "port",
			.offset = offsetof(struct spp_command,
					spec.classifier_table),
			.func = decode_classifier_port_value
		},
		DECODE_PARAMETER_LIST_EMPTY,
	},
	{ DECODE_PARAMETER_LIST_EMPTY }, /* flush            */
	{ DECODE_PARAMETER_LIST_EMPTY }, /* _get_client_id   */
	{ DECODE_PARAMETER_LIST_EMPTY }, /* status           */
	{ DECODE_PARAMETER_LIST_EMPTY }, /* exit             */
	{                                /* component        */
		{
			.name = "action",
			.offset = offsetof(struct spp_command,
					spec.component.action),
			.func = decode_component_action_value
		},
		{
			.name = "component name",
			.offset = offsetof(struct spp_command, spec.component),
			.func = decode_component_name_value
		},
		{
			.name = "core",
			.offset = offsetof(struct spp_command, spec.component),
			.func = decode_component_core_value
		},
		{
			.name = "component type",
			.offset = offsetof(struct spp_command, spec.component),
			.func = decode_component_type_value
		},
		DECODE_PARAMETER_LIST_EMPTY,
	},
	{                                /* port             */
		{
			.name = "action",
			.offset = offsetof(struct spp_command,
					spec.port.action),
			.func = decode_port_action_value
		},
		{
			.name = "port",
			.offset = offsetof(struct spp_command, spec.port),
			.func = decode_port_port_value
		},
		{
			.name = "port rxtx",
			.offset = offsetof(struct spp_command, spec.port),
			.func = decode_port_rxtx_value
		},
		{
			.name = "component name",
			.offset = offsetof(struct spp_command, spec.port.name),
			.func = decode_port_name_value
		},
		DECODE_PARAMETER_LIST_EMPTY,
	},
	{ DECODE_PARAMETER_LIST_EMPTY }, /* cancel           */
	{ DECODE_PARAMETER_LIST_EMPTY }, /* termination      */
};

/* check by list for each command line parameter */
static int
decode_command_parameter_in_list(struct spp_command_request *request,
				int argc, char *argv[],
				struct spp_command_decode_error *error)
{
	int ret = 0;
	int ci = request->commands[0].type;
	int pi = 0;
	struct decode_parameter_list *list = NULL;
	for (pi = 1; pi < argc; pi++) {
		list = &parameter_list[ci][pi-1];
		ret = (*list->func)((void *)
				((char *)&request->commands[0]+list->offset),
				argv[pi]);
		if (unlikely(ret < 0)) {
			RTE_LOG(ERR, SPP_COMMAND_PROC,
					"Bad value. command=%s, name=%s, index=%d, value=%s\n",
					argv[0], list->name, pi, argv[pi]);
			return set_string_value_decode_error(error, argv[pi],
					list->name);
		}
	}
	return 0;
}

/* command list for decoding */
struct decode_command_list {
	const char *name;       /* Command name */
	int   param_min;        /* Min number of parameters */
	int   param_max;        /* Max number of parameters */
	int (*func)(struct spp_command_request *request, int argc, char *argv[],
			struct spp_command_decode_error *error);
				/* Pointer to command handling function */
};

/* command list */
static struct decode_command_list command_list[] = {
	{ "classifier_table", 5, 5, decode_command_parameter_in_list },
						/* classifier_table */
	{ "flush",            1, 1, NULL },     /* flush            */
	{ "_get_client_id",   1, 1, NULL },     /* _get_client_id   */
	{ "status",           1, 1, NULL },     /* status           */
	{ "exit",             1, 1, NULL },     /* exit             */
	{ "component",        3, 5, decode_command_parameter_in_list },
						/* component        */
	{ "port",             5, 5, decode_command_parameter_in_list },
						/* port             */
	{ "cancel",           1, 1, NULL },     /* cancel           */
	{ "",                 0, 0, NULL }      /* termination      */
};

/* Decode command line parameters */
static int
decode_command_in_list(struct spp_command_request *request,
			const char *request_str,
			struct spp_command_decode_error *error)
{
	int ret = 0;
	struct decode_command_list *list = NULL;
	int i = 0;
	int argc = 0;
	char *argv[SPP_CMD_MAX_PARAMETERS];
	char tmp_str[SPP_CMD_MAX_PARAMETERS*SPP_CMD_VALUE_BUFSZ];
	memset(argv, 0x00, sizeof(argv));
	memset(tmp_str, 0x00, sizeof(tmp_str));

	strcpy(tmp_str, request_str);
	ret = decode_parameter_value(tmp_str, SPP_CMD_MAX_PARAMETERS,
			&argc, argv);
	if (ret < 0) {
		RTE_LOG(ERR, SPP_COMMAND_PROC, "Parameter number over limit."
				"request_str=%s\n", request_str);
		return set_decode_error(error, SPP_CMD_DERR_BAD_FORMAT, NULL);
	}
	RTE_LOG(DEBUG, SPP_COMMAND_PROC, "Decode array. num=%d\n", argc);

	for (i = 0; command_list[i].name[0] != '\0'; i++) {
		list = &command_list[i];
		if (strcmp(argv[0], list->name) != 0)
			continue;

		if (unlikely(argc < list->param_min) ||
				unlikely(list->param_max < argc)) {
			RTE_LOG(ERR, SPP_COMMAND_PROC,
					"Parameter number out of range."
					"request_str=%s\n", request_str);
			return set_decode_error(error, SPP_CMD_DERR_BAD_FORMAT,
					NULL);
		}

		request->commands[0].type = i;
		if (list->func != NULL)
			return (*list->func)(request, argc, argv, error);

		return 0;
	}

	RTE_LOG(ERR, SPP_COMMAND_PROC,
			"Unknown command. command=%s, request_str=%s\n",
			argv[0], request_str);
	return set_string_value_decode_error(error, argv[0], "command");
}

/* decode request from no-null-terminated string */
int
spp_command_decode_request(
		struct spp_command_request *request,
		const char *request_str, size_t request_str_len,
		struct spp_command_decode_error *error)
{
	int ret = -1;
	int i;

	/* decode request */
	request->num_command = 1;
	ret = decode_command_in_list(request, request_str, error);
	if (unlikely(ret != 0)) {
		RTE_LOG(ERR, SPP_COMMAND_PROC, "Cannot decode command request. "
				"ret=%d, request_str=%.*s\n",
				ret, (int)request_str_len, request_str);
		return ret;
	}
	request->num_valid_command = 1;

	/* check getter command */
	for (i = 0; i < request->num_valid_command; ++i) {
		switch (request->commands[i].type) {
		case SPP_CMDTYPE_CLIENT_ID:
			request->is_requested_client_id = 1;
			break;
		case SPP_CMDTYPE_STATUS:
			request->is_requested_status = 1;
			break;
		case SPP_CMDTYPE_EXIT:
			request->is_requested_exit = 1;
			break;
		default:
			/* nothing to do */
			break;
		}
	}

	return ret;
}