LLDPD allows a peer to run multiple protocols (LLDP, CDPv1, CDPv2).
lldpcli can be used to show the primary protocol for a nbr or all
the protocols using the "hidden" cmdline arg
This allows lldpcli to filter the nbr display based on the
protocol that is running on it.
Signed-off-by: Kanna Rajagopal <kanna@cumulusnetworks.com>
Signed-off-by: Sam Tannous <stannous@cumulusnetworks.com>
lldpctl_atom_t* cmd_iterate_on_interfaces(struct lldpctl_conn_t *,
struct cmd_env *);
void cmd_restrict_ports(struct cmd_node *);
+void cmd_restrict_protocol(struct cmd_node *);
/* misc.c */
int contains(const char *, const char *);
void display_interfaces(lldpctl_conn_t *, struct writer *,
struct cmd_env *, int, int);
void display_interface(lldpctl_conn_t *, struct writer *, int,
- lldpctl_atom_t *, lldpctl_atom_t *, int);
+ lldpctl_atom_t *, lldpctl_atom_t *, int, int);
void display_configuration(lldpctl_conn_t *, struct writer *);
void display_interfaces_stats(lldpctl_conn_t *, struct writer *,
struct cmd_env *);
"Restrict configuration to the specified ports (comma-separated list)",
NULL, cmd_store_env_value_and_pop2, "ports");
}
+
+/**
+ * Restrict the command to specific protocol
+ */
+void
+cmd_restrict_protocol(struct cmd_node *root)
+{
+ /* Restrict to some ports. */
+ commands_new(
+ commands_new(root,
+ "protocol",
+ "Restrict to specific protocol",
+ cmd_check_no_env, NULL, "protocol"),
+ NULL,
+ "Restrict display to the specified protocol",
+ NULL, cmd_store_env_value_and_pop2, "protocol");
+}
void
display_interface(lldpctl_conn_t *conn, struct writer *w, int hidden,
- lldpctl_atom_t *iface, lldpctl_atom_t *neighbor, int details)
+ lldpctl_atom_t *iface, lldpctl_atom_t *neighbor, int details, int protocol)
{
if (!hidden &&
lldpctl_atom_get_int(neighbor, lldpctl_k_port_hidden))
return;
+ /* user might have specified protocol to filter on display */
+ if ((protocol != LLDPD_MODE_MAX) &&
+ (protocol != lldpctl_atom_get_int(neighbor, lldpctl_k_port_protocol)))
+ return;
+
tag_start(w, "interface", "Interface");
tag_attr(w, "name", "",
lldpctl_atom_get_str(iface, lldpctl_k_interface_name));
int hidden, int details)
{
lldpctl_atom_t *iface;
+ int protocol = LLDPD_MODE_MAX;
+ char *proto_str;
+
+ /* user might have specified protocol to filter display results */
+ proto_str = cmdenv_get(env, "protocol");
+
+ if (proto_str) {
+ log_debug("display", "filter protocol: %s ", proto_str);
+
+ if (!strcmp(proto_str, "cdpv1")) {
+ protocol = LLDPD_MODE_CDPV1;
+ } else if (!strcmp(proto_str, "cdpv2")) {
+ protocol = LLDPD_MODE_CDPV2;
+ } else if (!strcmp(proto_str, "lldp")) {
+ protocol = LLDPD_MODE_LLDP;
+ } else {
+ /* unsupported - dont show anything */
+ protocol = 0;
+ }
+ }
tag_start(w, "lldp", "LLDP neighbors");
while ((iface = cmd_iterate_on_interfaces(conn, env))) {
port = lldpctl_get_port(iface);
neighbors = lldpctl_atom_get(port, lldpctl_k_port_neighbors);
lldpctl_atom_foreach(neighbors, neighbor) {
- display_interface(conn, w, hidden, iface, neighbor, details);
+ display_interface(conn, w, hidden, iface, neighbor, details, protocol);
}
lldpctl_atom_dec_ref(neighbors);
lldpctl_atom_dec_ref(port);
struct cmd_env *env = wa->env;
struct writer *w = wa->w;
const char *interfaces = cmdenv_get(env, "ports");
+ char *proto_str;
+ int protocol = LLDPD_MODE_MAX;
+
if (interfaces && !contains(interfaces, lldpctl_atom_get_str(interface,
lldpctl_k_interface_name)))
return;
+ /* user might have specified protocol to filter display results */
+ proto_str = cmdenv_get(env, "protocol");
+
+ if (proto_str) {
+ log_debug("display", "filter protocol: %s ", proto_str);
+
+ if (!strcmp(proto_str, "cdpv1"))
+ protocol = LLDPD_MODE_CDPV1;
+ else if (!strcmp(proto_str, "cdpv2"))
+ protocol = LLDPD_MODE_CDPV2;
+ else if (!strcmp(proto_str, "lldp"))
+ protocol = LLDPD_MODE_LLDP;
+ else
+ /* unsupported - dont show anything */
+ protocol = 0;
+ }
+
switch (type) {
case lldpctl_c_deleted:
tag_start(w, "lldp-deleted", "LLDP neighbor deleted");
display_interface(conn, w, 1, interface, neighbor,
cmdenv_get(env, "summary")?DISPLAY_BRIEF:
cmdenv_get(env, "detailed")?DISPLAY_DETAILS:
- DISPLAY_NORMAL);
+ DISPLAY_NORMAL, protocol);
tag_end(w);
}
/* Some specific port */
cmd_restrict_ports(root);
+
+ /* Specific protocol */
+ cmd_restrict_protocol(root);
}
/**