Skip to content
Merged
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
148 changes: 147 additions & 1 deletion common/src/api/external/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2497,7 +2497,7 @@ pub struct SwitchPortSettingsView {
pub routes: Vec<SwitchPortRouteConfig>,

/// BGP peer settings.
pub bgp_peers: Vec<SwitchPortBgpPeerConfig>,
pub bgp_peers: Vec<BgpPeer>,

/// Layer 3 IP address settings.
pub addresses: Vec<SwitchPortAddressConfig>,
Expand Down Expand Up @@ -2551,6 +2551,74 @@ pub struct SwitchPortConfig {
pub geometry: SwitchPortGeometry,
}

/// The speed of a link.
#[derive(Copy, Clone, Debug, Deserialize, Serialize, JsonSchema, PartialEq)]
#[serde(rename_all = "snake_case")]
pub enum LinkSpeed {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is not net-new, it's moved from nexus/external_api/params.rs to be used as a common data structure for PUT/POST and GET requests.

/// Zero gigabits per second.
Speed0G,
/// 1 gigabit per second.
Speed1G,
/// 10 gigabits per second.
Speed10G,
/// 25 gigabits per second.
Speed25G,
/// 40 gigabits per second.
Speed40G,
/// 50 gigabits per second.
Speed50G,
/// 100 gigabits per second.
Speed100G,
/// 200 gigabits per second.
Speed200G,
/// 400 gigabits per second.
Speed400G,
}

/// The forward error correction mode of a link.
#[derive(Copy, Clone, Debug, Deserialize, Serialize, JsonSchema, PartialEq)]
#[serde(rename_all = "snake_case")]
pub enum LinkFec {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is not net-new, it's moved from nexus/external_api/params.rs to be used as a common data structure for PUT/POST and GET requests.

/// Firecode foward error correction.
Firecode,
/// No forward error correction.
None,
/// Reed-Solomon forward error correction.
Rs,
}

impl From<crate::api::internal::shared::PortFec> for LinkFec {
fn from(x: crate::api::internal::shared::PortFec) -> LinkFec {
match x {
crate::api::internal::shared::PortFec::Firecode => Self::Firecode,
crate::api::internal::shared::PortFec::None => Self::None,
crate::api::internal::shared::PortFec::Rs => Self::Rs,
}
}
}

impl From<crate::api::internal::shared::PortSpeed> for LinkSpeed {
fn from(x: crate::api::internal::shared::PortSpeed) -> Self {
match x {
crate::api::internal::shared::PortSpeed::Speed0G => Self::Speed0G,
crate::api::internal::shared::PortSpeed::Speed1G => Self::Speed1G,
crate::api::internal::shared::PortSpeed::Speed10G => Self::Speed10G,
crate::api::internal::shared::PortSpeed::Speed25G => Self::Speed25G,
crate::api::internal::shared::PortSpeed::Speed40G => Self::Speed40G,
crate::api::internal::shared::PortSpeed::Speed50G => Self::Speed50G,
crate::api::internal::shared::PortSpeed::Speed100G => {
Self::Speed100G
}
crate::api::internal::shared::PortSpeed::Speed200G => {
Self::Speed200G
}
crate::api::internal::shared::PortSpeed::Speed400G => {
Self::Speed400G
}
}
}
}

/// A link configuration for a port settings object.
#[derive(Clone, Debug, Deserialize, JsonSchema, Serialize, PartialEq)]
pub struct SwitchPortLinkConfig {
Expand All @@ -2566,6 +2634,15 @@ pub struct SwitchPortLinkConfig {

/// The maximum transmission unit for this link.
pub mtu: u16,

/// The forward error correction mode of the link.
pub fec: LinkFec,

/// The configured speed of the link.
pub speed: LinkSpeed,

/// Whether or not the link has autonegotiation enabled.
pub autoneg: bool,
}

/// A link layer discovery protocol (LLDP) service configuration.
Expand Down Expand Up @@ -2674,6 +2751,7 @@ pub struct SwitchPortRouteConfig {
pub vlan_id: Option<u16>,
}

/*
/// A BGP peer configuration for a port settings object.
#[derive(Clone, Debug, Deserialize, JsonSchema, Serialize, PartialEq)]
pub struct SwitchPortBgpPeerConfig {
Expand All @@ -2692,6 +2770,74 @@ pub struct SwitchPortBgpPeerConfig {
/// The address of the peer.
pub addr: IpAddr,
}
*/

/// A BGP peer configuration for an interface. Includes the set of announcements
/// that will be advertised to the peer identified by `addr`. The `bgp_config`
/// parameter is a reference to global BGP parameters. The `interface_name`
/// indicates what interface the peer should be contacted on.
#[derive(Clone, Debug, Deserialize, Serialize, JsonSchema, PartialEq)]
pub struct BgpPeer {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is not net-new, it's moved from nexus/external_api/params.rs to be used as a common data structure for PUT/POST and GET requests.

/// The global BGP configuration used for establishing a session with this
/// peer.
pub bgp_config: NameOrId,

/// The name of interface to peer on. This is relative to the port
/// configuration this BGP peer configuration is a part of. For example this
/// value could be phy0 to refer to a primary physical interface. Or it
/// could be vlan47 to refer to a VLAN interface.
pub interface_name: String,

/// The address of the host to peer with.
pub addr: IpAddr,

/// How long to hold peer connections between keepalives (seconds).
pub hold_time: u32,

/// How long to hold a peer in idle before attempting a new session
/// (seconds).
pub idle_hold_time: u32,

/// How long to delay sending an open request after establishing a TCP
/// session (seconds).
pub delay_open: u32,

/// How long to to wait between TCP connection retries (seconds).
pub connect_retry: u32,

/// How often to send keepalive requests (seconds).
pub keepalive: u32,

/// Require that a peer has a specified ASN.
pub remote_asn: Option<u32>,

/// Require messages from a peer have a minimum IP time to live field.
pub min_ttl: Option<u8>,

/// Use the given key for TCP-MD5 authentication with the peer.
pub md5_auth_key: Option<String>,

/// Apply the provided multi-exit discriminator (MED) updates sent to the peer.
pub multi_exit_discriminator: Option<u32>,

/// Include the provided communities in updates sent to the peer.
pub communities: Vec<u32>,

/// Apply a local preference to routes received from this peer.
pub local_pref: Option<u32>,

/// Enforce that the first AS in paths received from this peer is the peer's AS.
pub enforce_first_as: bool,

/// Define import policy for a peer.
pub allowed_import: ImportExportPolicy,

/// Define export policy for a peer.
pub allowed_export: ImportExportPolicy,

/// Associate a VLAN ID with a peer.
pub vlan_id: Option<u16>,
}

/// A base BGP configuration.
#[derive(
Expand Down
76 changes: 47 additions & 29 deletions nexus/db-model/src/switch_port.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ use crate::{SqlU16, SqlU8};
use db_macros::Resource;
use diesel::AsChangeset;
use ipnetwork::IpNetwork;
use nexus_types::external_api::params::{self, BgpPeer};
use nexus_types::external_api::params;
use nexus_types::identity::Resource;
use omicron_common::api::external;
use omicron_common::api::external::ImportExportPolicy;
use omicron_common::api::external::{BgpPeer, ImportExportPolicy};
use omicron_common::api::internal::shared::{PortFec, PortSpeed};
use serde::{Deserialize, Serialize};
use uuid::Uuid;
Expand Down Expand Up @@ -110,12 +110,22 @@ impl From<SwitchLinkFec> for PortFec {
}
}

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

impl From<SwitchLinkFec> for external::LinkFec {
fn from(value: SwitchLinkFec) -> Self {
match value {
SwitchLinkFec::Firecode => external::LinkFec::Firecode,
SwitchLinkFec::None => external::LinkFec::None,
SwitchLinkFec::Rs => external::LinkFec::Rs,
}
}
}
Expand All @@ -136,18 +146,34 @@ impl From<SwitchLinkSpeed> for PortSpeed {
}
}

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

