Skip to content

Commit

Permalink
VRRP WIP
Browse files Browse the repository at this point in the history
Signed-off-by: Renato Westphal <[email protected]>
  • Loading branch information
rwestphal committed Jun 18, 2024
1 parent bd6a145 commit 2f0b189
Show file tree
Hide file tree
Showing 30 changed files with 2,960 additions and 1 deletion.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ members = [
"holo-routing",
"holo-tools",
"holo-utils",
"holo-vrrp",
"holo-yang",
]
default-members = ["holo-daemon"]
Expand Down
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,10 @@ Holo supports the following IETF RFCs and Internet drafts:
* RFC 2453 - RIP Version 2
* RFC 4822 - RIPv2 Cryptographic Authentication

##### VRRP

* RFC 3768 - Virtual Router Redundancy Protocol (VRRP)

##### IETF YANG implementation coverage

| Module | Configuration | State | RPCs | Notifications | Total |
Expand All @@ -234,6 +238,7 @@ Holo supports the following IETF RFCs and Internet drafts:
| ietf-routing@2018-03-13 | 100.00% | 85.71% | - | - | [92.31%](http://westphal.com.br/holo/ietf-routing.html) |
| ietf-segment-routing-mpls@2021-05-26 | 62.50% | 0.00% | - | 23.53% | [32.76%](http://westphal.com.br/holo/ietf-segment-routing-mpls.html) |
| ietf-segment-routing@2021-05-26 | 100.00% | - | - | - | [100.00%](http://westphal.com.br/holo/ietf-segment-routing.html) |
| ietf-vrrp@2018-03-13 | 51.06% | 60.47% | - | 41.67% | [53.92%](http://westphal.com.br/holo/[email protected]) |

## Funding

Expand Down
3 changes: 3 additions & 0 deletions holo-daemon/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ holo-protocol = { path = "../holo-protocol" }
holo-rip = { path = "../holo-rip", optional = true }
holo-routing = { path = "../holo-routing", optional = true }
holo-utils = { path = "../holo-utils" }
holo-vrrp = { path = "../holo-vrrp", optional = true }
holo-yang = { path = "../holo-yang" }

[build-dependencies]
Expand All @@ -67,6 +68,7 @@ default = [
"ldp",
"ospf",
"rip",
"vrrp",
]

# Base components
Expand All @@ -81,6 +83,7 @@ bgp = ["holo-bgp", "holo-routing/bgp"]
ldp = ["holo-ldp", "holo-routing/ldp"]
ospf = ["holo-ospf", "holo-routing/ospf"]
rip = ["holo-rip", "holo-routing/rip"]
vrrp = ["holo-vrrp", "holo-routing/vrrp"]

# Other features
io_uring = ["tokio-uring"]
5 changes: 5 additions & 0 deletions holo-daemon/src/northbound/yang.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,11 @@ pub(crate) fn create_context() {
modules_add::<Instance<Ripv2>>(&mut modules);
modules_add::<Instance<Ripng>>(&mut modules);
}
#[cfg(feature = "vrrp")]
{
use holo_vrrp::instance::Instance;
modules_add::<Instance>(&mut modules);
}

// Create YANG context and load all required modules and their deviations.
let mut yang_ctx = yang::new_context();
Expand Down
2 changes: 2 additions & 0 deletions holo-routing/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ holo-bgp = { path = "../holo-bgp", optional = true }
holo-ldp = { path = "../holo-ldp", optional = true }
holo-ospf = { path = "../holo-ospf", optional = true }
holo-rip = { path = "../holo-rip", optional = true }
holo-vrrp = { path = "../holo-vrrp", optional = true }

[lints]
workspace = true
Expand All @@ -41,3 +42,4 @@ bgp = ["holo-bgp"]
ldp = ["holo-ldp"]
ospf = ["holo-ospf"]
rip = ["holo-rip"]
vrrp = ["holo-vrrp"]
3 changes: 2 additions & 1 deletion holo-tools/yang-coverage.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,5 @@ cargo run --bin yang_coverage --\
-m ietf-ospf\
-m ietf-ospf-sr-mpls\
-m ietf-ospfv3-extended-lsa\
-m ietf-rip
-m ietf-rip\
-m ietf-vrrp
5 changes: 5 additions & 0 deletions holo-utils/src/protocol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ pub enum Protocol {
RIPV2,
RIPNG,
STATIC,
VRRP,
}

// ===== impl Protocol =====
Expand All @@ -41,6 +42,7 @@ impl std::fmt::Display for Protocol {
Protocol::RIPV2 => write!(f, "ripv2"),
Protocol::RIPNG => write!(f, "ripng"),
Protocol::STATIC => write!(f, "static"),
Protocol::VRRP => write!(f, "vrrp"),
}
}
}
Expand All @@ -59,6 +61,7 @@ impl FromStr for Protocol {
"ripv2" => Ok(Protocol::RIPV2),
"ripng" => Ok(Protocol::RIPNG),
"static" => Ok(Protocol::STATIC),
"vrrp" => Ok(Protocol::VRRP),
_ => Err(()),
}
}
Expand All @@ -76,6 +79,7 @@ impl ToYang for Protocol {
Protocol::RIPV2 => "ietf-rip:ripv2".into(),
Protocol::RIPNG => "ietf-rip:ripng".into(),
Protocol::STATIC => "ietf-routing:static".into(),
Protocol::VRRP => "holo-vrrp:vrrp".into(),
}
}
}
Expand All @@ -92,6 +96,7 @@ impl TryFromYang for Protocol {
"ietf-rip:ripv2" => Some(Protocol::RIPV2),
"ietf-rip:ripng" => Some(Protocol::RIPNG),
"ietf-routing:static" => Some(Protocol::STATIC),
"holo-vrrp:vrrp" => Some(Protocol::VRRP),
_ => None,
}
}
Expand Down
43 changes: 43 additions & 0 deletions holo-vrrp/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
[package]
name = "holo-vrrp"
version.workspace = true
authors.workspace = true # TODO
license.workspace = true
edition.workspace = true

