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