Skip to content

Commit 7e31261

Browse files
authored
Merge pull request #285 from michelsciortino/ms-documentation
Adding some hints in Polycube Documentation
2 parents 777e4fd + 6faa1cb commit 7e31261

File tree

1 file changed

+103
-2
lines changed

1 file changed

+103
-2
lines changed

Documentation/developers/hints.rst

Lines changed: 103 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,106 @@
1-
Some hints for programmers
2-
--------------------------
1+
Hints for programmers
2+
---------------------
3+
4+
Compiling a Polycube service
5+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6+
Polycube services can be compiled in two ways:
7+
8+
- together with the entire Polycube source code
9+
- as stand-alone services that can be loaded into Polycube at runtime
10+
11+
Compiling together with the Polycube source code
12+
************************************************
13+
1. Place the service into the :SCM_WEB:`src/services <src/services>` folder;
14+
15+
2. Update the :SCM_WEB:`src/services/CMakeLists.txt <src/services/CMakeLists.txt>` file adding a new `cmake` instruction:
16+
17+
::
18+
19+
add_service(service_name service_folder)
20+
21+
where the first argument is the service name used in the Polycube REST API, while second argument is the folder name of the service.
22+
23+
**Note**: the service folder name must follow the ``pcn-service_name`` naming convention (E.g. pcn-bridge, pcn-router).
24+
25+
3. Compile and re-install Polycube:
26+
27+
::
28+
29+
# having Polycube root folder as working directory
30+
mkdir build && cd build
31+
cmake ..
32+
make -j $(getconf _NPROCESSORS_ONLN)
33+
sudo make install
34+
35+
.. _stand_alone_compilation:
36+
37+
Compiling a stand-alone service
38+
*******************************
39+
1. create a `build` folder in the root folder of the service and set it as working directory:
40+
41+
::
42+
43+
mkdir build && cd build
44+
45+
2. generate a Makefile:
46+
47+
::
48+
49+
cmake ..
50+
51+
3. compile the service to build a shared library object:
52+
53+
::
54+
55+
make -j $(getconf _NPROCESSORS_ONLN)
56+
57+
At this point the service has been compiled and the built shared library object can be found into the ``build/src`` folder named as ``libpcn-service_name.so``
58+
59+
The compiled service, completely encapsulated in the .so file, is now ready to be loaded by the Polycube daemon.
60+
61+
Loading/unloading Polycube services at runtime
62+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
63+
In order to load a new service at runtime, we should provide to Polycube daemon the shared library object (.so) we compiled before.
64+
65+
Loading a service
66+
*****************
67+
In order to load a new service into Polycube a shared library object must be provided.
68+
Please see :ref:`stand_alone_compilation` to generate this object.
69+
70+
To load a service into a running Polycube instance use:
71+
72+
::
73+
74+
polycubectl services add type=lib uri=/absolute/path/to/libpcn-service_name.so name=service_name
75+
76+
- the ``uri`` parameter indicates the absolute path to the shared library object of the service;
77+
- the ``name`` parameter indicates the name that will be use in the Polycube rest API for the service.
78+
79+
After having loaded the service, it can be instantiated as a normal service using ``polycubectl``.
80+
81+
To verify the service has been loaded correctly and is ready to be instantiated:
82+
83+
::
84+
85+
# show available services list; the loaded service should be present
86+
polycubectl services show
87+
88+
# create an instance of the service
89+
polycubectl service_name add instance_name
90+
91+
# dump the service
92+
polycubectl instance_name show
93+
94+
95+
Unloading a service
96+
*******************
97+
To unload a service from a running Polycube instance use:
98+
99+
::
100+
101+
polycubectl services del service_name
102+
103+
where ``service_name`` indicates the name used by the Polycube rest API for the service (E.g. bridge, router)
3104

4105

5106
Install the provided git-hooks

0 commit comments

Comments
 (0)