Skip to content

Commit

Permalink
test cloud multi-AZ peering + various improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
rcgoodfellow committed Apr 26, 2024
1 parent e911b1c commit 294af01
Show file tree
Hide file tree
Showing 21 changed files with 494 additions and 189 deletions.
38 changes: 17 additions & 21 deletions bgp/src/messages.rs
Original file line number Diff line number Diff line change
Expand Up @@ -493,57 +493,53 @@ impl UpdateMessage {

pub fn nexthop4(&self) -> Option<Ipv4Addr> {
for a in &self.path_attributes {
match a.value {
PathAttributeValue::NextHop(IpAddr::V4(addr)) => {
return Some(addr);
}
_ => continue,
if let PathAttributeValue::NextHop(IpAddr::V4(addr)) = a.value {
return Some(addr);
}
}
None
}

pub fn graceful_shutdown(&self) -> bool {
for a in &self.path_attributes {
match &a.value {
PathAttributeValue::Communities(communities) => {
for c in communities {
if *c == Community::GracefulShutdown {
return true;
}
if let PathAttributeValue::Communities(communities) = &a.value {
for c in communities {
if *c == Community::GracefulShutdown {
return true;
}
}
_ => continue,
}
}
false
}

pub fn multi_exit_discriminator(&self) -> Option<u32> {
for a in &self.path_attributes {
match &a.value {
PathAttributeValue::MultiExitDisc(med) => return Some(*med),
_ => continue,
if let PathAttributeValue::MultiExitDisc(med) = &a.value {
return Some(*med);
}
}
None
}

pub fn local_pref(&self) -> Option<u32> {
for a in &self.path_attributes {
match &a.value {
PathAttributeValue::LocalPref(value) => return Some(*value),
_ => continue,
if let PathAttributeValue::LocalPref(value) = &a.value {
return Some(*value);
}
}
None
}

pub fn clear_local_perf(&mut self) {
self.path_attributes
.retain(|a| a.typ.type_code != PathAttributeTypeCode::LocalPref);
}

pub fn as_path(&self) -> Option<Vec<As4PathSegment>> {
for a in &self.path_attributes {
match &a.value {
PathAttributeValue::AsPath(path) => return Some(path.clone()),
_ => continue,
if let PathAttributeValue::AsPath(path) = &a.value {
return Some(path.clone());
}
}
None
Expand Down
27 changes: 19 additions & 8 deletions bgp/src/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use crate::router::Router;
use crate::{dbg, err, inf, to_canonical, trc, wrn};
use mg_common::{lock, read_lock, write_lock};
pub use rdb::DEFAULT_ROUTE_PRIORITY;
use rdb::{Asn, Db, Md5Key};
use rdb::{Asn, BgpPathProperties, Db, Md5Key};
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};
use slog::Logger;
Expand Down Expand Up @@ -1205,7 +1205,8 @@ impl<Cnx: BgpConnection + 'static> SessionRunner<Cnx> {
FsmEvent::Message(Message::Update(m)) => {
self.clock.timers.hold_timer.lock().unwrap().reset();
inf!(self; "update received: {m:#?}");
self.apply_update(m.clone(), pc.id);
let peer_as = lock!(self.session).remote_asn.unwrap_or(0);
self.apply_update(m.clone(), pc.id, peer_as);
self.message_history.lock().unwrap().receive(m.into());
self.counters
.updates_received
Expand Down Expand Up @@ -1535,7 +1536,7 @@ impl<Cnx: BgpConnection + 'static> SessionRunner<Cnx> {
}

/// Apply an update by adding it to our RIB.
fn apply_update(&self, update: UpdateMessage, id: u32) {
fn apply_update(&self, mut update: UpdateMessage, id: u32, peer_as: u32) {
if let Err(e) = self.check_update(&update) {
wrn!(
self;
Expand All @@ -1544,7 +1545,8 @@ impl<Cnx: BgpConnection + 'static> SessionRunner<Cnx> {
);
return;
}
self.update_rib(&update, id);
self.apply_update_policy(&mut update);
self.update_rib(&update, id, peer_as);

// NOTE: for now we are only acting as an edge router. This means we
// do not redistribute announcements. If this changes, uncomment
Expand All @@ -1554,7 +1556,7 @@ impl<Cnx: BgpConnection + 'static> SessionRunner<Cnx> {
}

/// Update this router's RIB based on an update message from a peer.
fn update_rib(&self, update: &UpdateMessage, id: u32) {
fn update_rib(&self, update: &UpdateMessage, id: u32, peer_as: u32) {
for w in &update.withdrawn {
self.db.remove_peer_prefix(id, w.as_prefix4().into());
}
Expand Down Expand Up @@ -1598,11 +1600,14 @@ impl<Cnx: BgpConnection + 'static> SessionRunner<Cnx> {

let path = rdb::Path {
nexthop: nexthop.into(),
bgp_id: id,
shutdown: update.graceful_shutdown(),
med: update.multi_exit_discriminator(),
local_pref: update.local_pref(),
as_path,
bgp: Some(BgpPathProperties {
origin_as: peer_as,
bgp_id: id,
med: update.multi_exit_discriminator(),
as_path,
}),
};

if let Err(e) =
Expand All @@ -1621,6 +1626,12 @@ impl<Cnx: BgpConnection + 'static> SessionRunner<Cnx> {
self.check_for_self_in_path(update)
}

fn apply_update_policy(&self, update: &mut UpdateMessage) {
if self.is_ebgp() {
update.clear_local_perf()
}
}

/// Do not accept routes that have our ASN in the AS_PATH e.g., do
/// path-vector routing not distance-vector routing.
fn check_for_self_in_path(
Expand Down
1 change: 1 addition & 0 deletions clab/.gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
clab-pop
*.bak
3 changes: 3 additions & 0 deletions clab/diagram.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 2 additions & 1 deletion clab/lab-init.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@

./transit-set-config.sh
./cdn-set-config.sh
./pcloud-set-config.sh
./pcwest-set-config.sh
./pceast-set-config.sh
./mgd-setup.sh
15 changes: 13 additions & 2 deletions clab/mgd-setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,20 @@ addr=`host -t A -4 clab-pop-oxpop | awk '{print $4}'`
--communities 3081893 \
--med 99

# public cloud
# public cloud west
~/src/maghemite/target/debug/mgadm -a $addr \
bgp add-neighbor 65547 pcloud 169.254.30.1 qsfp2 \
bgp add-neighbor 65547 pcwest 169.254.30.1 qsfp2 \
--remote-asn 64502 \
--min-ttl 255 \
--md5-auth-key hypermuffin \
--hold-time 900 \
--keepalive-time 300 \
--communities 8675309 \
--med 99

# public cloud east
~/src/maghemite/target/debug/mgadm -a $addr \
bgp add-neighbor 65547 pceast 169.254.40.1 qsfp3 \
--remote-asn 64502 \
--min-ttl 255 \
--md5-auth-key hypermuffin \
Expand Down
12 changes: 9 additions & 3 deletions clab/oxpop.clab.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@ topology:
cdn:
kind: nokia_srlinux
image: ghcr.io/nokia/srlinux
pcloud:
pcwest:
kind: nokia_srlinux
image: ghcr.io/nokia/srlinux
pceast:
kind: nokia_srlinux
image: ghcr.io/nokia/srlinux
oxpop:
Expand All @@ -26,5 +29,8 @@ topology:
- endpoints: ["cdn:e1-1", "oxpop:eth2"]
- endpoints: ["cdn:e1-2", "host:cdn_e1-2"]

- endpoints: ["pcloud:e1-1", "oxpop:eth3"]
- endpoints: ["pcloud:e1-2", "host:pcloud_e1-2"]
- endpoints: ["pcwest:e1-1", "oxpop:eth3"]
- endpoints: ["pcwest:e1-2", "host:pcwest_e1-2"]

- endpoints: ["pceast:e1-1", "oxpop:eth4"]
- endpoints: ["pceast:e1-2", "host:pceast_e1-2"]
4 changes: 4 additions & 0 deletions clab/pceast-set-config.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/bash

curl -s 'http://admin:NokiaSrl1!@clab-pop-pceast/jsonrpc' -d @pceast.json
echo;
128 changes: 128 additions & 0 deletions clab/pceast.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
{
"jsonrpc": "2.0",
"id": 0,
"method": "set",
"params": {
"commands": [
{
"action": "update",
"path": "/",
"value":
{
"interface": [
{
"name": "ethernet-1/1",
"subinterface": [
{
"index": 0,
"admin-state": "enable",
"ipv4": {
"admin-state": "enable",
"address": [
{
"ip-prefix": "169.254.40.1/30",
"primary": [null]
}
]
}
}
]
},
{
"name": "ethernet-1/2",
"subinterface": [
{
"index": 0,
"type": "routed",
"admin-state": "enable",
"ipv4": {
"admin-state": "enable",
"address": [
{
"ip-prefix": "10.10.0.2/16"
}
]
}
}
]
}
],
"network-instance": [
{
"name": "default",
"interface": [
{
"name": "ethernet-1/1.0"
},
{
"name": "ethernet-1/2.0"
}
],
"protocols": {
"bgp": {
"admin-state": "enable",
"autonomous-system": 64502,
"export-policy": "all",
"router-id": "10.10.0.2",
"afi-safi": [
{
"afi-safi-name": "ipv4-unicast",
"admin-state": "enable"
}
],
"group": [
{
"group-name": "oxpop",
"admin-state": "enable",
"afi-safi": [
{
"afi-safi-name": "ipv4-unicast",
"admin-state": "enable"
}
],
"trace-options": {
"flag": [
{
"name": "events"
}
]
}
}
],
"neighbor": [
{
"peer-address": "169.254.40.2",
"description": "oxide point of presence",
"peer-as": 65547,
"peer-group": "oxpop",
"authentication": {
"password": "$aes1$ATTuNB0NU2L7AW8=$HpBACI63gldrmF9SBkiuPQ=="
},
"multihop": {
"admin-state": "enable",
"maximum-hops": 255
},
"local-as": {
"as-number": 64502
}
}
]
}
}
}
],
"routing-policy": {
"policy": [
{
"name": "all",
"default-action": {
"policy-result": "accept"
}
}
]
}
}
}
]
}
}
4 changes: 0 additions & 4 deletions clab/pcloud-set-config.sh

This file was deleted.

4 changes: 4 additions & 0 deletions clab/pcwest-set-config.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/bash

curl -s 'http://admin:NokiaSrl1!@clab-pop-pcwest/jsonrpc' -d @pcwest.json
echo;
File renamed without changes.
1 change: 1 addition & 0 deletions clab/run-mgd.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@ apt install -y iproute2
ip addr add 169.254.10.2/30 dev eth1
ip addr add 169.254.20.2/30 dev eth2
ip addr add 169.254.30.2/30 dev eth3
ip addr add 169.254.40.2/30 dev eth4

/opt/oxide/mgd run
Loading

0 comments on commit 294af01

Please sign in to comment.