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