impl From<SwitchLinkSpeed> for external::LinkSpeed {
fn from(value: SwitchLinkSpeed) -> 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,
SwitchLinkSpeed::Speed0G => external::LinkSpeed::Speed0G,
SwitchLinkSpeed::Speed1G => external::LinkSpeed::Speed1G,
SwitchLinkSpeed::Speed10G => external::LinkSpeed::Speed10G,
SwitchLinkSpeed::Speed25G => external::LinkSpeed::Speed25G,
SwitchLinkSpeed::Speed40G => external::LinkSpeed::Speed40G,
SwitchLinkSpeed::Speed50G => external::LinkSpeed::Speed50G,
SwitchLinkSpeed::Speed100G => external::LinkSpeed::Speed100G,
SwitchLinkSpeed::Speed200G => external::LinkSpeed::Speed200G,
SwitchLinkSpeed::Speed400G => external::LinkSpeed::Speed400G,
}
}
}
Expand Down Expand Up @@ -391,6 +417,9 @@ impl Into<external::SwitchPortLinkConfig> for SwitchPortLinkConfig {
lldp_service_config_id: self.lldp_service_config_id,
link_name: self.link_name.clone(),
mtu: self.mtu.into(),
fec: self.fec.into(),
speed: self.speed.into(),
autoneg: self.autoneg,
}
}
}
Expand Down Expand Up @@ -676,17 +705,6 @@ impl SwitchPortBgpPeerConfig {
}
}

impl Into<external::SwitchPortBgpPeerConfig> for SwitchPortBgpPeerConfig {
fn into(self) -> external::SwitchPortBgpPeerConfig {
external::SwitchPortBgpPeerConfig {
port_settings_id: self.port_settings_id,
bgp_config_id: self.bgp_config_id,
interface_name: self.interface_name.clone(),
addr: self.addr.ip(),
}
}
}

#[derive(
Queryable,
Insertable,
Expand Down
Loading