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