mirror of
https://github.com/mii443/miibgpd.git
synced 2025-08-22 15:55:26 +00:00
add bgp type
This commit is contained in:
1
Cargo.lock
generated
1
Cargo.lock
generated
@ -107,6 +107,7 @@ name = "miibgpd"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"bytes",
|
||||
"thiserror",
|
||||
"tokio",
|
||||
"tracing",
|
||||
|
@ -9,3 +9,4 @@ thiserror = "1.0"
|
||||
anyhow = "1.0"
|
||||
tracing = "0.1"
|
||||
tracing-subscriber = "0.3"
|
||||
bytes = "1.10.0"
|
||||
|
@ -1,3 +1,5 @@
|
||||
use crate::error::ConvertBytesToBgpMessageError;
|
||||
|
||||
#[derive(PartialEq, Eq, Debug, Clone, Copy, Hash, PartialOrd, Ord)]
|
||||
pub struct AutonomousSystemNumber(u16);
|
||||
|
||||
@ -12,3 +14,65 @@ impl From<u16> for AutonomousSystemNumber {
|
||||
Self(as_number)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(PartialEq, Eq, Debug, Clone, Copy, Hash, PartialOrd, Ord)]
|
||||
pub struct HoldTime(u16);
|
||||
|
||||
impl From<HoldTime> for u16 {
|
||||
fn from(value: HoldTime) -> Self {
|
||||
value.0
|
||||
}
|
||||
}
|
||||
|
||||
impl From<u16> for HoldTime {
|
||||
fn from(value: u16) -> Self {
|
||||
Self(value)
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for HoldTime {
|
||||
fn default() -> Self {
|
||||
Self(0)
|
||||
}
|
||||
}
|
||||
|
||||
impl HoldTime {
|
||||
pub fn new() -> Self {
|
||||
Self::default()
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(PartialEq, Eq, Debug, Clone, Copy, Hash, PartialOrd, Ord)]
|
||||
pub struct Version(u8);
|
||||
|
||||
impl From<Version> for u8 {
|
||||
fn from(value: Version) -> Self {
|
||||
value.0
|
||||
}
|
||||
}
|
||||
|
||||
impl TryFrom<u8> for Version {
|
||||
type Error = ConvertBytesToBgpMessageError;
|
||||
|
||||
fn try_from(value: u8) -> Result<Self, Self::Error> {
|
||||
if value <= 4 {
|
||||
Ok(Self(value))
|
||||
} else {
|
||||
Err(Self::Error::from(anyhow::anyhow!(
|
||||
"excepted version is 1~4, but got {value}",
|
||||
)))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for Version {
|
||||
fn default() -> Self {
|
||||
Self(4)
|
||||
}
|
||||
}
|
||||
|
||||
impl Version {
|
||||
pub fn new() -> Self {
|
||||
Self::default()
|
||||
}
|
||||
}
|
||||
|
14
src/error.rs
14
src/error.rs
@ -13,3 +13,17 @@ pub struct CreateConnectionError {
|
||||
#[from]
|
||||
source: anyhow::Error,
|
||||
}
|
||||
|
||||
#[derive(Error, Debug)]
|
||||
#[error(transparent)]
|
||||
pub struct ConvertBytesToBgpMessageError {
|
||||
#[from]
|
||||
source: anyhow::Error,
|
||||
}
|
||||
|
||||
#[derive(Error, Debug)]
|
||||
#[error(transparent)]
|
||||
pub struct ConvertbgpMessageToBytesError {
|
||||
#[from]
|
||||
source: anyhow::Error,
|
||||
}
|
||||
|
@ -6,5 +6,6 @@ mod connection;
|
||||
mod error;
|
||||
mod event;
|
||||
mod event_queue;
|
||||
mod packets;
|
||||
pub mod peer;
|
||||
mod state;
|
||||
|
2
src/packets/header.rs
Normal file
2
src/packets/header.rs
Normal file
@ -0,0 +1,2 @@
|
||||
#[derive(PartialEq, Eq, Debug, Clone, Hash)]
|
||||
pub struct Header;
|
23
src/packets/message.rs
Normal file
23
src/packets/message.rs
Normal file
@ -0,0 +1,23 @@
|
||||
use bytes::BytesMut;
|
||||
|
||||
use crate::error::ConvertBytesToBgpMessageError;
|
||||
|
||||
use super::open::OpenMessage;
|
||||
|
||||
pub enum Message {
|
||||
Open(OpenMessage),
|
||||
}
|
||||
|
||||
impl TryFrom<BytesMut> for Message {
|
||||
type Error = ConvertBytesToBgpMessageError;
|
||||
|
||||
fn try_from(value: BytesMut) -> Result<Self, Self::Error> {
|
||||
todo!();
|
||||
}
|
||||
}
|
||||
|
||||
impl From<Message> for BytesMut {
|
||||
fn from(value: Message) -> Self {
|
||||
todo!();
|
||||
}
|
||||
}
|
3
src/packets/mod.rs
Normal file
3
src/packets/mod.rs
Normal file
@ -0,0 +1,3 @@
|
||||
pub mod header;
|
||||
pub mod message;
|
||||
pub mod open;
|
2
src/packets/open.rs
Normal file
2
src/packets/open.rs
Normal file
@ -0,0 +1,2 @@
|
||||
#[derive(PartialEq, Eq, Debug, Clone, Hash)]
|
||||
pub struct OpenMessage;
|
Reference in New Issue
Block a user