2 * This is an implementation of RFC3630
3 * Copyright (C) 2001 KDD R&D Laboratories, Inc.
4 * http://www.kddlabs.co.jp/
6 * Copyright (C) 2012 Orange Labs
7 * http://www.orange.com
9 * This file is part of GNU Zebra.
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
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.
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
27 /* Add support of RFC7471 */
28 /* Add support of RFC5392, RFC6827 */
44 #include "sockunion.h" /* for inet_aton() */
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"
66 * Global variable to manage Opaque-LSA/MPLS-TE on this node.
67 * Note that all parameter values are stored in network byte order.
69 struct ospf_mpls_te OspfMplsTE;
71 const char *mode2text[] = { "Disable", "AS", "Area", "Emulate" };
75 OI_ANY, OI_DOWN, OI_UP
78 /*------------------------------------------------------------------------*
79 * Followings are initialize/terminate functions for MPLS-TE handling.
80 *------------------------------------------------------------------------*/
82 static int ospf_mpls_te_new_if (struct interface *ifp);
83 static int ospf_mpls_te_del_if (struct interface *ifp);
84 static void ospf_mpls_te_ism_change (struct ospf_interface *oi,
86 static void ospf_mpls_te_nsm_change (struct ospf_neighbor *nbr, int old_status);
87 static void ospf_mpls_te_config_write_router (struct vty *vty);
88 static void ospf_mpls_te_show_info (struct vty *vty, struct ospf_lsa *lsa);
89 static int ospf_mpls_te_lsa_originate_area (void *arg);
90 static int ospf_mpls_te_lsa_originate_as (void *arg);
91 static struct ospf_lsa *ospf_mpls_te_lsa_refresh (struct ospf_lsa *lsa);
93 static void del_mpls_te_link (void *val);
94 static void ospf_mpls_te_register_vty (void);
97 ospf_mpls_te_init (void)
101 rc = ospf_register_opaque_functab (
102 OSPF_OPAQUE_AREA_LSA,
103 OPAQUE_TYPE_TRAFFIC_ENGINEERING_LSA,
106 ospf_mpls_te_ism_change,
107 ospf_mpls_te_nsm_change,
108 ospf_mpls_te_config_write_router,
109 NULL,/*ospf_mpls_te_config_write_if */
110 NULL,/* ospf_mpls_te_config_write_debug */
111 ospf_mpls_te_show_info,
112 ospf_mpls_te_lsa_originate_area,
113 ospf_mpls_te_lsa_refresh,
114 NULL,/* ospf_mpls_te_new_lsa_hook */
115 NULL /* ospf_mpls_te_del_lsa_hook */);
118 zlog_warn ("ospf_mpls_te_init: Failed to register Traffic Engineering functions");
122 memset (&OspfMplsTE, 0, sizeof (struct ospf_mpls_te));
123 OspfMplsTE.status = disabled;
124 OspfMplsTE.inter_as = Disable;
125 OspfMplsTE.iflist = list_new ();
126 OspfMplsTE.iflist->del = del_mpls_te_link;
128 ospf_mpls_te_register_vty ();
134 /* Additional register for RFC5392 support */
136 ospf_mpls_te_register (enum inter_as_mode mode)
141 if (OspfMplsTE.inter_as != Disable)
145 scope = OSPF_OPAQUE_AS_LSA;
147 scope = OSPF_OPAQUE_AREA_LSA;
149 rc = ospf_register_opaque_functab (scope,
150 OPAQUE_TYPE_INTER_AS_LSA,
158 ospf_mpls_te_show_info,
159 ospf_mpls_te_lsa_originate_as,
160 ospf_mpls_te_lsa_refresh, NULL, NULL);
164 zlog_warn ("ospf_router_info_init: Failed to register Inter-AS functions");
172 ospf_mpls_te_unregister ()
176 if (OspfMplsTE.inter_as == Disable)
179 if (OspfMplsTE.inter_as == AS)
180 scope = OSPF_OPAQUE_AS_LSA;
182 scope = OSPF_OPAQUE_AREA_LSA;
184 ospf_delete_opaque_functab (scope, OPAQUE_TYPE_INTER_AS_LSA);
191 ospf_mpls_te_term (void)
193 list_delete (OspfMplsTE.iflist);
194 OspfMplsTE.iflist = NULL;
196 ospf_delete_opaque_functab (OSPF_OPAQUE_AREA_LSA,
197 OPAQUE_TYPE_TRAFFIC_ENGINEERING_LSA);
198 OspfMplsTE.status = disabled;
200 ospf_mpls_te_unregister ();
201 OspfMplsTE.inter_as = Disable;
206 /*------------------------------------------------------------------------*
207 * Followings are control functions for MPLS-TE parameters management.
208 *------------------------------------------------------------------------*/
211 del_mpls_te_link (void *val)
213 XFREE (MTYPE_OSPF_MPLS_TE, val);
218 get_mpls_te_instance_value (void)
220 static u_int32_t seqno = 0;
222 if (seqno < MAX_LEGAL_TE_INSTANCE_NUM )
225 seqno = 1; /* Avoid zero. */
230 static struct ospf_interface *
231 lookup_oi_by_ifp (struct interface *ifp,
232 struct ospf_area *area, enum oifstate oifstate)
234 struct ospf_interface *oi = NULL;
235 struct route_node *rn;
237 for (rn = route_top (IF_OIFS (ifp)); rn; rn = route_next (rn))
239 if ((oi = rn->info) == NULL)
247 if (ospf_if_is_enable (oi))
251 if (! ospf_if_is_enable (oi))
255 zlog_warn ("lookup_oi_by_ifp: Unknown oifstate: %x", oifstate);
259 if (area == NULL || oi->area == area)
266 static struct mpls_te_link *
267 lookup_linkparams_by_ifp (struct interface *ifp)
269 struct listnode *node, *nnode;
270 struct mpls_te_link *lp;
272 for (ALL_LIST_ELEMENTS (OspfMplsTE.iflist, node, nnode, lp))
279 static struct mpls_te_link *
280 lookup_linkparams_by_instance (struct ospf_lsa *lsa)
282 struct listnode *node;
283 struct mpls_te_link *lp;
284 unsigned int key = GET_OPAQUE_ID (ntohl (lsa->data->id.s_addr));
286 for (ALL_LIST_ELEMENTS_RO (OspfMplsTE.iflist, node, lp))
287 if (lp->instance == key)
290 zlog_warn ("lookup_linkparams_by_instance: Entry not found: key(%x)", key);
295 ospf_mpls_te_foreach_area (void (*func)
296 (struct mpls_te_link * lp, opcode_t sched_opcode),
297 opcode_t sched_opcode)
299 struct listnode *node, *nnode;
300 struct listnode *node2;
301 struct mpls_te_link *lp;
302 struct ospf_area *area;
304 for (ALL_LIST_ELEMENTS (OspfMplsTE.iflist, node, nnode, lp))
306 /* Skip Inter-AS TEv2 Links */
307 if (IS_INTER_AS (lp->type))
309 if ((area = lp->area) == NULL)
311 if CHECK_FLAG (lp->flags, LPFLG_LOOKUP_DONE) continue;
314 (* func)(lp, sched_opcode);
316 for (node2 = listnextnode (node); node2; node2 = listnextnode (node2))
317 if ((lp = listgetdata (node2)) != NULL)
318 if (lp->area != NULL)
319 if (IPV4_ADDR_SAME (&lp->area->area_id, &area->area_id))
320 SET_FLAG (lp->flags, LPFLG_LOOKUP_DONE);
323 for (ALL_LIST_ELEMENTS_RO (OspfMplsTE.iflist, node, lp))
324 if (lp->area != NULL)
325 UNSET_FLAG (lp->flags, LPFLG_LOOKUP_DONE);
331 set_mpls_te_router_addr (struct in_addr ipv4)
333 OspfMplsTE.router_addr.header.type = htons (TE_TLV_ROUTER_ADDR);
334 OspfMplsTE.router_addr.header.length = htons (TE_LINK_SUBTLV_DEF_SIZE);
335 OspfMplsTE.router_addr.value = ipv4;
340 set_linkparams_link_header (struct mpls_te_link *lp)
342 u_int16_t length = 0;
344 /* TE_LINK_SUBTLV_LINK_TYPE */
345 if (ntohs (lp->link_type.header.type) != 0)
346 length += TLV_SIZE (&lp->link_type.header);
348 /* TE_LINK_SUBTLV_LINK_ID */
349 if (ntohs (lp->link_id.header.type) != 0)
350 length += TLV_SIZE (&lp->link_id.header);
352 /* TE_LINK_SUBTLV_LCLIF_IPADDR */
353 if (lp->lclif_ipaddr.header.type != 0)
354 length += TLV_SIZE (&lp->lclif_ipaddr.header);
356 /* TE_LINK_SUBTLV_RMTIF_IPADDR */
357 if (lp->rmtif_ipaddr.header.type != 0)
358 length += TLV_SIZE (&lp->rmtif_ipaddr.header);
360 /* TE_LINK_SUBTLV_TE_METRIC */
361 if (ntohs (lp->te_metric.header.type) != 0)
362 length += TLV_SIZE (&lp->te_metric.header);
364 /* TE_LINK_SUBTLV_MAX_BW */
365 if (ntohs (lp->max_bw.header.type) != 0)
366 length += TLV_SIZE (&lp->max_bw.header);
368 /* TE_LINK_SUBTLV_MAX_RSV_BW */
369 if (ntohs (lp->max_rsv_bw.header.type) != 0)
370 length += TLV_SIZE (&lp->max_rsv_bw.header);
372 /* TE_LINK_SUBTLV_UNRSV_BW */
373 if (ntohs (lp->unrsv_bw.header.type) != 0)
374 length += TLV_SIZE (&lp->unrsv_bw.header);
376 /* TE_LINK_SUBTLV_RSC_CLSCLR */
377 if (ntohs (lp->rsc_clsclr.header.type) != 0)
378 length += TLV_SIZE (&lp->rsc_clsclr.header);
380 /* TE_LINK_SUBTLV_LLRI */
381 if (ntohs (lp->llri.header.type) != 0)
382 length += TLV_SIZE (&lp->llri.header);
384 /* TE_LINK_SUBTLV_RIP */
385 if (ntohs (lp->rip.header.type) != 0)
386 length += TLV_SIZE (&lp->rip.header);
388 /* TE_LINK_SUBTLV_RAS */
389 if (ntohs (lp->ras.header.type) != 0)
390 length += TLV_SIZE (&lp->ras.header);
392 /* TE_LINK_SUBTLV_LRRID */
393 if (ntohs (lp->lrrid.header.type) != 0)
394 length += TLV_SIZE (&lp->lrrid.header);
396 /* TE_LINK_SUBTLV_AV_DELAY */
397 if (ntohs (lp->av_delay.header.type) != 0)
398 length += TLV_SIZE (&lp->av_delay.header);
400 /* TE_LINK_SUBTLV_MM_DELAY */
401 if (ntohs (lp->mm_delay.header.type) != 0)
402 length += TLV_SIZE (&lp->mm_delay.header);
404 /* TE_LINK_SUBTLV_DELAY_VAR */
405 if (ntohs (lp->delay_var.header.type) != 0)
406 length += TLV_SIZE (&lp->delay_var.header);
408 /* TE_LINK_SUBTLV_PKT_LOSS */
409 if (ntohs (lp->pkt_loss.header.type) != 0)
410 length += TLV_SIZE (&lp->pkt_loss.header);
412 /* TE_LINK_SUBTLV_RES_BW */
413 if (ntohs (lp->res_bw.header.type) != 0)
414 length += TLV_SIZE (&lp->res_bw.header);
416 /* TE_LINK_SUBTLV_AVA_BW */
417 if (ntohs (lp->ava_bw.header.type) != 0)
418 length += TLV_SIZE (&lp->ava_bw.header);
420 /* TE_LINK_SUBTLV_USE_BW */
421 if (ntohs (lp->use_bw.header.type) != 0)
422 length += TLV_SIZE (&lp->use_bw.header);
424 lp->link_header.header.type = htons (TE_TLV_LINK);
425 lp->link_header.header.length = htons (length);
431 set_linkparams_link_type (struct ospf_interface *oi, struct mpls_te_link *lp)
433 lp->link_type.header.type = htons (TE_LINK_SUBTLV_LINK_TYPE);
434 lp->link_type.header.length = htons (TE_LINK_SUBTLV_TYPE_SIZE);
438 case OSPF_IFTYPE_POINTOPOINT:
439 lp->link_type.link_type.value = LINK_TYPE_SUBTLV_VALUE_PTP;
441 case OSPF_IFTYPE_BROADCAST:
442 case OSPF_IFTYPE_NBMA:
443 lp->link_type.link_type.value = LINK_TYPE_SUBTLV_VALUE_MA;
446 /* Not supported yet. *//* XXX */
447 lp->link_type.header.type = htons (0);
454 set_linkparams_link_id (struct ospf_interface *oi, struct mpls_te_link *lp)
456 struct ospf_neighbor *nbr;
459 lp->link_id.header.type = htons (TE_LINK_SUBTLV_LINK_ID);
460 lp->link_id.header.length = htons (TE_LINK_SUBTLV_DEF_SIZE);
463 * The Link ID is identical to the contents of the Link ID field
464 * in the Router LSA for these link types.
468 case OSPF_IFTYPE_POINTOPOINT:
469 /* Take the router ID of the neighbor. */
470 if ((nbr = ospf_nbr_lookup_ptop (oi)) && nbr->state == NSM_Full)
472 lp->link_id.value = nbr->router_id;
476 case OSPF_IFTYPE_BROADCAST:
477 case OSPF_IFTYPE_NBMA:
478 /* Take the interface address of the designated router. */
479 if ((nbr = ospf_nbr_lookup_by_addr (oi->nbrs, &DR (oi))) == NULL)
482 if (nbr->state == NSM_Full
483 || (IPV4_ADDR_SAME (&oi->address->u.prefix4, &DR (oi))
484 && ospf_nbr_count (oi, NSM_Full) > 0))
486 lp->link_id.value = DR (oi);
491 /* Not supported yet. *//* XXX */
492 lp->link_id.header.type = htons (0);
499 masklen2ip (oi->address->prefixlen, &mask);
500 lp->link_id.value.s_addr = oi->address->u.prefix4.s_addr & mask.s_addr;
506 set_linkparams_lclif_ipaddr (struct mpls_te_link *lp, struct in_addr lclif)
509 lp->lclif_ipaddr.header.type = htons (TE_LINK_SUBTLV_LCLIF_IPADDR);
510 lp->lclif_ipaddr.header.length = htons (TE_LINK_SUBTLV_DEF_SIZE);
511 lp->lclif_ipaddr.value[0] = lclif;
516 set_linkparams_rmtif_ipaddr (struct mpls_te_link *lp, struct in_addr rmtif)
519 lp->rmtif_ipaddr.header.type = htons (TE_LINK_SUBTLV_RMTIF_IPADDR);
520 lp->rmtif_ipaddr.header.length = htons (TE_LINK_SUBTLV_DEF_SIZE);
521 lp->rmtif_ipaddr.value[0] = rmtif;
526 set_linkparams_te_metric (struct mpls_te_link *lp, u_int32_t te_metric)
528 lp->te_metric.header.type = htons (TE_LINK_SUBTLV_TE_METRIC);
529 lp->te_metric.header.length = htons (TE_LINK_SUBTLV_DEF_SIZE);
530 lp->te_metric.value = htonl (te_metric);
535 set_linkparams_max_bw (struct mpls_te_link *lp, float fp)
537 lp->max_bw.header.type = htons (TE_LINK_SUBTLV_MAX_BW);
538 lp->max_bw.header.length = htons (TE_LINK_SUBTLV_DEF_SIZE);
539 lp->max_bw.value = htonf (fp);
544 set_linkparams_max_rsv_bw (struct mpls_te_link *lp, float fp)
546 lp->max_rsv_bw.header.type = htons (TE_LINK_SUBTLV_MAX_RSV_BW);
547 lp->max_rsv_bw.header.length = htons (TE_LINK_SUBTLV_DEF_SIZE);
548 lp->max_rsv_bw.value = htonf (fp);
553 set_linkparams_unrsv_bw (struct mpls_te_link *lp, int priority, float fp)
555 /* Note that TLV-length field is the size of array. */
556 lp->unrsv_bw.header.type = htons (TE_LINK_SUBTLV_UNRSV_BW);
557 lp->unrsv_bw.header.length = htons (TE_LINK_SUBTLV_UNRSV_SIZE);
558 lp->unrsv_bw.value [priority] = htonf (fp);
563 set_linkparams_rsc_clsclr (struct mpls_te_link *lp, u_int32_t classcolor)
565 lp->rsc_clsclr.header.type = htons (TE_LINK_SUBTLV_RSC_CLSCLR);
566 lp->rsc_clsclr.header.length = htons (TE_LINK_SUBTLV_DEF_SIZE);
567 lp->rsc_clsclr.value = htonl (classcolor);
572 set_linkparams_inter_as (struct mpls_te_link *lp, struct in_addr addr,
576 /* Set the Remote ASBR IP address and then the associated AS number */
577 lp->rip.header.type = htons (TE_LINK_SUBTLV_RIP);
578 lp->rip.header.length = htons (TE_LINK_SUBTLV_DEF_SIZE);
579 lp->rip.value = addr;
581 lp->ras.header.type = htons (TE_LINK_SUBTLV_RAS);
582 lp->ras.header.length = htons (TE_LINK_SUBTLV_DEF_SIZE);
583 lp->ras.value = htonl (as);
587 unset_linkparams_inter_as (struct mpls_te_link *lp)
590 /* Reset the Remote ASBR IP address and then the associated AS number */
591 lp->rip.header.type = htons (0);
592 lp->rip.header.length = htons (0);
593 lp->rip.value.s_addr = htonl (0);
595 lp->ras.header.type = htons (0);
596 lp->ras.header.length = htons (0);
597 lp->ras.value = htonl (0);
601 set_linkparams_llri (struct mpls_te_link *lp, u_int32_t local,
605 lp->llri.header.type = htons (TE_LINK_SUBTLV_LLRI);
606 lp->llri.header.length = htons (TE_LINK_SUBTLV_LLRI_SIZE);
607 lp->llri.local = htonl (local);
608 lp->llri.remote = htonl (remote);
612 set_linkparams_lrrid (struct mpls_te_link *lp, struct in_addr local,
613 struct in_addr remote)
616 lp->lrrid.header.type = htons (TE_LINK_SUBTLV_LRRID);
617 lp->lrrid.header.length = htons (TE_LINK_SUBTLV_LRRID_SIZE);
618 lp->lrrid.local.s_addr = local.s_addr;
619 lp->lrrid.remote.s_addr = remote.s_addr;
623 set_linkparams_av_delay (struct mpls_te_link *lp, u_int32_t delay, u_char anormal)
626 /* Note that TLV-length field is the size of array. */
627 lp->av_delay.header.type = htons (TE_LINK_SUBTLV_AV_DELAY);
628 lp->av_delay.header.length = htons (TE_LINK_SUBTLV_DEF_SIZE);
629 tmp = delay & TE_EXT_MASK;
631 tmp |= TE_EXT_ANORMAL;
632 lp->av_delay.value = htonl (tmp);
637 set_linkparams_mm_delay (struct mpls_te_link *lp, u_int32_t low, u_int32_t high, u_char anormal)
640 /* Note that TLV-length field is the size of array. */
641 lp->mm_delay.header.type = htons (TE_LINK_SUBTLV_MM_DELAY);
642 lp->mm_delay.header.length = htons (TE_LINK_SUBTLV_MM_DELAY_SIZE);
643 tmp = low & TE_EXT_MASK;
645 tmp |= TE_EXT_ANORMAL;
646 lp->mm_delay.low = htonl (tmp);
647 lp->mm_delay.high = htonl (high);
652 set_linkparams_delay_var (struct mpls_te_link *lp, u_int32_t jitter)
654 /* Note that TLV-length field is the size of array. */
655 lp->delay_var.header.type = htons (TE_LINK_SUBTLV_DELAY_VAR);
656 lp->delay_var.header.length = htons (TE_LINK_SUBTLV_DEF_SIZE);
657 lp->delay_var.value = htonl (jitter & TE_EXT_MASK);
662 set_linkparams_pkt_loss (struct mpls_te_link *lp, u_int32_t loss, u_char anormal)
665 /* Note that TLV-length field is the size of array. */
666 lp->pkt_loss.header.type = htons (TE_LINK_SUBTLV_PKT_LOSS);
667 lp->pkt_loss.header.length = htons (TE_LINK_SUBTLV_DEF_SIZE);
668 tmp = loss & TE_EXT_MASK;
670 tmp |= TE_EXT_ANORMAL;
671 lp->pkt_loss.value = htonl (tmp);
676 set_linkparams_res_bw (struct mpls_te_link *lp, float fp)
678 /* Note that TLV-length field is the size of array. */
679 lp->res_bw.header.type = htons (TE_LINK_SUBTLV_RES_BW);
680 lp->res_bw.header.length = htons (TE_LINK_SUBTLV_DEF_SIZE);
681 lp->res_bw.value = htonf (fp);
686 set_linkparams_ava_bw (struct mpls_te_link *lp, float fp)
688 /* Note that TLV-length field is the size of array. */
689 lp->ava_bw.header.type = htons (TE_LINK_SUBTLV_AVA_BW);
690 lp->ava_bw.header.length = htons (TE_LINK_SUBTLV_DEF_SIZE);
691 lp->ava_bw.value = htonf (fp);
696 set_linkparams_use_bw (struct mpls_te_link *lp, float fp)
698 /* Note that TLV-length field is the size of array. */
699 lp->use_bw.header.type = htons (TE_LINK_SUBTLV_USE_BW);
700 lp->use_bw.header.length = htons (TE_LINK_SUBTLV_DEF_SIZE);
701 lp->use_bw.value = htonf (fp);
705 /* Update TE parameters from Interface */
707 update_linkparams(struct mpls_te_link *lp)
710 struct interface *ifp;
712 /* Get the Interface structure */
713 if ((ifp = lp->ifp) == NULL)
715 zlog_warn("OSPF MPLS-TE: Abort update TE parameters: no interface associated to Link Parameters");
718 if (!HAS_LINK_PARAMS(ifp))
720 zlog_warn("OSPF MPLS-TE: Abort update TE parameters: no Link Parameters for interface");
724 /* RFC3630 metrics */
725 if (IS_PARAM_SET(ifp->link_params, LP_ADM_GRP))
726 set_linkparams_rsc_clsclr (lp, ifp->link_params->admin_grp);
728 TLV_TYPE(lp->rsc_clsclr) = 0;
730 if (IS_PARAM_SET(ifp->link_params, LP_MAX_BW))
731 set_linkparams_max_bw (lp, ifp->link_params->max_bw);
733 TLV_TYPE(lp->max_bw) = 0;
735 if (IS_PARAM_SET(ifp->link_params, LP_MAX_RSV_BW))
736 set_linkparams_max_rsv_bw (lp, ifp->link_params->max_rsv_bw);
738 TLV_TYPE(lp->max_rsv_bw) = 0;
740 if (IS_PARAM_SET(ifp->link_params, LP_UNRSV_BW))
741 for (i = 0; i < MAX_CLASS_TYPE; i++)
742 set_linkparams_unrsv_bw (lp, i, ifp->link_params->unrsv_bw[i]);
744 TLV_TYPE(lp->unrsv_bw) = 0;
746 if (IS_PARAM_SET(ifp->link_params, LP_TE))
747 set_linkparams_te_metric(lp, ifp->link_params->te_metric);
749 TLV_TYPE(lp->te_metric) = 0;
751 /* TE metric Extensions */
752 if (IS_PARAM_SET(ifp->link_params, LP_DELAY))
753 set_linkparams_av_delay(lp, ifp->link_params->av_delay, 0);
755 TLV_TYPE(lp->av_delay) = 0;
757 if (IS_PARAM_SET(ifp->link_params, LP_MM_DELAY))
758 set_linkparams_mm_delay(lp, ifp->link_params->min_delay, ifp->link_params->max_delay, 0);
760 TLV_TYPE(lp->mm_delay) = 0;
762 if (IS_PARAM_SET(ifp->link_params, LP_DELAY_VAR))
763 set_linkparams_delay_var(lp, ifp->link_params->delay_var);
765 TLV_TYPE(lp->delay_var) = 0;
767 if (IS_PARAM_SET(ifp->link_params, LP_PKT_LOSS))
768 set_linkparams_pkt_loss(lp, ifp->link_params->pkt_loss, 0);
770 TLV_TYPE(lp->pkt_loss) = 0;
772 if (IS_PARAM_SET(ifp->link_params, LP_RES_BW))
773 set_linkparams_res_bw(lp, ifp->link_params->res_bw);
775 TLV_TYPE(lp->res_bw) = 0;
777 if (IS_PARAM_SET(ifp->link_params, LP_AVA_BW))
778 set_linkparams_ava_bw(lp, ifp->link_params->ava_bw);
780 TLV_TYPE(lp->ava_bw) = 0;
782 if (IS_PARAM_SET(ifp->link_params, LP_USE_BW))
783 set_linkparams_use_bw(lp, ifp->link_params->use_bw);
785 TLV_TYPE(lp->use_bw) = 0;
788 if (IS_PARAM_SET(ifp->link_params, LP_RMT_AS))
790 /* Flush LSA if it engaged and was previously a STD_TE one */
791 if (IS_STD_TE(lp->type) && CHECK_FLAG (lp->flags, LPFLG_LSA_ENGAGED))
793 if (IS_DEBUG_OSPF_TE)
794 zlog_debug("OSPF MPLS-TE Update IF: Switch from Standard LSA to INTER-AS for %s[%d/%d]",
795 ifp->name, lp->flags, lp->type);
797 ospf_mpls_te_lsa_schedule (lp, FLUSH_THIS_LSA);
798 /* Then, switch it to INTER-AS */
799 if (OspfMplsTE.inter_as == AS)
800 lp->flags = INTER_AS | FLOOD_AS;
803 lp->flags = INTER_AS | FLOOD_AREA;
804 lp->area = ospf_area_lookup_by_area_id (ospf_lookup(), OspfMplsTE.interas_areaid);
807 set_linkparams_inter_as(lp, ifp->link_params->rmt_ip, ifp->link_params->rmt_as);
811 if (IS_DEBUG_OSPF_TE)
812 zlog_debug("OSPF MPLS-TE Update IF: Switch from INTER-AS LSA to Standard for %s[%d/%d]",
813 ifp->name, lp->flags, lp->type);
815 /* reset inter-as TE params */
816 /* Flush LSA if it engaged and was previously an INTER_AS one */
817 if (IS_INTER_AS(lp->type) && CHECK_FLAG (lp->flags, LPFLG_LSA_ENGAGED))
819 ospf_mpls_te_lsa_schedule (lp, FLUSH_THIS_LSA);
820 /* Then, switch it to Standard TE */
821 lp->flags = STD_TE | FLOOD_AREA;
823 unset_linkparams_inter_as (lp);
828 initialize_linkparams (struct mpls_te_link *lp)
830 struct interface *ifp = lp->ifp;
831 struct ospf_interface *oi;
833 if (IS_DEBUG_OSPF_TE)
834 zlog_debug("MPLS-TE(initialize_linkparams) Initialize Link Parameters for interface %s",
837 if ((oi = lookup_oi_by_ifp (ifp, NULL, OI_ANY)) == NULL)
839 zlog_warn("MPLS-TE(initialize_linkparams) Could not find corresponding OSPF Interface for %s",
845 * Try to set initial values those can be derived from
846 * zebra-interface information.
848 set_linkparams_link_type (oi, lp);
850 /* Set local IP addr */
851 set_linkparams_lclif_ipaddr (lp, oi->address->u.prefix4);
853 /* Set Remote IP addr if Point to Point Interface */
854 if (oi->type == LINK_TYPE_SUBTLV_VALUE_PTP)
856 struct prefix *pref = CONNECTED_PREFIX(oi->connected);
858 set_linkparams_rmtif_ipaddr(lp, pref->u.prefix4);
861 /* Keep Area information in combination with link parameters. */
868 is_mandated_params_set (struct mpls_te_link *lp)
872 if (ntohs (OspfMplsTE.router_addr.header.type) == 0)
874 zlog_warn ("MPLS-TE(is_mandated_params_set) Missing Router Address");
878 if (ntohs (lp->link_type.header.type) == 0)
880 zlog_warn ("MPLS-TE(is_mandated_params_set) Missing Link Type");
884 if (!IS_INTER_AS (lp->type) && (ntohs (lp->link_id.header.type) == 0))
886 zlog_warn ("MPLS-TE(is_mandated_params_set) Missing Link ID");
895 /*------------------------------------------------------------------------*
896 * Followings are callback functions against generic Opaque-LSAs handling.
897 *------------------------------------------------------------------------*/
900 ospf_mpls_te_new_if (struct interface *ifp)
902 struct mpls_te_link *new;
905 if (IS_DEBUG_OSPF_TE)
906 zlog_debug ("MPLS-TE(ospf_mpls_te_new_if) Add new %s interface %s to MPLS-TE list",
907 ifp->link_params ? "Active" : "Inactive", ifp->name);
909 if (lookup_linkparams_by_ifp (ifp) != NULL)
911 zlog_warn ("ospf_mpls_te_new_if: ifp(%p) already in use?", (void *)ifp);
912 rc = 0; /* Do nothing here. */
916 new = XCALLOC (MTYPE_OSPF_MPLS_TE, sizeof (struct mpls_te_link));
919 zlog_warn ("ospf_mpls_te_new_if: XMALLOC: %s", safe_strerror (errno));
923 new->instance = get_mpls_te_instance_value ();
925 /* By default TE-Link is RFC3630 compatible flooding in Area and not active */
926 /* This default behavior will be adapted with call to ospf_mpls_te_update_if() */
927 new->type = STD_TE | FLOOD_AREA;
928 new->flags = LPFLG_LSA_INACTIVE;
930 /* Initialize Link Parameters from Interface */
931 initialize_linkparams(new);
933 /* Set TE Parameters from Interface */
934 update_linkparams(new);
936 /* Add Link Parameters structure to the list */
937 listnode_add (OspfMplsTE.iflist, new);
939 if (IS_DEBUG_OSPF_TE)
940 zlog_debug("OSPF MPLS-TE New IF: Add new LP context for %s[%d/%d]",
941 ifp->name, new->flags, new->type);
943 /* Schedule Opaque-LSA refresh. *//* XXX */
951 ospf_mpls_te_del_if (struct interface *ifp)
953 struct mpls_te_link *lp;
956 if ((lp = lookup_linkparams_by_ifp (ifp)) != NULL)
958 struct list *iflist = OspfMplsTE.iflist;
960 /* Dequeue listnode entry from the list. */
961 listnode_delete (iflist, lp);
963 /* Avoid misjudgement in the next lookup. */
964 if (listcount (iflist) == 0)
965 iflist->head = iflist->tail = NULL;
967 XFREE (MTYPE_OSPF_MPLS_TE, lp);
970 /* Schedule Opaque-LSA refresh. *//* XXX */
977 /* Main initialization / update function of the MPLS TE Link context */
979 /* Call when interface TE Link parameters are modified */
981 ospf_mpls_te_update_if (struct interface *ifp)
983 struct mpls_te_link *lp;
985 if (IS_DEBUG_OSPF_TE)
986 zlog_debug ("OSPF MPLS-TE: Update LSA parameters for interface %s [%s]",
987 ifp->name, HAS_LINK_PARAMS(ifp) ? "ON" : "OFF");
989 /* Get Link context from interface */
990 if ((lp = lookup_linkparams_by_ifp(ifp)) == NULL)
992 zlog_warn ("OSPF MPLS-TE Update: Did not find Link Parameters context for interface %s", ifp->name);
996 /* Fulfill MPLS-TE Link TLV from Interface TE Link parameters */
997 if (HAS_LINK_PARAMS(ifp))
999 SET_FLAG (lp->flags, LPFLG_LSA_ACTIVE);
1001 /* Update TE parameters */
1002 update_linkparams(lp);
1004 /* Finally Re-Originate or Refresh Opaque LSA if MPLS_TE is enabled */
1005 if (OspfMplsTE.status == enabled)
1006 if (lp->area != NULL)
1008 if CHECK_FLAG (lp->flags, LPFLG_LSA_ENGAGED)
1009 ospf_mpls_te_lsa_schedule (lp, REFRESH_THIS_LSA);
1011 ospf_mpls_te_lsa_schedule (lp, REORIGINATE_THIS_LSA);
1016 /* If MPLS TE is disable on this interface, flush LSA if it is already engaged */
1017 if CHECK_FLAG (lp->flags, LPFLG_LSA_ENGAGED)
1018 ospf_mpls_te_lsa_schedule (lp, FLUSH_THIS_LSA);
1020 /* Reset Activity flag */
1021 lp->flags = LPFLG_LSA_INACTIVE;
1028 ospf_mpls_te_ism_change (struct ospf_interface *oi, int old_state)
1030 struct te_link_subtlv_link_type old_type;
1031 struct te_link_subtlv_link_id old_id;
1032 struct mpls_te_link *lp;
1034 if ((lp = lookup_linkparams_by_ifp (oi->ifp)) == NULL)
1036 zlog_warn ("ospf_mpls_te_ism_change: Cannot get linkparams from OI(%s)?", IF_NAME (oi));
1040 if (oi->area == NULL || oi->area->ospf == NULL)
1042 zlog_warn ("ospf_mpls_te_ism_change: Cannot refer to OSPF from OI(%s)?", IF_NAME (oi));
1046 if ((lp->area != NULL
1047 && ! IPV4_ADDR_SAME (&lp->area->area_id, &oi->area->area_id))
1048 || (lp->area != NULL && oi->area == NULL))
1050 /* How should we consider this case? */
1051 zlog_warn ("MPLS-TE: Area for OI(%s) has changed to [%s], flush previous LSAs",
1052 IF_NAME (oi), oi->area ? inet_ntoa (oi->area->area_id) : "N/A");
1053 ospf_mpls_te_lsa_schedule (lp, FLUSH_THIS_LSA);
1056 /* Keep Area information in combination with linkparams. */
1057 lp->area = oi->area;
1059 /* Keep interface MPLS-TE status */
1060 lp->flags = HAS_LINK_PARAMS(oi->ifp);
1064 case ISM_PointToPoint:
1068 old_type = lp->link_type;
1069 old_id = lp->link_id;
1071 /* Set Link type, Link ID, Local and Remote IP addr */
1072 set_linkparams_link_type (oi, lp);
1073 set_linkparams_link_id (oi, lp);
1074 set_linkparams_lclif_ipaddr (lp, oi->address->u.prefix4);
1076 if (oi->type == LINK_TYPE_SUBTLV_VALUE_PTP)
1078 struct prefix *pref = CONNECTED_PREFIX(oi->connected);
1080 set_linkparams_rmtif_ipaddr(lp, pref->u.prefix4);
1083 /* Update TE parameters */
1084 update_linkparams(lp);
1086 /* Try to Schedule LSA */
1087 if ((ntohs (old_type.header.type) != ntohs (lp->link_type.header.type)
1088 || old_type.link_type.value != lp->link_type.link_type.value)
1089 || (ntohs (old_id.header.type) != ntohs (lp->link_id.header.type)
1090 || ntohl (old_id.value.s_addr) !=
1091 ntohl (lp->link_id.value.s_addr)))
1093 if CHECK_FLAG (lp->flags, LPFLG_LSA_ENGAGED)
1094 ospf_mpls_te_lsa_schedule (lp, REFRESH_THIS_LSA);
1096 ospf_mpls_te_lsa_schedule (lp, REORIGINATE_THIS_LSA);
1101 lp->link_type.header.type = htons (0);
1102 lp->link_id.header.type = htons (0);
1104 if CHECK_FLAG (lp->flags, LPFLG_LSA_ENGAGED)
1105 ospf_mpls_te_lsa_schedule (lp, FLUSH_THIS_LSA);
1115 ospf_mpls_te_nsm_change (struct ospf_neighbor *nbr, int old_state)
1117 /* Nothing to do here */
1121 /*------------------------------------------------------------------------*
1122 * Followings are OSPF protocol processing functions for MPLS-TE.
1123 *------------------------------------------------------------------------*/
1126 build_tlv_header (struct stream *s, struct te_tlv_header *tlvh)
1128 stream_put (s, tlvh, sizeof (struct te_tlv_header));
1133 build_router_tlv (struct stream *s)
1135 struct te_tlv_header *tlvh = &OspfMplsTE.router_addr.header;
1136 if (ntohs (tlvh->type) != 0)
1138 build_tlv_header (s, tlvh);
1139 stream_put (s, tlvh+1, TLV_BODY_SIZE (tlvh));
1145 build_link_subtlv (struct stream *s, struct te_tlv_header *tlvh)
1148 if ((tlvh != NULL) && (ntohs (tlvh->type) != 0))
1150 build_tlv_header (s, tlvh);
1151 stream_put (s, tlvh+1, TLV_BODY_SIZE (tlvh));
1157 build_link_tlv (struct stream *s, struct mpls_te_link *lp)
1159 set_linkparams_link_header (lp);
1160 build_tlv_header (s, &lp->link_header.header);
1162 build_link_subtlv (s, &lp->link_type.header);
1163 build_link_subtlv (s, &lp->link_id.header);
1164 build_link_subtlv (s, &lp->lclif_ipaddr.header);
1165 build_link_subtlv (s, &lp->rmtif_ipaddr.header);
1166 build_link_subtlv (s, &lp->te_metric.header);
1167 build_link_subtlv (s, &lp->max_bw.header);
1168 build_link_subtlv (s, &lp->max_rsv_bw.header);
1169 build_link_subtlv (s, &lp->unrsv_bw.header);
1170 build_link_subtlv (s, &lp->rsc_clsclr.header);
1171 build_link_subtlv (s, &lp->lrrid.header);
1172 build_link_subtlv (s, &lp->llri.header);
1173 build_link_subtlv (s, &lp->rip.header);
1174 build_link_subtlv (s, &lp->ras.header);
1175 build_link_subtlv (s, &lp->av_delay.header);
1176 build_link_subtlv (s, &lp->mm_delay.header);
1177 build_link_subtlv (s, &lp->delay_var.header);
1178 build_link_subtlv (s, &lp->pkt_loss.header);
1179 build_link_subtlv (s, &lp->res_bw.header);
1180 build_link_subtlv (s, &lp->ava_bw.header);
1181 build_link_subtlv (s, &lp->res_bw.header);
1187 ospf_mpls_te_lsa_body_set (struct stream *s, struct mpls_te_link *lp)
1190 * The router address TLV is type 1, and ...
1191 * It must appear in exactly one
1192 * Traffic Engineering LSA originated by a router.
1194 build_router_tlv (s);
1197 * Only one Link TLV shall be carried in each LSA, allowing for fine
1198 * granularity changes in topology.
1200 build_link_tlv (s, lp);
1204 /* Create new opaque-LSA. */
1205 static struct ospf_lsa *
1206 ospf_mpls_te_lsa_new (struct ospf_area *area, struct mpls_te_link *lp)
1209 struct lsa_header *lsah;
1210 struct ospf_lsa *new = NULL;
1211 u_char options, lsa_type = 0;
1212 struct in_addr lsa_id;
1216 /* Create a stream for LSA. */
1217 if ((s = stream_new (OSPF_MAX_LSA_SIZE)) == NULL)
1219 zlog_warn ("ospf_mpls_te_lsa_new: stream_new() ?");
1222 lsah = (struct lsa_header *) STREAM_DATA (s);
1224 options = OSPF_OPTION_O; /* Don't forget this :-) */
1226 /* Set opaque-LSA header fields depending of the type of RFC */
1227 if (IS_INTER_AS (lp->type))
1229 if IS_FLOOD_AS (lp->type)
1231 options |= OSPF_OPTION_E; /* Enable AS external as we flood Inter-AS with Opaque Type 11 */
1232 lsa_type = OSPF_OPAQUE_AS_LSA;
1236 options |= LSA_OPTIONS_GET (area); /* Get area default option */
1237 options |= LSA_OPTIONS_NSSA_GET (area);
1238 lsa_type = OSPF_OPAQUE_AREA_LSA;
1240 tmp = SET_OPAQUE_LSID (OPAQUE_TYPE_INTER_AS_LSA, lp->instance);
1241 lsa_id.s_addr = htonl (tmp);
1243 struct ospf *top = ospf_lookup ();
1245 lsa_header_set (s, options, lsa_type, lsa_id, top->router_id);
1249 options |= LSA_OPTIONS_GET (area); /* Get area default option */
1250 options |= LSA_OPTIONS_NSSA_GET (area);
1251 lsa_type = OSPF_OPAQUE_AREA_LSA;
1252 tmp = SET_OPAQUE_LSID (OPAQUE_TYPE_TRAFFIC_ENGINEERING_LSA, lp->instance);
1253 lsa_id.s_addr = htonl (tmp);
1254 lsa_header_set (s, options, lsa_type, lsa_id, area->ospf->router_id);
1257 if (IS_DEBUG_OSPF (lsa, LSA_GENERATE))
1258 zlog_debug ("LSA[Type%d:%s]: Create an Opaque-LSA/MPLS-TE instance",
1259 lsa_type, inet_ntoa (lsa_id));
1261 /* Set opaque-LSA body fields. */
1262 ospf_mpls_te_lsa_body_set (s, lp);
1265 length = stream_get_endp (s);
1266 lsah->length = htons (length);
1268 /* Now, create an OSPF LSA instance. */
1269 if ((new = ospf_lsa_new ()) == NULL)
1271 zlog_warn ("ospf_mpls_te_lsa_new: ospf_lsa_new() ?");
1275 if ((new->data = ospf_lsa_data_new (length)) == NULL)
1277 zlog_warn ("ospf_mpls_te_lsa_new: ospf_lsa_data_new() ?");
1278 ospf_lsa_unlock (&new);
1285 SET_FLAG (new->flags, OSPF_LSA_SELF);
1286 memcpy (new->data, lsah, length);
1294 ospf_mpls_te_lsa_originate1 (struct ospf_area *area, struct mpls_te_link *lp)
1296 struct ospf_lsa *new;
1299 /* Create new Opaque-LSA/MPLS-TE instance. */
1300 if ((new = ospf_mpls_te_lsa_new (area, lp)) == NULL)
1302 zlog_warn ("ospf_mpls_te_lsa_originate1: ospf_mpls_te_lsa_new() ?");
1306 /* Install this LSA into LSDB. */
1307 if (ospf_lsa_install (area->ospf, NULL/*oi*/, new) == NULL)
1309 zlog_warn ("ospf_mpls_te_lsa_originate1: ospf_lsa_install() ?");
1310 ospf_lsa_unlock (&new);
1314 /* Now this link-parameter entry has associated LSA. */
1315 SET_FLAG (lp->flags, LPFLG_LSA_ENGAGED);
1316 /* Update new LSA origination count. */
1317 area->ospf->lsa_originate_count++;
1319 /* Flood new LSA through area. */
1320 ospf_flood_through_area (area, NULL/*nbr*/, new);
1322 if (IS_DEBUG_OSPF (lsa, LSA_GENERATE))
1324 char area_id[INET_ADDRSTRLEN];
1325 strcpy (area_id, inet_ntoa (area->area_id));
1326 zlog_debug ("LSA[Type%d:%s]: Originate Opaque-LSA/MPLS-TE: Area(%s), Link(%s)",
1327 new->data->type, inet_ntoa (new->data->id), area_id, lp->ifp->name);
1328 ospf_lsa_header_dump (new->data);
1337 ospf_mpls_te_lsa_originate_area (void *arg)
1339 struct ospf_area *area = (struct ospf_area *) arg;
1340 struct listnode *node, *nnode;
1341 struct mpls_te_link *lp;
1344 if (OspfMplsTE.status == disabled)
1346 zlog_info ("ospf_mpls_te_lsa_originate_area: MPLS-TE is disabled now.");
1347 rc = 0; /* This is not an error case. */
1351 for (ALL_LIST_ELEMENTS (OspfMplsTE.iflist, node, nnode, lp))
1353 /* Process only enabled LSA with area scope flooding */
1354 if (!CHECK_FLAG (lp->flags, LPFLG_LSA_ACTIVE) || IS_FLOOD_AS (lp->type))
1357 if (lp->area == NULL)
1360 if (! IPV4_ADDR_SAME (&lp->area->area_id, &area->area_id))
1363 if CHECK_FLAG (lp->flags, LPFLG_LSA_ENGAGED)
1365 if CHECK_FLAG (lp->flags, LPFLG_LSA_FORCED_REFRESH)
1367 UNSET_FLAG (lp->flags, LPFLG_LSA_FORCED_REFRESH);
1368 zlog_warn ("OSPF MPLS-TE (ospf_mpls_te_lsa_originate_area): Refresh instead of Originate");
1369 ospf_mpls_te_lsa_schedule (lp, REFRESH_THIS_LSA);
1373 if (! is_mandated_params_set (lp))
1375 zlog_warn ("ospf_mpls_te_lsa_originate_area: Link(%s) lacks some mandated MPLS-TE parameters.",
1376 lp->ifp ? lp->ifp->name : "?");
1380 /* Ok, let's try to originate an LSA for this area and Link. */
1381 if (IS_DEBUG_OSPF_TE)
1382 zlog_debug ("MPLS-TE(ospf_mpls_te_lsa_originate_area) Let's finally reoriginate the LSA %d through the Area %s for Link %s",
1383 lp->instance, inet_ntoa (area->area_id), lp->ifp ? lp->ifp->name : "?");
1384 if (ospf_mpls_te_lsa_originate1 (area, lp) != 0)
1394 ospf_mpls_te_lsa_originate2 (struct ospf *top, struct mpls_te_link *lp)
1396 struct ospf_lsa *new;
1399 /* Create new Opaque-LSA/Inter-AS instance. */
1400 if ((new = ospf_mpls_te_lsa_new (NULL, lp)) == NULL)
1402 zlog_warn ("ospf_mpls_te_lsa_originate2: ospf_router_info_lsa_new() ?");
1406 /* Install this LSA into LSDB. */
1407 if (ospf_lsa_install (top, NULL /*oi */ , new) == NULL)
1409 zlog_warn ("ospf_mpls_te_lsa_originate2: ospf_lsa_install() ?");
1410 ospf_lsa_unlock (&new);
1414 /* Now this Router Info parameter entry has associated LSA. */
1415 SET_FLAG (lp->flags, LPFLG_LSA_ENGAGED);
1416 /* Update new LSA origination count. */
1417 top->lsa_originate_count++;
1419 /* Flood new LSA through AS. */
1420 ospf_flood_through_as (top, NULL /*nbr */ , new);
1422 if (IS_DEBUG_OSPF (lsa, LSA_GENERATE))
1424 zlog_debug ("LSA[Type%d:%s]: Originate Opaque-LSA/MPLS-TE Inter-AS",
1425 new->data->type, inet_ntoa (new->data->id));
1426 ospf_lsa_header_dump (new->data);
1434 ospf_mpls_te_lsa_originate_as (void *arg)
1437 struct ospf_area *area;
1438 struct listnode *node, *nnode;
1439 struct mpls_te_link *lp;
1442 if ((OspfMplsTE.status == disabled) || (OspfMplsTE.inter_as == Disable))
1445 ("ospf_mpls_te_lsa_originate_as: MPLS-TE Inter-AS is disabled for now.");
1446 rc = 0; /* This is not an error case. */
1450 for (ALL_LIST_ELEMENTS (OspfMplsTE.iflist, node, nnode, lp))
1452 /* Process only enabled INTER_AS Links or Pseudo-Links */
1453 if (!CHECK_FLAG (lp->flags, LPFLG_LSA_ACTIVE) || !IS_INTER_AS (lp->type))
1456 if CHECK_FLAG (lp->flags, LPFLG_LSA_ENGAGED)
1458 if CHECK_FLAG (lp->flags, LPFLG_LSA_FORCED_REFRESH)
1460 UNSET_FLAG (lp->flags, LPFLG_LSA_FORCED_REFRESH);
1461 ospf_mpls_te_lsa_schedule (lp, REFRESH_THIS_LSA);
1465 if (!is_mandated_params_set (lp))
1467 zlog_warn ("ospf_mpls_te_lsa_originate_as: Link(%s) lacks some mandated MPLS-TE parameters.",
1468 lp->ifp ? lp->ifp->name : "?");
1472 /* Ok, let's try to originate an LSA for this AS and Link. */
1473 if (IS_DEBUG_OSPF_TE)
1474 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",
1475 lp->instance, IS_FLOOD_AS (lp->type) ? "AS" : "Area", lp->ifp ? lp->ifp->name : "Unknown");
1477 if (IS_FLOOD_AS (lp->type))
1479 top = (struct ospf *) arg;
1480 rc = ospf_mpls_te_lsa_originate2 (top, lp);
1484 area = (struct ospf_area *) arg;
1485 rc = ospf_mpls_te_lsa_originate1 (area, lp);
1493 static struct ospf_lsa *
1494 ospf_mpls_te_lsa_refresh (struct ospf_lsa *lsa)
1496 struct mpls_te_link *lp;
1497 struct ospf_area *area = lsa->area;
1499 struct ospf_lsa *new = NULL;
1501 if (OspfMplsTE.status == disabled)
1504 * This LSA must have flushed before due to MPLS-TE status change.
1505 * It seems a slip among routers in the routing domain.
1507 zlog_info ("ospf_mpls_te_lsa_refresh: MPLS-TE is disabled now.");
1508 lsa->data->ls_age = htons (OSPF_LSA_MAXAGE); /* Flush it anyway. */
1511 /* At first, resolve lsa/lp relationship. */
1512 if ((lp = lookup_linkparams_by_instance (lsa)) == NULL)
1514 zlog_warn ("ospf_mpls_te_lsa_refresh: Invalid parameter?");
1515 lsa->data->ls_age = htons (OSPF_LSA_MAXAGE); /* Flush it anyway. */
1518 /* Check if lp was not disable in the interval */
1519 if (!CHECK_FLAG (lp->flags, LPFLG_LSA_ACTIVE))
1521 zlog_warn ("ospf_mpls_te_lsa_refresh: lp was disabled: Flush it!");
1522 lsa->data->ls_age = htons (OSPF_LSA_MAXAGE); /* Flush it anyway. */
1525 /* If the lsa's age reached to MaxAge, start flushing procedure. */
1526 if (IS_LSA_MAXAGE (lsa))
1529 UNSET_FLAG (lp->flags, LPFLG_LSA_ENGAGED);
1530 ospf_opaque_lsa_flush_schedule (lsa);
1534 /* Create new Opaque-LSA/MPLS-TE instance. */
1535 if ((new = ospf_mpls_te_lsa_new (area, lp)) == NULL)
1537 zlog_warn ("ospf_mpls_te_lsa_refresh: ospf_mpls_te_lsa_new() ?");
1540 new->data->ls_seqnum = lsa_seqnum_increment (lsa);
1542 /* Install this LSA into LSDB. */
1543 /* Given "lsa" will be freed in the next function. */
1544 /* As area could be NULL i.e. when using OPAQUE_LSA_AS, we prefer to use ospf_lookup() to get ospf instance */
1548 top = ospf_lookup ();
1550 if (ospf_lsa_install (top, NULL /*oi */ , new) == NULL)
1552 zlog_warn ("ospf_mpls_te_lsa_refresh: ospf_lsa_install() ?");
1553 ospf_lsa_unlock (&new);
1557 /* Flood updated LSA through AS or Area depending of the RFC of the link */
1558 if (IS_FLOOD_AS (lp->type))
1559 ospf_flood_through_as (top, NULL, new);
1561 ospf_flood_through_area (area, NULL/*nbr*/, new);
1563 /* Debug logging. */
1564 if (IS_DEBUG_OSPF (lsa, LSA_GENERATE))
1566 zlog_debug ("LSA[Type%d:%s]: Refresh Opaque-LSA/MPLS-TE",
1567 new->data->type, inet_ntoa (new->data->id));
1568 ospf_lsa_header_dump (new->data);
1576 ospf_mpls_te_lsa_schedule (struct mpls_te_link *lp, opcode_t opcode)
1578 struct ospf_lsa lsa;
1579 struct lsa_header lsah;
1583 memset (&lsa, 0, sizeof (lsa));
1584 memset (&lsah, 0, sizeof (lsah));
1585 top = ospf_lookup ();
1587 /* Check if the pseudo link is ready to flood */
1588 if (!(CHECK_FLAG (lp->flags, LPFLG_LSA_ACTIVE))
1589 || !(IS_FLOOD_AREA (lp->type) || IS_FLOOD_AS (lp->type))) {
1593 lsa.area = lp->area;
1595 if (IS_FLOOD_AS (lp->type))
1597 lsah.type = OSPF_OPAQUE_AS_LSA;
1598 tmp = SET_OPAQUE_LSID (OPAQUE_TYPE_INTER_AS_LSA, lp->instance);
1599 lsah.id.s_addr = htonl (tmp);
1603 lsah.type = OSPF_OPAQUE_AREA_LSA;
1604 if (IS_INTER_AS (lp->type))
1606 /* Set the area context if not know */
1607 if (lp->area == NULL)
1608 lp->area = ospf_area_lookup_by_area_id (top, OspfMplsTE.interas_areaid);
1609 /* Unable to set the area context. Abort! */
1610 if (lp->area == NULL)
1612 zlog_warn ("MPLS-TE(ospf_mpls_te_lsa_schedule) Area context is null. Abort !");
1615 tmp = SET_OPAQUE_LSID (OPAQUE_TYPE_INTER_AS_LSA, lp->instance);
1618 tmp = SET_OPAQUE_LSID (OPAQUE_TYPE_TRAFFIC_ENGINEERING_LSA, lp->instance);
1619 lsah.id.s_addr = htonl (tmp);
1624 case REORIGINATE_THIS_LSA:
1625 if (IS_FLOOD_AS (lp->type))
1627 ospf_opaque_lsa_reoriginate_schedule ((void *) top, OSPF_OPAQUE_AS_LSA,
1628 OPAQUE_TYPE_INTER_AS_LSA);
1632 if (IS_FLOOD_AREA (lp->type))
1634 if (IS_INTER_AS (lp->type))
1635 ospf_opaque_lsa_reoriginate_schedule ((void *) lp->area, OSPF_OPAQUE_AREA_LSA,
1636 OPAQUE_TYPE_INTER_AS_LSA);
1638 ospf_opaque_lsa_reoriginate_schedule ((void *) lp->area, OSPF_OPAQUE_AREA_LSA,
1639 OPAQUE_TYPE_TRAFFIC_ENGINEERING_LSA);
1643 case REFRESH_THIS_LSA:
1644 ospf_opaque_lsa_refresh_schedule (&lsa);
1646 case FLUSH_THIS_LSA:
1647 /* Reset Activity flag */
1648 lp->flags = LPFLG_LSA_INACTIVE;
1649 ospf_opaque_lsa_flush_schedule (&lsa);
1652 zlog_warn ("ospf_mpls_te_lsa_schedule: Unknown opcode (%u)", opcode);
1660 /*------------------------------------------------------------------------*
1661 * Followings are vty session control functions.
1662 *------------------------------------------------------------------------*/
1665 show_vty_router_addr (struct vty *vty, struct te_tlv_header *tlvh)
1667 struct te_tlv_router_addr *top = (struct te_tlv_router_addr *) tlvh;
1670 vty_out (vty, " Router-Address: %s%s", inet_ntoa (top->value),
1673 zlog_debug (" Router-Address: %s", inet_ntoa (top->value));
1675 return TLV_SIZE (tlvh);
1679 show_vty_link_header (struct vty *vty, struct te_tlv_header *tlvh)
1681 struct te_tlv_link *top = (struct te_tlv_link *) tlvh;
1684 vty_out (vty, " Link: %u octets of data%s", ntohs (top->header.length),
1687 zlog_debug (" Link: %u octets of data", ntohs (top->header.length));
1689 return TLV_HDR_SIZE; /* Here is special, not "TLV_SIZE". */
1693 show_vty_link_subtlv_link_type (struct vty *vty, struct te_tlv_header *tlvh)
1695 struct te_link_subtlv_link_type *top;
1696 const char *cp = "Unknown";
1698 top = (struct te_link_subtlv_link_type *) tlvh;
1699 switch (top->link_type.value)
1701 case LINK_TYPE_SUBTLV_VALUE_PTP:
1702 cp = "Point-to-point";
1704 case LINK_TYPE_SUBTLV_VALUE_MA:
1712 vty_out (vty, " Link-Type: %s (%u)%s", cp, top->link_type.value,
1715 zlog_debug (" Link-Type: %s (%u)", cp, top->link_type.value);
1717 return TLV_SIZE (tlvh);
1721 show_vty_link_subtlv_link_id (struct vty *vty, struct te_tlv_header *tlvh)
1723 struct te_link_subtlv_link_id *top;
1725 top = (struct te_link_subtlv_link_id *) tlvh;
1727 vty_out (vty, " Link-ID: %s%s", inet_ntoa (top->value), VTY_NEWLINE);
1729 zlog_debug (" Link-ID: %s", inet_ntoa (top->value));
1731 return TLV_SIZE (tlvh);
1735 show_vty_link_subtlv_lclif_ipaddr (struct vty *vty,
1736 struct te_tlv_header *tlvh)
1738 struct te_link_subtlv_lclif_ipaddr *top;
1741 top = (struct te_link_subtlv_lclif_ipaddr *) tlvh;
1742 n = ntohs (tlvh->length) / sizeof (top->value[0]);
1745 vty_out (vty, " Local Interface IP Address(es): %d%s", n, VTY_NEWLINE);
1747 zlog_debug (" Local Interface IP Address(es): %d", n);
1749 for (i = 0; i < n; i++)
1752 vty_out (vty, " #%d: %s%s", i, inet_ntoa (top->value[i]),
1755 zlog_debug (" #%d: %s", i, inet_ntoa (top->value[i]));
1757 return TLV_SIZE (tlvh);
1761 show_vty_link_subtlv_rmtif_ipaddr (struct vty *vty,
1762 struct te_tlv_header *tlvh)
1764 struct te_link_subtlv_rmtif_ipaddr *top;
1767 top = (struct te_link_subtlv_rmtif_ipaddr *) tlvh;
1768 n = ntohs (tlvh->length) / sizeof (top->value[0]);
1770 vty_out (vty, " Remote Interface IP Address(es): %d%s", n, VTY_NEWLINE);
1772 zlog_debug (" Remote Interface IP Address(es): %d", n);
1774 for (i = 0; i < n; i++)
1777 vty_out (vty, " #%d: %s%s", i, inet_ntoa (top->value[i]),
1780 zlog_debug (" #%d: %s", i, inet_ntoa (top->value[i]));
1782 return TLV_SIZE (tlvh);
1786 show_vty_link_subtlv_te_metric (struct vty *vty, struct te_tlv_header *tlvh)
1788 struct te_link_subtlv_te_metric *top;
1790 top = (struct te_link_subtlv_te_metric *) tlvh;
1792 vty_out (vty, " Traffic Engineering Metric: %u%s",
1793 (u_int32_t) ntohl (top->value), VTY_NEWLINE);
1795 zlog_debug (" Traffic Engineering Metric: %u",
1796 (u_int32_t) ntohl (top->value));
1798 return TLV_SIZE (tlvh);
1802 show_vty_link_subtlv_max_bw (struct vty *vty, struct te_tlv_header *tlvh)
1804 struct te_link_subtlv_max_bw *top;
1807 top = (struct te_link_subtlv_max_bw *) tlvh;
1808 fval = ntohf (top->value);
1811 vty_out (vty, " Maximum Bandwidth: %g (Bytes/sec)%s", fval, VTY_NEWLINE);
1813 zlog_debug (" Maximum Bandwidth: %g (Bytes/sec)", fval);
1815 return TLV_SIZE (tlvh);
1819 show_vty_link_subtlv_max_rsv_bw (struct vty *vty, struct te_tlv_header *tlvh)
1821 struct te_link_subtlv_max_rsv_bw *top;
1824 top = (struct te_link_subtlv_max_rsv_bw *) tlvh;
1825 fval = ntohf (top->value);
1828 vty_out (vty, " Maximum Reservable Bandwidth: %g (Bytes/sec)%s", fval,
1831 zlog_debug (" Maximum Reservable Bandwidth: %g (Bytes/sec)", fval);
1833 return TLV_SIZE (tlvh);
1837 show_vty_link_subtlv_unrsv_bw (struct vty *vty, struct te_tlv_header *tlvh)
1839 struct te_link_subtlv_unrsv_bw *top;
1843 top = (struct te_link_subtlv_unrsv_bw *) tlvh;
1845 vty_out (vty, " Unreserved Bandwidth per Class Type in Byte/s:%s", VTY_NEWLINE);
1847 zlog_debug (" Unreserved Bandwidth per Class Type in Byte/s:");
1848 for (i = 0; i < MAX_CLASS_TYPE; i+=2)
1850 fval1 = ntohf (top->value[i]);
1851 fval2 = ntohf (top->value[i+1]);
1854 vty_out(vty, " [%d]: %g (Bytes/sec),\t[%d]: %g (Bytes/sec)%s",
1855 i, fval1, i+1, fval2, VTY_NEWLINE);
1857 zlog_debug (" [%d]: %g (Bytes/sec),\t[%d]: %g (Bytes/sec)",
1858 i, fval1, i+1, fval2);
1861 return TLV_SIZE (tlvh);
1865 show_vty_link_subtlv_rsc_clsclr (struct vty *vty, struct te_tlv_header *tlvh)
1867 struct te_link_subtlv_rsc_clsclr *top;
1869 top = (struct te_link_subtlv_rsc_clsclr *) tlvh;
1871 vty_out (vty, " Resource class/color: 0x%x%s",
1872 (u_int32_t) ntohl (top->value), VTY_NEWLINE);
1874 zlog_debug (" Resource Class/Color: 0x%x",
1875 (u_int32_t) ntohl (top->value));
1877 return TLV_SIZE (tlvh);
1881 show_vty_link_subtlv_lrrid (struct vty *vty, struct te_tlv_header *tlvh)
1883 struct te_link_subtlv_lrrid *top;
1885 top = (struct te_link_subtlv_lrrid *) tlvh;
1889 vty_out (vty, " Local TE Router ID: %s%s", inet_ntoa (top->local),
1891 vty_out (vty, " Remote TE Router ID: %s%s", inet_ntoa (top->remote),
1896 zlog_debug (" Local TE Router ID: %s", inet_ntoa (top->local));
1897 zlog_debug (" Remote TE Router ID: %s", inet_ntoa (top->remote));
1900 return TLV_SIZE (tlvh);
1904 show_vty_link_subtlv_llri (struct vty *vty, struct te_tlv_header *tlvh)
1906 struct te_link_subtlv_llri *top;
1908 top = (struct te_link_subtlv_llri *) tlvh;
1912 vty_out (vty, " Link Local ID: %d%s", (u_int32_t) ntohl (top->local),
1914 vty_out (vty, " Link Remote ID: %d%s", (u_int32_t) ntohl (top->remote),
1919 zlog_debug (" Link Local ID: %d", (u_int32_t) ntohl (top->local));
1920 zlog_debug (" Link Remote ID: %d", (u_int32_t) ntohl (top->remote));
1923 return TLV_SIZE (tlvh);
1927 show_vty_link_subtlv_rip (struct vty *vty, struct te_tlv_header *tlvh)
1929 struct te_link_subtlv_rip *top;
1931 top = (struct te_link_subtlv_rip *) tlvh;
1934 vty_out (vty, " Inter-AS TE Remote ASBR IP address: %s%s",
1935 inet_ntoa (top->value), VTY_NEWLINE);
1937 zlog_debug (" Inter-AS TE Remote ASBR IP address: %s",
1938 inet_ntoa (top->value));
1940 return TLV_SIZE (tlvh);
1944 show_vty_link_subtlv_ras (struct vty *vty, struct te_tlv_header *tlvh)
1946 struct te_link_subtlv_ras *top;
1948 top = (struct te_link_subtlv_ras *) tlvh;
1951 vty_out (vty, " Inter-AS TE Remote AS number: %u%s", ntohl (top->value),
1954 zlog_debug (" Inter-AS TE Remote AS number: %u", ntohl (top->value));
1956 return TLV_SIZE (tlvh);
1960 show_vty_link_subtlv_av_delay (struct vty *vty, struct te_tlv_header *tlvh)
1962 struct te_link_subtlv_av_delay *top;
1964 u_int32_t anomalous;
1966 top = (struct te_link_subtlv_av_delay *) tlvh;
1967 delay = (u_int32_t) ntohl (top->value) & TE_EXT_MASK;
1968 anomalous = (u_int32_t) ntohl (top->value) & TE_EXT_ANORMAL;
1971 vty_out (vty, " %s Average Link Delay: %d (micro-sec)%s",
1972 anomalous ? "Anomalous" : "Normal", delay, VTY_NEWLINE);
1974 zlog_debug (" %s Average Link Delay: %d (micro-sec)",
1975 anomalous ? "Anomalous" : "Normal", delay);
1977 return TLV_SIZE (tlvh);
1981 show_vty_link_subtlv_mm_delay (struct vty *vty, struct te_tlv_header *tlvh)
1983 struct te_link_subtlv_mm_delay *top;
1984 u_int32_t low, high;
1985 u_int32_t anomalous;
1987 top = (struct te_link_subtlv_mm_delay *) tlvh;
1988 low = (u_int32_t) ntohl (top->low) & TE_EXT_MASK;
1989 anomalous = (u_int32_t) ntohl (top->low) & TE_EXT_ANORMAL;
1990 high = (u_int32_t) ntohl (top->high);
1993 vty_out (vty, " %s Min/Max Link Delay: %d/%d (micro-sec)%s",
1994 anomalous ? "Anomalous" : "Normal", low, high, VTY_NEWLINE);
1996 zlog_debug (" %s Min/Max Link Delay: %d/%d (micro-sec)",
1997 anomalous ? "Anomalous" : "Normal", low, high);
1999 return TLV_SIZE (tlvh);
2003 show_vty_link_subtlv_delay_var (struct vty *vty, struct te_tlv_header *tlvh)
2005 struct te_link_subtlv_delay_var *top;
2008 top = (struct te_link_subtlv_delay_var *) tlvh;
2009 jitter = (u_int32_t) ntohl (top->value) & TE_EXT_MASK;
2012 vty_out (vty, " Delay Variation: %d (micro-sec)%s", jitter, VTY_NEWLINE);
2014 zlog_debug (" Delay Variation: %d (micro-sec)", jitter);
2016 return TLV_SIZE (tlvh);
2020 show_vty_link_subtlv_pkt_loss (struct vty *vty, struct te_tlv_header *tlvh)
2022 struct te_link_subtlv_pkt_loss *top;
2024 u_int32_t anomalous;
2027 top = (struct te_link_subtlv_pkt_loss *) tlvh;
2028 loss = (u_int32_t) ntohl (top->value) & TE_EXT_MASK;
2029 fval = (float) (loss * LOSS_PRECISION);
2030 anomalous = (u_int32_t) ntohl (top->value) & TE_EXT_ANORMAL;
2033 vty_out (vty, " %s Link Loss: %g (%%)%s", anomalous ? "Anomalous" : "Normal",
2036 zlog_debug (" %s Link Loss: %g (%%)", anomalous ? "Anomalous" : "Normal",
2039 return TLV_SIZE (tlvh);
2043 show_vty_link_subtlv_res_bw (struct vty *vty, struct te_tlv_header *tlvh)
2045 struct te_link_subtlv_res_bw *top;
2048 top = (struct te_link_subtlv_res_bw *) tlvh;
2049 fval = ntohf (top->value);
2052 vty_out (vty, " Unidirectional Residual Bandwidth: %g (Bytes/sec)%s",
2055 zlog_debug (" Unidirectional Residual Bandwidth: %g (Bytes/sec)",
2058 return TLV_SIZE (tlvh);
2062 show_vty_link_subtlv_ava_bw (struct vty *vty, struct te_tlv_header *tlvh)
2064 struct te_link_subtlv_ava_bw *top;
2067 top = (struct te_link_subtlv_ava_bw *) tlvh;
2068 fval = ntohf (top->value);
2071 vty_out (vty, " Unidirectional Available Bandwidth: %g (Bytes/sec)%s",
2074 zlog_debug (" Unidirectional Available Bandwidth: %g (Bytes/sec)",
2077 return TLV_SIZE (tlvh);
2081 show_vty_link_subtlv_use_bw (struct vty *vty, struct te_tlv_header *tlvh)
2083 struct te_link_subtlv_use_bw *top;
2086 top = (struct te_link_subtlv_use_bw *) tlvh;
2087 fval = ntohf (top->value);
2090 vty_out (vty, " Unidirectional Utilized Bandwidth: %g (Bytes/sec)%s",
2093 zlog_debug (" Unidirectional Utilized Bandwidth: %g (Bytes/sec)",
2096 return TLV_SIZE (tlvh);
2100 show_vty_unknown_tlv (struct vty *vty, struct te_tlv_header *tlvh)
2103 vty_out (vty, " Unknown TLV: [type(0x%x), length(0x%x)]%s",
2104 ntohs (tlvh->type), ntohs (tlvh->length), VTY_NEWLINE);
2106 zlog_debug (" Unknown TLV: [type(0x%x), length(0x%x)]",
2107 ntohs (tlvh->type), ntohs (tlvh->length));
2109 return TLV_SIZE (tlvh);
2113 ospf_mpls_te_show_link_subtlv (struct vty *vty, struct te_tlv_header *tlvh0,
2114 u_int16_t subtotal, u_int16_t total)
2116 struct te_tlv_header *tlvh, *next;
2117 u_int16_t sum = subtotal;
2119 for (tlvh = tlvh0; sum < total; tlvh = (next ? next : TLV_HDR_NEXT (tlvh)))
2122 switch (ntohs (tlvh->type))
2124 case TE_LINK_SUBTLV_LINK_TYPE:
2125 sum += show_vty_link_subtlv_link_type (vty, tlvh);
2127 case TE_LINK_SUBTLV_LINK_ID:
2128 sum += show_vty_link_subtlv_link_id (vty, tlvh);
2130 case TE_LINK_SUBTLV_LCLIF_IPADDR:
2131 sum += show_vty_link_subtlv_lclif_ipaddr (vty, tlvh);
2133 case TE_LINK_SUBTLV_RMTIF_IPADDR:
2134 sum += show_vty_link_subtlv_rmtif_ipaddr (vty, tlvh);
2136 case TE_LINK_SUBTLV_TE_METRIC:
2137 sum += show_vty_link_subtlv_te_metric (vty, tlvh);
2139 case TE_LINK_SUBTLV_MAX_BW:
2140 sum += show_vty_link_subtlv_max_bw (vty, tlvh);
2142 case TE_LINK_SUBTLV_MAX_RSV_BW:
2143 sum += show_vty_link_subtlv_max_rsv_bw (vty, tlvh);
2145 case TE_LINK_SUBTLV_UNRSV_BW:
2146 sum += show_vty_link_subtlv_unrsv_bw (vty, tlvh);
2148 case TE_LINK_SUBTLV_RSC_CLSCLR:
2149 sum += show_vty_link_subtlv_rsc_clsclr (vty, tlvh);
2151 case TE_LINK_SUBTLV_LRRID:
2152 sum += show_vty_link_subtlv_lrrid (vty, tlvh);
2154 case TE_LINK_SUBTLV_LLRI:
2155 sum += show_vty_link_subtlv_llri (vty, tlvh);
2157 case TE_LINK_SUBTLV_RIP:
2158 sum += show_vty_link_subtlv_rip (vty, tlvh);
2160 case TE_LINK_SUBTLV_RAS:
2161 sum += show_vty_link_subtlv_ras (vty, tlvh);
2163 case TE_LINK_SUBTLV_AV_DELAY:
2164 sum += show_vty_link_subtlv_av_delay (vty, tlvh);
2166 case TE_LINK_SUBTLV_MM_DELAY:
2167 sum += show_vty_link_subtlv_mm_delay (vty, tlvh);
2169 case TE_LINK_SUBTLV_DELAY_VAR:
2170 sum += show_vty_link_subtlv_delay_var (vty, tlvh);
2172 case TE_LINK_SUBTLV_PKT_LOSS:
2173 sum += show_vty_link_subtlv_pkt_loss (vty, tlvh);
2175 case TE_LINK_SUBTLV_RES_BW:
2176 sum += show_vty_link_subtlv_res_bw (vty, tlvh);
2178 case TE_LINK_SUBTLV_AVA_BW:
2179 sum += show_vty_link_subtlv_ava_bw (vty, tlvh);
2181 case TE_LINK_SUBTLV_USE_BW:
2182 sum += show_vty_link_subtlv_use_bw (vty, tlvh);
2185 sum += show_vty_unknown_tlv (vty, tlvh);
2193 ospf_mpls_te_show_info (struct vty *vty, struct ospf_lsa *lsa)
2195 struct lsa_header *lsah = (struct lsa_header *) lsa->data;
2196 struct te_tlv_header *tlvh, *next;
2197 u_int16_t sum, total;
2198 u_int16_t (* subfunc)(struct vty *vty, struct te_tlv_header *tlvh,
2199 u_int16_t subtotal, u_int16_t total) = NULL;
2202 total = ntohs (lsah->length) - OSPF_LSA_HEADER_SIZE;
2204 for (tlvh = TLV_HDR_TOP (lsah); sum < total;
2205 tlvh = (next ? next : TLV_HDR_NEXT (tlvh)))
2207 if (subfunc != NULL)
2209 sum = (* subfunc)(vty, tlvh, sum, total);
2210 next = (struct te_tlv_header *)((char *) tlvh + sum);
2216 switch (ntohs (tlvh->type))
2218 case TE_TLV_ROUTER_ADDR:
2219 sum += show_vty_router_addr (vty, tlvh);
2222 sum += show_vty_link_header (vty, tlvh);
2223 subfunc = ospf_mpls_te_show_link_subtlv;
2227 sum += show_vty_unknown_tlv (vty, tlvh);
2235 ospf_mpls_te_config_write_router (struct vty *vty)
2238 if (OspfMplsTE.status == enabled)
2240 vty_out (vty, " mpls-te on%s", VTY_NEWLINE);
2241 vty_out (vty, " mpls-te router-address %s%s",
2242 inet_ntoa (OspfMplsTE.router_addr.value), VTY_NEWLINE);
2245 if (OspfMplsTE.inter_as == AS)
2246 vty_out (vty, " mpls-te inter-as as%s", VTY_NEWLINE);
2247 if (OspfMplsTE.inter_as == Area)
2248 vty_out (vty, " mpls-te inter-as area %s %s",
2249 inet_ntoa (OspfMplsTE.interas_areaid), VTY_NEWLINE);
2254 /*------------------------------------------------------------------------*
2255 * Followings are vty command functions.
2256 *------------------------------------------------------------------------*/
2258 DEFUN (ospf_mpls_te_on,
2259 ospf_mpls_te_on_cmd,
2262 "Enable the MPLS-TE functionality\n")
2264 struct listnode *node;
2265 struct mpls_te_link *lp;
2267 if (OspfMplsTE.status == enabled)
2270 if (IS_DEBUG_OSPF_EVENT)
2271 zlog_debug ("MPLS-TE: OFF -> ON");
2273 OspfMplsTE.status = enabled;
2275 /* Reoriginate RFC3630 & RFC6827 Links */
2276 ospf_mpls_te_foreach_area (ospf_mpls_te_lsa_schedule, REORIGINATE_THIS_LSA);
2278 /* Reoriginate LSA if INTER-AS is always on */
2279 if (OspfMplsTE.inter_as != Disable)
2281 for (ALL_LIST_ELEMENTS_RO (OspfMplsTE.iflist, node, lp))
2283 if (IS_INTER_AS (lp->type))
2285 ospf_mpls_te_lsa_schedule (lp, REORIGINATE_THIS_LSA);
2293 DEFUN (no_ospf_mpls_te,
2294 no_ospf_mpls_te_cmd,
2297 "Disable the MPLS-TE functionality\n")
2299 struct listnode *node, *nnode;
2300 struct mpls_te_link *lp;
2302 if (OspfMplsTE.status == disabled)
2305 if (IS_DEBUG_OSPF_EVENT)
2306 zlog_debug ("MPLS-TE: ON -> OFF");
2308 OspfMplsTE.status = disabled;
2310 for (ALL_LIST_ELEMENTS (OspfMplsTE.iflist, node, nnode, lp))
2311 if CHECK_FLAG (lp->flags, LPFLG_LSA_ENGAGED)
2312 ospf_mpls_te_lsa_schedule (lp, FLUSH_THIS_LSA);
2317 DEFUN (ospf_mpls_te_router_addr,
2318 ospf_mpls_te_router_addr_cmd,
2319 "mpls-te router-address A.B.C.D",
2321 "Stable IP address of the advertising router\n"
2322 "MPLS-TE router address in IPv4 address format\n")
2324 struct te_tlv_router_addr *ra = &OspfMplsTE.router_addr;
2325 struct in_addr value;
2327 if (! inet_aton (argv[0], &value))
2329 vty_out (vty, "Please specify Router-Addr by A.B.C.D%s", VTY_NEWLINE);
2333 if (ntohs (ra->header.type) == 0
2334 || ntohl (ra->value.s_addr) != ntohl (value.s_addr))
2336 struct listnode *node, *nnode;
2337 struct mpls_te_link *lp;
2338 int need_to_reoriginate = 0;
2340 set_mpls_te_router_addr (value);
2342 if (OspfMplsTE.status == disabled)
2345 for (ALL_LIST_ELEMENTS (OspfMplsTE.iflist, node, nnode, lp))
2347 if ((lp->area == NULL) || IS_FLOOD_AS (lp->type))
2350 if (!CHECK_FLAG (lp->flags, LPFLG_LSA_ENGAGED))
2352 need_to_reoriginate = 1;
2357 for (ALL_LIST_ELEMENTS (OspfMplsTE.iflist, node, nnode, lp))
2359 if ((lp->area == NULL) || IS_FLOOD_AS (lp->type))
2362 if (need_to_reoriginate)
2363 SET_FLAG (lp->flags, LPFLG_LSA_FORCED_REFRESH);
2365 ospf_mpls_te_lsa_schedule (lp, REFRESH_THIS_LSA);
2368 if (need_to_reoriginate)
2369 ospf_mpls_te_foreach_area (ospf_mpls_te_lsa_schedule, REORIGINATE_THIS_LSA);
2376 set_inter_as_mode (struct vty *vty, const char *mode_name,
2377 const char *area_id)
2379 enum inter_as_mode mode;
2380 struct listnode *node;
2381 struct mpls_te_link *lp;
2384 if (OspfMplsTE.status == enabled)
2387 /* Read and Check inter_as mode */
2388 if (strcmp (mode_name, "as") == 0)
2390 else if (strcmp (mode_name, "area") == 0)
2393 VTY_GET_OSPF_AREA_ID (OspfMplsTE.interas_areaid, format, area_id);
2397 vty_out (vty, "Unknown mode. Please choose between as or area%s",
2402 if (IS_DEBUG_OSPF_EVENT)
2403 zlog_debug ("MPLS-TE: Inter-AS enable with %s flooding support",
2406 /* Register new callbacks regarding the flooding scope (AS or Area) */
2407 if (ospf_mpls_te_register (mode) < 0)
2409 vty_out (vty, "Internal error: Unable to register Inter-AS functions%s",
2414 /* Enable mode and re-originate LSA if needed */
2415 if ((OspfMplsTE.inter_as == Disable) && (mode != OspfMplsTE.inter_as))
2417 OspfMplsTE.inter_as = mode;
2418 /* Re-originate all InterAS-TEv2 LSA */
2419 for (ALL_LIST_ELEMENTS_RO (OspfMplsTE.iflist, node, lp))
2421 if (IS_INTER_AS (lp->type))
2424 lp->type |= FLOOD_AS;
2426 lp->type |= FLOOD_AREA;
2427 ospf_mpls_te_lsa_schedule (lp, REORIGINATE_THIS_LSA);
2433 vty_out (vty, "Please change Inter-AS support to disable first before going to mode %s%s",
2434 mode2text[mode], VTY_NEWLINE);
2441 DEFUN (ospf_mpls_te_inter_as_as,
2442 ospf_mpls_te_inter_as_cmd,
2443 "mpls-te inter-as as",
2445 "Configure MPLS-TE Inter-AS support\n"
2446 "AS native mode self originate INTER_AS LSA with Type 11 (as flooding scope)\n")
2448 return set_inter_as_mode (vty, "as", "");
2451 DEFUN (ospf_mpls_te_inter_as_area,
2452 ospf_mpls_te_inter_as_area_cmd,
2453 "mpls-te inter-as area (A.B.C.D|<0-4294967295>)",
2455 "Configure MPLS-TE Inter-AS support\n"
2456 "AREA native mode self originate INTER_AS LSA with Type 10 (area flooding scope)\n"
2457 "OSPF area ID in IP format\n"
2458 "OSPF area ID as decimal value\n")
2460 return set_inter_as_mode (vty, "area", argv[0]);
2463 DEFUN (no_ospf_mpls_te_inter_as,
2464 no_ospf_mpls_te_inter_as_cmd,
2465 "no mpls-te inter-as",
2468 "Disable MPLS-TE Inter-AS support\n")
2471 struct listnode *node, *nnode;
2472 struct mpls_te_link *lp;
2474 if (IS_DEBUG_OSPF_EVENT)
2475 zlog_debug ("MPLS-TE: Inter-AS support OFF");
2477 if ((OspfMplsTE.status == enabled) && (OspfMplsTE.inter_as != Disable))
2479 OspfMplsTE.inter_as = Disable;
2480 /* Flush all Inter-AS LSA */
2481 for (ALL_LIST_ELEMENTS (OspfMplsTE.iflist, node, nnode, lp))
2482 if (IS_INTER_AS (lp->type) && CHECK_FLAG (lp->flags, LPFLG_LSA_ENGAGED))
2483 ospf_mpls_te_lsa_schedule (lp, FLUSH_THIS_LSA);
2486 /* Deregister the Callbacks for Inter-AS suport */
2487 ospf_mpls_te_unregister ();
2492 DEFUN (show_ip_ospf_mpls_te_router,
2493 show_ip_ospf_mpls_te_router_cmd,
2494 "show ip ospf mpls-te router",
2498 "MPLS-TE information\n"
2499 "MPLS-TE Router parameters\n")
2501 if (OspfMplsTE.status == enabled)
2503 vty_out (vty, "--- MPLS-TE router parameters ---%s", VTY_NEWLINE);
2505 if (ntohs (OspfMplsTE.router_addr.header.type) != 0)
2506 show_vty_router_addr (vty, &OspfMplsTE.router_addr.header);
2507 else if (vty != NULL)
2508 vty_out (vty, " N/A%s", VTY_NEWLINE);
2514 show_mpls_te_link_sub (struct vty *vty, struct interface *ifp)
2516 struct mpls_te_link *lp;
2518 if ((OspfMplsTE.status == enabled)
2519 && HAS_LINK_PARAMS(ifp)
2520 && !if_is_loopback (ifp)
2522 && ((lp = lookup_linkparams_by_ifp (ifp)) != NULL))
2524 /* Continue only if interface is not passive or support Inter-AS TEv2 */
2525 if (!(ospf_oi_count (ifp) > 0))
2527 if (IS_INTER_AS (lp->type))
2529 vty_out (vty, "-- Inter-AS TEv2 link parameters for %s --%s",
2530 ifp->name, VTY_NEWLINE);
2534 /* MPLS-TE is not activate on this interface */
2535 /* or this interface is passive and Inter-AS TEv2 is not activate */
2536 vty_out (vty, " %s: MPLS-TE is disabled on this interface%s",
2537 ifp->name, VTY_NEWLINE);
2543 vty_out (vty, "-- MPLS-TE link parameters for %s --%s",
2544 ifp->name, VTY_NEWLINE);
2547 if (TLV_TYPE(lp->link_type) != 0)
2548 show_vty_link_subtlv_link_type (vty, &lp->link_type.header);
2549 if (TLV_TYPE(lp->link_id) != 0)
2550 show_vty_link_subtlv_link_id (vty, &lp->link_id.header);
2551 if (TLV_TYPE(lp->lclif_ipaddr) != 0)
2552 show_vty_link_subtlv_lclif_ipaddr (vty, &lp->lclif_ipaddr.header);
2553 if (TLV_TYPE(lp->rmtif_ipaddr) != 0)
2554 show_vty_link_subtlv_rmtif_ipaddr (vty, &lp->rmtif_ipaddr.header);
2555 if (TLV_TYPE(lp->rip) != 0)
2556 show_vty_link_subtlv_rip (vty, &lp->rip.header);
2557 if (TLV_TYPE(lp->ras) != 0)
2558 show_vty_link_subtlv_ras (vty, &lp->ras.header);
2559 if (TLV_TYPE(lp->te_metric) != 0)
2560 show_vty_link_subtlv_te_metric (vty, &lp->te_metric.header);
2561 if (TLV_TYPE(lp->max_bw) != 0)
2562 show_vty_link_subtlv_max_bw (vty, &lp->max_bw.header);
2563 if (TLV_TYPE(lp->max_rsv_bw) != 0)
2564 show_vty_link_subtlv_max_rsv_bw (vty, &lp->max_rsv_bw.header);
2565 if (TLV_TYPE(lp->unrsv_bw) != 0)
2566 show_vty_link_subtlv_unrsv_bw (vty, &lp->unrsv_bw.header);
2567 if (TLV_TYPE(lp->rsc_clsclr) != 0)
2568 show_vty_link_subtlv_rsc_clsclr (vty, &lp->rsc_clsclr.header);
2569 if (TLV_TYPE(lp->av_delay) != 0)
2570 show_vty_link_subtlv_av_delay (vty, &lp->av_delay.header);
2571 if (TLV_TYPE(lp->mm_delay) != 0)
2572 show_vty_link_subtlv_mm_delay (vty, &lp->mm_delay.header);
2573 if (TLV_TYPE(lp->delay_var) != 0)
2574 show_vty_link_subtlv_delay_var (vty, &lp->delay_var.header);
2575 if (TLV_TYPE(lp->pkt_loss) != 0)
2576 show_vty_link_subtlv_pkt_loss (vty, &lp->pkt_loss.header);
2577 if (TLV_TYPE(lp->res_bw) != 0)
2578 show_vty_link_subtlv_res_bw (vty, &lp->res_bw.header);
2579 if (TLV_TYPE(lp->ava_bw) != 0)
2580 show_vty_link_subtlv_ava_bw (vty, &lp->ava_bw.header);
2581 if (TLV_TYPE(lp->use_bw) != 0)
2582 show_vty_link_subtlv_use_bw (vty, &lp->use_bw.header);
2583 vty_out (vty, "---------------%s%s", VTY_NEWLINE, VTY_NEWLINE);
2587 vty_out (vty, " %s: MPLS-TE is disabled on this interface%s",
2588 ifp->name, VTY_NEWLINE);
2594 DEFUN (show_ip_ospf_mpls_te_link,
2595 show_ip_ospf_mpls_te_link_cmd,
2596 "show ip ospf mpls-te interface [INTERFACE]",
2600 "MPLS-TE information\n"
2601 "Interface information\n"
2604 struct interface *ifp;
2605 struct listnode *node, *nnode;
2607 /* Show All Interfaces. */
2610 for (ALL_LIST_ELEMENTS (iflist, node, nnode, ifp))
2611 show_mpls_te_link_sub (vty, ifp);
2613 /* Interface name is specified. */
2616 if ((ifp = if_lookup_by_name (argv[0])) == NULL)
2617 vty_out (vty, "No such interface name%s", VTY_NEWLINE);
2619 show_mpls_te_link_sub (vty, ifp);
2626 ospf_mpls_te_register_vty (void)
2628 install_element (VIEW_NODE, &show_ip_ospf_mpls_te_router_cmd);
2629 install_element (VIEW_NODE, &show_ip_ospf_mpls_te_link_cmd);
2631 install_element (OSPF_NODE, &ospf_mpls_te_on_cmd);
2632 install_element (OSPF_NODE, &no_ospf_mpls_te_cmd);
2633 install_element (OSPF_NODE, &ospf_mpls_te_router_addr_cmd);
2634 install_element (OSPF_NODE, &ospf_mpls_te_inter_as_cmd);
2635 install_element (OSPF_NODE, &ospf_mpls_te_inter_as_area_cmd);
2636 install_element (OSPF_NODE, &no_ospf_mpls_te_inter_as_cmd);