1 .. SPDX-License-Identifier: BSD-3-Clause
2 Copyright(c) 2010-2014 Intel Corporation.
4 Command Line Sample Application
5 ===============================
7 This chapter describes the Command Line sample application that
8 is part of the Data Plane Development Kit (DPDK).
13 The Command Line sample application is a simple application that
14 demonstrates the use of the command line interface in the DPDK.
15 This application is a readline-like interface that can be used
16 to debug a DPDK application, in a Linux* application environment.
20 The rte_cmdline library should not be used in production code since
21 it is not validated to the same standard as other DPDK libraries.
22 See also the "rte_cmdline library should not be used in production code due to limited testing" item
23 in the "Known Issues" section of the Release Notes.
25 The Command Line sample application supports some of the features of the GNU readline library such as, completion,
26 cut/paste and some other special bindings that make configuration and debug faster and easier.
28 The application shows how the rte_cmdline application can be extended to handle a list of objects.
29 There are three simple commands:
31 * add obj_name IP: Add a new object with an IP/IPv6 address associated to it.
33 * del obj_name: Delete the specified object.
35 * show obj_name: Show the IP associated with the specified object.
39 To terminate the application, use **Ctrl-d**.
41 Compiling the Application
42 -------------------------
44 To compile the sample application see :doc:`compiling`
46 The application is located in the ``cmd_line`` sub-directory.
48 Running the Application
49 -----------------------
51 To run the application in linux environment, issue the following command:
53 .. code-block:: console
55 $ ./<build_dir>/examples/dpdk-cmdline -l 0-3 -n 4
57 Refer to the *DPDK Getting Started Guide* for general information on running applications
58 and the Environment Abstraction Layer (EAL) options.
63 The following sections provide some explanation of the code.
65 EAL Initialization and cmdline Start
66 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
68 The first task is the initialization of the Environment Abstraction Layer (EAL).
69 This is achieved as follows:
71 .. literalinclude:: ../../../examples/cmdline/main.c
73 :start-after: Initialization of the Environment Abstraction Layer (EAL). 8<
74 :end-before: >8 End of initialization of Environment Abstraction Layer (EAL).
76 Then, a new command line object is created and started to interact with the user through the console:
78 .. literalinclude:: ../../../examples/cmdline/main.c
80 :start-after: Creating a new command line object. 8<
81 :end-before: >8 End of creating a new command line object.
84 The cmd line_interact() function returns when the user types **Ctrl-d** and in this case,
85 the application exits.
87 Defining a cmdline Context
88 ~~~~~~~~~~~~~~~~~~~~~~~~~~
90 A cmdline context is a list of commands that are listed in a NULL-terminated table, for example:
92 .. literalinclude:: ../../../examples/cmdline/commands.c
94 :start-after: Cmdline context list of commands in NULL-terminated table. 8<
95 :end-before: >8 End of context list.
97 Each command (of type cmdline_parse_inst_t) is defined statically.
98 It contains a pointer to a callback function that is executed when the command is parsed,
99 an opaque pointer, a help string and a list of tokens in a NULL-terminated table.
101 The rte_cmdline application provides a list of pre-defined token types:
103 * String Token: Match a static string, a list of static strings or any string.
105 * Number Token: Match a number that can be signed or unsigned, from 8-bit to 32-bit.
107 * IP Address Token: Match an IPv4 or IPv6 address or network.
109 * Ethernet* Address Token: Match a MAC address.
111 In this example, a new token type obj_list is defined and implemented
112 in the parse_obj_list.c and parse_obj_list.h files.
114 For example, the cmd_obj_del_show command is defined as shown below:
116 .. literalinclude:: ../../../examples/cmdline/commands.c
118 :start-after: Show or delete tokens. 8<
119 :end-before: >8 End of show or delete tokens.
121 This command is composed of two tokens:
123 * The first token is a string token that can be show or del.
125 * The second token is an object that was previously added using the add command in the global_obj_list variable.
127 Once the command is parsed, the rte_cmdline application fills a cmd_obj_del_show_result structure.
128 A pointer to this structure is given as an argument to the callback function and can be used in the body of this function.