Imported Upstream version 16.04
[deb_dpdk.git] / doc / guides / prog_guide / extend_dpdk.rst
1 ..  BSD LICENSE
2     Copyright(c) 2010-2014 Intel Corporation. All rights reserved.
3     All rights reserved.
4
5     Redistribution and use in source and binary forms, with or without
6     modification, are permitted provided that the following conditions
7     are met:
8
9     * Redistributions of source code must retain the above copyright
10     notice, this list of conditions and the following disclaimer.
11     * Redistributions in binary form must reproduce the above copyright
12     notice, this list of conditions and the following disclaimer in
13     the documentation and/or other materials provided with the
14     distribution.
15     * Neither the name of Intel Corporation nor the names of its
16     contributors may be used to endorse or promote products derived
17     from this software without specific prior written permission.
18
19     THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20     "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21     LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22     A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
23     OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24     SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25     LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26     DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27     THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28     (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29     OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30
31 Extending the DPDK
32 =========================
33
34 This chapter describes how a developer can extend the DPDK to provide a new library,
35 a new target, or support a new target.
36
37 Example: Adding a New Library libfoo
38 ------------------------------------
39
40 To add a new library to the DPDK, proceed as follows:
41
42 #.  Add a new configuration option:
43
44    .. code-block:: bash
45
46         for f in config/\*; do \
47             echo CONFIG_RTE_LIBFOO=y >> $f; done
48
49 #.  Create a new directory with sources:
50
51    .. code-block:: console
52
53         mkdir ${RTE_SDK}/lib/libfoo
54         touch ${RTE_SDK}/lib/libfoo/foo.c
55         touch ${RTE_SDK}/lib/libfoo/foo.h
56
57 #.  Add a foo() function in libfoo.
58
59     Definition is in foo.c:
60
61     .. code-block:: c
62
63         void foo(void)
64         {
65         }
66
67     Declaration is in foo.h:
68
69     .. code-block:: c
70
71         extern void foo(void);
72
73
74 #.  Update lib/Makefile:
75
76     .. code-block:: console
77
78         vi ${RTE_SDK}/lib/Makefile
79         # add:
80         # DIRS-$(CONFIG_RTE_LIBFOO) += libfoo
81
82 #.  Create a new Makefile for this library, for example, derived from mempool Makefile:
83
84     .. code-block:: console
85
86         cp ${RTE_SDK}/lib/librte_mempool/Makefile ${RTE_SDK}/lib/libfoo/
87
88         vi ${RTE_SDK}/lib/libfoo/Makefile
89         # replace:
90         # librte_mempool -> libfoo
91         # rte_mempool -> foo
92
93
94 #.  Update mk/DPDK.app.mk, and add -lfoo in LDLIBS variable when the option is enabled.
95     This will automatically add this flag when linking a DPDK application.
96
97
98 #.  Build the DPDK with the new library (we only show a specific target here):
99
100     .. code-block:: console
101
102         cd ${RTE_SDK}
103         make config T=x86_64-native-linuxapp-gcc
104         make
105
106
107 #.  Check that the library is installed:
108
109     .. code-block:: console
110
111         ls build/lib
112         ls build/include
113
114 Example: Using libfoo in the Test Application
115 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
116
117 The test application is used to validate all functionality of the DPDK.
118 Once you have added a library, a new test case should be added in the test application.
119
120 *   A new test_foo.c file should be added, that includes foo.h and calls the foo() function from test_foo().
121     When the test passes, the test_foo() function should return 0.
122
123 *   Makefile, test.h and commands.c must be updated also, to handle the new test case.
124
125 *   Test report generation: autotest.py is a script that is used to generate the test report that is available in the
126     ${RTE_SDK}/doc/rst/test_report/autotests directory. This script must be updated also.
127     If libfoo is in a new test family, the links in ${RTE_SDK}/doc/rst/test_report/test_report.rst must be updated.
128
129 *   Build the DPDK with the updated test application (we only show a specific target here):
130
131
132     .. code-block:: console
133
134         cd ${RTE_SDK}
135         make config T=x86_64-native-linuxapp-gcc
136         make