]> git.proxmox.com Git - mirror_frr.git/blob - lib/link_state.h
Merge pull request #9906 from patrasar/2553196
[mirror_frr.git] / lib / link_state.h
1 /*
2 * Link State Database definition - ted.h
3 *
4 * Author: Olivier Dugeon <olivier.dugeon@orange.com>
5 *
6 * Copyright (C) 2020 Orange http://www.orange.com
7 *
8 * This file is part of Free Range Routing (FRR).
9 *
10 * FRR is free software; you can redistribute it and/or modify it
11 * under the terms of the GNU General Public License as published by the
12 * Free Software Foundation; either version 2, or (at your option) any
13 * later version.
14 *
15 * FRR is distributed in the hope that it will be useful, but
16 * WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License along
21 * with this program; see the file COPYING; if not, write to the Free Software
22 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
23 */
24
25 #ifndef _FRR_LINK_STATE_H_
26 #define _FRR_LINK_STATE_H_
27
28 #include "typesafe.h"
29
30 #ifdef __cplusplus
31 extern "C" {
32 #endif
33
34 /**
35 * This file defines the model used to implement a Link State Database
36 * suitable to be used by various protocol like RSVP-TE, BGP-LS, PCEP ...
37 * This database is normally fulfill by the link state routing protocol,
38 * commonly OSPF or ISIS, carrying Traffic Engineering information within
39 * Link State Attributes. See, RFC3630.(OSPF-TE) and RFC5305 (ISIS-TE).
40 *
41 * At least, 3 types of Link State structure are defined:
42 * - Link State Node that groups all information related to a node
43 * - Link State Attributes that groups all information related to a link
44 * - Link State Prefix that groups all information related to a prefix
45 *
46 * These 3 types of structures are those handled by BGP-LS (see RFC7752).
47 *
48 * Each structure, in addition to the specific parameters, embed the node
49 * identifier which advertises the Link State and a bit mask as flags to
50 * indicates which parameters are valid i.e. for which the value corresponds
51 * to a Link State information convey by the routing protocol.
52 * Node identifier is composed of the route id as IPv4 address plus the area
53 * id for OSPF and the ISO System id plus the IS-IS level for IS-IS.
54 */
55
56 /* external reference */
57 struct zapi_opaque_reg_info;
58 struct zclient;
59
60 /* Link State Common definitions */
61 #define MAX_NAME_LENGTH 256
62 #define ISO_SYS_ID_LEN 6
63
64 /* Type of Node */
65 enum ls_node_type {
66 NONE = 0, /* Unknown */
67 STANDARD, /* a P or PE node */
68 ABR, /* an Array Border Node */
69 ASBR, /* an Autonomous System Border Node */
70 RMT_ASBR, /* Remote ASBR */
71 PSEUDO /* a Pseudo Node */
72 };
73
74 /* Origin of the Link State information */
75 enum ls_origin { UNKNOWN = 0, ISIS_L1, ISIS_L2, OSPFv2, DIRECT, STATIC };
76
77 /**
78 * Link State Node Identifier as:
79 * - IPv4 address + Area ID for OSPF
80 * - ISO System ID + ISIS Level for ISIS
81 */
82 struct ls_node_id {
83 enum ls_origin origin; /* Origin of the LS information */
84 union {
85 struct {
86 struct in_addr addr; /* OSPF Router IS */
87 struct in_addr area_id; /* OSPF Area ID */
88 } ip;
89 struct {
90 uint8_t sys_id[ISO_SYS_ID_LEN]; /* ISIS System ID */
91 uint8_t level; /* ISIS Level */
92 uint8_t padding;
93 } iso;
94 } id __attribute__((aligned(8)));
95 };
96
97 /**
98 * Check if two Link State Node IDs are equal. Note that this routine has the
99 * same return value sense as '==' (which is different from a comparison).
100 *
101 * @param i1 First Link State Node Identifier
102 * @param i2 Second Link State Node Identifier
103 * @return 1 if equal, 0 otherwise
104 */
105 extern int ls_node_id_same(struct ls_node_id i1, struct ls_node_id i2);
106
107 /* Link State flags to indicate which Node parameters are valid */
108 #define LS_NODE_UNSET 0x0000
109 #define LS_NODE_NAME 0x0001
110 #define LS_NODE_ROUTER_ID 0x0002
111 #define LS_NODE_ROUTER_ID6 0x0004
112 #define LS_NODE_FLAG 0x0008
113 #define LS_NODE_TYPE 0x0010
114 #define LS_NODE_AS_NUMBER 0x0020
115 #define LS_NODE_SR 0x0040
116 #define LS_NODE_SRLB 0x0080
117 #define LS_NODE_MSD 0x0100
118
119 /* Link State Node structure */
120 struct ls_node {
121 uint16_t flags; /* Flag for parameters validity */
122 struct ls_node_id adv; /* Adv. Router of this Link State */
123 char name[MAX_NAME_LENGTH]; /* Name of the Node (IS-IS only) */
124 struct in_addr router_id; /* IPv4 Router ID */
125 struct in6_addr router6_id; /* IPv6 Router ID */
126 uint8_t node_flag; /* IS-IS or OSPF Node flag */
127 enum ls_node_type type; /* Type of Node */
128 uint32_t as_number; /* Local or neighbor AS number */
129 struct ls_srgb { /* Segment Routing Global Block */
130 uint32_t lower_bound; /* MPLS label lower bound */
131 uint32_t range_size; /* MPLS label range size */
132 uint8_t flag; /* IS-IS SRGB flags */
133 } srgb;
134 struct ls_srlb { /* Segment Routing Local Block */
135 uint32_t lower_bound; /* MPLS label lower bound */
136 uint32_t range_size; /* MPLS label range size */
137 } srlb;
138 uint8_t algo[2]; /* Segment Routing Algorithms */
139 uint8_t msd; /* Maximum Stack Depth */
140 };
141
142 /* Link State flags to indicate which Attribute parameters are valid */
143 #define LS_ATTR_UNSET 0x00000000
144 #define LS_ATTR_NAME 0x00000001
145 #define LS_ATTR_METRIC 0x00000002
146 #define LS_ATTR_TE_METRIC 0x00000004
147 #define LS_ATTR_ADM_GRP 0x00000008
148 #define LS_ATTR_LOCAL_ADDR 0x00000010
149 #define LS_ATTR_NEIGH_ADDR 0x00000020
150 #define LS_ATTR_LOCAL_ADDR6 0x00000040
151 #define LS_ATTR_NEIGH_ADDR6 0x00000080
152 #define LS_ATTR_LOCAL_ID 0x00000100
153 #define LS_ATTR_NEIGH_ID 0x00000200
154 #define LS_ATTR_MAX_BW 0x00000400
155 #define LS_ATTR_MAX_RSV_BW 0x00000800
156 #define LS_ATTR_UNRSV_BW 0x00001000
157 #define LS_ATTR_REMOTE_AS 0x00002000
158 #define LS_ATTR_REMOTE_ADDR 0x00004000
159 #define LS_ATTR_REMOTE_ADDR6 0x00008000
160 #define LS_ATTR_DELAY 0x00010000
161 #define LS_ATTR_MIN_MAX_DELAY 0x00020000
162 #define LS_ATTR_JITTER 0x00040000
163 #define LS_ATTR_PACKET_LOSS 0x00080000
164 #define LS_ATTR_AVA_BW 0x00100000
165 #define LS_ATTR_RSV_BW 0x00200000
166 #define LS_ATTR_USE_BW 0x00400000
167 #define LS_ATTR_ADJ_SID 0x01000000
168 #define LS_ATTR_BCK_ADJ_SID 0x02000000
169 #define LS_ATTR_SRLG 0x10000000
170
171 /* Link State Attributes */
172 struct ls_attributes {
173 uint32_t flags; /* Flag for parameters validity */
174 struct ls_node_id adv; /* Adv. Router of this Link State */
175 char name[MAX_NAME_LENGTH]; /* Name of the Edge. Could be null */
176 uint32_t metric; /* IGP standard metric */
177 struct ls_standard { /* Standard TE metrics */
178 uint32_t te_metric; /* Traffic Engineering metric */
179 uint32_t admin_group; /* Administrative Group */
180 struct in_addr local; /* Local IPv4 address */
181 struct in_addr remote; /* Remote IPv4 address */
182 struct in6_addr local6; /* Local IPv6 address */
183 struct in6_addr remote6; /* Remote IPv6 address */
184 uint32_t local_id; /* Local Identifier */
185 uint32_t remote_id; /* Remote Identifier */
186 float max_bw; /* Maximum Link Bandwidth */
187 float max_rsv_bw; /* Maximum Reservable BW */
188 float unrsv_bw[8]; /* Unreserved BW per CT (8) */
189 uint32_t remote_as; /* Remote AS number */
190 struct in_addr remote_addr; /* Remote IPv4 address */
191 struct in6_addr remote_addr6; /* Remote IPv6 address */
192 } standard;
193 struct ls_extended { /* Extended TE Metrics */
194 uint32_t delay; /* Unidirectional average delay */
195 uint32_t min_delay; /* Unidirectional minimum delay */
196 uint32_t max_delay; /* Unidirectional maximum delay */
197 uint32_t jitter; /* Unidirectional delay variation */
198 uint32_t pkt_loss; /* Unidirectional packet loss */
199 float ava_bw; /* Available Bandwidth */
200 float rsv_bw; /* Reserved Bandwidth */
201 float used_bw; /* Utilized Bandwidth */
202 } extended;
203 struct ls_adjacency { /* (LAN)-Adjacency SID for OSPF */
204 uint32_t sid; /* SID as MPLS label or index */
205 uint8_t flags; /* Flags */
206 uint8_t weight; /* Administrative weight */
207 union {
208 struct in_addr addr; /* Neighbor @IP for OSPF */
209 uint8_t sysid[ISO_SYS_ID_LEN]; /* or Sys-ID for ISIS */
210 } neighbor;
211 } adj_sid[2]; /* Primary & Backup (LAN)-Adj. SID */
212 uint32_t *srlgs; /* List of Shared Risk Link Group */
213 uint8_t srlg_len; /* number of SRLG in the list */
214 };
215
216 /* Link State flags to indicate which Prefix parameters are valid */
217 #define LS_PREF_UNSET 0x00
218 #define LS_PREF_IGP_FLAG 0x01
219 #define LS_PREF_ROUTE_TAG 0x02
220 #define LS_PREF_EXTENDED_TAG 0x04
221 #define LS_PREF_METRIC 0x08
222 #define LS_PREF_SR 0x10
223
224 /* Link State Prefix */
225 struct ls_prefix {
226 uint8_t flags; /* Flag for parameters validity */
227 struct ls_node_id adv; /* Adv. Router of this Link State */
228 struct prefix pref; /* IPv4 or IPv6 prefix */
229 uint8_t igp_flag; /* IGP Flags associated to the prefix */
230 uint32_t route_tag; /* IGP Route Tag */
231 uint64_t extended_tag; /* IGP Extended Route Tag */
232 uint32_t metric; /* Route metric for this prefix */
233 struct ls_sid {
234 uint32_t sid; /* Segment Routing ID */
235 uint8_t sid_flag; /* Segment Routing Flags */
236 uint8_t algo; /* Algorithm for Segment Routing */
237 } sr;
238 };
239
240 /**
241 * Create a new Link State Node. Structure is dynamically allocated.
242 *
243 * @param adv Mandatory Link State Node ID i.e. advertise router information
244 * @param rid Router ID as IPv4 address
245 * @param rid6 Router ID as IPv6 address
246 *
247 * @return New Link State Node
248 */
249 extern struct ls_node *ls_node_new(struct ls_node_id adv, struct in_addr rid,
250 struct in6_addr rid6);
251
252 /**
253 * Remove Link State Node. Data structure is freed.
254 *
255 * @param node Pointer to a valid Link State Node structure
256 */
257 extern void ls_node_del(struct ls_node *node);
258
259 /**
260 * Check if two Link State Nodes are equal. Note that this routine has the same
261 * return value sense as '==' (which is different from a comparison).
262 *
263 * @param n1 First Link State Node to be compare
264 * @param n2 Second Link State Node to be compare
265 *
266 * @return 1 if equal, 0 otherwise
267 */
268 extern int ls_node_same(struct ls_node *n1, struct ls_node *n2);
269
270 /**
271 * Create a new Link State Attributes. Structure is dynamically allocated.
272 * At least one of parameters MUST be valid and not equal to 0.
273 *
274 * @param adv Mandatory Link State Node ID i.e. advertise router ID
275 * @param local Local IPv4 address
276 * @param local6 Local Ipv6 address
277 * @param local_id Local Identifier
278 *
279 * @return New Link State Attributes
280 */
281 extern struct ls_attributes *ls_attributes_new(struct ls_node_id adv,
282 struct in_addr local,
283 struct in6_addr local6,
284 uint32_t local_id);
285
286 /**
287 * Remove SRLGs from Link State Attributes if defined.
288 *
289 * @param attr Pointer to a valid Link State Attribute structure
290 */
291 extern void ls_attributes_srlg_del(struct ls_attributes *attr);
292
293 /**
294 * Remove Link State Attributes. Data structure is freed.
295 *
296 * @param attr Pointer to a valid Link State Attribute structure
297 */
298 extern void ls_attributes_del(struct ls_attributes *attr);
299
300 /**
301 * Check if two Link State Attributes are equal. Note that this routine has the
302 * same return value sense as '==' (which is different from a comparison).
303 *
304 * @param a1 First Link State Attributes to be compare
305 * @param a2 Second Link State Attributes to be compare
306 *
307 * @return 1 if equal, 0 otherwise
308 */
309 extern int ls_attributes_same(struct ls_attributes *a1,
310 struct ls_attributes *a2);
311
312 /**
313 * Create a new Link State Prefix. Structure is dynamically allocated.
314 *
315 * @param adv Mandatory Link State Node ID i.e. advertise router ID
316 * @param p Mandatory Prefix
317 *
318 * @return New Link State Prefix
319 */
320 extern struct ls_prefix *ls_prefix_new(struct ls_node_id adv, struct prefix p);
321
322 /**
323 * Remove Link State Prefix. Data Structure is freed.
324 *
325 * @param pref Pointer to a valid Link State Attribute Prefix.
326 */
327 extern void ls_prefix_del(struct ls_prefix *pref);
328
329 /**
330 * Check if two Link State Prefix are equal. Note that this routine has the
331 * same return value sense as '==' (which is different from a comparison).
332 *
333 * @param p1 First Link State Prefix to be compare
334 * @param p2 Second Link State Prefix to be compare
335 *
336 * @return 1 if equal, 0 otherwise
337 */
338 extern int ls_prefix_same(struct ls_prefix *p1, struct ls_prefix *p2);
339
340 /**
341 * In addition a Graph model is defined as an overlay on top of link state
342 * database in order to ease Path Computation algorithm implementation.
343 * Denoted G(V, E), a graph is composed by a list of Vertices (V) which
344 * represents the network Node and a list of Edges (E) which represents node
345 * Link. An additional list of prefixes (P) is also added.
346 * A prefix (P) is also attached to the Vertex (V) which advertise it.
347 *
348 * Vertex (V) contains the list of outgoing Edges (E) that connect this Vertex
349 * with its direct neighbors and the list of incoming Edges (E) that connect
350 * the direct neighbors to this Vertex. Indeed, the Edge (E) is unidirectional,
351 * thus, it is necessary to add 2 Edges to model a bidirectional relation
352 * between 2 Vertices.
353 *
354 * Edge (E) contains the source and destination Vertex that this Edge
355 * is connecting.
356 *
357 * A unique Key is used to identify both Vertices and Edges within the Graph.
358 * An easy way to build this key is to used the IP address: i.e. loopback
359 * address for Vertices and link IP address for Edges.
360 *
361 * -------------- --------------------------- --------------
362 * | Connected |---->| Connected Edge Va to Vb |--->| Connected |
363 * --->| Vertex | --------------------------- | Vertex |---->
364 * | | | |
365 * | - Key (Va) | | - Key (Vb) |
366 * <---| - Vertex | --------------------------- | - Vertex |<----
367 * | |<----| Connected Edge Vb to Va |<---| |
368 * -------------- --------------------------- --------------
369 *
370 */
371
372 enum ls_status { UNSET = 0, NEW, UPDATE, DELETE, SYNC, ORPHAN };
373 enum ls_type { GENERIC = 0, VERTEX, EDGE, SUBNET };
374
375 /* Link State Vertex structure */
376 PREDECL_RBTREE_UNIQ(vertices);
377 struct ls_vertex {
378 enum ls_type type; /* Link State Type */
379 enum ls_status status; /* Status of the Vertex in the TED */
380 struct vertices_item entry; /* Entry in RB Tree */
381 uint64_t key; /* Unique Key identifier */
382 struct ls_node *node; /* Link State Node */
383 struct list *incoming_edges; /* List of incoming Link State links */
384 struct list *outgoing_edges; /* List of outgoing Link State links */
385 struct list *prefixes; /* List of advertised prefix */
386 };
387
388 /* Link State Edge structure */
389 PREDECL_RBTREE_UNIQ(edges);
390 struct ls_edge {
391 enum ls_type type; /* Link State Type */
392 enum ls_status status; /* Status of the Edge in the TED */
393 struct edges_item entry; /* Entry in RB tree */
394 uint64_t key; /* Unique Key identifier */
395 struct ls_attributes *attributes; /* Link State attributes */
396 struct ls_vertex *source; /* Pointer to the source Vertex */
397 struct ls_vertex *destination; /* Pointer to the destination Vertex */
398 };
399
400 /* Link State Subnet structure */
401 PREDECL_RBTREE_UNIQ(subnets);
402 struct ls_subnet {
403 enum ls_type type; /* Link State Type */
404 enum ls_status status; /* Status of the Subnet in the TED */
405 struct subnets_item entry; /* Entry in RB tree */
406 struct prefix key; /* Unique Key identifier */
407 struct ls_prefix *ls_pref; /* Link State Prefix */
408 struct ls_vertex *vertex; /* Back pointer to the Vertex owner */
409 };
410
411 /* Declaration of Vertices, Edges and Prefixes RB Trees */
412 macro_inline int vertex_cmp(const struct ls_vertex *node1,
413 const struct ls_vertex *node2)
414 {
415 return (node1->key - node2->key);
416 }
417 DECLARE_RBTREE_UNIQ(vertices, struct ls_vertex, entry, vertex_cmp);
418
419 macro_inline int edge_cmp(const struct ls_edge *edge1,
420 const struct ls_edge *edge2)
421 {
422 return (edge1->key - edge2->key);
423 }
424 DECLARE_RBTREE_UNIQ(edges, struct ls_edge, entry, edge_cmp);
425
426 macro_inline int subnet_cmp(const struct ls_subnet *a,
427 const struct ls_subnet *b)
428 {
429 return prefix_cmp(&a->key, &b->key);
430 }
431 DECLARE_RBTREE_UNIQ(subnets, struct ls_subnet, entry, subnet_cmp);
432
433 /* Link State TED Structure */
434 struct ls_ted {
435 uint32_t key; /* Unique identifier */
436 char name[MAX_NAME_LENGTH]; /* Name of this graph. Could be null */
437 uint32_t as_number; /* AS number of the modeled network */
438 struct ls_vertex *self; /* Vertex of the FRR instance */
439 struct vertices_head vertices; /* List of Vertices */
440 struct edges_head edges; /* List of Edges */
441 struct subnets_head subnets; /* List of Subnets */
442 };
443
444 /* Generic Link State Element */
445 struct ls_element {
446 enum ls_type type; /* Link State Element Type */
447 enum ls_status status; /* Link State Status in the TED */
448 void *data; /* Link State payload */
449 };
450
451 /**
452 * Add new vertex to the Link State DB. Vertex is created from the Link State
453 * Node. Vertex data structure is dynamically allocated.
454 *
455 * @param ted Traffic Engineering Database structure
456 * @param node Link State Node
457 *
458 * @return New Vertex or NULL in case of error
459 */
460 extern struct ls_vertex *ls_vertex_add(struct ls_ted *ted,
461 struct ls_node *node);
462
463 /**
464 * Delete Link State Vertex. This function clean internal Vertex lists (incoming
465 * and outgoing Link State Edge and Link State Subnet). Vertex Data structure
466 * is freed but not the Link State Node. Link State DB is not modified if Vertex
467 * is NULL or not found in the Data Base. Note that referenced to Link State
468 * Edges & SubNets are not removed as they could be connected to other Vertices.
469 *
470 * @param ted Traffic Engineering Database structure
471 * @param vertex Link State Vertex to be removed
472 */
473 extern void ls_vertex_del(struct ls_ted *ted, struct ls_vertex *vertex);
474
475 /**
476 * Delete Link State Vertex as ls_vertex_del() but also removed associated
477 * Link State Node.
478 *
479 * @param ted Traffic Engineering Database structure
480 * @param vertex Link State Vertex to be removed
481 */
482 extern void ls_vertex_del_all(struct ls_ted *ted, struct ls_vertex *vertex);
483
484 /**
485 * Update Vertex with the Link State Node. A new vertex is created if no one
486 * corresponds to the Link State Node.
487 *
488 * @param ted Link State Data Base
489 * @param node Link State Node to be updated
490 *
491 * @return Updated Link State Vertex or Null in case of error
492 */
493 extern struct ls_vertex *ls_vertex_update(struct ls_ted *ted,
494 struct ls_node *node);
495
496 /**
497 * Clean Vertex structure by removing all Edges and Subnets marked as ORPHAN
498 * from this vertex. Link State Update message is sent if zclient is not NULL.
499 *
500 * @param ted Link State Data Base
501 * @param vertex Link State Vertex to be cleaned
502 * @param zclient Reference to Zebra Client
503 */
504 extern void ls_vertex_clean(struct ls_ted *ted, struct ls_vertex *vertex,
505 struct zclient *zclient);
506 /**
507 * Find Vertex in the Link State DB by its unique key.
508 *
509 * @param ted Link State Data Base
510 * @param key Vertex Key different from 0
511 *
512 * @return Vertex if found, NULL otherwise
513 */
514 extern struct ls_vertex *ls_find_vertex_by_key(struct ls_ted *ted,
515 const uint64_t key);
516
517 /**
518 * Find Vertex in the Link State DB by its Link State Node.
519 *
520 * @param ted Link State Data Base
521 * @param nid Link State Node ID
522 *
523 * @return Vertex if found, NULL otherwise
524 */
525 extern struct ls_vertex *ls_find_vertex_by_id(struct ls_ted *ted,
526 struct ls_node_id nid);
527
528 /**
529 * Check if two Vertices are equal. Note that this routine has the same return
530 * value sense as '==' (which is different from a comparison).
531 *
532 * @param v1 First vertex to compare
533 * @param v2 Second vertex to compare
534 *
535 * @return 1 if equal, 0 otherwise
536 */
537 extern int ls_vertex_same(struct ls_vertex *v1, struct ls_vertex *v2);
538
539 /**
540 * Add new Edge to the Link State DB. Edge is created from the Link State
541 * Attributes. Edge data structure is dynamically allocated.
542 *
543 * @param ted Link State Data Base
544 * @param attributes Link State attributes
545 *
546 * @return New Edge or NULL in case of error
547 */
548 extern struct ls_edge *ls_edge_add(struct ls_ted *ted,
549 struct ls_attributes *attributes);
550
551 /**
552 * Update the Link State Attributes information of an existing Edge. If there is
553 * no corresponding Edge in the Link State Data Base, a new Edge is created.
554 *
555 * @param ted Link State Data Base
556 * @param attributes Link State Attributes
557 *
558 * @return Updated Link State Edge, or NULL in case of error
559 */
560 extern struct ls_edge *ls_edge_update(struct ls_ted *ted,
561 struct ls_attributes *attributes);
562
563 /**
564 * Check if two Edges are equal. Note that this routine has the same return
565 * value sense as '==' (which is different from a comparison).
566 *
567 * @param e1 First edge to compare
568 * @param e2 Second edge to compare
569 *
570 * @return 1 if equal, 0 otherwise
571 */
572 extern int ls_edge_same(struct ls_edge *e1, struct ls_edge *e2);
573
574 /**
575 * Remove Edge from the Link State DB. Edge data structure is freed but not the
576 * Link State Attributes data structure. Link State DB is not modified if Edge
577 * is NULL or not found in the Data Base.
578 *
579 * @param ted Link State Data Base
580 * @param edge Edge to be removed
581 */
582 extern void ls_edge_del(struct ls_ted *ted, struct ls_edge *edge);
583
584 /**
585 * Remove Edge and associated Link State Attributes from the Link State DB.
586 * Link State DB is not modified if Edge is NULL or not found.
587 *
588 * @param ted Link State Data Base
589 * @param edge Edge to be removed
590 */
591 extern void ls_edge_del_all(struct ls_ted *ted, struct ls_edge *edge);
592
593 /**
594 * Find Edge in the Link State Data Base by Edge key.
595 *
596 * @param ted Link State Data Base
597 * @param key Edge key
598 *
599 * @return Edge if found, NULL otherwise
600 */
601 extern struct ls_edge *ls_find_edge_by_key(struct ls_ted *ted,
602 const uint64_t key);
603
604 /**
605 * Find Edge in the Link State Data Base by the source (local IPv4 or IPv6
606 * address or local ID) informations of the Link State Attributes
607 *
608 * @param ted Link State Data Base
609 * @param attributes Link State Attributes
610 *
611 * @return Edge if found, NULL otherwise
612 */
613 extern struct ls_edge *
614 ls_find_edge_by_source(struct ls_ted *ted, struct ls_attributes *attributes);
615
616 /**
617 * Find Edge in the Link State Data Base by the destination (remote IPv4 or IPv6
618 * address of remote ID) information of the Link State Attributes
619 *
620 * @param ted Link State Data Base
621 * @param attributes Link State Attributes
622 *
623 * @return Edge if found, NULL otherwise
624 */
625 extern struct ls_edge *
626 ls_find_edge_by_destination(struct ls_ted *ted,
627 struct ls_attributes *attributes);
628
629 /**
630 * Add new Subnet to the Link State DB. Subnet is created from the Link State
631 * prefix. Subnet data structure is dynamically allocated.
632 *
633 * @param ted Link State Data Base
634 * @param pref Link State Prefix
635 *
636 * @return New Subnet
637 */
638 extern struct ls_subnet *ls_subnet_add(struct ls_ted *ted,
639 struct ls_prefix *pref);
640
641 /**
642 * Update the Link State Prefix information of an existing Subnet. If there is
643 * no corresponding Subnet in the Link State Data Base, a new Subnet is created.
644 *
645 * @param ted Link State Data Base
646 * @param pref Link State Prefix
647 *
648 * @return Updated Link State Subnet, or NULL in case of error
649 */
650 extern struct ls_subnet *ls_subnet_update(struct ls_ted *ted,
651 struct ls_prefix *pref);
652
653 /**
654 * Check if two Subnets are equal. Note that this routine has the same return
655 * value sense as '==' (which is different from a comparison).
656 *
657 * @param s1 First subnet to compare
658 * @param s2 Second subnet to compare
659 *
660 * @return 1 if equal, 0 otherwise
661 */
662 extern int ls_subnet_same(struct ls_subnet *s1, struct ls_subnet *s2);
663
664 /**
665 * Remove Subnet from the Link State DB. Subnet data structure is freed but
666 * not the Link State prefix data structure. Link State DB is not modified
667 * if Subnet is NULL or not found in the Data Base.
668 *
669 * @param ted Link State Data Base
670 * @param subnet Subnet to be removed
671 */
672 extern void ls_subnet_del(struct ls_ted *ted, struct ls_subnet *subnet);
673
674 /**
675 * Remove Subnet and the associated Link State Prefix from the Link State DB.
676 * Link State DB is not modified if Subnet is NULL or not found.
677 *
678 * @param ted Link State Data Base
679 * @param subnet Subnet to be removed
680 */
681 extern void ls_subnet_del_all(struct ls_ted *ted, struct ls_subnet *subnet);
682
683 /**
684 * Find Subnet in the Link State Data Base by prefix.
685 *
686 * @param ted Link State Data Base
687 * @param prefix Link State Prefix
688 *
689 * @return Subnet if found, NULL otherwise
690 */
691 extern struct ls_subnet *ls_find_subnet(struct ls_ted *ted,
692 const struct prefix prefix);
693
694 /**
695 * Create a new Link State Data Base.
696 *
697 * @param key Unique key of the data base. Must be different from 0
698 * @param name Name of the data base (may be NULL)
699 * @param asn AS Number for this data base. 0 if unknown
700 *
701 * @return New Link State Database or NULL in case of error
702 */
703 extern struct ls_ted *ls_ted_new(const uint32_t key, const char *name,
704 uint32_t asn);
705
706 /**
707 * Delete existing Link State Data Base. Vertices, Edges, and Subnets are not
708 * removed.
709 *
710 * @param ted Link State Data Base
711 */
712 extern void ls_ted_del(struct ls_ted *ted);
713
714 /**
715 * Delete all Link State Vertices, Edges and SubNets and the Link State DB.
716 *
717 * @param ted Link State Data Base
718 */
719 extern void ls_ted_del_all(struct ls_ted *ted);
720
721 /**
722 * Clean Link State Data Base by removing all Vertices, Edges and SubNets marked
723 * as ORPHAN.
724 *
725 * @param ted Link State Data Base
726 */
727 extern void ls_ted_clean(struct ls_ted *ted);
728
729 /**
730 * Connect Source and Destination Vertices by given Edge. Only non NULL source
731 * and destination vertices are connected.
732 *
733 * @param src Link State Source Vertex
734 * @param dst Link State Destination Vertex
735 * @param edge Link State Edge. Must not be NULL
736 */
737 extern void ls_connect_vertices(struct ls_vertex *src, struct ls_vertex *dst,
738 struct ls_edge *edge);
739
740 /**
741 * Connect Link State Edge to the Link State Vertex which could be a Source or
742 * a Destination Vertex.
743 *
744 * @param vertex Link State Vertex to be connected. Must not be NULL
745 * @param edge Link State Edge connection. Must not be NULL
746 * @param source True for a Source, false for a Destination Vertex
747 */
748 extern void ls_connect(struct ls_vertex *vertex, struct ls_edge *edge,
749 bool source);
750
751 /**
752 * Disconnect Link State Edge from the Link State Vertex which could be a
753 * Source or a Destination Vertex.
754 *
755 * @param vertex Link State Vertex to be connected. Must not be NULL
756 * @param edge Link State Edge connection. Must not be NULL
757 * @param source True for a Source, false for a Destination Vertex
758 */
759 extern void ls_disconnect(struct ls_vertex *vertex, struct ls_edge *edge,
760 bool source);
761
762 /**
763 * Disconnect Link State Edge from both Source and Destination Vertex.
764 *
765 * @param edge Link State Edge to be disconnected
766 */
767 extern void ls_disconnect_edge(struct ls_edge *edge);
768
769
770 /**
771 * The Link State Message is defined to convey Link State parameters from
772 * the routing protocol (OSPF or IS-IS) to other daemons e.g. BGP.
773 *
774 * The structure is composed of:
775 * - Event of the message:
776 * - Sync: Send the whole LS DB following a request
777 * - Add: Send the a new Link State element
778 * - Update: Send an update of an existing Link State element
779 * - Delete: Indicate that the given Link State element is removed
780 * - Type of Link State element: Node, Attribute or Prefix
781 * - Remote node id when known
782 * - Data: Node, Attributes or Prefix
783 *
784 * A Link State Message can carry only one Link State Element (Node, Attributes
785 * of Prefix) at once, and only one Link State Message is sent through ZAPI
786 * Opaque Link State type at once.
787 */
788
789 /* ZAPI Opaque Link State Message Event */
790 #define LS_MSG_EVENT_UNDEF 0
791 #define LS_MSG_EVENT_SYNC 1
792 #define LS_MSG_EVENT_ADD 2
793 #define LS_MSG_EVENT_UPDATE 3
794 #define LS_MSG_EVENT_DELETE 4
795
796 /* ZAPI Opaque Link State Message sub-Type */
797 #define LS_MSG_TYPE_NODE 1
798 #define LS_MSG_TYPE_ATTRIBUTES 2
799 #define LS_MSG_TYPE_PREFIX 3
800
801 /* Link State Message */
802 struct ls_message {
803 uint8_t event; /* Message Event: Sync, Add, Update, Delete */
804 uint8_t type; /* Message Data Type: Node, Attribute, Prefix */
805 struct ls_node_id remote_id; /* Remote Link State Node ID */
806 union {
807 struct ls_node *node; /* Link State Node */
808 struct ls_attributes *attr; /* Link State Attributes */
809 struct ls_prefix *prefix; /* Link State Prefix */
810 } data;
811 };
812
813 /**
814 * Register Link State daemon as a server or client for Zebra OPAQUE API.
815 *
816 * @param zclient Zebra client structure
817 * @param server Register daemon as a server (true) or as a client (false)
818 *
819 * @return 0 if success, -1 otherwise
820 */
821 extern int ls_register(struct zclient *zclient, bool server);
822
823 /**
824 * Unregister Link State daemon as a server or client for Zebra OPAQUE API.
825 *
826 * @param zclient Zebra client structure
827 * @param server Unregister daemon as a server (true) or as a client (false)
828 *
829 * @return 0 if success, -1 otherwise
830 */
831 extern int ls_unregister(struct zclient *zclient, bool server);
832
833 /**
834 * Send Link State SYNC message to request the complete Link State Database.
835 *
836 * @param zclient Zebra client
837 *
838 * @return 0 if success, -1 otherwise
839 */
840 extern int ls_request_sync(struct zclient *zclient);
841
842 /**
843 * Parse Link State Message from stream. Used this function once receiving a
844 * new ZAPI Opaque message of type Link State.
845 *
846 * @param s Stream buffer. Must not be NULL.
847 *
848 * @return New Link State Message or NULL in case of error
849 */
850 extern struct ls_message *ls_parse_msg(struct stream *s);
851
852 /**
853 * Delete existing message. Data structure is freed.
854 *
855 * @param msg Link state message to be deleted
856 */
857 extern void ls_delete_msg(struct ls_message *msg);
858
859 /**
860 * Send Link State Message as new ZAPI Opaque message of type Link State.
861 * If destination is not NULL, message is sent as Unicast otherwise it is
862 * broadcast to all registered daemon.
863 *
864 * @param zclient Zebra Client
865 * @param msg Link State Message to be sent
866 * @param dst Destination daemon for unicast message,
867 * NULL for broadcast message
868 *
869 * @return 0 on success, -1 otherwise
870 */
871 extern int ls_send_msg(struct zclient *zclient, struct ls_message *msg,
872 struct zapi_opaque_reg_info *dst);
873
874 /**
875 * Create a new Link State Message from a Link State Vertex. If Link State
876 * Message is NULL, a new data structure is dynamically allocated.
877 *
878 * @param msg Link State Message to be filled or NULL
879 * @param vertex Link State Vertex. Must not be NULL
880 *
881 * @return New Link State Message msg parameter is NULL or pointer
882 * to the provided Link State Message
883 */
884 extern struct ls_message *ls_vertex2msg(struct ls_message *msg,
885 struct ls_vertex *vertex);
886
887 /**
888 * Create a new Link State Message from a Link State Edge. If Link State
889 * Message is NULL, a new data structure is dynamically allocated.
890 *
891 * @param msg Link State Message to be filled or NULL
892 * @param edge Link State Edge. Must not be NULL
893 *
894 * @return New Link State Message msg parameter is NULL or pointer
895 * to the provided Link State Message
896 */
897 extern struct ls_message *ls_edge2msg(struct ls_message *msg,
898 struct ls_edge *edge);
899
900 /**
901 * Create a new Link State Message from a Link State Subnet. If Link State
902 * Message is NULL, a new data structure is dynamically allocated.
903 *
904 * @param msg Link State Message to be filled or NULL
905 * @param subnet Link State Subnet. Must not be NULL
906 *
907 * @return New Link State Message msg parameter is NULL or pointer
908 * to the provided Link State Message
909 */
910 extern struct ls_message *ls_subnet2msg(struct ls_message *msg,
911 struct ls_subnet *subnet);
912
913 /**
914 * Convert Link State Message into Vertex and update TED accordingly to
915 * the message event: SYNC, ADD, UPDATE or DELETE.
916 *
917 * @param ted Link State Database
918 * @param msg Link State Message
919 * @param delete True to delete the Link State Vertex from the Database,
920 * False otherwise. If true, return value is NULL in case
921 * of deletion.
922 *
923 * @return Vertex if success, NULL otherwise or if Vertex is removed
924 */
925 extern struct ls_vertex *ls_msg2vertex(struct ls_ted *ted,
926 struct ls_message *msg, bool delete);
927
928 /**
929 * Convert Link State Message into Edge and update TED accordingly to
930 * the message event: SYNC, ADD, UPDATE or DELETE.
931 *
932 * @param ted Link State Database
933 * @param msg Link State Message
934 * @param delete True to delete the Link State Edge from the Database,
935 * False otherwise. If true, return value is NULL in case
936 * of deletion.
937 *
938 * @return Edge if success, NULL otherwise or if Edge is removed
939 */
940 extern struct ls_edge *ls_msg2edge(struct ls_ted *ted, struct ls_message *msg,
941 bool delete);
942
943 /**
944 * Convert Link State Message into Subnet and update TED accordingly to
945 * the message event: SYNC, ADD, UPDATE or DELETE.
946 *
947 * @param ted Link State Database
948 * @param msg Link State Message
949 * @param delete True to delete the Link State Subnet from the Database,
950 * False otherwise. If true, return value is NULL in case
951 * of deletion.
952 *
953 * @return Subnet if success, NULL otherwise or if Subnet is removed
954 */
955 extern struct ls_subnet *ls_msg2subnet(struct ls_ted *ted,
956 struct ls_message *msg, bool delete);
957
958 /**
959 * Convert Link State Message into Link State element (Vertex, Edge or Subnet)
960 * and update TED accordingly to the message event: SYNC, ADD, UPDATE or DELETE.
961 *
962 * @param ted Link State Database
963 * @param msg Link State Message
964 * @param delete True to delete the Link State Element from the Database,
965 * False otherwise. If true, return value is NULL in case
966 * of deletion.
967 *
968 * @return Element if success, NULL otherwise or if Element is removed
969 */
970 extern struct ls_element *ls_msg2ted(struct ls_ted *ted, struct ls_message *msg,
971 bool delete);
972
973 /**
974 * Convert stream buffer into Link State element (Vertex, Edge or Subnet) and
975 * update TED accordingly to the message event: SYNC, ADD, UPDATE or DELETE.
976 *
977 * @param ted Link State Database
978 * @param s Stream buffer
979 * @param delete True to delete the Link State Element from the Database,
980 * False otherwise. If true, return value is NULL in case
981 * of deletion.
982 *
983 * @return Element if success, NULL otherwise or if Element is removed
984 */
985 extern struct ls_element *ls_stream2ted(struct ls_ted *ted, struct stream *s,
986 bool delete);
987
988 /**
989 * Send all the content of the Link State Data Base to the given destination.
990 * Link State content is sent is this order: Vertices, Edges, Subnet.
991 * This function must be used when a daemon request a Link State Data Base
992 * Synchronization.
993 *
994 * @param ted Link State Data Base. Must not be NULL
995 * @param zclient Zebra Client. Must not be NULL
996 * @param dst Destination FRR daemon. Must not be NULL
997 *
998 * @return 0 on success, -1 otherwise
999 */
1000 extern int ls_sync_ted(struct ls_ted *ted, struct zclient *zclient,
1001 struct zapi_opaque_reg_info *dst);
1002
1003 struct json_object;
1004 struct vty;
1005 /**
1006 * Show Link State Vertex information. If both vty and json are specified,
1007 * Json format output supersedes standard vty output.
1008 *
1009 * @param vertex Link State Vertex to show. Must not be NULL
1010 * @param vty Pointer to vty output, could be NULL
1011 * @param json Pointer to json output, could be NULL
1012 * @param verbose Set to true for more detail
1013 */
1014 extern void ls_show_vertex(struct ls_vertex *vertex, struct vty *vty,
1015 struct json_object *json, bool verbose);
1016
1017 /**
1018 * Show all Link State Vertices information. If both vty and json are specified,
1019 * Json format output supersedes standard vty output.
1020 *
1021 * @param ted Link State Data Base. Must not be NULL
1022 * @param vty Pointer to vty output, could be NULL
1023 * @param json Pointer to json output, could be NULL
1024 * @param verbose Set to true for more detail
1025 */
1026 extern void ls_show_vertices(struct ls_ted *ted, struct vty *vty,
1027 struct json_object *json, bool verbose);
1028
1029 /**
1030 * Show Link State Edge information. If both vty and json are specified,
1031 * Json format output supersedes standard vty output.
1032 *
1033 * @param edge Link State Edge to show. Must not be NULL
1034 * @param vty Pointer to vty output, could be NULL
1035 * @param json Pointer to json output, could be NULL
1036 * @param verbose Set to true for more detail
1037 */
1038 extern void ls_show_edge(struct ls_edge *edge, struct vty *vty,
1039 struct json_object *json, bool verbose);
1040
1041 /**
1042 * Show all Link State Edges information. If both vty and json are specified,
1043 * Json format output supersedes standard vty output.
1044 *
1045 * @param ted Link State Data Base. Must not be NULL
1046 * @param vty Pointer to vty output, could be NULL
1047 * @param json Pointer to json output, could be NULL
1048 * @param verbose Set to true for more detail
1049 */
1050 extern void ls_show_edges(struct ls_ted *ted, struct vty *vty,
1051 struct json_object *json, bool verbose);
1052
1053 /**
1054 * Show Link State Subnets information. If both vty and json are specified,
1055 * Json format output supersedes standard vty output.
1056 *
1057 * @param subnet Link State Subnet to show. Must not be NULL
1058 * @param vty Pointer to vty output, could be NULL
1059 * @param json Pointer to json output, could be NULL
1060 * @param verbose Set to true for more detail
1061 */
1062 extern void ls_show_subnet(struct ls_subnet *subnet, struct vty *vty,
1063 struct json_object *json, bool verbose);
1064
1065 /**
1066 * Show all Link State Subnet information. If both vty and json are specified,
1067 * Json format output supersedes standard vty output.
1068 *
1069 * @param ted Link State Data Base. Must not be NULL
1070 * @param vty Pointer to vty output, could be NULL
1071 * @param json Pointer to json output, could be NULL
1072 * @param verbose Set to true for more detail
1073 */
1074 extern void ls_show_subnets(struct ls_ted *ted, struct vty *vty,
1075 struct json_object *json, bool verbose);
1076
1077 /**
1078 * Show Link State Data Base information. If both vty and json are specified,
1079 * Json format output supersedes standard vty output.
1080 *
1081 * @param ted Link State Data Base to show. Must not be NULL
1082 * @param vty Pointer to vty output, could be NULL
1083 * @param json Pointer to json output, could be NULL
1084 * @param verbose Set to true for more detail
1085 */
1086 extern void ls_show_ted(struct ls_ted *ted, struct vty *vty,
1087 struct json_object *json, bool verbose);
1088
1089 /**
1090 * Dump all Link State Data Base elements for debugging purposes
1091 *
1092 * @param ted Link State Data Base. Must not be NULL
1093 *
1094 */
1095 extern void ls_dump_ted(struct ls_ted *ted);
1096
1097 #ifdef __cplusplus
1098 }
1099 #endif
1100
1101 #endif /* _FRR_LINK_STATE_H_ */