Skip to content

Commit

Permalink
bgp: import initial BGP implementation
Browse files Browse the repository at this point in the history
This is an work-in-progress implementation and *NOT* suitable for
production use at this stage.

Documentation detailing the implementation architecture will be added
as development progresses.

Signed-off-by: Renato Westphal <[email protected]>
  • Loading branch information
rwestphal committed Feb 17, 2024
1 parent 59ead7c commit 22f215b
Show file tree
Hide file tree
Showing 56 changed files with 18,397 additions and 59 deletions.
2 changes: 2 additions & 0 deletions Cargo.toml
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",
Expand Down Expand Up @@ -35,6 +36,7 @@ check_keyword = "0.2"
clap = "2.33"
chrono = { version = "0.4", features = ["serde"] }
criterion = "0.4"
crossbeam-channel = "0.5"
derive-new = "0.5"
enum-as-inner = "0.6"
futures = "0.3"
Expand Down
25 changes: 25 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,29 @@ Holo supports the following IETF RFCs and Internet drafts:
* RFC 5882 - Generic Application of Bidirectional Forwarding Detection (BFD)
* RFC 5883 - Bidirectional Forwarding Detection (BFD) for Multihop Paths

##### BGP

* RFC 1997 - BGP Communities Attribute
* RFC 2385 - Protection of BGP Sessions via the TCP MD5 Signature Option
* RFC 2545 - Use of BGP-4 Multiprotocol Extensions for IPv6 Inter-Domain Routing
* RFC 2918 - Route Refresh Capability for BGP-4
* RFC 4271 - A Border Gateway Protocol 4 (BGP-4)
* RFC 4360 - BGP Extended Communities Attribute
* RFC 4486 - Subcodes for BGP Cease Notification Message
* RFC 4760 - Multiprotocol Extensions for BGP-4
* RFC 5082 - The Generalized TTL Security Mechanism (GTSM)
* RFC 5492 - Capabilities Advertisement with BGP-4
* RFC 5668 - 4-Octet AS Specific BGP Extended Community
* RFC 5701 - IPv6 Address Specific BGP Extended Community Attribute
* RFC 6286 - Autonomous-System-Wide Unique BGP Identifier for BGP-4
* RFC 6608 - Subcodes for BGP Finite State Machine Error
* RFC 6793 - BGP Support for Four-Octet Autonomous System (AS) Number Space
* RFC 7606 - Revised Error Handling for BGP UPDATE Messages
* RFC 7607 - Codification of AS 0 Processing
* RFC 8092 - BGP Large Communities Attribute
* RFC 8212 - Default External BGP (EBGP) Route Propagation Behavior without Policies
* RFC 8642 - Policy Behavior for Well-Known BGP Communities

##### MPLS LDP

* RFC 5036 - LDP Specification
Expand Down Expand Up @@ -192,6 +215,8 @@ Holo supports the following IETF RFCs and Internet drafts:
| ietf-bfd-ip-mh@2022-09-22 | 100.00% | 100.00% | - | 100.00% | [100.00%](http://westphal.com.br/holo/ietf-bfd-ip-mh.html) |
| ietf-bfd-ip-sh@2022-09-22 | 100.00% | 100.00% | - | 100.00% | [100.00%](http://westphal.com.br/holo/ietf-bfd-ip-sh.html) |
| ietf-bfd@2022-09-22 | 100.00% | 100.00% | - | - | [100.00%](http://westphal.com.br/holo/ietf-bfd.html) |
| ietf-bgp-policy@2023-07-05 | 100.00% | - | - | - | [100.00%](http://westphal.com.br/holo/ietf-bgp-policy.html) |
| ietf-bgp@2023-07-05 | 32.38% | 87.86% | - | - | [61.39%](http://westphal.com.br/holo/ietf-bgp.html) |
| ietf-interfaces@2018-01-09 | 100.00% | 0.00% | - | - | [22.22%](http://westphal.com.br/holo/ietf-interfaces.html) |
| ietf-ip@2018-01-09 | 17.39% | 0.00% | - | - | [13.33%](http://westphal.com.br/holo/ietf-ip.html) |
| ietf-ipv4-unicast-routing@2018-03-13 | 100.00% | 100.00% | - | - | [100.00%](http://westphal.com.br/holo/ietf-ipv4-unicast-routing.html) |
Expand Down
54 changes: 54 additions & 0 deletions holo-bgp/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
[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
crossbeam-channel.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
19 changes: 19 additions & 0 deletions holo-bgp/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.
42 changes: 42 additions & 0 deletions holo-bgp/benches/msg_decoding.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#![feature(lazy_cell)]

use std::hint::black_box;

use criterion::{criterion_group, criterion_main, Criterion};
use holo_bgp::neighbor::PeerType;
use holo_bgp::packet::message::{
Capability, DecodeCxt, FourOctetAsNumber, Message,
};

fn msg_decode(n: u64) {
let cxt = DecodeCxt {
peer_type: PeerType::Internal,
peer_as: n as u32,
capabilities: [Capability::FourOctetAsNumber {
asn: FourOctetAsNumber(n as u32),
}]
.into(),
};

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, &cxt).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);
59 changes: 59 additions & 0 deletions holo-bgp/benches/msg_encoding.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
#![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::consts::{Afi, Safi, BGP_VERSION};
use holo_bgp::packet::message::{
Capability, EncodeCxt, FourOctetAsNumber, Message, OpenMsg,
};

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: FourOctetAsNumber(65550),
},
Capability::RouteRefresh,
Capability::EnhancedRouteRefresh,
]
.into(),
})
});

fn msg_encode(n: u64) {
let cxt = EncodeCxt {
capabilities: [Capability::FourOctetAsNumber {
asn: FourOctetAsNumber(n as u32),
}]
.into(),
};

for _ in 0..n {
MESSAGE.encode(&cxt);
}
}

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);
Loading

0 comments on commit 22f215b

Please sign in to comment.