]> git.proxmox.com Git - mirror_frr.git/blame - doc/developer/path-internals-pcep.rst
Merge pull request #13464 from sri-mohan1/srib-ldpd
[mirror_frr.git] / doc / developer / path-internals-pcep.rst
CommitLineData
efba0985
SM
1PCEP Module Internals
2=====================
3
4Introduction
5------------
6
7The PCEP module for the pathd daemon implements the PCEP protocol described in
8:rfc:`5440` to update the policies and candidate paths.
9
10The protocol encoding/decoding and the basic session management is handled by
11the `pceplib external library 1.2 <https://github.com/volta-networks/pceplib/tree/devel-1.2>`_.
12
13Together with pceplib, this module supports at least partially:
14
15 - :rfc:`5440`
16
17 Most of the protocol defined in the RFC is implemented.
18 All the messages can be parsed, but this was only tested in the context
19 of segment routing. Only a very small subset of metric types can be
20 configured, and there is a known issue with some Cisco routers not
21 following the IANA numbers for metrics.
22
23 - :rfc:`8231`
24
25 Support delegation of candidate path after performing the initial
26 computation request. If the PCE does not respond or cannot compute
27 a path, an empty candidate path is delegated to the PCE.
28 Only tested in the context of segment routing.
29
30 - :rfc:`8408`
31
32 Only used to comunicate the support for segment routing to the PCE.
33
34 - :rfc:`8664`
35
36 All the NAI types are implemented, but only the MPLS NAI are supported.
37 If the PCE provide segments that are not MPLS labels, the PCC will
38 return an error.
39
40Note that pceplib supports more RFCs and drafts, see pceplib
41`README <https://github.com/volta-networks/pceplib/blob/master/README.md>`_
42for more details.
43
44
45Architecture
46------------
47
48Overview
49........
50
51The module is separated into multiple layers:
52
53 - pathd interface
54 - command-line console
55 - controller
56 - PCC
57 - pceplib interface
58
59The pathd interface handles all the interactions with the daemon API.
60
61The command-line console handles all the VTYSH configuration commands.
62
63The controller manages the multiple PCC connections and the interaction between
64them and the daemon interface.
65
66The PCC handles a single connection to a PCE through a pceplib session.
67
68The pceplib interface abstracts the API of the pceplib.
69
70.. figure:: ../figures/pcep_module_threading_overview.svg
71
72
73Threading Model
74---------------
75
76The module requires multiple threads to cooperate:
77
78 - The main thread used by the pathd daemon.
79 - The controller pthread used to isolate the PCC from the main thread.
80 - The possible threads started in the pceplib library.
81
82To ensure thread safety, all the controller and PCC state data structures can
83only be read and modified in the controller thread, and all the global data
84structures can only be read and modified in the main thread. Most of the
85interactions between these threads are done through FRR timers and events.
86
87The controller is the bridge between the two threads, all the functions that
88**MUST** be called from the main thread start with the prefix `pcep_ctrl_` and
89all the functions that **MUST** be called from the controller thread start
90with the prefix `pcep_thread_`. When an asynchronous action must be taken in
91a different thread, an FRR event is sent to the thread. If some synchronous
92operation is needed, the calling thread will block and run a callback in the
93other thread, there the result is **COPIED** and returned to the calling thread.
94
95No function other than the controller functions defined for it should be called
96from the main thread. The only exception being some utility functions from
97`path_pcep_lib.[hc]`.
98
99All the calls to pathd API functions **MUST** be performed in the main thread,
100for that, the controller sends FRR events handled in function
101`path_pcep.c:pcep_main_event_handler`.
102
103For the same reason, the console client only runs in the main thread. It can
104freely use the global variable, but **MUST** use controller's `pcep_ctrl_`
105functions to interact with the PCCs.
106
107
108Source Code
109-----------
110
111Generic Data Structures
112.......................
113
114The data structures are defined in multiple places, and where they are defined
115dictates where they can be used.
116
117The data structures defined in `path_pcep.h` can be used anywhere in the module.
118
119Internally, throughout the module, the `struct path` data structure is used
120to describe PCEP messages. It is a simplified flattened structure that can
121represent multiple complex PCEP message types. The conversion from this
122structure to the PCEP data structures used by pceplib is done in the pceplib
123interface layer.
124
125The data structures defined in `path_pcep_controller.h` should only be used
126in `path_pcep_controller.c`. Even if a structure pointer is passed as a parameter
127to functions defined in `path_pcep_pcc.h`, these should consider it as an opaque
128data structure only used to call back controller functions.
129
130The same applies to the structures defined in `path_pcep_pcc.h`, even if the
131controller owns a reference to this data structure, it should never read or
132modify it directly, it should be considered an opaque structure.
133
134The global data structure can be accessed from the pathd interface layer
135`path_pcep.c` and the command line client code `path_pcep_cli.c`.
136
137
138Interface With Pathd
139....................
140
141All the functions calling or called by the pathd daemon are implemented in
142`path_pcep.c`. These functions **MUST** run in the main FRR thread, and
143all the interactions with the controller and the PCCs **MUST** pass through
144the controller's `pcep_ctrl_` prefixed functions.
145
146To handle asynchronous events from the PCCs, a callback is passed to
147`pcep_ctrl_initialize` that is called in the FRR main thread context.
148
149
150Command Line Client
151...................
152
153All the command line configuration commands (VTYSH) are implemented in
154`path_pcep_cli.c`. All the functions there run in the main FRR thread and
155can freely access the global variables. All the interaction with the
156controller's and the PCCs **MUST** pass through the controller `pcep_ctrl_`
157prefixed functions.
158
159
160Debugging Helpers
161.................
162
163All the functions formating data structures for debugging and logging purposes
164are implemented in `path_pcep_debug.[hc]`.
165
166
167Interface with pceplib
168......................
169
170All the functions calling the pceplib external library are defined in
171`path_pcep_lib.[hc]`. Some functions are called from the main FRR thread, like
172`pcep_lib_initialize`, `pcep_lib_finalize`; some can be called from either
173thread, like `pcep_lib_free_counters`; some function must be called from the
174controller thread, like `pcep_lib_connect`. This will probably be formalized
175later on with function prefix like done in the controller.
176
177
178Controller
179..........
180
181The controller is defined and implemented in `path_pcep_controller.[hc]`.
182Part of the controller code runs in FRR main thread and part runs in its own
183FRR pthread started to isolate the main thread from the PCCs' event loop.
184To communicate between the threads it uses FRR events, timers and
8c1186d3 185`event_execute` calls.
efba0985
SM
186
187
188PCC
189...
190
191Each PCC instance owns its state and runs in the controller thread. They are
192defined and implemented in `path_pcep_pcc.[hc]`. All the interactions with
193the daemon must pass through some controller's `pcep_thread_` prefixed function.