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
);
174 OspfMplsTE
.enabled
= false;
176 ospf_mpls_te_unregister();
177 OspfMplsTE
.inter_as
= Off
;
182 void ospf_mpls_te_finish(void)
184 // list_delete_all_node(OspfMplsTE.iflist);
186 OspfMplsTE
.enabled
= false;
187 OspfMplsTE
.inter_as
= Off
;
190 /*------------------------------------------------------------------------*
191 * Followings are control functions for MPLS-TE parameters management.
192 *------------------------------------------------------------------------*/
194 static void del_mpls_te_link(void *val
)
196 XFREE(MTYPE_OSPF_MPLS_TE
, val
);
200 static uint32_t get_mpls_te_instance_value(void)
202 static uint32_t seqno
= 0;
204 if (seqno
< MAX_LEGAL_TE_INSTANCE_NUM
)
207 seqno
= 1; /* Avoid zero. */
212 static struct mpls_te_link
*lookup_linkparams_by_ifp(struct interface
*ifp
)
214 struct listnode
*node
, *nnode
;
215 struct mpls_te_link
*lp
;
217 for (ALL_LIST_ELEMENTS(OspfMplsTE
.iflist
, node
, nnode
, lp
))
224 static struct mpls_te_link
*lookup_linkparams_by_instance(struct ospf_lsa
*lsa
)
226 struct listnode
*node
;
227 struct mpls_te_link
*lp
;
228 unsigned int key
= GET_OPAQUE_ID(ntohl(lsa
->data
->id
.s_addr
));
230 for (ALL_LIST_ELEMENTS_RO(OspfMplsTE
.iflist
, node
, lp
))
231 if (lp
->instance
== key
)
234 zlog_warn("lookup_linkparams_by_instance: Entry not found: key(%x)",
239 static void ospf_mpls_te_foreach_area(
240 void (*func
)(struct mpls_te_link
*lp
, enum lsa_opcode sched_opcode
),
241 enum lsa_opcode sched_opcode
)
243 struct listnode
*node
, *nnode
;
244 struct listnode
*node2
;
245 struct mpls_te_link
*lp
;
246 struct ospf_area
*area
;
248 for (ALL_LIST_ELEMENTS(OspfMplsTE
.iflist
, node
, nnode
, lp
)) {
249 /* Skip Inter-AS TEv2 Links */
250 if (IS_INTER_AS(lp
->type
))
252 if ((area
= lp
->area
) == NULL
)
254 if (CHECK_FLAG(lp
->flags
, LPFLG_LOOKUP_DONE
))
258 (*func
)(lp
, sched_opcode
);
260 for (node2
= listnextnode(node
); node2
;
261 node2
= listnextnode(node2
))
262 if ((lp
= listgetdata(node2
)) != NULL
)
263 if (lp
->area
!= NULL
)
264 if (IPV4_ADDR_SAME(&lp
->area
->area_id
,
270 for (ALL_LIST_ELEMENTS_RO(OspfMplsTE
.iflist
, node
, lp
))
271 if (lp
->area
!= NULL
)
272 UNSET_FLAG(lp
->flags
, LPFLG_LOOKUP_DONE
);
277 static void set_mpls_te_router_addr(struct in_addr ipv4
)
279 OspfMplsTE
.router_addr
.header
.type
= htons(TE_TLV_ROUTER_ADDR
);
280 OspfMplsTE
.router_addr
.header
.length
= htons(TE_LINK_SUBTLV_DEF_SIZE
);
281 OspfMplsTE
.router_addr
.value
= ipv4
;
285 static void set_linkparams_link_header(struct mpls_te_link
*lp
)
289 /* TE_LINK_SUBTLV_LINK_TYPE */
290 if (ntohs(lp
->link_type
.header
.type
) != 0)
291 length
+= TLV_SIZE(&lp
->link_type
.header
);
293 /* TE_LINK_SUBTLV_LINK_ID */
294 if (ntohs(lp
->link_id
.header
.type
) != 0)
295 length
+= TLV_SIZE(&lp
->link_id
.header
);
297 /* TE_LINK_SUBTLV_LCLIF_IPADDR */
298 if (lp
->lclif_ipaddr
.header
.type
!= 0)
299 length
+= TLV_SIZE(&lp
->lclif_ipaddr
.header
);
301 /* TE_LINK_SUBTLV_RMTIF_IPADDR */
302 if (lp
->rmtif_ipaddr
.header
.type
!= 0)
303 length
+= TLV_SIZE(&lp
->rmtif_ipaddr
.header
);
305 /* TE_LINK_SUBTLV_TE_METRIC */
306 if (ntohs(lp
->te_metric
.header
.type
) != 0)
307 length
+= TLV_SIZE(&lp
->te_metric
.header
);
309 /* TE_LINK_SUBTLV_MAX_BW */
310 if (ntohs(lp
->max_bw
.header
.type
) != 0)
311 length
+= TLV_SIZE(&lp
->max_bw
.header
);
313 /* TE_LINK_SUBTLV_MAX_RSV_BW */
314 if (ntohs(lp
->max_rsv_bw
.header
.type
) != 0)
315 length
+= TLV_SIZE(&lp
->max_rsv_bw
.header
);
317 /* TE_LINK_SUBTLV_UNRSV_BW */
318 if (ntohs(lp
->unrsv_bw
.header
.type
) != 0)
319 length
+= TLV_SIZE(&lp
->unrsv_bw
.header
);
321 /* TE_LINK_SUBTLV_RSC_CLSCLR */
322 if (ntohs(lp
->rsc_clsclr
.header
.type
) != 0)
323 length
+= TLV_SIZE(&lp
->rsc_clsclr
.header
);
325 /* TE_LINK_SUBTLV_LLRI */
326 if (ntohs(lp
->llri
.header
.type
) != 0)
327 length
+= TLV_SIZE(&lp
->llri
.header
);
329 /* TE_LINK_SUBTLV_RIP */
330 if (ntohs(lp
->rip
.header
.type
) != 0)
331 length
+= TLV_SIZE(&lp
->rip
.header
);
333 /* TE_LINK_SUBTLV_RAS */
334 if (ntohs(lp
->ras
.header
.type
) != 0)
335 length
+= TLV_SIZE(&lp
->ras
.header
);
337 /* TE_LINK_SUBTLV_LRRID */
338 if (ntohs(lp
->lrrid
.header
.type
) != 0)
339 length
+= TLV_SIZE(&lp
->lrrid
.header
);
341 /* TE_LINK_SUBTLV_AV_DELAY */
342 if (ntohs(lp
->av_delay
.header
.type
) != 0)
343 length
+= TLV_SIZE(&lp
->av_delay
.header
);
345 /* TE_LINK_SUBTLV_MM_DELAY */
346 if (ntohs(lp
->mm_delay
.header
.type
) != 0)
347 length
+= TLV_SIZE(&lp
->mm_delay
.header
);
349 /* TE_LINK_SUBTLV_DELAY_VAR */
350 if (ntohs(lp
->delay_var
.header
.type
) != 0)
351 length
+= TLV_SIZE(&lp
->delay_var
.header
);
353 /* TE_LINK_SUBTLV_PKT_LOSS */
354 if (ntohs(lp
->pkt_loss
.header
.type
) != 0)
355 length
+= TLV_SIZE(&lp
->pkt_loss
.header
);
357 /* TE_LINK_SUBTLV_RES_BW */
358 if (ntohs(lp
->res_bw
.header
.type
) != 0)
359 length
+= TLV_SIZE(&lp
->res_bw
.header
);
361 /* TE_LINK_SUBTLV_AVA_BW */
362 if (ntohs(lp
->ava_bw
.header
.type
) != 0)
363 length
+= TLV_SIZE(&lp
->ava_bw
.header
);
365 /* TE_LINK_SUBTLV_USE_BW */
366 if (ntohs(lp
->use_bw
.header
.type
) != 0)
367 length
+= TLV_SIZE(&lp
->use_bw
.header
);
369 lp
->link_header
.header
.type
= htons(TE_TLV_LINK
);
370 lp
->link_header
.header
.length
= htons(length
);
375 static void set_linkparams_link_type(struct ospf_interface
*oi
,
376 struct mpls_te_link
*lp
)
378 lp
->link_type
.header
.type
= htons(TE_LINK_SUBTLV_LINK_TYPE
);
379 lp
->link_type
.header
.length
= htons(TE_LINK_SUBTLV_TYPE_SIZE
);
382 case OSPF_IFTYPE_POINTOPOINT
:
383 lp
->link_type
.link_type
.value
= LINK_TYPE_SUBTLV_VALUE_PTP
;
385 case OSPF_IFTYPE_BROADCAST
:
386 case OSPF_IFTYPE_NBMA
:
387 lp
->link_type
.link_type
.value
= LINK_TYPE_SUBTLV_VALUE_MA
;
390 /* Not supported yet. */ /* XXX */
391 lp
->link_type
.header
.type
= htons(0);
397 static void set_linkparams_link_id(struct ospf_interface
*oi
,
398 struct mpls_te_link
*lp
)
400 struct ospf_neighbor
*nbr
;
403 lp
->link_id
.header
.type
= htons(TE_LINK_SUBTLV_LINK_ID
);
404 lp
->link_id
.header
.length
= htons(TE_LINK_SUBTLV_DEF_SIZE
);
407 * The Link ID is identical to the contents of the Link ID field
408 * in the Router LSA for these link types.
411 case OSPF_IFTYPE_POINTOPOINT
:
412 /* Take the router ID of the neighbor. */
413 if ((nbr
= ospf_nbr_lookup_ptop(oi
))
414 && nbr
->state
== NSM_Full
) {
415 lp
->link_id
.value
= nbr
->router_id
;
419 case OSPF_IFTYPE_BROADCAST
:
420 case OSPF_IFTYPE_NBMA
:
421 /* Take the interface address of the designated router. */
422 if ((nbr
= ospf_nbr_lookup_by_addr(oi
->nbrs
, &DR(oi
))) == NULL
)
425 if (nbr
->state
== NSM_Full
426 || (IPV4_ADDR_SAME(&oi
->address
->u
.prefix4
, &DR(oi
))
427 && ospf_nbr_count(oi
, NSM_Full
) > 0)) {
428 lp
->link_id
.value
= DR(oi
);
433 /* Not supported yet. */ /* XXX */
434 lp
->link_id
.header
.type
= htons(0);
440 masklen2ip(oi
->address
->prefixlen
, &mask
);
441 lp
->link_id
.value
.s_addr
=
442 oi
->address
->u
.prefix4
.s_addr
& mask
.s_addr
;
447 static void set_linkparams_lclif_ipaddr(struct mpls_te_link
*lp
,
448 struct in_addr lclif
)
451 lp
->lclif_ipaddr
.header
.type
= htons(TE_LINK_SUBTLV_LCLIF_IPADDR
);
452 lp
->lclif_ipaddr
.header
.length
= htons(TE_LINK_SUBTLV_DEF_SIZE
);
453 lp
->lclif_ipaddr
.value
[0] = lclif
;
457 static void set_linkparams_rmtif_ipaddr(struct mpls_te_link
*lp
,
458 struct in_addr rmtif
)
461 lp
->rmtif_ipaddr
.header
.type
= htons(TE_LINK_SUBTLV_RMTIF_IPADDR
);
462 lp
->rmtif_ipaddr
.header
.length
= htons(TE_LINK_SUBTLV_DEF_SIZE
);
463 lp
->rmtif_ipaddr
.value
[0] = rmtif
;
467 static void set_linkparams_te_metric(struct mpls_te_link
*lp
,
470 lp
->te_metric
.header
.type
= htons(TE_LINK_SUBTLV_TE_METRIC
);
471 lp
->te_metric
.header
.length
= htons(TE_LINK_SUBTLV_DEF_SIZE
);
472 lp
->te_metric
.value
= htonl(te_metric
);
476 static void set_linkparams_max_bw(struct mpls_te_link
*lp
, float fp
)
478 lp
->max_bw
.header
.type
= htons(TE_LINK_SUBTLV_MAX_BW
);
479 lp
->max_bw
.header
.length
= htons(TE_LINK_SUBTLV_DEF_SIZE
);
480 lp
->max_bw
.value
= htonf(fp
);
484 static void set_linkparams_max_rsv_bw(struct mpls_te_link
*lp
, float fp
)
486 lp
->max_rsv_bw
.header
.type
= htons(TE_LINK_SUBTLV_MAX_RSV_BW
);
487 lp
->max_rsv_bw
.header
.length
= htons(TE_LINK_SUBTLV_DEF_SIZE
);
488 lp
->max_rsv_bw
.value
= htonf(fp
);
492 static void set_linkparams_unrsv_bw(struct mpls_te_link
*lp
, int priority
,
495 /* Note that TLV-length field is the size of array. */
496 lp
->unrsv_bw
.header
.type
= htons(TE_LINK_SUBTLV_UNRSV_BW
);
497 lp
->unrsv_bw
.header
.length
= htons(TE_LINK_SUBTLV_UNRSV_SIZE
);
498 lp
->unrsv_bw
.value
[priority
] = htonf(fp
);
502 static void set_linkparams_rsc_clsclr(struct mpls_te_link
*lp
,
505 lp
->rsc_clsclr
.header
.type
= htons(TE_LINK_SUBTLV_RSC_CLSCLR
);
506 lp
->rsc_clsclr
.header
.length
= htons(TE_LINK_SUBTLV_DEF_SIZE
);
507 lp
->rsc_clsclr
.value
= htonl(classcolor
);
511 static void set_linkparams_inter_as(struct mpls_te_link
*lp
,
512 struct in_addr addr
, uint32_t as
)
515 /* Set the Remote ASBR IP address and then the associated AS number */
516 lp
->rip
.header
.type
= htons(TE_LINK_SUBTLV_RIP
);
517 lp
->rip
.header
.length
= htons(TE_LINK_SUBTLV_DEF_SIZE
);
518 lp
->rip
.value
= addr
;
520 lp
->ras
.header
.type
= htons(TE_LINK_SUBTLV_RAS
);
521 lp
->ras
.header
.length
= htons(TE_LINK_SUBTLV_DEF_SIZE
);
522 lp
->ras
.value
= htonl(as
);
525 static void unset_linkparams_inter_as(struct mpls_te_link
*lp
)
528 /* Reset the Remote ASBR IP address and then the associated AS number */
529 lp
->rip
.header
.type
= htons(0);
530 lp
->rip
.header
.length
= htons(0);
531 lp
->rip
.value
.s_addr
= htonl(0);
533 lp
->ras
.header
.type
= htons(0);
534 lp
->ras
.header
.length
= htons(0);
535 lp
->ras
.value
= htonl(0);
538 void set_linkparams_llri(struct mpls_te_link
*lp
, uint32_t local
,
542 lp
->llri
.header
.type
= htons(TE_LINK_SUBTLV_LLRI
);
543 lp
->llri
.header
.length
= htons(TE_LINK_SUBTLV_LLRI_SIZE
);
544 lp
->llri
.local
= htonl(local
);
545 lp
->llri
.remote
= htonl(remote
);
548 void set_linkparams_lrrid(struct mpls_te_link
*lp
, struct in_addr local
,
549 struct in_addr remote
)
552 lp
->lrrid
.header
.type
= htons(TE_LINK_SUBTLV_LRRID
);
553 lp
->lrrid
.header
.length
= htons(TE_LINK_SUBTLV_LRRID_SIZE
);
554 lp
->lrrid
.local
.s_addr
= local
.s_addr
;
555 lp
->lrrid
.remote
.s_addr
= remote
.s_addr
;
558 static void set_linkparams_av_delay(struct mpls_te_link
*lp
, uint32_t delay
,
562 /* Note that TLV-length field is the size of array. */
563 lp
->av_delay
.header
.type
= htons(TE_LINK_SUBTLV_AV_DELAY
);
564 lp
->av_delay
.header
.length
= htons(TE_LINK_SUBTLV_DEF_SIZE
);
565 tmp
= delay
& TE_EXT_MASK
;
567 tmp
|= TE_EXT_ANORMAL
;
568 lp
->av_delay
.value
= htonl(tmp
);
572 static void set_linkparams_mm_delay(struct mpls_te_link
*lp
, uint32_t low
,
573 uint32_t high
, uint8_t anormal
)
576 /* Note that TLV-length field is the size of array. */
577 lp
->mm_delay
.header
.type
= htons(TE_LINK_SUBTLV_MM_DELAY
);
578 lp
->mm_delay
.header
.length
= htons(TE_LINK_SUBTLV_MM_DELAY_SIZE
);
579 tmp
= low
& TE_EXT_MASK
;
581 tmp
|= TE_EXT_ANORMAL
;
582 lp
->mm_delay
.low
= htonl(tmp
);
583 lp
->mm_delay
.high
= htonl(high
);
587 static void set_linkparams_delay_var(struct mpls_te_link
*lp
, uint32_t jitter
)
589 /* Note that TLV-length field is the size of array. */
590 lp
->delay_var
.header
.type
= htons(TE_LINK_SUBTLV_DELAY_VAR
);
591 lp
->delay_var
.header
.length
= htons(TE_LINK_SUBTLV_DEF_SIZE
);
592 lp
->delay_var
.value
= htonl(jitter
& TE_EXT_MASK
);
596 static void set_linkparams_pkt_loss(struct mpls_te_link
*lp
, uint32_t loss
,
600 /* Note that TLV-length field is the size of array. */
601 lp
->pkt_loss
.header
.type
= htons(TE_LINK_SUBTLV_PKT_LOSS
);
602 lp
->pkt_loss
.header
.length
= htons(TE_LINK_SUBTLV_DEF_SIZE
);
603 tmp
= loss
& TE_EXT_MASK
;
605 tmp
|= TE_EXT_ANORMAL
;
606 lp
->pkt_loss
.value
= htonl(tmp
);
610 static void set_linkparams_res_bw(struct mpls_te_link
*lp
, float fp
)
612 /* Note that TLV-length field is the size of array. */
613 lp
->res_bw
.header
.type
= htons(TE_LINK_SUBTLV_RES_BW
);
614 lp
->res_bw
.header
.length
= htons(TE_LINK_SUBTLV_DEF_SIZE
);
615 lp
->res_bw
.value
= htonf(fp
);
619 static void set_linkparams_ava_bw(struct mpls_te_link
*lp
, float fp
)
621 /* Note that TLV-length field is the size of array. */
622 lp
->ava_bw
.header
.type
= htons(TE_LINK_SUBTLV_AVA_BW
);
623 lp
->ava_bw
.header
.length
= htons(TE_LINK_SUBTLV_DEF_SIZE
);
624 lp
->ava_bw
.value
= htonf(fp
);
628 static void set_linkparams_use_bw(struct mpls_te_link
*lp
, float fp
)
630 /* Note that TLV-length field is the size of array. */
631 lp
->use_bw
.header
.type
= htons(TE_LINK_SUBTLV_USE_BW
);
632 lp
->use_bw
.header
.length
= htons(TE_LINK_SUBTLV_DEF_SIZE
);
633 lp
->use_bw
.value
= htonf(fp
);
637 /* Update TE parameters from Interface */
638 static void update_linkparams(struct mpls_te_link
*lp
)
641 struct interface
*ifp
;
643 /* Get the Interface structure */
644 if ((ifp
= lp
->ifp
) == NULL
) {
645 if (IS_DEBUG_OSPF_TE
)
647 "OSPF MPLS-TE: Abort update TE parameters: no interface associated to Link Parameters");
650 if (!HAS_LINK_PARAMS(ifp
)) {
651 if (IS_DEBUG_OSPF_TE
)
653 "OSPF MPLS-TE: Abort update TE parameters: no Link Parameters for interface");
657 /* RFC3630 metrics */
658 if (IS_PARAM_SET(ifp
->link_params
, LP_ADM_GRP
))
659 set_linkparams_rsc_clsclr(lp
, ifp
->link_params
->admin_grp
);
661 TLV_TYPE(lp
->rsc_clsclr
) = 0;
663 if (IS_PARAM_SET(ifp
->link_params
, LP_MAX_BW
))
664 set_linkparams_max_bw(lp
, ifp
->link_params
->max_bw
);
666 TLV_TYPE(lp
->max_bw
) = 0;
668 if (IS_PARAM_SET(ifp
->link_params
, LP_MAX_RSV_BW
))
669 set_linkparams_max_rsv_bw(lp
, ifp
->link_params
->max_rsv_bw
);
671 TLV_TYPE(lp
->max_rsv_bw
) = 0;
673 if (IS_PARAM_SET(ifp
->link_params
, LP_UNRSV_BW
))
674 for (i
= 0; i
< MAX_CLASS_TYPE
; i
++)
675 set_linkparams_unrsv_bw(lp
, i
,
676 ifp
->link_params
->unrsv_bw
[i
]);
678 TLV_TYPE(lp
->unrsv_bw
) = 0;
680 if (IS_PARAM_SET(ifp
->link_params
, LP_TE_METRIC
))
681 set_linkparams_te_metric(lp
, ifp
->link_params
->te_metric
);
683 TLV_TYPE(lp
->te_metric
) = 0;
685 /* TE metric Extensions */
686 if (IS_PARAM_SET(ifp
->link_params
, LP_DELAY
))
687 set_linkparams_av_delay(lp
, ifp
->link_params
->av_delay
, 0);
689 TLV_TYPE(lp
->av_delay
) = 0;
691 if (IS_PARAM_SET(ifp
->link_params
, LP_MM_DELAY
))
692 set_linkparams_mm_delay(lp
, ifp
->link_params
->min_delay
,
693 ifp
->link_params
->max_delay
, 0);
695 TLV_TYPE(lp
->mm_delay
) = 0;
697 if (IS_PARAM_SET(ifp
->link_params
, LP_DELAY_VAR
))
698 set_linkparams_delay_var(lp
, ifp
->link_params
->delay_var
);
700 TLV_TYPE(lp
->delay_var
) = 0;
702 if (IS_PARAM_SET(ifp
->link_params
, LP_PKT_LOSS
))
703 set_linkparams_pkt_loss(lp
, ifp
->link_params
->pkt_loss
, 0);
705 TLV_TYPE(lp
->pkt_loss
) = 0;
707 if (IS_PARAM_SET(ifp
->link_params
, LP_RES_BW
))
708 set_linkparams_res_bw(lp
, ifp
->link_params
->res_bw
);
710 TLV_TYPE(lp
->res_bw
) = 0;
712 if (IS_PARAM_SET(ifp
->link_params
, LP_AVA_BW
))
713 set_linkparams_ava_bw(lp
, ifp
->link_params
->ava_bw
);
715 TLV_TYPE(lp
->ava_bw
) = 0;
717 if (IS_PARAM_SET(ifp
->link_params
, LP_USE_BW
))
718 set_linkparams_use_bw(lp
, ifp
->link_params
->use_bw
);
720 TLV_TYPE(lp
->use_bw
) = 0;
723 if (IS_PARAM_SET(ifp
->link_params
, LP_RMT_AS
)) {
724 /* Flush LSA if it engaged and was previously a STD_TE one */
725 if (IS_STD_TE(lp
->type
)
726 && CHECK_FLAG(lp
->flags
, LPFLG_LSA_ENGAGED
)) {
727 if (IS_DEBUG_OSPF_TE
)
729 "OSPF MPLS-TE Update IF: Switch from Standard LSA to INTER-AS for %s[%d/%d]",
730 ifp
->name
, lp
->flags
, lp
->type
);
732 ospf_mpls_te_lsa_schedule(lp
, FLUSH_THIS_LSA
);
733 /* Then, switch it to INTER-AS */
734 if (OspfMplsTE
.inter_as
== AS
)
735 lp
->flags
= INTER_AS
| FLOOD_AS
;
737 lp
->flags
= INTER_AS
| FLOOD_AREA
;
738 lp
->area
= ospf_area_lookup_by_area_id(
739 ospf_lookup_by_vrf_id(VRF_DEFAULT
),
740 OspfMplsTE
.interas_areaid
);
743 set_linkparams_inter_as(lp
, ifp
->link_params
->rmt_ip
,
744 ifp
->link_params
->rmt_as
);
746 if (IS_DEBUG_OSPF_TE
)
748 "OSPF MPLS-TE Update IF: Switch from INTER-AS LSA to Standard for %s[%d/%d]",
749 ifp
->name
, lp
->flags
, lp
->type
);
751 /* reset inter-as TE params */
752 /* Flush LSA if it engaged and was previously an INTER_AS one */
753 if (IS_INTER_AS(lp
->type
)
754 && CHECK_FLAG(lp
->flags
, LPFLG_LSA_ENGAGED
)) {
755 ospf_mpls_te_lsa_schedule(lp
, FLUSH_THIS_LSA
);
756 /* Then, switch it to Standard TE */
757 lp
->flags
= STD_TE
| FLOOD_AREA
;
759 unset_linkparams_inter_as(lp
);
763 static void initialize_linkparams(struct mpls_te_link
*lp
)
765 struct interface
*ifp
= lp
->ifp
;
766 struct ospf_interface
*oi
= NULL
;
767 struct route_node
*rn
;
769 if (IS_DEBUG_OSPF_TE
)
771 "MPLS-TE(initialize_linkparams) Initialize Link Parameters for interface %s",
774 /* Search OSPF Interface parameters for this interface */
775 for (rn
= route_top(IF_OIFS(ifp
)); rn
; rn
= route_next(rn
)) {
777 if ((oi
= rn
->info
) == NULL
)
784 if ((oi
== NULL
) || (oi
->ifp
!= ifp
)) {
785 if (IS_DEBUG_OSPF_TE
)
787 "MPLS-TE(initialize_linkparams) Could not find corresponding OSPF Interface for %s",
793 * Try to set initial values those can be derived from
794 * zebra-interface information.
796 set_linkparams_link_type(oi
, lp
);
798 /* Set local IP addr */
799 set_linkparams_lclif_ipaddr(lp
, oi
->address
->u
.prefix4
);
801 /* Set Remote IP addr if Point to Point Interface */
802 if (oi
->type
== OSPF_IFTYPE_POINTOPOINT
) {
803 struct prefix
*pref
= CONNECTED_PREFIX(oi
->connected
);
805 set_linkparams_rmtif_ipaddr(lp
, pref
->u
.prefix4
);
808 /* Keep Area information in combination with link parameters. */
814 static int is_mandated_params_set(struct mpls_te_link
*lp
)
818 if (ntohs(OspfMplsTE
.router_addr
.header
.type
) == 0) {
820 "MPLS-TE(is_mandated_params_set) Missing Router Address");
824 if (ntohs(lp
->link_type
.header
.type
) == 0) {
825 zlog_warn("MPLS-TE(is_mandated_params_set) Missing Link Type");
829 if (!IS_INTER_AS(lp
->type
) && (ntohs(lp
->link_id
.header
.type
) == 0)) {
830 zlog_warn("MPLS-TE(is_mandated_params_set) Missing Link ID");
838 /*------------------------------------------------------------------------*
839 * Followings are callback functions against generic Opaque-LSAs handling.
840 *------------------------------------------------------------------------*/
842 static int ospf_mpls_te_new_if(struct interface
*ifp
)
844 struct mpls_te_link
*new;
847 if (IS_DEBUG_OSPF_TE
)
849 "MPLS-TE(ospf_mpls_te_new_if) Add new %s interface %s to MPLS-TE list",
850 ifp
->link_params
? "Active" : "Inactive", ifp
->name
);
852 if (lookup_linkparams_by_ifp(ifp
) != NULL
) {
853 zlog_warn("ospf_mpls_te_new_if: ifp(%p) already in use?",
855 rc
= 0; /* Do nothing here. */
859 new = XCALLOC(MTYPE_OSPF_MPLS_TE
, sizeof(struct mpls_te_link
));
861 new->instance
= get_mpls_te_instance_value();
863 /* By default TE-Link is RFC3630 compatible flooding in Area and not
865 /* This default behavior will be adapted with call to
866 * ospf_mpls_te_update_if() */
867 new->type
= STD_TE
| FLOOD_AREA
;
868 new->flags
= LPFLG_LSA_INACTIVE
;
870 /* Initialize Link Parameters from Interface */
871 initialize_linkparams(new);
873 /* Set TE Parameters from Interface */
874 update_linkparams(new);
876 /* Add Link Parameters structure to the list */
877 listnode_add(OspfMplsTE
.iflist
, new);
879 if (IS_DEBUG_OSPF_TE
)
881 "OSPF MPLS-TE New IF: Add new LP context for %s[%d/%d]",
882 ifp
->name
, new->flags
, new->type
);
884 /* Schedule Opaque-LSA refresh. */ /* XXX */
890 static int ospf_mpls_te_del_if(struct interface
*ifp
)
892 struct mpls_te_link
*lp
;
895 if ((lp
= lookup_linkparams_by_ifp(ifp
)) != NULL
) {
896 struct list
*iflist
= OspfMplsTE
.iflist
;
898 /* Dequeue listnode entry from the list. */
899 listnode_delete(iflist
, lp
);
901 /* Avoid misjudgement in the next lookup. */
902 if (listcount(iflist
) == 0)
903 iflist
->head
= iflist
->tail
= NULL
;
905 XFREE(MTYPE_OSPF_MPLS_TE
, lp
);
908 /* Schedule Opaque-LSA refresh. */ /* XXX */
914 /* Main initialization / update function of the MPLS TE Link context */
916 /* Call when interface TE Link parameters are modified */
917 void ospf_mpls_te_update_if(struct interface
*ifp
)
919 struct mpls_te_link
*lp
;
921 if (IS_DEBUG_OSPF_TE
)
923 "OSPF MPLS-TE: Update LSA parameters for interface %s [%s]",
924 ifp
->name
, HAS_LINK_PARAMS(ifp
) ? "ON" : "OFF");
926 /* Get Link context from interface */
927 if ((lp
= lookup_linkparams_by_ifp(ifp
)) == NULL
) {
929 "OSPF MPLS-TE Update: Did not find Link Parameters context for interface %s",
934 /* Fulfill MPLS-TE Link TLV from Interface TE Link parameters */
935 if (HAS_LINK_PARAMS(ifp
)) {
936 SET_FLAG(lp
->flags
, LPFLG_LSA_ACTIVE
);
938 /* Update TE parameters */
939 update_linkparams(lp
);
941 /* Finally Re-Originate or Refresh Opaque LSA if MPLS_TE is
943 if (OspfMplsTE
.enabled
)
944 if (lp
->area
!= NULL
) {
945 if (CHECK_FLAG(lp
->flags
, LPFLG_LSA_ENGAGED
))
946 ospf_mpls_te_lsa_schedule(
947 lp
, REFRESH_THIS_LSA
);
949 ospf_mpls_te_lsa_schedule(
950 lp
, REORIGINATE_THIS_LSA
);
953 /* If MPLS TE is disable on this interface, flush LSA if it is
955 if (CHECK_FLAG(lp
->flags
, LPFLG_LSA_ENGAGED
))
956 ospf_mpls_te_lsa_schedule(lp
, FLUSH_THIS_LSA
);
958 /* Reset Activity flag */
959 lp
->flags
= LPFLG_LSA_INACTIVE
;
965 static void ospf_mpls_te_ism_change(struct ospf_interface
*oi
, int old_state
)
967 struct te_link_subtlv_link_type old_type
;
968 struct te_link_subtlv_link_id old_id
;
969 struct mpls_te_link
*lp
;
971 if ((lp
= lookup_linkparams_by_ifp(oi
->ifp
)) == NULL
) {
973 "ospf_mpls_te_ism_change: Cannot get linkparams from OI(%s)?",
978 if (oi
->area
== NULL
|| oi
->area
->ospf
== NULL
) {
980 "ospf_mpls_te_ism_change: Cannot refer to OSPF from OI(%s)?",
985 if ((lp
->area
!= NULL
986 && !IPV4_ADDR_SAME(&lp
->area
->area_id
, &oi
->area
->area_id
))
987 || (lp
->area
!= NULL
&& oi
->area
== NULL
)) {
988 /* How should we consider this case? */
990 "MPLS-TE: Area for OI(%s) has changed to [%s], flush previous LSAs",
992 oi
->area
? inet_ntoa(oi
->area
->area_id
) : "N/A");
993 ospf_mpls_te_lsa_schedule(lp
, FLUSH_THIS_LSA
);
996 /* Keep Area information in combination with linkparams. */
999 /* Keep interface MPLS-TE status */
1000 lp
->flags
= HAS_LINK_PARAMS(oi
->ifp
);
1002 switch (oi
->state
) {
1003 case ISM_PointToPoint
:
1007 old_type
= lp
->link_type
;
1008 old_id
= lp
->link_id
;
1010 /* Set Link type, Link ID, Local and Remote IP addr */
1011 set_linkparams_link_type(oi
, lp
);
1012 set_linkparams_link_id(oi
, lp
);
1013 set_linkparams_lclif_ipaddr(lp
, oi
->address
->u
.prefix4
);
1015 if (oi
->type
== LINK_TYPE_SUBTLV_VALUE_PTP
) {
1016 struct prefix
*pref
= CONNECTED_PREFIX(oi
->connected
);
1018 set_linkparams_rmtif_ipaddr(lp
,
1022 /* Update TE parameters */
1023 update_linkparams(lp
);
1025 /* Try to Schedule LSA */
1026 if ((ntohs(old_type
.header
.type
)
1027 != ntohs(lp
->link_type
.header
.type
)
1028 || old_type
.link_type
.value
1029 != lp
->link_type
.link_type
.value
)
1030 || (ntohs(old_id
.header
.type
)
1031 != ntohs(lp
->link_id
.header
.type
)
1032 || ntohl(old_id
.value
.s_addr
)
1033 != ntohl(lp
->link_id
.value
.s_addr
))) {
1034 if (CHECK_FLAG(lp
->flags
, LPFLG_LSA_ENGAGED
))
1035 ospf_mpls_te_lsa_schedule(lp
, REFRESH_THIS_LSA
);
1037 ospf_mpls_te_lsa_schedule(lp
,
1038 REORIGINATE_THIS_LSA
);
1042 lp
->link_type
.header
.type
= htons(0);
1043 lp
->link_id
.header
.type
= htons(0);
1045 if (CHECK_FLAG(lp
->flags
, LPFLG_LSA_ENGAGED
))
1046 ospf_mpls_te_lsa_schedule(lp
, FLUSH_THIS_LSA
);
1053 static void ospf_mpls_te_nsm_change(struct ospf_neighbor
*nbr
, int old_state
)
1055 /* Nothing to do here */
1059 /*------------------------------------------------------------------------*
1060 * Followings are OSPF protocol processing functions for MPLS-TE.
1061 *------------------------------------------------------------------------*/
1063 static void build_tlv_header(struct stream
*s
, struct tlv_header
*tlvh
)
1065 stream_put(s
, tlvh
, sizeof(struct tlv_header
));
1069 static void build_router_tlv(struct stream
*s
)
1071 struct tlv_header
*tlvh
= &OspfMplsTE
.router_addr
.header
;
1072 if (ntohs(tlvh
->type
) != 0) {
1073 build_tlv_header(s
, tlvh
);
1074 stream_put(s
, TLV_DATA(tlvh
), TLV_BODY_SIZE(tlvh
));
1079 static void build_link_subtlv(struct stream
*s
, struct tlv_header
*tlvh
)
1082 if ((tlvh
!= NULL
) && (ntohs(tlvh
->type
) != 0)) {
1083 build_tlv_header(s
, tlvh
);
1084 stream_put(s
, TLV_DATA(tlvh
), TLV_BODY_SIZE(tlvh
));
1089 static void build_link_tlv(struct stream
*s
, struct mpls_te_link
*lp
)
1091 set_linkparams_link_header(lp
);
1092 build_tlv_header(s
, &lp
->link_header
.header
);
1094 build_link_subtlv(s
, &lp
->link_type
.header
);
1095 build_link_subtlv(s
, &lp
->link_id
.header
);
1096 build_link_subtlv(s
, &lp
->lclif_ipaddr
.header
);
1097 build_link_subtlv(s
, &lp
->rmtif_ipaddr
.header
);
1098 build_link_subtlv(s
, &lp
->te_metric
.header
);
1099 build_link_subtlv(s
, &lp
->max_bw
.header
);
1100 build_link_subtlv(s
, &lp
->max_rsv_bw
.header
);
1101 build_link_subtlv(s
, &lp
->unrsv_bw
.header
);
1102 build_link_subtlv(s
, &lp
->rsc_clsclr
.header
);
1103 build_link_subtlv(s
, &lp
->lrrid
.header
);
1104 build_link_subtlv(s
, &lp
->llri
.header
);
1105 build_link_subtlv(s
, &lp
->rip
.header
);
1106 build_link_subtlv(s
, &lp
->ras
.header
);
1107 build_link_subtlv(s
, &lp
->av_delay
.header
);
1108 build_link_subtlv(s
, &lp
->mm_delay
.header
);
1109 build_link_subtlv(s
, &lp
->delay_var
.header
);
1110 build_link_subtlv(s
, &lp
->pkt_loss
.header
);
1111 build_link_subtlv(s
, &lp
->res_bw
.header
);
1112 build_link_subtlv(s
, &lp
->ava_bw
.header
);
1113 build_link_subtlv(s
, &lp
->use_bw
.header
);
1118 static void ospf_mpls_te_lsa_body_set(struct stream
*s
, struct mpls_te_link
*lp
)
1121 * The router address TLV is type 1, and ...
1122 * It must appear in exactly one
1123 * Traffic Engineering LSA originated by a router.
1125 build_router_tlv(s
);
1128 * Only one Link TLV shall be carried in each LSA, allowing for fine
1129 * granularity changes in topology.
1131 build_link_tlv(s
, lp
);
1135 /* Create new opaque-LSA. */
1136 static struct ospf_lsa
*ospf_mpls_te_lsa_new(struct ospf
*ospf
,
1137 struct ospf_area
*area
,
1138 struct mpls_te_link
*lp
)
1141 struct lsa_header
*lsah
;
1142 struct ospf_lsa
*new = NULL
;
1143 uint8_t options
, lsa_type
= 0;
1144 struct in_addr lsa_id
;
1148 /* Create a stream for LSA. */
1149 if ((s
= stream_new(OSPF_MAX_LSA_SIZE
)) == NULL
) {
1150 zlog_warn("ospf_mpls_te_lsa_new: stream_new() ?");
1153 lsah
= (struct lsa_header
*)STREAM_DATA(s
);
1155 options
= OSPF_OPTION_O
; /* Don't forget this :-) */
1157 /* Set opaque-LSA header fields depending of the type of RFC */
1158 if (IS_INTER_AS(lp
->type
)) {
1159 if (IS_FLOOD_AS(lp
->type
)) {
1160 /* Enable AS external as we flood Inter-AS with Opaque
1163 options
|= OSPF_OPTION_E
;
1164 lsa_type
= OSPF_OPAQUE_AS_LSA
;
1166 options
|= LSA_OPTIONS_GET(
1167 area
); /* Get area default option */
1168 options
|= LSA_OPTIONS_NSSA_GET(area
);
1169 lsa_type
= OSPF_OPAQUE_AREA_LSA
;
1171 tmp
= SET_OPAQUE_LSID(OPAQUE_TYPE_INTER_AS_LSA
, lp
->instance
);
1172 lsa_id
.s_addr
= htonl(tmp
);
1179 lsa_header_set(s
, options
, lsa_type
, lsa_id
, ospf
->router_id
);
1181 options
|= LSA_OPTIONS_GET(area
); /* Get area default option */
1182 options
|= LSA_OPTIONS_NSSA_GET(area
);
1183 lsa_type
= OSPF_OPAQUE_AREA_LSA
;
1184 tmp
= SET_OPAQUE_LSID(OPAQUE_TYPE_TRAFFIC_ENGINEERING_LSA
,
1186 lsa_id
.s_addr
= htonl(tmp
);
1187 lsa_header_set(s
, options
, lsa_type
, lsa_id
,
1188 area
->ospf
->router_id
);
1191 if (IS_DEBUG_OSPF(lsa
, LSA_GENERATE
))
1193 "LSA[Type%d:%s]: Create an Opaque-LSA/MPLS-TE instance",
1194 lsa_type
, inet_ntoa(lsa_id
));
1196 /* Set opaque-LSA body fields. */
1197 ospf_mpls_te_lsa_body_set(s
, lp
);
1200 length
= stream_get_endp(s
);
1201 lsah
->length
= htons(length
);
1203 /* Now, create an OSPF LSA instance. */
1204 if ((new = ospf_lsa_new()) == NULL
) {
1205 zlog_warn("%s: ospf_lsa_new() ?", __func__
);
1209 if ((new->data
= ospf_lsa_data_new(length
)) == NULL
) {
1210 zlog_warn("%s: ospf_lsa_data_new() ?", __func__
);
1211 ospf_lsa_unlock(&new);
1217 new->vrf_id
= ospf
->vrf_id
;
1218 if (area
&& area
->ospf
)
1219 new->vrf_id
= area
->ospf
->vrf_id
;
1221 SET_FLAG(new->flags
, OSPF_LSA_SELF
);
1222 memcpy(new->data
, lsah
, length
);
1228 static int ospf_mpls_te_lsa_originate1(struct ospf_area
*area
,
1229 struct mpls_te_link
*lp
)
1231 struct ospf_lsa
*new = NULL
;
1234 /* Create new Opaque-LSA/MPLS-TE instance. */
1235 new = ospf_mpls_te_lsa_new(area
->ospf
, area
, lp
);
1238 "ospf_mpls_te_lsa_originate1: ospf_mpls_te_lsa_new() ?");
1242 /* Install this LSA into LSDB. */
1243 if (ospf_lsa_install(area
->ospf
, NULL
/*oi*/, new) == NULL
) {
1244 zlog_warn("ospf_mpls_te_lsa_originate1: ospf_lsa_install() ?");
1245 ospf_lsa_unlock(&new);
1249 /* Now this link-parameter entry has associated LSA. */
1250 SET_FLAG(lp
->flags
, LPFLG_LSA_ENGAGED
);
1251 /* Update new LSA origination count. */
1252 area
->ospf
->lsa_originate_count
++;
1254 /* Flood new LSA through area. */
1255 ospf_flood_through_area(area
, NULL
/*nbr*/, new);
1257 if (IS_DEBUG_OSPF(lsa
, LSA_GENERATE
)) {
1258 char area_id
[INET_ADDRSTRLEN
];
1259 strlcpy(area_id
, inet_ntoa(area
->area_id
), sizeof(area_id
));
1261 "LSA[Type%d:%s]: Originate Opaque-LSA/MPLS-TE: Area(%s), Link(%s)",
1262 new->data
->type
, inet_ntoa(new->data
->id
), area_id
,
1264 ospf_lsa_header_dump(new->data
);
1271 static int ospf_mpls_te_lsa_originate_area(void *arg
)
1273 struct ospf_area
*area
= (struct ospf_area
*)arg
;
1274 struct listnode
*node
, *nnode
;
1275 struct mpls_te_link
*lp
;
1278 if (!OspfMplsTE
.enabled
) {
1280 "ospf_mpls_te_lsa_originate_area: MPLS-TE is disabled now.");
1281 rc
= 0; /* This is not an error case. */
1285 for (ALL_LIST_ELEMENTS(OspfMplsTE
.iflist
, node
, nnode
, lp
)) {
1286 /* Process only enabled LSA with area scope flooding */
1287 if (!CHECK_FLAG(lp
->flags
, LPFLG_LSA_ACTIVE
)
1288 || IS_FLOOD_AS(lp
->type
))
1291 if (lp
->area
== NULL
)
1294 if (!IPV4_ADDR_SAME(&lp
->area
->area_id
, &area
->area_id
))
1297 if (CHECK_FLAG(lp
->flags
, LPFLG_LSA_ENGAGED
)) {
1298 if (CHECK_FLAG(lp
->flags
, LPFLG_LSA_FORCED_REFRESH
)) {
1299 UNSET_FLAG(lp
->flags
, LPFLG_LSA_FORCED_REFRESH
);
1301 "OSPF MPLS-TE (ospf_mpls_te_lsa_originate_area): Refresh instead of Originate");
1302 ospf_mpls_te_lsa_schedule(lp
, REFRESH_THIS_LSA
);
1307 if (!is_mandated_params_set(lp
)) {
1309 "ospf_mpls_te_lsa_originate_area: Link(%s) lacks some mandated MPLS-TE parameters.",
1310 lp
->ifp
? lp
->ifp
->name
: "?");
1314 /* Ok, let's try to originate an LSA for this area and Link. */
1315 if (IS_DEBUG_OSPF_TE
)
1317 "MPLS-TE(ospf_mpls_te_lsa_originate_area) Let's finally reoriginate the LSA %d through the Area %s for Link %s",
1318 lp
->instance
, inet_ntoa(area
->area_id
),
1319 lp
->ifp
? lp
->ifp
->name
: "?");
1320 if (ospf_mpls_te_lsa_originate1(area
, lp
) != 0)
1328 static int ospf_mpls_te_lsa_originate2(struct ospf
*top
,
1329 struct mpls_te_link
*lp
)
1331 struct ospf_lsa
*new;
1334 /* Create new Opaque-LSA/Inter-AS instance. */
1335 new = ospf_mpls_te_lsa_new(top
, NULL
, lp
);
1338 "ospf_mpls_te_lsa_originate2: ospf_router_info_lsa_new() ?");
1341 new->vrf_id
= top
->vrf_id
;
1343 /* Install this LSA into LSDB. */
1344 if (ospf_lsa_install(top
, NULL
/*oi */, new) == NULL
) {
1345 zlog_warn("ospf_mpls_te_lsa_originate2: ospf_lsa_install() ?");
1346 ospf_lsa_unlock(&new);
1350 /* Now this Router Info parameter entry has associated LSA. */
1351 SET_FLAG(lp
->flags
, LPFLG_LSA_ENGAGED
);
1352 /* Update new LSA origination count. */
1353 top
->lsa_originate_count
++;
1355 /* Flood new LSA through AS. */
1356 ospf_flood_through_as(top
, NULL
/*nbr */, new);
1358 if (IS_DEBUG_OSPF(lsa
, LSA_GENERATE
)) {
1360 "LSA[Type%d:%s]: Originate Opaque-LSA/MPLS-TE Inter-AS",
1361 new->data
->type
, inet_ntoa(new->data
->id
));
1362 ospf_lsa_header_dump(new->data
);
1369 static int ospf_mpls_te_lsa_originate_as(void *arg
)
1372 struct ospf_area
*area
;
1373 struct listnode
*node
, *nnode
;
1374 struct mpls_te_link
*lp
;
1377 if ((!OspfMplsTE
.enabled
) || (OspfMplsTE
.inter_as
== Off
)) {
1379 "ospf_mpls_te_lsa_originate_as: MPLS-TE Inter-AS is disabled for now.");
1380 rc
= 0; /* This is not an error case. */
1384 for (ALL_LIST_ELEMENTS(OspfMplsTE
.iflist
, node
, nnode
, lp
)) {
1385 /* Process only enabled INTER_AS Links or Pseudo-Links */
1386 if (!CHECK_FLAG(lp
->flags
, LPFLG_LSA_ACTIVE
)
1387 || !IS_INTER_AS(lp
->type
))
1390 if (CHECK_FLAG(lp
->flags
, LPFLG_LSA_ENGAGED
)) {
1391 if (CHECK_FLAG(lp
->flags
, LPFLG_LSA_FORCED_REFRESH
)) {
1392 UNSET_FLAG(lp
->flags
, LPFLG_LSA_FORCED_REFRESH
);
1393 ospf_mpls_te_lsa_schedule(lp
, REFRESH_THIS_LSA
);
1398 if (!is_mandated_params_set(lp
)) {
1400 "ospf_mpls_te_lsa_originate_as: Link(%s) lacks some mandated MPLS-TE parameters.",
1401 lp
->ifp
? lp
->ifp
->name
: "?");
1405 /* Ok, let's try to originate an LSA for this AS and Link. */
1406 if (IS_DEBUG_OSPF_TE
)
1408 "MPLS-TE(ospf_mpls_te_lsa_originate_as) Let's finally re-originate the Inter-AS LSA %d through the %s for Link %s",
1410 IS_FLOOD_AS(lp
->type
) ? "AS" : "Area",
1411 lp
->ifp
? lp
->ifp
->name
: "Unknown");
1413 if (IS_FLOOD_AS(lp
->type
)) {
1414 top
= (struct ospf
*)arg
;
1415 ospf_mpls_te_lsa_originate2(top
, lp
);
1417 area
= (struct ospf_area
*)arg
;
1418 ospf_mpls_te_lsa_originate1(area
, lp
);
1426 static struct ospf_lsa
*ospf_mpls_te_lsa_refresh(struct ospf_lsa
*lsa
)
1428 struct mpls_te_link
*lp
;
1429 struct ospf_area
*area
= lsa
->area
;
1431 struct ospf_lsa
*new = NULL
;
1433 if (!OspfMplsTE
.enabled
) {
1435 * This LSA must have flushed before due to MPLS-TE status
1437 * It seems a slip among routers in the routing domain.
1439 zlog_info("ospf_mpls_te_lsa_refresh: MPLS-TE is disabled now.");
1441 htons(OSPF_LSA_MAXAGE
); /* Flush it anyway. */
1444 /* At first, resolve lsa/lp relationship. */
1445 if ((lp
= lookup_linkparams_by_instance(lsa
)) == NULL
) {
1446 zlog_warn("ospf_mpls_te_lsa_refresh: Invalid parameter?");
1448 htons(OSPF_LSA_MAXAGE
); /* Flush it anyway. */
1449 ospf_opaque_lsa_flush_schedule(lsa
);
1453 /* Check if lp was not disable in the interval */
1454 if (!CHECK_FLAG(lp
->flags
, LPFLG_LSA_ACTIVE
)) {
1456 "ospf_mpls_te_lsa_refresh: lp was disabled: Flush it!");
1458 htons(OSPF_LSA_MAXAGE
); /* Flush it anyway. */
1461 /* If the lsa's age reached to MaxAge, start flushing procedure. */
1462 if (IS_LSA_MAXAGE(lsa
)) {
1463 UNSET_FLAG(lp
->flags
, LPFLG_LSA_ENGAGED
);
1464 ospf_opaque_lsa_flush_schedule(lsa
);
1467 top
= ospf_lookup_by_vrf_id(lsa
->vrf_id
);
1468 /* Create new Opaque-LSA/MPLS-TE instance. */
1469 new = ospf_mpls_te_lsa_new(top
, area
, lp
);
1471 zlog_warn("ospf_mpls_te_lsa_refresh: ospf_mpls_te_lsa_new() ?");
1474 new->data
->ls_seqnum
= lsa_seqnum_increment(lsa
);
1476 /* Install this LSA into LSDB. */
1477 /* Given "lsa" will be freed in the next function. */
1478 /* As area could be NULL i.e. when using OPAQUE_LSA_AS, we prefer to use
1479 * ospf_lookup() to get ospf instance */
1483 if (ospf_lsa_install(top
, NULL
/*oi */, new) == NULL
) {
1484 zlog_warn("ospf_mpls_te_lsa_refresh: ospf_lsa_install() ?");
1485 ospf_lsa_unlock(&new);
1489 /* Flood updated LSA through AS or Area depending of the RFC of the link
1491 if (IS_FLOOD_AS(lp
->type
))
1492 ospf_flood_through_as(top
, NULL
, new);
1494 ospf_flood_through_area(area
, NULL
/*nbr*/, new);
1496 /* Debug logging. */
1497 if (IS_DEBUG_OSPF(lsa
, LSA_GENERATE
)) {
1498 zlog_debug("LSA[Type%d:%s]: Refresh Opaque-LSA/MPLS-TE",
1499 new->data
->type
, inet_ntoa(new->data
->id
));
1500 ospf_lsa_header_dump(new->data
);
1506 void ospf_mpls_te_lsa_schedule(struct mpls_te_link
*lp
, enum lsa_opcode opcode
)
1508 struct ospf_lsa lsa
;
1509 struct lsa_header lsah
;
1513 memset(&lsa
, 0, sizeof(lsa
));
1514 memset(&lsah
, 0, sizeof(lsah
));
1515 top
= ospf_lookup_by_vrf_id(VRF_DEFAULT
);
1517 /* Check if the pseudo link is ready to flood */
1518 if (!(CHECK_FLAG(lp
->flags
, LPFLG_LSA_ACTIVE
))
1519 || !(IS_FLOOD_AREA(lp
->type
) || IS_FLOOD_AS(lp
->type
))) {
1523 lsa
.area
= lp
->area
;
1525 if (IS_FLOOD_AS(lp
->type
)) {
1526 lsah
.type
= OSPF_OPAQUE_AS_LSA
;
1527 tmp
= SET_OPAQUE_LSID(OPAQUE_TYPE_INTER_AS_LSA
, lp
->instance
);
1528 lsah
.id
.s_addr
= htonl(tmp
);
1530 lsah
.type
= OSPF_OPAQUE_AREA_LSA
;
1531 if (IS_INTER_AS(lp
->type
)) {
1532 /* Set the area context if not know */
1533 if (lp
->area
== NULL
)
1534 lp
->area
= ospf_area_lookup_by_area_id(
1535 top
, OspfMplsTE
.interas_areaid
);
1536 /* Unable to set the area context. Abort! */
1537 if (lp
->area
== NULL
) {
1539 "MPLS-TE(ospf_mpls_te_lsa_schedule) Area context is null. Abort !");
1542 tmp
= SET_OPAQUE_LSID(OPAQUE_TYPE_INTER_AS_LSA
,
1545 tmp
= SET_OPAQUE_LSID(
1546 OPAQUE_TYPE_TRAFFIC_ENGINEERING_LSA
,
1548 lsah
.id
.s_addr
= htonl(tmp
);
1552 case REORIGINATE_THIS_LSA
:
1553 if (IS_FLOOD_AS(lp
->type
)) {
1554 ospf_opaque_lsa_reoriginate_schedule(
1555 (void *)top
, OSPF_OPAQUE_AS_LSA
,
1556 OPAQUE_TYPE_INTER_AS_LSA
);
1560 if (IS_FLOOD_AREA(lp
->type
)) {
1561 if (IS_INTER_AS(lp
->type
))
1562 ospf_opaque_lsa_reoriginate_schedule(
1563 (void *)lp
->area
, OSPF_OPAQUE_AREA_LSA
,
1564 OPAQUE_TYPE_INTER_AS_LSA
);
1566 ospf_opaque_lsa_reoriginate_schedule(
1567 (void *)lp
->area
, OSPF_OPAQUE_AREA_LSA
,
1568 OPAQUE_TYPE_TRAFFIC_ENGINEERING_LSA
);
1572 case REFRESH_THIS_LSA
:
1573 ospf_opaque_lsa_refresh_schedule(&lsa
);
1575 case FLUSH_THIS_LSA
:
1576 /* Reset Activity flag */
1577 lp
->flags
= LPFLG_LSA_INACTIVE
;
1578 ospf_opaque_lsa_flush_schedule(&lsa
);
1581 zlog_warn("ospf_mpls_te_lsa_schedule: Unknown opcode (%u)",
1590 /*------------------------------------------------------------------------*
1591 * Followings are vty session control functions.
1592 *------------------------------------------------------------------------*/
1594 static uint16_t show_vty_router_addr(struct vty
*vty
, struct tlv_header
*tlvh
)
1596 struct te_tlv_router_addr
*top
= (struct te_tlv_router_addr
*)tlvh
;
1599 vty_out(vty
, " Router-Address: %s\n", inet_ntoa(top
->value
));
1601 zlog_debug(" Router-Address: %s", inet_ntoa(top
->value
));
1603 return TLV_SIZE(tlvh
);
1606 static uint16_t show_vty_link_header(struct vty
*vty
, struct tlv_header
*tlvh
)
1608 struct te_tlv_link
*top
= (struct te_tlv_link
*)tlvh
;
1611 vty_out(vty
, " Link: %u octets of data\n",
1612 ntohs(top
->header
.length
));
1614 zlog_debug(" Link: %u octets of data",
1615 ntohs(top
->header
.length
));
1617 return TLV_HDR_SIZE
; /* Here is special, not "TLV_SIZE". */
1620 static uint16_t show_vty_link_subtlv_link_type(struct vty
*vty
,
1621 struct tlv_header
*tlvh
)
1623 struct te_link_subtlv_link_type
*top
;
1624 const char *cp
= "Unknown";
1626 top
= (struct te_link_subtlv_link_type
*)tlvh
;
1627 switch (top
->link_type
.value
) {
1628 case LINK_TYPE_SUBTLV_VALUE_PTP
:
1629 cp
= "Point-to-point";
1631 case LINK_TYPE_SUBTLV_VALUE_MA
:
1639 vty_out(vty
, " Link-Type: %s (%u)\n", cp
,
1640 top
->link_type
.value
);
1642 zlog_debug(" Link-Type: %s (%u)", cp
, top
->link_type
.value
);
1644 return TLV_SIZE(tlvh
);
1647 static uint16_t show_vty_link_subtlv_link_id(struct vty
*vty
,
1648 struct tlv_header
*tlvh
)
1650 struct te_link_subtlv_link_id
*top
;
1652 top
= (struct te_link_subtlv_link_id
*)tlvh
;
1654 vty_out(vty
, " Link-ID: %s\n", inet_ntoa(top
->value
));
1656 zlog_debug(" Link-ID: %s", inet_ntoa(top
->value
));
1658 return TLV_SIZE(tlvh
);
1661 static uint16_t show_vty_link_subtlv_lclif_ipaddr(struct vty
*vty
,
1662 struct tlv_header
*tlvh
)
1664 struct te_link_subtlv_lclif_ipaddr
*top
;
1667 top
= (struct te_link_subtlv_lclif_ipaddr
*)tlvh
;
1668 n
= ntohs(tlvh
->length
) / sizeof(top
->value
[0]);
1671 vty_out(vty
, " Local Interface IP Address(es): %d\n", n
);
1673 zlog_debug(" Local Interface IP Address(es): %d", n
);
1675 for (i
= 0; i
< n
; i
++) {
1677 vty_out(vty
, " #%d: %s\n", i
,
1678 inet_ntoa(top
->value
[i
]));
1680 zlog_debug(" #%d: %s", i
,
1681 inet_ntoa(top
->value
[i
]));
1683 return TLV_SIZE(tlvh
);
1686 static uint16_t show_vty_link_subtlv_rmtif_ipaddr(struct vty
*vty
,
1687 struct tlv_header
*tlvh
)
1689 struct te_link_subtlv_rmtif_ipaddr
*top
;
1692 top
= (struct te_link_subtlv_rmtif_ipaddr
*)tlvh
;
1693 n
= ntohs(tlvh
->length
) / sizeof(top
->value
[0]);
1695 vty_out(vty
, " Remote Interface IP Address(es): %d\n", n
);
1697 zlog_debug(" Remote Interface IP Address(es): %d", n
);
1699 for (i
= 0; i
< n
; i
++) {
1701 vty_out(vty
, " #%d: %s\n", i
,
1702 inet_ntoa(top
->value
[i
]));
1704 zlog_debug(" #%d: %s", i
,
1705 inet_ntoa(top
->value
[i
]));
1707 return TLV_SIZE(tlvh
);
1710 static uint16_t show_vty_link_subtlv_te_metric(struct vty
*vty
,
1711 struct tlv_header
*tlvh
)
1713 struct te_link_subtlv_te_metric
*top
;
1715 top
= (struct te_link_subtlv_te_metric
*)tlvh
;
1717 vty_out(vty
, " Traffic Engineering Metric: %u\n",
1718 (uint32_t)ntohl(top
->value
));
1720 zlog_debug(" Traffic Engineering Metric: %u",
1721 (uint32_t)ntohl(top
->value
));
1723 return TLV_SIZE(tlvh
);
1726 static uint16_t show_vty_link_subtlv_max_bw(struct vty
*vty
,
1727 struct tlv_header
*tlvh
)
1729 struct te_link_subtlv_max_bw
*top
;
1732 top
= (struct te_link_subtlv_max_bw
*)tlvh
;
1733 fval
= ntohf(top
->value
);
1736 vty_out(vty
, " Maximum Bandwidth: %g (Bytes/sec)\n", fval
);
1738 zlog_debug(" Maximum Bandwidth: %g (Bytes/sec)", fval
);
1740 return TLV_SIZE(tlvh
);
1743 static uint16_t show_vty_link_subtlv_max_rsv_bw(struct vty
*vty
,
1744 struct tlv_header
*tlvh
)
1746 struct te_link_subtlv_max_rsv_bw
*top
;
1749 top
= (struct te_link_subtlv_max_rsv_bw
*)tlvh
;
1750 fval
= ntohf(top
->value
);
1753 vty_out(vty
, " Maximum Reservable Bandwidth: %g (Bytes/sec)\n",
1756 zlog_debug(" Maximum Reservable Bandwidth: %g (Bytes/sec)",
1759 return TLV_SIZE(tlvh
);
1762 static uint16_t show_vty_link_subtlv_unrsv_bw(struct vty
*vty
,
1763 struct tlv_header
*tlvh
)
1765 struct te_link_subtlv_unrsv_bw
*top
;
1769 top
= (struct te_link_subtlv_unrsv_bw
*)tlvh
;
1772 " Unreserved Bandwidth per Class Type in Byte/s:\n");
1775 " Unreserved Bandwidth per Class Type in Byte/s:");
1776 for (i
= 0; i
< MAX_CLASS_TYPE
; i
+= 2) {
1777 fval1
= ntohf(top
->value
[i
]);
1778 fval2
= ntohf(top
->value
[i
+ 1]);
1782 " [%d]: %g (Bytes/sec),\t[%d]: %g (Bytes/sec)\n",
1783 i
, fval1
, i
+ 1, fval2
);
1786 " [%d]: %g (Bytes/sec),\t[%d]: %g (Bytes/sec)",
1787 i
, fval1
, i
+ 1, fval2
);
1790 return TLV_SIZE(tlvh
);
1793 static uint16_t show_vty_link_subtlv_rsc_clsclr(struct vty
*vty
,
1794 struct tlv_header
*tlvh
)
1796 struct te_link_subtlv_rsc_clsclr
*top
;
1798 top
= (struct te_link_subtlv_rsc_clsclr
*)tlvh
;
1800 vty_out(vty
, " Resource class/color: 0x%x\n",
1801 (uint32_t)ntohl(top
->value
));
1803 zlog_debug(" Resource Class/Color: 0x%x",
1804 (uint32_t)ntohl(top
->value
));
1806 return TLV_SIZE(tlvh
);
1809 static uint16_t show_vty_link_subtlv_lrrid(struct vty
*vty
,
1810 struct tlv_header
*tlvh
)
1812 struct te_link_subtlv_lrrid
*top
;
1814 top
= (struct te_link_subtlv_lrrid
*)tlvh
;
1817 vty_out(vty
, " Local TE Router ID: %s\n",
1818 inet_ntoa(top
->local
));
1819 vty_out(vty
, " Remote TE Router ID: %s\n",
1820 inet_ntoa(top
->remote
));
1822 zlog_debug(" Local TE Router ID: %s",
1823 inet_ntoa(top
->local
));
1824 zlog_debug(" Remote TE Router ID: %s",
1825 inet_ntoa(top
->remote
));
1828 return TLV_SIZE(tlvh
);
1831 static uint16_t show_vty_link_subtlv_llri(struct vty
*vty
,
1832 struct tlv_header
*tlvh
)
1834 struct te_link_subtlv_llri
*top
;
1836 top
= (struct te_link_subtlv_llri
*)tlvh
;
1839 vty_out(vty
, " Link Local ID: %d\n",
1840 (uint32_t)ntohl(top
->local
));
1841 vty_out(vty
, " Link Remote ID: %d\n",
1842 (uint32_t)ntohl(top
->remote
));
1844 zlog_debug(" Link Local ID: %d",
1845 (uint32_t)ntohl(top
->local
));
1846 zlog_debug(" Link Remote ID: %d",
1847 (uint32_t)ntohl(top
->remote
));
1850 return TLV_SIZE(tlvh
);
1853 static uint16_t show_vty_link_subtlv_rip(struct vty
*vty
,
1854 struct tlv_header
*tlvh
)
1856 struct te_link_subtlv_rip
*top
;
1858 top
= (struct te_link_subtlv_rip
*)tlvh
;
1861 vty_out(vty
, " Inter-AS TE Remote ASBR IP address: %s\n",
1862 inet_ntoa(top
->value
));
1864 zlog_debug(" Inter-AS TE Remote ASBR IP address: %s",
1865 inet_ntoa(top
->value
));
1867 return TLV_SIZE(tlvh
);
1870 static uint16_t show_vty_link_subtlv_ras(struct vty
*vty
,
1871 struct tlv_header
*tlvh
)
1873 struct te_link_subtlv_ras
*top
;
1875 top
= (struct te_link_subtlv_ras
*)tlvh
;
1878 vty_out(vty
, " Inter-AS TE Remote AS number: %u\n",
1881 zlog_debug(" Inter-AS TE Remote AS number: %u",
1884 return TLV_SIZE(tlvh
);
1887 static uint16_t show_vty_link_subtlv_av_delay(struct vty
*vty
,
1888 struct tlv_header
*tlvh
)
1890 struct te_link_subtlv_av_delay
*top
;
1894 top
= (struct te_link_subtlv_av_delay
*)tlvh
;
1895 delay
= (uint32_t)ntohl(top
->value
) & TE_EXT_MASK
;
1896 anomalous
= (uint32_t)ntohl(top
->value
) & TE_EXT_ANORMAL
;
1899 vty_out(vty
, " %s Average Link Delay: %d (micro-sec)\n",
1900 anomalous
? "Anomalous" : "Normal", delay
);
1902 zlog_debug(" %s Average Link Delay: %d (micro-sec)",
1903 anomalous
? "Anomalous" : "Normal", delay
);
1905 return TLV_SIZE(tlvh
);
1908 static uint16_t show_vty_link_subtlv_mm_delay(struct vty
*vty
,
1909 struct tlv_header
*tlvh
)
1911 struct te_link_subtlv_mm_delay
*top
;
1915 top
= (struct te_link_subtlv_mm_delay
*)tlvh
;
1916 low
= (uint32_t)ntohl(top
->low
) & TE_EXT_MASK
;
1917 anomalous
= (uint32_t)ntohl(top
->low
) & TE_EXT_ANORMAL
;
1918 high
= (uint32_t)ntohl(top
->high
);
1921 vty_out(vty
, " %s Min/Max Link Delay: %d/%d (micro-sec)\n",
1922 anomalous
? "Anomalous" : "Normal", low
, high
);
1924 zlog_debug(" %s Min/Max Link Delay: %d/%d (micro-sec)",
1925 anomalous
? "Anomalous" : "Normal", low
, high
);
1927 return TLV_SIZE(tlvh
);
1930 static uint16_t show_vty_link_subtlv_delay_var(struct vty
*vty
,
1931 struct tlv_header
*tlvh
)
1933 struct te_link_subtlv_delay_var
*top
;
1936 top
= (struct te_link_subtlv_delay_var
*)tlvh
;
1937 jitter
= (uint32_t)ntohl(top
->value
) & TE_EXT_MASK
;
1940 vty_out(vty
, " Delay Variation: %d (micro-sec)\n", jitter
);
1942 zlog_debug(" Delay Variation: %d (micro-sec)", jitter
);
1944 return TLV_SIZE(tlvh
);
1947 static uint16_t show_vty_link_subtlv_pkt_loss(struct vty
*vty
,
1948 struct tlv_header
*tlvh
)
1950 struct te_link_subtlv_pkt_loss
*top
;
1955 top
= (struct te_link_subtlv_pkt_loss
*)tlvh
;
1956 loss
= (uint32_t)ntohl(top
->value
) & TE_EXT_MASK
;
1957 fval
= (float)(loss
* LOSS_PRECISION
);
1958 anomalous
= (uint32_t)ntohl(top
->value
) & TE_EXT_ANORMAL
;
1961 vty_out(vty
, " %s Link Loss: %g (%%)\n",
1962 anomalous
? "Anomalous" : "Normal", fval
);
1964 zlog_debug(" %s Link Loss: %g (%%)",
1965 anomalous
? "Anomalous" : "Normal", fval
);
1967 return TLV_SIZE(tlvh
);
1970 static uint16_t show_vty_link_subtlv_res_bw(struct vty
*vty
,
1971 struct tlv_header
*tlvh
)
1973 struct te_link_subtlv_res_bw
*top
;
1976 top
= (struct te_link_subtlv_res_bw
*)tlvh
;
1977 fval
= ntohf(top
->value
);
1981 " Unidirectional Residual Bandwidth: %g (Bytes/sec)\n",
1985 " Unidirectional Residual Bandwidth: %g (Bytes/sec)",
1988 return TLV_SIZE(tlvh
);
1991 static uint16_t show_vty_link_subtlv_ava_bw(struct vty
*vty
,
1992 struct tlv_header
*tlvh
)
1994 struct te_link_subtlv_ava_bw
*top
;
1997 top
= (struct te_link_subtlv_ava_bw
*)tlvh
;
1998 fval
= ntohf(top
->value
);
2002 " Unidirectional Available Bandwidth: %g (Bytes/sec)\n",
2006 " Unidirectional Available Bandwidth: %g (Bytes/sec)",
2009 return TLV_SIZE(tlvh
);
2012 static uint16_t show_vty_link_subtlv_use_bw(struct vty
*vty
,
2013 struct tlv_header
*tlvh
)
2015 struct te_link_subtlv_use_bw
*top
;
2018 top
= (struct te_link_subtlv_use_bw
*)tlvh
;
2019 fval
= ntohf(top
->value
);
2023 " Unidirectional Utilized Bandwidth: %g (Bytes/sec)\n",
2027 " Unidirectional Utilized Bandwidth: %g (Bytes/sec)",
2030 return TLV_SIZE(tlvh
);
2033 static uint16_t show_vty_unknown_tlv(struct vty
*vty
, struct tlv_header
*tlvh
)
2036 vty_out(vty
, " Unknown TLV: [type(0x%x), length(0x%x)]\n",
2037 ntohs(tlvh
->type
), ntohs(tlvh
->length
));
2039 zlog_debug(" Unknown TLV: [type(0x%x), length(0x%x)]",
2040 ntohs(tlvh
->type
), ntohs(tlvh
->length
));
2042 return TLV_SIZE(tlvh
);
2045 static uint16_t ospf_mpls_te_show_link_subtlv(struct vty
*vty
,
2046 struct tlv_header
*tlvh0
,
2047 uint16_t subtotal
, uint16_t total
)
2049 struct tlv_header
*tlvh
;
2050 uint16_t sum
= subtotal
;
2052 for (tlvh
= tlvh0
; sum
< total
;
2053 tlvh
= TLV_HDR_NEXT(tlvh
)) {
2054 switch (ntohs(tlvh
->type
)) {
2055 case TE_LINK_SUBTLV_LINK_TYPE
:
2056 sum
+= show_vty_link_subtlv_link_type(vty
, tlvh
);
2058 case TE_LINK_SUBTLV_LINK_ID
:
2059 sum
+= show_vty_link_subtlv_link_id(vty
, tlvh
);
2061 case TE_LINK_SUBTLV_LCLIF_IPADDR
:
2062 sum
+= show_vty_link_subtlv_lclif_ipaddr(vty
, tlvh
);
2064 case TE_LINK_SUBTLV_RMTIF_IPADDR
:
2065 sum
+= show_vty_link_subtlv_rmtif_ipaddr(vty
, tlvh
);
2067 case TE_LINK_SUBTLV_TE_METRIC
:
2068 sum
+= show_vty_link_subtlv_te_metric(vty
, tlvh
);
2070 case TE_LINK_SUBTLV_MAX_BW
:
2071 sum
+= show_vty_link_subtlv_max_bw(vty
, tlvh
);
2073 case TE_LINK_SUBTLV_MAX_RSV_BW
:
2074 sum
+= show_vty_link_subtlv_max_rsv_bw(vty
, tlvh
);
2076 case TE_LINK_SUBTLV_UNRSV_BW
:
2077 sum
+= show_vty_link_subtlv_unrsv_bw(vty
, tlvh
);
2079 case TE_LINK_SUBTLV_RSC_CLSCLR
:
2080 sum
+= show_vty_link_subtlv_rsc_clsclr(vty
, tlvh
);
2082 case TE_LINK_SUBTLV_LRRID
:
2083 sum
+= show_vty_link_subtlv_lrrid(vty
, tlvh
);
2085 case TE_LINK_SUBTLV_LLRI
:
2086 sum
+= show_vty_link_subtlv_llri(vty
, tlvh
);
2088 case TE_LINK_SUBTLV_RIP
:
2089 sum
+= show_vty_link_subtlv_rip(vty
, tlvh
);
2091 case TE_LINK_SUBTLV_RAS
:
2092 sum
+= show_vty_link_subtlv_ras(vty
, tlvh
);
2094 case TE_LINK_SUBTLV_AV_DELAY
:
2095 sum
+= show_vty_link_subtlv_av_delay(vty
, tlvh
);
2097 case TE_LINK_SUBTLV_MM_DELAY
:
2098 sum
+= show_vty_link_subtlv_mm_delay(vty
, tlvh
);
2100 case TE_LINK_SUBTLV_DELAY_VAR
:
2101 sum
+= show_vty_link_subtlv_delay_var(vty
, tlvh
);
2103 case TE_LINK_SUBTLV_PKT_LOSS
:
2104 sum
+= show_vty_link_subtlv_pkt_loss(vty
, tlvh
);
2106 case TE_LINK_SUBTLV_RES_BW
:
2107 sum
+= show_vty_link_subtlv_res_bw(vty
, tlvh
);
2109 case TE_LINK_SUBTLV_AVA_BW
:
2110 sum
+= show_vty_link_subtlv_ava_bw(vty
, tlvh
);
2112 case TE_LINK_SUBTLV_USE_BW
:
2113 sum
+= show_vty_link_subtlv_use_bw(vty
, tlvh
);
2116 sum
+= show_vty_unknown_tlv(vty
, tlvh
);
2123 static void ospf_mpls_te_show_info(struct vty
*vty
, struct ospf_lsa
*lsa
)
2125 struct lsa_header
*lsah
= (struct lsa_header
*)lsa
->data
;
2126 struct tlv_header
*tlvh
, *next
;
2127 uint16_t sum
, total
;
2128 uint16_t (*subfunc
)(struct vty
* vty
, struct tlv_header
* tlvh
,
2129 uint16_t subtotal
, uint16_t total
) = NULL
;
2132 total
= ntohs(lsah
->length
) - OSPF_LSA_HEADER_SIZE
;
2134 for (tlvh
= TLV_HDR_TOP(lsah
); sum
< total
;
2135 tlvh
= (next
? next
: TLV_HDR_NEXT(tlvh
))) {
2136 if (subfunc
!= NULL
) {
2137 sum
= (*subfunc
)(vty
, tlvh
, sum
, total
);
2138 next
= (struct tlv_header
*)((char *)tlvh
+ sum
);
2144 switch (ntohs(tlvh
->type
)) {
2145 case TE_TLV_ROUTER_ADDR
:
2146 sum
+= show_vty_router_addr(vty
, tlvh
);
2149 sum
+= show_vty_link_header(vty
, tlvh
);
2150 subfunc
= ospf_mpls_te_show_link_subtlv
;
2151 next
= TLV_DATA(tlvh
);
2154 sum
+= show_vty_unknown_tlv(vty
, tlvh
);
2161 static void ospf_mpls_te_config_write_router(struct vty
*vty
)
2164 if (OspfMplsTE
.enabled
) {
2165 vty_out(vty
, " mpls-te on\n");
2166 vty_out(vty
, " mpls-te router-address %s\n",
2167 inet_ntoa(OspfMplsTE
.router_addr
.value
));
2170 if (OspfMplsTE
.inter_as
== AS
)
2171 vty_out(vty
, " mpls-te inter-as as\n");
2172 if (OspfMplsTE
.inter_as
== Area
)
2173 vty_out(vty
, " mpls-te inter-as area %s \n",
2174 inet_ntoa(OspfMplsTE
.interas_areaid
));
2179 /*------------------------------------------------------------------------*
2180 * Followings are vty command functions.
2181 *------------------------------------------------------------------------*/
2183 DEFUN (ospf_mpls_te_on
,
2184 ospf_mpls_te_on_cmd
,
2187 "Enable the MPLS-TE functionality\n")
2189 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2190 struct listnode
*node
;
2191 struct mpls_te_link
*lp
;
2193 if (OspfMplsTE
.enabled
)
2196 if (IS_DEBUG_OSPF_EVENT
)
2197 zlog_debug("MPLS-TE: OFF -> ON");
2199 OspfMplsTE
.enabled
= true;
2201 /* Reoriginate RFC3630 & RFC6827 Links */
2202 ospf_mpls_te_foreach_area(ospf_mpls_te_lsa_schedule
,
2203 REORIGINATE_THIS_LSA
);
2205 /* Reoriginate LSA if INTER-AS is always on */
2206 if (OspfMplsTE
.inter_as
!= Off
) {
2207 for (ALL_LIST_ELEMENTS_RO(OspfMplsTE
.iflist
, node
, lp
)) {
2208 if (IS_INTER_AS(lp
->type
)) {
2209 ospf_mpls_te_lsa_schedule(lp
,
2210 REORIGINATE_THIS_LSA
);
2218 DEFUN (no_ospf_mpls_te
,
2219 no_ospf_mpls_te_cmd
,
2223 "Disable the MPLS-TE functionality\n")
2225 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2226 struct listnode
*node
, *nnode
;
2227 struct mpls_te_link
*lp
;
2229 if (!OspfMplsTE
.enabled
)
2232 if (IS_DEBUG_OSPF_EVENT
)
2233 zlog_debug("MPLS-TE: ON -> OFF");
2235 OspfMplsTE
.enabled
= false;
2237 for (ALL_LIST_ELEMENTS(OspfMplsTE
.iflist
, node
, nnode
, lp
))
2238 if (CHECK_FLAG(lp
->flags
, LPFLG_LSA_ENGAGED
))
2239 ospf_mpls_te_lsa_schedule(lp
, FLUSH_THIS_LSA
);
2245 DEFUN (ospf_mpls_te_router_addr
,
2246 ospf_mpls_te_router_addr_cmd
,
2247 "mpls-te router-address A.B.C.D",
2249 "Stable IP address of the advertising router\n"
2250 "MPLS-TE router address in IPv4 address format\n")
2252 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2254 struct te_tlv_router_addr
*ra
= &OspfMplsTE
.router_addr
;
2255 struct in_addr value
;
2257 if (!inet_aton(argv
[idx_ipv4
]->arg
, &value
)) {
2258 vty_out(vty
, "Please specify Router-Addr by A.B.C.D\n");
2262 if (ntohs(ra
->header
.type
) == 0
2263 || ntohl(ra
->value
.s_addr
) != ntohl(value
.s_addr
)) {
2264 struct listnode
*node
, *nnode
;
2265 struct mpls_te_link
*lp
;
2266 int need_to_reoriginate
= 0;
2268 set_mpls_te_router_addr(value
);
2270 if (!OspfMplsTE
.enabled
)
2273 for (ALL_LIST_ELEMENTS(OspfMplsTE
.iflist
, node
, nnode
, lp
)) {
2274 if ((lp
->area
== NULL
) || IS_FLOOD_AS(lp
->type
))
2277 if (!CHECK_FLAG(lp
->flags
, LPFLG_LSA_ENGAGED
)) {
2278 need_to_reoriginate
= 1;
2283 for (ALL_LIST_ELEMENTS(OspfMplsTE
.iflist
, node
, nnode
, lp
)) {
2284 if ((lp
->area
== NULL
) || IS_FLOOD_AS(lp
->type
))
2287 if (need_to_reoriginate
)
2288 SET_FLAG(lp
->flags
, LPFLG_LSA_FORCED_REFRESH
);
2290 ospf_mpls_te_lsa_schedule(lp
, REFRESH_THIS_LSA
);
2293 if (need_to_reoriginate
)
2294 ospf_mpls_te_foreach_area(ospf_mpls_te_lsa_schedule
,
2295 REORIGINATE_THIS_LSA
);
2301 static int set_inter_as_mode(struct vty
*vty
, const char *mode_name
,
2302 const char *area_id
)
2304 enum inter_as_mode mode
;
2305 struct listnode
*node
;
2306 struct mpls_te_link
*lp
;
2309 if (OspfMplsTE
.enabled
) {
2311 /* Read and Check inter_as mode */
2312 if (strcmp(mode_name
, "as") == 0)
2314 else if (strcmp(mode_name
, "area") == 0) {
2316 VTY_GET_OSPF_AREA_ID(OspfMplsTE
.interas_areaid
, format
,
2320 "Unknown mode. Please choose between as or area\n");
2324 if (IS_DEBUG_OSPF_EVENT
)
2326 "MPLS-TE: Inter-AS enable with %s flooding support",
2329 /* Register new callbacks regarding the flooding scope (AS or
2331 if (ospf_mpls_te_register(mode
) < 0) {
2333 "Internal error: Unable to register Inter-AS functions\n");
2337 /* Enable mode and re-originate LSA if needed */
2338 if ((OspfMplsTE
.inter_as
== Off
)
2339 && (mode
!= OspfMplsTE
.inter_as
)) {
2340 OspfMplsTE
.inter_as
= mode
;
2341 /* Re-originate all InterAS-TEv2 LSA */
2342 for (ALL_LIST_ELEMENTS_RO(OspfMplsTE
.iflist
, node
,
2344 if (IS_INTER_AS(lp
->type
)) {
2346 lp
->type
|= FLOOD_AS
;
2348 lp
->type
|= FLOOD_AREA
;
2349 ospf_mpls_te_lsa_schedule(
2350 lp
, REORIGINATE_THIS_LSA
);
2355 "Please change Inter-AS support to disable first before going to mode %s\n",
2360 vty_out(vty
, "mpls-te has not been turned on\n");
2367 DEFUN (ospf_mpls_te_inter_as_as
,
2368 ospf_mpls_te_inter_as_cmd
,
2369 "mpls-te inter-as as",
2371 "Configure MPLS-TE Inter-AS support\n"
2372 "AS native mode self originate INTER_AS LSA with Type 11 (as flooding scope)\n")
2374 return set_inter_as_mode(vty
, "as", "");
2377 DEFUN (ospf_mpls_te_inter_as_area
,
2378 ospf_mpls_te_inter_as_area_cmd
,
2379 "mpls-te inter-as area <A.B.C.D|(0-4294967295)>",
2381 "Configure MPLS-TE Inter-AS support\n"
2382 "AREA native mode self originate INTER_AS LSA with Type 10 (area flooding scope)\n"
2383 "OSPF area ID in IP format\n"
2384 "OSPF area ID as decimal value\n")
2386 int idx_ipv4_number
= 3;
2387 return set_inter_as_mode(vty
, "area", argv
[idx_ipv4_number
]->arg
);
2390 DEFUN (no_ospf_mpls_te_inter_as
,
2391 no_ospf_mpls_te_inter_as_cmd
,
2392 "no mpls-te inter-as",
2395 "Disable MPLS-TE Inter-AS support\n")
2398 struct listnode
*node
, *nnode
;
2399 struct mpls_te_link
*lp
;
2401 if (IS_DEBUG_OSPF_EVENT
)
2402 zlog_debug("MPLS-TE: Inter-AS support OFF");
2404 if ((OspfMplsTE
.enabled
) && (OspfMplsTE
.inter_as
!= Off
)) {
2405 OspfMplsTE
.inter_as
= Off
;
2406 /* Flush all Inter-AS LSA */
2407 for (ALL_LIST_ELEMENTS(OspfMplsTE
.iflist
, node
, nnode
, lp
))
2408 if (IS_INTER_AS(lp
->type
)
2409 && CHECK_FLAG(lp
->flags
, LPFLG_LSA_ENGAGED
))
2410 ospf_mpls_te_lsa_schedule(lp
, FLUSH_THIS_LSA
);
2413 /* Deregister the Callbacks for Inter-AS suport */
2414 ospf_mpls_te_unregister();
2419 DEFUN (show_ip_ospf_mpls_te_router
,
2420 show_ip_ospf_mpls_te_router_cmd
,
2421 "show ip ospf mpls-te router",
2425 "MPLS-TE information\n"
2426 "MPLS-TE Router parameters\n")
2428 if (OspfMplsTE
.enabled
) {
2429 vty_out(vty
, "--- MPLS-TE router parameters ---\n");
2431 if (ntohs(OspfMplsTE
.router_addr
.header
.type
) != 0)
2432 show_vty_router_addr(vty
,
2433 &OspfMplsTE
.router_addr
.header
);
2435 vty_out(vty
, " N/A\n");
2440 static void show_mpls_te_link_sub(struct vty
*vty
, struct interface
*ifp
)
2442 struct mpls_te_link
*lp
;
2444 if ((OspfMplsTE
.enabled
) && HAS_LINK_PARAMS(ifp
) && !if_is_loopback(ifp
)
2446 && ((lp
= lookup_linkparams_by_ifp(ifp
)) != NULL
)) {
2447 /* Continue only if interface is not passive or support Inter-AS
2449 if (!(ospf_oi_count(ifp
) > 0)) {
2450 if (IS_INTER_AS(lp
->type
)) {
2452 "-- Inter-AS TEv2 link parameters for %s --\n",
2455 /* MPLS-TE is not activate on this interface */
2456 /* or this interface is passive and Inter-AS
2457 * TEv2 is not activate */
2459 " %s: MPLS-TE is disabled on this interface\n",
2464 vty_out(vty
, "-- MPLS-TE link parameters for %s --\n",
2468 if (TLV_TYPE(lp
->link_type
) != 0)
2469 show_vty_link_subtlv_link_type(vty
,
2470 &lp
->link_type
.header
);
2471 if (TLV_TYPE(lp
->link_id
) != 0)
2472 show_vty_link_subtlv_link_id(vty
, &lp
->link_id
.header
);
2473 if (TLV_TYPE(lp
->lclif_ipaddr
) != 0)
2474 show_vty_link_subtlv_lclif_ipaddr(
2475 vty
, &lp
->lclif_ipaddr
.header
);
2476 if (TLV_TYPE(lp
->rmtif_ipaddr
) != 0)
2477 show_vty_link_subtlv_rmtif_ipaddr(
2478 vty
, &lp
->rmtif_ipaddr
.header
);
2479 if (TLV_TYPE(lp
->rip
) != 0)
2480 show_vty_link_subtlv_rip(vty
, &lp
->rip
.header
);
2481 if (TLV_TYPE(lp
->ras
) != 0)
2482 show_vty_link_subtlv_ras(vty
, &lp
->ras
.header
);
2483 if (TLV_TYPE(lp
->te_metric
) != 0)
2484 show_vty_link_subtlv_te_metric(vty
,
2485 &lp
->te_metric
.header
);
2486 if (TLV_TYPE(lp
->max_bw
) != 0)
2487 show_vty_link_subtlv_max_bw(vty
, &lp
->max_bw
.header
);
2488 if (TLV_TYPE(lp
->max_rsv_bw
) != 0)
2489 show_vty_link_subtlv_max_rsv_bw(vty
,
2490 &lp
->max_rsv_bw
.header
);
2491 if (TLV_TYPE(lp
->unrsv_bw
) != 0)
2492 show_vty_link_subtlv_unrsv_bw(vty
,
2493 &lp
->unrsv_bw
.header
);
2494 if (TLV_TYPE(lp
->rsc_clsclr
) != 0)
2495 show_vty_link_subtlv_rsc_clsclr(vty
,
2496 &lp
->rsc_clsclr
.header
);
2497 if (TLV_TYPE(lp
->av_delay
) != 0)
2498 show_vty_link_subtlv_av_delay(vty
,
2499 &lp
->av_delay
.header
);
2500 if (TLV_TYPE(lp
->mm_delay
) != 0)
2501 show_vty_link_subtlv_mm_delay(vty
,
2502 &lp
->mm_delay
.header
);
2503 if (TLV_TYPE(lp
->delay_var
) != 0)
2504 show_vty_link_subtlv_delay_var(vty
,
2505 &lp
->delay_var
.header
);
2506 if (TLV_TYPE(lp
->pkt_loss
) != 0)
2507 show_vty_link_subtlv_pkt_loss(vty
,
2508 &lp
->pkt_loss
.header
);
2509 if (TLV_TYPE(lp
->res_bw
) != 0)
2510 show_vty_link_subtlv_res_bw(vty
, &lp
->res_bw
.header
);
2511 if (TLV_TYPE(lp
->ava_bw
) != 0)
2512 show_vty_link_subtlv_ava_bw(vty
, &lp
->ava_bw
.header
);
2513 if (TLV_TYPE(lp
->use_bw
) != 0)
2514 show_vty_link_subtlv_use_bw(vty
, &lp
->use_bw
.header
);
2515 vty_out(vty
, "---------------\n\n");
2517 vty_out(vty
, " %s: MPLS-TE is disabled on this interface\n",
2524 DEFUN (show_ip_ospf_mpls_te_link
,
2525 show_ip_ospf_mpls_te_link_cmd
,
2526 "show ip ospf [vrf <NAME|all>] mpls-te interface [INTERFACE]",
2532 "MPLS-TE information\n"
2533 "Interface information\n"
2537 int idx_interface
= 5;
2538 struct interface
*ifp
;
2539 struct listnode
*node
;
2540 char *vrf_name
= NULL
;
2544 struct ospf
*ospf
= NULL
;
2546 if (argv_find(argv
, argc
, "vrf", &idx_vrf
)) {
2547 vrf_name
= argv
[idx_vrf
+ 1]->arg
;
2548 all_vrf
= strmatch(vrf_name
, "all");
2551 /* vrf input is provided could be all or specific vrf*/
2554 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
2555 if (!ospf
->oi_running
)
2557 vrf
= vrf_lookup_by_id(ospf
->vrf_id
);
2558 FOR_ALL_INTERFACES (vrf
, ifp
)
2559 show_mpls_te_link_sub(vty
, ifp
);
2563 ospf
= ospf_lookup_by_inst_name(inst
, vrf_name
);
2564 if (ospf
== NULL
|| !ospf
->oi_running
)
2566 vrf
= vrf_lookup_by_id(ospf
->vrf_id
);
2567 FOR_ALL_INTERFACES (vrf
, ifp
)
2568 show_mpls_te_link_sub(vty
, ifp
);
2571 /* Show All Interfaces. */
2573 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
2574 if (!ospf
->oi_running
)
2576 vrf
= vrf_lookup_by_id(ospf
->vrf_id
);
2577 FOR_ALL_INTERFACES (vrf
, ifp
)
2578 show_mpls_te_link_sub(vty
, ifp
);
2581 /* Interface name is specified. */
2583 ifp
= if_lookup_by_name_all_vrf(argv
[idx_interface
]->arg
);
2585 vty_out(vty
, "No such interface name\n");
2587 show_mpls_te_link_sub(vty
, ifp
);
2593 static void ospf_mpls_te_register_vty(void)
2595 install_element(VIEW_NODE
, &show_ip_ospf_mpls_te_router_cmd
);
2596 install_element(VIEW_NODE
, &show_ip_ospf_mpls_te_link_cmd
);
2598 install_element(OSPF_NODE
, &ospf_mpls_te_on_cmd
);
2599 install_element(OSPF_NODE
, &no_ospf_mpls_te_cmd
);
2600 install_element(OSPF_NODE
, &ospf_mpls_te_router_addr_cmd
);
2601 install_element(OSPF_NODE
, &ospf_mpls_te_inter_as_cmd
);
2602 install_element(OSPF_NODE
, &ospf_mpls_te_inter_as_area_cmd
);
2603 install_element(OSPF_NODE
, &no_ospf_mpls_te_inter_as_cmd
);