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