Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

introduce vrrp commands #15

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 51 additions & 16 deletions src/internal_commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -192,8 +192,13 @@ impl<'a> YangTableBuilder<'a> {
}

// Builds and displays the table.
pub fn show(self) -> Result<(), String> {
let xpath_req = "/ietf-routing:routing/control-plane-protocols";
pub fn show(self, xpath_req: Option<String>) -> Result<(), String> {
// have a default xpath (ietf-routing:routing/control-plane-protocols)
// which is used by most of the other protocols.
let xpath_req = xpath_req.unwrap_or(String::from(
"/ietf-routing:routing/control-plane-protocols",
));
let xpath_req = xpath_req.as_str();

// Fetch data.
let data = fetch_data(self.session, self.data_type, xpath_req)?;
Expand Down Expand Up @@ -724,6 +729,37 @@ pub(crate) fn cmd_show_yang_modules(
Ok(false)
}

// ===== VRRP "show" commands =====

const XPATH_INTERFACE: &str = "/ietf-interfaces:interfaces/interface";
const XPATH_INTERFACE_IPV4: &str = "ietf-ip:ipv4";
const PROTOCOL_VRRP: &str = "ietf-vrrp:vrrp";

pub(crate) fn cmd_show_vrrp_details(
_commands: &Commands,
session: &mut Session,
mut args: ParsedArgs,
) -> Result<bool, String> {
YangTableBuilder::new(session, DataType::All)
.xpath(XPATH_INTERFACE)
.filter_list_key("name", get_opt_arg(&mut args, "name")) // filter by interface name
.xpath(XPATH_INTERFACE_IPV4)
.xpath(PROTOCOL_VRRP)
.xpath("vrrp-instance")
.filter_list_key("vrid", get_opt_arg(&mut args, "vrid")) // filter by vrid
.column_leaf("VRID", "vrid")
.xpath("statistics")
.column_leaf("Master Transitions", "master-transitions")
.column_leaf("Adverts received", "advertisement-rcvd")
.column_leaf("Adverts sent", "advertisement-sent")
.column_leaf("Interval Errors", "interval-errors")
.column_leaf("Priority Zero Pkts Received", "priority-zero-pkts-rcvd")
.column_leaf("Priority Zero Pkts Sent", "priority-zero-pkts-sent")
.column_leaf("Packet Length Errors", "packet-length-errors")
.show(Some(String::from("/ietf-interfaces:interfaces")))?;
Ok(false)
}

// ===== IS-IS "show" commands =====

const PROTOCOL_ISIS: &str = "ietf-isis:isis";
Expand All @@ -747,7 +783,7 @@ pub(crate) fn cmd_show_isis_interface(
.column_leaf("Type", "interface-type")
.column_leaf("Circuit ID", "circuit-id")
.column_leaf("State", "state")
.show()?;
.show(None)?;

Ok(false)
}
Expand All @@ -770,7 +806,7 @@ pub(crate) fn cmd_show_isis_adjacency(
.column_leaf("Level", "usage")
.column_leaf("State", "state")
.column_leaf("Holdtime", "hold-timer")
.show()?;
.show(None)?;

Ok(false)
}
Expand All @@ -791,7 +827,7 @@ pub(crate) fn cmd_show_isis_database(
.column_leaf_hex32("Sequence", "sequence")
.column_leaf_hex16("Checksum", "checksum")
.column_leaf("Lifetime", "remaining-lifetime")
.show()?;
.show(None)?;

Ok(false)
}
Expand Down Expand Up @@ -840,7 +876,7 @@ pub(crate) fn cmd_show_ospf_interface(
format!("{} ({})", interval, remaining)
}),
)
.show()?;
.show(None)?;

Ok(false)
}
Expand Down Expand Up @@ -951,7 +987,7 @@ pub(crate) fn cmd_show_ospf_neighbor(
format!("{} ({})", interval, remaining)
}),
)
.show()?;
.show(None)?;

