Import Upstream version 1.2.2
[quagga-debian.git] / ospfd / ospf_te.h
1 /*
2  * This is an implementation of RFC3630, RFC5392 & RFC6827
3  * Copyright (C) 2001 KDD R&D Laboratories, Inc.
4  * http://www.kddlabs.co.jp/
5  *
6  * Copyright (C) 2012 Orange Labs
7  * http://www.orange.com
8  *
9  * This file is part of GNU Zebra.
10  *
11  * GNU Zebra is free software; you can redistribute it and/or modify it
12  * under the terms of the GNU General Public License as published by the
13  * Free Software Foundation; either version 2, or (at your option) any
14  * later version.
15  * 
16  * GNU Zebra is distributed in the hope that it will be useful, but
17  * WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
19  * General Public License for more details.
20  *
21  * You should have received a copy of the GNU General Public License
22  * along with GNU Zebra; see the file COPYING.  If not, write to the Free
23  * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
24  * 02111-1307, USA.
25  */
26
27 /* Add support of RFC7471 */
28 /* Add support of RFC5392 */
29 /* Add support of RFC6827 (partial) */
30
31 #ifndef _ZEBRA_OSPF_MPLS_TE_H
32 #define _ZEBRA_OSPF_MPLS_TE_H
33
34 /*
35  * Opaque LSA's link state ID for Traffic Engineering is
36  * structured as follows.
37  *
38  *        24       16        8        0
39  * +--------+--------+--------+--------+
40  * |    1   |  MBZ   |........|........|
41  * +--------+--------+--------+--------+
42  * |<-Type->|<Resv'd>|<-- Instance --->|
43  *
44  *
45  * Type:      IANA has assigned '1' for Traffic Engineering.
46  * MBZ:       Reserved, must be set to zero.
47  * Instance:  User may select an arbitrary 16-bit value.
48  *
49  */
50
51 #define MAX_LEGAL_TE_INSTANCE_NUM (0xffff)
52 #define LEGAL_TE_INSTANCE_RANGE(i)  (0 <= (i) && (i) <= 0xffff)
53
54 /*
55  *        24       16        8        0
56  * +--------+--------+--------+--------+ ---
57  * |   LS age        |Options |   10   |  A
58  * +--------+--------+--------+--------+  |
59  * |    1   |   0    |    Instance     |  |
60  * +--------+--------+--------+--------+  |
61  * |        Advertising router         |  |  Standard (Opaque) LSA header;
62  * +--------+--------+--------+--------+  |  Only type-10 is used.
63  * |        LS sequence number         |  |
64  * +--------+--------+--------+--------+  |
65  * |   LS checksum   |     Length      |  V
66  * +--------+--------+--------+--------+ ---
67  * |      Type       |     Length      |  A
68  * +--------+--------+--------+--------+  |  TLV part for TE; Values might be
69  * |              Values ...           |  V  structured as a set of sub-TLVs.
70  * +--------+--------+--------+--------+ ---
71  */
72
73 /* Following define the type of TE link regarding the various RFC */
74 #define STD_TE          0x01
75 #define GMPLS           0x02
76 #define INTER_AS        0x04
77 #define PSEUDO_TE       0x08
78 #define FLOOD_AREA      0x10
79 #define FLOOD_AS        0x20
80 #define EMULATED        0x80
81
82 #define IS_STD_TE(x)            (x & STD_TE)
83 #define IS_PSEUDO_TE(x)         (x & PSEUDO_TE)
84 #define IS_INTER_AS(x)          (x & INTER_AS)
85 #define IS_EMULATED(x)          (x & EMULATED)
86 #define IS_FLOOD_AREA(x)        (x & FLOOD_AREA)
87 #define IS_FLOOD_AS(x)          (x & FLOOD_AS)
88 #define IS_INTER_AS_EMU(x)      (x & INTER_AS & EMULATED)
89 #define IS_INTER_AS_AS(x)       (x & INTER_AS & FLOOD_AS)
90
91 /* Flags to manage TE Link LSA */
92 #define LPFLG_LSA_INACTIVE              0x0
93 #define LPFLG_LSA_ACTIVE                0x1
94 #define LPFLG_LSA_ENGAGED               0x2
95 #define LPFLG_LOOKUP_DONE               0x4
96 #define LPFLG_LSA_FORCED_REFRESH        0x8
97
98 /*
99  * Following section defines TLV (tag, length, value) structures,
100  * used for Traffic Engineering.
101  */
102 struct te_tlv_header
103 {
104   u_int16_t     type;                   /* TE_TLV_XXX (see below) */
105   u_int16_t     length;                 /* Value portion only, in octets */
106 };
107
108 #define TLV_HDR_SIZE \
109         (sizeof (struct te_tlv_header))
110
111 #define TLV_BODY_SIZE(tlvh) \
112         (ROUNDUP (ntohs ((tlvh)->length), sizeof (u_int32_t)))
113
114 #define TLV_SIZE(tlvh) \
115         (TLV_HDR_SIZE + TLV_BODY_SIZE(tlvh))
116
117 #define TLV_HDR_TOP(lsah) \
118         (struct te_tlv_header *)((char *)(lsah) + OSPF_LSA_HEADER_SIZE)
119
120 #define TLV_HDR_NEXT(tlvh) \
121         (struct te_tlv_header *)((char *)(tlvh) + TLV_SIZE(tlvh))
122
123 #define TLV_HDR_SUBTLV(tlvh) \
124         (struct te_tlv_header *)((char *)(tlvh) + TLV_HDR_SIZE)
125
126 #define TLV_TYPE(tlvh)     tlvh.header.type
127 #define TLV_LEN(tlvh)      tlvh.header.length
128 #define TLV_HDR(tlvh)      tlvh.header
129
130
131 /*
132  * Following section defines TLV body parts.
133  */
134 /* Router Address TLV */ /* Mandatory */
135 #define TE_TLV_ROUTER_ADDR              1
136 struct te_tlv_router_addr
137 {
138   struct te_tlv_header  header;         /* Value length is 4 octets. */
139   struct in_addr        value;
140 };
141
142 /* Link TLV */
143 #define TE_TLV_LINK                     2
144 struct te_tlv_link
145 {
146   struct te_tlv_header  header;
147   /* A set of link-sub-TLVs will follow. */
148 };
149
150 #define TE_LINK_SUBTLV_DEF_SIZE         4
151
152 /* Link Type Sub-TLV */ /* Mandatory */
153 #define TE_LINK_SUBTLV_LINK_TYPE        1
154 #define TE_LINK_SUBTLV_TYPE_SIZE        1
155 struct te_link_subtlv_link_type
156 {
157   struct te_tlv_header  header;         /* Value length is 1 octet. */
158   struct
159   {
160 #define LINK_TYPE_SUBTLV_VALUE_PTP      1
161 #define LINK_TYPE_SUBTLV_VALUE_MA       2
162       u_char    value;
163       u_char    padding[3];
164   } link_type;
165 };
166
167 /* Link Sub-TLV: Link ID */ /* Mandatory */
168 #define TE_LINK_SUBTLV_LINK_ID          2
169 struct te_link_subtlv_link_id
170 {
171   struct te_tlv_header  header;         /* Value length is 4 octets. */
172   struct in_addr        value;          /* Same as router-lsa's link-id. */
173 };
174
175 /* Link Sub-TLV: Local Interface IP Address */ /* Optional */
176 #define TE_LINK_SUBTLV_LCLIF_IPADDR     3
177 struct te_link_subtlv_lclif_ipaddr
178 {
179   struct te_tlv_header  header;         /* Value length is 4 x N octets. */
180   struct in_addr        value[1];       /* Local IP address(es). */
181 };
182
183 /* Link Sub-TLV: Remote Interface IP Address */ /* Optional */
184 #define TE_LINK_SUBTLV_RMTIF_IPADDR     4
185 struct te_link_subtlv_rmtif_ipaddr
186 {
187   struct te_tlv_header  header;         /* Value length is 4 x N octets. */
188   struct in_addr        value[1];       /* Neighbor's IP address(es). */
189 };
190
191 /* Link Sub-TLV: Traffic Engineering Metric */ /* Optional */
192 #define TE_LINK_SUBTLV_TE_METRIC        5
193 struct te_link_subtlv_te_metric
194 {
195   struct te_tlv_header  header;         /* Value length is 4 octets. */
196   u_int32_t             value;          /* Link metric for TE purpose. */
197 };
198
199 /* Link Sub-TLV: Maximum Bandwidth */ /* Optional */
200 #define TE_LINK_SUBTLV_MAX_BW           6
201 struct te_link_subtlv_max_bw
202 {
203   struct te_tlv_header  header;         /* Value length is 4 octets. */
204   float                 value;          /* bytes/sec */
205 };
206
207 /* Link Sub-TLV: Maximum Reservable Bandwidth */ /* Optional */
208 #define TE_LINK_SUBTLV_MAX_RSV_BW       7
209 struct te_link_subtlv_max_rsv_bw
210 {
211   struct te_tlv_header  header;         /* Value length is 4 octets. */
212   float                 value;          /* bytes/sec */
213 };
214
215 /* Link Sub-TLV: Unreserved Bandwidth */ /* Optional */
216 #define TE_LINK_SUBTLV_UNRSV_BW         8
217 #define TE_LINK_SUBTLV_UNRSV_SIZE       32
218 struct te_link_subtlv_unrsv_bw
219 {
220   struct te_tlv_header  header;         /* Value length is 32 octets. */
221   float                 value[MAX_CLASS_TYPE];  /* One for each priority level. */
222 };
223
224 /* Link Sub-TLV: Resource Class/Color */ /* Optional */
225 #define TE_LINK_SUBTLV_RSC_CLSCLR       9
226 struct te_link_subtlv_rsc_clsclr
227 {
228   struct te_tlv_header  header;         /* Value length is 4 octets. */
229   u_int32_t             value;          /* Admin. group membership. */
230 };
231
232 /* For RFC6827 */
233 /* Local and Remote TE Router ID */
234 #define TE_LINK_SUBTLV_LRRID            10
235 #define TE_LINK_SUBTLV_LRRID_SIZE       8
236 struct te_link_subtlv_lrrid
237 {
238   struct te_tlv_header header;  /* Value length is 8 octets. */
239   struct in_addr local;         /* Local TE Router Identifier */
240   struct in_addr remote;        /* Remote TE Router Identifier */
241 };
242
243 /* RFC4203: Link Local/Remote Identifiers */
244 #define TE_LINK_SUBTLV_LLRI             11
245 #define TE_LINK_SUBTLV_LLRI_SIZE        8
246 struct te_link_subtlv_llri
247 {
248   struct te_tlv_header header;  /* Value length is 8 octets. */
249   u_int32_t local;              /* Link Local Identifier */
250   u_int32_t remote;             /* Link Remote Identifier */
251 };
252
253 /* Inter-RA Export Upward sub-TLV (12) and Inter-RA Export Downward sub-TLV (13) (RFC6827bis) are not yet supported */
254 /* SUBTLV 14-16 (RFC4203) are not yet supported */
255 /* Bandwidth Constraints sub-TLV (17) (RFC4124) is not yet supported */
256 /* SUBLV 18-20 are for OSPFv6 TE (RFC5329). see ospf6d */
257
258 /* For RFC 5392 */
259 /* Remote AS Number sub-TLV */
260 #define TE_LINK_SUBTLV_RAS              21
261 struct te_link_subtlv_ras
262 {
263   struct te_tlv_header header;  /* Value length is 4 octets. */
264   u_int32_t value;              /* Remote AS number */
265 };
266
267 /* IPv4 Remote ASBR ID Sub-TLV */
268 #define TE_LINK_SUBTLV_RIP              22
269 struct te_link_subtlv_rip
270 {
271   struct te_tlv_header header;  /* Value length is 4 octets. */
272   struct in_addr value;         /* Remote ASBR IP address */
273 };
274
275 /* SUBTLV 24 is IPv6 Remote ASBR ID (RFC5392). see ospf6d */
276
277 /* SUBTLV 23 (RFC5330) and 25 (RFC6001) are not yet supported */
278
279 /* SUBTLV 26 (RFC7308) is not yet supported */
280
281 /* RFC7471 */
282 /* Link Sub-TLV: Average Link Delay */ /* Optional */
283 #define TE_LINK_SUBTLV_AV_DELAY         27
284 struct te_link_subtlv_av_delay
285 {
286   struct te_tlv_header header;  /* Value length is 4 bytes. */
287   u_int32_t            value;   /* delay in micro-seconds only 24 bits => 0 ... 16777215
288                                    with Anomalous Bit as Upper most bit */
289 };
290
291 /* Link Sub-TLV: Low/High Link Delay */
292 #define TE_LINK_SUBTLV_MM_DELAY         28
293 #define TE_LINK_SUBTLV_MM_DELAY_SIZE    8
294 struct te_link_subtlv_mm_delay
295 {
296   struct te_tlv_header header;  /* Value length is 8 bytes. */
297   u_int32_t            low;     /* low delay in micro-seconds only 24 bits => 0 ... 16777215
298                                    with Anomalous Bit (A) as Upper most bit */
299   u_int32_t            high;    /* high delay in micro-seconds only 24 bits => 0 ... 16777215 */
300 };
301
302 /* Link Sub-TLV: Link Delay Variation i.e. Jitter */
303 #define TE_LINK_SUBTLV_DELAY_VAR        29
304 struct te_link_subtlv_delay_var
305 {
306   struct te_tlv_header header;  /* Value length is 4 bytes. */
307   u_int32_t            value;   /* interval in micro-seconds only 24 bits => 0 ... 16777215 */
308 };
309
310 /* Link Sub-TLV: Routine Unidirectional Link Packet Loss */
311 #define TE_LINK_SUBTLV_PKT_LOSS         30
312 struct te_link_subtlv_pkt_loss
313 {
314   struct te_tlv_header header;  /* Value length is 4 bytes. */
315   u_int32_t            value;   /* in percentage of total traffic only 24 bits (2^24 - 2)
316                                    with Anomalous Bit as Upper most bit */
317 };
318
319 /* Link Sub-TLV: Unidirectional Residual Bandwidth */ /* Optional */
320 #define TE_LINK_SUBTLV_RES_BW           31
321 struct te_link_subtlv_res_bw
322 {
323   struct te_tlv_header header;  /* Value length is 4 bytes. */
324   float                value;   /* bandwidth in IEEE floating point format with units in bytes per second */
325 };
326
327 /* Link Sub-TLV: Unidirectional Available Bandwidth */ /* Optional */
328 #define TE_LINK_SUBTLV_AVA_BW           32
329 struct te_link_subtlv_ava_bw
330 {
331   struct te_tlv_header header;  /* Value length is 4 octets. */
332   float                value;   /* bandwidth in IEEE floating point format with units in bytes per second */
333 };
334
335 /* Link Sub-TLV: Unidirectional Utilized Bandwidth */ /* Optional */
336 #define TE_LINK_SUBTLV_USE_BW           33
337 struct te_link_subtlv_use_bw
338 {
339   struct te_tlv_header header;  /* Value length is 4 octets. */
340   float                value;   /* bandwidth in IEEE floating point format with units in bytes per second */
341 };
342
343 #define TE_LINK_SUBTLV_MAX              34      /* Last SUBTLV + 1 */
344
345 /* Here are "non-official" architectural constants. */
346 #define MPLS_TE_MINIMUM_BANDWIDTH       1.0     /* Reasonable? *//* XXX */
347
348 /* Following declaration concerns the MPLS-TE and LINk-TE management */
349 typedef enum _opcode_t
350 { REORIGINATE_THIS_LSA, REFRESH_THIS_LSA, FLUSH_THIS_LSA } opcode_t;
351
352 typedef enum _status_t
353 { disabled, enabled } status_t;
354
355 /* Mode for Inter-AS Opaque-LSA */
356 enum inter_as_mode { Disable, AS, Area };
357
358 struct te_link_subtlv
359 {
360   struct te_tlv_header header;
361   union
362   {
363     u_int32_t link_type;
364     struct in_addr link_id;
365     struct in_addr lclif;
366     struct in_addr rmtif;
367     u_int32_t te_metric;
368     float max_bw;
369     float max_rsv_bw;
370     float unrsv[8];
371     u_int32_t rsc_clsclr;
372     u_int32_t llri[2];
373     u_int32_t ras;
374     struct in_addr rip;
375     struct in_addr lrrid[2];
376     u_int32_t av_delay;
377     u_int32_t mm_delay;
378     u_int32_t delay_var;
379     u_int32_t pkt_loss;
380     float res_bw;
381     float ava_bw;
382     float use_bw;
383   } value;
384 };
385
386 /* Following structure are internal use only. */
387 struct ospf_mpls_te
388 {
389   /* Status of MPLS-TE: enable or disbale */
390   status_t status;
391
392   /* RFC5392 */
393   enum inter_as_mode inter_as;
394   struct in_addr interas_areaid;
395
396   /* List elements are zebra-interfaces (ifp), not ospf-interfaces (oi). */
397   struct list *iflist;
398
399   /* Store Router-TLV in network byte order. */
400   struct te_tlv_router_addr router_addr;
401 };
402
403 struct mpls_te_link
404 {
405   /*
406    * According to MPLS-TE (draft) specification, 24-bit Opaque-ID field
407    * is subdivided into 8-bit "unused" field and 16-bit "instance" field.
408    * In this implementation, each Link-TLV has its own instance.
409    */
410   u_int32_t instance;
411
412   /* Reference pointer to a Zebra-interface. */
413   struct interface *ifp;
414
415   /* Area info in which this MPLS-TE link belongs to. */
416   struct ospf_area *area;
417
418   /* Flags to manage this link parameters. */
419   u_int32_t flags;
420
421   /* Type of MPLS-TE link: RFC3630, RFC5392, RFC5392 emulated, RFC6827 */
422   u_int8_t type;
423
424   /* Store Link-TLV in network byte order. */
425   /* RFC3630 & RFC6827 / RFC 6827 */
426   struct te_tlv_link link_header;
427   struct te_link_subtlv_link_type link_type;
428   struct te_link_subtlv_link_id link_id;
429   struct te_link_subtlv_lclif_ipaddr lclif_ipaddr;
430   struct te_link_subtlv_rmtif_ipaddr rmtif_ipaddr;
431   struct te_link_subtlv_te_metric te_metric;
432   struct te_link_subtlv_max_bw max_bw;
433   struct te_link_subtlv_max_rsv_bw max_rsv_bw;
434   struct te_link_subtlv_unrsv_bw unrsv_bw;
435   struct te_link_subtlv_rsc_clsclr rsc_clsclr;
436   /* RFC4203 */
437   struct te_link_subtlv_llri llri;
438   /* RFC5392 */
439   struct te_link_subtlv_ras ras;
440   struct te_link_subtlv_rip rip;
441   /* RFC6827 */
442   struct te_link_subtlv_lrrid lrrid;
443   /* RFC7471 */
444   struct te_link_subtlv_av_delay av_delay;
445   struct te_link_subtlv_mm_delay mm_delay;
446   struct te_link_subtlv_delay_var delay_var;
447   struct te_link_subtlv_pkt_loss pkt_loss;
448   struct te_link_subtlv_res_bw res_bw;
449   struct te_link_subtlv_ava_bw ava_bw;
450   struct te_link_subtlv_use_bw use_bw;
451
452   struct in_addr adv_router;
453   struct in_addr id;
454 };
455
456 /* Prototypes. */
457 extern int ospf_mpls_te_init (void);
458 extern void ospf_mpls_te_term (void);
459 extern struct ospf_mpls_te *get_ospf_mpls_te (void);
460 extern void ospf_mpls_te_update_if (struct interface *);
461 extern void ospf_mpls_te_lsa_schedule (struct mpls_te_link *, opcode_t);
462 extern u_int32_t get_mpls_te_instance_value (void);
463 extern void set_linkparams_llri (struct mpls_te_link *, u_int32_t, u_int32_t);
464 extern void set_linkparams_lrrid (struct mpls_te_link *, struct in_addr, struct in_addr);
465
466 #endif /* _ZEBRA_OSPF_MPLS_TE_H */