Skip to content

Commit

Permalink
vrrp: introduce vrrp commands
Browse files Browse the repository at this point in the history
introduce the following commands:
   show vrrp
   show vrrp vrid VRID
   show vrrp interface NAME

These commands help you get either
general information on VRRP
or filtered.

Todo: Add virtual IP details (
currently an issue from the
holod end)

Signed-off-by: Paul Wekesa <paul1tw1@gmail.com>
  • Loading branch information
Paul-weqe committed Nov 11, 2024
1 parent 19da113 commit 62b4565
Show file tree
Hide file tree
Showing 5 changed files with 91 additions and 20 deletions.
1 change: 1 addition & 0 deletions cmd
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
show state xpath /ietf-interfaces:interfaces/interface[name='wlo1']
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
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
23 changes: 23 additions & 0 deletions vrrp.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
!
interfaces interface wlo1
type iana-if-type:ethernetCsmacd
ipv4
!
ipv4 vrrp vrrp-instance 30
!
virtual-ipv4-addresses virtual-ipv4-address 10.0.30.1
!
virtual-ipv4-addresses virtual-ipv4-address 10.0.30.2
!
ipv4 vrrp vrrp-instance 50
!
virtual-ipv4-addresses virtual-ipv4-address 10.0.50.1
!
virtual-ipv4-addresses virtual-ipv4-address 10.0.50.2
!
ipv4 vrrp vrrp-instance 70
!
virtual-ipv4-addresses virtual-ipv4-address 10.0.70.1
!
virtual-ipv4-addresses virtual-ipv4-address 10.0.70.2
!

0 comments on commit 62b4565

Please sign in to comment.