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 along
22 * with this program; see the file COPYING; if not, write to the Free Software
23 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
26 /* Add support of RFC7471 */
27 /* 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
[] = {"Off", "AS", "Area"};
73 /*------------------------------------------------------------------------*
74 * Followings are initialize/terminate functions for MPLS-TE handling.
75 *------------------------------------------------------------------------*/
77 static int ospf_mpls_te_new_if(struct interface
*ifp
);
78 static int ospf_mpls_te_del_if(struct interface
*ifp
);
79 static void ospf_mpls_te_ism_change(struct ospf_interface
*oi
, int old_status
);
80 static void ospf_mpls_te_nsm_change(struct ospf_neighbor
*nbr
, int old_status
);
81 static void ospf_mpls_te_config_write_router(struct vty
*vty
);
82 static void ospf_mpls_te_show_info(struct vty
*vty
, struct ospf_lsa
*lsa
);
83 static int ospf_mpls_te_lsa_originate_area(void *arg
);
84 static int ospf_mpls_te_lsa_originate_as(void *arg
);
85 static struct ospf_lsa
*ospf_mpls_te_lsa_refresh(struct ospf_lsa
*lsa
);
87 static void del_mpls_te_link(void *val
);
88 static void ospf_mpls_te_register_vty(void);
90 int ospf_mpls_te_init(void)
94 rc
= ospf_register_opaque_functab(
95 OSPF_OPAQUE_AREA_LSA
, OPAQUE_TYPE_TRAFFIC_ENGINEERING_LSA
,
96 ospf_mpls_te_new_if
, ospf_mpls_te_del_if
,
97 ospf_mpls_te_ism_change
, ospf_mpls_te_nsm_change
,
98 ospf_mpls_te_config_write_router
,
99 NULL
, /*ospf_mpls_te_config_write_if */
100 NULL
, /* ospf_mpls_te_config_write_debug */
101 ospf_mpls_te_show_info
, ospf_mpls_te_lsa_originate_area
,
102 ospf_mpls_te_lsa_refresh
, NULL
, /* ospf_mpls_te_new_lsa_hook */
103 NULL
/* ospf_mpls_te_del_lsa_hook */);
106 "ospf_mpls_te_init: Failed to register Traffic Engineering functions");
110 memset(&OspfMplsTE
, 0, sizeof(struct ospf_mpls_te
));
111 OspfMplsTE
.enabled
= false;
112 OspfMplsTE
.inter_as
= Off
;
113 OspfMplsTE
.iflist
= list_new();
114 OspfMplsTE
.iflist
->del
= del_mpls_te_link
;
116 ospf_mpls_te_register_vty();
121 /* Additional register for RFC5392 support */
122 static int ospf_mpls_te_register(enum inter_as_mode mode
)
127 if (OspfMplsTE
.inter_as
!= Off
)
131 scope
= OSPF_OPAQUE_AS_LSA
;
133 scope
= OSPF_OPAQUE_AREA_LSA
;
135 rc
= ospf_register_opaque_functab(scope
, OPAQUE_TYPE_INTER_AS_LSA
, NULL
,
136 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
,
137 ospf_mpls_te_show_info
,
138 ospf_mpls_te_lsa_originate_as
,
139 ospf_mpls_te_lsa_refresh
, NULL
, NULL
);
143 "ospf_router_info_init: Failed to register Inter-AS functions");
150 static int ospf_mpls_te_unregister()
154 if (OspfMplsTE
.inter_as
== Off
)
157 if (OspfMplsTE
.inter_as
== AS
)
158 scope
= OSPF_OPAQUE_AS_LSA
;
160 scope
= OSPF_OPAQUE_AREA_LSA
;
162 ospf_delete_opaque_functab(scope
, OPAQUE_TYPE_INTER_AS_LSA
);
167 void ospf_mpls_te_term(void)
169 list_delete_and_null(&OspfMplsTE
.iflist
);
171 ospf_delete_opaque_functab(OSPF_OPAQUE_AREA_LSA
,
172 OPAQUE_TYPE_TRAFFIC_ENGINEERING_LSA
);
173 OspfMplsTE
.enabled
= false;
175 ospf_mpls_te_unregister();
176 OspfMplsTE
.inter_as
= Off
;
181 /*------------------------------------------------------------------------*
182 * Followings are control functions for MPLS-TE parameters management.
183 *------------------------------------------------------------------------*/
185 static void del_mpls_te_link(void *val
)
187 XFREE(MTYPE_OSPF_MPLS_TE
, val
);
191 static u_int32_t
get_mpls_te_instance_value(void)
193 static u_int32_t seqno
= 0;
195 if (seqno
< MAX_LEGAL_TE_INSTANCE_NUM
)
198 seqno
= 1; /* Avoid zero. */
203 static struct mpls_te_link
*lookup_linkparams_by_ifp(struct interface
*ifp
)
205 struct listnode
*node
, *nnode
;
206 struct mpls_te_link
*lp
;
208 for (ALL_LIST_ELEMENTS(OspfMplsTE
.iflist
, node
, nnode
, lp
))
215 static struct mpls_te_link
*lookup_linkparams_by_instance(struct ospf_lsa
*lsa
)
217 struct listnode
*node
;
218 struct mpls_te_link
*lp
;
219 unsigned int key
= GET_OPAQUE_ID(ntohl(lsa
->data
->id
.s_addr
));
221 for (ALL_LIST_ELEMENTS_RO(OspfMplsTE
.iflist
, node
, lp
))
222 if (lp
->instance
== key
)
225 zlog_warn("lookup_linkparams_by_instance: Entry not found: key(%x)",
230 static void ospf_mpls_te_foreach_area(void (*func
)(struct mpls_te_link
*lp
,
231 enum lsa_opcode sched_opcode
),
232 enum lsa_opcode sched_opcode
)
234 struct listnode
*node
, *nnode
;
235 struct listnode
*node2
;
236 struct mpls_te_link
*lp
;
237 struct ospf_area
*area
;
239 for (ALL_LIST_ELEMENTS(OspfMplsTE
.iflist
, node
, nnode
, lp
)) {
240 /* Skip Inter-AS TEv2 Links */
241 if (IS_INTER_AS(lp
->type
))
243 if ((area
= lp
->area
) == NULL
)
245 if (CHECK_FLAG(lp
->flags
, LPFLG_LOOKUP_DONE
))
249 (*func
)(lp
, sched_opcode
);
251 for (node2
= listnextnode(node
); node2
;
252 node2
= listnextnode(node2
))
253 if ((lp
= listgetdata(node2
)) != NULL
)
254 if (lp
->area
!= NULL
)
255 if (IPV4_ADDR_SAME(&lp
->area
->area_id
,
261 for (ALL_LIST_ELEMENTS_RO(OspfMplsTE
.iflist
, node
, lp
))
262 if (lp
->area
!= NULL
)
263 UNSET_FLAG(lp
->flags
, LPFLG_LOOKUP_DONE
);
268 static void set_mpls_te_router_addr(struct in_addr ipv4
)
270 OspfMplsTE
.router_addr
.header
.type
= htons(TE_TLV_ROUTER_ADDR
);
271 OspfMplsTE
.router_addr
.header
.length
= htons(TE_LINK_SUBTLV_DEF_SIZE
);
272 OspfMplsTE
.router_addr
.value
= ipv4
;
276 static void set_linkparams_link_header(struct mpls_te_link
*lp
)
278 u_int16_t length
= 0;
280 /* TE_LINK_SUBTLV_LINK_TYPE */
281 if (ntohs(lp
->link_type
.header
.type
) != 0)
282 length
+= TLV_SIZE(&lp
->link_type
.header
);
284 /* TE_LINK_SUBTLV_LINK_ID */
285 if (ntohs(lp
->link_id
.header
.type
) != 0)
286 length
+= TLV_SIZE(&lp
->link_id
.header
);
288 /* TE_LINK_SUBTLV_LCLIF_IPADDR */
289 if (lp
->lclif_ipaddr
.header
.type
!= 0)
290 length
+= TLV_SIZE(&lp
->lclif_ipaddr
.header
);
292 /* TE_LINK_SUBTLV_RMTIF_IPADDR */
293 if (lp
->rmtif_ipaddr
.header
.type
!= 0)
294 length
+= TLV_SIZE(&lp
->rmtif_ipaddr
.header
);
296 /* TE_LINK_SUBTLV_TE_METRIC */
297 if (ntohs(lp
->te_metric
.header
.type
) != 0)
298 length
+= TLV_SIZE(&lp
->te_metric
.header
);
300 /* TE_LINK_SUBTLV_MAX_BW */
301 if (ntohs(lp
->max_bw
.header
.type
) != 0)
302 length
+= TLV_SIZE(&lp
->max_bw
.header
);
304 /* TE_LINK_SUBTLV_MAX_RSV_BW */
305 if (ntohs(lp
->max_rsv_bw
.header
.type
) != 0)
306 length
+= TLV_SIZE(&lp
->max_rsv_bw
.header
);
308 /* TE_LINK_SUBTLV_UNRSV_BW */
309 if (ntohs(lp
->unrsv_bw
.header
.type
) != 0)
310 length
+= TLV_SIZE(&lp
->unrsv_bw
.header
);
312 /* TE_LINK_SUBTLV_RSC_CLSCLR */
313 if (ntohs(lp
->rsc_clsclr
.header
.type
) != 0)
314 length
+= TLV_SIZE(&lp
->rsc_clsclr
.header
);
316 /* TE_LINK_SUBTLV_LLRI */
317 if (ntohs(lp
->llri
.header
.type
) != 0)
318 length
+= TLV_SIZE(&lp
->llri
.header
);
320 /* TE_LINK_SUBTLV_RIP */
321 if (ntohs(lp
->rip
.header
.type
) != 0)
322 length
+= TLV_SIZE(&lp
->rip
.header
);
324 /* TE_LINK_SUBTLV_RAS */
325 if (ntohs(lp
->ras
.header
.type
) != 0)
326 length
+= TLV_SIZE(&lp
->ras
.header
);
328 /* TE_LINK_SUBTLV_LRRID */
329 if (ntohs(lp
->lrrid
.header
.type
) != 0)
330 length
+= TLV_SIZE(&lp
->lrrid
.header
);
332 /* TE_LINK_SUBTLV_AV_DELAY */
333 if (ntohs(lp
->av_delay
.header
.type
) != 0)
334 length
+= TLV_SIZE(&lp
->av_delay
.header
);
336 /* TE_LINK_SUBTLV_MM_DELAY */
337 if (ntohs(lp
->mm_delay
.header
.type
) != 0)
338 length
+= TLV_SIZE(&lp
->mm_delay
.header
);
340 /* TE_LINK_SUBTLV_DELAY_VAR */
341 if (ntohs(lp
->delay_var
.header
.type
) != 0)
342 length
+= TLV_SIZE(&lp
->delay_var
.header
);
344 /* TE_LINK_SUBTLV_PKT_LOSS */
345 if (ntohs(lp
->pkt_loss
.header
.type
) != 0)
346 length
+= TLV_SIZE(&lp
->pkt_loss
.header
);
348 /* TE_LINK_SUBTLV_RES_BW */
349 if (ntohs(lp
->res_bw
.header
.type
) != 0)
350 length
+= TLV_SIZE(&lp
->res_bw
.header
);
352 /* TE_LINK_SUBTLV_AVA_BW */
353 if (ntohs(lp
->ava_bw
.header
.type
) != 0)
354 length
+= TLV_SIZE(&lp
->ava_bw
.header
);
356 /* TE_LINK_SUBTLV_USE_BW */
357 if (ntohs(lp
->use_bw
.header
.type
) != 0)
358 length
+= TLV_SIZE(&lp
->use_bw
.header
);
360 lp
->link_header
.header
.type
= htons(TE_TLV_LINK
);
361 lp
->link_header
.header
.length
= htons(length
);
366 static void set_linkparams_link_type(struct ospf_interface
*oi
,
367 struct mpls_te_link
*lp
)
369 lp
->link_type
.header
.type
= htons(TE_LINK_SUBTLV_LINK_TYPE
);
370 lp
->link_type
.header
.length
= htons(TE_LINK_SUBTLV_TYPE_SIZE
);
373 case OSPF_IFTYPE_POINTOPOINT
:
374 lp
->link_type
.link_type
.value
= LINK_TYPE_SUBTLV_VALUE_PTP
;
376 case OSPF_IFTYPE_BROADCAST
:
377 case OSPF_IFTYPE_NBMA
:
378 lp
->link_type
.link_type
.value
= LINK_TYPE_SUBTLV_VALUE_MA
;
381 /* Not supported yet. */ /* XXX */
382 lp
->link_type
.header
.type
= htons(0);
388 static void set_linkparams_link_id(struct ospf_interface
*oi
,
389 struct mpls_te_link
*lp
)
391 struct ospf_neighbor
*nbr
;
394 lp
->link_id
.header
.type
= htons(TE_LINK_SUBTLV_LINK_ID
);
395 lp
->link_id
.header
.length
= htons(TE_LINK_SUBTLV_DEF_SIZE
);
398 * The Link ID is identical to the contents of the Link ID field
399 * in the Router LSA for these link types.
402 case OSPF_IFTYPE_POINTOPOINT
:
403 /* Take the router ID of the neighbor. */
404 if ((nbr
= ospf_nbr_lookup_ptop(oi
))
405 && nbr
->state
== NSM_Full
) {
406 lp
->link_id
.value
= nbr
->router_id
;
410 case OSPF_IFTYPE_BROADCAST
:
411 case OSPF_IFTYPE_NBMA
:
412 /* Take the interface address of the designated router. */
413 if ((nbr
= ospf_nbr_lookup_by_addr(oi
->nbrs
, &DR(oi
))) == NULL
)
416 if (nbr
->state
== NSM_Full
417 || (IPV4_ADDR_SAME(&oi
->address
->u
.prefix4
, &DR(oi
))
418 && ospf_nbr_count(oi
, NSM_Full
) > 0)) {
419 lp
->link_id
.value
= DR(oi
);
424 /* Not supported yet. */ /* XXX */
425 lp
->link_id
.header
.type
= htons(0);
431 masklen2ip(oi
->address
->prefixlen
, &mask
);
432 lp
->link_id
.value
.s_addr
=
433 oi
->address
->u
.prefix4
.s_addr
& mask
.s_addr
;
438 static void set_linkparams_lclif_ipaddr(struct mpls_te_link
*lp
,
439 struct in_addr lclif
)
442 lp
->lclif_ipaddr
.header
.type
= htons(TE_LINK_SUBTLV_LCLIF_IPADDR
);
443 lp
->lclif_ipaddr
.header
.length
= htons(TE_LINK_SUBTLV_DEF_SIZE
);
444 lp
->lclif_ipaddr
.value
[0] = lclif
;
448 static void set_linkparams_rmtif_ipaddr(struct mpls_te_link
*lp
,
449 struct in_addr rmtif
)
452 lp
->rmtif_ipaddr
.header
.type
= htons(TE_LINK_SUBTLV_RMTIF_IPADDR
);
453 lp
->rmtif_ipaddr
.header
.length
= htons(TE_LINK_SUBTLV_DEF_SIZE
);
454 lp
->rmtif_ipaddr
.value
[0] = rmtif
;
458 static void set_linkparams_te_metric(struct mpls_te_link
*lp
,
461 lp
->te_metric
.header
.type
= htons(TE_LINK_SUBTLV_TE_METRIC
);
462 lp
->te_metric
.header
.length
= htons(TE_LINK_SUBTLV_DEF_SIZE
);
463 lp
->te_metric
.value
= htonl(te_metric
);
467 static void set_linkparams_max_bw(struct mpls_te_link
*lp
, float fp
)
469 lp
->max_bw
.header
.type
= htons(TE_LINK_SUBTLV_MAX_BW
);
470 lp
->max_bw
.header
.length
= htons(TE_LINK_SUBTLV_DEF_SIZE
);
471 lp
->max_bw
.value
= htonf(fp
);
475 static void set_linkparams_max_rsv_bw(struct mpls_te_link
*lp
, float fp
)
477 lp
->max_rsv_bw
.header
.type
= htons(TE_LINK_SUBTLV_MAX_RSV_BW
);
478 lp
->max_rsv_bw
.header
.length
= htons(TE_LINK_SUBTLV_DEF_SIZE
);
479 lp
->max_rsv_bw
.value
= htonf(fp
);
483 static void set_linkparams_unrsv_bw(struct mpls_te_link
*lp
, int priority
,
486 /* Note that TLV-length field is the size of array. */
487 lp
->unrsv_bw
.header
.type
= htons(TE_LINK_SUBTLV_UNRSV_BW
);
488 lp
->unrsv_bw
.header
.length
= htons(TE_LINK_SUBTLV_UNRSV_SIZE
);
489 lp
->unrsv_bw
.value
[priority
] = htonf(fp
);
493 static void set_linkparams_rsc_clsclr(struct mpls_te_link
*lp
,
494 u_int32_t classcolor
)
496 lp
->rsc_clsclr
.header
.type
= htons(TE_LINK_SUBTLV_RSC_CLSCLR
);
497 lp
->rsc_clsclr
.header
.length
= htons(TE_LINK_SUBTLV_DEF_SIZE
);
498 lp
->rsc_clsclr
.value
= htonl(classcolor
);
502 static void set_linkparams_inter_as(struct mpls_te_link
*lp
,
503 struct in_addr addr
, u_int32_t as
)
506 /* Set the Remote ASBR IP address and then the associated AS number */
507 lp
->rip
.header
.type
= htons(TE_LINK_SUBTLV_RIP
);
508 lp
->rip
.header
.length
= htons(TE_LINK_SUBTLV_DEF_SIZE
);
509 lp
->rip
.value
= addr
;
511 lp
->ras
.header
.type
= htons(TE_LINK_SUBTLV_RAS
);
512 lp
->ras
.header
.length
= htons(TE_LINK_SUBTLV_DEF_SIZE
);
513 lp
->ras
.value
= htonl(as
);
516 static void unset_linkparams_inter_as(struct mpls_te_link
*lp
)
519 /* Reset the Remote ASBR IP address and then the associated AS number */
520 lp
->rip
.header
.type
= htons(0);
521 lp
->rip
.header
.length
= htons(0);
522 lp
->rip
.value
.s_addr
= htonl(0);
524 lp
->ras
.header
.type
= htons(0);
525 lp
->ras
.header
.length
= htons(0);
526 lp
->ras
.value
= htonl(0);
529 void set_linkparams_llri(struct mpls_te_link
*lp
, u_int32_t local
,
533 lp
->llri
.header
.type
= htons(TE_LINK_SUBTLV_LLRI
);
534 lp
->llri
.header
.length
= htons(TE_LINK_SUBTLV_LLRI_SIZE
);
535 lp
->llri
.local
= htonl(local
);
536 lp
->llri
.remote
= htonl(remote
);
539 void set_linkparams_lrrid(struct mpls_te_link
*lp
, struct in_addr local
,
540 struct in_addr remote
)
543 lp
->lrrid
.header
.type
= htons(TE_LINK_SUBTLV_LRRID
);
544 lp
->lrrid
.header
.length
= htons(TE_LINK_SUBTLV_LRRID_SIZE
);
545 lp
->lrrid
.local
.s_addr
= local
.s_addr
;
546 lp
->lrrid
.remote
.s_addr
= remote
.s_addr
;
549 static void set_linkparams_av_delay(struct mpls_te_link
*lp
, u_int32_t delay
,
553 /* Note that TLV-length field is the size of array. */
554 lp
->av_delay
.header
.type
= htons(TE_LINK_SUBTLV_AV_DELAY
);
555 lp
->av_delay
.header
.length
= htons(TE_LINK_SUBTLV_DEF_SIZE
);
556 tmp
= delay
& TE_EXT_MASK
;
558 tmp
|= TE_EXT_ANORMAL
;
559 lp
->av_delay
.value
= htonl(tmp
);
563 static void set_linkparams_mm_delay(struct mpls_te_link
*lp
, u_int32_t low
,
564 u_int32_t high
, u_char anormal
)
567 /* Note that TLV-length field is the size of array. */
568 lp
->mm_delay
.header
.type
= htons(TE_LINK_SUBTLV_MM_DELAY
);
569 lp
->mm_delay
.header
.length
= htons(TE_LINK_SUBTLV_MM_DELAY_SIZE
);
570 tmp
= low
& TE_EXT_MASK
;
572 tmp
|= TE_EXT_ANORMAL
;
573 lp
->mm_delay
.low
= htonl(tmp
);
574 lp
->mm_delay
.high
= htonl(high
);
578 static void set_linkparams_delay_var(struct mpls_te_link
*lp
, u_int32_t jitter
)
580 /* Note that TLV-length field is the size of array. */
581 lp
->delay_var
.header
.type
= htons(TE_LINK_SUBTLV_DELAY_VAR
);
582 lp
->delay_var
.header
.length
= htons(TE_LINK_SUBTLV_DEF_SIZE
);
583 lp
->delay_var
.value
= htonl(jitter
& TE_EXT_MASK
);
587 static void set_linkparams_pkt_loss(struct mpls_te_link
*lp
, u_int32_t loss
,
591 /* Note that TLV-length field is the size of array. */
592 lp
->pkt_loss
.header
.type
= htons(TE_LINK_SUBTLV_PKT_LOSS
);
593 lp
->pkt_loss
.header
.length
= htons(TE_LINK_SUBTLV_DEF_SIZE
);
594 tmp
= loss
& TE_EXT_MASK
;
596 tmp
|= TE_EXT_ANORMAL
;
597 lp
->pkt_loss
.value
= htonl(tmp
);
601 static void set_linkparams_res_bw(struct mpls_te_link
*lp
, float fp
)
603 /* Note that TLV-length field is the size of array. */
604 lp
->res_bw
.header
.type
= htons(TE_LINK_SUBTLV_RES_BW
);
605 lp
->res_bw
.header
.length
= htons(TE_LINK_SUBTLV_DEF_SIZE
);
606 lp
->res_bw
.value
= htonf(fp
);
610 static void set_linkparams_ava_bw(struct mpls_te_link
*lp
, float fp
)
612 /* Note that TLV-length field is the size of array. */
613 lp
->ava_bw
.header
.type
= htons(TE_LINK_SUBTLV_AVA_BW
);
614 lp
->ava_bw
.header
.length
= htons(TE_LINK_SUBTLV_DEF_SIZE
);
615 lp
->ava_bw
.value
= htonf(fp
);
619 static void set_linkparams_use_bw(struct mpls_te_link
*lp
, float fp
)
621 /* Note that TLV-length field is the size of array. */
622 lp
->use_bw
.header
.type
= htons(TE_LINK_SUBTLV_USE_BW
);
623 lp
->use_bw
.header
.length
= htons(TE_LINK_SUBTLV_DEF_SIZE
);
624 lp
->use_bw
.value
= htonf(fp
);
628 /* Update TE parameters from Interface */
629 static void update_linkparams(struct mpls_te_link
*lp
)
632 struct interface
*ifp
;
634 /* Get the Interface structure */
635 if ((ifp
= lp
->ifp
) == NULL
) {
636 if (IS_DEBUG_OSPF_TE
)
638 "OSPF MPLS-TE: Abort update TE parameters: no interface associated to Link Parameters");
641 if (!HAS_LINK_PARAMS(ifp
)) {
642 if (IS_DEBUG_OSPF_TE
)
644 "OSPF MPLS-TE: Abort update TE parameters: no Link Parameters for interface");
648 /* RFC3630 metrics */
649 if (IS_PARAM_SET(ifp
->link_params
, LP_ADM_GRP
))
650 set_linkparams_rsc_clsclr(lp
, ifp
->link_params
->admin_grp
);
652 TLV_TYPE(lp
->rsc_clsclr
) = 0;
654 if (IS_PARAM_SET(ifp
->link_params
, LP_MAX_BW
))
655 set_linkparams_max_bw(lp
, ifp
->link_params
->max_bw
);
657 TLV_TYPE(lp
->max_bw
) = 0;
659 if (IS_PARAM_SET(ifp
->link_params
, LP_MAX_RSV_BW
))
660 set_linkparams_max_rsv_bw(lp
, ifp
->link_params
->max_rsv_bw
);
662 TLV_TYPE(lp
->max_rsv_bw
) = 0;
664 if (IS_PARAM_SET(ifp
->link_params
, LP_UNRSV_BW
))
665 for (i
= 0; i
< MAX_CLASS_TYPE
; i
++)
666 set_linkparams_unrsv_bw(lp
, i
,
667 ifp
->link_params
->unrsv_bw
[i
]);
669 TLV_TYPE(lp
->unrsv_bw
) = 0;
671 if (IS_PARAM_SET(ifp
->link_params
, LP_TE_METRIC
))
672 set_linkparams_te_metric(lp
, ifp
->link_params
->te_metric
);
674 TLV_TYPE(lp
->te_metric
) = 0;
676 /* TE metric Extensions */
677 if (IS_PARAM_SET(ifp
->link_params
, LP_DELAY
))
678 set_linkparams_av_delay(lp
, ifp
->link_params
->av_delay
, 0);
680 TLV_TYPE(lp
->av_delay
) = 0;
682 if (IS_PARAM_SET(ifp
->link_params
, LP_MM_DELAY
))
683 set_linkparams_mm_delay(lp
, ifp
->link_params
->min_delay
,
684 ifp
->link_params
->max_delay
, 0);
686 TLV_TYPE(lp
->mm_delay
) = 0;
688 if (IS_PARAM_SET(ifp
->link_params
, LP_DELAY_VAR
))
689 set_linkparams_delay_var(lp
, ifp
->link_params
->delay_var
);
691 TLV_TYPE(lp
->delay_var
) = 0;
693 if (IS_PARAM_SET(ifp
->link_params
, LP_PKT_LOSS
))
694 set_linkparams_pkt_loss(lp
, ifp
->link_params
->pkt_loss
, 0);
696 TLV_TYPE(lp
->pkt_loss
) = 0;
698 if (IS_PARAM_SET(ifp
->link_params
, LP_RES_BW
))
699 set_linkparams_res_bw(lp
, ifp
->link_params
->res_bw
);
701 TLV_TYPE(lp
->res_bw
) = 0;
703 if (IS_PARAM_SET(ifp
->link_params
, LP_AVA_BW
))
704 set_linkparams_ava_bw(lp
, ifp
->link_params
->ava_bw
);
706 TLV_TYPE(lp
->ava_bw
) = 0;
708 if (IS_PARAM_SET(ifp
->link_params
, LP_USE_BW
))
709 set_linkparams_use_bw(lp
, ifp
->link_params
->use_bw
);
711 TLV_TYPE(lp
->use_bw
) = 0;
714 if (IS_PARAM_SET(ifp
->link_params
, LP_RMT_AS
)) {
715 /* Flush LSA if it engaged and was previously a STD_TE one */
716 if (IS_STD_TE(lp
->type
)
717 && CHECK_FLAG(lp
->flags
, LPFLG_LSA_ENGAGED
)) {
718 if (IS_DEBUG_OSPF_TE
)
720 "OSPF MPLS-TE Update IF: Switch from Standard LSA to INTER-AS for %s[%d/%d]",
721 ifp
->name
, lp
->flags
, lp
->type
);
723 ospf_mpls_te_lsa_schedule(lp
, FLUSH_THIS_LSA
);
724 /* Then, switch it to INTER-AS */
725 if (OspfMplsTE
.inter_as
== AS
)
726 lp
->flags
= INTER_AS
| FLOOD_AS
;
728 lp
->flags
= INTER_AS
| FLOOD_AREA
;
729 lp
->area
= ospf_area_lookup_by_area_id(
730 ospf_lookup_by_vrf_id(VRF_DEFAULT
),
731 OspfMplsTE
.interas_areaid
);
734 set_linkparams_inter_as(lp
, ifp
->link_params
->rmt_ip
,
735 ifp
->link_params
->rmt_as
);
737 if (IS_DEBUG_OSPF_TE
)
739 "OSPF MPLS-TE Update IF: Switch from INTER-AS LSA to Standard for %s[%d/%d]",
740 ifp
->name
, lp
->flags
, lp
->type
);
742 /* reset inter-as TE params */
743 /* Flush LSA if it engaged and was previously an INTER_AS one */
744 if (IS_INTER_AS(lp
->type
)
745 && CHECK_FLAG(lp
->flags
, LPFLG_LSA_ENGAGED
)) {
746 ospf_mpls_te_lsa_schedule(lp
, FLUSH_THIS_LSA
);
747 /* Then, switch it to Standard TE */
748 lp
->flags
= STD_TE
| FLOOD_AREA
;
750 unset_linkparams_inter_as(lp
);
754 static void initialize_linkparams(struct mpls_te_link
*lp
)
756 struct interface
*ifp
= lp
->ifp
;
757 struct ospf_interface
*oi
= NULL
;
758 struct route_node
*rn
;
760 if (IS_DEBUG_OSPF_TE
)
762 "MPLS-TE(initialize_linkparams) Initialize Link Parameters for interface %s",
765 /* Search OSPF Interface parameters for this interface */
766 for (rn
= route_top (IF_OIFS (ifp
)); rn
; rn
= route_next (rn
)) {
768 if ((oi
= rn
->info
) == NULL
)
775 if ((oi
== NULL
) || (oi
->ifp
!= ifp
)) {
776 if (IS_DEBUG_OSPF_TE
)
778 "MPLS-TE(initialize_linkparams) Could not find corresponding OSPF Interface for %s",
784 * Try to set initial values those can be derived from
785 * zebra-interface information.
787 set_linkparams_link_type(oi
, lp
);
789 /* Set local IP addr */
790 set_linkparams_lclif_ipaddr(lp
, oi
->address
->u
.prefix4
);
792 /* Set Remote IP addr if Point to Point Interface */
793 if (oi
->type
== OSPF_IFTYPE_POINTOPOINT
) {
794 struct prefix
*pref
= CONNECTED_PREFIX(oi
->connected
);
796 set_linkparams_rmtif_ipaddr(lp
, pref
->u
.prefix4
);
799 /* Keep Area information in combination with link parameters. */
805 static int is_mandated_params_set(struct mpls_te_link
*lp
)
809 if (ntohs(OspfMplsTE
.router_addr
.header
.type
) == 0) {
811 "MPLS-TE(is_mandated_params_set) Missing Router Address");
815 if (ntohs(lp
->link_type
.header
.type
) == 0) {
816 zlog_warn("MPLS-TE(is_mandated_params_set) Missing Link Type");
820 if (!IS_INTER_AS(lp
->type
) && (ntohs(lp
->link_id
.header
.type
) == 0)) {
821 zlog_warn("MPLS-TE(is_mandated_params_set) Missing Link ID");
829 /*------------------------------------------------------------------------*
830 * Followings are callback functions against generic Opaque-LSAs handling.
831 *------------------------------------------------------------------------*/
833 static int ospf_mpls_te_new_if(struct interface
*ifp
)
835 struct mpls_te_link
*new;
838 if (IS_DEBUG_OSPF_TE
)
840 "MPLS-TE(ospf_mpls_te_new_if) Add new %s interface %s to MPLS-TE list",
841 ifp
->link_params
? "Active" : "Inactive", ifp
->name
);
843 if (lookup_linkparams_by_ifp(ifp
) != NULL
) {
844 zlog_warn("ospf_mpls_te_new_if: ifp(%p) already in use?",
846 rc
= 0; /* Do nothing here. */
850 new = XCALLOC(MTYPE_OSPF_MPLS_TE
, sizeof(struct mpls_te_link
));
852 zlog_warn("ospf_mpls_te_new_if: XMALLOC: %s",
853 safe_strerror(errno
));
857 new->instance
= get_mpls_te_instance_value();
859 /* By default TE-Link is RFC3630 compatible flooding in Area and not
861 /* This default behavior will be adapted with call to
862 * ospf_mpls_te_update_if() */
863 new->type
= STD_TE
| FLOOD_AREA
;
864 new->flags
= LPFLG_LSA_INACTIVE
;
866 /* Initialize Link Parameters from Interface */
867 initialize_linkparams(new);
869 /* Set TE Parameters from Interface */
870 update_linkparams(new);
872 /* Add Link Parameters structure to the list */
873 listnode_add(OspfMplsTE
.iflist
, new);
875 if (IS_DEBUG_OSPF_TE
)
877 "OSPF MPLS-TE New IF: Add new LP context for %s[%d/%d]",
878 ifp
->name
, new->flags
, new->type
);
880 /* Schedule Opaque-LSA refresh. */ /* XXX */
886 static int ospf_mpls_te_del_if(struct interface
*ifp
)
888 struct mpls_te_link
*lp
;
891 if ((lp
= lookup_linkparams_by_ifp(ifp
)) != NULL
) {
892 struct list
*iflist
= OspfMplsTE
.iflist
;
894 /* Dequeue listnode entry from the list. */
895 listnode_delete(iflist
, lp
);
897 /* Avoid misjudgement in the next lookup. */
898 if (listcount(iflist
) == 0)
899 iflist
->head
= iflist
->tail
= NULL
;
901 XFREE(MTYPE_OSPF_MPLS_TE
, lp
);
904 /* Schedule Opaque-LSA refresh. */ /* XXX */
910 /* Main initialization / update function of the MPLS TE Link context */
912 /* Call when interface TE Link parameters are modified */
913 void ospf_mpls_te_update_if(struct interface
*ifp
)
915 struct mpls_te_link
*lp
;
917 if (IS_DEBUG_OSPF_TE
)
919 "OSPF MPLS-TE: Update LSA parameters for interface %s [%s]",
920 ifp
->name
, HAS_LINK_PARAMS(ifp
) ? "ON" : "OFF");
922 /* Get Link context from interface */
923 if ((lp
= lookup_linkparams_by_ifp(ifp
)) == NULL
) {
925 "OSPF MPLS-TE Update: Did not find Link Parameters context for interface %s",
930 /* Fulfill MPLS-TE Link TLV from Interface TE Link parameters */
931 if (HAS_LINK_PARAMS(ifp
)) {
932 SET_FLAG(lp
->flags
, LPFLG_LSA_ACTIVE
);
934 /* Update TE parameters */
935 update_linkparams(lp
);
937 /* Finally Re-Originate or Refresh Opaque LSA if MPLS_TE is
939 if (OspfMplsTE
.enabled
)
940 if (lp
->area
!= NULL
) {
941 if (CHECK_FLAG(lp
->flags
, LPFLG_LSA_ENGAGED
))
942 ospf_mpls_te_lsa_schedule(lp
, REFRESH_THIS_LSA
);
944 ospf_mpls_te_lsa_schedule(lp
, REORIGINATE_THIS_LSA
);
947 /* If MPLS TE is disable on this interface, flush LSA if it is
949 if (CHECK_FLAG(lp
->flags
, LPFLG_LSA_ENGAGED
))
950 ospf_mpls_te_lsa_schedule(lp
, FLUSH_THIS_LSA
);
952 /* Reset Activity flag */
953 lp
->flags
= LPFLG_LSA_INACTIVE
;
959 static void ospf_mpls_te_ism_change(struct ospf_interface
*oi
, int old_state
)
961 struct te_link_subtlv_link_type old_type
;
962 struct te_link_subtlv_link_id old_id
;
963 struct mpls_te_link
*lp
;
965 if ((lp
= lookup_linkparams_by_ifp(oi
->ifp
)) == NULL
) {
967 "ospf_mpls_te_ism_change: Cannot get linkparams from OI(%s)?",
972 if (oi
->area
== NULL
|| oi
->area
->ospf
== NULL
) {
974 "ospf_mpls_te_ism_change: Cannot refer to OSPF from OI(%s)?",
979 if ((lp
->area
!= NULL
980 && !IPV4_ADDR_SAME(&lp
->area
->area_id
, &oi
->area
->area_id
))
981 || (lp
->area
!= NULL
&& oi
->area
== NULL
)) {
982 /* How should we consider this case? */
984 "MPLS-TE: Area for OI(%s) has changed to [%s], flush previous LSAs",
986 oi
->area
? inet_ntoa(oi
->area
->area_id
) : "N/A");
987 ospf_mpls_te_lsa_schedule(lp
, FLUSH_THIS_LSA
);
990 /* Keep Area information in combination with linkparams. */
993 /* Keep interface MPLS-TE status */
994 lp
->flags
= HAS_LINK_PARAMS(oi
->ifp
);
997 case ISM_PointToPoint
:
1001 old_type
= lp
->link_type
;
1002 old_id
= lp
->link_id
;
1004 /* Set Link type, Link ID, Local and Remote IP addr */
1005 set_linkparams_link_type(oi
, lp
);
1006 set_linkparams_link_id(oi
, lp
);
1007 set_linkparams_lclif_ipaddr(lp
, oi
->address
->u
.prefix4
);
1009 if (oi
->type
== LINK_TYPE_SUBTLV_VALUE_PTP
) {
1010 struct prefix
*pref
= CONNECTED_PREFIX(oi
->connected
);
1012 set_linkparams_rmtif_ipaddr(lp
,
1016 /* Update TE parameters */
1017 update_linkparams(lp
);
1019 /* Try to Schedule LSA */
1020 if ((ntohs(old_type
.header
.type
)
1021 != ntohs(lp
->link_type
.header
.type
)
1022 || old_type
.link_type
.value
1023 != lp
->link_type
.link_type
.value
)
1024 || (ntohs(old_id
.header
.type
)
1025 != ntohs(lp
->link_id
.header
.type
)
1026 || ntohl(old_id
.value
.s_addr
)
1027 != ntohl(lp
->link_id
.value
.s_addr
))) {
1028 if (CHECK_FLAG(lp
->flags
, LPFLG_LSA_ENGAGED
))
1029 ospf_mpls_te_lsa_schedule(lp
, REFRESH_THIS_LSA
);
1031 ospf_mpls_te_lsa_schedule(lp
, REORIGINATE_THIS_LSA
);
1035 lp
->link_type
.header
.type
= htons(0);
1036 lp
->link_id
.header
.type
= htons(0);
1038 if (CHECK_FLAG(lp
->flags
, LPFLG_LSA_ENGAGED
))
1039 ospf_mpls_te_lsa_schedule(lp
, FLUSH_THIS_LSA
);
1046 static void ospf_mpls_te_nsm_change(struct ospf_neighbor
*nbr
, int old_state
)
1048 /* Nothing to do here */
1052 /*------------------------------------------------------------------------*
1053 * Followings are OSPF protocol processing functions for MPLS-TE.
1054 *------------------------------------------------------------------------*/
1056 static void build_tlv_header(struct stream
*s
, struct tlv_header
*tlvh
)
1058 stream_put(s
, tlvh
, sizeof(struct tlv_header
));
1062 static void build_router_tlv(struct stream
*s
)
1064 struct tlv_header
*tlvh
= &OspfMplsTE
.router_addr
.header
;
1065 if (ntohs(tlvh
->type
) != 0) {
1066 build_tlv_header(s
, tlvh
);
1067 stream_put(s
, TLV_DATA(tlvh
), TLV_BODY_SIZE(tlvh
));
1072 static void build_link_subtlv(struct stream
*s
, struct tlv_header
*tlvh
)
1075 if ((tlvh
!= NULL
) && (ntohs(tlvh
->type
) != 0)) {
1076 build_tlv_header(s
, tlvh
);
1077 stream_put(s
, TLV_DATA(tlvh
), TLV_BODY_SIZE(tlvh
));
1082 static void build_link_tlv(struct stream
*s
, struct mpls_te_link
*lp
)
1084 set_linkparams_link_header(lp
);
1085 build_tlv_header(s
, &lp
->link_header
.header
);
1087 build_link_subtlv(s
, &lp
->link_type
.header
);
1088 build_link_subtlv(s
, &lp
->link_id
.header
);
1089 build_link_subtlv(s
, &lp
->lclif_ipaddr
.header
);
1090 build_link_subtlv(s
, &lp
->rmtif_ipaddr
.header
);
1091 build_link_subtlv(s
, &lp
->te_metric
.header
);
1092 build_link_subtlv(s
, &lp
->max_bw
.header
);
1093 build_link_subtlv(s
, &lp
->max_rsv_bw
.header
);
1094 build_link_subtlv(s
, &lp
->unrsv_bw
.header
);
1095 build_link_subtlv(s
, &lp
->rsc_clsclr
.header
);
1096 build_link_subtlv(s
, &lp
->lrrid
.header
);
1097 build_link_subtlv(s
, &lp
->llri
.header
);
1098 build_link_subtlv(s
, &lp
->rip
.header
);
1099 build_link_subtlv(s
, &lp
->ras
.header
);
1100 build_link_subtlv(s
, &lp
->av_delay
.header
);
1101 build_link_subtlv(s
, &lp
->mm_delay
.header
);
1102 build_link_subtlv(s
, &lp
->delay_var
.header
);
1103 build_link_subtlv(s
, &lp
->pkt_loss
.header
);
1104 build_link_subtlv(s
, &lp
->res_bw
.header
);
1105 build_link_subtlv(s
, &lp
->ava_bw
.header
);
1106 build_link_subtlv(s
, &lp
->use_bw
.header
);
1111 static void ospf_mpls_te_lsa_body_set(struct stream
*s
, struct mpls_te_link
*lp
)
1114 * The router address TLV is type 1, and ...
1115 * It must appear in exactly one
1116 * Traffic Engineering LSA originated by a router.
1118 build_router_tlv(s
);
1121 * Only one Link TLV shall be carried in each LSA, allowing for fine
1122 * granularity changes in topology.
1124 build_link_tlv(s
, lp
);
1128 /* Create new opaque-LSA. */
1129 static struct ospf_lsa
*ospf_mpls_te_lsa_new(struct ospf
*ospf
,
1130 struct ospf_area
*area
,
1131 struct mpls_te_link
*lp
)
1134 struct lsa_header
*lsah
;
1135 struct ospf_lsa
*new = NULL
;
1136 u_char options
, lsa_type
= 0;
1137 struct in_addr lsa_id
;
1141 /* Create a stream for LSA. */
1142 if ((s
= stream_new(OSPF_MAX_LSA_SIZE
)) == NULL
) {
1143 zlog_warn("ospf_mpls_te_lsa_new: stream_new() ?");
1146 lsah
= (struct lsa_header
*)STREAM_DATA(s
);
1148 options
= OSPF_OPTION_O
; /* Don't forget this :-) */
1150 /* Set opaque-LSA header fields depending of the type of RFC */
1151 if (IS_INTER_AS(lp
->type
)) {
1153 IS_FLOOD_AS(lp
->type
)
1155 options
|= OSPF_OPTION_E
; /* Enable AS external
1159 lsa_type
= OSPF_OPAQUE_AS_LSA
;
1162 options
|= LSA_OPTIONS_GET(
1163 area
); /* Get area default option */
1164 options
|= LSA_OPTIONS_NSSA_GET(area
);
1165 lsa_type
= OSPF_OPAQUE_AREA_LSA
;
1167 tmp
= SET_OPAQUE_LSID(OPAQUE_TYPE_INTER_AS_LSA
, lp
->instance
);
1168 lsa_id
.s_addr
= htonl(tmp
);
1175 lsa_header_set(s
, options
, lsa_type
, lsa_id
, ospf
->router_id
);
1177 options
|= LSA_OPTIONS_GET(area
); /* Get area default option */
1178 options
|= LSA_OPTIONS_NSSA_GET(area
);
1179 lsa_type
= OSPF_OPAQUE_AREA_LSA
;
1180 tmp
= SET_OPAQUE_LSID(OPAQUE_TYPE_TRAFFIC_ENGINEERING_LSA
,
1182 lsa_id
.s_addr
= htonl(tmp
);
1183 lsa_header_set(s
, options
, lsa_type
, lsa_id
,
1184 area
->ospf
->router_id
);
1187 if (IS_DEBUG_OSPF(lsa
, LSA_GENERATE
))
1189 "LSA[Type%d:%s]: Create an Opaque-LSA/MPLS-TE instance",
1190 lsa_type
, inet_ntoa(lsa_id
));
1192 /* Set opaque-LSA body fields. */
1193 ospf_mpls_te_lsa_body_set(s
, lp
);
1196 length
= stream_get_endp(s
);
1197 lsah
->length
= htons(length
);
1199 /* Now, create an OSPF LSA instance. */
1200 if ((new = ospf_lsa_new()) == NULL
) {
1201 zlog_warn("ospf_mpls_te_lsa_new: ospf_lsa_new() ?");
1205 if ((new->data
= ospf_lsa_data_new(length
)) == NULL
) {
1206 zlog_warn("ospf_mpls_te_lsa_new: ospf_lsa_data_new() ?");
1207 ospf_lsa_unlock(&new);
1213 new->vrf_id
= ospf
->vrf_id
;
1214 if (area
&& area
->ospf
)
1215 new->vrf_id
= area
->ospf
->vrf_id
;
1217 SET_FLAG(new->flags
, OSPF_LSA_SELF
);
1218 memcpy(new->data
, lsah
, length
);
1224 static int ospf_mpls_te_lsa_originate1(struct ospf_area
*area
,
1225 struct mpls_te_link
*lp
)
1227 struct ospf_lsa
*new = NULL
;
1230 /* Create new Opaque-LSA/MPLS-TE instance. */
1231 new = ospf_mpls_te_lsa_new(area
->ospf
, area
, lp
);
1234 "ospf_mpls_te_lsa_originate1: ospf_mpls_te_lsa_new() ?");
1238 /* Install this LSA into LSDB. */
1239 if (ospf_lsa_install(area
->ospf
, NULL
/*oi*/, new) == NULL
) {
1240 zlog_warn("ospf_mpls_te_lsa_originate1: ospf_lsa_install() ?");
1241 ospf_lsa_unlock(&new);
1245 /* Now this link-parameter entry has associated LSA. */
1246 SET_FLAG(lp
->flags
, LPFLG_LSA_ENGAGED
);
1247 /* Update new LSA origination count. */
1248 area
->ospf
->lsa_originate_count
++;
1250 /* Flood new LSA through area. */
1251 ospf_flood_through_area(area
, NULL
/*nbr*/, new);
1253 if (IS_DEBUG_OSPF(lsa
, LSA_GENERATE
)) {
1254 char area_id
[INET_ADDRSTRLEN
];
1255 strlcpy(area_id
, inet_ntoa(area
->area_id
), sizeof(area_id
));
1257 "LSA[Type%d:%s]: Originate Opaque-LSA/MPLS-TE: Area(%s), Link(%s)",
1258 new->data
->type
, inet_ntoa(new->data
->id
), area_id
,
1260 ospf_lsa_header_dump(new->data
);
1267 static int ospf_mpls_te_lsa_originate_area(void *arg
)
1269 struct ospf_area
*area
= (struct ospf_area
*)arg
;
1270 struct listnode
*node
, *nnode
;
1271 struct mpls_te_link
*lp
;
1274 if (!OspfMplsTE
.enabled
) {
1276 "ospf_mpls_te_lsa_originate_area: MPLS-TE is disabled now.");
1277 rc
= 0; /* This is not an error case. */
1281 for (ALL_LIST_ELEMENTS(OspfMplsTE
.iflist
, node
, nnode
, lp
)) {
1282 /* Process only enabled LSA with area scope flooding */
1283 if (!CHECK_FLAG(lp
->flags
, LPFLG_LSA_ACTIVE
)
1284 || IS_FLOOD_AS(lp
->type
))
1287 if (lp
->area
== NULL
)
1290 if (!IPV4_ADDR_SAME(&lp
->area
->area_id
, &area
->area_id
))
1293 if (CHECK_FLAG(lp
->flags
, LPFLG_LSA_ENGAGED
)) {
1294 if (CHECK_FLAG(lp
->flags
, LPFLG_LSA_FORCED_REFRESH
)) {
1295 UNSET_FLAG(lp
->flags
, LPFLG_LSA_FORCED_REFRESH
);
1297 "OSPF MPLS-TE (ospf_mpls_te_lsa_originate_area): Refresh instead of Originate");
1298 ospf_mpls_te_lsa_schedule(lp
, REFRESH_THIS_LSA
);
1303 if (!is_mandated_params_set(lp
)) {
1305 "ospf_mpls_te_lsa_originate_area: Link(%s) lacks some mandated MPLS-TE parameters.",
1306 lp
->ifp
? lp
->ifp
->name
: "?");
1310 /* Ok, let's try to originate an LSA for this area and Link. */
1311 if (IS_DEBUG_OSPF_TE
)
1313 "MPLS-TE(ospf_mpls_te_lsa_originate_area) Let's finally reoriginate the LSA %d through the Area %s for Link %s",
1314 lp
->instance
, inet_ntoa(area
->area_id
),
1315 lp
->ifp
? lp
->ifp
->name
: "?");
1316 if (ospf_mpls_te_lsa_originate1(area
, lp
) != 0)
1324 static int ospf_mpls_te_lsa_originate2(struct ospf
*top
,
1325 struct mpls_te_link
*lp
)
1327 struct ospf_lsa
*new;
1330 /* Create new Opaque-LSA/Inter-AS instance. */
1331 new = ospf_mpls_te_lsa_new(top
, NULL
, lp
);
1334 "ospf_mpls_te_lsa_originate2: ospf_router_info_lsa_new() ?");
1337 new->vrf_id
= top
->vrf_id
;
1339 /* Install this LSA into LSDB. */
1340 if (ospf_lsa_install(top
, NULL
/*oi */, new) == NULL
) {
1341 zlog_warn("ospf_mpls_te_lsa_originate2: ospf_lsa_install() ?");
1342 ospf_lsa_unlock(&new);
1346 /* Now this Router Info parameter entry has associated LSA. */
1347 SET_FLAG(lp
->flags
, LPFLG_LSA_ENGAGED
);
1348 /* Update new LSA origination count. */
1349 top
->lsa_originate_count
++;
1351 /* Flood new LSA through AS. */
1352 ospf_flood_through_as(top
, NULL
/*nbr */, new);
1354 if (IS_DEBUG_OSPF(lsa
, LSA_GENERATE
)) {
1356 "LSA[Type%d:%s]: Originate Opaque-LSA/MPLS-TE Inter-AS",
1357 new->data
->type
, inet_ntoa(new->data
->id
));
1358 ospf_lsa_header_dump(new->data
);
1365 static int ospf_mpls_te_lsa_originate_as(void *arg
)
1368 struct ospf_area
*area
;
1369 struct listnode
*node
, *nnode
;
1370 struct mpls_te_link
*lp
;
1373 if ((!OspfMplsTE
.enabled
)
1374 || (OspfMplsTE
.inter_as
== Off
)) {
1376 "ospf_mpls_te_lsa_originate_as: MPLS-TE Inter-AS is disabled for now.");
1377 rc
= 0; /* This is not an error case. */
1381 for (ALL_LIST_ELEMENTS(OspfMplsTE
.iflist
, node
, nnode
, lp
)) {
1382 /* Process only enabled INTER_AS Links or Pseudo-Links */
1383 if (!CHECK_FLAG(lp
->flags
, LPFLG_LSA_ACTIVE
)
1384 || !IS_INTER_AS(lp
->type
))
1387 if (CHECK_FLAG(lp
->flags
, LPFLG_LSA_ENGAGED
)) {
1388 if (CHECK_FLAG(lp
->flags
, LPFLG_LSA_FORCED_REFRESH
)) {
1389 UNSET_FLAG(lp
->flags
,LPFLG_LSA_FORCED_REFRESH
);
1390 ospf_mpls_te_lsa_schedule(lp
, REFRESH_THIS_LSA
);
1395 if (!is_mandated_params_set(lp
)) {
1397 "ospf_mpls_te_lsa_originate_as: Link(%s) lacks some mandated MPLS-TE parameters.",
1398 lp
->ifp
? lp
->ifp
->name
: "?");
1402 /* Ok, let's try to originate an LSA for this AS and Link. */
1403 if (IS_DEBUG_OSPF_TE
)
1405 "MPLS-TE(ospf_mpls_te_lsa_originate_as) Let's finally re-originate the Inter-AS LSA %d through the %s for Link %s",
1407 IS_FLOOD_AS(lp
->type
) ? "AS" : "Area",
1408 lp
->ifp
? lp
->ifp
->name
: "Unknown");
1410 if (IS_FLOOD_AS(lp
->type
)) {
1411 top
= (struct ospf
*)arg
;
1412 ospf_mpls_te_lsa_originate2(top
, lp
);
1414 area
= (struct ospf_area
*)arg
;
1415 ospf_mpls_te_lsa_originate1(area
, lp
);
1423 static struct ospf_lsa
*ospf_mpls_te_lsa_refresh(struct ospf_lsa
*lsa
)
1425 struct mpls_te_link
*lp
;
1426 struct ospf_area
*area
= lsa
->area
;
1428 struct ospf_lsa
*new = NULL
;
1430 if (!OspfMplsTE
.enabled
) {
1432 * This LSA must have flushed before due to MPLS-TE status
1434 * It seems a slip among routers in the routing domain.
1436 zlog_info("ospf_mpls_te_lsa_refresh: MPLS-TE is disabled now.");
1438 htons(OSPF_LSA_MAXAGE
); /* Flush it anyway. */
1441 /* At first, resolve lsa/lp relationship. */
1442 if ((lp
= lookup_linkparams_by_instance(lsa
)) == NULL
) {
1443 zlog_warn("ospf_mpls_te_lsa_refresh: Invalid parameter?");
1445 htons(OSPF_LSA_MAXAGE
); /* Flush it anyway. */
1448 /* Check if lp was not disable in the interval */
1449 if (!CHECK_FLAG(lp
->flags
, LPFLG_LSA_ACTIVE
)) {
1451 "ospf_mpls_te_lsa_refresh: lp was disabled: Flush it!");
1453 htons(OSPF_LSA_MAXAGE
); /* Flush it anyway. */
1456 /* If the lsa's age reached to MaxAge, start flushing procedure. */
1457 if (IS_LSA_MAXAGE(lsa
)) {
1459 UNSET_FLAG(lp
->flags
, LPFLG_LSA_ENGAGED
);
1460 ospf_opaque_lsa_flush_schedule(lsa
);
1463 top
= ospf_lookup_by_vrf_id(lsa
->vrf_id
);
1464 /* Create new Opaque-LSA/MPLS-TE instance. */
1465 new = ospf_mpls_te_lsa_new(top
, area
, lp
);
1467 zlog_warn("ospf_mpls_te_lsa_refresh: ospf_mpls_te_lsa_new() ?");
1470 new->data
->ls_seqnum
= lsa_seqnum_increment(lsa
);
1472 /* Install this LSA into LSDB. */
1473 /* Given "lsa" will be freed in the next function. */
1474 /* As area could be NULL i.e. when using OPAQUE_LSA_AS, we prefer to use
1475 * ospf_lookup() to get ospf instance */
1479 if (ospf_lsa_install(top
, NULL
/*oi */, new) == NULL
) {
1480 zlog_warn("ospf_mpls_te_lsa_refresh: ospf_lsa_install() ?");
1481 ospf_lsa_unlock(&new);
1485 /* Flood updated LSA through AS or Area depending of the RFC of the link
1487 if (IS_FLOOD_AS(lp
->type
))
1488 ospf_flood_through_as(top
, NULL
, new);
1490 ospf_flood_through_area(area
, NULL
/*nbr*/, new);
1492 /* Debug logging. */
1493 if (IS_DEBUG_OSPF(lsa
, LSA_GENERATE
)) {
1494 zlog_debug("LSA[Type%d:%s]: Refresh Opaque-LSA/MPLS-TE",
1495 new->data
->type
, inet_ntoa(new->data
->id
));
1496 ospf_lsa_header_dump(new->data
);
1502 void ospf_mpls_te_lsa_schedule(struct mpls_te_link
*lp
, enum lsa_opcode opcode
)
1504 struct ospf_lsa lsa
;
1505 struct lsa_header lsah
;
1509 memset(&lsa
, 0, sizeof(lsa
));
1510 memset(&lsah
, 0, sizeof(lsah
));
1511 top
= ospf_lookup_by_vrf_id(VRF_DEFAULT
);
1513 /* Check if the pseudo link is ready to flood */
1514 if (!(CHECK_FLAG(lp
->flags
, LPFLG_LSA_ACTIVE
))
1515 || !(IS_FLOOD_AREA(lp
->type
) || IS_FLOOD_AS(lp
->type
))) {
1519 lsa
.area
= lp
->area
;
1521 if (IS_FLOOD_AS(lp
->type
)) {
1522 lsah
.type
= OSPF_OPAQUE_AS_LSA
;
1523 tmp
= SET_OPAQUE_LSID(OPAQUE_TYPE_INTER_AS_LSA
, lp
->instance
);
1524 lsah
.id
.s_addr
= htonl(tmp
);
1526 lsah
.type
= OSPF_OPAQUE_AREA_LSA
;
1527 if (IS_INTER_AS(lp
->type
)) {
1528 /* Set the area context if not know */
1529 if (lp
->area
== NULL
)
1530 lp
->area
= ospf_area_lookup_by_area_id(
1531 top
, OspfMplsTE
.interas_areaid
);
1532 /* Unable to set the area context. Abort! */
1533 if (lp
->area
== NULL
) {
1535 "MPLS-TE(ospf_mpls_te_lsa_schedule) Area context is null. Abort !");
1538 tmp
= SET_OPAQUE_LSID(OPAQUE_TYPE_INTER_AS_LSA
,
1541 tmp
= SET_OPAQUE_LSID(
1542 OPAQUE_TYPE_TRAFFIC_ENGINEERING_LSA
,
1544 lsah
.id
.s_addr
= htonl(tmp
);
1548 case REORIGINATE_THIS_LSA
:
1549 if (IS_FLOOD_AS(lp
->type
)) {
1550 ospf_opaque_lsa_reoriginate_schedule(
1551 (void *)top
, OSPF_OPAQUE_AS_LSA
,
1552 OPAQUE_TYPE_INTER_AS_LSA
);
1556 if (IS_FLOOD_AREA(lp
->type
)) {
1557 if (IS_INTER_AS(lp
->type
))
1558 ospf_opaque_lsa_reoriginate_schedule(
1559 (void *)lp
->area
, OSPF_OPAQUE_AREA_LSA
,
1560 OPAQUE_TYPE_INTER_AS_LSA
);
1562 ospf_opaque_lsa_reoriginate_schedule(
1563 (void *)lp
->area
, OSPF_OPAQUE_AREA_LSA
,
1564 OPAQUE_TYPE_TRAFFIC_ENGINEERING_LSA
);
1568 case REFRESH_THIS_LSA
:
1569 ospf_opaque_lsa_refresh_schedule(&lsa
);
1571 case FLUSH_THIS_LSA
:
1572 /* Reset Activity flag */
1573 lp
->flags
= LPFLG_LSA_INACTIVE
;
1574 ospf_opaque_lsa_flush_schedule(&lsa
);
1577 zlog_warn("ospf_mpls_te_lsa_schedule: Unknown opcode (%u)",
1586 /*------------------------------------------------------------------------*
1587 * Followings are vty session control functions.
1588 *------------------------------------------------------------------------*/
1590 static u_int16_t
show_vty_router_addr(struct vty
*vty
,
1591 struct tlv_header
*tlvh
)
1593 struct te_tlv_router_addr
*top
= (struct te_tlv_router_addr
*)tlvh
;
1596 vty_out(vty
, " Router-Address: %s\n", inet_ntoa(top
->value
));
1598 zlog_debug(" Router-Address: %s", inet_ntoa(top
->value
));
1600 return TLV_SIZE(tlvh
);
1603 static u_int16_t
show_vty_link_header(struct vty
*vty
,
1604 struct tlv_header
*tlvh
)
1606 struct te_tlv_link
*top
= (struct te_tlv_link
*)tlvh
;
1609 vty_out(vty
, " Link: %u octets of data\n",
1610 ntohs(top
->header
.length
));
1612 zlog_debug(" Link: %u octets of data",
1613 ntohs(top
->header
.length
));
1615 return TLV_HDR_SIZE
; /* Here is special, not "TLV_SIZE". */
1618 static u_int16_t
show_vty_link_subtlv_link_type(struct vty
*vty
,
1619 struct tlv_header
*tlvh
)
1621 struct te_link_subtlv_link_type
*top
;
1622 const char *cp
= "Unknown";
1624 top
= (struct te_link_subtlv_link_type
*)tlvh
;
1625 switch (top
->link_type
.value
) {
1626 case LINK_TYPE_SUBTLV_VALUE_PTP
:
1627 cp
= "Point-to-point";
1629 case LINK_TYPE_SUBTLV_VALUE_MA
:
1637 vty_out(vty
, " Link-Type: %s (%u)\n", cp
,
1638 top
->link_type
.value
);
1640 zlog_debug(" Link-Type: %s (%u)", cp
, top
->link_type
.value
);
1642 return TLV_SIZE(tlvh
);
1645 static u_int16_t
show_vty_link_subtlv_link_id(struct vty
*vty
,
1646 struct tlv_header
*tlvh
)
1648 struct te_link_subtlv_link_id
*top
;
1650 top
= (struct te_link_subtlv_link_id
*)tlvh
;
1652 vty_out(vty
, " Link-ID: %s\n", inet_ntoa(top
->value
));
1654 zlog_debug(" Link-ID: %s", inet_ntoa(top
->value
));
1656 return TLV_SIZE(tlvh
);
1659 static u_int16_t
show_vty_link_subtlv_lclif_ipaddr(struct vty
*vty
,
1660 struct tlv_header
*tlvh
)
1662 struct te_link_subtlv_lclif_ipaddr
*top
;
1665 top
= (struct te_link_subtlv_lclif_ipaddr
*)tlvh
;
1666 n
= ntohs(tlvh
->length
) / sizeof(top
->value
[0]);
1669 vty_out(vty
, " Local Interface IP Address(es): %d\n", n
);
1671 zlog_debug(" Local Interface IP Address(es): %d", n
);
1673 for (i
= 0; i
< n
; i
++) {
1675 vty_out(vty
, " #%d: %s\n", i
,
1676 inet_ntoa(top
->value
[i
]));
1678 zlog_debug(" #%d: %s", i
,
1679 inet_ntoa(top
->value
[i
]));
1681 return TLV_SIZE(tlvh
);
1684 static u_int16_t
show_vty_link_subtlv_rmtif_ipaddr(struct vty
*vty
,
1685 struct tlv_header
*tlvh
)
1687 struct te_link_subtlv_rmtif_ipaddr
*top
;
1690 top
= (struct te_link_subtlv_rmtif_ipaddr
*)tlvh
;
1691 n
= ntohs(tlvh
->length
) / sizeof(top
->value
[0]);
1693 vty_out(vty
, " Remote Interface IP Address(es): %d\n", n
);
1695 zlog_debug(" Remote Interface IP Address(es): %d", n
);
1697 for (i
= 0; i
< n
; i
++) {
1699 vty_out(vty
, " #%d: %s\n", i
,
1700 inet_ntoa(top
->value
[i
]));
1702 zlog_debug(" #%d: %s", i
,
1703 inet_ntoa(top
->value
[i
]));
1705 return TLV_SIZE(tlvh
);
1708 static u_int16_t
show_vty_link_subtlv_te_metric(struct vty
*vty
,
1709 struct tlv_header
*tlvh
)
1711 struct te_link_subtlv_te_metric
*top
;
1713 top
= (struct te_link_subtlv_te_metric
*)tlvh
;
1715 vty_out(vty
, " Traffic Engineering Metric: %u\n",
1716 (u_int32_t
)ntohl(top
->value
));
1718 zlog_debug(" Traffic Engineering Metric: %u",
1719 (u_int32_t
)ntohl(top
->value
));
1721 return TLV_SIZE(tlvh
);
1724 static u_int16_t
show_vty_link_subtlv_max_bw(struct vty
*vty
,
1725 struct tlv_header
*tlvh
)
1727 struct te_link_subtlv_max_bw
*top
;
1730 top
= (struct te_link_subtlv_max_bw
*)tlvh
;
1731 fval
= ntohf(top
->value
);
1734 vty_out(vty
, " Maximum Bandwidth: %g (Bytes/sec)\n", fval
);
1736 zlog_debug(" Maximum Bandwidth: %g (Bytes/sec)", fval
);
1738 return TLV_SIZE(tlvh
);
1741 static u_int16_t
show_vty_link_subtlv_max_rsv_bw(struct vty
*vty
,
1742 struct tlv_header
*tlvh
)
1744 struct te_link_subtlv_max_rsv_bw
*top
;
1747 top
= (struct te_link_subtlv_max_rsv_bw
*)tlvh
;
1748 fval
= ntohf(top
->value
);
1751 vty_out(vty
, " Maximum Reservable Bandwidth: %g (Bytes/sec)\n",
1754 zlog_debug(" Maximum Reservable Bandwidth: %g (Bytes/sec)",
1757 return TLV_SIZE(tlvh
);
1760 static u_int16_t
show_vty_link_subtlv_unrsv_bw(struct vty
*vty
,
1761 struct tlv_header
*tlvh
)
1763 struct te_link_subtlv_unrsv_bw
*top
;
1767 top
= (struct te_link_subtlv_unrsv_bw
*)tlvh
;
1770 " Unreserved Bandwidth per Class Type in Byte/s:\n");
1773 " Unreserved Bandwidth per Class Type in Byte/s:");
1774 for (i
= 0; i
< MAX_CLASS_TYPE
; i
+= 2) {
1775 fval1
= ntohf(top
->value
[i
]);
1776 fval2
= ntohf(top
->value
[i
+ 1]);
1780 " [%d]: %g (Bytes/sec),\t[%d]: %g (Bytes/sec)\n",
1781 i
, fval1
, i
+ 1, fval2
);
1784 " [%d]: %g (Bytes/sec),\t[%d]: %g (Bytes/sec)",
1785 i
, fval1
, i
+ 1, fval2
);
1788 return TLV_SIZE(tlvh
);
1791 static u_int16_t
show_vty_link_subtlv_rsc_clsclr(struct vty
*vty
,
1792 struct tlv_header
*tlvh
)
1794 struct te_link_subtlv_rsc_clsclr
*top
;
1796 top
= (struct te_link_subtlv_rsc_clsclr
*)tlvh
;
1798 vty_out(vty
, " Resource class/color: 0x%x\n",
1799 (u_int32_t
)ntohl(top
->value
));
1801 zlog_debug(" Resource Class/Color: 0x%x",
1802 (u_int32_t
)ntohl(top
->value
));
1804 return TLV_SIZE(tlvh
);
1807 static u_int16_t
show_vty_link_subtlv_lrrid(struct vty
*vty
,
1808 struct tlv_header
*tlvh
)
1810 struct te_link_subtlv_lrrid
*top
;
1812 top
= (struct te_link_subtlv_lrrid
*)tlvh
;
1815 vty_out(vty
, " Local TE Router ID: %s\n",
1816 inet_ntoa(top
->local
));
1817 vty_out(vty
, " Remote TE Router ID: %s\n",
1818 inet_ntoa(top
->remote
));
1820 zlog_debug(" Local TE Router ID: %s",
1821 inet_ntoa(top
->local
));
1822 zlog_debug(" Remote TE Router ID: %s",
1823 inet_ntoa(top
->remote
));
1826 return TLV_SIZE(tlvh
);
1829 static u_int16_t
show_vty_link_subtlv_llri(struct vty
*vty
,
1830 struct tlv_header
*tlvh
)
1832 struct te_link_subtlv_llri
*top
;
1834 top
= (struct te_link_subtlv_llri
*)tlvh
;
1837 vty_out(vty
, " Link Local ID: %d\n",
1838 (u_int32_t
)ntohl(top
->local
));
1839 vty_out(vty
, " Link Remote ID: %d\n",
1840 (u_int32_t
)ntohl(top
->remote
));
1842 zlog_debug(" Link Local ID: %d",
1843 (u_int32_t
)ntohl(top
->local
));
1844 zlog_debug(" Link Remote ID: %d",
1845 (u_int32_t
)ntohl(top
->remote
));
1848 return TLV_SIZE(tlvh
);
1851 static u_int16_t
show_vty_link_subtlv_rip(struct vty
*vty
,
1852 struct tlv_header
*tlvh
)
1854 struct te_link_subtlv_rip
*top
;
1856 top
= (struct te_link_subtlv_rip
*)tlvh
;
1859 vty_out(vty
, " Inter-AS TE Remote ASBR IP address: %s\n",
1860 inet_ntoa(top
->value
));
1862 zlog_debug(" Inter-AS TE Remote ASBR IP address: %s",
1863 inet_ntoa(top
->value
));
1865 return TLV_SIZE(tlvh
);
1868 static u_int16_t
show_vty_link_subtlv_ras(struct vty
*vty
,
1869 struct tlv_header
*tlvh
)
1871 struct te_link_subtlv_ras
*top
;
1873 top
= (struct te_link_subtlv_ras
*)tlvh
;
1876 vty_out(vty
, " Inter-AS TE Remote AS number: %u\n",
1879 zlog_debug(" Inter-AS TE Remote AS number: %u",
1882 return TLV_SIZE(tlvh
);
1885 static u_int16_t
show_vty_link_subtlv_av_delay(struct vty
*vty
,
1886 struct tlv_header
*tlvh
)
1888 struct te_link_subtlv_av_delay
*top
;
1890 u_int32_t anomalous
;
1892 top
= (struct te_link_subtlv_av_delay
*)tlvh
;
1893 delay
= (u_int32_t
)ntohl(top
->value
) & TE_EXT_MASK
;
1894 anomalous
= (u_int32_t
)ntohl(top
->value
) & TE_EXT_ANORMAL
;
1897 vty_out(vty
, " %s Average Link Delay: %d (micro-sec)\n",
1898 anomalous
? "Anomalous" : "Normal", delay
);
1900 zlog_debug(" %s Average Link Delay: %d (micro-sec)",
1901 anomalous
? "Anomalous" : "Normal", delay
);
1903 return TLV_SIZE(tlvh
);
1906 static u_int16_t
show_vty_link_subtlv_mm_delay(struct vty
*vty
,
1907 struct tlv_header
*tlvh
)
1909 struct te_link_subtlv_mm_delay
*top
;
1910 u_int32_t low
, high
;
1911 u_int32_t anomalous
;
1913 top
= (struct te_link_subtlv_mm_delay
*)tlvh
;
1914 low
= (u_int32_t
)ntohl(top
->low
) & TE_EXT_MASK
;
1915 anomalous
= (u_int32_t
)ntohl(top
->low
) & TE_EXT_ANORMAL
;
1916 high
= (u_int32_t
)ntohl(top
->high
);
1919 vty_out(vty
, " %s Min/Max Link Delay: %d/%d (micro-sec)\n",
1920 anomalous
? "Anomalous" : "Normal", low
, high
);
1922 zlog_debug(" %s Min/Max Link Delay: %d/%d (micro-sec)",
1923 anomalous
? "Anomalous" : "Normal", low
, high
);
1925 return TLV_SIZE(tlvh
);
1928 static u_int16_t
show_vty_link_subtlv_delay_var(struct vty
*vty
,
1929 struct tlv_header
*tlvh
)
1931 struct te_link_subtlv_delay_var
*top
;
1934 top
= (struct te_link_subtlv_delay_var
*)tlvh
;
1935 jitter
= (u_int32_t
)ntohl(top
->value
) & TE_EXT_MASK
;
1938 vty_out(vty
, " Delay Variation: %d (micro-sec)\n", jitter
);
1940 zlog_debug(" Delay Variation: %d (micro-sec)", jitter
);
1942 return TLV_SIZE(tlvh
);
1945 static u_int16_t
show_vty_link_subtlv_pkt_loss(struct vty
*vty
,
1946 struct tlv_header
*tlvh
)
1948 struct te_link_subtlv_pkt_loss
*top
;
1950 u_int32_t anomalous
;
1953 top
= (struct te_link_subtlv_pkt_loss
*)tlvh
;
1954 loss
= (u_int32_t
)ntohl(top
->value
) & TE_EXT_MASK
;
1955 fval
= (float)(loss
* LOSS_PRECISION
);
1956 anomalous
= (u_int32_t
)ntohl(top
->value
) & TE_EXT_ANORMAL
;
1959 vty_out(vty
, " %s Link Loss: %g (%%)\n",
1960 anomalous
? "Anomalous" : "Normal", fval
);
1962 zlog_debug(" %s Link Loss: %g (%%)",
1963 anomalous
? "Anomalous" : "Normal", fval
);
1965 return TLV_SIZE(tlvh
);
1968 static u_int16_t
show_vty_link_subtlv_res_bw(struct vty
*vty
,
1969 struct tlv_header
*tlvh
)
1971 struct te_link_subtlv_res_bw
*top
;
1974 top
= (struct te_link_subtlv_res_bw
*)tlvh
;
1975 fval
= ntohf(top
->value
);
1979 " Unidirectional Residual Bandwidth: %g (Bytes/sec)\n",
1983 " Unidirectional Residual Bandwidth: %g (Bytes/sec)",
1986 return TLV_SIZE(tlvh
);
1989 static u_int16_t
show_vty_link_subtlv_ava_bw(struct vty
*vty
,
1990 struct tlv_header
*tlvh
)
1992 struct te_link_subtlv_ava_bw
*top
;
1995 top
= (struct te_link_subtlv_ava_bw
*)tlvh
;
1996 fval
= ntohf(top
->value
);
2000 " Unidirectional Available Bandwidth: %g (Bytes/sec)\n",
2004 " Unidirectional Available Bandwidth: %g (Bytes/sec)",
2007 return TLV_SIZE(tlvh
);
2010 static u_int16_t
show_vty_link_subtlv_use_bw(struct vty
*vty
,
2011 struct tlv_header
*tlvh
)
2013 struct te_link_subtlv_use_bw
*top
;
2016 top
= (struct te_link_subtlv_use_bw
*)tlvh
;
2017 fval
= ntohf(top
->value
);
2021 " Unidirectional Utilized Bandwidth: %g (Bytes/sec)\n",
2025 " Unidirectional Utilized Bandwidth: %g (Bytes/sec)",
2028 return TLV_SIZE(tlvh
);
2031 static u_int16_t
show_vty_unknown_tlv(struct vty
*vty
,
2032 struct tlv_header
*tlvh
)
2035 vty_out(vty
, " Unknown TLV: [type(0x%x), length(0x%x)]\n",
2036 ntohs(tlvh
->type
), ntohs(tlvh
->length
));
2038 zlog_debug(" Unknown TLV: [type(0x%x), length(0x%x)]",
2039 ntohs(tlvh
->type
), ntohs(tlvh
->length
));
2041 return TLV_SIZE(tlvh
);
2044 static u_int16_t
ospf_mpls_te_show_link_subtlv(struct vty
*vty
,
2045 struct tlv_header
*tlvh0
,
2049 struct tlv_header
*tlvh
, *next
;
2050 u_int16_t sum
= subtotal
;
2052 for (tlvh
= tlvh0
; sum
< total
;
2053 tlvh
= (next
? next
: TLV_HDR_NEXT(tlvh
))) {
2055 switch (ntohs(tlvh
->type
)) {
2056 case TE_LINK_SUBTLV_LINK_TYPE
:
2057 sum
+= show_vty_link_subtlv_link_type(vty
, tlvh
);
2059 case TE_LINK_SUBTLV_LINK_ID
:
2060 sum
+= show_vty_link_subtlv_link_id(vty
, tlvh
);
2062 case TE_LINK_SUBTLV_LCLIF_IPADDR
:
2063 sum
+= show_vty_link_subtlv_lclif_ipaddr(vty
, tlvh
);
2065 case TE_LINK_SUBTLV_RMTIF_IPADDR
:
2066 sum
+= show_vty_link_subtlv_rmtif_ipaddr(vty
, tlvh
);
2068 case TE_LINK_SUBTLV_TE_METRIC
:
2069 sum
+= show_vty_link_subtlv_te_metric(vty
, tlvh
);
2071 case TE_LINK_SUBTLV_MAX_BW
:
2072 sum
+= show_vty_link_subtlv_max_bw(vty
, tlvh
);
2074 case TE_LINK_SUBTLV_MAX_RSV_BW
:
2075 sum
+= show_vty_link_subtlv_max_rsv_bw(vty
, tlvh
);
2077 case TE_LINK_SUBTLV_UNRSV_BW
:
2078 sum
+= show_vty_link_subtlv_unrsv_bw(vty
, tlvh
);
2080 case TE_LINK_SUBTLV_RSC_CLSCLR
:
2081 sum
+= show_vty_link_subtlv_rsc_clsclr(vty
, tlvh
);
2083 case TE_LINK_SUBTLV_LRRID
:
2084 sum
+= show_vty_link_subtlv_lrrid(vty
, tlvh
);
2086 case TE_LINK_SUBTLV_LLRI
:
2087 sum
+= show_vty_link_subtlv_llri(vty
, tlvh
);
2089 case TE_LINK_SUBTLV_RIP
:
2090 sum
+= show_vty_link_subtlv_rip(vty
, tlvh
);
2092 case TE_LINK_SUBTLV_RAS
:
2093 sum
+= show_vty_link_subtlv_ras(vty
, tlvh
);
2095 case TE_LINK_SUBTLV_AV_DELAY
:
2096 sum
+= show_vty_link_subtlv_av_delay(vty
, tlvh
);
2098 case TE_LINK_SUBTLV_MM_DELAY
:
2099 sum
+= show_vty_link_subtlv_mm_delay(vty
, tlvh
);
2101 case TE_LINK_SUBTLV_DELAY_VAR
:
2102 sum
+= show_vty_link_subtlv_delay_var(vty
, tlvh
);
2104 case TE_LINK_SUBTLV_PKT_LOSS
:
2105 sum
+= show_vty_link_subtlv_pkt_loss(vty
, tlvh
);
2107 case TE_LINK_SUBTLV_RES_BW
:
2108 sum
+= show_vty_link_subtlv_res_bw(vty
, tlvh
);
2110 case TE_LINK_SUBTLV_AVA_BW
:
2111 sum
+= show_vty_link_subtlv_ava_bw(vty
, tlvh
);
2113 case TE_LINK_SUBTLV_USE_BW
:
2114 sum
+= show_vty_link_subtlv_use_bw(vty
, tlvh
);
2117 sum
+= show_vty_unknown_tlv(vty
, tlvh
);
2124 static void ospf_mpls_te_show_info(struct vty
*vty
, struct ospf_lsa
*lsa
)
2126 struct lsa_header
*lsah
= (struct lsa_header
*)lsa
->data
;
2127 struct tlv_header
*tlvh
, *next
;
2128 u_int16_t sum
, total
;
2129 u_int16_t (*subfunc
)(struct vty
* vty
, struct tlv_header
* tlvh
,
2130 u_int16_t subtotal
, u_int16_t total
) = NULL
;
2133 total
= ntohs(lsah
->length
) - OSPF_LSA_HEADER_SIZE
;
2135 for (tlvh
= TLV_HDR_TOP(lsah
); sum
< total
;
2136 tlvh
= (next
? next
: TLV_HDR_NEXT(tlvh
))) {
2137 if (subfunc
!= NULL
) {
2138 sum
= (*subfunc
)(vty
, tlvh
, sum
, total
);
2139 next
= (struct tlv_header
*)((char *)tlvh
+ sum
);
2145 switch (ntohs(tlvh
->type
)) {
2146 case TE_TLV_ROUTER_ADDR
:
2147 sum
+= show_vty_router_addr(vty
, tlvh
);
2150 sum
+= show_vty_link_header(vty
, tlvh
);
2151 subfunc
= ospf_mpls_te_show_link_subtlv
;
2152 next
= TLV_DATA(tlvh
);
2155 sum
+= show_vty_unknown_tlv(vty
, tlvh
);
2162 static void ospf_mpls_te_config_write_router(struct vty
*vty
)
2165 if (OspfMplsTE
.enabled
) {
2166 vty_out(vty
, " mpls-te on\n");
2167 vty_out(vty
, " mpls-te router-address %s\n",
2168 inet_ntoa(OspfMplsTE
.router_addr
.value
));
2171 if (OspfMplsTE
.inter_as
== AS
)
2172 vty_out(vty
, " mpls-te inter-as as\n");
2173 if (OspfMplsTE
.inter_as
== Area
)
2174 vty_out(vty
, " mpls-te inter-as area %s \n",
2175 inet_ntoa(OspfMplsTE
.interas_areaid
));
2180 /*------------------------------------------------------------------------*
2181 * Followings are vty command functions.
2182 *------------------------------------------------------------------------*/
2184 DEFUN (ospf_mpls_te_on
,
2185 ospf_mpls_te_on_cmd
,
2188 "Enable the MPLS-TE functionality\n")
2190 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2191 struct listnode
*node
;
2192 struct mpls_te_link
*lp
;
2194 if (OspfMplsTE
.enabled
)
2197 if (IS_DEBUG_OSPF_EVENT
)
2198 zlog_debug("MPLS-TE: OFF -> ON");
2200 OspfMplsTE
.enabled
= true;
2202 /* Reoriginate RFC3630 & RFC6827 Links */
2203 ospf_mpls_te_foreach_area(ospf_mpls_te_lsa_schedule
,
2204 REORIGINATE_THIS_LSA
);
2206 /* Reoriginate LSA if INTER-AS is always on */
2207 if (OspfMplsTE
.inter_as
!= Off
) {
2208 for (ALL_LIST_ELEMENTS_RO(OspfMplsTE
.iflist
, node
, lp
)) {
2209 if (IS_INTER_AS(lp
->type
)) {
2210 ospf_mpls_te_lsa_schedule(lp
,
2211 REORIGINATE_THIS_LSA
);
2219 DEFUN (no_ospf_mpls_te
,
2220 no_ospf_mpls_te_cmd
,
2224 "Disable the MPLS-TE functionality\n")
2226 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2227 struct listnode
*node
, *nnode
;
2228 struct mpls_te_link
*lp
;
2230 if (!OspfMplsTE
.enabled
)
2233 if (IS_DEBUG_OSPF_EVENT
)
2234 zlog_debug("MPLS-TE: ON -> OFF");
2236 OspfMplsTE
.enabled
= false;
2238 for (ALL_LIST_ELEMENTS(OspfMplsTE
.iflist
, node
, nnode
, lp
))
2239 if (CHECK_FLAG(lp
->flags
, LPFLG_LSA_ENGAGED
))
2240 ospf_mpls_te_lsa_schedule(lp
, FLUSH_THIS_LSA
);
2246 DEFUN (ospf_mpls_te_router_addr
,
2247 ospf_mpls_te_router_addr_cmd
,
2248 "mpls-te router-address A.B.C.D",
2250 "Stable IP address of the advertising router\n"
2251 "MPLS-TE router address in IPv4 address format\n")
2253 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2255 struct te_tlv_router_addr
*ra
= &OspfMplsTE
.router_addr
;
2256 struct in_addr value
;
2258 if (!inet_aton(argv
[idx_ipv4
]->arg
, &value
)) {
2259 vty_out(vty
, "Please specify Router-Addr by A.B.C.D\n");
2263 if (ntohs(ra
->header
.type
) == 0
2264 || ntohl(ra
->value
.s_addr
) != ntohl(value
.s_addr
)) {
2265 struct listnode
*node
, *nnode
;
2266 struct mpls_te_link
*lp
;
2267 int need_to_reoriginate
= 0;
2269 set_mpls_te_router_addr(value
);
2271 if (!OspfMplsTE
.enabled
)
2274 for (ALL_LIST_ELEMENTS(OspfMplsTE
.iflist
, node
, nnode
, lp
)) {
2275 if ((lp
->area
== NULL
) || IS_FLOOD_AS(lp
->type
))
2278 if (!CHECK_FLAG(lp
->flags
, LPFLG_LSA_ENGAGED
)) {
2279 need_to_reoriginate
= 1;
2284 for (ALL_LIST_ELEMENTS(OspfMplsTE
.iflist
, node
, nnode
, lp
)) {
2285 if ((lp
->area
== NULL
) || IS_FLOOD_AS(lp
->type
))
2288 if (need_to_reoriginate
)
2289 SET_FLAG(lp
->flags
, LPFLG_LSA_FORCED_REFRESH
);
2291 ospf_mpls_te_lsa_schedule(lp
, REFRESH_THIS_LSA
);
2294 if (need_to_reoriginate
)
2295 ospf_mpls_te_foreach_area(ospf_mpls_te_lsa_schedule
,
2296 REORIGINATE_THIS_LSA
);
2302 static int set_inter_as_mode(struct vty
*vty
, const char *mode_name
,
2303 const char *area_id
)
2305 enum inter_as_mode mode
;
2306 struct listnode
*node
;
2307 struct mpls_te_link
*lp
;
2310 if (OspfMplsTE
.enabled
) {
2312 /* Read and Check inter_as mode */
2313 if (strcmp(mode_name
, "as") == 0)
2315 else if (strcmp(mode_name
, "area") == 0) {
2317 VTY_GET_OSPF_AREA_ID(OspfMplsTE
.interas_areaid
, format
,
2321 "Unknown mode. Please choose between as or area\n");
2325 if (IS_DEBUG_OSPF_EVENT
)
2327 "MPLS-TE: Inter-AS enable with %s flooding support",
2330 /* Register new callbacks regarding the flooding scope (AS or
2332 if (ospf_mpls_te_register(mode
) < 0) {
2334 "Internal error: Unable to register Inter-AS functions\n");
2338 /* Enable mode and re-originate LSA if needed */
2339 if ((OspfMplsTE
.inter_as
== Off
)
2340 && (mode
!= OspfMplsTE
.inter_as
)) {
2341 OspfMplsTE
.inter_as
= mode
;
2342 /* Re-originate all InterAS-TEv2 LSA */
2343 for (ALL_LIST_ELEMENTS_RO(OspfMplsTE
.iflist
, node
,
2345 if (IS_INTER_AS(lp
->type
)) {
2347 lp
->type
|= FLOOD_AS
;
2349 lp
->type
|= FLOOD_AREA
;
2350 ospf_mpls_te_lsa_schedule(
2351 lp
, REORIGINATE_THIS_LSA
);
2356 "Please change Inter-AS support to disable first before going to mode %s\n",
2361 vty_out(vty
, "mpls-te has not been turned on\n");
2368 DEFUN (ospf_mpls_te_inter_as_as
,
2369 ospf_mpls_te_inter_as_cmd
,
2370 "mpls-te inter-as as",
2372 "Configure MPLS-TE Inter-AS support\n"
2373 "AS native mode self originate INTER_AS LSA with Type 11 (as flooding scope)\n")
2375 return set_inter_as_mode(vty
, "as", "");
2378 DEFUN (ospf_mpls_te_inter_as_area
,
2379 ospf_mpls_te_inter_as_area_cmd
,
2380 "mpls-te inter-as area <A.B.C.D|(0-4294967295)>",
2382 "Configure MPLS-TE Inter-AS support\n"
2383 "AREA native mode self originate INTER_AS LSA with Type 10 (area flooding scope)\n"
2384 "OSPF area ID in IP format\n"
2385 "OSPF area ID as decimal value\n")
2387 int idx_ipv4_number
= 3;
2388 return set_inter_as_mode(vty
, "area", argv
[idx_ipv4_number
]->arg
);
2391 DEFUN (no_ospf_mpls_te_inter_as
,
2392 no_ospf_mpls_te_inter_as_cmd
,
2393 "no mpls-te inter-as",
2396 "Disable MPLS-TE Inter-AS support\n")
2399 struct listnode
*node
, *nnode
;
2400 struct mpls_te_link
*lp
;
2402 if (IS_DEBUG_OSPF_EVENT
)
2403 zlog_debug("MPLS-TE: Inter-AS support OFF");
2405 if ((OspfMplsTE
.enabled
)
2406 && (OspfMplsTE
.inter_as
!= Off
)) {
2407 OspfMplsTE
.inter_as
= Off
;
2408 /* Flush all Inter-AS LSA */
2409 for (ALL_LIST_ELEMENTS(OspfMplsTE
.iflist
, node
, nnode
, lp
))
2410 if (IS_INTER_AS(lp
->type
)
2411 && CHECK_FLAG(lp
->flags
, LPFLG_LSA_ENGAGED
))
2412 ospf_mpls_te_lsa_schedule(lp
, FLUSH_THIS_LSA
);
2415 /* Deregister the Callbacks for Inter-AS suport */
2416 ospf_mpls_te_unregister();
2421 DEFUN (show_ip_ospf_mpls_te_router
,
2422 show_ip_ospf_mpls_te_router_cmd
,
2423 "show ip ospf mpls-te router",
2427 "MPLS-TE information\n"
2428 "MPLS-TE Router parameters\n")
2430 if (OspfMplsTE
.enabled
) {
2431 vty_out(vty
, "--- MPLS-TE router parameters ---\n");
2433 if (ntohs(OspfMplsTE
.router_addr
.header
.type
) != 0)
2434 show_vty_router_addr(vty
,
2435 &OspfMplsTE
.router_addr
.header
);
2437 vty_out(vty
, " N/A\n");
2442 static void show_mpls_te_link_sub(struct vty
*vty
, struct interface
*ifp
)
2444 struct mpls_te_link
*lp
;
2446 if ((OspfMplsTE
.enabled
) && HAS_LINK_PARAMS(ifp
)
2447 && !if_is_loopback(ifp
) && if_is_up(ifp
)
2448 && ((lp
= lookup_linkparams_by_ifp(ifp
)) != NULL
)) {
2449 /* Continue only if interface is not passive or support Inter-AS
2451 if (!(ospf_oi_count(ifp
) > 0)) {
2452 if (IS_INTER_AS(lp
->type
)) {
2454 "-- Inter-AS TEv2 link parameters for %s --\n",
2457 /* MPLS-TE is not activate on this interface */
2458 /* or this interface is passive and Inter-AS
2459 * TEv2 is not activate */
2461 " %s: MPLS-TE is disabled on this interface\n",
2466 vty_out(vty
, "-- MPLS-TE link parameters for %s --\n",
2470 if (TLV_TYPE(lp
->link_type
) != 0)
2471 show_vty_link_subtlv_link_type(vty
,
2472 &lp
->link_type
.header
);
2473 if (TLV_TYPE(lp
->link_id
) != 0)
2474 show_vty_link_subtlv_link_id(vty
, &lp
->link_id
.header
);
2475 if (TLV_TYPE(lp
->lclif_ipaddr
) != 0)
2476 show_vty_link_subtlv_lclif_ipaddr(
2477 vty
, &lp
->lclif_ipaddr
.header
);
2478 if (TLV_TYPE(lp
->rmtif_ipaddr
) != 0)
2479 show_vty_link_subtlv_rmtif_ipaddr(
2480 vty
, &lp
->rmtif_ipaddr
.header
);
2481 if (TLV_TYPE(lp
->rip
) != 0)
2482 show_vty_link_subtlv_rip(vty
, &lp
->rip
.header
);
2483 if (TLV_TYPE(lp
->ras
) != 0)
2484 show_vty_link_subtlv_ras(vty
, &lp
->ras
.header
);
2485 if (TLV_TYPE(lp
->te_metric
) != 0)
2486 show_vty_link_subtlv_te_metric(vty
,
2487 &lp
->te_metric
.header
);
2488 if (TLV_TYPE(lp
->max_bw
) != 0)
2489 show_vty_link_subtlv_max_bw(vty
, &lp
->max_bw
.header
);
2490 if (TLV_TYPE(lp
->max_rsv_bw
) != 0)
2491 show_vty_link_subtlv_max_rsv_bw(vty
,
2492 &lp
->max_rsv_bw
.header
);
2493 if (TLV_TYPE(lp
->unrsv_bw
) != 0)
2494 show_vty_link_subtlv_unrsv_bw(vty
,
2495 &lp
->unrsv_bw
.header
);
2496 if (TLV_TYPE(lp
->rsc_clsclr
) != 0)
2497 show_vty_link_subtlv_rsc_clsclr(vty
,
2498 &lp
->rsc_clsclr
.header
);
2499 if (TLV_TYPE(lp
->av_delay
) != 0)
2500 show_vty_link_subtlv_av_delay(vty
,
2501 &lp
->av_delay
.header
);
2502 if (TLV_TYPE(lp
->mm_delay
) != 0)
2503 show_vty_link_subtlv_mm_delay(vty
,
2504 &lp
->mm_delay
.header
);
2505 if (TLV_TYPE(lp
->delay_var
) != 0)
2506 show_vty_link_subtlv_delay_var(vty
,
2507 &lp
->delay_var
.header
);
2508 if (TLV_TYPE(lp
->pkt_loss
) != 0)
2509 show_vty_link_subtlv_pkt_loss(vty
,
2510 &lp
->pkt_loss
.header
);
2511 if (TLV_TYPE(lp
->res_bw
) != 0)
2512 show_vty_link_subtlv_res_bw(vty
, &lp
->res_bw
.header
);
2513 if (TLV_TYPE(lp
->ava_bw
) != 0)
2514 show_vty_link_subtlv_ava_bw(vty
, &lp
->ava_bw
.header
);
2515 if (TLV_TYPE(lp
->use_bw
) != 0)
2516 show_vty_link_subtlv_use_bw(vty
, &lp
->use_bw
.header
);
2517 vty_out(vty
, "---------------\n\n");
2519 vty_out(vty
, " %s: MPLS-TE is disabled on this interface\n",
2526 DEFUN (show_ip_ospf_mpls_te_link
,
2527 show_ip_ospf_mpls_te_link_cmd
,
2528 "show ip ospf [vrf <NAME|all>] mpls-te interface [INTERFACE]",
2534 "MPLS-TE information\n"
2535 "Interface information\n"
2539 int idx_interface
= 5;
2540 struct interface
*ifp
;
2541 struct listnode
*node
;
2542 char *vrf_name
= NULL
;
2546 struct ospf
*ospf
= NULL
;
2548 if (argv_find(argv
, argc
, "vrf", &idx_vrf
)) {
2549 vrf_name
= argv
[idx_vrf
+ 1]->arg
;
2550 all_vrf
= strmatch(vrf_name
, "all");
2553 /* vrf input is provided could be all or specific vrf*/
2556 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
2557 if (!ospf
->oi_running
)
2559 vrf
= vrf_lookup_by_id(ospf
->vrf_id
);
2560 FOR_ALL_INTERFACES (vrf
, ifp
)
2561 show_mpls_te_link_sub(vty
, ifp
);
2565 ospf
= ospf_lookup_by_inst_name (inst
, vrf_name
);
2566 if (ospf
== NULL
|| !ospf
->oi_running
)
2568 vrf
= vrf_lookup_by_id(ospf
->vrf_id
);
2569 FOR_ALL_INTERFACES (vrf
, ifp
)
2570 show_mpls_te_link_sub(vty
, ifp
);
2573 /* Show All Interfaces. */
2575 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
2576 if (!ospf
->oi_running
)
2578 vrf
= vrf_lookup_by_id(ospf
->vrf_id
);
2579 FOR_ALL_INTERFACES (vrf
, ifp
)
2580 show_mpls_te_link_sub(vty
, ifp
);
2583 /* Interface name is specified. */
2585 ifp
= if_lookup_by_name_all_vrf(argv
[idx_interface
]->arg
);
2587 vty_out(vty
, "No such interface name\n");
2589 show_mpls_te_link_sub(vty
, ifp
);
2595 static void ospf_mpls_te_register_vty(void)
2597 install_element(VIEW_NODE
, &show_ip_ospf_mpls_te_router_cmd
);
2598 install_element(VIEW_NODE
, &show_ip_ospf_mpls_te_link_cmd
);
2600 install_element(OSPF_NODE
, &ospf_mpls_te_on_cmd
);
2601 install_element(OSPF_NODE
, &no_ospf_mpls_te_cmd
);
2602 install_element(OSPF_NODE
, &ospf_mpls_te_router_addr_cmd
);
2603 install_element(OSPF_NODE
, &ospf_mpls_te_inter_as_cmd
);
2604 install_element(OSPF_NODE
, &ospf_mpls_te_inter_as_area_cmd
);
2605 install_element(OSPF_NODE
, &no_ospf_mpls_te_inter_as_cmd
);