2 * This is an implementation of RFC3630
3 * Copyright (C) 2001 KDD R&D Laboratories, Inc.
4 * http://www.kddlabs.co.jp/
6 * Copyright (C) 2012 Orange Labs
7 * http://www.orange.com
9 * This file is part of GNU Zebra.
11 * GNU Zebra is free software; you can redistribute it and/or modify it
12 * under the terms of the GNU General Public License as published by the
13 * Free Software Foundation; either version 2, or (at your option) any
16 * GNU Zebra is distributed in the hope that it will be useful, but
17 * WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 * General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with GNU Zebra; see the file COPYING. If not, write to the Free
23 * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
27 /* Add support of RFC7471 */
28 /* Add support of RFC5392, RFC6827 */
45 #include "sockunion.h" /* for inet_aton() */
48 #include "ospfd/ospfd.h"
49 #include "ospfd/ospf_interface.h"
50 #include "ospfd/ospf_ism.h"
51 #include "ospfd/ospf_asbr.h"
52 #include "ospfd/ospf_lsa.h"
53 #include "ospfd/ospf_lsdb.h"
54 #include "ospfd/ospf_neighbor.h"
55 #include "ospfd/ospf_nsm.h"
56 #include "ospfd/ospf_flood.h"
57 #include "ospfd/ospf_packet.h"
58 #include "ospfd/ospf_spf.h"
59 #include "ospfd/ospf_dump.h"
60 #include "ospfd/ospf_route.h"
61 #include "ospfd/ospf_ase.h"
62 #include "ospfd/ospf_zebra.h"
63 #include "ospfd/ospf_te.h"
64 #include "ospfd/ospf_vty.h"
67 * Global variable to manage Opaque-LSA/MPLS-TE on this node.
68 * Note that all parameter values are stored in network byte order.
70 struct ospf_mpls_te OspfMplsTE
;
72 const char *mode2text
[] = {"Disable", "AS", "Area", "Emulate"};
74 enum oifstate
{ OI_ANY
, OI_DOWN
, OI_UP
};
76 /*------------------------------------------------------------------------*
77 * Followings are initialize/terminate functions for MPLS-TE handling.
78 *------------------------------------------------------------------------*/
80 static int ospf_mpls_te_new_if(struct interface
*ifp
);
81 static int ospf_mpls_te_del_if(struct interface
*ifp
);
82 static void ospf_mpls_te_ism_change(struct ospf_interface
*oi
, int old_status
);
83 static void ospf_mpls_te_nsm_change(struct ospf_neighbor
*nbr
, int old_status
);
84 static void ospf_mpls_te_config_write_router(struct vty
*vty
);
85 static void ospf_mpls_te_show_info(struct vty
*vty
, struct ospf_lsa
*lsa
);
86 static int ospf_mpls_te_lsa_originate_area(void *arg
);
87 static int ospf_mpls_te_lsa_originate_as(void *arg
);
88 static struct ospf_lsa
*ospf_mpls_te_lsa_refresh(struct ospf_lsa
*lsa
);
90 static void del_mpls_te_link(void *val
);
91 static void ospf_mpls_te_register_vty(void);
93 int ospf_mpls_te_init(void)
97 rc
= ospf_register_opaque_functab(
98 OSPF_OPAQUE_AREA_LSA
, OPAQUE_TYPE_TRAFFIC_ENGINEERING_LSA
,
99 ospf_mpls_te_new_if
, ospf_mpls_te_del_if
,
100 ospf_mpls_te_ism_change
, ospf_mpls_te_nsm_change
,
101 ospf_mpls_te_config_write_router
,
102 NULL
, /*ospf_mpls_te_config_write_if */
103 NULL
, /* ospf_mpls_te_config_write_debug */
104 ospf_mpls_te_show_info
, ospf_mpls_te_lsa_originate_area
,
105 ospf_mpls_te_lsa_refresh
, NULL
, /* ospf_mpls_te_new_lsa_hook */
106 NULL
/* ospf_mpls_te_del_lsa_hook */);
109 "ospf_mpls_te_init: Failed to register Traffic Engineering functions");
113 memset(&OspfMplsTE
, 0, sizeof(struct ospf_mpls_te
));
114 OspfMplsTE
.status
= disabled
;
115 OspfMplsTE
.inter_as
= Disable
;
116 OspfMplsTE
.iflist
= list_new();
117 OspfMplsTE
.iflist
->del
= del_mpls_te_link
;
119 ospf_mpls_te_register_vty();
125 /* Additional register for RFC5392 support */
126 static int ospf_mpls_te_register(enum inter_as_mode mode
)
131 if (OspfMplsTE
.inter_as
!= Disable
)
135 scope
= OSPF_OPAQUE_AS_LSA
;
137 scope
= OSPF_OPAQUE_AREA_LSA
;
139 rc
= ospf_register_opaque_functab(scope
, OPAQUE_TYPE_INTER_AS_LSA
, NULL
,
140 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
,
141 ospf_mpls_te_show_info
,
142 ospf_mpls_te_lsa_originate_as
,
143 ospf_mpls_te_lsa_refresh
, NULL
, NULL
);
147 "ospf_router_info_init: Failed to register Inter-AS functions");
154 static int ospf_mpls_te_unregister()
158 if (OspfMplsTE
.inter_as
== Disable
)
161 if (OspfMplsTE
.inter_as
== AS
)
162 scope
= OSPF_OPAQUE_AS_LSA
;
164 scope
= OSPF_OPAQUE_AREA_LSA
;
166 ospf_delete_opaque_functab(scope
, OPAQUE_TYPE_INTER_AS_LSA
);
171 void ospf_mpls_te_term(void)
173 list_delete(OspfMplsTE
.iflist
);
174 OspfMplsTE
.iflist
= NULL
;
176 ospf_delete_opaque_functab(OSPF_OPAQUE_AREA_LSA
,
177 OPAQUE_TYPE_TRAFFIC_ENGINEERING_LSA
);
178 OspfMplsTE
.status
= disabled
;
180 ospf_mpls_te_unregister();
181 OspfMplsTE
.inter_as
= Disable
;
186 /*------------------------------------------------------------------------*
187 * Followings are control functions for MPLS-TE parameters management.
188 *------------------------------------------------------------------------*/
190 static void del_mpls_te_link(void *val
)
192 XFREE(MTYPE_OSPF_MPLS_TE
, val
);
196 u_int32_t
get_mpls_te_instance_value(void)
198 static u_int32_t seqno
= 0;
200 if (seqno
< MAX_LEGAL_TE_INSTANCE_NUM
)
203 seqno
= 1; /* Avoid zero. */
208 static struct ospf_interface
*lookup_oi_by_ifp(struct interface
*ifp
,
209 struct ospf_area
*area
,
210 enum oifstate oifstate
)
212 struct ospf_interface
*oi
= NULL
;
213 struct route_node
*rn
;
215 for (rn
= route_top(IF_OIFS(ifp
)); rn
; rn
= route_next(rn
)) {
216 if ((oi
= rn
->info
) == NULL
)
223 if (ospf_if_is_enable(oi
))
227 if (!ospf_if_is_enable(oi
))
231 zlog_warn("lookup_oi_by_ifp: Unknown oifstate: %x",
236 if (area
== NULL
|| oi
->area
== area
)
243 static struct mpls_te_link
*lookup_linkparams_by_ifp(struct interface
*ifp
)
245 struct listnode
*node
, *nnode
;
246 struct mpls_te_link
*lp
;
248 for (ALL_LIST_ELEMENTS(OspfMplsTE
.iflist
, node
, nnode
, lp
))
255 static struct mpls_te_link
*lookup_linkparams_by_instance(struct ospf_lsa
*lsa
)
257 struct listnode
*node
;
258 struct mpls_te_link
*lp
;
259 unsigned int key
= GET_OPAQUE_ID(ntohl(lsa
->data
->id
.s_addr
));
261 for (ALL_LIST_ELEMENTS_RO(OspfMplsTE
.iflist
, node
, lp
))
262 if (lp
->instance
== key
)
265 zlog_warn("lookup_linkparams_by_instance: Entry not found: key(%x)",
270 static void ospf_mpls_te_foreach_area(void (*func
)(struct mpls_te_link
*lp
,
271 opcode_t sched_opcode
),
272 opcode_t sched_opcode
)
274 struct listnode
*node
, *nnode
;
275 struct listnode
*node2
;
276 struct mpls_te_link
*lp
;
277 struct ospf_area
*area
;
279 for (ALL_LIST_ELEMENTS(OspfMplsTE
.iflist
, node
, nnode
, lp
)) {
280 /* Skip Inter-AS TEv2 Links */
281 if (IS_INTER_AS(lp
->type
))
283 if ((area
= lp
->area
) == NULL
)
286 CHECK_FLAG(lp
->flags
, LPFLG_LOOKUP_DONE
) continue;
289 (*func
)(lp
, sched_opcode
);
291 for (node2
= listnextnode(node
); node2
;
292 node2
= listnextnode(node2
))
293 if ((lp
= listgetdata(node2
)) != NULL
)
294 if (lp
->area
!= NULL
)
295 if (IPV4_ADDR_SAME(&lp
->area
->area_id
,
301 for (ALL_LIST_ELEMENTS_RO(OspfMplsTE
.iflist
, node
, lp
))
302 if (lp
->area
!= NULL
)
303 UNSET_FLAG(lp
->flags
, LPFLG_LOOKUP_DONE
);
308 static void set_mpls_te_router_addr(struct in_addr ipv4
)
310 OspfMplsTE
.router_addr
.header
.type
= htons(TE_TLV_ROUTER_ADDR
);
311 OspfMplsTE
.router_addr
.header
.length
= htons(TE_LINK_SUBTLV_DEF_SIZE
);
312 OspfMplsTE
.router_addr
.value
= ipv4
;
316 static void set_linkparams_link_header(struct mpls_te_link
*lp
)
318 u_int16_t length
= 0;
320 /* TE_LINK_SUBTLV_LINK_TYPE */
321 if (ntohs(lp
->link_type
.header
.type
) != 0)
322 length
+= TLV_SIZE(&lp
->link_type
.header
);
324 /* TE_LINK_SUBTLV_LINK_ID */
325 if (ntohs(lp
->link_id
.header
.type
) != 0)
326 length
+= TLV_SIZE(&lp
->link_id
.header
);
328 /* TE_LINK_SUBTLV_LCLIF_IPADDR */
329 if (lp
->lclif_ipaddr
.header
.type
!= 0)
330 length
+= TLV_SIZE(&lp
->lclif_ipaddr
.header
);
332 /* TE_LINK_SUBTLV_RMTIF_IPADDR */
333 if (lp
->rmtif_ipaddr
.header
.type
!= 0)
334 length
+= TLV_SIZE(&lp
->rmtif_ipaddr
.header
);
336 /* TE_LINK_SUBTLV_TE_METRIC */
337 if (ntohs(lp
->te_metric
.header
.type
) != 0)
338 length
+= TLV_SIZE(&lp
->te_metric
.header
);
340 /* TE_LINK_SUBTLV_MAX_BW */
341 if (ntohs(lp
->max_bw
.header
.type
) != 0)
342 length
+= TLV_SIZE(&lp
->max_bw
.header
);
344 /* TE_LINK_SUBTLV_MAX_RSV_BW */
345 if (ntohs(lp
->max_rsv_bw
.header
.type
) != 0)
346 length
+= TLV_SIZE(&lp
->max_rsv_bw
.header
);
348 /* TE_LINK_SUBTLV_UNRSV_BW */
349 if (ntohs(lp
->unrsv_bw
.header
.type
) != 0)
350 length
+= TLV_SIZE(&lp
->unrsv_bw
.header
);
352 /* TE_LINK_SUBTLV_RSC_CLSCLR */
353 if (ntohs(lp
->rsc_clsclr
.header
.type
) != 0)
354 length
+= TLV_SIZE(&lp
->rsc_clsclr
.header
);
356 /* TE_LINK_SUBTLV_LLRI */
357 if (ntohs(lp
->llri
.header
.type
) != 0)
358 length
+= TLV_SIZE(&lp
->llri
.header
);
360 /* TE_LINK_SUBTLV_RIP */
361 if (ntohs(lp
->rip
.header
.type
) != 0)
362 length
+= TLV_SIZE(&lp
->rip
.header
);
364 /* TE_LINK_SUBTLV_RAS */
365 if (ntohs(lp
->ras
.header
.type
) != 0)
366 length
+= TLV_SIZE(&lp
->ras
.header
);
368 /* TE_LINK_SUBTLV_LRRID */
369 if (ntohs(lp
->lrrid
.header
.type
) != 0)
370 length
+= TLV_SIZE(&lp
->lrrid
.header
);
372 /* TE_LINK_SUBTLV_AV_DELAY */
373 if (ntohs(lp
->av_delay
.header
.type
) != 0)
374 length
+= TLV_SIZE(&lp
->av_delay
.header
);
376 /* TE_LINK_SUBTLV_MM_DELAY */
377 if (ntohs(lp
->mm_delay
.header
.type
) != 0)
378 length
+= TLV_SIZE(&lp
->mm_delay
.header
);
380 /* TE_LINK_SUBTLV_DELAY_VAR */
381 if (ntohs(lp
->delay_var
.header
.type
) != 0)
382 length
+= TLV_SIZE(&lp
->delay_var
.header
);
384 /* TE_LINK_SUBTLV_PKT_LOSS */
385 if (ntohs(lp
->pkt_loss
.header
.type
) != 0)
386 length
+= TLV_SIZE(&lp
->pkt_loss
.header
);
388 /* TE_LINK_SUBTLV_RES_BW */
389 if (ntohs(lp
->res_bw
.header
.type
) != 0)
390 length
+= TLV_SIZE(&lp
->res_bw
.header
);
392 /* TE_LINK_SUBTLV_AVA_BW */
393 if (ntohs(lp
->ava_bw
.header
.type
) != 0)
394 length
+= TLV_SIZE(&lp
->ava_bw
.header
);
396 /* TE_LINK_SUBTLV_USE_BW */
397 if (ntohs(lp
->use_bw
.header
.type
) != 0)
398 length
+= TLV_SIZE(&lp
->use_bw
.header
);
400 lp
->link_header
.header
.type
= htons(TE_TLV_LINK
);
401 lp
->link_header
.header
.length
= htons(length
);
406 static void set_linkparams_link_type(struct ospf_interface
*oi
,
407 struct mpls_te_link
*lp
)
409 lp
->link_type
.header
.type
= htons(TE_LINK_SUBTLV_LINK_TYPE
);
410 lp
->link_type
.header
.length
= htons(TE_LINK_SUBTLV_TYPE_SIZE
);
413 case OSPF_IFTYPE_POINTOPOINT
:
414 lp
->link_type
.link_type
.value
= LINK_TYPE_SUBTLV_VALUE_PTP
;
416 case OSPF_IFTYPE_BROADCAST
:
417 case OSPF_IFTYPE_NBMA
:
418 lp
->link_type
.link_type
.value
= LINK_TYPE_SUBTLV_VALUE_MA
;
421 /* Not supported yet. */ /* XXX */
422 lp
->link_type
.header
.type
= htons(0);
428 static void set_linkparams_link_id(struct ospf_interface
*oi
,
429 struct mpls_te_link
*lp
)
431 struct ospf_neighbor
*nbr
;
434 lp
->link_id
.header
.type
= htons(TE_LINK_SUBTLV_LINK_ID
);
435 lp
->link_id
.header
.length
= htons(TE_LINK_SUBTLV_DEF_SIZE
);
438 * The Link ID is identical to the contents of the Link ID field
439 * in the Router LSA for these link types.
442 case OSPF_IFTYPE_POINTOPOINT
:
443 /* Take the router ID of the neighbor. */
444 if ((nbr
= ospf_nbr_lookup_ptop(oi
))
445 && nbr
->state
== NSM_Full
) {
446 lp
->link_id
.value
= nbr
->router_id
;
450 case OSPF_IFTYPE_BROADCAST
:
451 case OSPF_IFTYPE_NBMA
:
452 /* Take the interface address of the designated router. */
453 if ((nbr
= ospf_nbr_lookup_by_addr(oi
->nbrs
, &DR(oi
))) == NULL
)
456 if (nbr
->state
== NSM_Full
457 || (IPV4_ADDR_SAME(&oi
->address
->u
.prefix4
, &DR(oi
))
458 && ospf_nbr_count(oi
, NSM_Full
) > 0)) {
459 lp
->link_id
.value
= DR(oi
);
464 /* Not supported yet. */ /* XXX */
465 lp
->link_id
.header
.type
= htons(0);
471 masklen2ip(oi
->address
->prefixlen
, &mask
);
472 lp
->link_id
.value
.s_addr
=
473 oi
->address
->u
.prefix4
.s_addr
& mask
.s_addr
;
478 static void set_linkparams_lclif_ipaddr(struct mpls_te_link
*lp
,
479 struct in_addr lclif
)
482 lp
->lclif_ipaddr
.header
.type
= htons(TE_LINK_SUBTLV_LCLIF_IPADDR
);
483 lp
->lclif_ipaddr
.header
.length
= htons(TE_LINK_SUBTLV_DEF_SIZE
);
484 lp
->lclif_ipaddr
.value
[0] = lclif
;
488 static void set_linkparams_rmtif_ipaddr(struct mpls_te_link
*lp
,
489 struct in_addr rmtif
)
492 lp
->rmtif_ipaddr
.header
.type
= htons(TE_LINK_SUBTLV_RMTIF_IPADDR
);
493 lp
->rmtif_ipaddr
.header
.length
= htons(TE_LINK_SUBTLV_DEF_SIZE
);
494 lp
->rmtif_ipaddr
.value
[0] = rmtif
;
498 static void set_linkparams_te_metric(struct mpls_te_link
*lp
,
501 lp
->te_metric
.header
.type
= htons(TE_LINK_SUBTLV_TE_METRIC
);
502 lp
->te_metric
.header
.length
= htons(TE_LINK_SUBTLV_DEF_SIZE
);
503 lp
->te_metric
.value
= htonl(te_metric
);
507 static void set_linkparams_max_bw(struct mpls_te_link
*lp
, float fp
)
509 lp
->max_bw
.header
.type
= htons(TE_LINK_SUBTLV_MAX_BW
);
510 lp
->max_bw
.header
.length
= htons(TE_LINK_SUBTLV_DEF_SIZE
);
511 lp
->max_bw
.value
= htonf(fp
);
515 static void set_linkparams_max_rsv_bw(struct mpls_te_link
*lp
, float fp
)
517 lp
->max_rsv_bw
.header
.type
= htons(TE_LINK_SUBTLV_MAX_RSV_BW
);
518 lp
->max_rsv_bw
.header
.length
= htons(TE_LINK_SUBTLV_DEF_SIZE
);
519 lp
->max_rsv_bw
.value
= htonf(fp
);
523 static void set_linkparams_unrsv_bw(struct mpls_te_link
*lp
, int priority
,
526 /* Note that TLV-length field is the size of array. */
527 lp
->unrsv_bw
.header
.type
= htons(TE_LINK_SUBTLV_UNRSV_BW
);
528 lp
->unrsv_bw
.header
.length
= htons(TE_LINK_SUBTLV_UNRSV_SIZE
);
529 lp
->unrsv_bw
.value
[priority
] = htonf(fp
);
533 static void set_linkparams_rsc_clsclr(struct mpls_te_link
*lp
,
534 u_int32_t classcolor
)
536 lp
->rsc_clsclr
.header
.type
= htons(TE_LINK_SUBTLV_RSC_CLSCLR
);
537 lp
->rsc_clsclr
.header
.length
= htons(TE_LINK_SUBTLV_DEF_SIZE
);
538 lp
->rsc_clsclr
.value
= htonl(classcolor
);
542 static void set_linkparams_inter_as(struct mpls_te_link
*lp
,
543 struct in_addr addr
, u_int32_t as
)
546 /* Set the Remote ASBR IP address and then the associated AS number */
547 lp
->rip
.header
.type
= htons(TE_LINK_SUBTLV_RIP
);
548 lp
->rip
.header
.length
= htons(TE_LINK_SUBTLV_DEF_SIZE
);
549 lp
->rip
.value
= addr
;
551 lp
->ras
.header
.type
= htons(TE_LINK_SUBTLV_RAS
);
552 lp
->ras
.header
.length
= htons(TE_LINK_SUBTLV_DEF_SIZE
);
553 lp
->ras
.value
= htonl(as
);
556 static void unset_linkparams_inter_as(struct mpls_te_link
*lp
)
559 /* Reset the Remote ASBR IP address and then the associated AS number */
560 lp
->rip
.header
.type
= htons(0);
561 lp
->rip
.header
.length
= htons(0);
562 lp
->rip
.value
.s_addr
= htonl(0);
564 lp
->ras
.header
.type
= htons(0);
565 lp
->ras
.header
.length
= htons(0);
566 lp
->ras
.value
= htonl(0);
569 void set_linkparams_llri(struct mpls_te_link
*lp
, u_int32_t local
,
573 lp
->llri
.header
.type
= htons(TE_LINK_SUBTLV_LLRI
);
574 lp
->llri
.header
.length
= htons(TE_LINK_SUBTLV_LLRI_SIZE
);
575 lp
->llri
.local
= htonl(local
);
576 lp
->llri
.remote
= htonl(remote
);
579 void set_linkparams_lrrid(struct mpls_te_link
*lp
, struct in_addr local
,
580 struct in_addr remote
)
583 lp
->lrrid
.header
.type
= htons(TE_LINK_SUBTLV_LRRID
);
584 lp
->lrrid
.header
.length
= htons(TE_LINK_SUBTLV_LRRID_SIZE
);
585 lp
->lrrid
.local
.s_addr
= local
.s_addr
;
586 lp
->lrrid
.remote
.s_addr
= remote
.s_addr
;
589 static void set_linkparams_av_delay(struct mpls_te_link
*lp
, u_int32_t delay
,
593 /* Note that TLV-length field is the size of array. */
594 lp
->av_delay
.header
.type
= htons(TE_LINK_SUBTLV_AV_DELAY
);
595 lp
->av_delay
.header
.length
= htons(TE_LINK_SUBTLV_DEF_SIZE
);
596 tmp
= delay
& TE_EXT_MASK
;
598 tmp
|= TE_EXT_ANORMAL
;
599 lp
->av_delay
.value
= htonl(tmp
);
603 static void set_linkparams_mm_delay(struct mpls_te_link
*lp
, u_int32_t low
,
604 u_int32_t high
, u_char anormal
)
607 /* Note that TLV-length field is the size of array. */
608 lp
->mm_delay
.header
.type
= htons(TE_LINK_SUBTLV_MM_DELAY
);
609 lp
->mm_delay
.header
.length
= htons(TE_LINK_SUBTLV_MM_DELAY_SIZE
);
610 tmp
= low
& TE_EXT_MASK
;
612 tmp
|= TE_EXT_ANORMAL
;
613 lp
->mm_delay
.low
= htonl(tmp
);
614 lp
->mm_delay
.high
= htonl(high
);
618 static void set_linkparams_delay_var(struct mpls_te_link
*lp
, u_int32_t jitter
)
620 /* Note that TLV-length field is the size of array. */
621 lp
->delay_var
.header
.type
= htons(TE_LINK_SUBTLV_DELAY_VAR
);
622 lp
->delay_var
.header
.length
= htons(TE_LINK_SUBTLV_DEF_SIZE
);
623 lp
->delay_var
.value
= htonl(jitter
& TE_EXT_MASK
);
627 static void set_linkparams_pkt_loss(struct mpls_te_link
*lp
, u_int32_t loss
,
631 /* Note that TLV-length field is the size of array. */
632 lp
->pkt_loss
.header
.type
= htons(TE_LINK_SUBTLV_PKT_LOSS
);
633 lp
->pkt_loss
.header
.length
= htons(TE_LINK_SUBTLV_DEF_SIZE
);
634 tmp
= loss
& TE_EXT_MASK
;
636 tmp
|= TE_EXT_ANORMAL
;
637 lp
->pkt_loss
.value
= htonl(tmp
);
641 static void set_linkparams_res_bw(struct mpls_te_link
*lp
, float fp
)
643 /* Note that TLV-length field is the size of array. */
644 lp
->res_bw
.header
.type
= htons(TE_LINK_SUBTLV_RES_BW
);
645 lp
->res_bw
.header
.length
= htons(TE_LINK_SUBTLV_DEF_SIZE
);
646 lp
->res_bw
.value
= htonf(fp
);
650 static void set_linkparams_ava_bw(struct mpls_te_link
*lp
, float fp
)
652 /* Note that TLV-length field is the size of array. */
653 lp
->ava_bw
.header
.type
= htons(TE_LINK_SUBTLV_AVA_BW
);
654 lp
->ava_bw
.header
.length
= htons(TE_LINK_SUBTLV_DEF_SIZE
);
655 lp
->ava_bw
.value
= htonf(fp
);
659 static void set_linkparams_use_bw(struct mpls_te_link
*lp
, float fp
)
661 /* Note that TLV-length field is the size of array. */
662 lp
->use_bw
.header
.type
= htons(TE_LINK_SUBTLV_USE_BW
);
663 lp
->use_bw
.header
.length
= htons(TE_LINK_SUBTLV_DEF_SIZE
);
664 lp
->use_bw
.value
= htonf(fp
);
668 /* Update TE parameters from Interface */
669 static void update_linkparams(struct mpls_te_link
*lp
)
672 struct interface
*ifp
;
674 /* Get the Interface structure */
675 if ((ifp
= lp
->ifp
) == NULL
) {
676 if (IS_DEBUG_OSPF_TE
)
678 "OSPF MPLS-TE: Abort update TE parameters: no interface associated to Link Parameters");
681 if (!HAS_LINK_PARAMS(ifp
)) {
682 if (IS_DEBUG_OSPF_TE
)
684 "OSPF MPLS-TE: Abort update TE parameters: no Link Parameters for interface");
688 /* RFC3630 metrics */
689 if (IS_PARAM_SET(ifp
->link_params
, LP_ADM_GRP
))
690 set_linkparams_rsc_clsclr(lp
, ifp
->link_params
->admin_grp
);
692 TLV_TYPE(lp
->rsc_clsclr
) = 0;
694 if (IS_PARAM_SET(ifp
->link_params
, LP_MAX_BW
))
695 set_linkparams_max_bw(lp
, ifp
->link_params
->max_bw
);
697 TLV_TYPE(lp
->max_bw
) = 0;
699 if (IS_PARAM_SET(ifp
->link_params
, LP_MAX_RSV_BW
))
700 set_linkparams_max_rsv_bw(lp
, ifp
->link_params
->max_rsv_bw
);
702 TLV_TYPE(lp
->max_rsv_bw
) = 0;
704 if (IS_PARAM_SET(ifp
->link_params
, LP_UNRSV_BW
))
705 for (i
= 0; i
< MAX_CLASS_TYPE
; i
++)
706 set_linkparams_unrsv_bw(lp
, i
,
707 ifp
->link_params
->unrsv_bw
[i
]);
709 TLV_TYPE(lp
->unrsv_bw
) = 0;
711 if (IS_PARAM_SET(ifp
->link_params
, LP_TE_METRIC
))
712 set_linkparams_te_metric(lp
, ifp
->link_params
->te_metric
);
714 TLV_TYPE(lp
->te_metric
) = 0;
716 /* TE metric Extensions */
717 if (IS_PARAM_SET(ifp
->link_params
, LP_DELAY
))
718 set_linkparams_av_delay(lp
, ifp
->link_params
->av_delay
, 0);
720 TLV_TYPE(lp
->av_delay
) = 0;
722 if (IS_PARAM_SET(ifp
->link_params
, LP_MM_DELAY
))
723 set_linkparams_mm_delay(lp
, ifp
->link_params
->min_delay
,
724 ifp
->link_params
->max_delay
, 0);
726 TLV_TYPE(lp
->mm_delay
) = 0;
728 if (IS_PARAM_SET(ifp
->link_params
, LP_DELAY_VAR
))
729 set_linkparams_delay_var(lp
, ifp
->link_params
->delay_var
);
731 TLV_TYPE(lp
->delay_var
) = 0;
733 if (IS_PARAM_SET(ifp
->link_params
, LP_PKT_LOSS
))
734 set_linkparams_pkt_loss(lp
, ifp
->link_params
->pkt_loss
, 0);
736 TLV_TYPE(lp
->pkt_loss
) = 0;
738 if (IS_PARAM_SET(ifp
->link_params
, LP_RES_BW
))
739 set_linkparams_res_bw(lp
, ifp
->link_params
->res_bw
);
741 TLV_TYPE(lp
->res_bw
) = 0;
743 if (IS_PARAM_SET(ifp
->link_params
, LP_AVA_BW
))
744 set_linkparams_ava_bw(lp
, ifp
->link_params
->ava_bw
);
746 TLV_TYPE(lp
->ava_bw
) = 0;
748 if (IS_PARAM_SET(ifp
->link_params
, LP_USE_BW
))
749 set_linkparams_use_bw(lp
, ifp
->link_params
->use_bw
);
751 TLV_TYPE(lp
->use_bw
) = 0;
754 if (IS_PARAM_SET(ifp
->link_params
, LP_RMT_AS
)) {
755 /* Flush LSA if it engaged and was previously a STD_TE one */
756 if (IS_STD_TE(lp
->type
)
757 && CHECK_FLAG(lp
->flags
, LPFLG_LSA_ENGAGED
)) {
758 if (IS_DEBUG_OSPF_TE
)
760 "OSPF MPLS-TE Update IF: Switch from Standard LSA to INTER-AS for %s[%d/%d]",
761 ifp
->name
, lp
->flags
, lp
->type
);
763 ospf_mpls_te_lsa_schedule(lp
, FLUSH_THIS_LSA
);
764 /* Then, switch it to INTER-AS */
765 if (OspfMplsTE
.inter_as
== AS
)
766 lp
->flags
= INTER_AS
| FLOOD_AS
;
768 lp
->flags
= INTER_AS
| FLOOD_AREA
;
769 lp
->area
= ospf_area_lookup_by_area_id(
771 OspfMplsTE
.interas_areaid
);
774 set_linkparams_inter_as(lp
, ifp
->link_params
->rmt_ip
,
775 ifp
->link_params
->rmt_as
);
777 if (IS_DEBUG_OSPF_TE
)
779 "OSPF MPLS-TE Update IF: Switch from INTER-AS LSA to Standard for %s[%d/%d]",
780 ifp
->name
, lp
->flags
, lp
->type
);
782 /* reset inter-as TE params */
783 /* Flush LSA if it engaged and was previously an INTER_AS one */
784 if (IS_INTER_AS(lp
->type
)
785 && CHECK_FLAG(lp
->flags
, LPFLG_LSA_ENGAGED
)) {
786 ospf_mpls_te_lsa_schedule(lp
, FLUSH_THIS_LSA
);
787 /* Then, switch it to Standard TE */
788 lp
->flags
= STD_TE
| FLOOD_AREA
;
790 unset_linkparams_inter_as(lp
);
794 static void initialize_linkparams(struct mpls_te_link
*lp
)
796 struct interface
*ifp
= lp
->ifp
;
797 struct ospf_interface
*oi
;
799 if (IS_DEBUG_OSPF_TE
)
801 "MPLS-TE(initialize_linkparams) Initialize Link Parameters for interface %s",
804 if ((oi
= lookup_oi_by_ifp(ifp
, NULL
, OI_ANY
)) == NULL
) {
806 "MPLS-TE(initialize_linkparams) Could not find corresponding OSPF Interface for %s",
812 * Try to set initial values those can be derived from
813 * zebra-interface information.
815 set_linkparams_link_type(oi
, lp
);
817 /* Set local IP addr */
818 set_linkparams_lclif_ipaddr(lp
, oi
->address
->u
.prefix4
);
820 /* Set Remote IP addr if Point to Point Interface */
821 if (oi
->type
== LINK_TYPE_SUBTLV_VALUE_PTP
) {
822 struct prefix
*pref
= CONNECTED_PREFIX(oi
->connected
);
824 set_linkparams_rmtif_ipaddr(lp
, pref
->u
.prefix4
);
827 /* Keep Area information in combination with link parameters. */
833 static int is_mandated_params_set(struct mpls_te_link
*lp
)
837 if (ntohs(OspfMplsTE
.router_addr
.header
.type
) == 0) {
839 "MPLS-TE(is_mandated_params_set) Missing Router Address");
843 if (ntohs(lp
->link_type
.header
.type
) == 0) {
844 zlog_warn("MPLS-TE(is_mandated_params_set) Missing Link Type");
848 if (!IS_INTER_AS(lp
->type
) && (ntohs(lp
->link_id
.header
.type
) == 0)) {
849 zlog_warn("MPLS-TE(is_mandated_params_set) Missing Link ID");
858 /*------------------------------------------------------------------------*
859 * Followings are callback functions against generic Opaque-LSAs handling.
860 *------------------------------------------------------------------------*/
862 static int ospf_mpls_te_new_if(struct interface
*ifp
)
864 struct mpls_te_link
*new;
867 if (IS_DEBUG_OSPF_TE
)
869 "MPLS-TE(ospf_mpls_te_new_if) Add new %s interface %s to MPLS-TE list",
870 ifp
->link_params
? "Active" : "Inactive", ifp
->name
);
872 if (lookup_linkparams_by_ifp(ifp
) != NULL
) {
873 zlog_warn("ospf_mpls_te_new_if: ifp(%p) already in use?",
875 rc
= 0; /* Do nothing here. */
879 new = XCALLOC(MTYPE_OSPF_MPLS_TE
, sizeof(struct mpls_te_link
));
881 zlog_warn("ospf_mpls_te_new_if: XMALLOC: %s",
882 safe_strerror(errno
));
886 new->instance
= get_mpls_te_instance_value();
888 /* By default TE-Link is RFC3630 compatible flooding in Area and not
890 /* This default behavior will be adapted with call to
891 * ospf_mpls_te_update_if() */
892 new->type
= STD_TE
| FLOOD_AREA
;
893 new->flags
= LPFLG_LSA_INACTIVE
;
895 /* Initialize Link Parameters from Interface */
896 initialize_linkparams(new);
898 /* Set TE Parameters from Interface */
899 update_linkparams(new);
901 /* Add Link Parameters structure to the list */
902 listnode_add(OspfMplsTE
.iflist
, new);
904 if (IS_DEBUG_OSPF_TE
)
906 "OSPF MPLS-TE New IF: Add new LP context for %s[%d/%d]",
907 ifp
->name
, new->flags
, new->type
);
909 /* Schedule Opaque-LSA refresh. */ /* XXX */
916 static int ospf_mpls_te_del_if(struct interface
*ifp
)
918 struct mpls_te_link
*lp
;
921 if ((lp
= lookup_linkparams_by_ifp(ifp
)) != NULL
) {
922 struct list
*iflist
= OspfMplsTE
.iflist
;
924 /* Dequeue listnode entry from the list. */
925 listnode_delete(iflist
, lp
);
927 /* Avoid misjudgement in the next lookup. */
928 if (listcount(iflist
) == 0)
929 iflist
->head
= iflist
->tail
= NULL
;
931 XFREE(MTYPE_OSPF_MPLS_TE
, lp
);
934 /* Schedule Opaque-LSA refresh. */ /* XXX */
941 /* Main initialization / update function of the MPLS TE Link context */
943 /* Call when interface TE Link parameters are modified */
944 void ospf_mpls_te_update_if(struct interface
*ifp
)
946 struct mpls_te_link
*lp
;
948 if (IS_DEBUG_OSPF_TE
)
950 "OSPF MPLS-TE: Update LSA parameters for interface %s [%s]",
951 ifp
->name
, HAS_LINK_PARAMS(ifp
) ? "ON" : "OFF");
953 /* Get Link context from interface */
954 if ((lp
= lookup_linkparams_by_ifp(ifp
)) == NULL
) {
956 "OSPF MPLS-TE Update: Did not find Link Parameters context for interface %s",
961 /* Fulfill MPLS-TE Link TLV from Interface TE Link parameters */
962 if (HAS_LINK_PARAMS(ifp
)) {
963 SET_FLAG(lp
->flags
, LPFLG_LSA_ACTIVE
);
965 /* Update TE parameters */
966 update_linkparams(lp
);
968 /* Finally Re-Originate or Refresh Opaque LSA if MPLS_TE is
970 if (OspfMplsTE
.status
== enabled
)
971 if (lp
->area
!= NULL
) {
973 CHECK_FLAG(lp
->flags
, LPFLG_LSA_ENGAGED
)
974 ospf_mpls_te_lsa_schedule(lp
, REFRESH_THIS_LSA
);
975 else ospf_mpls_te_lsa_schedule(
976 lp
, REORIGINATE_THIS_LSA
);
979 /* If MPLS TE is disable on this interface, flush LSA if it is
982 CHECK_FLAG(lp
->flags
, LPFLG_LSA_ENGAGED
)
983 ospf_mpls_te_lsa_schedule(lp
, FLUSH_THIS_LSA
);
985 /* Reset Activity flag */
986 lp
->flags
= LPFLG_LSA_INACTIVE
;
992 static void ospf_mpls_te_ism_change(struct ospf_interface
*oi
, int old_state
)
994 struct te_link_subtlv_link_type old_type
;
995 struct te_link_subtlv_link_id old_id
;
996 struct mpls_te_link
*lp
;
998 if ((lp
= lookup_linkparams_by_ifp(oi
->ifp
)) == NULL
) {
1000 "ospf_mpls_te_ism_change: Cannot get linkparams from OI(%s)?",
1005 if (oi
->area
== NULL
|| oi
->area
->ospf
== NULL
) {
1007 "ospf_mpls_te_ism_change: Cannot refer to OSPF from OI(%s)?",
1012 if ((lp
->area
!= NULL
1013 && !IPV4_ADDR_SAME(&lp
->area
->area_id
, &oi
->area
->area_id
))
1014 || (lp
->area
!= NULL
&& oi
->area
== NULL
)) {
1015 /* How should we consider this case? */
1017 "MPLS-TE: Area for OI(%s) has changed to [%s], flush previous LSAs",
1019 oi
->area
? inet_ntoa(oi
->area
->area_id
) : "N/A");
1020 ospf_mpls_te_lsa_schedule(lp
, FLUSH_THIS_LSA
);
1023 /* Keep Area information in combination with linkparams. */
1024 lp
->area
= oi
->area
;
1026 /* Keep interface MPLS-TE status */
1027 lp
->flags
= HAS_LINK_PARAMS(oi
->ifp
);
1029 switch (oi
->state
) {
1030 case ISM_PointToPoint
:
1034 old_type
= lp
->link_type
;
1035 old_id
= lp
->link_id
;
1037 /* Set Link type, Link ID, Local and Remote IP addr */
1038 set_linkparams_link_type(oi
, lp
);
1039 set_linkparams_link_id(oi
, lp
);
1040 set_linkparams_lclif_ipaddr(lp
, oi
->address
->u
.prefix4
);
1042 if (oi
->type
== LINK_TYPE_SUBTLV_VALUE_PTP
) {
1043 struct prefix
*pref
= CONNECTED_PREFIX(oi
->connected
);
1045 set_linkparams_rmtif_ipaddr(lp
,
1049 /* Update TE parameters */
1050 update_linkparams(lp
);
1052 /* Try to Schedule LSA */
1053 if ((ntohs(old_type
.header
.type
)
1054 != ntohs(lp
->link_type
.header
.type
)
1055 || old_type
.link_type
.value
1056 != lp
->link_type
.link_type
.value
)
1057 || (ntohs(old_id
.header
.type
)
1058 != ntohs(lp
->link_id
.header
.type
)
1059 || ntohl(old_id
.value
.s_addr
)
1060 != ntohl(lp
->link_id
.value
.s_addr
))) {
1062 CHECK_FLAG(lp
->flags
, LPFLG_LSA_ENGAGED
)
1063 ospf_mpls_te_lsa_schedule(lp
, REFRESH_THIS_LSA
);
1064 else ospf_mpls_te_lsa_schedule(lp
,
1065 REORIGINATE_THIS_LSA
);
1069 lp
->link_type
.header
.type
= htons(0);
1070 lp
->link_id
.header
.type
= htons(0);
1073 CHECK_FLAG(lp
->flags
, LPFLG_LSA_ENGAGED
)
1074 ospf_mpls_te_lsa_schedule(lp
, FLUSH_THIS_LSA
);
1082 static void ospf_mpls_te_nsm_change(struct ospf_neighbor
*nbr
, int old_state
)
1084 /* Nothing to do here */
1088 /*------------------------------------------------------------------------*
1089 * Followings are OSPF protocol processing functions for MPLS-TE.
1090 *------------------------------------------------------------------------*/
1092 static void build_tlv_header(struct stream
*s
, struct te_tlv_header
*tlvh
)
1094 stream_put(s
, tlvh
, sizeof(struct te_tlv_header
));
1098 static void build_router_tlv(struct stream
*s
)
1100 struct te_tlv_header
*tlvh
= &OspfMplsTE
.router_addr
.header
;
1101 if (ntohs(tlvh
->type
) != 0) {
1102 build_tlv_header(s
, tlvh
);
1103 stream_put(s
, tlvh
+ 1, TLV_BODY_SIZE(tlvh
));
1108 static void build_link_subtlv(struct stream
*s
, struct te_tlv_header
*tlvh
)
1111 if ((tlvh
!= NULL
) && (ntohs(tlvh
->type
) != 0)) {
1112 build_tlv_header(s
, tlvh
);
1113 stream_put(s
, tlvh
+ 1, TLV_BODY_SIZE(tlvh
));
1118 static void build_link_tlv(struct stream
*s
, struct mpls_te_link
*lp
)
1120 set_linkparams_link_header(lp
);
1121 build_tlv_header(s
, &lp
->link_header
.header
);
1123 build_link_subtlv(s
, &lp
->link_type
.header
);
1124 build_link_subtlv(s
, &lp
->link_id
.header
);
1125 build_link_subtlv(s
, &lp
->lclif_ipaddr
.header
);
1126 build_link_subtlv(s
, &lp
->rmtif_ipaddr
.header
);
1127 build_link_subtlv(s
, &lp
->te_metric
.header
);
1128 build_link_subtlv(s
, &lp
->max_bw
.header
);
1129 build_link_subtlv(s
, &lp
->max_rsv_bw
.header
);
1130 build_link_subtlv(s
, &lp
->unrsv_bw
.header
);
1131 build_link_subtlv(s
, &lp
->rsc_clsclr
.header
);
1132 build_link_subtlv(s
, &lp
->lrrid
.header
);
1133 build_link_subtlv(s
, &lp
->llri
.header
);
1134 build_link_subtlv(s
, &lp
->rip
.header
);
1135 build_link_subtlv(s
, &lp
->ras
.header
);
1136 build_link_subtlv(s
, &lp
->av_delay
.header
);
1137 build_link_subtlv(s
, &lp
->mm_delay
.header
);
1138 build_link_subtlv(s
, &lp
->delay_var
.header
);
1139 build_link_subtlv(s
, &lp
->pkt_loss
.header
);
1140 build_link_subtlv(s
, &lp
->res_bw
.header
);
1141 build_link_subtlv(s
, &lp
->ava_bw
.header
);
1142 build_link_subtlv(s
, &lp
->use_bw
.header
);
1147 static void ospf_mpls_te_lsa_body_set(struct stream
*s
, struct mpls_te_link
*lp
)
1150 * The router address TLV is type 1, and ...
1151 * It must appear in exactly one
1152 * Traffic Engineering LSA originated by a router.
1154 build_router_tlv(s
);
1157 * Only one Link TLV shall be carried in each LSA, allowing for fine
1158 * granularity changes in topology.
1160 build_link_tlv(s
, lp
);
1164 /* Create new opaque-LSA. */
1165 static struct ospf_lsa
*ospf_mpls_te_lsa_new(struct ospf_area
*area
,
1166 struct mpls_te_link
*lp
)
1169 struct lsa_header
*lsah
;
1170 struct ospf_lsa
*new = NULL
;
1171 u_char options
, lsa_type
= 0;
1172 struct in_addr lsa_id
;
1176 /* Create a stream for LSA. */
1177 if ((s
= stream_new(OSPF_MAX_LSA_SIZE
)) == NULL
) {
1178 zlog_warn("ospf_mpls_te_lsa_new: stream_new() ?");
1181 lsah
= (struct lsa_header
*)STREAM_DATA(s
);
1183 options
= OSPF_OPTION_O
; /* Don't forget this :-) */
1185 /* Set opaque-LSA header fields depending of the type of RFC */
1186 if (IS_INTER_AS(lp
->type
)) {
1188 IS_FLOOD_AS(lp
->type
)
1190 options
|= OSPF_OPTION_E
; /* Enable AS external
1194 lsa_type
= OSPF_OPAQUE_AS_LSA
;
1197 options
|= LSA_OPTIONS_GET(
1198 area
); /* Get area default option */
1199 options
|= LSA_OPTIONS_NSSA_GET(area
);
1200 lsa_type
= OSPF_OPAQUE_AREA_LSA
;
1202 tmp
= SET_OPAQUE_LSID(OPAQUE_TYPE_INTER_AS_LSA
, lp
->instance
);
1203 lsa_id
.s_addr
= htonl(tmp
);
1205 struct ospf
*top
= ospf_lookup();
1207 lsa_header_set(s
, options
, lsa_type
, lsa_id
, top
->router_id
);
1209 options
|= LSA_OPTIONS_GET(area
); /* Get area default option */
1210 options
|= LSA_OPTIONS_NSSA_GET(area
);
1211 lsa_type
= OSPF_OPAQUE_AREA_LSA
;
1212 tmp
= SET_OPAQUE_LSID(OPAQUE_TYPE_TRAFFIC_ENGINEERING_LSA
,
1214 lsa_id
.s_addr
= htonl(tmp
);
1215 lsa_header_set(s
, options
, lsa_type
, lsa_id
,
1216 area
->ospf
->router_id
);
1219 if (IS_DEBUG_OSPF(lsa
, LSA_GENERATE
))
1221 "LSA[Type%d:%s]: Create an Opaque-LSA/MPLS-TE instance",
1222 lsa_type
, inet_ntoa(lsa_id
));
1224 /* Set opaque-LSA body fields. */
1225 ospf_mpls_te_lsa_body_set(s
, lp
);
1228 length
= stream_get_endp(s
);
1229 lsah
->length
= htons(length
);
1231 /* Now, create an OSPF LSA instance. */
1232 if ((new = ospf_lsa_new()) == NULL
) {
1233 zlog_warn("ospf_mpls_te_lsa_new: ospf_lsa_new() ?");
1237 if ((new->data
= ospf_lsa_data_new(length
)) == NULL
) {
1238 zlog_warn("ospf_mpls_te_lsa_new: ospf_lsa_data_new() ?");
1239 ospf_lsa_unlock(&new);
1246 SET_FLAG(new->flags
, OSPF_LSA_SELF
);
1247 memcpy(new->data
, lsah
, length
);
1254 static int ospf_mpls_te_lsa_originate1(struct ospf_area
*area
,
1255 struct mpls_te_link
*lp
)
1257 struct ospf_lsa
*new;
1260 /* Create new Opaque-LSA/MPLS-TE instance. */
1261 if ((new = ospf_mpls_te_lsa_new(area
, lp
)) == NULL
) {
1263 "ospf_mpls_te_lsa_originate1: ospf_mpls_te_lsa_new() ?");
1267 /* Install this LSA into LSDB. */
1268 if (ospf_lsa_install(area
->ospf
, NULL
/*oi*/, new) == NULL
) {
1269 zlog_warn("ospf_mpls_te_lsa_originate1: ospf_lsa_install() ?");
1270 ospf_lsa_unlock(&new);
1274 /* Now this link-parameter entry has associated LSA. */
1275 SET_FLAG(lp
->flags
, LPFLG_LSA_ENGAGED
);
1276 /* Update new LSA origination count. */
1277 area
->ospf
->lsa_originate_count
++;
1279 /* Flood new LSA through area. */
1280 ospf_flood_through_area(area
, NULL
/*nbr*/, new);
1282 if (IS_DEBUG_OSPF(lsa
, LSA_GENERATE
)) {
1283 char area_id
[INET_ADDRSTRLEN
];
1284 strcpy(area_id
, inet_ntoa(area
->area_id
));
1286 "LSA[Type%d:%s]: Originate Opaque-LSA/MPLS-TE: Area(%s), Link(%s)",
1287 new->data
->type
, inet_ntoa(new->data
->id
), area_id
,
1289 ospf_lsa_header_dump(new->data
);
1297 static int ospf_mpls_te_lsa_originate_area(void *arg
)
1299 struct ospf_area
*area
= (struct ospf_area
*)arg
;
1300 struct listnode
*node
, *nnode
;
1301 struct mpls_te_link
*lp
;
1304 if (OspfMplsTE
.status
== disabled
) {
1306 "ospf_mpls_te_lsa_originate_area: MPLS-TE is disabled now.");
1307 rc
= 0; /* This is not an error case. */
1311 for (ALL_LIST_ELEMENTS(OspfMplsTE
.iflist
, node
, nnode
, lp
)) {
1312 /* Process only enabled LSA with area scope flooding */
1313 if (!CHECK_FLAG(lp
->flags
, LPFLG_LSA_ACTIVE
)
1314 || IS_FLOOD_AS(lp
->type
))
1317 if (lp
->area
== NULL
)
1320 if (!IPV4_ADDR_SAME(&lp
->area
->area_id
, &area
->area_id
))
1324 CHECK_FLAG(lp
->flags
, LPFLG_LSA_ENGAGED
)
1327 CHECK_FLAG(lp
->flags
,
1328 LPFLG_LSA_FORCED_REFRESH
)
1332 LPFLG_LSA_FORCED_REFRESH
);
1334 "OSPF MPLS-TE (ospf_mpls_te_lsa_originate_area): Refresh instead of Originate");
1335 ospf_mpls_te_lsa_schedule(
1336 lp
, REFRESH_THIS_LSA
);
1340 if (!is_mandated_params_set(lp
)) {
1342 "ospf_mpls_te_lsa_originate_area: Link(%s) lacks some mandated MPLS-TE parameters.",
1343 lp
->ifp
? lp
->ifp
->name
: "?");
1347 /* Ok, let's try to originate an LSA for this area and Link. */
1348 if (IS_DEBUG_OSPF_TE
)
1350 "MPLS-TE(ospf_mpls_te_lsa_originate_area) Let's finally reoriginate the LSA %d through the Area %s for Link %s",
1351 lp
->instance
, inet_ntoa(area
->area_id
),
1352 lp
->ifp
? lp
->ifp
->name
: "?");
1353 if (ospf_mpls_te_lsa_originate1(area
, lp
) != 0)
1362 static int ospf_mpls_te_lsa_originate2(struct ospf
*top
,
1363 struct mpls_te_link
*lp
)
1365 struct ospf_lsa
*new;
1368 /* Create new Opaque-LSA/Inter-AS instance. */
1369 if ((new = ospf_mpls_te_lsa_new(NULL
, lp
)) == NULL
) {
1371 "ospf_mpls_te_lsa_originate2: ospf_router_info_lsa_new() ?");
1375 /* Install this LSA into LSDB. */
1376 if (ospf_lsa_install(top
, NULL
/*oi */, new) == NULL
) {
1377 zlog_warn("ospf_mpls_te_lsa_originate2: ospf_lsa_install() ?");
1378 ospf_lsa_unlock(&new);
1382 /* Now this Router Info parameter entry has associated LSA. */
1383 SET_FLAG(lp
->flags
, LPFLG_LSA_ENGAGED
);
1384 /* Update new LSA origination count. */
1385 top
->lsa_originate_count
++;
1387 /* Flood new LSA through AS. */
1388 ospf_flood_through_as(top
, NULL
/*nbr */, new);
1390 if (IS_DEBUG_OSPF(lsa
, LSA_GENERATE
)) {
1392 "LSA[Type%d:%s]: Originate Opaque-LSA/MPLS-TE Inter-AS",
1393 new->data
->type
, inet_ntoa(new->data
->id
));
1394 ospf_lsa_header_dump(new->data
);
1402 static int ospf_mpls_te_lsa_originate_as(void *arg
)
1405 struct ospf_area
*area
;
1406 struct listnode
*node
, *nnode
;
1407 struct mpls_te_link
*lp
;
1410 if ((OspfMplsTE
.status
== disabled
)
1411 || (OspfMplsTE
.inter_as
== Disable
)) {
1413 "ospf_mpls_te_lsa_originate_as: MPLS-TE Inter-AS is disabled for now.");
1414 rc
= 0; /* This is not an error case. */
1418 for (ALL_LIST_ELEMENTS(OspfMplsTE
.iflist
, node
, nnode
, lp
)) {
1419 /* Process only enabled INTER_AS Links or Pseudo-Links */
1420 if (!CHECK_FLAG(lp
->flags
, LPFLG_LSA_ACTIVE
)
1421 || !IS_INTER_AS(lp
->type
))
1425 CHECK_FLAG(lp
->flags
, LPFLG_LSA_ENGAGED
)
1428 CHECK_FLAG(lp
->flags
,
1429 LPFLG_LSA_FORCED_REFRESH
)
1433 LPFLG_LSA_FORCED_REFRESH
);
1434 ospf_mpls_te_lsa_schedule(
1435 lp
, REFRESH_THIS_LSA
);
1439 if (!is_mandated_params_set(lp
)) {
1441 "ospf_mpls_te_lsa_originate_as: Link(%s) lacks some mandated MPLS-TE parameters.",
1442 lp
->ifp
? lp
->ifp
->name
: "?");
1446 /* Ok, let's try to originate an LSA for this AS and Link. */
1447 if (IS_DEBUG_OSPF_TE
)
1449 "MPLS-TE(ospf_mpls_te_lsa_originate_as) Let's finally re-originate the Inter-AS LSA %d through the %s for Link %s",
1451 IS_FLOOD_AS(lp
->type
) ? "AS" : "Area",
1452 lp
->ifp
? lp
->ifp
->name
: "Unknown");
1454 if (IS_FLOOD_AS(lp
->type
)) {
1455 top
= (struct ospf
*)arg
;
1456 ospf_mpls_te_lsa_originate2(top
, lp
);
1458 area
= (struct ospf_area
*)arg
;
1459 ospf_mpls_te_lsa_originate1(area
, lp
);
1468 static struct ospf_lsa
*ospf_mpls_te_lsa_refresh(struct ospf_lsa
*lsa
)
1470 struct mpls_te_link
*lp
;
1471 struct ospf_area
*area
= lsa
->area
;
1473 struct ospf_lsa
*new = NULL
;
1475 if (OspfMplsTE
.status
== disabled
) {
1477 * This LSA must have flushed before due to MPLS-TE status
1479 * It seems a slip among routers in the routing domain.
1481 zlog_info("ospf_mpls_te_lsa_refresh: MPLS-TE is disabled now.");
1483 htons(OSPF_LSA_MAXAGE
); /* Flush it anyway. */
1486 /* At first, resolve lsa/lp relationship. */
1487 if ((lp
= lookup_linkparams_by_instance(lsa
)) == NULL
) {
1488 zlog_warn("ospf_mpls_te_lsa_refresh: Invalid parameter?");
1490 htons(OSPF_LSA_MAXAGE
); /* Flush it anyway. */
1493 /* Check if lp was not disable in the interval */
1494 if (!CHECK_FLAG(lp
->flags
, LPFLG_LSA_ACTIVE
)) {
1496 "ospf_mpls_te_lsa_refresh: lp was disabled: Flush it!");
1498 htons(OSPF_LSA_MAXAGE
); /* Flush it anyway. */
1501 /* If the lsa's age reached to MaxAge, start flushing procedure. */
1502 if (IS_LSA_MAXAGE(lsa
)) {
1504 UNSET_FLAG(lp
->flags
, LPFLG_LSA_ENGAGED
);
1505 ospf_opaque_lsa_flush_schedule(lsa
);
1509 /* Create new Opaque-LSA/MPLS-TE instance. */
1510 if ((new = ospf_mpls_te_lsa_new(area
, lp
)) == NULL
) {
1511 zlog_warn("ospf_mpls_te_lsa_refresh: ospf_mpls_te_lsa_new() ?");
1514 new->data
->ls_seqnum
= lsa_seqnum_increment(lsa
);
1516 /* Install this LSA into LSDB. */
1517 /* Given "lsa" will be freed in the next function. */
1518 /* As area could be NULL i.e. when using OPAQUE_LSA_AS, we prefer to use
1519 * ospf_lookup() to get ospf instance */
1523 top
= ospf_lookup();
1525 if (ospf_lsa_install(top
, NULL
/*oi */, new) == NULL
) {
1526 zlog_warn("ospf_mpls_te_lsa_refresh: ospf_lsa_install() ?");
1527 ospf_lsa_unlock(&new);
1531 /* Flood updated LSA through AS or Area depending of the RFC of the link
1533 if (IS_FLOOD_AS(lp
->type
))
1534 ospf_flood_through_as(top
, NULL
, new);
1536 ospf_flood_through_area(area
, NULL
/*nbr*/, new);
1538 /* Debug logging. */
1539 if (IS_DEBUG_OSPF(lsa
, LSA_GENERATE
)) {
1540 zlog_debug("LSA[Type%d:%s]: Refresh Opaque-LSA/MPLS-TE",
1541 new->data
->type
, inet_ntoa(new->data
->id
));
1542 ospf_lsa_header_dump(new->data
);
1549 void ospf_mpls_te_lsa_schedule(struct mpls_te_link
*lp
, opcode_t opcode
)
1551 struct ospf_lsa lsa
;
1552 struct lsa_header lsah
;
1556 memset(&lsa
, 0, sizeof(lsa
));
1557 memset(&lsah
, 0, sizeof(lsah
));
1558 top
= ospf_lookup();
1560 /* Check if the pseudo link is ready to flood */
1561 if (!(CHECK_FLAG(lp
->flags
, LPFLG_LSA_ACTIVE
))
1562 || !(IS_FLOOD_AREA(lp
->type
) || IS_FLOOD_AS(lp
->type
))) {
1566 lsa
.area
= lp
->area
;
1568 if (IS_FLOOD_AS(lp
->type
)) {
1569 lsah
.type
= OSPF_OPAQUE_AS_LSA
;
1570 tmp
= SET_OPAQUE_LSID(OPAQUE_TYPE_INTER_AS_LSA
, lp
->instance
);
1571 lsah
.id
.s_addr
= htonl(tmp
);
1573 lsah
.type
= OSPF_OPAQUE_AREA_LSA
;
1574 if (IS_INTER_AS(lp
->type
)) {
1575 /* Set the area context if not know */
1576 if (lp
->area
== NULL
)
1577 lp
->area
= ospf_area_lookup_by_area_id(
1578 top
, OspfMplsTE
.interas_areaid
);
1579 /* Unable to set the area context. Abort! */
1580 if (lp
->area
== NULL
) {
1582 "MPLS-TE(ospf_mpls_te_lsa_schedule) Area context is null. Abort !");
1585 tmp
= SET_OPAQUE_LSID(OPAQUE_TYPE_INTER_AS_LSA
,
1588 tmp
= SET_OPAQUE_LSID(
1589 OPAQUE_TYPE_TRAFFIC_ENGINEERING_LSA
,
1591 lsah
.id
.s_addr
= htonl(tmp
);
1595 case REORIGINATE_THIS_LSA
:
1596 if (IS_FLOOD_AS(lp
->type
)) {
1597 ospf_opaque_lsa_reoriginate_schedule(
1598 (void *)top
, OSPF_OPAQUE_AS_LSA
,
1599 OPAQUE_TYPE_INTER_AS_LSA
);
1603 if (IS_FLOOD_AREA(lp
->type
)) {
1604 if (IS_INTER_AS(lp
->type
))
1605 ospf_opaque_lsa_reoriginate_schedule(
1606 (void *)lp
->area
, OSPF_OPAQUE_AREA_LSA
,
1607 OPAQUE_TYPE_INTER_AS_LSA
);
1609 ospf_opaque_lsa_reoriginate_schedule(
1610 (void *)lp
->area
, OSPF_OPAQUE_AREA_LSA
,
1611 OPAQUE_TYPE_TRAFFIC_ENGINEERING_LSA
);
1615 case REFRESH_THIS_LSA
:
1616 ospf_opaque_lsa_refresh_schedule(&lsa
);
1618 case FLUSH_THIS_LSA
:
1619 /* Reset Activity flag */
1620 lp
->flags
= LPFLG_LSA_INACTIVE
;
1621 ospf_opaque_lsa_flush_schedule(&lsa
);
1624 zlog_warn("ospf_mpls_te_lsa_schedule: Unknown opcode (%u)",
1633 /*------------------------------------------------------------------------*
1634 * Followings are vty session control functions.
1635 *------------------------------------------------------------------------*/
1637 static u_int16_t
show_vty_router_addr(struct vty
*vty
,
1638 struct te_tlv_header
*tlvh
)
1640 struct te_tlv_router_addr
*top
= (struct te_tlv_router_addr
*)tlvh
;
1643 vty_out(vty
, " Router-Address: %s%s", inet_ntoa(top
->value
),
1646 zlog_debug(" Router-Address: %s", inet_ntoa(top
->value
));
1648 return TLV_SIZE(tlvh
);
1651 static u_int16_t
show_vty_link_header(struct vty
*vty
,
1652 struct te_tlv_header
*tlvh
)
1654 struct te_tlv_link
*top
= (struct te_tlv_link
*)tlvh
;
1657 vty_out(vty
, " Link: %u octets of data%s",
1658 ntohs(top
->header
.length
), VTY_NEWLINE
);
1660 zlog_debug(" Link: %u octets of data",
1661 ntohs(top
->header
.length
));
1663 return TLV_HDR_SIZE
; /* Here is special, not "TLV_SIZE". */
1666 static u_int16_t
show_vty_link_subtlv_link_type(struct vty
*vty
,
1667 struct te_tlv_header
*tlvh
)
1669 struct te_link_subtlv_link_type
*top
;
1670 const char *cp
= "Unknown";
1672 top
= (struct te_link_subtlv_link_type
*)tlvh
;
1673 switch (top
->link_type
.value
) {
1674 case LINK_TYPE_SUBTLV_VALUE_PTP
:
1675 cp
= "Point-to-point";
1677 case LINK_TYPE_SUBTLV_VALUE_MA
:
1685 vty_out(vty
, " Link-Type: %s (%u)%s", cp
, top
->link_type
.value
,
1688 zlog_debug(" Link-Type: %s (%u)", cp
, top
->link_type
.value
);
1690 return TLV_SIZE(tlvh
);
1693 static u_int16_t
show_vty_link_subtlv_link_id(struct vty
*vty
,
1694 struct te_tlv_header
*tlvh
)
1696 struct te_link_subtlv_link_id
*top
;
1698 top
= (struct te_link_subtlv_link_id
*)tlvh
;
1700 vty_out(vty
, " Link-ID: %s%s", inet_ntoa(top
->value
),
1703 zlog_debug(" Link-ID: %s", inet_ntoa(top
->value
));
1705 return TLV_SIZE(tlvh
);
1708 static u_int16_t
show_vty_link_subtlv_lclif_ipaddr(struct vty
*vty
,
1709 struct te_tlv_header
*tlvh
)
1711 struct te_link_subtlv_lclif_ipaddr
*top
;
1714 top
= (struct te_link_subtlv_lclif_ipaddr
*)tlvh
;
1715 n
= ntohs(tlvh
->length
) / sizeof(top
->value
[0]);
1718 vty_out(vty
, " Local Interface IP Address(es): %d%s", n
,
1721 zlog_debug(" Local Interface IP Address(es): %d", n
);
1723 for (i
= 0; i
< n
; i
++) {
1725 vty_out(vty
, " #%d: %s%s", i
,
1726 inet_ntoa(top
->value
[i
]), VTY_NEWLINE
);
1728 zlog_debug(" #%d: %s", i
,
1729 inet_ntoa(top
->value
[i
]));
1731 return TLV_SIZE(tlvh
);
1734 static u_int16_t
show_vty_link_subtlv_rmtif_ipaddr(struct vty
*vty
,
1735 struct te_tlv_header
*tlvh
)
1737 struct te_link_subtlv_rmtif_ipaddr
*top
;
1740 top
= (struct te_link_subtlv_rmtif_ipaddr
*)tlvh
;
1741 n
= ntohs(tlvh
->length
) / sizeof(top
->value
[0]);
1743 vty_out(vty
, " Remote Interface IP Address(es): %d%s", n
,
1746 zlog_debug(" Remote Interface IP Address(es): %d", n
);
1748 for (i
= 0; i
< n
; i
++) {
1750 vty_out(vty
, " #%d: %s%s", i
,
1751 inet_ntoa(top
->value
[i
]), VTY_NEWLINE
);
1753 zlog_debug(" #%d: %s", i
,
1754 inet_ntoa(top
->value
[i
]));
1756 return TLV_SIZE(tlvh
);
1759 static u_int16_t
show_vty_link_subtlv_te_metric(struct vty
*vty
,
1760 struct te_tlv_header
*tlvh
)
1762 struct te_link_subtlv_te_metric
*top
;
1764 top
= (struct te_link_subtlv_te_metric
*)tlvh
;
1766 vty_out(vty
, " Traffic Engineering Metric: %u%s",
1767 (u_int32_t
)ntohl(top
->value
), VTY_NEWLINE
);
1769 zlog_debug(" Traffic Engineering Metric: %u",
1770 (u_int32_t
)ntohl(top
->value
));
1772 return TLV_SIZE(tlvh
);
1775 static u_int16_t
show_vty_link_subtlv_max_bw(struct vty
*vty
,
1776 struct te_tlv_header
*tlvh
)
1778 struct te_link_subtlv_max_bw
*top
;
1781 top
= (struct te_link_subtlv_max_bw
*)tlvh
;
1782 fval
= ntohf(top
->value
);
1785 vty_out(vty
, " Maximum Bandwidth: %g (Bytes/sec)%s", fval
,
1788 zlog_debug(" Maximum Bandwidth: %g (Bytes/sec)", fval
);
1790 return TLV_SIZE(tlvh
);
1793 static u_int16_t
show_vty_link_subtlv_max_rsv_bw(struct vty
*vty
,
1794 struct te_tlv_header
*tlvh
)
1796 struct te_link_subtlv_max_rsv_bw
*top
;
1799 top
= (struct te_link_subtlv_max_rsv_bw
*)tlvh
;
1800 fval
= ntohf(top
->value
);
1803 vty_out(vty
, " Maximum Reservable Bandwidth: %g (Bytes/sec)%s",
1806 zlog_debug(" Maximum Reservable Bandwidth: %g (Bytes/sec)",
1809 return TLV_SIZE(tlvh
);
1812 static u_int16_t
show_vty_link_subtlv_unrsv_bw(struct vty
*vty
,
1813 struct te_tlv_header
*tlvh
)
1815 struct te_link_subtlv_unrsv_bw
*top
;
1819 top
= (struct te_link_subtlv_unrsv_bw
*)tlvh
;
1822 " Unreserved Bandwidth per Class Type in Byte/s:%s",
1826 " Unreserved Bandwidth per Class Type in Byte/s:");
1827 for (i
= 0; i
< MAX_CLASS_TYPE
; i
+= 2) {
1828 fval1
= ntohf(top
->value
[i
]);
1829 fval2
= ntohf(top
->value
[i
+ 1]);
1833 " [%d]: %g (Bytes/sec),\t[%d]: %g (Bytes/sec)%s",
1834 i
, fval1
, i
+ 1, fval2
, VTY_NEWLINE
);
1837 " [%d]: %g (Bytes/sec),\t[%d]: %g (Bytes/sec)",
1838 i
, fval1
, i
+ 1, fval2
);
1841 return TLV_SIZE(tlvh
);
1844 static u_int16_t
show_vty_link_subtlv_rsc_clsclr(struct vty
*vty
,
1845 struct te_tlv_header
*tlvh
)
1847 struct te_link_subtlv_rsc_clsclr
*top
;
1849 top
= (struct te_link_subtlv_rsc_clsclr
*)tlvh
;
1851 vty_out(vty
, " Resource class/color: 0x%x%s",
1852 (u_int32_t
)ntohl(top
->value
), VTY_NEWLINE
);
1854 zlog_debug(" Resource Class/Color: 0x%x",
1855 (u_int32_t
)ntohl(top
->value
));
1857 return TLV_SIZE(tlvh
);
1860 static u_int16_t
show_vty_link_subtlv_lrrid(struct vty
*vty
,
1861 struct te_tlv_header
*tlvh
)
1863 struct te_link_subtlv_lrrid
*top
;
1865 top
= (struct te_link_subtlv_lrrid
*)tlvh
;
1868 vty_out(vty
, " Local TE Router ID: %s%s",
1869 inet_ntoa(top
->local
), VTY_NEWLINE
);
1870 vty_out(vty
, " Remote TE Router ID: %s%s",
1871 inet_ntoa(top
->remote
), VTY_NEWLINE
);
1873 zlog_debug(" Local TE Router ID: %s",
1874 inet_ntoa(top
->local
));
1875 zlog_debug(" Remote TE Router ID: %s",
1876 inet_ntoa(top
->remote
));
1879 return TLV_SIZE(tlvh
);
1882 static u_int16_t
show_vty_link_subtlv_llri(struct vty
*vty
,
1883 struct te_tlv_header
*tlvh
)
1885 struct te_link_subtlv_llri
*top
;
1887 top
= (struct te_link_subtlv_llri
*)tlvh
;
1890 vty_out(vty
, " Link Local ID: %d%s",
1891 (u_int32_t
)ntohl(top
->local
), VTY_NEWLINE
);
1892 vty_out(vty
, " Link Remote ID: %d%s",
1893 (u_int32_t
)ntohl(top
->remote
), VTY_NEWLINE
);
1895 zlog_debug(" Link Local ID: %d",
1896 (u_int32_t
)ntohl(top
->local
));
1897 zlog_debug(" Link Remote ID: %d",
1898 (u_int32_t
)ntohl(top
->remote
));
1901 return TLV_SIZE(tlvh
);
1904 static u_int16_t
show_vty_link_subtlv_rip(struct vty
*vty
,
1905 struct te_tlv_header
*tlvh
)
1907 struct te_link_subtlv_rip
*top
;
1909 top
= (struct te_link_subtlv_rip
*)tlvh
;
1912 vty_out(vty
, " Inter-AS TE Remote ASBR IP address: %s%s",
1913 inet_ntoa(top
->value
), VTY_NEWLINE
);
1915 zlog_debug(" Inter-AS TE Remote ASBR IP address: %s",
1916 inet_ntoa(top
->value
));
1918 return TLV_SIZE(tlvh
);
1921 static u_int16_t
show_vty_link_subtlv_ras(struct vty
*vty
,
1922 struct te_tlv_header
*tlvh
)
1924 struct te_link_subtlv_ras
*top
;
1926 top
= (struct te_link_subtlv_ras
*)tlvh
;
1929 vty_out(vty
, " Inter-AS TE Remote AS number: %u%s",
1930 ntohl(top
->value
), VTY_NEWLINE
);
1932 zlog_debug(" Inter-AS TE Remote AS number: %u",
1935 return TLV_SIZE(tlvh
);
1938 static u_int16_t
show_vty_link_subtlv_av_delay(struct vty
*vty
,
1939 struct te_tlv_header
*tlvh
)
1941 struct te_link_subtlv_av_delay
*top
;
1943 u_int32_t anomalous
;
1945 top
= (struct te_link_subtlv_av_delay
*)tlvh
;
1946 delay
= (u_int32_t
)ntohl(top
->value
) & TE_EXT_MASK
;
1947 anomalous
= (u_int32_t
)ntohl(top
->value
) & TE_EXT_ANORMAL
;
1950 vty_out(vty
, " %s Average Link Delay: %d (micro-sec)%s",
1951 anomalous
? "Anomalous" : "Normal", delay
, VTY_NEWLINE
);
1953 zlog_debug(" %s Average Link Delay: %d (micro-sec)",
1954 anomalous
? "Anomalous" : "Normal", delay
);
1956 return TLV_SIZE(tlvh
);
1959 static u_int16_t
show_vty_link_subtlv_mm_delay(struct vty
*vty
,
1960 struct te_tlv_header
*tlvh
)
1962 struct te_link_subtlv_mm_delay
*top
;
1963 u_int32_t low
, high
;
1964 u_int32_t anomalous
;
1966 top
= (struct te_link_subtlv_mm_delay
*)tlvh
;
1967 low
= (u_int32_t
)ntohl(top
->low
) & TE_EXT_MASK
;
1968 anomalous
= (u_int32_t
)ntohl(top
->low
) & TE_EXT_ANORMAL
;
1969 high
= (u_int32_t
)ntohl(top
->high
);
1972 vty_out(vty
, " %s Min/Max Link Delay: %d/%d (micro-sec)%s",
1973 anomalous
? "Anomalous" : "Normal", low
, high
,
1976 zlog_debug(" %s Min/Max Link Delay: %d/%d (micro-sec)",
1977 anomalous
? "Anomalous" : "Normal", low
, high
);
1979 return TLV_SIZE(tlvh
);
1982 static u_int16_t
show_vty_link_subtlv_delay_var(struct vty
*vty
,
1983 struct te_tlv_header
*tlvh
)
1985 struct te_link_subtlv_delay_var
*top
;
1988 top
= (struct te_link_subtlv_delay_var
*)tlvh
;
1989 jitter
= (u_int32_t
)ntohl(top
->value
) & TE_EXT_MASK
;
1992 vty_out(vty
, " Delay Variation: %d (micro-sec)%s", jitter
,
1995 zlog_debug(" Delay Variation: %d (micro-sec)", jitter
);
1997 return TLV_SIZE(tlvh
);
2000 static u_int16_t
show_vty_link_subtlv_pkt_loss(struct vty
*vty
,
2001 struct te_tlv_header
*tlvh
)
2003 struct te_link_subtlv_pkt_loss
*top
;
2005 u_int32_t anomalous
;
2008 top
= (struct te_link_subtlv_pkt_loss
*)tlvh
;
2009 loss
= (u_int32_t
)ntohl(top
->value
) & TE_EXT_MASK
;
2010 fval
= (float)(loss
* LOSS_PRECISION
);
2011 anomalous
= (u_int32_t
)ntohl(top
->value
) & TE_EXT_ANORMAL
;
2014 vty_out(vty
, " %s Link Loss: %g (%%)%s",
2015 anomalous
? "Anomalous" : "Normal", fval
, VTY_NEWLINE
);
2017 zlog_debug(" %s Link Loss: %g (%%)",
2018 anomalous
? "Anomalous" : "Normal", fval
);
2020 return TLV_SIZE(tlvh
);
2023 static u_int16_t
show_vty_link_subtlv_res_bw(struct vty
*vty
,
2024 struct te_tlv_header
*tlvh
)
2026 struct te_link_subtlv_res_bw
*top
;
2029 top
= (struct te_link_subtlv_res_bw
*)tlvh
;
2030 fval
= ntohf(top
->value
);
2034 " Unidirectional Residual Bandwidth: %g (Bytes/sec)%s",
2038 " Unidirectional Residual Bandwidth: %g (Bytes/sec)",
2041 return TLV_SIZE(tlvh
);
2044 static u_int16_t
show_vty_link_subtlv_ava_bw(struct vty
*vty
,
2045 struct te_tlv_header
*tlvh
)
2047 struct te_link_subtlv_ava_bw
*top
;
2050 top
= (struct te_link_subtlv_ava_bw
*)tlvh
;
2051 fval
= ntohf(top
->value
);
2055 " Unidirectional Available Bandwidth: %g (Bytes/sec)%s",
2059 " Unidirectional Available Bandwidth: %g (Bytes/sec)",
2062 return TLV_SIZE(tlvh
);
2065 static u_int16_t
show_vty_link_subtlv_use_bw(struct vty
*vty
,
2066 struct te_tlv_header
*tlvh
)
2068 struct te_link_subtlv_use_bw
*top
;
2071 top
= (struct te_link_subtlv_use_bw
*)tlvh
;
2072 fval
= ntohf(top
->value
);
2076 " Unidirectional Utilized Bandwidth: %g (Bytes/sec)%s",
2080 " Unidirectional Utilized Bandwidth: %g (Bytes/sec)",
2083 return TLV_SIZE(tlvh
);
2086 static u_int16_t
show_vty_unknown_tlv(struct vty
*vty
,
2087 struct te_tlv_header
*tlvh
)
2090 vty_out(vty
, " Unknown TLV: [type(0x%x), length(0x%x)]%s",
2091 ntohs(tlvh
->type
), ntohs(tlvh
->length
), VTY_NEWLINE
);
2093 zlog_debug(" Unknown TLV: [type(0x%x), length(0x%x)]",
2094 ntohs(tlvh
->type
), ntohs(tlvh
->length
));
2096 return TLV_SIZE(tlvh
);
2099 static u_int16_t
ospf_mpls_te_show_link_subtlv(struct vty
*vty
,
2100 struct te_tlv_header
*tlvh0
,
2104 struct te_tlv_header
*tlvh
, *next
;
2105 u_int16_t sum
= subtotal
;
2107 for (tlvh
= tlvh0
; sum
< total
;
2108 tlvh
= (next
? next
: TLV_HDR_NEXT(tlvh
))) {
2110 switch (ntohs(tlvh
->type
)) {
2111 case TE_LINK_SUBTLV_LINK_TYPE
:
2112 sum
+= show_vty_link_subtlv_link_type(vty
, tlvh
);
2114 case TE_LINK_SUBTLV_LINK_ID
:
2115 sum
+= show_vty_link_subtlv_link_id(vty
, tlvh
);
2117 case TE_LINK_SUBTLV_LCLIF_IPADDR
:
2118 sum
+= show_vty_link_subtlv_lclif_ipaddr(vty
, tlvh
);
2120 case TE_LINK_SUBTLV_RMTIF_IPADDR
:
2121 sum
+= show_vty_link_subtlv_rmtif_ipaddr(vty
, tlvh
);
2123 case TE_LINK_SUBTLV_TE_METRIC
:
2124 sum
+= show_vty_link_subtlv_te_metric(vty
, tlvh
);
2126 case TE_LINK_SUBTLV_MAX_BW
:
2127 sum
+= show_vty_link_subtlv_max_bw(vty
, tlvh
);
2129 case TE_LINK_SUBTLV_MAX_RSV_BW
:
2130 sum
+= show_vty_link_subtlv_max_rsv_bw(vty
, tlvh
);
2132 case TE_LINK_SUBTLV_UNRSV_BW
:
2133 sum
+= show_vty_link_subtlv_unrsv_bw(vty
, tlvh
);
2135 case TE_LINK_SUBTLV_RSC_CLSCLR
:
2136 sum
+= show_vty_link_subtlv_rsc_clsclr(vty
, tlvh
);
2138 case TE_LINK_SUBTLV_LRRID
:
2139 sum
+= show_vty_link_subtlv_lrrid(vty
, tlvh
);
2141 case TE_LINK_SUBTLV_LLRI
:
2142 sum
+= show_vty_link_subtlv_llri(vty
, tlvh
);
2144 case TE_LINK_SUBTLV_RIP
:
2145 sum
+= show_vty_link_subtlv_rip(vty
, tlvh
);
2147 case TE_LINK_SUBTLV_RAS
:
2148 sum
+= show_vty_link_subtlv_ras(vty
, tlvh
);
2150 case TE_LINK_SUBTLV_AV_DELAY
:
2151 sum
+= show_vty_link_subtlv_av_delay(vty
, tlvh
);
2153 case TE_LINK_SUBTLV_MM_DELAY
:
2154 sum
+= show_vty_link_subtlv_mm_delay(vty
, tlvh
);
2156 case TE_LINK_SUBTLV_DELAY_VAR
:
2157 sum
+= show_vty_link_subtlv_delay_var(vty
, tlvh
);
2159 case TE_LINK_SUBTLV_PKT_LOSS
:
2160 sum
+= show_vty_link_subtlv_pkt_loss(vty
, tlvh
);
2162 case TE_LINK_SUBTLV_RES_BW
:
2163 sum
+= show_vty_link_subtlv_res_bw(vty
, tlvh
);
2165 case TE_LINK_SUBTLV_AVA_BW
:
2166 sum
+= show_vty_link_subtlv_ava_bw(vty
, tlvh
);
2168 case TE_LINK_SUBTLV_USE_BW
:
2169 sum
+= show_vty_link_subtlv_use_bw(vty
, tlvh
);
2172 sum
+= show_vty_unknown_tlv(vty
, tlvh
);
2179 static void ospf_mpls_te_show_info(struct vty
*vty
, struct ospf_lsa
*lsa
)
2181 struct lsa_header
*lsah
= (struct lsa_header
*)lsa
->data
;
2182 struct te_tlv_header
*tlvh
, *next
;
2183 u_int16_t sum
, total
;
2184 u_int16_t (*subfunc
)(struct vty
* vty
, struct te_tlv_header
* tlvh
,
2185 u_int16_t subtotal
, u_int16_t total
) = NULL
;
2188 total
= ntohs(lsah
->length
) - OSPF_LSA_HEADER_SIZE
;
2190 for (tlvh
= TLV_HDR_TOP(lsah
); sum
< total
;
2191 tlvh
= (next
? next
: TLV_HDR_NEXT(tlvh
))) {
2192 if (subfunc
!= NULL
) {
2193 sum
= (*subfunc
)(vty
, tlvh
, sum
, total
);
2194 next
= (struct te_tlv_header
*)((char *)tlvh
+ sum
);
2200 switch (ntohs(tlvh
->type
)) {
2201 case TE_TLV_ROUTER_ADDR
:
2202 sum
+= show_vty_router_addr(vty
, tlvh
);
2205 sum
+= show_vty_link_header(vty
, tlvh
);
2206 subfunc
= ospf_mpls_te_show_link_subtlv
;
2210 sum
+= show_vty_unknown_tlv(vty
, tlvh
);
2217 static void ospf_mpls_te_config_write_router(struct vty
*vty
)
2220 if (OspfMplsTE
.status
== enabled
) {
2221 vty_out(vty
, " mpls-te on%s", VTY_NEWLINE
);
2222 vty_out(vty
, " mpls-te router-address %s%s",
2223 inet_ntoa(OspfMplsTE
.router_addr
.value
), VTY_NEWLINE
);
2226 if (OspfMplsTE
.inter_as
== AS
)
2227 vty_out(vty
, " mpls-te inter-as as%s", VTY_NEWLINE
);
2228 if (OspfMplsTE
.inter_as
== Area
)
2229 vty_out(vty
, " mpls-te inter-as area %s %s",
2230 inet_ntoa(OspfMplsTE
.interas_areaid
), VTY_NEWLINE
);
2235 /*------------------------------------------------------------------------*
2236 * Followings are vty command functions.
2237 *------------------------------------------------------------------------*/
2239 DEFUN (ospf_mpls_te_on
,
2240 ospf_mpls_te_on_cmd
,
2243 "Enable the MPLS-TE functionality\n")
2245 VTY_DECLVAR_CONTEXT(ospf
, ospf
);
2246 struct listnode
*node
;
2247 struct mpls_te_link
*lp
;
2249 if (OspfMplsTE
.status
== enabled
)
2252 if (IS_DEBUG_OSPF_EVENT
)
2253 zlog_debug("MPLS-TE: OFF -> ON");
2255 OspfMplsTE
.status
= enabled
;
2257 /* Reoriginate RFC3630 & RFC6827 Links */
2258 ospf_mpls_te_foreach_area(ospf_mpls_te_lsa_schedule
,
2259 REORIGINATE_THIS_LSA
);
2261 /* Reoriginate LSA if INTER-AS is always on */
2262 if (OspfMplsTE
.inter_as
!= Disable
) {
2263 for (ALL_LIST_ELEMENTS_RO(OspfMplsTE
.iflist
, node
, lp
)) {
2264 if (IS_INTER_AS(lp
->type
)) {
2265 ospf_mpls_te_lsa_schedule(lp
,
2266 REORIGINATE_THIS_LSA
);
2274 DEFUN (no_ospf_mpls_te
,
2275 no_ospf_mpls_te_cmd
,
2279 "Disable the MPLS-TE functionality\n")
2281 VTY_DECLVAR_CONTEXT(ospf
, ospf
);
2282 struct listnode
*node
, *nnode
;
2283 struct mpls_te_link
*lp
;
2285 if (OspfMplsTE
.status
== disabled
)
2288 if (IS_DEBUG_OSPF_EVENT
)
2289 zlog_debug("MPLS-TE: ON -> OFF");
2291 OspfMplsTE
.status
= disabled
;
2293 for (ALL_LIST_ELEMENTS(OspfMplsTE
.iflist
, node
, nnode
, lp
))
2295 CHECK_FLAG(lp
->flags
, LPFLG_LSA_ENGAGED
)
2296 ospf_mpls_te_lsa_schedule(lp
, FLUSH_THIS_LSA
);
2302 DEFUN (ospf_mpls_te_router_addr
,
2303 ospf_mpls_te_router_addr_cmd
,
2304 "mpls-te router-address A.B.C.D",
2306 "Stable IP address of the advertising router\n"
2307 "MPLS-TE router address in IPv4 address format\n")
2309 VTY_DECLVAR_CONTEXT(ospf
, ospf
);
2311 struct te_tlv_router_addr
*ra
= &OspfMplsTE
.router_addr
;
2312 struct in_addr value
;
2314 if (!inet_aton(argv
[idx_ipv4
]->arg
, &value
)) {
2315 vty_out(vty
, "Please specify Router-Addr by A.B.C.D%s",
2320 if (ntohs(ra
->header
.type
) == 0
2321 || ntohl(ra
->value
.s_addr
) != ntohl(value
.s_addr
)) {
2322 struct listnode
*node
, *nnode
;
2323 struct mpls_te_link
*lp
;
2324 int need_to_reoriginate
= 0;
2326 set_mpls_te_router_addr(value
);
2328 if (OspfMplsTE
.status
== disabled
)
2331 for (ALL_LIST_ELEMENTS(OspfMplsTE
.iflist
, node
, nnode
, lp
)) {
2332 if ((lp
->area
== NULL
) || IS_FLOOD_AS(lp
->type
))
2335 if (!CHECK_FLAG(lp
->flags
, LPFLG_LSA_ENGAGED
)) {
2336 need_to_reoriginate
= 1;
2341 for (ALL_LIST_ELEMENTS(OspfMplsTE
.iflist
, node
, nnode
, lp
)) {
2342 if ((lp
->area
== NULL
) || IS_FLOOD_AS(lp
->type
))
2345 if (need_to_reoriginate
)
2346 SET_FLAG(lp
->flags
, LPFLG_LSA_FORCED_REFRESH
);
2348 ospf_mpls_te_lsa_schedule(lp
, REFRESH_THIS_LSA
);
2351 if (need_to_reoriginate
)
2352 ospf_mpls_te_foreach_area(ospf_mpls_te_lsa_schedule
,
2353 REORIGINATE_THIS_LSA
);
2359 static int set_inter_as_mode(struct vty
*vty
, const char *mode_name
,
2360 const char *area_id
)
2362 enum inter_as_mode mode
;
2363 struct listnode
*node
;
2364 struct mpls_te_link
*lp
;
2367 if (OspfMplsTE
.status
== enabled
) {
2369 /* Read and Check inter_as mode */
2370 if (strcmp(mode_name
, "as") == 0)
2372 else if (strcmp(mode_name
, "area") == 0) {
2374 VTY_GET_OSPF_AREA_ID(OspfMplsTE
.interas_areaid
, format
,
2378 "Unknown mode. Please choose between as or area%s",
2383 if (IS_DEBUG_OSPF_EVENT
)
2385 "MPLS-TE: Inter-AS enable with %s flooding support",
2388 /* Register new callbacks regarding the flooding scope (AS or
2390 if (ospf_mpls_te_register(mode
) < 0) {
2392 "Internal error: Unable to register Inter-AS functions%s",
2397 /* Enable mode and re-originate LSA if needed */
2398 if ((OspfMplsTE
.inter_as
== Disable
)
2399 && (mode
!= OspfMplsTE
.inter_as
)) {
2400 OspfMplsTE
.inter_as
= mode
;
2401 /* Re-originate all InterAS-TEv2 LSA */
2402 for (ALL_LIST_ELEMENTS_RO(OspfMplsTE
.iflist
, node
,
2404 if (IS_INTER_AS(lp
->type
)) {
2406 lp
->type
|= FLOOD_AS
;
2408 lp
->type
|= FLOOD_AREA
;
2409 ospf_mpls_te_lsa_schedule(
2410 lp
, REORIGINATE_THIS_LSA
);
2415 "Please change Inter-AS support to disable first before going to mode %s%s",
2416 mode2text
[mode
], VTY_NEWLINE
);
2420 vty_out(vty
, "mpls-te has not been turned on%s", VTY_NEWLINE
);
2427 DEFUN (ospf_mpls_te_inter_as_as
,
2428 ospf_mpls_te_inter_as_cmd
,
2429 "mpls-te inter-as as",
2431 "Configure MPLS-TE Inter-AS support\n"
2432 "AS native mode self originate INTER_AS LSA with Type 11 (as flooding scope)\n")
2434 return set_inter_as_mode(vty
, "as", "");
2437 DEFUN (ospf_mpls_te_inter_as_area
,
2438 ospf_mpls_te_inter_as_area_cmd
,
2439 "mpls-te inter-as area <A.B.C.D|(0-4294967295)>",
2441 "Configure MPLS-TE Inter-AS support\n"
2442 "AREA native mode self originate INTER_AS LSA with Type 10 (area flooding scope)\n"
2443 "OSPF area ID in IP format\n"
2444 "OSPF area ID as decimal value\n")
2446 int idx_ipv4_number
= 3;
2447 return set_inter_as_mode(vty
, "area", argv
[idx_ipv4_number
]->arg
);
2450 DEFUN (no_ospf_mpls_te_inter_as
,
2451 no_ospf_mpls_te_inter_as_cmd
,
2452 "no mpls-te inter-as",
2455 "Disable MPLS-TE Inter-AS support\n")
2458 struct listnode
*node
, *nnode
;
2459 struct mpls_te_link
*lp
;
2461 if (IS_DEBUG_OSPF_EVENT
)
2462 zlog_debug("MPLS-TE: Inter-AS support OFF");
2464 if ((OspfMplsTE
.status
== enabled
)
2465 && (OspfMplsTE
.inter_as
!= Disable
)) {
2466 OspfMplsTE
.inter_as
= Disable
;
2467 /* Flush all Inter-AS LSA */
2468 for (ALL_LIST_ELEMENTS(OspfMplsTE
.iflist
, node
, nnode
, lp
))
2469 if (IS_INTER_AS(lp
->type
)
2470 && CHECK_FLAG(lp
->flags
, LPFLG_LSA_ENGAGED
))
2471 ospf_mpls_te_lsa_schedule(lp
, FLUSH_THIS_LSA
);
2474 /* Deregister the Callbacks for Inter-AS suport */
2475 ospf_mpls_te_unregister();
2480 DEFUN (show_ip_ospf_mpls_te_router
,
2481 show_ip_ospf_mpls_te_router_cmd
,
2482 "show ip ospf mpls-te router",
2486 "MPLS-TE information\n"
2487 "MPLS-TE Router parameters\n")
2489 if (OspfMplsTE
.status
== enabled
) {
2490 vty_out(vty
, "--- MPLS-TE router parameters ---%s",
2493 if (ntohs(OspfMplsTE
.router_addr
.header
.type
) != 0)
2494 show_vty_router_addr(vty
,
2495 &OspfMplsTE
.router_addr
.header
);
2496 else if (vty
!= NULL
)
2497 vty_out(vty
, " N/A%s", VTY_NEWLINE
);
2502 static void show_mpls_te_link_sub(struct vty
*vty
, struct interface
*ifp
)
2504 struct mpls_te_link
*lp
;
2506 if ((OspfMplsTE
.status
== enabled
) && HAS_LINK_PARAMS(ifp
)
2507 && !if_is_loopback(ifp
) && if_is_up(ifp
)
2508 && ((lp
= lookup_linkparams_by_ifp(ifp
)) != NULL
)) {
2509 /* Continue only if interface is not passive or support Inter-AS
2511 if (!(ospf_oi_count(ifp
) > 0)) {
2512 if (IS_INTER_AS(lp
->type
)) {
2514 "-- Inter-AS TEv2 link parameters for %s --%s",
2515 ifp
->name
, VTY_NEWLINE
);
2517 /* MPLS-TE is not activate on this interface */
2518 /* or this interface is passive and Inter-AS
2519 * TEv2 is not activate */
2521 " %s: MPLS-TE is disabled on this interface%s",
2522 ifp
->name
, VTY_NEWLINE
);
2526 vty_out(vty
, "-- MPLS-TE link parameters for %s --%s",
2527 ifp
->name
, VTY_NEWLINE
);
2530 if (TLV_TYPE(lp
->link_type
) != 0)
2531 show_vty_link_subtlv_link_type(vty
,
2532 &lp
->link_type
.header
);
2533 if (TLV_TYPE(lp
->link_id
) != 0)
2534 show_vty_link_subtlv_link_id(vty
, &lp
->link_id
.header
);
2535 if (TLV_TYPE(lp
->lclif_ipaddr
) != 0)
2536 show_vty_link_subtlv_lclif_ipaddr(
2537 vty
, &lp
->lclif_ipaddr
.header
);
2538 if (TLV_TYPE(lp
->rmtif_ipaddr
) != 0)
2539 show_vty_link_subtlv_rmtif_ipaddr(
2540 vty
, &lp
->rmtif_ipaddr
.header
);
2541 if (TLV_TYPE(lp
->rip
) != 0)
2542 show_vty_link_subtlv_rip(vty
, &lp
->rip
.header
);
2543 if (TLV_TYPE(lp
->ras
) != 0)
2544 show_vty_link_subtlv_ras(vty
, &lp
->ras
.header
);
2545 if (TLV_TYPE(lp
->te_metric
) != 0)
2546 show_vty_link_subtlv_te_metric(vty
,
2547 &lp
->te_metric
.header
);
2548 if (TLV_TYPE(lp
->max_bw
) != 0)
2549 show_vty_link_subtlv_max_bw(vty
, &lp
->max_bw
.header
);
2550 if (TLV_TYPE(lp
->max_rsv_bw
) != 0)
2551 show_vty_link_subtlv_max_rsv_bw(vty
,
2552 &lp
->max_rsv_bw
.header
);
2553 if (TLV_TYPE(lp
->unrsv_bw
) != 0)
2554 show_vty_link_subtlv_unrsv_bw(vty
,
2555 &lp
->unrsv_bw
.header
);
2556 if (TLV_TYPE(lp
->rsc_clsclr
) != 0)
2557 show_vty_link_subtlv_rsc_clsclr(vty
,
2558 &lp
->rsc_clsclr
.header
);
2559 if (TLV_TYPE(lp
->av_delay
) != 0)
2560 show_vty_link_subtlv_av_delay(vty
,
2561 &lp
->av_delay
.header
);
2562 if (TLV_TYPE(lp
->mm_delay
) != 0)
2563 show_vty_link_subtlv_mm_delay(vty
,
2564 &lp
->mm_delay
.header
);
2565 if (TLV_TYPE(lp
->delay_var
) != 0)
2566 show_vty_link_subtlv_delay_var(vty
,
2567 &lp
->delay_var
.header
);
2568 if (TLV_TYPE(lp
->pkt_loss
) != 0)
2569 show_vty_link_subtlv_pkt_loss(vty
,
2570 &lp
->pkt_loss
.header
);
2571 if (TLV_TYPE(lp
->res_bw
) != 0)
2572 show_vty_link_subtlv_res_bw(vty
, &lp
->res_bw
.header
);
2573 if (TLV_TYPE(lp
->ava_bw
) != 0)
2574 show_vty_link_subtlv_ava_bw(vty
, &lp
->ava_bw
.header
);
2575 if (TLV_TYPE(lp
->use_bw
) != 0)
2576 show_vty_link_subtlv_use_bw(vty
, &lp
->use_bw
.header
);
2577 vty_out(vty
, "---------------%s%s", VTY_NEWLINE
, VTY_NEWLINE
);
2579 vty_out(vty
, " %s: MPLS-TE is disabled on this interface%s",
2580 ifp
->name
, VTY_NEWLINE
);
2586 DEFUN (show_ip_ospf_mpls_te_link
,
2587 show_ip_ospf_mpls_te_link_cmd
,
2588 "show ip ospf mpls-te interface [INTERFACE]",
2592 "MPLS-TE information\n"
2593 "Interface information\n"
2596 int idx_interface
= 5;
2597 struct interface
*ifp
;
2598 struct listnode
*node
, *nnode
;
2600 /* Show All Interfaces. */
2602 for (ALL_LIST_ELEMENTS(vrf_iflist(VRF_DEFAULT
), node
, nnode
,
2604 show_mpls_te_link_sub(vty
, ifp
);
2606 /* Interface name is specified. */
2608 if ((ifp
= if_lookup_by_name(argv
[idx_interface
]->arg
,
2611 vty_out(vty
, "No such interface name%s", VTY_NEWLINE
);
2613 show_mpls_te_link_sub(vty
, ifp
);
2619 static void ospf_mpls_te_register_vty(void)
2621 install_element(VIEW_NODE
, &show_ip_ospf_mpls_te_router_cmd
);
2622 install_element(VIEW_NODE
, &show_ip_ospf_mpls_te_link_cmd
);
2624 install_element(OSPF_NODE
, &ospf_mpls_te_on_cmd
);
2625 install_element(OSPF_NODE
, &no_ospf_mpls_te_cmd
);
2626 install_element(OSPF_NODE
, &ospf_mpls_te_router_addr_cmd
);
2627 install_element(OSPF_NODE
, &ospf_mpls_te_inter_as_cmd
);
2628 install_element(OSPF_NODE
, &ospf_mpls_te_inter_as_area_cmd
);
2629 install_element(OSPF_NODE
, &no_ospf_mpls_te_inter_as_cmd
);