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