-
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
35 changed files
with
8,512 additions
and
2 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,43 @@ | ||
[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 | ||
socket2.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"] } | ||
|
||
[features] | ||
default = [] | ||
testing = [] |
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,85 @@ | ||
// | ||
// Copyright (c) The Holo Core Contributors | ||
// | ||
// SPDX-License-Identifier: MIT | ||
// | ||
|
||
use tracing::debug; | ||
|
||
// BGP debug messages. | ||
#[derive(Debug)] | ||
pub enum Debug<'a> { | ||
InstanceCreate, | ||
InstanceDelete, | ||
InstanceStart, | ||
InstanceStop(InstanceInactiveReason), | ||
InstanceStatusCheck(&'a str), | ||
} | ||
|
||
// 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); | ||
} | ||
} | ||
} | ||
} | ||
|
||
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") | ||
} | ||
} | ||
} | ||
} | ||
|
||
// ===== 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") | ||
} | ||
} | ||
} | ||
} |
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,141 @@ | ||
// | ||
// Copyright (c) The Holo Core Contributors | ||
// | ||
// SPDX-License-Identifier: MIT | ||
// | ||
|
||
use serde::{Deserialize, Serialize}; | ||
use tracing::{error, warn}; | ||
|
||
// BGP errors. | ||
#[derive(Debug, Deserialize, Serialize)] | ||
pub enum Error { | ||
// I/O errors | ||
#[serde(skip)] | ||
IoError(IoError), | ||
InstanceStartError(Box<Error>), | ||
} | ||
|
||
// BGP I/O errors. | ||
#[derive(Debug)] | ||
pub enum IoError { | ||
TcpSocketError(std::io::Error), | ||
TcpAcceptError(std::io::Error), | ||
TcpConnectError(std::io::Error), | ||
TcpInfoError(std::io::Error), | ||
TcpAuthError(std::io::Error), | ||
TcpRecvError(std::io::Error), | ||
TcpSendError(std::io::Error), | ||
} | ||
|
||
// ===== impl Error ===== | ||
|
||
impl Error { | ||
pub(crate) fn log(&self) { | ||
match self { | ||
Error::IoError(error) => { | ||
error.log(); | ||
} | ||
Error::InstanceStartError(error) => { | ||
error!(error = %with_source(error), "{}", self); | ||
} | ||
} | ||
} | ||
} | ||
|
||
impl std::fmt::Display for Error { | ||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { | ||
match self { | ||
Error::IoError(error) => error.fmt(f), | ||
Error::InstanceStartError(..) => { | ||
write!(f, "failed to start instance") | ||
} | ||
} | ||
} | ||
} | ||
|
||
impl std::error::Error for Error { | ||
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { | ||
match self { | ||
Error::IoError(error) => Some(error), | ||
Error::InstanceStartError(error) => Some(error), | ||
//_ => None, | ||
} | ||
} | ||
} | ||
|
||
impl From<IoError> for Error { | ||
fn from(error: IoError) -> Error { | ||
Error::IoError(error) | ||
} | ||
} | ||
|
||
// ===== impl IoError ===== | ||
|
||
impl IoError { | ||
pub(crate) fn log(&self) { | ||
match self { | ||
IoError::TcpSocketError(error) | ||
| IoError::TcpAcceptError(error) | ||
| IoError::TcpConnectError(error) | ||
| IoError::TcpAuthError(error) | ||
| IoError::TcpInfoError(error) | ||
| IoError::TcpRecvError(error) | ||
| IoError::TcpSendError(error) => { | ||
warn!(error = %with_source(error), "{}", self); | ||
} | ||
} | ||
} | ||
} | ||
|
||
impl std::fmt::Display for IoError { | ||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { | ||
match self { | ||
IoError::TcpSocketError(..) => { | ||
write!(f, "failed to create TCP socket") | ||
} | ||
IoError::TcpAcceptError(..) => { | ||
write!(f, "failed to accept connection request") | ||
} | ||
IoError::TcpConnectError(..) => { | ||
write!(f, "failed to establish TCP connection") | ||
} | ||
IoError::TcpAuthError(..) => { | ||
write!(f, "failed to set TCP authentication option") | ||
} | ||
IoError::TcpInfoError(..) => { | ||
write!(f, "failed to fetch address and port information from the socket") | ||
} | ||
IoError::TcpRecvError(..) => { | ||
write!(f, "failed to read TCP data") | ||
} | ||
IoError::TcpSendError(..) => { | ||
write!(f, "failed to send TCP data") | ||
} | ||
} | ||
} | ||
} | ||
|
||
impl std::error::Error for IoError { | ||
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { | ||
match self { | ||
IoError::TcpSocketError(error) | ||
| IoError::TcpAcceptError(error) | ||
| IoError::TcpConnectError(error) | ||
| IoError::TcpAuthError(error) | ||
| IoError::TcpInfoError(error) | ||
| IoError::TcpRecvError(error) | ||
| IoError::TcpSendError(error) => Some(error), | ||
} | ||
} | ||
} | ||
|
||
// ===== global functions ===== | ||
|
||
fn with_source<E: std::error::Error>(error: E) -> String { | ||
if let Some(source) = error.source() { | ||
format!("{} ({})", error, with_source(source)) | ||
} else { | ||
error.to_string() | ||
} | ||
} |
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,18 @@ | ||
// | ||
// Copyright (c) The Holo Core Contributors | ||
// | ||
// SPDX-License-Identifier: MIT | ||
// | ||
|
||
use holo_utils::socket::TcpStream; | ||
|
||
use crate::instance::InstanceUp; | ||
|
||
// ===== TCP connection request ===== | ||
|
||
pub(crate) fn process_tcp_accept( | ||
_instance: &mut InstanceUp, | ||
_stream: TcpStream, | ||
) { | ||
// TODO | ||
} |
Oops, something went wrong.