Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor Network Operator APIs #6016

Open
wants to merge 42 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 30 commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
cd6c856
WIP: refactor of operator api networking endpoints
Jun 18, 2024
c5f042b
Merge branch 'main' into refactor-networking-apis
internet-diglett Jul 4, 2024
65b25dc
fix address lot testing
internet-diglett Jul 4, 2024
7bccb1b
refactor address lot APIs to resemble ip pools
internet-diglett Jul 8, 2024
812e991
rename AddressLotBlock params
internet-diglett Jul 17, 2024
85abe0e
Merge branch 'main' into refactor-networking-apis
internet-diglett Jul 17, 2024
047c6fe
WIP: allow partial update of switch port configuration
internet-diglett Jul 23, 2024
8a807d9
fixup! WIP: allow partial update of switch port configuration
internet-diglett Jul 29, 2024
78033b5
plumb through switch port geometry
internet-diglett Jul 31, 2024
d8c2f42
fixup! plumb through switch port geometry
internet-diglett Jul 31, 2024
bca07fe
list links
internet-diglett Aug 1, 2024
30c217c
return structured data for geometry
internet-diglett Aug 1, 2024
7000904
plumb through switch port link configuration
internet-diglett Aug 6, 2024
1c695d0
WIP: plumb switch port link create
internet-diglett Aug 6, 2024
ba50716
create / delete link config
internet-diglett Aug 9, 2024
d5b5553
Merge branch 'main' into refactor-networking-apis-2
internet-diglett Aug 27, 2024
6eb4be4
WIP: interface address management
internet-diglett Aug 27, 2024
69ff1f0
WIP: interface address management
internet-diglett Aug 29, 2024
2e392d2
WIP: more refactor work
internet-diglett Aug 29, 2024
8cad50e
Make addresses list-able without knowing interface name
internet-diglett Aug 29, 2024
7a32cbd
regen openapi
internet-diglett Aug 29, 2024
2377850
fix address remove logic
internet-diglett Aug 30, 2024
8416cac
WIP: route add / remove
internet-diglett Aug 30, 2024
d991823
WIP: route add / remove
internet-diglett Aug 30, 2024
de92b30
WIP: route add / remove / list
internet-diglett Aug 30, 2024
22fe92a
add bgp peer list / add / remove
internet-diglett Aug 30, 2024
193bcaf
don't require entire peer config for peer removal
internet-diglett Aug 30, 2024
1360445
WIP: bgp import/export/community add and list
internet-diglett Aug 30, 2024
a392a80
WIP: finish roughing out bgp import/export/community endpoints
internet-diglett Aug 30, 2024
a1a70fd
WIP: breakout bgp peer import/export/communities
internet-diglett Aug 31, 2024
b1cbebe
WIP unsquash switch port query errors
internet-diglett Sep 10, 2024
822953e
WIP: update tests
internet-diglett Oct 15, 2024
9ef3456
add integration tests for new endpoints
internet-diglett Oct 16, 2024
f65f6f9
change const to static in test fixtures
internet-diglett Oct 16, 2024
2225b77
Round 1 of PR review fixes
internet-diglett Oct 18, 2024
155e5d4
Round 2 of PR review fixes
internet-diglett Oct 19, 2024
36d700a
Endpoints for managing active switch port configs
internet-diglett Oct 22, 2024
4140aad
add tests for new active-configuration endpoints
internet-diglett Oct 24, 2024
4edf90a
Merge branch 'main' into refactor-networking-apis
internet-diglett Oct 25, 2024
7d8e38f
regen authz txt
internet-diglett Oct 25, 2024
d1e4739
Merge branch 'main' into refactor-networking-apis
internet-diglett Oct 27, 2024
4f04635
remove unused params
internet-diglett Oct 31, 2024
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
111 changes: 106 additions & 5 deletions common/src/api/external/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2113,9 +2113,6 @@ impl std::fmt::Display for Digest {
pub struct AddressLotCreateResponse {
/// The address lot that was created.
pub lot: AddressLot,

/// The address lot blocks that were created.
pub blocks: Vec<AddressLotBlock>,
}

/// Represents an address lot object, containing the id of the lot that can be
Expand Down Expand Up @@ -2241,7 +2238,7 @@ pub struct SwitchPortSettingsView {
pub routes: Vec<SwitchPortRouteConfig>,

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

/// Layer 3 IP address settings.
pub addresses: Vec<SwitchPortAddressConfig>,
Expand Down Expand Up @@ -2520,7 +2517,7 @@ pub struct SwitchPortBgpPeerConfig {
/// 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 {
pub struct BgpPeerCombined {
/// The global BGP configuration used for establishing a session with this
/// peer.
pub bgp_config: NameOrId,
Expand Down Expand Up @@ -2582,6 +2579,110 @@ pub struct BgpPeer {
pub vlan_id: Option<u16>,
}

/// The information required to configure a BGP peer.
#[derive(Clone, Debug, Deserialize, Serialize, JsonSchema, PartialEq)]
pub struct BgpPeer {
/// 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
internet-diglett marked this conversation as resolved.
Show resolved Hide resolved
/// 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 th e host to peer with.
internet-diglett marked this conversation as resolved.
Show resolved Hide resolved
pub addr: oxnet::IpNet,

/// 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>,

/// 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,

/// Enable import policies
pub allow_import_list_active: bool,

/// Enable export policies
pub allow_export_list_active: bool,

/// Associate a VLAN ID with a peer.
internet-diglett marked this conversation as resolved.
Show resolved Hide resolved
pub vlan_id: Option<u16>,
}

/// A BGP peer configuration to remove from an interface
#[derive(Clone, Debug, Deserialize, Serialize, JsonSchema, PartialEq)]
pub struct BgpPeerRemove {
/// 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,
}

/// A BGP allowed prefix entry
#[derive(Clone, Debug, Deserialize, JsonSchema, Serialize, PartialEq)]
pub struct BgpAllowedPrefix {
/// Parent switch port configuration
pub port_settings_id: Uuid,
/// Interface peer is reachable on
pub interface_name: String,
/// Peer Address
pub addr: oxnet::IpNet,
/// Allowed Prefix
pub prefix: oxnet::IpNet,
}

/// A BGP community
#[derive(Clone, Debug, Deserialize, JsonSchema, Serialize, PartialEq)]
pub struct BgpCommunity {
/// Parent switch port configuration
pub port_settings_id: Uuid,
/// Interface peer is reachable on
pub interface_name: String,
/// Peer Address
pub addr: oxnet::IpNet,
/// Community
pub community: u32,
}

/// A base BGP configuration.
#[derive(
ObjectIdentity, Clone, Debug, Deserialize, JsonSchema, Serialize, PartialEq,
Expand Down
12 changes: 12 additions & 0 deletions nexus/db-model/src/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1904,3 +1904,15 @@ joinable!(instance_ssh_key -> instance (instance_id));
allow_tables_to_appear_in_same_query!(sled, sled_instance);

joinable!(network_interface -> probe (parent_id));

allow_tables_to_appear_in_same_query!(
switch_port_settings,
switch_port_settings_port_config,
switch_port_settings_link_config,
switch_port_settings_address_config,
switch_port_settings_route_config,
switch_port_settings_bgp_peer_config,
switch_port_settings_bgp_peer_config_allow_export,
switch_port_settings_bgp_peer_config_allow_import,
switch_port_settings_bgp_peer_config_communities,
);
3 changes: 2 additions & 1 deletion nexus/db-model/src/schema_versions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use std::collections::BTreeMap;
///
/// This must be updated when you change the database schema. Refer to
/// schema/crdb/README.adoc in the root of this repository for details.
pub const SCHEMA_VERSION: SemverVersion = SemverVersion::new(90, 0, 0);
pub const SCHEMA_VERSION: SemverVersion = SemverVersion::new(91, 0, 0);

/// List of all past database schema versions, in *reverse* order
///
Expand All @@ -29,6 +29,7 @@ static KNOWN_VERSIONS: Lazy<Vec<KnownVersion>> = Lazy::new(|| {
// | leaving the first copy as an example for the next person.
// v
// KnownVersion::new(next_int, "unique-dirname-with-the-sql-files"),
KnownVersion::new(91, "refactor-network-apis"),
KnownVersion::new(90, "lookup-bgp-config-by-asn"),
KnownVersion::new(89, "collapse_lldp_settings"),
KnownVersion::new(88, "route-local-pref"),
Expand Down
67 changes: 64 additions & 3 deletions nexus/db-model/src/switch_port.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,10 @@ 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::external::{BgpPeer, ImportExportPolicy};
use omicron_common::api::external::{
self, BgpAllowedPrefix, BgpCommunity, NameOrId,
};
use omicron_common::api::external::{BgpPeerCombined, ImportExportPolicy};
use omicron_common::api::internal::shared::{PortFec, PortSpeed};
use serde::{Deserialize, Serialize};
use uuid::Uuid;
Expand Down Expand Up @@ -620,6 +622,32 @@ pub struct SwitchPortBgpPeerConfig {
pub vlan_id: Option<SqlU16>,
}

impl Into<external::BgpPeer> for SwitchPortBgpPeerConfig {
fn into(self) -> external::BgpPeer {
external::BgpPeer {
bgp_config: NameOrId::Id(self.bgp_config_id),
interface_name: self.interface_name,
addr: self.addr.into(),
hold_time: self.hold_time.into(),
idle_hold_time: self.idle_hold_time.into(),
delay_open: self.delay_open.into(),
connect_retry: self.connect_retry.into(),
keepalive: self.keepalive.into(),
remote_asn: self.remote_asn.map(Into::into),
min_ttl: self.min_ttl.map(Into::into),
md5_auth_key: self.md5_auth_key,
multi_exit_discriminator: self
.multi_exit_discriminator
.map(Into::into),
local_pref: self.local_pref.map(Into::into),
enforce_first_as: self.enforce_first_as,
allow_import_list_active: self.allow_import_list_active,
allow_export_list_active: self.allow_export_list_active,
vlan_id: self.vlan_id.map(Into::into),
}
}
}

#[derive(
Queryable,
Insertable,
Expand All @@ -638,6 +666,17 @@ pub struct SwitchPortBgpPeerConfigCommunity {
pub community: SqlU32,
}

impl Into<BgpCommunity> for SwitchPortBgpPeerConfigCommunity {
fn into(self) -> BgpCommunity {
BgpCommunity {
port_settings_id: self.port_settings_id,
interface_name: self.interface_name,
addr: self.addr.into(),
community: self.community.into(),
}
}
}

#[derive(
Queryable,
Insertable,
Expand All @@ -660,6 +699,17 @@ pub struct SwitchPortBgpPeerConfigAllowExport {
pub prefix: IpNetwork,
}

impl Into<BgpAllowedPrefix> for SwitchPortBgpPeerConfigAllowExport {
fn into(self) -> BgpAllowedPrefix {
BgpAllowedPrefix {
port_settings_id: self.port_settings_id,
interface_name: self.interface_name,
addr: self.addr.into(),
prefix: self.prefix.into(),
}
}
}

#[derive(
Queryable,
Insertable,
Expand Down Expand Up @@ -688,7 +738,7 @@ impl SwitchPortBgpPeerConfig {
port_settings_id: Uuid,
bgp_config_id: Uuid,
interface_name: String,
p: &BgpPeer,
p: &BgpPeerCombined,
) -> Self {
Self {
port_settings_id,
Expand Down Expand Up @@ -721,6 +771,17 @@ impl SwitchPortBgpPeerConfig {
}
}

impl Into<BgpAllowedPrefix> for SwitchPortBgpPeerConfigAllowImport {
fn into(self) -> BgpAllowedPrefix {
BgpAllowedPrefix {
port_settings_id: self.port_settings_id,
interface_name: self.interface_name,
addr: self.addr.into(),
prefix: self.prefix.into(),
}
}
}

#[derive(
Queryable,
Insertable,
Expand Down
Loading
Loading