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