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