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 pim_interface
*pim_ifp
,
1659 struct pim_ifchannel
*ch
, json_object
*json
,
1660 time_t now
, struct ttable
*tt
)
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 tt
, "%s|%pPAs|%pPAs|%pPAs|%s|%s|%s|%s",
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
;
1809 struct ttable
*tt
= NULL
;
1812 now
= pim_time_monotonic_sec();
1815 /* Prepare table. */
1816 tt
= ttable_new(&ttable_styles
[TTSTYLE_BLANK
]);
1819 "Interface|Address|Source|Group|State|Uptime|Expire|Prune");
1820 tt
->style
.cell
.rpad
= 2;
1821 tt
->style
.corner
= '+';
1825 FOR_ALL_INTERFACES (pim
->vrf
, ifp
) {
1826 pim_ifp
= ifp
->info
;
1830 RB_FOREACH (ch
, pim_ifchannel_rb
, &pim_ifp
->ifchannel_rb
) {
1831 if (!pim_sgaddr_match(ch
->sg
, *sg
))
1834 pim_show_join_helper(pim_ifp
, ch
, json
, now
, tt
);
1835 } /* scan interface channels */
1837 /* Dump the generated table. */
1839 table
= ttable_dump(tt
, "\n");
1840 vty_out(vty
, "%s\n", table
);
1841 XFREE(MTYPE_TMP
, table
);
1846 static void pim_show_jp_agg_helper(struct interface
*ifp
,
1847 struct pim_neighbor
*neigh
,
1848 struct pim_upstream
*up
, int is_join
,
1851 ttable_add_row(tt
, "%s|%pPAs|%pPAs|%pPAs|%s", ifp
->name
,
1852 &neigh
->source_addr
, &up
->sg
.src
, &up
->sg
.grp
,
1853 is_join
? "J" : "P");
1856 int pim_show_jp_agg_list_cmd_helper(const char *vrf
, struct vty
*vty
)
1859 struct pim_instance
*pim
;
1861 v
= vrf_lookup_by_name(vrf
? vrf
: VRF_DEFAULT_NAME
);
1864 vty_out(vty
, "%% Vrf specified: %s does not exist\n", vrf
);
1870 vty_out(vty
, "%% Unable to find pim instance\n");
1874 pim_show_jp_agg_list(pim
, vty
);
1879 void pim_show_jp_agg_list(struct pim_instance
*pim
, struct vty
*vty
)
1881 struct interface
*ifp
;
1882 struct pim_interface
*pim_ifp
;
1883 struct listnode
*n_node
;
1884 struct pim_neighbor
*neigh
;
1885 struct listnode
*jag_node
;
1886 struct pim_jp_agg_group
*jag
;
1887 struct listnode
*js_node
;
1888 struct pim_jp_sources
*js
;
1892 /* Prepare table. */
1893 tt
= ttable_new(&ttable_styles
[TTSTYLE_BLANK
]);
1894 ttable_add_row(tt
, "Interface|RPF Nbr|Source|Group|State");
1895 tt
->style
.cell
.rpad
= 2;
1896 tt
->style
.corner
= '+';
1899 FOR_ALL_INTERFACES (pim
->vrf
, ifp
) {
1900 pim_ifp
= ifp
->info
;
1904 for (ALL_LIST_ELEMENTS_RO(pim_ifp
->pim_neighbor_list
, n_node
,
1906 for (ALL_LIST_ELEMENTS_RO(neigh
->upstream_jp_agg
,
1908 for (ALL_LIST_ELEMENTS_RO(jag
->sources
, js_node
,
1910 pim_show_jp_agg_helper(ifp
, neigh
,
1918 /* Dump the generated table. */
1919 table
= ttable_dump(tt
, "\n");
1920 vty_out(vty
, "%s\n", table
);
1921 XFREE(MTYPE_TMP
, table
);
1925 int pim_show_membership_cmd_helper(const char *vrf
, struct vty
*vty
, bool uj
)
1929 v
= vrf_lookup_by_name(vrf
? vrf
: VRF_DEFAULT_NAME
);
1934 pim_show_membership(v
->info
, vty
, uj
);
1939 static void pim_show_membership_helper(struct vty
*vty
,
1940 struct pim_interface
*pim_ifp
,
1941 struct pim_ifchannel
*ch
,
1942 struct json_object
*json
)
1944 json_object
*json_iface
= NULL
;
1945 json_object
*json_row
= NULL
;
1947 json_object_object_get_ex(json
, ch
->interface
->name
, &json_iface
);
1949 json_iface
= json_object_new_object();
1950 json_object_pim_ifp_add(json_iface
, ch
->interface
);
1951 json_object_object_add(json
, ch
->interface
->name
, json_iface
);
1954 json_row
= json_object_new_object();
1955 json_object_string_addf(json_row
, "source", "%pPAs", &ch
->sg
.src
);
1956 json_object_string_addf(json_row
, "group", "%pPAs", &ch
->sg
.grp
);
1957 json_object_string_add(json_row
, "localMembership",
1958 ch
->local_ifmembership
== PIM_IFMEMBERSHIP_NOINFO
1961 json_object_object_addf(json_iface
, json_row
, "%pPAs", &ch
->sg
.grp
);
1964 void pim_show_membership(struct pim_instance
*pim
, struct vty
*vty
, bool uj
)
1966 struct pim_interface
*pim_ifp
;
1967 struct pim_ifchannel
*ch
;
1968 struct interface
*ifp
;
1969 enum json_type type
;
1970 json_object
*json
= NULL
;
1971 json_object
*json_tmp
= NULL
;
1973 json
= json_object_new_object();
1975 FOR_ALL_INTERFACES (pim
->vrf
, ifp
) {
1976 pim_ifp
= ifp
->info
;
1980 RB_FOREACH (ch
, pim_ifchannel_rb
, &pim_ifp
->ifchannel_rb
) {
1981 pim_show_membership_helper(vty
, pim_ifp
, ch
, json
);
1982 } /* scan interface channels */
1986 vty_json(vty
, json
);
1989 "Interface Address Source Group Membership\n");
1992 * Example of the json data we are traversing
1998 * "address":"10.1.20.1",
2000 * "flagMulticast":true,
2001 * "flagBroadcast":true,
2002 * "lanDelayEnabled":true,
2005 * "group":"226.10.10.10",
2006 * "localMembership":"INCLUDE"
2012 /* foreach interface */
2013 json_object_object_foreach(json
, key
, val
)
2016 /* Find all of the keys where the val is an object. In
2018 * above the only one is 226.10.10.10
2020 json_object_object_foreach(val
, if_field_key
,
2023 type
= json_object_get_type(if_field_val
);
2025 if (type
== json_type_object
) {
2026 vty_out(vty
, "%-16s ", key
);
2028 json_object_object_get_ex(
2029 val
, "address", &json_tmp
);
2030 vty_out(vty
, "%-15s ",
2031 json_object_get_string(
2034 json_object_object_get_ex(if_field_val
,
2037 vty_out(vty
, "%-15s ",
2038 json_object_get_string(
2042 vty_out(vty
, "%-15s ", if_field_key
);
2044 json_object_object_get_ex(
2045 if_field_val
, "localMembership",
2047 vty_out(vty
, "%-10s\n",
2048 json_object_get_string(
2053 json_object_free(json
);
2057 static void pim_show_channel_helper(struct pim_instance
*pim
,
2058 struct pim_interface
*pim_ifp
,
2059 struct pim_ifchannel
*ch
, json_object
*json
,
2060 bool uj
, struct ttable
*tt
)
2062 struct pim_upstream
*up
= ch
->upstream
;
2063 json_object
*json_group
= NULL
;
2064 json_object
*json_row
= NULL
;
2067 char grp_str
[PIM_ADDRSTRLEN
];
2069 snprintfrr(grp_str
, sizeof(grp_str
), "%pPAs", &up
->sg
.grp
);
2070 json_object_object_get_ex(json
, grp_str
, &json_group
);
2073 json_group
= json_object_new_object();
2074 json_object_object_add(json
, grp_str
, json_group
);
2077 json_row
= json_object_new_object();
2078 json_object_pim_upstream_add(json_row
, up
);
2079 json_object_string_add(json_row
, "interface",
2080 ch
->interface
->name
);
2081 json_object_string_addf(json_row
, "source", "%pPAs",
2083 json_object_string_addf(json_row
, "group", "%pPAs",
2086 if (pim_macro_ch_lost_assert(ch
))
2087 json_object_boolean_true_add(json_row
, "lostAssert");
2089 if (pim_macro_chisin_joins(ch
))
2090 json_object_boolean_true_add(json_row
, "joins");
2092 if (pim_macro_chisin_pim_include(ch
))
2093 json_object_boolean_true_add(json_row
, "pimInclude");
2095 if (pim_upstream_evaluate_join_desired(pim
, up
))
2096 json_object_boolean_true_add(json_row
,
2097 "evaluateJoinDesired");
2099 json_object_object_addf(json_group
, json_row
, "%pPAs",
2103 ttable_add_row(tt
, "%s|%pPAs|%pPAs|%s|%s|%s|%s|%s",
2104 ch
->interface
->name
, &up
->sg
.src
, &up
->sg
.grp
,
2105 pim_macro_ch_lost_assert(ch
) ? "yes" : "no",
2106 pim_macro_chisin_joins(ch
) ? "yes" : "no",
2107 pim_macro_chisin_pim_include(ch
) ? "yes" : "no",
2108 PIM_UPSTREAM_FLAG_TEST_DR_JOIN_DESIRED(up
->flags
)
2111 pim_upstream_evaluate_join_desired(pim
, up
)
2117 void pim_show_channel(struct pim_instance
*pim
, struct vty
*vty
, bool uj
)
2119 struct pim_interface
*pim_ifp
;
2120 struct pim_ifchannel
*ch
;
2121 struct interface
*ifp
;
2122 struct ttable
*tt
= NULL
;
2123 json_object
*json
= NULL
;
2127 json
= json_object_new_object();
2129 /* Prepare table. */
2130 tt
= ttable_new(&ttable_styles
[TTSTYLE_BLANK
]);
2133 "Interface|Source|Group|LostAssert|Joins|PimInclude|JoinDesired|EvalJD");
2134 tt
->style
.cell
.rpad
= 2;
2135 tt
->style
.corner
= '+';
2139 /* scan per-interface (S,G) state */
2140 FOR_ALL_INTERFACES (pim
->vrf
, ifp
) {
2141 pim_ifp
= ifp
->info
;
2145 RB_FOREACH (ch
, pim_ifchannel_rb
, &pim_ifp
->ifchannel_rb
) {
2146 /* scan all interfaces */
2147 pim_show_channel_helper(pim
, pim_ifp
, ch
, json
, uj
, tt
);
2152 vty_json(vty
, json
);
2154 /* Dump the generated table. */
2155 table
= ttable_dump(tt
, "\n");
2156 vty_out(vty
, "%s\n", table
);
2157 XFREE(MTYPE_TMP
, table
);
2162 int pim_show_channel_cmd_helper(const char *vrf
, struct vty
*vty
, bool uj
)
2166 v
= vrf_lookup_by_name(vrf
? vrf
: VRF_DEFAULT_NAME
);
2171 pim_show_channel(v
->info
, vty
, uj
);
2176 int pim_show_interface_cmd_helper(const char *vrf
, struct vty
*vty
, bool uj
,
2177 bool mlag
, const char *interface
)
2180 json_object
*json_parent
= NULL
;
2182 v
= vrf_lookup_by_name(vrf
? vrf
: VRF_DEFAULT_NAME
);
2188 json_parent
= json_object_new_object();
2191 pim_show_interfaces_single(v
->info
, vty
, interface
, mlag
,
2194 pim_show_interfaces(v
->info
, vty
, mlag
, json_parent
);
2197 vty_json(vty
, json_parent
);
2202 int pim_show_interface_vrf_all_cmd_helper(struct vty
*vty
, bool uj
, bool mlag
,
2203 const char *interface
)
2206 json_object
*json_parent
= NULL
;
2207 json_object
*json_vrf
= NULL
;
2210 json_parent
= json_object_new_object();
2212 RB_FOREACH (v
, vrf_name_head
, &vrfs_by_name
) {
2214 vty_out(vty
, "VRF: %s\n", v
->name
);
2216 json_vrf
= json_object_new_object();
2219 pim_show_interfaces_single(v
->info
, vty
, interface
,
2222 pim_show_interfaces(v
->info
, vty
, mlag
, json_vrf
);
2225 json_object_object_add(json_parent
, v
->name
, json_vrf
);
2228 vty_json(vty
, json_parent
);
2233 void pim_show_interfaces(struct pim_instance
*pim
, struct vty
*vty
, bool mlag
,
2236 struct interface
*ifp
;
2237 struct pim_interface
*pim_ifp
;
2238 struct pim_upstream
*up
;
2241 int pim_ifchannels
= 0;
2243 struct ttable
*tt
= NULL
;
2245 json_object
*json_row
= NULL
;
2246 json_object
*json_tmp
;
2250 json
= json_object_new_object();
2253 FOR_ALL_INTERFACES (pim
->vrf
, ifp
) {
2254 pim_ifp
= ifp
->info
;
2259 if (mlag
== true && pim_ifp
->activeactive
== false)
2262 pim_nbrs
= pim_ifp
->pim_neighbor_list
->count
;
2263 pim_ifchannels
= pim_if_ifchannel_count(pim_ifp
);
2266 frr_each (rb_pim_upstream
, &pim
->upstream_head
, up
)
2267 if (ifp
== up
->rpf
.source_nexthop
.interface
)
2268 if (up
->flags
& PIM_UPSTREAM_FLAG_MASK_FHR
)
2271 json_row
= json_object_new_object();
2272 json_object_pim_ifp_add(json_row
, ifp
);
2273 json_object_int_add(json_row
, "pimNeighbors", pim_nbrs
);
2274 json_object_int_add(json_row
, "pimIfChannels", pim_ifchannels
);
2275 json_object_int_add(json_row
, "firstHopRouterCount", fhr
);
2276 json_object_string_addf(json_row
, "pimDesignatedRouter",
2277 "%pPAs", &pim_ifp
->pim_dr_addr
);
2279 if (!pim_addr_cmp(pim_ifp
->pim_dr_addr
,
2280 pim_ifp
->primary_address
))
2281 json_object_boolean_true_add(
2282 json_row
, "pimDesignatedRouterLocal");
2284 json_object_object_add(json
, ifp
->name
, json_row
);
2289 /* Prepare table. */
2290 tt
= ttable_new(&ttable_styles
[TTSTYLE_BLANK
]);
2293 "Interface|State|Address|PIM Nbrs|PIM DR|FHR|IfChannels");
2294 tt
->style
.cell
.rpad
= 2;
2295 tt
->style
.corner
= '+';
2298 json_object_object_foreach(json
, key
, val
)
2300 const char *state
, *address
, *pimdr
;
2301 int neighbors
, firsthpr
, pimifchnl
;
2303 json_object_object_get_ex(val
, "state", &json_tmp
);
2304 state
= json_object_get_string(json_tmp
);
2306 json_object_object_get_ex(val
, "address", &json_tmp
);
2307 address
= json_object_get_string(json_tmp
);
2309 json_object_object_get_ex(val
, "pimNeighbors",
2311 neighbors
= json_object_get_int(json_tmp
);
2313 if (json_object_object_get_ex(
2314 val
, "pimDesignatedRouterLocal",
2318 json_object_object_get_ex(
2319 val
, "pimDesignatedRouter", &json_tmp
);
2320 pimdr
= json_object_get_string(json_tmp
);
2323 json_object_object_get_ex(val
, "firstHopRouter",
2325 firsthpr
= json_object_get_int(json_tmp
);
2327 json_object_object_get_ex(val
, "pimIfChannels",
2329 pimifchnl
= json_object_get_int(json_tmp
);
2331 ttable_add_row(tt
, "%s|%s|%s|%d|%s|%d|%d", key
, state
,
2332 address
, neighbors
, pimdr
, firsthpr
,
2335 json_object_free(json
);
2337 /* Dump the generated table. */
2338 table
= ttable_dump(tt
, "\n");
2339 vty_out(vty
, "%s\n", table
);
2340 XFREE(MTYPE_TMP
, table
);
2346 void pim_show_interfaces_single(struct pim_instance
*pim
, struct vty
*vty
,
2347 const char *ifname
, bool mlag
,
2351 struct interface
*ifp
;
2352 struct listnode
*neighnode
;
2353 struct pim_interface
*pim_ifp
;
2354 struct pim_neighbor
*neigh
;
2355 struct pim_upstream
*up
;
2357 char dr_str
[PIM_ADDRSTRLEN
];
2360 char grp_str
[PIM_ADDRSTRLEN
];
2361 char hello_period
[10];
2362 char hello_timer
[10];
2363 char neigh_src_str
[PIM_ADDRSTRLEN
];
2364 char src_str
[PIM_ADDRSTRLEN
];
2365 char stat_uptime
[10];
2367 int found_ifname
= 0;
2369 json_object
*json_row
= NULL
;
2370 json_object
*json_pim_neighbor
= NULL
;
2371 json_object
*json_pim_neighbors
= NULL
;
2372 json_object
*json_group
= NULL
;
2373 json_object
*json_group_source
= NULL
;
2374 json_object
*json_fhr_sources
= NULL
;
2375 struct pim_secondary_addr
*sec_addr
;
2376 struct listnode
*sec_node
;
2378 now
= pim_time_monotonic_sec();
2380 FOR_ALL_INTERFACES (pim
->vrf
, ifp
) {
2381 pim_ifp
= ifp
->info
;
2386 if (mlag
== true && pim_ifp
->activeactive
== false)
2389 if (strcmp(ifname
, "detail") && strcmp(ifname
, ifp
->name
))
2393 ifaddr
= pim_ifp
->primary_address
;
2394 snprintfrr(dr_str
, sizeof(dr_str
), "%pPAs",
2395 &pim_ifp
->pim_dr_addr
);
2396 pim_time_uptime_begin(dr_uptime
, sizeof(dr_uptime
), now
,
2397 pim_ifp
->pim_dr_election_last
);
2398 pim_time_timer_to_hhmmss(hello_timer
, sizeof(hello_timer
),
2399 pim_ifp
->t_pim_hello_timer
);
2400 pim_time_mmss(hello_period
, sizeof(hello_period
),
2401 pim_ifp
->pim_hello_period
);
2402 pim_time_uptime(stat_uptime
, sizeof(stat_uptime
),
2403 now
- pim_ifp
->pim_ifstat_start
);
2406 json_row
= json_object_new_object();
2407 json_object_pim_ifp_add(json_row
, ifp
);
2409 if (!pim_addr_is_any(pim_ifp
->update_source
)) {
2410 json_object_string_addf(
2411 json_row
, "useSource", "%pPAs",
2412 &pim_ifp
->update_source
);
2414 if (pim_ifp
->sec_addr_list
) {
2415 json_object
*sec_list
= NULL
;
2417 sec_list
= json_object_new_array();
2418 for (ALL_LIST_ELEMENTS_RO(
2419 pim_ifp
->sec_addr_list
, sec_node
,
2421 json_object_array_add(
2423 json_object_new_stringf(
2427 json_object_object_add(json_row
,
2428 "secondaryAddressList",
2432 if (pim_ifp
->pim_passive_enable
)
2433 json_object_boolean_true_add(json_row
,
2437 if (pim_ifp
->pim_neighbor_list
->count
) {
2438 json_pim_neighbors
= json_object_new_object();
2440 for (ALL_LIST_ELEMENTS_RO(
2441 pim_ifp
->pim_neighbor_list
,
2442 neighnode
, neigh
)) {
2444 json_object_new_object();
2445 snprintfrr(neigh_src_str
,
2446 sizeof(neigh_src_str
),
2448 &neigh
->source_addr
);
2449 pim_time_uptime(uptime
, sizeof(uptime
),
2450 now
- neigh
->creation
);
2451 pim_time_timer_to_hhmmss(
2452 expire
, sizeof(expire
),
2453 neigh
->t_expire_timer
);
2455 json_object_string_add(
2456 json_pim_neighbor
, "address",
2458 json_object_string_add(
2459 json_pim_neighbor
, "upTime",
2461 json_object_string_add(
2462 json_pim_neighbor
, "holdtime",
2465 json_object_object_add(
2471 json_object_object_add(json_row
, "neighbors",
2472 json_pim_neighbors
);
2475 json_object_string_add(json_row
, "drAddress", dr_str
);
2476 json_object_int_add(json_row
, "drPriority",
2477 pim_ifp
->pim_dr_priority
);
2478 json_object_string_add(json_row
, "drUptime", dr_uptime
);
2479 json_object_int_add(json_row
, "drElections",
2480 pim_ifp
->pim_dr_election_count
);
2481 json_object_int_add(json_row
, "drChanges",
2482 pim_ifp
->pim_dr_election_changes
);
2485 frr_each (rb_pim_upstream
, &pim
->upstream_head
, up
) {
2486 if (ifp
!= up
->rpf
.source_nexthop
.interface
)
2489 if (!(up
->flags
& PIM_UPSTREAM_FLAG_MASK_FHR
))
2492 if (!json_fhr_sources
)
2494 json_object_new_object();
2496 snprintfrr(grp_str
, sizeof(grp_str
), "%pPAs",
2498 snprintfrr(src_str
, sizeof(src_str
), "%pPAs",
2500 pim_time_uptime(uptime
, sizeof(uptime
),
2501 now
- up
->state_transition
);
2504 * Does this group live in json_fhr_sources?
2507 json_object_object_get_ex(json_fhr_sources
,
2508 grp_str
, &json_group
);
2511 json_group
= json_object_new_object();
2512 json_object_object_add(json_fhr_sources
,
2517 json_group_source
= json_object_new_object();
2518 json_object_string_add(json_group_source
,
2520 json_object_string_add(json_group_source
,
2522 json_object_string_add(json_group_source
,
2524 json_object_object_add(json_group
, src_str
,
2528 if (json_fhr_sources
) {
2529 json_object_object_add(json_row
,
2534 json_object_int_add(json_row
, "helloPeriod",
2535 pim_ifp
->pim_hello_period
);
2536 json_object_int_add(json_row
, "holdTime",
2537 PIM_IF_DEFAULT_HOLDTIME(pim_ifp
));
2538 json_object_string_add(json_row
, "helloTimer",
2540 json_object_string_add(json_row
, "helloStatStart",
2542 json_object_int_add(json_row
, "helloReceived",
2543 pim_ifp
->pim_ifstat_hello_recv
);
2544 json_object_int_add(json_row
, "helloReceivedFailed",
2545 pim_ifp
->pim_ifstat_hello_recvfail
);
2546 json_object_int_add(json_row
, "helloSend",
2547 pim_ifp
->pim_ifstat_hello_sent
);
2548 json_object_int_add(json_row
, "hellosendFailed",
2549 pim_ifp
->pim_ifstat_hello_sendfail
);
2550 json_object_int_add(json_row
, "helloGenerationId",
2551 pim_ifp
->pim_generation_id
);
2553 json_object_int_add(
2554 json_row
, "effectivePropagationDelay",
2555 pim_if_effective_propagation_delay_msec(ifp
));
2556 json_object_int_add(
2557 json_row
, "effectiveOverrideInterval",
2558 pim_if_effective_override_interval_msec(ifp
));
2559 json_object_int_add(
2560 json_row
, "joinPruneOverrideInterval",
2561 pim_if_jp_override_interval_msec(ifp
));
2563 json_object_int_add(
2564 json_row
, "propagationDelay",
2565 pim_ifp
->pim_propagation_delay_msec
);
2566 json_object_int_add(
2567 json_row
, "propagationDelayHighest",
2568 pim_ifp
->pim_neighbors_highest_propagation_delay_msec
);
2569 json_object_int_add(
2570 json_row
, "overrideInterval",
2571 pim_ifp
->pim_override_interval_msec
);
2572 json_object_int_add(
2573 json_row
, "overrideIntervalHighest",
2574 pim_ifp
->pim_neighbors_highest_override_interval_msec
);
2575 if (pim_ifp
->bsm_enable
)
2576 json_object_boolean_true_add(json_row
,
2578 if (pim_ifp
->ucast_bsm_accept
)
2579 json_object_boolean_true_add(json_row
,
2581 json_object_object_add(json
, ifp
->name
, json_row
);
2584 vty_out(vty
, "Interface : %s\n", ifp
->name
);
2585 vty_out(vty
, "State : %s\n",
2586 if_is_up(ifp
) ? "up" : "down");
2587 if (!pim_addr_is_any(pim_ifp
->update_source
)) {
2588 vty_out(vty
, "Use Source : %pPAs\n",
2589 &pim_ifp
->update_source
);
2591 if (pim_ifp
->sec_addr_list
) {
2592 vty_out(vty
, "Address : %pPAs (primary)\n",
2594 for (ALL_LIST_ELEMENTS_RO(
2595 pim_ifp
->sec_addr_list
, sec_node
,
2597 vty_out(vty
, " %pFX\n",
2600 vty_out(vty
, "Address : %pPAs\n", &ifaddr
);
2603 if (pim_ifp
->pim_passive_enable
)
2604 vty_out(vty
, "Passive : %s\n",
2605 (pim_ifp
->pim_passive_enable
) ? "yes"
2613 for (ALL_LIST_ELEMENTS_RO(pim_ifp
->pim_neighbor_list
,
2614 neighnode
, neigh
)) {
2617 vty_out(vty
, "PIM Neighbors\n");
2618 vty_out(vty
, "-------------\n");
2622 snprintfrr(neigh_src_str
, sizeof(neigh_src_str
),
2623 "%pPAs", &neigh
->source_addr
);
2624 pim_time_uptime(uptime
, sizeof(uptime
),
2625 now
- neigh
->creation
);
2626 pim_time_timer_to_hhmmss(expire
, sizeof(expire
),
2627 neigh
->t_expire_timer
);
2629 "%-15s : up for %s, holdtime expires in %s\n",
2630 neigh_src_str
, uptime
, expire
);
2633 if (!print_header
) {
2638 vty_out(vty
, "Designated Router\n");
2639 vty_out(vty
, "-----------------\n");
2640 vty_out(vty
, "Address : %s\n", dr_str
);
2641 vty_out(vty
, "Priority : %u(%d)\n",
2642 pim_ifp
->pim_dr_priority
,
2643 pim_ifp
->pim_dr_num_nondrpri_neighbors
);
2644 vty_out(vty
, "Uptime : %s\n", dr_uptime
);
2645 vty_out(vty
, "Elections : %d\n",
2646 pim_ifp
->pim_dr_election_count
);
2647 vty_out(vty
, "Changes : %d\n",
2648 pim_ifp
->pim_dr_election_changes
);
2654 frr_each (rb_pim_upstream
, &pim
->upstream_head
, up
) {
2655 if (!up
->rpf
.source_nexthop
.interface
)
2658 if (strcmp(ifp
->name
,
2659 up
->rpf
.source_nexthop
2660 .interface
->name
) != 0)
2663 if (!(up
->flags
& PIM_UPSTREAM_FLAG_MASK_FHR
))
2668 "FHR - First Hop Router\n");
2670 "----------------------\n");
2674 pim_time_uptime(uptime
, sizeof(uptime
),
2675 now
- up
->state_transition
);
2677 "%pPAs : %pPAs is a source, uptime is %s\n",
2678 &up
->sg
.grp
, &up
->sg
.src
, uptime
);
2681 if (!print_header
) {
2686 vty_out(vty
, "Hellos\n");
2687 vty_out(vty
, "------\n");
2688 vty_out(vty
, "Period : %d\n",
2689 pim_ifp
->pim_hello_period
);
2690 vty_out(vty
, "HoldTime : %d\n",
2691 PIM_IF_DEFAULT_HOLDTIME(pim_ifp
));
2692 vty_out(vty
, "Timer : %s\n", hello_timer
);
2693 vty_out(vty
, "StatStart : %s\n", stat_uptime
);
2694 vty_out(vty
, "Receive : %d\n",
2695 pim_ifp
->pim_ifstat_hello_recv
);
2696 vty_out(vty
, "Receive Failed : %d\n",
2697 pim_ifp
->pim_ifstat_hello_recvfail
);
2698 vty_out(vty
, "Send : %d\n",
2699 pim_ifp
->pim_ifstat_hello_sent
);
2700 vty_out(vty
, "Send Failed : %d\n",
2701 pim_ifp
->pim_ifstat_hello_sendfail
);
2702 vty_out(vty
, "Generation ID : %08x\n",
2703 pim_ifp
->pim_generation_id
);
2707 pim_print_ifp_flags(vty
, ifp
);
2709 vty_out(vty
, "Join Prune Interval\n");
2710 vty_out(vty
, "-------------------\n");
2711 vty_out(vty
, "LAN Delay : %s\n",
2712 pim_if_lan_delay_enabled(ifp
) ? "yes" : "no");
2713 vty_out(vty
, "Effective Propagation Delay : %d msec\n",
2714 pim_if_effective_propagation_delay_msec(ifp
));
2715 vty_out(vty
, "Effective Override Interval : %d msec\n",
2716 pim_if_effective_override_interval_msec(ifp
));
2717 vty_out(vty
, "Join Prune Override Interval : %d msec\n",
2718 pim_if_jp_override_interval_msec(ifp
));
2722 vty_out(vty
, "LAN Prune Delay\n");
2723 vty_out(vty
, "---------------\n");
2724 vty_out(vty
, "Propagation Delay : %d msec\n",
2725 pim_ifp
->pim_propagation_delay_msec
);
2726 vty_out(vty
, "Propagation Delay (Highest) : %d msec\n",
2727 pim_ifp
->pim_neighbors_highest_propagation_delay_msec
);
2728 vty_out(vty
, "Override Interval : %d msec\n",
2729 pim_ifp
->pim_override_interval_msec
);
2730 vty_out(vty
, "Override Interval (Highest) : %d msec\n",
2731 pim_ifp
->pim_neighbors_highest_override_interval_msec
);
2735 vty_out(vty
, "BSM Status\n");
2736 vty_out(vty
, "----------\n");
2737 vty_out(vty
, "Bsm Enabled : %s\n",
2738 pim_ifp
->bsm_enable
? "yes" : "no");
2739 vty_out(vty
, "Unicast Bsm Enabled : %s\n",
2740 pim_ifp
->ucast_bsm_accept
? "yes" : "no");
2747 vty_out(vty
, "%% No such interface\n");
2750 void ip_pim_ssm_show_group_range(struct pim_instance
*pim
, struct vty
*vty
,
2753 struct pim_ssm
*ssm
= pim
->ssm_info
;
2754 const char *range_str
=
2755 ssm
->plist_name
? ssm
->plist_name
: PIM_SSM_STANDARD_RANGE
;
2760 json
= json_object_new_object();
2761 json_object_string_add(json
, "ssmGroups", range_str
);
2762 vty_json(vty
, json
);
2764 vty_out(vty
, "SSM group range : %s\n", range_str
);
2767 struct vty_pnc_cache_walk_data
{
2769 struct pim_instance
*pim
;
2772 struct json_pnc_cache_walk_data
{
2773 json_object
*json_obj
;
2774 struct pim_instance
*pim
;
2777 static int pim_print_vty_pnc_cache_walkcb(struct hash_bucket
*bucket
, void *arg
)
2779 struct pim_nexthop_cache
*pnc
= bucket
->data
;
2780 struct vty_pnc_cache_walk_data
*cwd
= arg
;
2781 struct vty
*vty
= cwd
->vty
;
2782 struct pim_instance
*pim
= cwd
->pim
;
2783 struct nexthop
*nh_node
= NULL
;
2784 ifindex_t first_ifindex
;
2785 struct interface
*ifp
= NULL
;
2787 for (nh_node
= pnc
->nexthop
; nh_node
; nh_node
= nh_node
->next
) {
2788 first_ifindex
= nh_node
->ifindex
;
2790 ifp
= if_lookup_by_index(first_ifindex
, pim
->vrf
->vrf_id
);
2792 vty_out(vty
, "%-15pPA ", &pnc
->rpf
.rpf_addr
);
2793 vty_out(vty
, "%-16s ", ifp
? ifp
->name
: "NULL");
2795 vty_out(vty
, "%pI4 ", &nh_node
->gate
.ipv4
);
2797 vty_out(vty
, "%pI6 ", &nh_node
->gate
.ipv6
);
2804 static int pim_print_json_pnc_cache_walkcb(struct hash_bucket
*backet
,
2807 struct pim_nexthop_cache
*pnc
= backet
->data
;
2808 struct json_pnc_cache_walk_data
*cwd
= arg
;
2809 struct pim_instance
*pim
= cwd
->pim
;
2810 struct nexthop
*nh_node
= NULL
;
2811 ifindex_t first_ifindex
;
2812 struct interface
*ifp
= NULL
;
2813 char addr_str
[PIM_ADDRSTRLEN
];
2814 json_object
*json_row
= NULL
;
2815 json_object
*json_ifp
= NULL
;
2816 json_object
*json_arr
= NULL
;
2818 for (nh_node
= pnc
->nexthop
; nh_node
; nh_node
= nh_node
->next
) {
2819 first_ifindex
= nh_node
->ifindex
;
2820 ifp
= if_lookup_by_index(first_ifindex
, pim
->vrf
->vrf_id
);
2821 snprintfrr(addr_str
, sizeof(addr_str
), "%pPA",
2822 &pnc
->rpf
.rpf_addr
);
2823 json_object_object_get_ex(cwd
->json_obj
, addr_str
, &json_row
);
2825 json_row
= json_object_new_object();
2826 json_object_string_addf(json_row
, "address", "%pPA",
2827 &pnc
->rpf
.rpf_addr
);
2828 json_object_object_addf(cwd
->json_obj
, json_row
, "%pPA",
2829 &pnc
->rpf
.rpf_addr
);
2830 json_arr
= json_object_new_array();
2831 json_object_object_add(json_row
, "nexthops", json_arr
);
2833 json_ifp
= json_object_new_object();
2834 json_object_string_add(json_ifp
, "interface",
2835 ifp
? ifp
->name
: "NULL");
2837 json_object_string_addf(json_ifp
, "nexthop", "%pI4",
2838 &nh_node
->gate
.ipv4
);
2840 json_object_string_addf(json_ifp
, "nexthop", "%pI6",
2841 &nh_node
->gate
.ipv6
);
2843 json_object_array_add(json_arr
, json_ifp
);
2848 int pim_show_nexthop_lookup_cmd_helper(const char *vrf
, struct vty
*vty
,
2849 pim_addr source
, pim_addr group
)
2852 pim_addr vif_source
;
2854 struct pim_nexthop nexthop
;
2856 char grp_str
[PREFIX_STRLEN
];
2858 v
= vrf_lookup_by_name(vrf
? vrf
: VRF_DEFAULT_NAME
);
2864 if (pim_is_group_224_4(source
)) {
2866 "Invalid argument. Expected Valid Source Address.\n");
2870 if (!pim_is_group_224_4(group
)) {
2872 "Invalid argument. Expected Valid Multicast Group Address.\n");
2877 if (!pim_rp_set_upstream_addr(v
->info
, &vif_source
, source
, group
))
2880 pim_addr_to_prefix(&grp
, group
);
2881 memset(&nexthop
, 0, sizeof(nexthop
));
2884 pim_ecmp_nexthop_lookup(v
->info
, &nexthop
, vif_source
, &grp
, 0);
2888 "Nexthop Lookup failed, no usable routes returned.\n");
2892 pim_addr_dump("<grp?>", &grp
, grp_str
, sizeof(grp_str
));
2894 vty_out(vty
, "Group %s --- Nexthop %pPAs Interface %s\n", grp_str
,
2895 &nexthop
.mrib_nexthop_addr
, nexthop
.interface
->name
);
2900 int pim_show_nexthop_cmd_helper(const char *vrf
, struct vty
*vty
, bool uj
)
2904 v
= vrf_lookup_by_name(vrf
? vrf
: VRF_DEFAULT_NAME
);
2909 pim_show_nexthop(v
->info
, vty
, uj
);
2914 void pim_show_nexthop(struct pim_instance
*pim
, struct vty
*vty
, bool uj
)
2916 struct vty_pnc_cache_walk_data cwd
;
2917 struct json_pnc_cache_walk_data jcwd
;
2924 jcwd
.json_obj
= json_object_new_object();
2926 vty_out(vty
, "Number of registered addresses: %lu\n",
2927 pim
->rpf_hash
->count
);
2928 vty_out(vty
, "Address Interface Nexthop\n");
2929 vty_out(vty
, "---------------------------------------------\n");
2933 hash_walk(pim
->rpf_hash
, pim_print_json_pnc_cache_walkcb
,
2935 vty_json(vty
, jcwd
.json_obj
);
2937 hash_walk(pim
->rpf_hash
, pim_print_vty_pnc_cache_walkcb
, &cwd
);
2940 int pim_show_neighbors_cmd_helper(const char *vrf
, struct vty
*vty
,
2941 const char *json
, const char *interface
)
2944 json_object
*json_parent
= NULL
;
2946 v
= vrf_lookup_by_name(vrf
? vrf
: VRF_DEFAULT_NAME
);
2952 json_parent
= json_object_new_object();
2955 pim_show_neighbors_single(v
->info
, vty
, interface
, json_parent
);
2957 pim_show_neighbors(v
->info
, vty
, json_parent
);
2960 vty_json(vty
, json_parent
);
2965 int pim_show_neighbors_vrf_all_cmd_helper(struct vty
*vty
, const char *json
,
2966 const char *interface
)
2969 json_object
*json_parent
= NULL
;
2970 json_object
*json_vrf
= NULL
;
2973 json_parent
= json_object_new_object();
2974 RB_FOREACH (v
, vrf_name_head
, &vrfs_by_name
) {
2976 vty_out(vty
, "VRF: %s\n", v
->name
);
2978 json_vrf
= json_object_new_object();
2981 pim_show_neighbors_single(v
->info
, vty
, interface
,
2984 pim_show_neighbors(v
->info
, vty
, json_vrf
);
2987 json_object_object_add(json_parent
, v
->name
, json_vrf
);
2990 vty_json(vty
, json_parent
);
2995 void pim_show_neighbors_single(struct pim_instance
*pim
, struct vty
*vty
,
2996 const char *neighbor
, json_object
*json
)
2998 struct listnode
*neighnode
;
2999 struct interface
*ifp
;
3000 struct pim_interface
*pim_ifp
;
3001 struct pim_neighbor
*neigh
;
3003 int found_neighbor
= 0;
3004 int option_address_list
;
3005 int option_dr_priority
;
3006 int option_generation_id
;
3007 int option_holdtime
;
3008 int option_lan_prune_delay
;
3012 char neigh_src_str
[PIM_ADDRSTRLEN
];
3014 json_object
*json_ifp
= NULL
;
3015 json_object
*json_row
= NULL
;
3017 now
= pim_time_monotonic_sec();
3019 FOR_ALL_INTERFACES (pim
->vrf
, ifp
) {
3020 pim_ifp
= ifp
->info
;
3025 if (pim_ifp
->pim_sock_fd
< 0)
3028 for (ALL_LIST_ELEMENTS_RO(pim_ifp
->pim_neighbor_list
, neighnode
,
3030 snprintfrr(neigh_src_str
, sizeof(neigh_src_str
),
3031 "%pPAs", &neigh
->source_addr
);
3034 * The user can specify either the interface name or the
3036 * If this pim_ifp matches neither then skip.
3038 if (strcmp(neighbor
, "detail") &&
3039 strcmp(neighbor
, ifp
->name
) &&
3040 strcmp(neighbor
, neigh_src_str
))
3044 pim_time_uptime(uptime
, sizeof(uptime
),
3045 now
- neigh
->creation
);
3046 pim_time_timer_to_hhmmss(expire
, sizeof(expire
),
3047 neigh
->t_expire_timer
);
3049 option_address_list
= 0;
3050 option_dr_priority
= 0;
3051 option_generation_id
= 0;
3052 option_holdtime
= 0;
3053 option_lan_prune_delay
= 0;
3056 if (PIM_OPTION_IS_SET(neigh
->hello_options
,
3057 PIM_OPTION_MASK_ADDRESS_LIST
))
3058 option_address_list
= 1;
3060 if (PIM_OPTION_IS_SET(neigh
->hello_options
,
3061 PIM_OPTION_MASK_DR_PRIORITY
))
3062 option_dr_priority
= 1;
3064 if (PIM_OPTION_IS_SET(neigh
->hello_options
,
3065 PIM_OPTION_MASK_GENERATION_ID
))
3066 option_generation_id
= 1;
3068 if (PIM_OPTION_IS_SET(neigh
->hello_options
,
3069 PIM_OPTION_MASK_HOLDTIME
))
3070 option_holdtime
= 1;
3072 if (PIM_OPTION_IS_SET(neigh
->hello_options
,
3073 PIM_OPTION_MASK_LAN_PRUNE_DELAY
))
3074 option_lan_prune_delay
= 1;
3076 if (PIM_OPTION_IS_SET(
3077 neigh
->hello_options
,
3078 PIM_OPTION_MASK_CAN_DISABLE_JOIN_SUPPRESSION
))
3083 /* Does this ifp live in json? If not create it
3085 json_object_object_get_ex(json
, ifp
->name
,
3089 json_ifp
= json_object_new_object();
3090 json_object_pim_ifp_add(json_ifp
, ifp
);
3091 json_object_object_add(json
, ifp
->name
,
3095 json_row
= json_object_new_object();
3096 json_object_string_add(json_row
, "interface",
3098 json_object_string_add(json_row
, "address",
3100 json_object_string_add(json_row
, "upTime",
3102 json_object_string_add(json_row
, "holdtime",
3104 json_object_int_add(json_row
, "drPriority",
3105 neigh
->dr_priority
);
3106 json_object_int_add(json_row
, "generationId",
3107 neigh
->generation_id
);
3109 if (option_address_list
)
3110 json_object_boolean_true_add(
3112 "helloOptionAddressList");
3114 if (option_dr_priority
)
3115 json_object_boolean_true_add(
3117 "helloOptionDrPriority");
3119 if (option_generation_id
)
3120 json_object_boolean_true_add(
3122 "helloOptionGenerationId");
3124 if (option_holdtime
)
3125 json_object_boolean_true_add(
3127 "helloOptionHoldtime");
3129 if (option_lan_prune_delay
)
3130 json_object_boolean_true_add(
3132 "helloOptionLanPruneDelay");
3135 json_object_boolean_true_add(
3136 json_row
, "helloOptionTBit");
3138 json_object_object_add(json_ifp
, neigh_src_str
,
3142 vty_out(vty
, "Interface : %s\n", ifp
->name
);
3143 vty_out(vty
, "Neighbor : %s\n", neigh_src_str
);
3151 " DR Priority : %d\n",
3152 neigh
->dr_priority
);
3154 " Generation ID : %08x\n",
3155 neigh
->generation_id
);
3157 " Override Interval (msec) : %d\n",
3158 neigh
->override_interval_msec
);
3160 " Propagation Delay (msec) : %d\n",
3161 neigh
->propagation_delay_msec
);
3163 " Hello Option - Address List : %s\n",
3164 option_address_list
? "yes" : "no");
3166 " Hello Option - DR Priority : %s\n",
3167 option_dr_priority
? "yes" : "no");
3169 " Hello Option - Generation ID : %s\n",
3170 option_generation_id
? "yes" : "no");
3172 " Hello Option - Holdtime : %s\n",
3173 option_holdtime
? "yes" : "no");
3175 " Hello Option - LAN Prune Delay : %s\n",
3176 option_lan_prune_delay
? "yes" : "no");
3178 " Hello Option - T-bit : %s\n",
3179 option_t_bit
? "yes" : "no");
3180 bfd_sess_show(vty
, json_ifp
,
3181 neigh
->bfd_session
);
3187 if (!found_neighbor
)
3188 vty_out(vty
, "%% No such interface or neighbor\n");
3191 void pim_show_neighbors(struct pim_instance
*pim
, struct vty
*vty
,
3194 struct listnode
*neighnode
;
3195 struct interface
*ifp
;
3196 struct pim_interface
*pim_ifp
;
3197 struct pim_neighbor
*neigh
;
3198 struct ttable
*tt
= NULL
;
3203 char neigh_src_str
[PIM_ADDRSTRLEN
];
3204 json_object
*json_ifp_rows
= NULL
;
3205 json_object
*json_row
= NULL
;
3207 now
= pim_time_monotonic_sec();
3210 /* Prepare table. */
3211 tt
= ttable_new(&ttable_styles
[TTSTYLE_BLANK
]);
3212 ttable_add_row(tt
, "Interface|Neighbor|Uptime|Holdtime|DR Pri");
3213 tt
->style
.cell
.rpad
= 2;
3214 tt
->style
.corner
= '+';
3218 FOR_ALL_INTERFACES (pim
->vrf
, ifp
) {
3219 pim_ifp
= ifp
->info
;
3224 if (pim_ifp
->pim_sock_fd
< 0)
3228 json_ifp_rows
= json_object_new_object();
3230 for (ALL_LIST_ELEMENTS_RO(pim_ifp
->pim_neighbor_list
, neighnode
,
3232 snprintfrr(neigh_src_str
, sizeof(neigh_src_str
),
3233 "%pPAs", &neigh
->source_addr
);
3234 pim_time_uptime(uptime
, sizeof(uptime
),
3235 now
- neigh
->creation
);
3236 pim_time_timer_to_hhmmss(expire
, sizeof(expire
),
3237 neigh
->t_expire_timer
);
3240 json_row
= json_object_new_object();
3241 json_object_string_add(json_row
, "interface",
3243 json_object_string_add(json_row
, "neighbor",
3245 json_object_string_add(json_row
, "upTime",
3247 json_object_string_add(json_row
, "holdTime",
3249 json_object_int_add(json_row
, "holdTimeMax",
3251 json_object_int_add(json_row
, "drPriority",
3252 neigh
->dr_priority
);
3253 json_object_object_add(json_ifp_rows
,
3254 neigh_src_str
, json_row
);
3257 ttable_add_row(tt
, "%s|%pPAs|%s|%s|%d",
3258 ifp
->name
, &neigh
->source_addr
,
3260 neigh
->dr_priority
);
3265 json_object_object_add(json
, ifp
->name
, json_ifp_rows
);
3266 json_ifp_rows
= NULL
;
3269 /* Dump the generated table. */
3271 table
= ttable_dump(tt
, "\n");
3272 vty_out(vty
, "%s\n", table
);
3273 XFREE(MTYPE_TMP
, table
);
3278 int gm_process_query_max_response_time_cmd(struct vty
*vty
,
3279 const char *qmrt_str
)
3281 const struct lyd_node
*pim_enable_dnode
;
3283 pim_enable_dnode
= yang_dnode_getf(vty
->candidate_config
->dnode
,
3284 FRR_PIM_ENABLE_XPATH
, VTY_CURR_XPATH
,
3285 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
, "./query-max-response-time", 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_query_max_response_time_cmd(struct vty
*vty
)
3303 nb_cli_enqueue_change(vty
, "./query-max-response-time", 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_count_cmd(struct vty
*vty
,
3310 const char *lmqc_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
, "./robustness-variable", 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_count_cmd(struct vty
*vty
)
3333 nb_cli_enqueue_change(vty
, "./robustness-variable", NB_OP_DESTROY
,
3335 return nb_cli_apply_changes(vty
, FRR_GMP_INTERFACE_XPATH
,
3336 FRR_PIM_AF_XPATH_VAL
);
3339 int gm_process_last_member_query_interval_cmd(struct vty
*vty
,
3340 const char *lmqi_str
)
3342 const struct lyd_node
*pim_enable_dnode
;
3344 pim_enable_dnode
= yang_dnode_getf(vty
->candidate_config
->dnode
,
3345 FRR_PIM_ENABLE_XPATH
, VTY_CURR_XPATH
,
3346 FRR_PIM_AF_XPATH_VAL
);
3347 if (!pim_enable_dnode
) {
3348 nb_cli_enqueue_change(vty
, "./enable", NB_OP_MODIFY
, "true");
3350 if (!yang_dnode_get_bool(pim_enable_dnode
, "."))
3351 nb_cli_enqueue_change(vty
, "./enable", NB_OP_MODIFY
,
3355 nb_cli_enqueue_change(vty
, "./last-member-query-interval", NB_OP_MODIFY
,
3357 return nb_cli_apply_changes(vty
, FRR_GMP_INTERFACE_XPATH
,
3358 FRR_PIM_AF_XPATH_VAL
);
3361 int gm_process_no_last_member_query_interval_cmd(struct vty
*vty
)
3363 nb_cli_enqueue_change(vty
, "./last-member-query-interval",
3364 NB_OP_DESTROY
, NULL
);
3365 return nb_cli_apply_changes(vty
, FRR_GMP_INTERFACE_XPATH
,
3366 FRR_PIM_AF_XPATH_VAL
);
3369 int pim_process_ssmpingd_cmd(struct vty
*vty
, enum nb_operation operation
,
3370 const char *src_str
)
3372 const char *vrfname
;
3373 char ssmpingd_ip_xpath
[XPATH_MAXLEN
];
3375 vrfname
= pim_cli_get_vrf_name(vty
);
3376 if (vrfname
== NULL
)
3377 return CMD_WARNING_CONFIG_FAILED
;
3379 snprintf(ssmpingd_ip_xpath
, sizeof(ssmpingd_ip_xpath
),
3380 FRR_PIM_VRF_XPATH
, "frr-pim:pimd", "pim", vrfname
,
3381 FRR_PIM_AF_XPATH_VAL
);
3382 strlcat(ssmpingd_ip_xpath
, "/ssm-pingd-source-ip",
3383 sizeof(ssmpingd_ip_xpath
));
3385 nb_cli_enqueue_change(vty
, ssmpingd_ip_xpath
, operation
, src_str
);
3387 return nb_cli_apply_changes(vty
, NULL
);
3390 static void show_scan_oil_stats(struct pim_instance
*pim
, struct vty
*vty
,
3393 char uptime_scan_oil
[10];
3394 char uptime_mroute_add
[10];
3395 char uptime_mroute_del
[10];
3397 pim_time_uptime_begin(uptime_scan_oil
, sizeof(uptime_scan_oil
), now
,
3398 pim
->scan_oil_last
);
3399 pim_time_uptime_begin(uptime_mroute_add
, sizeof(uptime_mroute_add
), now
,
3400 pim
->mroute_add_last
);
3401 pim_time_uptime_begin(uptime_mroute_del
, sizeof(uptime_mroute_del
), now
,
3402 pim
->mroute_del_last
);
3405 "Scan OIL - Last: %s Events: %lld\n"
3406 "MFC Add - Last: %s Events: %lld\n"
3407 "MFC Del - Last: %s Events: %lld\n",
3408 uptime_scan_oil
, (long long)pim
->scan_oil_events
,
3409 uptime_mroute_add
, (long long)pim
->mroute_add_events
,
3410 uptime_mroute_del
, (long long)pim
->mroute_del_events
);
3413 void show_multicast_interfaces(struct pim_instance
*pim
, struct vty
*vty
,
3416 struct interface
*ifp
;
3417 struct ttable
*tt
= NULL
;
3419 json_object
*json_row
= NULL
;
3424 /* Prepare table. */
3425 tt
= ttable_new(&ttable_styles
[TTSTYLE_BLANK
]);
3428 "Interface|Address|ifi|Vif|PktsIn|PktsOut|BytesIn|BytesOut");
3429 tt
->style
.cell
.rpad
= 2;
3430 tt
->style
.corner
= '+';
3434 FOR_ALL_INTERFACES (pim
->vrf
, ifp
) {
3435 struct pim_interface
*pim_ifp
;
3437 struct sioc_vif_req vreq
;
3439 struct sioc_mif_req6 vreq
;
3442 pim_ifp
= ifp
->info
;
3447 memset(&vreq
, 0, sizeof(vreq
));
3449 vreq
.vifi
= pim_ifp
->mroute_vif_index
;
3450 if (ioctl(pim
->mroute_socket
, SIOCGETVIFCNT
, &vreq
)) {
3452 "ioctl(SIOCGETVIFCNT=%lu) failure for interface %s vif_index=%d: errno=%d: %s",
3453 (unsigned long)SIOCGETVIFCNT
, ifp
->name
,
3454 pim_ifp
->mroute_vif_index
, errno
,
3455 safe_strerror(errno
));
3458 vreq
.mifi
= pim_ifp
->mroute_vif_index
;
3459 if (ioctl(pim
->mroute_socket
, SIOCGETMIFCNT_IN6
, &vreq
)) {
3461 "ioctl(SIOCGETMIFCNT_IN6=%lu) failure for interface %s vif_index=%d: errno=%d: %s",
3462 (unsigned long)SIOCGETMIFCNT_IN6
, ifp
->name
,
3463 pim_ifp
->mroute_vif_index
, errno
,
3464 safe_strerror(errno
));
3469 json_row
= json_object_new_object();
3470 json_object_string_add(json_row
, "name", ifp
->name
);
3471 json_object_string_add(json_row
, "state",
3472 if_is_up(ifp
) ? "up" : "down");
3473 json_object_string_addf(json_row
, "address", "%pPA",
3474 &pim_ifp
->primary_address
);
3475 json_object_int_add(json_row
, "ifIndex", ifp
->ifindex
);
3476 json_object_int_add(json_row
, "vif",
3477 pim_ifp
->mroute_vif_index
);
3478 json_object_int_add(json_row
, "pktsIn",
3479 (unsigned long)vreq
.icount
);
3480 json_object_int_add(json_row
, "pktsOut",
3481 (unsigned long)vreq
.ocount
);
3482 json_object_int_add(json_row
, "bytesIn",
3483 (unsigned long)vreq
.ibytes
);
3484 json_object_int_add(json_row
, "bytesOut",
3485 (unsigned long)vreq
.obytes
);
3486 json_object_object_add(json
, ifp
->name
, json_row
);
3488 ttable_add_row(tt
, "%s|%pPAs|%d|%d|%lu|%lu|%lu|%lu",
3489 ifp
->name
, &pim_ifp
->primary_address
,
3490 ifp
->ifindex
, pim_ifp
->mroute_vif_index
,
3491 (unsigned long)vreq
.icount
,
3492 (unsigned long)vreq
.ocount
,
3493 (unsigned long)vreq
.ibytes
,
3494 (unsigned long)vreq
.obytes
);
3497 /* Dump the generated table. */
3499 table
= ttable_dump(tt
, "\n");
3500 vty_out(vty
, "%s\n", table
);
3501 XFREE(MTYPE_TMP
, table
);
3506 void pim_cmd_show_ip_multicast_helper(struct pim_instance
*pim
, struct vty
*vty
)
3508 struct vrf
*vrf
= pim
->vrf
;
3509 time_t now
= pim_time_monotonic_sec();
3515 vty_out(vty
, "Router MLAG Role: %s\n",
3516 mlag_role2str(router
->mlag_role
, mlag_role
, sizeof(mlag_role
)));
3517 vty_out(vty
, "Mroute socket descriptor:");
3519 vty_out(vty
, " %d(%s)\n", pim
->mroute_socket
, vrf
->name
);
3520 vty_out(vty
, "PIM Register socket descriptor:");
3521 vty_out(vty
, " %d(%s)\n", pim
->reg_sock
, vrf
->name
);
3523 pim_time_uptime(uptime
, sizeof(uptime
),
3524 now
- pim
->mroute_socket_creation
);
3525 vty_out(vty
, "Mroute socket uptime: %s\n", uptime
);
3529 pim_zebra_zclient_update(vty
);
3530 pim_zlookup_show_ip_multicast(vty
);
3533 vty_out(vty
, "Maximum highest VifIndex: %d\n", PIM_MAX_USABLE_VIFS
);
3536 vty_out(vty
, "Upstream Join Timer: %d secs\n", router
->t_periodic
);
3537 vty_out(vty
, "Join/Prune Holdtime: %d secs\n", PIM_JP_HOLDTIME
);
3538 vty_out(vty
, "PIM ECMP: %s\n", pim
->ecmp_enable
? "Enable" : "Disable");
3539 vty_out(vty
, "PIM ECMP Rebalance: %s\n",
3540 pim
->ecmp_rebalance_enable
? "Enable" : "Disable");
3544 pim_show_rpf_refresh_stats(vty
, pim
, now
, NULL
);
3548 show_scan_oil_stats(pim
, vty
, now
);
3550 show_multicast_interfaces(pim
, vty
, NULL
);
3553 void show_mroute(struct pim_instance
*pim
, struct vty
*vty
, pim_sgaddr
*sg
,
3554 bool fill
, json_object
*json
)
3556 struct listnode
*node
;
3557 struct channel_oil
*c_oil
;
3558 struct static_route
*s_route
;
3559 struct ttable
*tt
= NULL
;
3562 json_object
*json_group
= NULL
;
3563 json_object
*json_source
= NULL
;
3564 json_object
*json_oil
= NULL
;
3565 json_object
*json_ifp_out
= NULL
;
3568 char grp_str
[PIM_ADDRSTRLEN
];
3569 char src_str
[PIM_ADDRSTRLEN
];
3570 char in_ifname
[INTERFACE_NAMSIZ
+ 1];
3571 char out_ifname
[INTERFACE_NAMSIZ
+ 1];
3573 struct interface
*ifp_in
;
3575 char state_str
[PIM_REG_STATE_STR_LEN
];
3576 char mroute_uptime
[10];
3579 vty_out(vty
, "IP Multicast Routing Table\n");
3580 vty_out(vty
, "Flags: S - Sparse, C - Connected, P - Pruned\n");
3582 " R - SGRpt Pruned, F - Register flag, T - SPT-bit set\n");
3584 /* Prepare table. */
3585 tt
= ttable_new(&ttable_styles
[TTSTYLE_BLANK
]);
3587 tt
, "Source|Group|Flags|Proto|Input|Output|TTL|Uptime");
3588 tt
->style
.cell
.rpad
= 2;
3589 tt
->style
.corner
= '+';
3593 now
= pim_time_monotonic_sec();
3595 /* print list of PIM and IGMP routes */
3596 frr_each (rb_pim_oil
, &pim
->channel_oil_head
, c_oil
) {
3599 if (!c_oil
->installed
)
3602 if (!pim_addr_is_any(sg
->grp
) &&
3603 pim_addr_cmp(sg
->grp
, *oil_mcastgrp(c_oil
)))
3605 if (!pim_addr_is_any(sg
->src
) &&
3606 pim_addr_cmp(sg
->src
, *oil_origin(c_oil
)))
3609 snprintfrr(grp_str
, sizeof(grp_str
), "%pPAs",
3610 oil_mcastgrp(c_oil
));
3611 snprintfrr(src_str
, sizeof(src_str
), "%pPAs",
3614 strlcpy(state_str
, "S", sizeof(state_str
));
3615 /* When a non DR receives a igmp join, it creates a (*,G)
3616 * channel_oil without any upstream creation
3619 if (PIM_UPSTREAM_FLAG_TEST_SRC_IGMP(c_oil
->up
->flags
))
3620 strlcat(state_str
, "C", sizeof(state_str
));
3621 if (pim_upstream_is_sg_rpt(c_oil
->up
))
3622 strlcat(state_str
, "R", sizeof(state_str
));
3623 if (PIM_UPSTREAM_FLAG_TEST_FHR(c_oil
->up
->flags
))
3624 strlcat(state_str
, "F", sizeof(state_str
));
3625 if (c_oil
->up
->sptbit
== PIM_UPSTREAM_SPTBIT_TRUE
)
3626 strlcat(state_str
, "T", sizeof(state_str
));
3628 if (pim_channel_oil_empty(c_oil
))
3629 strlcat(state_str
, "P", sizeof(state_str
));
3631 ifp_in
= pim_if_find_by_vif_index(pim
, *oil_parent(c_oil
));
3634 strlcpy(in_ifname
, ifp_in
->name
, sizeof(in_ifname
));
3636 strlcpy(in_ifname
, "<iif?>", sizeof(in_ifname
));
3639 pim_time_uptime(mroute_uptime
, sizeof(mroute_uptime
),
3640 now
- c_oil
->mroute_creation
);
3644 /* Find the group, create it if it doesn't exist */
3645 json_object_object_get_ex(json
, grp_str
, &json_group
);
3648 json_group
= json_object_new_object();
3649 json_object_object_add(json
, grp_str
,
3653 /* Find the source nested under the group, create it if
3656 json_object_object_get_ex(json_group
, src_str
,
3660 json_source
= json_object_new_object();
3661 json_object_object_add(json_group
, src_str
,
3665 /* Find the inbound interface nested under the source,
3666 * create it if it doesn't exist
3668 json_object_string_add(json_source
, "source", src_str
);
3669 json_object_string_add(json_source
, "group", grp_str
);
3670 json_object_int_add(json_source
, "installed",
3672 json_object_int_add(json_source
, "refCount",
3673 c_oil
->oil_ref_count
);
3674 json_object_int_add(json_source
, "oilSize",
3676 json_object_int_add(json_source
, "OilInheritedRescan",
3677 c_oil
->oil_inherited_rescan
);
3678 json_object_int_add(json_source
, "oilInheritedRescan",
3679 c_oil
->oil_inherited_rescan
);
3680 json_object_string_add(json_source
, "iif", in_ifname
);
3681 json_object_string_add(json_source
, "upTime",
3686 for (oif_vif_index
= 0; oif_vif_index
< MAXVIFS
;
3688 struct interface
*ifp_out
;
3691 ttl
= oil_if_has(c_oil
, oif_vif_index
);
3695 /* do not display muted OIFs */
3696 if (c_oil
->oif_flags
[oif_vif_index
] & PIM_OIF_FLAG_MUTE
)
3699 if (*oil_parent(c_oil
) == oif_vif_index
&&
3700 !pim_mroute_allow_iif_in_oil(c_oil
, oif_vif_index
))
3703 ifp_out
= pim_if_find_by_vif_index(pim
, oif_vif_index
);
3707 strlcpy(out_ifname
, ifp_out
->name
,
3708 sizeof(out_ifname
));
3710 strlcpy(out_ifname
, "<oif?>",
3711 sizeof(out_ifname
));
3714 json_ifp_out
= json_object_new_object();
3715 json_object_string_add(json_ifp_out
, "source",
3717 json_object_string_add(json_ifp_out
, "group",
3720 if (c_oil
->oif_flags
[oif_vif_index
] &
3721 PIM_OIF_FLAG_PROTO_PIM
)
3722 json_object_boolean_true_add(
3723 json_ifp_out
, "protocolPim");
3725 if (c_oil
->oif_flags
[oif_vif_index
] &
3726 PIM_OIF_FLAG_PROTO_GM
)
3728 json_object_boolean_true_add(
3729 json_ifp_out
, "protocolIgmp");
3731 json_object_boolean_true_add(
3732 json_ifp_out
, "protocolMld");
3735 if (c_oil
->oif_flags
[oif_vif_index
] &
3736 PIM_OIF_FLAG_PROTO_VXLAN
)
3737 json_object_boolean_true_add(
3738 json_ifp_out
, "protocolVxlan");
3740 if (c_oil
->oif_flags
[oif_vif_index
] &
3741 PIM_OIF_FLAG_PROTO_STAR
)
3742 json_object_boolean_true_add(
3744 "protocolInherited");
3746 json_object_string_add(json_ifp_out
,
3749 json_object_int_add(json_ifp_out
, "iVifI",
3750 *oil_parent(c_oil
));
3751 json_object_string_add(json_ifp_out
,
3752 "outboundInterface",
3754 json_object_int_add(json_ifp_out
, "oVifI",
3756 json_object_int_add(json_ifp_out
, "ttl", ttl
);
3757 json_object_string_add(json_ifp_out
, "upTime",
3759 json_object_string_add(json_source
, "flags",
3762 json_oil
= json_object_new_object();
3763 json_object_object_add(json_source
,
3766 json_object_object_add(json_oil
, out_ifname
,
3770 if (c_oil
->oif_flags
[oif_vif_index
] &
3771 PIM_OIF_FLAG_PROTO_PIM
) {
3772 strlcpy(proto
, "PIM", sizeof(proto
));
3775 if (c_oil
->oif_flags
[oif_vif_index
] &
3776 PIM_OIF_FLAG_PROTO_GM
) {
3778 strlcpy(proto
, "IGMP", sizeof(proto
));
3780 strlcpy(proto
, "MLD", sizeof(proto
));
3784 if (c_oil
->oif_flags
[oif_vif_index
] &
3785 PIM_OIF_FLAG_PROTO_VXLAN
) {
3786 strlcpy(proto
, "VxLAN", sizeof(proto
));
3789 if (c_oil
->oif_flags
[oif_vif_index
] &
3790 PIM_OIF_FLAG_PROTO_STAR
) {
3791 strlcpy(proto
, "STAR", sizeof(proto
));
3794 ttable_add_row(tt
, "%s|%s|%s|%s|%s|%s|%d|%s",
3795 src_str
, grp_str
, state_str
,
3796 proto
, in_ifname
, out_ifname
,
3797 ttl
, mroute_uptime
);
3802 in_ifname
[0] = '\0';
3803 state_str
[0] = '\0';
3804 mroute_uptime
[0] = '\0';
3810 if (!json
&& !found_oif
) {
3811 ttable_add_row(tt
, "%pPAs|%pPAs|%s|%s|%s|%s|%d|%s",
3812 oil_origin(c_oil
), oil_mcastgrp(c_oil
),
3813 state_str
, "none", in_ifname
, "none", 0,
3818 /* Print list of static routes */
3819 for (ALL_LIST_ELEMENTS_RO(pim
->static_routes
, node
, s_route
)) {
3822 if (!s_route
->c_oil
.installed
)
3825 snprintfrr(grp_str
, sizeof(grp_str
), "%pPAs", &s_route
->group
);
3826 snprintfrr(src_str
, sizeof(src_str
), "%pPAs", &s_route
->source
);
3827 ifp_in
= pim_if_find_by_vif_index(pim
, s_route
->iif
);
3831 strlcpy(in_ifname
, ifp_in
->name
, sizeof(in_ifname
));
3833 strlcpy(in_ifname
, "<iif?>", sizeof(in_ifname
));
3837 /* Find the group, create it if it doesn't exist */
3838 json_object_object_get_ex(json
, grp_str
, &json_group
);
3841 json_group
= json_object_new_object();
3842 json_object_object_add(json
, grp_str
,
3846 /* Find the source nested under the group, create it if
3849 json_object_object_get_ex(json_group
, src_str
,
3853 json_source
= json_object_new_object();
3854 json_object_object_add(json_group
, src_str
,
3858 json_object_string_add(json_source
, "iif", in_ifname
);
3861 strlcpy(proto
, "STATIC", sizeof(proto
));
3864 for (oif_vif_index
= 0; oif_vif_index
< MAXVIFS
;
3866 struct interface
*ifp_out
;
3867 char oif_uptime
[10];
3870 ttl
= s_route
->oif_ttls
[oif_vif_index
];
3874 ifp_out
= pim_if_find_by_vif_index(pim
, oif_vif_index
);
3876 oif_uptime
, sizeof(oif_uptime
),
3877 now
- s_route
->c_oil
3878 .oif_creation
[oif_vif_index
]);
3882 strlcpy(out_ifname
, ifp_out
->name
,
3883 sizeof(out_ifname
));
3885 strlcpy(out_ifname
, "<oif?>",
3886 sizeof(out_ifname
));
3889 json_ifp_out
= json_object_new_object();
3890 json_object_string_add(json_ifp_out
, "source",
3892 json_object_string_add(json_ifp_out
, "group",
3894 json_object_boolean_true_add(json_ifp_out
,
3896 json_object_string_add(json_ifp_out
,
3899 json_object_int_add(
3900 json_ifp_out
, "iVifI",
3901 *oil_parent(&s_route
->c_oil
));
3902 json_object_string_add(json_ifp_out
,
3903 "outboundInterface",
3905 json_object_int_add(json_ifp_out
, "oVifI",
3907 json_object_int_add(json_ifp_out
, "ttl", ttl
);
3908 json_object_string_add(json_ifp_out
, "upTime",
3911 json_oil
= json_object_new_object();
3912 json_object_object_add(json_source
,
3915 json_object_object_add(json_oil
, out_ifname
,
3919 tt
, "%pPAs|%pPAs|%s|%s|%s|%s|%d|%s",
3920 &s_route
->source
, &s_route
->group
, "-",
3921 proto
, in_ifname
, out_ifname
, ttl
,
3923 if (first
&& !fill
) {
3926 in_ifname
[0] = '\0';
3932 if (!json
&& !found_oif
) {
3933 ttable_add_row(tt
, "%pPAs|%pPAs|%s|%s|%s|%s|%d|%s",
3934 &s_route
->source
, &s_route
->group
, "-",
3935 proto
, in_ifname
, "none", 0, "--:--:--");
3938 /* Dump the generated table. */
3940 table
= ttable_dump(tt
, "\n");
3941 vty_out(vty
, "%s\n", table
);
3942 XFREE(MTYPE_TMP
, table
);
3947 static void show_mroute_count_per_channel_oil(struct channel_oil
*c_oil
,
3951 json_object
*json_group
= NULL
;
3952 json_object
*json_source
= NULL
;
3954 if (!c_oil
->installed
)
3957 pim_mroute_update_counters(c_oil
);
3960 char group_str
[PIM_ADDRSTRLEN
];
3961 char source_str
[PIM_ADDRSTRLEN
];
3963 snprintfrr(group_str
, sizeof(group_str
), "%pPAs",
3964 oil_mcastgrp(c_oil
));
3965 snprintfrr(source_str
, sizeof(source_str
), "%pPAs",
3968 json_object_object_get_ex(json
, group_str
, &json_group
);
3971 json_group
= json_object_new_object();
3972 json_object_object_add(json
, group_str
, json_group
);
3975 json_source
= json_object_new_object();
3976 json_object_object_add(json_group
, source_str
, json_source
);
3977 json_object_int_add(json_source
, "lastUsed",
3978 c_oil
->cc
.lastused
/ 100);
3979 json_object_int_add(json_source
, "packets", c_oil
->cc
.pktcnt
);
3980 json_object_int_add(json_source
, "bytes", c_oil
->cc
.bytecnt
);
3981 json_object_int_add(json_source
, "wrongIf", c_oil
->cc
.wrong_if
);
3984 ttable_add_row(tt
, "%pPAs|%pPAs|%llu|%ld|%ld|%ld",
3985 oil_origin(c_oil
), oil_mcastgrp(c_oil
),
3986 c_oil
->cc
.lastused
/ 100,
3987 c_oil
->cc
.pktcnt
- c_oil
->cc
.origpktcnt
,
3988 c_oil
->cc
.bytecnt
- c_oil
->cc
.origbytecnt
,
3989 c_oil
->cc
.wrong_if
- c_oil
->cc
.origwrong_if
);
3993 void show_mroute_count(struct pim_instance
*pim
, struct vty
*vty
,
3996 struct listnode
*node
;
3997 struct channel_oil
*c_oil
;
3998 struct static_route
*sr
;
3999 struct ttable
*tt
= NULL
;
4005 /* Prepare table. */
4006 tt
= ttable_new(&ttable_styles
[TTSTYLE_BLANK
]);
4008 "Source|Group|LastUsed|Packets|Bytes|WrongIf");
4009 tt
->style
.cell
.rpad
= 2;
4010 tt
->style
.corner
= '+';
4014 /* Print PIM and IGMP route counts */
4015 frr_each (rb_pim_oil
, &pim
->channel_oil_head
, c_oil
)
4016 show_mroute_count_per_channel_oil(c_oil
, json
, tt
);
4018 for (ALL_LIST_ELEMENTS_RO(pim
->static_routes
, node
, sr
))
4019 show_mroute_count_per_channel_oil(&sr
->c_oil
, json
, tt
);
4021 /* Dump the generated table. */
4023 table
= ttable_dump(tt
, "\n");
4024 vty_out(vty
, "%s\n", table
);
4025 XFREE(MTYPE_TMP
, table
);
4030 void show_mroute_summary(struct pim_instance
*pim
, struct vty
*vty
,
4033 struct listnode
*node
;
4034 struct channel_oil
*c_oil
;
4035 struct static_route
*s_route
;
4036 uint32_t starg_sw_mroute_cnt
= 0;
4037 uint32_t sg_sw_mroute_cnt
= 0;
4038 uint32_t starg_hw_mroute_cnt
= 0;
4039 uint32_t sg_hw_mroute_cnt
= 0;
4040 json_object
*json_starg
= NULL
;
4041 json_object
*json_sg
= NULL
;
4044 vty_out(vty
, "Mroute Type Installed/Total\n");
4046 frr_each (rb_pim_oil
, &pim
->channel_oil_head
, c_oil
) {
4047 if (!c_oil
->installed
) {
4048 if (pim_addr_is_any(*oil_origin(c_oil
)))
4049 starg_sw_mroute_cnt
++;
4053 if (pim_addr_is_any(*oil_origin(c_oil
)))
4054 starg_hw_mroute_cnt
++;
4060 for (ALL_LIST_ELEMENTS_RO(pim
->static_routes
, node
, s_route
)) {
4061 if (!s_route
->c_oil
.installed
) {
4062 if (pim_addr_is_any(*oil_origin(&s_route
->c_oil
)))
4063 starg_sw_mroute_cnt
++;
4067 if (pim_addr_is_any(*oil_origin(&s_route
->c_oil
)))
4068 starg_hw_mroute_cnt
++;
4075 vty_out(vty
, "%-20s %u/%u\n", "(*, G)", starg_hw_mroute_cnt
,
4076 starg_sw_mroute_cnt
+ starg_hw_mroute_cnt
);
4077 vty_out(vty
, "%-20s %u/%u\n", "(S, G)", sg_hw_mroute_cnt
,
4078 sg_sw_mroute_cnt
+ sg_hw_mroute_cnt
);
4079 vty_out(vty
, "------\n");
4080 vty_out(vty
, "%-20s %u/%u\n", "Total",
4081 (starg_hw_mroute_cnt
+ sg_hw_mroute_cnt
),
4082 (starg_sw_mroute_cnt
+ starg_hw_mroute_cnt
+
4083 sg_sw_mroute_cnt
+ sg_hw_mroute_cnt
));
4085 /* (*,G) route details */
4086 json_starg
= json_object_new_object();
4087 json_object_object_add(json
, "wildcardGroup", json_starg
);
4089 json_object_int_add(json_starg
, "installed",
4090 starg_hw_mroute_cnt
);
4091 json_object_int_add(json_starg
, "total",
4092 starg_sw_mroute_cnt
+ starg_hw_mroute_cnt
);
4094 /* (S, G) route details */
4095 json_sg
= json_object_new_object();
4096 json_object_object_add(json
, "sourceGroup", json_sg
);
4098 json_object_int_add(json_sg
, "installed", sg_hw_mroute_cnt
);
4099 json_object_int_add(json_sg
, "total",
4100 sg_sw_mroute_cnt
+ sg_hw_mroute_cnt
);
4102 json_object_int_add(json
, "totalNumOfInstalledMroutes",
4103 starg_hw_mroute_cnt
+ sg_hw_mroute_cnt
);
4104 json_object_int_add(json
, "totalNumOfMroutes",
4105 starg_sw_mroute_cnt
+ starg_hw_mroute_cnt
+
4111 int clear_ip_mroute_count_command(struct vty
*vty
, const char *name
)
4113 struct listnode
*node
;
4114 struct channel_oil
*c_oil
;
4115 struct static_route
*sr
;
4116 struct vrf
*v
= pim_cmd_lookup(vty
, name
);
4117 struct pim_instance
*pim
;
4123 frr_each (rb_pim_oil
, &pim
->channel_oil_head
, c_oil
) {
4124 if (!c_oil
->installed
)
4127 pim_mroute_update_counters(c_oil
);
4128 c_oil
->cc
.origpktcnt
= c_oil
->cc
.pktcnt
;
4129 c_oil
->cc
.origbytecnt
= c_oil
->cc
.bytecnt
;
4130 c_oil
->cc
.origwrong_if
= c_oil
->cc
.wrong_if
;
4133 for (ALL_LIST_ELEMENTS_RO(pim
->static_routes
, node
, sr
)) {
4134 if (!sr
->c_oil
.installed
)
4137 pim_mroute_update_counters(&sr
->c_oil
);
4139 sr
->c_oil
.cc
.origpktcnt
= sr
->c_oil
.cc
.pktcnt
;
4140 sr
->c_oil
.cc
.origbytecnt
= sr
->c_oil
.cc
.bytecnt
;
4141 sr
->c_oil
.cc
.origwrong_if
= sr
->c_oil
.cc
.wrong_if
;
4146 struct vrf
*pim_cmd_lookup(struct vty
*vty
, const char *name
)
4151 vrf
= vrf_lookup_by_name(name
);
4153 vrf
= vrf_lookup_by_id(VRF_DEFAULT
);
4156 vty_out(vty
, "Specified VRF: %s does not exist\n", name
);
4161 void clear_mroute(struct pim_instance
*pim
)
4163 struct pim_upstream
*up
;
4164 struct interface
*ifp
;
4166 /* scan interfaces */
4167 FOR_ALL_INTERFACES (pim
->vrf
, ifp
) {
4168 struct pim_interface
*pim_ifp
= ifp
->info
;
4169 struct pim_ifchannel
*ch
;
4174 /* deleting all ifchannels */
4175 while (!RB_EMPTY(pim_ifchannel_rb
, &pim_ifp
->ifchannel_rb
)) {
4176 ch
= RB_ROOT(pim_ifchannel_rb
, &pim_ifp
->ifchannel_rb
);
4178 pim_ifchannel_delete(ch
);
4182 /* clean up all igmp groups */
4183 struct gm_group
*grp
;
4185 if (pim_ifp
->gm_group_list
) {
4186 while (pim_ifp
->gm_group_list
->count
) {
4187 grp
= listnode_head(pim_ifp
->gm_group_list
);
4188 igmp_group_delete(grp
);
4192 struct gm_if
*gm_ifp
;
4194 gm_ifp
= pim_ifp
->mld
;
4196 gm_group_delete(gm_ifp
);
4200 /* clean up all upstreams*/
4201 while ((up
= rb_pim_upstream_first(&pim
->upstream_head
)))
4202 pim_upstream_del(pim
, up
, __func__
);
4205 void clear_pim_statistics(struct pim_instance
*pim
)
4207 struct interface
*ifp
;
4211 pim
->bsm_dropped
= 0;
4213 /* scan interfaces */
4214 FOR_ALL_INTERFACES (pim
->vrf
, ifp
) {
4215 struct pim_interface
*pim_ifp
= ifp
->info
;
4220 pim_ifp
->pim_ifstat_bsm_cfg_miss
= 0;
4221 pim_ifp
->pim_ifstat_ucast_bsm_cfg_miss
= 0;
4222 pim_ifp
->pim_ifstat_bsm_invalid_sz
= 0;
4226 int clear_pim_interface_traffic(const char *vrf
, struct vty
*vty
)
4228 struct interface
*ifp
= NULL
;
4229 struct pim_interface
*pim_ifp
= NULL
;
4231 struct vrf
*v
= pim_cmd_lookup(vty
, vrf
);
4236 FOR_ALL_INTERFACES (v
, ifp
) {
4237 pim_ifp
= ifp
->info
;
4242 pim_ifp
->pim_ifstat_hello_recv
= 0;
4243 pim_ifp
->pim_ifstat_hello_sent
= 0;
4244 pim_ifp
->pim_ifstat_join_recv
= 0;
4245 pim_ifp
->pim_ifstat_join_send
= 0;
4246 pim_ifp
->pim_ifstat_prune_recv
= 0;
4247 pim_ifp
->pim_ifstat_prune_send
= 0;
4248 pim_ifp
->pim_ifstat_reg_recv
= 0;
4249 pim_ifp
->pim_ifstat_reg_send
= 0;
4250 pim_ifp
->pim_ifstat_reg_stop_recv
= 0;
4251 pim_ifp
->pim_ifstat_reg_stop_send
= 0;
4252 pim_ifp
->pim_ifstat_assert_recv
= 0;
4253 pim_ifp
->pim_ifstat_assert_send
= 0;
4254 pim_ifp
->pim_ifstat_bsm_rx
= 0;
4255 pim_ifp
->pim_ifstat_bsm_tx
= 0;
4257 pim_ifp
->igmp_ifstat_joins_sent
= 0;
4258 pim_ifp
->igmp_ifstat_joins_failed
= 0;
4259 pim_ifp
->igmp_peak_group_count
= 0;
4266 int pim_debug_pim_cmd(void)
4268 PIM_DO_DEBUG_PIM_EVENTS
;
4269 PIM_DO_DEBUG_PIM_PACKETS
;
4270 PIM_DO_DEBUG_PIM_TRACE
;
4271 PIM_DO_DEBUG_MSDP_EVENTS
;
4272 PIM_DO_DEBUG_MSDP_PACKETS
;
4278 int pim_no_debug_pim_cmd(void)
4280 PIM_DONT_DEBUG_PIM_EVENTS
;
4281 PIM_DONT_DEBUG_PIM_PACKETS
;
4282 PIM_DONT_DEBUG_PIM_TRACE
;
4283 PIM_DONT_DEBUG_MSDP_EVENTS
;
4284 PIM_DONT_DEBUG_MSDP_PACKETS
;
4286 PIM_DONT_DEBUG_PIM_PACKETDUMP_SEND
;
4287 PIM_DONT_DEBUG_PIM_PACKETDUMP_RECV
;
4289 PIM_DONT_DEBUG_VXLAN
;
4293 int pim_debug_pim_packets_cmd(const char *hello
, const char *joins
,
4294 const char *registers
, struct vty
*vty
)
4297 PIM_DO_DEBUG_PIM_HELLO
;
4298 vty_out(vty
, "PIM Hello debugging is on\n");
4300 PIM_DO_DEBUG_PIM_J_P
;
4301 vty_out(vty
, "PIM Join/Prune debugging is on\n");
4302 } else if (registers
) {
4303 PIM_DO_DEBUG_PIM_REG
;
4304 vty_out(vty
, "PIM Register debugging is on\n");
4306 PIM_DO_DEBUG_PIM_PACKETS
;
4307 vty_out(vty
, "PIM Packet debugging is on\n");
4312 int pim_no_debug_pim_packets_cmd(const char *hello
, const char *joins
,
4313 const char *registers
, struct vty
*vty
)
4316 PIM_DONT_DEBUG_PIM_HELLO
;
4317 vty_out(vty
, "PIM Hello debugging is off\n");
4319 PIM_DONT_DEBUG_PIM_J_P
;
4320 vty_out(vty
, "PIM Join/Prune debugging is off\n");
4321 } else if (registers
) {
4322 PIM_DONT_DEBUG_PIM_REG
;
4323 vty_out(vty
, "PIM Register debugging is off\n");
4325 PIM_DONT_DEBUG_PIM_PACKETS
;
4326 vty_out(vty
, "PIM Packet debugging is off\n");
4332 int pim_show_rpf_helper(const char *vrf
, struct vty
*vty
, bool json
)
4334 struct pim_instance
*pim
;
4336 json_object
*json_parent
= NULL
;
4338 v
= vrf_lookup_by_name(vrf
? vrf
: VRF_DEFAULT_NAME
);
4346 vty_out(vty
, "%% Unable to find pim instance\n");
4351 json_parent
= json_object_new_object();
4353 pim_show_rpf(pim
, vty
, json_parent
);
4356 vty_json(vty
, json_parent
);
4361 int pim_show_rpf_vrf_all_helper(struct vty
*vty
, bool json
)
4364 json_object
*json_parent
= NULL
;
4365 json_object
*json_vrf
= NULL
;
4368 json_parent
= json_object_new_object();
4370 RB_FOREACH (vrf
, vrf_name_head
, &vrfs_by_name
) {
4372 vty_out(vty
, "VRF: %s\n", vrf
->name
);
4374 json_vrf
= json_object_new_object();
4375 pim_show_rpf(vrf
->info
, vty
, json_vrf
);
4377 json_object_object_add(json_parent
, vrf
->name
,
4381 vty_json(vty
, json_parent
);
4386 int pim_show_rp_helper(const char *vrf
, struct vty
*vty
, const char *group_str
,
4387 const struct prefix
*group
, bool json
)
4389 struct pim_instance
*pim
;
4391 json_object
*json_parent
= NULL
;
4392 struct prefix
*range
= NULL
;
4394 v
= vrf_lookup_by_name(vrf
? vrf
: VRF_DEFAULT_NAME
);
4402 vty_out(vty
, "%% Unable to find pim instance\n");
4407 range
= prefix_new();
4408 prefix_copy(range
, group
);
4413 json_parent
= json_object_new_object();
4415 pim_rp_show_information(pim
, range
, vty
, json_parent
);
4418 vty_json(vty
, json_parent
);
4420 prefix_free(&range
);
4425 int pim_show_rp_vrf_all_helper(struct vty
*vty
, const char *group_str
,
4426 const struct prefix
*group
, bool json
)
4429 json_object
*json_parent
= NULL
;
4430 json_object
*json_vrf
= NULL
;
4431 struct prefix
*range
= NULL
;
4434 range
= prefix_new();
4435 prefix_copy(range
, group
);
4440 json_parent
= json_object_new_object();
4442 RB_FOREACH (vrf
, vrf_name_head
, &vrfs_by_name
) {
4444 vty_out(vty
, "VRF: %s\n", vrf
->name
);
4446 json_vrf
= json_object_new_object();
4447 pim_rp_show_information(vrf
->info
, range
, vty
, json_vrf
);
4449 json_object_object_add(json_parent
, vrf
->name
,
4453 vty_json(vty
, json_parent
);
4455 prefix_free(&range
);
4460 int pim_show_secondary_helper(const char *vrf
, struct vty
*vty
)
4462 struct pim_instance
*pim
;
4465 v
= vrf_lookup_by_name(vrf
? vrf
: VRF_DEFAULT_NAME
);
4473 vty_out(vty
, "%% Unable to find pim instance\n");
4477 pim_show_neighbors_secondary(pim
, vty
);
4482 int pim_show_statistics_helper(const char *vrf
, struct vty
*vty
,
4483 const char *word
, bool uj
)
4485 struct pim_instance
*pim
;
4488 v
= vrf_lookup_by_name(vrf
? vrf
: VRF_DEFAULT_NAME
);
4496 vty_out(vty
, "%% Unable to find pim instance\n");
4501 pim_show_statistics(pim
, vty
, word
, uj
);
4503 pim_show_statistics(pim
, vty
, NULL
, uj
);
4508 int pim_show_upstream_helper(const char *vrf
, struct vty
*vty
, pim_addr s_or_g
,
4509 pim_addr g
, bool json
)
4511 pim_sgaddr sg
= {0};
4513 struct pim_instance
*pim
;
4514 json_object
*json_parent
= NULL
;
4516 v
= vrf_lookup_by_name(vrf
? vrf
: VRF_DEFAULT_NAME
);
4519 vty_out(vty
, "%% Vrf specified: %s does not exist\n", vrf
);
4525 vty_out(vty
, "%% Unable to find pim instance\n");
4530 json_parent
= json_object_new_object();
4532 if (!pim_addr_is_any(s_or_g
)) {
4533 if (!pim_addr_is_any(g
)) {
4540 pim_show_upstream(pim
, vty
, &sg
, json_parent
);
4543 vty_json(vty
, json_parent
);
4548 int pim_show_upstream_vrf_all_helper(struct vty
*vty
, bool json
)
4550 pim_sgaddr sg
= {0};
4552 json_object
*json_parent
= NULL
;
4553 json_object
*json_vrf
= NULL
;
4556 json_parent
= json_object_new_object();
4558 RB_FOREACH (vrf
, vrf_name_head
, &vrfs_by_name
) {
4560 vty_out(vty
, "VRF: %s\n", vrf
->name
);
4562 json_vrf
= json_object_new_object();
4563 pim_show_upstream(vrf
->info
, vty
, &sg
, json_vrf
);
4565 json_object_object_add(json_parent
, vrf
->name
,
4570 vty_json(vty
, json_parent
);
4575 int pim_show_upstream_join_desired_helper(const char *vrf
, struct vty
*vty
,
4578 struct pim_instance
*pim
;
4581 v
= vrf_lookup_by_name(vrf
? vrf
: VRF_DEFAULT_NAME
);
4589 vty_out(vty
, "%% Unable to find pim instance\n");
4593 pim_show_join_desired(pim
, vty
, uj
);
4598 int pim_show_upstream_rpf_helper(const char *vrf
, struct vty
*vty
, bool uj
)
4600 struct pim_instance
*pim
;
4603 v
= vrf_lookup_by_name(vrf
? vrf
: VRF_DEFAULT_NAME
);
4611 vty_out(vty
, "%% Unable to find pim instance\n");
4615 pim_show_upstream_rpf(pim
, vty
, uj
);
4620 int pim_show_state_helper(const char *vrf
, struct vty
*vty
,
4621 const char *s_or_g_str
, const char *g_str
, bool json
)
4623 struct pim_instance
*pim
;
4625 json_object
*json_parent
= NULL
;
4627 v
= vrf_lookup_by_name(vrf
? vrf
: VRF_DEFAULT_NAME
);
4635 vty_out(vty
, "%% Unable to find pim instance\n");
4640 json_parent
= json_object_new_object();
4642 pim_show_state(pim
, vty
, s_or_g_str
, g_str
, json_parent
);
4645 vty_json(vty
, json_parent
);
4650 int pim_show_state_vrf_all_helper(struct vty
*vty
, const char *s_or_g_str
,
4651 const char *g_str
, bool json
)
4654 json_object
*json_parent
= NULL
;
4655 json_object
*json_vrf
= NULL
;
4658 json_parent
= json_object_new_object();
4660 RB_FOREACH (vrf
, vrf_name_head
, &vrfs_by_name
) {
4662 vty_out(vty
, "VRF: %s\n", vrf
->name
);
4664 json_vrf
= json_object_new_object();
4665 pim_show_state(vrf
->info
, vty
, s_or_g_str
, g_str
, json_vrf
);
4667 json_object_object_add(json_parent
, vrf
->name
,
4671 vty_json(vty
, json_parent
);
4676 int pim_show_multicast_helper(const char *vrf
, struct vty
*vty
)
4679 struct pim_instance
*pim
;
4681 v
= vrf_lookup_by_name(vrf
? vrf
: VRF_DEFAULT_NAME
);
4689 vty_out(vty
, "%% Unable to find pim instance\n");
4693 pim_cmd_show_ip_multicast_helper(pim
, vty
);
4698 int pim_show_multicast_vrf_all_helper(struct vty
*vty
)
4702 RB_FOREACH (vrf
, vrf_name_head
, &vrfs_by_name
) {
4703 vty_out(vty
, "VRF: %s\n", vrf
->name
);
4704 pim_cmd_show_ip_multicast_helper(vrf
->info
, vty
);
4710 int pim_show_multicast_count_helper(const char *vrf
, struct vty
*vty
, bool json
)
4712 struct pim_instance
*pim
;
4714 json_object
*json_parent
= NULL
;
4716 v
= vrf_lookup_by_name(vrf
? vrf
: VRF_DEFAULT_NAME
);
4724 vty_out(vty
, "%% Unable to find pim instance\n");
4729 json_parent
= json_object_new_object();
4731 show_multicast_interfaces(pim
, vty
, json_parent
);
4734 vty_json(vty
, json_parent
);
4739 int pim_show_multicast_count_vrf_all_helper(struct vty
*vty
, bool json
)
4742 json_object
*json_parent
= NULL
;
4743 json_object
*json_vrf
= NULL
;
4746 json_parent
= json_object_new_object();
4748 RB_FOREACH (vrf
, vrf_name_head
, &vrfs_by_name
) {
4750 vty_out(vty
, "VRF: %s\n", vrf
->name
);
4752 json_vrf
= json_object_new_object();
4754 show_multicast_interfaces(vrf
->info
, vty
, json_vrf
);
4756 json_object_object_add(json_parent
, vrf
->name
,
4760 vty_json(vty
, json_parent
);
4765 int pim_show_mroute_helper(const char *vrf
, struct vty
*vty
, pim_addr s_or_g
,
4766 pim_addr g
, bool fill
, bool json
)
4768 pim_sgaddr sg
= {0};
4769 struct pim_instance
*pim
;
4771 json_object
*json_parent
= NULL
;
4773 v
= vrf_lookup_by_name(vrf
? vrf
: VRF_DEFAULT_NAME
);
4781 vty_out(vty
, "%% Unable to find pim instance\n");
4786 json_parent
= json_object_new_object();
4788 if (!pim_addr_is_any(s_or_g
)) {
4789 if (!pim_addr_is_any(g
)) {
4796 show_mroute(pim
, vty
, &sg
, fill
, json_parent
);
4799 vty_json(vty
, json_parent
);
4804 int pim_show_mroute_vrf_all_helper(struct vty
*vty
, bool fill
, bool json
)
4806 pim_sgaddr sg
= {0};
4808 json_object
*json_parent
= NULL
;
4809 json_object
*json_vrf
= NULL
;
4812 json_parent
= json_object_new_object();
4814 RB_FOREACH (vrf
, vrf_name_head
, &vrfs_by_name
) {
4816 vty_out(vty
, "VRF: %s\n", vrf
->name
);
4818 json_vrf
= json_object_new_object();
4819 show_mroute(vrf
->info
, vty
, &sg
, fill
, json_vrf
);
4821 json_object_object_add(json_parent
, vrf
->name
,
4825 vty_json(vty
, json_parent
);
4830 int pim_show_mroute_count_helper(const char *vrf
, struct vty
*vty
, bool json
)
4832 struct pim_instance
*pim
;
4834 json_object
*json_parent
= NULL
;
4836 v
= vrf_lookup_by_name(vrf
? vrf
: VRF_DEFAULT_NAME
);
4844 vty_out(vty
, "%% Unable to find pim instance\n");
4849 json_parent
= json_object_new_object();
4851 show_mroute_count(pim
, vty
, json_parent
);
4854 vty_json(vty
, json_parent
);
4859 int pim_show_mroute_count_vrf_all_helper(struct vty
*vty
, bool json
)
4862 json_object
*json_parent
= NULL
;
4863 json_object
*json_vrf
= NULL
;
4866 json_parent
= json_object_new_object();
4868 RB_FOREACH (vrf
, vrf_name_head
, &vrfs_by_name
) {
4870 vty_out(vty
, "VRF: %s\n", vrf
->name
);
4872 json_vrf
= json_object_new_object();
4874 show_mroute_count(vrf
->info
, vty
, json_vrf
);
4877 json_object_object_add(json_parent
, vrf
->name
,
4881 vty_json(vty
, json_parent
);
4886 int pim_show_mroute_summary_helper(const char *vrf
, struct vty
*vty
, bool json
)
4888 struct pim_instance
*pim
;
4890 json_object
*json_parent
= NULL
;
4892 v
= vrf_lookup_by_name(vrf
? vrf
: VRF_DEFAULT_NAME
);
4900 vty_out(vty
, "%% Unable to find pim instance\n");
4905 json_parent
= json_object_new_object();
4907 show_mroute_summary(pim
, vty
, json_parent
);
4910 vty_json(vty
, json_parent
);
4915 int pim_show_mroute_summary_vrf_all_helper(struct vty
*vty
, bool json
)
4918 json_object
*json_parent
= NULL
;
4919 json_object
*json_vrf
= NULL
;
4922 json_parent
= json_object_new_object();
4924 RB_FOREACH (vrf
, vrf_name_head
, &vrfs_by_name
) {
4926 vty_out(vty
, "VRF: %s\n", vrf
->name
);
4928 json_vrf
= json_object_new_object();
4930 show_mroute_summary(vrf
->info
, vty
, json_vrf
);
4933 json_object_object_add(json_parent
, vrf
->name
,
4938 vty_json(vty
, json_parent
);
4943 void pim_show_interface_traffic(struct pim_instance
*pim
, struct vty
*vty
,
4946 struct interface
*ifp
= NULL
;
4947 struct pim_interface
*pim_ifp
= NULL
;
4948 json_object
*json
= NULL
;
4949 json_object
*json_row
= NULL
;
4952 json
= json_object_new_object();
4955 vty_out(vty
, "%-16s%-17s%-17s%-17s%-17s%-17s%-17s%-17s\n",
4956 "Interface", " HELLO", " JOIN",
4957 " PRUNE", " REGISTER", "REGISTER-STOP",
4959 vty_out(vty
, "%-16s%-17s%-17s%-17s%-17s%-17s%-17s%-17s\n", "",
4960 " Rx/Tx", " Rx/Tx", " Rx/Tx",
4961 " Rx/Tx", " Rx/Tx", " Rx/Tx", " Rx/Tx");
4963 "---------------------------------------------------------------------------------------------------------------\n");
4966 FOR_ALL_INTERFACES (pim
->vrf
, ifp
) {
4967 pim_ifp
= ifp
->info
;
4973 json_row
= json_object_new_object();
4974 json_object_pim_ifp_add(json_row
, ifp
);
4975 json_object_int_add(json_row
, "helloRx",
4976 pim_ifp
->pim_ifstat_hello_recv
);
4977 json_object_int_add(json_row
, "helloTx",
4978 pim_ifp
->pim_ifstat_hello_sent
);
4979 json_object_int_add(json_row
, "joinRx",
4980 pim_ifp
->pim_ifstat_join_recv
);
4981 json_object_int_add(json_row
, "joinTx",
4982 pim_ifp
->pim_ifstat_join_send
);
4983 json_object_int_add(json_row
, "pruneRx",
4984 pim_ifp
->pim_ifstat_prune_recv
);
4985 json_object_int_add(json_row
, "pruneTx",
4986 pim_ifp
->pim_ifstat_prune_send
);
4987 json_object_int_add(json_row
, "registerRx",
4988 pim_ifp
->pim_ifstat_reg_recv
);
4989 json_object_int_add(json_row
, "registerTx",
4990 pim_ifp
->pim_ifstat_reg_send
);
4991 json_object_int_add(json_row
, "registerStopRx",
4992 pim_ifp
->pim_ifstat_reg_stop_recv
);
4993 json_object_int_add(json_row
, "registerStopTx",
4994 pim_ifp
->pim_ifstat_reg_stop_send
);
4995 json_object_int_add(json_row
, "assertRx",
4996 pim_ifp
->pim_ifstat_assert_recv
);
4997 json_object_int_add(json_row
, "assertTx",
4998 pim_ifp
->pim_ifstat_assert_send
);
4999 json_object_int_add(json_row
, "bsmRx",
5000 pim_ifp
->pim_ifstat_bsm_rx
);
5001 json_object_int_add(json_row
, "bsmTx",
5002 pim_ifp
->pim_ifstat_bsm_tx
);
5003 json_object_object_add(json
, ifp
->name
, json_row
);
5006 "%-16s %8u/%-8u %7u/%-7u %7u/%-7u %7u/%-7u %7u/%-7u %7u/%-7u %7" PRIu64
5008 ifp
->name
, pim_ifp
->pim_ifstat_hello_recv
,
5009 pim_ifp
->pim_ifstat_hello_sent
,
5010 pim_ifp
->pim_ifstat_join_recv
,
5011 pim_ifp
->pim_ifstat_join_send
,
5012 pim_ifp
->pim_ifstat_prune_recv
,
5013 pim_ifp
->pim_ifstat_prune_send
,
5014 pim_ifp
->pim_ifstat_reg_recv
,
5015 pim_ifp
->pim_ifstat_reg_send
,
5016 pim_ifp
->pim_ifstat_reg_stop_recv
,
5017 pim_ifp
->pim_ifstat_reg_stop_send
,
5018 pim_ifp
->pim_ifstat_assert_recv
,
5019 pim_ifp
->pim_ifstat_assert_send
,
5020 pim_ifp
->pim_ifstat_bsm_rx
,
5021 pim_ifp
->pim_ifstat_bsm_tx
);
5025 vty_json(vty
, json
);
5028 void pim_show_interface_traffic_single(struct pim_instance
*pim
,
5029 struct vty
*vty
, const char *ifname
,
5032 struct interface
*ifp
= NULL
;
5033 struct pim_interface
*pim_ifp
= NULL
;
5034 json_object
*json
= NULL
;
5035 json_object
*json_row
= NULL
;
5036 uint8_t found_ifname
= 0;
5039 json
= json_object_new_object();
5042 vty_out(vty
, "%-16s%-17s%-17s%-17s%-17s%-17s%-17s%-17s\n",
5043 "Interface", " HELLO", " JOIN", " PRUNE",
5044 " REGISTER", " REGISTER-STOP", " ASSERT",
5046 vty_out(vty
, "%-14s%-18s%-17s%-17s%-17s%-17s%-17s%-17s\n", "",
5047 " Rx/Tx", " Rx/Tx", " Rx/Tx", " Rx/Tx",
5048 " Rx/Tx", " Rx/Tx", " Rx/Tx");
5050 "-------------------------------------------------------------------------------------------------------------------------------\n");
5053 FOR_ALL_INTERFACES (pim
->vrf
, ifp
) {
5054 if (strcmp(ifname
, ifp
->name
))
5057 pim_ifp
= ifp
->info
;
5064 json_row
= json_object_new_object();
5065 json_object_pim_ifp_add(json_row
, ifp
);
5066 json_object_int_add(json_row
, "helloRx",
5067 pim_ifp
->pim_ifstat_hello_recv
);
5068 json_object_int_add(json_row
, "helloTx",
5069 pim_ifp
->pim_ifstat_hello_sent
);
5070 json_object_int_add(json_row
, "joinRx",
5071 pim_ifp
->pim_ifstat_join_recv
);
5072 json_object_int_add(json_row
, "joinTx",
5073 pim_ifp
->pim_ifstat_join_send
);
5074 json_object_int_add(json_row
, "pruneRx",
5075 pim_ifp
->pim_ifstat_prune_recv
);
5076 json_object_int_add(json_row
, "pruneTx",
5077 pim_ifp
->pim_ifstat_prune_send
);
5078 json_object_int_add(json_row
, "registerRx",
5079 pim_ifp
->pim_ifstat_reg_recv
);
5080 json_object_int_add(json_row
, "registerTx",
5081 pim_ifp
->pim_ifstat_reg_send
);
5082 json_object_int_add(json_row
, "registerStopRx",
5083 pim_ifp
->pim_ifstat_reg_stop_recv
);
5084 json_object_int_add(json_row
, "registerStopTx",
5085 pim_ifp
->pim_ifstat_reg_stop_send
);
5086 json_object_int_add(json_row
, "assertRx",
5087 pim_ifp
->pim_ifstat_assert_recv
);
5088 json_object_int_add(json_row
, "assertTx",
5089 pim_ifp
->pim_ifstat_assert_send
);
5090 json_object_int_add(json_row
, "bsmRx",
5091 pim_ifp
->pim_ifstat_bsm_rx
);
5092 json_object_int_add(json_row
, "bsmTx",
5093 pim_ifp
->pim_ifstat_bsm_tx
);
5095 json_object_object_add(json
, ifp
->name
, json_row
);
5098 "%-16s %8u/%-8u %7u/%-7u %7u/%-7u %7u/%-7u %7u/%-7u %7u/%-7u %7" PRIu64
5100 ifp
->name
, pim_ifp
->pim_ifstat_hello_recv
,
5101 pim_ifp
->pim_ifstat_hello_sent
,
5102 pim_ifp
->pim_ifstat_join_recv
,
5103 pim_ifp
->pim_ifstat_join_send
,
5104 pim_ifp
->pim_ifstat_prune_recv
,
5105 pim_ifp
->pim_ifstat_prune_send
,
5106 pim_ifp
->pim_ifstat_reg_recv
,
5107 pim_ifp
->pim_ifstat_reg_send
,
5108 pim_ifp
->pim_ifstat_reg_stop_recv
,
5109 pim_ifp
->pim_ifstat_reg_stop_send
,
5110 pim_ifp
->pim_ifstat_assert_recv
,
5111 pim_ifp
->pim_ifstat_assert_send
,
5112 pim_ifp
->pim_ifstat_bsm_rx
,
5113 pim_ifp
->pim_ifstat_bsm_tx
);
5117 vty_json(vty
, json
);
5118 else if (!found_ifname
)
5119 vty_out(vty
, "%% No such interface\n");
5122 int pim_show_interface_traffic_helper(const char *vrf
, const char *if_name
,
5123 struct vty
*vty
, bool uj
)
5125 struct pim_instance
*pim
;
5128 v
= vrf_lookup_by_name(vrf
? vrf
: VRF_DEFAULT_NAME
);
5136 vty_out(vty
, "%% Unable to find pim instance\n");
5141 pim_show_interface_traffic_single(v
->info
, vty
, if_name
, uj
);
5143 pim_show_interface_traffic(v
->info
, vty
, uj
);
5148 void clear_pim_interfaces(struct pim_instance
*pim
)
5150 struct interface
*ifp
;
5152 FOR_ALL_INTERFACES (pim
->vrf
, ifp
) {
5154 pim_neighbor_delete_all(ifp
, "interface cleared");