1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * This is an implementation of RFC3630, RFC5392 & RFC6827
4 * Copyright (C) 2001 KDD R&D Laboratories, Inc.
5 * http://www.kddlabs.co.jp/
7 * Copyright (C) 2012 Orange Labs
8 * http://www.orange.com
11 /* Add support of RFC7471 */
12 /* Add support of RFC5392 */
13 /* Add support of RFC6827 (partial) */
15 #ifndef _ZEBRA_OSPF_MPLS_TE_H
16 #define _ZEBRA_OSPF_MPLS_TE_H
19 * Opaque LSA's link state ID for Traffic Engineering is
20 * structured as follows.
23 * +--------+--------+--------+--------+
24 * | 1 | MBZ |........|........|
25 * +--------+--------+--------+--------+
26 * |<-Type->|<Resv'd>|<-- Instance --->|
29 * Type: IANA has assigned '1' for Traffic Engineering.
30 * MBZ: Reserved, must be set to zero.
31 * Instance: User may select an arbitrary 16-bit value.
35 #define MAX_LEGAL_TE_INSTANCE_NUM (0xffff)
36 #define LEGAL_TE_INSTANCE_RANGE(i) (0 <= (i) && (i) <= 0xffff)
40 * +--------+--------+--------+--------+ ---
41 * | LS age |Options | 10 | A
42 * +--------+--------+--------+--------+ |
43 * | 1 | 0 | Instance | |
44 * +--------+--------+--------+--------+ |
45 * | Advertising router | | Standard (Opaque) LSA header;
46 * +--------+--------+--------+--------+ | Only type-10 is used.
47 * | LS sequence number | |
48 * +--------+--------+--------+--------+ |
49 * | LS checksum | Length | V
50 * +--------+--------+--------+--------+ ---
52 * +--------+--------+--------+--------+ | TLV part for TE; Values might be
53 * | Values ... | V structured as a set of sub-TLVs.
54 * +--------+--------+--------+--------+ ---
57 /* Following define the type of TE link regarding the various RFC */
61 #define PSEUDO_TE 0x08
64 #define IS_STD_TE(x) (x & STD_TE)
65 #define IS_PSEUDO_TE(x) (x & PSEUDO_TE)
66 #define IS_INTER_AS(x) (x & INTER_AS)
67 #define IS_EMULATED(x) (x & EMULATED)
69 /* Flags to manage TE Link LSA */
70 #define LPFLG_LSA_INACTIVE 0x00
71 #define LPFLG_LSA_ACTIVE 0x01
72 #define LPFLG_LSA_ENGAGED 0x02
73 #define LPFLG_LOOKUP_DONE 0x04
74 #define LPFLG_LSA_FORCED_REFRESH 0x08
75 #define LPFLG_LSA_FLOOD_AS 0x10
77 #define IS_FLOOD_AS(x) (x & LPFLG_LSA_FLOOD_AS)
79 /* Macro to log debug message */
80 #define ote_debug(...) \
82 if (IS_DEBUG_OSPF_TE) \
83 zlog_debug(__VA_ARGS__); \
87 * Following section defines TLV body parts.
90 /* Router Address TLV */ /* Mandatory */
91 #define TE_TLV_ROUTER_ADDR 1
92 struct te_tlv_router_addr
{
93 struct tlv_header header
; /* Value length is 4 octets. */
100 struct tlv_header header
;
101 /* A set of link-sub-TLVs will follow. */
104 /* Default TE TLV size */
105 #define TE_LINK_SUBTLV_DEF_SIZE 4
107 /* Link Type Sub-TLV */ /* Mandatory */
108 #define TE_LINK_SUBTLV_LINK_TYPE 1
109 #define TE_LINK_SUBTLV_TYPE_SIZE 1
110 struct te_link_subtlv_link_type
{
111 struct tlv_header header
; /* Value length is 1 octet. */
113 #define LINK_TYPE_SUBTLV_VALUE_PTP 1
114 #define LINK_TYPE_SUBTLV_VALUE_MA 2
120 /* Link Sub-TLV: Link ID */ /* Mandatory */
121 #define TE_LINK_SUBTLV_LINK_ID 2
122 struct te_link_subtlv_link_id
{
123 struct tlv_header header
; /* Value length is 4 octets. */
124 struct in_addr value
; /* Same as router-lsa's link-id. */
127 /* Link Sub-TLV: Local Interface IP Address */ /* Optional */
128 #define TE_LINK_SUBTLV_LCLIF_IPADDR 3
129 struct te_link_subtlv_lclif_ipaddr
{
130 struct tlv_header header
; /* Value length is 4 x N octets. */
131 struct in_addr value
[1]; /* Local IP address(es). */
134 /* Link Sub-TLV: Remote Interface IP Address */ /* Optional */
135 #define TE_LINK_SUBTLV_RMTIF_IPADDR 4
136 struct te_link_subtlv_rmtif_ipaddr
{
137 struct tlv_header header
; /* Value length is 4 x N octets. */
138 struct in_addr value
[1]; /* Neighbor's IP address(es). */
141 /* Link Sub-TLV: Traffic Engineering Metric */ /* Optional */
142 #define TE_LINK_SUBTLV_TE_METRIC 5
143 struct te_link_subtlv_te_metric
{
144 struct tlv_header header
; /* Value length is 4 octets. */
145 uint32_t value
; /* Link metric for TE purpose. */
148 /* Link Sub-TLV: Maximum Bandwidth */ /* Optional */
149 #define TE_LINK_SUBTLV_MAX_BW 6
150 struct te_link_subtlv_max_bw
{
151 struct tlv_header header
; /* Value length is 4 octets. */
152 float value
; /* bytes/sec */
155 /* Link Sub-TLV: Maximum Reservable Bandwidth */ /* Optional */
156 #define TE_LINK_SUBTLV_MAX_RSV_BW 7
157 struct te_link_subtlv_max_rsv_bw
{
158 struct tlv_header header
; /* Value length is 4 octets. */
159 float value
; /* bytes/sec */
162 /* Link Sub-TLV: Unreserved Bandwidth */ /* Optional */
163 #define TE_LINK_SUBTLV_UNRSV_BW 8
164 #define TE_LINK_SUBTLV_UNRSV_SIZE 32
165 struct te_link_subtlv_unrsv_bw
{
166 struct tlv_header header
; /* Value length is 32 octets. */
167 float value
[MAX_CLASS_TYPE
]; /* One for each priority level. */
170 /* Link Sub-TLV: Resource Class/Color */ /* Optional */
171 #define TE_LINK_SUBTLV_RSC_CLSCLR 9
172 struct te_link_subtlv_rsc_clsclr
{
173 struct tlv_header header
; /* Value length is 4 octets. */
174 uint32_t value
; /* Admin. group membership. */
178 /* Local and Remote TE Router ID */
179 #define TE_LINK_SUBTLV_LRRID 10
180 #define TE_LINK_SUBTLV_LRRID_SIZE 8
181 struct te_link_subtlv_lrrid
{
182 struct tlv_header header
; /* Value length is 8 octets. */
183 struct in_addr local
; /* Local TE Router Identifier */
184 struct in_addr remote
; /* Remote TE Router Identifier */
187 /* RFC4203: Link Local/Remote Identifiers */
188 #define TE_LINK_SUBTLV_LLRI 11
189 #define TE_LINK_SUBTLV_LLRI_SIZE 8
190 struct te_link_subtlv_llri
{
191 struct tlv_header header
; /* Value length is 8 octets. */
192 uint32_t local
; /* Link Local Identifier */
193 uint32_t remote
; /* Link Remote Identifier */
196 /* Inter-RA Export Upward sub-TLV (12) and Inter-RA Export Downward sub-TLV (13)
197 * (RFC6827bis) are not yet supported */
198 /* SUBTLV 14-16 (RFC4203) are not yet supported */
199 /* Bandwidth Constraints sub-TLV (17) (RFC4124) is not yet supported */
200 /* SUBLV 18-20 are for OSPFv3 TE (RFC5329). see ospf6d */
203 /* Remote AS Number sub-TLV */
204 #define TE_LINK_SUBTLV_RAS 21
205 struct te_link_subtlv_ras
{
206 struct tlv_header header
; /* Value length is 4 octets. */
207 uint32_t value
; /* Remote AS number */
210 /* IPv4 Remote ASBR ID Sub-TLV */
211 #define TE_LINK_SUBTLV_RIP 22
212 struct te_link_subtlv_rip
{
213 struct tlv_header header
; /* Value length is 4 octets. */
214 struct in_addr value
; /* Remote ASBR IP address */
217 /* SUBTLV 24 is IPv6 Remote ASBR ID (RFC5392). see ospf6d */
219 /* SUBTLV 23 (RFC5330) and 25 (RFC6001) are not yet supported */
221 /* SUBTLV 26 (RFC7308) is not yet supported */
224 /* Link Sub-TLV: Average Link Delay */ /* Optional */
225 #define TE_LINK_SUBTLV_AV_DELAY 27
226 struct te_link_subtlv_av_delay
{
227 struct tlv_header header
; /* Value length is 4 bytes. */
229 * delay in micro-seconds only 24 bits => 0 ... 16777215
230 * with Anomalous Bit as Upper most bit
235 /* Link Sub-TLV: Low/High Link Delay */
236 #define TE_LINK_SUBTLV_MM_DELAY 28
237 #define TE_LINK_SUBTLV_MM_DELAY_SIZE 8
238 struct te_link_subtlv_mm_delay
{
239 struct tlv_header header
; /* Value length is 8 bytes. */
241 * low delay in micro-seconds only 24 bits => 0 ... 16777215
242 * with Anomalous Bit (A) as Upper most bit
245 /* high delay in micro-seconds only 24 bits => 0 ... 16777215 */
249 /* Link Sub-TLV: Link Delay Variation i.e. Jitter */
250 #define TE_LINK_SUBTLV_DELAY_VAR 29
251 struct te_link_subtlv_delay_var
{
252 struct tlv_header header
; /* Value length is 4 bytes. */
253 /* interval in micro-seconds only 24 bits => 0 ... 16777215 */
257 /* Link Sub-TLV: Routine Unidirectional Link Packet Loss */
258 #define TE_LINK_SUBTLV_PKT_LOSS 30
259 struct te_link_subtlv_pkt_loss
{
260 struct tlv_header header
; /* Value length is 4 bytes. */
262 * in percentage of total traffic only 24 bits (2^24 - 2)
263 * with Anomalous Bit as Upper most bit
268 /* Link Sub-TLV: Unidirectional Residual Bandwidth */ /* Optional */
269 #define TE_LINK_SUBTLV_RES_BW 31
270 struct te_link_subtlv_res_bw
{
271 struct tlv_header header
; /* Value length is 4 bytes. */
272 /* bandwidth in IEEE floating point format with units in bytes/second */
276 /* Link Sub-TLV: Unidirectional Available Bandwidth */ /* Optional */
277 #define TE_LINK_SUBTLV_AVA_BW 32
278 struct te_link_subtlv_ava_bw
{
279 struct tlv_header header
; /* Value length is 4 octets. */
280 /* bandwidth in IEEE floating point format with units in bytes/second */
284 /* Link Sub-TLV: Unidirectional Utilized Bandwidth */ /* Optional */
285 #define TE_LINK_SUBTLV_USE_BW 33
286 struct te_link_subtlv_use_bw
{
287 struct tlv_header header
; /* Value length is 4 octets. */
288 /* bandwidth in IEEE floating point format with units in bytes/second */
292 #define TE_LINK_SUBTLV_MAX 34 /* Last SUBTLV + 1 */
294 /* Here are "non-official" architectural constants. */
295 #define MPLS_TE_MINIMUM_BANDWIDTH 1.0 /* Reasonable? *//* XXX */
297 /* Mode for Inter-AS Opaque-LSA */
298 enum inter_as_mode
{ Off
, AS
, Area
};
300 struct te_link_subtlv
{
301 struct tlv_header header
;
304 struct in_addr link_id
;
305 struct in_addr lclif
;
306 struct in_addr rmtif
;
315 struct in_addr lrrid
[2];
326 /* Following structure are internal use only. */
327 struct ospf_mpls_te
{
328 /* Status of MPLS-TE: enable or disable */
331 /* Traffic Engineering Database i.e. Link State */
336 enum inter_as_mode inter_as
;
337 struct in_addr interas_areaid
;
339 /* List elements are zebra-interfaces (ifp), not ospf-interfaces (oi).
343 /* Store Router-TLV in network byte order. */
344 struct te_tlv_router_addr router_addr
;
347 struct mpls_te_link
{
349 * According to MPLS-TE (draft) specification, 24-bit Opaque-ID field
350 * is subdivided into 8-bit "unused" field and 16-bit "instance" field.
351 * In this implementation, each Link-TLV has its own instance.
355 /* Reference pointer to a Zebra-interface. */
356 struct interface
*ifp
;
358 /* Area info in which this MPLS-TE link belongs to. */
359 struct ospf_area
*area
;
361 /* Flags to manage this link parameters. */
364 /* Type of MPLS-TE link: RFC3630, RFC5392, RFC5392 emulated, RFC6827 */
367 /* Store Link-TLV in network byte order. */
368 /* RFC3630 & RFC6827 / RFC 6827 */
369 struct te_tlv_link link_header
;
370 struct te_link_subtlv_link_type link_type
;
371 struct te_link_subtlv_link_id link_id
;
372 struct te_link_subtlv_lclif_ipaddr lclif_ipaddr
;
373 struct te_link_subtlv_rmtif_ipaddr rmtif_ipaddr
;
374 struct te_link_subtlv_te_metric te_metric
;
375 struct te_link_subtlv_max_bw max_bw
;
376 struct te_link_subtlv_max_rsv_bw max_rsv_bw
;
377 struct te_link_subtlv_unrsv_bw unrsv_bw
;
378 struct te_link_subtlv_rsc_clsclr rsc_clsclr
;
380 struct te_link_subtlv_llri llri
;
382 struct te_link_subtlv_ras ras
;
383 struct te_link_subtlv_rip rip
;
385 struct te_link_subtlv_lrrid lrrid
;
387 struct te_link_subtlv_av_delay av_delay
;
388 struct te_link_subtlv_mm_delay mm_delay
;
389 struct te_link_subtlv_delay_var delay_var
;
390 struct te_link_subtlv_pkt_loss pkt_loss
;
391 struct te_link_subtlv_res_bw res_bw
;
392 struct te_link_subtlv_ava_bw ava_bw
;
393 struct te_link_subtlv_use_bw use_bw
;
395 struct in_addr adv_router
;
400 extern int ospf_mpls_te_init(void);
401 extern void ospf_mpls_te_term(void);
402 extern void ospf_mpls_te_finish(void);
403 extern struct ospf_mpls_te
*get_ospf_mpls_te(void);
404 extern void ospf_mpls_te_update_if(struct interface
*);
405 extern void ospf_mpls_te_lsa_schedule(struct mpls_te_link
*, enum lsa_opcode
);
406 extern void set_linkparams_llri(struct mpls_te_link
*, uint32_t, uint32_t);
407 extern void set_linkparams_lrrid(struct mpls_te_link
*, struct in_addr
,
410 struct zapi_opaque_reg_info
;
412 * Call when a client send a Link State Sync message. In turn, OSPF will send
413 * the contain of the Link State Data base.
415 * @param info ZAPI Opaque message information
417 * @return 0 on success, -1 otherwise
419 extern int ospf_te_sync_ted(struct zapi_opaque_reg_info dst
);
421 #endif /* _ZEBRA_OSPF_MPLS_TE_H */