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("%s: rcvd %s from LDP if %s", __func__
,
66 state
.sync_start
? "sync-start" : "sync-complete", ifp
->name
);
68 ospf_ldp_sync_if_start(ifp
, false);
70 ospf_ldp_sync_if_complete(ifp
);
75 int ospf_ldp_sync_announce_update(struct ldp_igp_sync_announce announce
)
79 struct interface
*ifp
;
81 /* if ospf is not enabled or LDP-SYNC is not configured ignore */
82 ospf
= ospf_lookup_by_vrf_id(VRF_DEFAULT
);
84 !CHECK_FLAG(ospf
->ldp_sync_cmd
.flags
, LDP_SYNC_FLAG_ENABLE
))
87 if (announce
.proto
!= ZEBRA_ROUTE_LDP
)
90 ols_debug("%s: rcvd announce from LDP", __func__
);
92 /* LDP just started up:
93 * set cost to LSInfinity
94 * send request to LDP for LDP-SYNC state for each interface
96 vrf
= vrf_lookup_by_id(ospf
->vrf_id
);
97 FOR_ALL_INTERFACES (vrf
, ifp
)
98 ospf_ldp_sync_if_start(ifp
, true);
103 void ospf_ldp_sync_state_req_msg(struct interface
*ifp
)
105 struct ldp_igp_sync_if_state_req request
;
107 ols_debug("%s: send state request to LDP for %s", __func__
, ifp
->name
);
109 memset(&request
, 0, sizeof(request
));
110 strlcpy(request
.name
, ifp
->name
, sizeof(ifp
->name
));
111 request
.proto
= LDP_IGP_SYNC_IF_STATE_REQUEST
;
112 request
.ifindex
= ifp
->ifindex
;
114 zclient_send_opaque(zclient
, LDP_IGP_SYNC_IF_STATE_REQUEST
,
115 (uint8_t *)&request
, sizeof(request
));
119 * LDP-SYNC general interface routines
121 void ospf_ldp_sync_if_init(struct ospf_interface
*oi
)
123 struct ospf_if_params
*params
;
124 struct ldp_sync_info
*ldp_sync_info
;
125 struct interface
*ifp
= oi
->ifp
;
127 /* called when OSPF is configured on an interface:
128 * if LDP-IGP Sync is configured globally set state
129 * if ptop interface inform LDP LDP-SYNC is enabled
131 if (if_is_loopback(ifp
) || (ifp
->vrf
->vrf_id
!= VRF_DEFAULT
)
132 || !(CHECK_FLAG(oi
->ospf
->ldp_sync_cmd
.flags
,
133 LDP_SYNC_FLAG_ENABLE
)))
136 ols_debug("%s: init if %s", __func__
, 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 /* specified 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("%s: start on if %s state: %s", __func__
, ifp
->name
,
177 "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("%s: LDP down", __func__
);
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("%s: down on if %s", __func__
, 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("%s: Removed from if %s", __func__
, 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(&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 void 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("%s: holddown timer expired for %s state: %s",
373 __func__
, ifp
->name
, "Sync achieved");
375 ospf_if_recalculate_output_cost(ifp
);
379 void ospf_ldp_sync_holddown_timer_add(struct interface
*ifp
)
381 struct ospf_if_params
*params
;
382 struct ldp_sync_info
*ldp_sync_info
;
384 params
= IF_DEF_PARAMS(ifp
);
385 ldp_sync_info
= params
->ldp_sync_info
;
387 /* Start holddown timer:
388 * this timer is used to keep interface cost at LSInfinity
389 * once expires returns cost to original value
390 * if timer is already running or holddown time is off just return
392 if (ldp_sync_info
->t_holddown
||
393 ldp_sync_info
->holddown
== LDP_IGP_SYNC_HOLDDOWN_DEFAULT
)
396 ols_debug("%s: start holddown timer for %s time %d", __func__
,
397 ifp
->name
, ldp_sync_info
->holddown
);
399 thread_add_timer(master
, ospf_ldp_sync_holddown_timer
,
400 ifp
, ldp_sync_info
->holddown
,
401 &ldp_sync_info
->t_holddown
);
405 * LDP-SYNC exit routes.
407 void ospf_ldp_sync_gbl_exit(struct ospf
*ospf
, bool remove
)
409 struct interface
*ifp
;
412 /* ospf is being removed
413 * stop any holddown timers
415 if (CHECK_FLAG(ospf
->ldp_sync_cmd
.flags
, LDP_SYNC_FLAG_ENABLE
)) {
416 /* unregister with opaque client to recv LDP-IGP Sync msgs */
417 zclient_unregister_opaque(zclient
,
418 LDP_IGP_SYNC_IF_STATE_UPDATE
);
419 zclient_unregister_opaque(zclient
,
420 LDP_IGP_SYNC_ANNOUNCE_UPDATE
);
422 /* disable LDP globally */
423 UNSET_FLAG(ospf
->ldp_sync_cmd
.flags
, LDP_SYNC_FLAG_ENABLE
);
424 UNSET_FLAG(ospf
->ldp_sync_cmd
.flags
, LDP_SYNC_FLAG_HOLDDOWN
);
425 ospf
->ldp_sync_cmd
.holddown
= LDP_IGP_SYNC_HOLDDOWN_DEFAULT
;
427 /* turn off LDP-IGP Sync on all OSPF interfaces */
428 vrf
= vrf_lookup_by_id(ospf
->vrf_id
);
429 FOR_ALL_INTERFACES (vrf
, ifp
)
430 ospf_ldp_sync_if_remove(ifp
, remove
);
435 * LDP-SYNC routes used by set commands.
437 void ospf_if_set_ldp_sync_enable(struct ospf
*ospf
, struct interface
*ifp
)
439 struct ospf_if_params
*params
;
440 struct ldp_sync_info
*ldp_sync_info
;
442 /* called when setting LDP-SYNC at the global level:
443 * specified on interface overrides global config
444 * if ptop link send msg to LDP indicating ldp-sync enabled
446 if (if_is_loopback(ifp
))
449 params
= IF_DEF_PARAMS(ifp
);
450 if (params
->ldp_sync_info
== NULL
)
451 params
->ldp_sync_info
= ldp_sync_info_create();
452 ldp_sync_info
= params
->ldp_sync_info
;
454 /* config on interface, overrides global config. */
455 if (CHECK_FLAG(ldp_sync_info
->flags
, LDP_SYNC_FLAG_IF_CONFIG
))
456 if (ldp_sync_info
->enabled
!= LDP_IGP_SYNC_ENABLED
)
459 ldp_sync_info
->enabled
= LDP_IGP_SYNC_ENABLED
;
461 ols_debug("%s: enable if %s", __func__
, ifp
->name
);
463 /* send message to LDP if ptop link */
464 if (params
->type
== OSPF_IFTYPE_POINTOPOINT
||
465 if_is_pointopoint(ifp
)) {
466 ldp_sync_info
->state
= LDP_IGP_SYNC_STATE_REQUIRED_NOT_UP
;
467 ospf_ldp_sync_state_req_msg(ifp
);
469 ldp_sync_info
->state
= LDP_IGP_SYNC_STATE_NOT_REQUIRED
;
470 zlog_debug("%s: Sync only runs on P2P links %s", __func__
,
475 void ospf_if_set_ldp_sync_holddown(struct ospf
*ospf
, struct interface
*ifp
)
477 struct ospf_if_params
*params
;
478 struct ldp_sync_info
*ldp_sync_info
;
480 /* called when setting LDP-SYNC at the global level:
481 * specified on interface overrides global config.
483 if (if_is_loopback(ifp
))
486 params
= IF_DEF_PARAMS(ifp
);
487 if (params
->ldp_sync_info
== NULL
)
488 params
->ldp_sync_info
= ldp_sync_info_create();
489 ldp_sync_info
= params
->ldp_sync_info
;
491 /* config on interface, overrides global config. */
492 if (CHECK_FLAG(ldp_sync_info
->flags
, LDP_SYNC_FLAG_HOLDDOWN
))
494 if (CHECK_FLAG(ospf
->ldp_sync_cmd
.flags
, LDP_SYNC_FLAG_HOLDDOWN
))
495 ldp_sync_info
->holddown
= ospf
->ldp_sync_cmd
.holddown
;
497 ldp_sync_info
->holddown
= LDP_IGP_SYNC_HOLDDOWN_DEFAULT
;
501 * LDP-SYNC routines used by show commands.
504 void ospf_ldp_sync_show_info(struct vty
*vty
, struct ospf
*ospf
,
505 json_object
*json_vrf
, bool use_json
)
508 if (CHECK_FLAG(ospf
->ldp_sync_cmd
.flags
, LDP_SYNC_FLAG_ENABLE
)) {
510 json_object_boolean_true_add(json_vrf
,
511 "mplsLdpIgpSyncEnabled");
512 json_object_int_add(json_vrf
, "mplsLdpIgpSyncHolddown",
513 ospf
->ldp_sync_cmd
.holddown
);
515 vty_out(vty
, " MPLS LDP-IGP Sync is enabled\n");
516 if (ospf
->ldp_sync_cmd
.holddown
== 0)
518 " MPLS LDP-IGP Sync holddown timer is disabled\n");
521 " MPLS LDP-IGP Sync holddown timer %d sec\n",
522 ospf
->ldp_sync_cmd
.holddown
);
527 static void show_ip_ospf_mpls_ldp_interface_sub(struct vty
*vty
,
528 struct ospf_interface
*oi
,
529 struct interface
*ifp
,
530 json_object
*json_interface_sub
,
533 const char *ldp_state
;
534 struct ospf_if_params
*params
;
535 char timebuf
[OSPF_TIME_DUMP_SIZE
];
536 struct ldp_sync_info
*ldp_sync_info
;
538 params
= IF_DEF_PARAMS(oi
->ifp
);
539 if (params
->ldp_sync_info
== NULL
)
542 ldp_sync_info
= params
->ldp_sync_info
;
544 if (ldp_sync_info
->enabled
== LDP_IGP_SYNC_ENABLED
)
545 json_object_boolean_true_add(json_interface_sub
,
546 "ldpIgpSyncEnabled");
548 json_object_boolean_false_add(json_interface_sub
,
549 "ldpIgpSyncEnabled");
551 json_object_int_add(json_interface_sub
, "holdDownTimeInSec",
552 ldp_sync_info
->holddown
);
555 vty_out(vty
, "%-10s\n", ifp
->name
);
556 vty_out(vty
, " LDP-IGP Synchronization enabled: %s\n",
557 ldp_sync_info
->enabled
== LDP_IGP_SYNC_ENABLED
560 vty_out(vty
, " Holddown timer in seconds: %u\n",
561 ldp_sync_info
->holddown
);
564 switch (ldp_sync_info
->state
) {
565 case LDP_IGP_SYNC_STATE_REQUIRED_UP
:
567 json_object_string_add(json_interface_sub
,
571 vty_out(vty
, " State: Sync achieved\n");
573 case LDP_IGP_SYNC_STATE_REQUIRED_NOT_UP
:
574 if (ldp_sync_info
->t_holddown
!= NULL
) {
578 time_store
= monotime_until(
579 &ldp_sync_info
->t_holddown
->u
.sands
,
583 json_object_int_add(json_interface_sub
,
584 "ldpIgpSyncTimeRemainInMsec",
587 json_object_string_add(json_interface_sub
,
589 "Holding down until Sync");
592 " Holddown timer is running %s remaining\n",
594 ldp_sync_info
->t_holddown
,
599 " State: Holding down until Sync\n");
603 json_object_string_add(json_interface_sub
,
605 "Sync not achieved");
607 vty_out(vty
, " State: Sync not achieved\n");
610 case LDP_IGP_SYNC_STATE_NOT_REQUIRED
:
612 if (IF_DEF_PARAMS(ifp
)->type
!= OSPF_IFTYPE_POINTOPOINT
&&
613 !if_is_pointopoint(ifp
))
614 ldp_state
= "Sync not required: non-p2p link";
616 ldp_state
= "Sync not required";
619 json_object_string_add(json_interface_sub
,
623 vty_out(vty
, " State: %s\n", ldp_state
);
628 static int show_ip_ospf_mpls_ldp_interface_common(struct vty
*vty
,
634 struct interface
*ifp
;
635 struct vrf
*vrf
= vrf_lookup_by_id(ospf
->vrf_id
);
636 json_object
*json_interface_sub
= NULL
;
638 if (intf_name
== NULL
) {
639 /* Show All Interfaces.*/
640 FOR_ALL_INTERFACES (vrf
, ifp
) {
641 struct route_node
*rn
;
642 struct ospf_interface
*oi
;
644 if (ospf_oi_count(ifp
) == 0 && !use_json
) {
646 vty_out(vty
, "%s\n Interface down\n",
650 for (rn
= route_top(IF_OIFS(ifp
)); rn
;
651 rn
= route_next(rn
)) {
656 json_object_new_object();
658 show_ip_ospf_mpls_ldp_interface_sub(
659 vty
, oi
, ifp
, json_interface_sub
,
663 json_object_object_add(
670 /* Interface name is specified. */
671 ifp
= if_lookup_by_name(intf_name
, ospf
->vrf_id
);
673 struct route_node
*rn
;
674 struct ospf_interface
*oi
;
676 if (ospf_oi_count(ifp
) == 0 && !use_json
) {
678 vty_out(vty
, "%s\n OSPF not enabled\n",
681 vty_out(vty
, "%s\n Interface down\n",
685 for (rn
= route_top(IF_OIFS(ifp
)); rn
;
686 rn
= route_next(rn
)) {
691 json_object_new_object();
693 show_ip_ospf_mpls_ldp_interface_sub(
694 vty
, oi
, ifp
, json_interface_sub
,
698 json_object_object_add(
709 * Write the global LDP-SYNC configuration.
711 void ospf_ldp_sync_write_config(struct vty
*vty
, struct ospf
*ospf
)
713 if (CHECK_FLAG(ospf
->ldp_sync_cmd
.flags
, LDP_SYNC_FLAG_ENABLE
))
714 vty_out(vty
, " mpls ldp-sync\n");
715 if (CHECK_FLAG(ospf
->ldp_sync_cmd
.flags
, LDP_SYNC_FLAG_HOLDDOWN
))
716 vty_out(vty
, " mpls ldp-sync holddown %u\n",
717 ospf
->ldp_sync_cmd
.holddown
);
721 * Write the interface LDP-SYNC configuration.
723 void ospf_ldp_sync_if_write_config(struct vty
*vty
,
724 struct ospf_if_params
*params
)
727 struct ldp_sync_info
*ldp_sync_info
;
729 ldp_sync_info
= params
->ldp_sync_info
;
730 if (ldp_sync_info
== NULL
)
733 if (CHECK_FLAG(ldp_sync_info
->flags
, LDP_SYNC_FLAG_IF_CONFIG
)) {
734 if (ldp_sync_info
->enabled
== LDP_IGP_SYNC_ENABLED
)
735 vty_out(vty
, " ip ospf mpls ldp-sync\n");
737 vty_out(vty
, " no ip ospf mpls ldp-sync\n");
739 if (CHECK_FLAG(ldp_sync_info
->flags
, LDP_SYNC_FLAG_HOLDDOWN
))
740 vty_out(vty
, " ip ospf mpls ldp-sync holddown %u\n",
741 ldp_sync_info
->holddown
);
747 #include "ospfd/ospf_ldp_sync_clippy.c"
749 DEFPY (ospf_mpls_ldp_sync
,
750 ospf_mpls_ldp_sync_cmd
,
752 "MPLS specific commands\n"
753 "Enable MPLS LDP-IGP Sync\n")
755 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
756 struct vrf
*vrf
= vrf_lookup_by_id(ospf
->vrf_id
);
757 struct interface
*ifp
;
759 if (ospf
->vrf_id
!= VRF_DEFAULT
) {
760 vty_out(vty
, "ldp-sync only runs on DEFAULT VRF\n");
761 return CMD_ERR_NOTHING_TODO
;
764 /* register with opaque client to recv LDP-IGP Sync msgs */
765 zclient_register_opaque(zclient
, LDP_IGP_SYNC_IF_STATE_UPDATE
);
766 zclient_register_opaque(zclient
, LDP_IGP_SYNC_ANNOUNCE_UPDATE
);
768 if (!CHECK_FLAG(ospf
->ldp_sync_cmd
.flags
, LDP_SYNC_FLAG_ENABLE
)) {
769 SET_FLAG(ospf
->ldp_sync_cmd
.flags
, LDP_SYNC_FLAG_ENABLE
);
770 /* turn on LDP-IGP Sync on all ptop OSPF interfaces */
771 FOR_ALL_INTERFACES (vrf
, ifp
)
772 ospf_if_set_ldp_sync_enable(ospf
, ifp
);
777 DEFPY (no_ospf_mpls_ldp_sync
,
778 no_ospf_mpls_ldp_sync_cmd
,
781 "MPLS specific commands\n"
782 "Disable MPLS LDP-IGP Sync\n")
784 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
785 ospf_ldp_sync_gbl_exit(ospf
, false);
789 DEFPY (ospf_mpls_ldp_sync_holddown
,
790 ospf_mpls_ldp_sync_holddown_cmd
,
791 "mpls ldp-sync holddown (1-10000)",
792 "MPLS specific commands\n"
793 "Enable MPLS LDP-IGP Sync\n"
794 "Set holddown timer\n"
797 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
798 struct vrf
*vrf
= vrf_lookup_by_id(ospf
->vrf_id
);
799 struct interface
*ifp
;
801 if (ospf
->vrf_id
!= VRF_DEFAULT
) {
802 vty_out(vty
, "ldp-sync only runs on DEFAULT VRF\n");
803 return CMD_ERR_NOTHING_TODO
;
806 SET_FLAG(ospf
->ldp_sync_cmd
.flags
, LDP_SYNC_FLAG_HOLDDOWN
);
807 ospf
->ldp_sync_cmd
.holddown
= holddown
;
808 /* set holddown time on all OSPF interfaces */
809 FOR_ALL_INTERFACES (vrf
, ifp
)
810 ospf_if_set_ldp_sync_holddown(ospf
, ifp
);
815 DEFPY (no_ospf_mpls_ldp_sync_holddown
,
816 no_ospf_mpls_ldp_sync_holddown_cmd
,
817 "no mpls ldp-sync holddown [<(1-10000)>]",
819 "MPLS specific commands\n"
820 "Disable MPLS LDP-IGP Sync\n"
821 "holddown timer disable\n"
824 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
825 struct vrf
*vrf
= vrf_lookup_by_id(ospf
->vrf_id
);
826 struct interface
*ifp
;
828 if (CHECK_FLAG(ospf
->ldp_sync_cmd
.flags
, LDP_SYNC_FLAG_HOLDDOWN
)) {
829 UNSET_FLAG(ospf
->ldp_sync_cmd
.flags
, LDP_SYNC_FLAG_HOLDDOWN
);
830 ospf
->ldp_sync_cmd
.holddown
= LDP_IGP_SYNC_HOLDDOWN_DEFAULT
;
831 /* turn off holddown timer on all OSPF interfaces */
832 FOR_ALL_INTERFACES (vrf
, ifp
)
833 ospf_if_set_ldp_sync_holddown(ospf
, ifp
);
839 DEFPY (mpls_ldp_sync
,
841 "ip ospf mpls ldp-sync",
843 "OSPF interface commands\n"
847 VTY_DECLVAR_CONTEXT(interface
, ifp
);
848 struct ospf_if_params
*params
;
849 struct ldp_sync_info
*ldp_sync_info
;
851 if (if_is_loopback(ifp
)) {
852 vty_out(vty
, "ldp-sync does not run on loopback interface\n");
853 return CMD_ERR_NOTHING_TODO
;
856 if (ifp
->vrf
->vrf_id
!= VRF_DEFAULT
) {
857 vty_out(vty
, "ldp-sync only runs on DEFAULT VRF\n");
858 return CMD_ERR_NOTHING_TODO
;
861 params
= IF_DEF_PARAMS(ifp
);
862 if (params
->ldp_sync_info
== NULL
)
863 params
->ldp_sync_info
= ldp_sync_info_create();
865 ldp_sync_info
= params
->ldp_sync_info
;
867 SET_FLAG(ldp_sync_info
->flags
, LDP_SYNC_FLAG_IF_CONFIG
);
868 ldp_sync_info
->enabled
= LDP_IGP_SYNC_ENABLED
;
869 if (params
->type
== OSPF_IFTYPE_POINTOPOINT
|| if_is_pointopoint(ifp
)) {
870 ldp_sync_info
->state
= LDP_IGP_SYNC_STATE_REQUIRED_NOT_UP
;
871 ospf_ldp_sync_state_req_msg(ifp
);
873 zlog_debug("ldp_sync: only runs on P2P links %s", ifp
->name
);
874 ldp_sync_info
->state
= LDP_IGP_SYNC_STATE_NOT_REQUIRED
;
879 DEFPY (no_mpls_ldp_sync
,
880 no_mpls_ldp_sync_cmd
,
881 "no ip ospf mpls ldp-sync",
884 "OSPF interface commands\n"
886 NO_MPLS_LDP_SYNC_STR
)
888 VTY_DECLVAR_CONTEXT(interface
, ifp
);
889 struct ospf_if_params
*params
;
890 struct ldp_sync_info
*ldp_sync_info
;
892 if (if_is_loopback(ifp
)) {
893 vty_out(vty
, "ldp-sync: does not run on loopback interface\n");
894 return CMD_ERR_NOTHING_TODO
;
897 if (ifp
->vrf
->vrf_id
!= VRF_DEFAULT
) {
898 vty_out(vty
, "ldp-sync only runs on DEFAULT VRF\n");
899 return CMD_ERR_NOTHING_TODO
;
902 params
= IF_DEF_PARAMS(ifp
);
903 if (params
->ldp_sync_info
== NULL
)
904 params
->ldp_sync_info
= ldp_sync_info_create();
906 ldp_sync_info
= params
->ldp_sync_info
;
908 /* disable LDP-SYNC on an interface
909 * stop holddown timer if running
912 SET_FLAG(ldp_sync_info
->flags
, LDP_SYNC_FLAG_IF_CONFIG
);
913 ldp_sync_info
->enabled
= LDP_IGP_SYNC_DEFAULT
;
914 ldp_sync_info
->state
= LDP_IGP_SYNC_STATE_NOT_REQUIRED
;
915 THREAD_OFF(ldp_sync_info
->t_holddown
);
916 ospf_if_recalculate_output_cost(ifp
);
921 DEFPY (mpls_ldp_sync_holddown
,
922 mpls_ldp_sync_holddown_cmd
,
923 "ip ospf mpls ldp-sync holddown (0-10000)",
925 "OSPF interface commands\n"
928 "Time to wait for LDP-SYNC to occur before restoring interface cost\n"
931 VTY_DECLVAR_CONTEXT(interface
, ifp
);
932 struct ospf_if_params
*params
;
933 struct ldp_sync_info
*ldp_sync_info
;
935 if (if_is_loopback(ifp
)) {
936 vty_out(vty
, "ldp-sync: does not run on loopback interface\n");
937 return CMD_ERR_NOTHING_TODO
;
940 if (ifp
->vrf
->vrf_id
!= VRF_DEFAULT
) {
941 vty_out(vty
, "ldp-sync only runs on DEFAULT VRF\n");
942 return CMD_ERR_NOTHING_TODO
;
945 params
= IF_DEF_PARAMS(ifp
);
946 if (params
->ldp_sync_info
== NULL
)
947 params
->ldp_sync_info
= ldp_sync_info_create();
949 ldp_sync_info
= params
->ldp_sync_info
;
951 SET_FLAG(ldp_sync_info
->flags
, LDP_SYNC_FLAG_HOLDDOWN
);
952 ldp_sync_info
->holddown
= holddown
;
957 DEFPY (no_mpls_ldp_sync_holddown
,
958 no_mpls_ldp_sync_holddown_cmd
,
959 "no ip ospf mpls ldp-sync holddown [<(1-10000)>]",
962 "OSPF interface commands\n"
965 NO_MPLS_LDP_SYNC_HOLDDOWN_STR
968 VTY_DECLVAR_CONTEXT(interface
, ifp
);
969 struct ospf_if_params
*params
;
970 struct ldp_sync_info
*ldp_sync_info
;
973 if (if_is_loopback(ifp
)) {
974 vty_out(vty
, "ldp-sync: does not run on loopback interface\n");
975 return CMD_ERR_NOTHING_TODO
;
978 if (ifp
->vrf
->vrf_id
!= VRF_DEFAULT
) {
979 vty_out(vty
, "ldp-sync only runs on DEFAULT VRF\n");
980 return CMD_ERR_NOTHING_TODO
;
983 params
= IF_DEF_PARAMS(ifp
);
984 ldp_sync_info
= params
->ldp_sync_info
;
985 if (ldp_sync_info
== NULL
)
988 /* use global configured value if set */
989 if (CHECK_FLAG(ldp_sync_info
->flags
, LDP_SYNC_FLAG_HOLDDOWN
)) {
990 UNSET_FLAG(ldp_sync_info
->flags
, LDP_SYNC_FLAG_HOLDDOWN
);
991 ospf
= ospf_lookup_by_vrf_id(VRF_DEFAULT
);
992 if (ospf
&& CHECK_FLAG(ospf
->ldp_sync_cmd
.flags
,
993 LDP_SYNC_FLAG_HOLDDOWN
))
994 ldp_sync_info
->holddown
= ospf
->ldp_sync_cmd
.holddown
;
996 ldp_sync_info
->holddown
= LDP_IGP_SYNC_HOLDDOWN_DEFAULT
;
1001 DEFPY (show_ip_ospf_mpls_ldp_interface
,
1002 show_ip_ospf_mpls_ldp_interface_cmd
,
1003 "show ip ospf mpls ldp-sync [interface <INTERFACE|all>] [json]",
1006 "OSPF information\n"
1008 "LDP-IGP Sync information\n"
1009 "Interface information\n"
1015 bool uj
= use_json(argc
, argv
);
1016 char *intf_name
= NULL
;
1017 int ret
= CMD_SUCCESS
;
1019 json_object
*json
= NULL
;
1021 if (argv_find(argv
, argc
, "INTERFACE", &idx_intf
))
1022 intf_name
= argv
[idx_intf
]->arg
;
1025 json
= json_object_new_object();
1027 /* Display default ospf (instance 0) info */
1028 ospf
= ospf_lookup_by_vrf_id(VRF_DEFAULT
);
1029 if (ospf
== NULL
|| !ospf
->oi_running
) {
1031 vty_json(vty
, json
);
1033 vty_out(vty
, "%% OSPF instance not found\n");
1037 if (!CHECK_FLAG(ospf
->ldp_sync_cmd
.flags
, LDP_SYNC_FLAG_ENABLE
)) {
1039 vty_json(vty
, json
);
1041 vty_out(vty
, "LDP-sync is disabled\n");
1045 ret
= show_ip_ospf_mpls_ldp_interface_common(vty
, ospf
, intf_name
,
1048 vty_json(vty
, json
);
1053 void ospf_ldp_sync_init(void)
1055 /* Install global ldp-igp sync commands */
1056 install_element(OSPF_NODE
, &ospf_mpls_ldp_sync_cmd
);
1057 install_element(OSPF_NODE
, &no_ospf_mpls_ldp_sync_cmd
);
1058 install_element(OSPF_NODE
, &ospf_mpls_ldp_sync_holddown_cmd
);
1059 install_element(OSPF_NODE
, &no_ospf_mpls_ldp_sync_holddown_cmd
);
1061 /* Interface lsp-igp sync commands */
1062 install_element(INTERFACE_NODE
, &mpls_ldp_sync_cmd
);
1063 install_element(INTERFACE_NODE
, &no_mpls_ldp_sync_cmd
);
1064 install_element(INTERFACE_NODE
, &mpls_ldp_sync_holddown_cmd
);
1065 install_element(INTERFACE_NODE
, &no_mpls_ldp_sync_holddown_cmd
);
1067 /* "show ip ospf mpls ldp interface" commands. */
1068 install_element(VIEW_NODE
, &show_ip_ospf_mpls_ldp_interface_cmd
);
1070 hook_register(ospf_ism_change
, ospf_ldp_sync_ism_change
);