[dependencies]
async-trait.workspace = true
bitflags.workspace = true
bytes.workspace = true
chrono.workspace = true
derive-new.workspace = true
enum-as-inner.workspace = true
ipnetwork.workspace = true
itertools.workspace = true
libc.workspace = true
num-derive.workspace = true
num-traits.workspace = true
rand.workspace = true
serde.workspace = true
serde_json.workspace = true
serde_with.workspace = true
tokio.workspace = true
tracing.workspace = true
yang2.workspace = true

holo-northbound = { path = "../holo-northbound" }
holo-protocol = { path = "../holo-protocol" }
holo-utils = { path = "../holo-utils" }
holo-yang = { path = "../holo-yang" }

[dev-dependencies]
holo-vrrp = { path = ".", features = ["testing"] }
holo-protocol = { path = "../holo-protocol", features = ["testing"] }
holo-utils = { path = "../holo-utils", features = ["testing"] }

[lints]
workspace = true

[features]
default = []
testing = []
19 changes: 19 additions & 0 deletions holo-vrrp/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
Copyright (c) 2023 The Holo Core Contributors

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
101 changes: 101 additions & 0 deletions holo-vrrp/src/debug.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
//
// Copyright (c) The Holo Core Contributors
//
// SPDX-License-Identifier: MIT
//

use std::net::IpAddr;

use tracing::{debug, debug_span};

use crate::packet::Packet;

// VRRP debug messages.
#[derive(Debug)]
pub enum Debug<'a> {
InstanceCreate,
InstanceDelete,
InstanceStart,
InstanceStop(InstanceInactiveReason),
// Network
PacketRx(&'a IpAddr, &'a Packet),
PacketTx(&'a IpAddr, &'a Packet),
}

// Reason why an VRRP instance is inactive.
#[derive(Debug)]
pub enum InstanceInactiveReason {
AdminDown,
MissingRouterId,
}

// ===== impl Debug =====

impl<'a> Debug<'a> {
// Log debug message using the tracing API.
pub(crate) fn log(&self) {
match self {
Debug::InstanceCreate
| Debug::InstanceDelete
| Debug::InstanceStart => {
// Parent span(s): vrrp-instance
debug!("{}", self);
}
Debug::InstanceStop(reason) => {
// Parent span(s): vrrp-instance
debug!(%reason, "{}", self);
}
Debug::PacketRx(src, packet) => {
// Parent span(s): vrrp-instance
debug_span!("network").in_scope(|| {
debug_span!("input").in_scope(|| {
let data = serde_json::to_string(&packet).unwrap();
debug!(%src, %data, "{}", self);
})
})
}
Debug::PacketTx(addr, packet) => {
// Parent span(s): vrrp-instance:network:output
let data = serde_json::to_string(&packet).unwrap();
debug!(%addr, %data, "{}", self);
}
}
}
}

impl<'a> std::fmt::Display for Debug<'a> {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Debug::InstanceCreate => {
write!(f, "instance created")
}
Debug::InstanceDelete => {
write!(f, "instance deleted")
}
Debug::InstanceStart => {
write!(f, "starting instance")
}
Debug::InstanceStop(..) => {
write!(f, "stopping instance")
}
Debug::PacketRx(..) | Debug::PacketTx(..) => {
write!(f, "packet")
}
}
}
}

// ===== impl InstanceInactiveReason =====

impl std::fmt::Display for InstanceInactiveReason {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
InstanceInactiveReason::AdminDown => {
write!(f, "administrative status down")
}
InstanceInactiveReason::MissingRouterId => {
write!(f, "missing router-id")
}
}
}
}
Loading

0 comments on commit 2f0b189

Please sign in to comment.