blob: e750933d053b1c6916c17fc23d4521041cf76445 [file] [log] [blame]
paul718e3742002-12-13 20:15:29 +00001/*
2 * This is an implementation of draft-katz-yeung-ospf-traffic-06.txt
3 * Copyright (C) 2001 KDD R&D Laboratories, Inc.
4 * http://www.kddlabs.co.jp/
5 *
6 * This file is part of GNU Zebra.
7 *
8 * GNU Zebra is free software; you can redistribute it and/or modify it
9 * under the terms of the GNU General Public License as published by the
10 * Free Software Foundation; either version 2, or (at your option) any
11 * later version.
12 *
13 * GNU Zebra is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with GNU Zebra; see the file COPYING. If not, write to the Free
20 * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
21 * 02111-1307, USA.
22 */
23
24/***** MTYPE definition is not reflected to "memory.h" yet. *****/
David Lamparter23757db2016-02-24 06:26:02 +010025#define MTYPE_OSPF_MPLS_TE_LINKPARAMS MTYPE_TMP
paul718e3742002-12-13 20:15:29 +000026
27#include <zebra.h>
28
paul718e3742002-12-13 20:15:29 +000029#include "linklist.h"
30#include "prefix.h"
31#include "if.h"
32#include "table.h"
33#include "memory.h"
34#include "command.h"
35#include "vty.h"
36#include "stream.h"
37#include "log.h"
38#include "thread.h"
39#include "hash.h"
40#include "sockunion.h" /* for inet_aton() */
Paul Jakma43595012015-05-19 18:50:49 +010041#include "network.h"
paul718e3742002-12-13 20:15:29 +000042
43#include "ospfd/ospfd.h"
44#include "ospfd/ospf_interface.h"
45#include "ospfd/ospf_ism.h"
46#include "ospfd/ospf_asbr.h"
47#include "ospfd/ospf_lsa.h"
48#include "ospfd/ospf_lsdb.h"
49#include "ospfd/ospf_neighbor.h"
50#include "ospfd/ospf_nsm.h"
51#include "ospfd/ospf_flood.h"
52#include "ospfd/ospf_packet.h"
53#include "ospfd/ospf_spf.h"
54#include "ospfd/ospf_dump.h"
55#include "ospfd/ospf_route.h"
56#include "ospfd/ospf_ase.h"
57#include "ospfd/ospf_zebra.h"
58#include "ospfd/ospf_te.h"
59
60/* Following structure are internal use only. */
61struct ospf_mpls_te
62{
63 enum { disabled, enabled } status;
64
65 /* List elements are zebra-interfaces (ifp), not ospf-interfaces (oi). */
paul87d6f872004-09-24 08:01:38 +000066 struct list *iflist;
paul718e3742002-12-13 20:15:29 +000067
68 /* Store Router-TLV in network byte order. */
69 struct te_tlv_router_addr router_addr;
70};
71
72struct mpls_te_link
73{
74 /*
75 * According to MPLS-TE (draft) specification, 24-bit Opaque-ID field
76 * is subdivided into 8-bit "unused" field and 16-bit "instance" field.
77 * In this implementation, each Link-TLV has its own instance.
78 */
79 u_int32_t instance;
80
81 /* Reference pointer to a Zebra-interface. */
82 struct interface *ifp;
83
84 /* Area info in which this MPLS-TE link belongs to. */
85 struct ospf_area *area;
86
87 /* Flags to manage this link parameters. */
88 u_int32_t flags;
89#define LPFLG_LOOKUP_DONE 0x1
90#define LPFLG_LSA_ENGAGED 0x2
91#define LPFLG_LSA_FORCED_REFRESH 0x4
92
93 /* Store Link-TLV in network byte order. */
94 struct te_tlv_link link_header;
95 struct te_link_subtlv_link_type link_type;
96 struct te_link_subtlv_link_id link_id;
97 struct te_link_subtlv_lclif_ipaddr *lclif_ipaddr;
98 struct te_link_subtlv_rmtif_ipaddr *rmtif_ipaddr;
99 struct te_link_subtlv_te_metric te_metric;
100 struct te_link_subtlv_max_bw max_bw;
101 struct te_link_subtlv_max_rsv_bw max_rsv_bw;
102 struct te_link_subtlv_unrsv_bw unrsv_bw;
103 struct te_link_subtlv_rsc_clsclr rsc_clsclr;
104};
105
106/*
107 * Global variable to manage Opaque-LSA/MPLS-TE on this node.
108 * Note that all parameter values are stored in network byte order.
109 */
110static struct ospf_mpls_te OspfMplsTE;
111
112enum oifstate {
113 OI_ANY, OI_DOWN, OI_UP
114};
115
116enum sched_opcode {
117 REORIGINATE_PER_AREA, REFRESH_THIS_LSA, FLUSH_THIS_LSA
118};
119
120/*------------------------------------------------------------------------*
121 * Followings are initialize/terminate functions for MPLS-TE handling.
122 *------------------------------------------------------------------------*/
123
124static int ospf_mpls_te_new_if (struct interface *ifp);
125static int ospf_mpls_te_del_if (struct interface *ifp);
126static void ospf_mpls_te_ism_change (struct ospf_interface *oi, int old_status);
127static void ospf_mpls_te_nsm_change (struct ospf_neighbor *nbr, int old_status);
128static void ospf_mpls_te_config_write_router (struct vty *vty);
129static void ospf_mpls_te_config_write_if (struct vty *vty, struct interface *ifp);
130static void ospf_mpls_te_show_info (struct vty *vty, struct ospf_lsa *lsa);
131static int ospf_mpls_te_lsa_originate (void *arg);
Paul Jakma072990e2011-04-11 16:28:16 +0100132static struct ospf_lsa *ospf_mpls_te_lsa_refresh (struct ospf_lsa *lsa);
paul718e3742002-12-13 20:15:29 +0000133static void ospf_mpls_te_lsa_schedule (struct mpls_te_link *lp, enum sched_opcode);
134
135static void del_mpls_te_link (void *val);
136static void ospf_mpls_te_register_vty (void);
137
138int
139ospf_mpls_te_init (void)
140{
141 int rc;
142
143 rc = ospf_register_opaque_functab (
144 OSPF_OPAQUE_AREA_LSA,
145 OPAQUE_TYPE_TRAFFIC_ENGINEERING_LSA,
146 ospf_mpls_te_new_if,
147 ospf_mpls_te_del_if,
148 ospf_mpls_te_ism_change,
149 ospf_mpls_te_nsm_change,
150 ospf_mpls_te_config_write_router,
151 ospf_mpls_te_config_write_if,
152 NULL,/* ospf_mpls_te_config_write_debug */
153 ospf_mpls_te_show_info,
154 ospf_mpls_te_lsa_originate,
155 ospf_mpls_te_lsa_refresh,
156 NULL,/* ospf_mpls_te_new_lsa_hook */
157 NULL /* ospf_mpls_te_del_lsa_hook */);
158 if (rc != 0)
159 {
160 zlog_warn ("ospf_mpls_te_init: Failed to register functions");
161 goto out;
162 }
163
164 memset (&OspfMplsTE, 0, sizeof (struct ospf_mpls_te));
165 OspfMplsTE.status = disabled;
166 OspfMplsTE.iflist = list_new ();
167 OspfMplsTE.iflist->del = del_mpls_te_link;
168
169 ospf_mpls_te_register_vty ();
170
171out:
172 return rc;
173}
174
175void
176ospf_mpls_te_term (void)
177{
178 list_delete (OspfMplsTE.iflist);
179
180 OspfMplsTE.iflist = NULL;
181 OspfMplsTE.status = disabled;
182
183 ospf_delete_opaque_functab (OSPF_OPAQUE_AREA_LSA,
184 OPAQUE_TYPE_TRAFFIC_ENGINEERING_LSA);
185 return;
186}
187
188/*------------------------------------------------------------------------*
189 * Followings are control functions for MPLS-TE parameters management.
190 *------------------------------------------------------------------------*/
191
192static void
193del_mpls_te_link (void *val)
194{
195 XFREE (MTYPE_OSPF_MPLS_TE_LINKPARAMS, val);
196 return;
197}
198
199static u_int32_t
paul4dadc292005-05-06 21:37:42 +0000200get_mpls_te_instance_value (void)
paul718e3742002-12-13 20:15:29 +0000201{
202 static u_int32_t seqno = 0;
203
Andrew Certain703819a2012-12-04 13:36:41 -0800204 if (seqno < MAX_LEGAL_TE_INSTANCE_NUM )
paul718e3742002-12-13 20:15:29 +0000205 seqno += 1;
206 else
207 seqno = 1; /* Avoid zero. */
208
209 return seqno;
210}
211
212static struct ospf_interface *
213lookup_oi_by_ifp (struct interface *ifp,
214 struct ospf_area *area, enum oifstate oifstate)
215{
216 struct ospf_interface *oi = NULL;
217 struct route_node *rn;
218
219 for (rn = route_top (IF_OIFS (ifp)); rn; rn = route_next (rn))
220 {
221 if ((oi = rn->info) == NULL)
222 continue;
223
224 switch (oifstate)
225 {
226 case OI_ANY:
227 break;
228 case OI_DOWN:
229 if (ospf_if_is_enable (oi))
230 continue;
231 break;
232 case OI_UP:
233 if (! ospf_if_is_enable (oi))
234 continue;
235 break;
236 default:
237 zlog_warn ("lookup_oi_by_ifp: Unknown oifstate: %x", oifstate);
238 goto out;
239 }
240
241 if (area == NULL || oi->area == area)
242 return oi;
243 }
244out:
245 return NULL;
246}
247
248static struct mpls_te_link *
249lookup_linkparams_by_ifp (struct interface *ifp)
250{
paul1eb8ef22005-04-07 07:30:20 +0000251 struct listnode *node, *nnode;
paul718e3742002-12-13 20:15:29 +0000252 struct mpls_te_link *lp;
253
paul1eb8ef22005-04-07 07:30:20 +0000254 for (ALL_LIST_ELEMENTS (OspfMplsTE.iflist, node, nnode, lp))
paul87d6f872004-09-24 08:01:38 +0000255 if (lp->ifp == ifp)
256 return lp;
paul718e3742002-12-13 20:15:29 +0000257
258 return NULL;
259}
260
261static struct mpls_te_link *
262lookup_linkparams_by_instance (struct ospf_lsa *lsa)
263{
paul87d6f872004-09-24 08:01:38 +0000264 struct listnode *node;
paul718e3742002-12-13 20:15:29 +0000265 struct mpls_te_link *lp;
paul6c835672004-10-11 11:00:30 +0000266 unsigned int key = GET_OPAQUE_ID (ntohl (lsa->data->id.s_addr));
paul718e3742002-12-13 20:15:29 +0000267
paul1eb8ef22005-04-07 07:30:20 +0000268 for (ALL_LIST_ELEMENTS_RO (OspfMplsTE.iflist, node, lp))
paul87d6f872004-09-24 08:01:38 +0000269 if (lp->instance == key)
270 return lp;
paul718e3742002-12-13 20:15:29 +0000271
272 zlog_warn ("lookup_linkparams_by_instance: Entry not found: key(%x)", key);
273 return NULL;
274}
275
276static void
277ospf_mpls_te_foreach_area (
278 void (*func)(struct mpls_te_link *lp, enum sched_opcode),
279 enum sched_opcode sched_opcode)
280{
paul1eb8ef22005-04-07 07:30:20 +0000281 struct listnode *node, *nnode;
282 struct listnode *node2;
paul718e3742002-12-13 20:15:29 +0000283 struct mpls_te_link *lp;
284 struct ospf_area *area;
285
paul1eb8ef22005-04-07 07:30:20 +0000286 for (ALL_LIST_ELEMENTS (OspfMplsTE.iflist, node, nnode, lp))
paul718e3742002-12-13 20:15:29 +0000287 {
paul718e3742002-12-13 20:15:29 +0000288 if ((area = lp->area) == NULL)
289 continue;
290 if (lp->flags & LPFLG_LOOKUP_DONE)
291 continue;
292
293 if (func != NULL)
294 (* func)(lp, sched_opcode);
295
paul1eb8ef22005-04-07 07:30:20 +0000296 for (node2 = listnextnode (node); node2; node2 = listnextnode (node2))
297 if ((lp = listgetdata (node2)) != NULL)
paul718e3742002-12-13 20:15:29 +0000298 if (lp->area != NULL)
299 if (IPV4_ADDR_SAME (&lp->area->area_id, &area->area_id))
300 lp->flags |= LPFLG_LOOKUP_DONE;
301 }
302
paul1eb8ef22005-04-07 07:30:20 +0000303 for (ALL_LIST_ELEMENTS_RO (OspfMplsTE.iflist, node, lp))
paul87d6f872004-09-24 08:01:38 +0000304 if (lp->area != NULL)
305 lp->flags &= ~LPFLG_LOOKUP_DONE;
paul718e3742002-12-13 20:15:29 +0000306
307 return;
308}
309
310static void
311set_mpls_te_router_addr (struct in_addr ipv4)
312{
313 OspfMplsTE.router_addr.header.type = htons (TE_TLV_ROUTER_ADDR);
314 OspfMplsTE.router_addr.header.length = htons (sizeof (ipv4));
315 OspfMplsTE.router_addr.value = ipv4;
316 return;
317}
318
319static void
320set_linkparams_link_header (struct mpls_te_link *lp)
321{
322 struct te_tlv_header *tlvh;
323 u_int16_t length = 0;
324
325 /* TE_LINK_SUBTLV_LINK_TYPE */
326 if (ntohs (lp->link_type.header.type) != 0)
327 length += TLV_SIZE (&lp->link_type.header);
328
329 /* TE_LINK_SUBTLV_LINK_ID */
330 if (ntohs (lp->link_id.header.type) != 0)
331 length += TLV_SIZE (&lp->link_id.header);
332
333 /* TE_LINK_SUBTLV_LCLIF_IPADDR */
334 if ((tlvh = (struct te_tlv_header *) lp->lclif_ipaddr) != NULL
335 && ntohs (tlvh->type) != 0)
336 length += TLV_SIZE (tlvh);
337
338 /* TE_LINK_SUBTLV_RMTIF_IPADDR */
339 if ((tlvh = (struct te_tlv_header *) lp->rmtif_ipaddr) != NULL
340 && ntohs (tlvh->type) != 0)
341 length += TLV_SIZE (tlvh);
342
343 /* TE_LINK_SUBTLV_TE_METRIC */
344 if (ntohs (lp->te_metric.header.type) != 0)
345 length += TLV_SIZE (&lp->te_metric.header);
346
347 /* TE_LINK_SUBTLV_MAX_BW */
348 if (ntohs (lp->max_bw.header.type) != 0)
349 length += TLV_SIZE (&lp->max_bw.header);
350
351 /* TE_LINK_SUBTLV_MAX_RSV_BW */
352 if (ntohs (lp->max_rsv_bw.header.type) != 0)
353 length += TLV_SIZE (&lp->max_rsv_bw.header);
354
355 /* TE_LINK_SUBTLV_UNRSV_BW */
356 if (ntohs (lp->unrsv_bw.header.type) != 0)
357 length += TLV_SIZE (&lp->unrsv_bw.header);
358
359 /* TE_LINK_SUBTLV_RSC_CLSCLR */
360 if (ntohs (lp->rsc_clsclr.header.type) != 0)
361 length += TLV_SIZE (&lp->rsc_clsclr.header);
362
363 lp->link_header.header.type = htons (TE_TLV_LINK);
364 lp->link_header.header.length = htons (length);
365
366 return;
367}
368
369static void
370set_linkparams_link_type (struct ospf_interface *oi, struct mpls_te_link *lp)
371{
372 lp->link_type.header.type = htons (TE_LINK_SUBTLV_LINK_TYPE);
373 lp->link_type.header.length = htons (sizeof (lp->link_type.link_type.value));
374
375 switch (oi->type)
376 {
377 case OSPF_IFTYPE_POINTOPOINT:
378 lp->link_type.link_type.value = LINK_TYPE_SUBTLV_VALUE_PTP;
379 break;
380 case OSPF_IFTYPE_BROADCAST:
381 case OSPF_IFTYPE_NBMA:
382 lp->link_type.link_type.value = LINK_TYPE_SUBTLV_VALUE_MA;
383 break;
384 default:
385 /* Not supported yet. *//* XXX */
386 lp->link_type.header.type = htons (0);
387 break;
388 }
389 return;
390}
391
392static void
393set_linkparams_link_id (struct ospf_interface *oi, struct mpls_te_link *lp)
394{
395 struct ospf_neighbor *nbr;
396 int done = 0;
397
398 lp->link_id.header.type = htons (TE_LINK_SUBTLV_LINK_ID);
399 lp->link_id.header.length = htons (sizeof (lp->link_id.value));
400
401 /*
402 * The Link ID is identical to the contents of the Link ID field
403 * in the Router LSA for these link types.
404 */
405 switch (oi->type)
406 {
407 case OSPF_IFTYPE_POINTOPOINT:
408 /* Take the router ID of the neighbor. */
pauld4a53d52003-07-12 21:30:57 +0000409 if ((nbr = ospf_nbr_lookup_ptop (oi))
410 && nbr->state == NSM_Full)
paul718e3742002-12-13 20:15:29 +0000411 {
412 lp->link_id.value = nbr->router_id;
413 done = 1;
414 }
415 break;
416 case OSPF_IFTYPE_BROADCAST:
417 case OSPF_IFTYPE_NBMA:
418 /* Take the interface address of the designated router. */
419 if ((nbr = ospf_nbr_lookup_by_addr (oi->nbrs, &DR (oi))) == NULL)
420 break;
421
422 if (nbr->state == NSM_Full
423 || (IPV4_ADDR_SAME (&oi->address->u.prefix4, &DR (oi))
pauld4a53d52003-07-12 21:30:57 +0000424 && ospf_nbr_count (oi, NSM_Full) > 0))
paul718e3742002-12-13 20:15:29 +0000425 {
426 lp->link_id.value = DR (oi);
427 done = 1;
428 }
429 break;
430 default:
431 /* Not supported yet. *//* XXX */
432 lp->link_id.header.type = htons (0);
433 break;
434 }
435
436 if (! done)
437 {
438 struct in_addr mask;
439 masklen2ip (oi->address->prefixlen, &mask);
440 lp->link_id.value.s_addr = oi->address->u.prefix4.s_addr & mask.s_addr;
441 }
442 return;
443}
444
445static void
446set_linkparams_te_metric (struct mpls_te_link *lp, u_int32_t te_metric)
447{
448 lp->te_metric.header.type = htons (TE_LINK_SUBTLV_TE_METRIC);
449 lp->te_metric.header.length = htons (sizeof (lp->te_metric.value));
450 lp->te_metric.value = htonl (te_metric);
451 return;
452}
453
454static void
Paul Jakma43595012015-05-19 18:50:49 +0100455set_linkparams_max_bw (struct mpls_te_link *lp, float fp)
paul718e3742002-12-13 20:15:29 +0000456{
457 lp->max_bw.header.type = htons (TE_LINK_SUBTLV_MAX_BW);
458 lp->max_bw.header.length = htons (sizeof (lp->max_bw.value));
Paul Jakma43595012015-05-19 18:50:49 +0100459 lp->max_bw.value = htonf (fp);
paul718e3742002-12-13 20:15:29 +0000460 return;
461}
462
463static void
Paul Jakma43595012015-05-19 18:50:49 +0100464set_linkparams_max_rsv_bw (struct mpls_te_link *lp, float fp)
paul718e3742002-12-13 20:15:29 +0000465{
466 lp->max_rsv_bw.header.type = htons (TE_LINK_SUBTLV_MAX_RSV_BW);
467 lp->max_rsv_bw.header.length = htons (sizeof (lp->max_rsv_bw.value));
Paul Jakma43595012015-05-19 18:50:49 +0100468 lp->max_rsv_bw.value = htonf (fp);
paul718e3742002-12-13 20:15:29 +0000469 return;
470}
471
472static void
Paul Jakma43595012015-05-19 18:50:49 +0100473set_linkparams_unrsv_bw (struct mpls_te_link *lp, int priority, float fp)
paul718e3742002-12-13 20:15:29 +0000474{
475 /* Note that TLV-length field is the size of array. */
476 lp->unrsv_bw.header.type = htons (TE_LINK_SUBTLV_UNRSV_BW);
477 lp->unrsv_bw.header.length = htons (sizeof (lp->unrsv_bw.value));
Paul Jakma43595012015-05-19 18:50:49 +0100478 lp->unrsv_bw.value [priority] = htonf (fp);
paul718e3742002-12-13 20:15:29 +0000479 return;
480}
481
482static void
483set_linkparams_rsc_clsclr (struct mpls_te_link *lp, u_int32_t classcolor)
484{
485 lp->rsc_clsclr.header.type = htons (TE_LINK_SUBTLV_RSC_CLSCLR);
486 lp->rsc_clsclr.header.length = htons (sizeof (lp->rsc_clsclr.value));
487 lp->rsc_clsclr.value = htonl (classcolor);
488 return;
489}
490
491static void
492initialize_linkparams (struct mpls_te_link *lp)
493{
494 struct interface *ifp = lp->ifp;
495 struct ospf_interface *oi;
496 float fval;
497 int i;
498
499 if ((oi = lookup_oi_by_ifp (ifp, NULL, OI_ANY)) == NULL)
500 return;
501
502 /*
503 * Try to set initial values those can be derived from
504 * zebra-interface information.
505 */
506 set_linkparams_link_type (oi, lp);
507
508 /*
509 * Linux and *BSD kernel holds bandwidth parameter as an "int" type.
510 * We may have to reconsider, if "ifp->bandwidth" type changes to float.
511 */
512 fval = (float)((ifp->bandwidth ? ifp->bandwidth
513 : OSPF_DEFAULT_BANDWIDTH) * 1000 / 8);
514
Paul Jakma43595012015-05-19 18:50:49 +0100515 set_linkparams_max_bw (lp, fval);
516 set_linkparams_max_rsv_bw (lp, fval);
paul718e3742002-12-13 20:15:29 +0000517
518 for (i = 0; i < 8; i++)
Paul Jakma43595012015-05-19 18:50:49 +0100519 set_linkparams_unrsv_bw (lp, i, fval);
paul718e3742002-12-13 20:15:29 +0000520
521 return;
522}
523
524static int
525is_mandated_params_set (struct mpls_te_link *lp)
526{
527 int rc = 0;
528
529 if (ntohs (OspfMplsTE.router_addr.header.type) == 0)
530 goto out;
531
532 if (ntohs (lp->link_type.header.type) == 0)
533 goto out;
534
535 if (ntohs (lp->link_id.header.type) == 0)
536 goto out;
537
538 rc = 1;
539out:
540 return rc;
541}
542
543/*------------------------------------------------------------------------*
544 * Followings are callback functions against generic Opaque-LSAs handling.
545 *------------------------------------------------------------------------*/
546
547static int
548ospf_mpls_te_new_if (struct interface *ifp)
549{
550 struct mpls_te_link *new;
551 int rc = -1;
552
553 if (lookup_linkparams_by_ifp (ifp) != NULL)
554 {
David Lampartereed3c482015-03-03 08:51:53 +0100555 zlog_warn ("ospf_mpls_te_new_if: ifp(%p) already in use?", (void *)ifp);
paul718e3742002-12-13 20:15:29 +0000556 rc = 0; /* Do nothing here. */
557 goto out;
558 }
559
Stephen Hemminger393deb92008-08-18 14:13:29 -0700560 new = XCALLOC (MTYPE_OSPF_MPLS_TE_LINKPARAMS,
561 sizeof (struct mpls_te_link));
562 if (new == NULL)
paul718e3742002-12-13 20:15:29 +0000563 {
ajs6099b3b2004-11-20 02:06:59 +0000564 zlog_warn ("ospf_mpls_te_new_if: XMALLOC: %s", safe_strerror (errno));
paul718e3742002-12-13 20:15:29 +0000565 goto out;
566 }
paul718e3742002-12-13 20:15:29 +0000567
568 new->area = NULL;
569 new->flags = 0;
570 new->instance = get_mpls_te_instance_value ();
571 new->ifp = ifp;
572
573 initialize_linkparams (new);
574
575 listnode_add (OspfMplsTE.iflist, new);
576
577 /* Schedule Opaque-LSA refresh. *//* XXX */
578
579 rc = 0;
580out:
581 return rc;
582}
583
584static int
585ospf_mpls_te_del_if (struct interface *ifp)
586{
587 struct mpls_te_link *lp;
588 int rc = -1;
589
590 if ((lp = lookup_linkparams_by_ifp (ifp)) != NULL)
591 {
paul87d6f872004-09-24 08:01:38 +0000592 struct list *iflist = OspfMplsTE.iflist;
paul718e3742002-12-13 20:15:29 +0000593
594 /* Dequeue listnode entry from the list. */
595 listnode_delete (iflist, lp);
596
597 /* Avoid misjudgement in the next lookup. */
598 if (listcount (iflist) == 0)
599 iflist->head = iflist->tail = NULL;
600
601 XFREE (MTYPE_OSPF_MPLS_TE_LINKPARAMS, lp);
602 }
603
604 /* Schedule Opaque-LSA refresh. *//* XXX */
605
606 rc = 0;
607/*out:*/
608 return rc;
609}
610
611static void
612ospf_mpls_te_ism_change (struct ospf_interface *oi, int old_state)
613{
614 struct te_link_subtlv_link_type old_type;
615 struct te_link_subtlv_link_id old_id;
616 struct mpls_te_link *lp;
617
618 if ((lp = lookup_linkparams_by_ifp (oi->ifp)) == NULL)
619 {
620 zlog_warn ("ospf_mpls_te_ism_change: Cannot get linkparams from OI(%s)?", IF_NAME (oi));
621 goto out;
622 }
pauld4a53d52003-07-12 21:30:57 +0000623 if (oi->area == NULL || oi->area->ospf == NULL)
paul718e3742002-12-13 20:15:29 +0000624 {
625 zlog_warn ("ospf_mpls_te_ism_change: Cannot refer to OSPF from OI(%s)?",
626IF_NAME (oi));
627 goto out;
628 }
629#ifdef notyet
630 if ((lp->area != NULL
631 && ! IPV4_ADDR_SAME (&lp->area->area_id, &oi->area->area_id))
632 || (lp->area != NULL && oi->area == NULL))
633 {
634 /* How should we consider this case? */
635 zlog_warn ("MPLS-TE: Area for OI(%s) has changed to [%s], flush previous LSAs", IF_NAME (oi), oi->area ? inet_ntoa (oi->area->area_id) : "N/A");
636 ospf_mpls_te_lsa_schedule (lp, FLUSH_THIS_LSA);
637 }
638#endif
639 /* Keep Area information in conbination with linkparams. */
640 lp->area = oi->area;
641
642 switch (oi->state)
643 {
644 case ISM_PointToPoint:
645 case ISM_DROther:
646 case ISM_Backup:
647 case ISM_DR:
648 old_type = lp->link_type;
649 old_id = lp->link_id;
650
651 set_linkparams_link_type (oi, lp);
652 set_linkparams_link_id (oi, lp);
653
654 if ((ntohs (old_type.header.type) != ntohs (lp->link_type.header.type)
655 || old_type.link_type.value != lp->link_type.link_type.value)
656 || (ntohs (old_id.header.type) != ntohs (lp->link_id.header.type)
657 || ntohl (old_id.value.s_addr) != ntohl (lp->link_id.value.s_addr)))
658 {
659 if (lp->flags & LPFLG_LSA_ENGAGED)
660 ospf_mpls_te_lsa_schedule (lp, REFRESH_THIS_LSA);
661 else
662 ospf_mpls_te_lsa_schedule (lp, REORIGINATE_PER_AREA);
663 }
664 break;
665 default:
666 lp->link_type.header.type = htons (0);
667 lp->link_id.header.type = htons (0);
668
669 if (lp->flags & LPFLG_LSA_ENGAGED)
670 ospf_mpls_te_lsa_schedule (lp, FLUSH_THIS_LSA);
671 break;
672 }
673
674out:
675 return;
676}
677
678static void
679ospf_mpls_te_nsm_change (struct ospf_neighbor *nbr, int old_state)
680{
681 /* So far, nothing to do here. */
682 return;
683}
684
685/*------------------------------------------------------------------------*
686 * Followings are OSPF protocol processing functions for MPLS-TE.
687 *------------------------------------------------------------------------*/
688
689static void
690build_tlv_header (struct stream *s, struct te_tlv_header *tlvh)
691{
692 stream_put (s, tlvh, sizeof (struct te_tlv_header));
693 return;
694}
695
696static void
697build_router_tlv (struct stream *s)
698{
699 struct te_tlv_header *tlvh = &OspfMplsTE.router_addr.header;
700 if (ntohs (tlvh->type) != 0)
701 {
702 build_tlv_header (s, tlvh);
703 stream_put (s, tlvh+1, TLV_BODY_SIZE (tlvh));
704 }
705 return;
706}
707
708static void
709build_link_subtlv_link_type (struct stream *s, struct mpls_te_link *lp)
710{
711 struct te_tlv_header *tlvh = &lp->link_type.header;
712 if (ntohs (tlvh->type) != 0)
713 {
714 build_tlv_header (s, tlvh);
715 stream_put (s, tlvh+1, TLV_BODY_SIZE (tlvh));
716 }
717 return;
718}
719
720static void
721build_link_subtlv_link_id (struct stream *s, struct mpls_te_link *lp)
722{
723 struct te_tlv_header *tlvh = &lp->link_id.header;
724 if (ntohs (tlvh->type) != 0)
725 {
726 build_tlv_header (s, tlvh);
727 stream_put (s, tlvh+1, TLV_BODY_SIZE (tlvh));
728 }
729 return;
730}
731
732static void
733build_link_subtlv_lclif_ipaddr (struct stream *s, struct mpls_te_link *lp)
734{
735 struct te_tlv_header *tlvh = (struct te_tlv_header *) lp->lclif_ipaddr;
736 if (tlvh != NULL && ntohs (tlvh->type) != 0)
737 {
738 build_tlv_header (s, tlvh);
739 stream_put (s, tlvh+1, TLV_BODY_SIZE (tlvh));
740 }
741 return;
742}
743
744static void
745build_link_subtlv_rmtif_ipaddr (struct stream *s, struct mpls_te_link *lp)
746{
747 struct te_tlv_header *tlvh = (struct te_tlv_header *) lp->rmtif_ipaddr;
748 if (tlvh != NULL && ntohs (tlvh->type) != 0)
749 {
750 build_tlv_header (s, tlvh);
751 stream_put (s, tlvh+1, TLV_BODY_SIZE (tlvh));
752 }
753 return;
754}
755
756static void
757build_link_subtlv_te_metric (struct stream *s, struct mpls_te_link *lp)
758{
759 struct te_tlv_header *tlvh = &lp->te_metric.header;
760 if (ntohs (tlvh->type) != 0)
761 {
762 build_tlv_header (s, tlvh);
763 stream_put (s, tlvh+1, TLV_BODY_SIZE (tlvh));
764 }
765 return;
766}
767
768static void
769build_link_subtlv_max_bw (struct stream *s, struct mpls_te_link *lp)
770{
771 struct te_tlv_header *tlvh = &lp->max_bw.header;
772 if (ntohs (tlvh->type) != 0)
773 {
774 build_tlv_header (s, tlvh);
775 stream_put (s, tlvh+1, TLV_BODY_SIZE (tlvh));
776 }
777 return;
778}
779
780static void
781build_link_subtlv_max_rsv_bw (struct stream *s, struct mpls_te_link *lp)
782{
783 struct te_tlv_header *tlvh = &lp->max_rsv_bw.header;
784 if (ntohs (tlvh->type) != 0)
785 {
786 build_tlv_header (s, tlvh);
787 stream_put (s, tlvh+1, TLV_BODY_SIZE (tlvh));
788 }
789 return;
790}
791
792static void
793build_link_subtlv_unrsv_bw (struct stream *s, struct mpls_te_link *lp)
794{
795 struct te_tlv_header *tlvh = &lp->unrsv_bw.header;
796 if (ntohs (tlvh->type) != 0)
797 {
798 build_tlv_header (s, tlvh);
799 stream_put (s, tlvh+1, TLV_BODY_SIZE (tlvh));
800 }
801 return;
802}
803
804static void
805build_link_subtlv_rsc_clsclr (struct stream *s, struct mpls_te_link *lp)
806{
807 struct te_tlv_header *tlvh = &lp->rsc_clsclr.header;
808 if (ntohs (tlvh->type) != 0)
809 {
810 build_tlv_header (s, tlvh);
811 stream_put (s, tlvh+1, TLV_BODY_SIZE (tlvh));
812 }
813 return;
814}
815
816static void
817build_link_tlv (struct stream *s, struct mpls_te_link *lp)
818{
819 set_linkparams_link_header (lp);
820 build_tlv_header (s, &lp->link_header.header);
821
822 build_link_subtlv_link_type (s, lp);
823 build_link_subtlv_link_id (s, lp);
824 build_link_subtlv_lclif_ipaddr (s, lp);
825 build_link_subtlv_rmtif_ipaddr (s, lp);
826 build_link_subtlv_te_metric (s, lp);
827 build_link_subtlv_max_bw (s, lp);
828 build_link_subtlv_max_rsv_bw (s, lp);
829 build_link_subtlv_unrsv_bw (s, lp);
830 build_link_subtlv_rsc_clsclr (s, lp);
831 return;
832}
833
834static void
835ospf_mpls_te_lsa_body_set (struct stream *s, struct mpls_te_link *lp)
836{
837 /*
838 * The router address TLV is type 1, and ...
839 * It must appear in exactly one
840 * Traffic Engineering LSA originated by a router.
841 */
842 build_router_tlv (s);
843
844 /*
845 * Only one Link TLV shall be carried in each LSA, allowing for fine
846 * granularity changes in topology.
847 */
848 build_link_tlv (s, lp);
849 return;
850}
851
852/* Create new opaque-LSA. */
853static struct ospf_lsa *
854ospf_mpls_te_lsa_new (struct ospf_area *area, struct mpls_te_link *lp)
855{
856 struct stream *s;
857 struct lsa_header *lsah;
858 struct ospf_lsa *new = NULL;
859 u_char options, lsa_type;
860 struct in_addr lsa_id;
861 u_int32_t tmp;
862 u_int16_t length;
863
864 /* Create a stream for LSA. */
865 if ((s = stream_new (OSPF_MAX_LSA_SIZE)) == NULL)
866 {
867 zlog_warn ("ospf_mpls_te_lsa_new: stream_new() ?");
868 goto out;
869 }
870 lsah = (struct lsa_header *) STREAM_DATA (s);
871
872 options = LSA_OPTIONS_GET (area);
pauld4a53d52003-07-12 21:30:57 +0000873 options |= LSA_OPTIONS_NSSA_GET (area);
paul718e3742002-12-13 20:15:29 +0000874 options |= OSPF_OPTION_O; /* Don't forget this :-) */
875
876 lsa_type = OSPF_OPAQUE_AREA_LSA;
877 tmp = SET_OPAQUE_LSID (OPAQUE_TYPE_TRAFFIC_ENGINEERING_LSA, lp->instance);
878 lsa_id.s_addr = htonl (tmp);
879
880 if (IS_DEBUG_OSPF (lsa, LSA_GENERATE))
ajs2a42e282004-12-08 18:43:03 +0000881 zlog_debug ("LSA[Type%d:%s]: Create an Opaque-LSA/MPLS-TE instance", lsa_type, inet_ntoa (lsa_id));
paul718e3742002-12-13 20:15:29 +0000882
883 /* Set opaque-LSA header fields. */
pauld4a53d52003-07-12 21:30:57 +0000884 lsa_header_set (s, options, lsa_type, lsa_id, area->ospf->router_id);
paul718e3742002-12-13 20:15:29 +0000885
886 /* Set opaque-LSA body fields. */
887 ospf_mpls_te_lsa_body_set (s, lp);
888
889 /* Set length. */
890 length = stream_get_endp (s);
891 lsah->length = htons (length);
892
893 /* Now, create an OSPF LSA instance. */
894 if ((new = ospf_lsa_new ()) == NULL)
895 {
896 zlog_warn ("ospf_mpls_te_lsa_new: ospf_lsa_new() ?");
897 stream_free (s);
898 goto out;
899 }
900 if ((new->data = ospf_lsa_data_new (length)) == NULL)
901 {
902 zlog_warn ("ospf_mpls_te_lsa_new: ospf_lsa_data_new() ?");
Paul Jakma1fe6ed32006-07-26 09:37:26 +0000903 ospf_lsa_unlock (&new);
paul718e3742002-12-13 20:15:29 +0000904 new = NULL;
905 stream_free (s);
906 goto out;
907 }
908
909 new->area = area;
910 SET_FLAG (new->flags, OSPF_LSA_SELF);
911 memcpy (new->data, lsah, length);
912 stream_free (s);
913
914out:
915 return new;
916}
917
918static int
919ospf_mpls_te_lsa_originate1 (struct ospf_area *area, struct mpls_te_link *lp)
920{
921 struct ospf_lsa *new;
922 int rc = -1;
923
924 /* Create new Opaque-LSA/MPLS-TE instance. */
925 if ((new = ospf_mpls_te_lsa_new (area, lp)) == NULL)
926 {
927 zlog_warn ("ospf_mpls_te_lsa_originate1: ospf_mpls_te_lsa_new() ?");
928 goto out;
929 }
930
931 /* Install this LSA into LSDB. */
pauld4a53d52003-07-12 21:30:57 +0000932 if (ospf_lsa_install (area->ospf, NULL/*oi*/, new) == NULL)
paul718e3742002-12-13 20:15:29 +0000933 {
934 zlog_warn ("ospf_mpls_te_lsa_originate1: ospf_lsa_install() ?");
Paul Jakma1fe6ed32006-07-26 09:37:26 +0000935 ospf_lsa_unlock (&new);
paul718e3742002-12-13 20:15:29 +0000936 goto out;
937 }
938
939 /* Now this linkparameter entry has associated LSA. */
940 lp->flags |= LPFLG_LSA_ENGAGED;
941
942 /* Update new LSA origination count. */
pauld4a53d52003-07-12 21:30:57 +0000943 area->ospf->lsa_originate_count++;
paul718e3742002-12-13 20:15:29 +0000944
945 /* Flood new LSA through area. */
946 ospf_flood_through_area (area, NULL/*nbr*/, new);
947
948 if (IS_DEBUG_OSPF (lsa, LSA_GENERATE))
949 {
950 char area_id[INET_ADDRSTRLEN];
951 strcpy (area_id, inet_ntoa (area->area_id));
ajs2a42e282004-12-08 18:43:03 +0000952 zlog_debug ("LSA[Type%d:%s]: Originate Opaque-LSA/MPLS-TE: Area(%s), Link(%s)", new->data->type, inet_ntoa (new->data->id), area_id, lp->ifp->name);
paul718e3742002-12-13 20:15:29 +0000953 ospf_lsa_header_dump (new->data);
954 }
955
956 rc = 0;
957out:
958 return rc;
959}
960
961static int
962ospf_mpls_te_lsa_originate (void *arg)
963{
964 struct ospf_area *area = (struct ospf_area *) arg;
paul1eb8ef22005-04-07 07:30:20 +0000965 struct listnode *node, *nnode;
paul718e3742002-12-13 20:15:29 +0000966 struct mpls_te_link *lp;
967 int rc = -1;
968
969 if (OspfMplsTE.status == disabled)
970 {
971 zlog_info ("ospf_mpls_te_lsa_originate: MPLS-TE is disabled now.");
972 rc = 0; /* This is not an error case. */
973 goto out;
974 }
975
paul1eb8ef22005-04-07 07:30:20 +0000976 for (ALL_LIST_ELEMENTS (OspfMplsTE.iflist, node, nnode, lp))
paul718e3742002-12-13 20:15:29 +0000977 {
paul718e3742002-12-13 20:15:29 +0000978 if (lp->area == NULL)
979 continue;
980 if (! IPV4_ADDR_SAME (&lp->area->area_id, &area->area_id))
981 continue;
982
983 if (lp->flags & LPFLG_LSA_ENGAGED)
984 {
985 if (lp->flags & LPFLG_LSA_FORCED_REFRESH)
986 {
987 lp->flags &= ~LPFLG_LSA_FORCED_REFRESH;
988 ospf_mpls_te_lsa_schedule (lp, REFRESH_THIS_LSA);
989 }
990 continue;
991 }
992 if (! is_mandated_params_set (lp))
993 {
994 zlog_warn ("ospf_mpls_te_lsa_originate: Link(%s) lacks some mandated MPLS-TE parameters.", lp->ifp ? lp->ifp->name : "?");
995 continue;
996 }
997
998 /* Ok, let's try to originate an LSA for this area and Link. */
999 if (ospf_mpls_te_lsa_originate1 (area, lp) != 0)
1000 goto out;
1001 }
1002
1003 rc = 0;
1004out:
1005 return rc;
1006}
1007
Paul Jakma072990e2011-04-11 16:28:16 +01001008static struct ospf_lsa *
paul718e3742002-12-13 20:15:29 +00001009ospf_mpls_te_lsa_refresh (struct ospf_lsa *lsa)
1010{
1011 struct mpls_te_link *lp;
1012 struct ospf_area *area = lsa->area;
1013 struct ospf_lsa *new = NULL;
1014
1015 if (OspfMplsTE.status == disabled)
1016 {
1017 /*
1018 * This LSA must have flushed before due to MPLS-TE status change.
1019 * It seems a slip among routers in the routing domain.
1020 */
1021 zlog_info ("ospf_mpls_te_lsa_refresh: MPLS-TE is disabled now.");
1022 lsa->data->ls_age = htons (OSPF_LSA_MAXAGE); /* Flush it anyway. */
1023 }
1024
1025 /* At first, resolve lsa/lp relationship. */
1026 if ((lp = lookup_linkparams_by_instance (lsa)) == NULL)
1027 {
1028 zlog_warn ("ospf_mpls_te_lsa_refresh: Invalid parameter?");
1029 lsa->data->ls_age = htons (OSPF_LSA_MAXAGE); /* Flush it anyway. */
1030 }
1031
1032 /* If the lsa's age reached to MaxAge, start flushing procedure. */
1033 if (IS_LSA_MAXAGE (lsa))
1034 {
Remi Gacognea11e0122013-09-08 13:48:34 +00001035 if (lp)
1036 lp->flags &= ~LPFLG_LSA_ENGAGED;
paul718e3742002-12-13 20:15:29 +00001037 ospf_opaque_lsa_flush_schedule (lsa);
1038 goto out;
1039 }
1040
1041 /* Create new Opaque-LSA/MPLS-TE instance. */
1042 if ((new = ospf_mpls_te_lsa_new (area, lp)) == NULL)
1043 {
1044 zlog_warn ("ospf_mpls_te_lsa_refresh: ospf_mpls_te_lsa_new() ?");
1045 goto out;
1046 }
1047 new->data->ls_seqnum = lsa_seqnum_increment (lsa);
1048
1049 /* Install this LSA into LSDB. */
1050 /* Given "lsa" will be freed in the next function. */
pauld4a53d52003-07-12 21:30:57 +00001051 if (ospf_lsa_install (area->ospf, NULL/*oi*/, new) == NULL)
paul718e3742002-12-13 20:15:29 +00001052 {
1053 zlog_warn ("ospf_mpls_te_lsa_refresh: ospf_lsa_install() ?");
Paul Jakma1fe6ed32006-07-26 09:37:26 +00001054 ospf_lsa_unlock (&new);
paul718e3742002-12-13 20:15:29 +00001055 goto out;
1056 }
1057
1058 /* Flood updated LSA through area. */
1059 ospf_flood_through_area (area, NULL/*nbr*/, new);
1060
1061 /* Debug logging. */
1062 if (IS_DEBUG_OSPF (lsa, LSA_GENERATE))
1063 {
ajs2a42e282004-12-08 18:43:03 +00001064 zlog_debug ("LSA[Type%d:%s]: Refresh Opaque-LSA/MPLS-TE",
paul718e3742002-12-13 20:15:29 +00001065 new->data->type, inet_ntoa (new->data->id));
1066 ospf_lsa_header_dump (new->data);
1067 }
1068
1069out:
Paul Jakma072990e2011-04-11 16:28:16 +01001070 return new;
paul718e3742002-12-13 20:15:29 +00001071}
1072
1073static void
1074ospf_mpls_te_lsa_schedule (struct mpls_te_link *lp,
1075 enum sched_opcode opcode)
1076{
1077 struct ospf_lsa lsa;
1078 struct lsa_header lsah;
1079 u_int32_t tmp;
1080
1081 memset (&lsa, 0, sizeof (lsa));
1082 memset (&lsah, 0, sizeof (lsah));
1083
1084 lsa.area = lp->area;
1085 lsa.data = &lsah;
1086 lsah.type = OSPF_OPAQUE_AREA_LSA;
1087 tmp = SET_OPAQUE_LSID (OPAQUE_TYPE_TRAFFIC_ENGINEERING_LSA, lp->instance);
1088 lsah.id.s_addr = htonl (tmp);
1089
1090 switch (opcode)
1091 {
1092 case REORIGINATE_PER_AREA:
1093 ospf_opaque_lsa_reoriginate_schedule ((void *) lp->area,
1094 OSPF_OPAQUE_AREA_LSA, OPAQUE_TYPE_TRAFFIC_ENGINEERING_LSA);
1095 break;
1096 case REFRESH_THIS_LSA:
1097 ospf_opaque_lsa_refresh_schedule (&lsa);
1098 break;
1099 case FLUSH_THIS_LSA:
1100 lp->flags &= ~LPFLG_LSA_ENGAGED;
1101 ospf_opaque_lsa_flush_schedule (&lsa);
1102 break;
1103 default:
1104 zlog_warn ("ospf_mpls_te_lsa_schedule: Unknown opcode (%u)", opcode);
1105 break;
1106 }
1107
1108 return;
1109}
1110
1111/*------------------------------------------------------------------------*
1112 * Followings are vty session control functions.
1113 *------------------------------------------------------------------------*/
1114
1115static u_int16_t
1116show_vty_router_addr (struct vty *vty, struct te_tlv_header *tlvh)
1117{
1118 struct te_tlv_router_addr *top = (struct te_tlv_router_addr *) tlvh;
1119
1120 if (vty != NULL)
1121 vty_out (vty, " Router-Address: %s%s", inet_ntoa (top->value), VTY_NEWLINE);
1122 else
ajs2a42e282004-12-08 18:43:03 +00001123 zlog_debug (" Router-Address: %s", inet_ntoa (top->value));
paul718e3742002-12-13 20:15:29 +00001124
1125 return TLV_SIZE (tlvh);
1126}
1127
1128static u_int16_t
1129show_vty_link_header (struct vty *vty, struct te_tlv_header *tlvh)
1130{
1131 struct te_tlv_link *top = (struct te_tlv_link *) tlvh;
1132
1133 if (vty != NULL)
1134 vty_out (vty, " Link: %u octets of data%s", ntohs (top->header.length), VTY_NEWLINE);
1135 else
ajs2a42e282004-12-08 18:43:03 +00001136 zlog_debug (" Link: %u octets of data", ntohs (top->header.length));
paul718e3742002-12-13 20:15:29 +00001137
1138 return TLV_HDR_SIZE; /* Here is special, not "TLV_SIZE". */
1139}
1140
1141static u_int16_t
1142show_vty_link_subtlv_link_type (struct vty *vty, struct te_tlv_header *tlvh)
1143{
1144 struct te_link_subtlv_link_type *top;
1145 const char *cp = "Unknown";
1146
1147 top = (struct te_link_subtlv_link_type *) tlvh;
1148 switch (top->link_type.value)
1149 {
1150 case LINK_TYPE_SUBTLV_VALUE_PTP:
1151 cp = "Point-to-point";
1152 break;
1153 case LINK_TYPE_SUBTLV_VALUE_MA:
1154 cp = "Multiaccess";
1155 break;
1156 default:
1157 break;
1158 }
1159
1160 if (vty != NULL)
1161 vty_out (vty, " Link-Type: %s (%u)%s", cp, top->link_type.value, VTY_NEWLINE);
1162 else
ajs2a42e282004-12-08 18:43:03 +00001163 zlog_debug (" Link-Type: %s (%u)", cp, top->link_type.value);
paul718e3742002-12-13 20:15:29 +00001164
1165 return TLV_SIZE (tlvh);
1166}
1167
1168static u_int16_t
1169show_vty_link_subtlv_link_id (struct vty *vty, struct te_tlv_header *tlvh)
1170{
1171 struct te_link_subtlv_link_id *top;
1172
1173 top = (struct te_link_subtlv_link_id *) tlvh;
1174 if (vty != NULL)
1175 vty_out (vty, " Link-ID: %s%s", inet_ntoa (top->value), VTY_NEWLINE);
1176 else
ajs2a42e282004-12-08 18:43:03 +00001177 zlog_debug (" Link-ID: %s", inet_ntoa (top->value));
paul718e3742002-12-13 20:15:29 +00001178
1179 return TLV_SIZE (tlvh);
1180}
1181
1182static u_int16_t
1183show_vty_link_subtlv_lclif_ipaddr (struct vty *vty, struct te_tlv_header *tlvh)
1184{
1185 struct te_link_subtlv_lclif_ipaddr *top;
1186 int i, n;
1187
1188 top = (struct te_link_subtlv_lclif_ipaddr *) tlvh;
1189 n = ntohs (tlvh->length) / sizeof (top->value[0]);
1190
1191 if (vty != NULL)
1192 vty_out (vty, " Local Interface IP Address(es): %d%s", n, VTY_NEWLINE);
1193 else
ajs2a42e282004-12-08 18:43:03 +00001194 zlog_debug (" Local Interface IP Address(es): %d", n);
paul718e3742002-12-13 20:15:29 +00001195
1196 for (i = 0; i < n; i++)
1197 {
1198 if (vty != NULL)
1199 vty_out (vty, " #%d: %s%s", i, inet_ntoa (top->value[i]), VTY_NEWLINE);
1200 else
ajs2a42e282004-12-08 18:43:03 +00001201 zlog_debug (" #%d: %s", i, inet_ntoa (top->value[i]));
paul718e3742002-12-13 20:15:29 +00001202 }
1203 return TLV_SIZE (tlvh);
1204}
1205
1206static u_int16_t
1207show_vty_link_subtlv_rmtif_ipaddr (struct vty *vty, struct te_tlv_header *tlvh)
1208{
1209 struct te_link_subtlv_rmtif_ipaddr *top;
1210 int i, n;
1211
1212 top = (struct te_link_subtlv_rmtif_ipaddr *) tlvh;
1213 n = ntohs (tlvh->length) / sizeof (top->value[0]);
1214 if (vty != NULL)
1215 vty_out (vty, " Remote Interface IP Address(es): %d%s", n, VTY_NEWLINE);
1216 else
ajs2a42e282004-12-08 18:43:03 +00001217 zlog_debug (" Remote Interface IP Address(es): %d", n);
paul718e3742002-12-13 20:15:29 +00001218
1219 for (i = 0; i < n; i++)
1220 {
1221 if (vty != NULL)
1222 vty_out (vty, " #%d: %s%s", i, inet_ntoa (top->value[i]), VTY_NEWLINE);
1223 else
ajs2a42e282004-12-08 18:43:03 +00001224 zlog_debug (" #%d: %s", i, inet_ntoa (top->value[i]));
paul718e3742002-12-13 20:15:29 +00001225 }
1226 return TLV_SIZE (tlvh);
1227}
1228
1229static u_int16_t
1230show_vty_link_subtlv_te_metric (struct vty *vty, struct te_tlv_header *tlvh)
1231{
1232 struct te_link_subtlv_te_metric *top;
1233
1234 top = (struct te_link_subtlv_te_metric *) tlvh;
1235 if (vty != NULL)
1236 vty_out (vty, " Traffic Engineering Metric: %u%s", (u_int32_t) ntohl (top->value), VTY_NEWLINE);
1237 else
ajs2a42e282004-12-08 18:43:03 +00001238 zlog_debug (" Traffic Engineering Metric: %u", (u_int32_t) ntohl (top->value));
paul718e3742002-12-13 20:15:29 +00001239
1240 return TLV_SIZE (tlvh);
1241}
1242
1243static u_int16_t
1244show_vty_link_subtlv_max_bw (struct vty *vty, struct te_tlv_header *tlvh)
1245{
1246 struct te_link_subtlv_max_bw *top;
1247 float fval;
1248
1249 top = (struct te_link_subtlv_max_bw *) tlvh;
Paul Jakma43595012015-05-19 18:50:49 +01001250 fval = ntohf (top->value);
paul718e3742002-12-13 20:15:29 +00001251
1252 if (vty != NULL)
1253 vty_out (vty, " Maximum Bandwidth: %g (Bytes/sec)%s", fval, VTY_NEWLINE);
1254 else
ajs2a42e282004-12-08 18:43:03 +00001255 zlog_debug (" Maximum Bandwidth: %g (Bytes/sec)", fval);
paul718e3742002-12-13 20:15:29 +00001256
1257 return TLV_SIZE (tlvh);
1258}
1259
1260static u_int16_t
1261show_vty_link_subtlv_max_rsv_bw (struct vty *vty, struct te_tlv_header *tlvh)
1262{
1263 struct te_link_subtlv_max_rsv_bw *top;
1264 float fval;
1265
1266 top = (struct te_link_subtlv_max_rsv_bw *) tlvh;
Paul Jakma43595012015-05-19 18:50:49 +01001267 fval = ntohf (top->value);
paul718e3742002-12-13 20:15:29 +00001268
1269 if (vty != NULL)
1270 vty_out (vty, " Maximum Reservable Bandwidth: %g (Bytes/sec)%s", fval, VTY_NEWLINE);
1271 else
ajs2a42e282004-12-08 18:43:03 +00001272 zlog_debug (" Maximum Reservable Bandwidth: %g (Bytes/sec)", fval);
paul718e3742002-12-13 20:15:29 +00001273
1274 return TLV_SIZE (tlvh);
1275}
1276
1277static u_int16_t
1278show_vty_link_subtlv_unrsv_bw (struct vty *vty, struct te_tlv_header *tlvh)
1279{
1280 struct te_link_subtlv_unrsv_bw *top;
1281 float fval;
1282 int i;
1283
1284 top = (struct te_link_subtlv_unrsv_bw *) tlvh;
1285 for (i = 0; i < 8; i++)
1286 {
Paul Jakma43595012015-05-19 18:50:49 +01001287 fval = ntohf (top->value[i]);
paul718e3742002-12-13 20:15:29 +00001288 if (vty != NULL)
1289 vty_out (vty, " Unreserved Bandwidth (pri %d): %g (Bytes/sec)%s", i, fval, VTY_NEWLINE);
1290 else
ajs2a42e282004-12-08 18:43:03 +00001291 zlog_debug (" Unreserved Bandwidth (pri %d): %g (Bytes/sec)", i, fval);
paul718e3742002-12-13 20:15:29 +00001292 }
1293
1294 return TLV_SIZE (tlvh);
1295}
1296
1297static u_int16_t
1298show_vty_link_subtlv_rsc_clsclr (struct vty *vty, struct te_tlv_header *tlvh)
1299{
1300 struct te_link_subtlv_rsc_clsclr *top;
1301
1302 top = (struct te_link_subtlv_rsc_clsclr *) tlvh;
1303 if (vty != NULL)
1304 vty_out (vty, " Resource class/color: 0x%x%s", (u_int32_t) ntohl (top->value), VTY_NEWLINE);
1305 else
ajs2a42e282004-12-08 18:43:03 +00001306 zlog_debug (" Resource Class/Color: 0x%x", (u_int32_t) ntohl (top->value));
paul718e3742002-12-13 20:15:29 +00001307
1308 return TLV_SIZE (tlvh);
1309}
1310
1311static u_int16_t
1312show_vty_unknown_tlv (struct vty *vty, struct te_tlv_header *tlvh)
1313{
1314 if (vty != NULL)
1315 vty_out (vty, " Unknown TLV: [type(0x%x), length(0x%x)]%s", ntohs (tlvh->type), ntohs (tlvh->length), VTY_NEWLINE);
1316 else
ajs2a42e282004-12-08 18:43:03 +00001317 zlog_debug (" Unknown TLV: [type(0x%x), length(0x%x)]", ntohs (tlvh->type), ntohs (tlvh->length));
paul718e3742002-12-13 20:15:29 +00001318
1319 return TLV_SIZE (tlvh);
1320}
1321
1322static u_int16_t
1323ospf_mpls_te_show_link_subtlv (struct vty *vty, struct te_tlv_header *tlvh0,
1324 u_int16_t subtotal, u_int16_t total)
1325{
1326 struct te_tlv_header *tlvh, *next;
1327 u_int16_t sum = subtotal;
1328
1329 for (tlvh = tlvh0; sum < total; tlvh = (next ? next : TLV_HDR_NEXT (tlvh)))
1330 {
1331 next = NULL;
1332 switch (ntohs (tlvh->type))
1333 {
1334 case TE_LINK_SUBTLV_LINK_TYPE:
1335 sum += show_vty_link_subtlv_link_type (vty, tlvh);
1336 break;
1337 case TE_LINK_SUBTLV_LINK_ID:
1338 sum += show_vty_link_subtlv_link_id (vty, tlvh);
1339 break;
1340 case TE_LINK_SUBTLV_LCLIF_IPADDR:
1341 sum += show_vty_link_subtlv_lclif_ipaddr (vty, tlvh);
1342 break;
1343 case TE_LINK_SUBTLV_RMTIF_IPADDR:
1344 sum += show_vty_link_subtlv_rmtif_ipaddr (vty, tlvh);
1345 break;
1346 case TE_LINK_SUBTLV_TE_METRIC:
1347 sum += show_vty_link_subtlv_te_metric (vty, tlvh);
1348 break;
1349 case TE_LINK_SUBTLV_MAX_BW:
1350 sum += show_vty_link_subtlv_max_bw (vty, tlvh);
1351 break;
1352 case TE_LINK_SUBTLV_MAX_RSV_BW:
1353 sum += show_vty_link_subtlv_max_rsv_bw (vty, tlvh);
1354 break;
1355 case TE_LINK_SUBTLV_UNRSV_BW:
1356 sum += show_vty_link_subtlv_unrsv_bw (vty, tlvh);
1357 break;
1358 case TE_LINK_SUBTLV_RSC_CLSCLR:
1359 sum += show_vty_link_subtlv_rsc_clsclr (vty, tlvh);
1360 break;
1361 default:
1362 sum += show_vty_unknown_tlv (vty, tlvh);
1363 break;
1364 }
1365 }
1366 return sum;
1367}
1368
1369static void
1370ospf_mpls_te_show_info (struct vty *vty, struct ospf_lsa *lsa)
1371{
1372 struct lsa_header *lsah = (struct lsa_header *) lsa->data;
1373 struct te_tlv_header *tlvh, *next;
1374 u_int16_t sum, total;
1375 u_int16_t (* subfunc)(struct vty *vty, struct te_tlv_header *tlvh,
1376 u_int16_t subtotal, u_int16_t total) = NULL;
1377
1378 sum = 0;
1379 total = ntohs (lsah->length) - OSPF_LSA_HEADER_SIZE;
1380
1381 for (tlvh = TLV_HDR_TOP (lsah); sum < total;
1382 tlvh = (next ? next : TLV_HDR_NEXT (tlvh)))
1383 {
1384 if (subfunc != NULL)
1385 {
1386 sum = (* subfunc)(vty, tlvh, sum, total);
1387 next = (struct te_tlv_header *)((char *) tlvh + sum);
1388 subfunc = NULL;
1389 continue;
1390 }
1391
1392 next = NULL;
1393 switch (ntohs (tlvh->type))
1394 {
1395 case TE_TLV_ROUTER_ADDR:
1396 sum += show_vty_router_addr (vty, tlvh);
1397 break;
1398 case TE_TLV_LINK:
1399 sum += show_vty_link_header (vty, tlvh);
1400 subfunc = ospf_mpls_te_show_link_subtlv;
1401 next = tlvh + 1;
1402 break;
1403 default:
1404 sum += show_vty_unknown_tlv (vty, tlvh);
1405 break;
1406 }
1407 }
1408 return;
1409}
1410
1411static void
1412ospf_mpls_te_config_write_router (struct vty *vty)
1413{
1414 if (OspfMplsTE.status == enabled)
1415 {
1416 vty_out (vty, " mpls-te%s", VTY_NEWLINE);
1417 vty_out (vty, " mpls-te router-address %s%s",
1418 inet_ntoa (OspfMplsTE.router_addr.value), VTY_NEWLINE);
1419 }
1420 return;
1421}
1422
1423static void
1424ospf_mpls_te_config_write_if (struct vty *vty, struct interface *ifp)
1425{
1426 struct mpls_te_link *lp;
1427
1428 if ((OspfMplsTE.status == enabled)
1429 && (! if_is_loopback (ifp) && if_is_up (ifp) && ospf_oi_count (ifp) > 0)
1430 && ((lp = lookup_linkparams_by_ifp (ifp)) != NULL))
1431 {
1432 float fval;
1433 int i;
1434
1435 vty_out (vty, " mpls-te link metric %u%s",
1436 (u_int32_t) ntohl (lp->te_metric.value), VTY_NEWLINE);
1437
Paul Jakma43595012015-05-19 18:50:49 +01001438 fval = ntohf (lp->max_bw.value);
paul718e3742002-12-13 20:15:29 +00001439 if (fval >= MPLS_TE_MINIMUM_BANDWIDTH)
1440 vty_out (vty, " mpls-te link max-bw %g%s", fval, VTY_NEWLINE);
1441
Paul Jakma43595012015-05-19 18:50:49 +01001442 fval = ntohf (lp->max_rsv_bw.value);
paul718e3742002-12-13 20:15:29 +00001443 if (fval >= MPLS_TE_MINIMUM_BANDWIDTH)
1444 vty_out (vty, " mpls-te link max-rsv-bw %g%s", fval, VTY_NEWLINE);
1445
1446 for (i = 0; i < 8; i++)
1447 {
Paul Jakma43595012015-05-19 18:50:49 +01001448 fval = ntohf (lp->unrsv_bw.value[i]);
paul718e3742002-12-13 20:15:29 +00001449 if (fval >= MPLS_TE_MINIMUM_BANDWIDTH)
1450 vty_out (vty, " mpls-te link unrsv-bw %d %g%s",
1451 i, fval, VTY_NEWLINE);
1452 }
1453
1454 vty_out (vty, " mpls-te link rsc-clsclr 0x%x%s",
1455 (u_int32_t) ntohl (lp->rsc_clsclr.value), VTY_NEWLINE);
1456 }
1457 return;
1458}
1459
1460/*------------------------------------------------------------------------*
1461 * Followings are vty command functions.
1462 *------------------------------------------------------------------------*/
1463
1464DEFUN (mpls_te,
1465 mpls_te_cmd,
1466 "mpls-te",
1467 "Configure MPLS-TE parameters\n"
1468 "Enable the MPLS-TE functionality\n")
1469{
paul1eb8ef22005-04-07 07:30:20 +00001470 struct listnode *node, *nnode;
paul718e3742002-12-13 20:15:29 +00001471 struct mpls_te_link *lp;
1472
1473 if (OspfMplsTE.status == enabled)
1474 return CMD_SUCCESS;
1475
1476 if (IS_DEBUG_OSPF_EVENT)
ajs2a42e282004-12-08 18:43:03 +00001477 zlog_debug ("MPLS-TE: OFF -> ON");
paul718e3742002-12-13 20:15:29 +00001478
1479 OspfMplsTE.status = enabled;
1480
1481 /*
1482 * Following code is intended to handle two cases;
1483 *
1484 * 1) MPLS-TE was disabled at startup time, but now become enabled.
1485 * 2) MPLS-TE was once enabled then disabled, and now enabled again.
1486 */
paul1eb8ef22005-04-07 07:30:20 +00001487 for (ALL_LIST_ELEMENTS (OspfMplsTE.iflist, node, nnode, lp))
1488 initialize_linkparams (lp);
paul718e3742002-12-13 20:15:29 +00001489
1490 ospf_mpls_te_foreach_area (ospf_mpls_te_lsa_schedule, REORIGINATE_PER_AREA);
1491
1492 return CMD_SUCCESS;
1493}
1494
1495ALIAS (mpls_te,
1496 mpls_te_on_cmd,
1497 "mpls-te on",
1498 "Configure MPLS-TE parameters\n"
1499 "Enable the MPLS-TE functionality\n")
1500
1501DEFUN (no_mpls_te,
1502 no_mpls_te_cmd,
1503 "no mpls-te",
1504 NO_STR
1505 "Configure MPLS-TE parameters\n"
1506 "Disable the MPLS-TE functionality\n")
1507{
paul1eb8ef22005-04-07 07:30:20 +00001508 struct listnode *node, *nnode;
paul718e3742002-12-13 20:15:29 +00001509 struct mpls_te_link *lp;
1510
1511 if (OspfMplsTE.status == disabled)
1512 return CMD_SUCCESS;
1513
1514 if (IS_DEBUG_OSPF_EVENT)
ajs2a42e282004-12-08 18:43:03 +00001515 zlog_debug ("MPLS-TE: ON -> OFF");
paul718e3742002-12-13 20:15:29 +00001516
1517 OspfMplsTE.status = disabled;
1518
paul1eb8ef22005-04-07 07:30:20 +00001519 for (ALL_LIST_ELEMENTS (OspfMplsTE.iflist, node, nnode, lp))
1520 if (lp->area != NULL)
1521 if (lp->flags & LPFLG_LSA_ENGAGED)
1522 ospf_mpls_te_lsa_schedule (lp, FLUSH_THIS_LSA);
paul718e3742002-12-13 20:15:29 +00001523
1524 return CMD_SUCCESS;
1525}
1526
1527DEFUN (mpls_te_router_addr,
1528 mpls_te_router_addr_cmd,
1529 "mpls-te router-address A.B.C.D",
1530 "MPLS-TE specific commands\n"
1531 "Stable IP address of the advertising router\n"
1532 "MPLS-TE router address in IPv4 address format\n")
1533{
1534 struct te_tlv_router_addr *ra = &OspfMplsTE.router_addr;
1535 struct in_addr value;
1536
1537 if (! inet_aton (argv[0], &value))
1538 {
1539 vty_out (vty, "Please specify Router-Addr by A.B.C.D%s", VTY_NEWLINE);
1540 return CMD_WARNING;
1541 }
1542
1543 if (ntohs (ra->header.type) == 0
paul87d6f872004-09-24 08:01:38 +00001544 || ntohl (ra->value.s_addr) != ntohl (value.s_addr))
paul718e3742002-12-13 20:15:29 +00001545 {
paul1eb8ef22005-04-07 07:30:20 +00001546 struct listnode *node, *nnode;
paul718e3742002-12-13 20:15:29 +00001547 struct mpls_te_link *lp;
1548 int need_to_reoriginate = 0;
1549
1550 set_mpls_te_router_addr (value);
1551
1552 if (OspfMplsTE.status == disabled)
1553 goto out;
1554
paul1eb8ef22005-04-07 07:30:20 +00001555 for (ALL_LIST_ELEMENTS (OspfMplsTE.iflist, node, nnode, lp))
paul718e3742002-12-13 20:15:29 +00001556 {
paul718e3742002-12-13 20:15:29 +00001557 if (lp->area == NULL)
1558 continue;
1559
1560 if ((lp->flags & LPFLG_LSA_ENGAGED) == 0)
1561 {
1562 need_to_reoriginate = 1;
1563 break;
1564 }
1565 }
paul1eb8ef22005-04-07 07:30:20 +00001566
1567 for (ALL_LIST_ELEMENTS (OspfMplsTE.iflist, node, nnode, lp))
paul718e3742002-12-13 20:15:29 +00001568 {
paul718e3742002-12-13 20:15:29 +00001569 if (lp->area == NULL)
1570 continue;
1571
1572 if (need_to_reoriginate)
1573 lp->flags |= LPFLG_LSA_FORCED_REFRESH;
1574 else
1575 ospf_mpls_te_lsa_schedule (lp, REFRESH_THIS_LSA);
1576 }
1577
1578 if (need_to_reoriginate)
1579 ospf_mpls_te_foreach_area (
1580 ospf_mpls_te_lsa_schedule, REORIGINATE_PER_AREA);
1581 }
1582out:
1583 return CMD_SUCCESS;
1584}
1585
1586DEFUN (mpls_te_link_metric,
1587 mpls_te_link_metric_cmd,
1588 "mpls-te link metric <0-4294967295>",
1589 "MPLS-TE specific commands\n"
1590 "Configure MPLS-TE link parameters\n"
1591 "Link metric for MPLS-TE purpose\n"
1592 "Metric\n")
1593{
1594 struct interface *ifp = (struct interface *) vty->index;
1595 struct mpls_te_link *lp;
1596 u_int32_t value;
1597
1598 if ((lp = lookup_linkparams_by_ifp (ifp)) == NULL)
1599 {
1600 vty_out (vty, "mpls_te_link_metric: Something wrong!%s", VTY_NEWLINE);
1601 return CMD_WARNING;
1602 }
1603
1604 value = strtoul (argv[0], NULL, 10);
1605
1606 if (ntohs (lp->te_metric.header.type) == 0
1607 || ntohl (lp->te_metric.value) != value)
1608 {
1609 set_linkparams_te_metric (lp, value);
1610
1611 if (OspfMplsTE.status == enabled)
1612 if (lp->area != NULL)
1613 {
1614 if (lp->flags & LPFLG_LSA_ENGAGED)
1615 ospf_mpls_te_lsa_schedule (lp, REFRESH_THIS_LSA);
1616 else
1617 ospf_mpls_te_lsa_schedule (lp, REORIGINATE_PER_AREA);
1618 }
1619 }
1620 return CMD_SUCCESS;
1621}
1622
1623DEFUN (mpls_te_link_maxbw,
1624 mpls_te_link_maxbw_cmd,
1625 "mpls-te link max-bw BANDWIDTH",
1626 "MPLS-TE specific commands\n"
1627 "Configure MPLS-TE link parameters\n"
1628 "Maximum bandwidth that can be used\n"
1629 "Bytes/second (IEEE floating point format)\n")
1630{
1631 struct interface *ifp = (struct interface *) vty->index;
1632 struct mpls_te_link *lp;
1633 float f1, f2;
1634
1635 if ((lp = lookup_linkparams_by_ifp (ifp)) == NULL)
1636 {
1637 vty_out (vty, "mpls_te_link_maxbw: Something wrong!%s", VTY_NEWLINE);
1638 return CMD_WARNING;
1639 }
1640
Paul Jakma43595012015-05-19 18:50:49 +01001641 f1 = ntohf (lp->max_bw.value);
paul718e3742002-12-13 20:15:29 +00001642 if (sscanf (argv[0], "%g", &f2) != 1)
1643 {
ajs6099b3b2004-11-20 02:06:59 +00001644 vty_out (vty, "mpls_te_link_maxbw: fscanf: %s%s", safe_strerror (errno), VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00001645 return CMD_WARNING;
1646 }
1647
1648 if (ntohs (lp->max_bw.header.type) == 0
1649 || f1 != f2)
1650 {
Paul Jakma43595012015-05-19 18:50:49 +01001651 set_linkparams_max_bw (lp, f2);
paul718e3742002-12-13 20:15:29 +00001652
1653 if (OspfMplsTE.status == enabled)
1654 if (lp->area != NULL)
1655 {
1656 if (lp->flags & LPFLG_LSA_ENGAGED)
1657 ospf_mpls_te_lsa_schedule (lp, REFRESH_THIS_LSA);
1658 else
1659 ospf_mpls_te_lsa_schedule (lp, REORIGINATE_PER_AREA);
1660 }
1661 }
1662 return CMD_SUCCESS;
1663}
1664
1665DEFUN (mpls_te_link_max_rsv_bw,
1666 mpls_te_link_max_rsv_bw_cmd,
1667 "mpls-te link max-rsv-bw BANDWIDTH",
1668 "MPLS-TE specific commands\n"
1669 "Configure MPLS-TE link parameters\n"
1670 "Maximum bandwidth that may be reserved\n"
1671 "Bytes/second (IEEE floating point format)\n")
1672{
1673 struct interface *ifp = (struct interface *) vty->index;
1674 struct mpls_te_link *lp;
1675 float f1, f2;
1676
1677 if ((lp = lookup_linkparams_by_ifp (ifp)) == NULL)
1678 {
1679 vty_out (vty, "mpls_te_link_max_rsv_bw: Something wrong!%s", VTY_NEWLINE);
1680 return CMD_WARNING;
1681 }
1682
Paul Jakma43595012015-05-19 18:50:49 +01001683 f1 = ntohf (lp->max_rsv_bw.value);
paul718e3742002-12-13 20:15:29 +00001684 if (sscanf (argv[0], "%g", &f2) != 1)
1685 {
ajs6099b3b2004-11-20 02:06:59 +00001686 vty_out (vty, "mpls_te_link_max_rsv_bw: fscanf: %s%s", safe_strerror (errno), VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00001687 return CMD_WARNING;
1688 }
1689
1690 if (ntohs (lp->max_rsv_bw.header.type) == 0
1691 || f1 != f2)
1692 {
Paul Jakma43595012015-05-19 18:50:49 +01001693 set_linkparams_max_rsv_bw (lp, f2);
paul718e3742002-12-13 20:15:29 +00001694
1695 if (OspfMplsTE.status == enabled)
1696 if (lp->area != NULL)
1697 {
1698 if (lp->flags & LPFLG_LSA_ENGAGED)
1699 ospf_mpls_te_lsa_schedule (lp, REFRESH_THIS_LSA);
1700 else
1701 ospf_mpls_te_lsa_schedule (lp, REORIGINATE_PER_AREA);
1702 }
1703 }
1704 return CMD_SUCCESS;
1705}
1706
1707DEFUN (mpls_te_link_unrsv_bw,
1708 mpls_te_link_unrsv_bw_cmd,
1709 "mpls-te link unrsv-bw <0-7> BANDWIDTH",
1710 "MPLS-TE specific commands\n"
1711 "Configure MPLS-TE link parameters\n"
1712 "Unreserved bandwidth at each priority level\n"
1713 "Priority\n"
1714 "Bytes/second (IEEE floating point format)\n")
1715{
1716 struct interface *ifp = (struct interface *) vty->index;
1717 struct mpls_te_link *lp;
1718 int priority;
1719 float f1, f2;
1720
1721 if ((lp = lookup_linkparams_by_ifp (ifp)) == NULL)
1722 {
1723 vty_out (vty, "mpls_te_link_unrsv_bw: Something wrong!%s", VTY_NEWLINE);
1724 return CMD_WARNING;
1725 }
1726
1727 /* We don't have to consider about range check here. */
1728 if (sscanf (argv[0], "%d", &priority) != 1)
1729 {
ajs6099b3b2004-11-20 02:06:59 +00001730 vty_out (vty, "mpls_te_link_unrsv_bw: fscanf: %s%s", safe_strerror (errno), VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00001731 return CMD_WARNING;
1732 }
1733
Paul Jakma43595012015-05-19 18:50:49 +01001734 f1 = ntohf (lp->unrsv_bw.value [priority]);
paul718e3742002-12-13 20:15:29 +00001735 if (sscanf (argv[1], "%g", &f2) != 1)
1736 {
ajs6099b3b2004-11-20 02:06:59 +00001737 vty_out (vty, "mpls_te_link_unrsv_bw: fscanf: %s%s", safe_strerror (errno), VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00001738 return CMD_WARNING;
1739 }
1740
1741 if (ntohs (lp->unrsv_bw.header.type) == 0
1742 || f1 != f2)
1743 {
Paul Jakma43595012015-05-19 18:50:49 +01001744 set_linkparams_unrsv_bw (lp, priority, f2);
paul718e3742002-12-13 20:15:29 +00001745
1746 if (OspfMplsTE.status == enabled)
1747 if (lp->area != NULL)
1748 {
1749 if (lp->flags & LPFLG_LSA_ENGAGED)
1750 ospf_mpls_te_lsa_schedule (lp, REFRESH_THIS_LSA);
1751 else
1752 ospf_mpls_te_lsa_schedule (lp, REORIGINATE_PER_AREA);
1753 }
1754 }
1755 return CMD_SUCCESS;
1756}
1757
1758DEFUN (mpls_te_link_rsc_clsclr,
1759 mpls_te_link_rsc_clsclr_cmd,
1760 "mpls-te link rsc-clsclr BITPATTERN",
1761 "MPLS-TE specific commands\n"
1762 "Configure MPLS-TE link parameters\n"
1763 "Administrative group membership\n"
1764 "32-bit Hexadecimal value (ex. 0xa1)\n")
1765{
1766 struct interface *ifp = (struct interface *) vty->index;
1767 struct mpls_te_link *lp;
1768 unsigned long value;
1769
1770 if ((lp = lookup_linkparams_by_ifp (ifp)) == NULL)
1771 {
1772 vty_out (vty, "mpls_te_link_rsc_clsclr: Something wrong!%s", VTY_NEWLINE);
1773 return CMD_WARNING;
1774 }
1775
1776 if (sscanf (argv[0], "0x%lx", &value) != 1)
1777 {
ajs6099b3b2004-11-20 02:06:59 +00001778 vty_out (vty, "mpls_te_link_rsc_clsclr: fscanf: %s%s", safe_strerror (errno), VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00001779 return CMD_WARNING;
1780 }
1781
1782 if (ntohs (lp->rsc_clsclr.header.type) == 0
1783 || ntohl (lp->rsc_clsclr.value) != value)
1784 {
1785 set_linkparams_rsc_clsclr (lp, value);
1786
1787 if (OspfMplsTE.status == enabled)
1788 if (lp->area != NULL)
1789 {
1790 if (lp->flags & LPFLG_LSA_ENGAGED)
1791 ospf_mpls_te_lsa_schedule (lp, REFRESH_THIS_LSA);
1792 else
1793 ospf_mpls_te_lsa_schedule (lp, REORIGINATE_PER_AREA);
1794 }
1795 }
1796 return CMD_SUCCESS;
1797}
1798
1799DEFUN (show_mpls_te_router,
1800 show_mpls_te_router_cmd,
1801 "show mpls-te router",
1802 SHOW_STR
1803 "MPLS-TE information\n"
1804 "Router information\n")
1805{
1806 if (OspfMplsTE.status == enabled)
1807 {
1808 vty_out (vty, "--- MPLS-TE router parameters ---%s",
1809 VTY_NEWLINE);
1810
1811 if (ntohs (OspfMplsTE.router_addr.header.type) != 0)
1812 show_vty_router_addr (vty, &OspfMplsTE.router_addr.header);
1813 else if (vty != NULL)
1814 vty_out (vty, " N/A%s", VTY_NEWLINE);
1815 }
1816 return CMD_SUCCESS;
1817}
1818
1819static void
1820show_mpls_te_link_sub (struct vty *vty, struct interface *ifp)
1821{
1822 struct mpls_te_link *lp;
1823 struct te_tlv_header *tlvh;
1824
1825 if ((OspfMplsTE.status == enabled)
1826 && (! if_is_loopback (ifp) && if_is_up (ifp) && ospf_oi_count (ifp) > 0)
1827 && ((lp = lookup_linkparams_by_ifp (ifp)) != NULL))
1828 {
1829 vty_out (vty, "-- MPLS-TE link parameters for %s --%s",
1830 ifp->name, VTY_NEWLINE);
1831
1832 show_vty_link_subtlv_link_type (vty, &lp->link_type.header);
1833 show_vty_link_subtlv_link_id (vty, &lp->link_id.header);
1834
1835 if ((tlvh = (struct te_tlv_header *) lp->lclif_ipaddr) != NULL)
1836 show_vty_link_subtlv_lclif_ipaddr (vty, tlvh);
1837 if ((tlvh = (struct te_tlv_header *) lp->rmtif_ipaddr) != NULL)
1838 show_vty_link_subtlv_rmtif_ipaddr (vty, tlvh);
1839
1840 show_vty_link_subtlv_te_metric (vty, &lp->te_metric.header);
1841
1842 show_vty_link_subtlv_max_bw (vty, &lp->max_bw.header);
1843 show_vty_link_subtlv_max_rsv_bw (vty, &lp->max_rsv_bw.header);
1844 show_vty_link_subtlv_unrsv_bw (vty, &lp->unrsv_bw.header);
1845 show_vty_link_subtlv_rsc_clsclr (vty, &lp->rsc_clsclr.header);
1846 }
1847 else
1848 {
1849 vty_out (vty, " %s: MPLS-TE is disabled on this interface%s",
1850 ifp->name, VTY_NEWLINE);
1851 }
1852
1853 return;
1854}
1855
1856DEFUN (show_mpls_te_link,
1857 show_mpls_te_link_cmd,
1858 "show mpls-te interface [INTERFACE]",
1859 SHOW_STR
1860 "MPLS-TE information\n"
1861 "Interface information\n"
1862 "Interface name\n")
1863{
1864 struct interface *ifp;
paul1eb8ef22005-04-07 07:30:20 +00001865 struct listnode *node, *nnode;
paul718e3742002-12-13 20:15:29 +00001866
1867 /* Show All Interfaces. */
1868 if (argc == 0)
hassoeb1ce602004-10-08 08:17:22 +00001869 {
paul1eb8ef22005-04-07 07:30:20 +00001870 for (ALL_LIST_ELEMENTS (iflist, node, nnode, ifp))
1871 show_mpls_te_link_sub (vty, ifp);
hassoeb1ce602004-10-08 08:17:22 +00001872 }
paul718e3742002-12-13 20:15:29 +00001873 /* Interface name is specified. */
1874 else
1875 {
1876 if ((ifp = if_lookup_by_name (argv[0])) == NULL)
1877 vty_out (vty, "No such interface name%s", VTY_NEWLINE);
1878 else
1879 show_mpls_te_link_sub (vty, ifp);
1880 }
1881
1882 return CMD_SUCCESS;
1883}
1884
1885static void
1886ospf_mpls_te_register_vty (void)
1887{
1888 install_element (VIEW_NODE, &show_mpls_te_router_cmd);
1889 install_element (VIEW_NODE, &show_mpls_te_link_cmd);
paul718e3742002-12-13 20:15:29 +00001890
1891 install_element (OSPF_NODE, &mpls_te_cmd);
1892 install_element (OSPF_NODE, &no_mpls_te_cmd);
1893 install_element (OSPF_NODE, &mpls_te_on_cmd);
1894 install_element (OSPF_NODE, &mpls_te_router_addr_cmd);
1895
1896 install_element (INTERFACE_NODE, &mpls_te_link_metric_cmd);
1897 install_element (INTERFACE_NODE, &mpls_te_link_maxbw_cmd);
1898 install_element (INTERFACE_NODE, &mpls_te_link_max_rsv_bw_cmd);
1899 install_element (INTERFACE_NODE, &mpls_te_link_unrsv_bw_cmd);
1900 install_element (INTERFACE_NODE, &mpls_te_link_rsc_clsclr_cmd);
1901
1902 return;
1903}