]> git.proxmox.com Git - mirror_frr.git/blob - ospfd/ospf_te.c
Merge pull request #3017 from pacovn/devbuild_Wshadow_flag
[mirror_frr.git] / ospfd / ospf_te.c
1 /*
2 * This is an implementation of RFC3630
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 along
22 * with this program; see the file COPYING; if not, write to the Free Software
23 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
24 */
25
26 /* Add support of RFC7471 */
27 /* Add support of RFC5392, RFC6827 */
28
29 #include <zebra.h>
30 #include <math.h>
31
32 #include "linklist.h"
33 #include "prefix.h"
34 #include "vrf.h"
35 #include "if.h"
36 #include "table.h"
37 #include "memory.h"
38 #include "command.h"
39 #include "vty.h"
40 #include "stream.h"
41 #include "log.h"
42 #include "thread.h"
43 #include "hash.h"
44 #include "sockunion.h" /* for inet_aton() */
45 #include "network.h"
46
47 #include "ospfd/ospfd.h"
48 #include "ospfd/ospf_interface.h"
49 #include "ospfd/ospf_ism.h"
50 #include "ospfd/ospf_asbr.h"
51 #include "ospfd/ospf_lsa.h"
52 #include "ospfd/ospf_lsdb.h"
53 #include "ospfd/ospf_neighbor.h"
54 #include "ospfd/ospf_nsm.h"
55 #include "ospfd/ospf_flood.h"
56 #include "ospfd/ospf_packet.h"
57 #include "ospfd/ospf_spf.h"
58 #include "ospfd/ospf_dump.h"
59 #include "ospfd/ospf_route.h"
60 #include "ospfd/ospf_ase.h"
61 #include "ospfd/ospf_zebra.h"
62 #include "ospfd/ospf_te.h"
63 #include "ospfd/ospf_vty.h"
64 #include "ospfd/ospf_errors.h"
65
66 /*
67 * Global variable to manage Opaque-LSA/MPLS-TE on this node.
68 * Note that all parameter values are stored in network byte order.
69 */
70 struct ospf_mpls_te OspfMplsTE;
71
72 const char *mode2text[] = {"Off", "AS", "Area"};
73
74 /*------------------------------------------------------------------------*
75 * Followings are initialize/terminate functions for MPLS-TE handling.
76 *------------------------------------------------------------------------*/
77
78 static int ospf_mpls_te_new_if(struct interface *ifp);
79 static int ospf_mpls_te_del_if(struct interface *ifp);
80 static void ospf_mpls_te_ism_change(struct ospf_interface *oi, int old_status);
81 static void ospf_mpls_te_nsm_change(struct ospf_neighbor *nbr, int old_status);
82 static void ospf_mpls_te_config_write_router(struct vty *vty);
83 static void ospf_mpls_te_show_info(struct vty *vty, struct ospf_lsa *lsa);
84 static int ospf_mpls_te_lsa_originate_area(void *arg);
85 static int ospf_mpls_te_lsa_originate_as(void *arg);
86 static struct ospf_lsa *ospf_mpls_te_lsa_refresh(struct ospf_lsa *lsa);
87
88 static void del_mpls_te_link(void *val);
89 static void ospf_mpls_te_register_vty(void);
90
91 int ospf_mpls_te_init(void)
92 {
93 int rc;
94
95 rc = ospf_register_opaque_functab(
96 OSPF_OPAQUE_AREA_LSA, OPAQUE_TYPE_TRAFFIC_ENGINEERING_LSA,
97 ospf_mpls_te_new_if, ospf_mpls_te_del_if,
98 ospf_mpls_te_ism_change, ospf_mpls_te_nsm_change,
99 ospf_mpls_te_config_write_router,
100 NULL, /*ospf_mpls_te_config_write_if */
101 NULL, /* ospf_mpls_te_config_write_debug */
102 ospf_mpls_te_show_info, ospf_mpls_te_lsa_originate_area,
103 ospf_mpls_te_lsa_refresh, NULL, /* ospf_mpls_te_new_lsa_hook */
104 NULL /* ospf_mpls_te_del_lsa_hook */);
105 if (rc != 0) {
106 flog_warn(
107 EC_OSPF_OPAQUE_REGISTRATION,
108 "ospf_mpls_te_init: Failed to register Traffic Engineering functions");
109 return rc;
110 }
111
112 memset(&OspfMplsTE, 0, sizeof(struct ospf_mpls_te));
113 OspfMplsTE.enabled = false;
114 OspfMplsTE.inter_as = Off;
115 OspfMplsTE.iflist = list_new();
116 OspfMplsTE.iflist->del = del_mpls_te_link;
117
118 ospf_mpls_te_register_vty();
119
120 return rc;
121 }
122
123 /* Additional register for RFC5392 support */
124 static int ospf_mpls_te_register(enum inter_as_mode mode)
125 {
126 int rc = 0;
127 uint8_t scope;
128
129 if (OspfMplsTE.inter_as != Off)
130 return rc;
131
132 if (mode == AS)
133 scope = OSPF_OPAQUE_AS_LSA;
134 else
135 scope = OSPF_OPAQUE_AREA_LSA;
136
137 rc = ospf_register_opaque_functab(scope, OPAQUE_TYPE_INTER_AS_LSA, NULL,
138 NULL, NULL, NULL, NULL, NULL, NULL,
139 ospf_mpls_te_show_info,
140 ospf_mpls_te_lsa_originate_as,
141 ospf_mpls_te_lsa_refresh, NULL, NULL);
142
143 if (rc != 0) {
144 flog_warn(
145 EC_OSPF_OPAQUE_REGISTRATION,
146 "ospf_router_info_init: Failed to register Inter-AS functions");
147 return rc;
148 }
149
150 return rc;
151 }
152
153 static int ospf_mpls_te_unregister()
154 {
155 uint8_t scope;
156
157 if (OspfMplsTE.inter_as == Off)
158 return 0;
159
160 if (OspfMplsTE.inter_as == AS)
161 scope = OSPF_OPAQUE_AS_LSA;
162 else
163 scope = OSPF_OPAQUE_AREA_LSA;
164
165 ospf_delete_opaque_functab(scope, OPAQUE_TYPE_INTER_AS_LSA);
166
167 return 0;
168 }
169
170 void ospf_mpls_te_term(void)
171 {
172 list_delete_and_null(&OspfMplsTE.iflist);
173
174 ospf_delete_opaque_functab(OSPF_OPAQUE_AREA_LSA,
175 OPAQUE_TYPE_TRAFFIC_ENGINEERING_LSA);
176
177 OspfMplsTE.enabled = false;
178
179 ospf_mpls_te_unregister();
180 OspfMplsTE.inter_as = Off;
181
182 return;
183 }
184
185 void ospf_mpls_te_finish(void)
186 {
187 // list_delete_all_node(OspfMplsTE.iflist);
188
189 OspfMplsTE.enabled = false;
190 OspfMplsTE.inter_as = Off;
191 }
192
193 /*------------------------------------------------------------------------*
194 * Followings are control functions for MPLS-TE parameters management.
195 *------------------------------------------------------------------------*/
196
197 static void del_mpls_te_link(void *val)
198 {
199 XFREE(MTYPE_OSPF_MPLS_TE, val);
200 return;
201 }
202
203 static uint32_t get_mpls_te_instance_value(void)
204 {
205 static uint32_t seqno = 0;
206
207 if (seqno < MAX_LEGAL_TE_INSTANCE_NUM)
208 seqno += 1;
209 else
210 seqno = 1; /* Avoid zero. */
211
212 return seqno;
213 }
214
215 static struct mpls_te_link *lookup_linkparams_by_ifp(struct interface *ifp)
216 {
217 struct listnode *node, *nnode;
218 struct mpls_te_link *lp;
219
220 for (ALL_LIST_ELEMENTS(OspfMplsTE.iflist, node, nnode, lp))
221 if (lp->ifp == ifp)
222 return lp;
223
224 return NULL;
225 }
226
227 static struct mpls_te_link *lookup_linkparams_by_instance(struct ospf_lsa *lsa)
228 {
229 struct listnode *node;
230 struct mpls_te_link *lp;
231 unsigned int key = GET_OPAQUE_ID(ntohl(lsa->data->id.s_addr));
232
233 for (ALL_LIST_ELEMENTS_RO(OspfMplsTE.iflist, node, lp))
234 if (lp->instance == key)
235 return lp;
236
237 zlog_info("lookup_linkparams_by_instance: Entry not found: key(%x)",
238 key);
239 return NULL;
240 }
241
242 static void ospf_mpls_te_foreach_area(
243 void (*func)(struct mpls_te_link *lp, enum lsa_opcode sched_opcode),
244 enum lsa_opcode sched_opcode)
245 {
246 struct listnode *node, *nnode;
247 struct listnode *node2;
248 struct mpls_te_link *lp;
249 struct ospf_area *area;
250
251 for (ALL_LIST_ELEMENTS(OspfMplsTE.iflist, node, nnode, lp)) {
252 /* Skip Inter-AS TEv2 Links */
253 if (IS_INTER_AS(lp->type))
254 continue;
255 if ((area = lp->area) == NULL)
256 continue;
257 if (CHECK_FLAG(lp->flags, LPFLG_LOOKUP_DONE))
258 continue;
259
260 if (func != NULL)
261 (*func)(lp, sched_opcode);
262
263 for (node2 = listnextnode(node); node2;
264 node2 = listnextnode(node2))
265 if ((lp = listgetdata(node2)) != NULL)
266 if (lp->area != NULL)
267 if (IPV4_ADDR_SAME(&lp->area->area_id,
268 &area->area_id))
269 SET_FLAG(lp->flags,
270 LPFLG_LOOKUP_DONE);
271 }
272
273 for (ALL_LIST_ELEMENTS_RO(OspfMplsTE.iflist, node, lp))
274 if (lp->area != NULL)
275 UNSET_FLAG(lp->flags, LPFLG_LOOKUP_DONE);
276
277 return;
278 }
279
280 static void set_mpls_te_router_addr(struct in_addr ipv4)
281 {
282 OspfMplsTE.router_addr.header.type = htons(TE_TLV_ROUTER_ADDR);
283 OspfMplsTE.router_addr.header.length = htons(TE_LINK_SUBTLV_DEF_SIZE);
284 OspfMplsTE.router_addr.value = ipv4;
285 return;
286 }
287
288 static void set_linkparams_link_header(struct mpls_te_link *lp)
289 {
290 uint16_t length = 0;
291
292 /* TE_LINK_SUBTLV_LINK_TYPE */
293 if (ntohs(lp->link_type.header.type) != 0)
294 length += TLV_SIZE(&lp->link_type.header);
295
296 /* TE_LINK_SUBTLV_LINK_ID */
297 if (ntohs(lp->link_id.header.type) != 0)
298 length += TLV_SIZE(&lp->link_id.header);
299
300 /* TE_LINK_SUBTLV_LCLIF_IPADDR */
301 if (lp->lclif_ipaddr.header.type != 0)
302 length += TLV_SIZE(&lp->lclif_ipaddr.header);
303
304 /* TE_LINK_SUBTLV_RMTIF_IPADDR */
305 if (lp->rmtif_ipaddr.header.type != 0)
306 length += TLV_SIZE(&lp->rmtif_ipaddr.header);
307
308 /* TE_LINK_SUBTLV_TE_METRIC */
309 if (ntohs(lp->te_metric.header.type) != 0)
310 length += TLV_SIZE(&lp->te_metric.header);
311
312 /* TE_LINK_SUBTLV_MAX_BW */
313 if (ntohs(lp->max_bw.header.type) != 0)
314 length += TLV_SIZE(&lp->max_bw.header);
315
316 /* TE_LINK_SUBTLV_MAX_RSV_BW */
317 if (ntohs(lp->max_rsv_bw.header.type) != 0)
318 length += TLV_SIZE(&lp->max_rsv_bw.header);
319
320 /* TE_LINK_SUBTLV_UNRSV_BW */
321 if (ntohs(lp->unrsv_bw.header.type) != 0)
322 length += TLV_SIZE(&lp->unrsv_bw.header);
323
324 /* TE_LINK_SUBTLV_RSC_CLSCLR */
325 if (ntohs(lp->rsc_clsclr.header.type) != 0)
326 length += TLV_SIZE(&lp->rsc_clsclr.header);
327
328 /* TE_LINK_SUBTLV_LLRI */
329 if (ntohs(lp->llri.header.type) != 0)
330 length += TLV_SIZE(&lp->llri.header);
331
332 /* TE_LINK_SUBTLV_RIP */
333 if (ntohs(lp->rip.header.type) != 0)
334 length += TLV_SIZE(&lp->rip.header);
335
336 /* TE_LINK_SUBTLV_RAS */
337 if (ntohs(lp->ras.header.type) != 0)
338 length += TLV_SIZE(&lp->ras.header);
339
340 /* TE_LINK_SUBTLV_LRRID */
341 if (ntohs(lp->lrrid.header.type) != 0)
342 length += TLV_SIZE(&lp->lrrid.header);
343
344 /* TE_LINK_SUBTLV_AV_DELAY */
345 if (ntohs(lp->av_delay.header.type) != 0)
346 length += TLV_SIZE(&lp->av_delay.header);
347
348 /* TE_LINK_SUBTLV_MM_DELAY */
349 if (ntohs(lp->mm_delay.header.type) != 0)
350 length += TLV_SIZE(&lp->mm_delay.header);
351
352 /* TE_LINK_SUBTLV_DELAY_VAR */
353 if (ntohs(lp->delay_var.header.type) != 0)
354 length += TLV_SIZE(&lp->delay_var.header);
355
356 /* TE_LINK_SUBTLV_PKT_LOSS */
357 if (ntohs(lp->pkt_loss.header.type) != 0)
358 length += TLV_SIZE(&lp->pkt_loss.header);
359
360 /* TE_LINK_SUBTLV_RES_BW */
361 if (ntohs(lp->res_bw.header.type) != 0)
362 length += TLV_SIZE(&lp->res_bw.header);
363
364 /* TE_LINK_SUBTLV_AVA_BW */
365 if (ntohs(lp->ava_bw.header.type) != 0)
366 length += TLV_SIZE(&lp->ava_bw.header);
367
368 /* TE_LINK_SUBTLV_USE_BW */
369 if (ntohs(lp->use_bw.header.type) != 0)
370 length += TLV_SIZE(&lp->use_bw.header);
371
372 lp->link_header.header.type = htons(TE_TLV_LINK);
373 lp->link_header.header.length = htons(length);
374
375 return;
376 }
377
378 static void set_linkparams_link_type(struct ospf_interface *oi,
379 struct mpls_te_link *lp)
380 {
381 lp->link_type.header.type = htons(TE_LINK_SUBTLV_LINK_TYPE);
382 lp->link_type.header.length = htons(TE_LINK_SUBTLV_TYPE_SIZE);
383
384 switch (oi->type) {
385 case OSPF_IFTYPE_POINTOPOINT:
386 lp->link_type.link_type.value = LINK_TYPE_SUBTLV_VALUE_PTP;
387 break;
388 case OSPF_IFTYPE_BROADCAST:
389 case OSPF_IFTYPE_NBMA:
390 lp->link_type.link_type.value = LINK_TYPE_SUBTLV_VALUE_MA;
391 break;
392 default:
393 /* Not supported yet. */ /* XXX */
394 lp->link_type.header.type = htons(0);
395 break;
396 }
397 return;
398 }
399
400 static void set_linkparams_link_id(struct ospf_interface *oi,
401 struct mpls_te_link *lp)
402 {
403 struct ospf_neighbor *nbr;
404 int done = 0;
405
406 lp->link_id.header.type = htons(TE_LINK_SUBTLV_LINK_ID);
407 lp->link_id.header.length = htons(TE_LINK_SUBTLV_DEF_SIZE);
408
409 /*
410 * The Link ID is identical to the contents of the Link ID field
411 * in the Router LSA for these link types.
412 */
413 switch (oi->type) {
414 case OSPF_IFTYPE_POINTOPOINT:
415 /* Take the router ID of the neighbor. */
416 if ((nbr = ospf_nbr_lookup_ptop(oi))
417 && nbr->state == NSM_Full) {
418 lp->link_id.value = nbr->router_id;
419 done = 1;
420 }
421 break;
422 case OSPF_IFTYPE_BROADCAST:
423 case OSPF_IFTYPE_NBMA:
424 /* Take the interface address of the designated router. */
425 if ((nbr = ospf_nbr_lookup_by_addr(oi->nbrs, &DR(oi))) == NULL)
426 break;
427
428 if (nbr->state == NSM_Full
429 || (IPV4_ADDR_SAME(&oi->address->u.prefix4, &DR(oi))
430 && ospf_nbr_count(oi, NSM_Full) > 0)) {
431 lp->link_id.value = DR(oi);
432 done = 1;
433 }
434 break;
435 default:
436 /* Not supported yet. */ /* XXX */
437 lp->link_id.header.type = htons(0);
438 break;
439 }
440
441 if (!done) {
442 struct in_addr mask;
443 masklen2ip(oi->address->prefixlen, &mask);
444 lp->link_id.value.s_addr =
445 oi->address->u.prefix4.s_addr & mask.s_addr;
446 }
447 return;
448 }
449
450 static void set_linkparams_lclif_ipaddr(struct mpls_te_link *lp,
451 struct in_addr lclif)
452 {
453
454 lp->lclif_ipaddr.header.type = htons(TE_LINK_SUBTLV_LCLIF_IPADDR);
455 lp->lclif_ipaddr.header.length = htons(TE_LINK_SUBTLV_DEF_SIZE);
456 lp->lclif_ipaddr.value[0] = lclif;
457 return;
458 }
459
460 static void set_linkparams_rmtif_ipaddr(struct mpls_te_link *lp,
461 struct in_addr rmtif)
462 {
463
464 lp->rmtif_ipaddr.header.type = htons(TE_LINK_SUBTLV_RMTIF_IPADDR);
465 lp->rmtif_ipaddr.header.length = htons(TE_LINK_SUBTLV_DEF_SIZE);
466 lp->rmtif_ipaddr.value[0] = rmtif;
467 return;
468 }
469
470 static void set_linkparams_te_metric(struct mpls_te_link *lp,
471 uint32_t te_metric)
472 {
473 lp->te_metric.header.type = htons(TE_LINK_SUBTLV_TE_METRIC);
474 lp->te_metric.header.length = htons(TE_LINK_SUBTLV_DEF_SIZE);
475 lp->te_metric.value = htonl(te_metric);
476 return;
477 }
478
479 static void set_linkparams_max_bw(struct mpls_te_link *lp, float fp)
480 {
481 lp->max_bw.header.type = htons(TE_LINK_SUBTLV_MAX_BW);
482 lp->max_bw.header.length = htons(TE_LINK_SUBTLV_DEF_SIZE);
483 lp->max_bw.value = htonf(fp);
484 return;
485 }
486
487 static void set_linkparams_max_rsv_bw(struct mpls_te_link *lp, float fp)
488 {
489 lp->max_rsv_bw.header.type = htons(TE_LINK_SUBTLV_MAX_RSV_BW);
490 lp->max_rsv_bw.header.length = htons(TE_LINK_SUBTLV_DEF_SIZE);
491 lp->max_rsv_bw.value = htonf(fp);
492 return;
493 }
494
495 static void set_linkparams_unrsv_bw(struct mpls_te_link *lp, int priority,
496 float fp)
497 {
498 /* Note that TLV-length field is the size of array. */
499 lp->unrsv_bw.header.type = htons(TE_LINK_SUBTLV_UNRSV_BW);
500 lp->unrsv_bw.header.length = htons(TE_LINK_SUBTLV_UNRSV_SIZE);
501 lp->unrsv_bw.value[priority] = htonf(fp);
502 return;
503 }
504
505 static void set_linkparams_rsc_clsclr(struct mpls_te_link *lp,
506 uint32_t classcolor)
507 {
508 lp->rsc_clsclr.header.type = htons(TE_LINK_SUBTLV_RSC_CLSCLR);
509 lp->rsc_clsclr.header.length = htons(TE_LINK_SUBTLV_DEF_SIZE);
510 lp->rsc_clsclr.value = htonl(classcolor);
511 return;
512 }
513
514 static void set_linkparams_inter_as(struct mpls_te_link *lp,
515 struct in_addr addr, uint32_t as)
516 {
517
518 /* Set the Remote ASBR IP address and then the associated AS number */
519 lp->rip.header.type = htons(TE_LINK_SUBTLV_RIP);
520 lp->rip.header.length = htons(TE_LINK_SUBTLV_DEF_SIZE);
521 lp->rip.value = addr;
522
523 lp->ras.header.type = htons(TE_LINK_SUBTLV_RAS);
524 lp->ras.header.length = htons(TE_LINK_SUBTLV_DEF_SIZE);
525 lp->ras.value = htonl(as);
526 }
527
528 static void unset_linkparams_inter_as(struct mpls_te_link *lp)
529 {
530
531 /* Reset the Remote ASBR IP address and then the associated AS number */
532 lp->rip.header.type = htons(0);
533 lp->rip.header.length = htons(0);
534 lp->rip.value.s_addr = htonl(0);
535
536 lp->ras.header.type = htons(0);
537 lp->ras.header.length = htons(0);
538 lp->ras.value = htonl(0);
539 }
540
541 void set_linkparams_llri(struct mpls_te_link *lp, uint32_t local,
542 uint32_t remote)
543 {
544
545 lp->llri.header.type = htons(TE_LINK_SUBTLV_LLRI);
546 lp->llri.header.length = htons(TE_LINK_SUBTLV_LLRI_SIZE);
547 lp->llri.local = htonl(local);
548 lp->llri.remote = htonl(remote);
549 }
550
551 void set_linkparams_lrrid(struct mpls_te_link *lp, struct in_addr local,
552 struct in_addr remote)
553 {
554
555 lp->lrrid.header.type = htons(TE_LINK_SUBTLV_LRRID);
556 lp->lrrid.header.length = htons(TE_LINK_SUBTLV_LRRID_SIZE);
557 lp->lrrid.local.s_addr = local.s_addr;
558 lp->lrrid.remote.s_addr = remote.s_addr;
559 }
560
561 static void set_linkparams_av_delay(struct mpls_te_link *lp, uint32_t delay,
562 uint8_t anormal)
563 {
564 uint32_t tmp;
565 /* Note that TLV-length field is the size of array. */
566 lp->av_delay.header.type = htons(TE_LINK_SUBTLV_AV_DELAY);
567 lp->av_delay.header.length = htons(TE_LINK_SUBTLV_DEF_SIZE);
568 tmp = delay & TE_EXT_MASK;
569 if (anormal)
570 tmp |= TE_EXT_ANORMAL;
571 lp->av_delay.value = htonl(tmp);
572 return;
573 }
574
575 static void set_linkparams_mm_delay(struct mpls_te_link *lp, uint32_t low,
576 uint32_t high, uint8_t anormal)
577 {
578 uint32_t tmp;
579 /* Note that TLV-length field is the size of array. */
580 lp->mm_delay.header.type = htons(TE_LINK_SUBTLV_MM_DELAY);
581 lp->mm_delay.header.length = htons(TE_LINK_SUBTLV_MM_DELAY_SIZE);
582 tmp = low & TE_EXT_MASK;
583 if (anormal)
584 tmp |= TE_EXT_ANORMAL;
585 lp->mm_delay.low = htonl(tmp);
586 lp->mm_delay.high = htonl(high);
587 return;
588 }
589
590 static void set_linkparams_delay_var(struct mpls_te_link *lp, uint32_t jitter)
591 {
592 /* Note that TLV-length field is the size of array. */
593 lp->delay_var.header.type = htons(TE_LINK_SUBTLV_DELAY_VAR);
594 lp->delay_var.header.length = htons(TE_LINK_SUBTLV_DEF_SIZE);
595 lp->delay_var.value = htonl(jitter & TE_EXT_MASK);
596 return;
597 }
598
599 static void set_linkparams_pkt_loss(struct mpls_te_link *lp, uint32_t loss,
600 uint8_t anormal)
601 {
602 uint32_t tmp;
603 /* Note that TLV-length field is the size of array. */
604 lp->pkt_loss.header.type = htons(TE_LINK_SUBTLV_PKT_LOSS);
605 lp->pkt_loss.header.length = htons(TE_LINK_SUBTLV_DEF_SIZE);
606 tmp = loss & TE_EXT_MASK;
607 if (anormal)
608 tmp |= TE_EXT_ANORMAL;
609 lp->pkt_loss.value = htonl(tmp);
610 return;
611 }
612
613 static void set_linkparams_res_bw(struct mpls_te_link *lp, float fp)
614 {
615 /* Note that TLV-length field is the size of array. */
616 lp->res_bw.header.type = htons(TE_LINK_SUBTLV_RES_BW);
617 lp->res_bw.header.length = htons(TE_LINK_SUBTLV_DEF_SIZE);
618 lp->res_bw.value = htonf(fp);
619 return;
620 }
621
622 static void set_linkparams_ava_bw(struct mpls_te_link *lp, float fp)
623 {
624 /* Note that TLV-length field is the size of array. */
625 lp->ava_bw.header.type = htons(TE_LINK_SUBTLV_AVA_BW);
626 lp->ava_bw.header.length = htons(TE_LINK_SUBTLV_DEF_SIZE);
627 lp->ava_bw.value = htonf(fp);
628 return;
629 }
630
631 static void set_linkparams_use_bw(struct mpls_te_link *lp, float fp)
632 {
633 /* Note that TLV-length field is the size of array. */
634 lp->use_bw.header.type = htons(TE_LINK_SUBTLV_USE_BW);
635 lp->use_bw.header.length = htons(TE_LINK_SUBTLV_DEF_SIZE);
636 lp->use_bw.value = htonf(fp);
637 return;
638 }
639
640 /* Update TE parameters from Interface */
641 static void update_linkparams(struct mpls_te_link *lp)
642 {
643 int i;
644 struct interface *ifp;
645
646 /* Get the Interface structure */
647 if ((ifp = lp->ifp) == NULL) {
648 if (IS_DEBUG_OSPF_TE)
649 zlog_debug(
650 "OSPF MPLS-TE: Abort update TE parameters: no interface associated to Link Parameters");
651 return;
652 }
653 if (!HAS_LINK_PARAMS(ifp)) {
654 if (IS_DEBUG_OSPF_TE)
655 zlog_debug(
656 "OSPF MPLS-TE: Abort update TE parameters: no Link Parameters for interface");
657 return;
658 }
659
660 /* RFC3630 metrics */
661 if (IS_PARAM_SET(ifp->link_params, LP_ADM_GRP))
662 set_linkparams_rsc_clsclr(lp, ifp->link_params->admin_grp);
663 else
664 TLV_TYPE(lp->rsc_clsclr) = 0;
665
666 if (IS_PARAM_SET(ifp->link_params, LP_MAX_BW))
667 set_linkparams_max_bw(lp, ifp->link_params->max_bw);
668 else
669 TLV_TYPE(lp->max_bw) = 0;
670
671 if (IS_PARAM_SET(ifp->link_params, LP_MAX_RSV_BW))
672 set_linkparams_max_rsv_bw(lp, ifp->link_params->max_rsv_bw);
673 else
674 TLV_TYPE(lp->max_rsv_bw) = 0;
675
676 if (IS_PARAM_SET(ifp->link_params, LP_UNRSV_BW))
677 for (i = 0; i < MAX_CLASS_TYPE; i++)
678 set_linkparams_unrsv_bw(lp, i,
679 ifp->link_params->unrsv_bw[i]);
680 else
681 TLV_TYPE(lp->unrsv_bw) = 0;
682
683 if (IS_PARAM_SET(ifp->link_params, LP_TE_METRIC))
684 set_linkparams_te_metric(lp, ifp->link_params->te_metric);
685 else
686 TLV_TYPE(lp->te_metric) = 0;
687
688 /* TE metric Extensions */
689 if (IS_PARAM_SET(ifp->link_params, LP_DELAY))
690 set_linkparams_av_delay(lp, ifp->link_params->av_delay, 0);
691 else
692 TLV_TYPE(lp->av_delay) = 0;
693
694 if (IS_PARAM_SET(ifp->link_params, LP_MM_DELAY))
695 set_linkparams_mm_delay(lp, ifp->link_params->min_delay,
696 ifp->link_params->max_delay, 0);
697 else
698 TLV_TYPE(lp->mm_delay) = 0;
699
700 if (IS_PARAM_SET(ifp->link_params, LP_DELAY_VAR))
701 set_linkparams_delay_var(lp, ifp->link_params->delay_var);
702 else
703 TLV_TYPE(lp->delay_var) = 0;
704
705 if (IS_PARAM_SET(ifp->link_params, LP_PKT_LOSS))
706 set_linkparams_pkt_loss(lp, ifp->link_params->pkt_loss, 0);
707 else
708 TLV_TYPE(lp->pkt_loss) = 0;
709
710 if (IS_PARAM_SET(ifp->link_params, LP_RES_BW))
711 set_linkparams_res_bw(lp, ifp->link_params->res_bw);
712 else
713 TLV_TYPE(lp->res_bw) = 0;
714
715 if (IS_PARAM_SET(ifp->link_params, LP_AVA_BW))
716 set_linkparams_ava_bw(lp, ifp->link_params->ava_bw);
717 else
718 TLV_TYPE(lp->ava_bw) = 0;
719
720 if (IS_PARAM_SET(ifp->link_params, LP_USE_BW))
721 set_linkparams_use_bw(lp, ifp->link_params->use_bw);
722 else
723 TLV_TYPE(lp->use_bw) = 0;
724
725 /* RFC5392 */
726 if (IS_PARAM_SET(ifp->link_params, LP_RMT_AS)) {
727 /* Flush LSA if it engaged and was previously a STD_TE one */
728 if (IS_STD_TE(lp->type)
729 && CHECK_FLAG(lp->flags, LPFLG_LSA_ENGAGED)) {
730 if (IS_DEBUG_OSPF_TE)
731 zlog_debug(
732 "OSPF MPLS-TE Update IF: Switch from Standard LSA to INTER-AS for %s[%d/%d]",
733 ifp->name, lp->flags, lp->type);
734
735 ospf_mpls_te_lsa_schedule(lp, FLUSH_THIS_LSA);
736 /* Then, switch it to INTER-AS */
737 if (OspfMplsTE.inter_as == AS)
738 lp->flags = INTER_AS | FLOOD_AS;
739 else {
740 lp->flags = INTER_AS | FLOOD_AREA;
741 lp->area = ospf_area_lookup_by_area_id(
742 ospf_lookup_by_vrf_id(VRF_DEFAULT),
743 OspfMplsTE.interas_areaid);
744 }
745 }
746 set_linkparams_inter_as(lp, ifp->link_params->rmt_ip,
747 ifp->link_params->rmt_as);
748 } else {
749 if (IS_DEBUG_OSPF_TE)
750 zlog_debug(
751 "OSPF MPLS-TE Update IF: Switch from INTER-AS LSA to Standard for %s[%d/%d]",
752 ifp->name, lp->flags, lp->type);
753
754 /* reset inter-as TE params */
755 /* Flush LSA if it engaged and was previously an INTER_AS one */
756 if (IS_INTER_AS(lp->type)
757 && CHECK_FLAG(lp->flags, LPFLG_LSA_ENGAGED)) {
758 ospf_mpls_te_lsa_schedule(lp, FLUSH_THIS_LSA);
759 /* Then, switch it to Standard TE */
760 lp->flags = STD_TE | FLOOD_AREA;
761 }
762 unset_linkparams_inter_as(lp);
763 }
764 }
765
766 static void initialize_linkparams(struct mpls_te_link *lp)
767 {
768 struct interface *ifp = lp->ifp;
769 struct ospf_interface *oi = NULL;
770 struct route_node *rn;
771
772 if (IS_DEBUG_OSPF_TE)
773 zlog_debug(
774 "MPLS-TE(initialize_linkparams) Initialize Link Parameters for interface %s",
775 ifp->name);
776
777 /* Search OSPF Interface parameters for this interface */
778 for (rn = route_top(IF_OIFS(ifp)); rn; rn = route_next(rn)) {
779
780 if ((oi = rn->info) == NULL)
781 continue;
782
783 if (oi->ifp == ifp)
784 break;
785 }
786
787 if ((oi == NULL) || (oi->ifp != ifp)) {
788 if (IS_DEBUG_OSPF_TE)
789 zlog_debug(
790 "MPLS-TE(initialize_linkparams) Could not find corresponding OSPF Interface for %s",
791 ifp->name);
792 return;
793 }
794
795 /*
796 * Try to set initial values those can be derived from
797 * zebra-interface information.
798 */
799 set_linkparams_link_type(oi, lp);
800
801 /* Set local IP addr */
802 set_linkparams_lclif_ipaddr(lp, oi->address->u.prefix4);
803
804 /* Set Remote IP addr if Point to Point Interface */
805 if (oi->type == OSPF_IFTYPE_POINTOPOINT) {
806 struct prefix *pref = CONNECTED_PREFIX(oi->connected);
807 if (pref != NULL)
808 set_linkparams_rmtif_ipaddr(lp, pref->u.prefix4);
809 }
810
811 /* Keep Area information in combination with link parameters. */
812 lp->area = oi->area;
813
814 return;
815 }
816
817 static int is_mandated_params_set(struct mpls_te_link *lp)
818 {
819 int rc = 0;
820
821 if (ntohs(OspfMplsTE.router_addr.header.type) == 0) {
822 flog_warn(
823 EC_OSPF_TE_UNEXPECTED,
824 "MPLS-TE(is_mandated_params_set) Missing Router Address");
825 return rc;
826 }
827
828 if (ntohs(lp->link_type.header.type) == 0) {
829 flog_warn(EC_OSPF_TE_UNEXPECTED,
830 "MPLS-TE(is_mandated_params_set) Missing Link Type");
831 return rc;
832 }
833
834 if (!IS_INTER_AS(lp->type) && (ntohs(lp->link_id.header.type) == 0)) {
835 flog_warn(EC_OSPF_TE_UNEXPECTED,
836 "MPLS-TE(is_mandated_params_set) Missing Link ID");
837 return rc;
838 }
839
840 rc = 1;
841 return rc;
842 }
843
844 /*------------------------------------------------------------------------*
845 * Followings are callback functions against generic Opaque-LSAs handling.
846 *------------------------------------------------------------------------*/
847
848 static int ospf_mpls_te_new_if(struct interface *ifp)
849 {
850 struct mpls_te_link *new;
851
852 if (IS_DEBUG_OSPF_TE)
853 zlog_debug(
854 "MPLS-TE(ospf_mpls_te_new_if) Add new %s interface %s to MPLS-TE list",
855 ifp->link_params ? "Active" : "Inactive", ifp->name);
856
857 if (lookup_linkparams_by_ifp(ifp) != NULL)
858 return 0;
859
860 new = XCALLOC(MTYPE_OSPF_MPLS_TE, sizeof(struct mpls_te_link));
861
862 new->instance = get_mpls_te_instance_value();
863 new->ifp = ifp;
864 /* By default TE-Link is RFC3630 compatible flooding in Area and not
865 * active */
866 /* This default behavior will be adapted with call to
867 * ospf_mpls_te_update_if() */
868 new->type = STD_TE | FLOOD_AREA;
869 new->flags = LPFLG_LSA_INACTIVE;
870
871 /* Initialize Link Parameters from Interface */
872 initialize_linkparams(new);
873
874 /* Set TE Parameters from Interface */
875 update_linkparams(new);
876
877 /* Add Link Parameters structure to the list */
878 listnode_add(OspfMplsTE.iflist, new);
879
880 if (IS_DEBUG_OSPF_TE)
881 zlog_debug(
882 "OSPF MPLS-TE New IF: Add new LP context for %s[%d/%d]",
883 ifp->name, new->flags, new->type);
884
885 /* Schedule Opaque-LSA refresh. */ /* XXX */
886 return 0;
887 }
888
889 static int ospf_mpls_te_del_if(struct interface *ifp)
890 {
891 struct mpls_te_link *lp;
892 int rc = -1;
893
894 if ((lp = lookup_linkparams_by_ifp(ifp)) != NULL) {
895 struct list *iflist = OspfMplsTE.iflist;
896
897 /* Dequeue listnode entry from the list. */
898 listnode_delete(iflist, lp);
899
900 /* Avoid misjudgement in the next lookup. */
901 if (listcount(iflist) == 0)
902 iflist->head = iflist->tail = NULL;
903
904 XFREE(MTYPE_OSPF_MPLS_TE, lp);
905 }
906
907 /* Schedule Opaque-LSA refresh. */ /* XXX */
908
909 rc = 0;
910 return rc;
911 }
912
913 /* Main initialization / update function of the MPLS TE Link context */
914
915 /* Call when interface TE Link parameters are modified */
916 void ospf_mpls_te_update_if(struct interface *ifp)
917 {
918 struct mpls_te_link *lp;
919
920 if (IS_DEBUG_OSPF_TE)
921 zlog_debug(
922 "OSPF MPLS-TE: Update LSA parameters for interface %s [%s]",
923 ifp->name, HAS_LINK_PARAMS(ifp) ? "ON" : "OFF");
924
925 /* Get Link context from interface */
926 if ((lp = lookup_linkparams_by_ifp(ifp)) == NULL) {
927 flog_warn(
928 EC_OSPF_TE_UNEXPECTED,
929 "OSPF MPLS-TE Update: Did not find Link Parameters context for interface %s",
930 ifp->name);
931 return;
932 }
933
934 /* Fulfill MPLS-TE Link TLV from Interface TE Link parameters */
935 if (HAS_LINK_PARAMS(ifp)) {
936 SET_FLAG(lp->flags, LPFLG_LSA_ACTIVE);
937
938 /* Update TE parameters */
939 update_linkparams(lp);
940
941 /* Finally Re-Originate or Refresh Opaque LSA if MPLS_TE is
942 * enabled */
943 if (OspfMplsTE.enabled)
944 if (lp->area != NULL) {
945 if (CHECK_FLAG(lp->flags, LPFLG_LSA_ENGAGED))
946 ospf_mpls_te_lsa_schedule(
947 lp, REFRESH_THIS_LSA);
948 else
949 ospf_mpls_te_lsa_schedule(
950 lp, REORIGINATE_THIS_LSA);
951 }
952 } else {
953 /* If MPLS TE is disable on this interface, flush LSA if it is
954 * already engaged */
955 if (CHECK_FLAG(lp->flags, LPFLG_LSA_ENGAGED))
956 ospf_mpls_te_lsa_schedule(lp, FLUSH_THIS_LSA);
957 else
958 /* Reset Activity flag */
959 lp->flags = LPFLG_LSA_INACTIVE;
960 }
961
962 return;
963 }
964
965 static void ospf_mpls_te_ism_change(struct ospf_interface *oi, int old_state)
966 {
967 struct te_link_subtlv_link_type old_type;
968 struct te_link_subtlv_link_id old_id;
969 struct mpls_te_link *lp;
970
971 if ((lp = lookup_linkparams_by_ifp(oi->ifp)) == NULL) {
972 flog_warn(
973 EC_OSPF_TE_UNEXPECTED,
974 "ospf_mpls_te_ism_change: Cannot get linkparams from OI(%s)?",
975 IF_NAME(oi));
976 return;
977 }
978
979 if (oi->area == NULL || oi->area->ospf == NULL) {
980 flog_warn(
981 EC_OSPF_TE_UNEXPECTED,
982 "ospf_mpls_te_ism_change: Cannot refer to OSPF from OI(%s)?",
983 IF_NAME(oi));
984 return;
985 }
986 #ifdef notyet
987 if ((lp->area != NULL
988 && !IPV4_ADDR_SAME(&lp->area->area_id, &oi->area->area_id))
989 || (lp->area != NULL && oi->area == NULL)) {
990 /* How should we consider this case? */
991 flog_warn(
992 EC_OSPF_TE_UNEXPECTED,
993 "MPLS-TE: Area for OI(%s) has changed to [%s], flush previous LSAs",
994 IF_NAME(oi),
995 oi->area ? inet_ntoa(oi->area->area_id) : "N/A");
996 ospf_mpls_te_lsa_schedule(lp, FLUSH_THIS_LSA);
997 }
998 #endif
999 /* Keep Area information in combination with linkparams. */
1000 lp->area = oi->area;
1001
1002 /* Keep interface MPLS-TE status */
1003 lp->flags = HAS_LINK_PARAMS(oi->ifp);
1004
1005 switch (oi->state) {
1006 case ISM_PointToPoint:
1007 case ISM_DROther:
1008 case ISM_Backup:
1009 case ISM_DR:
1010 old_type = lp->link_type;
1011 old_id = lp->link_id;
1012
1013 /* Set Link type, Link ID, Local and Remote IP addr */
1014 set_linkparams_link_type(oi, lp);
1015 set_linkparams_link_id(oi, lp);
1016 set_linkparams_lclif_ipaddr(lp, oi->address->u.prefix4);
1017
1018 if (oi->type == LINK_TYPE_SUBTLV_VALUE_PTP) {
1019 struct prefix *pref = CONNECTED_PREFIX(oi->connected);
1020 if (pref != NULL)
1021 set_linkparams_rmtif_ipaddr(lp,
1022 pref->u.prefix4);
1023 }
1024
1025 /* Update TE parameters */
1026 update_linkparams(lp);
1027
1028 /* Try to Schedule LSA */
1029 if ((ntohs(old_type.header.type)
1030 != ntohs(lp->link_type.header.type)
1031 || old_type.link_type.value
1032 != lp->link_type.link_type.value)
1033 || (ntohs(old_id.header.type)
1034 != ntohs(lp->link_id.header.type)
1035 || ntohl(old_id.value.s_addr)
1036 != ntohl(lp->link_id.value.s_addr))) {
1037 if (CHECK_FLAG(lp->flags, LPFLG_LSA_ENGAGED))
1038 ospf_mpls_te_lsa_schedule(lp, REFRESH_THIS_LSA);
1039 else
1040 ospf_mpls_te_lsa_schedule(lp,
1041 REORIGINATE_THIS_LSA);
1042 }
1043 break;
1044 default:
1045 lp->link_type.header.type = htons(0);
1046 lp->link_id.header.type = htons(0);
1047
1048 if (CHECK_FLAG(lp->flags, LPFLG_LSA_ENGAGED))
1049 ospf_mpls_te_lsa_schedule(lp, FLUSH_THIS_LSA);
1050 break;
1051 }
1052
1053 return;
1054 }
1055
1056 static void ospf_mpls_te_nsm_change(struct ospf_neighbor *nbr, int old_state)
1057 {
1058 /* Nothing to do here */
1059 return;
1060 }
1061
1062 /*------------------------------------------------------------------------*
1063 * Followings are OSPF protocol processing functions for MPLS-TE.
1064 *------------------------------------------------------------------------*/
1065
1066 static void build_tlv_header(struct stream *s, struct tlv_header *tlvh)
1067 {
1068 stream_put(s, tlvh, sizeof(struct tlv_header));
1069 return;
1070 }
1071
1072 static void build_router_tlv(struct stream *s)
1073 {
1074 struct tlv_header *tlvh = &OspfMplsTE.router_addr.header;
1075 if (ntohs(tlvh->type) != 0) {
1076 build_tlv_header(s, tlvh);
1077 stream_put(s, TLV_DATA(tlvh), TLV_BODY_SIZE(tlvh));
1078 }
1079 return;
1080 }
1081
1082 static void build_link_subtlv(struct stream *s, struct tlv_header *tlvh)
1083 {
1084
1085 if ((tlvh != NULL) && (ntohs(tlvh->type) != 0)) {
1086 build_tlv_header(s, tlvh);
1087 stream_put(s, TLV_DATA(tlvh), TLV_BODY_SIZE(tlvh));
1088 }
1089 return;
1090 }
1091
1092 static void build_link_tlv(struct stream *s, struct mpls_te_link *lp)
1093 {
1094 set_linkparams_link_header(lp);
1095 build_tlv_header(s, &lp->link_header.header);
1096
1097 build_link_subtlv(s, &lp->link_type.header);
1098 build_link_subtlv(s, &lp->link_id.header);
1099 build_link_subtlv(s, &lp->lclif_ipaddr.header);
1100 build_link_subtlv(s, &lp->rmtif_ipaddr.header);
1101 build_link_subtlv(s, &lp->te_metric.header);
1102 build_link_subtlv(s, &lp->max_bw.header);
1103 build_link_subtlv(s, &lp->max_rsv_bw.header);
1104 build_link_subtlv(s, &lp->unrsv_bw.header);
1105 build_link_subtlv(s, &lp->rsc_clsclr.header);
1106 build_link_subtlv(s, &lp->lrrid.header);
1107 build_link_subtlv(s, &lp->llri.header);
1108 build_link_subtlv(s, &lp->rip.header);
1109 build_link_subtlv(s, &lp->ras.header);
1110 build_link_subtlv(s, &lp->av_delay.header);
1111 build_link_subtlv(s, &lp->mm_delay.header);
1112 build_link_subtlv(s, &lp->delay_var.header);
1113 build_link_subtlv(s, &lp->pkt_loss.header);
1114 build_link_subtlv(s, &lp->res_bw.header);
1115 build_link_subtlv(s, &lp->ava_bw.header);
1116 build_link_subtlv(s, &lp->use_bw.header);
1117
1118 return;
1119 }
1120
1121 static void ospf_mpls_te_lsa_body_set(struct stream *s, struct mpls_te_link *lp)
1122 {
1123 /*
1124 * The router address TLV is type 1, and ...
1125 * It must appear in exactly one
1126 * Traffic Engineering LSA originated by a router.
1127 */
1128 build_router_tlv(s);
1129
1130 /*
1131 * Only one Link TLV shall be carried in each LSA, allowing for fine
1132 * granularity changes in topology.
1133 */
1134 build_link_tlv(s, lp);
1135 return;
1136 }
1137
1138 /* Create new opaque-LSA. */
1139 static struct ospf_lsa *ospf_mpls_te_lsa_new(struct ospf *ospf,
1140 struct ospf_area *area,
1141 struct mpls_te_link *lp)
1142 {
1143 struct stream *s;
1144 struct lsa_header *lsah;
1145 struct ospf_lsa *new = NULL;
1146 uint8_t options, lsa_type = 0;
1147 struct in_addr lsa_id;
1148 uint32_t tmp;
1149 uint16_t length;
1150
1151 /* Create a stream for LSA. */
1152 s = stream_new(OSPF_MAX_LSA_SIZE);
1153 lsah = (struct lsa_header *)STREAM_DATA(s);
1154
1155 options = OSPF_OPTION_O; /* Don't forget this :-) */
1156
1157 /* Set opaque-LSA header fields depending of the type of RFC */
1158 if (IS_INTER_AS(lp->type)) {
1159 if (IS_FLOOD_AS(lp->type)) {
1160 /* Enable AS external as we flood Inter-AS with Opaque
1161 * Type 11
1162 */
1163 options |= OSPF_OPTION_E;
1164 lsa_type = OSPF_OPAQUE_AS_LSA;
1165 } else {
1166 options |= LSA_OPTIONS_GET(
1167 area); /* Get area default option */
1168 options |= LSA_OPTIONS_NSSA_GET(area);
1169 lsa_type = OSPF_OPAQUE_AREA_LSA;
1170 }
1171 tmp = SET_OPAQUE_LSID(OPAQUE_TYPE_INTER_AS_LSA, lp->instance);
1172 lsa_id.s_addr = htonl(tmp);
1173
1174 if (!ospf) {
1175 stream_free(s);
1176 return NULL;
1177 }
1178
1179 lsa_header_set(s, options, lsa_type, lsa_id, ospf->router_id);
1180 } else {
1181 options |= LSA_OPTIONS_GET(area); /* Get area default option */
1182 options |= LSA_OPTIONS_NSSA_GET(area);
1183 lsa_type = OSPF_OPAQUE_AREA_LSA;
1184 tmp = SET_OPAQUE_LSID(OPAQUE_TYPE_TRAFFIC_ENGINEERING_LSA,
1185 lp->instance);
1186 lsa_id.s_addr = htonl(tmp);
1187 lsa_header_set(s, options, lsa_type, lsa_id,
1188 area->ospf->router_id);
1189 }
1190
1191 if (IS_DEBUG_OSPF(lsa, LSA_GENERATE))
1192 zlog_debug(
1193 "LSA[Type%d:%s]: Create an Opaque-LSA/MPLS-TE instance",
1194 lsa_type, inet_ntoa(lsa_id));
1195
1196 /* Set opaque-LSA body fields. */
1197 ospf_mpls_te_lsa_body_set(s, lp);
1198
1199 /* Set length. */
1200 length = stream_get_endp(s);
1201 lsah->length = htons(length);
1202
1203 /* Now, create an OSPF LSA instance. */
1204 new = ospf_lsa_new_and_data(length);
1205
1206 new->vrf_id = ospf->vrf_id;
1207 if (area && area->ospf)
1208 new->vrf_id = area->ospf->vrf_id;
1209 new->area = area;
1210 SET_FLAG(new->flags, OSPF_LSA_SELF);
1211 memcpy(new->data, lsah, length);
1212 stream_free(s);
1213
1214 return new;
1215 }
1216
1217 static int ospf_mpls_te_lsa_originate1(struct ospf_area *area,
1218 struct mpls_te_link *lp)
1219 {
1220 struct ospf_lsa *new = NULL;
1221 int rc = -1;
1222
1223 /* Create new Opaque-LSA/MPLS-TE instance. */
1224 new = ospf_mpls_te_lsa_new(area->ospf, area, lp);
1225 if (new == NULL) {
1226 flog_warn(
1227 EC_OSPF_TE_UNEXPECTED,
1228 "ospf_mpls_te_lsa_originate1: ospf_mpls_te_lsa_new() ?");
1229 return rc;
1230 }
1231
1232 /* Install this LSA into LSDB. */
1233 if (ospf_lsa_install(area->ospf, NULL /*oi*/, new) == NULL) {
1234 flog_warn(EC_OSPF_LSA_INSTALL_FAILURE,
1235 "ospf_mpls_te_lsa_originate1: ospf_lsa_install() ?");
1236 ospf_lsa_unlock(&new);
1237 return rc;
1238 }
1239
1240 /* Now this link-parameter entry has associated LSA. */
1241 SET_FLAG(lp->flags, LPFLG_LSA_ENGAGED);
1242 /* Update new LSA origination count. */
1243 area->ospf->lsa_originate_count++;
1244
1245 /* Flood new LSA through area. */
1246 ospf_flood_through_area(area, NULL /*nbr*/, new);
1247
1248 if (IS_DEBUG_OSPF(lsa, LSA_GENERATE)) {
1249 char area_id[INET_ADDRSTRLEN];
1250 strlcpy(area_id, inet_ntoa(area->area_id), sizeof(area_id));
1251 zlog_debug(
1252 "LSA[Type%d:%s]: Originate Opaque-LSA/MPLS-TE: Area(%s), Link(%s)",
1253 new->data->type, inet_ntoa(new->data->id), area_id,
1254 lp->ifp->name);
1255 ospf_lsa_header_dump(new->data);
1256 }
1257
1258 rc = 0;
1259 return rc;
1260 }
1261
1262 static int ospf_mpls_te_lsa_originate_area(void *arg)
1263 {
1264 struct ospf_area *area = (struct ospf_area *)arg;
1265 struct listnode *node, *nnode;
1266 struct mpls_te_link *lp;
1267 int rc = -1;
1268
1269 if (!OspfMplsTE.enabled) {
1270 zlog_info(
1271 "ospf_mpls_te_lsa_originate_area: MPLS-TE is disabled now.");
1272 rc = 0; /* This is not an error case. */
1273 return rc;
1274 }
1275
1276 for (ALL_LIST_ELEMENTS(OspfMplsTE.iflist, node, nnode, lp)) {
1277 /* Process only enabled LSA with area scope flooding */
1278 if (!CHECK_FLAG(lp->flags, LPFLG_LSA_ACTIVE)
1279 || IS_FLOOD_AS(lp->type))
1280 continue;
1281
1282 if (lp->area == NULL)
1283 continue;
1284
1285 if (!IPV4_ADDR_SAME(&lp->area->area_id, &area->area_id))
1286 continue;
1287
1288 if (CHECK_FLAG(lp->flags, LPFLG_LSA_ENGAGED)) {
1289 if (CHECK_FLAG(lp->flags, LPFLG_LSA_FORCED_REFRESH)) {
1290 UNSET_FLAG(lp->flags, LPFLG_LSA_FORCED_REFRESH);
1291 zlog_info(
1292 "OSPF MPLS-TE (ospf_mpls_te_lsa_originate_area): Refresh instead of Originate");
1293 ospf_mpls_te_lsa_schedule(lp, REFRESH_THIS_LSA);
1294 }
1295 continue;
1296 }
1297
1298 if (!is_mandated_params_set(lp)) {
1299 zlog_info(
1300 "ospf_mpls_te_lsa_originate_area: Link(%s) lacks some mandated MPLS-TE parameters.",
1301 lp->ifp ? lp->ifp->name : "?");
1302 continue;
1303 }
1304
1305 /* Ok, let's try to originate an LSA for this area and Link. */
1306 if (IS_DEBUG_OSPF_TE)
1307 zlog_debug(
1308 "MPLS-TE(ospf_mpls_te_lsa_originate_area) Let's finally reoriginate the LSA %d through the Area %s for Link %s",
1309 lp->instance, inet_ntoa(area->area_id),
1310 lp->ifp ? lp->ifp->name : "?");
1311 if (ospf_mpls_te_lsa_originate1(area, lp) != 0)
1312 return rc;
1313 }
1314
1315 rc = 0;
1316 return rc;
1317 }
1318
1319 static int ospf_mpls_te_lsa_originate2(struct ospf *top,
1320 struct mpls_te_link *lp)
1321 {
1322 struct ospf_lsa *new;
1323 int rc = -1;
1324
1325 /* Create new Opaque-LSA/Inter-AS instance. */
1326 new = ospf_mpls_te_lsa_new(top, NULL, lp);
1327 if (new == NULL) {
1328 flog_warn(
1329 EC_OSPF_LSA_UNEXPECTED,
1330 "ospf_mpls_te_lsa_originate2: ospf_router_info_lsa_new() ?");
1331 return rc;
1332 }
1333 new->vrf_id = top->vrf_id;
1334
1335 /* Install this LSA into LSDB. */
1336 if (ospf_lsa_install(top, NULL /*oi */, new) == NULL) {
1337 flog_warn(EC_OSPF_LSA_INSTALL_FAILURE,
1338 "ospf_mpls_te_lsa_originate2: ospf_lsa_install() ?");
1339 ospf_lsa_unlock(&new);
1340 return rc;
1341 }
1342
1343 /* Now this Router Info parameter entry has associated LSA. */
1344 SET_FLAG(lp->flags, LPFLG_LSA_ENGAGED);
1345 /* Update new LSA origination count. */
1346 top->lsa_originate_count++;
1347
1348 /* Flood new LSA through AS. */
1349 ospf_flood_through_as(top, NULL /*nbr */, new);
1350
1351 if (IS_DEBUG_OSPF(lsa, LSA_GENERATE)) {
1352 zlog_debug(
1353 "LSA[Type%d:%s]: Originate Opaque-LSA/MPLS-TE Inter-AS",
1354 new->data->type, inet_ntoa(new->data->id));
1355 ospf_lsa_header_dump(new->data);
1356 }
1357
1358 rc = 0;
1359 return rc;
1360 }
1361
1362 static int ospf_mpls_te_lsa_originate_as(void *arg)
1363 {
1364 struct ospf *top;
1365 struct ospf_area *area;
1366 struct listnode *node, *nnode;
1367 struct mpls_te_link *lp;
1368 int rc = -1;
1369
1370 if ((!OspfMplsTE.enabled) || (OspfMplsTE.inter_as == Off)) {
1371 zlog_info(
1372 "ospf_mpls_te_lsa_originate_as: MPLS-TE Inter-AS is disabled for now.");
1373 rc = 0; /* This is not an error case. */
1374 return rc;
1375 }
1376
1377 for (ALL_LIST_ELEMENTS(OspfMplsTE.iflist, node, nnode, lp)) {
1378 /* Process only enabled INTER_AS Links or Pseudo-Links */
1379 if (!CHECK_FLAG(lp->flags, LPFLG_LSA_ACTIVE)
1380 || !IS_INTER_AS(lp->type))
1381 continue;
1382
1383 if (CHECK_FLAG(lp->flags, LPFLG_LSA_ENGAGED)) {
1384 if (CHECK_FLAG(lp->flags, LPFLG_LSA_FORCED_REFRESH)) {
1385 UNSET_FLAG(lp->flags, LPFLG_LSA_FORCED_REFRESH);
1386 ospf_mpls_te_lsa_schedule(lp, REFRESH_THIS_LSA);
1387 }
1388 continue;
1389 }
1390
1391 if (!is_mandated_params_set(lp)) {
1392 flog_warn(
1393 EC_OSPF_TE_UNEXPECTED,
1394 "ospf_mpls_te_lsa_originate_as: Link(%s) lacks some mandated MPLS-TE parameters.",
1395 lp->ifp ? lp->ifp->name : "?");
1396 continue;
1397 }
1398
1399 /* Ok, let's try to originate an LSA for this AS and Link. */
1400 if (IS_DEBUG_OSPF_TE)
1401 zlog_debug(
1402 "MPLS-TE(ospf_mpls_te_lsa_originate_as) Let's finally re-originate the Inter-AS LSA %d through the %s for Link %s",
1403 lp->instance,
1404 IS_FLOOD_AS(lp->type) ? "AS" : "Area",
1405 lp->ifp ? lp->ifp->name : "Unknown");
1406
1407 if (IS_FLOOD_AS(lp->type)) {
1408 top = (struct ospf *)arg;
1409 ospf_mpls_te_lsa_originate2(top, lp);
1410 } else {
1411 area = (struct ospf_area *)arg;
1412 ospf_mpls_te_lsa_originate1(area, lp);
1413 }
1414 }
1415
1416 rc = 0;
1417 return rc;
1418 }
1419
1420 static struct ospf_lsa *ospf_mpls_te_lsa_refresh(struct ospf_lsa *lsa)
1421 {
1422 struct mpls_te_link *lp;
1423 struct ospf_area *area = lsa->area;
1424 struct ospf *top;
1425 struct ospf_lsa *new = NULL;
1426
1427 if (!OspfMplsTE.enabled) {
1428 /*
1429 * This LSA must have flushed before due to MPLS-TE status
1430 * change.
1431 * It seems a slip among routers in the routing domain.
1432 */
1433 zlog_info("ospf_mpls_te_lsa_refresh: MPLS-TE is disabled now.");
1434 lsa->data->ls_age =
1435 htons(OSPF_LSA_MAXAGE); /* Flush it anyway. */
1436 }
1437
1438 /* At first, resolve lsa/lp relationship. */
1439 if ((lp = lookup_linkparams_by_instance(lsa)) == NULL) {
1440 flog_warn(EC_OSPF_TE_UNEXPECTED,
1441 "ospf_mpls_te_lsa_refresh: Invalid parameter?");
1442 lsa->data->ls_age =
1443 htons(OSPF_LSA_MAXAGE); /* Flush it anyway. */
1444 ospf_opaque_lsa_flush_schedule(lsa);
1445 return NULL;
1446 }
1447
1448 /* Check if lp was not disable in the interval */
1449 if (!CHECK_FLAG(lp->flags, LPFLG_LSA_ACTIVE)) {
1450 flog_warn(
1451 EC_OSPF_TE_UNEXPECTED,
1452 "ospf_mpls_te_lsa_refresh: lp was disabled: Flush it!");
1453 lsa->data->ls_age =
1454 htons(OSPF_LSA_MAXAGE); /* Flush it anyway. */
1455 }
1456
1457 /* If the lsa's age reached to MaxAge, start flushing procedure. */
1458 if (IS_LSA_MAXAGE(lsa)) {
1459 UNSET_FLAG(lp->flags, LPFLG_LSA_ENGAGED);
1460 ospf_opaque_lsa_flush_schedule(lsa);
1461 return NULL;
1462 }
1463 top = ospf_lookup_by_vrf_id(lsa->vrf_id);
1464 /* Create new Opaque-LSA/MPLS-TE instance. */
1465 new = ospf_mpls_te_lsa_new(top, area, lp);
1466 if (new == NULL) {
1467 flog_warn(EC_OSPF_TE_UNEXPECTED,
1468 "ospf_mpls_te_lsa_refresh: ospf_mpls_te_lsa_new() ?");
1469 return NULL;
1470 }
1471 new->data->ls_seqnum = lsa_seqnum_increment(lsa);
1472
1473 /* Install this LSA into LSDB. */
1474 /* Given "lsa" will be freed in the next function. */
1475 /* As area could be NULL i.e. when using OPAQUE_LSA_AS, we prefer to use
1476 * ospf_lookup() to get ospf instance */
1477 if (area)
1478 top = area->ospf;
1479
1480 if (ospf_lsa_install(top, NULL /*oi */, new) == NULL) {
1481 flog_warn(EC_OSPF_LSA_INSTALL_FAILURE,
1482 "ospf_mpls_te_lsa_refresh: ospf_lsa_install() ?");
1483 ospf_lsa_unlock(&new);
1484 return NULL;
1485 }
1486
1487 /* Flood updated LSA through AS or Area depending of the RFC of the link
1488 */
1489 if (IS_FLOOD_AS(lp->type))
1490 ospf_flood_through_as(top, NULL, new);
1491 else
1492 ospf_flood_through_area(area, NULL /*nbr*/, new);
1493
1494 /* Debug logging. */
1495 if (IS_DEBUG_OSPF(lsa, LSA_GENERATE)) {
1496 zlog_debug("LSA[Type%d:%s]: Refresh Opaque-LSA/MPLS-TE",
1497 new->data->type, inet_ntoa(new->data->id));
1498 ospf_lsa_header_dump(new->data);
1499 }
1500
1501 return new;
1502 }
1503
1504 void ospf_mpls_te_lsa_schedule(struct mpls_te_link *lp, enum lsa_opcode opcode)
1505 {
1506 struct ospf_lsa lsa;
1507 struct lsa_header lsah;
1508 struct ospf *top;
1509 uint32_t tmp;
1510
1511 memset(&lsa, 0, sizeof(lsa));
1512 memset(&lsah, 0, sizeof(lsah));
1513 top = ospf_lookup_by_vrf_id(VRF_DEFAULT);
1514
1515 /* Check if the pseudo link is ready to flood */
1516 if (!(CHECK_FLAG(lp->flags, LPFLG_LSA_ACTIVE))
1517 || !(IS_FLOOD_AREA(lp->type) || IS_FLOOD_AS(lp->type))) {
1518 return;
1519 }
1520
1521 lsa.area = lp->area;
1522 lsa.data = &lsah;
1523 if (IS_FLOOD_AS(lp->type)) {
1524 lsah.type = OSPF_OPAQUE_AS_LSA;
1525 tmp = SET_OPAQUE_LSID(OPAQUE_TYPE_INTER_AS_LSA, lp->instance);
1526 lsah.id.s_addr = htonl(tmp);
1527 } else {
1528 lsah.type = OSPF_OPAQUE_AREA_LSA;
1529 if (IS_INTER_AS(lp->type)) {
1530 /* Set the area context if not know */
1531 if (lp->area == NULL)
1532 lp->area = ospf_area_lookup_by_area_id(
1533 top, OspfMplsTE.interas_areaid);
1534 /* Unable to set the area context. Abort! */
1535 if (lp->area == NULL) {
1536 flog_warn(
1537 EC_OSPF_TE_UNEXPECTED,
1538 "MPLS-TE(ospf_mpls_te_lsa_schedule) Area context is null. Abort !");
1539 return;
1540 }
1541 tmp = SET_OPAQUE_LSID(OPAQUE_TYPE_INTER_AS_LSA,
1542 lp->instance);
1543 } else
1544 tmp = SET_OPAQUE_LSID(
1545 OPAQUE_TYPE_TRAFFIC_ENGINEERING_LSA,
1546 lp->instance);
1547 lsah.id.s_addr = htonl(tmp);
1548 }
1549
1550 switch (opcode) {
1551 case REORIGINATE_THIS_LSA:
1552 if (IS_FLOOD_AS(lp->type)) {
1553 ospf_opaque_lsa_reoriginate_schedule(
1554 (void *)top, OSPF_OPAQUE_AS_LSA,
1555 OPAQUE_TYPE_INTER_AS_LSA);
1556 break;
1557 }
1558
1559 if (IS_FLOOD_AREA(lp->type)) {
1560 if (IS_INTER_AS(lp->type))
1561 ospf_opaque_lsa_reoriginate_schedule(
1562 (void *)lp->area, OSPF_OPAQUE_AREA_LSA,
1563 OPAQUE_TYPE_INTER_AS_LSA);
1564 else
1565 ospf_opaque_lsa_reoriginate_schedule(
1566 (void *)lp->area, OSPF_OPAQUE_AREA_LSA,
1567 OPAQUE_TYPE_TRAFFIC_ENGINEERING_LSA);
1568 break;
1569 }
1570 break;
1571 case REFRESH_THIS_LSA:
1572 ospf_opaque_lsa_refresh_schedule(&lsa);
1573 break;
1574 case FLUSH_THIS_LSA:
1575 /* Reset Activity flag */
1576 lp->flags = LPFLG_LSA_INACTIVE;
1577 ospf_opaque_lsa_flush_schedule(&lsa);
1578 break;
1579 default:
1580 flog_warn(EC_OSPF_TE_UNEXPECTED,
1581 "ospf_mpls_te_lsa_schedule: Unknown opcode (%u)",
1582 opcode);
1583 break;
1584 }
1585
1586 return;
1587 }
1588
1589
1590 /*------------------------------------------------------------------------*
1591 * Followings are vty session control functions.
1592 *------------------------------------------------------------------------*/
1593
1594 static uint16_t show_vty_router_addr(struct vty *vty, struct tlv_header *tlvh)
1595 {
1596 struct te_tlv_router_addr *top = (struct te_tlv_router_addr *)tlvh;
1597
1598 if (vty != NULL)
1599 vty_out(vty, " Router-Address: %s\n", inet_ntoa(top->value));
1600 else
1601 zlog_debug(" Router-Address: %s", inet_ntoa(top->value));
1602
1603 return TLV_SIZE(tlvh);
1604 }
1605
1606 static uint16_t show_vty_link_header(struct vty *vty, struct tlv_header *tlvh)
1607 {
1608 struct te_tlv_link *top = (struct te_tlv_link *)tlvh;
1609
1610 if (vty != NULL)
1611 vty_out(vty, " Link: %u octets of data\n",
1612 ntohs(top->header.length));
1613 else
1614 zlog_debug(" Link: %u octets of data",
1615 ntohs(top->header.length));
1616
1617 return TLV_HDR_SIZE; /* Here is special, not "TLV_SIZE". */
1618 }
1619
1620 static uint16_t show_vty_link_subtlv_link_type(struct vty *vty,
1621 struct tlv_header *tlvh)
1622 {
1623 struct te_link_subtlv_link_type *top;
1624 const char *cp = "Unknown";
1625
1626 top = (struct te_link_subtlv_link_type *)tlvh;
1627 switch (top->link_type.value) {
1628 case LINK_TYPE_SUBTLV_VALUE_PTP:
1629 cp = "Point-to-point";
1630 break;
1631 case LINK_TYPE_SUBTLV_VALUE_MA:
1632 cp = "Multiaccess";
1633 break;
1634 default:
1635 break;
1636 }
1637
1638 if (vty != NULL)
1639 vty_out(vty, " Link-Type: %s (%u)\n", cp,
1640 top->link_type.value);
1641 else
1642 zlog_debug(" Link-Type: %s (%u)", cp, top->link_type.value);
1643
1644 return TLV_SIZE(tlvh);
1645 }
1646
1647 static uint16_t show_vty_link_subtlv_link_id(struct vty *vty,
1648 struct tlv_header *tlvh)
1649 {
1650 struct te_link_subtlv_link_id *top;
1651
1652 top = (struct te_link_subtlv_link_id *)tlvh;
1653 if (vty != NULL)
1654 vty_out(vty, " Link-ID: %s\n", inet_ntoa(top->value));
1655 else
1656 zlog_debug(" Link-ID: %s", inet_ntoa(top->value));
1657
1658 return TLV_SIZE(tlvh);
1659 }
1660
1661 static uint16_t show_vty_link_subtlv_lclif_ipaddr(struct vty *vty,
1662 struct tlv_header *tlvh)
1663 {
1664 struct te_link_subtlv_lclif_ipaddr *top;
1665 int i, n;
1666
1667 top = (struct te_link_subtlv_lclif_ipaddr *)tlvh;
1668 n = ntohs(tlvh->length) / sizeof(top->value[0]);
1669
1670 if (vty != NULL)
1671 vty_out(vty, " Local Interface IP Address(es): %d\n", n);
1672 else
1673 zlog_debug(" Local Interface IP Address(es): %d", n);
1674
1675 for (i = 0; i < n; i++) {
1676 if (vty != NULL)
1677 vty_out(vty, " #%d: %s\n", i,
1678 inet_ntoa(top->value[i]));
1679 else
1680 zlog_debug(" #%d: %s", i,
1681 inet_ntoa(top->value[i]));
1682 }
1683 return TLV_SIZE(tlvh);
1684 }
1685
1686 static uint16_t show_vty_link_subtlv_rmtif_ipaddr(struct vty *vty,
1687 struct tlv_header *tlvh)
1688 {
1689 struct te_link_subtlv_rmtif_ipaddr *top;
1690 int i, n;
1691
1692 top = (struct te_link_subtlv_rmtif_ipaddr *)tlvh;
1693 n = ntohs(tlvh->length) / sizeof(top->value[0]);
1694 if (vty != NULL)
1695 vty_out(vty, " Remote Interface IP Address(es): %d\n", n);
1696 else
1697 zlog_debug(" Remote Interface IP Address(es): %d", n);
1698
1699 for (i = 0; i < n; i++) {
1700 if (vty != NULL)
1701 vty_out(vty, " #%d: %s\n", i,
1702 inet_ntoa(top->value[i]));
1703 else
1704 zlog_debug(" #%d: %s", i,
1705 inet_ntoa(top->value[i]));
1706 }
1707 return TLV_SIZE(tlvh);
1708 }
1709
1710 static uint16_t show_vty_link_subtlv_te_metric(struct vty *vty,
1711 struct tlv_header *tlvh)
1712 {
1713 struct te_link_subtlv_te_metric *top;
1714
1715 top = (struct te_link_subtlv_te_metric *)tlvh;
1716 if (vty != NULL)
1717 vty_out(vty, " Traffic Engineering Metric: %u\n",
1718 (uint32_t)ntohl(top->value));
1719 else
1720 zlog_debug(" Traffic Engineering Metric: %u",
1721 (uint32_t)ntohl(top->value));
1722
1723 return TLV_SIZE(tlvh);
1724 }
1725
1726 static uint16_t show_vty_link_subtlv_max_bw(struct vty *vty,
1727 struct tlv_header *tlvh)
1728 {
1729 struct te_link_subtlv_max_bw *top;
1730 float fval;
1731
1732 top = (struct te_link_subtlv_max_bw *)tlvh;
1733 fval = ntohf(top->value);
1734
1735 if (vty != NULL)
1736 vty_out(vty, " Maximum Bandwidth: %g (Bytes/sec)\n", fval);
1737 else
1738 zlog_debug(" Maximum Bandwidth: %g (Bytes/sec)", fval);
1739
1740 return TLV_SIZE(tlvh);
1741 }
1742
1743 static uint16_t show_vty_link_subtlv_max_rsv_bw(struct vty *vty,
1744 struct tlv_header *tlvh)
1745 {
1746 struct te_link_subtlv_max_rsv_bw *top;
1747 float fval;
1748
1749 top = (struct te_link_subtlv_max_rsv_bw *)tlvh;
1750 fval = ntohf(top->value);
1751
1752 if (vty != NULL)
1753 vty_out(vty, " Maximum Reservable Bandwidth: %g (Bytes/sec)\n",
1754 fval);
1755 else
1756 zlog_debug(" Maximum Reservable Bandwidth: %g (Bytes/sec)",
1757 fval);
1758
1759 return TLV_SIZE(tlvh);
1760 }
1761
1762 static uint16_t show_vty_link_subtlv_unrsv_bw(struct vty *vty,
1763 struct tlv_header *tlvh)
1764 {
1765 struct te_link_subtlv_unrsv_bw *top;
1766 float fval1, fval2;
1767 int i;
1768
1769 top = (struct te_link_subtlv_unrsv_bw *)tlvh;
1770 if (vty != NULL)
1771 vty_out(vty,
1772 " Unreserved Bandwidth per Class Type in Byte/s:\n");
1773 else
1774 zlog_debug(
1775 " Unreserved Bandwidth per Class Type in Byte/s:");
1776 for (i = 0; i < MAX_CLASS_TYPE; i += 2) {
1777 fval1 = ntohf(top->value[i]);
1778 fval2 = ntohf(top->value[i + 1]);
1779
1780 if (vty != NULL)
1781 vty_out(vty,
1782 " [%d]: %g (Bytes/sec),\t[%d]: %g (Bytes/sec)\n",
1783 i, fval1, i + 1, fval2);
1784 else
1785 zlog_debug(
1786 " [%d]: %g (Bytes/sec),\t[%d]: %g (Bytes/sec)",
1787 i, fval1, i + 1, fval2);
1788 }
1789
1790 return TLV_SIZE(tlvh);
1791 }
1792
1793 static uint16_t show_vty_link_subtlv_rsc_clsclr(struct vty *vty,
1794 struct tlv_header *tlvh)
1795 {
1796 struct te_link_subtlv_rsc_clsclr *top;
1797
1798 top = (struct te_link_subtlv_rsc_clsclr *)tlvh;
1799 if (vty != NULL)
1800 vty_out(vty, " Resource class/color: 0x%x\n",
1801 (uint32_t)ntohl(top->value));
1802 else
1803 zlog_debug(" Resource Class/Color: 0x%x",
1804 (uint32_t)ntohl(top->value));
1805
1806 return TLV_SIZE(tlvh);
1807 }
1808
1809 static uint16_t show_vty_link_subtlv_lrrid(struct vty *vty,
1810 struct tlv_header *tlvh)
1811 {
1812 struct te_link_subtlv_lrrid *top;
1813
1814 top = (struct te_link_subtlv_lrrid *)tlvh;
1815
1816 if (vty != NULL) {
1817 vty_out(vty, " Local TE Router ID: %s\n",
1818 inet_ntoa(top->local));
1819 vty_out(vty, " Remote TE Router ID: %s\n",
1820 inet_ntoa(top->remote));
1821 } else {
1822 zlog_debug(" Local TE Router ID: %s",
1823 inet_ntoa(top->local));
1824 zlog_debug(" Remote TE Router ID: %s",
1825 inet_ntoa(top->remote));
1826 }
1827
1828 return TLV_SIZE(tlvh);
1829 }
1830
1831 static uint16_t show_vty_link_subtlv_llri(struct vty *vty,
1832 struct tlv_header *tlvh)
1833 {
1834 struct te_link_subtlv_llri *top;
1835
1836 top = (struct te_link_subtlv_llri *)tlvh;
1837
1838 if (vty != NULL) {
1839 vty_out(vty, " Link Local ID: %d\n",
1840 (uint32_t)ntohl(top->local));
1841 vty_out(vty, " Link Remote ID: %d\n",
1842 (uint32_t)ntohl(top->remote));
1843 } else {
1844 zlog_debug(" Link Local ID: %d",
1845 (uint32_t)ntohl(top->local));
1846 zlog_debug(" Link Remote ID: %d",
1847 (uint32_t)ntohl(top->remote));
1848 }
1849
1850 return TLV_SIZE(tlvh);
1851 }
1852
1853 static uint16_t show_vty_link_subtlv_rip(struct vty *vty,
1854 struct tlv_header *tlvh)
1855 {
1856 struct te_link_subtlv_rip *top;
1857
1858 top = (struct te_link_subtlv_rip *)tlvh;
1859
1860 if (vty != NULL)
1861 vty_out(vty, " Inter-AS TE Remote ASBR IP address: %s\n",
1862 inet_ntoa(top->value));
1863 else
1864 zlog_debug(" Inter-AS TE Remote ASBR IP address: %s",
1865 inet_ntoa(top->value));
1866
1867 return TLV_SIZE(tlvh);
1868 }
1869
1870 static uint16_t show_vty_link_subtlv_ras(struct vty *vty,
1871 struct tlv_header *tlvh)
1872 {
1873 struct te_link_subtlv_ras *top;
1874
1875 top = (struct te_link_subtlv_ras *)tlvh;
1876
1877 if (vty != NULL)
1878 vty_out(vty, " Inter-AS TE Remote AS number: %u\n",
1879 ntohl(top->value));
1880 else
1881 zlog_debug(" Inter-AS TE Remote AS number: %u",
1882 ntohl(top->value));
1883
1884 return TLV_SIZE(tlvh);
1885 }
1886
1887 static uint16_t show_vty_link_subtlv_av_delay(struct vty *vty,
1888 struct tlv_header *tlvh)
1889 {
1890 struct te_link_subtlv_av_delay *top;
1891 uint32_t delay;
1892 uint32_t anomalous;
1893
1894 top = (struct te_link_subtlv_av_delay *)tlvh;
1895 delay = (uint32_t)ntohl(top->value) & TE_EXT_MASK;
1896 anomalous = (uint32_t)ntohl(top->value) & TE_EXT_ANORMAL;
1897
1898 if (vty != NULL)
1899 vty_out(vty, " %s Average Link Delay: %d (micro-sec)\n",
1900 anomalous ? "Anomalous" : "Normal", delay);
1901 else
1902 zlog_debug(" %s Average Link Delay: %d (micro-sec)",
1903 anomalous ? "Anomalous" : "Normal", delay);
1904
1905 return TLV_SIZE(tlvh);
1906 }
1907
1908 static uint16_t show_vty_link_subtlv_mm_delay(struct vty *vty,
1909 struct tlv_header *tlvh)
1910 {
1911 struct te_link_subtlv_mm_delay *top;
1912 uint32_t low, high;
1913 uint32_t anomalous;
1914
1915 top = (struct te_link_subtlv_mm_delay *)tlvh;
1916 low = (uint32_t)ntohl(top->low) & TE_EXT_MASK;
1917 anomalous = (uint32_t)ntohl(top->low) & TE_EXT_ANORMAL;
1918 high = (uint32_t)ntohl(top->high);
1919
1920 if (vty != NULL)
1921 vty_out(vty, " %s Min/Max Link Delay: %d/%d (micro-sec)\n",
1922 anomalous ? "Anomalous" : "Normal", low, high);
1923 else
1924 zlog_debug(" %s Min/Max Link Delay: %d/%d (micro-sec)",
1925 anomalous ? "Anomalous" : "Normal", low, high);
1926
1927 return TLV_SIZE(tlvh);
1928 }
1929
1930 static uint16_t show_vty_link_subtlv_delay_var(struct vty *vty,
1931 struct tlv_header *tlvh)
1932 {
1933 struct te_link_subtlv_delay_var *top;
1934 uint32_t jitter;
1935
1936 top = (struct te_link_subtlv_delay_var *)tlvh;
1937 jitter = (uint32_t)ntohl(top->value) & TE_EXT_MASK;
1938
1939 if (vty != NULL)
1940 vty_out(vty, " Delay Variation: %d (micro-sec)\n", jitter);
1941 else
1942 zlog_debug(" Delay Variation: %d (micro-sec)", jitter);
1943
1944 return TLV_SIZE(tlvh);
1945 }
1946
1947 static uint16_t show_vty_link_subtlv_pkt_loss(struct vty *vty,
1948 struct tlv_header *tlvh)
1949 {
1950 struct te_link_subtlv_pkt_loss *top;
1951 uint32_t loss;
1952 uint32_t anomalous;
1953 float fval;
1954
1955 top = (struct te_link_subtlv_pkt_loss *)tlvh;
1956 loss = (uint32_t)ntohl(top->value) & TE_EXT_MASK;
1957 fval = (float)(loss * LOSS_PRECISION);
1958 anomalous = (uint32_t)ntohl(top->value) & TE_EXT_ANORMAL;
1959
1960 if (vty != NULL)
1961 vty_out(vty, " %s Link Loss: %g (%%)\n",
1962 anomalous ? "Anomalous" : "Normal", fval);
1963 else
1964 zlog_debug(" %s Link Loss: %g (%%)",
1965 anomalous ? "Anomalous" : "Normal", fval);
1966
1967 return TLV_SIZE(tlvh);
1968 }
1969
1970 static uint16_t show_vty_link_subtlv_res_bw(struct vty *vty,
1971 struct tlv_header *tlvh)
1972 {
1973 struct te_link_subtlv_res_bw *top;
1974 float fval;
1975
1976 top = (struct te_link_subtlv_res_bw *)tlvh;
1977 fval = ntohf(top->value);
1978
1979 if (vty != NULL)
1980 vty_out(vty,
1981 " Unidirectional Residual Bandwidth: %g (Bytes/sec)\n",
1982 fval);
1983 else
1984 zlog_debug(
1985 " Unidirectional Residual Bandwidth: %g (Bytes/sec)",
1986 fval);
1987
1988 return TLV_SIZE(tlvh);
1989 }
1990
1991 static uint16_t show_vty_link_subtlv_ava_bw(struct vty *vty,
1992 struct tlv_header *tlvh)
1993 {
1994 struct te_link_subtlv_ava_bw *top;
1995 float fval;
1996
1997 top = (struct te_link_subtlv_ava_bw *)tlvh;
1998 fval = ntohf(top->value);
1999
2000 if (vty != NULL)
2001 vty_out(vty,
2002 " Unidirectional Available Bandwidth: %g (Bytes/sec)\n",
2003 fval);
2004 else
2005 zlog_debug(
2006 " Unidirectional Available Bandwidth: %g (Bytes/sec)",
2007 fval);
2008
2009 return TLV_SIZE(tlvh);
2010 }
2011
2012 static uint16_t show_vty_link_subtlv_use_bw(struct vty *vty,
2013 struct tlv_header *tlvh)
2014 {
2015 struct te_link_subtlv_use_bw *top;
2016 float fval;
2017
2018 top = (struct te_link_subtlv_use_bw *)tlvh;
2019 fval = ntohf(top->value);
2020
2021 if (vty != NULL)
2022 vty_out(vty,
2023 " Unidirectional Utilized Bandwidth: %g (Bytes/sec)\n",
2024 fval);
2025 else
2026 zlog_debug(
2027 " Unidirectional Utilized Bandwidth: %g (Bytes/sec)",
2028 fval);
2029
2030 return TLV_SIZE(tlvh);
2031 }
2032
2033 static uint16_t show_vty_unknown_tlv(struct vty *vty, struct tlv_header *tlvh)
2034 {
2035 if (vty != NULL)
2036 vty_out(vty, " Unknown TLV: [type(0x%x), length(0x%x)]\n",
2037 ntohs(tlvh->type), ntohs(tlvh->length));
2038 else
2039 zlog_debug(" Unknown TLV: [type(0x%x), length(0x%x)]",
2040 ntohs(tlvh->type), ntohs(tlvh->length));
2041
2042 return TLV_SIZE(tlvh);
2043 }
2044
2045 static uint16_t ospf_mpls_te_show_link_subtlv(struct vty *vty,
2046 struct tlv_header *tlvh0,
2047 uint16_t subtotal, uint16_t total)
2048 {
2049 struct tlv_header *tlvh;
2050 uint16_t sum = subtotal;
2051
2052 for (tlvh = tlvh0; sum < total;
2053 tlvh = TLV_HDR_NEXT(tlvh)) {
2054 switch (ntohs(tlvh->type)) {
2055 case TE_LINK_SUBTLV_LINK_TYPE:
2056 sum += show_vty_link_subtlv_link_type(vty, tlvh);
2057 break;
2058 case TE_LINK_SUBTLV_LINK_ID:
2059 sum += show_vty_link_subtlv_link_id(vty, tlvh);
2060 break;
2061 case TE_LINK_SUBTLV_LCLIF_IPADDR:
2062 sum += show_vty_link_subtlv_lclif_ipaddr(vty, tlvh);
2063 break;
2064 case TE_LINK_SUBTLV_RMTIF_IPADDR:
2065 sum += show_vty_link_subtlv_rmtif_ipaddr(vty, tlvh);
2066 break;
2067 case TE_LINK_SUBTLV_TE_METRIC:
2068 sum += show_vty_link_subtlv_te_metric(vty, tlvh);
2069 break;
2070 case TE_LINK_SUBTLV_MAX_BW:
2071 sum += show_vty_link_subtlv_max_bw(vty, tlvh);
2072 break;
2073 case TE_LINK_SUBTLV_MAX_RSV_BW:
2074 sum += show_vty_link_subtlv_max_rsv_bw(vty, tlvh);
2075 break;
2076 case TE_LINK_SUBTLV_UNRSV_BW:
2077 sum += show_vty_link_subtlv_unrsv_bw(vty, tlvh);
2078 break;
2079 case TE_LINK_SUBTLV_RSC_CLSCLR:
2080 sum += show_vty_link_subtlv_rsc_clsclr(vty, tlvh);
2081 break;
2082 case TE_LINK_SUBTLV_LRRID:
2083 sum += show_vty_link_subtlv_lrrid(vty, tlvh);
2084 break;
2085 case TE_LINK_SUBTLV_LLRI:
2086 sum += show_vty_link_subtlv_llri(vty, tlvh);
2087 break;
2088 case TE_LINK_SUBTLV_RIP:
2089 sum += show_vty_link_subtlv_rip(vty, tlvh);
2090 break;
2091 case TE_LINK_SUBTLV_RAS:
2092 sum += show_vty_link_subtlv_ras(vty, tlvh);
2093 break;
2094 case TE_LINK_SUBTLV_AV_DELAY:
2095 sum += show_vty_link_subtlv_av_delay(vty, tlvh);
2096 break;
2097 case TE_LINK_SUBTLV_MM_DELAY:
2098 sum += show_vty_link_subtlv_mm_delay(vty, tlvh);
2099 break;
2100 case TE_LINK_SUBTLV_DELAY_VAR:
2101 sum += show_vty_link_subtlv_delay_var(vty, tlvh);
2102 break;
2103 case TE_LINK_SUBTLV_PKT_LOSS:
2104 sum += show_vty_link_subtlv_pkt_loss(vty, tlvh);
2105 break;
2106 case TE_LINK_SUBTLV_RES_BW:
2107 sum += show_vty_link_subtlv_res_bw(vty, tlvh);
2108 break;
2109 case TE_LINK_SUBTLV_AVA_BW:
2110 sum += show_vty_link_subtlv_ava_bw(vty, tlvh);
2111 break;
2112 case TE_LINK_SUBTLV_USE_BW:
2113 sum += show_vty_link_subtlv_use_bw(vty, tlvh);
2114 break;
2115 default:
2116 sum += show_vty_unknown_tlv(vty, tlvh);
2117 break;
2118 }
2119 }
2120 return sum;
2121 }
2122
2123 static void ospf_mpls_te_show_info(struct vty *vty, struct ospf_lsa *lsa)
2124 {
2125 struct lsa_header *lsah = (struct lsa_header *)lsa->data;
2126 struct tlv_header *tlvh, *next;
2127 uint16_t sum, total;
2128 uint16_t (*subfunc)(struct vty * vty, struct tlv_header * tlvh,
2129 uint16_t subtotal, uint16_t total) = NULL;
2130
2131 sum = 0;
2132 total = ntohs(lsah->length) - OSPF_LSA_HEADER_SIZE;
2133
2134 for (tlvh = TLV_HDR_TOP(lsah); sum < total;
2135 tlvh = (next ? next : TLV_HDR_NEXT(tlvh))) {
2136 if (subfunc != NULL) {
2137 sum = (*subfunc)(vty, tlvh, sum, total);
2138 next = (struct tlv_header *)((char *)tlvh + sum);
2139 subfunc = NULL;
2140 continue;
2141 }
2142
2143 next = NULL;
2144 switch (ntohs(tlvh->type)) {
2145 case TE_TLV_ROUTER_ADDR:
2146 sum += show_vty_router_addr(vty, tlvh);
2147 break;
2148 case TE_TLV_LINK:
2149 sum += show_vty_link_header(vty, tlvh);
2150 subfunc = ospf_mpls_te_show_link_subtlv;
2151 next = TLV_DATA(tlvh);
2152 break;
2153 default:
2154 sum += show_vty_unknown_tlv(vty, tlvh);
2155 break;
2156 }
2157 }
2158 return;
2159 }
2160
2161 static void ospf_mpls_te_config_write_router(struct vty *vty)
2162 {
2163
2164 if (OspfMplsTE.enabled) {
2165 vty_out(vty, " mpls-te on\n");
2166 vty_out(vty, " mpls-te router-address %s\n",
2167 inet_ntoa(OspfMplsTE.router_addr.value));
2168 }
2169
2170 if (OspfMplsTE.inter_as == AS)
2171 vty_out(vty, " mpls-te inter-as as\n");
2172 if (OspfMplsTE.inter_as == Area)
2173 vty_out(vty, " mpls-te inter-as area %s \n",
2174 inet_ntoa(OspfMplsTE.interas_areaid));
2175
2176 return;
2177 }
2178
2179 /*------------------------------------------------------------------------*
2180 * Followings are vty command functions.
2181 *------------------------------------------------------------------------*/
2182
2183 DEFUN (ospf_mpls_te_on,
2184 ospf_mpls_te_on_cmd,
2185 "mpls-te on",
2186 MPLS_TE_STR
2187 "Enable the MPLS-TE functionality\n")
2188 {
2189 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
2190 struct listnode *node;
2191 struct mpls_te_link *lp;
2192
2193 if (OspfMplsTE.enabled)
2194 return CMD_SUCCESS;
2195
2196 if (IS_DEBUG_OSPF_EVENT)
2197 zlog_debug("MPLS-TE: OFF -> ON");
2198
2199 OspfMplsTE.enabled = true;
2200
2201 /* Reoriginate RFC3630 & RFC6827 Links */
2202 ospf_mpls_te_foreach_area(ospf_mpls_te_lsa_schedule,
2203 REORIGINATE_THIS_LSA);
2204
2205 /* Reoriginate LSA if INTER-AS is always on */
2206 if (OspfMplsTE.inter_as != Off) {
2207 for (ALL_LIST_ELEMENTS_RO(OspfMplsTE.iflist, node, lp)) {
2208 if (IS_INTER_AS(lp->type)) {
2209 ospf_mpls_te_lsa_schedule(lp,
2210 REORIGINATE_THIS_LSA);
2211 }
2212 }
2213 }
2214
2215 return CMD_SUCCESS;
2216 }
2217
2218 DEFUN (no_ospf_mpls_te,
2219 no_ospf_mpls_te_cmd,
2220 "no mpls-te [on]",
2221 NO_STR
2222 MPLS_TE_STR
2223 "Disable the MPLS-TE functionality\n")
2224 {
2225 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
2226 struct listnode *node, *nnode;
2227 struct mpls_te_link *lp;
2228
2229 if (!OspfMplsTE.enabled)
2230 return CMD_SUCCESS;
2231
2232 if (IS_DEBUG_OSPF_EVENT)
2233 zlog_debug("MPLS-TE: ON -> OFF");
2234
2235 OspfMplsTE.enabled = false;
2236
2237 for (ALL_LIST_ELEMENTS(OspfMplsTE.iflist, node, nnode, lp))
2238 if (CHECK_FLAG(lp->flags, LPFLG_LSA_ENGAGED))
2239 ospf_mpls_te_lsa_schedule(lp, FLUSH_THIS_LSA);
2240
2241 return CMD_SUCCESS;
2242 }
2243
2244
2245 DEFUN (ospf_mpls_te_router_addr,
2246 ospf_mpls_te_router_addr_cmd,
2247 "mpls-te router-address A.B.C.D",
2248 MPLS_TE_STR
2249 "Stable IP address of the advertising router\n"
2250 "MPLS-TE router address in IPv4 address format\n")
2251 {
2252 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
2253 int idx_ipv4 = 2;
2254 struct te_tlv_router_addr *ra = &OspfMplsTE.router_addr;
2255 struct in_addr value;
2256
2257 if (!inet_aton(argv[idx_ipv4]->arg, &value)) {
2258 vty_out(vty, "Please specify Router-Addr by A.B.C.D\n");
2259 return CMD_WARNING;
2260 }
2261
2262 if (ntohs(ra->header.type) == 0
2263 || ntohl(ra->value.s_addr) != ntohl(value.s_addr)) {
2264 struct listnode *node, *nnode;
2265 struct mpls_te_link *lp;
2266 int need_to_reoriginate = 0;
2267
2268 set_mpls_te_router_addr(value);
2269
2270 if (!OspfMplsTE.enabled)
2271 return CMD_SUCCESS;
2272
2273 for (ALL_LIST_ELEMENTS(OspfMplsTE.iflist, node, nnode, lp)) {
2274 if ((lp->area == NULL) || IS_FLOOD_AS(lp->type))
2275 continue;
2276
2277 if (!CHECK_FLAG(lp->flags, LPFLG_LSA_ENGAGED)) {
2278 need_to_reoriginate = 1;
2279 break;
2280 }
2281 }
2282
2283 for (ALL_LIST_ELEMENTS(OspfMplsTE.iflist, node, nnode, lp)) {
2284 if ((lp->area == NULL) || IS_FLOOD_AS(lp->type))
2285 continue;
2286
2287 if (need_to_reoriginate)
2288 SET_FLAG(lp->flags, LPFLG_LSA_FORCED_REFRESH);
2289 else
2290 ospf_mpls_te_lsa_schedule(lp, REFRESH_THIS_LSA);
2291 }
2292
2293 if (need_to_reoriginate)
2294 ospf_mpls_te_foreach_area(ospf_mpls_te_lsa_schedule,
2295 REORIGINATE_THIS_LSA);
2296 }
2297
2298 return CMD_SUCCESS;
2299 }
2300
2301 static int set_inter_as_mode(struct vty *vty, const char *mode_name,
2302 const char *area_id)
2303 {
2304 enum inter_as_mode mode;
2305 struct listnode *node;
2306 struct mpls_te_link *lp;
2307 int format;
2308
2309 if (OspfMplsTE.enabled) {
2310
2311 /* Read and Check inter_as mode */
2312 if (strcmp(mode_name, "as") == 0)
2313 mode = AS;
2314 else if (strcmp(mode_name, "area") == 0) {
2315 mode = Area;
2316 VTY_GET_OSPF_AREA_ID(OspfMplsTE.interas_areaid, format,
2317 area_id);
2318 } else {
2319 vty_out(vty,
2320 "Unknown mode. Please choose between as or area\n");
2321 return CMD_WARNING;
2322 }
2323
2324 if (IS_DEBUG_OSPF_EVENT)
2325 zlog_debug(
2326 "MPLS-TE: Inter-AS enable with %s flooding support",
2327 mode2text[mode]);
2328
2329 /* Register new callbacks regarding the flooding scope (AS or
2330 * Area) */
2331 if (ospf_mpls_te_register(mode) < 0) {
2332 vty_out(vty,
2333 "Internal error: Unable to register Inter-AS functions\n");
2334 return CMD_WARNING;
2335 }
2336
2337 /* Enable mode and re-originate LSA if needed */
2338 if ((OspfMplsTE.inter_as == Off)
2339 && (mode != OspfMplsTE.inter_as)) {
2340 OspfMplsTE.inter_as = mode;
2341 /* Re-originate all InterAS-TEv2 LSA */
2342 for (ALL_LIST_ELEMENTS_RO(OspfMplsTE.iflist, node,
2343 lp)) {
2344 if (IS_INTER_AS(lp->type)) {
2345 if (mode == AS)
2346 lp->type |= FLOOD_AS;
2347 else
2348 lp->type |= FLOOD_AREA;
2349 ospf_mpls_te_lsa_schedule(
2350 lp, REORIGINATE_THIS_LSA);
2351 }
2352 }
2353 } else {
2354 vty_out(vty,
2355 "Please change Inter-AS support to disable first before going to mode %s\n",
2356 mode2text[mode]);
2357 return CMD_WARNING;
2358 }
2359 } else {
2360 vty_out(vty, "mpls-te has not been turned on\n");
2361 return CMD_WARNING;
2362 }
2363 return CMD_SUCCESS;
2364 }
2365
2366
2367 DEFUN (ospf_mpls_te_inter_as_as,
2368 ospf_mpls_te_inter_as_cmd,
2369 "mpls-te inter-as as",
2370 MPLS_TE_STR
2371 "Configure MPLS-TE Inter-AS support\n"
2372 "AS native mode self originate INTER_AS LSA with Type 11 (as flooding scope)\n")
2373 {
2374 return set_inter_as_mode(vty, "as", "");
2375 }
2376
2377 DEFUN (ospf_mpls_te_inter_as_area,
2378 ospf_mpls_te_inter_as_area_cmd,
2379 "mpls-te inter-as area <A.B.C.D|(0-4294967295)>",
2380 MPLS_TE_STR
2381 "Configure MPLS-TE Inter-AS support\n"
2382 "AREA native mode self originate INTER_AS LSA with Type 10 (area flooding scope)\n"
2383 "OSPF area ID in IP format\n"
2384 "OSPF area ID as decimal value\n")
2385 {
2386 int idx_ipv4_number = 3;
2387 return set_inter_as_mode(vty, "area", argv[idx_ipv4_number]->arg);
2388 }
2389
2390 DEFUN (no_ospf_mpls_te_inter_as,
2391 no_ospf_mpls_te_inter_as_cmd,
2392 "no mpls-te inter-as",
2393 NO_STR
2394 MPLS_TE_STR
2395 "Disable MPLS-TE Inter-AS support\n")
2396 {
2397
2398 struct listnode *node, *nnode;
2399 struct mpls_te_link *lp;
2400
2401 if (IS_DEBUG_OSPF_EVENT)
2402 zlog_debug("MPLS-TE: Inter-AS support OFF");
2403
2404 if ((OspfMplsTE.enabled) && (OspfMplsTE.inter_as != Off)) {
2405 OspfMplsTE.inter_as = Off;
2406 /* Flush all Inter-AS LSA */
2407 for (ALL_LIST_ELEMENTS(OspfMplsTE.iflist, node, nnode, lp))
2408 if (IS_INTER_AS(lp->type)
2409 && CHECK_FLAG(lp->flags, LPFLG_LSA_ENGAGED))
2410 ospf_mpls_te_lsa_schedule(lp, FLUSH_THIS_LSA);
2411 }
2412
2413 /* Deregister the Callbacks for Inter-AS suport */
2414 ospf_mpls_te_unregister();
2415
2416 return CMD_SUCCESS;
2417 }
2418
2419 DEFUN (show_ip_ospf_mpls_te_router,
2420 show_ip_ospf_mpls_te_router_cmd,
2421 "show ip ospf mpls-te router",
2422 SHOW_STR
2423 IP_STR
2424 OSPF_STR
2425 "MPLS-TE information\n"
2426 "MPLS-TE Router parameters\n")
2427 {
2428 if (OspfMplsTE.enabled) {
2429 vty_out(vty, "--- MPLS-TE router parameters ---\n");
2430
2431 if (ntohs(OspfMplsTE.router_addr.header.type) != 0)
2432 show_vty_router_addr(vty,
2433 &OspfMplsTE.router_addr.header);
2434 else
2435 vty_out(vty, " N/A\n");
2436 }
2437 return CMD_SUCCESS;
2438 }
2439
2440 static void show_mpls_te_link_sub(struct vty *vty, struct interface *ifp)
2441 {
2442 struct mpls_te_link *lp;
2443
2444 if ((OspfMplsTE.enabled) && HAS_LINK_PARAMS(ifp) && !if_is_loopback(ifp)
2445 && if_is_up(ifp)
2446 && ((lp = lookup_linkparams_by_ifp(ifp)) != NULL)) {
2447 /* Continue only if interface is not passive or support Inter-AS
2448 * TEv2 */
2449 if (!(ospf_oi_count(ifp) > 0)) {
2450 if (IS_INTER_AS(lp->type)) {
2451 vty_out(vty,
2452 "-- Inter-AS TEv2 link parameters for %s --\n",
2453 ifp->name);
2454 } else {
2455 /* MPLS-TE is not activate on this interface */
2456 /* or this interface is passive and Inter-AS
2457 * TEv2 is not activate */
2458 vty_out(vty,
2459 " %s: MPLS-TE is disabled on this interface\n",
2460 ifp->name);
2461 return;
2462 }
2463 } else {
2464 vty_out(vty, "-- MPLS-TE link parameters for %s --\n",
2465 ifp->name);
2466 }
2467
2468 if (TLV_TYPE(lp->link_type) != 0)
2469 show_vty_link_subtlv_link_type(vty,
2470 &lp->link_type.header);
2471 if (TLV_TYPE(lp->link_id) != 0)
2472 show_vty_link_subtlv_link_id(vty, &lp->link_id.header);
2473 if (TLV_TYPE(lp->lclif_ipaddr) != 0)
2474 show_vty_link_subtlv_lclif_ipaddr(
2475 vty, &lp->lclif_ipaddr.header);
2476 if (TLV_TYPE(lp->rmtif_ipaddr) != 0)
2477 show_vty_link_subtlv_rmtif_ipaddr(
2478 vty, &lp->rmtif_ipaddr.header);
2479 if (TLV_TYPE(lp->rip) != 0)
2480 show_vty_link_subtlv_rip(vty, &lp->rip.header);
2481 if (TLV_TYPE(lp->ras) != 0)
2482 show_vty_link_subtlv_ras(vty, &lp->ras.header);
2483 if (TLV_TYPE(lp->te_metric) != 0)
2484 show_vty_link_subtlv_te_metric(vty,
2485 &lp->te_metric.header);
2486 if (TLV_TYPE(lp->max_bw) != 0)
2487 show_vty_link_subtlv_max_bw(vty, &lp->max_bw.header);
2488 if (TLV_TYPE(lp->max_rsv_bw) != 0)
2489 show_vty_link_subtlv_max_rsv_bw(vty,
2490 &lp->max_rsv_bw.header);
2491 if (TLV_TYPE(lp->unrsv_bw) != 0)
2492 show_vty_link_subtlv_unrsv_bw(vty,
2493 &lp->unrsv_bw.header);
2494 if (TLV_TYPE(lp->rsc_clsclr) != 0)
2495 show_vty_link_subtlv_rsc_clsclr(vty,
2496 &lp->rsc_clsclr.header);
2497 if (TLV_TYPE(lp->av_delay) != 0)
2498 show_vty_link_subtlv_av_delay(vty,
2499 &lp->av_delay.header);
2500 if (TLV_TYPE(lp->mm_delay) != 0)
2501 show_vty_link_subtlv_mm_delay(vty,
2502 &lp->mm_delay.header);
2503 if (TLV_TYPE(lp->delay_var) != 0)
2504 show_vty_link_subtlv_delay_var(vty,
2505 &lp->delay_var.header);
2506 if (TLV_TYPE(lp->pkt_loss) != 0)
2507 show_vty_link_subtlv_pkt_loss(vty,
2508 &lp->pkt_loss.header);
2509 if (TLV_TYPE(lp->res_bw) != 0)
2510 show_vty_link_subtlv_res_bw(vty, &lp->res_bw.header);
2511 if (TLV_TYPE(lp->ava_bw) != 0)
2512 show_vty_link_subtlv_ava_bw(vty, &lp->ava_bw.header);
2513 if (TLV_TYPE(lp->use_bw) != 0)
2514 show_vty_link_subtlv_use_bw(vty, &lp->use_bw.header);
2515 vty_out(vty, "---------------\n\n");
2516 } else {
2517 vty_out(vty, " %s: MPLS-TE is disabled on this interface\n",
2518 ifp->name);
2519 }
2520
2521 return;
2522 }
2523
2524 DEFUN (show_ip_ospf_mpls_te_link,
2525 show_ip_ospf_mpls_te_link_cmd,
2526 "show ip ospf [vrf <NAME|all>] mpls-te interface [INTERFACE]",
2527 SHOW_STR
2528 IP_STR
2529 OSPF_STR
2530 VRF_CMD_HELP_STR
2531 "All VRFs\n"
2532 "MPLS-TE information\n"
2533 "Interface information\n"
2534 "Interface name\n")
2535 {
2536 struct vrf *vrf;
2537 int idx_interface = 5;
2538 struct interface *ifp;
2539 struct listnode *node;
2540 char *vrf_name = NULL;
2541 bool all_vrf;
2542 int inst = 0;
2543 int idx_vrf = 0;
2544 struct ospf *ospf = NULL;
2545
2546 if (argv_find(argv, argc, "vrf", &idx_vrf)) {
2547 vrf_name = argv[idx_vrf + 1]->arg;
2548 all_vrf = strmatch(vrf_name, "all");
2549 }
2550
2551 /* vrf input is provided could be all or specific vrf*/
2552 if (vrf_name) {
2553 if (all_vrf) {
2554 for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) {
2555 if (!ospf->oi_running)
2556 continue;
2557 vrf = vrf_lookup_by_id(ospf->vrf_id);
2558 FOR_ALL_INTERFACES (vrf, ifp)
2559 show_mpls_te_link_sub(vty, ifp);
2560 }
2561 return CMD_SUCCESS;
2562 }
2563 ospf = ospf_lookup_by_inst_name(inst, vrf_name);
2564 if (ospf == NULL || !ospf->oi_running)
2565 return CMD_SUCCESS;
2566 vrf = vrf_lookup_by_id(ospf->vrf_id);
2567 FOR_ALL_INTERFACES (vrf, ifp)
2568 show_mpls_te_link_sub(vty, ifp);
2569 return CMD_SUCCESS;
2570 }
2571 /* Show All Interfaces. */
2572 if (argc == 5) {
2573 for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) {
2574 if (!ospf->oi_running)
2575 continue;
2576 vrf = vrf_lookup_by_id(ospf->vrf_id);
2577 FOR_ALL_INTERFACES (vrf, ifp)
2578 show_mpls_te_link_sub(vty, ifp);
2579 }
2580 }
2581 /* Interface name is specified. */
2582 else {
2583 ifp = if_lookup_by_name_all_vrf(argv[idx_interface]->arg);
2584 if (ifp == NULL)
2585 vty_out(vty, "No such interface name\n");
2586 else
2587 show_mpls_te_link_sub(vty, ifp);
2588 }
2589
2590 return CMD_SUCCESS;
2591 }
2592
2593 static void ospf_mpls_te_register_vty(void)
2594 {
2595 install_element(VIEW_NODE, &show_ip_ospf_mpls_te_router_cmd);
2596 install_element(VIEW_NODE, &show_ip_ospf_mpls_te_link_cmd);
2597
2598 install_element(OSPF_NODE, &ospf_mpls_te_on_cmd);
2599 install_element(OSPF_NODE, &no_ospf_mpls_te_cmd);
2600 install_element(OSPF_NODE, &ospf_mpls_te_router_addr_cmd);
2601 install_element(OSPF_NODE, &ospf_mpls_te_inter_as_cmd);
2602 install_element(OSPF_NODE, &ospf_mpls_te_inter_as_area_cmd);
2603 install_element(OSPF_NODE, &no_ospf_mpls_te_inter_as_cmd);
2604
2605 return;
2606 }