3 * Copyright (C) 2022 Vmware, Inc.
4 * Mobashshera Rasool <mrasool@vmware.com>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
16 * You should have received a copy of the GNU General Public License along
17 * with this program; see the file COPYING; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
33 #include "lib/srcdest_table.h"
34 #include "lib/linklist.h"
35 #include "termtable.h"
38 #include "pim_instance.h"
40 #include "lib/northbound_cli.h"
41 #include "pim_errors.h"
43 #include "pim_mroute.h"
46 #include "pim_cmd_common.h"
48 #include "pim_zebra.h"
49 #include "pim_zlookup.h"
50 #include "pim_iface.h"
51 #include "pim_macro.h"
52 #include "pim_neighbor.h"
56 #include "pim_static.h"
58 #include "pim_static.h"
63 * Get current node VRF name.
66 * In case of failure it will print error message to user.
68 * \returns name or NULL if failed to get VRF.
70 const char *pim_cli_get_vrf_name(struct vty
*vty
)
72 const struct lyd_node
*vrf_node
;
74 /* Not inside any VRF context. */
75 if (vty
->xpath_index
== 0)
76 return VRF_DEFAULT_NAME
;
78 vrf_node
= yang_dnode_get(vty
->candidate_config
->dnode
, VTY_CURR_XPATH
);
79 if (vrf_node
== NULL
) {
80 vty_out(vty
, "%% Failed to get vrf dnode in configuration\n");
84 return yang_dnode_get_string(vrf_node
, "./name");
87 int pim_process_join_prune_cmd(struct vty
*vty
, const char *jpi_str
)
89 char xpath
[XPATH_MAXLEN
];
91 snprintf(xpath
, sizeof(xpath
), FRR_PIM_ROUTER_XPATH
,
92 FRR_PIM_AF_XPATH_VAL
);
93 strlcat(xpath
, "/join-prune-interval", sizeof(xpath
));
95 nb_cli_enqueue_change(vty
, xpath
, NB_OP_MODIFY
, jpi_str
);
97 return nb_cli_apply_changes(vty
, NULL
);
100 int pim_process_no_join_prune_cmd(struct vty
*vty
)
102 char xpath
[XPATH_MAXLEN
];
104 snprintf(xpath
, sizeof(xpath
), FRR_PIM_ROUTER_XPATH
,
105 FRR_PIM_AF_XPATH_VAL
);
106 strlcat(xpath
, "/join-prune-interval", sizeof(xpath
));
108 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
110 return nb_cli_apply_changes(vty
, NULL
);
113 int pim_process_spt_switchover_infinity_cmd(struct vty
*vty
)
116 char spt_plist_xpath
[XPATH_MAXLEN
];
117 char spt_action_xpath
[XPATH_MAXLEN
];
119 vrfname
= pim_cli_get_vrf_name(vty
);
121 return CMD_WARNING_CONFIG_FAILED
;
123 snprintf(spt_plist_xpath
, sizeof(spt_plist_xpath
),
124 FRR_PIM_VRF_XPATH
, "frr-pim:pimd", "pim", vrfname
,
125 FRR_PIM_AF_XPATH_VAL
);
126 strlcat(spt_plist_xpath
, "/spt-switchover/spt-infinity-prefix-list",
127 sizeof(spt_plist_xpath
));
129 snprintf(spt_action_xpath
, sizeof(spt_action_xpath
),
130 FRR_PIM_VRF_XPATH
, "frr-pim:pimd", "pim", vrfname
,
131 FRR_PIM_AF_XPATH_VAL
);
132 strlcat(spt_action_xpath
, "/spt-switchover/spt-action",
133 sizeof(spt_action_xpath
));
135 if (yang_dnode_exists(vty
->candidate_config
->dnode
, spt_plist_xpath
))
136 nb_cli_enqueue_change(vty
, spt_plist_xpath
, NB_OP_DESTROY
,
138 nb_cli_enqueue_change(vty
, spt_action_xpath
, NB_OP_MODIFY
,
141 return nb_cli_apply_changes(vty
, NULL
);
144 int pim_process_spt_switchover_prefixlist_cmd(struct vty
*vty
,
148 char spt_plist_xpath
[XPATH_MAXLEN
];
149 char spt_action_xpath
[XPATH_MAXLEN
];
151 vrfname
= pim_cli_get_vrf_name(vty
);
153 return CMD_WARNING_CONFIG_FAILED
;
155 snprintf(spt_plist_xpath
, sizeof(spt_plist_xpath
),
156 FRR_PIM_VRF_XPATH
, "frr-pim:pimd", "pim", vrfname
,
157 FRR_PIM_AF_XPATH_VAL
);
158 strlcat(spt_plist_xpath
, "/spt-switchover/spt-infinity-prefix-list",
159 sizeof(spt_plist_xpath
));
161 snprintf(spt_action_xpath
, sizeof(spt_action_xpath
),
162 FRR_PIM_VRF_XPATH
, "frr-pim:pimd", "pim", vrfname
,
163 FRR_PIM_AF_XPATH_VAL
);
164 strlcat(spt_action_xpath
, "/spt-switchover/spt-action",
165 sizeof(spt_action_xpath
));
167 nb_cli_enqueue_change(vty
, spt_action_xpath
, NB_OP_MODIFY
,
169 nb_cli_enqueue_change(vty
, spt_plist_xpath
, NB_OP_MODIFY
,
172 return nb_cli_apply_changes(vty
, NULL
);
175 int pim_process_no_spt_switchover_cmd(struct vty
*vty
)
178 char spt_plist_xpath
[XPATH_MAXLEN
];
179 char spt_action_xpath
[XPATH_MAXLEN
];
181 vrfname
= pim_cli_get_vrf_name(vty
);
183 return CMD_WARNING_CONFIG_FAILED
;
185 snprintf(spt_plist_xpath
, sizeof(spt_plist_xpath
),
186 FRR_PIM_VRF_XPATH
, "frr-pim:pimd", "pim", vrfname
,
187 FRR_PIM_AF_XPATH_VAL
);
188 strlcat(spt_plist_xpath
, "/spt-switchover/spt-infinity-prefix-list",
189 sizeof(spt_plist_xpath
));
191 snprintf(spt_action_xpath
, sizeof(spt_action_xpath
),
192 FRR_PIM_VRF_XPATH
, "frr-pim:pimd", "pim", vrfname
,
193 FRR_PIM_AF_XPATH_VAL
);
194 strlcat(spt_action_xpath
, "/spt-switchover/spt-action",
195 sizeof(spt_action_xpath
));
197 nb_cli_enqueue_change(vty
, spt_plist_xpath
, NB_OP_DESTROY
, NULL
);
198 nb_cli_enqueue_change(vty
, spt_action_xpath
, NB_OP_MODIFY
,
199 "PIM_SPT_IMMEDIATE");
201 return nb_cli_apply_changes(vty
, NULL
);
204 int pim_process_pim_packet_cmd(struct vty
*vty
, const char *packet
)
206 char xpath
[XPATH_MAXLEN
];
208 snprintf(xpath
, sizeof(xpath
), FRR_PIM_ROUTER_XPATH
,
209 FRR_PIM_AF_XPATH_VAL
);
210 strlcat(xpath
, "/packets", sizeof(xpath
));
212 nb_cli_enqueue_change(vty
, xpath
, NB_OP_MODIFY
, packet
);
214 return nb_cli_apply_changes(vty
, NULL
);
217 int pim_process_no_pim_packet_cmd(struct vty
*vty
)
219 char xpath
[XPATH_MAXLEN
];
221 snprintf(xpath
, sizeof(xpath
), FRR_PIM_ROUTER_XPATH
,
222 FRR_PIM_AF_XPATH_VAL
);
223 strlcat(xpath
, "/packets", sizeof(xpath
));
225 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
227 return nb_cli_apply_changes(vty
, NULL
);
230 int pim_process_keepalivetimer_cmd(struct vty
*vty
, const char *kat
)
233 char ka_timer_xpath
[XPATH_MAXLEN
];
235 vrfname
= pim_cli_get_vrf_name(vty
);
237 return CMD_WARNING_CONFIG_FAILED
;
239 snprintf(ka_timer_xpath
, sizeof(ka_timer_xpath
), FRR_PIM_VRF_XPATH
,
240 "frr-pim:pimd", "pim", vrfname
, FRR_PIM_AF_XPATH_VAL
);
241 strlcat(ka_timer_xpath
, "/keep-alive-timer", sizeof(ka_timer_xpath
));
243 nb_cli_enqueue_change(vty
, ka_timer_xpath
, NB_OP_MODIFY
,
246 return nb_cli_apply_changes(vty
, NULL
);
249 int pim_process_no_keepalivetimer_cmd(struct vty
*vty
)
252 char ka_timer_xpath
[XPATH_MAXLEN
];
254 vrfname
= pim_cli_get_vrf_name(vty
);
256 return CMD_WARNING_CONFIG_FAILED
;
258 snprintf(ka_timer_xpath
, sizeof(ka_timer_xpath
), FRR_PIM_VRF_XPATH
,
259 "frr-pim:pimd", "pim", vrfname
, FRR_PIM_AF_XPATH_VAL
);
260 strlcat(ka_timer_xpath
, "/keep-alive-timer", sizeof(ka_timer_xpath
));
262 nb_cli_enqueue_change(vty
, ka_timer_xpath
, NB_OP_DESTROY
, NULL
);
264 return nb_cli_apply_changes(vty
, NULL
);
267 int pim_process_rp_kat_cmd(struct vty
*vty
, const char *rpkat
)
270 char rp_ka_timer_xpath
[XPATH_MAXLEN
];
272 vrfname
= pim_cli_get_vrf_name(vty
);
274 return CMD_WARNING_CONFIG_FAILED
;
276 snprintf(rp_ka_timer_xpath
, sizeof(rp_ka_timer_xpath
),
277 FRR_PIM_VRF_XPATH
, "frr-pim:pimd", "pim", vrfname
,
278 FRR_PIM_AF_XPATH_VAL
);
279 strlcat(rp_ka_timer_xpath
, "/rp-keep-alive-timer",
280 sizeof(rp_ka_timer_xpath
));
282 nb_cli_enqueue_change(vty
, rp_ka_timer_xpath
, NB_OP_MODIFY
,
285 return nb_cli_apply_changes(vty
, NULL
);
288 int pim_process_no_rp_kat_cmd(struct vty
*vty
)
292 char rp_ka_timer_xpath
[XPATH_MAXLEN
];
294 char rs_timer_xpath
[XPATH_MAXLEN
];
296 snprintf(rs_timer_xpath
, sizeof(rs_timer_xpath
),
297 FRR_PIM_ROUTER_XPATH
, FRR_PIM_AF_XPATH_VAL
);
298 strlcat(rs_timer_xpath
, "/register-suppress-time",
299 sizeof(rs_timer_xpath
));
302 v
= yang_dnode_get_uint16(vty
->candidate_config
->dnode
,
304 v
= 3 * v
+ PIM_REGISTER_PROBE_TIME_DEFAULT
;
307 snprintf(rp_ka_timer
, sizeof(rp_ka_timer
), "%u", v
);
309 vrfname
= pim_cli_get_vrf_name(vty
);
311 return CMD_WARNING_CONFIG_FAILED
;
313 snprintf(rp_ka_timer_xpath
, sizeof(rp_ka_timer_xpath
),
314 FRR_PIM_VRF_XPATH
, "frr-pim:pimd", "pim", vrfname
,
315 FRR_PIM_AF_XPATH_VAL
);
316 strlcat(rp_ka_timer_xpath
, "/rp-keep-alive-timer",
317 sizeof(rp_ka_timer_xpath
));
319 nb_cli_enqueue_change(vty
, rp_ka_timer_xpath
, NB_OP_MODIFY
,
322 return nb_cli_apply_changes(vty
, NULL
);
325 int pim_process_register_suppress_cmd(struct vty
*vty
, const char *rst
)
327 char xpath
[XPATH_MAXLEN
];
329 snprintf(xpath
, sizeof(xpath
), FRR_PIM_ROUTER_XPATH
,
330 FRR_PIM_AF_XPATH_VAL
);
331 strlcat(xpath
, "/register-suppress-time", sizeof(xpath
));
333 nb_cli_enqueue_change(vty
, xpath
, NB_OP_MODIFY
, rst
);
335 return nb_cli_apply_changes(vty
, NULL
);
338 int pim_process_no_register_suppress_cmd(struct vty
*vty
)
340 char xpath
[XPATH_MAXLEN
];
342 snprintf(xpath
, sizeof(xpath
), FRR_PIM_ROUTER_XPATH
,
343 FRR_PIM_AF_XPATH_VAL
);
344 strlcat(xpath
, "/register-suppress-time", sizeof(xpath
));
346 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
348 return nb_cli_apply_changes(vty
, NULL
);
351 int pim_process_ip_pim_cmd(struct vty
*vty
)
353 nb_cli_enqueue_change(vty
, "./pim-enable", NB_OP_MODIFY
, "true");
355 return nb_cli_apply_changes(vty
, FRR_PIM_INTERFACE_XPATH
,
356 FRR_PIM_AF_XPATH_VAL
);
359 int pim_process_ip_pim_passive_cmd(struct vty
*vty
, bool enable
)
362 nb_cli_enqueue_change(vty
, "./pim-passive-enable", NB_OP_MODIFY
,
365 nb_cli_enqueue_change(vty
, "./pim-passive-enable", NB_OP_MODIFY
,
368 return nb_cli_apply_changes(vty
, FRR_PIM_INTERFACE_XPATH
,
369 FRR_PIM_AF_XPATH_VAL
);
372 int pim_process_no_ip_pim_cmd(struct vty
*vty
)
374 const struct lyd_node
*mld_enable_dnode
;
375 char mld_if_xpath
[XPATH_MAXLEN
];
378 snprintf(mld_if_xpath
, sizeof(mld_if_xpath
),
379 "%s/frr-gmp:gmp/address-family[address-family='%s']",
380 VTY_CURR_XPATH
, FRR_PIM_AF_XPATH_VAL
);
382 if (printed
>= (int)(sizeof(mld_if_xpath
))) {
383 vty_out(vty
, "Xpath too long (%d > %u)", printed
+ 1,
385 return CMD_WARNING_CONFIG_FAILED
;
388 mld_enable_dnode
= yang_dnode_getf(vty
->candidate_config
->dnode
,
389 FRR_GMP_ENABLE_XPATH
, VTY_CURR_XPATH
,
390 FRR_PIM_AF_XPATH_VAL
);
392 if (!mld_enable_dnode
) {
393 nb_cli_enqueue_change(vty
, mld_if_xpath
, NB_OP_DESTROY
, NULL
);
394 nb_cli_enqueue_change(vty
, ".", NB_OP_DESTROY
, NULL
);
396 if (!yang_dnode_get_bool(mld_enable_dnode
, ".")) {
397 nb_cli_enqueue_change(vty
, mld_if_xpath
, NB_OP_DESTROY
,
399 nb_cli_enqueue_change(vty
, ".", NB_OP_DESTROY
, NULL
);
401 nb_cli_enqueue_change(vty
, "./pim-enable", NB_OP_MODIFY
,
405 return nb_cli_apply_changes(vty
, FRR_PIM_INTERFACE_XPATH
,
406 FRR_PIM_AF_XPATH_VAL
);
409 int pim_process_ip_pim_drprio_cmd(struct vty
*vty
, const char *drpriority_str
)
411 nb_cli_enqueue_change(vty
, "./dr-priority", NB_OP_MODIFY
,
414 return nb_cli_apply_changes(vty
, FRR_PIM_INTERFACE_XPATH
,
415 FRR_PIM_AF_XPATH_VAL
);
418 int pim_process_no_ip_pim_drprio_cmd(struct vty
*vty
)
420 nb_cli_enqueue_change(vty
, "./dr-priority", NB_OP_DESTROY
, NULL
);
422 return nb_cli_apply_changes(vty
, FRR_PIM_INTERFACE_XPATH
,
423 FRR_PIM_AF_XPATH_VAL
);
426 int pim_process_ip_pim_hello_cmd(struct vty
*vty
, const char *hello_str
,
427 const char *hold_str
)
429 const struct lyd_node
*mld_enable_dnode
;
431 mld_enable_dnode
= yang_dnode_getf(vty
->candidate_config
->dnode
,
432 FRR_GMP_ENABLE_XPATH
, VTY_CURR_XPATH
,
433 FRR_PIM_AF_XPATH_VAL
);
435 if (!mld_enable_dnode
) {
436 nb_cli_enqueue_change(vty
, "./pim-enable", NB_OP_MODIFY
,
439 if (!yang_dnode_get_bool(mld_enable_dnode
, "."))
440 nb_cli_enqueue_change(vty
, "./pim-enable", NB_OP_MODIFY
,
444 nb_cli_enqueue_change(vty
, "./hello-interval", NB_OP_MODIFY
, hello_str
);
447 nb_cli_enqueue_change(vty
, "./hello-holdtime", NB_OP_MODIFY
,
450 return nb_cli_apply_changes(vty
, FRR_PIM_INTERFACE_XPATH
,
451 FRR_PIM_AF_XPATH_VAL
);
454 int pim_process_no_ip_pim_hello_cmd(struct vty
*vty
)
456 nb_cli_enqueue_change(vty
, "./hello-interval", NB_OP_DESTROY
, NULL
);
457 nb_cli_enqueue_change(vty
, "./hello-holdtime", NB_OP_DESTROY
, NULL
);
459 return nb_cli_apply_changes(vty
, FRR_PIM_INTERFACE_XPATH
,
460 FRR_PIM_AF_XPATH_VAL
);
463 int pim_process_ip_pim_activeactive_cmd(struct vty
*vty
, const char *no
)
466 nb_cli_enqueue_change(vty
, "./active-active", NB_OP_MODIFY
,
469 nb_cli_enqueue_change(vty
, "./pim-enable", NB_OP_MODIFY
,
472 nb_cli_enqueue_change(vty
, "./active-active", NB_OP_MODIFY
,
476 return nb_cli_apply_changes(vty
, FRR_PIM_INTERFACE_XPATH
,
477 FRR_PIM_AF_XPATH_VAL
);
480 int pim_process_ip_pim_boundary_oil_cmd(struct vty
*vty
, const char *oil
)
482 nb_cli_enqueue_change(vty
, "./multicast-boundary-oil", NB_OP_MODIFY
,
485 return nb_cli_apply_changes(vty
, FRR_PIM_INTERFACE_XPATH
,
486 FRR_PIM_AF_XPATH_VAL
);
489 int pim_process_no_ip_pim_boundary_oil_cmd(struct vty
*vty
)
491 nb_cli_enqueue_change(vty
, "./multicast-boundary-oil", NB_OP_DESTROY
,
494 return nb_cli_apply_changes(vty
, FRR_PIM_INTERFACE_XPATH
,
495 FRR_PIM_AF_XPATH_VAL
);
498 int pim_process_ip_mroute_cmd(struct vty
*vty
, const char *interface
,
499 const char *group_str
, const char *source_str
)
501 nb_cli_enqueue_change(vty
, "./oif", NB_OP_MODIFY
, interface
);
504 char buf
[SRCDEST2STR_BUFFER
];
506 inet_ntop(AF_INET6
, &in6addr_any
, buf
, sizeof(buf
));
507 return nb_cli_apply_changes(vty
, FRR_PIM_MROUTE_XPATH
,
508 FRR_PIM_AF_XPATH_VAL
, buf
,
512 return nb_cli_apply_changes(vty
, FRR_PIM_MROUTE_XPATH
,
513 FRR_PIM_AF_XPATH_VAL
, source_str
,
517 int pim_process_no_ip_mroute_cmd(struct vty
*vty
, const char *interface
,
518 const char *group_str
, const char *source_str
)
520 nb_cli_enqueue_change(vty
, ".", NB_OP_DESTROY
, NULL
);
523 char buf
[SRCDEST2STR_BUFFER
];
525 inet_ntop(AF_INET6
, &in6addr_any
, buf
, sizeof(buf
));
526 return nb_cli_apply_changes(vty
, FRR_PIM_MROUTE_XPATH
,
527 FRR_PIM_AF_XPATH_VAL
, buf
,
531 return nb_cli_apply_changes(vty
, FRR_PIM_MROUTE_XPATH
,
532 FRR_PIM_AF_XPATH_VAL
, source_str
,
536 int pim_process_rp_cmd(struct vty
*vty
, const char *rp_str
,
537 const char *group_str
)
540 char rp_group_xpath
[XPATH_MAXLEN
];
545 result
= str2prefix(group_str
, &group
);
549 prefix_copy(&temp
, &group
);
551 if (!prefix_same(&group
, &temp
)) {
552 vty_out(vty
, "%% Inconsistent address and mask: %s\n",
554 return CMD_WARNING_CONFIG_FAILED
;
559 vty_out(vty
, "%% Bad group address specified: %s\n", group_str
);
560 return CMD_WARNING_CONFIG_FAILED
;
563 result
= inet_pton(PIM_AF
, rp_str
, &rp_addr
);
565 vty_out(vty
, "%% Bad RP address specified: %s\n", rp_str
);
566 return CMD_WARNING_CONFIG_FAILED
;
569 vrfname
= pim_cli_get_vrf_name(vty
);
571 return CMD_WARNING_CONFIG_FAILED
;
573 snprintf(rp_group_xpath
, sizeof(rp_group_xpath
),
574 FRR_PIM_STATIC_RP_XPATH
, "frr-pim:pimd", "pim", vrfname
,
575 FRR_PIM_AF_XPATH_VAL
, rp_str
);
576 strlcat(rp_group_xpath
, "/group-list", sizeof(rp_group_xpath
));
578 nb_cli_enqueue_change(vty
, rp_group_xpath
, NB_OP_CREATE
, group_str
);
580 return nb_cli_apply_changes(vty
, NULL
);
583 int pim_process_no_rp_cmd(struct vty
*vty
, const char *rp_str
,
584 const char *group_str
)
586 char group_list_xpath
[XPATH_MAXLEN
];
587 char group_xpath
[XPATH_MAXLEN
];
588 char rp_xpath
[XPATH_MAXLEN
];
591 const struct lyd_node
*group_dnode
;
593 vrfname
= pim_cli_get_vrf_name(vty
);
595 return CMD_WARNING_CONFIG_FAILED
;
597 snprintf(rp_xpath
, sizeof(rp_xpath
), FRR_PIM_STATIC_RP_XPATH
,
598 "frr-pim:pimd", "pim", vrfname
, FRR_PIM_AF_XPATH_VAL
, rp_str
);
600 printed
= snprintf(group_list_xpath
, sizeof(group_list_xpath
),
601 "%s/group-list", rp_xpath
);
603 if (printed
>= (int)(sizeof(group_list_xpath
))) {
604 vty_out(vty
, "Xpath too long (%d > %u)", printed
+ 1,
606 return CMD_WARNING_CONFIG_FAILED
;
609 printed
= snprintf(group_xpath
, sizeof(group_xpath
), "%s[.='%s']",
610 group_list_xpath
, group_str
);
612 if (printed
>= (int)(sizeof(group_xpath
))) {
613 vty_out(vty
, "Xpath too long (%d > %u)", printed
+ 1,
615 return CMD_WARNING_CONFIG_FAILED
;
618 group_dnode
= yang_dnode_get(vty
->candidate_config
->dnode
, group_xpath
);
620 vty_out(vty
, "%% Unable to find specified RP\n");
624 if (yang_is_last_list_dnode(group_dnode
))
625 nb_cli_enqueue_change(vty
, rp_xpath
, NB_OP_DESTROY
, NULL
);
627 nb_cli_enqueue_change(vty
, group_list_xpath
, NB_OP_DESTROY
,
630 return nb_cli_apply_changes(vty
, NULL
);
633 int pim_process_rp_plist_cmd(struct vty
*vty
, const char *rp_str
,
634 const char *prefix_list
)
637 char rp_plist_xpath
[XPATH_MAXLEN
];
639 vrfname
= pim_cli_get_vrf_name(vty
);
641 return CMD_WARNING_CONFIG_FAILED
;
643 snprintf(rp_plist_xpath
, sizeof(rp_plist_xpath
),
644 FRR_PIM_STATIC_RP_XPATH
, "frr-pim:pimd", "pim", vrfname
,
645 FRR_PIM_AF_XPATH_VAL
, rp_str
);
646 strlcat(rp_plist_xpath
, "/prefix-list", sizeof(rp_plist_xpath
));
648 nb_cli_enqueue_change(vty
, rp_plist_xpath
, NB_OP_MODIFY
, prefix_list
);
650 return nb_cli_apply_changes(vty
, NULL
);
653 int pim_process_no_rp_plist_cmd(struct vty
*vty
, const char *rp_str
,
654 const char *prefix_list
)
656 char rp_xpath
[XPATH_MAXLEN
];
657 char plist_xpath
[XPATH_MAXLEN
];
659 const struct lyd_node
*plist_dnode
;
662 vrfname
= pim_cli_get_vrf_name(vty
);
664 return CMD_WARNING_CONFIG_FAILED
;
666 snprintf(rp_xpath
, sizeof(rp_xpath
), FRR_PIM_STATIC_RP_XPATH
,
667 "frr-pim:pimd", "pim", vrfname
, FRR_PIM_AF_XPATH_VAL
, rp_str
);
669 snprintf(plist_xpath
, sizeof(plist_xpath
), FRR_PIM_STATIC_RP_XPATH
,
670 "frr-pim:pimd", "pim", vrfname
, FRR_PIM_AF_XPATH_VAL
, rp_str
);
671 strlcat(plist_xpath
, "/prefix-list", sizeof(plist_xpath
));
673 plist_dnode
= yang_dnode_get(vty
->candidate_config
->dnode
, plist_xpath
);
675 vty_out(vty
, "%% Unable to find specified RP\n");
679 plist
= yang_dnode_get_string(plist_dnode
, plist_xpath
);
680 if (strcmp(prefix_list
, plist
)) {
681 vty_out(vty
, "%% Unable to find specified RP\n");
685 nb_cli_enqueue_change(vty
, rp_xpath
, NB_OP_DESTROY
, NULL
);
687 return nb_cli_apply_changes(vty
, NULL
);
690 bool pim_sgaddr_match(pim_sgaddr item
, pim_sgaddr match
)
692 return (pim_addr_is_any(match
.grp
) ||
693 !pim_addr_cmp(match
.grp
, item
.grp
)) &&
694 (pim_addr_is_any(match
.src
) ||
695 !pim_addr_cmp(match
.src
, item
.src
));
698 void json_object_pim_ifp_add(struct json_object
*json
, struct interface
*ifp
)
700 struct pim_interface
*pim_ifp
;
703 json_object_string_add(json
, "name", ifp
->name
);
704 json_object_string_add(json
, "state", if_is_up(ifp
) ? "up" : "down");
705 json_object_string_addf(json
, "address", "%pPA",
706 &pim_ifp
->primary_address
);
707 json_object_int_add(json
, "index", ifp
->ifindex
);
709 if (if_is_multicast(ifp
))
710 json_object_boolean_true_add(json
, "flagMulticast");
712 if (if_is_broadcast(ifp
))
713 json_object_boolean_true_add(json
, "flagBroadcast");
715 if (ifp
->flags
& IFF_ALLMULTI
)
716 json_object_boolean_true_add(json
, "flagAllMulticast");
718 if (ifp
->flags
& IFF_PROMISC
)
719 json_object_boolean_true_add(json
, "flagPromiscuous");
721 if (PIM_IF_IS_DELETED(ifp
))
722 json_object_boolean_true_add(json
, "flagDeleted");
724 if (pim_if_lan_delay_enabled(ifp
))
725 json_object_boolean_true_add(json
, "lanDelayEnabled");
728 void pim_print_ifp_flags(struct vty
*vty
, struct interface
*ifp
)
730 vty_out(vty
, "Flags\n");
731 vty_out(vty
, "-----\n");
732 vty_out(vty
, "All Multicast : %s\n",
733 (ifp
->flags
& IFF_ALLMULTI
) ? "yes" : "no");
734 vty_out(vty
, "Broadcast : %s\n",
735 if_is_broadcast(ifp
) ? "yes" : "no");
736 vty_out(vty
, "Deleted : %s\n",
737 PIM_IF_IS_DELETED(ifp
) ? "yes" : "no");
738 vty_out(vty
, "Interface Index : %d\n", ifp
->ifindex
);
739 vty_out(vty
, "Multicast : %s\n",
740 if_is_multicast(ifp
) ? "yes" : "no");
741 vty_out(vty
, "Promiscuous : %s\n",
742 (ifp
->flags
& IFF_PROMISC
) ? "yes" : "no");
747 void json_object_pim_upstream_add(json_object
*json
, struct pim_upstream
*up
)
749 json_object_boolean_add(
750 json
, "drJoinDesired",
751 CHECK_FLAG(up
->flags
, PIM_UPSTREAM_FLAG_MASK_DR_JOIN_DESIRED
));
752 json_object_boolean_add(
753 json
, "drJoinDesiredUpdated",
754 CHECK_FLAG(up
->flags
,
755 PIM_UPSTREAM_FLAG_MASK_DR_JOIN_DESIRED_UPDATED
));
756 json_object_boolean_add(
757 json
, "firstHopRouter",
758 CHECK_FLAG(up
->flags
, PIM_UPSTREAM_FLAG_MASK_FHR
));
759 json_object_boolean_add(
761 CHECK_FLAG(up
->flags
, PIM_UPSTREAM_FLAG_MASK_SRC_IGMP
));
762 json_object_boolean_add(
764 CHECK_FLAG(up
->flags
, PIM_UPSTREAM_FLAG_MASK_SRC_PIM
));
765 json_object_boolean_add(
766 json
, "sourceStream",
767 CHECK_FLAG(up
->flags
, PIM_UPSTREAM_FLAG_MASK_SRC_STREAM
));
768 /* XXX: need to print ths flag in the plain text display as well */
769 json_object_boolean_add(
771 CHECK_FLAG(up
->flags
, PIM_UPSTREAM_FLAG_MASK_SRC_MSDP
));
772 json_object_boolean_add(
773 json
, "sendSGRptPrune",
774 CHECK_FLAG(up
->flags
,
775 PIM_UPSTREAM_FLAG_MASK_SEND_SG_RPT_PRUNE
));
776 json_object_boolean_add(
777 json
, "lastHopRouter",
778 CHECK_FLAG(up
->flags
, PIM_UPSTREAM_FLAG_MASK_SRC_LHR
));
779 json_object_boolean_add(
780 json
, "disableKATExpiry",
781 CHECK_FLAG(up
->flags
,
782 PIM_UPSTREAM_FLAG_MASK_DISABLE_KAT_EXPIRY
));
783 json_object_boolean_add(
784 json
, "staticIncomingInterface",
785 CHECK_FLAG(up
->flags
, PIM_UPSTREAM_FLAG_MASK_STATIC_IIF
));
786 json_object_boolean_add(
787 json
, "allowIncomingInterfaceinOil",
788 CHECK_FLAG(up
->flags
, PIM_UPSTREAM_FLAG_MASK_ALLOW_IIF_IN_OIL
));
789 json_object_boolean_add(
790 json
, "noPimRegistrationData",
791 CHECK_FLAG(up
->flags
, PIM_UPSTREAM_FLAG_MASK_NO_PIMREG_DATA
));
792 json_object_boolean_add(
793 json
, "forcePimRegistration",
794 CHECK_FLAG(up
->flags
, PIM_UPSTREAM_FLAG_MASK_FORCE_PIMREG
));
795 json_object_boolean_add(
796 json
, "sourceVxlanOrigination",
797 CHECK_FLAG(up
->flags
, PIM_UPSTREAM_FLAG_MASK_SRC_VXLAN_ORIG
));
798 json_object_boolean_add(
799 json
, "sourceVxlanTermination",
800 CHECK_FLAG(up
->flags
, PIM_UPSTREAM_FLAG_MASK_SRC_VXLAN_TERM
));
801 json_object_boolean_add(
803 CHECK_FLAG(up
->flags
, PIM_UPSTREAM_FLAG_MASK_MLAG_VXLAN
));
804 json_object_boolean_add(
805 json
, "mlagNonDesignatedForwarder",
806 CHECK_FLAG(up
->flags
, PIM_UPSTREAM_FLAG_MASK_MLAG_NON_DF
));
810 pim_upstream_state2brief_str(enum pim_upstream_state join_state
,
811 char *state_str
, size_t state_str_len
)
813 switch (join_state
) {
814 case PIM_UPSTREAM_NOTJOINED
:
815 strlcpy(state_str
, "NotJ", state_str_len
);
817 case PIM_UPSTREAM_JOINED
:
818 strlcpy(state_str
, "J", state_str_len
);
821 strlcpy(state_str
, "Unk", state_str_len
);
826 static const char *pim_reg_state2brief_str(enum pim_reg_state reg_state
,
828 size_t state_str_len
)
832 strlcpy(state_str
, "RegNI", state_str_len
);
835 strlcpy(state_str
, "RegJ", state_str_len
);
837 case PIM_REG_JOIN_PENDING
:
839 strlcpy(state_str
, "RegP", state_str_len
);
845 void pim_show_rpf_refresh_stats(struct vty
*vty
, struct pim_instance
*pim
,
846 time_t now
, json_object
*json
)
848 char refresh_uptime
[10];
850 pim_time_uptime_begin(refresh_uptime
, sizeof(refresh_uptime
), now
,
851 pim
->rpf_cache_refresh_last
);
854 json_object_int_add(json
, "rpfCacheRefreshDelayMsecs",
855 router
->rpf_cache_refresh_delay_msec
);
857 json
, "rpfCacheRefreshTimer",
858 pim_time_timer_remain_msec(pim
->rpf_cache_refresher
));
859 json_object_int_add(json
, "rpfCacheRefreshRequests",
860 pim
->rpf_cache_refresh_requests
);
861 json_object_int_add(json
, "rpfCacheRefreshEvents",
862 pim
->rpf_cache_refresh_events
);
863 json_object_string_add(json
, "rpfCacheRefreshLast",
865 json_object_int_add(json
, "nexthopLookups",
866 pim
->nexthop_lookups
);
867 json_object_int_add(json
, "nexthopLookupsAvoided",
868 pim
->nexthop_lookups_avoided
);
871 "RPF Cache Refresh Delay: %ld msecs\n"
872 "RPF Cache Refresh Timer: %ld msecs\n"
873 "RPF Cache Refresh Requests: %lld\n"
874 "RPF Cache Refresh Events: %lld\n"
875 "RPF Cache Refresh Last: %s\n"
876 "Nexthop Lookups: %lld\n"
877 "Nexthop Lookups Avoided: %lld\n",
878 router
->rpf_cache_refresh_delay_msec
,
879 pim_time_timer_remain_msec(pim
->rpf_cache_refresher
),
880 (long long)pim
->rpf_cache_refresh_requests
,
881 (long long)pim
->rpf_cache_refresh_events
,
882 refresh_uptime
, (long long)pim
->nexthop_lookups
,
883 (long long)pim
->nexthop_lookups_avoided
);
887 void pim_show_rpf(struct pim_instance
*pim
, struct vty
*vty
, json_object
*json
)
889 struct pim_upstream
*up
;
890 time_t now
= pim_time_monotonic_sec();
891 struct ttable
*tt
= NULL
;
893 json_object
*json_group
= NULL
;
894 json_object
*json_row
= NULL
;
896 pim_show_rpf_refresh_stats(vty
, pim
, now
, json
);
902 tt
= ttable_new(&ttable_styles
[TTSTYLE_BLANK
]);
905 "Source|Group|RpfIface|RpfAddress|RibNextHop|Metric|Pref");
906 tt
->style
.cell
.rpad
= 2;
907 tt
->style
.corner
= '+';
911 frr_each (rb_pim_upstream
, &pim
->upstream_head
, up
) {
912 const char *rpf_ifname
;
913 struct pim_rpf
*rpf
= &up
->rpf
;
916 rpf
->source_nexthop
.interface
? rpf
->source_nexthop
921 char grp_str
[PIM_ADDRSTRLEN
];
922 char src_str
[PIM_ADDRSTRLEN
];
924 snprintfrr(grp_str
, sizeof(grp_str
), "%pPAs",
926 snprintfrr(src_str
, sizeof(src_str
), "%pPAs",
929 json_object_object_get_ex(json
, grp_str
, &json_group
);
932 json_group
= json_object_new_object();
933 json_object_object_add(json
, grp_str
,
937 json_row
= json_object_new_object();
938 json_object_string_add(json_row
, "source", src_str
);
939 json_object_string_add(json_row
, "group", grp_str
);
940 json_object_string_add(json_row
, "rpfInterface",
942 json_object_string_addf(json_row
, "rpfAddress", "%pPA",
944 json_object_string_addf(
945 json_row
, "ribNexthop", "%pPAs",
946 &rpf
->source_nexthop
.mrib_nexthop_addr
);
948 json_row
, "routeMetric",
949 rpf
->source_nexthop
.mrib_route_metric
);
951 json_row
, "routePreference",
952 rpf
->source_nexthop
.mrib_metric_preference
);
953 json_object_object_add(json_group
, src_str
, json_row
);
957 tt
, "%pPAs|%pPAs|%s|%pPA|%pPAs|%d|%d",
958 &up
->sg
.src
, &up
->sg
.grp
, rpf_ifname
,
960 &rpf
->source_nexthop
.mrib_nexthop_addr
,
961 rpf
->source_nexthop
.mrib_route_metric
,
962 rpf
->source_nexthop
.mrib_metric_preference
);
965 /* Dump the generated table. */
967 table
= ttable_dump(tt
, "\n");
968 vty_out(vty
, "%s\n", table
);
969 XFREE(MTYPE_TMP
, table
);
974 void pim_show_neighbors_secondary(struct pim_instance
*pim
, struct vty
*vty
)
976 struct interface
*ifp
;
977 struct ttable
*tt
= NULL
;
981 tt
= ttable_new(&ttable_styles
[TTSTYLE_BLANK
]);
982 ttable_add_row(tt
, "Interface|Address|Neighbor|Secondary");
983 tt
->style
.cell
.rpad
= 2;
984 tt
->style
.corner
= '+';
987 FOR_ALL_INTERFACES (pim
->vrf
, ifp
) {
988 struct pim_interface
*pim_ifp
;
990 struct listnode
*neighnode
;
991 struct pim_neighbor
*neigh
;
998 if (pim_ifp
->pim_sock_fd
< 0)
1001 ifaddr
= pim_ifp
->primary_address
;
1003 for (ALL_LIST_ELEMENTS_RO(pim_ifp
->pim_neighbor_list
, neighnode
,
1005 struct listnode
*prefix_node
;
1008 if (!neigh
->prefix_list
)
1011 for (ALL_LIST_ELEMENTS_RO(neigh
->prefix_list
,
1013 ttable_add_row(tt
, "%s|%pPAs|%pPAs|%pFX",
1015 &neigh
->source_addr
, p
);
1018 /* Dump the generated table. */
1019 table
= ttable_dump(tt
, "\n");
1020 vty_out(vty
, "%s\n", table
);
1021 XFREE(MTYPE_TMP
, table
);
1025 void pim_show_state(struct pim_instance
*pim
, struct vty
*vty
,
1026 const char *src_or_group
, const char *group
,
1029 struct channel_oil
*c_oil
;
1030 json_object
*json_group
= NULL
;
1031 json_object
*json_ifp_in
= NULL
;
1032 json_object
*json_ifp_out
= NULL
;
1033 json_object
*json_source
= NULL
;
1037 now
= pim_time_monotonic_sec();
1041 "Codes: J -> Pim Join, I -> " GM
" Report, S -> Source, * -> Inherited from (*,G), V -> VxLAN, M -> Muted");
1043 "\nActive Source Group RPT IIF OIL\n");
1046 frr_each (rb_pim_oil
, &pim
->channel_oil_head
, c_oil
) {
1047 char src_str
[PIM_ADDRSTRLEN
];
1048 char grp_str
[PIM_ADDRSTRLEN
];
1049 char in_ifname
[INTERFACE_NAMSIZ
+ 1];
1050 char out_ifname
[INTERFACE_NAMSIZ
+ 1];
1052 struct interface
*ifp_in
;
1058 PIM_UPSTREAM_FLAG_TEST_USE_RPT(c_oil
->up
->flags
)) ||
1059 pim_addr_is_any(*oil_origin(c_oil
)))
1064 snprintfrr(grp_str
, sizeof(grp_str
), "%pPAs",
1065 oil_mcastgrp(c_oil
));
1066 snprintfrr(src_str
, sizeof(src_str
), "%pPAs",
1068 ifp_in
= pim_if_find_by_vif_index(pim
, *oil_parent(c_oil
));
1071 strlcpy(in_ifname
, ifp_in
->name
, sizeof(in_ifname
));
1073 strlcpy(in_ifname
, "<iif?>", sizeof(in_ifname
));
1076 if (strcmp(src_or_group
, src_str
) &&
1077 strcmp(src_or_group
, grp_str
))
1080 if (group
&& strcmp(group
, grp_str
))
1086 /* Find the group, create it if it doesn't exist */
1087 json_object_object_get_ex(json
, grp_str
, &json_group
);
1090 json_group
= json_object_new_object();
1091 json_object_object_add(json
, grp_str
,
1095 /* Find the source nested under the group, create it if
1098 json_object_object_get_ex(json_group
, src_str
,
1102 json_source
= json_object_new_object();
1103 json_object_object_add(json_group
, src_str
,
1107 /* Find the inbound interface nested under the source,
1108 * create it if it doesn't exist
1110 json_object_object_get_ex(json_source
, in_ifname
,
1114 json_ifp_in
= json_object_new_object();
1115 json_object_object_add(json_source
, in_ifname
,
1117 json_object_int_add(json_source
, "Installed",
1119 json_object_int_add(json_source
, "installed",
1121 json_object_boolean_add(json_source
, "isRpt",
1123 json_object_int_add(json_source
, "RefCount",
1124 c_oil
->oil_ref_count
);
1125 json_object_int_add(json_source
, "refCount",
1126 c_oil
->oil_ref_count
);
1127 json_object_int_add(json_source
, "OilListSize",
1129 json_object_int_add(json_source
, "oilListSize",
1131 json_object_int_add(
1132 json_source
, "OilRescan",
1133 c_oil
->oil_inherited_rescan
);
1134 json_object_int_add(
1135 json_source
, "oilRescan",
1136 c_oil
->oil_inherited_rescan
);
1137 json_object_int_add(json_source
, "LastUsed",
1138 c_oil
->cc
.lastused
);
1139 json_object_int_add(json_source
, "lastUsed",
1140 c_oil
->cc
.lastused
);
1141 json_object_int_add(json_source
, "PacketCount",
1143 json_object_int_add(json_source
, "packetCount",
1145 json_object_int_add(json_source
, "ByteCount",
1147 json_object_int_add(json_source
, "byteCount",
1149 json_object_int_add(json_source
,
1151 c_oil
->cc
.wrong_if
);
1152 json_object_int_add(json_source
,
1154 c_oil
->cc
.wrong_if
);
1157 vty_out(vty
, "%-6d %-15pPAs %-15pPAs %-3s %-16s ",
1158 c_oil
->installed
, oil_origin(c_oil
),
1159 oil_mcastgrp(c_oil
), isRpt
? "y" : "n",
1162 for (oif_vif_index
= 0; oif_vif_index
< MAXVIFS
;
1164 struct interface
*ifp_out
;
1165 char oif_uptime
[10];
1168 ttl
= oil_if_has(c_oil
, oif_vif_index
);
1172 ifp_out
= pim_if_find_by_vif_index(pim
, oif_vif_index
);
1174 oif_uptime
, sizeof(oif_uptime
),
1175 now
- c_oil
->oif_creation
[oif_vif_index
]);
1178 strlcpy(out_ifname
, ifp_out
->name
,
1179 sizeof(out_ifname
));
1181 strlcpy(out_ifname
, "<oif?>",
1182 sizeof(out_ifname
));
1185 json_ifp_out
= json_object_new_object();
1186 json_object_string_add(json_ifp_out
, "source",
1188 json_object_string_add(json_ifp_out
, "group",
1190 json_object_string_add(json_ifp_out
,
1193 json_object_string_add(json_ifp_out
,
1194 "outboundInterface",
1196 json_object_int_add(json_ifp_out
, "installed",
1199 json_object_object_add(json_ifp_in
, out_ifname
,
1204 vty_out(vty
, "%s(%c%c%c%c%c)",
1208 PIM_OIF_FLAG_PROTO_GM
)
1213 PIM_OIF_FLAG_PROTO_PIM
)
1218 PIM_OIF_FLAG_PROTO_VXLAN
)
1223 PIM_OIF_FLAG_PROTO_STAR
)
1232 vty_out(vty
, ", %s(%c%c%c%c%c)",
1236 PIM_OIF_FLAG_PROTO_GM
)
1241 PIM_OIF_FLAG_PROTO_PIM
)
1246 PIM_OIF_FLAG_PROTO_VXLAN
)
1251 PIM_OIF_FLAG_PROTO_STAR
)
1270 /* pim statistics - just adding only bsm related now.
1271 * We can continue to add all pim related stats here.
1273 void pim_show_statistics(struct pim_instance
*pim
, struct vty
*vty
,
1274 const char *ifname
, bool uj
)
1276 json_object
*json
= NULL
;
1277 struct interface
*ifp
;
1280 json
= json_object_new_object();
1281 json_object_int_add(json
, "bsmRx", pim
->bsm_rcvd
);
1282 json_object_int_add(json
, "bsmTx", pim
->bsm_sent
);
1283 json_object_int_add(json
, "bsmDropped", pim
->bsm_dropped
);
1285 vty_out(vty
, "BSM Statistics :\n");
1286 vty_out(vty
, "----------------\n");
1287 vty_out(vty
, "Number of Received BSMs : %" PRIu64
"\n",
1289 vty_out(vty
, "Number of Forwared BSMs : %" PRIu64
"\n",
1291 vty_out(vty
, "Number of Dropped BSMs : %" PRIu64
"\n",
1297 /* scan interfaces */
1298 FOR_ALL_INTERFACES (pim
->vrf
, ifp
) {
1299 struct pim_interface
*pim_ifp
= ifp
->info
;
1301 if (ifname
&& strcmp(ifname
, ifp
->name
))
1308 vty_out(vty
, "Interface : %s\n", ifp
->name
);
1309 vty_out(vty
, "-------------------\n");
1311 "Number of BSMs dropped due to config miss : %u\n",
1312 pim_ifp
->pim_ifstat_bsm_cfg_miss
);
1313 vty_out(vty
, "Number of unicast BSMs dropped : %u\n",
1314 pim_ifp
->pim_ifstat_ucast_bsm_cfg_miss
);
1316 "Number of BSMs dropped due to invalid scope zone : %u\n",
1317 pim_ifp
->pim_ifstat_bsm_invalid_sz
);
1320 json_object
*json_row
= NULL
;
1322 json_row
= json_object_new_object();
1324 json_object_string_add(json_row
, "If Name", ifp
->name
);
1325 json_object_int_add(json_row
, "bsmDroppedConfig",
1326 pim_ifp
->pim_ifstat_bsm_cfg_miss
);
1327 json_object_int_add(
1328 json_row
, "bsmDroppedUnicast",
1329 pim_ifp
->pim_ifstat_ucast_bsm_cfg_miss
);
1330 json_object_int_add(json_row
,
1331 "bsmDroppedInvalidScopeZone",
1332 pim_ifp
->pim_ifstat_bsm_invalid_sz
);
1333 json_object_object_add(json
, ifp
->name
, json_row
);
1339 vty_json(vty
, json
);
1342 void pim_show_upstream(struct pim_instance
*pim
, struct vty
*vty
,
1343 pim_sgaddr
*sg
, json_object
*json
)
1345 struct pim_upstream
*up
;
1346 struct ttable
*tt
= NULL
;
1349 json_object
*json_group
= NULL
;
1350 json_object
*json_row
= NULL
;
1352 now
= pim_time_monotonic_sec();
1355 /* Prepare table. */
1356 tt
= ttable_new(&ttable_styles
[TTSTYLE_BLANK
]);
1359 "Iif|Source|Group|State|Uptime|JoinTimer|RSTimer|KATimer|RefCnt");
1360 tt
->style
.cell
.rpad
= 2;
1361 tt
->style
.corner
= '+';
1365 frr_each (rb_pim_upstream
, &pim
->upstream_head
, up
) {
1367 char join_timer
[10];
1370 char msdp_reg_timer
[10];
1371 char state_str
[PIM_REG_STATE_STR_LEN
];
1373 if (!pim_sgaddr_match(up
->sg
, *sg
))
1376 pim_time_uptime(uptime
, sizeof(uptime
),
1377 now
- up
->state_transition
);
1378 pim_time_timer_to_hhmmss(join_timer
, sizeof(join_timer
),
1382 * If the upstream is not dummy and it has a J/P timer for the
1383 * neighbor display that
1385 if (!up
->t_join_timer
&& up
->rpf
.source_nexthop
.interface
) {
1386 struct pim_neighbor
*nbr
;
1388 nbr
= pim_neighbor_find(
1389 up
->rpf
.source_nexthop
.interface
,
1392 pim_time_timer_to_hhmmss(join_timer
,
1397 pim_time_timer_to_hhmmss(rs_timer
, sizeof(rs_timer
),
1399 pim_time_timer_to_hhmmss(ka_timer
, sizeof(ka_timer
),
1401 pim_time_timer_to_hhmmss(msdp_reg_timer
, sizeof(msdp_reg_timer
),
1402 up
->t_msdp_reg_timer
);
1404 pim_upstream_state2brief_str(up
->join_state
, state_str
,
1406 if (up
->reg_state
!= PIM_REG_NOINFO
) {
1407 char tmp_str
[PIM_REG_STATE_STR_LEN
];
1408 char tmp
[sizeof(state_str
) + 1];
1410 snprintf(tmp
, sizeof(tmp
), ",%s",
1411 pim_reg_state2brief_str(up
->reg_state
, tmp_str
,
1413 strlcat(state_str
, tmp
, sizeof(state_str
));
1417 char grp_str
[PIM_ADDRSTRLEN
];
1418 char src_str
[PIM_ADDRSTRLEN
];
1420 snprintfrr(grp_str
, sizeof(grp_str
), "%pPAs",
1422 snprintfrr(src_str
, sizeof(src_str
), "%pPAs",
1425 json_object_object_get_ex(json
, grp_str
, &json_group
);
1428 json_group
= json_object_new_object();
1429 json_object_object_add(json
, grp_str
,
1433 json_row
= json_object_new_object();
1434 json_object_pim_upstream_add(json_row
, up
);
1435 json_object_string_add(
1436 json_row
, "inboundInterface",
1437 up
->rpf
.source_nexthop
.interface
1438 ? up
->rpf
.source_nexthop
.interface
->name
1442 * The RPF address we use is slightly different
1443 * based upon what we are looking up.
1444 * If we have a S, list that unless
1445 * we are the FHR, else we just put
1446 * the RP as the rpfAddress
1448 if (up
->flags
& PIM_UPSTREAM_FLAG_MASK_FHR
||
1449 pim_addr_is_any(up
->sg
.src
)) {
1450 struct pim_rpf
*rpg
;
1452 rpg
= RP(pim
, up
->sg
.grp
);
1453 json_object_string_addf(json_row
, "rpfAddress",
1454 "%pPA", &rpg
->rpf_addr
);
1456 json_object_string_add(json_row
, "rpfAddress",
1460 json_object_string_add(json_row
, "source", src_str
);
1461 json_object_string_add(json_row
, "group", grp_str
);
1462 json_object_string_add(json_row
, "state", state_str
);
1463 json_object_string_add(
1464 json_row
, "joinState",
1465 pim_upstream_state2str(up
->join_state
));
1466 json_object_string_add(
1467 json_row
, "regState",
1468 pim_reg_state2str(up
->reg_state
, state_str
,
1469 sizeof(state_str
)));
1470 json_object_string_add(json_row
, "upTime", uptime
);
1471 json_object_string_add(json_row
, "joinTimer",
1473 json_object_string_add(json_row
, "resetTimer",
1475 json_object_string_add(json_row
, "keepaliveTimer",
1477 json_object_string_add(json_row
, "msdpRegTimer",
1479 json_object_int_add(json_row
, "refCount",
1481 json_object_int_add(json_row
, "sptBit", up
->sptbit
);
1482 json_object_object_add(json_group
, src_str
, json_row
);
1485 "%s|%pPAs|%pPAs|%s|%s|%s|%s|%s|%d",
1486 up
->rpf
.source_nexthop
.interface
1487 ? up
->rpf
.source_nexthop
.interface
->name
1489 &up
->sg
.src
, &up
->sg
.grp
, state_str
, uptime
,
1490 join_timer
, rs_timer
, ka_timer
, up
->ref_count
);
1493 /* Dump the generated table. */
1495 table
= ttable_dump(tt
, "\n");
1496 vty_out(vty
, "%s\n", table
);
1497 XFREE(MTYPE_TMP
, table
);
1502 static void pim_show_join_desired_helper(struct pim_instance
*pim
,
1504 struct pim_upstream
*up
,
1505 json_object
*json
, bool uj
,
1508 json_object
*json_group
= NULL
;
1509 json_object
*json_row
= NULL
;
1512 char grp_str
[PIM_ADDRSTRLEN
];
1513 char src_str
[PIM_ADDRSTRLEN
];
1515 snprintfrr(grp_str
, sizeof(grp_str
), "%pPAs", &up
->sg
.grp
);
1516 snprintfrr(src_str
, sizeof(src_str
), "%pPAs", &up
->sg
.src
);
1518 json_object_object_get_ex(json
, grp_str
, &json_group
);
1521 json_group
= json_object_new_object();
1522 json_object_object_add(json
, grp_str
, json_group
);
1525 json_row
= json_object_new_object();
1526 json_object_pim_upstream_add(json_row
, up
);
1527 json_object_string_add(json_row
, "source", src_str
);
1528 json_object_string_add(json_row
, "group", grp_str
);
1530 if (pim_upstream_evaluate_join_desired(pim
, up
))
1531 json_object_boolean_true_add(json_row
,
1532 "evaluateJoinDesired");
1534 json_object_object_add(json_group
, src_str
, json_row
);
1537 ttable_add_row(tt
, "%pPAs|%pPAs|%s", &up
->sg
.src
, &up
->sg
.grp
,
1538 pim_upstream_evaluate_join_desired(pim
, up
)
1544 void pim_show_join_desired(struct pim_instance
*pim
, struct vty
*vty
, bool uj
)
1546 struct pim_upstream
*up
;
1547 struct ttable
*tt
= NULL
;
1550 json_object
*json
= NULL
;
1553 json
= json_object_new_object();
1555 /* Prepare table. */
1556 tt
= ttable_new(&ttable_styles
[TTSTYLE_BLANK
]);
1557 ttable_add_row(tt
, "Source|Group|EvalJD");
1558 tt
->style
.cell
.rpad
= 2;
1559 tt
->style
.corner
= '+';
1563 frr_each (rb_pim_upstream
, &pim
->upstream_head
, up
) {
1564 /* scan all interfaces */
1565 pim_show_join_desired_helper(pim
, vty
, up
, json
, uj
, tt
);
1569 vty_json(vty
, json
);
1571 /* Dump the generated table. */
1572 table
= ttable_dump(tt
, "\n");
1573 vty_out(vty
, "%s\n", table
);
1574 XFREE(MTYPE_TMP
, table
);
1579 void pim_show_upstream_rpf(struct pim_instance
*pim
, struct vty
*vty
, bool uj
)
1581 struct pim_upstream
*up
;
1582 struct ttable
*tt
= NULL
;
1584 json_object
*json
= NULL
;
1585 json_object
*json_group
= NULL
;
1586 json_object
*json_row
= NULL
;
1589 json
= json_object_new_object();
1591 /* Prepare table. */
1592 tt
= ttable_new(&ttable_styles
[TTSTYLE_BLANK
]);
1594 "Source|Group|RpfIface|RibNextHop|RpfAddress");
1595 tt
->style
.cell
.rpad
= 2;
1596 tt
->style
.corner
= '+';
1600 frr_each (rb_pim_upstream
, &pim
->upstream_head
, up
) {
1601 struct pim_rpf
*rpf
;
1602 const char *rpf_ifname
;
1607 rpf
->source_nexthop
.interface
? rpf
->source_nexthop
1612 char grp_str
[PIM_ADDRSTRLEN
];
1613 char src_str
[PIM_ADDRSTRLEN
];
1615 snprintfrr(grp_str
, sizeof(grp_str
), "%pPAs",
1617 snprintfrr(src_str
, sizeof(src_str
), "%pPAs",
1619 json_object_object_get_ex(json
, grp_str
, &json_group
);
1622 json_group
= json_object_new_object();
1623 json_object_object_add(json
, grp_str
,
1627 json_row
= json_object_new_object();
1628 json_object_pim_upstream_add(json_row
, up
);
1629 json_object_string_add(json_row
, "source", src_str
);
1630 json_object_string_add(json_row
, "group", grp_str
);
1631 json_object_string_add(json_row
, "rpfInterface",
1633 json_object_string_addf(
1634 json_row
, "ribNexthop", "%pPAs",
1635 &rpf
->source_nexthop
.mrib_nexthop_addr
);
1636 json_object_string_addf(json_row
, "rpfAddress", "%pPA",
1638 json_object_object_add(json_group
, src_str
, json_row
);
1640 ttable_add_row(tt
, "%pPAs|%pPAs|%s|%pPA|%pPA",
1641 &up
->sg
.src
, &up
->sg
.grp
, rpf_ifname
,
1642 &rpf
->source_nexthop
.mrib_nexthop_addr
,
1648 vty_json(vty
, json
);
1650 /* Dump the generated table. */
1651 table
= ttable_dump(tt
, "\n");
1652 vty_out(vty
, "%s\n", table
);
1653 XFREE(MTYPE_TMP
, table
);
1658 static void pim_show_join_helper(struct vty
*vty
, struct pim_interface
*pim_ifp
,
1659 struct pim_ifchannel
*ch
, json_object
*json
,
1662 json_object
*json_iface
= NULL
;
1663 json_object
*json_row
= NULL
;
1664 json_object
*json_grp
= NULL
;
1670 ifaddr
= pim_ifp
->primary_address
;
1672 pim_time_uptime_begin(uptime
, sizeof(uptime
), now
, ch
->ifjoin_creation
);
1673 pim_time_timer_to_mmss(expire
, sizeof(expire
),
1674 ch
->t_ifjoin_expiry_timer
);
1675 pim_time_timer_to_mmss(prune
, sizeof(prune
),
1676 ch
->t_ifjoin_prune_pending_timer
);
1679 char ch_grp_str
[PIM_ADDRSTRLEN
];
1681 json_object_object_get_ex(json
, ch
->interface
->name
,
1685 json_iface
= json_object_new_object();
1686 json_object_pim_ifp_add(json_iface
, ch
->interface
);
1687 json_object_object_add(json
, ch
->interface
->name
,
1691 json_row
= json_object_new_object();
1692 json_object_string_addf(json_row
, "source", "%pPAs",
1694 json_object_string_addf(json_row
, "group", "%pPAs",
1696 json_object_string_add(json_row
, "upTime", uptime
);
1697 json_object_string_add(json_row
, "expire", expire
);
1698 json_object_string_add(json_row
, "prune", prune
);
1699 json_object_string_add(
1700 json_row
, "channelJoinName",
1701 pim_ifchannel_ifjoin_name(ch
->ifjoin_state
, ch
->flags
));
1702 if (PIM_IF_FLAG_TEST_S_G_RPT(ch
->flags
)) {
1703 #if CONFDATE > 20230131
1705 "Remove JSON object commands with keys starting with capital")
1707 json_object_int_add(json_row
, "SGRpt", 1);
1708 json_object_int_add(json_row
, "sgRpt", 1);
1710 if (PIM_IF_FLAG_TEST_PROTO_PIM(ch
->flags
))
1711 json_object_int_add(json_row
, "protocolPim", 1);
1712 if (PIM_IF_FLAG_TEST_PROTO_IGMP(ch
->flags
))
1713 json_object_int_add(json_row
, "protocolIgmp", 1);
1714 snprintfrr(ch_grp_str
, sizeof(ch_grp_str
), "%pPAs",
1716 json_object_object_get_ex(json_iface
, ch_grp_str
, &json_grp
);
1718 json_grp
= json_object_new_object();
1719 json_object_object_addf(json_grp
, json_row
, "%pPAs",
1721 json_object_object_addf(json_iface
, json_grp
, "%pPAs",
1724 json_object_object_addf(json_grp
, json_row
, "%pPAs",
1728 "%-16s %-15pPAs %-15pPAs %-15pPAs %-10s %8s %-6s %5s\n",
1729 ch
->interface
->name
, &ifaddr
, &ch
->sg
.src
, &ch
->sg
.grp
,
1730 pim_ifchannel_ifjoin_name(ch
->ifjoin_state
, ch
->flags
),
1731 uptime
, expire
, prune
);
1735 int pim_show_join_cmd_helper(const char *vrf
, struct vty
*vty
, pim_addr s_or_g
,
1736 pim_addr g
, const char *json
)
1740 struct pim_instance
*pim
;
1741 json_object
*json_parent
= NULL
;
1743 v
= vrf_lookup_by_name(vrf
? vrf
: VRF_DEFAULT_NAME
);
1746 vty_out(vty
, "%% Vrf specified: %s does not exist\n", vrf
);
1752 vty_out(vty
, "%% Unable to find pim instance\n");
1756 if (!pim_addr_is_any(s_or_g
)) {
1757 if (!pim_addr_is_any(g
)) {
1765 json_parent
= json_object_new_object();
1767 pim_show_join(pim
, vty
, &sg
, json_parent
);
1770 vty_json(vty
, json_parent
);
1775 int pim_show_join_vrf_all_cmd_helper(struct vty
*vty
, const char *json
)
1777 pim_sgaddr sg
= {0};
1778 struct vrf
*vrf_struct
;
1779 json_object
*json_parent
= NULL
;
1780 json_object
*json_vrf
= NULL
;
1783 json_parent
= json_object_new_object();
1785 RB_FOREACH (vrf_struct
, vrf_name_head
, &vrfs_by_name
) {
1787 vty_out(vty
, "VRF: %s\n", vrf_struct
->name
);
1789 json_vrf
= json_object_new_object();
1790 pim_show_join(vrf_struct
->info
, vty
, &sg
, json_vrf
);
1793 json_object_object_add(json_parent
, vrf_struct
->name
,
1797 vty_json(vty
, json_parent
);
1802 void pim_show_join(struct pim_instance
*pim
, struct vty
*vty
, pim_sgaddr
*sg
,
1805 struct pim_interface
*pim_ifp
;
1806 struct pim_ifchannel
*ch
;
1807 struct interface
*ifp
;
1810 now
= pim_time_monotonic_sec();
1814 "Interface Address Source Group State Uptime Expire Prune\n");
1816 FOR_ALL_INTERFACES (pim
->vrf
, ifp
) {
1817 pim_ifp
= ifp
->info
;
1821 RB_FOREACH (ch
, pim_ifchannel_rb
, &pim_ifp
->ifchannel_rb
) {
1822 if (!pim_sgaddr_match(ch
->sg
, *sg
))
1825 pim_show_join_helper(vty
, pim_ifp
, ch
, json
, now
);
1826 } /* scan interface channels */
1830 static void pim_show_jp_agg_helper(struct interface
*ifp
,
1831 struct pim_neighbor
*neigh
,
1832 struct pim_upstream
*up
, int is_join
,
1835 ttable_add_row(tt
, "%s|%pPAs|%pPAs|%pPAs|%s", ifp
->name
,
1836 &neigh
->source_addr
, &up
->sg
.src
, &up
->sg
.grp
,
1837 is_join
? "J" : "P");
1840 int pim_show_jp_agg_list_cmd_helper(const char *vrf
, struct vty
*vty
)
1843 struct pim_instance
*pim
;
1845 v
= vrf_lookup_by_name(vrf
? vrf
: VRF_DEFAULT_NAME
);
1848 vty_out(vty
, "%% Vrf specified: %s does not exist\n", vrf
);
1854 vty_out(vty
, "%% Unable to find pim instance\n");
1858 pim_show_jp_agg_list(pim
, vty
);
1863 void pim_show_jp_agg_list(struct pim_instance
*pim
, struct vty
*vty
)
1865 struct interface
*ifp
;
1866 struct pim_interface
*pim_ifp
;
1867 struct listnode
*n_node
;
1868 struct pim_neighbor
*neigh
;
1869 struct listnode
*jag_node
;
1870 struct pim_jp_agg_group
*jag
;
1871 struct listnode
*js_node
;
1872 struct pim_jp_sources
*js
;
1876 /* Prepare table. */
1877 tt
= ttable_new(&ttable_styles
[TTSTYLE_BLANK
]);
1878 ttable_add_row(tt
, "Interface|RPF Nbr|Source|Group|State");
1879 tt
->style
.cell
.rpad
= 2;
1880 tt
->style
.corner
= '+';
1883 FOR_ALL_INTERFACES (pim
->vrf
, ifp
) {
1884 pim_ifp
= ifp
->info
;
1888 for (ALL_LIST_ELEMENTS_RO(pim_ifp
->pim_neighbor_list
, n_node
,
1890 for (ALL_LIST_ELEMENTS_RO(neigh
->upstream_jp_agg
,
1892 for (ALL_LIST_ELEMENTS_RO(jag
->sources
, js_node
,
1894 pim_show_jp_agg_helper(ifp
, neigh
,
1902 /* Dump the generated table. */
1903 table
= ttable_dump(tt
, "\n");
1904 vty_out(vty
, "%s\n", table
);
1905 XFREE(MTYPE_TMP
, table
);
1909 int pim_show_membership_cmd_helper(const char *vrf
, struct vty
*vty
, bool uj
)
1913 v
= vrf_lookup_by_name(vrf
? vrf
: VRF_DEFAULT_NAME
);
1918 pim_show_membership(v
->info
, vty
, uj
);
1923 static void pim_show_membership_helper(struct vty
*vty
,
1924 struct pim_interface
*pim_ifp
,
1925 struct pim_ifchannel
*ch
,
1926 struct json_object
*json
)
1928 json_object
*json_iface
= NULL
;
1929 json_object
*json_row
= NULL
;
1931 json_object_object_get_ex(json
, ch
->interface
->name
, &json_iface
);
1933 json_iface
= json_object_new_object();
1934 json_object_pim_ifp_add(json_iface
, ch
->interface
);
1935 json_object_object_add(json
, ch
->interface
->name
, json_iface
);
1938 json_row
= json_object_new_object();
1939 json_object_string_addf(json_row
, "source", "%pPAs", &ch
->sg
.src
);
1940 json_object_string_addf(json_row
, "group", "%pPAs", &ch
->sg
.grp
);
1941 json_object_string_add(json_row
, "localMembership",
1942 ch
->local_ifmembership
== PIM_IFMEMBERSHIP_NOINFO
1945 json_object_object_addf(json_iface
, json_row
, "%pPAs", &ch
->sg
.grp
);
1948 void pim_show_membership(struct pim_instance
*pim
, struct vty
*vty
, bool uj
)
1950 struct pim_interface
*pim_ifp
;
1951 struct pim_ifchannel
*ch
;
1952 struct interface
*ifp
;
1953 enum json_type type
;
1954 json_object
*json
= NULL
;
1955 json_object
*json_tmp
= NULL
;
1957 json
= json_object_new_object();
1959 FOR_ALL_INTERFACES (pim
->vrf
, ifp
) {
1960 pim_ifp
= ifp
->info
;
1964 RB_FOREACH (ch
, pim_ifchannel_rb
, &pim_ifp
->ifchannel_rb
) {
1965 pim_show_membership_helper(vty
, pim_ifp
, ch
, json
);
1966 } /* scan interface channels */
1970 vty_json(vty
, json
);
1973 "Interface Address Source Group Membership\n");
1976 * Example of the json data we are traversing
1982 * "address":"10.1.20.1",
1984 * "flagMulticast":true,
1985 * "flagBroadcast":true,
1986 * "lanDelayEnabled":true,
1989 * "group":"226.10.10.10",
1990 * "localMembership":"INCLUDE"
1996 /* foreach interface */
1997 json_object_object_foreach(json
, key
, val
)
2000 /* Find all of the keys where the val is an object. In
2002 * above the only one is 226.10.10.10
2004 json_object_object_foreach(val
, if_field_key
,
2007 type
= json_object_get_type(if_field_val
);
2009 if (type
== json_type_object
) {
2010 vty_out(vty
, "%-16s ", key
);
2012 json_object_object_get_ex(
2013 val
, "address", &json_tmp
);
2014 vty_out(vty
, "%-15s ",
2015 json_object_get_string(
2018 json_object_object_get_ex(if_field_val
,
2021 vty_out(vty
, "%-15s ",
2022 json_object_get_string(
2026 vty_out(vty
, "%-15s ", if_field_key
);
2028 json_object_object_get_ex(
2029 if_field_val
, "localMembership",
2031 vty_out(vty
, "%-10s\n",
2032 json_object_get_string(
2037 json_object_free(json
);
2041 static void pim_show_channel_helper(struct pim_instance
*pim
,
2042 struct pim_interface
*pim_ifp
,
2043 struct pim_ifchannel
*ch
, json_object
*json
,
2044 bool uj
, struct ttable
*tt
)
2046 struct pim_upstream
*up
= ch
->upstream
;
2047 json_object
*json_group
= NULL
;
2048 json_object
*json_row
= NULL
;
2051 char grp_str
[PIM_ADDRSTRLEN
];
2053 snprintfrr(grp_str
, sizeof(grp_str
), "%pPAs", &up
->sg
.grp
);
2054 json_object_object_get_ex(json
, grp_str
, &json_group
);
2057 json_group
= json_object_new_object();
2058 json_object_object_add(json
, grp_str
, json_group
);
2061 json_row
= json_object_new_object();
2062 json_object_pim_upstream_add(json_row
, up
);
2063 json_object_string_add(json_row
, "interface",
2064 ch
->interface
->name
);
2065 json_object_string_addf(json_row
, "source", "%pPAs",
2067 json_object_string_addf(json_row
, "group", "%pPAs",
2070 if (pim_macro_ch_lost_assert(ch
))
2071 json_object_boolean_true_add(json_row
, "lostAssert");
2073 if (pim_macro_chisin_joins(ch
))
2074 json_object_boolean_true_add(json_row
, "joins");
2076 if (pim_macro_chisin_pim_include(ch
))
2077 json_object_boolean_true_add(json_row
, "pimInclude");
2079 if (pim_upstream_evaluate_join_desired(pim
, up
))
2080 json_object_boolean_true_add(json_row
,
2081 "evaluateJoinDesired");
2083 json_object_object_addf(json_group
, json_row
, "%pPAs",
2087 ttable_add_row(tt
, "%s|%pPAs|%pPAs|%s|%s|%s|%s|%s",
2088 ch
->interface
->name
, &up
->sg
.src
, &up
->sg
.grp
,
2089 pim_macro_ch_lost_assert(ch
) ? "yes" : "no",
2090 pim_macro_chisin_joins(ch
) ? "yes" : "no",
2091 pim_macro_chisin_pim_include(ch
) ? "yes" : "no",
2092 PIM_UPSTREAM_FLAG_TEST_DR_JOIN_DESIRED(up
->flags
)
2095 pim_upstream_evaluate_join_desired(pim
, up
)
2101 void pim_show_channel(struct pim_instance
*pim
, struct vty
*vty
, bool uj
)
2103 struct pim_interface
*pim_ifp
;
2104 struct pim_ifchannel
*ch
;
2105 struct interface
*ifp
;
2106 struct ttable
*tt
= NULL
;
2107 json_object
*json
= NULL
;
2111 json
= json_object_new_object();
2113 /* Prepare table. */
2114 tt
= ttable_new(&ttable_styles
[TTSTYLE_BLANK
]);
2117 "Interface|Source|Group|LostAssert|Joins|PimInclude|JoinDesired|EvalJD");
2118 tt
->style
.cell
.rpad
= 2;
2119 tt
->style
.corner
= '+';
2123 /* scan per-interface (S,G) state */
2124 FOR_ALL_INTERFACES (pim
->vrf
, ifp
) {
2125 pim_ifp
= ifp
->info
;
2129 RB_FOREACH (ch
, pim_ifchannel_rb
, &pim_ifp
->ifchannel_rb
) {
2130 /* scan all interfaces */
2131 pim_show_channel_helper(pim
, pim_ifp
, ch
, json
, uj
, tt
);
2136 vty_json(vty
, json
);
2138 /* Dump the generated table. */
2139 table
= ttable_dump(tt
, "\n");
2140 vty_out(vty
, "%s\n", table
);
2141 XFREE(MTYPE_TMP
, table
);
2146 int pim_show_channel_cmd_helper(const char *vrf
, struct vty
*vty
, bool uj
)
2150 v
= vrf_lookup_by_name(vrf
? vrf
: VRF_DEFAULT_NAME
);
2155 pim_show_channel(v
->info
, vty
, uj
);
2160 int pim_show_interface_cmd_helper(const char *vrf
, struct vty
*vty
, bool uj
,
2161 bool mlag
, const char *interface
)
2164 json_object
*json_parent
= NULL
;
2166 v
= vrf_lookup_by_name(vrf
? vrf
: VRF_DEFAULT_NAME
);
2172 json_parent
= json_object_new_object();
2175 pim_show_interfaces_single(v
->info
, vty
, interface
, mlag
,
2178 pim_show_interfaces(v
->info
, vty
, mlag
, json_parent
);
2181 vty_json(vty
, json_parent
);
2186 int pim_show_interface_vrf_all_cmd_helper(struct vty
*vty
, bool uj
, bool mlag
,
2187 const char *interface
)
2190 json_object
*json_parent
= NULL
;
2191 json_object
*json_vrf
= NULL
;
2194 json_parent
= json_object_new_object();
2196 RB_FOREACH (v
, vrf_name_head
, &vrfs_by_name
) {
2198 vty_out(vty
, "VRF: %s\n", v
->name
);
2200 json_vrf
= json_object_new_object();
2203 pim_show_interfaces_single(v
->info
, vty
, interface
,
2206 pim_show_interfaces(v
->info
, vty
, mlag
, json_vrf
);
2209 json_object_object_add(json_parent
, v
->name
, json_vrf
);
2212 vty_json(vty
, json_parent
);
2217 void pim_show_interfaces(struct pim_instance
*pim
, struct vty
*vty
, bool mlag
,
2220 struct interface
*ifp
;
2221 struct pim_interface
*pim_ifp
;
2222 struct pim_upstream
*up
;
2225 int pim_ifchannels
= 0;
2227 struct ttable
*tt
= NULL
;
2229 json_object
*json_row
= NULL
;
2230 json_object
*json_tmp
;
2234 json
= json_object_new_object();
2237 FOR_ALL_INTERFACES (pim
->vrf
, ifp
) {
2238 pim_ifp
= ifp
->info
;
2243 if (mlag
== true && pim_ifp
->activeactive
== false)
2246 pim_nbrs
= pim_ifp
->pim_neighbor_list
->count
;
2247 pim_ifchannels
= pim_if_ifchannel_count(pim_ifp
);
2250 frr_each (rb_pim_upstream
, &pim
->upstream_head
, up
)
2251 if (ifp
== up
->rpf
.source_nexthop
.interface
)
2252 if (up
->flags
& PIM_UPSTREAM_FLAG_MASK_FHR
)
2255 json_row
= json_object_new_object();
2256 json_object_pim_ifp_add(json_row
, ifp
);
2257 json_object_int_add(json_row
, "pimNeighbors", pim_nbrs
);
2258 json_object_int_add(json_row
, "pimIfChannels", pim_ifchannels
);
2259 json_object_int_add(json_row
, "firstHopRouterCount", fhr
);
2260 json_object_string_addf(json_row
, "pimDesignatedRouter",
2261 "%pPAs", &pim_ifp
->pim_dr_addr
);
2263 if (!pim_addr_cmp(pim_ifp
->pim_dr_addr
,
2264 pim_ifp
->primary_address
))
2265 json_object_boolean_true_add(
2266 json_row
, "pimDesignatedRouterLocal");
2268 json_object_object_add(json
, ifp
->name
, json_row
);
2273 /* Prepare table. */
2274 tt
= ttable_new(&ttable_styles
[TTSTYLE_BLANK
]);
2277 "Interface|State|Address|PIM Nbrs|PIM DR|FHR|IfChannels");
2278 tt
->style
.cell
.rpad
= 2;
2279 tt
->style
.corner
= '+';
2282 json_object_object_foreach(json
, key
, val
)
2284 const char *state
, *address
, *pimdr
;
2285 int neighbors
, firsthpr
, pimifchnl
;
2287 json_object_object_get_ex(val
, "state", &json_tmp
);
2288 state
= json_object_get_string(json_tmp
);
2290 json_object_object_get_ex(val
, "address", &json_tmp
);
2291 address
= json_object_get_string(json_tmp
);
2293 json_object_object_get_ex(val
, "pimNeighbors",
2295 neighbors
= json_object_get_int(json_tmp
);
2297 if (json_object_object_get_ex(
2298 val
, "pimDesignatedRouterLocal",
2302 json_object_object_get_ex(
2303 val
, "pimDesignatedRouter", &json_tmp
);
2304 pimdr
= json_object_get_string(json_tmp
);
2307 json_object_object_get_ex(val
, "firstHopRouter",
2309 firsthpr
= json_object_get_int(json_tmp
);
2311 json_object_object_get_ex(val
, "pimIfChannels",
2313 pimifchnl
= json_object_get_int(json_tmp
);
2315 ttable_add_row(tt
, "%s|%s|%s|%d|%s|%d|%d", key
, state
,
2316 address
, neighbors
, pimdr
, firsthpr
,
2319 json_object_free(json
);
2321 /* Dump the generated table. */
2322 table
= ttable_dump(tt
, "\n");
2323 vty_out(vty
, "%s\n", table
);
2324 XFREE(MTYPE_TMP
, table
);
2330 void pim_show_interfaces_single(struct pim_instance
*pim
, struct vty
*vty
,
2331 const char *ifname
, bool mlag
,
2335 struct interface
*ifp
;
2336 struct listnode
*neighnode
;
2337 struct pim_interface
*pim_ifp
;
2338 struct pim_neighbor
*neigh
;
2339 struct pim_upstream
*up
;
2341 char dr_str
[PIM_ADDRSTRLEN
];
2344 char grp_str
[PIM_ADDRSTRLEN
];
2345 char hello_period
[10];
2346 char hello_timer
[10];
2347 char neigh_src_str
[PIM_ADDRSTRLEN
];
2348 char src_str
[PIM_ADDRSTRLEN
];
2349 char stat_uptime
[10];
2351 int found_ifname
= 0;
2353 json_object
*json_row
= NULL
;
2354 json_object
*json_pim_neighbor
= NULL
;
2355 json_object
*json_pim_neighbors
= NULL
;
2356 json_object
*json_group
= NULL
;
2357 json_object
*json_group_source
= NULL
;
2358 json_object
*json_fhr_sources
= NULL
;
2359 struct pim_secondary_addr
*sec_addr
;
2360 struct listnode
*sec_node
;
2362 now
= pim_time_monotonic_sec();
2364 FOR_ALL_INTERFACES (pim
->vrf
, ifp
) {
2365 pim_ifp
= ifp
->info
;
2370 if (mlag
== true && pim_ifp
->activeactive
== false)
2373 if (strcmp(ifname
, "detail") && strcmp(ifname
, ifp
->name
))
2377 ifaddr
= pim_ifp
->primary_address
;
2378 snprintfrr(dr_str
, sizeof(dr_str
), "%pPAs",
2379 &pim_ifp
->pim_dr_addr
);
2380 pim_time_uptime_begin(dr_uptime
, sizeof(dr_uptime
), now
,
2381 pim_ifp
->pim_dr_election_last
);
2382 pim_time_timer_to_hhmmss(hello_timer
, sizeof(hello_timer
),
2383 pim_ifp
->t_pim_hello_timer
);
2384 pim_time_mmss(hello_period
, sizeof(hello_period
),
2385 pim_ifp
->pim_hello_period
);
2386 pim_time_uptime(stat_uptime
, sizeof(stat_uptime
),
2387 now
- pim_ifp
->pim_ifstat_start
);
2390 json_row
= json_object_new_object();
2391 json_object_pim_ifp_add(json_row
, ifp
);
2393 if (!pim_addr_is_any(pim_ifp
->update_source
)) {
2394 json_object_string_addf(
2395 json_row
, "useSource", "%pPAs",
2396 &pim_ifp
->update_source
);
2398 if (pim_ifp
->sec_addr_list
) {
2399 json_object
*sec_list
= NULL
;
2401 sec_list
= json_object_new_array();
2402 for (ALL_LIST_ELEMENTS_RO(
2403 pim_ifp
->sec_addr_list
, sec_node
,
2405 json_object_array_add(
2407 json_object_new_stringf(
2411 json_object_object_add(json_row
,
2412 "secondaryAddressList",
2416 if (pim_ifp
->pim_passive_enable
)
2417 json_object_boolean_true_add(json_row
,
2421 if (pim_ifp
->pim_neighbor_list
->count
) {
2422 json_pim_neighbors
= json_object_new_object();
2424 for (ALL_LIST_ELEMENTS_RO(
2425 pim_ifp
->pim_neighbor_list
,
2426 neighnode
, neigh
)) {
2428 json_object_new_object();
2429 snprintfrr(neigh_src_str
,
2430 sizeof(neigh_src_str
),
2432 &neigh
->source_addr
);
2433 pim_time_uptime(uptime
, sizeof(uptime
),
2434 now
- neigh
->creation
);
2435 pim_time_timer_to_hhmmss(
2436 expire
, sizeof(expire
),
2437 neigh
->t_expire_timer
);
2439 json_object_string_add(
2440 json_pim_neighbor
, "address",
2442 json_object_string_add(
2443 json_pim_neighbor
, "upTime",
2445 json_object_string_add(
2446 json_pim_neighbor
, "holdtime",
2449 json_object_object_add(
2455 json_object_object_add(json_row
, "neighbors",
2456 json_pim_neighbors
);
2459 json_object_string_add(json_row
, "drAddress", dr_str
);
2460 json_object_int_add(json_row
, "drPriority",
2461 pim_ifp
->pim_dr_priority
);
2462 json_object_string_add(json_row
, "drUptime", dr_uptime
);
2463 json_object_int_add(json_row
, "drElections",
2464 pim_ifp
->pim_dr_election_count
);
2465 json_object_int_add(json_row
, "drChanges",
2466 pim_ifp
->pim_dr_election_changes
);
2469 frr_each (rb_pim_upstream
, &pim
->upstream_head
, up
) {
2470 if (ifp
!= up
->rpf
.source_nexthop
.interface
)
2473 if (!(up
->flags
& PIM_UPSTREAM_FLAG_MASK_FHR
))
2476 if (!json_fhr_sources
)
2478 json_object_new_object();
2480 snprintfrr(grp_str
, sizeof(grp_str
), "%pPAs",
2482 snprintfrr(src_str
, sizeof(src_str
), "%pPAs",
2484 pim_time_uptime(uptime
, sizeof(uptime
),
2485 now
- up
->state_transition
);
2488 * Does this group live in json_fhr_sources?
2491 json_object_object_get_ex(json_fhr_sources
,
2492 grp_str
, &json_group
);
2495 json_group
= json_object_new_object();
2496 json_object_object_add(json_fhr_sources
,
2501 json_group_source
= json_object_new_object();
2502 json_object_string_add(json_group_source
,
2504 json_object_string_add(json_group_source
,
2506 json_object_string_add(json_group_source
,
2508 json_object_object_add(json_group
, src_str
,
2512 if (json_fhr_sources
) {
2513 json_object_object_add(json_row
,
2518 json_object_int_add(json_row
, "helloPeriod",
2519 pim_ifp
->pim_hello_period
);
2520 json_object_int_add(json_row
, "holdTime",
2521 PIM_IF_DEFAULT_HOLDTIME(pim_ifp
));
2522 json_object_string_add(json_row
, "helloTimer",
2524 json_object_string_add(json_row
, "helloStatStart",
2526 json_object_int_add(json_row
, "helloReceived",
2527 pim_ifp
->pim_ifstat_hello_recv
);
2528 json_object_int_add(json_row
, "helloReceivedFailed",
2529 pim_ifp
->pim_ifstat_hello_recvfail
);
2530 json_object_int_add(json_row
, "helloSend",
2531 pim_ifp
->pim_ifstat_hello_sent
);
2532 json_object_int_add(json_row
, "hellosendFailed",
2533 pim_ifp
->pim_ifstat_hello_sendfail
);
2534 json_object_int_add(json_row
, "helloGenerationId",
2535 pim_ifp
->pim_generation_id
);
2537 json_object_int_add(
2538 json_row
, "effectivePropagationDelay",
2539 pim_if_effective_propagation_delay_msec(ifp
));
2540 json_object_int_add(
2541 json_row
, "effectiveOverrideInterval",
2542 pim_if_effective_override_interval_msec(ifp
));
2543 json_object_int_add(
2544 json_row
, "joinPruneOverrideInterval",
2545 pim_if_jp_override_interval_msec(ifp
));
2547 json_object_int_add(
2548 json_row
, "propagationDelay",
2549 pim_ifp
->pim_propagation_delay_msec
);
2550 json_object_int_add(
2551 json_row
, "propagationDelayHighest",
2552 pim_ifp
->pim_neighbors_highest_propagation_delay_msec
);
2553 json_object_int_add(
2554 json_row
, "overrideInterval",
2555 pim_ifp
->pim_override_interval_msec
);
2556 json_object_int_add(
2557 json_row
, "overrideIntervalHighest",
2558 pim_ifp
->pim_neighbors_highest_override_interval_msec
);
2559 if (pim_ifp
->bsm_enable
)
2560 json_object_boolean_true_add(json_row
,
2562 if (pim_ifp
->ucast_bsm_accept
)
2563 json_object_boolean_true_add(json_row
,
2565 json_object_object_add(json
, ifp
->name
, json_row
);
2568 vty_out(vty
, "Interface : %s\n", ifp
->name
);
2569 vty_out(vty
, "State : %s\n",
2570 if_is_up(ifp
) ? "up" : "down");
2571 if (!pim_addr_is_any(pim_ifp
->update_source
)) {
2572 vty_out(vty
, "Use Source : %pPAs\n",
2573 &pim_ifp
->update_source
);
2575 if (pim_ifp
->sec_addr_list
) {
2576 vty_out(vty
, "Address : %pPAs (primary)\n",
2578 for (ALL_LIST_ELEMENTS_RO(
2579 pim_ifp
->sec_addr_list
, sec_node
,
2581 vty_out(vty
, " %pFX\n",
2584 vty_out(vty
, "Address : %pPAs\n", &ifaddr
);
2587 if (pim_ifp
->pim_passive_enable
)
2588 vty_out(vty
, "Passive : %s\n",
2589 (pim_ifp
->pim_passive_enable
) ? "yes"
2597 for (ALL_LIST_ELEMENTS_RO(pim_ifp
->pim_neighbor_list
,
2598 neighnode
, neigh
)) {
2601 vty_out(vty
, "PIM Neighbors\n");
2602 vty_out(vty
, "-------------\n");
2606 snprintfrr(neigh_src_str
, sizeof(neigh_src_str
),
2607 "%pPAs", &neigh
->source_addr
);
2608 pim_time_uptime(uptime
, sizeof(uptime
),
2609 now
- neigh
->creation
);
2610 pim_time_timer_to_hhmmss(expire
, sizeof(expire
),
2611 neigh
->t_expire_timer
);
2613 "%-15s : up for %s, holdtime expires in %s\n",
2614 neigh_src_str
, uptime
, expire
);
2617 if (!print_header
) {
2622 vty_out(vty
, "Designated Router\n");
2623 vty_out(vty
, "-----------------\n");
2624 vty_out(vty
, "Address : %s\n", dr_str
);
2625 vty_out(vty
, "Priority : %u(%d)\n",
2626 pim_ifp
->pim_dr_priority
,
2627 pim_ifp
->pim_dr_num_nondrpri_neighbors
);
2628 vty_out(vty
, "Uptime : %s\n", dr_uptime
);
2629 vty_out(vty
, "Elections : %d\n",
2630 pim_ifp
->pim_dr_election_count
);
2631 vty_out(vty
, "Changes : %d\n",
2632 pim_ifp
->pim_dr_election_changes
);
2638 frr_each (rb_pim_upstream
, &pim
->upstream_head
, up
) {
2639 if (!up
->rpf
.source_nexthop
.interface
)
2642 if (strcmp(ifp
->name
,
2643 up
->rpf
.source_nexthop
2644 .interface
->name
) != 0)
2647 if (!(up
->flags
& PIM_UPSTREAM_FLAG_MASK_FHR
))
2652 "FHR - First Hop Router\n");
2654 "----------------------\n");
2658 pim_time_uptime(uptime
, sizeof(uptime
),
2659 now
- up
->state_transition
);
2661 "%pPAs : %pPAs is a source, uptime is %s\n",
2662 &up
->sg
.grp
, &up
->sg
.src
, uptime
);
2665 if (!print_header
) {
2670 vty_out(vty
, "Hellos\n");
2671 vty_out(vty
, "------\n");
2672 vty_out(vty
, "Period : %d\n",
2673 pim_ifp
->pim_hello_period
);
2674 vty_out(vty
, "HoldTime : %d\n",
2675 PIM_IF_DEFAULT_HOLDTIME(pim_ifp
));
2676 vty_out(vty
, "Timer : %s\n", hello_timer
);
2677 vty_out(vty
, "StatStart : %s\n", stat_uptime
);
2678 vty_out(vty
, "Receive : %d\n",
2679 pim_ifp
->pim_ifstat_hello_recv
);
2680 vty_out(vty
, "Receive Failed : %d\n",
2681 pim_ifp
->pim_ifstat_hello_recvfail
);
2682 vty_out(vty
, "Send : %d\n",
2683 pim_ifp
->pim_ifstat_hello_sent
);
2684 vty_out(vty
, "Send Failed : %d\n",
2685 pim_ifp
->pim_ifstat_hello_sendfail
);
2686 vty_out(vty
, "Generation ID : %08x\n",
2687 pim_ifp
->pim_generation_id
);
2691 pim_print_ifp_flags(vty
, ifp
);
2693 vty_out(vty
, "Join Prune Interval\n");
2694 vty_out(vty
, "-------------------\n");
2695 vty_out(vty
, "LAN Delay : %s\n",
2696 pim_if_lan_delay_enabled(ifp
) ? "yes" : "no");
2697 vty_out(vty
, "Effective Propagation Delay : %d msec\n",
2698 pim_if_effective_propagation_delay_msec(ifp
));
2699 vty_out(vty
, "Effective Override Interval : %d msec\n",
2700 pim_if_effective_override_interval_msec(ifp
));
2701 vty_out(vty
, "Join Prune Override Interval : %d msec\n",
2702 pim_if_jp_override_interval_msec(ifp
));
2706 vty_out(vty
, "LAN Prune Delay\n");
2707 vty_out(vty
, "---------------\n");
2708 vty_out(vty
, "Propagation Delay : %d msec\n",
2709 pim_ifp
->pim_propagation_delay_msec
);
2710 vty_out(vty
, "Propagation Delay (Highest) : %d msec\n",
2711 pim_ifp
->pim_neighbors_highest_propagation_delay_msec
);
2712 vty_out(vty
, "Override Interval : %d msec\n",
2713 pim_ifp
->pim_override_interval_msec
);
2714 vty_out(vty
, "Override Interval (Highest) : %d msec\n",
2715 pim_ifp
->pim_neighbors_highest_override_interval_msec
);
2719 vty_out(vty
, "BSM Status\n");
2720 vty_out(vty
, "----------\n");
2721 vty_out(vty
, "Bsm Enabled : %s\n",
2722 pim_ifp
->bsm_enable
? "yes" : "no");
2723 vty_out(vty
, "Unicast Bsm Enabled : %s\n",
2724 pim_ifp
->ucast_bsm_accept
? "yes" : "no");
2731 vty_out(vty
, "%% No such interface\n");
2734 void ip_pim_ssm_show_group_range(struct pim_instance
*pim
, struct vty
*vty
,
2737 struct pim_ssm
*ssm
= pim
->ssm_info
;
2738 const char *range_str
=
2739 ssm
->plist_name
? ssm
->plist_name
: PIM_SSM_STANDARD_RANGE
;
2744 json
= json_object_new_object();
2745 json_object_string_add(json
, "ssmGroups", range_str
);
2746 vty_json(vty
, json
);
2748 vty_out(vty
, "SSM group range : %s\n", range_str
);
2751 struct vty_pnc_cache_walk_data
{
2753 struct pim_instance
*pim
;
2756 struct json_pnc_cache_walk_data
{
2757 json_object
*json_obj
;
2758 struct pim_instance
*pim
;
2761 static int pim_print_vty_pnc_cache_walkcb(struct hash_bucket
*bucket
, void *arg
)
2763 struct pim_nexthop_cache
*pnc
= bucket
->data
;
2764 struct vty_pnc_cache_walk_data
*cwd
= arg
;
2765 struct vty
*vty
= cwd
->vty
;
2766 struct pim_instance
*pim
= cwd
->pim
;
2767 struct nexthop
*nh_node
= NULL
;
2768 ifindex_t first_ifindex
;
2769 struct interface
*ifp
= NULL
;
2771 for (nh_node
= pnc
->nexthop
; nh_node
; nh_node
= nh_node
->next
) {
2772 first_ifindex
= nh_node
->ifindex
;
2774 ifp
= if_lookup_by_index(first_ifindex
, pim
->vrf
->vrf_id
);
2776 vty_out(vty
, "%-15pPA ", &pnc
->rpf
.rpf_addr
);
2777 vty_out(vty
, "%-16s ", ifp
? ifp
->name
: "NULL");
2779 vty_out(vty
, "%pI4 ", &nh_node
->gate
.ipv4
);
2781 vty_out(vty
, "%pI6 ", &nh_node
->gate
.ipv6
);
2788 static int pim_print_json_pnc_cache_walkcb(struct hash_bucket
*backet
,
2791 struct pim_nexthop_cache
*pnc
= backet
->data
;
2792 struct json_pnc_cache_walk_data
*cwd
= arg
;
2793 struct pim_instance
*pim
= cwd
->pim
;
2794 struct nexthop
*nh_node
= NULL
;
2795 ifindex_t first_ifindex
;
2796 struct interface
*ifp
= NULL
;
2797 char addr_str
[PIM_ADDRSTRLEN
];
2798 json_object
*json_row
= NULL
;
2799 json_object
*json_ifp
= NULL
;
2800 json_object
*json_arr
= NULL
;
2802 for (nh_node
= pnc
->nexthop
; nh_node
; nh_node
= nh_node
->next
) {
2803 first_ifindex
= nh_node
->ifindex
;
2804 ifp
= if_lookup_by_index(first_ifindex
, pim
->vrf
->vrf_id
);
2805 snprintfrr(addr_str
, sizeof(addr_str
), "%pPA",
2806 &pnc
->rpf
.rpf_addr
);
2807 json_object_object_get_ex(cwd
->json_obj
, addr_str
, &json_row
);
2809 json_row
= json_object_new_object();
2810 json_object_string_addf(json_row
, "address", "%pPA",
2811 &pnc
->rpf
.rpf_addr
);
2812 json_object_object_addf(cwd
->json_obj
, json_row
, "%pPA",
2813 &pnc
->rpf
.rpf_addr
);
2814 json_arr
= json_object_new_array();
2815 json_object_object_add(json_row
, "nexthops", json_arr
);
2817 json_ifp
= json_object_new_object();
2818 json_object_string_add(json_ifp
, "interface",
2819 ifp
? ifp
->name
: "NULL");
2821 json_object_string_addf(json_ifp
, "nexthop", "%pI4",
2822 &nh_node
->gate
.ipv4
);
2824 json_object_string_addf(json_ifp
, "nexthop", "%pI6",
2825 &nh_node
->gate
.ipv6
);
2827 json_object_array_add(json_arr
, json_ifp
);
2832 int pim_show_nexthop_lookup_cmd_helper(const char *vrf
, struct vty
*vty
,
2833 pim_addr source
, pim_addr group
)
2836 pim_addr vif_source
;
2838 struct pim_nexthop nexthop
;
2840 char grp_str
[PREFIX_STRLEN
];
2842 v
= vrf_lookup_by_name(vrf
? vrf
: VRF_DEFAULT_NAME
);
2848 if (pim_is_group_224_4(source
)) {
2850 "Invalid argument. Expected Valid Source Address.\n");
2854 if (!pim_is_group_224_4(group
)) {
2856 "Invalid argument. Expected Valid Multicast Group Address.\n");
2861 if (!pim_rp_set_upstream_addr(v
->info
, &vif_source
, source
, group
))
2864 pim_addr_to_prefix(&grp
, group
);
2865 memset(&nexthop
, 0, sizeof(nexthop
));
2868 pim_ecmp_nexthop_lookup(v
->info
, &nexthop
, vif_source
, &grp
, 0);
2872 "Nexthop Lookup failed, no usable routes returned.\n");
2876 pim_addr_dump("<grp?>", &grp
, grp_str
, sizeof(grp_str
));
2878 vty_out(vty
, "Group %s --- Nexthop %pPAs Interface %s\n", grp_str
,
2879 &nexthop
.mrib_nexthop_addr
, nexthop
.interface
->name
);
2884 int pim_show_nexthop_cmd_helper(const char *vrf
, struct vty
*vty
, bool uj
)
2888 v
= vrf_lookup_by_name(vrf
? vrf
: VRF_DEFAULT_NAME
);
2893 pim_show_nexthop(v
->info
, vty
, uj
);
2898 void pim_show_nexthop(struct pim_instance
*pim
, struct vty
*vty
, bool uj
)
2900 struct vty_pnc_cache_walk_data cwd
;
2901 struct json_pnc_cache_walk_data jcwd
;
2908 jcwd
.json_obj
= json_object_new_object();
2910 vty_out(vty
, "Number of registered addresses: %lu\n",
2911 pim
->rpf_hash
->count
);
2912 vty_out(vty
, "Address Interface Nexthop\n");
2913 vty_out(vty
, "---------------------------------------------\n");
2917 hash_walk(pim
->rpf_hash
, pim_print_json_pnc_cache_walkcb
,
2919 vty_json(vty
, jcwd
.json_obj
);
2921 hash_walk(pim
->rpf_hash
, pim_print_vty_pnc_cache_walkcb
, &cwd
);
2924 int pim_show_neighbors_cmd_helper(const char *vrf
, struct vty
*vty
,
2925 const char *json
, const char *interface
)
2928 json_object
*json_parent
= NULL
;
2930 v
= vrf_lookup_by_name(vrf
? vrf
: VRF_DEFAULT_NAME
);
2936 json_parent
= json_object_new_object();
2939 pim_show_neighbors_single(v
->info
, vty
, interface
, json_parent
);
2941 pim_show_neighbors(v
->info
, vty
, json_parent
);
2944 vty_json(vty
, json_parent
);
2949 int pim_show_neighbors_vrf_all_cmd_helper(struct vty
*vty
, const char *json
,
2950 const char *interface
)
2953 json_object
*json_parent
= NULL
;
2954 json_object
*json_vrf
= NULL
;
2957 json_parent
= json_object_new_object();
2958 RB_FOREACH (v
, vrf_name_head
, &vrfs_by_name
) {
2960 vty_out(vty
, "VRF: %s\n", v
->name
);
2962 json_vrf
= json_object_new_object();
2965 pim_show_neighbors_single(v
->info
, vty
, interface
,
2968 pim_show_neighbors(v
->info
, vty
, json_vrf
);
2971 json_object_object_add(json_parent
, v
->name
, json_vrf
);
2974 vty_json(vty
, json_parent
);
2979 void pim_show_neighbors_single(struct pim_instance
*pim
, struct vty
*vty
,
2980 const char *neighbor
, json_object
*json
)
2982 struct listnode
*neighnode
;
2983 struct interface
*ifp
;
2984 struct pim_interface
*pim_ifp
;
2985 struct pim_neighbor
*neigh
;
2987 int found_neighbor
= 0;
2988 int option_address_list
;
2989 int option_dr_priority
;
2990 int option_generation_id
;
2991 int option_holdtime
;
2992 int option_lan_prune_delay
;
2996 char neigh_src_str
[PIM_ADDRSTRLEN
];
2998 json_object
*json_ifp
= NULL
;
2999 json_object
*json_row
= NULL
;
3001 now
= pim_time_monotonic_sec();
3003 FOR_ALL_INTERFACES (pim
->vrf
, ifp
) {
3004 pim_ifp
= ifp
->info
;
3009 if (pim_ifp
->pim_sock_fd
< 0)
3012 for (ALL_LIST_ELEMENTS_RO(pim_ifp
->pim_neighbor_list
, neighnode
,
3014 snprintfrr(neigh_src_str
, sizeof(neigh_src_str
),
3015 "%pPAs", &neigh
->source_addr
);
3018 * The user can specify either the interface name or the
3020 * If this pim_ifp matches neither then skip.
3022 if (strcmp(neighbor
, "detail") &&
3023 strcmp(neighbor
, ifp
->name
) &&
3024 strcmp(neighbor
, neigh_src_str
))
3028 pim_time_uptime(uptime
, sizeof(uptime
),
3029 now
- neigh
->creation
);
3030 pim_time_timer_to_hhmmss(expire
, sizeof(expire
),
3031 neigh
->t_expire_timer
);
3033 option_address_list
= 0;
3034 option_dr_priority
= 0;
3035 option_generation_id
= 0;
3036 option_holdtime
= 0;
3037 option_lan_prune_delay
= 0;
3040 if (PIM_OPTION_IS_SET(neigh
->hello_options
,
3041 PIM_OPTION_MASK_ADDRESS_LIST
))
3042 option_address_list
= 1;
3044 if (PIM_OPTION_IS_SET(neigh
->hello_options
,
3045 PIM_OPTION_MASK_DR_PRIORITY
))
3046 option_dr_priority
= 1;
3048 if (PIM_OPTION_IS_SET(neigh
->hello_options
,
3049 PIM_OPTION_MASK_GENERATION_ID
))
3050 option_generation_id
= 1;
3052 if (PIM_OPTION_IS_SET(neigh
->hello_options
,
3053 PIM_OPTION_MASK_HOLDTIME
))
3054 option_holdtime
= 1;
3056 if (PIM_OPTION_IS_SET(neigh
->hello_options
,
3057 PIM_OPTION_MASK_LAN_PRUNE_DELAY
))
3058 option_lan_prune_delay
= 1;
3060 if (PIM_OPTION_IS_SET(
3061 neigh
->hello_options
,
3062 PIM_OPTION_MASK_CAN_DISABLE_JOIN_SUPPRESSION
))
3067 /* Does this ifp live in json? If not create it
3069 json_object_object_get_ex(json
, ifp
->name
,
3073 json_ifp
= json_object_new_object();
3074 json_object_pim_ifp_add(json_ifp
, ifp
);
3075 json_object_object_add(json
, ifp
->name
,
3079 json_row
= json_object_new_object();
3080 json_object_string_add(json_row
, "interface",
3082 json_object_string_add(json_row
, "address",
3084 json_object_string_add(json_row
, "upTime",
3086 json_object_string_add(json_row
, "holdtime",
3088 json_object_int_add(json_row
, "drPriority",
3089 neigh
->dr_priority
);
3090 json_object_int_add(json_row
, "generationId",
3091 neigh
->generation_id
);
3093 if (option_address_list
)
3094 json_object_boolean_true_add(
3096 "helloOptionAddressList");
3098 if (option_dr_priority
)
3099 json_object_boolean_true_add(
3101 "helloOptionDrPriority");
3103 if (option_generation_id
)
3104 json_object_boolean_true_add(
3106 "helloOptionGenerationId");
3108 if (option_holdtime
)
3109 json_object_boolean_true_add(
3111 "helloOptionHoldtime");
3113 if (option_lan_prune_delay
)
3114 json_object_boolean_true_add(
3116 "helloOptionLanPruneDelay");
3119 json_object_boolean_true_add(
3120 json_row
, "helloOptionTBit");
3122 json_object_object_add(json_ifp
, neigh_src_str
,
3126 vty_out(vty
, "Interface : %s\n", ifp
->name
);
3127 vty_out(vty
, "Neighbor : %s\n", neigh_src_str
);
3135 " DR Priority : %d\n",
3136 neigh
->dr_priority
);
3138 " Generation ID : %08x\n",
3139 neigh
->generation_id
);
3141 " Override Interval (msec) : %d\n",
3142 neigh
->override_interval_msec
);
3144 " Propagation Delay (msec) : %d\n",
3145 neigh
->propagation_delay_msec
);
3147 " Hello Option - Address List : %s\n",
3148 option_address_list
? "yes" : "no");
3150 " Hello Option - DR Priority : %s\n",
3151 option_dr_priority
? "yes" : "no");
3153 " Hello Option - Generation ID : %s\n",
3154 option_generation_id
? "yes" : "no");
3156 " Hello Option - Holdtime : %s\n",
3157 option_holdtime
? "yes" : "no");
3159 " Hello Option - LAN Prune Delay : %s\n",
3160 option_lan_prune_delay
? "yes" : "no");
3162 " Hello Option - T-bit : %s\n",
3163 option_t_bit
? "yes" : "no");
3164 bfd_sess_show(vty
, json_ifp
,
3165 neigh
->bfd_session
);
3171 if (!found_neighbor
)
3172 vty_out(vty
, "%% No such interface or neighbor\n");
3175 void pim_show_neighbors(struct pim_instance
*pim
, struct vty
*vty
,
3178 struct listnode
*neighnode
;
3179 struct interface
*ifp
;
3180 struct pim_interface
*pim_ifp
;
3181 struct pim_neighbor
*neigh
;
3185 char neigh_src_str
[PIM_ADDRSTRLEN
];
3186 json_object
*json_ifp_rows
= NULL
;
3187 json_object
*json_row
= NULL
;
3189 now
= pim_time_monotonic_sec();
3193 "Interface Neighbor Uptime Holdtime DR Pri\n");
3196 FOR_ALL_INTERFACES (pim
->vrf
, ifp
) {
3197 pim_ifp
= ifp
->info
;
3202 if (pim_ifp
->pim_sock_fd
< 0)
3206 json_ifp_rows
= json_object_new_object();
3208 for (ALL_LIST_ELEMENTS_RO(pim_ifp
->pim_neighbor_list
, neighnode
,
3210 snprintfrr(neigh_src_str
, sizeof(neigh_src_str
),
3211 "%pPAs", &neigh
->source_addr
);
3212 pim_time_uptime(uptime
, sizeof(uptime
),
3213 now
- neigh
->creation
);
3214 pim_time_timer_to_hhmmss(expire
, sizeof(expire
),
3215 neigh
->t_expire_timer
);
3218 json_row
= json_object_new_object();
3219 json_object_string_add(json_row
, "interface",
3221 json_object_string_add(json_row
, "neighbor",
3223 json_object_string_add(json_row
, "upTime",
3225 json_object_string_add(json_row
, "holdTime",
3227 json_object_int_add(json_row
, "holdTimeMax",
3229 json_object_int_add(json_row
, "drPriority",
3230 neigh
->dr_priority
);
3231 json_object_object_add(json_ifp_rows
,
3232 neigh_src_str
, json_row
);
3235 vty_out(vty
, "%-16s %15s %8s %8s %6d\n",
3236 ifp
->name
, neigh_src_str
, uptime
,
3237 expire
, neigh
->dr_priority
);
3242 json_object_object_add(json
, ifp
->name
, json_ifp_rows
);
3243 json_ifp_rows
= NULL
;
3248 int gm_process_query_max_response_time_cmd(struct vty
*vty
,
3249 const char *qmrt_str
)
3251 const struct lyd_node
*pim_enable_dnode
;
3253 pim_enable_dnode
= yang_dnode_getf(vty
->candidate_config
->dnode
,
3254 FRR_PIM_ENABLE_XPATH
, VTY_CURR_XPATH
,
3255 FRR_PIM_AF_XPATH_VAL
);
3257 if (!pim_enable_dnode
) {
3258 nb_cli_enqueue_change(vty
, "./enable", NB_OP_MODIFY
, "true");
3260 if (!yang_dnode_get_bool(pim_enable_dnode
, "."))
3261 nb_cli_enqueue_change(vty
, "./enable", NB_OP_MODIFY
,
3265 nb_cli_enqueue_change(vty
, "./query-max-response-time", NB_OP_MODIFY
,
3267 return nb_cli_apply_changes(vty
, FRR_GMP_INTERFACE_XPATH
,
3268 FRR_PIM_AF_XPATH_VAL
);
3271 int gm_process_no_query_max_response_time_cmd(struct vty
*vty
)
3273 nb_cli_enqueue_change(vty
, "./query-max-response-time", NB_OP_DESTROY
,
3275 return nb_cli_apply_changes(vty
, FRR_GMP_INTERFACE_XPATH
,
3276 FRR_PIM_AF_XPATH_VAL
);
3279 int gm_process_last_member_query_count_cmd(struct vty
*vty
,
3280 const char *lmqc_str
)
3282 const struct lyd_node
*pim_enable_dnode
;
3284 pim_enable_dnode
= yang_dnode_getf(vty
->candidate_config
->dnode
,
3285 FRR_PIM_ENABLE_XPATH
, VTY_CURR_XPATH
,
3286 FRR_PIM_AF_XPATH_VAL
);
3287 if (!pim_enable_dnode
) {
3288 nb_cli_enqueue_change(vty
, "./enable", NB_OP_MODIFY
, "true");
3290 if (!yang_dnode_get_bool(pim_enable_dnode
, "."))
3291 nb_cli_enqueue_change(vty
, "./enable", NB_OP_MODIFY
,
3295 nb_cli_enqueue_change(vty
, "./robustness-variable", NB_OP_MODIFY
,
3297 return nb_cli_apply_changes(vty
, FRR_GMP_INTERFACE_XPATH
,
3298 FRR_PIM_AF_XPATH_VAL
);
3301 int gm_process_no_last_member_query_count_cmd(struct vty
*vty
)
3303 nb_cli_enqueue_change(vty
, "./robustness-variable", NB_OP_DESTROY
,
3305 return nb_cli_apply_changes(vty
, FRR_GMP_INTERFACE_XPATH
,
3306 FRR_PIM_AF_XPATH_VAL
);
3309 int gm_process_last_member_query_interval_cmd(struct vty
*vty
,
3310 const char *lmqi_str
)
3312 const struct lyd_node
*pim_enable_dnode
;
3314 pim_enable_dnode
= yang_dnode_getf(vty
->candidate_config
->dnode
,
3315 FRR_PIM_ENABLE_XPATH
, VTY_CURR_XPATH
,
3316 FRR_PIM_AF_XPATH_VAL
);
3317 if (!pim_enable_dnode
) {
3318 nb_cli_enqueue_change(vty
, "./enable", NB_OP_MODIFY
, "true");
3320 if (!yang_dnode_get_bool(pim_enable_dnode
, "."))
3321 nb_cli_enqueue_change(vty
, "./enable", NB_OP_MODIFY
,
3325 nb_cli_enqueue_change(vty
, "./last-member-query-interval", NB_OP_MODIFY
,
3327 return nb_cli_apply_changes(vty
, FRR_GMP_INTERFACE_XPATH
,
3328 FRR_PIM_AF_XPATH_VAL
);
3331 int gm_process_no_last_member_query_interval_cmd(struct vty
*vty
)
3333 nb_cli_enqueue_change(vty
, "./last-member-query-interval",
3334 NB_OP_DESTROY
, NULL
);
3335 return nb_cli_apply_changes(vty
, FRR_GMP_INTERFACE_XPATH
,
3336 FRR_PIM_AF_XPATH_VAL
);
3339 int pim_process_ssmpingd_cmd(struct vty
*vty
, enum nb_operation operation
,
3340 const char *src_str
)
3342 const char *vrfname
;
3343 char ssmpingd_ip_xpath
[XPATH_MAXLEN
];
3345 vrfname
= pim_cli_get_vrf_name(vty
);
3346 if (vrfname
== NULL
)
3347 return CMD_WARNING_CONFIG_FAILED
;
3349 snprintf(ssmpingd_ip_xpath
, sizeof(ssmpingd_ip_xpath
),
3350 FRR_PIM_VRF_XPATH
, "frr-pim:pimd", "pim", vrfname
,
3351 FRR_PIM_AF_XPATH_VAL
);
3352 strlcat(ssmpingd_ip_xpath
, "/ssm-pingd-source-ip",
3353 sizeof(ssmpingd_ip_xpath
));
3355 nb_cli_enqueue_change(vty
, ssmpingd_ip_xpath
, operation
, src_str
);
3357 return nb_cli_apply_changes(vty
, NULL
);
3360 static void show_scan_oil_stats(struct pim_instance
*pim
, struct vty
*vty
,
3363 char uptime_scan_oil
[10];
3364 char uptime_mroute_add
[10];
3365 char uptime_mroute_del
[10];
3367 pim_time_uptime_begin(uptime_scan_oil
, sizeof(uptime_scan_oil
), now
,
3368 pim
->scan_oil_last
);
3369 pim_time_uptime_begin(uptime_mroute_add
, sizeof(uptime_mroute_add
), now
,
3370 pim
->mroute_add_last
);
3371 pim_time_uptime_begin(uptime_mroute_del
, sizeof(uptime_mroute_del
), now
,
3372 pim
->mroute_del_last
);
3375 "Scan OIL - Last: %s Events: %lld\n"
3376 "MFC Add - Last: %s Events: %lld\n"
3377 "MFC Del - Last: %s Events: %lld\n",
3378 uptime_scan_oil
, (long long)pim
->scan_oil_events
,
3379 uptime_mroute_add
, (long long)pim
->mroute_add_events
,
3380 uptime_mroute_del
, (long long)pim
->mroute_del_events
);
3383 void show_multicast_interfaces(struct pim_instance
*pim
, struct vty
*vty
,
3386 struct interface
*ifp
;
3387 struct ttable
*tt
= NULL
;
3389 json_object
*json_row
= NULL
;
3394 /* Prepare table. */
3395 tt
= ttable_new(&ttable_styles
[TTSTYLE_BLANK
]);
3398 "Interface|Address|ifi|Vif|PktsIn|PktsOut|BytesIn|BytesOut");
3399 tt
->style
.cell
.rpad
= 2;
3400 tt
->style
.corner
= '+';
3404 FOR_ALL_INTERFACES (pim
->vrf
, ifp
) {
3405 struct pim_interface
*pim_ifp
;
3407 struct sioc_vif_req vreq
;
3409 struct sioc_mif_req6 vreq
;
3412 pim_ifp
= ifp
->info
;
3417 memset(&vreq
, 0, sizeof(vreq
));
3419 vreq
.vifi
= pim_ifp
->mroute_vif_index
;
3420 if (ioctl(pim
->mroute_socket
, SIOCGETVIFCNT
, &vreq
)) {
3422 "ioctl(SIOCGETVIFCNT=%lu) failure for interface %s vif_index=%d: errno=%d: %s",
3423 (unsigned long)SIOCGETVIFCNT
, ifp
->name
,
3424 pim_ifp
->mroute_vif_index
, errno
,
3425 safe_strerror(errno
));
3428 vreq
.mifi
= pim_ifp
->mroute_vif_index
;
3429 if (ioctl(pim
->mroute_socket
, SIOCGETMIFCNT_IN6
, &vreq
)) {
3431 "ioctl(SIOCGETMIFCNT_IN6=%lu) failure for interface %s vif_index=%d: errno=%d: %s",
3432 (unsigned long)SIOCGETMIFCNT_IN6
, ifp
->name
,
3433 pim_ifp
->mroute_vif_index
, errno
,
3434 safe_strerror(errno
));
3439 json_row
= json_object_new_object();
3440 json_object_string_add(json_row
, "name", ifp
->name
);
3441 json_object_string_add(json_row
, "state",
3442 if_is_up(ifp
) ? "up" : "down");
3443 json_object_string_addf(json_row
, "address", "%pPA",
3444 &pim_ifp
->primary_address
);
3445 json_object_int_add(json_row
, "ifIndex", ifp
->ifindex
);
3446 json_object_int_add(json_row
, "vif",
3447 pim_ifp
->mroute_vif_index
);
3448 json_object_int_add(json_row
, "pktsIn",
3449 (unsigned long)vreq
.icount
);
3450 json_object_int_add(json_row
, "pktsOut",
3451 (unsigned long)vreq
.ocount
);
3452 json_object_int_add(json_row
, "bytesIn",
3453 (unsigned long)vreq
.ibytes
);
3454 json_object_int_add(json_row
, "bytesOut",
3455 (unsigned long)vreq
.obytes
);
3456 json_object_object_add(json
, ifp
->name
, json_row
);
3458 ttable_add_row(tt
, "%s|%pPAs|%d|%d|%lu|%lu|%lu|%lu",
3459 ifp
->name
, &pim_ifp
->primary_address
,
3460 ifp
->ifindex
, pim_ifp
->mroute_vif_index
,
3461 (unsigned long)vreq
.icount
,
3462 (unsigned long)vreq
.ocount
,
3463 (unsigned long)vreq
.ibytes
,
3464 (unsigned long)vreq
.obytes
);
3467 /* Dump the generated table. */
3469 table
= ttable_dump(tt
, "\n");
3470 vty_out(vty
, "%s\n", table
);
3471 XFREE(MTYPE_TMP
, table
);
3476 void pim_cmd_show_ip_multicast_helper(struct pim_instance
*pim
, struct vty
*vty
)
3478 struct vrf
*vrf
= pim
->vrf
;
3479 time_t now
= pim_time_monotonic_sec();
3485 vty_out(vty
, "Router MLAG Role: %s\n",
3486 mlag_role2str(router
->mlag_role
, mlag_role
, sizeof(mlag_role
)));
3487 vty_out(vty
, "Mroute socket descriptor:");
3489 vty_out(vty
, " %d(%s)\n", pim
->mroute_socket
, vrf
->name
);
3490 vty_out(vty
, "PIM Register socket descriptor:");
3491 vty_out(vty
, " %d(%s)\n", pim
->reg_sock
, vrf
->name
);
3493 pim_time_uptime(uptime
, sizeof(uptime
),
3494 now
- pim
->mroute_socket_creation
);
3495 vty_out(vty
, "Mroute socket uptime: %s\n", uptime
);
3499 pim_zebra_zclient_update(vty
);
3500 pim_zlookup_show_ip_multicast(vty
);
3503 vty_out(vty
, "Maximum highest VifIndex: %d\n", PIM_MAX_USABLE_VIFS
);
3506 vty_out(vty
, "Upstream Join Timer: %d secs\n", router
->t_periodic
);
3507 vty_out(vty
, "Join/Prune Holdtime: %d secs\n", PIM_JP_HOLDTIME
);
3508 vty_out(vty
, "PIM ECMP: %s\n", pim
->ecmp_enable
? "Enable" : "Disable");
3509 vty_out(vty
, "PIM ECMP Rebalance: %s\n",
3510 pim
->ecmp_rebalance_enable
? "Enable" : "Disable");
3514 pim_show_rpf_refresh_stats(vty
, pim
, now
, NULL
);
3518 show_scan_oil_stats(pim
, vty
, now
);
3520 show_multicast_interfaces(pim
, vty
, NULL
);
3523 void show_mroute(struct pim_instance
*pim
, struct vty
*vty
, pim_sgaddr
*sg
,
3524 bool fill
, json_object
*json
)
3526 struct listnode
*node
;
3527 struct channel_oil
*c_oil
;
3528 struct static_route
*s_route
;
3529 struct ttable
*tt
= NULL
;
3532 json_object
*json_group
= NULL
;
3533 json_object
*json_source
= NULL
;
3534 json_object
*json_oil
= NULL
;
3535 json_object
*json_ifp_out
= NULL
;
3538 char grp_str
[PIM_ADDRSTRLEN
];
3539 char src_str
[PIM_ADDRSTRLEN
];
3540 char in_ifname
[INTERFACE_NAMSIZ
+ 1];
3541 char out_ifname
[INTERFACE_NAMSIZ
+ 1];
3543 struct interface
*ifp_in
;
3545 char state_str
[PIM_REG_STATE_STR_LEN
];
3546 char mroute_uptime
[10];
3549 vty_out(vty
, "IP Multicast Routing Table\n");
3550 vty_out(vty
, "Flags: S - Sparse, C - Connected, P - Pruned\n");
3552 " R - SGRpt Pruned, F - Register flag, T - SPT-bit set\n");
3554 /* Prepare table. */
3555 tt
= ttable_new(&ttable_styles
[TTSTYLE_BLANK
]);
3557 tt
, "Source|Group|Flags|Proto|Input|Output|TTL|Uptime");
3558 tt
->style
.cell
.rpad
= 2;
3559 tt
->style
.corner
= '+';
3563 now
= pim_time_monotonic_sec();
3565 /* print list of PIM and IGMP routes */
3566 frr_each (rb_pim_oil
, &pim
->channel_oil_head
, c_oil
) {
3569 if (!c_oil
->installed
)
3572 if (!pim_addr_is_any(sg
->grp
) &&
3573 pim_addr_cmp(sg
->grp
, *oil_mcastgrp(c_oil
)))
3575 if (!pim_addr_is_any(sg
->src
) &&
3576 pim_addr_cmp(sg
->src
, *oil_origin(c_oil
)))
3579 snprintfrr(grp_str
, sizeof(grp_str
), "%pPAs",
3580 oil_mcastgrp(c_oil
));
3581 snprintfrr(src_str
, sizeof(src_str
), "%pPAs",
3584 strlcpy(state_str
, "S", sizeof(state_str
));
3585 /* When a non DR receives a igmp join, it creates a (*,G)
3586 * channel_oil without any upstream creation
3589 if (PIM_UPSTREAM_FLAG_TEST_SRC_IGMP(c_oil
->up
->flags
))
3590 strlcat(state_str
, "C", sizeof(state_str
));
3591 if (pim_upstream_is_sg_rpt(c_oil
->up
))
3592 strlcat(state_str
, "R", sizeof(state_str
));
3593 if (PIM_UPSTREAM_FLAG_TEST_FHR(c_oil
->up
->flags
))
3594 strlcat(state_str
, "F", sizeof(state_str
));
3595 if (c_oil
->up
->sptbit
== PIM_UPSTREAM_SPTBIT_TRUE
)
3596 strlcat(state_str
, "T", sizeof(state_str
));
3598 if (pim_channel_oil_empty(c_oil
))
3599 strlcat(state_str
, "P", sizeof(state_str
));
3601 ifp_in
= pim_if_find_by_vif_index(pim
, *oil_parent(c_oil
));
3604 strlcpy(in_ifname
, ifp_in
->name
, sizeof(in_ifname
));
3606 strlcpy(in_ifname
, "<iif?>", sizeof(in_ifname
));
3609 pim_time_uptime(mroute_uptime
, sizeof(mroute_uptime
),
3610 now
- c_oil
->mroute_creation
);
3614 /* Find the group, create it if it doesn't exist */
3615 json_object_object_get_ex(json
, grp_str
, &json_group
);
3618 json_group
= json_object_new_object();
3619 json_object_object_add(json
, grp_str
,
3623 /* Find the source nested under the group, create it if
3626 json_object_object_get_ex(json_group
, src_str
,
3630 json_source
= json_object_new_object();
3631 json_object_object_add(json_group
, src_str
,
3635 /* Find the inbound interface nested under the source,
3636 * create it if it doesn't exist
3638 json_object_string_add(json_source
, "source", src_str
);
3639 json_object_string_add(json_source
, "group", grp_str
);
3640 json_object_int_add(json_source
, "installed",
3642 json_object_int_add(json_source
, "refCount",
3643 c_oil
->oil_ref_count
);
3644 json_object_int_add(json_source
, "oilSize",
3646 json_object_int_add(json_source
, "OilInheritedRescan",
3647 c_oil
->oil_inherited_rescan
);
3648 json_object_int_add(json_source
, "oilInheritedRescan",
3649 c_oil
->oil_inherited_rescan
);
3650 json_object_string_add(json_source
, "iif", in_ifname
);
3651 json_object_string_add(json_source
, "upTime",
3656 for (oif_vif_index
= 0; oif_vif_index
< MAXVIFS
;
3658 struct interface
*ifp_out
;
3661 ttl
= oil_if_has(c_oil
, oif_vif_index
);
3665 /* do not display muted OIFs */
3666 if (c_oil
->oif_flags
[oif_vif_index
] & PIM_OIF_FLAG_MUTE
)
3669 if (*oil_parent(c_oil
) == oif_vif_index
&&
3670 !pim_mroute_allow_iif_in_oil(c_oil
, oif_vif_index
))
3673 ifp_out
= pim_if_find_by_vif_index(pim
, oif_vif_index
);
3677 strlcpy(out_ifname
, ifp_out
->name
,
3678 sizeof(out_ifname
));
3680 strlcpy(out_ifname
, "<oif?>",
3681 sizeof(out_ifname
));
3684 json_ifp_out
= json_object_new_object();
3685 json_object_string_add(json_ifp_out
, "source",
3687 json_object_string_add(json_ifp_out
, "group",
3690 if (c_oil
->oif_flags
[oif_vif_index
] &
3691 PIM_OIF_FLAG_PROTO_PIM
)
3692 json_object_boolean_true_add(
3693 json_ifp_out
, "protocolPim");
3695 if (c_oil
->oif_flags
[oif_vif_index
] &
3696 PIM_OIF_FLAG_PROTO_GM
)
3698 json_object_boolean_true_add(
3699 json_ifp_out
, "protocolIgmp");
3701 json_object_boolean_true_add(
3702 json_ifp_out
, "protocolMld");
3705 if (c_oil
->oif_flags
[oif_vif_index
] &
3706 PIM_OIF_FLAG_PROTO_VXLAN
)
3707 json_object_boolean_true_add(
3708 json_ifp_out
, "protocolVxlan");
3710 if (c_oil
->oif_flags
[oif_vif_index
] &
3711 PIM_OIF_FLAG_PROTO_STAR
)
3712 json_object_boolean_true_add(
3714 "protocolInherited");
3716 json_object_string_add(json_ifp_out
,
3719 json_object_int_add(json_ifp_out
, "iVifI",
3720 *oil_parent(c_oil
));
3721 json_object_string_add(json_ifp_out
,
3722 "outboundInterface",
3724 json_object_int_add(json_ifp_out
, "oVifI",
3726 json_object_int_add(json_ifp_out
, "ttl", ttl
);
3727 json_object_string_add(json_ifp_out
, "upTime",
3729 json_object_string_add(json_source
, "flags",
3732 json_oil
= json_object_new_object();
3733 json_object_object_add(json_source
,
3736 json_object_object_add(json_oil
, out_ifname
,
3740 if (c_oil
->oif_flags
[oif_vif_index
] &
3741 PIM_OIF_FLAG_PROTO_PIM
) {
3742 strlcpy(proto
, "PIM", sizeof(proto
));
3745 if (c_oil
->oif_flags
[oif_vif_index
] &
3746 PIM_OIF_FLAG_PROTO_GM
) {
3748 strlcpy(proto
, "IGMP", sizeof(proto
));
3750 strlcpy(proto
, "MLD", sizeof(proto
));
3754 if (c_oil
->oif_flags
[oif_vif_index
] &
3755 PIM_OIF_FLAG_PROTO_VXLAN
) {
3756 strlcpy(proto
, "VxLAN", sizeof(proto
));
3759 if (c_oil
->oif_flags
[oif_vif_index
] &
3760 PIM_OIF_FLAG_PROTO_STAR
) {
3761 strlcpy(proto
, "STAR", sizeof(proto
));
3764 ttable_add_row(tt
, "%s|%s|%s|%s|%s|%s|%d|%s",
3765 src_str
, grp_str
, state_str
,
3766 proto
, in_ifname
, out_ifname
,
3767 ttl
, mroute_uptime
);
3772 in_ifname
[0] = '\0';
3773 state_str
[0] = '\0';
3774 mroute_uptime
[0] = '\0';
3780 if (!json
&& !found_oif
) {
3781 ttable_add_row(tt
, "%pPAs|%pPAs|%s|%s|%s|%s|%d|%s",
3782 oil_origin(c_oil
), oil_mcastgrp(c_oil
),
3783 state_str
, "none", in_ifname
, "none", 0,
3788 /* Print list of static routes */
3789 for (ALL_LIST_ELEMENTS_RO(pim
->static_routes
, node
, s_route
)) {
3792 if (!s_route
->c_oil
.installed
)
3795 snprintfrr(grp_str
, sizeof(grp_str
), "%pPAs", &s_route
->group
);
3796 snprintfrr(src_str
, sizeof(src_str
), "%pPAs", &s_route
->source
);
3797 ifp_in
= pim_if_find_by_vif_index(pim
, s_route
->iif
);
3801 strlcpy(in_ifname
, ifp_in
->name
, sizeof(in_ifname
));
3803 strlcpy(in_ifname
, "<iif?>", sizeof(in_ifname
));
3807 /* Find the group, create it if it doesn't exist */
3808 json_object_object_get_ex(json
, grp_str
, &json_group
);
3811 json_group
= json_object_new_object();
3812 json_object_object_add(json
, grp_str
,
3816 /* Find the source nested under the group, create it if
3819 json_object_object_get_ex(json_group
, src_str
,
3823 json_source
= json_object_new_object();
3824 json_object_object_add(json_group
, src_str
,
3828 json_object_string_add(json_source
, "iif", in_ifname
);
3831 strlcpy(proto
, "STATIC", sizeof(proto
));
3834 for (oif_vif_index
= 0; oif_vif_index
< MAXVIFS
;
3836 struct interface
*ifp_out
;
3837 char oif_uptime
[10];
3840 ttl
= s_route
->oif_ttls
[oif_vif_index
];
3844 ifp_out
= pim_if_find_by_vif_index(pim
, oif_vif_index
);
3846 oif_uptime
, sizeof(oif_uptime
),
3847 now
- s_route
->c_oil
3848 .oif_creation
[oif_vif_index
]);
3852 strlcpy(out_ifname
, ifp_out
->name
,
3853 sizeof(out_ifname
));
3855 strlcpy(out_ifname
, "<oif?>",
3856 sizeof(out_ifname
));
3859 json_ifp_out
= json_object_new_object();
3860 json_object_string_add(json_ifp_out
, "source",
3862 json_object_string_add(json_ifp_out
, "group",
3864 json_object_boolean_true_add(json_ifp_out
,
3866 json_object_string_add(json_ifp_out
,
3869 json_object_int_add(
3870 json_ifp_out
, "iVifI",
3871 *oil_parent(&s_route
->c_oil
));
3872 json_object_string_add(json_ifp_out
,
3873 "outboundInterface",
3875 json_object_int_add(json_ifp_out
, "oVifI",
3877 json_object_int_add(json_ifp_out
, "ttl", ttl
);
3878 json_object_string_add(json_ifp_out
, "upTime",
3881 json_oil
= json_object_new_object();
3882 json_object_object_add(json_source
,
3885 json_object_object_add(json_oil
, out_ifname
,
3889 tt
, "%pPAs|%pPAs|%s|%s|%s|%s|%d|%s",
3890 &s_route
->source
, &s_route
->group
, "-",
3891 proto
, in_ifname
, out_ifname
, ttl
,
3893 if (first
&& !fill
) {
3896 in_ifname
[0] = '\0';
3902 if (!json
&& !found_oif
) {
3903 ttable_add_row(tt
, "%pPAs|%pPAs|%s|%s|%s|%s|%d|%s",
3904 &s_route
->source
, &s_route
->group
, "-",
3905 proto
, in_ifname
, "none", 0, "--:--:--");
3908 /* Dump the generated table. */
3910 table
= ttable_dump(tt
, "\n");
3911 vty_out(vty
, "%s\n", table
);
3912 XFREE(MTYPE_TMP
, table
);
3917 static void show_mroute_count_per_channel_oil(struct channel_oil
*c_oil
,
3921 json_object
*json_group
= NULL
;
3922 json_object
*json_source
= NULL
;
3924 if (!c_oil
->installed
)
3927 pim_mroute_update_counters(c_oil
);
3930 char group_str
[PIM_ADDRSTRLEN
];
3931 char source_str
[PIM_ADDRSTRLEN
];
3933 snprintfrr(group_str
, sizeof(group_str
), "%pPAs",
3934 oil_mcastgrp(c_oil
));
3935 snprintfrr(source_str
, sizeof(source_str
), "%pPAs",
3938 json_object_object_get_ex(json
, group_str
, &json_group
);
3941 json_group
= json_object_new_object();
3942 json_object_object_add(json
, group_str
, json_group
);
3945 json_source
= json_object_new_object();
3946 json_object_object_add(json_group
, source_str
, json_source
);
3947 json_object_int_add(json_source
, "lastUsed",
3948 c_oil
->cc
.lastused
/ 100);
3949 json_object_int_add(json_source
, "packets", c_oil
->cc
.pktcnt
);
3950 json_object_int_add(json_source
, "bytes", c_oil
->cc
.bytecnt
);
3951 json_object_int_add(json_source
, "wrongIf", c_oil
->cc
.wrong_if
);
3954 ttable_add_row(tt
, "%pPAs|%pPAs|%llu|%ld|%ld|%ld",
3955 oil_origin(c_oil
), oil_mcastgrp(c_oil
),
3956 c_oil
->cc
.lastused
/ 100,
3957 c_oil
->cc
.pktcnt
- c_oil
->cc
.origpktcnt
,
3958 c_oil
->cc
.bytecnt
- c_oil
->cc
.origbytecnt
,
3959 c_oil
->cc
.wrong_if
- c_oil
->cc
.origwrong_if
);
3963 void show_mroute_count(struct pim_instance
*pim
, struct vty
*vty
,
3966 struct listnode
*node
;
3967 struct channel_oil
*c_oil
;
3968 struct static_route
*sr
;
3969 struct ttable
*tt
= NULL
;
3975 /* Prepare table. */
3976 tt
= ttable_new(&ttable_styles
[TTSTYLE_BLANK
]);
3978 "Source|Group|LastUsed|Packets|Bytes|WrongIf");
3979 tt
->style
.cell
.rpad
= 2;
3980 tt
->style
.corner
= '+';
3984 /* Print PIM and IGMP route counts */
3985 frr_each (rb_pim_oil
, &pim
->channel_oil_head
, c_oil
)
3986 show_mroute_count_per_channel_oil(c_oil
, json
, tt
);
3988 for (ALL_LIST_ELEMENTS_RO(pim
->static_routes
, node
, sr
))
3989 show_mroute_count_per_channel_oil(&sr
->c_oil
, json
, tt
);
3991 /* Dump the generated table. */
3993 table
= ttable_dump(tt
, "\n");
3994 vty_out(vty
, "%s\n", table
);
3995 XFREE(MTYPE_TMP
, table
);
4000 void show_mroute_summary(struct pim_instance
*pim
, struct vty
*vty
,
4003 struct listnode
*node
;
4004 struct channel_oil
*c_oil
;
4005 struct static_route
*s_route
;
4006 uint32_t starg_sw_mroute_cnt
= 0;
4007 uint32_t sg_sw_mroute_cnt
= 0;
4008 uint32_t starg_hw_mroute_cnt
= 0;
4009 uint32_t sg_hw_mroute_cnt
= 0;
4010 json_object
*json_starg
= NULL
;
4011 json_object
*json_sg
= NULL
;
4014 vty_out(vty
, "Mroute Type Installed/Total\n");
4016 frr_each (rb_pim_oil
, &pim
->channel_oil_head
, c_oil
) {
4017 if (!c_oil
->installed
) {
4018 if (pim_addr_is_any(*oil_origin(c_oil
)))
4019 starg_sw_mroute_cnt
++;
4023 if (pim_addr_is_any(*oil_origin(c_oil
)))
4024 starg_hw_mroute_cnt
++;
4030 for (ALL_LIST_ELEMENTS_RO(pim
->static_routes
, node
, s_route
)) {
4031 if (!s_route
->c_oil
.installed
) {
4032 if (pim_addr_is_any(*oil_origin(&s_route
->c_oil
)))
4033 starg_sw_mroute_cnt
++;
4037 if (pim_addr_is_any(*oil_origin(&s_route
->c_oil
)))
4038 starg_hw_mroute_cnt
++;
4045 vty_out(vty
, "%-20s %u/%u\n", "(*, G)", starg_hw_mroute_cnt
,
4046 starg_sw_mroute_cnt
+ starg_hw_mroute_cnt
);
4047 vty_out(vty
, "%-20s %u/%u\n", "(S, G)", sg_hw_mroute_cnt
,
4048 sg_sw_mroute_cnt
+ sg_hw_mroute_cnt
);
4049 vty_out(vty
, "------\n");
4050 vty_out(vty
, "%-20s %u/%u\n", "Total",
4051 (starg_hw_mroute_cnt
+ sg_hw_mroute_cnt
),
4052 (starg_sw_mroute_cnt
+ starg_hw_mroute_cnt
+
4053 sg_sw_mroute_cnt
+ sg_hw_mroute_cnt
));
4055 /* (*,G) route details */
4056 json_starg
= json_object_new_object();
4057 json_object_object_add(json
, "wildcardGroup", json_starg
);
4059 json_object_int_add(json_starg
, "installed",
4060 starg_hw_mroute_cnt
);
4061 json_object_int_add(json_starg
, "total",
4062 starg_sw_mroute_cnt
+ starg_hw_mroute_cnt
);
4064 /* (S, G) route details */
4065 json_sg
= json_object_new_object();
4066 json_object_object_add(json
, "sourceGroup", json_sg
);
4068 json_object_int_add(json_sg
, "installed", sg_hw_mroute_cnt
);
4069 json_object_int_add(json_sg
, "total",
4070 sg_sw_mroute_cnt
+ sg_hw_mroute_cnt
);
4072 json_object_int_add(json
, "totalNumOfInstalledMroutes",
4073 starg_hw_mroute_cnt
+ sg_hw_mroute_cnt
);
4074 json_object_int_add(json
, "totalNumOfMroutes",
4075 starg_sw_mroute_cnt
+ starg_hw_mroute_cnt
+
4081 int clear_ip_mroute_count_command(struct vty
*vty
, const char *name
)
4083 struct listnode
*node
;
4084 struct channel_oil
*c_oil
;
4085 struct static_route
*sr
;
4086 struct vrf
*v
= pim_cmd_lookup(vty
, name
);
4087 struct pim_instance
*pim
;
4093 frr_each (rb_pim_oil
, &pim
->channel_oil_head
, c_oil
) {
4094 if (!c_oil
->installed
)
4097 pim_mroute_update_counters(c_oil
);
4098 c_oil
->cc
.origpktcnt
= c_oil
->cc
.pktcnt
;
4099 c_oil
->cc
.origbytecnt
= c_oil
->cc
.bytecnt
;
4100 c_oil
->cc
.origwrong_if
= c_oil
->cc
.wrong_if
;
4103 for (ALL_LIST_ELEMENTS_RO(pim
->static_routes
, node
, sr
)) {
4104 if (!sr
->c_oil
.installed
)
4107 pim_mroute_update_counters(&sr
->c_oil
);
4109 sr
->c_oil
.cc
.origpktcnt
= sr
->c_oil
.cc
.pktcnt
;
4110 sr
->c_oil
.cc
.origbytecnt
= sr
->c_oil
.cc
.bytecnt
;
4111 sr
->c_oil
.cc
.origwrong_if
= sr
->c_oil
.cc
.wrong_if
;
4116 struct vrf
*pim_cmd_lookup(struct vty
*vty
, const char *name
)
4121 vrf
= vrf_lookup_by_name(name
);
4123 vrf
= vrf_lookup_by_id(VRF_DEFAULT
);
4126 vty_out(vty
, "Specified VRF: %s does not exist\n", name
);
4131 void clear_mroute(struct pim_instance
*pim
)
4133 struct pim_upstream
*up
;
4134 struct interface
*ifp
;
4136 /* scan interfaces */
4137 FOR_ALL_INTERFACES (pim
->vrf
, ifp
) {
4138 struct pim_interface
*pim_ifp
= ifp
->info
;
4139 struct pim_ifchannel
*ch
;
4144 /* deleting all ifchannels */
4145 while (!RB_EMPTY(pim_ifchannel_rb
, &pim_ifp
->ifchannel_rb
)) {
4146 ch
= RB_ROOT(pim_ifchannel_rb
, &pim_ifp
->ifchannel_rb
);
4148 pim_ifchannel_delete(ch
);
4152 /* clean up all igmp groups */
4153 struct gm_group
*grp
;
4155 if (pim_ifp
->gm_group_list
) {
4156 while (pim_ifp
->gm_group_list
->count
) {
4157 grp
= listnode_head(pim_ifp
->gm_group_list
);
4158 igmp_group_delete(grp
);
4162 struct gm_if
*gm_ifp
;
4164 gm_ifp
= pim_ifp
->mld
;
4166 gm_group_delete(gm_ifp
);
4170 /* clean up all upstreams*/
4171 while ((up
= rb_pim_upstream_first(&pim
->upstream_head
)))
4172 pim_upstream_del(pim
, up
, __func__
);
4175 void clear_pim_statistics(struct pim_instance
*pim
)
4177 struct interface
*ifp
;
4181 pim
->bsm_dropped
= 0;
4183 /* scan interfaces */
4184 FOR_ALL_INTERFACES (pim
->vrf
, ifp
) {
4185 struct pim_interface
*pim_ifp
= ifp
->info
;
4190 pim_ifp
->pim_ifstat_bsm_cfg_miss
= 0;
4191 pim_ifp
->pim_ifstat_ucast_bsm_cfg_miss
= 0;
4192 pim_ifp
->pim_ifstat_bsm_invalid_sz
= 0;
4196 int clear_pim_interface_traffic(const char *vrf
, struct vty
*vty
)
4198 struct interface
*ifp
= NULL
;
4199 struct pim_interface
*pim_ifp
= NULL
;
4201 struct vrf
*v
= pim_cmd_lookup(vty
, vrf
);
4206 FOR_ALL_INTERFACES (v
, ifp
) {
4207 pim_ifp
= ifp
->info
;
4212 pim_ifp
->pim_ifstat_hello_recv
= 0;
4213 pim_ifp
->pim_ifstat_hello_sent
= 0;
4214 pim_ifp
->pim_ifstat_join_recv
= 0;
4215 pim_ifp
->pim_ifstat_join_send
= 0;
4216 pim_ifp
->pim_ifstat_prune_recv
= 0;
4217 pim_ifp
->pim_ifstat_prune_send
= 0;
4218 pim_ifp
->pim_ifstat_reg_recv
= 0;
4219 pim_ifp
->pim_ifstat_reg_send
= 0;
4220 pim_ifp
->pim_ifstat_reg_stop_recv
= 0;
4221 pim_ifp
->pim_ifstat_reg_stop_send
= 0;
4222 pim_ifp
->pim_ifstat_assert_recv
= 0;
4223 pim_ifp
->pim_ifstat_assert_send
= 0;
4224 pim_ifp
->pim_ifstat_bsm_rx
= 0;
4225 pim_ifp
->pim_ifstat_bsm_tx
= 0;
4227 pim_ifp
->igmp_ifstat_joins_sent
= 0;
4228 pim_ifp
->igmp_ifstat_joins_failed
= 0;
4229 pim_ifp
->igmp_peak_group_count
= 0;
4236 int pim_debug_pim_cmd(void)
4238 PIM_DO_DEBUG_PIM_EVENTS
;
4239 PIM_DO_DEBUG_PIM_PACKETS
;
4240 PIM_DO_DEBUG_PIM_TRACE
;
4241 PIM_DO_DEBUG_MSDP_EVENTS
;
4242 PIM_DO_DEBUG_MSDP_PACKETS
;
4248 int pim_no_debug_pim_cmd(void)
4250 PIM_DONT_DEBUG_PIM_EVENTS
;
4251 PIM_DONT_DEBUG_PIM_PACKETS
;
4252 PIM_DONT_DEBUG_PIM_TRACE
;
4253 PIM_DONT_DEBUG_MSDP_EVENTS
;
4254 PIM_DONT_DEBUG_MSDP_PACKETS
;
4256 PIM_DONT_DEBUG_PIM_PACKETDUMP_SEND
;
4257 PIM_DONT_DEBUG_PIM_PACKETDUMP_RECV
;
4259 PIM_DONT_DEBUG_VXLAN
;
4263 int pim_debug_pim_packets_cmd(const char *hello
, const char *joins
,
4264 const char *registers
, struct vty
*vty
)
4267 PIM_DO_DEBUG_PIM_HELLO
;
4268 vty_out(vty
, "PIM Hello debugging is on\n");
4270 PIM_DO_DEBUG_PIM_J_P
;
4271 vty_out(vty
, "PIM Join/Prune debugging is on\n");
4272 } else if (registers
) {
4273 PIM_DO_DEBUG_PIM_REG
;
4274 vty_out(vty
, "PIM Register debugging is on\n");
4276 PIM_DO_DEBUG_PIM_PACKETS
;
4277 vty_out(vty
, "PIM Packet debugging is on\n");
4282 int pim_no_debug_pim_packets_cmd(const char *hello
, const char *joins
,
4283 const char *registers
, struct vty
*vty
)
4286 PIM_DONT_DEBUG_PIM_HELLO
;
4287 vty_out(vty
, "PIM Hello debugging is off\n");
4289 PIM_DONT_DEBUG_PIM_J_P
;
4290 vty_out(vty
, "PIM Join/Prune debugging is off\n");
4291 } else if (registers
) {
4292 PIM_DONT_DEBUG_PIM_REG
;
4293 vty_out(vty
, "PIM Register debugging is off\n");
4295 PIM_DONT_DEBUG_PIM_PACKETS
;
4296 vty_out(vty
, "PIM Packet debugging is off\n");
4302 int pim_show_rpf_helper(const char *vrf
, struct vty
*vty
, bool json
)
4304 struct pim_instance
*pim
;
4306 json_object
*json_parent
= NULL
;
4308 v
= vrf_lookup_by_name(vrf
? vrf
: VRF_DEFAULT_NAME
);
4316 vty_out(vty
, "%% Unable to find pim instance\n");
4321 json_parent
= json_object_new_object();
4323 pim_show_rpf(pim
, vty
, json_parent
);
4326 vty_json(vty
, json_parent
);
4331 int pim_show_rpf_vrf_all_helper(struct vty
*vty
, bool json
)
4334 json_object
*json_parent
= NULL
;
4335 json_object
*json_vrf
= NULL
;
4338 json_parent
= json_object_new_object();
4340 RB_FOREACH (vrf
, vrf_name_head
, &vrfs_by_name
) {
4342 vty_out(vty
, "VRF: %s\n", vrf
->name
);
4344 json_vrf
= json_object_new_object();
4345 pim_show_rpf(vrf
->info
, vty
, json_vrf
);
4347 json_object_object_add(json_parent
, vrf
->name
,
4351 vty_json(vty
, json_parent
);
4356 int pim_show_rp_helper(const char *vrf
, struct vty
*vty
, const char *group_str
,
4357 const struct prefix
*group
, bool json
)
4359 struct pim_instance
*pim
;
4361 json_object
*json_parent
= NULL
;
4362 struct prefix
*range
= NULL
;
4364 v
= vrf_lookup_by_name(vrf
? vrf
: VRF_DEFAULT_NAME
);
4372 vty_out(vty
, "%% Unable to find pim instance\n");
4377 range
= prefix_new();
4378 prefix_copy(range
, group
);
4383 json_parent
= json_object_new_object();
4385 pim_rp_show_information(pim
, range
, vty
, json_parent
);
4388 vty_json(vty
, json_parent
);
4390 prefix_free(&range
);
4395 int pim_show_rp_vrf_all_helper(struct vty
*vty
, const char *group_str
,
4396 const struct prefix
*group
, bool json
)
4399 json_object
*json_parent
= NULL
;
4400 json_object
*json_vrf
= NULL
;
4401 struct prefix
*range
= NULL
;
4404 range
= prefix_new();
4405 prefix_copy(range
, group
);
4410 json_parent
= json_object_new_object();
4412 RB_FOREACH (vrf
, vrf_name_head
, &vrfs_by_name
) {
4414 vty_out(vty
, "VRF: %s\n", vrf
->name
);
4416 json_vrf
= json_object_new_object();
4417 pim_rp_show_information(vrf
->info
, range
, vty
, json_vrf
);
4419 json_object_object_add(json_parent
, vrf
->name
,
4423 vty_json(vty
, json_parent
);
4425 prefix_free(&range
);
4430 int pim_show_secondary_helper(const char *vrf
, struct vty
*vty
)
4432 struct pim_instance
*pim
;
4435 v
= vrf_lookup_by_name(vrf
? vrf
: VRF_DEFAULT_NAME
);
4443 vty_out(vty
, "%% Unable to find pim instance\n");
4447 pim_show_neighbors_secondary(pim
, vty
);
4452 int pim_show_statistics_helper(const char *vrf
, struct vty
*vty
,
4453 const char *word
, bool uj
)
4455 struct pim_instance
*pim
;
4458 v
= vrf_lookup_by_name(vrf
? vrf
: VRF_DEFAULT_NAME
);
4466 vty_out(vty
, "%% Unable to find pim instance\n");
4471 pim_show_statistics(pim
, vty
, word
, uj
);
4473 pim_show_statistics(pim
, vty
, NULL
, uj
);
4478 int pim_show_upstream_helper(const char *vrf
, struct vty
*vty
, pim_addr s_or_g
,
4479 pim_addr g
, bool json
)
4481 pim_sgaddr sg
= {0};
4483 struct pim_instance
*pim
;
4484 json_object
*json_parent
= NULL
;
4486 v
= vrf_lookup_by_name(vrf
? vrf
: VRF_DEFAULT_NAME
);
4489 vty_out(vty
, "%% Vrf specified: %s does not exist\n", vrf
);
4495 vty_out(vty
, "%% Unable to find pim instance\n");
4500 json_parent
= json_object_new_object();
4502 if (!pim_addr_is_any(s_or_g
)) {
4503 if (!pim_addr_is_any(g
)) {
4510 pim_show_upstream(pim
, vty
, &sg
, json_parent
);
4513 vty_json(vty
, json_parent
);
4518 int pim_show_upstream_vrf_all_helper(struct vty
*vty
, bool json
)
4520 pim_sgaddr sg
= {0};
4522 json_object
*json_parent
= NULL
;
4523 json_object
*json_vrf
= NULL
;
4526 json_parent
= json_object_new_object();
4528 RB_FOREACH (vrf
, vrf_name_head
, &vrfs_by_name
) {
4530 vty_out(vty
, "VRF: %s\n", vrf
->name
);
4532 json_vrf
= json_object_new_object();
4533 pim_show_upstream(vrf
->info
, vty
, &sg
, json_vrf
);
4535 json_object_object_add(json_parent
, vrf
->name
,
4540 vty_json(vty
, json_parent
);
4545 int pim_show_upstream_join_desired_helper(const char *vrf
, struct vty
*vty
,
4548 struct pim_instance
*pim
;
4551 v
= vrf_lookup_by_name(vrf
? vrf
: VRF_DEFAULT_NAME
);
4559 vty_out(vty
, "%% Unable to find pim instance\n");
4563 pim_show_join_desired(pim
, vty
, uj
);
4568 int pim_show_upstream_rpf_helper(const char *vrf
, struct vty
*vty
, bool uj
)
4570 struct pim_instance
*pim
;
4573 v
= vrf_lookup_by_name(vrf
? vrf
: VRF_DEFAULT_NAME
);
4581 vty_out(vty
, "%% Unable to find pim instance\n");
4585 pim_show_upstream_rpf(pim
, vty
, uj
);
4590 int pim_show_state_helper(const char *vrf
, struct vty
*vty
,
4591 const char *s_or_g_str
, const char *g_str
, bool json
)
4593 struct pim_instance
*pim
;
4595 json_object
*json_parent
= NULL
;
4597 v
= vrf_lookup_by_name(vrf
? vrf
: VRF_DEFAULT_NAME
);
4605 vty_out(vty
, "%% Unable to find pim instance\n");
4610 json_parent
= json_object_new_object();
4612 pim_show_state(pim
, vty
, s_or_g_str
, g_str
, json_parent
);
4615 vty_json(vty
, json_parent
);
4620 int pim_show_state_vrf_all_helper(struct vty
*vty
, const char *s_or_g_str
,
4621 const char *g_str
, bool json
)
4624 json_object
*json_parent
= NULL
;
4625 json_object
*json_vrf
= NULL
;
4628 json_parent
= json_object_new_object();
4630 RB_FOREACH (vrf
, vrf_name_head
, &vrfs_by_name
) {
4632 vty_out(vty
, "VRF: %s\n", vrf
->name
);
4634 json_vrf
= json_object_new_object();
4635 pim_show_state(vrf
->info
, vty
, s_or_g_str
, g_str
, json_vrf
);
4637 json_object_object_add(json_parent
, vrf
->name
,
4641 vty_json(vty
, json_parent
);
4646 int pim_show_multicast_helper(const char *vrf
, struct vty
*vty
)
4649 struct pim_instance
*pim
;
4651 v
= vrf_lookup_by_name(vrf
? vrf
: VRF_DEFAULT_NAME
);
4659 vty_out(vty
, "%% Unable to find pim instance\n");
4663 pim_cmd_show_ip_multicast_helper(pim
, vty
);
4668 int pim_show_multicast_vrf_all_helper(struct vty
*vty
)
4672 RB_FOREACH (vrf
, vrf_name_head
, &vrfs_by_name
) {
4673 vty_out(vty
, "VRF: %s\n", vrf
->name
);
4674 pim_cmd_show_ip_multicast_helper(vrf
->info
, vty
);
4680 int pim_show_multicast_count_helper(const char *vrf
, struct vty
*vty
, bool json
)
4682 struct pim_instance
*pim
;
4684 json_object
*json_parent
= NULL
;
4686 v
= vrf_lookup_by_name(vrf
? vrf
: VRF_DEFAULT_NAME
);
4694 vty_out(vty
, "%% Unable to find pim instance\n");
4699 json_parent
= json_object_new_object();
4701 show_multicast_interfaces(pim
, vty
, json_parent
);
4704 vty_json(vty
, json_parent
);
4709 int pim_show_multicast_count_vrf_all_helper(struct vty
*vty
, bool json
)
4712 json_object
*json_parent
= NULL
;
4713 json_object
*json_vrf
= NULL
;
4716 json_parent
= json_object_new_object();
4718 RB_FOREACH (vrf
, vrf_name_head
, &vrfs_by_name
) {
4720 vty_out(vty
, "VRF: %s\n", vrf
->name
);
4722 json_vrf
= json_object_new_object();
4724 show_multicast_interfaces(vrf
->info
, vty
, json_vrf
);
4726 json_object_object_add(json_parent
, vrf
->name
,
4730 vty_json(vty
, json_parent
);
4735 int pim_show_mroute_helper(const char *vrf
, struct vty
*vty
, pim_addr s_or_g
,
4736 pim_addr g
, bool fill
, bool json
)
4738 pim_sgaddr sg
= {0};
4739 struct pim_instance
*pim
;
4741 json_object
*json_parent
= NULL
;
4743 v
= vrf_lookup_by_name(vrf
? vrf
: VRF_DEFAULT_NAME
);
4751 vty_out(vty
, "%% Unable to find pim instance\n");
4756 json_parent
= json_object_new_object();
4758 if (!pim_addr_is_any(s_or_g
)) {
4759 if (!pim_addr_is_any(g
)) {
4766 show_mroute(pim
, vty
, &sg
, fill
, json_parent
);
4769 vty_json(vty
, json_parent
);
4774 int pim_show_mroute_vrf_all_helper(struct vty
*vty
, bool fill
, bool json
)
4776 pim_sgaddr sg
= {0};
4778 json_object
*json_parent
= NULL
;
4779 json_object
*json_vrf
= NULL
;
4782 json_parent
= json_object_new_object();
4784 RB_FOREACH (vrf
, vrf_name_head
, &vrfs_by_name
) {
4786 vty_out(vty
, "VRF: %s\n", vrf
->name
);
4788 json_vrf
= json_object_new_object();
4789 show_mroute(vrf
->info
, vty
, &sg
, fill
, json_vrf
);
4791 json_object_object_add(json_parent
, vrf
->name
,
4795 vty_json(vty
, json_parent
);
4800 int pim_show_mroute_count_helper(const char *vrf
, struct vty
*vty
, bool json
)
4802 struct pim_instance
*pim
;
4804 json_object
*json_parent
= NULL
;
4806 v
= vrf_lookup_by_name(vrf
? vrf
: VRF_DEFAULT_NAME
);
4814 vty_out(vty
, "%% Unable to find pim instance\n");
4819 json_parent
= json_object_new_object();
4821 show_mroute_count(pim
, vty
, json_parent
);
4824 vty_json(vty
, json_parent
);
4829 int pim_show_mroute_count_vrf_all_helper(struct vty
*vty
, bool json
)
4832 json_object
*json_parent
= NULL
;
4833 json_object
*json_vrf
= NULL
;
4836 json_parent
= json_object_new_object();
4838 RB_FOREACH (vrf
, vrf_name_head
, &vrfs_by_name
) {
4840 vty_out(vty
, "VRF: %s\n", vrf
->name
);
4842 json_vrf
= json_object_new_object();
4844 show_mroute_count(vrf
->info
, vty
, json_vrf
);
4847 json_object_object_add(json_parent
, vrf
->name
,
4851 vty_json(vty
, json_parent
);
4856 int pim_show_mroute_summary_helper(const char *vrf
, struct vty
*vty
, bool json
)
4858 struct pim_instance
*pim
;
4860 json_object
*json_parent
= NULL
;
4862 v
= vrf_lookup_by_name(vrf
? vrf
: VRF_DEFAULT_NAME
);
4870 vty_out(vty
, "%% Unable to find pim instance\n");
4875 json_parent
= json_object_new_object();
4877 show_mroute_summary(pim
, vty
, json_parent
);
4880 vty_json(vty
, json_parent
);
4885 int pim_show_mroute_summary_vrf_all_helper(struct vty
*vty
, bool json
)
4888 json_object
*json_parent
= NULL
;
4889 json_object
*json_vrf
= NULL
;
4892 json_parent
= json_object_new_object();
4894 RB_FOREACH (vrf
, vrf_name_head
, &vrfs_by_name
) {
4896 vty_out(vty
, "VRF: %s\n", vrf
->name
);
4898 json_vrf
= json_object_new_object();
4900 show_mroute_summary(vrf
->info
, vty
, json_vrf
);
4903 json_object_object_add(json_parent
, vrf
->name
,
4908 vty_json(vty
, json_parent
);
4913 void pim_show_interface_traffic(struct pim_instance
*pim
, struct vty
*vty
,
4916 struct interface
*ifp
= NULL
;
4917 struct pim_interface
*pim_ifp
= NULL
;
4918 json_object
*json
= NULL
;
4919 json_object
*json_row
= NULL
;
4922 json
= json_object_new_object();
4925 vty_out(vty
, "%-16s%-17s%-17s%-17s%-17s%-17s%-17s%-17s\n",
4926 "Interface", " HELLO", " JOIN",
4927 " PRUNE", " REGISTER", "REGISTER-STOP",
4929 vty_out(vty
, "%-16s%-17s%-17s%-17s%-17s%-17s%-17s%-17s\n", "",
4930 " Rx/Tx", " Rx/Tx", " Rx/Tx",
4931 " Rx/Tx", " Rx/Tx", " Rx/Tx", " Rx/Tx");
4933 "---------------------------------------------------------------------------------------------------------------\n");
4936 FOR_ALL_INTERFACES (pim
->vrf
, ifp
) {
4937 pim_ifp
= ifp
->info
;
4943 json_row
= json_object_new_object();
4944 json_object_pim_ifp_add(json_row
, ifp
);
4945 json_object_int_add(json_row
, "helloRx",
4946 pim_ifp
->pim_ifstat_hello_recv
);
4947 json_object_int_add(json_row
, "helloTx",
4948 pim_ifp
->pim_ifstat_hello_sent
);
4949 json_object_int_add(json_row
, "joinRx",
4950 pim_ifp
->pim_ifstat_join_recv
);
4951 json_object_int_add(json_row
, "joinTx",
4952 pim_ifp
->pim_ifstat_join_send
);
4953 json_object_int_add(json_row
, "pruneRx",
4954 pim_ifp
->pim_ifstat_prune_recv
);
4955 json_object_int_add(json_row
, "pruneTx",
4956 pim_ifp
->pim_ifstat_prune_send
);
4957 json_object_int_add(json_row
, "registerRx",
4958 pim_ifp
->pim_ifstat_reg_recv
);
4959 json_object_int_add(json_row
, "registerTx",
4960 pim_ifp
->pim_ifstat_reg_send
);
4961 json_object_int_add(json_row
, "registerStopRx",
4962 pim_ifp
->pim_ifstat_reg_stop_recv
);
4963 json_object_int_add(json_row
, "registerStopTx",
4964 pim_ifp
->pim_ifstat_reg_stop_send
);
4965 json_object_int_add(json_row
, "assertRx",
4966 pim_ifp
->pim_ifstat_assert_recv
);
4967 json_object_int_add(json_row
, "assertTx",
4968 pim_ifp
->pim_ifstat_assert_send
);
4969 json_object_int_add(json_row
, "bsmRx",
4970 pim_ifp
->pim_ifstat_bsm_rx
);
4971 json_object_int_add(json_row
, "bsmTx",
4972 pim_ifp
->pim_ifstat_bsm_tx
);
4973 json_object_object_add(json
, ifp
->name
, json_row
);
4976 "%-16s %8u/%-8u %7u/%-7u %7u/%-7u %7u/%-7u %7u/%-7u %7u/%-7u %7" PRIu64
4978 ifp
->name
, pim_ifp
->pim_ifstat_hello_recv
,
4979 pim_ifp
->pim_ifstat_hello_sent
,
4980 pim_ifp
->pim_ifstat_join_recv
,
4981 pim_ifp
->pim_ifstat_join_send
,
4982 pim_ifp
->pim_ifstat_prune_recv
,
4983 pim_ifp
->pim_ifstat_prune_send
,
4984 pim_ifp
->pim_ifstat_reg_recv
,
4985 pim_ifp
->pim_ifstat_reg_send
,
4986 pim_ifp
->pim_ifstat_reg_stop_recv
,
4987 pim_ifp
->pim_ifstat_reg_stop_send
,
4988 pim_ifp
->pim_ifstat_assert_recv
,
4989 pim_ifp
->pim_ifstat_assert_send
,
4990 pim_ifp
->pim_ifstat_bsm_rx
,
4991 pim_ifp
->pim_ifstat_bsm_tx
);
4995 vty_json(vty
, json
);
4998 void pim_show_interface_traffic_single(struct pim_instance
*pim
,
4999 struct vty
*vty
, const char *ifname
,
5002 struct interface
*ifp
= NULL
;
5003 struct pim_interface
*pim_ifp
= NULL
;
5004 json_object
*json
= NULL
;
5005 json_object
*json_row
= NULL
;
5006 uint8_t found_ifname
= 0;
5009 json
= json_object_new_object();
5012 vty_out(vty
, "%-16s%-17s%-17s%-17s%-17s%-17s%-17s%-17s\n",
5013 "Interface", " HELLO", " JOIN", " PRUNE",
5014 " REGISTER", " REGISTER-STOP", " ASSERT",
5016 vty_out(vty
, "%-14s%-18s%-17s%-17s%-17s%-17s%-17s%-17s\n", "",
5017 " Rx/Tx", " Rx/Tx", " Rx/Tx", " Rx/Tx",
5018 " Rx/Tx", " Rx/Tx", " Rx/Tx");
5020 "-------------------------------------------------------------------------------------------------------------------------------\n");
5023 FOR_ALL_INTERFACES (pim
->vrf
, ifp
) {
5024 if (strcmp(ifname
, ifp
->name
))
5027 pim_ifp
= ifp
->info
;
5034 json_row
= json_object_new_object();
5035 json_object_pim_ifp_add(json_row
, ifp
);
5036 json_object_int_add(json_row
, "helloRx",
5037 pim_ifp
->pim_ifstat_hello_recv
);
5038 json_object_int_add(json_row
, "helloTx",
5039 pim_ifp
->pim_ifstat_hello_sent
);
5040 json_object_int_add(json_row
, "joinRx",
5041 pim_ifp
->pim_ifstat_join_recv
);
5042 json_object_int_add(json_row
, "joinTx",
5043 pim_ifp
->pim_ifstat_join_send
);
5044 json_object_int_add(json_row
, "pruneRx",
5045 pim_ifp
->pim_ifstat_prune_recv
);
5046 json_object_int_add(json_row
, "pruneTx",
5047 pim_ifp
->pim_ifstat_prune_send
);
5048 json_object_int_add(json_row
, "registerRx",
5049 pim_ifp
->pim_ifstat_reg_recv
);
5050 json_object_int_add(json_row
, "registerTx",
5051 pim_ifp
->pim_ifstat_reg_send
);
5052 json_object_int_add(json_row
, "registerStopRx",
5053 pim_ifp
->pim_ifstat_reg_stop_recv
);
5054 json_object_int_add(json_row
, "registerStopTx",
5055 pim_ifp
->pim_ifstat_reg_stop_send
);
5056 json_object_int_add(json_row
, "assertRx",
5057 pim_ifp
->pim_ifstat_assert_recv
);
5058 json_object_int_add(json_row
, "assertTx",
5059 pim_ifp
->pim_ifstat_assert_send
);
5060 json_object_int_add(json_row
, "bsmRx",
5061 pim_ifp
->pim_ifstat_bsm_rx
);
5062 json_object_int_add(json_row
, "bsmTx",
5063 pim_ifp
->pim_ifstat_bsm_tx
);
5065 json_object_object_add(json
, ifp
->name
, json_row
);
5068 "%-16s %8u/%-8u %7u/%-7u %7u/%-7u %7u/%-7u %7u/%-7u %7u/%-7u %7" PRIu64
5070 ifp
->name
, pim_ifp
->pim_ifstat_hello_recv
,
5071 pim_ifp
->pim_ifstat_hello_sent
,
5072 pim_ifp
->pim_ifstat_join_recv
,
5073 pim_ifp
->pim_ifstat_join_send
,
5074 pim_ifp
->pim_ifstat_prune_recv
,
5075 pim_ifp
->pim_ifstat_prune_send
,
5076 pim_ifp
->pim_ifstat_reg_recv
,
5077 pim_ifp
->pim_ifstat_reg_send
,
5078 pim_ifp
->pim_ifstat_reg_stop_recv
,
5079 pim_ifp
->pim_ifstat_reg_stop_send
,
5080 pim_ifp
->pim_ifstat_assert_recv
,
5081 pim_ifp
->pim_ifstat_assert_send
,
5082 pim_ifp
->pim_ifstat_bsm_rx
,
5083 pim_ifp
->pim_ifstat_bsm_tx
);
5087 vty_json(vty
, json
);
5088 else if (!found_ifname
)
5089 vty_out(vty
, "%% No such interface\n");
5092 int pim_show_interface_traffic_helper(const char *vrf
, const char *if_name
,
5093 struct vty
*vty
, bool uj
)
5095 struct pim_instance
*pim
;
5098 v
= vrf_lookup_by_name(vrf
? vrf
: VRF_DEFAULT_NAME
);
5106 vty_out(vty
, "%% Unable to find pim instance\n");
5111 pim_show_interface_traffic_single(v
->info
, vty
, if_name
, uj
);
5113 pim_show_interface_traffic(v
->info
, vty
, uj
);
5118 void clear_pim_interfaces(struct pim_instance
*pim
)
5120 struct interface
*ifp
;
5122 FOR_ALL_INTERFACES (pim
->vrf
, ifp
) {
5124 pim_neighbor_delete_all(ifp
, "interface cleared");