Ok(false)
}
Expand Down Expand Up @@ -1071,7 +1107,7 @@ pub(crate) fn cmd_show_ospf_route(
.xpath(XPATH_OSPF_NEXTHOP)
.column_leaf("Nexthop Interface", "outgoing-interface")
.column_leaf("Nexthop Address", "next-hop")
.show()?;
.show(None)?;

Ok(false)
}
Expand Down Expand Up @@ -1103,7 +1139,7 @@ pub(crate) fn cmd_show_rip_interface(
.filter_list_key("interface", get_opt_arg(&mut args, "name"))
.column_leaf("Name", "interface")
.column_leaf("State", "oper-status")
.show()?;
.show(None)?;

Ok(false)
}
Expand Down Expand Up @@ -1202,7 +1238,7 @@ pub(crate) fn cmd_show_rip_neighbor(
.filter_list_key(address, get_opt_arg(&mut args, "address"))
.column_leaf("Address", address)
.column_leaf("Last update", "last-update")
.show()?;
.show(None)?;

Ok(false)
}
Expand Down Expand Up @@ -1296,7 +1332,7 @@ pub(crate) fn cmd_show_rip_route(
.column_leaf("Tag", "route-tag")
.column_leaf("Nexthop Interface", "interface")
.column_leaf("Nexthop Address", "next-hop")
.show()?;
.show(None)?;

Ok(false)
}
Expand Down Expand Up @@ -1338,7 +1374,7 @@ pub(crate) fn cmd_show_mpls_ldp_interface(
.column_leaf("Adjacent address", "adjacent-address")
.xpath(XPATH_MPLS_LDP_ADJACENCY_PEER)
.column_leaf("Neighbor lsr-id", "lsr-id")
.show()?;
.show(None)?;

Ok(false)
}
Expand Down Expand Up @@ -1462,7 +1498,7 @@ pub(crate) fn cmd_show_mpls_ldp_peer(
.xpath(XPATH_MPLS_LDP_ADJACENCY)
.column_leaf("Local address", "local-address")
.column_leaf("Adjacent address", "adjacent-address")
.show()?;
.show(None)?;

Ok(false)
}
Expand Down Expand Up @@ -1659,11 +1695,10 @@ pub(crate) fn cmd_show_mpls_ldp_binding_address(
output
}),
)
.show()?;
.show(None)?;

Ok(false)
}

pub(crate) fn cmd_show_mpls_ldp_binding_fec(
_commands: &Commands,
session: &mut Session,
Expand Down Expand Up @@ -1708,7 +1743,7 @@ pub(crate) fn cmd_show_mpls_ldp_binding_fec(
}),
)
.column_leaf("In use", "used-in-forwarding")
.show()?;
.show(None)?;

Ok(false)
}
19 changes: 15 additions & 4 deletions src/internal_commands.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@
</token>
<token name="state" help="Show operational state." cmd="cmd_show_state">
<token name="xpath" help="XPath expression.">
<token name="xpath" argument="xpath" kind="string" help="XPath expression." cmd="cmd_show_state">
<token name="xpath" argument="xpath" kind="string" help="XPath expression." cmd="cmd_show_state">
<token name="format" help="Configuration format.">
<token name="json" argument="format" help="JSON output format." cmd="cmd_show_state"/>
<token name="xml" argument="format" help="XML output format." cmd="cmd_show_state"/>
<token name="xml" argument="format" help="XML output format." cmd="cmd_show_state"/>
</token>
</token>
</token>
Expand All @@ -34,9 +34,20 @@
<token name="interface" help="Interface information" cmd="cmd_show_isis_interface">
<token name="NAME" help="Interface name" argument="name" kind="string" cmd="cmd_show_isis_interface"/>
</token>
<token name="database" help="Link state database" cmd="cmd_show_isis_database"/>
<token name="adjacency" help="Adjacency information" cmd="cmd_show_isis_adjacency"/>
<token name="database" help="Link state database" cmd="cmd_show_isis_database"/>
<token name="adjacency" help="Adjacency information" cmd="cmd_show_isis_adjacency"/>
</token>

<!-- VRRP show commands -->
<token name="vrrp" argument="protocol" help="VRRP information" cmd="cmd_show_vrrp_details">
<token name="interface" help="Filter By Parent Interface" cmd="cmd_show_vrrp_details">
<token name="NAME" help="Interface Name" argument="name" kind="string" cmd="cmd_show_vrrp_details"/>
</token>
<token name="vrid" help="Filter By VRID" cmd="cmd_show_vrrp_details">
<token name="VRID" help="VRID" argument="vrid" kind="string" cmd="cmd_show_vrrp_details"/>
</token>
</token>

<!-- OSPF show commands -->
<token name="ospfv2" argument="protocol" help="OSPFv2 information">
<token name="interface" help="Interface information" cmd="cmd_show_ospf_interface">
Expand Down
5 changes: 1 addition & 4 deletions src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,7 @@ pub type ParsedArgs = VecDeque<(String, String)>;
pub(crate) fn normalize_input_line(line: &str) -> Option<String> {
// Ignore "!" comments.
// TODO: allow "!" within user input like interface descriptions
let line = match line.split('!').next() {
Some(line) => line,
None => return None,
};
let line = line.split('!').next()?;

// Remove redundant whitespaces.
let line = line.split_whitespace().collect::<Vec<_>>().join(" ");
Expand Down
1 change: 1 addition & 0 deletions src/token_xml.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ fn parse_tag_token(
"cmd_show_mpls_ldp_binding_fec" => {
internal_commands::cmd_show_mpls_ldp_binding_fec
}
"cmd_show_vrrp_details" => internal_commands::cmd_show_vrrp_details,
_ => panic!("unknown command name: {}", name),
});

Expand Down
Loading