blob: 23023e21bfba44b119cb5790470cce3457ba9064 [file] [log] [blame]
Nathan Skrzypczaka2c95092021-10-08 14:05:58 +02001.. _sample_plugin_doc:
2
3Sample plugin for VPP
4=====================
5
6Overview
7--------
8
9This is the VPP sample plugin demonstrates how to create a new plugin
10that integrates with VPP. The sample code implements a trivial macswap
11algorithm that demonstrates plugin runtime integration with the VPP
12graph hierarchy, api and cli.
13
14For deeper dive information see the annotations in the sample code
15itself. See `sample.c <@ref%20sample.c>`__
16
17How to build and run the sample plugin.
18---------------------------------------
19
20Now (re)build VPP.
21
22::
23
24 $ make wipe
25
26Define environmental variable SAMPLE_PLUGIN=yes with a process scope
27
28::
29
30 $ SAMPLE_PLUGIN=yes make build
31
32or a session scope, and build VPP.
33
34::
35
36 $ export SAMPLE_PLUGIN=yes
37 $ make build
38
39Now run VPP and make sure the plugin is loaded.
40
41::
42
43 $ make run
44 ...
45 load_one_plugin:184: Loaded plugin: memif_plugin.so (Packet Memory Interface (experimetal))
46 load_one_plugin:184: Loaded plugin: sample_plugin.so (Sample of VPP Plugin)
47 load_one_plugin:184: Loaded plugin: nat_plugin.so (Network Address Translation)
48 ...
49 DBGvpp#
50
51How to create a new plugin
52--------------------------
53
54To create a new plugin based on the sample plugin, copy and rename the
55sample plugin directory and automake config.
56
57::
58
59 cp -r src/examples/sample-plugin/sample src/plugins/newplugin
60 cp src/examples/sample-plugin/sample.am src/plugins/newplugin.am
61
62Add the following entry to the plugins section of ``src/configure.ac``.
63
64::
65
66 PLUGIN_ENABLED(newplugin)
67
68Add the following entry to the plugins section of
69``src/plugins/Makefile.am``
70
71::
72
73 if ENABLE_NEWPLUGIN
74 include newplugin.am
75 endif
76
77Now (re)build VPP.
78
79::
80
81 $ make wipe
82 $ make build
83
84Configuration
85-------------
86
87To enable the sample plugin
88
89::
90
91 sample macswap <interface name>
92
93To disable the sample plugin
94
95::
96
97 sample macswap <interface name> disable