Skip to content

Commit

Permalink
replace hardcoded port/bgp-peer values with API params
Browse files Browse the repository at this point in the history
  • Loading branch information
rcgoodfellow committed Oct 14, 2023
1 parent 324c2db commit c703722
Show file tree
Hide file tree
Showing 10 changed files with 457 additions and 46 deletions.
7 changes: 7 additions & 0 deletions nexus/db-model/src/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,8 @@ table! {
lldp_service_config_id -> Uuid,
link_name -> Text,
mtu -> Int4,
fec -> crate::SwitchLinkFecEnum,
speed -> crate::SwitchLinkSpeedEnum,
}
}

Expand Down Expand Up @@ -203,6 +205,11 @@ table! {
bgp_config_id -> Uuid,
interface_name -> Text,
addr -> Inet,
hold_time -> Int8,
idle_hold_time -> Int8,
delay_open -> Int8,
connect_retry -> Int8,
keepalive -> Int8,
}
}

Expand Down
136 changes: 134 additions & 2 deletions nexus/db-model/src/switch_port.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
// 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/.

use crate::impl_enum_type;
use crate::schema::{
lldp_config, lldp_service_config, switch_port, switch_port_settings,
switch_port_settings_address_config, switch_port_settings_bgp_peer_config,
Expand All @@ -11,12 +10,14 @@ use crate::schema::{
switch_port_settings_port_config, switch_port_settings_route_config,
};
use crate::SqlU16;
use crate::{impl_enum_type, SqlU32};
use db_macros::Resource;
use diesel::AsChangeset;
use ipnetwork::IpNetwork;
use nexus_types::external_api::params;
use nexus_types::identity::Resource;
use omicron_common::api::external;
use omicron_common::api::internal::shared::{PortFec, PortSpeed};
use serde::{Deserialize, Serialize};
use uuid::Uuid;

Expand All @@ -43,6 +44,110 @@ impl_enum_type!(
Sfp28x4 => b"Sfp28x4"
);

impl_enum_type!(
#[derive(SqlType, Debug, Clone, Copy)]
#[diesel(postgres_type(name = "switch_link_fec"))]
pub struct SwitchLinkFecEnum;

#[derive(
Clone,
Copy,
Debug,
AsExpression,
FromSqlRow,
PartialEq,
Serialize,
Deserialize
)]
#[diesel(sql_type = SwitchLinkFecEnum)]
pub enum SwitchLinkFec;

Firecode => b"Firecode"
None => b"None"
Rs => b"Rs"
);

impl_enum_type!(
#[derive(SqlType, Debug, Clone, Copy)]
#[diesel(postgres_type(name = "switch_link_speed"))]
pub struct SwitchLinkSpeedEnum;

#[derive(
Clone,
Copy,
Debug,
AsExpression,
FromSqlRow,
PartialEq,
Serialize,
Deserialize
)]
#[diesel(sql_type = SwitchLinkSpeedEnum)]
pub enum SwitchLinkSpeed;

Speed0G => b"0G"
Speed1G => b"1G"
Speed10G => b"10G"
Speed25G => b"25G"
Speed40G => b"40G"
Speed50G => b"50G"
Speed100G => b"100G"
Speed200G => b"200G"
Speed400G => b"400G"
);

impl From<SwitchLinkFec> for PortFec {
fn from(value: SwitchLinkFec) -> Self {
match value {
SwitchLinkFec::Firecode => PortFec::Firecode,
SwitchLinkFec::None => PortFec::None,
SwitchLinkFec::Rs => PortFec::Rs,
}
}
}

impl From<params::LinkFec> for SwitchLinkFec {
fn from(value: params::LinkFec) -> Self {
match value {
params::LinkFec::Firecode => SwitchLinkFec::Firecode,
params::LinkFec::None => SwitchLinkFec::None,
params::LinkFec::Rs => SwitchLinkFec::Rs,
}
}
}

impl From<SwitchLinkSpeed> for PortSpeed {
fn from(value: SwitchLinkSpeed) -> Self {
match value {
SwitchLinkSpeed::Speed0G => PortSpeed::Speed0G,
SwitchLinkSpeed::Speed1G => PortSpeed::Speed1G,
SwitchLinkSpeed::Speed10G => PortSpeed::Speed10G,
SwitchLinkSpeed::Speed25G => PortSpeed::Speed25G,
SwitchLinkSpeed::Speed40G => PortSpeed::Speed40G,
SwitchLinkSpeed::Speed50G => PortSpeed::Speed50G,
SwitchLinkSpeed::Speed100G => PortSpeed::Speed100G,
SwitchLinkSpeed::Speed200G => PortSpeed::Speed200G,
SwitchLinkSpeed::Speed400G => PortSpeed::Speed400G,
}
}
}

