]> git.proxmox.com Git - mirror_frr.git/blob - isisd/isis_te.c
zebra: Remove MM seq from evpn rmac json output
[mirror_frr.git] / isisd / isis_te.c
1 /*
2 * IS-IS Rout(e)ing protocol - isis_te.c
3 *
4 * This is an implementation of RFC5305 & RFC 7810
5 *
6 * Author: Olivier Dugeon <olivier.dugeon@orange.com>
7 *
8 * Copyright (C) 2014 - 2019 Orange Labs http://www.orange.com
9 *
10 * This file is part of GNU Zebra.
11 *
12 * GNU Zebra is free software; you can redistribute it and/or modify it
13 * under the terms of the GNU General Public License as published by the
14 * Free Software Foundation; either version 2, or (at your option) any
15 * later version.
16 *
17 * GNU Zebra is distributed in the hope that it will be useful, but
18 * WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 * General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License along
23 * with this program; see the file COPYING; if not, write to the Free Software
24 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25 */
26
27 #include <zebra.h>
28 #include <math.h>
29
30 #include "linklist.h"
31 #include "thread.h"
32 #include "vty.h"
33 #include "stream.h"
34 #include "memory.h"
35 #include "log.h"
36 #include "prefix.h"
37 #include "command.h"
38 #include "hash.h"
39 #include "if.h"
40 #include "vrf.h"
41 #include "checksum.h"
42 #include "md5.h"
43 #include "sockunion.h"
44 #include "network.h"
45 #include "sbuf.h"
46
47 #include "isisd/isis_constants.h"
48 #include "isisd/isis_common.h"
49 #include "isisd/isis_flags.h"
50 #include "isisd/isis_circuit.h"
51 #include "isisd/isis_adjacency.h"
52 #include "isisd/isisd.h"
53 #include "isisd/isis_lsp.h"
54 #include "isisd/isis_pdu.h"
55 #include "isisd/isis_dynhn.h"
56 #include "isisd/isis_misc.h"
57 #include "isisd/isis_csm.h"
58 #include "isisd/isis_adjacency.h"
59 #include "isisd/isis_spf.h"
60 #include "isisd/isis_te.h"
61 #include "isisd/isis_zebra.h"
62
63 /*------------------------------------------------------------------------*
64 * Followings are control functions for MPLS-TE parameters management.
65 *------------------------------------------------------------------------*/
66
67 /* Main initialization / update function of the MPLS TE Circuit context */
68 /* Call when interface TE Link parameters are modified */
69 void isis_link_params_update(struct isis_circuit *circuit,
70 struct interface *ifp)
71 {
72 int i;
73 struct prefix_ipv4 *addr;
74 struct prefix_ipv6 *addr6;
75 struct isis_ext_subtlvs *ext;
76
77 /* Check if TE is enable or not */
78 if (!circuit->area || !IS_MPLS_TE(circuit->area->mta))
79 return;
80
81 /* Sanity Check */
82 if ((ifp == NULL) || (circuit->state != C_STATE_UP))
83 return;
84
85 zlog_debug("TE(%s): Update circuit parameters for interface %s",
86 circuit->area->area_tag, ifp->name);
87
88 /* Check if MPLS TE Circuit context has not been already created */
89 if (circuit->ext == NULL) {
90 circuit->ext = isis_alloc_ext_subtlvs();
91 zlog_debug(" |- Allocated new Ext-subTLVs for interface %s",
92 ifp->name);
93 }
94
95 ext = circuit->ext;
96
97 /* Fulfill Extended subTLVs from interface link parameters */
98 if (HAS_LINK_PARAMS(ifp)) {
99 /* STD_TE metrics */
100 if (IS_PARAM_SET(ifp->link_params, LP_ADM_GRP)) {
101 ext->adm_group = ifp->link_params->admin_grp;
102 SET_SUBTLV(ext, EXT_ADM_GRP);
103 } else
104 UNSET_SUBTLV(ext, EXT_ADM_GRP);
105
106 /* If known, register local IPv4 addr from ip_addr list */
107 if (circuit->ip_addrs != NULL
108 && listcount(circuit->ip_addrs) != 0) {
109 addr = (struct prefix_ipv4 *)listgetdata(
110 (struct listnode *)listhead(circuit->ip_addrs));
111 IPV4_ADDR_COPY(&ext->local_addr, &addr->prefix);
112 SET_SUBTLV(ext, EXT_LOCAL_ADDR);
113 } else
114 UNSET_SUBTLV(ext, EXT_LOCAL_ADDR);
115
116 /* Same for Remote IPv4 address */
117 if (circuit->circ_type == CIRCUIT_T_P2P) {
118 struct isis_adjacency *adj = circuit->u.p2p.neighbor;
119
120 if (adj && adj->adj_state == ISIS_ADJ_UP
121 && adj->ipv4_address_count) {
122 IPV4_ADDR_COPY(&ext->neigh_addr,
123 &adj->ipv4_addresses[0]);
124 SET_SUBTLV(ext, EXT_NEIGH_ADDR);
125 }
126 } else
127 UNSET_SUBTLV(ext, EXT_NEIGH_ADDR);
128
129 /* If known, register local IPv6 addr from ip_addr list */
130 if (circuit->ipv6_non_link != NULL
131 && listcount(circuit->ipv6_non_link) != 0) {
132 addr6 = (struct prefix_ipv6 *)listgetdata(
133 (struct listnode *)listhead(
134 circuit->ipv6_non_link));
135 IPV6_ADDR_COPY(&ext->local_addr6, &addr6->prefix);
136 SET_SUBTLV(ext, EXT_LOCAL_ADDR6);
137 } else
138 UNSET_SUBTLV(ext, EXT_LOCAL_ADDR6);
139
140 /* Same for Remote IPv6 address */
141 if (circuit->circ_type == CIRCUIT_T_P2P) {
142 struct isis_adjacency *adj = circuit->u.p2p.neighbor;
143
144 if (adj && adj->adj_state == ISIS_ADJ_UP
145 && adj->ipv6_address_count) {
146 IPV6_ADDR_COPY(&ext->neigh_addr6,
147 &adj->ipv6_addresses[0]);
148 SET_SUBTLV(ext, EXT_NEIGH_ADDR6);
149 }
150 } else
151 UNSET_SUBTLV(ext, EXT_NEIGH_ADDR6);
152
153 if (IS_PARAM_SET(ifp->link_params, LP_MAX_BW)) {
154 ext->max_bw = ifp->link_params->max_bw;
155 SET_SUBTLV(ext, EXT_MAX_BW);
156 } else
157 UNSET_SUBTLV(ext, EXT_MAX_BW);
158
159 if (IS_PARAM_SET(ifp->link_params, LP_MAX_RSV_BW)) {
160 ext->max_rsv_bw = ifp->link_params->max_rsv_bw;
161 SET_SUBTLV(ext, EXT_MAX_RSV_BW);
162 } else
163 UNSET_SUBTLV(ext, EXT_MAX_RSV_BW);
164
165 if (IS_PARAM_SET(ifp->link_params, LP_UNRSV_BW)) {
166 for (i = 0; i < MAX_CLASS_TYPE; i++)
167 ext->unrsv_bw[i] =
168 ifp->link_params->unrsv_bw[i];
169 SET_SUBTLV(ext, EXT_UNRSV_BW);
170 } else
171 UNSET_SUBTLV(ext, EXT_UNRSV_BW);
172
173 if (IS_PARAM_SET(ifp->link_params, LP_TE_METRIC)) {
174 ext->te_metric = ifp->link_params->te_metric;
175 SET_SUBTLV(ext, EXT_TE_METRIC);
176 } else
177 UNSET_SUBTLV(ext, EXT_TE_METRIC);
178
179 /* TE metric extensions */
180 if (IS_PARAM_SET(ifp->link_params, LP_DELAY)) {
181 ext->delay = ifp->link_params->av_delay;
182 SET_SUBTLV(ext, EXT_DELAY);
183 } else
184 UNSET_SUBTLV(ext, EXT_DELAY);
185
186 if (IS_PARAM_SET(ifp->link_params, LP_MM_DELAY)) {
187 ext->min_delay = ifp->link_params->min_delay;
188 ext->max_delay = ifp->link_params->max_delay;
189 SET_SUBTLV(ext, EXT_MM_DELAY);
190 } else
191 UNSET_SUBTLV(ext, EXT_MM_DELAY);
192
193 if (IS_PARAM_SET(ifp->link_params, LP_DELAY_VAR)) {
194 ext->delay_var = ifp->link_params->delay_var;
195 SET_SUBTLV(ext, EXT_DELAY_VAR);
196 } else
197 UNSET_SUBTLV(ext, EXT_DELAY_VAR);
198
199 if (IS_PARAM_SET(ifp->link_params, LP_PKT_LOSS)) {
200 ext->pkt_loss = ifp->link_params->pkt_loss;
201 SET_SUBTLV(ext, EXT_PKT_LOSS);
202 } else
203 UNSET_SUBTLV(ext, EXT_PKT_LOSS);
204
205 if (IS_PARAM_SET(ifp->link_params, LP_RES_BW)) {
206 ext->res_bw = ifp->link_params->res_bw;
207 SET_SUBTLV(ext, EXT_RES_BW);
208 } else
209 UNSET_SUBTLV(ext, EXT_RES_BW);
210
211 if (IS_PARAM_SET(ifp->link_params, LP_AVA_BW)) {
212 ext->ava_bw = ifp->link_params->ava_bw;
213 SET_SUBTLV(ext, EXT_AVA_BW);
214 } else
215 UNSET_SUBTLV(ext, EXT_AVA_BW);
216
217 if (IS_PARAM_SET(ifp->link_params, LP_USE_BW)) {
218 ext->use_bw = ifp->link_params->use_bw;
219 SET_SUBTLV(ext, EXT_USE_BW);
220 } else
221 UNSET_SUBTLV(ext, EXT_USE_BW);
222
223 /* INTER_AS */
224 if (IS_PARAM_SET(ifp->link_params, LP_RMT_AS)) {
225 ext->remote_as = ifp->link_params->rmt_as;
226 ext->remote_ip = ifp->link_params->rmt_ip;
227 SET_SUBTLV(ext, EXT_RMT_AS);
228 SET_SUBTLV(ext, EXT_RMT_IP);
229 } else {
230 /* reset inter-as TE params */
231 UNSET_SUBTLV(ext, EXT_RMT_AS);
232 UNSET_SUBTLV(ext, EXT_RMT_IP);
233 }
234 zlog_debug(" |- New MPLS-TE link parameters status 0x%x",
235 ext->status);
236 } else {
237 zlog_debug(" |- Reset Extended subTLVs status 0x%x",
238 ext->status);
239 /* Reset TE subTLVs keeping SR one's */
240 if (IS_SUBTLV(ext, EXT_ADJ_SID))
241 ext->status = EXT_ADJ_SID;
242 else if (IS_SUBTLV(ext, EXT_LAN_ADJ_SID))
243 ext->status = EXT_LAN_ADJ_SID;
244 else
245 ext->status = 0;
246 }
247
248 return;
249 }
250
251 static int isis_link_update_adj_hook(struct isis_adjacency *adj)
252 {
253
254 struct isis_circuit *circuit = adj->circuit;
255
256 /* Update MPLS TE Remote IP address parameter if possible */
257 if (!IS_MPLS_TE(circuit->area->mta) || !IS_EXT_TE(circuit->ext))
258 return 0;
259
260 /* IPv4 first */
261 if (adj->ipv4_address_count > 0) {
262 IPV4_ADDR_COPY(&circuit->ext->neigh_addr,
263 &adj->ipv4_addresses[0]);
264 SET_SUBTLV(circuit->ext, EXT_NEIGH_ADDR);
265 }
266
267 /* and IPv6 */
268 if (adj->ipv6_address_count > 0) {
269 IPV6_ADDR_COPY(&circuit->ext->neigh_addr6,
270 &adj->ipv6_addresses[0]);
271 SET_SUBTLV(circuit->ext, EXT_NEIGH_ADDR6);
272 }
273
274 return 0;
275 }
276
277 int isis_mpls_te_update(struct interface *ifp)
278 {
279 struct isis_circuit *circuit;
280 uint8_t rc = 1;
281
282 /* Sanity Check */
283 if (ifp == NULL)
284 return rc;
285
286 /* Get circuit context from interface */
287 circuit = circuit_scan_by_ifp(ifp);
288 if (circuit == NULL)
289 return rc;
290
291 /* Update TE TLVs ... */
292 isis_link_params_update(circuit, ifp);
293
294 /* ... and LSP */
295 if (circuit->area && IS_MPLS_TE(circuit->area->mta))
296 lsp_regenerate_schedule(circuit->area, circuit->is_type, 0);
297
298 rc = 0;
299 return rc;
300 }
301
302 /* Followings are vty command functions */
303 #ifndef FABRICD
304
305 DEFUN(show_isis_mpls_te_router,
306 show_isis_mpls_te_router_cmd,
307 "show " PROTO_NAME " [vrf <NAME|all>] mpls-te router",
308 SHOW_STR
309 PROTO_HELP
310 VRF_CMD_HELP_STR "All VRFs\n"
311 MPLS_TE_STR "Router information\n")
312 {
313
314 struct listnode *anode, *inode;
315 struct isis_area *area;
316 struct isis *isis = NULL;
317 const char *vrf_name = VRF_DEFAULT_NAME;
318 bool all_vrf = false;
319 int idx_vrf = 0;
320
321 if (!im) {
322 vty_out(vty, "IS-IS Routing Process not enabled\n");
323 return CMD_SUCCESS;
324 }
325 ISIS_FIND_VRF_ARGS(argv, argc, idx_vrf, vrf_name, all_vrf);
326 if (vrf_name) {
327 if (all_vrf) {
328 for (ALL_LIST_ELEMENTS_RO(im->isis, inode, isis)) {
329 for (ALL_LIST_ELEMENTS_RO(isis->area_list,
330 anode, area)) {
331 if (!IS_MPLS_TE(area->mta))
332 continue;
333
334 vty_out(vty, "Area %s:\n",
335 area->area_tag);
336 if (ntohs(area->mta->router_id.s_addr)
337 != 0)
338 vty_out(vty,
339 " MPLS-TE Router-Address: %pI4\n",
340 &area->mta->router_id);
341 else
342 vty_out(vty, " N/A\n");
343 }
344 }
345 return 0;
346 }
347 isis = isis_lookup_by_vrfname(vrf_name);
348 if (isis != NULL) {
349 for (ALL_LIST_ELEMENTS_RO(isis->area_list, anode,
350 area)) {
351
352 if (!IS_MPLS_TE(area->mta))
353 continue;
354
355 vty_out(vty, "Area %s:\n", area->area_tag);
356 if (ntohs(area->mta->router_id.s_addr) != 0)
357 vty_out(vty,
358 " MPLS-TE Router-Address: %pI4\n",
359 &area->mta->router_id);
360 else
361 vty_out(vty, " N/A\n");
362 }
363 }
364 }
365
366 return CMD_SUCCESS;
367 }
368
369 static void show_ext_sub(struct vty *vty, char *name,
370 struct isis_ext_subtlvs *ext)
371 {
372 struct sbuf buf;
373 char ibuf[PREFIX2STR_BUFFER];
374
375 sbuf_init(&buf, NULL, 0);
376
377 if (!ext || ext->status == EXT_DISABLE)
378 return;
379
380 vty_out(vty, "-- MPLS-TE link parameters for %s --\n", name);
381
382 sbuf_reset(&buf);
383
384 if (IS_SUBTLV(ext, EXT_ADM_GRP))
385 sbuf_push(&buf, 4, "Administrative Group: 0x%x\n",
386 ext->adm_group);
387 if (IS_SUBTLV(ext, EXT_LLRI)) {
388 sbuf_push(&buf, 4, "Link Local ID: %u\n",
389 ext->local_llri);
390 sbuf_push(&buf, 4, "Link Remote ID: %u\n",
391 ext->remote_llri);
392 }
393 if (IS_SUBTLV(ext, EXT_LOCAL_ADDR))
394 sbuf_push(&buf, 4, "Local Interface IP Address(es): %pI4\n",
395 &ext->local_addr);
396 if (IS_SUBTLV(ext, EXT_NEIGH_ADDR))
397 sbuf_push(&buf, 4, "Remote Interface IP Address(es): %pI4\n",
398 &ext->neigh_addr);
399 if (IS_SUBTLV(ext, EXT_LOCAL_ADDR6))
400 sbuf_push(&buf, 4, "Local Interface IPv6 Address(es): %s\n",
401 inet_ntop(AF_INET6, &ext->local_addr6, ibuf,
402 PREFIX2STR_BUFFER));
403 if (IS_SUBTLV(ext, EXT_NEIGH_ADDR6))
404 sbuf_push(&buf, 4, "Remote Interface IPv6 Address(es): %s\n",
405 inet_ntop(AF_INET6, &ext->local_addr6, ibuf,
406 PREFIX2STR_BUFFER));
407 if (IS_SUBTLV(ext, EXT_MAX_BW))
408 sbuf_push(&buf, 4, "Maximum Bandwidth: %g (Bytes/sec)\n",
409 ext->max_bw);
410 if (IS_SUBTLV(ext, EXT_MAX_RSV_BW))
411 sbuf_push(&buf, 4,
412 "Maximum Reservable Bandwidth: %g (Bytes/sec)\n",
413 ext->max_rsv_bw);
414 if (IS_SUBTLV(ext, EXT_UNRSV_BW)) {
415 sbuf_push(&buf, 4, "Unreserved Bandwidth:\n");
416 for (int j = 0; j < MAX_CLASS_TYPE; j += 2) {
417 sbuf_push(&buf, 4 + 2,
418 "[%d]: %g (Bytes/sec),\t[%d]: %g (Bytes/sec)\n",
419 j, ext->unrsv_bw[j],
420 j + 1, ext->unrsv_bw[j + 1]);
421 }
422 }
423 if (IS_SUBTLV(ext, EXT_TE_METRIC))
424 sbuf_push(&buf, 4, "Traffic Engineering Metric: %u\n",
425 ext->te_metric);
426 if (IS_SUBTLV(ext, EXT_RMT_AS))
427 sbuf_push(&buf, 4,
428 "Inter-AS TE Remote AS number: %u\n",
429 ext->remote_as);
430 if (IS_SUBTLV(ext, EXT_RMT_IP))
431 sbuf_push(&buf, 4,
432 "Inter-AS TE Remote ASBR IP address: %pI4\n",
433 &ext->remote_ip);
434 if (IS_SUBTLV(ext, EXT_DELAY))
435 sbuf_push(&buf, 4,
436 "%s Average Link Delay: %u (micro-sec)\n",
437 IS_ANORMAL(ext->delay) ? "Anomalous" : "Normal",
438 ext->delay);
439 if (IS_SUBTLV(ext, EXT_MM_DELAY)) {
440 sbuf_push(&buf, 4, "%s Min/Max Link Delay: %u / %u (micro-sec)\n",
441 IS_ANORMAL(ext->min_delay) ? "Anomalous" : "Normal",
442 ext->min_delay & TE_EXT_MASK,
443 ext->max_delay & TE_EXT_MASK);
444 }
445 if (IS_SUBTLV(ext, EXT_DELAY_VAR))
446 sbuf_push(&buf, 4,
447 "Delay Variation: %u (micro-sec)\n",
448 ext->delay_var & TE_EXT_MASK);
449 if (IS_SUBTLV(ext, EXT_PKT_LOSS))
450 sbuf_push(&buf, 4, "%s Link Packet Loss: %g (%%)\n",
451 IS_ANORMAL(ext->pkt_loss) ? "Anomalous" : "Normal",
452 (float)((ext->pkt_loss & TE_EXT_MASK)
453 * LOSS_PRECISION));
454 if (IS_SUBTLV(ext, EXT_RES_BW))
455 sbuf_push(&buf, 4,
456 "Unidirectional Residual Bandwidth: %g (Bytes/sec)\n",
457 ext->res_bw);
458 if (IS_SUBTLV(ext, EXT_AVA_BW))
459 sbuf_push(&buf, 4,
460 "Unidirectional Available Bandwidth: %g (Bytes/sec)\n",
461 ext->ava_bw);
462 if (IS_SUBTLV(ext, EXT_USE_BW))
463 sbuf_push(&buf, 4,
464 "Unidirectional Utilized Bandwidth: %g (Bytes/sec)\n",
465 ext->use_bw);
466
467 vty_multiline(vty, "", "%s", sbuf_buf(&buf));
468 vty_out(vty, "---------------\n\n");
469
470 sbuf_free(&buf);
471 return;
472 }
473
474 DEFUN (show_isis_mpls_te_interface,
475 show_isis_mpls_te_interface_cmd,
476 "show " PROTO_NAME " mpls-te interface [INTERFACE]",
477 SHOW_STR
478 PROTO_HELP
479 MPLS_TE_STR
480 "Interface information\n"
481 "Interface name\n")
482 {
483 struct listnode *anode, *cnode, *inode;
484 struct isis_area *area;
485 struct isis_circuit *circuit;
486 struct interface *ifp;
487 int idx_interface = 4;
488 struct isis *isis = NULL;
489
490 if (!im) {
491 vty_out(vty, "IS-IS Routing Process not enabled\n");
492 return CMD_SUCCESS;
493 }
494
495 if (argc == idx_interface) {
496 /* Show All Interfaces. */
497 for (ALL_LIST_ELEMENTS_RO(im->isis, inode, isis)) {
498 for (ALL_LIST_ELEMENTS_RO(isis->area_list, anode,
499 area)) {
500
501 if (!IS_MPLS_TE(area->mta))
502 continue;
503
504 vty_out(vty, "Area %s:\n", area->area_tag);
505
506 for (ALL_LIST_ELEMENTS_RO(area->circuit_list,
507 cnode, circuit))
508 show_ext_sub(vty,
509 circuit->interface->name,
510 circuit->ext);
511 }
512 }
513 } else {
514 /* Interface name is specified. */
515 ifp = if_lookup_by_name(argv[idx_interface]->arg, VRF_DEFAULT);
516 if (ifp == NULL)
517 vty_out(vty, "No such interface name\n");
518 else {
519 circuit = circuit_scan_by_ifp(ifp);
520 if (!circuit)
521 vty_out(vty,
522 "ISIS is not enabled on circuit %s\n",
523 ifp->name);
524 else
525 show_ext_sub(vty, ifp->name, circuit->ext);
526 }
527 }
528
529 return CMD_SUCCESS;
530 }
531 #endif
532
533 /* Initialize MPLS_TE */
534 void isis_mpls_te_init(void)
535 {
536
537 /* Register Circuit and Adjacency hook */
538 hook_register(isis_if_new_hook, isis_mpls_te_update);
539 hook_register(isis_adj_state_change_hook, isis_link_update_adj_hook);
540
541
542 #ifndef FABRICD
543 /* Register new VTY commands */
544 install_element(VIEW_NODE, &show_isis_mpls_te_router_cmd);
545 install_element(VIEW_NODE, &show_isis_mpls_te_interface_cmd);
546 #endif
547
548 return;
549 }