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