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
, "%s",
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 if (pim_addr_is_any(rp_addr
) || pim_addr_is_multicast(rp_addr
)) {
570 vty_out(vty
, "%% Bad RP address specified: %s\n", rp_str
);
571 return CMD_WARNING_CONFIG_FAILED
;
575 if (IN6_IS_ADDR_LINKLOCAL(&rp_addr
)) {
576 vty_out(vty
, "%% Bad RP address specified: %s\n", rp_str
);
577 return CMD_WARNING_CONFIG_FAILED
;
581 vrfname
= pim_cli_get_vrf_name(vty
);
583 return CMD_WARNING_CONFIG_FAILED
;
585 snprintf(rp_group_xpath
, sizeof(rp_group_xpath
),
586 FRR_PIM_STATIC_RP_XPATH
, "frr-pim:pimd", "pim", vrfname
,
587 FRR_PIM_AF_XPATH_VAL
, rp_str
);
588 strlcat(rp_group_xpath
, "/group-list", sizeof(rp_group_xpath
));
590 nb_cli_enqueue_change(vty
, rp_group_xpath
, NB_OP_CREATE
, group_str
);
592 return nb_cli_apply_changes(vty
, NULL
);
595 int pim_process_no_rp_cmd(struct vty
*vty
, const char *rp_str
,
596 const char *group_str
)
598 char group_list_xpath
[XPATH_MAXLEN
];
599 char group_xpath
[XPATH_MAXLEN
];
600 char rp_xpath
[XPATH_MAXLEN
];
603 const struct lyd_node
*group_dnode
;
605 vrfname
= pim_cli_get_vrf_name(vty
);
607 return CMD_WARNING_CONFIG_FAILED
;
609 snprintf(rp_xpath
, sizeof(rp_xpath
), FRR_PIM_STATIC_RP_XPATH
,
610 "frr-pim:pimd", "pim", vrfname
, FRR_PIM_AF_XPATH_VAL
, rp_str
);
612 printed
= snprintf(group_list_xpath
, sizeof(group_list_xpath
),
613 "%s/group-list", rp_xpath
);
615 if (printed
>= (int)(sizeof(group_list_xpath
))) {
616 vty_out(vty
, "Xpath too long (%d > %u)", printed
+ 1,
618 return CMD_WARNING_CONFIG_FAILED
;
621 printed
= snprintf(group_xpath
, sizeof(group_xpath
), "%s[.='%s']",
622 group_list_xpath
, group_str
);
624 if (printed
>= (int)(sizeof(group_xpath
))) {
625 vty_out(vty
, "Xpath too long (%d > %u)", printed
+ 1,
627 return CMD_WARNING_CONFIG_FAILED
;
630 group_dnode
= yang_dnode_get(vty
->candidate_config
->dnode
, group_xpath
);
632 vty_out(vty
, "%% Unable to find specified RP\n");
636 if (yang_is_last_list_dnode(group_dnode
))
637 nb_cli_enqueue_change(vty
, rp_xpath
, NB_OP_DESTROY
, NULL
);
639 nb_cli_enqueue_change(vty
, group_list_xpath
, NB_OP_DESTROY
,
642 return nb_cli_apply_changes(vty
, NULL
);
645 int pim_process_rp_plist_cmd(struct vty
*vty
, const char *rp_str
,
646 const char *prefix_list
)
649 char rp_plist_xpath
[XPATH_MAXLEN
];
651 vrfname
= pim_cli_get_vrf_name(vty
);
653 return CMD_WARNING_CONFIG_FAILED
;
655 snprintf(rp_plist_xpath
, sizeof(rp_plist_xpath
),
656 FRR_PIM_STATIC_RP_XPATH
, "frr-pim:pimd", "pim", vrfname
,
657 FRR_PIM_AF_XPATH_VAL
, rp_str
);
658 strlcat(rp_plist_xpath
, "/prefix-list", sizeof(rp_plist_xpath
));
660 nb_cli_enqueue_change(vty
, rp_plist_xpath
, NB_OP_MODIFY
, prefix_list
);
662 return nb_cli_apply_changes(vty
, NULL
);
665 int pim_process_no_rp_plist_cmd(struct vty
*vty
, const char *rp_str
,
666 const char *prefix_list
)
668 char rp_xpath
[XPATH_MAXLEN
];
669 char plist_xpath
[XPATH_MAXLEN
];
671 const struct lyd_node
*plist_dnode
;
674 vrfname
= pim_cli_get_vrf_name(vty
);
676 return CMD_WARNING_CONFIG_FAILED
;
678 snprintf(rp_xpath
, sizeof(rp_xpath
), FRR_PIM_STATIC_RP_XPATH
,
679 "frr-pim:pimd", "pim", vrfname
, FRR_PIM_AF_XPATH_VAL
, rp_str
);
681 snprintf(plist_xpath
, sizeof(plist_xpath
), FRR_PIM_STATIC_RP_XPATH
,
682 "frr-pim:pimd", "pim", vrfname
, FRR_PIM_AF_XPATH_VAL
, rp_str
);
683 strlcat(plist_xpath
, "/prefix-list", sizeof(plist_xpath
));
685 plist_dnode
= yang_dnode_get(vty
->candidate_config
->dnode
, plist_xpath
);
687 vty_out(vty
, "%% Unable to find specified RP\n");
691 plist
= yang_dnode_get_string(plist_dnode
, "%s", plist_xpath
);
692 if (strcmp(prefix_list
, plist
)) {
693 vty_out(vty
, "%% Unable to find specified RP\n");
697 nb_cli_enqueue_change(vty
, rp_xpath
, NB_OP_DESTROY
, NULL
);
699 return nb_cli_apply_changes(vty
, NULL
);
702 bool pim_sgaddr_match(pim_sgaddr item
, pim_sgaddr match
)
704 return (pim_addr_is_any(match
.grp
) ||
705 !pim_addr_cmp(match
.grp
, item
.grp
)) &&
706 (pim_addr_is_any(match
.src
) ||
707 !pim_addr_cmp(match
.src
, item
.src
));
710 void json_object_pim_ifp_add(struct json_object
*json
, struct interface
*ifp
)
712 struct pim_interface
*pim_ifp
;
715 json_object_string_add(json
, "name", ifp
->name
);
716 json_object_string_add(json
, "state", if_is_up(ifp
) ? "up" : "down");
717 json_object_string_addf(json
, "address", "%pPA",
718 &pim_ifp
->primary_address
);
719 json_object_int_add(json
, "index", ifp
->ifindex
);
721 if (if_is_multicast(ifp
))
722 json_object_boolean_true_add(json
, "flagMulticast");
724 if (if_is_broadcast(ifp
))
725 json_object_boolean_true_add(json
, "flagBroadcast");
727 if (ifp
->flags
& IFF_ALLMULTI
)
728 json_object_boolean_true_add(json
, "flagAllMulticast");
730 if (ifp
->flags
& IFF_PROMISC
)
731 json_object_boolean_true_add(json
, "flagPromiscuous");
733 if (PIM_IF_IS_DELETED(ifp
))
734 json_object_boolean_true_add(json
, "flagDeleted");
736 if (pim_if_lan_delay_enabled(ifp
))
737 json_object_boolean_true_add(json
, "lanDelayEnabled");
740 void pim_print_ifp_flags(struct vty
*vty
, struct interface
*ifp
)
742 vty_out(vty
, "Flags\n");
743 vty_out(vty
, "-----\n");
744 vty_out(vty
, "All Multicast : %s\n",
745 (ifp
->flags
& IFF_ALLMULTI
) ? "yes" : "no");
746 vty_out(vty
, "Broadcast : %s\n",
747 if_is_broadcast(ifp
) ? "yes" : "no");
748 vty_out(vty
, "Deleted : %s\n",
749 PIM_IF_IS_DELETED(ifp
) ? "yes" : "no");
750 vty_out(vty
, "Interface Index : %d\n", ifp
->ifindex
);
751 vty_out(vty
, "Multicast : %s\n",
752 if_is_multicast(ifp
) ? "yes" : "no");
753 vty_out(vty
, "Promiscuous : %s\n",
754 (ifp
->flags
& IFF_PROMISC
) ? "yes" : "no");
759 void json_object_pim_upstream_add(json_object
*json
, struct pim_upstream
*up
)
761 json_object_boolean_add(
762 json
, "drJoinDesired",
763 CHECK_FLAG(up
->flags
, PIM_UPSTREAM_FLAG_MASK_DR_JOIN_DESIRED
));
764 json_object_boolean_add(
765 json
, "drJoinDesiredUpdated",
766 CHECK_FLAG(up
->flags
,
767 PIM_UPSTREAM_FLAG_MASK_DR_JOIN_DESIRED_UPDATED
));
768 json_object_boolean_add(
769 json
, "firstHopRouter",
770 CHECK_FLAG(up
->flags
, PIM_UPSTREAM_FLAG_MASK_FHR
));
771 json_object_boolean_add(
773 CHECK_FLAG(up
->flags
, PIM_UPSTREAM_FLAG_MASK_SRC_IGMP
));
774 json_object_boolean_add(
776 CHECK_FLAG(up
->flags
, PIM_UPSTREAM_FLAG_MASK_SRC_PIM
));
777 json_object_boolean_add(
778 json
, "sourceStream",
779 CHECK_FLAG(up
->flags
, PIM_UPSTREAM_FLAG_MASK_SRC_STREAM
));
780 /* XXX: need to print ths flag in the plain text display as well */
781 json_object_boolean_add(
783 CHECK_FLAG(up
->flags
, PIM_UPSTREAM_FLAG_MASK_SRC_MSDP
));
784 json_object_boolean_add(
785 json
, "sendSGRptPrune",
786 CHECK_FLAG(up
->flags
,
787 PIM_UPSTREAM_FLAG_MASK_SEND_SG_RPT_PRUNE
));
788 json_object_boolean_add(
789 json
, "lastHopRouter",
790 CHECK_FLAG(up
->flags
, PIM_UPSTREAM_FLAG_MASK_SRC_LHR
));
791 json_object_boolean_add(
792 json
, "disableKATExpiry",
793 CHECK_FLAG(up
->flags
,
794 PIM_UPSTREAM_FLAG_MASK_DISABLE_KAT_EXPIRY
));
795 json_object_boolean_add(
796 json
, "staticIncomingInterface",
797 CHECK_FLAG(up
->flags
, PIM_UPSTREAM_FLAG_MASK_STATIC_IIF
));
798 json_object_boolean_add(
799 json
, "allowIncomingInterfaceinOil",
800 CHECK_FLAG(up
->flags
, PIM_UPSTREAM_FLAG_MASK_ALLOW_IIF_IN_OIL
));
801 json_object_boolean_add(
802 json
, "noPimRegistrationData",
803 CHECK_FLAG(up
->flags
, PIM_UPSTREAM_FLAG_MASK_NO_PIMREG_DATA
));
804 json_object_boolean_add(
805 json
, "forcePimRegistration",
806 CHECK_FLAG(up
->flags
, PIM_UPSTREAM_FLAG_MASK_FORCE_PIMREG
));
807 json_object_boolean_add(
808 json
, "sourceVxlanOrigination",
809 CHECK_FLAG(up
->flags
, PIM_UPSTREAM_FLAG_MASK_SRC_VXLAN_ORIG
));
810 json_object_boolean_add(
811 json
, "sourceVxlanTermination",
812 CHECK_FLAG(up
->flags
, PIM_UPSTREAM_FLAG_MASK_SRC_VXLAN_TERM
));
813 json_object_boolean_add(
815 CHECK_FLAG(up
->flags
, PIM_UPSTREAM_FLAG_MASK_MLAG_VXLAN
));
816 json_object_boolean_add(
817 json
, "mlagNonDesignatedForwarder",
818 CHECK_FLAG(up
->flags
, PIM_UPSTREAM_FLAG_MASK_MLAG_NON_DF
));
822 pim_upstream_state2brief_str(enum pim_upstream_state join_state
,
823 char *state_str
, size_t state_str_len
)
825 switch (join_state
) {
826 case PIM_UPSTREAM_NOTJOINED
:
827 strlcpy(state_str
, "NotJ", state_str_len
);
829 case PIM_UPSTREAM_JOINED
:
830 strlcpy(state_str
, "J", state_str_len
);
833 strlcpy(state_str
, "Unk", state_str_len
);
838 static const char *pim_reg_state2brief_str(enum pim_reg_state reg_state
,
840 size_t state_str_len
)
844 strlcpy(state_str
, "RegNI", state_str_len
);
847 strlcpy(state_str
, "RegJ", state_str_len
);
849 case PIM_REG_JOIN_PENDING
:
851 strlcpy(state_str
, "RegP", state_str_len
);
857 void pim_show_rpf_refresh_stats(struct vty
*vty
, struct pim_instance
*pim
,
858 time_t now
, json_object
*json
)
860 char refresh_uptime
[10];
862 pim_time_uptime_begin(refresh_uptime
, sizeof(refresh_uptime
), now
,
863 pim
->rpf_cache_refresh_last
);
866 json_object_int_add(json
, "rpfCacheRefreshDelayMsecs",
867 router
->rpf_cache_refresh_delay_msec
);
869 json
, "rpfCacheRefreshTimer",
870 pim_time_timer_remain_msec(pim
->rpf_cache_refresher
));
871 json_object_int_add(json
, "rpfCacheRefreshRequests",
872 pim
->rpf_cache_refresh_requests
);
873 json_object_int_add(json
, "rpfCacheRefreshEvents",
874 pim
->rpf_cache_refresh_events
);
875 json_object_string_add(json
, "rpfCacheRefreshLast",
877 json_object_int_add(json
, "nexthopLookups",
878 pim
->nexthop_lookups
);
879 json_object_int_add(json
, "nexthopLookupsAvoided",
880 pim
->nexthop_lookups_avoided
);
883 "RPF Cache Refresh Delay: %ld msecs\n"
884 "RPF Cache Refresh Timer: %ld msecs\n"
885 "RPF Cache Refresh Requests: %lld\n"
886 "RPF Cache Refresh Events: %lld\n"
887 "RPF Cache Refresh Last: %s\n"
888 "Nexthop Lookups: %lld\n"
889 "Nexthop Lookups Avoided: %lld\n",
890 router
->rpf_cache_refresh_delay_msec
,
891 pim_time_timer_remain_msec(pim
->rpf_cache_refresher
),
892 (long long)pim
->rpf_cache_refresh_requests
,
893 (long long)pim
->rpf_cache_refresh_events
,
894 refresh_uptime
, (long long)pim
->nexthop_lookups
,
895 (long long)pim
->nexthop_lookups_avoided
);
899 void pim_show_rpf(struct pim_instance
*pim
, struct vty
*vty
, json_object
*json
)
901 struct pim_upstream
*up
;
902 time_t now
= pim_time_monotonic_sec();
903 struct ttable
*tt
= NULL
;
905 json_object
*json_group
= NULL
;
906 json_object
*json_row
= NULL
;
908 pim_show_rpf_refresh_stats(vty
, pim
, now
, json
);
914 tt
= ttable_new(&ttable_styles
[TTSTYLE_BLANK
]);
917 "Source|Group|RpfIface|RpfAddress|RibNextHop|Metric|Pref");
918 tt
->style
.cell
.rpad
= 2;
919 tt
->style
.corner
= '+';
923 frr_each (rb_pim_upstream
, &pim
->upstream_head
, up
) {
924 const char *rpf_ifname
;
925 struct pim_rpf
*rpf
= &up
->rpf
;
928 rpf
->source_nexthop
.interface
? rpf
->source_nexthop
933 char grp_str
[PIM_ADDRSTRLEN
];
934 char src_str
[PIM_ADDRSTRLEN
];
936 snprintfrr(grp_str
, sizeof(grp_str
), "%pPAs",
938 snprintfrr(src_str
, sizeof(src_str
), "%pPAs",
941 json_object_object_get_ex(json
, grp_str
, &json_group
);
944 json_group
= json_object_new_object();
945 json_object_object_add(json
, grp_str
,
949 json_row
= json_object_new_object();
950 json_object_string_add(json_row
, "source", src_str
);
951 json_object_string_add(json_row
, "group", grp_str
);
952 json_object_string_add(json_row
, "rpfInterface",
954 json_object_string_addf(json_row
, "rpfAddress", "%pPA",
956 json_object_string_addf(
957 json_row
, "ribNexthop", "%pPAs",
958 &rpf
->source_nexthop
.mrib_nexthop_addr
);
960 json_row
, "routeMetric",
961 rpf
->source_nexthop
.mrib_route_metric
);
963 json_row
, "routePreference",
964 rpf
->source_nexthop
.mrib_metric_preference
);
965 json_object_object_add(json_group
, src_str
, json_row
);
969 tt
, "%pPAs|%pPAs|%s|%pPA|%pPAs|%d|%d",
970 &up
->sg
.src
, &up
->sg
.grp
, rpf_ifname
,
972 &rpf
->source_nexthop
.mrib_nexthop_addr
,
973 rpf
->source_nexthop
.mrib_route_metric
,
974 rpf
->source_nexthop
.mrib_metric_preference
);
977 /* Dump the generated table. */
979 table
= ttable_dump(tt
, "\n");
980 vty_out(vty
, "%s\n", table
);
981 XFREE(MTYPE_TMP
, table
);
986 void pim_show_neighbors_secondary(struct pim_instance
*pim
, struct vty
*vty
)
988 struct interface
*ifp
;
989 struct ttable
*tt
= NULL
;
993 tt
= ttable_new(&ttable_styles
[TTSTYLE_BLANK
]);
994 ttable_add_row(tt
, "Interface|Address|Neighbor|Secondary");
995 tt
->style
.cell
.rpad
= 2;
996 tt
->style
.corner
= '+';
999 FOR_ALL_INTERFACES (pim
->vrf
, ifp
) {
1000 struct pim_interface
*pim_ifp
;
1002 struct listnode
*neighnode
;
1003 struct pim_neighbor
*neigh
;
1005 pim_ifp
= ifp
->info
;
1010 if (pim_ifp
->pim_sock_fd
< 0)
1013 ifaddr
= pim_ifp
->primary_address
;
1015 for (ALL_LIST_ELEMENTS_RO(pim_ifp
->pim_neighbor_list
, neighnode
,
1017 struct listnode
*prefix_node
;
1020 if (!neigh
->prefix_list
)
1023 for (ALL_LIST_ELEMENTS_RO(neigh
->prefix_list
,
1025 ttable_add_row(tt
, "%s|%pPAs|%pPAs|%pFX",
1027 &neigh
->source_addr
, p
);
1030 /* Dump the generated table. */
1031 table
= ttable_dump(tt
, "\n");
1032 vty_out(vty
, "%s\n", table
);
1033 XFREE(MTYPE_TMP
, table
);
1037 void pim_show_state(struct pim_instance
*pim
, struct vty
*vty
,
1038 const char *src_or_group
, const char *group
,
1041 struct channel_oil
*c_oil
;
1043 struct ttable
*tt
= NULL
;
1047 json_object
*json_group
= NULL
;
1048 json_object
*json_ifp_in
= NULL
;
1049 json_object
*json_ifp_out
= NULL
;
1050 json_object
*json_source
= NULL
;
1054 now
= pim_time_monotonic_sec();
1058 "Codes: J -> Pim Join, I -> " GM
" Report, S -> Source, * -> Inherited from (*,G), V -> VxLAN, M -> Muted\n");
1061 "Active Source Group RPT IIF OIL\n");
1063 /* Prepare table. */
1064 tt
= ttable_new(&ttable_styles
[TTSTYLE_BLANK
]);
1065 ttable_add_row(tt
, "Active|Source|Group|RPT|IIF|OIL");
1066 tt
->style
.cell
.rpad
= 2;
1067 tt
->style
.corner
= '+';
1072 frr_each (rb_pim_oil
, &pim
->channel_oil_head
, c_oil
) {
1073 char src_str
[PIM_ADDRSTRLEN
];
1074 char grp_str
[PIM_ADDRSTRLEN
];
1075 char in_ifname
[INTERFACE_NAMSIZ
+ 1];
1076 char out_ifname
[INTERFACE_NAMSIZ
+ 1];
1078 struct interface
*ifp_in
;
1084 PIM_UPSTREAM_FLAG_TEST_USE_RPT(c_oil
->up
->flags
)) ||
1085 pim_addr_is_any(*oil_origin(c_oil
)))
1090 snprintfrr(grp_str
, sizeof(grp_str
), "%pPAs",
1091 oil_mcastgrp(c_oil
));
1092 snprintfrr(src_str
, sizeof(src_str
), "%pPAs",
1094 ifp_in
= pim_if_find_by_vif_index(pim
, *oil_parent(c_oil
));
1097 strlcpy(in_ifname
, ifp_in
->name
, sizeof(in_ifname
));
1099 strlcpy(in_ifname
, "<iif?>", sizeof(in_ifname
));
1102 if (strcmp(src_or_group
, src_str
) &&
1103 strcmp(src_or_group
, grp_str
))
1106 if (group
&& strcmp(group
, grp_str
))
1112 /* Find the group, create it if it doesn't exist */
1113 json_object_object_get_ex(json
, grp_str
, &json_group
);
1116 json_group
= json_object_new_object();
1117 json_object_object_add(json
, grp_str
,
1121 /* Find the source nested under the group, create it if
1124 json_object_object_get_ex(json_group
, src_str
,
1128 json_source
= json_object_new_object();
1129 json_object_object_add(json_group
, src_str
,
1133 /* Find the inbound interface nested under the source,
1134 * create it if it doesn't exist
1136 json_object_object_get_ex(json_source
, in_ifname
,
1140 json_ifp_in
= json_object_new_object();
1141 json_object_object_add(json_source
, in_ifname
,
1143 json_object_int_add(json_source
, "installed",
1145 json_object_boolean_add(json_source
, "isRpt",
1147 json_object_int_add(json_source
, "refCount",
1148 c_oil
->oil_ref_count
);
1149 json_object_int_add(json_source
, "oilListSize",
1151 json_object_int_add(
1152 json_source
, "oilRescan",
1153 c_oil
->oil_inherited_rescan
);
1154 json_object_int_add(json_source
, "lastUsed",
1155 c_oil
->cc
.lastused
);
1156 json_object_int_add(json_source
, "packetCount",
1158 json_object_int_add(json_source
, "byteCount",
1160 json_object_int_add(json_source
,
1162 c_oil
->cc
.wrong_if
);
1167 vty_out(vty
, "%-6d %-15pPAs %-15pPAs %-3s %-16s ",
1168 c_oil
->installed
, oil_origin(c_oil
),
1169 oil_mcastgrp(c_oil
), isRpt
? "y" : "n",
1173 for (oif_vif_index
= 0; oif_vif_index
< MAXVIFS
;
1175 struct interface
*ifp_out
;
1176 char oif_uptime
[10];
1179 ttl
= oil_if_has(c_oil
, oif_vif_index
);
1183 ifp_out
= pim_if_find_by_vif_index(pim
, oif_vif_index
);
1185 oif_uptime
, sizeof(oif_uptime
),
1186 now
- c_oil
->oif_creation
[oif_vif_index
]);
1189 strlcpy(out_ifname
, ifp_out
->name
,
1190 sizeof(out_ifname
));
1192 strlcpy(out_ifname
, "<oif?>",
1193 sizeof(out_ifname
));
1196 json_ifp_out
= json_object_new_object();
1197 json_object_string_add(json_ifp_out
, "source",
1199 json_object_string_add(json_ifp_out
, "group",
1201 json_object_string_add(json_ifp_out
,
1204 json_object_string_add(json_ifp_out
,
1205 "outboundInterface",
1207 json_object_int_add(json_ifp_out
, "installed",
1210 json_object_object_add(json_ifp_in
, out_ifname
,
1214 snprintf(flag
, sizeof(flag
), "(%c%c%c%c%c)",
1215 (c_oil
->oif_flags
[oif_vif_index
] &
1216 PIM_OIF_FLAG_PROTO_GM
)
1219 (c_oil
->oif_flags
[oif_vif_index
] &
1220 PIM_OIF_FLAG_PROTO_PIM
)
1223 (c_oil
->oif_flags
[oif_vif_index
] &
1224 PIM_OIF_FLAG_PROTO_VXLAN
)
1227 (c_oil
->oif_flags
[oif_vif_index
] &
1228 PIM_OIF_FLAG_PROTO_STAR
)
1231 (c_oil
->oif_flags
[oif_vif_index
] &
1239 vty_out(vty
, "%s%s", out_ifname
, flag
);
1242 tt
, "%d|%pPAs|%pPAs|%s|%s|%s%s",
1245 oil_mcastgrp(c_oil
),
1246 isRpt
? "y" : "n", in_ifname
,
1251 vty_out(vty
, ", %s%s", out_ifname
,
1255 "%c|%c|%c|%c|%c|%s%s",
1256 ' ', ' ', ' ', ' ', ' ',
1268 /* Dump the generated table. */
1273 table
= ttable_dump(tt
, "\n");
1274 vty_out(vty
, "%s\n", table
);
1275 XFREE(MTYPE_TMP
, table
);
1281 /* pim statistics - just adding only bsm related now.
1282 * We can continue to add all pim related stats here.
1284 void pim_show_statistics(struct pim_instance
*pim
, struct vty
*vty
,
1285 const char *ifname
, bool uj
)
1287 json_object
*json
= NULL
;
1288 struct interface
*ifp
;
1291 json
= json_object_new_object();
1292 json_object_int_add(json
, "bsmRx", pim
->bsm_rcvd
);
1293 json_object_int_add(json
, "bsmTx", pim
->bsm_sent
);
1294 json_object_int_add(json
, "bsmDropped", pim
->bsm_dropped
);
1296 vty_out(vty
, "BSM Statistics :\n");
1297 vty_out(vty
, "----------------\n");
1298 vty_out(vty
, "Number of Received BSMs : %" PRIu64
"\n",
1300 vty_out(vty
, "Number of Forwared BSMs : %" PRIu64
"\n",
1302 vty_out(vty
, "Number of Dropped BSMs : %" PRIu64
"\n",
1308 /* scan interfaces */
1309 FOR_ALL_INTERFACES (pim
->vrf
, ifp
) {
1310 struct pim_interface
*pim_ifp
= ifp
->info
;
1312 if (ifname
&& strcmp(ifname
, ifp
->name
))
1319 vty_out(vty
, "Interface : %s\n", ifp
->name
);
1320 vty_out(vty
, "-------------------\n");
1322 "Number of BSMs dropped due to config miss : %u\n",
1323 pim_ifp
->pim_ifstat_bsm_cfg_miss
);
1324 vty_out(vty
, "Number of unicast BSMs dropped : %u\n",
1325 pim_ifp
->pim_ifstat_ucast_bsm_cfg_miss
);
1327 "Number of BSMs dropped due to invalid scope zone : %u\n",
1328 pim_ifp
->pim_ifstat_bsm_invalid_sz
);
1331 json_object
*json_row
= NULL
;
1333 json_row
= json_object_new_object();
1335 json_object_string_add(json_row
, "If Name", ifp
->name
);
1336 json_object_int_add(json_row
, "bsmDroppedConfig",
1337 pim_ifp
->pim_ifstat_bsm_cfg_miss
);
1338 json_object_int_add(
1339 json_row
, "bsmDroppedUnicast",
1340 pim_ifp
->pim_ifstat_ucast_bsm_cfg_miss
);
1341 json_object_int_add(json_row
,
1342 "bsmDroppedInvalidScopeZone",
1343 pim_ifp
->pim_ifstat_bsm_invalid_sz
);
1344 json_object_object_add(json
, ifp
->name
, json_row
);
1350 vty_json(vty
, json
);
1353 void pim_show_upstream(struct pim_instance
*pim
, struct vty
*vty
,
1354 pim_sgaddr
*sg
, json_object
*json
)
1356 struct pim_upstream
*up
;
1357 struct ttable
*tt
= NULL
;
1360 json_object
*json_group
= NULL
;
1361 json_object
*json_row
= NULL
;
1363 now
= pim_time_monotonic_sec();
1366 /* Prepare table. */
1367 tt
= ttable_new(&ttable_styles
[TTSTYLE_BLANK
]);
1370 "Iif|Source|Group|State|Uptime|JoinTimer|RSTimer|KATimer|RefCnt");
1371 tt
->style
.cell
.rpad
= 2;
1372 tt
->style
.corner
= '+';
1376 frr_each (rb_pim_upstream
, &pim
->upstream_head
, up
) {
1378 char join_timer
[10];
1381 char msdp_reg_timer
[10];
1382 char state_str
[PIM_REG_STATE_STR_LEN
];
1384 if (!pim_sgaddr_match(up
->sg
, *sg
))
1387 pim_time_uptime(uptime
, sizeof(uptime
),
1388 now
- up
->state_transition
);
1389 pim_time_timer_to_hhmmss(join_timer
, sizeof(join_timer
),
1393 * If the upstream is not dummy and it has a J/P timer for the
1394 * neighbor display that
1396 if (!up
->t_join_timer
&& up
->rpf
.source_nexthop
.interface
) {
1397 struct pim_neighbor
*nbr
;
1399 nbr
= pim_neighbor_find(
1400 up
->rpf
.source_nexthop
.interface
,
1403 pim_time_timer_to_hhmmss(join_timer
,
1408 pim_time_timer_to_hhmmss(rs_timer
, sizeof(rs_timer
),
1410 pim_time_timer_to_hhmmss(ka_timer
, sizeof(ka_timer
),
1412 pim_time_timer_to_hhmmss(msdp_reg_timer
, sizeof(msdp_reg_timer
),
1413 up
->t_msdp_reg_timer
);
1415 pim_upstream_state2brief_str(up
->join_state
, state_str
,
1417 if (up
->reg_state
!= PIM_REG_NOINFO
) {
1418 char tmp_str
[PIM_REG_STATE_STR_LEN
];
1419 char tmp
[sizeof(state_str
) + 1];
1421 snprintf(tmp
, sizeof(tmp
), ",%s",
1422 pim_reg_state2brief_str(up
->reg_state
, tmp_str
,
1424 strlcat(state_str
, tmp
, sizeof(state_str
));
1428 char grp_str
[PIM_ADDRSTRLEN
];
1429 char src_str
[PIM_ADDRSTRLEN
];
1431 snprintfrr(grp_str
, sizeof(grp_str
), "%pPAs",
1433 snprintfrr(src_str
, sizeof(src_str
), "%pPAs",
1436 json_object_object_get_ex(json
, grp_str
, &json_group
);
1439 json_group
= json_object_new_object();
1440 json_object_object_add(json
, grp_str
,
1444 json_row
= json_object_new_object();
1445 json_object_pim_upstream_add(json_row
, up
);
1446 json_object_string_add(
1447 json_row
, "inboundInterface",
1448 up
->rpf
.source_nexthop
.interface
1449 ? up
->rpf
.source_nexthop
.interface
->name
1453 * The RPF address we use is slightly different
1454 * based upon what we are looking up.
1455 * If we have a S, list that unless
1456 * we are the FHR, else we just put
1457 * the RP as the rpfAddress
1459 if (up
->flags
& PIM_UPSTREAM_FLAG_MASK_FHR
||
1460 pim_addr_is_any(up
->sg
.src
)) {
1461 struct pim_rpf
*rpg
;
1463 rpg
= RP(pim
, up
->sg
.grp
);
1464 json_object_string_addf(json_row
, "rpfAddress",
1465 "%pPA", &rpg
->rpf_addr
);
1467 json_object_string_add(json_row
, "rpfAddress",
1471 json_object_string_add(json_row
, "source", src_str
);
1472 json_object_string_add(json_row
, "group", grp_str
);
1473 json_object_string_add(json_row
, "state", state_str
);
1474 json_object_string_add(
1475 json_row
, "joinState",
1476 pim_upstream_state2str(up
->join_state
));
1477 json_object_string_add(
1478 json_row
, "regState",
1479 pim_reg_state2str(up
->reg_state
, state_str
,
1480 sizeof(state_str
)));
1481 json_object_string_add(json_row
, "upTime", uptime
);
1482 json_object_string_add(json_row
, "joinTimer",
1484 json_object_string_add(json_row
, "resetTimer",
1486 json_object_string_add(json_row
, "keepaliveTimer",
1488 json_object_string_add(json_row
, "msdpRegTimer",
1490 json_object_int_add(json_row
, "refCount",
1492 json_object_int_add(json_row
, "sptBit", up
->sptbit
);
1493 json_object_object_add(json_group
, src_str
, json_row
);
1496 "%s|%pPAs|%pPAs|%s|%s|%s|%s|%s|%d",
1497 up
->rpf
.source_nexthop
.interface
1498 ? up
->rpf
.source_nexthop
.interface
->name
1500 &up
->sg
.src
, &up
->sg
.grp
, state_str
, uptime
,
1501 join_timer
, rs_timer
, ka_timer
, up
->ref_count
);
1504 /* Dump the generated table. */
1506 table
= ttable_dump(tt
, "\n");
1507 vty_out(vty
, "%s\n", table
);
1508 XFREE(MTYPE_TMP
, table
);
1513 static void pim_show_join_desired_helper(struct pim_instance
*pim
,
1515 struct pim_upstream
*up
,
1516 json_object
*json
, bool uj
,
1519 json_object
*json_group
= NULL
;
1520 json_object
*json_row
= NULL
;
1523 char grp_str
[PIM_ADDRSTRLEN
];
1524 char src_str
[PIM_ADDRSTRLEN
];
1526 snprintfrr(grp_str
, sizeof(grp_str
), "%pPAs", &up
->sg
.grp
);
1527 snprintfrr(src_str
, sizeof(src_str
), "%pPAs", &up
->sg
.src
);
1529 json_object_object_get_ex(json
, grp_str
, &json_group
);
1532 json_group
= json_object_new_object();
1533 json_object_object_add(json
, grp_str
, json_group
);
1536 json_row
= json_object_new_object();
1537 json_object_pim_upstream_add(json_row
, up
);
1538 json_object_string_add(json_row
, "source", src_str
);
1539 json_object_string_add(json_row
, "group", grp_str
);
1541 if (pim_upstream_evaluate_join_desired(pim
, up
))
1542 json_object_boolean_true_add(json_row
,
1543 "evaluateJoinDesired");
1545 json_object_object_add(json_group
, src_str
, json_row
);
1548 ttable_add_row(tt
, "%pPAs|%pPAs|%s", &up
->sg
.src
, &up
->sg
.grp
,
1549 pim_upstream_evaluate_join_desired(pim
, up
)
1555 void pim_show_join_desired(struct pim_instance
*pim
, struct vty
*vty
, bool uj
)
1557 struct pim_upstream
*up
;
1558 struct ttable
*tt
= NULL
;
1561 json_object
*json
= NULL
;
1564 json
= json_object_new_object();
1566 /* Prepare table. */
1567 tt
= ttable_new(&ttable_styles
[TTSTYLE_BLANK
]);
1568 ttable_add_row(tt
, "Source|Group|EvalJD");
1569 tt
->style
.cell
.rpad
= 2;
1570 tt
->style
.corner
= '+';
1574 frr_each (rb_pim_upstream
, &pim
->upstream_head
, up
) {
1575 /* scan all interfaces */
1576 pim_show_join_desired_helper(pim
, vty
, up
, json
, uj
, tt
);
1580 vty_json(vty
, json
);
1582 /* Dump the generated table. */
1583 table
= ttable_dump(tt
, "\n");
1584 vty_out(vty
, "%s\n", table
);
1585 XFREE(MTYPE_TMP
, table
);
1590 void pim_show_upstream_rpf(struct pim_instance
*pim
, struct vty
*vty
, bool uj
)
1592 struct pim_upstream
*up
;
1593 struct ttable
*tt
= NULL
;
1595 json_object
*json
= NULL
;
1596 json_object
*json_group
= NULL
;
1597 json_object
*json_row
= NULL
;
1600 json
= json_object_new_object();
1602 /* Prepare table. */
1603 tt
= ttable_new(&ttable_styles
[TTSTYLE_BLANK
]);
1605 "Source|Group|RpfIface|RibNextHop|RpfAddress");
1606 tt
->style
.cell
.rpad
= 2;
1607 tt
->style
.corner
= '+';
1611 frr_each (rb_pim_upstream
, &pim
->upstream_head
, up
) {
1612 struct pim_rpf
*rpf
;
1613 const char *rpf_ifname
;
1618 rpf
->source_nexthop
.interface
? rpf
->source_nexthop
1623 char grp_str
[PIM_ADDRSTRLEN
];
1624 char src_str
[PIM_ADDRSTRLEN
];
1626 snprintfrr(grp_str
, sizeof(grp_str
), "%pPAs",
1628 snprintfrr(src_str
, sizeof(src_str
), "%pPAs",
1630 json_object_object_get_ex(json
, grp_str
, &json_group
);
1633 json_group
= json_object_new_object();
1634 json_object_object_add(json
, grp_str
,
1638 json_row
= json_object_new_object();
1639 json_object_pim_upstream_add(json_row
, up
);
1640 json_object_string_add(json_row
, "source", src_str
);
1641 json_object_string_add(json_row
, "group", grp_str
);
1642 json_object_string_add(json_row
, "rpfInterface",
1644 json_object_string_addf(
1645 json_row
, "ribNexthop", "%pPAs",
1646 &rpf
->source_nexthop
.mrib_nexthop_addr
);
1647 json_object_string_addf(json_row
, "rpfAddress", "%pPA",
1649 json_object_object_add(json_group
, src_str
, json_row
);
1651 ttable_add_row(tt
, "%pPAs|%pPAs|%s|%pPA|%pPA",
1652 &up
->sg
.src
, &up
->sg
.grp
, rpf_ifname
,
1653 &rpf
->source_nexthop
.mrib_nexthop_addr
,
1659 vty_json(vty
, json
);
1661 /* Dump the generated table. */
1662 table
= ttable_dump(tt
, "\n");
1663 vty_out(vty
, "%s\n", table
);
1664 XFREE(MTYPE_TMP
, table
);
1669 static void pim_show_join_helper(struct pim_interface
*pim_ifp
,
1670 struct pim_ifchannel
*ch
, json_object
*json
,
1671 time_t now
, struct ttable
*tt
)
1673 json_object
*json_iface
= NULL
;
1674 json_object
*json_row
= NULL
;
1675 json_object
*json_grp
= NULL
;
1681 ifaddr
= pim_ifp
->primary_address
;
1683 pim_time_uptime_begin(uptime
, sizeof(uptime
), now
, ch
->ifjoin_creation
);
1684 pim_time_timer_to_mmss(expire
, sizeof(expire
),
1685 ch
->t_ifjoin_expiry_timer
);
1686 pim_time_timer_to_mmss(prune
, sizeof(prune
),
1687 ch
->t_ifjoin_prune_pending_timer
);
1690 char ch_grp_str
[PIM_ADDRSTRLEN
];
1692 json_object_object_get_ex(json
, ch
->interface
->name
,
1696 json_iface
= json_object_new_object();
1697 json_object_pim_ifp_add(json_iface
, ch
->interface
);
1698 json_object_object_add(json
, ch
->interface
->name
,
1702 json_row
= json_object_new_object();
1703 json_object_string_addf(json_row
, "source", "%pPAs",
1705 json_object_string_addf(json_row
, "group", "%pPAs",
1707 json_object_string_add(json_row
, "upTime", uptime
);
1708 json_object_string_add(json_row
, "expire", expire
);
1709 json_object_string_add(json_row
, "prune", prune
);
1710 json_object_string_add(
1711 json_row
, "channelJoinName",
1712 pim_ifchannel_ifjoin_name(ch
->ifjoin_state
, ch
->flags
));
1713 if (PIM_IF_FLAG_TEST_S_G_RPT(ch
->flags
))
1714 json_object_int_add(json_row
, "sgRpt", 1);
1715 if (PIM_IF_FLAG_TEST_PROTO_PIM(ch
->flags
))
1716 json_object_int_add(json_row
, "protocolPim", 1);
1717 if (PIM_IF_FLAG_TEST_PROTO_IGMP(ch
->flags
))
1718 json_object_int_add(json_row
, "protocolIgmp", 1);
1719 snprintfrr(ch_grp_str
, sizeof(ch_grp_str
), "%pPAs",
1721 json_object_object_get_ex(json_iface
, ch_grp_str
, &json_grp
);
1723 json_grp
= json_object_new_object();
1724 json_object_object_addf(json_grp
, json_row
, "%pPAs",
1726 json_object_object_addf(json_iface
, json_grp
, "%pPAs",
1729 json_object_object_addf(json_grp
, json_row
, "%pPAs",
1733 tt
, "%s|%pPAs|%pPAs|%pPAs|%s|%s|%s|%s",
1734 ch
->interface
->name
, &ifaddr
, &ch
->sg
.src
, &ch
->sg
.grp
,
1735 pim_ifchannel_ifjoin_name(ch
->ifjoin_state
, ch
->flags
),
1736 uptime
, expire
, prune
);
1740 int pim_show_join_cmd_helper(const char *vrf
, struct vty
*vty
, pim_addr s_or_g
,
1741 pim_addr g
, const char *json
)
1745 struct pim_instance
*pim
;
1746 json_object
*json_parent
= NULL
;
1748 v
= vrf_lookup_by_name(vrf
? vrf
: VRF_DEFAULT_NAME
);
1751 vty_out(vty
, "%% Vrf specified: %s does not exist\n", vrf
);
1757 vty_out(vty
, "%% Unable to find pim instance\n");
1761 if (!pim_addr_is_any(s_or_g
)) {
1762 if (!pim_addr_is_any(g
)) {
1770 json_parent
= json_object_new_object();
1772 pim_show_join(pim
, vty
, &sg
, json_parent
);
1775 vty_json(vty
, json_parent
);
1780 int pim_show_join_vrf_all_cmd_helper(struct vty
*vty
, const char *json
)
1782 pim_sgaddr sg
= {0};
1783 struct vrf
*vrf_struct
;
1784 json_object
*json_parent
= NULL
;
1785 json_object
*json_vrf
= NULL
;
1788 json_parent
= json_object_new_object();
1790 RB_FOREACH (vrf_struct
, vrf_name_head
, &vrfs_by_name
) {
1792 vty_out(vty
, "VRF: %s\n", vrf_struct
->name
);
1794 json_vrf
= json_object_new_object();
1795 pim_show_join(vrf_struct
->info
, vty
, &sg
, json_vrf
);
1798 json_object_object_add(json_parent
, vrf_struct
->name
,
1802 vty_json(vty
, json_parent
);
1807 void pim_show_join(struct pim_instance
*pim
, struct vty
*vty
, pim_sgaddr
*sg
,
1810 struct pim_interface
*pim_ifp
;
1811 struct pim_ifchannel
*ch
;
1812 struct interface
*ifp
;
1814 struct ttable
*tt
= NULL
;
1817 now
= pim_time_monotonic_sec();
1820 /* Prepare table. */
1821 tt
= ttable_new(&ttable_styles
[TTSTYLE_BLANK
]);
1824 "Interface|Address|Source|Group|State|Uptime|Expire|Prune");
1825 tt
->style
.cell
.rpad
= 2;
1826 tt
->style
.corner
= '+';
1830 FOR_ALL_INTERFACES (pim
->vrf
, ifp
) {
1831 pim_ifp
= ifp
->info
;
1835 RB_FOREACH (ch
, pim_ifchannel_rb
, &pim_ifp
->ifchannel_rb
) {
1836 if (!pim_sgaddr_match(ch
->sg
, *sg
))
1839 pim_show_join_helper(pim_ifp
, ch
, json
, now
, tt
);
1840 } /* scan interface channels */
1842 /* Dump the generated table. */
1844 table
= ttable_dump(tt
, "\n");
1845 vty_out(vty
, "%s\n", table
);
1846 XFREE(MTYPE_TMP
, table
);
1851 static void pim_show_jp_agg_helper(struct interface
*ifp
,
1852 struct pim_neighbor
*neigh
,
1853 struct pim_upstream
*up
, int is_join
,
1856 ttable_add_row(tt
, "%s|%pPAs|%pPAs|%pPAs|%s", ifp
->name
,
1857 &neigh
->source_addr
, &up
->sg
.src
, &up
->sg
.grp
,
1858 is_join
? "J" : "P");
1861 int pim_show_jp_agg_list_cmd_helper(const char *vrf
, struct vty
*vty
)
1864 struct pim_instance
*pim
;
1866 v
= vrf_lookup_by_name(vrf
? vrf
: VRF_DEFAULT_NAME
);
1869 vty_out(vty
, "%% Vrf specified: %s does not exist\n", vrf
);
1875 vty_out(vty
, "%% Unable to find pim instance\n");
1879 pim_show_jp_agg_list(pim
, vty
);
1884 void pim_show_jp_agg_list(struct pim_instance
*pim
, struct vty
*vty
)
1886 struct interface
*ifp
;
1887 struct pim_interface
*pim_ifp
;
1888 struct listnode
*n_node
;
1889 struct pim_neighbor
*neigh
;
1890 struct listnode
*jag_node
;
1891 struct pim_jp_agg_group
*jag
;
1892 struct listnode
*js_node
;
1893 struct pim_jp_sources
*js
;
1897 /* Prepare table. */
1898 tt
= ttable_new(&ttable_styles
[TTSTYLE_BLANK
]);
1899 ttable_add_row(tt
, "Interface|RPF Nbr|Source|Group|State");
1900 tt
->style
.cell
.rpad
= 2;
1901 tt
->style
.corner
= '+';
1904 FOR_ALL_INTERFACES (pim
->vrf
, ifp
) {
1905 pim_ifp
= ifp
->info
;
1909 for (ALL_LIST_ELEMENTS_RO(pim_ifp
->pim_neighbor_list
, n_node
,
1911 for (ALL_LIST_ELEMENTS_RO(neigh
->upstream_jp_agg
,
1913 for (ALL_LIST_ELEMENTS_RO(jag
->sources
, js_node
,
1915 pim_show_jp_agg_helper(ifp
, neigh
,
1923 /* Dump the generated table. */
1924 table
= ttable_dump(tt
, "\n");
1925 vty_out(vty
, "%s\n", table
);
1926 XFREE(MTYPE_TMP
, table
);
1930 int pim_show_membership_cmd_helper(const char *vrf
, struct vty
*vty
, bool uj
)
1934 v
= vrf_lookup_by_name(vrf
? vrf
: VRF_DEFAULT_NAME
);
1939 pim_show_membership(v
->info
, vty
, uj
);
1944 static void pim_show_membership_helper(struct vty
*vty
,
1945 struct pim_interface
*pim_ifp
,
1946 struct pim_ifchannel
*ch
,
1947 struct json_object
*json
)
1949 json_object
*json_iface
= NULL
;
1950 json_object
*json_row
= NULL
;
1952 json_object_object_get_ex(json
, ch
->interface
->name
, &json_iface
);
1954 json_iface
= json_object_new_object();
1955 json_object_pim_ifp_add(json_iface
, ch
->interface
);
1956 json_object_object_add(json
, ch
->interface
->name
, json_iface
);
1959 json_row
= json_object_new_object();
1960 json_object_string_addf(json_row
, "source", "%pPAs", &ch
->sg
.src
);
1961 json_object_string_addf(json_row
, "group", "%pPAs", &ch
->sg
.grp
);
1962 json_object_string_add(json_row
, "localMembership",
1963 ch
->local_ifmembership
== PIM_IFMEMBERSHIP_NOINFO
1966 json_object_object_addf(json_iface
, json_row
, "%pPAs", &ch
->sg
.grp
);
1969 void pim_show_membership(struct pim_instance
*pim
, struct vty
*vty
, bool uj
)
1971 struct pim_interface
*pim_ifp
;
1972 struct pim_ifchannel
*ch
;
1973 struct interface
*ifp
;
1974 enum json_type type
;
1975 json_object
*json
= NULL
;
1976 json_object
*json_tmp
= NULL
;
1977 struct ttable
*tt
= NULL
;
1980 json
= json_object_new_object();
1982 FOR_ALL_INTERFACES (pim
->vrf
, ifp
) {
1983 pim_ifp
= ifp
->info
;
1987 RB_FOREACH (ch
, pim_ifchannel_rb
, &pim_ifp
->ifchannel_rb
) {
1988 pim_show_membership_helper(vty
, pim_ifp
, ch
, json
);
1989 } /* scan interface channels */
1993 vty_json(vty
, json
);
1995 /* Prepare table. */
1996 tt
= ttable_new(&ttable_styles
[TTSTYLE_BLANK
]);
1997 ttable_add_row(tt
, "Interface|Address|Source|Group|Membership");
1998 tt
->style
.cell
.rpad
= 2;
1999 tt
->style
.corner
= '+';
2003 * Example of the json data we are traversing
2009 * "address":"10.1.20.1",
2011 * "flagMulticast":true,
2012 * "flagBroadcast":true,
2013 * "lanDelayEnabled":true,
2016 * "group":"226.10.10.10",
2017 * "localMembership":"INCLUDE"
2023 /* foreach interface */
2024 json_object_object_foreach(json
, key
, val
)
2027 /* Find all of the keys where the val is an object. In
2029 * above the only one is 226.10.10.10
2031 json_object_object_foreach(val
, if_field_key
,
2034 type
= json_object_get_type(if_field_val
);
2036 if (type
== json_type_object
) {
2037 const char *address
, *source
,
2040 json_object_object_get_ex(
2041 val
, "address", &json_tmp
);
2042 address
= json_object_get_string(
2045 json_object_object_get_ex(if_field_val
,
2048 source
= json_object_get_string(
2051 json_object_object_get_ex(
2052 if_field_val
, "localMembership",
2055 json_object_get_string(
2058 ttable_add_row(tt
, "%s|%s|%s|%s|%s",
2059 key
, address
, source
,
2065 json_object_free(json
);
2066 /* Dump the generated table. */
2067 table
= ttable_dump(tt
, "\n");
2068 vty_out(vty
, "%s\n", table
);
2069 XFREE(MTYPE_TMP
, table
);
2074 static void pim_show_channel_helper(struct pim_instance
*pim
,
2075 struct pim_interface
*pim_ifp
,
2076 struct pim_ifchannel
*ch
, json_object
*json
,
2077 bool uj
, struct ttable
*tt
)
2079 struct pim_upstream
*up
= ch
->upstream
;
2080 json_object
*json_group
= NULL
;
2081 json_object
*json_row
= NULL
;
2084 char grp_str
[PIM_ADDRSTRLEN
];
2086 snprintfrr(grp_str
, sizeof(grp_str
), "%pPAs", &up
->sg
.grp
);
2087 json_object_object_get_ex(json
, grp_str
, &json_group
);
2090 json_group
= json_object_new_object();
2091 json_object_object_add(json
, grp_str
, json_group
);
2094 json_row
= json_object_new_object();
2095 json_object_pim_upstream_add(json_row
, up
);
2096 json_object_string_add(json_row
, "interface",
2097 ch
->interface
->name
);
2098 json_object_string_addf(json_row
, "source", "%pPAs",
2100 json_object_string_addf(json_row
, "group", "%pPAs",
2103 if (pim_macro_ch_lost_assert(ch
))
2104 json_object_boolean_true_add(json_row
, "lostAssert");
2106 if (pim_macro_chisin_joins(ch
))
2107 json_object_boolean_true_add(json_row
, "joins");
2109 if (pim_macro_chisin_pim_include(ch
))
2110 json_object_boolean_true_add(json_row
, "pimInclude");
2112 if (pim_upstream_evaluate_join_desired(pim
, up
))
2113 json_object_boolean_true_add(json_row
,
2114 "evaluateJoinDesired");
2116 json_object_object_addf(json_group
, json_row
, "%pPAs",
2120 ttable_add_row(tt
, "%s|%pPAs|%pPAs|%s|%s|%s|%s|%s",
2121 ch
->interface
->name
, &up
->sg
.src
, &up
->sg
.grp
,
2122 pim_macro_ch_lost_assert(ch
) ? "yes" : "no",
2123 pim_macro_chisin_joins(ch
) ? "yes" : "no",
2124 pim_macro_chisin_pim_include(ch
) ? "yes" : "no",
2125 PIM_UPSTREAM_FLAG_TEST_DR_JOIN_DESIRED(up
->flags
)
2128 pim_upstream_evaluate_join_desired(pim
, up
)
2134 void pim_show_channel(struct pim_instance
*pim
, struct vty
*vty
, bool uj
)
2136 struct pim_interface
*pim_ifp
;
2137 struct pim_ifchannel
*ch
;
2138 struct interface
*ifp
;
2139 struct ttable
*tt
= NULL
;
2140 json_object
*json
= NULL
;
2144 json
= json_object_new_object();
2146 /* Prepare table. */
2147 tt
= ttable_new(&ttable_styles
[TTSTYLE_BLANK
]);
2150 "Interface|Source|Group|LostAssert|Joins|PimInclude|JoinDesired|EvalJD");
2151 tt
->style
.cell
.rpad
= 2;
2152 tt
->style
.corner
= '+';
2156 /* scan per-interface (S,G) state */
2157 FOR_ALL_INTERFACES (pim
->vrf
, ifp
) {
2158 pim_ifp
= ifp
->info
;
2162 RB_FOREACH (ch
, pim_ifchannel_rb
, &pim_ifp
->ifchannel_rb
) {
2163 /* scan all interfaces */
2164 pim_show_channel_helper(pim
, pim_ifp
, ch
, json
, uj
, tt
);
2169 vty_json(vty
, json
);
2171 /* Dump the generated table. */
2172 table
= ttable_dump(tt
, "\n");
2173 vty_out(vty
, "%s\n", table
);
2174 XFREE(MTYPE_TMP
, table
);
2179 int pim_show_channel_cmd_helper(const char *vrf
, struct vty
*vty
, bool uj
)
2183 v
= vrf_lookup_by_name(vrf
? vrf
: VRF_DEFAULT_NAME
);
2188 pim_show_channel(v
->info
, vty
, uj
);
2193 int pim_show_interface_cmd_helper(const char *vrf
, struct vty
*vty
, bool uj
,
2194 bool mlag
, const char *interface
)
2197 json_object
*json_parent
= NULL
;
2199 v
= vrf_lookup_by_name(vrf
? vrf
: VRF_DEFAULT_NAME
);
2205 json_parent
= json_object_new_object();
2208 pim_show_interfaces_single(v
->info
, vty
, interface
, mlag
,
2211 pim_show_interfaces(v
->info
, vty
, mlag
, json_parent
);
2214 vty_json(vty
, json_parent
);
2219 int pim_show_interface_vrf_all_cmd_helper(struct vty
*vty
, bool uj
, bool mlag
,
2220 const char *interface
)
2223 json_object
*json_parent
= NULL
;
2224 json_object
*json_vrf
= NULL
;
2227 json_parent
= json_object_new_object();
2229 RB_FOREACH (v
, vrf_name_head
, &vrfs_by_name
) {
2231 vty_out(vty
, "VRF: %s\n", v
->name
);
2233 json_vrf
= json_object_new_object();
2236 pim_show_interfaces_single(v
->info
, vty
, interface
,
2239 pim_show_interfaces(v
->info
, vty
, mlag
, json_vrf
);
2242 json_object_object_add(json_parent
, v
->name
, json_vrf
);
2245 vty_json(vty
, json_parent
);
2250 void pim_show_interfaces(struct pim_instance
*pim
, struct vty
*vty
, bool mlag
,
2253 struct interface
*ifp
;
2254 struct pim_interface
*pim_ifp
;
2255 struct pim_upstream
*up
;
2258 int pim_ifchannels
= 0;
2260 struct ttable
*tt
= NULL
;
2262 json_object
*json_row
= NULL
;
2263 json_object
*json_tmp
;
2267 json
= json_object_new_object();
2270 FOR_ALL_INTERFACES (pim
->vrf
, ifp
) {
2271 pim_ifp
= ifp
->info
;
2276 if (mlag
== true && pim_ifp
->activeactive
== false)
2279 pim_nbrs
= pim_ifp
->pim_neighbor_list
->count
;
2280 pim_ifchannels
= pim_if_ifchannel_count(pim_ifp
);
2283 frr_each (rb_pim_upstream
, &pim
->upstream_head
, up
)
2284 if (ifp
== up
->rpf
.source_nexthop
.interface
)
2285 if (up
->flags
& PIM_UPSTREAM_FLAG_MASK_FHR
)
2288 json_row
= json_object_new_object();
2289 json_object_pim_ifp_add(json_row
, ifp
);
2290 json_object_int_add(json_row
, "pimNeighbors", pim_nbrs
);
2291 json_object_int_add(json_row
, "pimIfChannels", pim_ifchannels
);
2292 json_object_int_add(json_row
, "firstHopRouterCount", fhr
);
2293 json_object_string_addf(json_row
, "pimDesignatedRouter",
2294 "%pPAs", &pim_ifp
->pim_dr_addr
);
2296 if (!pim_addr_cmp(pim_ifp
->pim_dr_addr
,
2297 pim_ifp
->primary_address
))
2298 json_object_boolean_true_add(
2299 json_row
, "pimDesignatedRouterLocal");
2301 json_object_object_add(json
, ifp
->name
, json_row
);
2306 /* Prepare table. */
2307 tt
= ttable_new(&ttable_styles
[TTSTYLE_BLANK
]);
2310 "Interface|State|Address|PIM Nbrs|PIM DR|FHR|IfChannels");
2311 tt
->style
.cell
.rpad
= 2;
2312 tt
->style
.corner
= '+';
2315 json_object_object_foreach(json
, key
, val
)
2317 const char *state
, *address
, *pimdr
;
2318 int neighbors
, firsthpr
, pimifchnl
;
2320 json_object_object_get_ex(val
, "state", &json_tmp
);
2321 state
= json_object_get_string(json_tmp
);
2323 json_object_object_get_ex(val
, "address", &json_tmp
);
2324 address
= json_object_get_string(json_tmp
);
2326 json_object_object_get_ex(val
, "pimNeighbors",
2328 neighbors
= json_object_get_int(json_tmp
);
2330 if (json_object_object_get_ex(
2331 val
, "pimDesignatedRouterLocal",
2335 json_object_object_get_ex(
2336 val
, "pimDesignatedRouter", &json_tmp
);
2337 pimdr
= json_object_get_string(json_tmp
);
2340 json_object_object_get_ex(val
, "firstHopRouter",
2342 firsthpr
= json_object_get_int(json_tmp
);
2344 json_object_object_get_ex(val
, "pimIfChannels",
2346 pimifchnl
= json_object_get_int(json_tmp
);
2348 ttable_add_row(tt
, "%s|%s|%s|%d|%s|%d|%d", key
, state
,
2349 address
, neighbors
, pimdr
, firsthpr
,
2352 json_object_free(json
);
2354 /* Dump the generated table. */
2355 table
= ttable_dump(tt
, "\n");
2356 vty_out(vty
, "%s\n", table
);
2357 XFREE(MTYPE_TMP
, table
);
2363 void pim_show_interfaces_single(struct pim_instance
*pim
, struct vty
*vty
,
2364 const char *ifname
, bool mlag
,
2368 struct interface
*ifp
;
2369 struct listnode
*neighnode
;
2370 struct pim_interface
*pim_ifp
;
2371 struct pim_neighbor
*neigh
;
2372 struct pim_upstream
*up
;
2374 char dr_str
[PIM_ADDRSTRLEN
];
2377 char grp_str
[PIM_ADDRSTRLEN
];
2378 char hello_period
[10];
2379 char hello_timer
[10];
2380 char neigh_src_str
[PIM_ADDRSTRLEN
];
2381 char src_str
[PIM_ADDRSTRLEN
];
2382 char stat_uptime
[10];
2384 int found_ifname
= 0;
2386 json_object
*json_row
= NULL
;
2387 json_object
*json_pim_neighbor
= NULL
;
2388 json_object
*json_pim_neighbors
= NULL
;
2389 json_object
*json_group
= NULL
;
2390 json_object
*json_group_source
= NULL
;
2391 json_object
*json_fhr_sources
= NULL
;
2392 struct pim_secondary_addr
*sec_addr
;
2393 struct listnode
*sec_node
;
2395 now
= pim_time_monotonic_sec();
2397 FOR_ALL_INTERFACES (pim
->vrf
, ifp
) {
2398 pim_ifp
= ifp
->info
;
2403 if (mlag
== true && pim_ifp
->activeactive
== false)
2406 if (strcmp(ifname
, "detail") && strcmp(ifname
, ifp
->name
))
2410 ifaddr
= pim_ifp
->primary_address
;
2411 snprintfrr(dr_str
, sizeof(dr_str
), "%pPAs",
2412 &pim_ifp
->pim_dr_addr
);
2413 pim_time_uptime_begin(dr_uptime
, sizeof(dr_uptime
), now
,
2414 pim_ifp
->pim_dr_election_last
);
2415 pim_time_timer_to_hhmmss(hello_timer
, sizeof(hello_timer
),
2416 pim_ifp
->t_pim_hello_timer
);
2417 pim_time_mmss(hello_period
, sizeof(hello_period
),
2418 pim_ifp
->pim_hello_period
);
2419 pim_time_uptime(stat_uptime
, sizeof(stat_uptime
),
2420 now
- pim_ifp
->pim_ifstat_start
);
2423 json_row
= json_object_new_object();
2424 json_object_pim_ifp_add(json_row
, ifp
);
2426 if (!pim_addr_is_any(pim_ifp
->update_source
)) {
2427 json_object_string_addf(
2428 json_row
, "useSource", "%pPAs",
2429 &pim_ifp
->update_source
);
2431 if (pim_ifp
->sec_addr_list
) {
2432 json_object
*sec_list
= NULL
;
2434 sec_list
= json_object_new_array();
2435 for (ALL_LIST_ELEMENTS_RO(
2436 pim_ifp
->sec_addr_list
, sec_node
,
2438 json_object_array_add(
2440 json_object_new_stringf(
2444 json_object_object_add(json_row
,
2445 "secondaryAddressList",
2449 if (pim_ifp
->pim_passive_enable
)
2450 json_object_boolean_true_add(json_row
,
2454 if (pim_ifp
->pim_neighbor_list
->count
) {
2455 json_pim_neighbors
= json_object_new_object();
2457 for (ALL_LIST_ELEMENTS_RO(
2458 pim_ifp
->pim_neighbor_list
,
2459 neighnode
, neigh
)) {
2461 json_object_new_object();
2462 snprintfrr(neigh_src_str
,
2463 sizeof(neigh_src_str
),
2465 &neigh
->source_addr
);
2466 pim_time_uptime(uptime
, sizeof(uptime
),
2467 now
- neigh
->creation
);
2468 pim_time_timer_to_hhmmss(
2469 expire
, sizeof(expire
),
2470 neigh
->t_expire_timer
);
2472 json_object_string_add(
2473 json_pim_neighbor
, "address",
2475 json_object_string_add(
2476 json_pim_neighbor
, "upTime",
2478 json_object_string_add(
2479 json_pim_neighbor
, "holdtime",
2482 json_object_object_add(
2488 json_object_object_add(json_row
, "neighbors",
2489 json_pim_neighbors
);
2492 json_object_string_add(json_row
, "drAddress", dr_str
);
2493 json_object_int_add(json_row
, "drPriority",
2494 pim_ifp
->pim_dr_priority
);
2495 json_object_string_add(json_row
, "drUptime", dr_uptime
);
2496 json_object_int_add(json_row
, "drElections",
2497 pim_ifp
->pim_dr_election_count
);
2498 json_object_int_add(json_row
, "drChanges",
2499 pim_ifp
->pim_dr_election_changes
);
2502 frr_each (rb_pim_upstream
, &pim
->upstream_head
, up
) {
2503 if (ifp
!= up
->rpf
.source_nexthop
.interface
)
2506 if (!(up
->flags
& PIM_UPSTREAM_FLAG_MASK_FHR
))
2509 if (!json_fhr_sources
)
2511 json_object_new_object();
2513 snprintfrr(grp_str
, sizeof(grp_str
), "%pPAs",
2515 snprintfrr(src_str
, sizeof(src_str
), "%pPAs",
2517 pim_time_uptime(uptime
, sizeof(uptime
),
2518 now
- up
->state_transition
);
2521 * Does this group live in json_fhr_sources?
2524 json_object_object_get_ex(json_fhr_sources
,
2525 grp_str
, &json_group
);
2528 json_group
= json_object_new_object();
2529 json_object_object_add(json_fhr_sources
,
2534 json_group_source
= json_object_new_object();
2535 json_object_string_add(json_group_source
,
2537 json_object_string_add(json_group_source
,
2539 json_object_string_add(json_group_source
,
2541 json_object_object_add(json_group
, src_str
,
2545 if (json_fhr_sources
) {
2546 json_object_object_add(json_row
,
2551 json_object_int_add(json_row
, "helloPeriod",
2552 pim_ifp
->pim_hello_period
);
2553 json_object_int_add(json_row
, "holdTime",
2554 PIM_IF_DEFAULT_HOLDTIME(pim_ifp
));
2555 json_object_string_add(json_row
, "helloTimer",
2557 json_object_string_add(json_row
, "helloStatStart",
2559 json_object_int_add(json_row
, "helloReceived",
2560 pim_ifp
->pim_ifstat_hello_recv
);
2561 json_object_int_add(json_row
, "helloReceivedFailed",
2562 pim_ifp
->pim_ifstat_hello_recvfail
);
2563 json_object_int_add(json_row
, "helloSend",
2564 pim_ifp
->pim_ifstat_hello_sent
);
2565 json_object_int_add(json_row
, "hellosendFailed",
2566 pim_ifp
->pim_ifstat_hello_sendfail
);
2567 json_object_int_add(json_row
, "helloGenerationId",
2568 pim_ifp
->pim_generation_id
);
2570 json_object_int_add(
2571 json_row
, "effectivePropagationDelay",
2572 pim_if_effective_propagation_delay_msec(ifp
));
2573 json_object_int_add(
2574 json_row
, "effectiveOverrideInterval",
2575 pim_if_effective_override_interval_msec(ifp
));
2576 json_object_int_add(
2577 json_row
, "joinPruneOverrideInterval",
2578 pim_if_jp_override_interval_msec(ifp
));
2580 json_object_int_add(
2581 json_row
, "propagationDelay",
2582 pim_ifp
->pim_propagation_delay_msec
);
2583 json_object_int_add(
2584 json_row
, "propagationDelayHighest",
2585 pim_ifp
->pim_neighbors_highest_propagation_delay_msec
);
2586 json_object_int_add(
2587 json_row
, "overrideInterval",
2588 pim_ifp
->pim_override_interval_msec
);
2589 json_object_int_add(
2590 json_row
, "overrideIntervalHighest",
2591 pim_ifp
->pim_neighbors_highest_override_interval_msec
);
2592 if (pim_ifp
->bsm_enable
)
2593 json_object_boolean_true_add(json_row
,
2595 if (pim_ifp
->ucast_bsm_accept
)
2596 json_object_boolean_true_add(json_row
,
2598 json_object_object_add(json
, ifp
->name
, json_row
);
2601 vty_out(vty
, "Interface : %s\n", ifp
->name
);
2602 vty_out(vty
, "State : %s\n",
2603 if_is_up(ifp
) ? "up" : "down");
2604 if (!pim_addr_is_any(pim_ifp
->update_source
)) {
2605 vty_out(vty
, "Use Source : %pPAs\n",
2606 &pim_ifp
->update_source
);
2608 if (pim_ifp
->sec_addr_list
) {
2609 vty_out(vty
, "Address : %pPAs (primary)\n",
2611 for (ALL_LIST_ELEMENTS_RO(
2612 pim_ifp
->sec_addr_list
, sec_node
,
2614 vty_out(vty
, " %pFX\n",
2617 vty_out(vty
, "Address : %pPAs\n", &ifaddr
);
2620 if (pim_ifp
->pim_passive_enable
)
2621 vty_out(vty
, "Passive : %s\n",
2622 (pim_ifp
->pim_passive_enable
) ? "yes"
2630 for (ALL_LIST_ELEMENTS_RO(pim_ifp
->pim_neighbor_list
,
2631 neighnode
, neigh
)) {
2634 vty_out(vty
, "PIM Neighbors\n");
2635 vty_out(vty
, "-------------\n");
2639 snprintfrr(neigh_src_str
, sizeof(neigh_src_str
),
2640 "%pPAs", &neigh
->source_addr
);
2641 pim_time_uptime(uptime
, sizeof(uptime
),
2642 now
- neigh
->creation
);
2643 pim_time_timer_to_hhmmss(expire
, sizeof(expire
),
2644 neigh
->t_expire_timer
);
2646 "%-15s : up for %s, holdtime expires in %s\n",
2647 neigh_src_str
, uptime
, expire
);
2650 if (!print_header
) {
2655 vty_out(vty
, "Designated Router\n");
2656 vty_out(vty
, "-----------------\n");
2657 vty_out(vty
, "Address : %s\n", dr_str
);
2658 vty_out(vty
, "Priority : %u(%d)\n",
2659 pim_ifp
->pim_dr_priority
,
2660 pim_ifp
->pim_dr_num_nondrpri_neighbors
);
2661 vty_out(vty
, "Uptime : %s\n", dr_uptime
);
2662 vty_out(vty
, "Elections : %d\n",
2663 pim_ifp
->pim_dr_election_count
);
2664 vty_out(vty
, "Changes : %d\n",
2665 pim_ifp
->pim_dr_election_changes
);
2671 frr_each (rb_pim_upstream
, &pim
->upstream_head
, up
) {
2672 if (!up
->rpf
.source_nexthop
.interface
)
2675 if (strcmp(ifp
->name
,
2676 up
->rpf
.source_nexthop
2677 .interface
->name
) != 0)
2680 if (!(up
->flags
& PIM_UPSTREAM_FLAG_MASK_FHR
))
2685 "FHR - First Hop Router\n");
2687 "----------------------\n");
2691 pim_time_uptime(uptime
, sizeof(uptime
),
2692 now
- up
->state_transition
);
2694 "%pPAs : %pPAs is a source, uptime is %s\n",
2695 &up
->sg
.grp
, &up
->sg
.src
, uptime
);
2698 if (!print_header
) {
2703 vty_out(vty
, "Hellos\n");
2704 vty_out(vty
, "------\n");
2705 vty_out(vty
, "Period : %d\n",
2706 pim_ifp
->pim_hello_period
);
2707 vty_out(vty
, "HoldTime : %d\n",
2708 PIM_IF_DEFAULT_HOLDTIME(pim_ifp
));
2709 vty_out(vty
, "Timer : %s\n", hello_timer
);
2710 vty_out(vty
, "StatStart : %s\n", stat_uptime
);
2711 vty_out(vty
, "Receive : %d\n",
2712 pim_ifp
->pim_ifstat_hello_recv
);
2713 vty_out(vty
, "Receive Failed : %d\n",
2714 pim_ifp
->pim_ifstat_hello_recvfail
);
2715 vty_out(vty
, "Send : %d\n",
2716 pim_ifp
->pim_ifstat_hello_sent
);
2717 vty_out(vty
, "Send Failed : %d\n",
2718 pim_ifp
->pim_ifstat_hello_sendfail
);
2719 vty_out(vty
, "Generation ID : %08x\n",
2720 pim_ifp
->pim_generation_id
);
2724 pim_print_ifp_flags(vty
, ifp
);
2726 vty_out(vty
, "Join Prune Interval\n");
2727 vty_out(vty
, "-------------------\n");
2728 vty_out(vty
, "LAN Delay : %s\n",
2729 pim_if_lan_delay_enabled(ifp
) ? "yes" : "no");
2730 vty_out(vty
, "Effective Propagation Delay : %d msec\n",
2731 pim_if_effective_propagation_delay_msec(ifp
));
2732 vty_out(vty
, "Effective Override Interval : %d msec\n",
2733 pim_if_effective_override_interval_msec(ifp
));
2734 vty_out(vty
, "Join Prune Override Interval : %d msec\n",
2735 pim_if_jp_override_interval_msec(ifp
));
2739 vty_out(vty
, "LAN Prune Delay\n");
2740 vty_out(vty
, "---------------\n");
2741 vty_out(vty
, "Propagation Delay : %d msec\n",
2742 pim_ifp
->pim_propagation_delay_msec
);
2743 vty_out(vty
, "Propagation Delay (Highest) : %d msec\n",
2744 pim_ifp
->pim_neighbors_highest_propagation_delay_msec
);
2745 vty_out(vty
, "Override Interval : %d msec\n",
2746 pim_ifp
->pim_override_interval_msec
);
2747 vty_out(vty
, "Override Interval (Highest) : %d msec\n",
2748 pim_ifp
->pim_neighbors_highest_override_interval_msec
);
2752 vty_out(vty
, "BSM Status\n");
2753 vty_out(vty
, "----------\n");
2754 vty_out(vty
, "Bsm Enabled : %s\n",
2755 pim_ifp
->bsm_enable
? "yes" : "no");
2756 vty_out(vty
, "Unicast Bsm Enabled : %s\n",
2757 pim_ifp
->ucast_bsm_accept
? "yes" : "no");
2764 vty_out(vty
, "%% No such interface\n");
2767 void ip_pim_ssm_show_group_range(struct pim_instance
*pim
, struct vty
*vty
,
2770 struct pim_ssm
*ssm
= pim
->ssm_info
;
2771 const char *range_str
=
2772 ssm
->plist_name
? ssm
->plist_name
: PIM_SSM_STANDARD_RANGE
;
2777 json
= json_object_new_object();
2778 json_object_string_add(json
, "ssmGroups", range_str
);
2779 vty_json(vty
, json
);
2781 vty_out(vty
, "SSM group range : %s\n", range_str
);
2784 struct vty_pnc_cache_walk_data
{
2786 struct pim_instance
*pim
;
2789 struct json_pnc_cache_walk_data
{
2790 json_object
*json_obj
;
2791 struct pim_instance
*pim
;
2794 static int pim_print_vty_pnc_cache_walkcb(struct hash_bucket
*bucket
, void *arg
)
2796 struct pim_nexthop_cache
*pnc
= bucket
->data
;
2797 struct vty_pnc_cache_walk_data
*cwd
= arg
;
2798 struct vty
*vty
= cwd
->vty
;
2799 struct pim_instance
*pim
= cwd
->pim
;
2800 struct nexthop
*nh_node
= NULL
;
2801 ifindex_t first_ifindex
;
2802 struct interface
*ifp
= NULL
;
2803 struct ttable
*tt
= NULL
;
2806 /* Prepare table. */
2807 tt
= ttable_new(&ttable_styles
[TTSTYLE_BLANK
]);
2808 ttable_add_row(tt
, "Address|Interface|Nexthop");
2809 tt
->style
.cell
.rpad
= 2;
2810 tt
->style
.corner
= '+';
2813 for (nh_node
= pnc
->nexthop
; nh_node
; nh_node
= nh_node
->next
) {
2814 first_ifindex
= nh_node
->ifindex
;
2816 ifp
= if_lookup_by_index(first_ifindex
, pim
->vrf
->vrf_id
);
2819 ttable_add_row(tt
, "%pPA|%s|%pI4", &pnc
->rpf
.rpf_addr
,
2820 ifp
? ifp
->name
: "NULL", &nh_node
->gate
.ipv4
);
2822 ttable_add_row(tt
, "%pPA|%s|%pI6", &pnc
->rpf
.rpf_addr
,
2823 ifp
? ifp
->name
: "NULL", &nh_node
->gate
.ipv6
);
2826 /* Dump the generated table. */
2827 table
= ttable_dump(tt
, "\n");
2828 vty_out(vty
, "%s\n", table
);
2829 XFREE(MTYPE_TMP
, table
);
2835 static int pim_print_json_pnc_cache_walkcb(struct hash_bucket
*backet
,
2838 struct pim_nexthop_cache
*pnc
= backet
->data
;
2839 struct json_pnc_cache_walk_data
*cwd
= arg
;
2840 struct pim_instance
*pim
= cwd
->pim
;
2841 struct nexthop
*nh_node
= NULL
;
2842 ifindex_t first_ifindex
;
2843 struct interface
*ifp
= NULL
;
2844 char addr_str
[PIM_ADDRSTRLEN
];
2845 json_object
*json_row
= NULL
;
2846 json_object
*json_ifp
= NULL
;
2847 json_object
*json_arr
= NULL
;
2849 for (nh_node
= pnc
->nexthop
; nh_node
; nh_node
= nh_node
->next
) {
2850 first_ifindex
= nh_node
->ifindex
;
2851 ifp
= if_lookup_by_index(first_ifindex
, pim
->vrf
->vrf_id
);
2852 snprintfrr(addr_str
, sizeof(addr_str
), "%pPA",
2853 &pnc
->rpf
.rpf_addr
);
2854 json_object_object_get_ex(cwd
->json_obj
, addr_str
, &json_row
);
2856 json_row
= json_object_new_object();
2857 json_object_string_addf(json_row
, "address", "%pPA",
2858 &pnc
->rpf
.rpf_addr
);
2859 json_object_object_addf(cwd
->json_obj
, json_row
, "%pPA",
2860 &pnc
->rpf
.rpf_addr
);
2861 json_arr
= json_object_new_array();
2862 json_object_object_add(json_row
, "nexthops", json_arr
);
2864 json_ifp
= json_object_new_object();
2865 json_object_string_add(json_ifp
, "interface",
2866 ifp
? ifp
->name
: "NULL");
2868 json_object_string_addf(json_ifp
, "nexthop", "%pI4",
2869 &nh_node
->gate
.ipv4
);
2871 json_object_string_addf(json_ifp
, "nexthop", "%pI6",
2872 &nh_node
->gate
.ipv6
);
2874 json_object_array_add(json_arr
, json_ifp
);
2879 int pim_show_nexthop_lookup_cmd_helper(const char *vrf
, struct vty
*vty
,
2880 pim_addr source
, pim_addr group
)
2883 pim_addr vif_source
;
2885 struct pim_nexthop nexthop
;
2887 char grp_str
[PREFIX_STRLEN
];
2889 v
= vrf_lookup_by_name(vrf
? vrf
: VRF_DEFAULT_NAME
);
2895 if (pim_is_group_224_4(source
)) {
2897 "Invalid argument. Expected Valid Source Address.\n");
2901 if (!pim_is_group_224_4(group
)) {
2903 "Invalid argument. Expected Valid Multicast Group Address.\n");
2908 if (!pim_rp_set_upstream_addr(v
->info
, &vif_source
, source
, group
))
2911 pim_addr_to_prefix(&grp
, group
);
2912 memset(&nexthop
, 0, sizeof(nexthop
));
2915 pim_ecmp_nexthop_lookup(v
->info
, &nexthop
, vif_source
, &grp
, 0);
2919 "Nexthop Lookup failed, no usable routes returned.\n");
2923 pim_addr_dump("<grp?>", &grp
, grp_str
, sizeof(grp_str
));
2925 vty_out(vty
, "Group %s --- Nexthop %pPAs Interface %s\n", grp_str
,
2926 &nexthop
.mrib_nexthop_addr
, nexthop
.interface
->name
);
2931 int pim_show_nexthop_cmd_helper(const char *vrf
, struct vty
*vty
, bool uj
)
2935 v
= vrf_lookup_by_name(vrf
? vrf
: VRF_DEFAULT_NAME
);
2940 pim_show_nexthop(v
->info
, vty
, uj
);
2945 void pim_show_nexthop(struct pim_instance
*pim
, struct vty
*vty
, bool uj
)
2947 struct vty_pnc_cache_walk_data cwd
;
2948 struct json_pnc_cache_walk_data jcwd
;
2955 jcwd
.json_obj
= json_object_new_object();
2957 vty_out(vty
, "Number of registered addresses: %lu\n",
2958 pim
->rpf_hash
->count
);
2962 hash_walk(pim
->rpf_hash
, pim_print_json_pnc_cache_walkcb
,
2964 vty_json(vty
, jcwd
.json_obj
);
2966 hash_walk(pim
->rpf_hash
, pim_print_vty_pnc_cache_walkcb
, &cwd
);
2969 int pim_show_neighbors_cmd_helper(const char *vrf
, struct vty
*vty
,
2970 const char *json
, const char *interface
)
2973 json_object
*json_parent
= NULL
;
2975 v
= vrf_lookup_by_name(vrf
? vrf
: VRF_DEFAULT_NAME
);
2981 json_parent
= json_object_new_object();
2984 pim_show_neighbors_single(v
->info
, vty
, interface
, json_parent
);
2986 pim_show_neighbors(v
->info
, vty
, json_parent
);
2989 vty_json(vty
, json_parent
);
2994 int pim_show_neighbors_vrf_all_cmd_helper(struct vty
*vty
, const char *json
,
2995 const char *interface
)
2998 json_object
*json_parent
= NULL
;
2999 json_object
*json_vrf
= NULL
;
3002 json_parent
= json_object_new_object();
3003 RB_FOREACH (v
, vrf_name_head
, &vrfs_by_name
) {
3005 vty_out(vty
, "VRF: %s\n", v
->name
);
3007 json_vrf
= json_object_new_object();
3010 pim_show_neighbors_single(v
->info
, vty
, interface
,
3013 pim_show_neighbors(v
->info
, vty
, json_vrf
);
3016 json_object_object_add(json_parent
, v
->name
, json_vrf
);
3019 vty_json(vty
, json_parent
);
3024 void pim_show_neighbors_single(struct pim_instance
*pim
, struct vty
*vty
,
3025 const char *neighbor
, json_object
*json
)
3027 struct listnode
*neighnode
;
3028 struct interface
*ifp
;
3029 struct pim_interface
*pim_ifp
;
3030 struct pim_neighbor
*neigh
;
3032 int found_neighbor
= 0;
3033 int option_address_list
;
3034 int option_dr_priority
;
3035 int option_generation_id
;
3036 int option_holdtime
;
3037 int option_lan_prune_delay
;
3041 char neigh_src_str
[PIM_ADDRSTRLEN
];
3043 json_object
*json_ifp
= NULL
;
3044 json_object
*json_row
= NULL
;
3046 now
= pim_time_monotonic_sec();
3048 FOR_ALL_INTERFACES (pim
->vrf
, ifp
) {
3049 pim_ifp
= ifp
->info
;
3054 if (pim_ifp
->pim_sock_fd
< 0)
3057 for (ALL_LIST_ELEMENTS_RO(pim_ifp
->pim_neighbor_list
, neighnode
,
3059 snprintfrr(neigh_src_str
, sizeof(neigh_src_str
),
3060 "%pPAs", &neigh
->source_addr
);
3063 * The user can specify either the interface name or the
3065 * If this pim_ifp matches neither then skip.
3067 if (strcmp(neighbor
, "detail") &&
3068 strcmp(neighbor
, ifp
->name
) &&
3069 strcmp(neighbor
, neigh_src_str
))
3073 pim_time_uptime(uptime
, sizeof(uptime
),
3074 now
- neigh
->creation
);
3075 pim_time_timer_to_hhmmss(expire
, sizeof(expire
),
3076 neigh
->t_expire_timer
);
3078 option_address_list
= 0;
3079 option_dr_priority
= 0;
3080 option_generation_id
= 0;
3081 option_holdtime
= 0;
3082 option_lan_prune_delay
= 0;
3085 if (PIM_OPTION_IS_SET(neigh
->hello_options
,
3086 PIM_OPTION_MASK_ADDRESS_LIST
))
3087 option_address_list
= 1;
3089 if (PIM_OPTION_IS_SET(neigh
->hello_options
,
3090 PIM_OPTION_MASK_DR_PRIORITY
))
3091 option_dr_priority
= 1;
3093 if (PIM_OPTION_IS_SET(neigh
->hello_options
,
3094 PIM_OPTION_MASK_GENERATION_ID
))
3095 option_generation_id
= 1;
3097 if (PIM_OPTION_IS_SET(neigh
->hello_options
,
3098 PIM_OPTION_MASK_HOLDTIME
))
3099 option_holdtime
= 1;
3101 if (PIM_OPTION_IS_SET(neigh
->hello_options
,
3102 PIM_OPTION_MASK_LAN_PRUNE_DELAY
))
3103 option_lan_prune_delay
= 1;
3105 if (PIM_OPTION_IS_SET(
3106 neigh
->hello_options
,
3107 PIM_OPTION_MASK_CAN_DISABLE_JOIN_SUPPRESSION
))
3112 /* Does this ifp live in json? If not create it
3114 json_object_object_get_ex(json
, ifp
->name
,
3118 json_ifp
= json_object_new_object();
3119 json_object_pim_ifp_add(json_ifp
, ifp
);
3120 json_object_object_add(json
, ifp
->name
,
3124 json_row
= json_object_new_object();
3125 json_object_string_add(json_row
, "interface",
3127 json_object_string_add(json_row
, "address",
3129 json_object_string_add(json_row
, "upTime",
3131 json_object_string_add(json_row
, "holdtime",
3133 json_object_int_add(json_row
, "drPriority",
3134 neigh
->dr_priority
);
3135 json_object_int_add(json_row
, "generationId",
3136 neigh
->generation_id
);
3138 if (option_address_list
)
3139 json_object_boolean_true_add(
3141 "helloOptionAddressList");
3143 if (option_dr_priority
)
3144 json_object_boolean_true_add(
3146 "helloOptionDrPriority");
3148 if (option_generation_id
)
3149 json_object_boolean_true_add(
3151 "helloOptionGenerationId");
3153 if (option_holdtime
)
3154 json_object_boolean_true_add(
3156 "helloOptionHoldtime");
3158 if (option_lan_prune_delay
)
3159 json_object_boolean_true_add(
3161 "helloOptionLanPruneDelay");
3164 json_object_boolean_true_add(
3165 json_row
, "helloOptionTBit");
3167 json_object_object_add(json_ifp
, neigh_src_str
,
3171 vty_out(vty
, "Interface : %s\n", ifp
->name
);
3172 vty_out(vty
, "Neighbor : %s\n", neigh_src_str
);
3180 " DR Priority : %d\n",
3181 neigh
->dr_priority
);
3183 " Generation ID : %08x\n",
3184 neigh
->generation_id
);
3186 " Override Interval (msec) : %d\n",
3187 neigh
->override_interval_msec
);
3189 " Propagation Delay (msec) : %d\n",
3190 neigh
->propagation_delay_msec
);
3192 " Hello Option - Address List : %s\n",
3193 option_address_list
? "yes" : "no");
3195 " Hello Option - DR Priority : %s\n",
3196 option_dr_priority
? "yes" : "no");
3198 " Hello Option - Generation ID : %s\n",
3199 option_generation_id
? "yes" : "no");
3201 " Hello Option - Holdtime : %s\n",
3202 option_holdtime
? "yes" : "no");
3204 " Hello Option - LAN Prune Delay : %s\n",
3205 option_lan_prune_delay
? "yes" : "no");
3207 " Hello Option - T-bit : %s\n",
3208 option_t_bit
? "yes" : "no");
3209 bfd_sess_show(vty
, json_ifp
,
3210 neigh
->bfd_session
);
3216 if (!found_neighbor
)
3217 vty_out(vty
, "%% No such interface or neighbor\n");
3220 void pim_show_neighbors(struct pim_instance
*pim
, struct vty
*vty
,
3223 struct listnode
*neighnode
;
3224 struct interface
*ifp
;
3225 struct pim_interface
*pim_ifp
;
3226 struct pim_neighbor
*neigh
;
3227 struct ttable
*tt
= NULL
;
3232 char neigh_src_str
[PIM_ADDRSTRLEN
];
3233 json_object
*json_ifp_rows
= NULL
;
3234 json_object
*json_row
= NULL
;
3236 now
= pim_time_monotonic_sec();
3239 /* Prepare table. */
3240 tt
= ttable_new(&ttable_styles
[TTSTYLE_BLANK
]);
3241 ttable_add_row(tt
, "Interface|Neighbor|Uptime|Holdtime|DR Pri");
3242 tt
->style
.cell
.rpad
= 2;
3243 tt
->style
.corner
= '+';
3247 FOR_ALL_INTERFACES (pim
->vrf
, ifp
) {
3248 pim_ifp
= ifp
->info
;
3253 if (pim_ifp
->pim_sock_fd
< 0)
3257 json_ifp_rows
= json_object_new_object();
3259 for (ALL_LIST_ELEMENTS_RO(pim_ifp
->pim_neighbor_list
, neighnode
,
3261 snprintfrr(neigh_src_str
, sizeof(neigh_src_str
),
3262 "%pPAs", &neigh
->source_addr
);
3263 pim_time_uptime(uptime
, sizeof(uptime
),
3264 now
- neigh
->creation
);
3265 pim_time_timer_to_hhmmss(expire
, sizeof(expire
),
3266 neigh
->t_expire_timer
);
3269 json_row
= json_object_new_object();
3270 json_object_string_add(json_row
, "interface",
3272 json_object_string_add(json_row
, "neighbor",
3274 json_object_string_add(json_row
, "upTime",
3276 json_object_string_add(json_row
, "holdTime",
3278 json_object_int_add(json_row
, "holdTimeMax",
3280 json_object_int_add(json_row
, "drPriority",
3281 neigh
->dr_priority
);
3282 json_object_object_add(json_ifp_rows
,
3283 neigh_src_str
, json_row
);
3286 ttable_add_row(tt
, "%s|%pPAs|%s|%s|%d",
3287 ifp
->name
, &neigh
->source_addr
,
3289 neigh
->dr_priority
);
3294 json_object_object_add(json
, ifp
->name
, json_ifp_rows
);
3295 json_ifp_rows
= NULL
;
3298 /* Dump the generated table. */
3300 table
= ttable_dump(tt
, "\n");
3301 vty_out(vty
, "%s\n", table
);
3302 XFREE(MTYPE_TMP
, table
);
3307 int gm_process_query_max_response_time_cmd(struct vty
*vty
,
3308 const char *qmrt_str
)
3310 const struct lyd_node
*pim_enable_dnode
;
3312 pim_enable_dnode
= yang_dnode_getf(vty
->candidate_config
->dnode
,
3313 FRR_PIM_ENABLE_XPATH
, VTY_CURR_XPATH
,
3314 FRR_PIM_AF_XPATH_VAL
);
3316 if (!pim_enable_dnode
) {
3317 nb_cli_enqueue_change(vty
, "./enable", NB_OP_MODIFY
, "true");
3319 if (!yang_dnode_get_bool(pim_enable_dnode
, "."))
3320 nb_cli_enqueue_change(vty
, "./enable", NB_OP_MODIFY
,
3324 nb_cli_enqueue_change(vty
, "./query-max-response-time", NB_OP_MODIFY
,
3326 return nb_cli_apply_changes(vty
, FRR_GMP_INTERFACE_XPATH
,
3327 FRR_PIM_AF_XPATH_VAL
);
3330 int gm_process_no_query_max_response_time_cmd(struct vty
*vty
)
3332 nb_cli_enqueue_change(vty
, "./query-max-response-time", NB_OP_DESTROY
,
3334 return nb_cli_apply_changes(vty
, FRR_GMP_INTERFACE_XPATH
,
3335 FRR_PIM_AF_XPATH_VAL
);
3338 int gm_process_last_member_query_count_cmd(struct vty
*vty
,
3339 const char *lmqc_str
)
3341 const struct lyd_node
*pim_enable_dnode
;
3343 pim_enable_dnode
= yang_dnode_getf(vty
->candidate_config
->dnode
,
3344 FRR_PIM_ENABLE_XPATH
, VTY_CURR_XPATH
,
3345 FRR_PIM_AF_XPATH_VAL
);
3346 if (!pim_enable_dnode
) {
3347 nb_cli_enqueue_change(vty
, "./enable", NB_OP_MODIFY
, "true");
3349 if (!yang_dnode_get_bool(pim_enable_dnode
, "."))
3350 nb_cli_enqueue_change(vty
, "./enable", NB_OP_MODIFY
,
3354 nb_cli_enqueue_change(vty
, "./robustness-variable", NB_OP_MODIFY
,
3356 return nb_cli_apply_changes(vty
, FRR_GMP_INTERFACE_XPATH
,
3357 FRR_PIM_AF_XPATH_VAL
);
3360 int gm_process_no_last_member_query_count_cmd(struct vty
*vty
)
3362 nb_cli_enqueue_change(vty
, "./robustness-variable", NB_OP_DESTROY
,
3364 return nb_cli_apply_changes(vty
, FRR_GMP_INTERFACE_XPATH
,
3365 FRR_PIM_AF_XPATH_VAL
);
3368 int gm_process_last_member_query_interval_cmd(struct vty
*vty
,
3369 const char *lmqi_str
)
3371 const struct lyd_node
*pim_enable_dnode
;
3373 pim_enable_dnode
= yang_dnode_getf(vty
->candidate_config
->dnode
,
3374 FRR_PIM_ENABLE_XPATH
, VTY_CURR_XPATH
,
3375 FRR_PIM_AF_XPATH_VAL
);
3376 if (!pim_enable_dnode
) {
3377 nb_cli_enqueue_change(vty
, "./enable", NB_OP_MODIFY
, "true");
3379 if (!yang_dnode_get_bool(pim_enable_dnode
, "."))
3380 nb_cli_enqueue_change(vty
, "./enable", NB_OP_MODIFY
,
3384 nb_cli_enqueue_change(vty
, "./last-member-query-interval", NB_OP_MODIFY
,
3386 return nb_cli_apply_changes(vty
, FRR_GMP_INTERFACE_XPATH
,
3387 FRR_PIM_AF_XPATH_VAL
);
3390 int gm_process_no_last_member_query_interval_cmd(struct vty
*vty
)
3392 nb_cli_enqueue_change(vty
, "./last-member-query-interval",
3393 NB_OP_DESTROY
, NULL
);
3394 return nb_cli_apply_changes(vty
, FRR_GMP_INTERFACE_XPATH
,
3395 FRR_PIM_AF_XPATH_VAL
);
3398 int pim_process_ssmpingd_cmd(struct vty
*vty
, enum nb_operation operation
,
3399 const char *src_str
)
3401 const char *vrfname
;
3402 char ssmpingd_ip_xpath
[XPATH_MAXLEN
];
3404 vrfname
= pim_cli_get_vrf_name(vty
);
3405 if (vrfname
== NULL
)
3406 return CMD_WARNING_CONFIG_FAILED
;
3408 snprintf(ssmpingd_ip_xpath
, sizeof(ssmpingd_ip_xpath
),
3409 FRR_PIM_VRF_XPATH
, "frr-pim:pimd", "pim", vrfname
,
3410 FRR_PIM_AF_XPATH_VAL
);
3411 strlcat(ssmpingd_ip_xpath
, "/ssm-pingd-source-ip",
3412 sizeof(ssmpingd_ip_xpath
));
3414 nb_cli_enqueue_change(vty
, ssmpingd_ip_xpath
, operation
, src_str
);
3416 return nb_cli_apply_changes(vty
, NULL
);
3419 int pim_process_bsm_cmd(struct vty
*vty
)
3421 const struct lyd_node
*gm_enable_dnode
;
3423 gm_enable_dnode
= yang_dnode_getf(vty
->candidate_config
->dnode
,
3424 FRR_GMP_ENABLE_XPATH
, VTY_CURR_XPATH
,
3425 FRR_PIM_AF_XPATH_VAL
);
3426 if (!gm_enable_dnode
)
3427 nb_cli_enqueue_change(vty
, "./pim-enable", NB_OP_MODIFY
,
3430 if (!yang_dnode_get_bool(gm_enable_dnode
, "."))
3431 nb_cli_enqueue_change(vty
, "./pim-enable", NB_OP_MODIFY
,
3435 nb_cli_enqueue_change(vty
, "./bsm", NB_OP_MODIFY
, "true");
3437 return nb_cli_apply_changes(vty
, FRR_PIM_INTERFACE_XPATH
,
3438 FRR_PIM_AF_XPATH_VAL
);
3441 int pim_process_no_bsm_cmd(struct vty
*vty
)
3443 nb_cli_enqueue_change(vty
, "./bsm", NB_OP_MODIFY
, "false");
3445 return nb_cli_apply_changes(vty
, FRR_PIM_INTERFACE_XPATH
,
3446 FRR_PIM_AF_XPATH_VAL
);
3449 int pim_process_unicast_bsm_cmd(struct vty
*vty
)
3451 const struct lyd_node
*gm_enable_dnode
;
3453 gm_enable_dnode
= yang_dnode_getf(vty
->candidate_config
->dnode
,
3454 FRR_GMP_ENABLE_XPATH
, VTY_CURR_XPATH
,
3455 FRR_PIM_AF_XPATH_VAL
);
3456 if (!gm_enable_dnode
)
3457 nb_cli_enqueue_change(vty
, "./pim-enable", NB_OP_MODIFY
,
3460 if (!yang_dnode_get_bool(gm_enable_dnode
, "."))
3461 nb_cli_enqueue_change(vty
, "./pim-enable", NB_OP_MODIFY
,
3465 nb_cli_enqueue_change(vty
, "./unicast-bsm", NB_OP_MODIFY
, "true");
3467 return nb_cli_apply_changes(vty
, FRR_PIM_INTERFACE_XPATH
,
3468 FRR_PIM_AF_XPATH_VAL
);
3471 int pim_process_no_unicast_bsm_cmd(struct vty
*vty
)
3473 nb_cli_enqueue_change(vty
, "./unicast-bsm", NB_OP_MODIFY
, "false");
3475 return nb_cli_apply_changes(vty
, FRR_PIM_INTERFACE_XPATH
,
3476 FRR_PIM_AF_XPATH_VAL
);
3479 static void show_scan_oil_stats(struct pim_instance
*pim
, struct vty
*vty
,
3482 char uptime_scan_oil
[10];
3483 char uptime_mroute_add
[10];
3484 char uptime_mroute_del
[10];
3486 pim_time_uptime_begin(uptime_scan_oil
, sizeof(uptime_scan_oil
), now
,
3487 pim
->scan_oil_last
);
3488 pim_time_uptime_begin(uptime_mroute_add
, sizeof(uptime_mroute_add
), now
,
3489 pim
->mroute_add_last
);
3490 pim_time_uptime_begin(uptime_mroute_del
, sizeof(uptime_mroute_del
), now
,
3491 pim
->mroute_del_last
);
3494 "Scan OIL - Last: %s Events: %lld\n"
3495 "MFC Add - Last: %s Events: %lld\n"
3496 "MFC Del - Last: %s Events: %lld\n",
3497 uptime_scan_oil
, (long long)pim
->scan_oil_events
,
3498 uptime_mroute_add
, (long long)pim
->mroute_add_events
,
3499 uptime_mroute_del
, (long long)pim
->mroute_del_events
);
3502 void show_multicast_interfaces(struct pim_instance
*pim
, struct vty
*vty
,
3505 struct interface
*ifp
;
3506 struct ttable
*tt
= NULL
;
3508 json_object
*json_row
= NULL
;
3513 /* Prepare table. */
3514 tt
= ttable_new(&ttable_styles
[TTSTYLE_BLANK
]);
3517 "Interface|Address|ifi|Vif|PktsIn|PktsOut|BytesIn|BytesOut");
3518 tt
->style
.cell
.rpad
= 2;
3519 tt
->style
.corner
= '+';
3523 FOR_ALL_INTERFACES (pim
->vrf
, ifp
) {
3524 struct pim_interface
*pim_ifp
;
3526 struct sioc_vif_req vreq
;
3528 struct sioc_mif_req6 vreq
;
3531 pim_ifp
= ifp
->info
;
3536 memset(&vreq
, 0, sizeof(vreq
));
3538 vreq
.vifi
= pim_ifp
->mroute_vif_index
;
3539 if (ioctl(pim
->mroute_socket
, SIOCGETVIFCNT
, &vreq
)) {
3541 "ioctl(SIOCGETVIFCNT=%lu) failure for interface %s vif_index=%d: errno=%d: %s",
3542 (unsigned long)SIOCGETVIFCNT
, ifp
->name
,
3543 pim_ifp
->mroute_vif_index
, errno
,
3544 safe_strerror(errno
));
3547 vreq
.mifi
= pim_ifp
->mroute_vif_index
;
3548 if (ioctl(pim
->mroute_socket
, SIOCGETMIFCNT_IN6
, &vreq
)) {
3550 "ioctl(SIOCGETMIFCNT_IN6=%lu) failure for interface %s vif_index=%d: errno=%d: %s",
3551 (unsigned long)SIOCGETMIFCNT_IN6
, ifp
->name
,
3552 pim_ifp
->mroute_vif_index
, errno
,
3553 safe_strerror(errno
));
3558 json_row
= json_object_new_object();
3559 json_object_string_add(json_row
, "name", ifp
->name
);
3560 json_object_string_add(json_row
, "state",
3561 if_is_up(ifp
) ? "up" : "down");
3562 json_object_string_addf(json_row
, "address", "%pPA",
3563 &pim_ifp
->primary_address
);
3564 json_object_int_add(json_row
, "ifIndex", ifp
->ifindex
);
3565 json_object_int_add(json_row
, "vif",
3566 pim_ifp
->mroute_vif_index
);
3567 json_object_int_add(json_row
, "pktsIn",
3568 (unsigned long)vreq
.icount
);
3569 json_object_int_add(json_row
, "pktsOut",
3570 (unsigned long)vreq
.ocount
);
3571 json_object_int_add(json_row
, "bytesIn",
3572 (unsigned long)vreq
.ibytes
);
3573 json_object_int_add(json_row
, "bytesOut",
3574 (unsigned long)vreq
.obytes
);
3575 json_object_object_add(json
, ifp
->name
, json_row
);
3577 ttable_add_row(tt
, "%s|%pPAs|%d|%d|%lu|%lu|%lu|%lu",
3578 ifp
->name
, &pim_ifp
->primary_address
,
3579 ifp
->ifindex
, pim_ifp
->mroute_vif_index
,
3580 (unsigned long)vreq
.icount
,
3581 (unsigned long)vreq
.ocount
,
3582 (unsigned long)vreq
.ibytes
,
3583 (unsigned long)vreq
.obytes
);
3586 /* Dump the generated table. */
3588 table
= ttable_dump(tt
, "\n");
3589 vty_out(vty
, "%s\n", table
);
3590 XFREE(MTYPE_TMP
, table
);
3595 void pim_cmd_show_ip_multicast_helper(struct pim_instance
*pim
, struct vty
*vty
)
3597 struct vrf
*vrf
= pim
->vrf
;
3598 time_t now
= pim_time_monotonic_sec();
3604 vty_out(vty
, "Router MLAG Role: %s\n",
3605 mlag_role2str(router
->mlag_role
, mlag_role
, sizeof(mlag_role
)));
3606 vty_out(vty
, "Mroute socket descriptor:");
3608 vty_out(vty
, " %d(%s)\n", pim
->mroute_socket
, vrf
->name
);
3609 vty_out(vty
, "PIM Register socket descriptor:");
3610 vty_out(vty
, " %d(%s)\n", pim
->reg_sock
, vrf
->name
);
3612 pim_time_uptime(uptime
, sizeof(uptime
),
3613 now
- pim
->mroute_socket_creation
);
3614 vty_out(vty
, "Mroute socket uptime: %s\n", uptime
);
3618 pim_zebra_zclient_update(vty
);
3619 pim_zlookup_show_ip_multicast(vty
);
3622 vty_out(vty
, "Maximum highest VifIndex: %d\n", PIM_MAX_USABLE_VIFS
);
3625 vty_out(vty
, "Upstream Join Timer: %d secs\n", router
->t_periodic
);
3626 vty_out(vty
, "Join/Prune Holdtime: %d secs\n", PIM_JP_HOLDTIME
);
3627 vty_out(vty
, "PIM ECMP: %s\n", pim
->ecmp_enable
? "Enable" : "Disable");
3628 vty_out(vty
, "PIM ECMP Rebalance: %s\n",
3629 pim
->ecmp_rebalance_enable
? "Enable" : "Disable");
3633 pim_show_rpf_refresh_stats(vty
, pim
, now
, NULL
);
3637 show_scan_oil_stats(pim
, vty
, now
);
3639 show_multicast_interfaces(pim
, vty
, NULL
);
3642 void show_mroute(struct pim_instance
*pim
, struct vty
*vty
, pim_sgaddr
*sg
,
3643 bool fill
, json_object
*json
)
3645 struct listnode
*node
;
3646 struct channel_oil
*c_oil
;
3647 struct static_route
*s_route
;
3648 struct ttable
*tt
= NULL
;
3651 json_object
*json_group
= NULL
;
3652 json_object
*json_source
= NULL
;
3653 json_object
*json_oil
= NULL
;
3654 json_object
*json_ifp_out
= NULL
;
3657 char grp_str
[PIM_ADDRSTRLEN
];
3658 char src_str
[PIM_ADDRSTRLEN
];
3659 char in_ifname
[INTERFACE_NAMSIZ
+ 1];
3660 char out_ifname
[INTERFACE_NAMSIZ
+ 1];
3662 struct interface
*ifp_in
;
3664 char state_str
[PIM_REG_STATE_STR_LEN
];
3665 char mroute_uptime
[10];
3668 vty_out(vty
, "IP Multicast Routing Table\n");
3669 vty_out(vty
, "Flags: S - Sparse, C - Connected, P - Pruned\n");
3671 " R - SGRpt Pruned, F - Register flag, T - SPT-bit set\n");
3673 /* Prepare table. */
3674 tt
= ttable_new(&ttable_styles
[TTSTYLE_BLANK
]);
3676 tt
, "Source|Group|Flags|Proto|Input|Output|TTL|Uptime");
3677 tt
->style
.cell
.rpad
= 2;
3678 tt
->style
.corner
= '+';
3682 now
= pim_time_monotonic_sec();
3684 /* print list of PIM and IGMP routes */
3685 frr_each (rb_pim_oil
, &pim
->channel_oil_head
, c_oil
) {
3688 if (!c_oil
->installed
)
3691 if (!pim_addr_is_any(sg
->grp
) &&
3692 pim_addr_cmp(sg
->grp
, *oil_mcastgrp(c_oil
)))
3694 if (!pim_addr_is_any(sg
->src
) &&
3695 pim_addr_cmp(sg
->src
, *oil_origin(c_oil
)))
3698 snprintfrr(grp_str
, sizeof(grp_str
), "%pPAs",
3699 oil_mcastgrp(c_oil
));
3700 snprintfrr(src_str
, sizeof(src_str
), "%pPAs",
3703 strlcpy(state_str
, "S", sizeof(state_str
));
3704 /* When a non DR receives a igmp join, it creates a (*,G)
3705 * channel_oil without any upstream creation
3708 if (PIM_UPSTREAM_FLAG_TEST_SRC_IGMP(c_oil
->up
->flags
))
3709 strlcat(state_str
, "C", sizeof(state_str
));
3710 if (pim_upstream_is_sg_rpt(c_oil
->up
))
3711 strlcat(state_str
, "R", sizeof(state_str
));
3712 if (PIM_UPSTREAM_FLAG_TEST_FHR(c_oil
->up
->flags
))
3713 strlcat(state_str
, "F", sizeof(state_str
));
3714 if (c_oil
->up
->sptbit
== PIM_UPSTREAM_SPTBIT_TRUE
)
3715 strlcat(state_str
, "T", sizeof(state_str
));
3717 if (pim_channel_oil_empty(c_oil
))
3718 strlcat(state_str
, "P", sizeof(state_str
));
3720 ifp_in
= pim_if_find_by_vif_index(pim
, *oil_parent(c_oil
));
3723 strlcpy(in_ifname
, ifp_in
->name
, sizeof(in_ifname
));
3725 strlcpy(in_ifname
, "<iif?>", sizeof(in_ifname
));
3728 pim_time_uptime(mroute_uptime
, sizeof(mroute_uptime
),
3729 now
- c_oil
->mroute_creation
);
3733 /* Find the group, create it if it doesn't exist */
3734 json_object_object_get_ex(json
, grp_str
, &json_group
);
3737 json_group
= json_object_new_object();
3738 json_object_object_add(json
, grp_str
,
3742 /* Find the source nested under the group, create it if
3745 json_object_object_get_ex(json_group
, src_str
,
3749 json_source
= json_object_new_object();
3750 json_object_object_add(json_group
, src_str
,
3754 /* Find the inbound interface nested under the source,
3755 * create it if it doesn't exist
3757 json_object_string_add(json_source
, "source", src_str
);
3758 json_object_string_add(json_source
, "group", grp_str
);
3759 json_object_int_add(json_source
, "installed",
3761 json_object_int_add(json_source
, "refCount",
3762 c_oil
->oil_ref_count
);
3763 json_object_int_add(json_source
, "oilSize",
3765 json_object_int_add(json_source
, "oilInheritedRescan",
3766 c_oil
->oil_inherited_rescan
);
3767 json_object_string_add(json_source
, "iif", in_ifname
);
3768 json_object_string_add(json_source
, "upTime",
3773 for (oif_vif_index
= 0; oif_vif_index
< MAXVIFS
;
3775 struct interface
*ifp_out
;
3778 ttl
= oil_if_has(c_oil
, oif_vif_index
);
3782 /* do not display muted OIFs */
3783 if (c_oil
->oif_flags
[oif_vif_index
] & PIM_OIF_FLAG_MUTE
)
3786 if (*oil_parent(c_oil
) == oif_vif_index
&&
3787 !pim_mroute_allow_iif_in_oil(c_oil
, oif_vif_index
))
3790 ifp_out
= pim_if_find_by_vif_index(pim
, oif_vif_index
);
3794 strlcpy(out_ifname
, ifp_out
->name
,
3795 sizeof(out_ifname
));
3797 strlcpy(out_ifname
, "<oif?>",
3798 sizeof(out_ifname
));
3801 json_ifp_out
= json_object_new_object();
3802 json_object_string_add(json_ifp_out
, "source",
3804 json_object_string_add(json_ifp_out
, "group",
3807 if (c_oil
->oif_flags
[oif_vif_index
] &
3808 PIM_OIF_FLAG_PROTO_PIM
)
3809 json_object_boolean_true_add(
3810 json_ifp_out
, "protocolPim");
3812 if (c_oil
->oif_flags
[oif_vif_index
] &
3813 PIM_OIF_FLAG_PROTO_GM
)
3815 json_object_boolean_true_add(
3816 json_ifp_out
, "protocolIgmp");
3818 json_object_boolean_true_add(
3819 json_ifp_out
, "protocolMld");
3822 if (c_oil
->oif_flags
[oif_vif_index
] &
3823 PIM_OIF_FLAG_PROTO_VXLAN
)
3824 json_object_boolean_true_add(
3825 json_ifp_out
, "protocolVxlan");
3827 if (c_oil
->oif_flags
[oif_vif_index
] &
3828 PIM_OIF_FLAG_PROTO_STAR
)
3829 json_object_boolean_true_add(
3831 "protocolInherited");
3833 json_object_string_add(json_ifp_out
,
3836 json_object_int_add(json_ifp_out
, "iVifI",
3837 *oil_parent(c_oil
));
3838 json_object_string_add(json_ifp_out
,
3839 "outboundInterface",
3841 json_object_int_add(json_ifp_out
, "oVifI",
3843 json_object_int_add(json_ifp_out
, "ttl", ttl
);
3844 json_object_string_add(json_ifp_out
, "upTime",
3846 json_object_string_add(json_source
, "flags",
3849 json_oil
= json_object_new_object();
3850 json_object_object_add(json_source
,
3853 json_object_object_add(json_oil
, out_ifname
,
3857 if (c_oil
->oif_flags
[oif_vif_index
] &
3858 PIM_OIF_FLAG_PROTO_PIM
) {
3859 strlcpy(proto
, "PIM", sizeof(proto
));
3862 if (c_oil
->oif_flags
[oif_vif_index
] &
3863 PIM_OIF_FLAG_PROTO_GM
) {
3865 strlcpy(proto
, "IGMP", sizeof(proto
));
3867 strlcpy(proto
, "MLD", sizeof(proto
));
3871 if (c_oil
->oif_flags
[oif_vif_index
] &
3872 PIM_OIF_FLAG_PROTO_VXLAN
) {
3873 strlcpy(proto
, "VxLAN", sizeof(proto
));
3876 if (c_oil
->oif_flags
[oif_vif_index
] &
3877 PIM_OIF_FLAG_PROTO_STAR
) {
3878 strlcpy(proto
, "STAR", sizeof(proto
));
3881 ttable_add_row(tt
, "%s|%s|%s|%s|%s|%s|%d|%s",
3882 src_str
, grp_str
, state_str
,
3883 proto
, in_ifname
, out_ifname
,
3884 ttl
, mroute_uptime
);
3889 in_ifname
[0] = '\0';
3890 state_str
[0] = '\0';
3891 mroute_uptime
[0] = '\0';
3897 if (!json
&& !found_oif
) {
3898 ttable_add_row(tt
, "%pPAs|%pPAs|%s|%s|%s|%s|%d|%s",
3899 oil_origin(c_oil
), oil_mcastgrp(c_oil
),
3900 state_str
, "none", in_ifname
, "none", 0,
3905 /* Print list of static routes */
3906 for (ALL_LIST_ELEMENTS_RO(pim
->static_routes
, node
, s_route
)) {
3909 if (!s_route
->c_oil
.installed
)
3912 snprintfrr(grp_str
, sizeof(grp_str
), "%pPAs", &s_route
->group
);
3913 snprintfrr(src_str
, sizeof(src_str
), "%pPAs", &s_route
->source
);
3914 ifp_in
= pim_if_find_by_vif_index(pim
, s_route
->iif
);
3918 strlcpy(in_ifname
, ifp_in
->name
, sizeof(in_ifname
));
3920 strlcpy(in_ifname
, "<iif?>", sizeof(in_ifname
));
3924 /* Find the group, create it if it doesn't exist */
3925 json_object_object_get_ex(json
, grp_str
, &json_group
);
3928 json_group
= json_object_new_object();
3929 json_object_object_add(json
, grp_str
,
3933 /* Find the source nested under the group, create it if
3936 json_object_object_get_ex(json_group
, src_str
,
3940 json_source
= json_object_new_object();
3941 json_object_object_add(json_group
, src_str
,
3945 json_object_string_add(json_source
, "iif", in_ifname
);
3948 strlcpy(proto
, "STATIC", sizeof(proto
));
3951 for (oif_vif_index
= 0; oif_vif_index
< MAXVIFS
;
3953 struct interface
*ifp_out
;
3954 char oif_uptime
[10];
3957 ttl
= s_route
->oif_ttls
[oif_vif_index
];
3961 ifp_out
= pim_if_find_by_vif_index(pim
, oif_vif_index
);
3963 oif_uptime
, sizeof(oif_uptime
),
3964 now
- s_route
->c_oil
3965 .oif_creation
[oif_vif_index
]);
3969 strlcpy(out_ifname
, ifp_out
->name
,
3970 sizeof(out_ifname
));
3972 strlcpy(out_ifname
, "<oif?>",
3973 sizeof(out_ifname
));
3976 json_ifp_out
= json_object_new_object();
3977 json_object_string_add(json_ifp_out
, "source",
3979 json_object_string_add(json_ifp_out
, "group",
3981 json_object_boolean_true_add(json_ifp_out
,
3983 json_object_string_add(json_ifp_out
,
3986 json_object_int_add(
3987 json_ifp_out
, "iVifI",
3988 *oil_parent(&s_route
->c_oil
));
3989 json_object_string_add(json_ifp_out
,
3990 "outboundInterface",
3992 json_object_int_add(json_ifp_out
, "oVifI",
3994 json_object_int_add(json_ifp_out
, "ttl", ttl
);
3995 json_object_string_add(json_ifp_out
, "upTime",
3998 json_oil
= json_object_new_object();
3999 json_object_object_add(json_source
,
4002 json_object_object_add(json_oil
, out_ifname
,
4006 tt
, "%pPAs|%pPAs|%s|%s|%s|%s|%d|%s",
4007 &s_route
->source
, &s_route
->group
, "-",
4008 proto
, in_ifname
, out_ifname
, ttl
,
4010 if (first
&& !fill
) {
4013 in_ifname
[0] = '\0';
4019 if (!json
&& !found_oif
) {
4020 ttable_add_row(tt
, "%pPAs|%pPAs|%s|%s|%s|%s|%d|%s",
4021 &s_route
->source
, &s_route
->group
, "-",
4022 proto
, in_ifname
, "none", 0, "--:--:--");
4025 /* Dump the generated table. */
4027 table
= ttable_dump(tt
, "\n");
4028 vty_out(vty
, "%s\n", table
);
4029 XFREE(MTYPE_TMP
, table
);
4034 static void show_mroute_count_per_channel_oil(struct channel_oil
*c_oil
,
4038 json_object
*json_group
= NULL
;
4039 json_object
*json_source
= NULL
;
4041 if (!c_oil
->installed
)
4044 pim_mroute_update_counters(c_oil
);
4047 char group_str
[PIM_ADDRSTRLEN
];
4048 char source_str
[PIM_ADDRSTRLEN
];
4050 snprintfrr(group_str
, sizeof(group_str
), "%pPAs",
4051 oil_mcastgrp(c_oil
));
4052 snprintfrr(source_str
, sizeof(source_str
), "%pPAs",
4055 json_object_object_get_ex(json
, group_str
, &json_group
);
4058 json_group
= json_object_new_object();
4059 json_object_object_add(json
, group_str
, json_group
);
4062 json_source
= json_object_new_object();
4063 json_object_object_add(json_group
, source_str
, json_source
);
4064 json_object_int_add(json_source
, "lastUsed",
4065 c_oil
->cc
.lastused
/ 100);
4066 json_object_int_add(json_source
, "packets", c_oil
->cc
.pktcnt
);
4067 json_object_int_add(json_source
, "bytes", c_oil
->cc
.bytecnt
);
4068 json_object_int_add(json_source
, "wrongIf", c_oil
->cc
.wrong_if
);
4071 ttable_add_row(tt
, "%pPAs|%pPAs|%llu|%ld|%ld|%ld",
4072 oil_origin(c_oil
), oil_mcastgrp(c_oil
),
4073 c_oil
->cc
.lastused
/ 100,
4074 c_oil
->cc
.pktcnt
- c_oil
->cc
.origpktcnt
,
4075 c_oil
->cc
.bytecnt
- c_oil
->cc
.origbytecnt
,
4076 c_oil
->cc
.wrong_if
- c_oil
->cc
.origwrong_if
);
4080 void show_mroute_count(struct pim_instance
*pim
, struct vty
*vty
,
4083 struct listnode
*node
;
4084 struct channel_oil
*c_oil
;
4085 struct static_route
*sr
;
4086 struct ttable
*tt
= NULL
;
4092 /* Prepare table. */
4093 tt
= ttable_new(&ttable_styles
[TTSTYLE_BLANK
]);
4095 "Source|Group|LastUsed|Packets|Bytes|WrongIf");
4096 tt
->style
.cell
.rpad
= 2;
4097 tt
->style
.corner
= '+';
4101 /* Print PIM and IGMP route counts */
4102 frr_each (rb_pim_oil
, &pim
->channel_oil_head
, c_oil
)
4103 show_mroute_count_per_channel_oil(c_oil
, json
, tt
);
4105 for (ALL_LIST_ELEMENTS_RO(pim
->static_routes
, node
, sr
))
4106 show_mroute_count_per_channel_oil(&sr
->c_oil
, json
, tt
);
4108 /* Dump the generated table. */
4110 table
= ttable_dump(tt
, "\n");
4111 vty_out(vty
, "%s\n", table
);
4112 XFREE(MTYPE_TMP
, table
);
4117 void show_mroute_summary(struct pim_instance
*pim
, struct vty
*vty
,
4120 struct listnode
*node
;
4121 struct channel_oil
*c_oil
;
4122 struct static_route
*s_route
;
4123 uint32_t starg_sw_mroute_cnt
= 0;
4124 uint32_t sg_sw_mroute_cnt
= 0;
4125 uint32_t starg_hw_mroute_cnt
= 0;
4126 uint32_t sg_hw_mroute_cnt
= 0;
4127 json_object
*json_starg
= NULL
;
4128 json_object
*json_sg
= NULL
;
4131 vty_out(vty
, "Mroute Type Installed/Total\n");
4133 frr_each (rb_pim_oil
, &pim
->channel_oil_head
, c_oil
) {
4134 if (!c_oil
->installed
) {
4135 if (pim_addr_is_any(*oil_origin(c_oil
)))
4136 starg_sw_mroute_cnt
++;
4140 if (pim_addr_is_any(*oil_origin(c_oil
)))
4141 starg_hw_mroute_cnt
++;
4147 for (ALL_LIST_ELEMENTS_RO(pim
->static_routes
, node
, s_route
)) {
4148 if (!s_route
->c_oil
.installed
) {
4149 if (pim_addr_is_any(*oil_origin(&s_route
->c_oil
)))
4150 starg_sw_mroute_cnt
++;
4154 if (pim_addr_is_any(*oil_origin(&s_route
->c_oil
)))
4155 starg_hw_mroute_cnt
++;
4162 vty_out(vty
, "%-20s %u/%u\n", "(*, G)", starg_hw_mroute_cnt
,
4163 starg_sw_mroute_cnt
+ starg_hw_mroute_cnt
);
4164 vty_out(vty
, "%-20s %u/%u\n", "(S, G)", sg_hw_mroute_cnt
,
4165 sg_sw_mroute_cnt
+ sg_hw_mroute_cnt
);
4166 vty_out(vty
, "------\n");
4167 vty_out(vty
, "%-20s %u/%u\n", "Total",
4168 (starg_hw_mroute_cnt
+ sg_hw_mroute_cnt
),
4169 (starg_sw_mroute_cnt
+ starg_hw_mroute_cnt
+
4170 sg_sw_mroute_cnt
+ sg_hw_mroute_cnt
));
4172 /* (*,G) route details */
4173 json_starg
= json_object_new_object();
4174 json_object_object_add(json
, "wildcardGroup", json_starg
);
4176 json_object_int_add(json_starg
, "installed",
4177 starg_hw_mroute_cnt
);
4178 json_object_int_add(json_starg
, "total",
4179 starg_sw_mroute_cnt
+ starg_hw_mroute_cnt
);
4181 /* (S, G) route details */
4182 json_sg
= json_object_new_object();
4183 json_object_object_add(json
, "sourceGroup", json_sg
);
4185 json_object_int_add(json_sg
, "installed", sg_hw_mroute_cnt
);
4186 json_object_int_add(json_sg
, "total",
4187 sg_sw_mroute_cnt
+ sg_hw_mroute_cnt
);
4189 json_object_int_add(json
, "totalNumOfInstalledMroutes",
4190 starg_hw_mroute_cnt
+ sg_hw_mroute_cnt
);
4191 json_object_int_add(json
, "totalNumOfMroutes",
4192 starg_sw_mroute_cnt
+ starg_hw_mroute_cnt
+
4198 int clear_ip_mroute_count_command(struct vty
*vty
, const char *name
)
4200 struct listnode
*node
;
4201 struct channel_oil
*c_oil
;
4202 struct static_route
*sr
;
4203 struct vrf
*v
= pim_cmd_lookup(vty
, name
);
4204 struct pim_instance
*pim
;
4210 frr_each (rb_pim_oil
, &pim
->channel_oil_head
, c_oil
) {
4211 if (!c_oil
->installed
)
4214 pim_mroute_update_counters(c_oil
);
4215 c_oil
->cc
.origpktcnt
= c_oil
->cc
.pktcnt
;
4216 c_oil
->cc
.origbytecnt
= c_oil
->cc
.bytecnt
;
4217 c_oil
->cc
.origwrong_if
= c_oil
->cc
.wrong_if
;
4220 for (ALL_LIST_ELEMENTS_RO(pim
->static_routes
, node
, sr
)) {
4221 if (!sr
->c_oil
.installed
)
4224 pim_mroute_update_counters(&sr
->c_oil
);
4226 sr
->c_oil
.cc
.origpktcnt
= sr
->c_oil
.cc
.pktcnt
;
4227 sr
->c_oil
.cc
.origbytecnt
= sr
->c_oil
.cc
.bytecnt
;
4228 sr
->c_oil
.cc
.origwrong_if
= sr
->c_oil
.cc
.wrong_if
;
4233 struct vrf
*pim_cmd_lookup(struct vty
*vty
, const char *name
)
4238 vrf
= vrf_lookup_by_name(name
);
4240 vrf
= vrf_lookup_by_id(VRF_DEFAULT
);
4243 vty_out(vty
, "Specified VRF: %s does not exist\n", name
);
4248 void clear_mroute(struct pim_instance
*pim
)
4250 struct pim_upstream
*up
;
4251 struct interface
*ifp
;
4253 /* scan interfaces */
4254 FOR_ALL_INTERFACES (pim
->vrf
, ifp
) {
4255 struct pim_interface
*pim_ifp
= ifp
->info
;
4256 struct pim_ifchannel
*ch
;
4261 /* deleting all ifchannels */
4262 while (!RB_EMPTY(pim_ifchannel_rb
, &pim_ifp
->ifchannel_rb
)) {
4263 ch
= RB_ROOT(pim_ifchannel_rb
, &pim_ifp
->ifchannel_rb
);
4265 pim_ifchannel_delete(ch
);
4269 /* clean up all igmp groups */
4270 struct gm_group
*grp
;
4272 if (pim_ifp
->gm_group_list
) {
4273 while (pim_ifp
->gm_group_list
->count
) {
4274 grp
= listnode_head(pim_ifp
->gm_group_list
);
4275 igmp_group_delete(grp
);
4279 struct gm_if
*gm_ifp
;
4281 gm_ifp
= pim_ifp
->mld
;
4283 gm_group_delete(gm_ifp
);
4287 /* clean up all upstreams*/
4288 while ((up
= rb_pim_upstream_first(&pim
->upstream_head
)))
4289 pim_upstream_del(pim
, up
, __func__
);
4292 void clear_pim_statistics(struct pim_instance
*pim
)
4294 struct interface
*ifp
;
4298 pim
->bsm_dropped
= 0;
4300 /* scan interfaces */
4301 FOR_ALL_INTERFACES (pim
->vrf
, ifp
) {
4302 struct pim_interface
*pim_ifp
= ifp
->info
;
4307 pim_ifp
->pim_ifstat_bsm_cfg_miss
= 0;
4308 pim_ifp
->pim_ifstat_ucast_bsm_cfg_miss
= 0;
4309 pim_ifp
->pim_ifstat_bsm_invalid_sz
= 0;
4313 int clear_pim_interface_traffic(const char *vrf
, struct vty
*vty
)
4315 struct interface
*ifp
= NULL
;
4316 struct pim_interface
*pim_ifp
= NULL
;
4318 struct vrf
*v
= pim_cmd_lookup(vty
, vrf
);
4323 FOR_ALL_INTERFACES (v
, ifp
) {
4324 pim_ifp
= ifp
->info
;
4329 pim_ifp
->pim_ifstat_hello_recv
= 0;
4330 pim_ifp
->pim_ifstat_hello_sent
= 0;
4331 pim_ifp
->pim_ifstat_join_recv
= 0;
4332 pim_ifp
->pim_ifstat_join_send
= 0;
4333 pim_ifp
->pim_ifstat_prune_recv
= 0;
4334 pim_ifp
->pim_ifstat_prune_send
= 0;
4335 pim_ifp
->pim_ifstat_reg_recv
= 0;
4336 pim_ifp
->pim_ifstat_reg_send
= 0;
4337 pim_ifp
->pim_ifstat_reg_stop_recv
= 0;
4338 pim_ifp
->pim_ifstat_reg_stop_send
= 0;
4339 pim_ifp
->pim_ifstat_assert_recv
= 0;
4340 pim_ifp
->pim_ifstat_assert_send
= 0;
4341 pim_ifp
->pim_ifstat_bsm_rx
= 0;
4342 pim_ifp
->pim_ifstat_bsm_tx
= 0;
4344 pim_ifp
->igmp_ifstat_joins_sent
= 0;
4345 pim_ifp
->igmp_ifstat_joins_failed
= 0;
4346 pim_ifp
->igmp_peak_group_count
= 0;
4353 int pim_debug_pim_cmd(void)
4355 PIM_DO_DEBUG_PIM_EVENTS
;
4356 PIM_DO_DEBUG_PIM_PACKETS
;
4357 PIM_DO_DEBUG_PIM_TRACE
;
4358 PIM_DO_DEBUG_MSDP_EVENTS
;
4359 PIM_DO_DEBUG_MSDP_PACKETS
;
4365 int pim_no_debug_pim_cmd(void)
4367 PIM_DONT_DEBUG_PIM_EVENTS
;
4368 PIM_DONT_DEBUG_PIM_PACKETS
;
4369 PIM_DONT_DEBUG_PIM_TRACE
;
4370 PIM_DONT_DEBUG_MSDP_EVENTS
;
4371 PIM_DONT_DEBUG_MSDP_PACKETS
;
4373 PIM_DONT_DEBUG_PIM_PACKETDUMP_SEND
;
4374 PIM_DONT_DEBUG_PIM_PACKETDUMP_RECV
;
4376 PIM_DONT_DEBUG_VXLAN
;
4380 int pim_debug_pim_packets_cmd(const char *hello
, const char *joins
,
4381 const char *registers
, struct vty
*vty
)
4384 PIM_DO_DEBUG_PIM_HELLO
;
4385 vty_out(vty
, "PIM Hello debugging is on\n");
4387 PIM_DO_DEBUG_PIM_J_P
;
4388 vty_out(vty
, "PIM Join/Prune debugging is on\n");
4389 } else if (registers
) {
4390 PIM_DO_DEBUG_PIM_REG
;
4391 vty_out(vty
, "PIM Register debugging is on\n");
4393 PIM_DO_DEBUG_PIM_PACKETS
;
4394 vty_out(vty
, "PIM Packet debugging is on\n");
4399 int pim_no_debug_pim_packets_cmd(const char *hello
, const char *joins
,
4400 const char *registers
, struct vty
*vty
)
4403 PIM_DONT_DEBUG_PIM_HELLO
;
4404 vty_out(vty
, "PIM Hello debugging is off\n");
4406 PIM_DONT_DEBUG_PIM_J_P
;
4407 vty_out(vty
, "PIM Join/Prune debugging is off\n");
4408 } else if (registers
) {
4409 PIM_DONT_DEBUG_PIM_REG
;
4410 vty_out(vty
, "PIM Register debugging is off\n");
4412 PIM_DONT_DEBUG_PIM_PACKETS
;
4413 vty_out(vty
, "PIM Packet debugging is off\n");
4419 int pim_show_rpf_helper(const char *vrf
, struct vty
*vty
, bool json
)
4421 struct pim_instance
*pim
;
4423 json_object
*json_parent
= NULL
;
4425 v
= vrf_lookup_by_name(vrf
? vrf
: VRF_DEFAULT_NAME
);
4433 vty_out(vty
, "%% Unable to find pim instance\n");
4438 json_parent
= json_object_new_object();
4440 pim_show_rpf(pim
, vty
, json_parent
);
4443 vty_json(vty
, json_parent
);
4448 int pim_show_rpf_vrf_all_helper(struct vty
*vty
, bool json
)
4451 json_object
*json_parent
= NULL
;
4452 json_object
*json_vrf
= NULL
;
4455 json_parent
= json_object_new_object();
4457 RB_FOREACH (vrf
, vrf_name_head
, &vrfs_by_name
) {
4459 vty_out(vty
, "VRF: %s\n", vrf
->name
);
4461 json_vrf
= json_object_new_object();
4462 pim_show_rpf(vrf
->info
, vty
, json_vrf
);
4464 json_object_object_add(json_parent
, vrf
->name
,
4468 vty_json(vty
, json_parent
);
4473 int pim_show_rp_helper(const char *vrf
, struct vty
*vty
, const char *group_str
,
4474 const struct prefix
*group
, bool json
)
4476 struct pim_instance
*pim
;
4478 json_object
*json_parent
= NULL
;
4479 struct prefix
*range
= NULL
;
4481 v
= vrf_lookup_by_name(vrf
? vrf
: VRF_DEFAULT_NAME
);
4489 vty_out(vty
, "%% Unable to find pim instance\n");
4494 range
= prefix_new();
4495 prefix_copy(range
, group
);
4500 json_parent
= json_object_new_object();
4502 pim_rp_show_information(pim
, range
, vty
, json_parent
);
4505 vty_json(vty
, json_parent
);
4507 prefix_free(&range
);
4512 int pim_show_rp_vrf_all_helper(struct vty
*vty
, const char *group_str
,
4513 const struct prefix
*group
, bool json
)
4516 json_object
*json_parent
= NULL
;
4517 json_object
*json_vrf
= NULL
;
4518 struct prefix
*range
= NULL
;
4521 range
= prefix_new();
4522 prefix_copy(range
, group
);
4527 json_parent
= json_object_new_object();
4529 RB_FOREACH (vrf
, vrf_name_head
, &vrfs_by_name
) {
4531 vty_out(vty
, "VRF: %s\n", vrf
->name
);
4533 json_vrf
= json_object_new_object();
4534 pim_rp_show_information(vrf
->info
, range
, vty
, json_vrf
);
4536 json_object_object_add(json_parent
, vrf
->name
,
4540 vty_json(vty
, json_parent
);
4542 prefix_free(&range
);
4547 int pim_show_secondary_helper(const char *vrf
, struct vty
*vty
)
4549 struct pim_instance
*pim
;
4552 v
= vrf_lookup_by_name(vrf
? vrf
: VRF_DEFAULT_NAME
);
4560 vty_out(vty
, "%% Unable to find pim instance\n");
4564 pim_show_neighbors_secondary(pim
, vty
);
4569 int pim_show_statistics_helper(const char *vrf
, struct vty
*vty
,
4570 const char *word
, bool uj
)
4572 struct pim_instance
*pim
;
4575 v
= vrf_lookup_by_name(vrf
? vrf
: VRF_DEFAULT_NAME
);
4583 vty_out(vty
, "%% Unable to find pim instance\n");
4588 pim_show_statistics(pim
, vty
, word
, uj
);
4590 pim_show_statistics(pim
, vty
, NULL
, uj
);
4595 int pim_show_upstream_helper(const char *vrf
, struct vty
*vty
, pim_addr s_or_g
,
4596 pim_addr g
, bool json
)
4598 pim_sgaddr sg
= {0};
4600 struct pim_instance
*pim
;
4601 json_object
*json_parent
= NULL
;
4603 v
= vrf_lookup_by_name(vrf
? vrf
: VRF_DEFAULT_NAME
);
4606 vty_out(vty
, "%% Vrf specified: %s does not exist\n", vrf
);
4612 vty_out(vty
, "%% Unable to find pim instance\n");
4617 json_parent
= json_object_new_object();
4619 if (!pim_addr_is_any(s_or_g
)) {
4620 if (!pim_addr_is_any(g
)) {
4627 pim_show_upstream(pim
, vty
, &sg
, json_parent
);
4630 vty_json(vty
, json_parent
);
4635 int pim_show_upstream_vrf_all_helper(struct vty
*vty
, bool json
)
4637 pim_sgaddr sg
= {0};
4639 json_object
*json_parent
= NULL
;
4640 json_object
*json_vrf
= NULL
;
4643 json_parent
= json_object_new_object();
4645 RB_FOREACH (vrf
, vrf_name_head
, &vrfs_by_name
) {
4647 vty_out(vty
, "VRF: %s\n", vrf
->name
);
4649 json_vrf
= json_object_new_object();
4650 pim_show_upstream(vrf
->info
, vty
, &sg
, json_vrf
);
4652 json_object_object_add(json_parent
, vrf
->name
,
4657 vty_json(vty
, json_parent
);
4662 int pim_show_upstream_join_desired_helper(const char *vrf
, struct vty
*vty
,
4665 struct pim_instance
*pim
;
4668 v
= vrf_lookup_by_name(vrf
? vrf
: VRF_DEFAULT_NAME
);
4676 vty_out(vty
, "%% Unable to find pim instance\n");
4680 pim_show_join_desired(pim
, vty
, uj
);
4685 int pim_show_upstream_rpf_helper(const char *vrf
, struct vty
*vty
, bool uj
)
4687 struct pim_instance
*pim
;
4690 v
= vrf_lookup_by_name(vrf
? vrf
: VRF_DEFAULT_NAME
);
4698 vty_out(vty
, "%% Unable to find pim instance\n");
4702 pim_show_upstream_rpf(pim
, vty
, uj
);
4707 int pim_show_state_helper(const char *vrf
, struct vty
*vty
,
4708 const char *s_or_g_str
, const char *g_str
, bool json
)
4710 struct pim_instance
*pim
;
4712 json_object
*json_parent
= NULL
;
4714 v
= vrf_lookup_by_name(vrf
? vrf
: VRF_DEFAULT_NAME
);
4722 vty_out(vty
, "%% Unable to find pim instance\n");
4727 json_parent
= json_object_new_object();
4729 pim_show_state(pim
, vty
, s_or_g_str
, g_str
, json_parent
);
4732 vty_json(vty
, json_parent
);
4737 int pim_show_state_vrf_all_helper(struct vty
*vty
, const char *s_or_g_str
,
4738 const char *g_str
, bool json
)
4741 json_object
*json_parent
= NULL
;
4742 json_object
*json_vrf
= NULL
;
4745 json_parent
= json_object_new_object();
4747 RB_FOREACH (vrf
, vrf_name_head
, &vrfs_by_name
) {
4749 vty_out(vty
, "VRF: %s\n", vrf
->name
);
4751 json_vrf
= json_object_new_object();
4752 pim_show_state(vrf
->info
, vty
, s_or_g_str
, g_str
, json_vrf
);
4754 json_object_object_add(json_parent
, vrf
->name
,
4758 vty_json(vty
, json_parent
);
4763 int pim_show_multicast_helper(const char *vrf
, struct vty
*vty
)
4766 struct pim_instance
*pim
;
4768 v
= vrf_lookup_by_name(vrf
? vrf
: VRF_DEFAULT_NAME
);
4776 vty_out(vty
, "%% Unable to find pim instance\n");
4780 pim_cmd_show_ip_multicast_helper(pim
, vty
);
4785 int pim_show_multicast_vrf_all_helper(struct vty
*vty
)
4789 RB_FOREACH (vrf
, vrf_name_head
, &vrfs_by_name
) {
4790 vty_out(vty
, "VRF: %s\n", vrf
->name
);
4791 pim_cmd_show_ip_multicast_helper(vrf
->info
, vty
);
4797 int pim_show_multicast_count_helper(const char *vrf
, struct vty
*vty
, bool json
)
4799 struct pim_instance
*pim
;
4801 json_object
*json_parent
= NULL
;
4803 v
= vrf_lookup_by_name(vrf
? vrf
: VRF_DEFAULT_NAME
);
4811 vty_out(vty
, "%% Unable to find pim instance\n");
4816 json_parent
= json_object_new_object();
4818 show_multicast_interfaces(pim
, vty
, json_parent
);
4821 vty_json(vty
, json_parent
);
4826 int pim_show_multicast_count_vrf_all_helper(struct vty
*vty
, bool json
)
4829 json_object
*json_parent
= NULL
;
4830 json_object
*json_vrf
= NULL
;
4833 json_parent
= json_object_new_object();
4835 RB_FOREACH (vrf
, vrf_name_head
, &vrfs_by_name
) {
4837 vty_out(vty
, "VRF: %s\n", vrf
->name
);
4839 json_vrf
= json_object_new_object();
4841 show_multicast_interfaces(vrf
->info
, vty
, json_vrf
);
4843 json_object_object_add(json_parent
, vrf
->name
,
4847 vty_json(vty
, json_parent
);
4852 int pim_show_mroute_helper(const char *vrf
, struct vty
*vty
, pim_addr s_or_g
,
4853 pim_addr g
, bool fill
, bool json
)
4855 pim_sgaddr sg
= {0};
4856 struct pim_instance
*pim
;
4858 json_object
*json_parent
= NULL
;
4860 v
= vrf_lookup_by_name(vrf
? vrf
: VRF_DEFAULT_NAME
);
4868 vty_out(vty
, "%% Unable to find pim instance\n");
4873 json_parent
= json_object_new_object();
4875 if (!pim_addr_is_any(s_or_g
)) {
4876 if (!pim_addr_is_any(g
)) {
4883 show_mroute(pim
, vty
, &sg
, fill
, json_parent
);
4886 vty_json(vty
, json_parent
);
4891 int pim_show_mroute_vrf_all_helper(struct vty
*vty
, bool fill
, bool json
)
4893 pim_sgaddr sg
= {0};
4895 json_object
*json_parent
= NULL
;
4896 json_object
*json_vrf
= NULL
;
4899 json_parent
= json_object_new_object();
4901 RB_FOREACH (vrf
, vrf_name_head
, &vrfs_by_name
) {
4903 vty_out(vty
, "VRF: %s\n", vrf
->name
);
4905 json_vrf
= json_object_new_object();
4906 show_mroute(vrf
->info
, vty
, &sg
, fill
, json_vrf
);
4908 json_object_object_add(json_parent
, vrf
->name
,
4912 vty_json(vty
, json_parent
);
4917 int pim_show_mroute_count_helper(const char *vrf
, struct vty
*vty
, bool json
)
4919 struct pim_instance
*pim
;
4921 json_object
*json_parent
= NULL
;
4923 v
= vrf_lookup_by_name(vrf
? vrf
: VRF_DEFAULT_NAME
);
4931 vty_out(vty
, "%% Unable to find pim instance\n");
4936 json_parent
= json_object_new_object();
4938 show_mroute_count(pim
, vty
, json_parent
);
4941 vty_json(vty
, json_parent
);
4946 int pim_show_mroute_count_vrf_all_helper(struct vty
*vty
, bool json
)
4949 json_object
*json_parent
= NULL
;
4950 json_object
*json_vrf
= NULL
;
4953 json_parent
= json_object_new_object();
4955 RB_FOREACH (vrf
, vrf_name_head
, &vrfs_by_name
) {
4957 vty_out(vty
, "VRF: %s\n", vrf
->name
);
4959 json_vrf
= json_object_new_object();
4961 show_mroute_count(vrf
->info
, vty
, json_vrf
);
4964 json_object_object_add(json_parent
, vrf
->name
,
4968 vty_json(vty
, json_parent
);
4973 int pim_show_mroute_summary_helper(const char *vrf
, struct vty
*vty
, bool json
)
4975 struct pim_instance
*pim
;
4977 json_object
*json_parent
= NULL
;
4979 v
= vrf_lookup_by_name(vrf
? vrf
: VRF_DEFAULT_NAME
);
4987 vty_out(vty
, "%% Unable to find pim instance\n");
4992 json_parent
= json_object_new_object();
4994 show_mroute_summary(pim
, vty
, json_parent
);
4997 vty_json(vty
, json_parent
);
5002 int pim_show_mroute_summary_vrf_all_helper(struct vty
*vty
, bool json
)
5005 json_object
*json_parent
= NULL
;
5006 json_object
*json_vrf
= NULL
;
5009 json_parent
= json_object_new_object();
5011 RB_FOREACH (vrf
, vrf_name_head
, &vrfs_by_name
) {
5013 vty_out(vty
, "VRF: %s\n", vrf
->name
);
5015 json_vrf
= json_object_new_object();
5017 show_mroute_summary(vrf
->info
, vty
, json_vrf
);
5020 json_object_object_add(json_parent
, vrf
->name
,
5025 vty_json(vty
, json_parent
);
5030 void pim_show_interface_traffic(struct pim_instance
*pim
, struct vty
*vty
,
5033 struct interface
*ifp
= NULL
;
5034 struct pim_interface
*pim_ifp
= NULL
;
5035 json_object
*json
= NULL
;
5036 json_object
*json_row
= NULL
;
5039 json
= json_object_new_object();
5042 vty_out(vty
, "%-16s%-17s%-17s%-17s%-17s%-17s%-17s%-17s\n",
5043 "Interface", " HELLO", " JOIN",
5044 " PRUNE", " REGISTER", "REGISTER-STOP",
5046 vty_out(vty
, "%-16s%-17s%-17s%-17s%-17s%-17s%-17s%-17s\n", "",
5047 " Rx/Tx", " Rx/Tx", " Rx/Tx",
5048 " Rx/Tx", " Rx/Tx", " Rx/Tx", " Rx/Tx");
5050 "---------------------------------------------------------------------------------------------------------------\n");
5053 FOR_ALL_INTERFACES (pim
->vrf
, ifp
) {
5054 pim_ifp
= ifp
->info
;
5060 json_row
= json_object_new_object();
5061 json_object_pim_ifp_add(json_row
, ifp
);
5062 json_object_int_add(json_row
, "helloRx",
5063 pim_ifp
->pim_ifstat_hello_recv
);
5064 json_object_int_add(json_row
, "helloTx",
5065 pim_ifp
->pim_ifstat_hello_sent
);
5066 json_object_int_add(json_row
, "joinRx",
5067 pim_ifp
->pim_ifstat_join_recv
);
5068 json_object_int_add(json_row
, "joinTx",
5069 pim_ifp
->pim_ifstat_join_send
);
5070 json_object_int_add(json_row
, "pruneRx",
5071 pim_ifp
->pim_ifstat_prune_recv
);
5072 json_object_int_add(json_row
, "pruneTx",
5073 pim_ifp
->pim_ifstat_prune_send
);
5074 json_object_int_add(json_row
, "registerRx",
5075 pim_ifp
->pim_ifstat_reg_recv
);
5076 json_object_int_add(json_row
, "registerTx",
5077 pim_ifp
->pim_ifstat_reg_send
);
5078 json_object_int_add(json_row
, "registerStopRx",
5079 pim_ifp
->pim_ifstat_reg_stop_recv
);
5080 json_object_int_add(json_row
, "registerStopTx",
5081 pim_ifp
->pim_ifstat_reg_stop_send
);
5082 json_object_int_add(json_row
, "assertRx",
5083 pim_ifp
->pim_ifstat_assert_recv
);
5084 json_object_int_add(json_row
, "assertTx",
5085 pim_ifp
->pim_ifstat_assert_send
);
5086 json_object_int_add(json_row
, "bsmRx",
5087 pim_ifp
->pim_ifstat_bsm_rx
);
5088 json_object_int_add(json_row
, "bsmTx",
5089 pim_ifp
->pim_ifstat_bsm_tx
);
5090 json_object_object_add(json
, ifp
->name
, json_row
);
5093 "%-16s %8u/%-8u %7u/%-7u %7u/%-7u %7u/%-7u %7u/%-7u %7u/%-7u %7" PRIu64
5095 ifp
->name
, pim_ifp
->pim_ifstat_hello_recv
,
5096 pim_ifp
->pim_ifstat_hello_sent
,
5097 pim_ifp
->pim_ifstat_join_recv
,
5098 pim_ifp
->pim_ifstat_join_send
,
5099 pim_ifp
->pim_ifstat_prune_recv
,
5100 pim_ifp
->pim_ifstat_prune_send
,
5101 pim_ifp
->pim_ifstat_reg_recv
,
5102 pim_ifp
->pim_ifstat_reg_send
,
5103 pim_ifp
->pim_ifstat_reg_stop_recv
,
5104 pim_ifp
->pim_ifstat_reg_stop_send
,
5105 pim_ifp
->pim_ifstat_assert_recv
,
5106 pim_ifp
->pim_ifstat_assert_send
,
5107 pim_ifp
->pim_ifstat_bsm_rx
,
5108 pim_ifp
->pim_ifstat_bsm_tx
);
5112 vty_json(vty
, json
);
5115 void pim_show_interface_traffic_single(struct pim_instance
*pim
,
5116 struct vty
*vty
, const char *ifname
,
5119 struct interface
*ifp
= NULL
;
5120 struct pim_interface
*pim_ifp
= NULL
;
5121 json_object
*json
= NULL
;
5122 json_object
*json_row
= NULL
;
5123 uint8_t found_ifname
= 0;
5126 json
= json_object_new_object();
5129 vty_out(vty
, "%-16s%-17s%-17s%-17s%-17s%-17s%-17s%-17s\n",
5130 "Interface", " HELLO", " JOIN", " PRUNE",
5131 " REGISTER", " REGISTER-STOP", " ASSERT",
5133 vty_out(vty
, "%-14s%-18s%-17s%-17s%-17s%-17s%-17s%-17s\n", "",
5134 " Rx/Tx", " Rx/Tx", " Rx/Tx", " Rx/Tx",
5135 " Rx/Tx", " Rx/Tx", " Rx/Tx");
5137 "-------------------------------------------------------------------------------------------------------------------------------\n");
5140 FOR_ALL_INTERFACES (pim
->vrf
, ifp
) {
5141 if (strcmp(ifname
, ifp
->name
))
5144 pim_ifp
= ifp
->info
;
5151 json_row
= json_object_new_object();
5152 json_object_pim_ifp_add(json_row
, ifp
);
5153 json_object_int_add(json_row
, "helloRx",
5154 pim_ifp
->pim_ifstat_hello_recv
);
5155 json_object_int_add(json_row
, "helloTx",
5156 pim_ifp
->pim_ifstat_hello_sent
);
5157 json_object_int_add(json_row
, "joinRx",
5158 pim_ifp
->pim_ifstat_join_recv
);
5159 json_object_int_add(json_row
, "joinTx",
5160 pim_ifp
->pim_ifstat_join_send
);
5161 json_object_int_add(json_row
, "pruneRx",
5162 pim_ifp
->pim_ifstat_prune_recv
);
5163 json_object_int_add(json_row
, "pruneTx",
5164 pim_ifp
->pim_ifstat_prune_send
);
5165 json_object_int_add(json_row
, "registerRx",
5166 pim_ifp
->pim_ifstat_reg_recv
);
5167 json_object_int_add(json_row
, "registerTx",
5168 pim_ifp
->pim_ifstat_reg_send
);
5169 json_object_int_add(json_row
, "registerStopRx",
5170 pim_ifp
->pim_ifstat_reg_stop_recv
);
5171 json_object_int_add(json_row
, "registerStopTx",
5172 pim_ifp
->pim_ifstat_reg_stop_send
);
5173 json_object_int_add(json_row
, "assertRx",
5174 pim_ifp
->pim_ifstat_assert_recv
);
5175 json_object_int_add(json_row
, "assertTx",
5176 pim_ifp
->pim_ifstat_assert_send
);
5177 json_object_int_add(json_row
, "bsmRx",
5178 pim_ifp
->pim_ifstat_bsm_rx
);
5179 json_object_int_add(json_row
, "bsmTx",
5180 pim_ifp
->pim_ifstat_bsm_tx
);
5182 json_object_object_add(json
, ifp
->name
, json_row
);
5185 "%-16s %8u/%-8u %7u/%-7u %7u/%-7u %7u/%-7u %7u/%-7u %7u/%-7u %7" PRIu64
5187 ifp
->name
, pim_ifp
->pim_ifstat_hello_recv
,
5188 pim_ifp
->pim_ifstat_hello_sent
,
5189 pim_ifp
->pim_ifstat_join_recv
,
5190 pim_ifp
->pim_ifstat_join_send
,
5191 pim_ifp
->pim_ifstat_prune_recv
,
5192 pim_ifp
->pim_ifstat_prune_send
,
5193 pim_ifp
->pim_ifstat_reg_recv
,
5194 pim_ifp
->pim_ifstat_reg_send
,
5195 pim_ifp
->pim_ifstat_reg_stop_recv
,
5196 pim_ifp
->pim_ifstat_reg_stop_send
,
5197 pim_ifp
->pim_ifstat_assert_recv
,
5198 pim_ifp
->pim_ifstat_assert_send
,
5199 pim_ifp
->pim_ifstat_bsm_rx
,
5200 pim_ifp
->pim_ifstat_bsm_tx
);
5204 vty_json(vty
, json
);
5205 else if (!found_ifname
)
5206 vty_out(vty
, "%% No such interface\n");
5209 int pim_show_interface_traffic_helper(const char *vrf
, const char *if_name
,
5210 struct vty
*vty
, bool uj
)
5212 struct pim_instance
*pim
;
5215 v
= vrf_lookup_by_name(vrf
? vrf
: VRF_DEFAULT_NAME
);
5223 vty_out(vty
, "%% Unable to find pim instance\n");
5228 pim_show_interface_traffic_single(v
->info
, vty
, if_name
, uj
);
5230 pim_show_interface_traffic(v
->info
, vty
, uj
);
5235 void clear_pim_interfaces(struct pim_instance
*pim
)
5237 struct interface
*ifp
;
5239 FOR_ALL_INTERFACES (pim
->vrf
, ifp
) {
5241 pim_neighbor_delete_all(ifp
, "interface cleared");
5245 void pim_show_bsr(struct pim_instance
*pim
, struct vty
*vty
, bool uj
)
5248 char last_bsm_seen
[10];
5251 json_object
*json
= NULL
;
5253 if (pim_addr_is_any(pim
->global_scope
.current_bsr
)) {
5254 pim_time_uptime(uptime
, sizeof(uptime
),
5255 pim
->global_scope
.current_bsr_first_ts
);
5256 pim_time_uptime(last_bsm_seen
, sizeof(last_bsm_seen
),
5257 pim
->global_scope
.current_bsr_last_ts
);
5261 now
= pim_time_monotonic_sec();
5262 pim_time_uptime(uptime
, sizeof(uptime
),
5263 (now
- pim
->global_scope
.current_bsr_first_ts
));
5264 pim_time_uptime(last_bsm_seen
, sizeof(last_bsm_seen
),
5265 now
- pim
->global_scope
.current_bsr_last_ts
);
5268 switch (pim
->global_scope
.state
) {
5270 strlcpy(bsr_state
, "NO_INFO", sizeof(bsr_state
));
5273 strlcpy(bsr_state
, "ACCEPT_ANY", sizeof(bsr_state
));
5275 case ACCEPT_PREFERRED
:
5276 strlcpy(bsr_state
, "ACCEPT_PREFERRED", sizeof(bsr_state
));
5279 strlcpy(bsr_state
, "", sizeof(bsr_state
));
5284 json
= json_object_new_object();
5285 json_object_string_addf(json
, "bsr", "%pPA",
5286 &pim
->global_scope
.current_bsr
);
5287 json_object_int_add(json
, "priority",
5288 pim
->global_scope
.current_bsr_prio
);
5289 json_object_int_add(json
, "fragmentTag",
5290 pim
->global_scope
.bsm_frag_tag
);
5291 json_object_string_add(json
, "state", bsr_state
);
5292 json_object_string_add(json
, "upTime", uptime
);
5293 json_object_string_add(json
, "lastBsmSeen", last_bsm_seen
);
5297 vty_out(vty
, "PIMv2 Bootstrap information\n");
5298 vty_out(vty
, "Current preferred BSR address: %pPA\n",
5299 &pim
->global_scope
.current_bsr
);
5301 "Priority Fragment-Tag State UpTime\n");
5302 vty_out(vty
, " %-12d %-12d %-13s %7s\n",
5303 pim
->global_scope
.current_bsr_prio
,
5304 pim
->global_scope
.bsm_frag_tag
, bsr_state
, uptime
);
5305 vty_out(vty
, "Last BSM seen: %s\n", last_bsm_seen
);
5309 vty_json(vty
, json
);
5312 int pim_show_bsr_helper(const char *vrf
, struct vty
*vty
, bool uj
)
5314 struct pim_instance
*pim
;
5317 v
= vrf_lookup_by_name(vrf
? vrf
: VRF_DEFAULT_NAME
);
5322 pim
= pim_get_pim_instance(v
->vrf_id
);
5325 vty_out(vty
, "%% Unable to find pim instance\n");
5329 pim_show_bsr(v
->info
, vty
, uj
);
5334 /*Display the group-rp mappings */
5335 static void pim_show_group_rp_mappings_info(struct pim_instance
*pim
,
5336 struct vty
*vty
, bool uj
)
5338 struct bsgrp_node
*bsgrp
;
5339 struct bsm_rpinfo
*bsm_rp
;
5340 struct route_node
*rn
;
5341 json_object
*json
= NULL
;
5342 json_object
*json_group
= NULL
;
5343 json_object
*json_row
= NULL
;
5344 struct ttable
*tt
= NULL
;
5347 json
= json_object_new_object();
5348 json_object_string_addf(json
, "BSR Address", "%pPA",
5349 &pim
->global_scope
.current_bsr
);
5351 vty_out(vty
, "BSR Address %pPA\n",
5352 &pim
->global_scope
.current_bsr
);
5354 for (rn
= route_top(pim
->global_scope
.bsrp_table
); rn
;
5355 rn
= route_next(rn
)) {
5356 bsgrp
= (struct bsgrp_node
*)rn
->info
;
5361 char grp_str
[PREFIX_STRLEN
];
5363 prefix2str(&bsgrp
->group
, grp_str
, sizeof(grp_str
));
5366 json_object_object_get_ex(json
, grp_str
, &json_group
);
5368 json_group
= json_object_new_object();
5369 json_object_object_add(json
, grp_str
,
5373 vty_out(vty
, "Group Address %pFX\n", &bsgrp
->group
);
5374 vty_out(vty
, "--------------------------\n");
5375 /* Prepare table. */
5376 tt
= ttable_new(&ttable_styles
[TTSTYLE_BLANK
]);
5377 ttable_add_row(tt
, "Rp Address|priority|Holdtime|Hash");
5378 tt
->style
.cell
.rpad
= 2;
5379 tt
->style
.corner
= '+';
5382 ttable_add_row(tt
, "%s|%c|%c|%c", "(ACTIVE)", ' ', ' ',
5386 frr_each (bsm_rpinfos
, bsgrp
->bsrp_list
, bsm_rp
) {
5388 json_row
= json_object_new_object();
5389 json_object_string_addf(json_row
, "Rp Address",
5391 &bsm_rp
->rp_address
);
5392 json_object_int_add(json_row
, "Rp HoldTime",
5393 bsm_rp
->rp_holdtime
);
5394 json_object_int_add(json_row
, "Rp Priority",
5396 json_object_int_add(json_row
, "Hash Val",
5398 json_object_object_addf(json_group
, json_row
,
5400 &bsm_rp
->rp_address
);
5404 tt
, "%pPA|%u|%u|%u",
5405 &bsm_rp
->rp_address
, bsm_rp
->rp_prio
,
5406 bsm_rp
->rp_holdtime
, bsm_rp
->hash
);
5409 /* Dump the generated table. */
5413 table
= ttable_dump(tt
, "\n");
5414 vty_out(vty
, "%s\n", table
);
5415 XFREE(MTYPE_TMP
, table
);
5419 if (!bsm_rpinfos_count(bsgrp
->bsrp_list
) && !uj
)
5420 vty_out(vty
, "Active List is empty.\n");
5423 json_object_int_add(json_group
, "Pending RP count",
5424 bsgrp
->pend_rp_cnt
);
5426 vty_out(vty
, "(PENDING)\n");
5427 vty_out(vty
, "Pending RP count :%d\n",
5428 bsgrp
->pend_rp_cnt
);
5429 if (bsgrp
->pend_rp_cnt
) {
5430 /* Prepare table. */
5431 tt
= ttable_new(&ttable_styles
[TTSTYLE_BLANK
]);
5434 "Rp Address|priority|Holdtime|Hash");
5435 tt
->style
.cell
.rpad
= 2;
5436 tt
->style
.corner
= '+';
5441 frr_each (bsm_rpinfos
, bsgrp
->partial_bsrp_list
, bsm_rp
) {
5443 json_row
= json_object_new_object();
5444 json_object_string_addf(json_row
, "Rp Address",
5446 &bsm_rp
->rp_address
);
5447 json_object_int_add(json_row
, "Rp HoldTime",
5448 bsm_rp
->rp_holdtime
);
5449 json_object_int_add(json_row
, "Rp Priority",
5451 json_object_int_add(json_row
, "Hash Val",
5453 json_object_object_addf(json_group
, json_row
,
5455 &bsm_rp
->rp_address
);
5458 tt
, "%pPA|%u|%u|%u",
5459 &bsm_rp
->rp_address
, bsm_rp
->rp_prio
,
5460 bsm_rp
->rp_holdtime
, bsm_rp
->hash
);
5463 /* Dump the generated table. */
5467 table
= ttable_dump(tt
, "\n");
5468 vty_out(vty
, "%s\n", table
);
5469 XFREE(MTYPE_TMP
, table
);
5472 if (!bsm_rpinfos_count(bsgrp
->partial_bsrp_list
) && !uj
)
5473 vty_out(vty
, "Partial List is empty\n");
5480 vty_json(vty
, json
);
5483 int pim_show_group_rp_mappings_info_helper(const char *vrf
, struct vty
*vty
,
5486 struct pim_instance
*pim
;
5489 v
= vrf_lookup_by_name(vrf
? vrf
: VRF_DEFAULT_NAME
);
5497 vty_out(vty
, "%% Unable to find pim instance\n");
5501 pim_show_group_rp_mappings_info(v
->info
, vty
, uj
);
5506 /* Display the bsm database details */
5507 static void pim_show_bsm_db(struct pim_instance
*pim
, struct vty
*vty
, bool uj
)
5511 struct bsm_frag
*bsfrag
;
5512 json_object
*json
= NULL
;
5513 json_object
*json_group
= NULL
;
5514 json_object
*json_row
= NULL
;
5516 count
= bsm_frags_count(pim
->global_scope
.bsm_frags
);
5519 json
= json_object_new_object();
5520 json_object_int_add(json
, "Number of the fragments", count
);
5522 vty_out(vty
, "Scope Zone: Global\n");
5523 vty_out(vty
, "Number of the fragments: %d\n", count
);
5527 frr_each (bsm_frags
, pim
->global_scope
.bsm_frags
, bsfrag
) {
5528 char grp_str
[PREFIX_STRLEN
];
5529 struct bsmmsg_grpinfo
*group
;
5530 struct bsmmsg_rpinfo
*bsm_rpinfo
;
5532 struct bsm_hdr
*hdr
;
5534 uint32_t offset
= 0;
5537 uint32_t frag_rp_cnt
= 0;
5542 /* skip pim header */
5543 buf
+= PIM_MSG_HEADER_LEN
;
5544 len
-= PIM_MSG_HEADER_LEN
;
5546 hdr
= (struct bsm_hdr
*)buf
;
5547 /* NB: bshdr->bsr_addr.addr is packed/unaligned => memcpy */
5548 memcpy(&bsr_addr
, &hdr
->bsr_addr
.addr
, sizeof(bsr_addr
));
5550 /* BSM starts with bsr header */
5551 buf
+= sizeof(struct bsm_hdr
);
5552 len
-= sizeof(struct bsm_hdr
);
5555 json_object_string_addf(json
, "BSR address", "%pPA",
5557 json_object_int_add(json
, "BSR priority",
5559 json_object_int_add(json
, "Hashmask Length",
5561 json_object_int_add(json
, "Fragment Tag",
5562 ntohs(hdr
->frag_tag
));
5564 vty_out(vty
, "BSM Fragment : %d\n", fragment
);
5565 vty_out(vty
, "------------------\n");
5566 vty_out(vty
, "%-15s %-15s %-15s %-15s\n", "BSR-Address",
5567 "BSR-Priority", "Hashmask-len", "Fragment-Tag");
5568 vty_out(vty
, "%-15pPA %-15d %-15d %-15d\n", &bsr_addr
,
5569 hdr
->bsr_prio
, hdr
->hm_len
,
5570 ntohs(hdr
->frag_tag
));
5575 while (offset
< len
) {
5576 group
= (struct bsmmsg_grpinfo
*)buf
;
5578 if (group
->group
.family
== PIM_MSG_ADDRESS_FAMILY_IPV4
)
5579 grp
.family
= AF_INET
;
5580 else if (group
->group
.family
==
5581 PIM_MSG_ADDRESS_FAMILY_IPV6
)
5582 grp
.family
= AF_INET6
;
5584 grp
.prefixlen
= group
->group
.mask
;
5586 grp
.u
.prefix4
= group
->group
.addr
;
5588 grp
.u
.prefix6
= group
->group
.addr
;
5591 prefix2str(&grp
, grp_str
, sizeof(grp_str
));
5593 buf
+= sizeof(struct bsmmsg_grpinfo
);
5594 offset
+= sizeof(struct bsmmsg_grpinfo
);
5597 json_object_object_get_ex(json
, grp_str
,
5600 json_group
= json_object_new_object();
5601 json_object_int_add(json_group
,
5604 json_object_int_add(
5605 json_group
, "Fragment Rp count",
5606 group
->frag_rp_count
);
5607 json_object_object_add(json
, grp_str
,
5611 vty_out(vty
, "Group : %s\n", grp_str
);
5612 vty_out(vty
, "-------------------\n");
5613 vty_out(vty
, "Rp Count:%d\n", group
->rp_count
);
5614 vty_out(vty
, "Fragment Rp Count : %d\n",
5615 group
->frag_rp_count
);
5618 frag_rp_cnt
= group
->frag_rp_count
;
5625 "RpAddress HoldTime Priority\n");
5627 while (frag_rp_cnt
--) {
5630 bsm_rpinfo
= (struct bsmmsg_rpinfo
*)buf
;
5631 /* unaligned, again */
5632 memcpy(&rp_addr
, &bsm_rpinfo
->rpaddr
.addr
,
5635 buf
+= sizeof(struct bsmmsg_rpinfo
);
5636 offset
+= sizeof(struct bsmmsg_rpinfo
);
5639 json_row
= json_object_new_object();
5640 json_object_string_addf(
5641 json_row
, "Rp Address", "%pPA",
5643 json_object_int_add(
5644 json_row
, "Rp HoldTime",
5645 ntohs(bsm_rpinfo
->rp_holdtime
));
5646 json_object_int_add(json_row
,
5648 bsm_rpinfo
->rp_pri
);
5649 json_object_object_addf(
5650 json_group
, json_row
, "%pPA",
5653 vty_out(vty
, "%-15pPA %-12d %d\n",
5655 ntohs(bsm_rpinfo
->rp_holdtime
),
5656 bsm_rpinfo
->rp_pri
);
5666 vty_json(vty
, json
);
5669 int pim_show_bsm_db_helper(const char *vrf
, struct vty
*vty
, bool uj
)
5671 struct pim_instance
*pim
;
5674 v
= vrf_lookup_by_name(vrf
? vrf
: VRF_DEFAULT_NAME
);
5682 vty_out(vty
, "%% Unable to find pim instance\n");
5686 pim_show_bsm_db(v
->info
, vty
, uj
);