impl From<params::LinkSpeed> for SwitchLinkSpeed {
fn from(value: params::LinkSpeed) -> Self {
match value {
params::LinkSpeed::Speed0G => SwitchLinkSpeed::Speed0G,
params::LinkSpeed::Speed1G => SwitchLinkSpeed::Speed1G,
params::LinkSpeed::Speed10G => SwitchLinkSpeed::Speed10G,
params::LinkSpeed::Speed25G => SwitchLinkSpeed::Speed25G,
params::LinkSpeed::Speed40G => SwitchLinkSpeed::Speed40G,
params::LinkSpeed::Speed50G => SwitchLinkSpeed::Speed50G,
params::LinkSpeed::Speed100G => SwitchLinkSpeed::Speed100G,
params::LinkSpeed::Speed200G => SwitchLinkSpeed::Speed200G,
params::LinkSpeed::Speed400G => SwitchLinkSpeed::Speed400G,
}
}
}

impl From<params::SwitchPortGeometry> for SwitchPortGeometry {
fn from(g: params::SwitchPortGeometry) -> Self {
match g {
Expand Down Expand Up @@ -241,6 +346,8 @@ pub struct SwitchPortLinkConfig {
pub lldp_service_config_id: Uuid,
pub link_name: String,
pub mtu: SqlU16,
pub fec: SwitchLinkFec,
pub speed: SwitchLinkSpeed,
}

impl SwitchPortLinkConfig {
Expand All @@ -249,11 +356,15 @@ impl SwitchPortLinkConfig {
lldp_service_config_id: Uuid,
link_name: String,
mtu: u16,
fec: SwitchLinkFec,
speed: SwitchLinkSpeed,
) -> Self {
Self {
port_settings_id,
lldp_service_config_id,
link_name,
fec,
speed,
mtu: mtu.into(),
}
}
Expand Down Expand Up @@ -442,16 +553,37 @@ pub struct SwitchPortBgpPeerConfig {
pub bgp_config_id: Uuid,
pub interface_name: String,
pub addr: IpNetwork,
pub hold_time: SqlU32,
pub idle_hold_time: SqlU32,
pub delay_open: SqlU32,
pub connect_retry: SqlU32,
pub keepalive: SqlU32,
}

impl SwitchPortBgpPeerConfig {
#[allow(clippy::too_many_arguments)]
pub fn new(
port_settings_id: Uuid,
bgp_config_id: Uuid,
interface_name: String,
addr: IpNetwork,
hold_time: SqlU32,
idle_hold_time: SqlU32,
delay_open: SqlU32,
connect_retry: SqlU32,
keepalive: SqlU32,
) -> Self {
Self { port_settings_id, bgp_config_id, interface_name, addr }
Self {
port_settings_id,
bgp_config_id,
interface_name,
addr,
hold_time,
idle_hold_time,
delay_open,
connect_retry,
keepalive,
}
}
}

Expand Down
29 changes: 7 additions & 22 deletions nexus/db-queries/src/db/datastore/switch_port.rs
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,8 @@ impl DataStore {
lldp_svc_config.id,
link_name.clone(),
c.mtu,
c.fec.into(),
c.speed.into(),
));
}
result.link_lldp =
Expand Down Expand Up @@ -298,28 +300,6 @@ impl DataStore {

let mut bgp_peer_config = Vec::new();
for (interface_name, p) in &params.bgp_peers {
/* XXX ANNOUNCE
use db::schema::bgp_announce_set;
let announce_set_id = match &p.bgp_announce_set {
NameOrId::Id(id) => *id,
NameOrId::Name(name) => {
let name = name.to_string();
bgp_announce_set_dsl::bgp_announce_set
.filter(bgp_announce_set::time_deleted.is_null())
.filter(bgp_announce_set::name.eq(name))
.select(bgp_announce_set::id)
.limit(1)
.first_async::<Uuid>(&conn)
.await
.map_err(|_| {
TxnError::CustomError(
SwitchPortSettingsCreateError::BgpAnnounceSetNotFound,
)
})?
}
};
*/

use db::schema::bgp_config;
let bgp_config_id = match &p.bgp_config {
NameOrId::Id(id) => *id,
Expand All @@ -345,6 +325,11 @@ impl DataStore {
bgp_config_id,
interface_name.clone(),
p.addr.into(),
p.hold_time.into(),
p.idle_hold_time.into(),
p.delay_open.into(),
p.connect_retry.into(),
p.keepalive.into(),
));

}
Expand Down
37 changes: 26 additions & 11 deletions nexus/src/app/sagas/switch_port_settings_apply.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@ use internal_dns::ServiceName;
use ipnetwork::IpNetwork;
use mg_admin_client::types::Prefix4;
use mg_admin_client::types::{ApplyRequest, BgpPeerConfig, BgpRoute};
use nexus_db_model::{SwitchLinkFec, SwitchLinkSpeed};
use nexus_db_queries::context::OpContext;
use nexus_db_queries::db::datastore::UpdatePrecondition;
use nexus_db_queries::{authn, db};
use nexus_types::external_api::params;
use omicron_common::api::external::{self, NameOrId};
use omicron_common::api::internal::shared::{
ParseSwitchLocationError, PortFec as OmicronPortFec,
PortSpeed as OmicronPortSpeed, SwitchLocation,
ParseSwitchLocationError, SwitchLocation,
};
use serde::{Deserialize, Serialize};
use sled_agent_client::types::PortConfigV1;
Expand All @@ -43,6 +43,11 @@ use std::sync::Arc;
use steno::ActionError;
use uuid::Uuid;

// This is more of an implementation detail of the BGP implementation. It
// defines the maximum time the peering engine will wait for external messages
// before breaking to check for shutdown conditions.
const BGP_SESSION_RESOLUTION: u64 = 100;

// switch port settings apply saga: input parameters

#[derive(Debug, Deserialize, Serialize)]
Expand Down Expand Up @@ -418,14 +423,14 @@ pub(crate) async fn ensure_switch_port_bgp_settings(

let bpc = BgpPeerConfig {
asn: *config.asn,
name: format!("{}", peer.addr.ip()), //TODO(ry)(user defined name)
name: format!("{}", peer.addr.ip()), //TODO user defined name?
host: format!("{}:179", peer.addr.ip()),
hold_time: 6, //TODO(ry)(hardocde)
idle_hold_time: 6, //TODO(ry)(hardocde)
delay_open: 0, //TODO(ry)(hardocde)
connect_retry: 0, //TODO(ry)(hardcode)
keepalive: 3, //TODO(ry)(hardcode)
resolution: 100, //TODO(ry)(hardcode)
hold_time: peer.hold_time.0.into(),
idle_hold_time: peer.idle_hold_time.0.into(),
delay_open: peer.delay_open.0.into(),
connect_retry: peer.connect_retry.0.into(),
keepalive: peer.keepalive.0.into(),
resolution: BGP_SESSION_RESOLUTION,
routes: vec![BgpRoute { nexthop, prefixes }],
};

Expand Down Expand Up @@ -888,8 +893,18 @@ pub(crate) async fn bootstore_update(
addresses: settings.addresses.iter().map(|a| a.address).collect(),
switch: switch_location,
port: switch_port_name.into(),
uplink_port_fec: OmicronPortFec::None, //TODO hardcode
uplink_port_speed: OmicronPortSpeed::Speed100G, //TODO hardcode
uplink_port_fec: settings
.links
.get(0)
.map(|l| l.fec)
.unwrap_or(SwitchLinkFec::None)
.into(),
uplink_port_speed: settings
.links
.get(0)
.map(|l| l.speed)
.unwrap_or(SwitchLinkSpeed::Speed100G)
.into(),
bgp_peers: peer_info
.iter()
.filter_map(|(p, asn)| {
Expand Down
19 changes: 13 additions & 6 deletions nexus/src/app/switch_port.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use crate::app::sagas;
use crate::external_api::params;
use db::datastore::SwitchPortSettingsCombinedResult;
use ipnetwork::IpNetwork;
use nexus_db_model::{SwitchLinkFec, SwitchLinkSpeed};
use nexus_db_queries::authn;
use nexus_db_queries::authz;
use nexus_db_queries::context::OpContext;
Expand Down Expand Up @@ -394,12 +395,18 @@ impl super::Nexus {
.collect(),
switch: port.switch_location.parse().unwrap(),
port: port.port_name.clone(),
//TODO hardcode
uplink_port_fec:
omicron_common::api::internal::shared::PortFec::None,
//TODO hardcode
uplink_port_speed:
omicron_common::api::internal::shared::PortSpeed::Speed100G,
uplink_port_fec: info
.links
.get(0) //TODO breakout support
.map(|l| l.fec)
.unwrap_or(SwitchLinkFec::None)
.into(),
uplink_port_speed: info
.links
.get(0) //TODO breakout support
.map(|l| l.speed)
.unwrap_or(SwitchLinkSpeed::Speed100G)
.into(),
};

rack_net_config.ports.push(p);
Expand Down
Loading

0 comments on commit c703722

Please sign in to comment.