]> git.proxmox.com Git - mirror_frr.git/blame - ospfd/ospf_te.c
*: add missing \n in some help strings
[mirror_frr.git] / ospfd / ospf_te.c
CommitLineData
718e3744 1/*
16f1b9ee 2 * This is an implementation of RFC3630
718e3744 3 * Copyright (C) 2001 KDD R&D Laboratories, Inc.
4 * http://www.kddlabs.co.jp/
5 *
16f1b9ee
OD
6 * Copyright (C) 2012 Orange Labs
7 * http://www.orange.com
8 *
718e3744 9 * This file is part of GNU Zebra.
10 *
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
14 * later version.
896014f4 15 *
718e3744 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.
20 *
896014f4
DL
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
718e3744 24 */
25
16f1b9ee
OD
26/* Add support of RFC7471 */
27/* Add support of RFC5392, RFC6827 */
718e3744 28
29#include <zebra.h>
16f1b9ee 30#include <math.h>
718e3744 31
718e3744 32#include "linklist.h"
33#include "prefix.h"
b2d7c082 34#include "vrf.h"
718e3744 35#include "if.h"
36#include "table.h"
37#include "memory.h"
38#include "command.h"
39#include "vty.h"
40#include "stream.h"
41#include "log.h"
42#include "thread.h"
43#include "hash.h"
d62a17ae 44#include "sockunion.h" /* for inet_aton() */
16f1b9ee 45#include "network.h"
718e3744 46
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"
16f1b9ee 63#include "ospfd/ospf_vty.h"
718e3744 64
65/*
66 * Global variable to manage Opaque-LSA/MPLS-TE on this node.
67 * Note that all parameter values are stored in network byte order.
68 */
16f1b9ee 69struct ospf_mpls_te OspfMplsTE;
718e3744 70
ead99d5f 71const char *mode2text[] = {"Off", "AS", "Area"};
718e3744 72
73/*------------------------------------------------------------------------*
74 * Followings are initialize/terminate functions for MPLS-TE handling.
75 *------------------------------------------------------------------------*/
76
d62a17ae 77static int ospf_mpls_te_new_if(struct interface *ifp);
78static int ospf_mpls_te_del_if(struct interface *ifp);
79static void ospf_mpls_te_ism_change(struct ospf_interface *oi, int old_status);
80static void ospf_mpls_te_nsm_change(struct ospf_neighbor *nbr, int old_status);
81static void ospf_mpls_te_config_write_router(struct vty *vty);
82static void ospf_mpls_te_show_info(struct vty *vty, struct ospf_lsa *lsa);
83static int ospf_mpls_te_lsa_originate_area(void *arg);
84static int ospf_mpls_te_lsa_originate_as(void *arg);
85static struct ospf_lsa *ospf_mpls_te_lsa_refresh(struct ospf_lsa *lsa);
86
87static void del_mpls_te_link(void *val);
88static void ospf_mpls_te_register_vty(void);
89
90int ospf_mpls_te_init(void)
91{
92 int rc;
93
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,
718e3744 98 ospf_mpls_te_config_write_router,
d62a17ae 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 */
718e3744 103 NULL /* ospf_mpls_te_del_lsa_hook */);
d62a17ae 104 if (rc != 0) {
105 zlog_warn(
106 "ospf_mpls_te_init: Failed to register Traffic Engineering functions");
ead99d5f 107 return rc;
d62a17ae 108 }
718e3744 109
d62a17ae 110 memset(&OspfMplsTE, 0, sizeof(struct ospf_mpls_te));
32ab5cf4 111 OspfMplsTE.enabled = false;
ead99d5f 112 OspfMplsTE.inter_as = Off;
d62a17ae 113 OspfMplsTE.iflist = list_new();
114 OspfMplsTE.iflist->del = del_mpls_te_link;
718e3744 115
d62a17ae 116 ospf_mpls_te_register_vty();
718e3744 117
d62a17ae 118 return rc;
718e3744 119}
120
16f1b9ee 121/* Additional register for RFC5392 support */
d62a17ae 122static int ospf_mpls_te_register(enum inter_as_mode mode)
16f1b9ee 123{
ead99d5f 124 int rc = 0;
d62a17ae 125 u_int8_t scope;
16f1b9ee 126
ead99d5f
OD
127 if (OspfMplsTE.inter_as != Off)
128 return rc;
16f1b9ee 129
d62a17ae 130 if (mode == AS)
131 scope = OSPF_OPAQUE_AS_LSA;
132 else
133 scope = OSPF_OPAQUE_AREA_LSA;
16f1b9ee 134
d62a17ae 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);
16f1b9ee 140
d62a17ae 141 if (rc != 0) {
142 zlog_warn(
143 "ospf_router_info_init: Failed to register Inter-AS functions");
144 return rc;
145 }
16f1b9ee 146
ead99d5f 147 return rc;
16f1b9ee
OD
148}
149
d62a17ae 150static int ospf_mpls_te_unregister()
16f1b9ee 151{
d62a17ae 152 u_int8_t scope;
16f1b9ee 153
ead99d5f 154 if (OspfMplsTE.inter_as == Off)
d62a17ae 155 return 0;
16f1b9ee 156
d62a17ae 157 if (OspfMplsTE.inter_as == AS)
158 scope = OSPF_OPAQUE_AS_LSA;
159 else
160 scope = OSPF_OPAQUE_AREA_LSA;
16f1b9ee 161
d62a17ae 162 ospf_delete_opaque_functab(scope, OPAQUE_TYPE_INTER_AS_LSA);
16f1b9ee 163
d62a17ae 164 return 0;
16f1b9ee
OD
165}
166
d62a17ae 167void ospf_mpls_te_term(void)
718e3744 168{
affe9e99 169 list_delete_and_null(&OspfMplsTE.iflist);
718e3744 170
d62a17ae 171 ospf_delete_opaque_functab(OSPF_OPAQUE_AREA_LSA,
172 OPAQUE_TYPE_TRAFFIC_ENGINEERING_LSA);
32ab5cf4 173 OspfMplsTE.enabled = false;
16f1b9ee 174
d62a17ae 175 ospf_mpls_te_unregister();
ead99d5f 176 OspfMplsTE.inter_as = Off;
16f1b9ee 177
d62a17ae 178 return;
718e3744 179}
180
181/*------------------------------------------------------------------------*
182 * Followings are control functions for MPLS-TE parameters management.
183 *------------------------------------------------------------------------*/
184
d62a17ae 185static void del_mpls_te_link(void *val)
718e3744 186{
d62a17ae 187 XFREE(MTYPE_OSPF_MPLS_TE, val);
188 return;
718e3744 189}
190
ead99d5f 191static u_int32_t get_mpls_te_instance_value(void)
718e3744 192{
d62a17ae 193 static u_int32_t seqno = 0;
718e3744 194
d62a17ae 195 if (seqno < MAX_LEGAL_TE_INSTANCE_NUM)
196 seqno += 1;
197 else
198 seqno = 1; /* Avoid zero. */
718e3744 199
d62a17ae 200 return seqno;
718e3744 201}
202
d62a17ae 203static struct mpls_te_link *lookup_linkparams_by_ifp(struct interface *ifp)
718e3744 204{
d62a17ae 205 struct listnode *node, *nnode;
206 struct mpls_te_link *lp;
718e3744 207
d62a17ae 208 for (ALL_LIST_ELEMENTS(OspfMplsTE.iflist, node, nnode, lp))
209 if (lp->ifp == ifp)
210 return lp;
718e3744 211
d62a17ae 212 return NULL;
718e3744 213}
214
d62a17ae 215static struct mpls_te_link *lookup_linkparams_by_instance(struct ospf_lsa *lsa)
718e3744 216{
d62a17ae 217 struct listnode *node;
218 struct mpls_te_link *lp;
219 unsigned int key = GET_OPAQUE_ID(ntohl(lsa->data->id.s_addr));
718e3744 220
d62a17ae 221 for (ALL_LIST_ELEMENTS_RO(OspfMplsTE.iflist, node, lp))
222 if (lp->instance == key)
223 return lp;
718e3744 224
d62a17ae 225 zlog_warn("lookup_linkparams_by_instance: Entry not found: key(%x)",
226 key);
227 return NULL;
718e3744 228}
229
d62a17ae 230static void ospf_mpls_te_foreach_area(void (*func)(struct mpls_te_link *lp,
2a39170c
OD
231 enum lsa_opcode sched_opcode),
232 enum lsa_opcode sched_opcode)
718e3744 233{
d62a17ae 234 struct listnode *node, *nnode;
235 struct listnode *node2;
236 struct mpls_te_link *lp;
237 struct ospf_area *area;
718e3744 238
d62a17ae 239 for (ALL_LIST_ELEMENTS(OspfMplsTE.iflist, node, nnode, lp)) {
240 /* Skip Inter-AS TEv2 Links */
241 if (IS_INTER_AS(lp->type))
242 continue;
243 if ((area = lp->area) == NULL)
244 continue;
32ab5cf4
OD
245 if (CHECK_FLAG(lp->flags, LPFLG_LOOKUP_DONE))
246 continue;
718e3744 247
d62a17ae 248 if (func != NULL)
249 (*func)(lp, sched_opcode);
718e3744 250
d62a17ae 251 for (node2 = listnextnode(node); node2;
252 node2 = listnextnode(node2))
253 if ((lp = listgetdata(node2)) != NULL)
254 if (lp->area != NULL)
255 if (IPV4_ADDR_SAME(&lp->area->area_id,
256 &area->area_id))
257 SET_FLAG(lp->flags,
258 LPFLG_LOOKUP_DONE);
259 }
718e3744 260
d62a17ae 261 for (ALL_LIST_ELEMENTS_RO(OspfMplsTE.iflist, node, lp))
262 if (lp->area != NULL)
263 UNSET_FLAG(lp->flags, LPFLG_LOOKUP_DONE);
718e3744 264
d62a17ae 265 return;
718e3744 266}
267
d62a17ae 268static void set_mpls_te_router_addr(struct in_addr ipv4)
718e3744 269{
d62a17ae 270 OspfMplsTE.router_addr.header.type = htons(TE_TLV_ROUTER_ADDR);
271 OspfMplsTE.router_addr.header.length = htons(TE_LINK_SUBTLV_DEF_SIZE);
272 OspfMplsTE.router_addr.value = ipv4;
273 return;
718e3744 274}
275
d62a17ae 276static void set_linkparams_link_header(struct mpls_te_link *lp)
718e3744 277{
d62a17ae 278 u_int16_t length = 0;
718e3744 279
d62a17ae 280 /* TE_LINK_SUBTLV_LINK_TYPE */
281 if (ntohs(lp->link_type.header.type) != 0)
282 length += TLV_SIZE(&lp->link_type.header);
718e3744 283
d62a17ae 284 /* TE_LINK_SUBTLV_LINK_ID */
285 if (ntohs(lp->link_id.header.type) != 0)
286 length += TLV_SIZE(&lp->link_id.header);
718e3744 287
d62a17ae 288 /* TE_LINK_SUBTLV_LCLIF_IPADDR */
289 if (lp->lclif_ipaddr.header.type != 0)
290 length += TLV_SIZE(&lp->lclif_ipaddr.header);
718e3744 291
d62a17ae 292 /* TE_LINK_SUBTLV_RMTIF_IPADDR */
293 if (lp->rmtif_ipaddr.header.type != 0)
294 length += TLV_SIZE(&lp->rmtif_ipaddr.header);
718e3744 295
d62a17ae 296 /* TE_LINK_SUBTLV_TE_METRIC */
297 if (ntohs(lp->te_metric.header.type) != 0)
298 length += TLV_SIZE(&lp->te_metric.header);
718e3744 299
d62a17ae 300 /* TE_LINK_SUBTLV_MAX_BW */
301 if (ntohs(lp->max_bw.header.type) != 0)
302 length += TLV_SIZE(&lp->max_bw.header);
718e3744 303
d62a17ae 304 /* TE_LINK_SUBTLV_MAX_RSV_BW */
305 if (ntohs(lp->max_rsv_bw.header.type) != 0)
306 length += TLV_SIZE(&lp->max_rsv_bw.header);
718e3744 307
d62a17ae 308 /* TE_LINK_SUBTLV_UNRSV_BW */
309 if (ntohs(lp->unrsv_bw.header.type) != 0)
310 length += TLV_SIZE(&lp->unrsv_bw.header);
718e3744 311
d62a17ae 312 /* TE_LINK_SUBTLV_RSC_CLSCLR */
313 if (ntohs(lp->rsc_clsclr.header.type) != 0)
314 length += TLV_SIZE(&lp->rsc_clsclr.header);
315
316 /* TE_LINK_SUBTLV_LLRI */
317 if (ntohs(lp->llri.header.type) != 0)
318 length += TLV_SIZE(&lp->llri.header);
319
320 /* TE_LINK_SUBTLV_RIP */
321 if (ntohs(lp->rip.header.type) != 0)
322 length += TLV_SIZE(&lp->rip.header);
323
324 /* TE_LINK_SUBTLV_RAS */
325 if (ntohs(lp->ras.header.type) != 0)
326 length += TLV_SIZE(&lp->ras.header);
327
328 /* TE_LINK_SUBTLV_LRRID */
329 if (ntohs(lp->lrrid.header.type) != 0)
330 length += TLV_SIZE(&lp->lrrid.header);
331
332 /* TE_LINK_SUBTLV_AV_DELAY */
333 if (ntohs(lp->av_delay.header.type) != 0)
334 length += TLV_SIZE(&lp->av_delay.header);
335
336 /* TE_LINK_SUBTLV_MM_DELAY */
337 if (ntohs(lp->mm_delay.header.type) != 0)
338 length += TLV_SIZE(&lp->mm_delay.header);
339
340 /* TE_LINK_SUBTLV_DELAY_VAR */
341 if (ntohs(lp->delay_var.header.type) != 0)
342 length += TLV_SIZE(&lp->delay_var.header);
343
344 /* TE_LINK_SUBTLV_PKT_LOSS */
345 if (ntohs(lp->pkt_loss.header.type) != 0)
346 length += TLV_SIZE(&lp->pkt_loss.header);
347
348 /* TE_LINK_SUBTLV_RES_BW */
349 if (ntohs(lp->res_bw.header.type) != 0)
350 length += TLV_SIZE(&lp->res_bw.header);
351
352 /* TE_LINK_SUBTLV_AVA_BW */
353 if (ntohs(lp->ava_bw.header.type) != 0)
354 length += TLV_SIZE(&lp->ava_bw.header);
355
356 /* TE_LINK_SUBTLV_USE_BW */
357 if (ntohs(lp->use_bw.header.type) != 0)
358 length += TLV_SIZE(&lp->use_bw.header);
718e3744 359
d62a17ae 360 lp->link_header.header.type = htons(TE_TLV_LINK);
361 lp->link_header.header.length = htons(length);
362
363 return;
718e3744 364}
d62a17ae 365
366static void set_linkparams_link_type(struct ospf_interface *oi,
367 struct mpls_te_link *lp)
368{
369 lp->link_type.header.type = htons(TE_LINK_SUBTLV_LINK_TYPE);
370 lp->link_type.header.length = htons(TE_LINK_SUBTLV_TYPE_SIZE);
371
372 switch (oi->type) {
373 case OSPF_IFTYPE_POINTOPOINT:
374 lp->link_type.link_type.value = LINK_TYPE_SUBTLV_VALUE_PTP;
375 break;
376 case OSPF_IFTYPE_BROADCAST:
377 case OSPF_IFTYPE_NBMA:
378 lp->link_type.link_type.value = LINK_TYPE_SUBTLV_VALUE_MA;
379 break;
380 default:
381 /* Not supported yet. */ /* XXX */
382 lp->link_type.header.type = htons(0);
383 break;
384 }
385 return;
718e3744 386}
d62a17ae 387
388static void set_linkparams_link_id(struct ospf_interface *oi,
389 struct mpls_te_link *lp)
718e3744 390{
d62a17ae 391 struct ospf_neighbor *nbr;
392 int done = 0;
718e3744 393
d62a17ae 394 lp->link_id.header.type = htons(TE_LINK_SUBTLV_LINK_ID);
395 lp->link_id.header.length = htons(TE_LINK_SUBTLV_DEF_SIZE);
718e3744 396
d62a17ae 397 /*
398 * The Link ID is identical to the contents of the Link ID field
399 * in the Router LSA for these link types.
400 */
401 switch (oi->type) {
402 case OSPF_IFTYPE_POINTOPOINT:
403 /* Take the router ID of the neighbor. */
404 if ((nbr = ospf_nbr_lookup_ptop(oi))
405 && nbr->state == NSM_Full) {
406 lp->link_id.value = nbr->router_id;
407 done = 1;
408 }
409 break;
410 case OSPF_IFTYPE_BROADCAST:
411 case OSPF_IFTYPE_NBMA:
412 /* Take the interface address of the designated router. */
413 if ((nbr = ospf_nbr_lookup_by_addr(oi->nbrs, &DR(oi))) == NULL)
414 break;
718e3744 415
d62a17ae 416 if (nbr->state == NSM_Full
417 || (IPV4_ADDR_SAME(&oi->address->u.prefix4, &DR(oi))
418 && ospf_nbr_count(oi, NSM_Full) > 0)) {
419 lp->link_id.value = DR(oi);
420 done = 1;
421 }
422 break;
423 default:
424 /* Not supported yet. */ /* XXX */
425 lp->link_id.header.type = htons(0);
426 break;
427 }
428
429 if (!done) {
430 struct in_addr mask;
431 masklen2ip(oi->address->prefixlen, &mask);
432 lp->link_id.value.s_addr =
433 oi->address->u.prefix4.s_addr & mask.s_addr;
434 }
435 return;
718e3744 436}
437
d62a17ae 438static void set_linkparams_lclif_ipaddr(struct mpls_te_link *lp,
439 struct in_addr lclif)
16f1b9ee
OD
440{
441
d62a17ae 442 lp->lclif_ipaddr.header.type = htons(TE_LINK_SUBTLV_LCLIF_IPADDR);
443 lp->lclif_ipaddr.header.length = htons(TE_LINK_SUBTLV_DEF_SIZE);
444 lp->lclif_ipaddr.value[0] = lclif;
445 return;
16f1b9ee
OD
446}
447
d62a17ae 448static void set_linkparams_rmtif_ipaddr(struct mpls_te_link *lp,
449 struct in_addr rmtif)
16f1b9ee
OD
450{
451
d62a17ae 452 lp->rmtif_ipaddr.header.type = htons(TE_LINK_SUBTLV_RMTIF_IPADDR);
453 lp->rmtif_ipaddr.header.length = htons(TE_LINK_SUBTLV_DEF_SIZE);
454 lp->rmtif_ipaddr.value[0] = rmtif;
455 return;
16f1b9ee
OD
456}
457
d62a17ae 458static void set_linkparams_te_metric(struct mpls_te_link *lp,
459 u_int32_t te_metric)
718e3744 460{
d62a17ae 461 lp->te_metric.header.type = htons(TE_LINK_SUBTLV_TE_METRIC);
462 lp->te_metric.header.length = htons(TE_LINK_SUBTLV_DEF_SIZE);
463 lp->te_metric.value = htonl(te_metric);
464 return;
718e3744 465}
466
d62a17ae 467static void set_linkparams_max_bw(struct mpls_te_link *lp, float fp)
718e3744 468{
d62a17ae 469 lp->max_bw.header.type = htons(TE_LINK_SUBTLV_MAX_BW);
470 lp->max_bw.header.length = htons(TE_LINK_SUBTLV_DEF_SIZE);
471 lp->max_bw.value = htonf(fp);
472 return;
718e3744 473}
474
d62a17ae 475static void set_linkparams_max_rsv_bw(struct mpls_te_link *lp, float fp)
718e3744 476{
d62a17ae 477 lp->max_rsv_bw.header.type = htons(TE_LINK_SUBTLV_MAX_RSV_BW);
478 lp->max_rsv_bw.header.length = htons(TE_LINK_SUBTLV_DEF_SIZE);
479 lp->max_rsv_bw.value = htonf(fp);
480 return;
718e3744 481}
482
d62a17ae 483static void set_linkparams_unrsv_bw(struct mpls_te_link *lp, int priority,
484 float fp)
718e3744 485{
d62a17ae 486 /* Note that TLV-length field is the size of array. */
487 lp->unrsv_bw.header.type = htons(TE_LINK_SUBTLV_UNRSV_BW);
488 lp->unrsv_bw.header.length = htons(TE_LINK_SUBTLV_UNRSV_SIZE);
489 lp->unrsv_bw.value[priority] = htonf(fp);
490 return;
718e3744 491}
492
d62a17ae 493static void set_linkparams_rsc_clsclr(struct mpls_te_link *lp,
494 u_int32_t classcolor)
718e3744 495{
d62a17ae 496 lp->rsc_clsclr.header.type = htons(TE_LINK_SUBTLV_RSC_CLSCLR);
497 lp->rsc_clsclr.header.length = htons(TE_LINK_SUBTLV_DEF_SIZE);
498 lp->rsc_clsclr.value = htonl(classcolor);
499 return;
718e3744 500}
501
d62a17ae 502static void set_linkparams_inter_as(struct mpls_te_link *lp,
503 struct in_addr addr, u_int32_t as)
16f1b9ee
OD
504{
505
d62a17ae 506 /* Set the Remote ASBR IP address and then the associated AS number */
507 lp->rip.header.type = htons(TE_LINK_SUBTLV_RIP);
508 lp->rip.header.length = htons(TE_LINK_SUBTLV_DEF_SIZE);
509 lp->rip.value = addr;
16f1b9ee 510
d62a17ae 511 lp->ras.header.type = htons(TE_LINK_SUBTLV_RAS);
512 lp->ras.header.length = htons(TE_LINK_SUBTLV_DEF_SIZE);
513 lp->ras.value = htonl(as);
16f1b9ee
OD
514}
515
d62a17ae 516static void unset_linkparams_inter_as(struct mpls_te_link *lp)
16f1b9ee
OD
517{
518
d62a17ae 519 /* Reset the Remote ASBR IP address and then the associated AS number */
520 lp->rip.header.type = htons(0);
521 lp->rip.header.length = htons(0);
522 lp->rip.value.s_addr = htonl(0);
16f1b9ee 523
d62a17ae 524 lp->ras.header.type = htons(0);
525 lp->ras.header.length = htons(0);
526 lp->ras.value = htonl(0);
16f1b9ee
OD
527}
528
d62a17ae 529void set_linkparams_llri(struct mpls_te_link *lp, u_int32_t local,
530 u_int32_t remote)
16f1b9ee
OD
531{
532
d62a17ae 533 lp->llri.header.type = htons(TE_LINK_SUBTLV_LLRI);
534 lp->llri.header.length = htons(TE_LINK_SUBTLV_LLRI_SIZE);
535 lp->llri.local = htonl(local);
536 lp->llri.remote = htonl(remote);
16f1b9ee
OD
537}
538
d62a17ae 539void set_linkparams_lrrid(struct mpls_te_link *lp, struct in_addr local,
540 struct in_addr remote)
16f1b9ee
OD
541{
542
d62a17ae 543 lp->lrrid.header.type = htons(TE_LINK_SUBTLV_LRRID);
544 lp->lrrid.header.length = htons(TE_LINK_SUBTLV_LRRID_SIZE);
545 lp->lrrid.local.s_addr = local.s_addr;
546 lp->lrrid.remote.s_addr = remote.s_addr;
16f1b9ee
OD
547}
548
d62a17ae 549static void set_linkparams_av_delay(struct mpls_te_link *lp, u_int32_t delay,
550 u_char anormal)
16f1b9ee 551{
d62a17ae 552 u_int32_t tmp;
553 /* Note that TLV-length field is the size of array. */
554 lp->av_delay.header.type = htons(TE_LINK_SUBTLV_AV_DELAY);
555 lp->av_delay.header.length = htons(TE_LINK_SUBTLV_DEF_SIZE);
556 tmp = delay & TE_EXT_MASK;
557 if (anormal)
558 tmp |= TE_EXT_ANORMAL;
559 lp->av_delay.value = htonl(tmp);
560 return;
16f1b9ee
OD
561}
562
d62a17ae 563static void set_linkparams_mm_delay(struct mpls_te_link *lp, u_int32_t low,
564 u_int32_t high, u_char anormal)
16f1b9ee 565{
d62a17ae 566 u_int32_t tmp;
567 /* Note that TLV-length field is the size of array. */
568 lp->mm_delay.header.type = htons(TE_LINK_SUBTLV_MM_DELAY);
569 lp->mm_delay.header.length = htons(TE_LINK_SUBTLV_MM_DELAY_SIZE);
570 tmp = low & TE_EXT_MASK;
571 if (anormal)
572 tmp |= TE_EXT_ANORMAL;
573 lp->mm_delay.low = htonl(tmp);
574 lp->mm_delay.high = htonl(high);
575 return;
16f1b9ee
OD
576}
577
d62a17ae 578static void set_linkparams_delay_var(struct mpls_te_link *lp, u_int32_t jitter)
16f1b9ee 579{
d62a17ae 580 /* Note that TLV-length field is the size of array. */
581 lp->delay_var.header.type = htons(TE_LINK_SUBTLV_DELAY_VAR);
582 lp->delay_var.header.length = htons(TE_LINK_SUBTLV_DEF_SIZE);
583 lp->delay_var.value = htonl(jitter & TE_EXT_MASK);
584 return;
16f1b9ee
OD
585}
586
d62a17ae 587static void set_linkparams_pkt_loss(struct mpls_te_link *lp, u_int32_t loss,
588 u_char anormal)
16f1b9ee 589{
d62a17ae 590 u_int32_t tmp;
591 /* Note that TLV-length field is the size of array. */
592 lp->pkt_loss.header.type = htons(TE_LINK_SUBTLV_PKT_LOSS);
593 lp->pkt_loss.header.length = htons(TE_LINK_SUBTLV_DEF_SIZE);
594 tmp = loss & TE_EXT_MASK;
595 if (anormal)
596 tmp |= TE_EXT_ANORMAL;
597 lp->pkt_loss.value = htonl(tmp);
598 return;
16f1b9ee
OD
599}
600
d62a17ae 601static void set_linkparams_res_bw(struct mpls_te_link *lp, float fp)
16f1b9ee 602{
d62a17ae 603 /* Note that TLV-length field is the size of array. */
604 lp->res_bw.header.type = htons(TE_LINK_SUBTLV_RES_BW);
605 lp->res_bw.header.length = htons(TE_LINK_SUBTLV_DEF_SIZE);
606 lp->res_bw.value = htonf(fp);
607 return;
16f1b9ee
OD
608}
609
d62a17ae 610static void set_linkparams_ava_bw(struct mpls_te_link *lp, float fp)
16f1b9ee 611{
d62a17ae 612 /* Note that TLV-length field is the size of array. */
613 lp->ava_bw.header.type = htons(TE_LINK_SUBTLV_AVA_BW);
614 lp->ava_bw.header.length = htons(TE_LINK_SUBTLV_DEF_SIZE);
615 lp->ava_bw.value = htonf(fp);
616 return;
16f1b9ee
OD
617}
618
d62a17ae 619static void set_linkparams_use_bw(struct mpls_te_link *lp, float fp)
16f1b9ee 620{
d62a17ae 621 /* Note that TLV-length field is the size of array. */
622 lp->use_bw.header.type = htons(TE_LINK_SUBTLV_USE_BW);
623 lp->use_bw.header.length = htons(TE_LINK_SUBTLV_DEF_SIZE);
624 lp->use_bw.value = htonf(fp);
625 return;
16f1b9ee
OD
626}
627
628/* Update TE parameters from Interface */
d62a17ae 629static void update_linkparams(struct mpls_te_link *lp)
630{
631 int i;
632 struct interface *ifp;
633
634 /* Get the Interface structure */
635 if ((ifp = lp->ifp) == NULL) {
636 if (IS_DEBUG_OSPF_TE)
637 zlog_debug(
638 "OSPF MPLS-TE: Abort update TE parameters: no interface associated to Link Parameters");
639 return;
640 }
641 if (!HAS_LINK_PARAMS(ifp)) {
642 if (IS_DEBUG_OSPF_TE)
643 zlog_debug(
644 "OSPF MPLS-TE: Abort update TE parameters: no Link Parameters for interface");
645 return;
646 }
647
648 /* RFC3630 metrics */
649 if (IS_PARAM_SET(ifp->link_params, LP_ADM_GRP))
650 set_linkparams_rsc_clsclr(lp, ifp->link_params->admin_grp);
651 else
652 TLV_TYPE(lp->rsc_clsclr) = 0;
653
654 if (IS_PARAM_SET(ifp->link_params, LP_MAX_BW))
655 set_linkparams_max_bw(lp, ifp->link_params->max_bw);
656 else
657 TLV_TYPE(lp->max_bw) = 0;
658
659 if (IS_PARAM_SET(ifp->link_params, LP_MAX_RSV_BW))
660 set_linkparams_max_rsv_bw(lp, ifp->link_params->max_rsv_bw);
661 else
662 TLV_TYPE(lp->max_rsv_bw) = 0;
663
664 if (IS_PARAM_SET(ifp->link_params, LP_UNRSV_BW))
665 for (i = 0; i < MAX_CLASS_TYPE; i++)
666 set_linkparams_unrsv_bw(lp, i,
667 ifp->link_params->unrsv_bw[i]);
668 else
669 TLV_TYPE(lp->unrsv_bw) = 0;
670
671 if (IS_PARAM_SET(ifp->link_params, LP_TE_METRIC))
672 set_linkparams_te_metric(lp, ifp->link_params->te_metric);
673 else
674 TLV_TYPE(lp->te_metric) = 0;
675
676 /* TE metric Extensions */
677 if (IS_PARAM_SET(ifp->link_params, LP_DELAY))
678 set_linkparams_av_delay(lp, ifp->link_params->av_delay, 0);
679 else
680 TLV_TYPE(lp->av_delay) = 0;
681
682 if (IS_PARAM_SET(ifp->link_params, LP_MM_DELAY))
683 set_linkparams_mm_delay(lp, ifp->link_params->min_delay,
684 ifp->link_params->max_delay, 0);
685 else
686 TLV_TYPE(lp->mm_delay) = 0;
687
688 if (IS_PARAM_SET(ifp->link_params, LP_DELAY_VAR))
689 set_linkparams_delay_var(lp, ifp->link_params->delay_var);
690 else
691 TLV_TYPE(lp->delay_var) = 0;
692
693 if (IS_PARAM_SET(ifp->link_params, LP_PKT_LOSS))
694 set_linkparams_pkt_loss(lp, ifp->link_params->pkt_loss, 0);
695 else
696 TLV_TYPE(lp->pkt_loss) = 0;
697
698 if (IS_PARAM_SET(ifp->link_params, LP_RES_BW))
699 set_linkparams_res_bw(lp, ifp->link_params->res_bw);
700 else
701 TLV_TYPE(lp->res_bw) = 0;
702
703 if (IS_PARAM_SET(ifp->link_params, LP_AVA_BW))
704 set_linkparams_ava_bw(lp, ifp->link_params->ava_bw);
705 else
706 TLV_TYPE(lp->ava_bw) = 0;
707
708 if (IS_PARAM_SET(ifp->link_params, LP_USE_BW))
709 set_linkparams_use_bw(lp, ifp->link_params->use_bw);
710 else
711 TLV_TYPE(lp->use_bw) = 0;
712
713 /* RFC5392 */
714 if (IS_PARAM_SET(ifp->link_params, LP_RMT_AS)) {
715 /* Flush LSA if it engaged and was previously a STD_TE one */
716 if (IS_STD_TE(lp->type)
717 && CHECK_FLAG(lp->flags, LPFLG_LSA_ENGAGED)) {
718 if (IS_DEBUG_OSPF_TE)
719 zlog_debug(
720 "OSPF MPLS-TE Update IF: Switch from Standard LSA to INTER-AS for %s[%d/%d]",
721 ifp->name, lp->flags, lp->type);
722
723 ospf_mpls_te_lsa_schedule(lp, FLUSH_THIS_LSA);
724 /* Then, switch it to INTER-AS */
725 if (OspfMplsTE.inter_as == AS)
726 lp->flags = INTER_AS | FLOOD_AS;
727 else {
728 lp->flags = INTER_AS | FLOOD_AREA;
729 lp->area = ospf_area_lookup_by_area_id(
b5a8894d 730 ospf_lookup_by_vrf_id(VRF_DEFAULT),
d62a17ae 731 OspfMplsTE.interas_areaid);
732 }
733 }
734 set_linkparams_inter_as(lp, ifp->link_params->rmt_ip,
735 ifp->link_params->rmt_as);
736 } else {
737 if (IS_DEBUG_OSPF_TE)
738 zlog_debug(
739 "OSPF MPLS-TE Update IF: Switch from INTER-AS LSA to Standard for %s[%d/%d]",
740 ifp->name, lp->flags, lp->type);
741
742 /* reset inter-as TE params */
743 /* Flush LSA if it engaged and was previously an INTER_AS one */
744 if (IS_INTER_AS(lp->type)
745 && CHECK_FLAG(lp->flags, LPFLG_LSA_ENGAGED)) {
746 ospf_mpls_te_lsa_schedule(lp, FLUSH_THIS_LSA);
747 /* Then, switch it to Standard TE */
748 lp->flags = STD_TE | FLOOD_AREA;
749 }
750 unset_linkparams_inter_as(lp);
751 }
752}
753
754static void initialize_linkparams(struct mpls_te_link *lp)
755{
756 struct interface *ifp = lp->ifp;
ead99d5f
OD
757 struct ospf_interface *oi = NULL;
758 struct route_node *rn;
d62a17ae 759
760 if (IS_DEBUG_OSPF_TE)
761 zlog_debug(
762 "MPLS-TE(initialize_linkparams) Initialize Link Parameters for interface %s",
763 ifp->name);
764
ead99d5f
OD
765 /* Search OSPF Interface parameters for this interface */
766 for (rn = route_top (IF_OIFS (ifp)); rn; rn = route_next (rn)) {
767
768 if ((oi = rn->info) == NULL)
769 continue;
770
771 if (oi->ifp == ifp)
772 break;
773 }
774
775 if ((oi == NULL) || (oi->ifp != ifp)) {
d62a17ae 776 if (IS_DEBUG_OSPF_TE)
777 zlog_warn(
778 "MPLS-TE(initialize_linkparams) Could not find corresponding OSPF Interface for %s",
779 ifp->name);
780 return;
781 }
782
783 /*
784 * Try to set initial values those can be derived from
785 * zebra-interface information.
786 */
787 set_linkparams_link_type(oi, lp);
788
789 /* Set local IP addr */
790 set_linkparams_lclif_ipaddr(lp, oi->address->u.prefix4);
791
792 /* Set Remote IP addr if Point to Point Interface */
ead99d5f 793 if (oi->type == OSPF_IFTYPE_POINTOPOINT) {
d62a17ae 794 struct prefix *pref = CONNECTED_PREFIX(oi->connected);
795 if (pref != NULL)
796 set_linkparams_rmtif_ipaddr(lp, pref->u.prefix4);
797 }
798
799 /* Keep Area information in combination with link parameters. */
800 lp->area = oi->area;
801
802 return;
803}
804
805static int is_mandated_params_set(struct mpls_te_link *lp)
806{
807 int rc = 0;
808
809 if (ntohs(OspfMplsTE.router_addr.header.type) == 0) {
810 zlog_warn(
811 "MPLS-TE(is_mandated_params_set) Missing Router Address");
ead99d5f 812 return rc;
d62a17ae 813 }
814
815 if (ntohs(lp->link_type.header.type) == 0) {
816 zlog_warn("MPLS-TE(is_mandated_params_set) Missing Link Type");
ead99d5f 817 return rc;
d62a17ae 818 }
819
820 if (!IS_INTER_AS(lp->type) && (ntohs(lp->link_id.header.type) == 0)) {
821 zlog_warn("MPLS-TE(is_mandated_params_set) Missing Link ID");
ead99d5f 822 return rc;
d62a17ae 823 }
824
825 rc = 1;
d62a17ae 826 return rc;
718e3744 827}
828
829/*------------------------------------------------------------------------*
830 * Followings are callback functions against generic Opaque-LSAs handling.
831 *------------------------------------------------------------------------*/
832
d62a17ae 833static int ospf_mpls_te_new_if(struct interface *ifp)
718e3744 834{
d62a17ae 835 struct mpls_te_link *new;
836 int rc = -1;
718e3744 837
d62a17ae 838 if (IS_DEBUG_OSPF_TE)
839 zlog_debug(
840 "MPLS-TE(ospf_mpls_te_new_if) Add new %s interface %s to MPLS-TE list",
841 ifp->link_params ? "Active" : "Inactive", ifp->name);
16f1b9ee 842
d62a17ae 843 if (lookup_linkparams_by_ifp(ifp) != NULL) {
844 zlog_warn("ospf_mpls_te_new_if: ifp(%p) already in use?",
845 (void *)ifp);
846 rc = 0; /* Do nothing here. */
ead99d5f 847 return rc;
d62a17ae 848 }
718e3744 849
d62a17ae 850 new = XCALLOC(MTYPE_OSPF_MPLS_TE, sizeof(struct mpls_te_link));
851 if (new == NULL) {
852 zlog_warn("ospf_mpls_te_new_if: XMALLOC: %s",
853 safe_strerror(errno));
ead99d5f 854 return rc;
d62a17ae 855 }
718e3744 856
d62a17ae 857 new->instance = get_mpls_te_instance_value();
858 new->ifp = ifp;
859 /* By default TE-Link is RFC3630 compatible flooding in Area and not
860 * active */
861 /* This default behavior will be adapted with call to
862 * ospf_mpls_te_update_if() */
863 new->type = STD_TE | FLOOD_AREA;
864 new->flags = LPFLG_LSA_INACTIVE;
16f1b9ee 865
d62a17ae 866 /* Initialize Link Parameters from Interface */
867 initialize_linkparams(new);
718e3744 868
d62a17ae 869 /* Set TE Parameters from Interface */
870 update_linkparams(new);
718e3744 871
d62a17ae 872 /* Add Link Parameters structure to the list */
873 listnode_add(OspfMplsTE.iflist, new);
718e3744 874
d62a17ae 875 if (IS_DEBUG_OSPF_TE)
876 zlog_debug(
877 "OSPF MPLS-TE New IF: Add new LP context for %s[%d/%d]",
878 ifp->name, new->flags, new->type);
16f1b9ee 879
d62a17ae 880 /* Schedule Opaque-LSA refresh. */ /* XXX */
718e3744 881
d62a17ae 882 rc = 0;
d62a17ae 883 return rc;
718e3744 884}
885
d62a17ae 886static int ospf_mpls_te_del_if(struct interface *ifp)
718e3744 887{
d62a17ae 888 struct mpls_te_link *lp;
889 int rc = -1;
718e3744 890
d62a17ae 891 if ((lp = lookup_linkparams_by_ifp(ifp)) != NULL) {
892 struct list *iflist = OspfMplsTE.iflist;
718e3744 893
d62a17ae 894 /* Dequeue listnode entry from the list. */
895 listnode_delete(iflist, lp);
718e3744 896
d62a17ae 897 /* Avoid misjudgement in the next lookup. */
898 if (listcount(iflist) == 0)
899 iflist->head = iflist->tail = NULL;
718e3744 900
d62a17ae 901 XFREE(MTYPE_OSPF_MPLS_TE, lp);
902 }
718e3744 903
d62a17ae 904 /* Schedule Opaque-LSA refresh. */ /* XXX */
718e3744 905
d62a17ae 906 rc = 0;
d62a17ae 907 return rc;
718e3744 908}
909
16f1b9ee
OD
910/* Main initialization / update function of the MPLS TE Link context */
911
912/* Call when interface TE Link parameters are modified */
d62a17ae 913void ospf_mpls_te_update_if(struct interface *ifp)
914{
915 struct mpls_te_link *lp;
916
917 if (IS_DEBUG_OSPF_TE)
918 zlog_debug(
919 "OSPF MPLS-TE: Update LSA parameters for interface %s [%s]",
920 ifp->name, HAS_LINK_PARAMS(ifp) ? "ON" : "OFF");
921
922 /* Get Link context from interface */
923 if ((lp = lookup_linkparams_by_ifp(ifp)) == NULL) {
ead99d5f
OD
924 zlog_warn(
925 "OSPF MPLS-TE Update: Did not find Link Parameters context for interface %s",
926 ifp->name);
d62a17ae 927 return;
928 }
929
930 /* Fulfill MPLS-TE Link TLV from Interface TE Link parameters */
931 if (HAS_LINK_PARAMS(ifp)) {
932 SET_FLAG(lp->flags, LPFLG_LSA_ACTIVE);
933
934 /* Update TE parameters */
935 update_linkparams(lp);
936
937 /* Finally Re-Originate or Refresh Opaque LSA if MPLS_TE is
938 * enabled */
32ab5cf4 939 if (OspfMplsTE.enabled)
d62a17ae 940 if (lp->area != NULL) {
32ab5cf4
OD
941 if (CHECK_FLAG(lp->flags, LPFLG_LSA_ENGAGED))
942 ospf_mpls_te_lsa_schedule(lp, REFRESH_THIS_LSA);
943 else
944 ospf_mpls_te_lsa_schedule(lp, REORIGINATE_THIS_LSA);
d62a17ae 945 }
946 } else {
947 /* If MPLS TE is disable on this interface, flush LSA if it is
948 * already engaged */
32ab5cf4
OD
949 if (CHECK_FLAG(lp->flags, LPFLG_LSA_ENGAGED))
950 ospf_mpls_te_lsa_schedule(lp, FLUSH_THIS_LSA);
d62a17ae 951 else
952 /* Reset Activity flag */
953 lp->flags = LPFLG_LSA_INACTIVE;
954 }
955
956 return;
957}
958
959static void ospf_mpls_te_ism_change(struct ospf_interface *oi, int old_state)
960{
961 struct te_link_subtlv_link_type old_type;
962 struct te_link_subtlv_link_id old_id;
963 struct mpls_te_link *lp;
964
965 if ((lp = lookup_linkparams_by_ifp(oi->ifp)) == NULL) {
966 zlog_warn(
967 "ospf_mpls_te_ism_change: Cannot get linkparams from OI(%s)?",
968 IF_NAME(oi));
ead99d5f 969 return;
d62a17ae 970 }
971
972 if (oi->area == NULL || oi->area->ospf == NULL) {
973 zlog_warn(
974 "ospf_mpls_te_ism_change: Cannot refer to OSPF from OI(%s)?",
975 IF_NAME(oi));
ead99d5f 976 return;
d62a17ae 977 }
718e3744 978#ifdef notyet
d62a17ae 979 if ((lp->area != NULL
980 && !IPV4_ADDR_SAME(&lp->area->area_id, &oi->area->area_id))
981 || (lp->area != NULL && oi->area == NULL)) {
982 /* How should we consider this case? */
983 zlog_warn(
984 "MPLS-TE: Area for OI(%s) has changed to [%s], flush previous LSAs",
985 IF_NAME(oi),
986 oi->area ? inet_ntoa(oi->area->area_id) : "N/A");
987 ospf_mpls_te_lsa_schedule(lp, FLUSH_THIS_LSA);
988 }
718e3744 989#endif
d62a17ae 990 /* Keep Area information in combination with linkparams. */
991 lp->area = oi->area;
992
993 /* Keep interface MPLS-TE status */
994 lp->flags = HAS_LINK_PARAMS(oi->ifp);
995
996 switch (oi->state) {
997 case ISM_PointToPoint:
998 case ISM_DROther:
999 case ISM_Backup:
1000 case ISM_DR:
1001 old_type = lp->link_type;
1002 old_id = lp->link_id;
1003
1004 /* Set Link type, Link ID, Local and Remote IP addr */
1005 set_linkparams_link_type(oi, lp);
1006 set_linkparams_link_id(oi, lp);
1007 set_linkparams_lclif_ipaddr(lp, oi->address->u.prefix4);
1008
1009 if (oi->type == LINK_TYPE_SUBTLV_VALUE_PTP) {
1010 struct prefix *pref = CONNECTED_PREFIX(oi->connected);
1011 if (pref != NULL)
1012 set_linkparams_rmtif_ipaddr(lp,
1013 pref->u.prefix4);
1014 }
1015
1016 /* Update TE parameters */
1017 update_linkparams(lp);
1018
1019 /* Try to Schedule LSA */
1020 if ((ntohs(old_type.header.type)
1021 != ntohs(lp->link_type.header.type)
1022 || old_type.link_type.value
1023 != lp->link_type.link_type.value)
1024 || (ntohs(old_id.header.type)
1025 != ntohs(lp->link_id.header.type)
1026 || ntohl(old_id.value.s_addr)
1027 != ntohl(lp->link_id.value.s_addr))) {
32ab5cf4
OD
1028 if (CHECK_FLAG(lp->flags, LPFLG_LSA_ENGAGED))
1029 ospf_mpls_te_lsa_schedule(lp, REFRESH_THIS_LSA);
1030 else
1031 ospf_mpls_te_lsa_schedule(lp, REORIGINATE_THIS_LSA);
d62a17ae 1032 }
1033 break;
1034 default:
1035 lp->link_type.header.type = htons(0);
1036 lp->link_id.header.type = htons(0);
1037
32ab5cf4
OD
1038 if (CHECK_FLAG(lp->flags, LPFLG_LSA_ENGAGED))
1039 ospf_mpls_te_lsa_schedule(lp, FLUSH_THIS_LSA);
d62a17ae 1040 break;
1041 }
718e3744 1042
d62a17ae 1043 return;
718e3744 1044}
1045
d62a17ae 1046static void ospf_mpls_te_nsm_change(struct ospf_neighbor *nbr, int old_state)
718e3744 1047{
d62a17ae 1048 /* Nothing to do here */
1049 return;
718e3744 1050}
1051
1052/*------------------------------------------------------------------------*
1053 * Followings are OSPF protocol processing functions for MPLS-TE.
1054 *------------------------------------------------------------------------*/
1055
ead99d5f 1056static void build_tlv_header(struct stream *s, struct tlv_header *tlvh)
d62a17ae 1057{
ead99d5f 1058 stream_put(s, tlvh, sizeof(struct tlv_header));
d62a17ae 1059 return;
1060}
1061
1062static void build_router_tlv(struct stream *s)
1063{
ead99d5f 1064 struct tlv_header *tlvh = &OspfMplsTE.router_addr.header;
d62a17ae 1065 if (ntohs(tlvh->type) != 0) {
1066 build_tlv_header(s, tlvh);
5d0df50f 1067 stream_put(s, TLV_DATA(tlvh), TLV_BODY_SIZE(tlvh));
d62a17ae 1068 }
1069 return;
1070}
1071
ead99d5f 1072static void build_link_subtlv(struct stream *s, struct tlv_header *tlvh)
d62a17ae 1073{
1074
1075 if ((tlvh != NULL) && (ntohs(tlvh->type) != 0)) {
1076 build_tlv_header(s, tlvh);
5d0df50f 1077 stream_put(s, TLV_DATA(tlvh), TLV_BODY_SIZE(tlvh));
d62a17ae 1078 }
1079 return;
1080}
1081
1082static void build_link_tlv(struct stream *s, struct mpls_te_link *lp)
1083{
1084 set_linkparams_link_header(lp);
1085 build_tlv_header(s, &lp->link_header.header);
1086
1087 build_link_subtlv(s, &lp->link_type.header);
1088 build_link_subtlv(s, &lp->link_id.header);
1089 build_link_subtlv(s, &lp->lclif_ipaddr.header);
1090 build_link_subtlv(s, &lp->rmtif_ipaddr.header);
1091 build_link_subtlv(s, &lp->te_metric.header);
1092 build_link_subtlv(s, &lp->max_bw.header);
1093 build_link_subtlv(s, &lp->max_rsv_bw.header);
1094 build_link_subtlv(s, &lp->unrsv_bw.header);
1095 build_link_subtlv(s, &lp->rsc_clsclr.header);
1096 build_link_subtlv(s, &lp->lrrid.header);
1097 build_link_subtlv(s, &lp->llri.header);
1098 build_link_subtlv(s, &lp->rip.header);
1099 build_link_subtlv(s, &lp->ras.header);
1100 build_link_subtlv(s, &lp->av_delay.header);
1101 build_link_subtlv(s, &lp->mm_delay.header);
1102 build_link_subtlv(s, &lp->delay_var.header);
1103 build_link_subtlv(s, &lp->pkt_loss.header);
1104 build_link_subtlv(s, &lp->res_bw.header);
1105 build_link_subtlv(s, &lp->ava_bw.header);
1106 build_link_subtlv(s, &lp->use_bw.header);
1107
1108 return;
1109}
1110
1111static void ospf_mpls_te_lsa_body_set(struct stream *s, struct mpls_te_link *lp)
1112{
1113 /*
1114 * The router address TLV is type 1, and ...
1115 * It must appear in exactly one
1116 * Traffic Engineering LSA originated by a router.
1117 */
1118 build_router_tlv(s);
1119
1120 /*
1121 * Only one Link TLV shall be carried in each LSA, allowing for fine
1122 * granularity changes in topology.
1123 */
1124 build_link_tlv(s, lp);
1125 return;
718e3744 1126}
1127
1128/* Create new opaque-LSA. */
b5a8894d
CS
1129static struct ospf_lsa *ospf_mpls_te_lsa_new(struct ospf *ospf,
1130 struct ospf_area *area,
d62a17ae 1131 struct mpls_te_link *lp)
1132{
1133 struct stream *s;
1134 struct lsa_header *lsah;
1135 struct ospf_lsa *new = NULL;
1136 u_char options, lsa_type = 0;
1137 struct in_addr lsa_id;
1138 u_int32_t tmp;
1139 u_int16_t length;
1140
1141 /* Create a stream for LSA. */
1142 if ((s = stream_new(OSPF_MAX_LSA_SIZE)) == NULL) {
1143 zlog_warn("ospf_mpls_te_lsa_new: stream_new() ?");
ead99d5f 1144 return NULL;
d62a17ae 1145 }
1146 lsah = (struct lsa_header *)STREAM_DATA(s);
1147
1148 options = OSPF_OPTION_O; /* Don't forget this :-) */
1149
1150 /* Set opaque-LSA header fields depending of the type of RFC */
1151 if (IS_INTER_AS(lp->type)) {
1152 if
1153 IS_FLOOD_AS(lp->type)
1154 {
1155 options |= OSPF_OPTION_E; /* Enable AS external
1156 as we flood
1157 Inter-AS with
1158 Opaque Type 11 */
1159 lsa_type = OSPF_OPAQUE_AS_LSA;
1160 }
1161 else {
1162 options |= LSA_OPTIONS_GET(
1163 area); /* Get area default option */
1164 options |= LSA_OPTIONS_NSSA_GET(area);
1165 lsa_type = OSPF_OPAQUE_AREA_LSA;
1166 }
1167 tmp = SET_OPAQUE_LSID(OPAQUE_TYPE_INTER_AS_LSA, lp->instance);
1168 lsa_id.s_addr = htonl(tmp);
1169
0760d3c9
DS
1170 if (!ospf) {
1171 stream_free(s);
b5a8894d 1172 return NULL;
0760d3c9 1173 }
d62a17ae 1174
b5a8894d 1175 lsa_header_set(s, options, lsa_type, lsa_id, ospf->router_id);
d62a17ae 1176 } else {
1177 options |= LSA_OPTIONS_GET(area); /* Get area default option */
1178 options |= LSA_OPTIONS_NSSA_GET(area);
1179 lsa_type = OSPF_OPAQUE_AREA_LSA;
1180 tmp = SET_OPAQUE_LSID(OPAQUE_TYPE_TRAFFIC_ENGINEERING_LSA,
1181 lp->instance);
1182 lsa_id.s_addr = htonl(tmp);
1183 lsa_header_set(s, options, lsa_type, lsa_id,
1184 area->ospf->router_id);
1185 }
1186
1187 if (IS_DEBUG_OSPF(lsa, LSA_GENERATE))
1188 zlog_debug(
1189 "LSA[Type%d:%s]: Create an Opaque-LSA/MPLS-TE instance",
1190 lsa_type, inet_ntoa(lsa_id));
1191
1192 /* Set opaque-LSA body fields. */
1193 ospf_mpls_te_lsa_body_set(s, lp);
1194
1195 /* Set length. */
1196 length = stream_get_endp(s);
1197 lsah->length = htons(length);
1198
1199 /* Now, create an OSPF LSA instance. */
1200 if ((new = ospf_lsa_new()) == NULL) {
1201 zlog_warn("ospf_mpls_te_lsa_new: ospf_lsa_new() ?");
1202 stream_free(s);
ead99d5f 1203 return NULL;
d62a17ae 1204 }
1205 if ((new->data = ospf_lsa_data_new(length)) == NULL) {
1206 zlog_warn("ospf_mpls_te_lsa_new: ospf_lsa_data_new() ?");
1207 ospf_lsa_unlock(&new);
1208 new = NULL;
1209 stream_free(s);
ead99d5f 1210 return new;
d62a17ae 1211 }
1212
b5a8894d
CS
1213 new->vrf_id = ospf->vrf_id;
1214 if (area && area->ospf)
1215 new->vrf_id = area->ospf->vrf_id;
d62a17ae 1216 new->area = area;
1217 SET_FLAG(new->flags, OSPF_LSA_SELF);
1218 memcpy(new->data, lsah, length);
1219 stream_free(s);
718e3744 1220
d62a17ae 1221 return new;
1222}
1223
1224static int ospf_mpls_te_lsa_originate1(struct ospf_area *area,
1225 struct mpls_te_link *lp)
1226{
b5a8894d 1227 struct ospf_lsa *new = NULL;
d62a17ae 1228 int rc = -1;
1229
1230 /* Create new Opaque-LSA/MPLS-TE instance. */
b5a8894d
CS
1231 new = ospf_mpls_te_lsa_new(area->ospf, area, lp);
1232 if (new == NULL) {
d62a17ae 1233 zlog_warn(
1234 "ospf_mpls_te_lsa_originate1: ospf_mpls_te_lsa_new() ?");
ead99d5f 1235 return rc;
d62a17ae 1236 }
1237
1238 /* Install this LSA into LSDB. */
1239 if (ospf_lsa_install(area->ospf, NULL /*oi*/, new) == NULL) {
1240 zlog_warn("ospf_mpls_te_lsa_originate1: ospf_lsa_install() ?");
1241 ospf_lsa_unlock(&new);
ead99d5f 1242 return rc;
d62a17ae 1243 }
1244
1245 /* Now this link-parameter entry has associated LSA. */
1246 SET_FLAG(lp->flags, LPFLG_LSA_ENGAGED);
1247 /* Update new LSA origination count. */
1248 area->ospf->lsa_originate_count++;
1249
1250 /* Flood new LSA through area. */
1251 ospf_flood_through_area(area, NULL /*nbr*/, new);
1252
1253 if (IS_DEBUG_OSPF(lsa, LSA_GENERATE)) {
1254 char area_id[INET_ADDRSTRLEN];
1255 strcpy(area_id, inet_ntoa(area->area_id));
1256 zlog_debug(
1257 "LSA[Type%d:%s]: Originate Opaque-LSA/MPLS-TE: Area(%s), Link(%s)",
1258 new->data->type, inet_ntoa(new->data->id), area_id,
1259 lp->ifp->name);
1260 ospf_lsa_header_dump(new->data);
1261 }
1262
1263 rc = 0;
d62a17ae 1264 return rc;
1265}
1266
1267static int ospf_mpls_te_lsa_originate_area(void *arg)
1268{
1269 struct ospf_area *area = (struct ospf_area *)arg;
1270 struct listnode *node, *nnode;
1271 struct mpls_te_link *lp;
1272 int rc = -1;
1273
32ab5cf4 1274 if (!OspfMplsTE.enabled) {
d62a17ae 1275 zlog_info(
1276 "ospf_mpls_te_lsa_originate_area: MPLS-TE is disabled now.");
1277 rc = 0; /* This is not an error case. */
ead99d5f 1278 return rc;
d62a17ae 1279 }
1280
1281 for (ALL_LIST_ELEMENTS(OspfMplsTE.iflist, node, nnode, lp)) {
1282 /* Process only enabled LSA with area scope flooding */
1283 if (!CHECK_FLAG(lp->flags, LPFLG_LSA_ACTIVE)
1284 || IS_FLOOD_AS(lp->type))
1285 continue;
1286
1287 if (lp->area == NULL)
1288 continue;
1289
1290 if (!IPV4_ADDR_SAME(&lp->area->area_id, &area->area_id))
1291 continue;
1292
32ab5cf4
OD
1293 if (CHECK_FLAG(lp->flags, LPFLG_LSA_ENGAGED)) {
1294 if (CHECK_FLAG(lp->flags, LPFLG_LSA_FORCED_REFRESH)) {
1295 UNSET_FLAG(lp->flags, LPFLG_LSA_FORCED_REFRESH);
1296 zlog_warn(
1297 "OSPF MPLS-TE (ospf_mpls_te_lsa_originate_area): Refresh instead of Originate");
1298 ospf_mpls_te_lsa_schedule(lp, REFRESH_THIS_LSA);
d62a17ae 1299 }
32ab5cf4
OD
1300 continue;
1301 }
1302
d62a17ae 1303 if (!is_mandated_params_set(lp)) {
1304 zlog_warn(
1305 "ospf_mpls_te_lsa_originate_area: Link(%s) lacks some mandated MPLS-TE parameters.",
1306 lp->ifp ? lp->ifp->name : "?");
1307 continue;
1308 }
1309
1310 /* Ok, let's try to originate an LSA for this area and Link. */
1311 if (IS_DEBUG_OSPF_TE)
1312 zlog_debug(
1313 "MPLS-TE(ospf_mpls_te_lsa_originate_area) Let's finally reoriginate the LSA %d through the Area %s for Link %s",
1314 lp->instance, inet_ntoa(area->area_id),
1315 lp->ifp ? lp->ifp->name : "?");
1316 if (ospf_mpls_te_lsa_originate1(area, lp) != 0)
ead99d5f 1317 return rc;
d62a17ae 1318 }
1319
1320 rc = 0;
d62a17ae 1321 return rc;
1322}
718e3744 1323
d62a17ae 1324static int ospf_mpls_te_lsa_originate2(struct ospf *top,
1325 struct mpls_te_link *lp)
1326{
1327 struct ospf_lsa *new;
1328 int rc = -1;
1329
1330 /* Create new Opaque-LSA/Inter-AS instance. */
b5a8894d
CS
1331 new = ospf_mpls_te_lsa_new(top, NULL, lp);
1332 if (new == NULL) {
d62a17ae 1333 zlog_warn(
1334 "ospf_mpls_te_lsa_originate2: ospf_router_info_lsa_new() ?");
ead99d5f 1335 return rc;
d62a17ae 1336 }
b5a8894d 1337 new->vrf_id = top->vrf_id;
d62a17ae 1338
1339 /* Install this LSA into LSDB. */
1340 if (ospf_lsa_install(top, NULL /*oi */, new) == NULL) {
1341 zlog_warn("ospf_mpls_te_lsa_originate2: ospf_lsa_install() ?");
1342 ospf_lsa_unlock(&new);
ead99d5f 1343 return rc;
d62a17ae 1344 }
1345
1346 /* Now this Router Info parameter entry has associated LSA. */
1347 SET_FLAG(lp->flags, LPFLG_LSA_ENGAGED);
1348 /* Update new LSA origination count. */
1349 top->lsa_originate_count++;
1350
1351 /* Flood new LSA through AS. */
1352 ospf_flood_through_as(top, NULL /*nbr */, new);
1353
1354 if (IS_DEBUG_OSPF(lsa, LSA_GENERATE)) {
1355 zlog_debug(
1356 "LSA[Type%d:%s]: Originate Opaque-LSA/MPLS-TE Inter-AS",
1357 new->data->type, inet_ntoa(new->data->id));
1358 ospf_lsa_header_dump(new->data);
1359 }
1360
1361 rc = 0;
d62a17ae 1362 return rc;
1363}
1364
1365static int ospf_mpls_te_lsa_originate_as(void *arg)
1366{
1367 struct ospf *top;
1368 struct ospf_area *area;
1369 struct listnode *node, *nnode;
1370 struct mpls_te_link *lp;
1371 int rc = -1;
1372
32ab5cf4 1373 if ((!OspfMplsTE.enabled)
ead99d5f 1374 || (OspfMplsTE.inter_as == Off)) {
d62a17ae 1375 zlog_info(
1376 "ospf_mpls_te_lsa_originate_as: MPLS-TE Inter-AS is disabled for now.");
1377 rc = 0; /* This is not an error case. */
ead99d5f 1378 return rc;
d62a17ae 1379 }
1380
1381 for (ALL_LIST_ELEMENTS(OspfMplsTE.iflist, node, nnode, lp)) {
1382 /* Process only enabled INTER_AS Links or Pseudo-Links */
1383 if (!CHECK_FLAG(lp->flags, LPFLG_LSA_ACTIVE)
1384 || !IS_INTER_AS(lp->type))
1385 continue;
1386
32ab5cf4
OD
1387 if (CHECK_FLAG(lp->flags, LPFLG_LSA_ENGAGED)) {
1388 if (CHECK_FLAG(lp->flags, LPFLG_LSA_FORCED_REFRESH)) {
1389 UNSET_FLAG(lp->flags,LPFLG_LSA_FORCED_REFRESH);
1390 ospf_mpls_te_lsa_schedule(lp, REFRESH_THIS_LSA);
d62a17ae 1391 }
32ab5cf4
OD
1392 continue;
1393 }
1394
d62a17ae 1395 if (!is_mandated_params_set(lp)) {
1396 zlog_warn(
1397 "ospf_mpls_te_lsa_originate_as: Link(%s) lacks some mandated MPLS-TE parameters.",
1398 lp->ifp ? lp->ifp->name : "?");
1399 continue;
1400 }
1401
1402 /* Ok, let's try to originate an LSA for this AS and Link. */
1403 if (IS_DEBUG_OSPF_TE)
1404 zlog_debug(
1405 "MPLS-TE(ospf_mpls_te_lsa_originate_as) Let's finally re-originate the Inter-AS LSA %d through the %s for Link %s",
1406 lp->instance,
1407 IS_FLOOD_AS(lp->type) ? "AS" : "Area",
1408 lp->ifp ? lp->ifp->name : "Unknown");
1409
1410 if (IS_FLOOD_AS(lp->type)) {
1411 top = (struct ospf *)arg;
1412 ospf_mpls_te_lsa_originate2(top, lp);
1413 } else {
1414 area = (struct ospf_area *)arg;
1415 ospf_mpls_te_lsa_originate1(area, lp);
1416 }
1417 }
1418
1419 rc = 0;
d62a17ae 1420 return rc;
1421}
1422
1423static struct ospf_lsa *ospf_mpls_te_lsa_refresh(struct ospf_lsa *lsa)
1424{
1425 struct mpls_te_link *lp;
1426 struct ospf_area *area = lsa->area;
1427 struct ospf *top;
1428 struct ospf_lsa *new = NULL;
1429
32ab5cf4 1430 if (!OspfMplsTE.enabled) {
d62a17ae 1431 /*
1432 * This LSA must have flushed before due to MPLS-TE status
1433 * change.
1434 * It seems a slip among routers in the routing domain.
1435 */
1436 zlog_info("ospf_mpls_te_lsa_refresh: MPLS-TE is disabled now.");
1437 lsa->data->ls_age =
1438 htons(OSPF_LSA_MAXAGE); /* Flush it anyway. */
1439 }
1440
1441 /* At first, resolve lsa/lp relationship. */
1442 if ((lp = lookup_linkparams_by_instance(lsa)) == NULL) {
1443 zlog_warn("ospf_mpls_te_lsa_refresh: Invalid parameter?");
1444 lsa->data->ls_age =
1445 htons(OSPF_LSA_MAXAGE); /* Flush it anyway. */
1446 }
1447
1448 /* Check if lp was not disable in the interval */
1449 if (!CHECK_FLAG(lp->flags, LPFLG_LSA_ACTIVE)) {
1450 zlog_warn(
1451 "ospf_mpls_te_lsa_refresh: lp was disabled: Flush it!");
1452 lsa->data->ls_age =
1453 htons(OSPF_LSA_MAXAGE); /* Flush it anyway. */
1454 }
1455
1456 /* If the lsa's age reached to MaxAge, start flushing procedure. */
1457 if (IS_LSA_MAXAGE(lsa)) {
1458 if (lp)
1459 UNSET_FLAG(lp->flags, LPFLG_LSA_ENGAGED);
1460 ospf_opaque_lsa_flush_schedule(lsa);
ead99d5f 1461 return NULL;
d62a17ae 1462 }
b5a8894d 1463 top = ospf_lookup_by_vrf_id(lsa->vrf_id);
d62a17ae 1464 /* Create new Opaque-LSA/MPLS-TE instance. */
b5a8894d
CS
1465 new = ospf_mpls_te_lsa_new(top, area, lp);
1466 if (new == NULL) {
d62a17ae 1467 zlog_warn("ospf_mpls_te_lsa_refresh: ospf_mpls_te_lsa_new() ?");
ead99d5f 1468 return NULL;
d62a17ae 1469 }
1470 new->data->ls_seqnum = lsa_seqnum_increment(lsa);
1471
1472 /* Install this LSA into LSDB. */
1473 /* Given "lsa" will be freed in the next function. */
1474 /* As area could be NULL i.e. when using OPAQUE_LSA_AS, we prefer to use
1475 * ospf_lookup() to get ospf instance */
1476 if (area)
1477 top = area->ospf;
d62a17ae 1478
1479 if (ospf_lsa_install(top, NULL /*oi */, new) == NULL) {
1480 zlog_warn("ospf_mpls_te_lsa_refresh: ospf_lsa_install() ?");
1481 ospf_lsa_unlock(&new);
ead99d5f 1482 return NULL;
d62a17ae 1483 }
1484
1485 /* Flood updated LSA through AS or Area depending of the RFC of the link
1486 */
1487 if (IS_FLOOD_AS(lp->type))
1488 ospf_flood_through_as(top, NULL, new);
1489 else
1490 ospf_flood_through_area(area, NULL /*nbr*/, new);
1491
1492 /* Debug logging. */
1493 if (IS_DEBUG_OSPF(lsa, LSA_GENERATE)) {
1494 zlog_debug("LSA[Type%d:%s]: Refresh Opaque-LSA/MPLS-TE",
1495 new->data->type, inet_ntoa(new->data->id));
1496 ospf_lsa_header_dump(new->data);
1497 }
1498
d62a17ae 1499 return new;
1500}
1501
2a39170c 1502void ospf_mpls_te_lsa_schedule(struct mpls_te_link *lp, enum lsa_opcode opcode)
d62a17ae 1503{
1504 struct ospf_lsa lsa;
1505 struct lsa_header lsah;
1506 struct ospf *top;
1507 u_int32_t tmp;
1508
1509 memset(&lsa, 0, sizeof(lsa));
1510 memset(&lsah, 0, sizeof(lsah));
b5a8894d 1511 top = ospf_lookup_by_vrf_id(VRF_DEFAULT);
d62a17ae 1512
1513 /* Check if the pseudo link is ready to flood */
1514 if (!(CHECK_FLAG(lp->flags, LPFLG_LSA_ACTIVE))
1515 || !(IS_FLOOD_AREA(lp->type) || IS_FLOOD_AS(lp->type))) {
1516 return;
1517 }
1518
1519 lsa.area = lp->area;
1520 lsa.data = &lsah;
1521 if (IS_FLOOD_AS(lp->type)) {
1522 lsah.type = OSPF_OPAQUE_AS_LSA;
1523 tmp = SET_OPAQUE_LSID(OPAQUE_TYPE_INTER_AS_LSA, lp->instance);
1524 lsah.id.s_addr = htonl(tmp);
1525 } else {
1526 lsah.type = OSPF_OPAQUE_AREA_LSA;
1527 if (IS_INTER_AS(lp->type)) {
1528 /* Set the area context if not know */
1529 if (lp->area == NULL)
1530 lp->area = ospf_area_lookup_by_area_id(
1531 top, OspfMplsTE.interas_areaid);
1532 /* Unable to set the area context. Abort! */
1533 if (lp->area == NULL) {
1534 zlog_warn(
1535 "MPLS-TE(ospf_mpls_te_lsa_schedule) Area context is null. Abort !");
1536 return;
1537 }
1538 tmp = SET_OPAQUE_LSID(OPAQUE_TYPE_INTER_AS_LSA,
1539 lp->instance);
1540 } else
1541 tmp = SET_OPAQUE_LSID(
1542 OPAQUE_TYPE_TRAFFIC_ENGINEERING_LSA,
1543 lp->instance);
1544 lsah.id.s_addr = htonl(tmp);
1545 }
1546
1547 switch (opcode) {
1548 case REORIGINATE_THIS_LSA:
1549 if (IS_FLOOD_AS(lp->type)) {
1550 ospf_opaque_lsa_reoriginate_schedule(
1551 (void *)top, OSPF_OPAQUE_AS_LSA,
1552 OPAQUE_TYPE_INTER_AS_LSA);
1553 break;
1554 }
1555
1556 if (IS_FLOOD_AREA(lp->type)) {
1557 if (IS_INTER_AS(lp->type))
1558 ospf_opaque_lsa_reoriginate_schedule(
1559 (void *)lp->area, OSPF_OPAQUE_AREA_LSA,
1560 OPAQUE_TYPE_INTER_AS_LSA);
1561 else
1562 ospf_opaque_lsa_reoriginate_schedule(
1563 (void *)lp->area, OSPF_OPAQUE_AREA_LSA,
1564 OPAQUE_TYPE_TRAFFIC_ENGINEERING_LSA);
1565 break;
1566 }
1567 break;
1568 case REFRESH_THIS_LSA:
1569 ospf_opaque_lsa_refresh_schedule(&lsa);
1570 break;
1571 case FLUSH_THIS_LSA:
1572 /* Reset Activity flag */
1573 lp->flags = LPFLG_LSA_INACTIVE;
1574 ospf_opaque_lsa_flush_schedule(&lsa);
1575 break;
1576 default:
1577 zlog_warn("ospf_mpls_te_lsa_schedule: Unknown opcode (%u)",
1578 opcode);
1579 break;
1580 }
1581
1582 return;
718e3744 1583}
1584
16f1b9ee 1585
718e3744 1586/*------------------------------------------------------------------------*
1587 * Followings are vty session control functions.
1588 *------------------------------------------------------------------------*/
1589
d62a17ae 1590static u_int16_t show_vty_router_addr(struct vty *vty,
ead99d5f 1591 struct tlv_header *tlvh)
718e3744 1592{
d62a17ae 1593 struct te_tlv_router_addr *top = (struct te_tlv_router_addr *)tlvh;
718e3744 1594
d62a17ae 1595 if (vty != NULL)
1596 vty_out(vty, " Router-Address: %s\n", inet_ntoa(top->value));
1597 else
1598 zlog_debug(" Router-Address: %s", inet_ntoa(top->value));
718e3744 1599
d62a17ae 1600 return TLV_SIZE(tlvh);
718e3744 1601}
1602
d62a17ae 1603static u_int16_t show_vty_link_header(struct vty *vty,
ead99d5f 1604 struct tlv_header *tlvh)
718e3744 1605{
d62a17ae 1606 struct te_tlv_link *top = (struct te_tlv_link *)tlvh;
718e3744 1607
d62a17ae 1608 if (vty != NULL)
1609 vty_out(vty, " Link: %u octets of data\n",
1610 ntohs(top->header.length));
1611 else
1612 zlog_debug(" Link: %u octets of data",
1613 ntohs(top->header.length));
718e3744 1614
d62a17ae 1615 return TLV_HDR_SIZE; /* Here is special, not "TLV_SIZE". */
718e3744 1616}
1617
d62a17ae 1618static u_int16_t show_vty_link_subtlv_link_type(struct vty *vty,
ead99d5f 1619 struct tlv_header *tlvh)
718e3744 1620{
d62a17ae 1621 struct te_link_subtlv_link_type *top;
1622 const char *cp = "Unknown";
718e3744 1623
d62a17ae 1624 top = (struct te_link_subtlv_link_type *)tlvh;
1625 switch (top->link_type.value) {
1626 case LINK_TYPE_SUBTLV_VALUE_PTP:
1627 cp = "Point-to-point";
1628 break;
1629 case LINK_TYPE_SUBTLV_VALUE_MA:
1630 cp = "Multiaccess";
1631 break;
1632 default:
1633 break;
1634 }
718e3744 1635
d62a17ae 1636 if (vty != NULL)
1637 vty_out(vty, " Link-Type: %s (%u)\n", cp,
1638 top->link_type.value);
1639 else
1640 zlog_debug(" Link-Type: %s (%u)", cp, top->link_type.value);
718e3744 1641
d62a17ae 1642 return TLV_SIZE(tlvh);
718e3744 1643}
1644
d62a17ae 1645static u_int16_t show_vty_link_subtlv_link_id(struct vty *vty,
ead99d5f 1646 struct tlv_header *tlvh)
718e3744 1647{
d62a17ae 1648 struct te_link_subtlv_link_id *top;
718e3744 1649
d62a17ae 1650 top = (struct te_link_subtlv_link_id *)tlvh;
1651 if (vty != NULL)
1652 vty_out(vty, " Link-ID: %s\n", inet_ntoa(top->value));
1653 else
1654 zlog_debug(" Link-ID: %s", inet_ntoa(top->value));
718e3744 1655
d62a17ae 1656 return TLV_SIZE(tlvh);
718e3744 1657}
1658
d62a17ae 1659static u_int16_t show_vty_link_subtlv_lclif_ipaddr(struct vty *vty,
ead99d5f 1660 struct tlv_header *tlvh)
718e3744 1661{
d62a17ae 1662 struct te_link_subtlv_lclif_ipaddr *top;
1663 int i, n;
718e3744 1664
d62a17ae 1665 top = (struct te_link_subtlv_lclif_ipaddr *)tlvh;
1666 n = ntohs(tlvh->length) / sizeof(top->value[0]);
718e3744 1667
d62a17ae 1668 if (vty != NULL)
1669 vty_out(vty, " Local Interface IP Address(es): %d\n", n);
1670 else
1671 zlog_debug(" Local Interface IP Address(es): %d", n);
718e3744 1672
d62a17ae 1673 for (i = 0; i < n; i++) {
1674 if (vty != NULL)
1675 vty_out(vty, " #%d: %s\n", i,
1676 inet_ntoa(top->value[i]));
1677 else
1678 zlog_debug(" #%d: %s", i,
1679 inet_ntoa(top->value[i]));
1680 }
1681 return TLV_SIZE(tlvh);
718e3744 1682}
1683
d62a17ae 1684static u_int16_t show_vty_link_subtlv_rmtif_ipaddr(struct vty *vty,
ead99d5f 1685 struct tlv_header *tlvh)
718e3744 1686{
d62a17ae 1687 struct te_link_subtlv_rmtif_ipaddr *top;
1688 int i, n;
718e3744 1689
d62a17ae 1690 top = (struct te_link_subtlv_rmtif_ipaddr *)tlvh;
1691 n = ntohs(tlvh->length) / sizeof(top->value[0]);
1692 if (vty != NULL)
1693 vty_out(vty, " Remote Interface IP Address(es): %d\n", n);
1694 else
1695 zlog_debug(" Remote Interface IP Address(es): %d", n);
718e3744 1696
d62a17ae 1697 for (i = 0; i < n; i++) {
1698 if (vty != NULL)
1699 vty_out(vty, " #%d: %s\n", i,
1700 inet_ntoa(top->value[i]));
1701 else
1702 zlog_debug(" #%d: %s", i,
1703 inet_ntoa(top->value[i]));
1704 }
1705 return TLV_SIZE(tlvh);
718e3744 1706}
1707
d62a17ae 1708static u_int16_t show_vty_link_subtlv_te_metric(struct vty *vty,
ead99d5f 1709 struct tlv_header *tlvh)
718e3744 1710{
d62a17ae 1711 struct te_link_subtlv_te_metric *top;
718e3744 1712
d62a17ae 1713 top = (struct te_link_subtlv_te_metric *)tlvh;
1714 if (vty != NULL)
1715 vty_out(vty, " Traffic Engineering Metric: %u\n",
1716 (u_int32_t)ntohl(top->value));
1717 else
1718 zlog_debug(" Traffic Engineering Metric: %u",
1719 (u_int32_t)ntohl(top->value));
718e3744 1720
d62a17ae 1721 return TLV_SIZE(tlvh);
718e3744 1722}
1723
d62a17ae 1724static u_int16_t show_vty_link_subtlv_max_bw(struct vty *vty,
ead99d5f 1725 struct tlv_header *tlvh)
718e3744 1726{
d62a17ae 1727 struct te_link_subtlv_max_bw *top;
1728 float fval;
718e3744 1729
d62a17ae 1730 top = (struct te_link_subtlv_max_bw *)tlvh;
1731 fval = ntohf(top->value);
718e3744 1732
d62a17ae 1733 if (vty != NULL)
1734 vty_out(vty, " Maximum Bandwidth: %g (Bytes/sec)\n", fval);
1735 else
1736 zlog_debug(" Maximum Bandwidth: %g (Bytes/sec)", fval);
718e3744 1737
d62a17ae 1738 return TLV_SIZE(tlvh);
718e3744 1739}
1740
d62a17ae 1741static u_int16_t show_vty_link_subtlv_max_rsv_bw(struct vty *vty,
ead99d5f 1742 struct tlv_header *tlvh)
718e3744 1743{
d62a17ae 1744 struct te_link_subtlv_max_rsv_bw *top;
1745 float fval;
718e3744 1746
d62a17ae 1747 top = (struct te_link_subtlv_max_rsv_bw *)tlvh;
1748 fval = ntohf(top->value);
718e3744 1749
d62a17ae 1750 if (vty != NULL)
1751 vty_out(vty, " Maximum Reservable Bandwidth: %g (Bytes/sec)\n",
1752 fval);
1753 else
1754 zlog_debug(" Maximum Reservable Bandwidth: %g (Bytes/sec)",
1755 fval);
718e3744 1756
d62a17ae 1757 return TLV_SIZE(tlvh);
718e3744 1758}
1759
d62a17ae 1760static u_int16_t show_vty_link_subtlv_unrsv_bw(struct vty *vty,
ead99d5f 1761 struct tlv_header *tlvh)
718e3744 1762{
d62a17ae 1763 struct te_link_subtlv_unrsv_bw *top;
1764 float fval1, fval2;
1765 int i;
718e3744 1766
d62a17ae 1767 top = (struct te_link_subtlv_unrsv_bw *)tlvh;
1768 if (vty != NULL)
1769 vty_out(vty,
1770 " Unreserved Bandwidth per Class Type in Byte/s:\n");
1771 else
1772 zlog_debug(
1773 " Unreserved Bandwidth per Class Type in Byte/s:");
1774 for (i = 0; i < MAX_CLASS_TYPE; i += 2) {
1775 fval1 = ntohf(top->value[i]);
1776 fval2 = ntohf(top->value[i + 1]);
16f1b9ee 1777
d62a17ae 1778 if (vty != NULL)
1779 vty_out(vty,
1780 " [%d]: %g (Bytes/sec),\t[%d]: %g (Bytes/sec)\n",
1781 i, fval1, i + 1, fval2);
1782 else
1783 zlog_debug(
1784 " [%d]: %g (Bytes/sec),\t[%d]: %g (Bytes/sec)",
1785 i, fval1, i + 1, fval2);
1786 }
718e3744 1787
d62a17ae 1788 return TLV_SIZE(tlvh);
718e3744 1789}
1790
d62a17ae 1791static u_int16_t show_vty_link_subtlv_rsc_clsclr(struct vty *vty,
ead99d5f 1792 struct tlv_header *tlvh)
718e3744 1793{
d62a17ae 1794 struct te_link_subtlv_rsc_clsclr *top;
718e3744 1795
d62a17ae 1796 top = (struct te_link_subtlv_rsc_clsclr *)tlvh;
1797 if (vty != NULL)
1798 vty_out(vty, " Resource class/color: 0x%x\n",
1799 (u_int32_t)ntohl(top->value));
1800 else
1801 zlog_debug(" Resource Class/Color: 0x%x",
1802 (u_int32_t)ntohl(top->value));
16f1b9ee 1803
d62a17ae 1804 return TLV_SIZE(tlvh);
16f1b9ee
OD
1805}
1806
d62a17ae 1807static u_int16_t show_vty_link_subtlv_lrrid(struct vty *vty,
ead99d5f 1808 struct tlv_header *tlvh)
16f1b9ee 1809{
d62a17ae 1810 struct te_link_subtlv_lrrid *top;
16f1b9ee 1811
d62a17ae 1812 top = (struct te_link_subtlv_lrrid *)tlvh;
16f1b9ee 1813
d62a17ae 1814 if (vty != NULL) {
1815 vty_out(vty, " Local TE Router ID: %s\n",
1816 inet_ntoa(top->local));
1817 vty_out(vty, " Remote TE Router ID: %s\n",
1818 inet_ntoa(top->remote));
1819 } else {
1820 zlog_debug(" Local TE Router ID: %s",
1821 inet_ntoa(top->local));
1822 zlog_debug(" Remote TE Router ID: %s",
1823 inet_ntoa(top->remote));
1824 }
16f1b9ee 1825
d62a17ae 1826 return TLV_SIZE(tlvh);
16f1b9ee
OD
1827}
1828
d62a17ae 1829static u_int16_t show_vty_link_subtlv_llri(struct vty *vty,
ead99d5f 1830 struct tlv_header *tlvh)
16f1b9ee 1831{
d62a17ae 1832 struct te_link_subtlv_llri *top;
16f1b9ee 1833
d62a17ae 1834 top = (struct te_link_subtlv_llri *)tlvh;
16f1b9ee 1835
d62a17ae 1836 if (vty != NULL) {
1837 vty_out(vty, " Link Local ID: %d\n",
1838 (u_int32_t)ntohl(top->local));
1839 vty_out(vty, " Link Remote ID: %d\n",
1840 (u_int32_t)ntohl(top->remote));
1841 } else {
1842 zlog_debug(" Link Local ID: %d",
1843 (u_int32_t)ntohl(top->local));
1844 zlog_debug(" Link Remote ID: %d",
1845 (u_int32_t)ntohl(top->remote));
1846 }
16f1b9ee 1847
d62a17ae 1848 return TLV_SIZE(tlvh);
16f1b9ee
OD
1849}
1850
d62a17ae 1851static u_int16_t show_vty_link_subtlv_rip(struct vty *vty,
ead99d5f 1852 struct tlv_header *tlvh)
16f1b9ee 1853{
d62a17ae 1854 struct te_link_subtlv_rip *top;
16f1b9ee 1855
d62a17ae 1856 top = (struct te_link_subtlv_rip *)tlvh;
16f1b9ee 1857
d62a17ae 1858 if (vty != NULL)
1859 vty_out(vty, " Inter-AS TE Remote ASBR IP address: %s\n",
1860 inet_ntoa(top->value));
1861 else
1862 zlog_debug(" Inter-AS TE Remote ASBR IP address: %s",
1863 inet_ntoa(top->value));
16f1b9ee 1864
d62a17ae 1865 return TLV_SIZE(tlvh);
16f1b9ee
OD
1866}
1867
d62a17ae 1868static u_int16_t show_vty_link_subtlv_ras(struct vty *vty,
ead99d5f 1869 struct tlv_header *tlvh)
16f1b9ee 1870{
d62a17ae 1871 struct te_link_subtlv_ras *top;
16f1b9ee 1872
d62a17ae 1873 top = (struct te_link_subtlv_ras *)tlvh;
16f1b9ee 1874
d62a17ae 1875 if (vty != NULL)
1876 vty_out(vty, " Inter-AS TE Remote AS number: %u\n",
1877 ntohl(top->value));
1878 else
1879 zlog_debug(" Inter-AS TE Remote AS number: %u",
1880 ntohl(top->value));
16f1b9ee 1881
d62a17ae 1882 return TLV_SIZE(tlvh);
16f1b9ee
OD
1883}
1884
d62a17ae 1885static u_int16_t show_vty_link_subtlv_av_delay(struct vty *vty,
ead99d5f 1886 struct tlv_header *tlvh)
16f1b9ee 1887{
d62a17ae 1888 struct te_link_subtlv_av_delay *top;
1889 u_int32_t delay;
1890 u_int32_t anomalous;
16f1b9ee 1891
d62a17ae 1892 top = (struct te_link_subtlv_av_delay *)tlvh;
1893 delay = (u_int32_t)ntohl(top->value) & TE_EXT_MASK;
1894 anomalous = (u_int32_t)ntohl(top->value) & TE_EXT_ANORMAL;
16f1b9ee 1895
d62a17ae 1896 if (vty != NULL)
1897 vty_out(vty, " %s Average Link Delay: %d (micro-sec)\n",
1898 anomalous ? "Anomalous" : "Normal", delay);
1899 else
1900 zlog_debug(" %s Average Link Delay: %d (micro-sec)",
1901 anomalous ? "Anomalous" : "Normal", delay);
16f1b9ee 1902
d62a17ae 1903 return TLV_SIZE(tlvh);
16f1b9ee
OD
1904}
1905
d62a17ae 1906static u_int16_t show_vty_link_subtlv_mm_delay(struct vty *vty,
ead99d5f 1907 struct tlv_header *tlvh)
16f1b9ee 1908{
d62a17ae 1909 struct te_link_subtlv_mm_delay *top;
1910 u_int32_t low, high;
1911 u_int32_t anomalous;
16f1b9ee 1912
d62a17ae 1913 top = (struct te_link_subtlv_mm_delay *)tlvh;
1914 low = (u_int32_t)ntohl(top->low) & TE_EXT_MASK;
1915 anomalous = (u_int32_t)ntohl(top->low) & TE_EXT_ANORMAL;
1916 high = (u_int32_t)ntohl(top->high);
16f1b9ee 1917
d62a17ae 1918 if (vty != NULL)
1919 vty_out(vty, " %s Min/Max Link Delay: %d/%d (micro-sec)\n",
1920 anomalous ? "Anomalous" : "Normal", low, high);
1921 else
1922 zlog_debug(" %s Min/Max Link Delay: %d/%d (micro-sec)",
1923 anomalous ? "Anomalous" : "Normal", low, high);
16f1b9ee 1924
d62a17ae 1925 return TLV_SIZE(tlvh);
16f1b9ee
OD
1926}
1927
d62a17ae 1928static u_int16_t show_vty_link_subtlv_delay_var(struct vty *vty,
ead99d5f 1929 struct tlv_header *tlvh)
16f1b9ee 1930{
d62a17ae 1931 struct te_link_subtlv_delay_var *top;
1932 u_int32_t jitter;
16f1b9ee 1933
d62a17ae 1934 top = (struct te_link_subtlv_delay_var *)tlvh;
1935 jitter = (u_int32_t)ntohl(top->value) & TE_EXT_MASK;
16f1b9ee 1936
d62a17ae 1937 if (vty != NULL)
1938 vty_out(vty, " Delay Variation: %d (micro-sec)\n", jitter);
1939 else
1940 zlog_debug(" Delay Variation: %d (micro-sec)", jitter);
16f1b9ee 1941
d62a17ae 1942 return TLV_SIZE(tlvh);
16f1b9ee
OD
1943}
1944
d62a17ae 1945static u_int16_t show_vty_link_subtlv_pkt_loss(struct vty *vty,
ead99d5f 1946 struct tlv_header *tlvh)
16f1b9ee 1947{
d62a17ae 1948 struct te_link_subtlv_pkt_loss *top;
1949 u_int32_t loss;
1950 u_int32_t anomalous;
1951 float fval;
16f1b9ee 1952
d62a17ae 1953 top = (struct te_link_subtlv_pkt_loss *)tlvh;
1954 loss = (u_int32_t)ntohl(top->value) & TE_EXT_MASK;
1955 fval = (float)(loss * LOSS_PRECISION);
1956 anomalous = (u_int32_t)ntohl(top->value) & TE_EXT_ANORMAL;
16f1b9ee 1957
d62a17ae 1958 if (vty != NULL)
1959 vty_out(vty, " %s Link Loss: %g (%%)\n",
1960 anomalous ? "Anomalous" : "Normal", fval);
1961 else
1962 zlog_debug(" %s Link Loss: %g (%%)",
1963 anomalous ? "Anomalous" : "Normal", fval);
16f1b9ee 1964
d62a17ae 1965 return TLV_SIZE(tlvh);
16f1b9ee
OD
1966}
1967
d62a17ae 1968static u_int16_t show_vty_link_subtlv_res_bw(struct vty *vty,
ead99d5f 1969 struct tlv_header *tlvh)
16f1b9ee 1970{
d62a17ae 1971 struct te_link_subtlv_res_bw *top;
1972 float fval;
16f1b9ee 1973
d62a17ae 1974 top = (struct te_link_subtlv_res_bw *)tlvh;
1975 fval = ntohf(top->value);
16f1b9ee 1976
d62a17ae 1977 if (vty != NULL)
1978 vty_out(vty,
1979 " Unidirectional Residual Bandwidth: %g (Bytes/sec)\n",
1980 fval);
1981 else
1982 zlog_debug(
1983 " Unidirectional Residual Bandwidth: %g (Bytes/sec)",
1984 fval);
1985
1986 return TLV_SIZE(tlvh);
1987}
1988
1989static u_int16_t show_vty_link_subtlv_ava_bw(struct vty *vty,
ead99d5f 1990 struct tlv_header *tlvh)
d62a17ae 1991{
1992 struct te_link_subtlv_ava_bw *top;
1993 float fval;
1994
1995 top = (struct te_link_subtlv_ava_bw *)tlvh;
1996 fval = ntohf(top->value);
1997
1998 if (vty != NULL)
1999 vty_out(vty,
2000 " Unidirectional Available Bandwidth: %g (Bytes/sec)\n",
2001 fval);
2002 else
2003 zlog_debug(
2004 " Unidirectional Available Bandwidth: %g (Bytes/sec)",
2005 fval);
2006
2007 return TLV_SIZE(tlvh);
2008}
2009
2010static u_int16_t show_vty_link_subtlv_use_bw(struct vty *vty,
ead99d5f 2011 struct tlv_header *tlvh)
d62a17ae 2012{
2013 struct te_link_subtlv_use_bw *top;
2014 float fval;
2015
2016 top = (struct te_link_subtlv_use_bw *)tlvh;
2017 fval = ntohf(top->value);
2018
2019 if (vty != NULL)
2020 vty_out(vty,
2021 " Unidirectional Utilized Bandwidth: %g (Bytes/sec)\n",
2022 fval);
2023 else
2024 zlog_debug(
2025 " Unidirectional Utilized Bandwidth: %g (Bytes/sec)",
2026 fval);
2027
2028 return TLV_SIZE(tlvh);
2029}
2030
2031static u_int16_t show_vty_unknown_tlv(struct vty *vty,
ead99d5f 2032 struct tlv_header *tlvh)
d62a17ae 2033{
2034 if (vty != NULL)
2035 vty_out(vty, " Unknown TLV: [type(0x%x), length(0x%x)]\n",
2036 ntohs(tlvh->type), ntohs(tlvh->length));
2037 else
2038 zlog_debug(" Unknown TLV: [type(0x%x), length(0x%x)]",
2039 ntohs(tlvh->type), ntohs(tlvh->length));
2040
2041 return TLV_SIZE(tlvh);
2042}
2043
2044static u_int16_t ospf_mpls_te_show_link_subtlv(struct vty *vty,
ead99d5f 2045 struct tlv_header *tlvh0,
d62a17ae 2046 u_int16_t subtotal,
2047 u_int16_t total)
2048{
ead99d5f 2049 struct tlv_header *tlvh, *next;
d62a17ae 2050 u_int16_t sum = subtotal;
2051
2052 for (tlvh = tlvh0; sum < total;
2053 tlvh = (next ? next : TLV_HDR_NEXT(tlvh))) {
2054 next = NULL;
2055 switch (ntohs(tlvh->type)) {
2056 case TE_LINK_SUBTLV_LINK_TYPE:
2057 sum += show_vty_link_subtlv_link_type(vty, tlvh);
2058 break;
2059 case TE_LINK_SUBTLV_LINK_ID:
2060 sum += show_vty_link_subtlv_link_id(vty, tlvh);
2061 break;
2062 case TE_LINK_SUBTLV_LCLIF_IPADDR:
2063 sum += show_vty_link_subtlv_lclif_ipaddr(vty, tlvh);
2064 break;
2065 case TE_LINK_SUBTLV_RMTIF_IPADDR:
2066 sum += show_vty_link_subtlv_rmtif_ipaddr(vty, tlvh);
2067 break;
2068 case TE_LINK_SUBTLV_TE_METRIC:
2069 sum += show_vty_link_subtlv_te_metric(vty, tlvh);
2070 break;
2071 case TE_LINK_SUBTLV_MAX_BW:
2072 sum += show_vty_link_subtlv_max_bw(vty, tlvh);
2073 break;
2074 case TE_LINK_SUBTLV_MAX_RSV_BW:
2075 sum += show_vty_link_subtlv_max_rsv_bw(vty, tlvh);
2076 break;
2077 case TE_LINK_SUBTLV_UNRSV_BW:
2078 sum += show_vty_link_subtlv_unrsv_bw(vty, tlvh);
2079 break;
2080 case TE_LINK_SUBTLV_RSC_CLSCLR:
2081 sum += show_vty_link_subtlv_rsc_clsclr(vty, tlvh);
2082 break;
2083 case TE_LINK_SUBTLV_LRRID:
2084 sum += show_vty_link_subtlv_lrrid(vty, tlvh);
2085 break;
2086 case TE_LINK_SUBTLV_LLRI:
2087 sum += show_vty_link_subtlv_llri(vty, tlvh);
2088 break;
2089 case TE_LINK_SUBTLV_RIP:
2090 sum += show_vty_link_subtlv_rip(vty, tlvh);
2091 break;
2092 case TE_LINK_SUBTLV_RAS:
2093 sum += show_vty_link_subtlv_ras(vty, tlvh);
2094 break;
2095 case TE_LINK_SUBTLV_AV_DELAY:
2096 sum += show_vty_link_subtlv_av_delay(vty, tlvh);
2097 break;
2098 case TE_LINK_SUBTLV_MM_DELAY:
2099 sum += show_vty_link_subtlv_mm_delay(vty, tlvh);
2100 break;
2101 case TE_LINK_SUBTLV_DELAY_VAR:
2102 sum += show_vty_link_subtlv_delay_var(vty, tlvh);
2103 break;
2104 case TE_LINK_SUBTLV_PKT_LOSS:
2105 sum += show_vty_link_subtlv_pkt_loss(vty, tlvh);
2106 break;
2107 case TE_LINK_SUBTLV_RES_BW:
2108 sum += show_vty_link_subtlv_res_bw(vty, tlvh);
2109 break;
2110 case TE_LINK_SUBTLV_AVA_BW:
2111 sum += show_vty_link_subtlv_ava_bw(vty, tlvh);
2112 break;
2113 case TE_LINK_SUBTLV_USE_BW:
2114 sum += show_vty_link_subtlv_use_bw(vty, tlvh);
2115 break;
2116 default:
2117 sum += show_vty_unknown_tlv(vty, tlvh);
2118 break;
2119 }
2120 }
2121 return sum;
2122}
2123
2124static void ospf_mpls_te_show_info(struct vty *vty, struct ospf_lsa *lsa)
2125{
2126 struct lsa_header *lsah = (struct lsa_header *)lsa->data;
ead99d5f 2127 struct tlv_header *tlvh, *next;
d62a17ae 2128 u_int16_t sum, total;
ead99d5f 2129 u_int16_t (*subfunc)(struct vty * vty, struct tlv_header * tlvh,
d62a17ae 2130 u_int16_t subtotal, u_int16_t total) = NULL;
2131
2132 sum = 0;
2133 total = ntohs(lsah->length) - OSPF_LSA_HEADER_SIZE;
2134
2135 for (tlvh = TLV_HDR_TOP(lsah); sum < total;
2136 tlvh = (next ? next : TLV_HDR_NEXT(tlvh))) {
2137 if (subfunc != NULL) {
2138 sum = (*subfunc)(vty, tlvh, sum, total);
ead99d5f 2139 next = (struct tlv_header *)((char *)tlvh + sum);
d62a17ae 2140 subfunc = NULL;
2141 continue;
2142 }
2143
2144 next = NULL;
2145 switch (ntohs(tlvh->type)) {
2146 case TE_TLV_ROUTER_ADDR:
2147 sum += show_vty_router_addr(vty, tlvh);
2148 break;
2149 case TE_TLV_LINK:
2150 sum += show_vty_link_header(vty, tlvh);
2151 subfunc = ospf_mpls_te_show_link_subtlv;
5d0df50f 2152 next = TLV_DATA(tlvh);
d62a17ae 2153 break;
2154 default:
2155 sum += show_vty_unknown_tlv(vty, tlvh);
2156 break;
2157 }
2158 }
2159 return;
2160}
2161
2162static void ospf_mpls_te_config_write_router(struct vty *vty)
2163{
2164
32ab5cf4 2165 if (OspfMplsTE.enabled) {
d62a17ae 2166 vty_out(vty, " mpls-te on\n");
2167 vty_out(vty, " mpls-te router-address %s\n",
2168 inet_ntoa(OspfMplsTE.router_addr.value));
2169 }
2170
2171 if (OspfMplsTE.inter_as == AS)
2172 vty_out(vty, " mpls-te inter-as as\n");
2173 if (OspfMplsTE.inter_as == Area)
2174 vty_out(vty, " mpls-te inter-as area %s \n",
2175 inet_ntoa(OspfMplsTE.interas_areaid));
2176
2177 return;
718e3744 2178}
2179
2180/*------------------------------------------------------------------------*
2181 * Followings are vty command functions.
2182 *------------------------------------------------------------------------*/
2183
16f1b9ee
OD
2184DEFUN (ospf_mpls_te_on,
2185 ospf_mpls_te_on_cmd,
2186 "mpls-te on",
2187 MPLS_TE_STR
718e3744 2188 "Enable the MPLS-TE functionality\n")
2189{
a3d826f0 2190 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
d62a17ae 2191 struct listnode *node;
2192 struct mpls_te_link *lp;
7c8ff89e 2193
32ab5cf4 2194 if (OspfMplsTE.enabled)
d62a17ae 2195 return CMD_SUCCESS;
718e3744 2196
d62a17ae 2197 if (IS_DEBUG_OSPF_EVENT)
2198 zlog_debug("MPLS-TE: OFF -> ON");
718e3744 2199
32ab5cf4 2200 OspfMplsTE.enabled = true;
718e3744 2201
d62a17ae 2202 /* Reoriginate RFC3630 & RFC6827 Links */
2203 ospf_mpls_te_foreach_area(ospf_mpls_te_lsa_schedule,
2204 REORIGINATE_THIS_LSA);
718e3744 2205
d62a17ae 2206 /* Reoriginate LSA if INTER-AS is always on */
ead99d5f 2207 if (OspfMplsTE.inter_as != Off) {
d62a17ae 2208 for (ALL_LIST_ELEMENTS_RO(OspfMplsTE.iflist, node, lp)) {
2209 if (IS_INTER_AS(lp->type)) {
2210 ospf_mpls_te_lsa_schedule(lp,
2211 REORIGINATE_THIS_LSA);
2212 }
2213 }
2214 }
718e3744 2215
d62a17ae 2216 return CMD_SUCCESS;
718e3744 2217}
2218
16f1b9ee
OD
2219DEFUN (no_ospf_mpls_te,
2220 no_ospf_mpls_te_cmd,
3a2d747c 2221 "no mpls-te [on]",
718e3744 2222 NO_STR
3a2d747c 2223 MPLS_TE_STR
718e3744 2224 "Disable the MPLS-TE functionality\n")
2225{
a3d826f0 2226 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
d62a17ae 2227 struct listnode *node, *nnode;
2228 struct mpls_te_link *lp;
718e3744 2229
32ab5cf4 2230 if (!OspfMplsTE.enabled)
d62a17ae 2231 return CMD_SUCCESS;
718e3744 2232
d62a17ae 2233 if (IS_DEBUG_OSPF_EVENT)
2234 zlog_debug("MPLS-TE: ON -> OFF");
718e3744 2235
32ab5cf4 2236 OspfMplsTE.enabled = false;
718e3744 2237
d62a17ae 2238 for (ALL_LIST_ELEMENTS(OspfMplsTE.iflist, node, nnode, lp))
32ab5cf4
OD
2239 if (CHECK_FLAG(lp->flags, LPFLG_LSA_ENGAGED))
2240 ospf_mpls_te_lsa_schedule(lp, FLUSH_THIS_LSA);
718e3744 2241
d62a17ae 2242 return CMD_SUCCESS;
718e3744 2243}
2244
813d4307 2245
16f1b9ee
OD
2246DEFUN (ospf_mpls_te_router_addr,
2247 ospf_mpls_te_router_addr_cmd,
718e3744 2248 "mpls-te router-address A.B.C.D",
16f1b9ee 2249 MPLS_TE_STR
718e3744 2250 "Stable IP address of the advertising router\n"
2251 "MPLS-TE router address in IPv4 address format\n")
2252{
a3d826f0 2253 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
d62a17ae 2254 int idx_ipv4 = 2;
2255 struct te_tlv_router_addr *ra = &OspfMplsTE.router_addr;
2256 struct in_addr value;
2257
2258 if (!inet_aton(argv[idx_ipv4]->arg, &value)) {
2259 vty_out(vty, "Please specify Router-Addr by A.B.C.D\n");
2260 return CMD_WARNING;
2261 }
2262
2263 if (ntohs(ra->header.type) == 0
2264 || ntohl(ra->value.s_addr) != ntohl(value.s_addr)) {
2265 struct listnode *node, *nnode;
2266 struct mpls_te_link *lp;
2267 int need_to_reoriginate = 0;
2268
2269 set_mpls_te_router_addr(value);
2270
32ab5cf4 2271 if (!OspfMplsTE.enabled)
ead99d5f 2272 return CMD_SUCCESS;
d62a17ae 2273
2274 for (ALL_LIST_ELEMENTS(OspfMplsTE.iflist, node, nnode, lp)) {
2275 if ((lp->area == NULL) || IS_FLOOD_AS(lp->type))
2276 continue;
2277
2278 if (!CHECK_FLAG(lp->flags, LPFLG_LSA_ENGAGED)) {
2279 need_to_reoriginate = 1;
2280 break;
2281 }
2282 }
2283
2284 for (ALL_LIST_ELEMENTS(OspfMplsTE.iflist, node, nnode, lp)) {
2285 if ((lp->area == NULL) || IS_FLOOD_AS(lp->type))
2286 continue;
2287
2288 if (need_to_reoriginate)
2289 SET_FLAG(lp->flags, LPFLG_LSA_FORCED_REFRESH);
2290 else
2291 ospf_mpls_te_lsa_schedule(lp, REFRESH_THIS_LSA);
2292 }
2293
2294 if (need_to_reoriginate)
2295 ospf_mpls_te_foreach_area(ospf_mpls_te_lsa_schedule,
2296 REORIGINATE_THIS_LSA);
2297 }
ead99d5f 2298
d62a17ae 2299 return CMD_SUCCESS;
2300}
2301
2302static int set_inter_as_mode(struct vty *vty, const char *mode_name,
2303 const char *area_id)
2304{
2305 enum inter_as_mode mode;
2306 struct listnode *node;
2307 struct mpls_te_link *lp;
2308 int format;
2309
32ab5cf4 2310 if (OspfMplsTE.enabled) {
d62a17ae 2311
2312 /* Read and Check inter_as mode */
2313 if (strcmp(mode_name, "as") == 0)
2314 mode = AS;
2315 else if (strcmp(mode_name, "area") == 0) {
2316 mode = Area;
2317 VTY_GET_OSPF_AREA_ID(OspfMplsTE.interas_areaid, format,
2318 area_id);
2319 } else {
2320 vty_out(vty,
2321 "Unknown mode. Please choose between as or area\n");
2322 return CMD_WARNING;
2323 }
2324
2325 if (IS_DEBUG_OSPF_EVENT)
2326 zlog_debug(
2327 "MPLS-TE: Inter-AS enable with %s flooding support",
2328 mode2text[mode]);
2329
2330 /* Register new callbacks regarding the flooding scope (AS or
2331 * Area) */
2332 if (ospf_mpls_te_register(mode) < 0) {
2333 vty_out(vty,
2334 "Internal error: Unable to register Inter-AS functions\n");
2335 return CMD_WARNING;
2336 }
2337
2338 /* Enable mode and re-originate LSA if needed */
ead99d5f 2339 if ((OspfMplsTE.inter_as == Off)
d62a17ae 2340 && (mode != OspfMplsTE.inter_as)) {
2341 OspfMplsTE.inter_as = mode;
2342 /* Re-originate all InterAS-TEv2 LSA */
2343 for (ALL_LIST_ELEMENTS_RO(OspfMplsTE.iflist, node,
2344 lp)) {
2345 if (IS_INTER_AS(lp->type)) {
2346 if (mode == AS)
2347 lp->type |= FLOOD_AS;
2348 else
2349 lp->type |= FLOOD_AREA;
2350 ospf_mpls_te_lsa_schedule(
2351 lp, REORIGINATE_THIS_LSA);
2352 }
2353 }
2354 } else {
2355 vty_out(vty,
2356 "Please change Inter-AS support to disable first before going to mode %s\n",
2357 mode2text[mode]);
2358 return CMD_WARNING;
2359 }
2360 } else {
2361 vty_out(vty, "mpls-te has not been turned on\n");
2362 return CMD_WARNING;
2363 }
2364 return CMD_SUCCESS;
718e3744 2365}
2366
718e3744 2367
16f1b9ee
OD
2368DEFUN (ospf_mpls_te_inter_as_as,
2369 ospf_mpls_te_inter_as_cmd,
2370 "mpls-te inter-as as",
2371 MPLS_TE_STR
2372 "Configure MPLS-TE Inter-AS support\n"
2373 "AS native mode self originate INTER_AS LSA with Type 11 (as flooding scope)\n")
2374{
d62a17ae 2375 return set_inter_as_mode(vty, "as", "");
718e3744 2376}
2377
16f1b9ee
OD
2378DEFUN (ospf_mpls_te_inter_as_area,
2379 ospf_mpls_te_inter_as_area_cmd,
6147e2c6 2380 "mpls-te inter-as area <A.B.C.D|(0-4294967295)>",
16f1b9ee
OD
2381 MPLS_TE_STR
2382 "Configure MPLS-TE Inter-AS support\n"
2383 "AREA native mode self originate INTER_AS LSA with Type 10 (area flooding scope)\n"
2384 "OSPF area ID in IP format\n"
2385 "OSPF area ID as decimal value\n")
718e3744 2386{
d62a17ae 2387 int idx_ipv4_number = 3;
2388 return set_inter_as_mode(vty, "area", argv[idx_ipv4_number]->arg);
718e3744 2389}
2390
16f1b9ee
OD
2391DEFUN (no_ospf_mpls_te_inter_as,
2392 no_ospf_mpls_te_inter_as_cmd,
2393 "no mpls-te inter-as",
2394 NO_STR
2395 MPLS_TE_STR
2396 "Disable MPLS-TE Inter-AS support\n")
718e3744 2397{
16f1b9ee 2398
d62a17ae 2399 struct listnode *node, *nnode;
2400 struct mpls_te_link *lp;
718e3744 2401
d62a17ae 2402 if (IS_DEBUG_OSPF_EVENT)
2403 zlog_debug("MPLS-TE: Inter-AS support OFF");
718e3744 2404
32ab5cf4 2405 if ((OspfMplsTE.enabled)
ead99d5f
OD
2406 && (OspfMplsTE.inter_as != Off)) {
2407 OspfMplsTE.inter_as = Off;
d62a17ae 2408 /* Flush all Inter-AS LSA */
2409 for (ALL_LIST_ELEMENTS(OspfMplsTE.iflist, node, nnode, lp))
2410 if (IS_INTER_AS(lp->type)
2411 && CHECK_FLAG(lp->flags, LPFLG_LSA_ENGAGED))
2412 ospf_mpls_te_lsa_schedule(lp, FLUSH_THIS_LSA);
2413 }
718e3744 2414
d62a17ae 2415 /* Deregister the Callbacks for Inter-AS suport */
2416 ospf_mpls_te_unregister();
718e3744 2417
d62a17ae 2418 return CMD_SUCCESS;
718e3744 2419}
2420
16f1b9ee
OD
2421DEFUN (show_ip_ospf_mpls_te_router,
2422 show_ip_ospf_mpls_te_router_cmd,
2423 "show ip ospf mpls-te router",
718e3744 2424 SHOW_STR
16f1b9ee
OD
2425 IP_STR
2426 OSPF_STR
718e3744 2427 "MPLS-TE information\n"
16f1b9ee 2428 "MPLS-TE Router parameters\n")
718e3744 2429{
32ab5cf4 2430 if (OspfMplsTE.enabled) {
d62a17ae 2431 vty_out(vty, "--- MPLS-TE router parameters ---\n");
2432
2433 if (ntohs(OspfMplsTE.router_addr.header.type) != 0)
2434 show_vty_router_addr(vty,
2435 &OspfMplsTE.router_addr.header);
0af35d90 2436 else
d62a17ae 2437 vty_out(vty, " N/A\n");
2438 }
2439 return CMD_SUCCESS;
2440}
2441
2442static void show_mpls_te_link_sub(struct vty *vty, struct interface *ifp)
2443{
2444 struct mpls_te_link *lp;
2445
32ab5cf4 2446 if ((OspfMplsTE.enabled) && HAS_LINK_PARAMS(ifp)
d62a17ae 2447 && !if_is_loopback(ifp) && if_is_up(ifp)
2448 && ((lp = lookup_linkparams_by_ifp(ifp)) != NULL)) {
2449 /* Continue only if interface is not passive or support Inter-AS
2450 * TEv2 */
2451 if (!(ospf_oi_count(ifp) > 0)) {
2452 if (IS_INTER_AS(lp->type)) {
2453 vty_out(vty,
2454 "-- Inter-AS TEv2 link parameters for %s --\n",
2455 ifp->name);
2456 } else {
2457 /* MPLS-TE is not activate on this interface */
2458 /* or this interface is passive and Inter-AS
2459 * TEv2 is not activate */
2460 vty_out(vty,
2461 " %s: MPLS-TE is disabled on this interface\n",
2462 ifp->name);
2463 return;
2464 }
2465 } else {
2466 vty_out(vty, "-- MPLS-TE link parameters for %s --\n",
2467 ifp->name);
2468 }
2469
2470 if (TLV_TYPE(lp->link_type) != 0)
2471 show_vty_link_subtlv_link_type(vty,
2472 &lp->link_type.header);
2473 if (TLV_TYPE(lp->link_id) != 0)
2474 show_vty_link_subtlv_link_id(vty, &lp->link_id.header);
2475 if (TLV_TYPE(lp->lclif_ipaddr) != 0)
2476 show_vty_link_subtlv_lclif_ipaddr(
2477 vty, &lp->lclif_ipaddr.header);
2478 if (TLV_TYPE(lp->rmtif_ipaddr) != 0)
2479 show_vty_link_subtlv_rmtif_ipaddr(
2480 vty, &lp->rmtif_ipaddr.header);
2481 if (TLV_TYPE(lp->rip) != 0)
2482 show_vty_link_subtlv_rip(vty, &lp->rip.header);
2483 if (TLV_TYPE(lp->ras) != 0)
2484 show_vty_link_subtlv_ras(vty, &lp->ras.header);
2485 if (TLV_TYPE(lp->te_metric) != 0)
2486 show_vty_link_subtlv_te_metric(vty,
2487 &lp->te_metric.header);
2488 if (TLV_TYPE(lp->max_bw) != 0)
2489 show_vty_link_subtlv_max_bw(vty, &lp->max_bw.header);
2490 if (TLV_TYPE(lp->max_rsv_bw) != 0)
2491 show_vty_link_subtlv_max_rsv_bw(vty,
2492 &lp->max_rsv_bw.header);
2493 if (TLV_TYPE(lp->unrsv_bw) != 0)
2494 show_vty_link_subtlv_unrsv_bw(vty,
2495 &lp->unrsv_bw.header);
2496 if (TLV_TYPE(lp->rsc_clsclr) != 0)
2497 show_vty_link_subtlv_rsc_clsclr(vty,
2498 &lp->rsc_clsclr.header);
2499 if (TLV_TYPE(lp->av_delay) != 0)
2500 show_vty_link_subtlv_av_delay(vty,
2501 &lp->av_delay.header);
2502 if (TLV_TYPE(lp->mm_delay) != 0)
2503 show_vty_link_subtlv_mm_delay(vty,
2504 &lp->mm_delay.header);
2505 if (TLV_TYPE(lp->delay_var) != 0)
2506 show_vty_link_subtlv_delay_var(vty,
2507 &lp->delay_var.header);
2508 if (TLV_TYPE(lp->pkt_loss) != 0)
2509 show_vty_link_subtlv_pkt_loss(vty,
2510 &lp->pkt_loss.header);
2511 if (TLV_TYPE(lp->res_bw) != 0)
2512 show_vty_link_subtlv_res_bw(vty, &lp->res_bw.header);
2513 if (TLV_TYPE(lp->ava_bw) != 0)
2514 show_vty_link_subtlv_ava_bw(vty, &lp->ava_bw.header);
2515 if (TLV_TYPE(lp->use_bw) != 0)
2516 show_vty_link_subtlv_use_bw(vty, &lp->use_bw.header);
2517 vty_out(vty, "---------------\n\n");
2518 } else {
2519 vty_out(vty, " %s: MPLS-TE is disabled on this interface\n",
2520 ifp->name);
2521 }
2522
2523 return;
718e3744 2524}
2525
16f1b9ee
OD
2526DEFUN (show_ip_ospf_mpls_te_link,
2527 show_ip_ospf_mpls_te_link_cmd,
b5a8894d 2528 "show ip ospf [vrf <NAME|all>] mpls-te interface [INTERFACE]",
718e3744 2529 SHOW_STR
16f1b9ee
OD
2530 IP_STR
2531 OSPF_STR
b5a8894d
CS
2532 VRF_CMD_HELP_STR
2533 "All VRFs\n"
718e3744 2534 "MPLS-TE information\n"
2535 "Interface information\n"
2536 "Interface name\n")
2537{
f4e14fdb 2538 struct vrf *vrf;
d62a17ae 2539 int idx_interface = 5;
2540 struct interface *ifp;
f4e14fdb 2541 struct listnode *node;
b5a8894d
CS
2542 char *vrf_name = NULL;
2543 bool all_vrf;
2544 int inst = 0;
2545 int idx_vrf = 0;
2546 struct ospf *ospf = NULL;
2547
2548 if (argv_find(argv, argc, "vrf", &idx_vrf)) {
2549 vrf_name = argv[idx_vrf + 1]->arg;
2550 all_vrf = strmatch(vrf_name, "all");
2551 }
2552
2553 /* vrf input is provided could be all or specific vrf*/
2554 if (vrf_name) {
2555 if (all_vrf) {
f4e14fdb 2556 for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) {
b5a8894d
CS
2557 if (!ospf->oi_running)
2558 continue;
f4e14fdb 2559 vrf = vrf_lookup_by_id(ospf->vrf_id);
451fda4f 2560 FOR_ALL_INTERFACES (vrf, ifp)
b5a8894d
CS
2561 show_mpls_te_link_sub(vty, ifp);
2562 }
2563 return CMD_SUCCESS;
2564 }
2565 ospf = ospf_lookup_by_inst_name (inst, vrf_name);
2566 if (ospf == NULL || !ospf->oi_running)
2567 return CMD_SUCCESS;
f4e14fdb 2568 vrf = vrf_lookup_by_id(ospf->vrf_id);
451fda4f 2569 FOR_ALL_INTERFACES (vrf, ifp)
b5a8894d
CS
2570 show_mpls_te_link_sub(vty, ifp);
2571 return CMD_SUCCESS;
2572 }
d62a17ae 2573 /* Show All Interfaces. */
2574 if (argc == 5) {
f4e14fdb 2575 for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) {
43b8d1d8
CS
2576 if (!ospf->oi_running)
2577 continue;
f4e14fdb 2578 vrf = vrf_lookup_by_id(ospf->vrf_id);
451fda4f 2579 FOR_ALL_INTERFACES (vrf, ifp)
43b8d1d8
CS
2580 show_mpls_te_link_sub(vty, ifp);
2581 }
d62a17ae 2582 }
2583 /* Interface name is specified. */
2584 else {
b5a8894d
CS
2585 ifp = if_lookup_by_name_all_vrf(argv[idx_interface]->arg);
2586 if (ifp == NULL)
d62a17ae 2587 vty_out(vty, "No such interface name\n");
2588 else
2589 show_mpls_te_link_sub(vty, ifp);
2590 }
2591
2592 return CMD_SUCCESS;
2593}
2594
2595static void ospf_mpls_te_register_vty(void)
2596{
2597 install_element(VIEW_NODE, &show_ip_ospf_mpls_te_router_cmd);
2598 install_element(VIEW_NODE, &show_ip_ospf_mpls_te_link_cmd);
2599
2600 install_element(OSPF_NODE, &ospf_mpls_te_on_cmd);
2601 install_element(OSPF_NODE, &no_ospf_mpls_te_cmd);
2602 install_element(OSPF_NODE, &ospf_mpls_te_router_addr_cmd);
2603 install_element(OSPF_NODE, &ospf_mpls_te_inter_as_cmd);
2604 install_element(OSPF_NODE, &ospf_mpls_te_inter_as_area_cmd);
2605 install_element(OSPF_NODE, &no_ospf_mpls_te_inter_as_cmd);
2606
2607 return;
718e3744 2608}