Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 32 additions & 11 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -538,8 +538,8 @@ newtype_derive = "0.1.6"
ntp-admin-api = { path = "ntp-admin/api" }
ntp-admin-client = { path = "clients/ntp-admin-client" }
ntp-admin-types = { path = "ntp-admin/types" }
mg-admin-client = { git = "https://github.com/oxidecomputer/maghemite", rev = "08f2a34d487658e87545ffbba3add632a82baf0d" }
ddm-admin-client = { git = "https://github.com/oxidecomputer/maghemite", rev = "08f2a34d487658e87545ffbba3add632a82baf0d" }
mg-admin-client = { git = "https://github.com/oxidecomputer/maghemite", rev = "835553064c9702789fc09af7fa1eb3f12caa91c5" }
ddm-admin-client = { git = "https://github.com/oxidecomputer/maghemite", rev = "835553064c9702789fc09af7fa1eb3f12caa91c5" }
multimap = "0.10.1"
nexus-auth = { path = "nexus/auth" }
nexus-background-task-interface = { path = "nexus/background-task-interface" }
Expand Down Expand Up @@ -667,6 +667,7 @@ ratatui = "0.29.0"
raw-cpuid = { git = "https://github.com/oxidecomputer/rust-cpuid.git", rev = "a4cf01df76f35430ff5d39dc2fe470bcb953503b" }
rayon = "1.10"
rcgen = "0.12.1"
rdb-types = { git = "https://github.com/oxidecomputer/maghemite", rev = "835553064c9702789fc09af7fa1eb3f12caa91c5" }
reconfigurator-cli = { path = "dev-tools/reconfigurator-cli" }
reedline = "0.40.0"
ref-cast = "1.0"
Expand Down
8 changes: 8 additions & 0 deletions common/src/api/external/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3291,6 +3291,11 @@ pub enum BgpPeerState {
/// Waiting for keepaliave or notification from peer.
OpenConfirm,

/// There is an ongoing Connection Collision that hasn't yet been resolved.
/// Two connections are maintained until one connection receives an Open or
/// is able to progress into Established.
ConnectionCollision,

/// Synchronizing with peer.
SessionSetup,

Expand All @@ -3308,6 +3313,9 @@ impl From<mg_admin_client::types::FsmStateKind> for BgpPeerState {
FsmStateKind::Active => BgpPeerState::Active,
FsmStateKind::OpenSent => BgpPeerState::OpenSent,
FsmStateKind::OpenConfirm => BgpPeerState::OpenConfirm,
FsmStateKind::ConnectionCollision => {
BgpPeerState::ConnectionCollision
}
FsmStateKind::SessionSetup => BgpPeerState::SessionSetup,
FsmStateKind::Established => BgpPeerState::Established,
}
Expand Down
1 change: 1 addition & 0 deletions nexus/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ qorb.workspace = true
rand.workspace = true
range-requests.workspace = true
ref-cast.workspace = true
rdb-types.workspace = true
regex.workspace = true
reqwest = { workspace = true, features = ["json"] }
ring.workspace = true
Expand Down
8 changes: 4 additions & 4 deletions nexus/db-queries/src/db/datastore/vpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3907,21 +3907,21 @@ mod tests {
assert!(resolved.iter().any(|x| {
let k = &x.dest;
let v = &x.target;
*k == subnet.ipv4_block.0.into()
*k == IpNet::from(subnet.ipv4_block.0)
&& match v {
RouterTarget::VpcSubnet(ip) => {
*ip == subnet.ipv4_block.0.into()
*ip == IpNet::from(subnet.ipv4_block.0)
}
_ => false,
}
}));
assert!(resolved.iter().any(|x| {
let k = &x.dest;
let v = &x.target;
*k == subnet.ipv6_block.0.into()
*k == IpNet::from(subnet.ipv6_block.0)
&& match v {
RouterTarget::VpcSubnet(ip) => {
*ip == subnet.ipv6_block.0.into()
*ip == IpNet::from(subnet.ipv6_block.0)
}
_ => false,
}
Expand Down
50 changes: 50 additions & 0 deletions nexus/external-api/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ use openapiv3::OpenAPI;

/// Copies of data types that changed between versions
mod v2025112000;
mod v2025120300;

api_versions!([
// API versions are in the format YYYYMMDDNN.0.0, defined below as
Expand Down Expand Up @@ -64,6 +65,7 @@ api_versions!([
// | date-based version should be at the top of the list.
// v
// (next_yyyymmddnn, IDENT),
(2025121200, BGP_PEER_COLLISION_STATE),
(2025120300, LOCAL_STORAGE),
(2025112000, INITIAL),
]);
Expand Down Expand Up @@ -2433,12 +2435,60 @@ pub trait NexusExternalApi {
query_params: Query<PaginatedByNameOrId>,
) -> Result<HttpResponseOk<ResultsPage<BgpConfig>>, HttpError>;

#[endpoint {
method = GET,
path = "/v1/system/networking/bgp-status",
tags = ["system/networking"],
versions = ..VERSION_BGP_PEER_COLLISION_STATE,
}]
async fn v2025120300_networking_bgp_status(
rqctx: RequestContext<Self::Context>,
) -> Result<HttpResponseOk<Vec<v2025120300::BgpPeerStatus>>, HttpError>
{
let result = Self::networking_bgp_status(rqctx).await?.0;
Ok(HttpResponseOk(
result
.into_iter()
.map(|x| v2025120300::BgpPeerStatus {
addr: x.addr,
local_asn: x.local_asn,
remote_asn: x.remote_asn,
state: match x.state {
BgpPeerState::Idle => v2025120300::BgpPeerState::Idle,
BgpPeerState::Connect => {
v2025120300::BgpPeerState::Connect
}
BgpPeerState::Active => {
v2025120300::BgpPeerState::Active
}
BgpPeerState::OpenSent => {
v2025120300::BgpPeerState::OpenSent
}
BgpPeerState::OpenConfirm => {
v2025120300::BgpPeerState::OpenConfirm
}
BgpPeerState::ConnectionCollision
| BgpPeerState::SessionSetup => {
v2025120300::BgpPeerState::SessionSetup
}
BgpPeerState::Established => {
v2025120300::BgpPeerState::Established
}
},
state_duration_millis: x.state_duration_millis,
switch: x.switch,
})
.collect(),
))
}

//TODO pagination? the normal by-name/by-id stuff does not work here
/// Get BGP peer status
#[endpoint {
method = GET,
path = "/v1/system/networking/bgp-status",
tags = ["system/networking"],
versions = VERSION_BGP_PEER_COLLISION_STATE..,
}]
async fn networking_bgp_status(
rqctx: RequestContext<Self::Context>,
Expand Down
61 changes: 61 additions & 0 deletions nexus/external-api/src/v2025120300.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at https://mozilla.org/MPL/2.0/.

//! Nexus external types that changed from 2025120300 to 2025121200

use std::net::IpAddr;

use omicron_common::api::external::SwitchLocation;
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};

/// The current status of a BGP peer.
#[derive(Clone, Debug, Deserialize, JsonSchema, Serialize, PartialEq)]
pub struct BgpPeerStatus {
/// IP address of the peer.
pub addr: IpAddr,

/// Local autonomous system number.
pub local_asn: u32,

/// Remote autonomous system number.
pub remote_asn: u32,

/// State of the peer.
pub state: BgpPeerState,

/// Time of last state change.
pub state_duration_millis: u64,

/// Switch with the peer session.
pub switch: SwitchLocation,
}

/// The current state of a BGP peer.
#[derive(Clone, Debug, Deserialize, JsonSchema, Serialize, PartialEq)]
#[serde(rename_all = "snake_case")]
pub enum BgpPeerState {
/// Initial state. Refuse all incoming BGP connections. No resources
/// allocated to peer.
Idle,

/// Waiting for the TCP connection to be completed.
Connect,

/// Trying to acquire peer by listening for and accepting a TCP connection.
Active,

/// Waiting for open message from peer.
OpenSent,

/// Waiting for keepaliave or notification from peer.
OpenConfirm,

/// Synchronizing with peer.
SessionSetup,

/// Session established. Able to exchange update, notification and keepalive
/// messages with peers.
Established,
}
2 changes: 1 addition & 1 deletion nexus/src/app/background/tasks/bfd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ impl BackgroundTask for BfdManager {
},
};

let mgd_clients = build_mgd_clients(mappings, log);
let mgd_clients = build_mgd_clients(mappings, log, &self.resolver).await;

for (location, c) in &mgd_clients {
let client_current = match c.get_bfd_peers().await {
Expand Down
25 changes: 22 additions & 3 deletions nexus/src/app/background/tasks/networking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,37 @@ use db::datastore::SwitchPortSettingsCombinedResult;
use dpd_client::types::{
LinkCreate, LinkId, LinkSettings, PortFec, PortSettings, PortSpeed, TxEq,
};
use internal_dns_types::names::ServiceName;
use nexus_db_model::{SwitchLinkFec, SwitchLinkSpeed};
use nexus_db_queries::db;
use omicron_common::{address::MGD_PORT, api::external::SwitchLocation};
use std::{collections::HashMap, net::SocketAddrV6};
use std::{
collections::HashMap,
net::{Ipv6Addr, SocketAddrV6},
};

pub(crate) fn build_mgd_clients(
pub(crate) async fn build_mgd_clients(
mappings: HashMap<SwitchLocation, std::net::Ipv6Addr>,
log: &slog::Logger,
resolver: &internal_dns_resolver::Resolver,
) -> HashMap<SwitchLocation, mg_admin_client::Client> {
let mut clients: Vec<(SwitchLocation, mg_admin_client::Client)> = vec![];
for (location, addr) in &mappings {
let port = MGD_PORT;
let port = match resolver.lookup_all_socket_v6(ServiceName::Mgd).await {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Special scrutiny is warranted here. I think this should be ok as we fallback to the previous constant port when DNS does not work out.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as noted above

Ok(addrs) => {
let port_map: HashMap<Ipv6Addr, u16> = addrs
.into_iter()
.map(|sockaddr| (*sockaddr.ip(), sockaddr.port()))
.collect();

*port_map.get(&addr).unwrap_or(&MGD_PORT)
}
Err(e) => {
error!(log, "failed to addresses"; "error" => %e);
MGD_PORT
}
};

let socketaddr =
std::net::SocketAddr::V6(SocketAddrV6::new(*addr, port, 0, 0));
let client = mg_admin_client::Client::new(
Expand Down
Loading
Loading