2 * ospf_ldp_sync.c: OSPF LDP-IGP Sync handling routines
3 * Copyright (C) 2020 Volta Networks, Inc.
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License as published by the Free
7 * Software Foundation; either version 2 of the License, or (at your option)
10 * This program is distributed in the hope that it will be useful, but WITHOUT
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
15 * You should have received a copy of the GNU General Public License along
16 * with this program; see the file COPYING; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
38 #include "ospf_interface.h"
40 #include "ospf_ldp_sync.h"
41 #include "ospf_dump.h"
44 extern struct zclient
*zclient
;
47 * LDP-SYNC msg between IGP and LDP
49 int ospf_ldp_sync_state_update(struct ldp_igp_sync_if_state state
)
52 struct interface
*ifp
;
54 /* if ospf is not enabled or LDP-SYNC is not configured ignore */
55 ospf
= ospf_lookup_by_vrf_id(VRF_DEFAULT
);
57 !CHECK_FLAG(ospf
->ldp_sync_cmd
.flags
, LDP_SYNC_FLAG_ENABLE
))
60 /* received ldp-sync interface state from LDP */
61 ifp
= if_lookup_by_index(state
.ifindex
, VRF_DEFAULT
);
62 if (ifp
== NULL
|| if_is_loopback(ifp
))
65 ols_debug("ldp_sync: rcvd %s from LDP if %s",
66 state
.sync_start
? "sync-start" : "sync-complete",
69 ospf_ldp_sync_if_start(ifp
, false);
71 ospf_ldp_sync_if_complete(ifp
);
76 int ospf_ldp_sync_announce_update(struct ldp_igp_sync_announce announce
)
80 struct interface
*ifp
;
82 /* if ospf is not enabled or LDP-SYNC is not configured ignore */
83 ospf
= ospf_lookup_by_vrf_id(VRF_DEFAULT
);
85 !CHECK_FLAG(ospf
->ldp_sync_cmd
.flags
, LDP_SYNC_FLAG_ENABLE
))
88 if (announce
.proto
!= ZEBRA_ROUTE_LDP
)
91 ols_debug("ldp_sync: rcvd announce from LDP");
93 /* LDP just started up:
94 * set cost to LSInfinity
95 * send request to LDP for LDP-SYNC state for each interface
97 vrf
= vrf_lookup_by_id(ospf
->vrf_id
);
98 FOR_ALL_INTERFACES (vrf
, ifp
)
99 ospf_ldp_sync_if_start(ifp
, true);
104 void ospf_ldp_sync_state_req_msg(struct interface
*ifp
)
106 struct ldp_igp_sync_if_state_req request
;
108 ols_debug("ldp_sync: send state request to LDP for %s", ifp
->name
);
110 memset(&request
, 0, sizeof(request
));
111 strlcpy(request
.name
, ifp
->name
, sizeof(ifp
->name
));
112 request
.proto
= LDP_IGP_SYNC_IF_STATE_REQUEST
;
113 request
.ifindex
= ifp
->ifindex
;
115 zclient_send_opaque(zclient
, LDP_IGP_SYNC_IF_STATE_REQUEST
,
116 (uint8_t *)&request
, sizeof(request
));
120 * LDP-SYNC general interface routines
122 void ospf_ldp_sync_if_init(struct ospf_interface
*oi
)
124 struct ospf_if_params
*params
;
125 struct ldp_sync_info
*ldp_sync_info
;
126 struct interface
*ifp
= oi
->ifp
;
128 /* called when OSPF is configured on an interface:
129 * if LDP-IGP Sync is configured globally set state
130 * if ptop interface inform LDP LDP-SYNC is enabled
132 if (if_is_loopback(ifp
) || (ifp
->vrf_id
!= VRF_DEFAULT
) ||
133 !(CHECK_FLAG(oi
->ospf
->ldp_sync_cmd
.flags
, LDP_SYNC_FLAG_ENABLE
)))
136 ols_debug("ldp_sync: init if %s",ifp
->name
);
137 params
= IF_DEF_PARAMS(ifp
);
138 if (params
->ldp_sync_info
== NULL
)
139 params
->ldp_sync_info
= ldp_sync_info_create();
141 ldp_sync_info
= params
->ldp_sync_info
;
143 /* specifed on interface overrides global config. */
144 if (!CHECK_FLAG(ldp_sync_info
->flags
, LDP_SYNC_FLAG_HOLDDOWN
))
145 ldp_sync_info
->holddown
= oi
->ospf
->ldp_sync_cmd
.holddown
;
147 if (!CHECK_FLAG(ldp_sync_info
->flags
, LDP_SYNC_FLAG_IF_CONFIG
))
148 ldp_sync_info
->enabled
= LDP_IGP_SYNC_ENABLED
;
150 if ((params
->type
== OSPF_IFTYPE_POINTOPOINT
||
151 if_is_pointopoint(ifp
)) &&
152 ldp_sync_info
->enabled
== LDP_IGP_SYNC_ENABLED
)
153 ldp_sync_info
->state
= LDP_IGP_SYNC_STATE_REQUIRED_NOT_UP
;
156 void ospf_ldp_sync_if_start(struct interface
*ifp
, bool send_state_req
)
158 struct ospf_if_params
*params
;
159 struct ldp_sync_info
*ldp_sync_info
;
161 if (if_is_loopback(ifp
))
164 params
= IF_DEF_PARAMS(ifp
);
165 ldp_sync_info
= params
->ldp_sync_info
;
167 /* Start LDP-SYNC on this interface:
168 * set cost of interface to LSInfinity so traffic will use different
169 * interface until LDP has learned all labels from peer
170 * start holddown timer if configured
171 * send msg to LDP to get LDP-SYNC state
174 ldp_sync_info
->enabled
== LDP_IGP_SYNC_ENABLED
&&
175 ldp_sync_info
->state
!= LDP_IGP_SYNC_STATE_NOT_REQUIRED
) {
176 ols_debug("ldp_sync: start on if %s state: %s",
177 ifp
->name
, "Holding down until Sync");
178 ldp_sync_info
->state
= LDP_IGP_SYNC_STATE_REQUIRED_NOT_UP
;
179 ospf_if_recalculate_output_cost(ifp
);
180 ospf_ldp_sync_holddown_timer_add(ifp
);
183 ospf_ldp_sync_state_req_msg(ifp
);
187 void ospf_ldp_sync_if_complete(struct interface
*ifp
)
189 struct ospf_if_params
*params
;
190 struct ldp_sync_info
*ldp_sync_info
;
192 if (if_is_loopback(ifp
))
195 params
= IF_DEF_PARAMS(ifp
);
196 ldp_sync_info
= params
->ldp_sync_info
;
198 /* received sync-complete from LDP:
201 * restore interface cost to original value
203 if (ldp_sync_info
&& ldp_sync_info
->enabled
== LDP_IGP_SYNC_ENABLED
) {
204 if (ldp_sync_info
->state
== LDP_IGP_SYNC_STATE_REQUIRED_NOT_UP
)
205 ldp_sync_info
->state
= LDP_IGP_SYNC_STATE_REQUIRED_UP
;
206 THREAD_OFF(ldp_sync_info
->t_holddown
);
207 ospf_if_recalculate_output_cost(ifp
);
211 void ospf_ldp_sync_handle_client_close(struct zapi_client_close_info
*info
)
215 struct interface
*ifp
;
217 /* if ospf is not enabled or LDP-SYNC is not configured ignore */
218 ospf
= ospf_lookup_by_vrf_id(VRF_DEFAULT
);
220 || !CHECK_FLAG(ospf
->ldp_sync_cmd
.flags
, LDP_SYNC_FLAG_ENABLE
))
223 /* Check if the LDP main client session closed */
224 if (info
->proto
!= ZEBRA_ROUTE_LDP
|| info
->session_id
== 0)
227 /* Handle the zebra notification that the LDP client session closed.
228 * set cost to LSInfinity
229 * send request to LDP for LDP-SYNC state for each interface
231 zlog_err("ldp_sync: LDP down");
233 vrf
= vrf_lookup_by_id(ospf
->vrf_id
);
234 FOR_ALL_INTERFACES (vrf
, ifp
)
235 ospf_ldp_sync_ldp_fail(ifp
);
238 void ospf_ldp_sync_ldp_fail(struct interface
*ifp
)
240 struct ospf_if_params
*params
;
241 struct ldp_sync_info
*ldp_sync_info
;
243 if (if_is_loopback(ifp
))
246 params
= IF_DEF_PARAMS(ifp
);
247 ldp_sync_info
= params
->ldp_sync_info
;
249 /* LDP client close detected:
250 * stop holddown timer
251 * set cost of interface to LSInfinity so traffic will use different
252 * interface until LDP has learned all labels from peer
255 ldp_sync_info
->enabled
== LDP_IGP_SYNC_ENABLED
&&
256 ldp_sync_info
->state
!= LDP_IGP_SYNC_STATE_NOT_REQUIRED
) {
257 THREAD_OFF(ldp_sync_info
->t_holddown
);
258 ldp_sync_info
->state
= LDP_IGP_SYNC_STATE_REQUIRED_NOT_UP
;
259 ospf_if_recalculate_output_cost(ifp
);
263 void ospf_ldp_sync_if_down(struct interface
*ifp
)
265 struct ospf_if_params
*params
;
266 struct ldp_sync_info
*ldp_sync_info
;
268 if (if_is_loopback(ifp
))
271 params
= IF_DEF_PARAMS(ifp
);
272 ldp_sync_info
= params
->ldp_sync_info
;
274 if (ldp_sync_if_down(ldp_sync_info
) == false)
277 ols_debug("ldp_sync: down on if %s", ifp
->name
);
280 * can occur from a link down or changing config
281 * ospf network type change interface is brought down/up
283 switch (ldp_sync_info
->state
) {
284 case LDP_IGP_SYNC_STATE_REQUIRED_NOT_UP
:
285 case LDP_IGP_SYNC_STATE_REQUIRED_UP
:
286 if (params
->type
!= OSPF_IFTYPE_POINTOPOINT
&&
287 !if_is_pointopoint(ifp
))
288 /* LDP-SYNC not able to run on non-ptop interface */
289 ldp_sync_info
->state
= LDP_IGP_SYNC_STATE_NOT_REQUIRED
;
291 case LDP_IGP_SYNC_STATE_NOT_REQUIRED
:
292 if (params
->type
== OSPF_IFTYPE_POINTOPOINT
||
293 if_is_pointopoint(ifp
))
294 /* LDP-SYNC is able to run on ptop interface */
295 ldp_sync_info
->state
=
296 LDP_IGP_SYNC_STATE_REQUIRED_NOT_UP
;
303 void ospf_ldp_sync_if_remove(struct interface
*ifp
, bool remove
)
305 struct ospf_if_params
*params
;
306 struct ldp_sync_info
*ldp_sync_info
;
308 params
= IF_DEF_PARAMS(ifp
);
309 if (params
->ldp_sync_info
== NULL
)
312 ldp_sync_info
= params
->ldp_sync_info
;
314 /* Stop LDP-SYNC on this interface:
315 * if holddown timer is running stop it
316 * delete ldp instance on interface
319 ols_debug("ldp_sync: Removed from if %s", ifp
->name
);
321 THREAD_OFF(ldp_sync_info
->t_holddown
);
323 ldp_sync_info
->state
= LDP_IGP_SYNC_STATE_NOT_REQUIRED
;
324 ospf_if_recalculate_output_cost(ifp
);
325 if (!CHECK_FLAG(ldp_sync_info
->flags
, LDP_SYNC_FLAG_IF_CONFIG
))
326 ldp_sync_info
->enabled
= LDP_IGP_SYNC_DEFAULT
;
328 ldp_sync_info_free((struct ldp_sync_info
**)&(ldp_sync_info
));
329 params
->ldp_sync_info
= NULL
;
333 static int ospf_ldp_sync_ism_change(struct ospf_interface
*oi
, int state
,
336 /* Terminal state or regression */
338 case ISM_PointToPoint
:
339 /* If LDP-SYNC is configure on interface then start */
340 ospf_ldp_sync_if_start(oi
->ifp
, true);
343 /* If LDP-SYNC is configure on this interface then stop it */
344 ospf_ldp_sync_if_down(oi
->ifp
);
353 * LDP-SYNC holddown timer routines
355 static int ospf_ldp_sync_holddown_timer(struct thread
*thread
)
357 struct interface
*ifp
;
358 struct ospf_if_params
*params
;
359 struct ldp_sync_info
*ldp_sync_info
;
361 /* holddown timer expired:
362 * didn't receive msg from LDP indicating sync-complete
363 * restore interface cost to original value
365 ifp
= THREAD_ARG(thread
);
366 params
= IF_DEF_PARAMS(ifp
);
367 if (params
->ldp_sync_info
) {
368 ldp_sync_info
= params
->ldp_sync_info
;
370 ldp_sync_info
->state
= LDP_IGP_SYNC_STATE_REQUIRED_UP
;
372 ols_debug("ldp_sync: holddown timer expired for %s state: %s",
373 ifp
->name
, "Sync achieved");
375 ospf_if_recalculate_output_cost(ifp
);
380 void ospf_ldp_sync_holddown_timer_add(struct interface
*ifp
)
382 struct ospf_if_params
*params
;
383 struct ldp_sync_info
*ldp_sync_info
;
385 params
= IF_DEF_PARAMS(ifp
);
386 ldp_sync_info
= params
->ldp_sync_info
;
388 /* Start holddown timer:
389 * this timer is used to keep interface cost at LSInfinity
390 * once expires returns cost to original value
391 * if timer is already running or holddown time is off just return
393 if (ldp_sync_info
->t_holddown
||
394 ldp_sync_info
->holddown
== LDP_IGP_SYNC_HOLDDOWN_DEFAULT
)
397 ols_debug("ldp_sync: start holddown timer for %s time %d",
398 ifp
->name
, ldp_sync_info
->holddown
);
400 thread_add_timer(master
, ospf_ldp_sync_holddown_timer
,
401 ifp
, ldp_sync_info
->holddown
,
402 &ldp_sync_info
->t_holddown
);
406 * LDP-SYNC exit routes.
408 void ospf_ldp_sync_gbl_exit(struct ospf
*ospf
, bool remove
)
410 struct interface
*ifp
;
413 /* ospf is being removed
414 * stop any holddown timers
416 if (CHECK_FLAG(ospf
->ldp_sync_cmd
.flags
, LDP_SYNC_FLAG_ENABLE
)) {
417 /* unregister with opaque client to recv LDP-IGP Sync msgs */
418 zclient_unregister_opaque(zclient
,
419 LDP_IGP_SYNC_IF_STATE_UPDATE
);
420 zclient_unregister_opaque(zclient
,
421 LDP_IGP_SYNC_ANNOUNCE_UPDATE
);
423 /* disable LDP globally */
424 UNSET_FLAG(ospf
->ldp_sync_cmd
.flags
, LDP_SYNC_FLAG_ENABLE
);
425 UNSET_FLAG(ospf
->ldp_sync_cmd
.flags
, LDP_SYNC_FLAG_HOLDDOWN
);
426 ospf
->ldp_sync_cmd
.holddown
= LDP_IGP_SYNC_HOLDDOWN_DEFAULT
;
428 /* turn off LDP-IGP Sync on all OSPF interfaces */
429 vrf
= vrf_lookup_by_id(ospf
->vrf_id
);
430 FOR_ALL_INTERFACES (vrf
, ifp
)
431 ospf_ldp_sync_if_remove(ifp
, remove
);
436 * LDP-SYNC routes used by set commands.
438 void ospf_if_set_ldp_sync_enable(struct ospf
*ospf
, struct interface
*ifp
)
440 struct ospf_if_params
*params
;
441 struct ldp_sync_info
*ldp_sync_info
;
443 /* called when setting LDP-SYNC at the global level:
444 * specifed on interface overrides global config
445 * if ptop link send msg to LDP indicating ldp-sync enabled
447 if (if_is_loopback(ifp
))
450 params
= IF_DEF_PARAMS(ifp
);
451 if (params
->ldp_sync_info
== NULL
)
452 params
->ldp_sync_info
= ldp_sync_info_create();
453 ldp_sync_info
= params
->ldp_sync_info
;
455 /* config on interface, overrides global config. */
456 if (CHECK_FLAG(ldp_sync_info
->flags
, LDP_SYNC_FLAG_IF_CONFIG
))
457 if (ldp_sync_info
->enabled
!= LDP_IGP_SYNC_ENABLED
)
460 ldp_sync_info
->enabled
= LDP_IGP_SYNC_ENABLED
;
462 ols_debug("ldp_sync: enable if %s", ifp
->name
);
464 /* send message to LDP if ptop link */
465 if (params
->type
== OSPF_IFTYPE_POINTOPOINT
||
466 if_is_pointopoint(ifp
)) {
467 ldp_sync_info
->state
= LDP_IGP_SYNC_STATE_REQUIRED_NOT_UP
;
468 ospf_ldp_sync_state_req_msg(ifp
);
470 ldp_sync_info
->state
= LDP_IGP_SYNC_STATE_NOT_REQUIRED
;
471 zlog_debug("ldp_sync: Sync only runs on P2P links %s",
476 void ospf_if_set_ldp_sync_holddown(struct ospf
*ospf
, struct interface
*ifp
)
478 struct ospf_if_params
*params
;
479 struct ldp_sync_info
*ldp_sync_info
;
481 /* called when setting LDP-SYNC at the global level:
482 * specifed on interface overrides global config.
484 if (if_is_loopback(ifp
))
487 params
= IF_DEF_PARAMS(ifp
);
488 if (params
->ldp_sync_info
== NULL
)
489 params
->ldp_sync_info
= ldp_sync_info_create();
490 ldp_sync_info
= params
->ldp_sync_info
;
492 /* config on interface, overrides global config. */
493 if (CHECK_FLAG(ldp_sync_info
->flags
, LDP_SYNC_FLAG_HOLDDOWN
))
495 if (CHECK_FLAG(ospf
->ldp_sync_cmd
.flags
, LDP_SYNC_FLAG_HOLDDOWN
))
496 ldp_sync_info
->holddown
= ospf
->ldp_sync_cmd
.holddown
;
498 ldp_sync_info
->holddown
= LDP_IGP_SYNC_HOLDDOWN_DEFAULT
;
502 * LDP-SYNC routines used by show commands.
505 void ospf_ldp_sync_show_info(struct vty
*vty
, struct ospf
*ospf
,
506 json_object
*json_vrf
, bool use_json
)
509 if (CHECK_FLAG(ospf
->ldp_sync_cmd
.flags
, LDP_SYNC_FLAG_ENABLE
)) {
511 json_object_boolean_true_add(json_vrf
,
512 "MplsLdpIgpSyncEnabled");
513 json_object_int_add(json_vrf
, "MplsLdpIgpSyncHolddown",
514 ospf
->ldp_sync_cmd
.holddown
);
516 vty_out(vty
, " MPLS LDP-IGP Sync is enabled\n");
517 if (ospf
->ldp_sync_cmd
.holddown
== 0)
519 " MPLS LDP-IGP Sync holddown timer is disabled\n");
522 " MPLS LDP-IGP Sync holddown timer %d sec\n",
523 ospf
->ldp_sync_cmd
.holddown
);
528 static void show_ip_ospf_mpls_ldp_interface_sub(struct vty
*vty
,
529 struct ospf_interface
*oi
,
530 struct interface
*ifp
,
531 json_object
*json_interface_sub
,
534 const char *ldp_state
;
535 struct ospf_if_params
*params
;
536 char timebuf
[OSPF_TIME_DUMP_SIZE
];
537 struct ldp_sync_info
*ldp_sync_info
;
539 params
= IF_DEF_PARAMS(oi
->ifp
);
540 if (params
->ldp_sync_info
== NULL
)
543 ldp_sync_info
= params
->ldp_sync_info
;
545 if (ldp_sync_info
->enabled
== LDP_IGP_SYNC_ENABLED
)
546 json_object_boolean_true_add(json_interface_sub
,
547 "ldpIgpSyncEnabled");
549 json_object_boolean_false_add(json_interface_sub
,
550 "ldpIgpSyncEnabled");
552 json_object_int_add(json_interface_sub
, "holdDownTimeInSec",
553 ldp_sync_info
->holddown
);
556 vty_out(vty
, "%-10s\n", ifp
->name
);
557 vty_out(vty
, " LDP-IGP Synchronization enabled: %s\n",
558 ldp_sync_info
->enabled
== LDP_IGP_SYNC_ENABLED
561 vty_out(vty
, " Holddown timer in seconds: %u\n",
562 ldp_sync_info
->holddown
);
565 switch (ldp_sync_info
->state
) {
566 case LDP_IGP_SYNC_STATE_REQUIRED_UP
:
568 json_object_string_add(json_interface_sub
,
572 vty_out(vty
, " State: Sync achieved\n");
574 case LDP_IGP_SYNC_STATE_REQUIRED_NOT_UP
:
575 if (ldp_sync_info
->t_holddown
!= NULL
) {
579 time_store
= monotime_until(
580 &ldp_sync_info
->t_holddown
->u
.sands
,
584 json_object_int_add(json_interface_sub
,
585 "ldpIgpSyncTimeRemainInMsec",
588 json_object_string_add(json_interface_sub
,
590 "Holding down until Sync");
593 " Holddown timer is running %s remaining\n",
595 ldp_sync_info
->t_holddown
,
600 " State: Holding down until Sync\n");
604 json_object_string_add(json_interface_sub
,
606 "Sync not achieved");
608 vty_out(vty
, " State: Sync not achieved\n");
611 case LDP_IGP_SYNC_STATE_NOT_REQUIRED
:
613 if (IF_DEF_PARAMS(ifp
)->type
!= OSPF_IFTYPE_POINTOPOINT
&&
614 !if_is_pointopoint(ifp
))
615 ldp_state
= "Sync not required: non-p2p link";
617 ldp_state
= "Sync not required";
620 json_object_string_add(json_interface_sub
,
624 vty_out(vty
, " State: %s\n", ldp_state
);
629 static int show_ip_ospf_mpls_ldp_interface_common(struct vty
*vty
,
635 struct interface
*ifp
;
636 struct vrf
*vrf
= vrf_lookup_by_id(ospf
->vrf_id
);
637 json_object
*json_interface_sub
= NULL
;
639 if (intf_name
== NULL
) {
640 /* Show All Interfaces.*/
641 FOR_ALL_INTERFACES (vrf
, ifp
) {
642 struct route_node
*rn
;
643 struct ospf_interface
*oi
;
645 if (ospf_oi_count(ifp
) == 0 && !use_json
) {
647 vty_out(vty
, "%s\n Interface down\n",
651 for (rn
= route_top(IF_OIFS(ifp
)); rn
;
652 rn
= route_next(rn
)) {
657 json_object_new_object();
659 show_ip_ospf_mpls_ldp_interface_sub(
660 vty
, oi
, ifp
, json_interface_sub
,
664 json_object_object_add(
671 /* Interface name is specified. */
672 ifp
= if_lookup_by_name(intf_name
, ospf
->vrf_id
);
674 struct route_node
*rn
;
675 struct ospf_interface
*oi
;
677 if (ospf_oi_count(ifp
) == 0 && !use_json
) {
679 vty_out(vty
, "%s\n OSPF not enabled\n",
682 vty_out(vty
, "%s\n Interface down\n",
686 for (rn
= route_top(IF_OIFS(ifp
)); rn
;
687 rn
= route_next(rn
)) {
692 json_object_new_object();
694 show_ip_ospf_mpls_ldp_interface_sub(
695 vty
, oi
, ifp
, json_interface_sub
,
699 json_object_object_add(
710 * Write the global LDP-SYNC configuration.
712 void ospf_ldp_sync_write_config(struct vty
*vty
, struct ospf
*ospf
)
714 if (CHECK_FLAG(ospf
->ldp_sync_cmd
.flags
, LDP_SYNC_FLAG_ENABLE
))
715 vty_out(vty
, " mpls ldp-sync\n");
716 if (CHECK_FLAG(ospf
->ldp_sync_cmd
.flags
, LDP_SYNC_FLAG_HOLDDOWN
))
717 vty_out(vty
, " mpls ldp-sync holddown %u\n",
718 ospf
->ldp_sync_cmd
.holddown
);
722 * Write the interface LDP-SYNC configuration.
724 void ospf_ldp_sync_if_write_config(struct vty
*vty
,
725 struct ospf_if_params
*params
)
728 struct ldp_sync_info
*ldp_sync_info
;
730 ldp_sync_info
= params
->ldp_sync_info
;
731 if (ldp_sync_info
== NULL
)
734 if (CHECK_FLAG(ldp_sync_info
->flags
, LDP_SYNC_FLAG_IF_CONFIG
)) {
735 if (ldp_sync_info
->enabled
== LDP_IGP_SYNC_ENABLED
)
736 vty_out(vty
, " ip ospf mpls ldp-sync\n");
738 vty_out(vty
, " no ip ospf mpls ldp-sync\n");
740 if (CHECK_FLAG(ldp_sync_info
->flags
, LDP_SYNC_FLAG_HOLDDOWN
))
741 vty_out(vty
, " ip ospf mpls ldp-sync holddown %u\n",
742 ldp_sync_info
->holddown
);
748 #ifndef VTYSH_EXTRACT_PL
749 #include "ospfd/ospf_ldp_sync_clippy.c"
752 DEFPY (ospf_mpls_ldp_sync
,
753 ospf_mpls_ldp_sync_cmd
,
755 "MPLS specific commands\n"
756 "Enable MPLS LDP-IGP Sync\n")
758 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
759 struct vrf
*vrf
= vrf_lookup_by_id(ospf
->vrf_id
);
760 struct interface
*ifp
;
762 if (ospf
->vrf_id
!= VRF_DEFAULT
) {
763 vty_out(vty
, "ldp-sync only runs on DEFAULT VRF\n");
764 return CMD_ERR_NOTHING_TODO
;
767 /* register with opaque client to recv LDP-IGP Sync msgs */
768 zclient_register_opaque(zclient
, LDP_IGP_SYNC_IF_STATE_UPDATE
);
769 zclient_register_opaque(zclient
, LDP_IGP_SYNC_ANNOUNCE_UPDATE
);
771 if (!CHECK_FLAG(ospf
->ldp_sync_cmd
.flags
, LDP_SYNC_FLAG_ENABLE
)) {
772 SET_FLAG(ospf
->ldp_sync_cmd
.flags
, LDP_SYNC_FLAG_ENABLE
);
773 /* turn on LDP-IGP Sync on all ptop OSPF interfaces */
774 FOR_ALL_INTERFACES (vrf
, ifp
)
775 ospf_if_set_ldp_sync_enable(ospf
, ifp
);
780 DEFPY (no_ospf_mpls_ldp_sync
,
781 no_ospf_mpls_ldp_sync_cmd
,
784 "MPLS specific commands\n"
785 "Disable MPLS LDP-IGP Sync\n")
787 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
788 ospf_ldp_sync_gbl_exit(ospf
, false);
792 DEFPY (ospf_mpls_ldp_sync_holddown
,
793 ospf_mpls_ldp_sync_holddown_cmd
,
794 "mpls ldp-sync holddown (1-10000)",
795 "MPLS specific commands\n"
796 "Enable MPLS LDP-IGP Sync\n"
797 "Set holddown timer\n"
800 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
801 struct vrf
*vrf
= vrf_lookup_by_id(ospf
->vrf_id
);
802 struct interface
*ifp
;
804 if (ospf
->vrf_id
!= VRF_DEFAULT
) {
805 vty_out(vty
, "ldp-sync only runs on DEFAULT VRF\n");
806 return CMD_ERR_NOTHING_TODO
;
809 SET_FLAG(ospf
->ldp_sync_cmd
.flags
, LDP_SYNC_FLAG_HOLDDOWN
);
810 ospf
->ldp_sync_cmd
.holddown
= holddown
;
811 /* set holddown time on all OSPF interfaces */
812 FOR_ALL_INTERFACES (vrf
, ifp
)
813 ospf_if_set_ldp_sync_holddown(ospf
, ifp
);
818 DEFPY (no_ospf_mpls_ldp_sync_holddown
,
819 no_ospf_mpls_ldp_sync_holddown_cmd
,
820 "no mpls ldp-sync holddown [<(1-10000)>]",
822 "MPLS specific commands\n"
823 "Disable MPLS LDP-IGP Sync\n"
824 "holddown timer disable\n"
827 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
828 struct vrf
*vrf
= vrf_lookup_by_id(ospf
->vrf_id
);
829 struct interface
*ifp
;
831 if (CHECK_FLAG(ospf
->ldp_sync_cmd
.flags
, LDP_SYNC_FLAG_HOLDDOWN
)) {
832 UNSET_FLAG(ospf
->ldp_sync_cmd
.flags
, LDP_SYNC_FLAG_HOLDDOWN
);
833 ospf
->ldp_sync_cmd
.holddown
= LDP_IGP_SYNC_HOLDDOWN_DEFAULT
;
834 /* turn off holddown timer on all OSPF interfaces */
835 FOR_ALL_INTERFACES (vrf
, ifp
)
836 ospf_if_set_ldp_sync_holddown(ospf
, ifp
);
842 DEFPY (mpls_ldp_sync
,
844 "ip ospf mpls ldp-sync",
846 "OSPF interface commands\n"
850 VTY_DECLVAR_CONTEXT(interface
, ifp
);
851 struct ospf_if_params
*params
;
852 struct ldp_sync_info
*ldp_sync_info
;
854 if (if_is_loopback(ifp
)) {
855 vty_out(vty
, "ldp-sync does not run on loopback interface\n");
856 return CMD_ERR_NOTHING_TODO
;
859 if (ifp
->vrf_id
!= VRF_DEFAULT
) {
860 vty_out(vty
, "ldp-sync only runs on DEFAULT VRF\n");
861 return CMD_ERR_NOTHING_TODO
;
864 params
= IF_DEF_PARAMS(ifp
);
865 if (params
->ldp_sync_info
== NULL
)
866 params
->ldp_sync_info
= ldp_sync_info_create();
868 ldp_sync_info
= params
->ldp_sync_info
;
870 SET_FLAG(ldp_sync_info
->flags
, LDP_SYNC_FLAG_IF_CONFIG
);
871 ldp_sync_info
->enabled
= LDP_IGP_SYNC_ENABLED
;
872 if (params
->type
== OSPF_IFTYPE_POINTOPOINT
|| if_is_pointopoint(ifp
)) {
873 ldp_sync_info
->state
= LDP_IGP_SYNC_STATE_REQUIRED_NOT_UP
;
874 ospf_ldp_sync_state_req_msg(ifp
);
876 zlog_debug("ldp_sync: only runs on P2P links %s", ifp
->name
);
877 ldp_sync_info
->state
= LDP_IGP_SYNC_STATE_NOT_REQUIRED
;
882 DEFPY (no_mpls_ldp_sync
,
883 no_mpls_ldp_sync_cmd
,
884 "no ip ospf mpls ldp-sync",
887 "OSPF interface commands\n"
889 NO_MPLS_LDP_SYNC_STR
)
891 VTY_DECLVAR_CONTEXT(interface
, ifp
);
892 struct ospf_if_params
*params
;
893 struct ldp_sync_info
*ldp_sync_info
;
895 if (if_is_loopback(ifp
)) {
896 vty_out(vty
, "ldp-sync: does not run on loopback interface\n");
897 return CMD_ERR_NOTHING_TODO
;
900 if (ifp
->vrf_id
!= VRF_DEFAULT
) {
901 vty_out(vty
, "ldp-sync only runs on DEFAULT VRF\n");
902 return CMD_ERR_NOTHING_TODO
;
905 params
= IF_DEF_PARAMS(ifp
);
906 if (params
->ldp_sync_info
== NULL
)
907 params
->ldp_sync_info
= ldp_sync_info_create();
909 ldp_sync_info
= params
->ldp_sync_info
;
911 /* disable LDP-SYNC on an interface
912 * stop holddown timer if running
915 SET_FLAG(ldp_sync_info
->flags
, LDP_SYNC_FLAG_IF_CONFIG
);
916 ldp_sync_info
->enabled
= LDP_IGP_SYNC_DEFAULT
;
917 ldp_sync_info
->state
= LDP_IGP_SYNC_STATE_NOT_REQUIRED
;
918 THREAD_OFF(ldp_sync_info
->t_holddown
);
919 ospf_if_recalculate_output_cost(ifp
);
924 DEFPY (mpls_ldp_sync_holddown
,
925 mpls_ldp_sync_holddown_cmd
,
926 "ip ospf mpls ldp-sync holddown (0-10000)",
928 "OSPF interface commands\n"
931 "Time to wait for LDP-SYNC to occur before restoring interface cost\n"
934 VTY_DECLVAR_CONTEXT(interface
, ifp
);
935 struct ospf_if_params
*params
;
936 struct ldp_sync_info
*ldp_sync_info
;
938 if (if_is_loopback(ifp
)) {
939 vty_out(vty
, "ldp-sync: does not run on loopback interface\n");
940 return CMD_ERR_NOTHING_TODO
;
943 if (ifp
->vrf_id
!= VRF_DEFAULT
) {
944 vty_out(vty
, "ldp-sync only runs on DEFAULT VRF\n");
945 return CMD_ERR_NOTHING_TODO
;
948 params
= IF_DEF_PARAMS(ifp
);
949 if (params
->ldp_sync_info
== NULL
)
950 params
->ldp_sync_info
= ldp_sync_info_create();
952 ldp_sync_info
= params
->ldp_sync_info
;
954 SET_FLAG(ldp_sync_info
->flags
, LDP_SYNC_FLAG_HOLDDOWN
);
955 ldp_sync_info
->holddown
= holddown
;
960 DEFPY (no_mpls_ldp_sync_holddown
,
961 no_mpls_ldp_sync_holddown_cmd
,
962 "no ip ospf mpls ldp-sync holddown [<(1-10000)>]",
965 "OSPF interface commands\n"
968 NO_MPLS_LDP_SYNC_HOLDDOWN_STR
971 VTY_DECLVAR_CONTEXT(interface
, ifp
);
972 struct ospf_if_params
*params
;
973 struct ldp_sync_info
*ldp_sync_info
;
976 if (if_is_loopback(ifp
)) {
977 vty_out(vty
, "ldp-sync: does not run on loopback interface\n");
978 return CMD_ERR_NOTHING_TODO
;
981 if (ifp
->vrf_id
!= VRF_DEFAULT
) {
982 vty_out(vty
, "ldp-sync only runs on DEFAULT VRF\n");
983 return CMD_ERR_NOTHING_TODO
;
986 params
= IF_DEF_PARAMS(ifp
);
987 ldp_sync_info
= params
->ldp_sync_info
;
988 if (ldp_sync_info
== NULL
)
991 /* use global configured value if set */
992 if (CHECK_FLAG(ldp_sync_info
->flags
, LDP_SYNC_FLAG_HOLDDOWN
)) {
993 UNSET_FLAG(ldp_sync_info
->flags
, LDP_SYNC_FLAG_HOLDDOWN
);
994 ospf
= ospf_lookup_by_vrf_id(VRF_DEFAULT
);
995 if (ospf
&& CHECK_FLAG(ospf
->ldp_sync_cmd
.flags
,
996 LDP_SYNC_FLAG_HOLDDOWN
))
997 ldp_sync_info
->holddown
= ospf
->ldp_sync_cmd
.holddown
;
999 ldp_sync_info
->holddown
= LDP_IGP_SYNC_HOLDDOWN_DEFAULT
;
1004 DEFPY (show_ip_ospf_mpls_ldp_interface
,
1005 show_ip_ospf_mpls_ldp_interface_cmd
,
1006 "show ip ospf mpls ldp-sync [interface <INTERFACE|all>] [json]",
1009 "OSPF information\n"
1011 "LDP-IGP Sync information\n"
1012 "Interface information\n"
1018 bool uj
= use_json(argc
, argv
);
1019 char *intf_name
= NULL
;
1020 int ret
= CMD_SUCCESS
;
1022 json_object
*json
= NULL
;
1024 if (argv_find(argv
, argc
, "INTERFACE", &idx_intf
))
1025 intf_name
= argv
[idx_intf
]->arg
;
1028 json
= json_object_new_object();
1030 /* Display default ospf (instance 0) info */
1031 ospf
= ospf_lookup_by_vrf_id(VRF_DEFAULT
);
1032 if (ospf
== NULL
|| !ospf
->oi_running
) {
1034 vty_out(vty
, "%s\n", json_object_to_json_string_ext(
1035 json
, JSON_C_TO_STRING_PRETTY
));
1036 json_object_free(json
);
1038 vty_out(vty
, "%% OSPF instance not found\n");
1042 if (!CHECK_FLAG(ospf
->ldp_sync_cmd
.flags
, LDP_SYNC_FLAG_ENABLE
)) {
1044 vty_out(vty
, "%s\n", json_object_to_json_string_ext(
1045 json
, JSON_C_TO_STRING_PRETTY
));
1046 json_object_free(json
);
1048 vty_out(vty
, "LDP-sync is disabled\n");
1052 ret
= show_ip_ospf_mpls_ldp_interface_common(vty
, ospf
, intf_name
,
1055 vty_out(vty
, "%s\n", json_object_to_json_string_ext(
1056 json
, JSON_C_TO_STRING_PRETTY
));
1057 json_object_free(json
);
1063 void ospf_ldp_sync_init(void)
1065 /* Install global ldp-igp sync commands */
1066 install_element(OSPF_NODE
, &ospf_mpls_ldp_sync_cmd
);
1067 install_element(OSPF_NODE
, &no_ospf_mpls_ldp_sync_cmd
);
1068 install_element(OSPF_NODE
, &ospf_mpls_ldp_sync_holddown_cmd
);
1069 install_element(OSPF_NODE
, &no_ospf_mpls_ldp_sync_holddown_cmd
);
1071 /* Interface lsp-igp sync commands */
1072 install_element(INTERFACE_NODE
, &mpls_ldp_sync_cmd
);
1073 install_element(INTERFACE_NODE
, &no_mpls_ldp_sync_cmd
);
1074 install_element(INTERFACE_NODE
, &mpls_ldp_sync_holddown_cmd
);
1075 install_element(INTERFACE_NODE
, &no_mpls_ldp_sync_holddown_cmd
);
1077 /* "show ip ospf mpls ldp interface" commands. */
1078 install_element(VIEW_NODE
, &show_ip_ospf_mpls_ldp_interface_cmd
);
1080 hook_register(ospf_ism_change
, ospf_ldp_sync_ism_change
);