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