-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Renato Westphal <[email protected]>
- Loading branch information
Showing
49 changed files
with
12,923 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
[workspace] | ||
members = [ | ||
"holo-bfd", | ||
"holo-bgp", | ||
"holo-cli", | ||
"holo-daemon", | ||
"holo-interface", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
[package] | ||
name = "holo-bgp" | ||
version.workspace = true | ||
authors.workspace = true | ||
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 | ||
generational-arena.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 | ||
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] | ||
criterion.workspace = true | ||
|
||
holo-bgp = { path = ".", features = ["testing"] } | ||
holo-protocol = { path = "../holo-protocol", features = ["testing"] } | ||
holo-utils = { path = "../holo-utils", features = ["testing"] } | ||
|
||
[lints] | ||
workspace = true | ||
|
||
[features] | ||
default = [] | ||
testing = [] | ||
|
||
[[bench]] | ||
name = "msg_encoding" | ||
harness = false | ||
|
||
[[bench]] | ||
name = "msg_decoding" | ||
harness = false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
#![feature(lazy_cell)] | ||
|
||
use std::hint::black_box; | ||
|
||
use criterion::{criterion_group, criterion_main, Criterion}; | ||
use holo_bgp::packet::message::Message; | ||
|
||
fn msg_decode(n: u64) { | ||
let bytes = vec![ | ||
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, | ||
0xff, 0xff, 0xff, 0xff, 0x00, 0x3d, 0x01, 0x04, 0x00, 0x01, 0x00, 0xb4, | ||
0x01, 0x01, 0x01, 0x01, 0x20, 0x02, 0x06, 0x01, 0x04, 0x00, 0x01, 0x00, | ||
0x01, 0x02, 0x06, 0x01, 0x04, 0x00, 0x02, 0x00, 0x01, 0x02, 0x02, 0x02, | ||
0x00, 0x02, 0x06, 0x41, 0x04, 0x00, 0x01, 0x00, 0x0e, 0x02, 0x02, 0x46, | ||
0x00, | ||
]; | ||
|
||
for _ in 0..n { | ||
let _msg = Message::decode(&bytes).unwrap(); | ||
} | ||
} | ||
|
||
fn criterion_benchmark(c: &mut Criterion) { | ||
c.bench_function("Message decode", |b| { | ||
b.iter(|| msg_decode(black_box(10000))) | ||
}); | ||
} | ||
|
||
criterion_group!(benches, criterion_benchmark); | ||
criterion_main!(benches); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
#![feature(lazy_cell)] | ||
|
||
use std::hint::black_box; | ||
use std::net::Ipv4Addr; | ||
use std::str::FromStr; | ||
use std::sync::LazyLock as Lazy; | ||
|
||
use criterion::{criterion_group, criterion_main, Criterion}; | ||
use holo_bgp::packet::message::{Capability, Message, OpenMsg, BGP_VERSION}; | ||
use holo_bgp::packet::{Afi, Safi}; | ||
|
||
static MESSAGE: Lazy<Message> = Lazy::new(|| { | ||
Message::Open(OpenMsg { | ||
version: BGP_VERSION, | ||
my_as: 1, | ||
holdtime: 180, | ||
identifier: Ipv4Addr::from_str("1.1.1.1").unwrap(), | ||
capabilities: [ | ||
Capability::MultiProtocol { | ||
afi: Afi::Ipv4, | ||
safi: Safi::Unicast, | ||
}, | ||
Capability::MultiProtocol { | ||
afi: Afi::Ipv6, | ||
safi: Safi::Unicast, | ||
}, | ||
Capability::FourOctetAsNumber { asn: 65550 }, | ||
Capability::RouteRefresh, | ||
Capability::EnhancedRouteRefresh, | ||
] | ||
.into(), | ||
}) | ||
}); | ||
|
||
fn msg_encode(n: u64) { | ||
for _ in 0..n { | ||
MESSAGE.encode(); | ||
} | ||
} | ||
|
||
fn criterion_benchmark(c: &mut Criterion) { | ||
c.bench_function("Message encode", |b| { | ||
b.iter(|| msg_encode(black_box(10000))) | ||
}); | ||
} | ||
|
||
criterion_group!(benches, criterion_benchmark); | ||
criterion_main!(benches); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,137 @@ | ||
// | ||
// Copyright (c) The Holo Core Contributors | ||
// | ||
// SPDX-License-Identifier: MIT | ||
// | ||
|
||
use std::net::IpAddr; | ||
|
||
use tracing::{debug, debug_span}; | ||
|
||
use crate::neighbor::fsm; | ||
use crate::packet::message::Message; | ||
|
||
// BGP debug messages. | ||
#[derive(Debug)] | ||
pub enum Debug<'a> { | ||
InstanceCreate, | ||
InstanceDelete, | ||
InstanceStart, | ||
InstanceStop(InstanceInactiveReason), | ||
InstanceStatusCheck(&'a str), | ||
NbrFsmEvent(&'a IpAddr, &'a fsm::Event), | ||
NbrFsmTransition(&'a IpAddr, &'a fsm::State, &'a fsm::State), | ||
NbrMsgRx(&'a IpAddr, &'a Message), | ||
NbrMsgTx(&'a IpAddr, &'a Message), | ||
} | ||
|
||
// Reason why an BGP 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): bgp-instance | ||
debug!("{}", self); | ||
} | ||
Debug::InstanceStop(reason) => { | ||
// Parent span(s): bgp-instance | ||
debug!(%reason, "{}", self); | ||
} | ||
Debug::InstanceStatusCheck(status) => { | ||
// Parent span(s): bgp-instance | ||
debug!(%status, "{}", self); | ||
} | ||
Debug::NbrFsmEvent(nbr_addr, event) => { | ||
// Parent span(s): bgp-instance | ||
debug_span!("neighbor", %nbr_addr).in_scope(|| { | ||
debug_span!("fsm").in_scope(|| { | ||
debug!(?event, "{}", self); | ||
}) | ||
}); | ||
} | ||
Debug::NbrFsmTransition(nbr_addr, old_state, new_state) => { | ||
// Parent span(s): bgp-instance | ||
debug_span!("neighbor", %nbr_addr).in_scope(|| { | ||
debug_span!("fsm").in_scope(|| { | ||
debug!(?old_state, ?new_state, "{}", self); | ||
}) | ||
}); | ||
} | ||
Debug::NbrMsgRx(nbr_addr, msg) => { | ||
// Parent span(s): bgp-instance | ||
debug_span!("neighbor", %nbr_addr).in_scope(|| { | ||
debug_span!("input").in_scope(|| { | ||
let data = serde_json::to_string(&msg).unwrap(); | ||
debug!(%data, "{}", self); | ||
}) | ||
}); | ||
} | ||
Debug::NbrMsgTx(nbr_addr, msg) => { | ||
// Parent span(s): bgp-instance | ||
debug_span!("neighbor", %nbr_addr).in_scope(|| { | ||
debug_span!("output").in_scope(|| { | ||
let data = serde_json::to_string(&msg).unwrap(); | ||
debug!(%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::InstanceStatusCheck(..) => { | ||
write!(f, "checking instance status") | ||
} | ||
Debug::NbrFsmEvent(..) => { | ||
write!(f, "event") | ||
} | ||
Debug::NbrFsmTransition(..) => { | ||
write!(f, "state transition") | ||
} | ||
Debug::NbrMsgRx(..) | Debug::NbrMsgTx(..) => { | ||
write!(f, "message") | ||
} | ||
} | ||
} | ||
} | ||
|
||
// ===== 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") | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.