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 */
45 #include "sockunion.h" /* for inet_aton() */
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"
67 * Global variable to manage Opaque-LSA/MPLS-TE on this node.
68 * Note that all parameter values are stored in network byte order.
70 struct ospf_mpls_te OspfMplsTE
;
72 const char *mode2text
[] = { "Disable", "AS", "Area", "Emulate" };
76 OI_ANY
, OI_DOWN
, OI_UP
79 /*------------------------------------------------------------------------*
80 * Followings are initialize/terminate functions for MPLS-TE handling.
81 *------------------------------------------------------------------------*/
83 static int ospf_mpls_te_new_if (struct interface
*ifp
);
84 static int ospf_mpls_te_del_if (struct interface
*ifp
);
85 static void ospf_mpls_te_ism_change (struct ospf_interface
*oi
,
87 static void ospf_mpls_te_nsm_change (struct ospf_neighbor
*nbr
, int old_status
);
88 static void ospf_mpls_te_config_write_router (struct vty
*vty
);
89 static void ospf_mpls_te_show_info (struct vty
*vty
, struct ospf_lsa
*lsa
);
90 static int ospf_mpls_te_lsa_originate_area (void *arg
);
91 static int ospf_mpls_te_lsa_originate_as (void *arg
);
92 static struct ospf_lsa
*ospf_mpls_te_lsa_refresh (struct ospf_lsa
*lsa
);
94 static void del_mpls_te_link (void *val
);
95 static void ospf_mpls_te_register_vty (void);
98 ospf_mpls_te_init (void)
102 rc
= ospf_register_opaque_functab (
103 OSPF_OPAQUE_AREA_LSA
,
104 OPAQUE_TYPE_TRAFFIC_ENGINEERING_LSA
,
107 ospf_mpls_te_ism_change
,
108 ospf_mpls_te_nsm_change
,
109 ospf_mpls_te_config_write_router
,
110 NULL
,/*ospf_mpls_te_config_write_if */
111 NULL
,/* ospf_mpls_te_config_write_debug */
112 ospf_mpls_te_show_info
,
113 ospf_mpls_te_lsa_originate_area
,
114 ospf_mpls_te_lsa_refresh
,
115 NULL
,/* ospf_mpls_te_new_lsa_hook */
116 NULL
/* ospf_mpls_te_del_lsa_hook */);
119 zlog_warn ("ospf_mpls_te_init: Failed to register Traffic Engineering functions");
123 memset (&OspfMplsTE
, 0, sizeof (struct ospf_mpls_te
));
124 OspfMplsTE
.status
= disabled
;
125 OspfMplsTE
.inter_as
= Disable
;
126 OspfMplsTE
.iflist
= list_new ();
127 OspfMplsTE
.iflist
->del
= del_mpls_te_link
;
129 ospf_mpls_te_register_vty ();
135 /* Additional register for RFC5392 support */
137 ospf_mpls_te_register (enum inter_as_mode mode
)
142 if (OspfMplsTE
.inter_as
!= Disable
)
146 scope
= OSPF_OPAQUE_AS_LSA
;
148 scope
= OSPF_OPAQUE_AREA_LSA
;
150 rc
= ospf_register_opaque_functab (scope
,
151 OPAQUE_TYPE_INTER_AS_LSA
,
159 ospf_mpls_te_show_info
,
160 ospf_mpls_te_lsa_originate_as
,
161 ospf_mpls_te_lsa_refresh
, NULL
, NULL
);
165 zlog_warn ("ospf_router_info_init: Failed to register Inter-AS functions");
173 ospf_mpls_te_unregister ()
177 if (OspfMplsTE
.inter_as
== Disable
)
180 if (OspfMplsTE
.inter_as
== AS
)
181 scope
= OSPF_OPAQUE_AS_LSA
;
183 scope
= OSPF_OPAQUE_AREA_LSA
;
185 ospf_delete_opaque_functab (scope
, OPAQUE_TYPE_INTER_AS_LSA
);
192 ospf_mpls_te_term (void)
194 list_delete (OspfMplsTE
.iflist
);
195 OspfMplsTE
.iflist
= NULL
;
197 ospf_delete_opaque_functab (OSPF_OPAQUE_AREA_LSA
,
198 OPAQUE_TYPE_TRAFFIC_ENGINEERING_LSA
);
199 OspfMplsTE
.status
= disabled
;
201 ospf_mpls_te_unregister ();
202 OspfMplsTE
.inter_as
= Disable
;
207 /*------------------------------------------------------------------------*
208 * Followings are control functions for MPLS-TE parameters management.
209 *------------------------------------------------------------------------*/
212 del_mpls_te_link (void *val
)
214 XFREE (MTYPE_OSPF_MPLS_TE
, val
);
219 get_mpls_te_instance_value (void)
221 static u_int32_t seqno
= 0;
223 if (seqno
< MAX_LEGAL_TE_INSTANCE_NUM
)
226 seqno
= 1; /* Avoid zero. */
231 static struct ospf_interface
*
232 lookup_oi_by_ifp (struct interface
*ifp
,
233 struct ospf_area
*area
, enum oifstate oifstate
)
235 struct ospf_interface
*oi
= NULL
;
236 struct route_node
*rn
;
238 for (rn
= route_top (IF_OIFS (ifp
)); rn
; rn
= route_next (rn
))
240 if ((oi
= rn
->info
) == NULL
)
248 if (ospf_if_is_enable (oi
))
252 if (! ospf_if_is_enable (oi
))
256 zlog_warn ("lookup_oi_by_ifp: Unknown oifstate: %x", oifstate
);
260 if (area
== NULL
|| oi
->area
== area
)
267 static struct mpls_te_link
*
268 lookup_linkparams_by_ifp (struct interface
*ifp
)
270 struct listnode
*node
, *nnode
;
271 struct mpls_te_link
*lp
;
273 for (ALL_LIST_ELEMENTS (OspfMplsTE
.iflist
, node
, nnode
, lp
))
280 static struct mpls_te_link
*
281 lookup_linkparams_by_instance (struct ospf_lsa
*lsa
)
283 struct listnode
*node
;
284 struct mpls_te_link
*lp
;
285 unsigned int key
= GET_OPAQUE_ID (ntohl (lsa
->data
->id
.s_addr
));
287 for (ALL_LIST_ELEMENTS_RO (OspfMplsTE
.iflist
, node
, lp
))
288 if (lp
->instance
== key
)
291 zlog_warn ("lookup_linkparams_by_instance: Entry not found: key(%x)", key
);
296 ospf_mpls_te_foreach_area (void (*func
)
297 (struct mpls_te_link
* lp
, opcode_t sched_opcode
),
298 opcode_t sched_opcode
)
300 struct listnode
*node
, *nnode
;
301 struct listnode
*node2
;
302 struct mpls_te_link
*lp
;
303 struct ospf_area
*area
;
305 for (ALL_LIST_ELEMENTS (OspfMplsTE
.iflist
, node
, nnode
, lp
))
307 /* Skip Inter-AS TEv2 Links */
308 if (IS_INTER_AS (lp
->type
))
310 if ((area
= lp
->area
) == NULL
)
312 if CHECK_FLAG (lp
->flags
, LPFLG_LOOKUP_DONE
) continue;
315 (* func
)(lp
, sched_opcode
);
317 for (node2
= listnextnode (node
); node2
; node2
= listnextnode (node2
))
318 if ((lp
= listgetdata (node2
)) != NULL
)
319 if (lp
->area
!= NULL
)
320 if (IPV4_ADDR_SAME (&lp
->area
->area_id
, &area
->area_id
))
321 SET_FLAG (lp
->flags
, LPFLG_LOOKUP_DONE
);
324 for (ALL_LIST_ELEMENTS_RO (OspfMplsTE
.iflist
, node
, lp
))
325 if (lp
->area
!= NULL
)
326 UNSET_FLAG (lp
->flags
, LPFLG_LOOKUP_DONE
);
332 set_mpls_te_router_addr (struct in_addr ipv4
)
334 OspfMplsTE
.router_addr
.header
.type
= htons (TE_TLV_ROUTER_ADDR
);
335 OspfMplsTE
.router_addr
.header
.length
= htons (TE_LINK_SUBTLV_DEF_SIZE
);
336 OspfMplsTE
.router_addr
.value
= ipv4
;
341 set_linkparams_link_header (struct mpls_te_link
*lp
)
343 u_int16_t length
= 0;
345 /* TE_LINK_SUBTLV_LINK_TYPE */
346 if (ntohs (lp
->link_type
.header
.type
) != 0)
347 length
+= TLV_SIZE (&lp
->link_type
.header
);
349 /* TE_LINK_SUBTLV_LINK_ID */
350 if (ntohs (lp
->link_id
.header
.type
) != 0)
351 length
+= TLV_SIZE (&lp
->link_id
.header
);
353 /* TE_LINK_SUBTLV_LCLIF_IPADDR */
354 if (lp
->lclif_ipaddr
.header
.type
!= 0)
355 length
+= TLV_SIZE (&lp
->lclif_ipaddr
.header
);
357 /* TE_LINK_SUBTLV_RMTIF_IPADDR */
358 if (lp
->rmtif_ipaddr
.header
.type
!= 0)
359 length
+= TLV_SIZE (&lp
->rmtif_ipaddr
.header
);
361 /* TE_LINK_SUBTLV_TE_METRIC */
362 if (ntohs (lp
->te_metric
.header
.type
) != 0)
363 length
+= TLV_SIZE (&lp
->te_metric
.header
);
365 /* TE_LINK_SUBTLV_MAX_BW */
366 if (ntohs (lp
->max_bw
.header
.type
) != 0)
367 length
+= TLV_SIZE (&lp
->max_bw
.header
);
369 /* TE_LINK_SUBTLV_MAX_RSV_BW */
370 if (ntohs (lp
->max_rsv_bw
.header
.type
) != 0)
371 length
+= TLV_SIZE (&lp
->max_rsv_bw
.header
);
373 /* TE_LINK_SUBTLV_UNRSV_BW */
374 if (ntohs (lp
->unrsv_bw
.header
.type
) != 0)
375 length
+= TLV_SIZE (&lp
->unrsv_bw
.header
);
377 /* TE_LINK_SUBTLV_RSC_CLSCLR */
378 if (ntohs (lp
->rsc_clsclr
.header
.type
) != 0)
379 length
+= TLV_SIZE (&lp
->rsc_clsclr
.header
);
381 /* TE_LINK_SUBTLV_LLRI */
382 if (ntohs (lp
->llri
.header
.type
) != 0)
383 length
+= TLV_SIZE (&lp
->llri
.header
);
385 /* TE_LINK_SUBTLV_RIP */
386 if (ntohs (lp
->rip
.header
.type
) != 0)
387 length
+= TLV_SIZE (&lp
->rip
.header
);
389 /* TE_LINK_SUBTLV_RAS */
390 if (ntohs (lp
->ras
.header
.type
) != 0)
391 length
+= TLV_SIZE (&lp
->ras
.header
);
393 /* TE_LINK_SUBTLV_LRRID */
394 if (ntohs (lp
->lrrid
.header
.type
) != 0)
395 length
+= TLV_SIZE (&lp
->lrrid
.header
);
397 /* TE_LINK_SUBTLV_AV_DELAY */
398 if (ntohs (lp
->av_delay
.header
.type
) != 0)
399 length
+= TLV_SIZE (&lp
->av_delay
.header
);
401 /* TE_LINK_SUBTLV_MM_DELAY */
402 if (ntohs (lp
->mm_delay
.header
.type
) != 0)
403 length
+= TLV_SIZE (&lp
->mm_delay
.header
);
405 /* TE_LINK_SUBTLV_DELAY_VAR */
406 if (ntohs (lp
->delay_var
.header
.type
) != 0)
407 length
+= TLV_SIZE (&lp
->delay_var
.header
);
409 /* TE_LINK_SUBTLV_PKT_LOSS */
410 if (ntohs (lp
->pkt_loss
.header
.type
) != 0)
411 length
+= TLV_SIZE (&lp
->pkt_loss
.header
);
413 /* TE_LINK_SUBTLV_RES_BW */
414 if (ntohs (lp
->res_bw
.header
.type
) != 0)
415 length
+= TLV_SIZE (&lp
->res_bw
.header
);
417 /* TE_LINK_SUBTLV_AVA_BW */
418 if (ntohs (lp
->ava_bw
.header
.type
) != 0)
419 length
+= TLV_SIZE (&lp
->ava_bw
.header
);
421 /* TE_LINK_SUBTLV_USE_BW */
422 if (ntohs (lp
->use_bw
.header
.type
) != 0)
423 length
+= TLV_SIZE (&lp
->use_bw
.header
);
425 lp
->link_header
.header
.type
= htons (TE_TLV_LINK
);
426 lp
->link_header
.header
.length
= htons (length
);
432 set_linkparams_link_type (struct ospf_interface
*oi
, struct mpls_te_link
*lp
)
434 lp
->link_type
.header
.type
= htons (TE_LINK_SUBTLV_LINK_TYPE
);
435 lp
->link_type
.header
.length
= htons (TE_LINK_SUBTLV_TYPE_SIZE
);
439 case OSPF_IFTYPE_POINTOPOINT
:
440 lp
->link_type
.link_type
.value
= LINK_TYPE_SUBTLV_VALUE_PTP
;
442 case OSPF_IFTYPE_BROADCAST
:
443 case OSPF_IFTYPE_NBMA
:
444 lp
->link_type
.link_type
.value
= LINK_TYPE_SUBTLV_VALUE_MA
;
447 /* Not supported yet. *//* XXX */
448 lp
->link_type
.header
.type
= htons (0);
455 set_linkparams_link_id (struct ospf_interface
*oi
, struct mpls_te_link
*lp
)
457 struct ospf_neighbor
*nbr
;
460 lp
->link_id
.header
.type
= htons (TE_LINK_SUBTLV_LINK_ID
);
461 lp
->link_id
.header
.length
= htons (TE_LINK_SUBTLV_DEF_SIZE
);
464 * The Link ID is identical to the contents of the Link ID field
465 * in the Router LSA for these link types.
469 case OSPF_IFTYPE_POINTOPOINT
:
470 /* Take the router ID of the neighbor. */
471 if ((nbr
= ospf_nbr_lookup_ptop (oi
)) && nbr
->state
== NSM_Full
)
473 lp
->link_id
.value
= nbr
->router_id
;
477 case OSPF_IFTYPE_BROADCAST
:
478 case OSPF_IFTYPE_NBMA
:
479 /* Take the interface address of the designated router. */
480 if ((nbr
= ospf_nbr_lookup_by_addr (oi
->nbrs
, &DR (oi
))) == NULL
)
483 if (nbr
->state
== NSM_Full
484 || (IPV4_ADDR_SAME (&oi
->address
->u
.prefix4
, &DR (oi
))
485 && ospf_nbr_count (oi
, NSM_Full
) > 0))
487 lp
->link_id
.value
= DR (oi
);
492 /* Not supported yet. *//* XXX */
493 lp
->link_id
.header
.type
= htons (0);
500 masklen2ip (oi
->address
->prefixlen
, &mask
);
501 lp
->link_id
.value
.s_addr
= oi
->address
->u
.prefix4
.s_addr
& mask
.s_addr
;
507 set_linkparams_lclif_ipaddr (struct mpls_te_link
*lp
, struct in_addr lclif
)
510 lp
->lclif_ipaddr
.header
.type
= htons (TE_LINK_SUBTLV_LCLIF_IPADDR
);
511 lp
->lclif_ipaddr
.header
.length
= htons (TE_LINK_SUBTLV_DEF_SIZE
);
512 lp
->lclif_ipaddr
.value
[0] = lclif
;
517 set_linkparams_rmtif_ipaddr (struct mpls_te_link
*lp
, struct in_addr rmtif
)
520 lp
->rmtif_ipaddr
.header
.type
= htons (TE_LINK_SUBTLV_RMTIF_IPADDR
);
521 lp
->rmtif_ipaddr
.header
.length
= htons (TE_LINK_SUBTLV_DEF_SIZE
);
522 lp
->rmtif_ipaddr
.value
[0] = rmtif
;
527 set_linkparams_te_metric (struct mpls_te_link
*lp
, u_int32_t te_metric
)
529 lp
->te_metric
.header
.type
= htons (TE_LINK_SUBTLV_TE_METRIC
);
530 lp
->te_metric
.header
.length
= htons (TE_LINK_SUBTLV_DEF_SIZE
);
531 lp
->te_metric
.value
= htonl (te_metric
);
536 set_linkparams_max_bw (struct mpls_te_link
*lp
, float fp
)
538 lp
->max_bw
.header
.type
= htons (TE_LINK_SUBTLV_MAX_BW
);
539 lp
->max_bw
.header
.length
= htons (TE_LINK_SUBTLV_DEF_SIZE
);
540 lp
->max_bw
.value
= htonf (fp
);
545 set_linkparams_max_rsv_bw (struct mpls_te_link
*lp
, float fp
)
547 lp
->max_rsv_bw
.header
.type
= htons (TE_LINK_SUBTLV_MAX_RSV_BW
);
548 lp
->max_rsv_bw
.header
.length
= htons (TE_LINK_SUBTLV_DEF_SIZE
);
549 lp
->max_rsv_bw
.value
= htonf (fp
);
554 set_linkparams_unrsv_bw (struct mpls_te_link
*lp
, int priority
, float fp
)
556 /* Note that TLV-length field is the size of array. */
557 lp
->unrsv_bw
.header
.type
= htons (TE_LINK_SUBTLV_UNRSV_BW
);
558 lp
->unrsv_bw
.header
.length
= htons (TE_LINK_SUBTLV_UNRSV_SIZE
);
559 lp
->unrsv_bw
.value
[priority
] = htonf (fp
);
564 set_linkparams_rsc_clsclr (struct mpls_te_link
*lp
, u_int32_t classcolor
)
566 lp
->rsc_clsclr
.header
.type
= htons (TE_LINK_SUBTLV_RSC_CLSCLR
);
567 lp
->rsc_clsclr
.header
.length
= htons (TE_LINK_SUBTLV_DEF_SIZE
);
568 lp
->rsc_clsclr
.value
= htonl (classcolor
);
573 set_linkparams_inter_as (struct mpls_te_link
*lp
, struct in_addr addr
,
577 /* Set the Remote ASBR IP address and then the associated AS number */
578 lp
->rip
.header
.type
= htons (TE_LINK_SUBTLV_RIP
);
579 lp
->rip
.header
.length
= htons (TE_LINK_SUBTLV_DEF_SIZE
);
580 lp
->rip
.value
= addr
;
582 lp
->ras
.header
.type
= htons (TE_LINK_SUBTLV_RAS
);
583 lp
->ras
.header
.length
= htons (TE_LINK_SUBTLV_DEF_SIZE
);
584 lp
->ras
.value
= htonl (as
);
588 unset_linkparams_inter_as (struct mpls_te_link
*lp
)
591 /* Reset the Remote ASBR IP address and then the associated AS number */
592 lp
->rip
.header
.type
= htons (0);
593 lp
->rip
.header
.length
= htons (0);
594 lp
->rip
.value
.s_addr
= htonl (0);
596 lp
->ras
.header
.type
= htons (0);
597 lp
->ras
.header
.length
= htons (0);
598 lp
->ras
.value
= htonl (0);
602 set_linkparams_llri (struct mpls_te_link
*lp
, u_int32_t local
,
606 lp
->llri
.header
.type
= htons (TE_LINK_SUBTLV_LLRI
);
607 lp
->llri
.header
.length
= htons (TE_LINK_SUBTLV_LLRI_SIZE
);
608 lp
->llri
.local
= htonl (local
);
609 lp
->llri
.remote
= htonl (remote
);
613 set_linkparams_lrrid (struct mpls_te_link
*lp
, struct in_addr local
,
614 struct in_addr remote
)
617 lp
->lrrid
.header
.type
= htons (TE_LINK_SUBTLV_LRRID
);
618 lp
->lrrid
.header
.length
= htons (TE_LINK_SUBTLV_LRRID_SIZE
);
619 lp
->lrrid
.local
.s_addr
= local
.s_addr
;
620 lp
->lrrid
.remote
.s_addr
= remote
.s_addr
;
624 set_linkparams_av_delay (struct mpls_te_link
*lp
, u_int32_t delay
, u_char anormal
)
627 /* Note that TLV-length field is the size of array. */
628 lp
->av_delay
.header
.type
= htons (TE_LINK_SUBTLV_AV_DELAY
);
629 lp
->av_delay
.header
.length
= htons (TE_LINK_SUBTLV_DEF_SIZE
);
630 tmp
= delay
& TE_EXT_MASK
;
632 tmp
|= TE_EXT_ANORMAL
;
633 lp
->av_delay
.value
= htonl (tmp
);
638 set_linkparams_mm_delay (struct mpls_te_link
*lp
, u_int32_t low
, u_int32_t high
, u_char anormal
)
641 /* Note that TLV-length field is the size of array. */
642 lp
->mm_delay
.header
.type
= htons (TE_LINK_SUBTLV_MM_DELAY
);
643 lp
->mm_delay
.header
.length
= htons (TE_LINK_SUBTLV_MM_DELAY_SIZE
);
644 tmp
= low
& TE_EXT_MASK
;
646 tmp
|= TE_EXT_ANORMAL
;
647 lp
->mm_delay
.low
= htonl (tmp
);
648 lp
->mm_delay
.high
= htonl (high
);
653 set_linkparams_delay_var (struct mpls_te_link
*lp
, u_int32_t jitter
)
655 /* Note that TLV-length field is the size of array. */
656 lp
->delay_var
.header
.type
= htons (TE_LINK_SUBTLV_DELAY_VAR
);
657 lp
->delay_var
.header
.length
= htons (TE_LINK_SUBTLV_DEF_SIZE
);
658 lp
->delay_var
.value
= htonl (jitter
& TE_EXT_MASK
);
663 set_linkparams_pkt_loss (struct mpls_te_link
*lp
, u_int32_t loss
, u_char anormal
)
666 /* Note that TLV-length field is the size of array. */
667 lp
->pkt_loss
.header
.type
= htons (TE_LINK_SUBTLV_PKT_LOSS
);
668 lp
->pkt_loss
.header
.length
= htons (TE_LINK_SUBTLV_DEF_SIZE
);
669 tmp
= loss
& TE_EXT_MASK
;
671 tmp
|= TE_EXT_ANORMAL
;
672 lp
->pkt_loss
.value
= htonl (tmp
);
677 set_linkparams_res_bw (struct mpls_te_link
*lp
, float fp
)
679 /* Note that TLV-length field is the size of array. */
680 lp
->res_bw
.header
.type
= htons (TE_LINK_SUBTLV_RES_BW
);
681 lp
->res_bw
.header
.length
= htons (TE_LINK_SUBTLV_DEF_SIZE
);
682 lp
->res_bw
.value
= htonf (fp
);
687 set_linkparams_ava_bw (struct mpls_te_link
*lp
, float fp
)
689 /* Note that TLV-length field is the size of array. */
690 lp
->ava_bw
.header
.type
= htons (TE_LINK_SUBTLV_AVA_BW
);
691 lp
->ava_bw
.header
.length
= htons (TE_LINK_SUBTLV_DEF_SIZE
);
692 lp
->ava_bw
.value
= htonf (fp
);
697 set_linkparams_use_bw (struct mpls_te_link
*lp
, float fp
)
699 /* Note that TLV-length field is the size of array. */
700 lp
->use_bw
.header
.type
= htons (TE_LINK_SUBTLV_USE_BW
);
701 lp
->use_bw
.header
.length
= htons (TE_LINK_SUBTLV_DEF_SIZE
);
702 lp
->use_bw
.value
= htonf (fp
);
706 /* Update TE parameters from Interface */
708 update_linkparams(struct mpls_te_link
*lp
)
711 struct interface
*ifp
;
713 /* Get the Interface structure */
714 if ((ifp
= lp
->ifp
) == NULL
)
716 if (IS_DEBUG_OSPF_TE
)
717 zlog_debug("OSPF MPLS-TE: Abort update TE parameters: no interface associated to Link Parameters");
720 if (!HAS_LINK_PARAMS(ifp
))
722 if (IS_DEBUG_OSPF_TE
)
723 zlog_debug("OSPF MPLS-TE: Abort update TE parameters: no Link Parameters for interface");
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
);
731 TLV_TYPE(lp
->rsc_clsclr
) = 0;
733 if (IS_PARAM_SET(ifp
->link_params
, LP_MAX_BW
))
734 set_linkparams_max_bw (lp
, ifp
->link_params
->max_bw
);
736 TLV_TYPE(lp
->max_bw
) = 0;
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
);
741 TLV_TYPE(lp
->max_rsv_bw
) = 0;
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
]);
747 TLV_TYPE(lp
->unrsv_bw
) = 0;
749 if (IS_PARAM_SET(ifp
->link_params
, LP_TE
))
750 set_linkparams_te_metric(lp
, ifp
->link_params
->te_metric
);
752 TLV_TYPE(lp
->te_metric
) = 0;
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);
758 TLV_TYPE(lp
->av_delay
) = 0;
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);
763 TLV_TYPE(lp
->mm_delay
) = 0;
765 if (IS_PARAM_SET(ifp
->link_params
, LP_DELAY_VAR
))
766 set_linkparams_delay_var(lp
, ifp
->link_params
->delay_var
);
768 TLV_TYPE(lp
->delay_var
) = 0;
770 if (IS_PARAM_SET(ifp
->link_params
, LP_PKT_LOSS
))
771 set_linkparams_pkt_loss(lp
, ifp
->link_params
->pkt_loss
, 0);
773 TLV_TYPE(lp
->pkt_loss
) = 0;
775 if (IS_PARAM_SET(ifp
->link_params
, LP_RES_BW
))
776 set_linkparams_res_bw(lp
, ifp
->link_params
->res_bw
);
778 TLV_TYPE(lp
->res_bw
) = 0;
780 if (IS_PARAM_SET(ifp
->link_params
, LP_AVA_BW
))
781 set_linkparams_ava_bw(lp
, ifp
->link_params
->ava_bw
);
783 TLV_TYPE(lp
->ava_bw
) = 0;
785 if (IS_PARAM_SET(ifp
->link_params
, LP_USE_BW
))
786 set_linkparams_use_bw(lp
, ifp
->link_params
->use_bw
);
788 TLV_TYPE(lp
->use_bw
) = 0;
791 if (IS_PARAM_SET(ifp
->link_params
, LP_RMT_AS
))
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
))
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
);
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
;
806 lp
->flags
= INTER_AS
| FLOOD_AREA
;
807 lp
->area
= ospf_area_lookup_by_area_id (ospf_lookup(), OspfMplsTE
.interas_areaid
);
810 set_linkparams_inter_as(lp
, ifp
->link_params
->rmt_ip
, ifp
->link_params
->rmt_as
);
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
);
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
))
822 ospf_mpls_te_lsa_schedule (lp
, FLUSH_THIS_LSA
);
823 /* Then, switch it to Standard TE */
824 lp
->flags
= STD_TE
| FLOOD_AREA
;
826 unset_linkparams_inter_as (lp
);
831 initialize_linkparams (struct mpls_te_link
*lp
)
833 struct interface
*ifp
= lp
->ifp
;
834 struct ospf_interface
*oi
;
836 if (IS_DEBUG_OSPF_TE
)
837 zlog_debug("MPLS-TE(initialize_linkparams) Initialize Link Parameters for interface %s",
840 if ((oi
= lookup_oi_by_ifp (ifp
, NULL
, OI_ANY
)) == NULL
)
842 zlog_warn("MPLS-TE(initialize_linkparams) Could not find corresponding OSPF Interface for %s",
848 * Try to set initial values those can be derived from
849 * zebra-interface information.
851 set_linkparams_link_type (oi
, lp
);
853 /* Set local IP addr */
854 set_linkparams_lclif_ipaddr (lp
, oi
->address
->u
.prefix4
);
856 /* Set Remote IP addr if Point to Point Interface */
857 if (oi
->type
== LINK_TYPE_SUBTLV_VALUE_PTP
)
859 struct prefix
*pref
= CONNECTED_PREFIX(oi
->connected
);
861 set_linkparams_rmtif_ipaddr(lp
, pref
->u
.prefix4
);
864 /* Keep Area information in combination with link parameters. */
871 is_mandated_params_set (struct mpls_te_link
*lp
)
875 if (ntohs (OspfMplsTE
.router_addr
.header
.type
) == 0)
877 zlog_warn ("MPLS-TE(is_mandated_params_set) Missing Router Address");
881 if (ntohs (lp
->link_type
.header
.type
) == 0)
883 zlog_warn ("MPLS-TE(is_mandated_params_set) Missing Link Type");
887 if (!IS_INTER_AS (lp
->type
) && (ntohs (lp
->link_id
.header
.type
) == 0))
889 zlog_warn ("MPLS-TE(is_mandated_params_set) Missing Link ID");
898 /*------------------------------------------------------------------------*
899 * Followings are callback functions against generic Opaque-LSAs handling.
900 *------------------------------------------------------------------------*/
903 ospf_mpls_te_new_if (struct interface
*ifp
)
905 struct mpls_te_link
*new;
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
);
912 if (lookup_linkparams_by_ifp (ifp
) != NULL
)
914 zlog_warn ("ospf_mpls_te_new_if: ifp(%p) already in use?", (void *)ifp
);
915 rc
= 0; /* Do nothing here. */
919 new = XCALLOC (MTYPE_OSPF_MPLS_TE
, sizeof (struct mpls_te_link
));
922 zlog_warn ("ospf_mpls_te_new_if: XMALLOC: %s", safe_strerror (errno
));
926 new->instance
= get_mpls_te_instance_value ();
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
;
933 /* Initialize Link Parameters from Interface */
934 initialize_linkparams(new);
936 /* Set TE Parameters from Interface */
937 update_linkparams(new);
939 /* Add Link Parameters structure to the list */
940 listnode_add (OspfMplsTE
.iflist
, new);
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
);
946 /* Schedule Opaque-LSA refresh. *//* XXX */
954 ospf_mpls_te_del_if (struct interface
*ifp
)
956 struct mpls_te_link
*lp
;
959 if ((lp
= lookup_linkparams_by_ifp (ifp
)) != NULL
)
961 struct list
*iflist
= OspfMplsTE
.iflist
;
963 /* Dequeue listnode entry from the list. */
964 listnode_delete (iflist
, lp
);
966 /* Avoid misjudgement in the next lookup. */
967 if (listcount (iflist
) == 0)
968 iflist
->head
= iflist
->tail
= NULL
;
970 XFREE (MTYPE_OSPF_MPLS_TE
, lp
);
973 /* Schedule Opaque-LSA refresh. *//* XXX */
980 /* Main initialization / update function of the MPLS TE Link context */
982 /* Call when interface TE Link parameters are modified */
984 ospf_mpls_te_update_if (struct interface
*ifp
)
986 struct mpls_te_link
*lp
;
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");
992 /* Get Link context from interface */
993 if ((lp
= lookup_linkparams_by_ifp(ifp
)) == NULL
)
995 zlog_warn ("OSPF MPLS-TE Update: Did not find Link Parameters context for interface %s", ifp
->name
);
999 /* Fulfill MPLS-TE Link TLV from Interface TE Link parameters */
1000 if (HAS_LINK_PARAMS(ifp
))
1002 SET_FLAG (lp
->flags
, LPFLG_LSA_ACTIVE
);
1004 /* Update TE parameters */
1005 update_linkparams(lp
);
1007 /* Finally Re-Originate or Refresh Opaque LSA if MPLS_TE is enabled */
1008 if (OspfMplsTE
.status
== enabled
)
1009 if (lp
->area
!= NULL
)
1011 if CHECK_FLAG (lp
->flags
, LPFLG_LSA_ENGAGED
)
1012 ospf_mpls_te_lsa_schedule (lp
, REFRESH_THIS_LSA
);
1014 ospf_mpls_te_lsa_schedule (lp
, REORIGINATE_THIS_LSA
);
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
);
1023 /* Reset Activity flag */
1024 lp
->flags
= LPFLG_LSA_INACTIVE
;
1031 ospf_mpls_te_ism_change (struct ospf_interface
*oi
, int old_state
)
1033 struct te_link_subtlv_link_type old_type
;
1034 struct te_link_subtlv_link_id old_id
;
1035 struct mpls_te_link
*lp
;
1037 if ((lp
= lookup_linkparams_by_ifp (oi
->ifp
)) == NULL
)
1039 zlog_warn ("ospf_mpls_te_ism_change: Cannot get linkparams from OI(%s)?", IF_NAME (oi
));
1043 if (oi
->area
== NULL
|| oi
->area
->ospf
== NULL
)
1045 zlog_warn ("ospf_mpls_te_ism_change: Cannot refer to OSPF from OI(%s)?", IF_NAME (oi
));
1049 if ((lp
->area
!= NULL
1050 && ! IPV4_ADDR_SAME (&lp
->area
->area_id
, &oi
->area
->area_id
))
1051 || (lp
->area
!= NULL
&& oi
->area
== NULL
))
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
);
1059 /* Keep Area information in combination with linkparams. */
1060 lp
->area
= oi
->area
;
1062 /* Keep interface MPLS-TE status */
1063 lp
->flags
= HAS_LINK_PARAMS(oi
->ifp
);
1067 case ISM_PointToPoint
:
1071 old_type
= lp
->link_type
;
1072 old_id
= lp
->link_id
;
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
);
1079 if (oi
->type
== LINK_TYPE_SUBTLV_VALUE_PTP
)
1081 struct prefix
*pref
= CONNECTED_PREFIX(oi
->connected
);
1083 set_linkparams_rmtif_ipaddr(lp
, pref
->u
.prefix4
);
1086 /* Update TE parameters */
1087 update_linkparams(lp
);
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
)))
1096 if CHECK_FLAG (lp
->flags
, LPFLG_LSA_ENGAGED
)
1097 ospf_mpls_te_lsa_schedule (lp
, REFRESH_THIS_LSA
);
1099 ospf_mpls_te_lsa_schedule (lp
, REORIGINATE_THIS_LSA
);
1104 lp
->link_type
.header
.type
= htons (0);
1105 lp
->link_id
.header
.type
= htons (0);
1107 if CHECK_FLAG (lp
->flags
, LPFLG_LSA_ENGAGED
)
1108 ospf_mpls_te_lsa_schedule (lp
, FLUSH_THIS_LSA
);
1118 ospf_mpls_te_nsm_change (struct ospf_neighbor
*nbr
, int old_state
)
1120 /* Nothing to do here */
1124 /*------------------------------------------------------------------------*
1125 * Followings are OSPF protocol processing functions for MPLS-TE.
1126 *------------------------------------------------------------------------*/
1129 build_tlv_header (struct stream
*s
, struct te_tlv_header
*tlvh
)
1131 stream_put (s
, tlvh
, sizeof (struct te_tlv_header
));
1136 build_router_tlv (struct stream
*s
)
1138 struct te_tlv_header
*tlvh
= &OspfMplsTE
.router_addr
.header
;
1139 if (ntohs (tlvh
->type
) != 0)
1141 build_tlv_header (s
, tlvh
);
1142 stream_put (s
, tlvh
+1, TLV_BODY_SIZE (tlvh
));
1148 build_link_subtlv (struct stream
*s
, struct te_tlv_header
*tlvh
)
1151 if ((tlvh
!= NULL
) && (ntohs (tlvh
->type
) != 0))
1153 build_tlv_header (s
, tlvh
);
1154 stream_put (s
, tlvh
+1, TLV_BODY_SIZE (tlvh
));
1160 build_link_tlv (struct stream
*s
, struct mpls_te_link
*lp
)
1162 set_linkparams_link_header (lp
);
1163 build_tlv_header (s
, &lp
->link_header
.header
);
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
);
1190 ospf_mpls_te_lsa_body_set (struct stream
*s
, struct mpls_te_link
*lp
)
1193 * The router address TLV is type 1, and ...
1194 * It must appear in exactly one
1195 * Traffic Engineering LSA originated by a router.
1197 build_router_tlv (s
);
1200 * Only one Link TLV shall be carried in each LSA, allowing for fine
1201 * granularity changes in topology.
1203 build_link_tlv (s
, lp
);
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
)
1212 struct lsa_header
*lsah
;
1213 struct ospf_lsa
*new = NULL
;
1214 u_char options
, lsa_type
= 0;
1215 struct in_addr lsa_id
;
1219 /* Create a stream for LSA. */
1220 if ((s
= stream_new (OSPF_MAX_LSA_SIZE
)) == NULL
)
1222 zlog_warn ("ospf_mpls_te_lsa_new: stream_new() ?");
1225 lsah
= (struct lsa_header
*) STREAM_DATA (s
);
1227 options
= OSPF_OPTION_O
; /* Don't forget this :-) */
1229 /* Set opaque-LSA header fields depending of the type of RFC */
1230 if (IS_INTER_AS (lp
->type
))
1232 if IS_FLOOD_AS (lp
->type
)
1234 options
|= OSPF_OPTION_E
; /* Enable AS external as we flood Inter-AS with Opaque Type 11 */
1235 lsa_type
= OSPF_OPAQUE_AS_LSA
;
1239 options
|= LSA_OPTIONS_GET (area
); /* Get area default option */
1240 options
|= LSA_OPTIONS_NSSA_GET (area
);
1241 lsa_type
= OSPF_OPAQUE_AREA_LSA
;
1243 tmp
= SET_OPAQUE_LSID (OPAQUE_TYPE_INTER_AS_LSA
, lp
->instance
);
1244 lsa_id
.s_addr
= htonl (tmp
);
1246 struct ospf
*top
= ospf_lookup ();
1248 lsa_header_set (s
, options
, lsa_type
, lsa_id
, top
->router_id
);
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
);
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
));
1264 /* Set opaque-LSA body fields. */
1265 ospf_mpls_te_lsa_body_set (s
, lp
);
1268 length
= stream_get_endp (s
);
1269 lsah
->length
= htons (length
);
1271 /* Now, create an OSPF LSA instance. */
1272 if ((new = ospf_lsa_new ()) == NULL
)
1274 zlog_warn ("ospf_mpls_te_lsa_new: ospf_lsa_new() ?");
1278 if ((new->data
= ospf_lsa_data_new (length
)) == NULL
)
1280 zlog_warn ("ospf_mpls_te_lsa_new: ospf_lsa_data_new() ?");
1281 ospf_lsa_unlock (&new);
1288 SET_FLAG (new->flags
, OSPF_LSA_SELF
);
1289 memcpy (new->data
, lsah
, length
);
1297 ospf_mpls_te_lsa_originate1 (struct ospf_area
*area
, struct mpls_te_link
*lp
)
1299 struct ospf_lsa
*new;
1302 /* Create new Opaque-LSA/MPLS-TE instance. */
1303 if ((new = ospf_mpls_te_lsa_new (area
, lp
)) == NULL
)
1305 zlog_warn ("ospf_mpls_te_lsa_originate1: ospf_mpls_te_lsa_new() ?");
1309 /* Install this LSA into LSDB. */
1310 if (ospf_lsa_install (area
->ospf
, NULL
/*oi*/, new) == NULL
)
1312 zlog_warn ("ospf_mpls_te_lsa_originate1: ospf_lsa_install() ?");
1313 ospf_lsa_unlock (&new);
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
++;
1322 /* Flood new LSA through area. */
1323 ospf_flood_through_area (area
, NULL
/*nbr*/, new);
1325 if (IS_DEBUG_OSPF (lsa
, LSA_GENERATE
))
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
);
1340 ospf_mpls_te_lsa_originate_area (void *arg
)
1342 struct ospf_area
*area
= (struct ospf_area
*) arg
;
1343 struct listnode
*node
, *nnode
;
1344 struct mpls_te_link
*lp
;
1347 if (OspfMplsTE
.status
== disabled
)
1349 zlog_info ("ospf_mpls_te_lsa_originate_area: MPLS-TE is disabled now.");
1350 rc
= 0; /* This is not an error case. */
1354 for (ALL_LIST_ELEMENTS (OspfMplsTE
.iflist
, node
, nnode
, lp
))
1356 /* Process only enabled LSA with area scope flooding */
1357 if (!CHECK_FLAG (lp
->flags
, LPFLG_LSA_ACTIVE
) || IS_FLOOD_AS (lp
->type
))
1360 if (lp
->area
== NULL
)
1363 if (! IPV4_ADDR_SAME (&lp
->area
->area_id
, &area
->area_id
))
1366 if CHECK_FLAG (lp
->flags
, LPFLG_LSA_ENGAGED
)
1368 if CHECK_FLAG (lp
->flags
, LPFLG_LSA_FORCED_REFRESH
)
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
);
1376 if (! is_mandated_params_set (lp
))
1378 zlog_warn ("ospf_mpls_te_lsa_originate_area: Link(%s) lacks some mandated MPLS-TE parameters.",
1379 lp
->ifp
? lp
->ifp
->name
: "?");
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)
1397 ospf_mpls_te_lsa_originate2 (struct ospf
*top
, struct mpls_te_link
*lp
)
1399 struct ospf_lsa
*new;
1402 /* Create new Opaque-LSA/Inter-AS instance. */
1403 if ((new = ospf_mpls_te_lsa_new (NULL
, lp
)) == NULL
)
1405 zlog_warn ("ospf_mpls_te_lsa_originate2: ospf_router_info_lsa_new() ?");
1409 /* Install this LSA into LSDB. */
1410 if (ospf_lsa_install (top
, NULL
/*oi */ , new) == NULL
)
1412 zlog_warn ("ospf_mpls_te_lsa_originate2: ospf_lsa_install() ?");
1413 ospf_lsa_unlock (&new);
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
++;
1422 /* Flood new LSA through AS. */
1423 ospf_flood_through_as (top
, NULL
/*nbr */ , new);
1425 if (IS_DEBUG_OSPF (lsa
, LSA_GENERATE
))
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
);
1437 ospf_mpls_te_lsa_originate_as (void *arg
)
1440 struct ospf_area
*area
;
1441 struct listnode
*node
, *nnode
;
1442 struct mpls_te_link
*lp
;
1445 if ((OspfMplsTE
.status
== disabled
) || (OspfMplsTE
.inter_as
== Disable
))
1448 ("ospf_mpls_te_lsa_originate_as: MPLS-TE Inter-AS is disabled for now.");
1449 rc
= 0; /* This is not an error case. */
1453 for (ALL_LIST_ELEMENTS (OspfMplsTE
.iflist
, node
, nnode
, lp
))
1455 /* Process only enabled INTER_AS Links or Pseudo-Links */
1456 if (!CHECK_FLAG (lp
->flags
, LPFLG_LSA_ACTIVE
) || !IS_INTER_AS (lp
->type
))
1459 if CHECK_FLAG (lp
->flags
, LPFLG_LSA_ENGAGED
)
1461 if CHECK_FLAG (lp
->flags
, LPFLG_LSA_FORCED_REFRESH
)
1463 UNSET_FLAG (lp
->flags
, LPFLG_LSA_FORCED_REFRESH
);
1464 ospf_mpls_te_lsa_schedule (lp
, REFRESH_THIS_LSA
);
1468 if (!is_mandated_params_set (lp
))
1470 zlog_warn ("ospf_mpls_te_lsa_originate_as: Link(%s) lacks some mandated MPLS-TE parameters.",
1471 lp
->ifp
? lp
->ifp
->name
: "?");
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");
1480 if (IS_FLOOD_AS (lp
->type
))
1482 top
= (struct ospf
*) arg
;
1483 rc
= ospf_mpls_te_lsa_originate2 (top
, lp
);
1487 area
= (struct ospf_area
*) arg
;
1488 rc
= ospf_mpls_te_lsa_originate1 (area
, lp
);
1496 static struct ospf_lsa
*
1497 ospf_mpls_te_lsa_refresh (struct ospf_lsa
*lsa
)
1499 struct mpls_te_link
*lp
;
1500 struct ospf_area
*area
= lsa
->area
;
1502 struct ospf_lsa
*new = NULL
;
1504 if (OspfMplsTE
.status
== disabled
)
1507 * This LSA must have flushed before due to MPLS-TE status change.
1508 * It seems a slip among routers in the routing domain.
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. */
1514 /* At first, resolve lsa/lp relationship. */
1515 if ((lp
= lookup_linkparams_by_instance (lsa
)) == NULL
)
1517 zlog_warn ("ospf_mpls_te_lsa_refresh: Invalid parameter?");
1518 lsa
->data
->ls_age
= htons (OSPF_LSA_MAXAGE
); /* Flush it anyway. */
1521 /* Check if lp was not disable in the interval */
1522 if (!CHECK_FLAG (lp
->flags
, LPFLG_LSA_ACTIVE
))
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. */
1528 /* If the lsa's age reached to MaxAge, start flushing procedure. */
1529 if (IS_LSA_MAXAGE (lsa
))
1532 UNSET_FLAG (lp
->flags
, LPFLG_LSA_ENGAGED
);
1533 ospf_opaque_lsa_flush_schedule (lsa
);
1537 /* Create new Opaque-LSA/MPLS-TE instance. */
1538 if ((new = ospf_mpls_te_lsa_new (area
, lp
)) == NULL
)
1540 zlog_warn ("ospf_mpls_te_lsa_refresh: ospf_mpls_te_lsa_new() ?");
1543 new->data
->ls_seqnum
= lsa_seqnum_increment (lsa
);
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 */
1551 top
= ospf_lookup ();
1553 if (ospf_lsa_install (top
, NULL
/*oi */ , new) == NULL
)
1555 zlog_warn ("ospf_mpls_te_lsa_refresh: ospf_lsa_install() ?");
1556 ospf_lsa_unlock (&new);
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);
1564 ospf_flood_through_area (area
, NULL
/*nbr*/, new);
1566 /* Debug logging. */
1567 if (IS_DEBUG_OSPF (lsa
, LSA_GENERATE
))
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
);
1579 ospf_mpls_te_lsa_schedule (struct mpls_te_link
*lp
, opcode_t opcode
)
1581 struct ospf_lsa lsa
;
1582 struct lsa_header lsah
;
1586 memset (&lsa
, 0, sizeof (lsa
));
1587 memset (&lsah
, 0, sizeof (lsah
));
1588 top
= ospf_lookup ();
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
))) {
1596 lsa
.area
= lp
->area
;
1598 if (IS_FLOOD_AS (lp
->type
))
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
);
1606 lsah
.type
= OSPF_OPAQUE_AREA_LSA
;
1607 if (IS_INTER_AS (lp
->type
))
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
)
1615 zlog_warn ("MPLS-TE(ospf_mpls_te_lsa_schedule) Area context is null. Abort !");
1618 tmp
= SET_OPAQUE_LSID (OPAQUE_TYPE_INTER_AS_LSA
, lp
->instance
);
1621 tmp
= SET_OPAQUE_LSID (OPAQUE_TYPE_TRAFFIC_ENGINEERING_LSA
, lp
->instance
);
1622 lsah
.id
.s_addr
= htonl (tmp
);
1627 case REORIGINATE_THIS_LSA
:
1628 if (IS_FLOOD_AS (lp
->type
))
1630 ospf_opaque_lsa_reoriginate_schedule ((void *) top
, OSPF_OPAQUE_AS_LSA
,
1631 OPAQUE_TYPE_INTER_AS_LSA
);
1635 if (IS_FLOOD_AREA (lp
->type
))
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
);
1641 ospf_opaque_lsa_reoriginate_schedule ((void *) lp
->area
, OSPF_OPAQUE_AREA_LSA
,
1642 OPAQUE_TYPE_TRAFFIC_ENGINEERING_LSA
);
1646 case REFRESH_THIS_LSA
:
1647 ospf_opaque_lsa_refresh_schedule (&lsa
);
1649 case FLUSH_THIS_LSA
:
1650 /* Reset Activity flag */
1651 lp
->flags
= LPFLG_LSA_INACTIVE
;
1652 ospf_opaque_lsa_flush_schedule (&lsa
);
1655 zlog_warn ("ospf_mpls_te_lsa_schedule: Unknown opcode (%u)", opcode
);
1663 /*------------------------------------------------------------------------*
1664 * Followings are vty session control functions.
1665 *------------------------------------------------------------------------*/
1668 show_vty_router_addr (struct vty
*vty
, struct te_tlv_header
*tlvh
)
1670 struct te_tlv_router_addr
*top
= (struct te_tlv_router_addr
*) tlvh
;
1673 vty_out (vty
, " Router-Address: %s%s", inet_ntoa (top
->value
),
1676 zlog_debug (" Router-Address: %s", inet_ntoa (top
->value
));
1678 return TLV_SIZE (tlvh
);
1682 show_vty_link_header (struct vty
*vty
, struct te_tlv_header
*tlvh
)
1684 struct te_tlv_link
*top
= (struct te_tlv_link
*) tlvh
;
1687 vty_out (vty
, " Link: %u octets of data%s", ntohs (top
->header
.length
),
1690 zlog_debug (" Link: %u octets of data", ntohs (top
->header
.length
));
1692 return TLV_HDR_SIZE
; /* Here is special, not "TLV_SIZE". */
1696 show_vty_link_subtlv_link_type (struct vty
*vty
, struct te_tlv_header
*tlvh
)
1698 struct te_link_subtlv_link_type
*top
;
1699 const char *cp
= "Unknown";
1701 top
= (struct te_link_subtlv_link_type
*) tlvh
;
1702 switch (top
->link_type
.value
)
1704 case LINK_TYPE_SUBTLV_VALUE_PTP
:
1705 cp
= "Point-to-point";
1707 case LINK_TYPE_SUBTLV_VALUE_MA
:
1715 vty_out (vty
, " Link-Type: %s (%u)%s", cp
, top
->link_type
.value
,
1718 zlog_debug (" Link-Type: %s (%u)", cp
, top
->link_type
.value
);
1720 return TLV_SIZE (tlvh
);
1724 show_vty_link_subtlv_link_id (struct vty
*vty
, struct te_tlv_header
*tlvh
)
1726 struct te_link_subtlv_link_id
*top
;
1728 top
= (struct te_link_subtlv_link_id
*) tlvh
;
1730 vty_out (vty
, " Link-ID: %s%s", inet_ntoa (top
->value
), VTY_NEWLINE
);
1732 zlog_debug (" Link-ID: %s", inet_ntoa (top
->value
));
1734 return TLV_SIZE (tlvh
);
1738 show_vty_link_subtlv_lclif_ipaddr (struct vty
*vty
,
1739 struct te_tlv_header
*tlvh
)
1741 struct te_link_subtlv_lclif_ipaddr
*top
;
1744 top
= (struct te_link_subtlv_lclif_ipaddr
*) tlvh
;
1745 n
= ntohs (tlvh
->length
) / sizeof (top
->value
[0]);
1748 vty_out (vty
, " Local Interface IP Address(es): %d%s", n
, VTY_NEWLINE
);
1750 zlog_debug (" Local Interface IP Address(es): %d", n
);
1752 for (i
= 0; i
< n
; i
++)
1755 vty_out (vty
, " #%d: %s%s", i
, inet_ntoa (top
->value
[i
]),
1758 zlog_debug (" #%d: %s", i
, inet_ntoa (top
->value
[i
]));
1760 return TLV_SIZE (tlvh
);
1764 show_vty_link_subtlv_rmtif_ipaddr (struct vty
*vty
,
1765 struct te_tlv_header
*tlvh
)
1767 struct te_link_subtlv_rmtif_ipaddr
*top
;
1770 top
= (struct te_link_subtlv_rmtif_ipaddr
*) tlvh
;
1771 n
= ntohs (tlvh
->length
) / sizeof (top
->value
[0]);
1773 vty_out (vty
, " Remote Interface IP Address(es): %d%s", n
, VTY_NEWLINE
);
1775 zlog_debug (" Remote Interface IP Address(es): %d", n
);
1777 for (i
= 0; i
< n
; i
++)
1780 vty_out (vty
, " #%d: %s%s", i
, inet_ntoa (top
->value
[i
]),
1783 zlog_debug (" #%d: %s", i
, inet_ntoa (top
->value
[i
]));
1785 return TLV_SIZE (tlvh
);
1789 show_vty_link_subtlv_te_metric (struct vty
*vty
, struct te_tlv_header
*tlvh
)
1791 struct te_link_subtlv_te_metric
*top
;
1793 top
= (struct te_link_subtlv_te_metric
*) tlvh
;
1795 vty_out (vty
, " Traffic Engineering Metric: %u%s",
1796 (u_int32_t
) ntohl (top
->value
), VTY_NEWLINE
);
1798 zlog_debug (" Traffic Engineering Metric: %u",
1799 (u_int32_t
) ntohl (top
->value
));
1801 return TLV_SIZE (tlvh
);
1805 show_vty_link_subtlv_max_bw (struct vty
*vty
, struct te_tlv_header
*tlvh
)
1807 struct te_link_subtlv_max_bw
*top
;
1810 top
= (struct te_link_subtlv_max_bw
*) tlvh
;
1811 fval
= ntohf (top
->value
);
1814 vty_out (vty
, " Maximum Bandwidth: %g (Bytes/sec)%s", fval
, VTY_NEWLINE
);
1816 zlog_debug (" Maximum Bandwidth: %g (Bytes/sec)", fval
);
1818 return TLV_SIZE (tlvh
);
1822 show_vty_link_subtlv_max_rsv_bw (struct vty
*vty
, struct te_tlv_header
*tlvh
)
1824 struct te_link_subtlv_max_rsv_bw
*top
;
1827 top
= (struct te_link_subtlv_max_rsv_bw
*) tlvh
;
1828 fval
= ntohf (top
->value
);
1831 vty_out (vty
, " Maximum Reservable Bandwidth: %g (Bytes/sec)%s", fval
,
1834 zlog_debug (" Maximum Reservable Bandwidth: %g (Bytes/sec)", fval
);
1836 return TLV_SIZE (tlvh
);
1840 show_vty_link_subtlv_unrsv_bw (struct vty
*vty
, struct te_tlv_header
*tlvh
)
1842 struct te_link_subtlv_unrsv_bw
*top
;
1846 top
= (struct te_link_subtlv_unrsv_bw
*) tlvh
;
1848 vty_out (vty
, " Unreserved Bandwidth per Class Type in Byte/s:%s", VTY_NEWLINE
);
1850 zlog_debug (" Unreserved Bandwidth per Class Type in Byte/s:");
1851 for (i
= 0; i
< MAX_CLASS_TYPE
; i
+=2)
1853 fval1
= ntohf (top
->value
[i
]);
1854 fval2
= ntohf (top
->value
[i
+1]);
1857 vty_out(vty
, " [%d]: %g (Bytes/sec),\t[%d]: %g (Bytes/sec)%s",
1858 i
, fval1
, i
+1, fval2
, VTY_NEWLINE
);
1860 zlog_debug (" [%d]: %g (Bytes/sec),\t[%d]: %g (Bytes/sec)",
1861 i
, fval1
, i
+1, fval2
);
1864 return TLV_SIZE (tlvh
);
1868 show_vty_link_subtlv_rsc_clsclr (struct vty
*vty
, struct te_tlv_header
*tlvh
)
1870 struct te_link_subtlv_rsc_clsclr
*top
;
1872 top
= (struct te_link_subtlv_rsc_clsclr
*) tlvh
;
1874 vty_out (vty
, " Resource class/color: 0x%x%s",
1875 (u_int32_t
) ntohl (top
->value
), VTY_NEWLINE
);
1877 zlog_debug (" Resource Class/Color: 0x%x",
1878 (u_int32_t
) ntohl (top
->value
));
1880 return TLV_SIZE (tlvh
);
1884 show_vty_link_subtlv_lrrid (struct vty
*vty
, struct te_tlv_header
*tlvh
)
1886 struct te_link_subtlv_lrrid
*top
;
1888 top
= (struct te_link_subtlv_lrrid
*) tlvh
;
1892 vty_out (vty
, " Local TE Router ID: %s%s", inet_ntoa (top
->local
),
1894 vty_out (vty
, " Remote TE Router ID: %s%s", inet_ntoa (top
->remote
),
1899 zlog_debug (" Local TE Router ID: %s", inet_ntoa (top
->local
));
1900 zlog_debug (" Remote TE Router ID: %s", inet_ntoa (top
->remote
));
1903 return TLV_SIZE (tlvh
);
1907 show_vty_link_subtlv_llri (struct vty
*vty
, struct te_tlv_header
*tlvh
)
1909 struct te_link_subtlv_llri
*top
;
1911 top
= (struct te_link_subtlv_llri
*) tlvh
;
1915 vty_out (vty
, " Link Local ID: %d%s", (u_int32_t
) ntohl (top
->local
),
1917 vty_out (vty
, " Link Remote ID: %d%s", (u_int32_t
) ntohl (top
->remote
),
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
));
1926 return TLV_SIZE (tlvh
);
1930 show_vty_link_subtlv_rip (struct vty
*vty
, struct te_tlv_header
*tlvh
)
1932 struct te_link_subtlv_rip
*top
;
1934 top
= (struct te_link_subtlv_rip
*) tlvh
;
1937 vty_out (vty
, " Inter-AS TE Remote ASBR IP address: %s%s",
1938 inet_ntoa (top
->value
), VTY_NEWLINE
);
1940 zlog_debug (" Inter-AS TE Remote ASBR IP address: %s",
1941 inet_ntoa (top
->value
));
1943 return TLV_SIZE (tlvh
);
1947 show_vty_link_subtlv_ras (struct vty
*vty
, struct te_tlv_header
*tlvh
)
1949 struct te_link_subtlv_ras
*top
;
1951 top
= (struct te_link_subtlv_ras
*) tlvh
;
1954 vty_out (vty
, " Inter-AS TE Remote AS number: %u%s", ntohl (top
->value
),
1957 zlog_debug (" Inter-AS TE Remote AS number: %u", ntohl (top
->value
));
1959 return TLV_SIZE (tlvh
);
1963 show_vty_link_subtlv_av_delay (struct vty
*vty
, struct te_tlv_header
*tlvh
)
1965 struct te_link_subtlv_av_delay
*top
;
1967 u_int32_t anomalous
;
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
;
1974 vty_out (vty
, " %s Average Link Delay: %d (micro-sec)%s",
1975 anomalous
? "Anomalous" : "Normal", delay
, VTY_NEWLINE
);
1977 zlog_debug (" %s Average Link Delay: %d (micro-sec)",
1978 anomalous
? "Anomalous" : "Normal", delay
);
1980 return TLV_SIZE (tlvh
);
1984 show_vty_link_subtlv_mm_delay (struct vty
*vty
, struct te_tlv_header
*tlvh
)
1986 struct te_link_subtlv_mm_delay
*top
;
1987 u_int32_t low
, high
;
1988 u_int32_t anomalous
;
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
);
1996 vty_out (vty
, " %s Min/Max Link Delay: %d/%d (micro-sec)%s",
1997 anomalous
? "Anomalous" : "Normal", low
, high
, VTY_NEWLINE
);
1999 zlog_debug (" %s Min/Max Link Delay: %d/%d (micro-sec)",
2000 anomalous
? "Anomalous" : "Normal", low
, high
);
2002 return TLV_SIZE (tlvh
);
2006 show_vty_link_subtlv_delay_var (struct vty
*vty
, struct te_tlv_header
*tlvh
)
2008 struct te_link_subtlv_delay_var
*top
;
2011 top
= (struct te_link_subtlv_delay_var
*) tlvh
;
2012 jitter
= (u_int32_t
) ntohl (top
->value
) & TE_EXT_MASK
;
2015 vty_out (vty
, " Delay Variation: %d (micro-sec)%s", jitter
, VTY_NEWLINE
);
2017 zlog_debug (" Delay Variation: %d (micro-sec)", jitter
);
2019 return TLV_SIZE (tlvh
);
2023 show_vty_link_subtlv_pkt_loss (struct vty
*vty
, struct te_tlv_header
*tlvh
)
2025 struct te_link_subtlv_pkt_loss
*top
;
2027 u_int32_t anomalous
;
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
;
2036 vty_out (vty
, " %s Link Loss: %g (%%)%s", anomalous
? "Anomalous" : "Normal",
2039 zlog_debug (" %s Link Loss: %g (%%)", anomalous
? "Anomalous" : "Normal",
2042 return TLV_SIZE (tlvh
);
2046 show_vty_link_subtlv_res_bw (struct vty
*vty
, struct te_tlv_header
*tlvh
)
2048 struct te_link_subtlv_res_bw
*top
;
2051 top
= (struct te_link_subtlv_res_bw
*) tlvh
;
2052 fval
= ntohf (top
->value
);
2055 vty_out (vty
, " Unidirectional Residual Bandwidth: %g (Bytes/sec)%s",
2058 zlog_debug (" Unidirectional Residual Bandwidth: %g (Bytes/sec)",
2061 return TLV_SIZE (tlvh
);
2065 show_vty_link_subtlv_ava_bw (struct vty
*vty
, struct te_tlv_header
*tlvh
)
2067 struct te_link_subtlv_ava_bw
*top
;
2070 top
= (struct te_link_subtlv_ava_bw
*) tlvh
;
2071 fval
= ntohf (top
->value
);
2074 vty_out (vty
, " Unidirectional Available Bandwidth: %g (Bytes/sec)%s",
2077 zlog_debug (" Unidirectional Available Bandwidth: %g (Bytes/sec)",
2080 return TLV_SIZE (tlvh
);
2084 show_vty_link_subtlv_use_bw (struct vty
*vty
, struct te_tlv_header
*tlvh
)
2086 struct te_link_subtlv_use_bw
*top
;
2089 top
= (struct te_link_subtlv_use_bw
*) tlvh
;
2090 fval
= ntohf (top
->value
);
2093 vty_out (vty
, " Unidirectional Utilized Bandwidth: %g (Bytes/sec)%s",
2096 zlog_debug (" Unidirectional Utilized Bandwidth: %g (Bytes/sec)",
2099 return TLV_SIZE (tlvh
);
2103 show_vty_unknown_tlv (struct vty
*vty
, struct te_tlv_header
*tlvh
)
2106 vty_out (vty
, " Unknown TLV: [type(0x%x), length(0x%x)]%s",
2107 ntohs (tlvh
->type
), ntohs (tlvh
->length
), VTY_NEWLINE
);
2109 zlog_debug (" Unknown TLV: [type(0x%x), length(0x%x)]",
2110 ntohs (tlvh
->type
), ntohs (tlvh
->length
));
2112 return TLV_SIZE (tlvh
);
2116 ospf_mpls_te_show_link_subtlv (struct vty
*vty
, struct te_tlv_header
*tlvh0
,
2117 u_int16_t subtotal
, u_int16_t total
)
2119 struct te_tlv_header
*tlvh
, *next
;
2120 u_int16_t sum
= subtotal
;
2122 for (tlvh
= tlvh0
; sum
< total
; tlvh
= (next
? next
: TLV_HDR_NEXT (tlvh
)))
2125 switch (ntohs (tlvh
->type
))
2127 case TE_LINK_SUBTLV_LINK_TYPE
:
2128 sum
+= show_vty_link_subtlv_link_type (vty
, tlvh
);
2130 case TE_LINK_SUBTLV_LINK_ID
:
2131 sum
+= show_vty_link_subtlv_link_id (vty
, tlvh
);
2133 case TE_LINK_SUBTLV_LCLIF_IPADDR
:
2134 sum
+= show_vty_link_subtlv_lclif_ipaddr (vty
, tlvh
);
2136 case TE_LINK_SUBTLV_RMTIF_IPADDR
:
2137 sum
+= show_vty_link_subtlv_rmtif_ipaddr (vty
, tlvh
);
2139 case TE_LINK_SUBTLV_TE_METRIC
:
2140 sum
+= show_vty_link_subtlv_te_metric (vty
, tlvh
);
2142 case TE_LINK_SUBTLV_MAX_BW
:
2143 sum
+= show_vty_link_subtlv_max_bw (vty
, tlvh
);
2145 case TE_LINK_SUBTLV_MAX_RSV_BW
:
2146 sum
+= show_vty_link_subtlv_max_rsv_bw (vty
, tlvh
);
2148 case TE_LINK_SUBTLV_UNRSV_BW
:
2149 sum
+= show_vty_link_subtlv_unrsv_bw (vty
, tlvh
);
2151 case TE_LINK_SUBTLV_RSC_CLSCLR
:
2152 sum
+= show_vty_link_subtlv_rsc_clsclr (vty
, tlvh
);
2154 case TE_LINK_SUBTLV_LRRID
:
2155 sum
+= show_vty_link_subtlv_lrrid (vty
, tlvh
);
2157 case TE_LINK_SUBTLV_LLRI
:
2158 sum
+= show_vty_link_subtlv_llri (vty
, tlvh
);
2160 case TE_LINK_SUBTLV_RIP
:
2161 sum
+= show_vty_link_subtlv_rip (vty
, tlvh
);
2163 case TE_LINK_SUBTLV_RAS
:
2164 sum
+= show_vty_link_subtlv_ras (vty
, tlvh
);
2166 case TE_LINK_SUBTLV_AV_DELAY
:
2167 sum
+= show_vty_link_subtlv_av_delay (vty
, tlvh
);
2169 case TE_LINK_SUBTLV_MM_DELAY
:
2170 sum
+= show_vty_link_subtlv_mm_delay (vty
, tlvh
);
2172 case TE_LINK_SUBTLV_DELAY_VAR
:
2173 sum
+= show_vty_link_subtlv_delay_var (vty
, tlvh
);
2175 case TE_LINK_SUBTLV_PKT_LOSS
:
2176 sum
+= show_vty_link_subtlv_pkt_loss (vty
, tlvh
);
2178 case TE_LINK_SUBTLV_RES_BW
:
2179 sum
+= show_vty_link_subtlv_res_bw (vty
, tlvh
);
2181 case TE_LINK_SUBTLV_AVA_BW
:
2182 sum
+= show_vty_link_subtlv_ava_bw (vty
, tlvh
);
2184 case TE_LINK_SUBTLV_USE_BW
:
2185 sum
+= show_vty_link_subtlv_use_bw (vty
, tlvh
);
2188 sum
+= show_vty_unknown_tlv (vty
, tlvh
);
2196 ospf_mpls_te_show_info (struct vty
*vty
, struct ospf_lsa
*lsa
)
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
;
2205 total
= ntohs (lsah
->length
) - OSPF_LSA_HEADER_SIZE
;
2207 for (tlvh
= TLV_HDR_TOP (lsah
); sum
< total
;
2208 tlvh
= (next
? next
: TLV_HDR_NEXT (tlvh
)))
2210 if (subfunc
!= NULL
)
2212 sum
= (* subfunc
)(vty
, tlvh
, sum
, total
);
2213 next
= (struct te_tlv_header
*)((char *) tlvh
+ sum
);
2219 switch (ntohs (tlvh
->type
))
2221 case TE_TLV_ROUTER_ADDR
:
2222 sum
+= show_vty_router_addr (vty
, tlvh
);
2225 sum
+= show_vty_link_header (vty
, tlvh
);
2226 subfunc
= ospf_mpls_te_show_link_subtlv
;
2230 sum
+= show_vty_unknown_tlv (vty
, tlvh
);
2238 ospf_mpls_te_config_write_router (struct vty
*vty
)
2241 if (OspfMplsTE
.status
== enabled
)
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
);
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
);
2257 /*------------------------------------------------------------------------*
2258 * Followings are vty command functions.
2259 *------------------------------------------------------------------------*/
2261 DEFUN (ospf_mpls_te_on
,
2262 ospf_mpls_te_on_cmd
,
2265 "Enable the MPLS-TE functionality\n")
2267 struct listnode
*node
;
2268 struct mpls_te_link
*lp
;
2269 struct ospf
*ospf
= vty
->index
;
2274 if (OspfMplsTE
.status
== enabled
)
2277 if (IS_DEBUG_OSPF_EVENT
)
2278 zlog_debug ("MPLS-TE: OFF -> ON");
2280 OspfMplsTE
.status
= enabled
;
2282 /* Reoriginate RFC3630 & RFC6827 Links */
2283 ospf_mpls_te_foreach_area (ospf_mpls_te_lsa_schedule
, REORIGINATE_THIS_LSA
);
2285 /* Reoriginate LSA if INTER-AS is always on */
2286 if (OspfMplsTE
.inter_as
!= Disable
)
2288 for (ALL_LIST_ELEMENTS_RO (OspfMplsTE
.iflist
, node
, lp
))
2290 if (IS_INTER_AS (lp
->type
))
2292 ospf_mpls_te_lsa_schedule (lp
, REORIGINATE_THIS_LSA
);
2300 DEFUN (no_ospf_mpls_te
,
2301 no_ospf_mpls_te_cmd
,
2304 "Disable the MPLS-TE functionality\n")
2306 struct listnode
*node
, *nnode
;
2307 struct mpls_te_link
*lp
;
2308 struct ospf
*ospf
= vty
->index
;
2313 if (OspfMplsTE
.status
== disabled
)
2316 if (IS_DEBUG_OSPF_EVENT
)
2317 zlog_debug ("MPLS-TE: ON -> OFF");
2319 OspfMplsTE
.status
= disabled
;
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
);
2329 DEFUN (ospf_mpls_te_router_addr
,
2330 ospf_mpls_te_router_addr_cmd
,
2331 "mpls-te router-address A.B.C.D",
2333 "Stable IP address of the advertising router\n"
2334 "MPLS-TE router address in IPv4 address format\n")
2337 struct te_tlv_router_addr
*ra
= &OspfMplsTE
.router_addr
;
2338 struct in_addr value
;
2339 struct ospf
*ospf
= vty
->index
;
2344 if (! inet_aton (argv
[idx_ipv4
]->arg
, &value
))
2346 vty_out (vty
, "Please specify Router-Addr by A.B.C.D%s", VTY_NEWLINE
);
2350 if (ntohs (ra
->header
.type
) == 0
2351 || ntohl (ra
->value
.s_addr
) != ntohl (value
.s_addr
))
2353 struct listnode
*node
, *nnode
;
2354 struct mpls_te_link
*lp
;
2355 int need_to_reoriginate
= 0;
2357 set_mpls_te_router_addr (value
);
2359 if (OspfMplsTE
.status
== disabled
)
2362 for (ALL_LIST_ELEMENTS (OspfMplsTE
.iflist
, node
, nnode
, lp
))
2364 if ((lp
->area
== NULL
) || IS_FLOOD_AS (lp
->type
))
2367 if (!CHECK_FLAG (lp
->flags
, LPFLG_LSA_ENGAGED
))
2369 need_to_reoriginate
= 1;
2374 for (ALL_LIST_ELEMENTS (OspfMplsTE
.iflist
, node
, nnode
, lp
))
2376 if ((lp
->area
== NULL
) || IS_FLOOD_AS (lp
->type
))
2379 if (need_to_reoriginate
)
2380 SET_FLAG (lp
->flags
, LPFLG_LSA_FORCED_REFRESH
);
2382 ospf_mpls_te_lsa_schedule (lp
, REFRESH_THIS_LSA
);
2385 if (need_to_reoriginate
)
2386 ospf_mpls_te_foreach_area (ospf_mpls_te_lsa_schedule
, REORIGINATE_THIS_LSA
);
2393 set_inter_as_mode (struct vty
*vty
, const char *mode_name
,
2394 const char *area_id
)
2396 enum inter_as_mode mode
;
2397 struct listnode
*node
;
2398 struct mpls_te_link
*lp
;
2401 if (OspfMplsTE
.status
== enabled
)
2404 /* Read and Check inter_as mode */
2405 if (strcmp (mode_name
, "as") == 0)
2407 else if (strcmp (mode_name
, "area") == 0)
2410 VTY_GET_OSPF_AREA_ID (OspfMplsTE
.interas_areaid
, format
, area_id
);
2414 vty_out (vty
, "Unknown mode. Please choose between as or area%s",
2419 if (IS_DEBUG_OSPF_EVENT
)
2420 zlog_debug ("MPLS-TE: Inter-AS enable with %s flooding support",
2423 /* Register new callbacks regarding the flooding scope (AS or Area) */
2424 if (ospf_mpls_te_register (mode
) < 0)
2426 vty_out (vty
, "Internal error: Unable to register Inter-AS functions%s",
2431 /* Enable mode and re-originate LSA if needed */
2432 if ((OspfMplsTE
.inter_as
== Disable
) && (mode
!= OspfMplsTE
.inter_as
))
2434 OspfMplsTE
.inter_as
= mode
;
2435 /* Re-originate all InterAS-TEv2 LSA */
2436 for (ALL_LIST_ELEMENTS_RO (OspfMplsTE
.iflist
, node
, lp
))
2438 if (IS_INTER_AS (lp
->type
))
2441 lp
->type
|= FLOOD_AS
;
2443 lp
->type
|= FLOOD_AREA
;
2444 ospf_mpls_te_lsa_schedule (lp
, REORIGINATE_THIS_LSA
);
2450 vty_out (vty
, "Please change Inter-AS support to disable first before going to mode %s%s",
2451 mode2text
[mode
], VTY_NEWLINE
);
2459 DEFUN (ospf_mpls_te_inter_as_as
,
2460 ospf_mpls_te_inter_as_cmd
,
2461 "mpls-te inter-as as",
2463 "Configure MPLS-TE Inter-AS support\n"
2464 "AS native mode self originate INTER_AS LSA with Type 11 (as flooding scope)\n")
2466 return set_inter_as_mode (vty
, "as", "");
2469 DEFUN (ospf_mpls_te_inter_as_area
,
2470 ospf_mpls_te_inter_as_area_cmd
,
2471 "mpls-te inter-as area <A.B.C.D|(0-4294967295)>",
2473 "Configure MPLS-TE Inter-AS support\n"
2474 "AREA native mode self originate INTER_AS LSA with Type 10 (area flooding scope)\n"
2475 "OSPF area ID in IP format\n"
2476 "OSPF area ID as decimal value\n")
2478 int idx_ipv4_number
= 3;
2479 return set_inter_as_mode (vty
, "area", argv
[idx_ipv4_number
]->arg
);
2482 DEFUN (no_ospf_mpls_te_inter_as
,
2483 no_ospf_mpls_te_inter_as_cmd
,
2484 "no mpls-te inter-as",
2487 "Disable MPLS-TE Inter-AS support\n")
2490 struct listnode
*node
, *nnode
;
2491 struct mpls_te_link
*lp
;
2493 if (IS_DEBUG_OSPF_EVENT
)
2494 zlog_debug ("MPLS-TE: Inter-AS support OFF");
2496 if ((OspfMplsTE
.status
== enabled
) && (OspfMplsTE
.inter_as
!= Disable
))
2498 OspfMplsTE
.inter_as
= Disable
;
2499 /* Flush all Inter-AS LSA */
2500 for (ALL_LIST_ELEMENTS (OspfMplsTE
.iflist
, node
, nnode
, lp
))
2501 if (IS_INTER_AS (lp
->type
) && CHECK_FLAG (lp
->flags
, LPFLG_LSA_ENGAGED
))
2502 ospf_mpls_te_lsa_schedule (lp
, FLUSH_THIS_LSA
);
2505 /* Deregister the Callbacks for Inter-AS suport */
2506 ospf_mpls_te_unregister ();
2511 DEFUN (show_ip_ospf_mpls_te_router
,
2512 show_ip_ospf_mpls_te_router_cmd
,
2513 "show ip ospf mpls-te router",
2517 "MPLS-TE information\n"
2518 "MPLS-TE Router parameters\n")
2520 if (OspfMplsTE
.status
== enabled
)
2522 vty_out (vty
, "--- MPLS-TE router parameters ---%s", VTY_NEWLINE
);
2524 if (ntohs (OspfMplsTE
.router_addr
.header
.type
) != 0)
2525 show_vty_router_addr (vty
, &OspfMplsTE
.router_addr
.header
);
2526 else if (vty
!= NULL
)
2527 vty_out (vty
, " N/A%s", VTY_NEWLINE
);
2533 show_mpls_te_link_sub (struct vty
*vty
, struct interface
*ifp
)
2535 struct mpls_te_link
*lp
;
2537 if ((OspfMplsTE
.status
== enabled
)
2538 && HAS_LINK_PARAMS(ifp
)
2539 && !if_is_loopback (ifp
)
2541 && ((lp
= lookup_linkparams_by_ifp (ifp
)) != NULL
))
2543 /* Continue only if interface is not passive or support Inter-AS TEv2 */
2544 if (!(ospf_oi_count (ifp
) > 0))
2546 if (IS_INTER_AS (lp
->type
))
2548 vty_out (vty
, "-- Inter-AS TEv2 link parameters for %s --%s",
2549 ifp
->name
, VTY_NEWLINE
);
2553 /* MPLS-TE is not activate on this interface */
2554 /* or this interface is passive and Inter-AS TEv2 is not activate */
2555 vty_out (vty
, " %s: MPLS-TE is disabled on this interface%s",
2556 ifp
->name
, VTY_NEWLINE
);
2562 vty_out (vty
, "-- MPLS-TE link parameters for %s --%s",
2563 ifp
->name
, VTY_NEWLINE
);
2566 if (TLV_TYPE(lp
->link_type
) != 0)
2567 show_vty_link_subtlv_link_type (vty
, &lp
->link_type
.header
);
2568 if (TLV_TYPE(lp
->link_id
) != 0)
2569 show_vty_link_subtlv_link_id (vty
, &lp
->link_id
.header
);
2570 if (TLV_TYPE(lp
->lclif_ipaddr
) != 0)
2571 show_vty_link_subtlv_lclif_ipaddr (vty
, &lp
->lclif_ipaddr
.header
);
2572 if (TLV_TYPE(lp
->rmtif_ipaddr
) != 0)
2573 show_vty_link_subtlv_rmtif_ipaddr (vty
, &lp
->rmtif_ipaddr
.header
);
2574 if (TLV_TYPE(lp
->rip
) != 0)
2575 show_vty_link_subtlv_rip (vty
, &lp
->rip
.header
);
2576 if (TLV_TYPE(lp
->ras
) != 0)
2577 show_vty_link_subtlv_ras (vty
, &lp
->ras
.header
);
2578 if (TLV_TYPE(lp
->te_metric
) != 0)
2579 show_vty_link_subtlv_te_metric (vty
, &lp
->te_metric
.header
);
2580 if (TLV_TYPE(lp
->max_bw
) != 0)
2581 show_vty_link_subtlv_max_bw (vty
, &lp
->max_bw
.header
);
2582 if (TLV_TYPE(lp
->max_rsv_bw
) != 0)
2583 show_vty_link_subtlv_max_rsv_bw (vty
, &lp
->max_rsv_bw
.header
);
2584 if (TLV_TYPE(lp
->unrsv_bw
) != 0)
2585 show_vty_link_subtlv_unrsv_bw (vty
, &lp
->unrsv_bw
.header
);
2586 if (TLV_TYPE(lp
->rsc_clsclr
) != 0)
2587 show_vty_link_subtlv_rsc_clsclr (vty
, &lp
->rsc_clsclr
.header
);
2588 if (TLV_TYPE(lp
->av_delay
) != 0)
2589 show_vty_link_subtlv_av_delay (vty
, &lp
->av_delay
.header
);
2590 if (TLV_TYPE(lp
->mm_delay
) != 0)
2591 show_vty_link_subtlv_mm_delay (vty
, &lp
->mm_delay
.header
);
2592 if (TLV_TYPE(lp
->delay_var
) != 0)
2593 show_vty_link_subtlv_delay_var (vty
, &lp
->delay_var
.header
);
2594 if (TLV_TYPE(lp
->pkt_loss
) != 0)
2595 show_vty_link_subtlv_pkt_loss (vty
, &lp
->pkt_loss
.header
);
2596 if (TLV_TYPE(lp
->res_bw
) != 0)
2597 show_vty_link_subtlv_res_bw (vty
, &lp
->res_bw
.header
);
2598 if (TLV_TYPE(lp
->ava_bw
) != 0)
2599 show_vty_link_subtlv_ava_bw (vty
, &lp
->ava_bw
.header
);
2600 if (TLV_TYPE(lp
->use_bw
) != 0)
2601 show_vty_link_subtlv_use_bw (vty
, &lp
->use_bw
.header
);
2602 vty_out (vty
, "---------------%s%s", VTY_NEWLINE
, VTY_NEWLINE
);
2606 vty_out (vty
, " %s: MPLS-TE is disabled on this interface%s",
2607 ifp
->name
, VTY_NEWLINE
);
2613 DEFUN (show_ip_ospf_mpls_te_link
,
2614 show_ip_ospf_mpls_te_link_cmd
,
2615 "show ip ospf mpls-te interface [INTERFACE]",
2619 "MPLS-TE information\n"
2620 "Interface information\n"
2623 int idx_interface
= 5;
2624 struct interface
*ifp
;
2625 struct listnode
*node
, *nnode
;
2627 /* Show All Interfaces. */
2630 for (ALL_LIST_ELEMENTS (vrf_iflist (VRF_DEFAULT
), node
, nnode
, ifp
))
2631 show_mpls_te_link_sub (vty
, ifp
);
2633 /* Interface name is specified. */
2636 if ((ifp
= if_lookup_by_name (argv
[idx_interface
]->arg
)) == NULL
)
2637 vty_out (vty
, "No such interface name%s", VTY_NEWLINE
);
2639 show_mpls_te_link_sub (vty
, ifp
);
2646 ospf_mpls_te_register_vty (void)
2648 install_element (VIEW_NODE
, &show_ip_ospf_mpls_te_router_cmd
);
2649 install_element (VIEW_NODE
, &show_ip_ospf_mpls_te_link_cmd
);
2650 install_element (ENABLE_NODE
, &show_ip_ospf_mpls_te_router_cmd
);
2651 install_element (ENABLE_NODE
, &show_ip_ospf_mpls_te_link_cmd
);
2653 install_element (OSPF_NODE
, &ospf_mpls_te_on_cmd
);
2654 install_element (OSPF_NODE
, &no_ospf_mpls_te_cmd
);
2655 install_element (OSPF_NODE
, &ospf_mpls_te_router_addr_cmd
);
2656 install_element (OSPF_NODE
, &ospf_mpls_te_inter_as_cmd
);
2657 install_element (OSPF_NODE
, &ospf_mpls_te_inter_as_area_cmd
);
2658 install_element (OSPF_NODE
, &no_ospf_mpls_te_inter_as_cmd
);