]>
Commit | Line | Data |
---|---|---|
718e3744 | 1 | /* |
2 | * This is an implementation of draft-katz-yeung-ospf-traffic-06.txt | |
3 | * Copyright (C) 2001 KDD R&D Laboratories, Inc. | |
4 | * http://www.kddlabs.co.jp/ | |
5 | * | |
6 | * This file is part of GNU Zebra. | |
7 | * | |
8 | * GNU Zebra is free software; you can redistribute it and/or modify it | |
9 | * under the terms of the GNU General Public License as published by the | |
10 | * Free Software Foundation; either version 2, or (at your option) any | |
11 | * later version. | |
12 | * | |
13 | * GNU Zebra is distributed in the hope that it will be useful, but | |
14 | * WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
16 | * General Public License for more details. | |
17 | * | |
18 | * You should have received a copy of the GNU General Public License | |
19 | * along with GNU Zebra; see the file COPYING. If not, write to the Free | |
20 | * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA | |
21 | * 02111-1307, USA. | |
22 | */ | |
23 | ||
24 | /***** MTYPE definition is not reflected to "memory.h" yet. *****/ | |
c66f9c61 | 25 | #define MTYPE_OSPF_MPLS_TE_LINKPARAMS MTYPE_TMP |
718e3744 | 26 | |
27 | #include <zebra.h> | |
28 | ||
718e3744 | 29 | #include "linklist.h" |
30 | #include "prefix.h" | |
b2d7c082 | 31 | #include "vrf.h" |
718e3744 | 32 | #include "if.h" |
33 | #include "table.h" | |
34 | #include "memory.h" | |
35 | #include "command.h" | |
36 | #include "vty.h" | |
37 | #include "stream.h" | |
38 | #include "log.h" | |
39 | #include "thread.h" | |
40 | #include "hash.h" | |
41 | #include "sockunion.h" /* for inet_aton() */ | |
42 | ||
43 | #include "ospfd/ospfd.h" | |
44 | #include "ospfd/ospf_interface.h" | |
45 | #include "ospfd/ospf_ism.h" | |
46 | #include "ospfd/ospf_asbr.h" | |
47 | #include "ospfd/ospf_lsa.h" | |
48 | #include "ospfd/ospf_lsdb.h" | |
49 | #include "ospfd/ospf_neighbor.h" | |
50 | #include "ospfd/ospf_nsm.h" | |
51 | #include "ospfd/ospf_flood.h" | |
52 | #include "ospfd/ospf_packet.h" | |
53 | #include "ospfd/ospf_spf.h" | |
54 | #include "ospfd/ospf_dump.h" | |
55 | #include "ospfd/ospf_route.h" | |
56 | #include "ospfd/ospf_ase.h" | |
57 | #include "ospfd/ospf_zebra.h" | |
58 | #include "ospfd/ospf_te.h" | |
59 | ||
60 | /* Following structure are internal use only. */ | |
61 | struct ospf_mpls_te | |
62 | { | |
63 | enum { disabled, enabled } status; | |
64 | ||
65 | /* List elements are zebra-interfaces (ifp), not ospf-interfaces (oi). */ | |
87d6f87a | 66 | struct list *iflist; |
718e3744 | 67 | |
68 | /* Store Router-TLV in network byte order. */ | |
69 | struct te_tlv_router_addr router_addr; | |
70 | }; | |
71 | ||
72 | struct mpls_te_link | |
73 | { | |
74 | /* | |
75 | * According to MPLS-TE (draft) specification, 24-bit Opaque-ID field | |
76 | * is subdivided into 8-bit "unused" field and 16-bit "instance" field. | |
77 | * In this implementation, each Link-TLV has its own instance. | |
78 | */ | |
79 | u_int32_t instance; | |
80 | ||
81 | /* Reference pointer to a Zebra-interface. */ | |
82 | struct interface *ifp; | |
83 | ||
84 | /* Area info in which this MPLS-TE link belongs to. */ | |
85 | struct ospf_area *area; | |
86 | ||
87 | /* Flags to manage this link parameters. */ | |
88 | u_int32_t flags; | |
89 | #define LPFLG_LOOKUP_DONE 0x1 | |
90 | #define LPFLG_LSA_ENGAGED 0x2 | |
91 | #define LPFLG_LSA_FORCED_REFRESH 0x4 | |
92 | ||
93 | /* Store Link-TLV in network byte order. */ | |
94 | struct te_tlv_link link_header; | |
95 | struct te_link_subtlv_link_type link_type; | |
96 | struct te_link_subtlv_link_id link_id; | |
97 | struct te_link_subtlv_lclif_ipaddr *lclif_ipaddr; | |
98 | struct te_link_subtlv_rmtif_ipaddr *rmtif_ipaddr; | |
99 | struct te_link_subtlv_te_metric te_metric; | |
100 | struct te_link_subtlv_max_bw max_bw; | |
101 | struct te_link_subtlv_max_rsv_bw max_rsv_bw; | |
102 | struct te_link_subtlv_unrsv_bw unrsv_bw; | |
103 | struct te_link_subtlv_rsc_clsclr rsc_clsclr; | |
104 | }; | |
105 | ||
106 | /* | |
107 | * Global variable to manage Opaque-LSA/MPLS-TE on this node. | |
108 | * Note that all parameter values are stored in network byte order. | |
109 | */ | |
110 | static struct ospf_mpls_te OspfMplsTE; | |
111 | ||
112 | enum oifstate { | |
113 | OI_ANY, OI_DOWN, OI_UP | |
114 | }; | |
115 | ||
116 | enum sched_opcode { | |
117 | REORIGINATE_PER_AREA, REFRESH_THIS_LSA, FLUSH_THIS_LSA | |
118 | }; | |
119 | ||
120 | /*------------------------------------------------------------------------* | |
121 | * Followings are initialize/terminate functions for MPLS-TE handling. | |
122 | *------------------------------------------------------------------------*/ | |
123 | ||
124 | static int ospf_mpls_te_new_if (struct interface *ifp); | |
125 | static int ospf_mpls_te_del_if (struct interface *ifp); | |
126 | static void ospf_mpls_te_ism_change (struct ospf_interface *oi, int old_status); | |
127 | static void ospf_mpls_te_nsm_change (struct ospf_neighbor *nbr, int old_status); | |
128 | static void ospf_mpls_te_config_write_router (struct vty *vty); | |
129 | static void ospf_mpls_te_config_write_if (struct vty *vty, struct interface *ifp); | |
130 | static void ospf_mpls_te_show_info (struct vty *vty, struct ospf_lsa *lsa); | |
131 | static int ospf_mpls_te_lsa_originate (void *arg); | |
072990e2 | 132 | static struct ospf_lsa *ospf_mpls_te_lsa_refresh (struct ospf_lsa *lsa); |
718e3744 | 133 | static void ospf_mpls_te_lsa_schedule (struct mpls_te_link *lp, enum sched_opcode); |
134 | ||
135 | static void del_mpls_te_link (void *val); | |
136 | static void ospf_mpls_te_register_vty (void); | |
137 | ||
138 | int | |
139 | ospf_mpls_te_init (void) | |
140 | { | |
141 | int rc; | |
142 | ||
143 | rc = ospf_register_opaque_functab ( | |
144 | OSPF_OPAQUE_AREA_LSA, | |
145 | OPAQUE_TYPE_TRAFFIC_ENGINEERING_LSA, | |
146 | ospf_mpls_te_new_if, | |
147 | ospf_mpls_te_del_if, | |
148 | ospf_mpls_te_ism_change, | |
149 | ospf_mpls_te_nsm_change, | |
150 | ospf_mpls_te_config_write_router, | |
151 | ospf_mpls_te_config_write_if, | |
152 | NULL,/* ospf_mpls_te_config_write_debug */ | |
153 | ospf_mpls_te_show_info, | |
154 | ospf_mpls_te_lsa_originate, | |
155 | ospf_mpls_te_lsa_refresh, | |
156 | NULL,/* ospf_mpls_te_new_lsa_hook */ | |
157 | NULL /* ospf_mpls_te_del_lsa_hook */); | |
158 | if (rc != 0) | |
159 | { | |
160 | zlog_warn ("ospf_mpls_te_init: Failed to register functions"); | |
161 | goto out; | |
162 | } | |
163 | ||
164 | memset (&OspfMplsTE, 0, sizeof (struct ospf_mpls_te)); | |
165 | OspfMplsTE.status = disabled; | |
166 | OspfMplsTE.iflist = list_new (); | |
167 | OspfMplsTE.iflist->del = del_mpls_te_link; | |
168 | ||
169 | ospf_mpls_te_register_vty (); | |
170 | ||
171 | out: | |
172 | return rc; | |
173 | } | |
174 | ||
175 | void | |
176 | ospf_mpls_te_term (void) | |
177 | { | |
178 | list_delete (OspfMplsTE.iflist); | |
179 | ||
180 | OspfMplsTE.iflist = NULL; | |
181 | OspfMplsTE.status = disabled; | |
182 | ||
183 | ospf_delete_opaque_functab (OSPF_OPAQUE_AREA_LSA, | |
184 | OPAQUE_TYPE_TRAFFIC_ENGINEERING_LSA); | |
185 | return; | |
186 | } | |
187 | ||
188 | /*------------------------------------------------------------------------* | |
189 | * Followings are control functions for MPLS-TE parameters management. | |
190 | *------------------------------------------------------------------------*/ | |
191 | ||
192 | static void | |
193 | del_mpls_te_link (void *val) | |
194 | { | |
195 | XFREE (MTYPE_OSPF_MPLS_TE_LINKPARAMS, val); | |
196 | return; | |
197 | } | |
198 | ||
199 | static u_int32_t | |
4dadc291 | 200 | get_mpls_te_instance_value (void) |
718e3744 | 201 | { |
202 | static u_int32_t seqno = 0; | |
203 | ||
703819a9 | 204 | if (seqno < MAX_LEGAL_TE_INSTANCE_NUM ) |
718e3744 | 205 | seqno += 1; |
206 | else | |
207 | seqno = 1; /* Avoid zero. */ | |
208 | ||
209 | return seqno; | |
210 | } | |
211 | ||
212 | static struct ospf_interface * | |
213 | lookup_oi_by_ifp (struct interface *ifp, | |
214 | struct ospf_area *area, enum oifstate oifstate) | |
215 | { | |
216 | struct ospf_interface *oi = NULL; | |
217 | struct route_node *rn; | |
218 | ||
219 | for (rn = route_top (IF_OIFS (ifp)); rn; rn = route_next (rn)) | |
220 | { | |
221 | if ((oi = rn->info) == NULL) | |
222 | continue; | |
223 | ||
224 | switch (oifstate) | |
225 | { | |
226 | case OI_ANY: | |
227 | break; | |
228 | case OI_DOWN: | |
229 | if (ospf_if_is_enable (oi)) | |
230 | continue; | |
231 | break; | |
232 | case OI_UP: | |
233 | if (! ospf_if_is_enable (oi)) | |
234 | continue; | |
235 | break; | |
236 | default: | |
237 | zlog_warn ("lookup_oi_by_ifp: Unknown oifstate: %x", oifstate); | |
238 | goto out; | |
239 | } | |
240 | ||
241 | if (area == NULL || oi->area == area) | |
242 | return oi; | |
243 | } | |
244 | out: | |
245 | return NULL; | |
246 | } | |
247 | ||
248 | static struct mpls_te_link * | |
249 | lookup_linkparams_by_ifp (struct interface *ifp) | |
250 | { | |
1eb8ef25 | 251 | struct listnode *node, *nnode; |
718e3744 | 252 | struct mpls_te_link *lp; |
253 | ||
1eb8ef25 | 254 | for (ALL_LIST_ELEMENTS (OspfMplsTE.iflist, node, nnode, lp)) |
87d6f87a | 255 | if (lp->ifp == ifp) |
256 | return lp; | |
718e3744 | 257 | |
258 | return NULL; | |
259 | } | |
260 | ||
261 | static struct mpls_te_link * | |
262 | lookup_linkparams_by_instance (struct ospf_lsa *lsa) | |
263 | { | |
87d6f87a | 264 | struct listnode *node; |
718e3744 | 265 | struct mpls_te_link *lp; |
6c835671 | 266 | unsigned int key = GET_OPAQUE_ID (ntohl (lsa->data->id.s_addr)); |
718e3744 | 267 | |
1eb8ef25 | 268 | for (ALL_LIST_ELEMENTS_RO (OspfMplsTE.iflist, node, lp)) |
87d6f87a | 269 | if (lp->instance == key) |
270 | return lp; | |
718e3744 | 271 | |
272 | zlog_warn ("lookup_linkparams_by_instance: Entry not found: key(%x)", key); | |
273 | return NULL; | |
274 | } | |
275 | ||
276 | static void | |
277 | ospf_mpls_te_foreach_area ( | |
278 | void (*func)(struct mpls_te_link *lp, enum sched_opcode), | |
279 | enum sched_opcode sched_opcode) | |
280 | { | |
1eb8ef25 | 281 | struct listnode *node, *nnode; |
282 | struct listnode *node2; | |
718e3744 | 283 | struct mpls_te_link *lp; |
284 | struct ospf_area *area; | |
285 | ||
1eb8ef25 | 286 | for (ALL_LIST_ELEMENTS (OspfMplsTE.iflist, node, nnode, lp)) |
718e3744 | 287 | { |
718e3744 | 288 | if ((area = lp->area) == NULL) |
289 | continue; | |
290 | if (lp->flags & LPFLG_LOOKUP_DONE) | |
291 | continue; | |
292 | ||
293 | if (func != NULL) | |
294 | (* func)(lp, sched_opcode); | |
295 | ||
1eb8ef25 | 296 | for (node2 = listnextnode (node); node2; node2 = listnextnode (node2)) |
297 | if ((lp = listgetdata (node2)) != NULL) | |
718e3744 | 298 | if (lp->area != NULL) |
299 | if (IPV4_ADDR_SAME (&lp->area->area_id, &area->area_id)) | |
300 | lp->flags |= LPFLG_LOOKUP_DONE; | |
301 | } | |
302 | ||
1eb8ef25 | 303 | for (ALL_LIST_ELEMENTS_RO (OspfMplsTE.iflist, node, lp)) |
87d6f87a | 304 | if (lp->area != NULL) |
305 | lp->flags &= ~LPFLG_LOOKUP_DONE; | |
718e3744 | 306 | |
307 | return; | |
308 | } | |
309 | ||
310 | static void | |
311 | set_mpls_te_router_addr (struct in_addr ipv4) | |
312 | { | |
313 | OspfMplsTE.router_addr.header.type = htons (TE_TLV_ROUTER_ADDR); | |
314 | OspfMplsTE.router_addr.header.length = htons (sizeof (ipv4)); | |
315 | OspfMplsTE.router_addr.value = ipv4; | |
316 | return; | |
317 | } | |
318 | ||
319 | static void | |
320 | set_linkparams_link_header (struct mpls_te_link *lp) | |
321 | { | |
322 | struct te_tlv_header *tlvh; | |
323 | u_int16_t length = 0; | |
324 | ||
325 | /* TE_LINK_SUBTLV_LINK_TYPE */ | |
326 | if (ntohs (lp->link_type.header.type) != 0) | |
327 | length += TLV_SIZE (&lp->link_type.header); | |
328 | ||
329 | /* TE_LINK_SUBTLV_LINK_ID */ | |
330 | if (ntohs (lp->link_id.header.type) != 0) | |
331 | length += TLV_SIZE (&lp->link_id.header); | |
332 | ||
333 | /* TE_LINK_SUBTLV_LCLIF_IPADDR */ | |
334 | if ((tlvh = (struct te_tlv_header *) lp->lclif_ipaddr) != NULL | |
335 | && ntohs (tlvh->type) != 0) | |
336 | length += TLV_SIZE (tlvh); | |
337 | ||
338 | /* TE_LINK_SUBTLV_RMTIF_IPADDR */ | |
339 | if ((tlvh = (struct te_tlv_header *) lp->rmtif_ipaddr) != NULL | |
340 | && ntohs (tlvh->type) != 0) | |
341 | length += TLV_SIZE (tlvh); | |
342 | ||
343 | /* TE_LINK_SUBTLV_TE_METRIC */ | |
344 | if (ntohs (lp->te_metric.header.type) != 0) | |
345 | length += TLV_SIZE (&lp->te_metric.header); | |
346 | ||
347 | /* TE_LINK_SUBTLV_MAX_BW */ | |
348 | if (ntohs (lp->max_bw.header.type) != 0) | |
349 | length += TLV_SIZE (&lp->max_bw.header); | |
350 | ||
351 | /* TE_LINK_SUBTLV_MAX_RSV_BW */ | |
352 | if (ntohs (lp->max_rsv_bw.header.type) != 0) | |
353 | length += TLV_SIZE (&lp->max_rsv_bw.header); | |
354 | ||
355 | /* TE_LINK_SUBTLV_UNRSV_BW */ | |
356 | if (ntohs (lp->unrsv_bw.header.type) != 0) | |
357 | length += TLV_SIZE (&lp->unrsv_bw.header); | |
358 | ||
359 | /* TE_LINK_SUBTLV_RSC_CLSCLR */ | |
360 | if (ntohs (lp->rsc_clsclr.header.type) != 0) | |
361 | length += TLV_SIZE (&lp->rsc_clsclr.header); | |
362 | ||
363 | lp->link_header.header.type = htons (TE_TLV_LINK); | |
364 | lp->link_header.header.length = htons (length); | |
365 | ||
366 | return; | |
367 | } | |
368 | ||
369 | static void | |
370 | set_linkparams_link_type (struct ospf_interface *oi, struct mpls_te_link *lp) | |
371 | { | |
372 | lp->link_type.header.type = htons (TE_LINK_SUBTLV_LINK_TYPE); | |
373 | lp->link_type.header.length = htons (sizeof (lp->link_type.link_type.value)); | |
374 | ||
375 | switch (oi->type) | |
376 | { | |
377 | case OSPF_IFTYPE_POINTOPOINT: | |
378 | lp->link_type.link_type.value = LINK_TYPE_SUBTLV_VALUE_PTP; | |
379 | break; | |
380 | case OSPF_IFTYPE_BROADCAST: | |
381 | case OSPF_IFTYPE_NBMA: | |
382 | lp->link_type.link_type.value = LINK_TYPE_SUBTLV_VALUE_MA; | |
383 | break; | |
384 | default: | |
385 | /* Not supported yet. *//* XXX */ | |
386 | lp->link_type.header.type = htons (0); | |
387 | break; | |
388 | } | |
389 | return; | |
390 | } | |
391 | ||
392 | static void | |
393 | set_linkparams_link_id (struct ospf_interface *oi, struct mpls_te_link *lp) | |
394 | { | |
395 | struct ospf_neighbor *nbr; | |
396 | int done = 0; | |
397 | ||
398 | lp->link_id.header.type = htons (TE_LINK_SUBTLV_LINK_ID); | |
399 | lp->link_id.header.length = htons (sizeof (lp->link_id.value)); | |
400 | ||
401 | /* | |
402 | * The Link ID is identical to the contents of the Link ID field | |
403 | * in the Router LSA for these link types. | |
404 | */ | |
405 | switch (oi->type) | |
406 | { | |
407 | case OSPF_IFTYPE_POINTOPOINT: | |
408 | /* Take the router ID of the neighbor. */ | |
d4a53d58 | 409 | if ((nbr = ospf_nbr_lookup_ptop (oi)) |
410 | && nbr->state == NSM_Full) | |
718e3744 | 411 | { |
412 | lp->link_id.value = nbr->router_id; | |
413 | done = 1; | |
414 | } | |
415 | break; | |
416 | case OSPF_IFTYPE_BROADCAST: | |
417 | case OSPF_IFTYPE_NBMA: | |
418 | /* Take the interface address of the designated router. */ | |
419 | if ((nbr = ospf_nbr_lookup_by_addr (oi->nbrs, &DR (oi))) == NULL) | |
420 | break; | |
421 | ||
422 | if (nbr->state == NSM_Full | |
423 | || (IPV4_ADDR_SAME (&oi->address->u.prefix4, &DR (oi)) | |
d4a53d58 | 424 | && ospf_nbr_count (oi, NSM_Full) > 0)) |
718e3744 | 425 | { |
426 | lp->link_id.value = DR (oi); | |
427 | done = 1; | |
428 | } | |
429 | break; | |
430 | default: | |
431 | /* Not supported yet. *//* XXX */ | |
432 | lp->link_id.header.type = htons (0); | |
433 | break; | |
434 | } | |
435 | ||
436 | if (! done) | |
437 | { | |
438 | struct in_addr mask; | |
439 | masklen2ip (oi->address->prefixlen, &mask); | |
440 | lp->link_id.value.s_addr = oi->address->u.prefix4.s_addr & mask.s_addr; | |
441 | } | |
442 | return; | |
443 | } | |
444 | ||
445 | static void | |
446 | set_linkparams_te_metric (struct mpls_te_link *lp, u_int32_t te_metric) | |
447 | { | |
448 | lp->te_metric.header.type = htons (TE_LINK_SUBTLV_TE_METRIC); | |
449 | lp->te_metric.header.length = htons (sizeof (lp->te_metric.value)); | |
450 | lp->te_metric.value = htonl (te_metric); | |
451 | return; | |
452 | } | |
453 | ||
454 | static void | |
455 | set_linkparams_max_bw (struct mpls_te_link *lp, float *fp) | |
456 | { | |
457 | lp->max_bw.header.type = htons (TE_LINK_SUBTLV_MAX_BW); | |
458 | lp->max_bw.header.length = htons (sizeof (lp->max_bw.value)); | |
459 | htonf (fp, &lp->max_bw.value); | |
460 | return; | |
461 | } | |
462 | ||
463 | static void | |
464 | set_linkparams_max_rsv_bw (struct mpls_te_link *lp, float *fp) | |
465 | { | |
466 | lp->max_rsv_bw.header.type = htons (TE_LINK_SUBTLV_MAX_RSV_BW); | |
467 | lp->max_rsv_bw.header.length = htons (sizeof (lp->max_rsv_bw.value)); | |
468 | htonf (fp, &lp->max_rsv_bw.value); | |
469 | return; | |
470 | } | |
471 | ||
472 | static void | |
473 | set_linkparams_unrsv_bw (struct mpls_te_link *lp, int priority, float *fp) | |
474 | { | |
475 | /* Note that TLV-length field is the size of array. */ | |
476 | lp->unrsv_bw.header.type = htons (TE_LINK_SUBTLV_UNRSV_BW); | |
477 | lp->unrsv_bw.header.length = htons (sizeof (lp->unrsv_bw.value)); | |
478 | htonf (fp, &lp->unrsv_bw.value [priority]); | |
479 | return; | |
480 | } | |
481 | ||
482 | static void | |
483 | set_linkparams_rsc_clsclr (struct mpls_te_link *lp, u_int32_t classcolor) | |
484 | { | |
485 | lp->rsc_clsclr.header.type = htons (TE_LINK_SUBTLV_RSC_CLSCLR); | |
486 | lp->rsc_clsclr.header.length = htons (sizeof (lp->rsc_clsclr.value)); | |
487 | lp->rsc_clsclr.value = htonl (classcolor); | |
488 | return; | |
489 | } | |
490 | ||
491 | static void | |
492 | initialize_linkparams (struct mpls_te_link *lp) | |
493 | { | |
494 | struct interface *ifp = lp->ifp; | |
495 | struct ospf_interface *oi; | |
496 | float fval; | |
497 | int i; | |
498 | ||
499 | if ((oi = lookup_oi_by_ifp (ifp, NULL, OI_ANY)) == NULL) | |
500 | return; | |
501 | ||
502 | /* | |
503 | * Try to set initial values those can be derived from | |
504 | * zebra-interface information. | |
505 | */ | |
506 | set_linkparams_link_type (oi, lp); | |
507 | ||
508 | /* | |
509 | * Linux and *BSD kernel holds bandwidth parameter as an "int" type. | |
510 | * We may have to reconsider, if "ifp->bandwidth" type changes to float. | |
511 | */ | |
512 | fval = (float)((ifp->bandwidth ? ifp->bandwidth | |
513 | : OSPF_DEFAULT_BANDWIDTH) * 1000 / 8); | |
514 | ||
515 | set_linkparams_max_bw (lp, &fval); | |
516 | set_linkparams_max_rsv_bw (lp, &fval); | |
517 | ||
518 | for (i = 0; i < 8; i++) | |
519 | set_linkparams_unrsv_bw (lp, i, &fval); | |
520 | ||
521 | return; | |
522 | } | |
523 | ||
524 | static int | |
525 | is_mandated_params_set (struct mpls_te_link *lp) | |
526 | { | |
527 | int rc = 0; | |
528 | ||
529 | if (ntohs (OspfMplsTE.router_addr.header.type) == 0) | |
530 | goto out; | |
531 | ||
532 | if (ntohs (lp->link_type.header.type) == 0) | |
533 | goto out; | |
534 | ||
535 | if (ntohs (lp->link_id.header.type) == 0) | |
536 | goto out; | |
537 | ||
538 | rc = 1; | |
539 | out: | |
540 | return rc; | |
541 | } | |
542 | ||
543 | /*------------------------------------------------------------------------* | |
544 | * Followings are callback functions against generic Opaque-LSAs handling. | |
545 | *------------------------------------------------------------------------*/ | |
546 | ||
547 | static int | |
548 | ospf_mpls_te_new_if (struct interface *ifp) | |
549 | { | |
550 | struct mpls_te_link *new; | |
551 | int rc = -1; | |
552 | ||
553 | if (lookup_linkparams_by_ifp (ifp) != NULL) | |
554 | { | |
6c4f4e6e | 555 | zlog_warn ("ospf_mpls_te_new_if: ifp(%p) already in use?", (void *)ifp); |
718e3744 | 556 | rc = 0; /* Do nothing here. */ |
557 | goto out; | |
558 | } | |
559 | ||
393deb9b SH |
560 | new = XCALLOC (MTYPE_OSPF_MPLS_TE_LINKPARAMS, |
561 | sizeof (struct mpls_te_link)); | |
562 | if (new == NULL) | |
718e3744 | 563 | { |
6099b3b5 | 564 | zlog_warn ("ospf_mpls_te_new_if: XMALLOC: %s", safe_strerror (errno)); |
718e3744 | 565 | goto out; |
566 | } | |
718e3744 | 567 | |
568 | new->area = NULL; | |
569 | new->flags = 0; | |
570 | new->instance = get_mpls_te_instance_value (); | |
571 | new->ifp = ifp; | |
572 | ||
573 | initialize_linkparams (new); | |
574 | ||
575 | listnode_add (OspfMplsTE.iflist, new); | |
576 | ||
577 | /* Schedule Opaque-LSA refresh. *//* XXX */ | |
578 | ||
579 | rc = 0; | |
580 | out: | |
581 | return rc; | |
582 | } | |
583 | ||
584 | static int | |
585 | ospf_mpls_te_del_if (struct interface *ifp) | |
586 | { | |
587 | struct mpls_te_link *lp; | |
588 | int rc = -1; | |
589 | ||
590 | if ((lp = lookup_linkparams_by_ifp (ifp)) != NULL) | |
591 | { | |
87d6f87a | 592 | struct list *iflist = OspfMplsTE.iflist; |
718e3744 | 593 | |
594 | /* Dequeue listnode entry from the list. */ | |
595 | listnode_delete (iflist, lp); | |
596 | ||
597 | /* Avoid misjudgement in the next lookup. */ | |
598 | if (listcount (iflist) == 0) | |
599 | iflist->head = iflist->tail = NULL; | |
600 | ||
601 | XFREE (MTYPE_OSPF_MPLS_TE_LINKPARAMS, lp); | |
602 | } | |
603 | ||
604 | /* Schedule Opaque-LSA refresh. *//* XXX */ | |
605 | ||
606 | rc = 0; | |
607 | /*out:*/ | |
608 | return rc; | |
609 | } | |
610 | ||
611 | static void | |
612 | ospf_mpls_te_ism_change (struct ospf_interface *oi, int old_state) | |
613 | { | |
614 | struct te_link_subtlv_link_type old_type; | |
615 | struct te_link_subtlv_link_id old_id; | |
616 | struct mpls_te_link *lp; | |
617 | ||
618 | if ((lp = lookup_linkparams_by_ifp (oi->ifp)) == NULL) | |
619 | { | |
620 | zlog_warn ("ospf_mpls_te_ism_change: Cannot get linkparams from OI(%s)?", IF_NAME (oi)); | |
621 | goto out; | |
622 | } | |
d4a53d58 | 623 | if (oi->area == NULL || oi->area->ospf == NULL) |
718e3744 | 624 | { |
625 | zlog_warn ("ospf_mpls_te_ism_change: Cannot refer to OSPF from OI(%s)?", | |
626 | IF_NAME (oi)); | |
627 | goto out; | |
628 | } | |
629 | #ifdef notyet | |
630 | if ((lp->area != NULL | |
631 | && ! IPV4_ADDR_SAME (&lp->area->area_id, &oi->area->area_id)) | |
632 | || (lp->area != NULL && oi->area == NULL)) | |
633 | { | |
634 | /* How should we consider this case? */ | |
635 | zlog_warn ("MPLS-TE: Area for OI(%s) has changed to [%s], flush previous LSAs", IF_NAME (oi), oi->area ? inet_ntoa (oi->area->area_id) : "N/A"); | |
636 | ospf_mpls_te_lsa_schedule (lp, FLUSH_THIS_LSA); | |
637 | } | |
638 | #endif | |
639 | /* Keep Area information in conbination with linkparams. */ | |
640 | lp->area = oi->area; | |
641 | ||
642 | switch (oi->state) | |
643 | { | |
644 | case ISM_PointToPoint: | |
645 | case ISM_DROther: | |
646 | case ISM_Backup: | |
647 | case ISM_DR: | |
648 | old_type = lp->link_type; | |
649 | old_id = lp->link_id; | |
650 | ||
651 | set_linkparams_link_type (oi, lp); | |
652 | set_linkparams_link_id (oi, lp); | |
653 | ||
654 | if ((ntohs (old_type.header.type) != ntohs (lp->link_type.header.type) | |
655 | || old_type.link_type.value != lp->link_type.link_type.value) | |
656 | || (ntohs (old_id.header.type) != ntohs (lp->link_id.header.type) | |
657 | || ntohl (old_id.value.s_addr) != ntohl (lp->link_id.value.s_addr))) | |
658 | { | |
659 | if (lp->flags & LPFLG_LSA_ENGAGED) | |
660 | ospf_mpls_te_lsa_schedule (lp, REFRESH_THIS_LSA); | |
661 | else | |
662 | ospf_mpls_te_lsa_schedule (lp, REORIGINATE_PER_AREA); | |
663 | } | |
664 | break; | |
665 | default: | |
666 | lp->link_type.header.type = htons (0); | |
667 | lp->link_id.header.type = htons (0); | |
668 | ||
669 | if (lp->flags & LPFLG_LSA_ENGAGED) | |
670 | ospf_mpls_te_lsa_schedule (lp, FLUSH_THIS_LSA); | |
671 | break; | |
672 | } | |
673 | ||
674 | out: | |
675 | return; | |
676 | } | |
677 | ||
678 | static void | |
679 | ospf_mpls_te_nsm_change (struct ospf_neighbor *nbr, int old_state) | |
680 | { | |
681 | /* So far, nothing to do here. */ | |
682 | return; | |
683 | } | |
684 | ||
685 | /*------------------------------------------------------------------------* | |
686 | * Followings are OSPF protocol processing functions for MPLS-TE. | |
687 | *------------------------------------------------------------------------*/ | |
688 | ||
689 | static void | |
690 | build_tlv_header (struct stream *s, struct te_tlv_header *tlvh) | |
691 | { | |
692 | stream_put (s, tlvh, sizeof (struct te_tlv_header)); | |
693 | return; | |
694 | } | |
695 | ||
696 | static void | |
697 | build_router_tlv (struct stream *s) | |
698 | { | |
699 | struct te_tlv_header *tlvh = &OspfMplsTE.router_addr.header; | |
700 | if (ntohs (tlvh->type) != 0) | |
701 | { | |
702 | build_tlv_header (s, tlvh); | |
703 | stream_put (s, tlvh+1, TLV_BODY_SIZE (tlvh)); | |
704 | } | |
705 | return; | |
706 | } | |
707 | ||
708 | static void | |
709 | build_link_subtlv_link_type (struct stream *s, struct mpls_te_link *lp) | |
710 | { | |
711 | struct te_tlv_header *tlvh = &lp->link_type.header; | |
712 | if (ntohs (tlvh->type) != 0) | |
713 | { | |
714 | build_tlv_header (s, tlvh); | |
715 | stream_put (s, tlvh+1, TLV_BODY_SIZE (tlvh)); | |
716 | } | |
717 | return; | |
718 | } | |
719 | ||
720 | static void | |
721 | build_link_subtlv_link_id (struct stream *s, struct mpls_te_link *lp) | |
722 | { | |
723 | struct te_tlv_header *tlvh = &lp->link_id.header; | |
724 | if (ntohs (tlvh->type) != 0) | |
725 | { | |
726 | build_tlv_header (s, tlvh); | |
727 | stream_put (s, tlvh+1, TLV_BODY_SIZE (tlvh)); | |
728 | } | |
729 | return; | |
730 | } | |
731 | ||
732 | static void | |
733 | build_link_subtlv_lclif_ipaddr (struct stream *s, struct mpls_te_link *lp) | |
734 | { | |
735 | struct te_tlv_header *tlvh = (struct te_tlv_header *) lp->lclif_ipaddr; | |
736 | if (tlvh != NULL && ntohs (tlvh->type) != 0) | |
737 | { | |
738 | build_tlv_header (s, tlvh); | |
739 | stream_put (s, tlvh+1, TLV_BODY_SIZE (tlvh)); | |
740 | } | |
741 | return; | |
742 | } | |
743 | ||
744 | static void | |
745 | build_link_subtlv_rmtif_ipaddr (struct stream *s, struct mpls_te_link *lp) | |
746 | { | |
747 | struct te_tlv_header *tlvh = (struct te_tlv_header *) lp->rmtif_ipaddr; | |
748 | if (tlvh != NULL && ntohs (tlvh->type) != 0) | |
749 | { | |
750 | build_tlv_header (s, tlvh); | |
751 | stream_put (s, tlvh+1, TLV_BODY_SIZE (tlvh)); | |
752 | } | |
753 | return; | |
754 | } | |
755 | ||
756 | static void | |
757 | build_link_subtlv_te_metric (struct stream *s, struct mpls_te_link *lp) | |
758 | { | |
759 | struct te_tlv_header *tlvh = &lp->te_metric.header; | |
760 | if (ntohs (tlvh->type) != 0) | |
761 | { | |
762 | build_tlv_header (s, tlvh); | |
763 | stream_put (s, tlvh+1, TLV_BODY_SIZE (tlvh)); | |
764 | } | |
765 | return; | |
766 | } | |
767 | ||
768 | static void | |
769 | build_link_subtlv_max_bw (struct stream *s, struct mpls_te_link *lp) | |
770 | { | |
771 | struct te_tlv_header *tlvh = &lp->max_bw.header; | |
772 | if (ntohs (tlvh->type) != 0) | |
773 | { | |
774 | build_tlv_header (s, tlvh); | |
775 | stream_put (s, tlvh+1, TLV_BODY_SIZE (tlvh)); | |
776 | } | |
777 | return; | |
778 | } | |
779 | ||
780 | static void | |
781 | build_link_subtlv_max_rsv_bw (struct stream *s, struct mpls_te_link *lp) | |
782 | { | |
783 | struct te_tlv_header *tlvh = &lp->max_rsv_bw.header; | |
784 | if (ntohs (tlvh->type) != 0) | |
785 | { | |
786 | build_tlv_header (s, tlvh); | |
787 | stream_put (s, tlvh+1, TLV_BODY_SIZE (tlvh)); | |
788 | } | |
789 | return; | |
790 | } | |
791 | ||
792 | static void | |
793 | build_link_subtlv_unrsv_bw (struct stream *s, struct mpls_te_link *lp) | |
794 | { | |
795 | struct te_tlv_header *tlvh = &lp->unrsv_bw.header; | |
796 | if (ntohs (tlvh->type) != 0) | |
797 | { | |
798 | build_tlv_header (s, tlvh); | |
799 | stream_put (s, tlvh+1, TLV_BODY_SIZE (tlvh)); | |
800 | } | |
801 | return; | |
802 | } | |
803 | ||
804 | static void | |
805 | build_link_subtlv_rsc_clsclr (struct stream *s, struct mpls_te_link *lp) | |
806 | { | |
807 | struct te_tlv_header *tlvh = &lp->rsc_clsclr.header; | |
808 | if (ntohs (tlvh->type) != 0) | |
809 | { | |
810 | build_tlv_header (s, tlvh); | |
811 | stream_put (s, tlvh+1, TLV_BODY_SIZE (tlvh)); | |
812 | } | |
813 | return; | |
814 | } | |
815 | ||
816 | static void | |
817 | build_link_tlv (struct stream *s, struct mpls_te_link *lp) | |
818 | { | |
819 | set_linkparams_link_header (lp); | |
820 | build_tlv_header (s, &lp->link_header.header); | |
821 | ||
822 | build_link_subtlv_link_type (s, lp); | |
823 | build_link_subtlv_link_id (s, lp); | |
824 | build_link_subtlv_lclif_ipaddr (s, lp); | |
825 | build_link_subtlv_rmtif_ipaddr (s, lp); | |
826 | build_link_subtlv_te_metric (s, lp); | |
827 | build_link_subtlv_max_bw (s, lp); | |
828 | build_link_subtlv_max_rsv_bw (s, lp); | |
829 | build_link_subtlv_unrsv_bw (s, lp); | |
830 | build_link_subtlv_rsc_clsclr (s, lp); | |
831 | return; | |
832 | } | |
833 | ||
834 | static void | |
835 | ospf_mpls_te_lsa_body_set (struct stream *s, struct mpls_te_link *lp) | |
836 | { | |
837 | /* | |
838 | * The router address TLV is type 1, and ... | |
839 | * It must appear in exactly one | |
840 | * Traffic Engineering LSA originated by a router. | |
841 | */ | |
842 | build_router_tlv (s); | |
843 | ||
844 | /* | |
845 | * Only one Link TLV shall be carried in each LSA, allowing for fine | |
846 | * granularity changes in topology. | |
847 | */ | |
848 | build_link_tlv (s, lp); | |
849 | return; | |
850 | } | |
851 | ||
852 | /* Create new opaque-LSA. */ | |
853 | static struct ospf_lsa * | |
854 | ospf_mpls_te_lsa_new (struct ospf_area *area, struct mpls_te_link *lp) | |
855 | { | |
856 | struct stream *s; | |
857 | struct lsa_header *lsah; | |
858 | struct ospf_lsa *new = NULL; | |
859 | u_char options, lsa_type; | |
860 | struct in_addr lsa_id; | |
861 | u_int32_t tmp; | |
862 | u_int16_t length; | |
863 | ||
864 | /* Create a stream for LSA. */ | |
865 | if ((s = stream_new (OSPF_MAX_LSA_SIZE)) == NULL) | |
866 | { | |
867 | zlog_warn ("ospf_mpls_te_lsa_new: stream_new() ?"); | |
868 | goto out; | |
869 | } | |
870 | lsah = (struct lsa_header *) STREAM_DATA (s); | |
871 | ||
872 | options = LSA_OPTIONS_GET (area); | |
d4a53d58 | 873 | options |= LSA_OPTIONS_NSSA_GET (area); |
718e3744 | 874 | options |= OSPF_OPTION_O; /* Don't forget this :-) */ |
875 | ||
876 | lsa_type = OSPF_OPAQUE_AREA_LSA; | |
877 | tmp = SET_OPAQUE_LSID (OPAQUE_TYPE_TRAFFIC_ENGINEERING_LSA, lp->instance); | |
878 | lsa_id.s_addr = htonl (tmp); | |
879 | ||
880 | if (IS_DEBUG_OSPF (lsa, LSA_GENERATE)) | |
2a42e285 | 881 | zlog_debug ("LSA[Type%d:%s]: Create an Opaque-LSA/MPLS-TE instance", lsa_type, inet_ntoa (lsa_id)); |
718e3744 | 882 | |
883 | /* Set opaque-LSA header fields. */ | |
d4a53d58 | 884 | lsa_header_set (s, options, lsa_type, lsa_id, area->ospf->router_id); |
718e3744 | 885 | |
886 | /* Set opaque-LSA body fields. */ | |
887 | ospf_mpls_te_lsa_body_set (s, lp); | |
888 | ||
889 | /* Set length. */ | |
890 | length = stream_get_endp (s); | |
891 | lsah->length = htons (length); | |
892 | ||
893 | /* Now, create an OSPF LSA instance. */ | |
894 | if ((new = ospf_lsa_new ()) == NULL) | |
895 | { | |
896 | zlog_warn ("ospf_mpls_te_lsa_new: ospf_lsa_new() ?"); | |
897 | stream_free (s); | |
898 | goto out; | |
899 | } | |
900 | if ((new->data = ospf_lsa_data_new (length)) == NULL) | |
901 | { | |
902 | zlog_warn ("ospf_mpls_te_lsa_new: ospf_lsa_data_new() ?"); | |
1fe6ed38 | 903 | ospf_lsa_unlock (&new); |
718e3744 | 904 | new = NULL; |
905 | stream_free (s); | |
906 | goto out; | |
907 | } | |
908 | ||
909 | new->area = area; | |
910 | SET_FLAG (new->flags, OSPF_LSA_SELF); | |
911 | memcpy (new->data, lsah, length); | |
912 | stream_free (s); | |
913 | ||
914 | out: | |
915 | return new; | |
916 | } | |
917 | ||
918 | static int | |
919 | ospf_mpls_te_lsa_originate1 (struct ospf_area *area, struct mpls_te_link *lp) | |
920 | { | |
921 | struct ospf_lsa *new; | |
922 | int rc = -1; | |
923 | ||
924 | /* Create new Opaque-LSA/MPLS-TE instance. */ | |
925 | if ((new = ospf_mpls_te_lsa_new (area, lp)) == NULL) | |
926 | { | |
927 | zlog_warn ("ospf_mpls_te_lsa_originate1: ospf_mpls_te_lsa_new() ?"); | |
928 | goto out; | |
929 | } | |
930 | ||
931 | /* Install this LSA into LSDB. */ | |
d4a53d58 | 932 | if (ospf_lsa_install (area->ospf, NULL/*oi*/, new) == NULL) |
718e3744 | 933 | { |
934 | zlog_warn ("ospf_mpls_te_lsa_originate1: ospf_lsa_install() ?"); | |
1fe6ed38 | 935 | ospf_lsa_unlock (&new); |
718e3744 | 936 | goto out; |
937 | } | |
938 | ||
939 | /* Now this linkparameter entry has associated LSA. */ | |
940 | lp->flags |= LPFLG_LSA_ENGAGED; | |
941 | ||
942 | /* Update new LSA origination count. */ | |
d4a53d58 | 943 | area->ospf->lsa_originate_count++; |
718e3744 | 944 | |
945 | /* Flood new LSA through area. */ | |
946 | ospf_flood_through_area (area, NULL/*nbr*/, new); | |
947 | ||
948 | if (IS_DEBUG_OSPF (lsa, LSA_GENERATE)) | |
949 | { | |
950 | char area_id[INET_ADDRSTRLEN]; | |
951 | strcpy (area_id, inet_ntoa (area->area_id)); | |
2a42e285 | 952 | zlog_debug ("LSA[Type%d:%s]: Originate Opaque-LSA/MPLS-TE: Area(%s), Link(%s)", new->data->type, inet_ntoa (new->data->id), area_id, lp->ifp->name); |
718e3744 | 953 | ospf_lsa_header_dump (new->data); |
954 | } | |
955 | ||
956 | rc = 0; | |
957 | out: | |
958 | return rc; | |
959 | } | |
960 | ||
961 | static int | |
962 | ospf_mpls_te_lsa_originate (void *arg) | |
963 | { | |
964 | struct ospf_area *area = (struct ospf_area *) arg; | |
1eb8ef25 | 965 | struct listnode *node, *nnode; |
718e3744 | 966 | struct mpls_te_link *lp; |
967 | int rc = -1; | |
968 | ||
969 | if (OspfMplsTE.status == disabled) | |
970 | { | |
971 | zlog_info ("ospf_mpls_te_lsa_originate: MPLS-TE is disabled now."); | |
972 | rc = 0; /* This is not an error case. */ | |
973 | goto out; | |
974 | } | |
975 | ||
1eb8ef25 | 976 | for (ALL_LIST_ELEMENTS (OspfMplsTE.iflist, node, nnode, lp)) |
718e3744 | 977 | { |
718e3744 | 978 | if (lp->area == NULL) |
979 | continue; | |
980 | if (! IPV4_ADDR_SAME (&lp->area->area_id, &area->area_id)) | |
981 | continue; | |
982 | ||
983 | if (lp->flags & LPFLG_LSA_ENGAGED) | |
984 | { | |
985 | if (lp->flags & LPFLG_LSA_FORCED_REFRESH) | |
986 | { | |
987 | lp->flags &= ~LPFLG_LSA_FORCED_REFRESH; | |
988 | ospf_mpls_te_lsa_schedule (lp, REFRESH_THIS_LSA); | |
989 | } | |
990 | continue; | |
991 | } | |
992 | if (! is_mandated_params_set (lp)) | |
993 | { | |
994 | zlog_warn ("ospf_mpls_te_lsa_originate: Link(%s) lacks some mandated MPLS-TE parameters.", lp->ifp ? lp->ifp->name : "?"); | |
995 | continue; | |
996 | } | |
997 | ||
998 | /* Ok, let's try to originate an LSA for this area and Link. */ | |
999 | if (ospf_mpls_te_lsa_originate1 (area, lp) != 0) | |
1000 | goto out; | |
1001 | } | |
1002 | ||
1003 | rc = 0; | |
1004 | out: | |
1005 | return rc; | |
1006 | } | |
1007 | ||
072990e2 | 1008 | static struct ospf_lsa * |
718e3744 | 1009 | ospf_mpls_te_lsa_refresh (struct ospf_lsa *lsa) |
1010 | { | |
1011 | struct mpls_te_link *lp; | |
1012 | struct ospf_area *area = lsa->area; | |
1013 | struct ospf_lsa *new = NULL; | |
1014 | ||
1015 | if (OspfMplsTE.status == disabled) | |
1016 | { | |
1017 | /* | |
1018 | * This LSA must have flushed before due to MPLS-TE status change. | |
1019 | * It seems a slip among routers in the routing domain. | |
1020 | */ | |
1021 | zlog_info ("ospf_mpls_te_lsa_refresh: MPLS-TE is disabled now."); | |
1022 | lsa->data->ls_age = htons (OSPF_LSA_MAXAGE); /* Flush it anyway. */ | |
1023 | } | |
1024 | ||
1025 | /* At first, resolve lsa/lp relationship. */ | |
1026 | if ((lp = lookup_linkparams_by_instance (lsa)) == NULL) | |
1027 | { | |
1028 | zlog_warn ("ospf_mpls_te_lsa_refresh: Invalid parameter?"); | |
1029 | lsa->data->ls_age = htons (OSPF_LSA_MAXAGE); /* Flush it anyway. */ | |
1030 | } | |
1031 | ||
1032 | /* If the lsa's age reached to MaxAge, start flushing procedure. */ | |
1033 | if (IS_LSA_MAXAGE (lsa)) | |
1034 | { | |
a11e012e RG |
1035 | if (lp) |
1036 | lp->flags &= ~LPFLG_LSA_ENGAGED; | |
718e3744 | 1037 | ospf_opaque_lsa_flush_schedule (lsa); |
1038 | goto out; | |
1039 | } | |
1040 | ||
1041 | /* Create new Opaque-LSA/MPLS-TE instance. */ | |
1042 | if ((new = ospf_mpls_te_lsa_new (area, lp)) == NULL) | |
1043 | { | |
1044 | zlog_warn ("ospf_mpls_te_lsa_refresh: ospf_mpls_te_lsa_new() ?"); | |
1045 | goto out; | |
1046 | } | |
1047 | new->data->ls_seqnum = lsa_seqnum_increment (lsa); | |
1048 | ||
1049 | /* Install this LSA into LSDB. */ | |
1050 | /* Given "lsa" will be freed in the next function. */ | |
d4a53d58 | 1051 | if (ospf_lsa_install (area->ospf, NULL/*oi*/, new) == NULL) |
718e3744 | 1052 | { |
1053 | zlog_warn ("ospf_mpls_te_lsa_refresh: ospf_lsa_install() ?"); | |
1fe6ed38 | 1054 | ospf_lsa_unlock (&new); |
718e3744 | 1055 | goto out; |
1056 | } | |
1057 | ||
1058 | /* Flood updated LSA through area. */ | |
1059 | ospf_flood_through_area (area, NULL/*nbr*/, new); | |
1060 | ||
1061 | /* Debug logging. */ | |
1062 | if (IS_DEBUG_OSPF (lsa, LSA_GENERATE)) | |
1063 | { | |
2a42e285 | 1064 | zlog_debug ("LSA[Type%d:%s]: Refresh Opaque-LSA/MPLS-TE", |
718e3744 | 1065 | new->data->type, inet_ntoa (new->data->id)); |
1066 | ospf_lsa_header_dump (new->data); | |
1067 | } | |
1068 | ||
1069 | out: | |
072990e2 | 1070 | return new; |
718e3744 | 1071 | } |
1072 | ||
1073 | static void | |
1074 | ospf_mpls_te_lsa_schedule (struct mpls_te_link *lp, | |
1075 | enum sched_opcode opcode) | |
1076 | { | |
1077 | struct ospf_lsa lsa; | |
1078 | struct lsa_header lsah; | |
1079 | u_int32_t tmp; | |
1080 | ||
1081 | memset (&lsa, 0, sizeof (lsa)); | |
1082 | memset (&lsah, 0, sizeof (lsah)); | |
1083 | ||
1084 | lsa.area = lp->area; | |
1085 | lsa.data = &lsah; | |
1086 | lsah.type = OSPF_OPAQUE_AREA_LSA; | |
1087 | tmp = SET_OPAQUE_LSID (OPAQUE_TYPE_TRAFFIC_ENGINEERING_LSA, lp->instance); | |
1088 | lsah.id.s_addr = htonl (tmp); | |
1089 | ||
1090 | switch (opcode) | |
1091 | { | |
1092 | case REORIGINATE_PER_AREA: | |
1093 | ospf_opaque_lsa_reoriginate_schedule ((void *) lp->area, | |
1094 | OSPF_OPAQUE_AREA_LSA, OPAQUE_TYPE_TRAFFIC_ENGINEERING_LSA); | |
1095 | break; | |
1096 | case REFRESH_THIS_LSA: | |
1097 | ospf_opaque_lsa_refresh_schedule (&lsa); | |
1098 | break; | |
1099 | case FLUSH_THIS_LSA: | |
1100 | lp->flags &= ~LPFLG_LSA_ENGAGED; | |
1101 | ospf_opaque_lsa_flush_schedule (&lsa); | |
1102 | break; | |
1103 | default: | |
1104 | zlog_warn ("ospf_mpls_te_lsa_schedule: Unknown opcode (%u)", opcode); | |
1105 | break; | |
1106 | } | |
1107 | ||
1108 | return; | |
1109 | } | |
1110 | ||
1111 | /*------------------------------------------------------------------------* | |
1112 | * Followings are vty session control functions. | |
1113 | *------------------------------------------------------------------------*/ | |
1114 | ||
1115 | static u_int16_t | |
1116 | show_vty_router_addr (struct vty *vty, struct te_tlv_header *tlvh) | |
1117 | { | |
1118 | struct te_tlv_router_addr *top = (struct te_tlv_router_addr *) tlvh; | |
1119 | ||
1120 | if (vty != NULL) | |
1121 | vty_out (vty, " Router-Address: %s%s", inet_ntoa (top->value), VTY_NEWLINE); | |
1122 | else | |
2a42e285 | 1123 | zlog_debug (" Router-Address: %s", inet_ntoa (top->value)); |
718e3744 | 1124 | |
1125 | return TLV_SIZE (tlvh); | |
1126 | } | |
1127 | ||
1128 | static u_int16_t | |
1129 | show_vty_link_header (struct vty *vty, struct te_tlv_header *tlvh) | |
1130 | { | |
1131 | struct te_tlv_link *top = (struct te_tlv_link *) tlvh; | |
1132 | ||
1133 | if (vty != NULL) | |
1134 | vty_out (vty, " Link: %u octets of data%s", ntohs (top->header.length), VTY_NEWLINE); | |
1135 | else | |
2a42e285 | 1136 | zlog_debug (" Link: %u octets of data", ntohs (top->header.length)); |
718e3744 | 1137 | |
1138 | return TLV_HDR_SIZE; /* Here is special, not "TLV_SIZE". */ | |
1139 | } | |
1140 | ||
1141 | static u_int16_t | |
1142 | show_vty_link_subtlv_link_type (struct vty *vty, struct te_tlv_header *tlvh) | |
1143 | { | |
1144 | struct te_link_subtlv_link_type *top; | |
1145 | const char *cp = "Unknown"; | |
1146 | ||
1147 | top = (struct te_link_subtlv_link_type *) tlvh; | |
1148 | switch (top->link_type.value) | |
1149 | { | |
1150 | case LINK_TYPE_SUBTLV_VALUE_PTP: | |
1151 | cp = "Point-to-point"; | |
1152 | break; | |
1153 | case LINK_TYPE_SUBTLV_VALUE_MA: | |
1154 | cp = "Multiaccess"; | |
1155 | break; | |
1156 | default: | |
1157 | break; | |
1158 | } | |
1159 | ||
1160 | if (vty != NULL) | |
1161 | vty_out (vty, " Link-Type: %s (%u)%s", cp, top->link_type.value, VTY_NEWLINE); | |
1162 | else | |
2a42e285 | 1163 | zlog_debug (" Link-Type: %s (%u)", cp, top->link_type.value); |
718e3744 | 1164 | |
1165 | return TLV_SIZE (tlvh); | |
1166 | } | |
1167 | ||
1168 | static u_int16_t | |
1169 | show_vty_link_subtlv_link_id (struct vty *vty, struct te_tlv_header *tlvh) | |
1170 | { | |
1171 | struct te_link_subtlv_link_id *top; | |
1172 | ||
1173 | top = (struct te_link_subtlv_link_id *) tlvh; | |
1174 | if (vty != NULL) | |
1175 | vty_out (vty, " Link-ID: %s%s", inet_ntoa (top->value), VTY_NEWLINE); | |
1176 | else | |
2a42e285 | 1177 | zlog_debug (" Link-ID: %s", inet_ntoa (top->value)); |
718e3744 | 1178 | |
1179 | return TLV_SIZE (tlvh); | |
1180 | } | |
1181 | ||
1182 | static u_int16_t | |
1183 | show_vty_link_subtlv_lclif_ipaddr (struct vty *vty, struct te_tlv_header *tlvh) | |
1184 | { | |
1185 | struct te_link_subtlv_lclif_ipaddr *top; | |
1186 | int i, n; | |
1187 | ||
1188 | top = (struct te_link_subtlv_lclif_ipaddr *) tlvh; | |
1189 | n = ntohs (tlvh->length) / sizeof (top->value[0]); | |
1190 | ||
1191 | if (vty != NULL) | |
1192 | vty_out (vty, " Local Interface IP Address(es): %d%s", n, VTY_NEWLINE); | |
1193 | else | |
2a42e285 | 1194 | zlog_debug (" Local Interface IP Address(es): %d", n); |
718e3744 | 1195 | |
1196 | for (i = 0; i < n; i++) | |
1197 | { | |
1198 | if (vty != NULL) | |
1199 | vty_out (vty, " #%d: %s%s", i, inet_ntoa (top->value[i]), VTY_NEWLINE); | |
1200 | else | |
2a42e285 | 1201 | zlog_debug (" #%d: %s", i, inet_ntoa (top->value[i])); |
718e3744 | 1202 | } |
1203 | return TLV_SIZE (tlvh); | |
1204 | } | |
1205 | ||
1206 | static u_int16_t | |
1207 | show_vty_link_subtlv_rmtif_ipaddr (struct vty *vty, struct te_tlv_header *tlvh) | |
1208 | { | |
1209 | struct te_link_subtlv_rmtif_ipaddr *top; | |
1210 | int i, n; | |
1211 | ||
1212 | top = (struct te_link_subtlv_rmtif_ipaddr *) tlvh; | |
1213 | n = ntohs (tlvh->length) / sizeof (top->value[0]); | |
1214 | if (vty != NULL) | |
1215 | vty_out (vty, " Remote Interface IP Address(es): %d%s", n, VTY_NEWLINE); | |
1216 | else | |
2a42e285 | 1217 | zlog_debug (" Remote Interface IP Address(es): %d", n); |
718e3744 | 1218 | |
1219 | for (i = 0; i < n; i++) | |
1220 | { | |
1221 | if (vty != NULL) | |
1222 | vty_out (vty, " #%d: %s%s", i, inet_ntoa (top->value[i]), VTY_NEWLINE); | |
1223 | else | |
2a42e285 | 1224 | zlog_debug (" #%d: %s", i, inet_ntoa (top->value[i])); |
718e3744 | 1225 | } |
1226 | return TLV_SIZE (tlvh); | |
1227 | } | |
1228 | ||
1229 | static u_int16_t | |
1230 | show_vty_link_subtlv_te_metric (struct vty *vty, struct te_tlv_header *tlvh) | |
1231 | { | |
1232 | struct te_link_subtlv_te_metric *top; | |
1233 | ||
1234 | top = (struct te_link_subtlv_te_metric *) tlvh; | |
1235 | if (vty != NULL) | |
1236 | vty_out (vty, " Traffic Engineering Metric: %u%s", (u_int32_t) ntohl (top->value), VTY_NEWLINE); | |
1237 | else | |
2a42e285 | 1238 | zlog_debug (" Traffic Engineering Metric: %u", (u_int32_t) ntohl (top->value)); |
718e3744 | 1239 | |
1240 | return TLV_SIZE (tlvh); | |
1241 | } | |
1242 | ||
1243 | static u_int16_t | |
1244 | show_vty_link_subtlv_max_bw (struct vty *vty, struct te_tlv_header *tlvh) | |
1245 | { | |
1246 | struct te_link_subtlv_max_bw *top; | |
1247 | float fval; | |
1248 | ||
1249 | top = (struct te_link_subtlv_max_bw *) tlvh; | |
1250 | ntohf (&top->value, &fval); | |
1251 | ||
1252 | if (vty != NULL) | |
1253 | vty_out (vty, " Maximum Bandwidth: %g (Bytes/sec)%s", fval, VTY_NEWLINE); | |
1254 | else | |
2a42e285 | 1255 | zlog_debug (" Maximum Bandwidth: %g (Bytes/sec)", fval); |
718e3744 | 1256 | |
1257 | return TLV_SIZE (tlvh); | |
1258 | } | |
1259 | ||
1260 | static u_int16_t | |
1261 | show_vty_link_subtlv_max_rsv_bw (struct vty *vty, struct te_tlv_header *tlvh) | |
1262 | { | |
1263 | struct te_link_subtlv_max_rsv_bw *top; | |
1264 | float fval; | |
1265 | ||
1266 | top = (struct te_link_subtlv_max_rsv_bw *) tlvh; | |
1267 | ntohf (&top->value, &fval); | |
1268 | ||
1269 | if (vty != NULL) | |
1270 | vty_out (vty, " Maximum Reservable Bandwidth: %g (Bytes/sec)%s", fval, VTY_NEWLINE); | |
1271 | else | |
2a42e285 | 1272 | zlog_debug (" Maximum Reservable Bandwidth: %g (Bytes/sec)", fval); |
718e3744 | 1273 | |
1274 | return TLV_SIZE (tlvh); | |
1275 | } | |
1276 | ||
1277 | static u_int16_t | |
1278 | show_vty_link_subtlv_unrsv_bw (struct vty *vty, struct te_tlv_header *tlvh) | |
1279 | { | |
1280 | struct te_link_subtlv_unrsv_bw *top; | |
1281 | float fval; | |
1282 | int i; | |
1283 | ||
1284 | top = (struct te_link_subtlv_unrsv_bw *) tlvh; | |
1285 | for (i = 0; i < 8; i++) | |
1286 | { | |
1287 | ntohf (&top->value[i], &fval); | |
1288 | if (vty != NULL) | |
1289 | vty_out (vty, " Unreserved Bandwidth (pri %d): %g (Bytes/sec)%s", i, fval, VTY_NEWLINE); | |
1290 | else | |
2a42e285 | 1291 | zlog_debug (" Unreserved Bandwidth (pri %d): %g (Bytes/sec)", i, fval); |
718e3744 | 1292 | } |
1293 | ||
1294 | return TLV_SIZE (tlvh); | |
1295 | } | |
1296 | ||
1297 | static u_int16_t | |
1298 | show_vty_link_subtlv_rsc_clsclr (struct vty *vty, struct te_tlv_header *tlvh) | |
1299 | { | |
1300 | struct te_link_subtlv_rsc_clsclr *top; | |
1301 | ||
1302 | top = (struct te_link_subtlv_rsc_clsclr *) tlvh; | |
1303 | if (vty != NULL) | |
1304 | vty_out (vty, " Resource class/color: 0x%x%s", (u_int32_t) ntohl (top->value), VTY_NEWLINE); | |
1305 | else | |
2a42e285 | 1306 | zlog_debug (" Resource Class/Color: 0x%x", (u_int32_t) ntohl (top->value)); |
718e3744 | 1307 | |
1308 | return TLV_SIZE (tlvh); | |
1309 | } | |
1310 | ||
1311 | static u_int16_t | |
1312 | show_vty_unknown_tlv (struct vty *vty, struct te_tlv_header *tlvh) | |
1313 | { | |
1314 | if (vty != NULL) | |
1315 | vty_out (vty, " Unknown TLV: [type(0x%x), length(0x%x)]%s", ntohs (tlvh->type), ntohs (tlvh->length), VTY_NEWLINE); | |
1316 | else | |
2a42e285 | 1317 | zlog_debug (" Unknown TLV: [type(0x%x), length(0x%x)]", ntohs (tlvh->type), ntohs (tlvh->length)); |
718e3744 | 1318 | |
1319 | return TLV_SIZE (tlvh); | |
1320 | } | |
1321 | ||
1322 | static u_int16_t | |
1323 | ospf_mpls_te_show_link_subtlv (struct vty *vty, struct te_tlv_header *tlvh0, | |
1324 | u_int16_t subtotal, u_int16_t total) | |
1325 | { | |
1326 | struct te_tlv_header *tlvh, *next; | |
1327 | u_int16_t sum = subtotal; | |
1328 | ||
1329 | for (tlvh = tlvh0; sum < total; tlvh = (next ? next : TLV_HDR_NEXT (tlvh))) | |
1330 | { | |
1331 | next = NULL; | |
1332 | switch (ntohs (tlvh->type)) | |
1333 | { | |
1334 | case TE_LINK_SUBTLV_LINK_TYPE: | |
1335 | sum += show_vty_link_subtlv_link_type (vty, tlvh); | |
1336 | break; | |
1337 | case TE_LINK_SUBTLV_LINK_ID: | |
1338 | sum += show_vty_link_subtlv_link_id (vty, tlvh); | |
1339 | break; | |
1340 | case TE_LINK_SUBTLV_LCLIF_IPADDR: | |
1341 | sum += show_vty_link_subtlv_lclif_ipaddr (vty, tlvh); | |
1342 | break; | |
1343 | case TE_LINK_SUBTLV_RMTIF_IPADDR: | |
1344 | sum += show_vty_link_subtlv_rmtif_ipaddr (vty, tlvh); | |
1345 | break; | |
1346 | case TE_LINK_SUBTLV_TE_METRIC: | |
1347 | sum += show_vty_link_subtlv_te_metric (vty, tlvh); | |
1348 | break; | |
1349 | case TE_LINK_SUBTLV_MAX_BW: | |
1350 | sum += show_vty_link_subtlv_max_bw (vty, tlvh); | |
1351 | break; | |
1352 | case TE_LINK_SUBTLV_MAX_RSV_BW: | |
1353 | sum += show_vty_link_subtlv_max_rsv_bw (vty, tlvh); | |
1354 | break; | |
1355 | case TE_LINK_SUBTLV_UNRSV_BW: | |
1356 | sum += show_vty_link_subtlv_unrsv_bw (vty, tlvh); | |
1357 | break; | |
1358 | case TE_LINK_SUBTLV_RSC_CLSCLR: | |
1359 | sum += show_vty_link_subtlv_rsc_clsclr (vty, tlvh); | |
1360 | break; | |
1361 | default: | |
1362 | sum += show_vty_unknown_tlv (vty, tlvh); | |
1363 | break; | |
1364 | } | |
1365 | } | |
1366 | return sum; | |
1367 | } | |
1368 | ||
1369 | static void | |
1370 | ospf_mpls_te_show_info (struct vty *vty, struct ospf_lsa *lsa) | |
1371 | { | |
1372 | struct lsa_header *lsah = (struct lsa_header *) lsa->data; | |
1373 | struct te_tlv_header *tlvh, *next; | |
1374 | u_int16_t sum, total; | |
1375 | u_int16_t (* subfunc)(struct vty *vty, struct te_tlv_header *tlvh, | |
1376 | u_int16_t subtotal, u_int16_t total) = NULL; | |
1377 | ||
1378 | sum = 0; | |
1379 | total = ntohs (lsah->length) - OSPF_LSA_HEADER_SIZE; | |
1380 | ||
1381 | for (tlvh = TLV_HDR_TOP (lsah); sum < total; | |
1382 | tlvh = (next ? next : TLV_HDR_NEXT (tlvh))) | |
1383 | { | |
1384 | if (subfunc != NULL) | |
1385 | { | |
1386 | sum = (* subfunc)(vty, tlvh, sum, total); | |
1387 | next = (struct te_tlv_header *)((char *) tlvh + sum); | |
1388 | subfunc = NULL; | |
1389 | continue; | |
1390 | } | |
1391 | ||
1392 | next = NULL; | |
1393 | switch (ntohs (tlvh->type)) | |
1394 | { | |
1395 | case TE_TLV_ROUTER_ADDR: | |
1396 | sum += show_vty_router_addr (vty, tlvh); | |
1397 | break; | |
1398 | case TE_TLV_LINK: | |
1399 | sum += show_vty_link_header (vty, tlvh); | |
1400 | subfunc = ospf_mpls_te_show_link_subtlv; | |
1401 | next = tlvh + 1; | |
1402 | break; | |
1403 | default: | |
1404 | sum += show_vty_unknown_tlv (vty, tlvh); | |
1405 | break; | |
1406 | } | |
1407 | } | |
1408 | return; | |
1409 | } | |
1410 | ||
1411 | static void | |
1412 | ospf_mpls_te_config_write_router (struct vty *vty) | |
1413 | { | |
1414 | if (OspfMplsTE.status == enabled) | |
1415 | { | |
813d4307 DW |
1416 | vty_out (vty, " mpls-te%s", VTY_NEWLINE); |
1417 | vty_out (vty, " mpls-te router-address %s%s", | |
718e3744 | 1418 | inet_ntoa (OspfMplsTE.router_addr.value), VTY_NEWLINE); |
1419 | } | |
1420 | return; | |
1421 | } | |
1422 | ||
1423 | static void | |
1424 | ospf_mpls_te_config_write_if (struct vty *vty, struct interface *ifp) | |
1425 | { | |
1426 | struct mpls_te_link *lp; | |
1427 | ||
1428 | if ((OspfMplsTE.status == enabled) | |
1429 | && (! if_is_loopback (ifp) && if_is_up (ifp) && ospf_oi_count (ifp) > 0) | |
1430 | && ((lp = lookup_linkparams_by_ifp (ifp)) != NULL)) | |
1431 | { | |
1432 | float fval; | |
1433 | int i; | |
1434 | ||
1435 | vty_out (vty, " mpls-te link metric %u%s", | |
1436 | (u_int32_t) ntohl (lp->te_metric.value), VTY_NEWLINE); | |
1437 | ||
1438 | ntohf (&lp->max_bw.value, &fval); | |
1439 | if (fval >= MPLS_TE_MINIMUM_BANDWIDTH) | |
1440 | vty_out (vty, " mpls-te link max-bw %g%s", fval, VTY_NEWLINE); | |
1441 | ||
1442 | ntohf (&lp->max_rsv_bw.value, &fval); | |
1443 | if (fval >= MPLS_TE_MINIMUM_BANDWIDTH) | |
1444 | vty_out (vty, " mpls-te link max-rsv-bw %g%s", fval, VTY_NEWLINE); | |
1445 | ||
1446 | for (i = 0; i < 8; i++) | |
1447 | { | |
1448 | ntohf (&lp->unrsv_bw.value[i], &fval); | |
1449 | if (fval >= MPLS_TE_MINIMUM_BANDWIDTH) | |
1450 | vty_out (vty, " mpls-te link unrsv-bw %d %g%s", | |
1451 | i, fval, VTY_NEWLINE); | |
1452 | } | |
1453 | ||
1454 | vty_out (vty, " mpls-te link rsc-clsclr 0x%x%s", | |
1455 | (u_int32_t) ntohl (lp->rsc_clsclr.value), VTY_NEWLINE); | |
1456 | } | |
1457 | return; | |
1458 | } | |
1459 | ||
1460 | /*------------------------------------------------------------------------* | |
1461 | * Followings are vty command functions. | |
1462 | *------------------------------------------------------------------------*/ | |
1463 | ||
1464 | DEFUN (mpls_te, | |
1465 | mpls_te_cmd, | |
1466 | "mpls-te", | |
1467 | "Configure MPLS-TE parameters\n" | |
1468 | "Enable the MPLS-TE functionality\n") | |
1469 | { | |
1eb8ef25 | 1470 | struct listnode *node, *nnode; |
718e3744 | 1471 | struct mpls_te_link *lp; |
7c8ff89e DS |
1472 | struct ospf *ospf = vty->index; |
1473 | ||
1474 | if (!ospf) | |
1475 | return CMD_SUCCESS; | |
718e3744 | 1476 | |
1477 | if (OspfMplsTE.status == enabled) | |
1478 | return CMD_SUCCESS; | |
1479 | ||
1480 | if (IS_DEBUG_OSPF_EVENT) | |
2a42e285 | 1481 | zlog_debug ("MPLS-TE: OFF -> ON"); |
718e3744 | 1482 | |
1483 | OspfMplsTE.status = enabled; | |
1484 | ||
1485 | /* | |
1486 | * Following code is intended to handle two cases; | |
1487 | * | |
1488 | * 1) MPLS-TE was disabled at startup time, but now become enabled. | |
1489 | * 2) MPLS-TE was once enabled then disabled, and now enabled again. | |
1490 | */ | |
1eb8ef25 | 1491 | for (ALL_LIST_ELEMENTS (OspfMplsTE.iflist, node, nnode, lp)) |
1492 | initialize_linkparams (lp); | |
718e3744 | 1493 | |
1494 | ospf_mpls_te_foreach_area (ospf_mpls_te_lsa_schedule, REORIGINATE_PER_AREA); | |
1495 | ||
1496 | return CMD_SUCCESS; | |
1497 | } | |
1498 | ||
1499 | ALIAS (mpls_te, | |
1500 | mpls_te_on_cmd, | |
1501 | "mpls-te on", | |
1502 | "Configure MPLS-TE parameters\n" | |
1503 | "Enable the MPLS-TE functionality\n") | |
1504 | ||
1505 | DEFUN (no_mpls_te, | |
1506 | no_mpls_te_cmd, | |
1507 | "no mpls-te", | |
1508 | NO_STR | |
1509 | "Configure MPLS-TE parameters\n" | |
1510 | "Disable the MPLS-TE functionality\n") | |
1511 | { | |
1eb8ef25 | 1512 | struct listnode *node, *nnode; |
718e3744 | 1513 | struct mpls_te_link *lp; |
7c8ff89e DS |
1514 | struct ospf *ospf = vty->index; |
1515 | ||
1516 | if (!ospf) | |
1517 | return CMD_SUCCESS; | |
718e3744 | 1518 | |
1519 | if (OspfMplsTE.status == disabled) | |
1520 | return CMD_SUCCESS; | |
1521 | ||
1522 | if (IS_DEBUG_OSPF_EVENT) | |
2a42e285 | 1523 | zlog_debug ("MPLS-TE: ON -> OFF"); |
718e3744 | 1524 | |
1525 | OspfMplsTE.status = disabled; | |
1526 | ||
1eb8ef25 | 1527 | for (ALL_LIST_ELEMENTS (OspfMplsTE.iflist, node, nnode, lp)) |
1528 | if (lp->area != NULL) | |
1529 | if (lp->flags & LPFLG_LSA_ENGAGED) | |
1530 | ospf_mpls_te_lsa_schedule (lp, FLUSH_THIS_LSA); | |
718e3744 | 1531 | |
1532 | return CMD_SUCCESS; | |
1533 | } | |
1534 | ||
813d4307 DW |
1535 | ALIAS (no_mpls_te, |
1536 | no_mpls_te_val_cmd, | |
1537 | "no mpls-te on", | |
1538 | NO_STR | |
1539 | "Configure MPLS-TE parameters\n" | |
1540 | "Disable the MPLS-TE functionality\n") | |
1541 | ||
718e3744 | 1542 | DEFUN (mpls_te_router_addr, |
1543 | mpls_te_router_addr_cmd, | |
1544 | "mpls-te router-address A.B.C.D", | |
1545 | "MPLS-TE specific commands\n" | |
1546 | "Stable IP address of the advertising router\n" | |
1547 | "MPLS-TE router address in IPv4 address format\n") | |
1548 | { | |
1549 | struct te_tlv_router_addr *ra = &OspfMplsTE.router_addr; | |
1550 | struct in_addr value; | |
7c8ff89e DS |
1551 | struct ospf *ospf = vty->index; |
1552 | ||
1553 | if (!ospf) | |
1554 | return CMD_SUCCESS; | |
718e3744 | 1555 | |
1556 | if (! inet_aton (argv[0], &value)) | |
1557 | { | |
1558 | vty_out (vty, "Please specify Router-Addr by A.B.C.D%s", VTY_NEWLINE); | |
1559 | return CMD_WARNING; | |
1560 | } | |
1561 | ||
1562 | if (ntohs (ra->header.type) == 0 | |
87d6f87a | 1563 | || ntohl (ra->value.s_addr) != ntohl (value.s_addr)) |
718e3744 | 1564 | { |
1eb8ef25 | 1565 | struct listnode *node, *nnode; |
718e3744 | 1566 | struct mpls_te_link *lp; |
1567 | int need_to_reoriginate = 0; | |
1568 | ||
1569 | set_mpls_te_router_addr (value); | |
1570 | ||
1571 | if (OspfMplsTE.status == disabled) | |
1572 | goto out; | |
1573 | ||
1eb8ef25 | 1574 | for (ALL_LIST_ELEMENTS (OspfMplsTE.iflist, node, nnode, lp)) |
718e3744 | 1575 | { |
718e3744 | 1576 | if (lp->area == NULL) |
1577 | continue; | |
1578 | ||
1579 | if ((lp->flags & LPFLG_LSA_ENGAGED) == 0) | |
1580 | { | |
1581 | need_to_reoriginate = 1; | |
1582 | break; | |
1583 | } | |
1584 | } | |
1eb8ef25 | 1585 | |
1586 | for (ALL_LIST_ELEMENTS (OspfMplsTE.iflist, node, nnode, lp)) | |
718e3744 | 1587 | { |
718e3744 | 1588 | if (lp->area == NULL) |
1589 | continue; | |
1590 | ||
1591 | if (need_to_reoriginate) | |
1592 | lp->flags |= LPFLG_LSA_FORCED_REFRESH; | |
1593 | else | |
1594 | ospf_mpls_te_lsa_schedule (lp, REFRESH_THIS_LSA); | |
1595 | } | |
1596 | ||
1597 | if (need_to_reoriginate) | |
1598 | ospf_mpls_te_foreach_area ( | |
1599 | ospf_mpls_te_lsa_schedule, REORIGINATE_PER_AREA); | |
1600 | } | |
1601 | out: | |
1602 | return CMD_SUCCESS; | |
1603 | } | |
1604 | ||
1605 | DEFUN (mpls_te_link_metric, | |
1606 | mpls_te_link_metric_cmd, | |
1607 | "mpls-te link metric <0-4294967295>", | |
1608 | "MPLS-TE specific commands\n" | |
1609 | "Configure MPLS-TE link parameters\n" | |
1610 | "Link metric for MPLS-TE purpose\n" | |
1611 | "Metric\n") | |
1612 | { | |
1613 | struct interface *ifp = (struct interface *) vty->index; | |
1614 | struct mpls_te_link *lp; | |
1615 | u_int32_t value; | |
1616 | ||
1617 | if ((lp = lookup_linkparams_by_ifp (ifp)) == NULL) | |
1618 | { | |
1619 | vty_out (vty, "mpls_te_link_metric: Something wrong!%s", VTY_NEWLINE); | |
1620 | return CMD_WARNING; | |
1621 | } | |
1622 | ||
1623 | value = strtoul (argv[0], NULL, 10); | |
1624 | ||
1625 | if (ntohs (lp->te_metric.header.type) == 0 | |
1626 | || ntohl (lp->te_metric.value) != value) | |
1627 | { | |
1628 | set_linkparams_te_metric (lp, value); | |
1629 | ||
1630 | if (OspfMplsTE.status == enabled) | |
1631 | if (lp->area != NULL) | |
1632 | { | |
1633 | if (lp->flags & LPFLG_LSA_ENGAGED) | |
1634 | ospf_mpls_te_lsa_schedule (lp, REFRESH_THIS_LSA); | |
1635 | else | |
1636 | ospf_mpls_te_lsa_schedule (lp, REORIGINATE_PER_AREA); | |
1637 | } | |
1638 | } | |
1639 | return CMD_SUCCESS; | |
1640 | } | |
1641 | ||
1642 | DEFUN (mpls_te_link_maxbw, | |
1643 | mpls_te_link_maxbw_cmd, | |
1644 | "mpls-te link max-bw BANDWIDTH", | |
1645 | "MPLS-TE specific commands\n" | |
1646 | "Configure MPLS-TE link parameters\n" | |
1647 | "Maximum bandwidth that can be used\n" | |
1648 | "Bytes/second (IEEE floating point format)\n") | |
1649 | { | |
1650 | struct interface *ifp = (struct interface *) vty->index; | |
1651 | struct mpls_te_link *lp; | |
1652 | float f1, f2; | |
1653 | ||
1654 | if ((lp = lookup_linkparams_by_ifp (ifp)) == NULL) | |
1655 | { | |
1656 | vty_out (vty, "mpls_te_link_maxbw: Something wrong!%s", VTY_NEWLINE); | |
1657 | return CMD_WARNING; | |
1658 | } | |
1659 | ||
1660 | ntohf (&lp->max_bw.value, &f1); | |
1661 | if (sscanf (argv[0], "%g", &f2) != 1) | |
1662 | { | |
6099b3b5 | 1663 | vty_out (vty, "mpls_te_link_maxbw: fscanf: %s%s", safe_strerror (errno), VTY_NEWLINE); |
718e3744 | 1664 | return CMD_WARNING; |
1665 | } | |
1666 | ||
1667 | if (ntohs (lp->max_bw.header.type) == 0 | |
1668 | || f1 != f2) | |
1669 | { | |
1670 | set_linkparams_max_bw (lp, &f2); | |
1671 | ||
1672 | if (OspfMplsTE.status == enabled) | |
1673 | if (lp->area != NULL) | |
1674 | { | |
1675 | if (lp->flags & LPFLG_LSA_ENGAGED) | |
1676 | ospf_mpls_te_lsa_schedule (lp, REFRESH_THIS_LSA); | |
1677 | else | |
1678 | ospf_mpls_te_lsa_schedule (lp, REORIGINATE_PER_AREA); | |
1679 | } | |
1680 | } | |
1681 | return CMD_SUCCESS; | |
1682 | } | |
1683 | ||
1684 | DEFUN (mpls_te_link_max_rsv_bw, | |
1685 | mpls_te_link_max_rsv_bw_cmd, | |
1686 | "mpls-te link max-rsv-bw BANDWIDTH", | |
1687 | "MPLS-TE specific commands\n" | |
1688 | "Configure MPLS-TE link parameters\n" | |
1689 | "Maximum bandwidth that may be reserved\n" | |
1690 | "Bytes/second (IEEE floating point format)\n") | |
1691 | { | |
1692 | struct interface *ifp = (struct interface *) vty->index; | |
1693 | struct mpls_te_link *lp; | |
1694 | float f1, f2; | |
1695 | ||
1696 | if ((lp = lookup_linkparams_by_ifp (ifp)) == NULL) | |
1697 | { | |
1698 | vty_out (vty, "mpls_te_link_max_rsv_bw: Something wrong!%s", VTY_NEWLINE); | |
1699 | return CMD_WARNING; | |
1700 | } | |
1701 | ||
1702 | ntohf (&lp->max_rsv_bw.value, &f1); | |
1703 | if (sscanf (argv[0], "%g", &f2) != 1) | |
1704 | { | |
6099b3b5 | 1705 | vty_out (vty, "mpls_te_link_max_rsv_bw: fscanf: %s%s", safe_strerror (errno), VTY_NEWLINE); |
718e3744 | 1706 | return CMD_WARNING; |
1707 | } | |
1708 | ||
1709 | if (ntohs (lp->max_rsv_bw.header.type) == 0 | |
1710 | || f1 != f2) | |
1711 | { | |
1712 | set_linkparams_max_rsv_bw (lp, &f2); | |
1713 | ||
1714 | if (OspfMplsTE.status == enabled) | |
1715 | if (lp->area != NULL) | |
1716 | { | |
1717 | if (lp->flags & LPFLG_LSA_ENGAGED) | |
1718 | ospf_mpls_te_lsa_schedule (lp, REFRESH_THIS_LSA); | |
1719 | else | |
1720 | ospf_mpls_te_lsa_schedule (lp, REORIGINATE_PER_AREA); | |
1721 | } | |
1722 | } | |
1723 | return CMD_SUCCESS; | |
1724 | } | |
1725 | ||
1726 | DEFUN (mpls_te_link_unrsv_bw, | |
1727 | mpls_te_link_unrsv_bw_cmd, | |
1728 | "mpls-te link unrsv-bw <0-7> BANDWIDTH", | |
1729 | "MPLS-TE specific commands\n" | |
1730 | "Configure MPLS-TE link parameters\n" | |
1731 | "Unreserved bandwidth at each priority level\n" | |
1732 | "Priority\n" | |
1733 | "Bytes/second (IEEE floating point format)\n") | |
1734 | { | |
1735 | struct interface *ifp = (struct interface *) vty->index; | |
1736 | struct mpls_te_link *lp; | |
1737 | int priority; | |
1738 | float f1, f2; | |
1739 | ||
1740 | if ((lp = lookup_linkparams_by_ifp (ifp)) == NULL) | |
1741 | { | |
1742 | vty_out (vty, "mpls_te_link_unrsv_bw: Something wrong!%s", VTY_NEWLINE); | |
1743 | return CMD_WARNING; | |
1744 | } | |
1745 | ||
1746 | /* We don't have to consider about range check here. */ | |
1747 | if (sscanf (argv[0], "%d", &priority) != 1) | |
1748 | { | |
6099b3b5 | 1749 | vty_out (vty, "mpls_te_link_unrsv_bw: fscanf: %s%s", safe_strerror (errno), VTY_NEWLINE); |
718e3744 | 1750 | return CMD_WARNING; |
1751 | } | |
1752 | ||
1753 | ntohf (&lp->unrsv_bw.value [priority], &f1); | |
1754 | if (sscanf (argv[1], "%g", &f2) != 1) | |
1755 | { | |
6099b3b5 | 1756 | vty_out (vty, "mpls_te_link_unrsv_bw: fscanf: %s%s", safe_strerror (errno), VTY_NEWLINE); |
718e3744 | 1757 | return CMD_WARNING; |
1758 | } | |
1759 | ||
1760 | if (ntohs (lp->unrsv_bw.header.type) == 0 | |
1761 | || f1 != f2) | |
1762 | { | |
1763 | set_linkparams_unrsv_bw (lp, priority, &f2); | |
1764 | ||
1765 | if (OspfMplsTE.status == enabled) | |
1766 | if (lp->area != NULL) | |
1767 | { | |
1768 | if (lp->flags & LPFLG_LSA_ENGAGED) | |
1769 | ospf_mpls_te_lsa_schedule (lp, REFRESH_THIS_LSA); | |
1770 | else | |
1771 | ospf_mpls_te_lsa_schedule (lp, REORIGINATE_PER_AREA); | |
1772 | } | |
1773 | } | |
1774 | return CMD_SUCCESS; | |
1775 | } | |
1776 | ||
1777 | DEFUN (mpls_te_link_rsc_clsclr, | |
1778 | mpls_te_link_rsc_clsclr_cmd, | |
1779 | "mpls-te link rsc-clsclr BITPATTERN", | |
1780 | "MPLS-TE specific commands\n" | |
1781 | "Configure MPLS-TE link parameters\n" | |
1782 | "Administrative group membership\n" | |
1783 | "32-bit Hexadecimal value (ex. 0xa1)\n") | |
1784 | { | |
1785 | struct interface *ifp = (struct interface *) vty->index; | |
1786 | struct mpls_te_link *lp; | |
1787 | unsigned long value; | |
1788 | ||
1789 | if ((lp = lookup_linkparams_by_ifp (ifp)) == NULL) | |
1790 | { | |
1791 | vty_out (vty, "mpls_te_link_rsc_clsclr: Something wrong!%s", VTY_NEWLINE); | |
1792 | return CMD_WARNING; | |
1793 | } | |
1794 | ||
1795 | if (sscanf (argv[0], "0x%lx", &value) != 1) | |
1796 | { | |
6099b3b5 | 1797 | vty_out (vty, "mpls_te_link_rsc_clsclr: fscanf: %s%s", safe_strerror (errno), VTY_NEWLINE); |
718e3744 | 1798 | return CMD_WARNING; |
1799 | } | |
1800 | ||
1801 | if (ntohs (lp->rsc_clsclr.header.type) == 0 | |
1802 | || ntohl (lp->rsc_clsclr.value) != value) | |
1803 | { | |
1804 | set_linkparams_rsc_clsclr (lp, value); | |
1805 | ||
1806 | if (OspfMplsTE.status == enabled) | |
1807 | if (lp->area != NULL) | |
1808 | { | |
1809 | if (lp->flags & LPFLG_LSA_ENGAGED) | |
1810 | ospf_mpls_te_lsa_schedule (lp, REFRESH_THIS_LSA); | |
1811 | else | |
1812 | ospf_mpls_te_lsa_schedule (lp, REORIGINATE_PER_AREA); | |
1813 | } | |
1814 | } | |
1815 | return CMD_SUCCESS; | |
1816 | } | |
1817 | ||
1818 | DEFUN (show_mpls_te_router, | |
1819 | show_mpls_te_router_cmd, | |
1820 | "show mpls-te router", | |
1821 | SHOW_STR | |
1822 | "MPLS-TE information\n" | |
1823 | "Router information\n") | |
1824 | { | |
1825 | if (OspfMplsTE.status == enabled) | |
1826 | { | |
1827 | vty_out (vty, "--- MPLS-TE router parameters ---%s", | |
1828 | VTY_NEWLINE); | |
1829 | ||
1830 | if (ntohs (OspfMplsTE.router_addr.header.type) != 0) | |
1831 | show_vty_router_addr (vty, &OspfMplsTE.router_addr.header); | |
1832 | else if (vty != NULL) | |
1833 | vty_out (vty, " N/A%s", VTY_NEWLINE); | |
1834 | } | |
1835 | return CMD_SUCCESS; | |
1836 | } | |
1837 | ||
1838 | static void | |
1839 | show_mpls_te_link_sub (struct vty *vty, struct interface *ifp) | |
1840 | { | |
1841 | struct mpls_te_link *lp; | |
1842 | struct te_tlv_header *tlvh; | |
1843 | ||
1844 | if ((OspfMplsTE.status == enabled) | |
1845 | && (! if_is_loopback (ifp) && if_is_up (ifp) && ospf_oi_count (ifp) > 0) | |
1846 | && ((lp = lookup_linkparams_by_ifp (ifp)) != NULL)) | |
1847 | { | |
1848 | vty_out (vty, "-- MPLS-TE link parameters for %s --%s", | |
1849 | ifp->name, VTY_NEWLINE); | |
1850 | ||
1851 | show_vty_link_subtlv_link_type (vty, &lp->link_type.header); | |
1852 | show_vty_link_subtlv_link_id (vty, &lp->link_id.header); | |
1853 | ||
1854 | if ((tlvh = (struct te_tlv_header *) lp->lclif_ipaddr) != NULL) | |
1855 | show_vty_link_subtlv_lclif_ipaddr (vty, tlvh); | |
1856 | if ((tlvh = (struct te_tlv_header *) lp->rmtif_ipaddr) != NULL) | |
1857 | show_vty_link_subtlv_rmtif_ipaddr (vty, tlvh); | |
1858 | ||
1859 | show_vty_link_subtlv_te_metric (vty, &lp->te_metric.header); | |
1860 | ||
1861 | show_vty_link_subtlv_max_bw (vty, &lp->max_bw.header); | |
1862 | show_vty_link_subtlv_max_rsv_bw (vty, &lp->max_rsv_bw.header); | |
1863 | show_vty_link_subtlv_unrsv_bw (vty, &lp->unrsv_bw.header); | |
1864 | show_vty_link_subtlv_rsc_clsclr (vty, &lp->rsc_clsclr.header); | |
1865 | } | |
1866 | else | |
1867 | { | |
1868 | vty_out (vty, " %s: MPLS-TE is disabled on this interface%s", | |
1869 | ifp->name, VTY_NEWLINE); | |
1870 | } | |
1871 | ||
1872 | return; | |
1873 | } | |
1874 | ||
1875 | DEFUN (show_mpls_te_link, | |
1876 | show_mpls_te_link_cmd, | |
1877 | "show mpls-te interface [INTERFACE]", | |
1878 | SHOW_STR | |
1879 | "MPLS-TE information\n" | |
1880 | "Interface information\n" | |
1881 | "Interface name\n") | |
1882 | { | |
1883 | struct interface *ifp; | |
1eb8ef25 | 1884 | struct listnode *node, *nnode; |
718e3744 | 1885 | |
1886 | /* Show All Interfaces. */ | |
1887 | if (argc == 0) | |
eb1ce605 | 1888 | { |
b2d7c082 | 1889 | for (ALL_LIST_ELEMENTS (vrf_iflist (VRF_DEFAULT), node, nnode, ifp)) |
1eb8ef25 | 1890 | show_mpls_te_link_sub (vty, ifp); |
eb1ce605 | 1891 | } |
718e3744 | 1892 | /* Interface name is specified. */ |
1893 | else | |
1894 | { | |
1895 | if ((ifp = if_lookup_by_name (argv[0])) == NULL) | |
1896 | vty_out (vty, "No such interface name%s", VTY_NEWLINE); | |
1897 | else | |
1898 | show_mpls_te_link_sub (vty, ifp); | |
1899 | } | |
1900 | ||
1901 | return CMD_SUCCESS; | |
1902 | } | |
1903 | ||
1904 | static void | |
1905 | ospf_mpls_te_register_vty (void) | |
1906 | { | |
1907 | install_element (VIEW_NODE, &show_mpls_te_router_cmd); | |
1908 | install_element (VIEW_NODE, &show_mpls_te_link_cmd); | |
1909 | install_element (ENABLE_NODE, &show_mpls_te_router_cmd); | |
1910 | install_element (ENABLE_NODE, &show_mpls_te_link_cmd); | |
1911 | ||
1912 | install_element (OSPF_NODE, &mpls_te_cmd); | |
1913 | install_element (OSPF_NODE, &no_mpls_te_cmd); | |
813d4307 | 1914 | install_element (OSPF_NODE, &no_mpls_te_val_cmd); |
718e3744 | 1915 | install_element (OSPF_NODE, &mpls_te_on_cmd); |
1916 | install_element (OSPF_NODE, &mpls_te_router_addr_cmd); | |
1917 | ||
1918 | install_element (INTERFACE_NODE, &mpls_te_link_metric_cmd); | |
1919 | install_element (INTERFACE_NODE, &mpls_te_link_maxbw_cmd); | |
1920 | install_element (INTERFACE_NODE, &mpls_te_link_max_rsv_bw_cmd); | |
1921 | install_element (INTERFACE_NODE, &mpls_te_link_unrsv_bw_cmd); | |
1922 | install_element (INTERFACE_NODE, &mpls_te_link_rsc_clsclr_cmd); | |
1923 | ||
1924 | return; | |
1925 | } |