1.. SPDX-License-Identifier: BSD-3-Clause 2 Copyright(c) 2010-2014 Intel Corporation. 3 4Command Line Sample Application 5=============================== 6 7This chapter describes the Command Line sample application that 8is part of the Data Plane Development Kit (DPDK). 9 10Overview 11-------- 12 13The Command Line sample application is a simple application that 14demonstrates the use of the command line interface in the DPDK. 15This application is a readline-like interface that can be used 16to debug a DPDK application, in a Linux* application environment. 17 18.. note:: 19 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. 24 25The Command Line sample application supports some of the features of the GNU readline library such as, completion, 26cut/paste and some other special bindings that make configuration and debug faster and easier. 27 28The application shows how the rte_cmdline application can be extended to handle a list of objects. 29There are three simple commands: 30 31* add obj_name IP: Add a new object with an IP/IPv6 address associated to it. 32 33* del obj_name: Delete the specified object. 34 35* show obj_name: Show the IP associated with the specified object. 36 37.. note:: 38 39 To terminate the application, use **Ctrl-d**. 40 41Compiling the Application 42------------------------- 43 44To compile the sample application see :doc:`compiling` 45 46The application is located in the ``cmd_line`` sub-directory. 47 48Running the Application 49----------------------- 50 51To run the application in linux environment, issue the following command: 52 53.. code-block:: console 54 55 $ ./<build_dir>/examples/dpdk-cmdline -l 0-3 -n 4 56 57Refer to the *DPDK Getting Started Guide* for general information on running applications 58and the Environment Abstraction Layer (EAL) options. 59 60Explanation 61----------- 62 63The following sections provide some explanation of the code. 64 65EAL Initialization and cmdline Start 66~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 67 68The first task is the initialization of the Environment Abstraction Layer (EAL). 69This is achieved as follows: 70 71.. literalinclude:: ../../../examples/cmdline/main.c 72 :language: c 73 :start-after: Initialization of the Environment Abstraction Layer (EAL). 8< 74 :end-before: >8 End of initialization of Environment Abstraction Layer (EAL). 75 76Then, a new command line object is created and started to interact with the user through the console: 77 78.. literalinclude:: ../../../examples/cmdline/main.c 79 :language: c 80 :start-after: Creating a new command line object. 8< 81 :end-before: >8 End of creating a new command line object. 82 :dedent: 1 83 84The cmd line_interact() function returns when the user types **Ctrl-d** and in this case, 85the application exits. 86 87Defining a cmdline Context 88~~~~~~~~~~~~~~~~~~~~~~~~~~ 89 90A cmdline context is a list of commands that are listed in a NULL-terminated table, for example: 91 92.. literalinclude:: ../../../examples/cmdline/commands.c 93 :language: c 94 :start-after: Cmdline context list of commands in NULL-terminated table. 8< 95 :end-before: >8 End of context list. 96 97Each command (of type cmdline_parse_inst_t) is defined statically. 98It contains a pointer to a callback function that is executed when the command is parsed, 99an opaque pointer, a help string and a list of tokens in a NULL-terminated table. 100 101The rte_cmdline application provides a list of pre-defined token types: 102 103* String Token: Match a static string, a list of static strings or any string. 104 105* Number Token: Match a number that can be signed or unsigned, from 8-bit to 32-bit. 106 107* IP Address Token: Match an IPv4 or IPv6 address or network. 108 109* Ethernet* Address Token: Match a MAC address. 110 111In this example, a new token type obj_list is defined and implemented 112in the parse_obj_list.c and parse_obj_list.h files. 113 114For example, the cmd_obj_del_show command is defined as shown below: 115 116.. literalinclude:: ../../../examples/cmdline/commands.c 117 :language: c 118 :start-after: Show or delete tokens. 8< 119 :end-before: >8 End of show or delete tokens. 120 121This command is composed of two tokens: 122 123* The first token is a string token that can be show or del. 124 125* The second token is an object that was previously added using the add command in the global_obj_list variable. 126 127Once the command is parsed, the rte_cmdline application fills a cmd_obj_del_show_result structure. 128A pointer to this structure is given as an argument to the callback function and can be used in the body of this function. 129