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

6750 Add support for post-install LLDP configuration #7132

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
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
32 changes: 32 additions & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -439,6 +439,7 @@ libfalcon = { git = "https://github.com/oxidecomputer/falcon", branch = "main" }
libnvme = { git = "https://github.com/oxidecomputer/libnvme", rev = "dd5bb221d327a1bc9287961718c3c10d6bd37da0" }
linear-map = "1.2.0"
live-tests-macros = { path = "live-tests/macros" }
lldpd-client = { git = "https://github.com/oxidecomputer/lldp" }
macaddr = { version = "1.0.1", features = ["serde_std"] }
maplit = "1.0.2"
mockall = "0.13"
Expand Down
35 changes: 35 additions & 0 deletions common/src/api/external/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1010,6 +1010,7 @@ pub enum ResourceType {
FloatingIp,
Probe,
ProbeNetworkInterface,
LldpLinkConfig,
}

// IDENTITY METADATA
Expand Down Expand Up @@ -2555,6 +2556,40 @@ pub struct LldpLinkConfig {
pub management_ip: Option<oxnet::IpNet>,
}

/// Information about LLDP advertisements from other network entities directly
/// connected to a switch port. This structure contains both metadata about
/// when and where the neighbor was seen, as well as the specific information
/// the neighbor was advertising.
#[derive(Clone, Debug, Deserialize, JsonSchema, Serialize, PartialEq)]
pub struct LldpNeighbor {
/// The port on which the neighbor was seen
pub local_port: String,

/// Initial sighting of this LldpNeighbor
pub first_seen: DateTime<Utc>,

/// Most recent sighting of this LldpNeighbor
pub last_seen: DateTime<Utc>,

/// The LLDP link name advertised by the neighbor
pub link_name: String,

/// The LLDP link description advertised by the neighbor
pub link_description: Option<String>,

/// The LLDP chassis identifier advertised by the neighbor
pub chassis_id: String,

/// The LLDP system name advertised by the neighbor
pub system_name: Option<String>,

/// The LLDP system description advertised by the neighbor
pub system_description: Option<String>,

/// The LLDP management IP(s) advertised by the neighbor
pub management_ip: Vec<oxnet::IpNet>,
}

/// Per-port tx-eq overrides. This can be used to fine-tune the transceiver
/// equalization settings to improve signal integrity.
#[derive(Clone, Debug, Deserialize, JsonSchema, Serialize, PartialEq)]
Expand Down
8 changes: 7 additions & 1 deletion dev-tools/ls-apis/api-manifest.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
# Progenitor clients or APIs, so they're left out to avoid needing to create and
# process clones of these repos:
#
# - lldp
# - pumpkind
# - thundermuffin
#
Expand Down Expand Up @@ -74,6 +73,7 @@ packages = [
# switch zone
"ddmd",
"dpd",
"lldpd",
"mgd",
"omicron-gateway",
"tfportd",
Expand Down Expand Up @@ -231,6 +231,12 @@ and exists as a client library within omicron. This is because the Dendrite \
repo is not currently open source.
"""

[[apis]]
client_package_name = "lldpd-client"
label = "LLDP daemon"
server_package_name = "lldpd"
notes = "The LLDP daemon runs in the switch zone and is deployed next to dpd."

[[apis]]
client_package_name = "gateway-client"
label = "Management Gateway Service"
Expand Down
1 change: 1 addition & 0 deletions dev-tools/ls-apis/src/workspaces.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ impl Workspaces {
)])),
),
("maghemite", "mg-admin-client", None),
("lldp", "lldpd-client", None),
]
.into_iter()
.map(|(repo, omicron_pkg, extra_features)| {
Expand Down
3 changes: 3 additions & 0 deletions dev-tools/ls-apis/tests/api_dependencies.out
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ Management Gateway Service (client: gateway-client)
Wicketd Installinator (client: installinator-client)
consumed by: installinator (omicron/installinator) via 1 path

LLDP daemon (client: lldpd-client)
consumed by: omicron-nexus (omicron/nexus) via 1 path

Maghemite MG Admin (client: mg-admin-client)
consumed by: omicron-nexus (omicron/nexus) via 1 path
consumed by: omicron-sled-agent (omicron/sled-agent) via 1 path
Expand Down
1 change: 1 addition & 0 deletions nexus/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ internal-dns-resolver.workspace = true
internal-dns-types.workspace = true
ipnetwork.workspace = true
itertools.workspace = true
lldpd-client.workspace = true
macaddr.workspace = true
# Not under "dev-dependencies"; these also need to be implemented for
# integration tests.
Expand Down
178 changes: 178 additions & 0 deletions nexus/db-queries/src/db/datastore/lldp.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,178 @@
use super::DataStore;
use crate::context::OpContext;
use crate::db;
use crate::db::error::public_error_from_diesel;
use crate::db::error::ErrorHandler;
use crate::db::model::LldpLinkConfig;
use async_bb8_diesel::AsyncRunQueryDsl;
use chrono::Utc;
use diesel::ExpressionMethods;
use diesel::QueryDsl;
use diesel::SelectableHelper;
use ipnetwork::IpNetwork;
use omicron_common::api::external;
use omicron_common::api::external::Error;
use omicron_common::api::external::LookupResult;
use omicron_common::api::external::Name;
use omicron_common::api::external::ResourceType;
use omicron_common::api::external::UpdateResult;
use uuid::Uuid;

// The LLDP configuration has been defined as a leaf of the switch-port-settings
// tree, and is identified in the database with a UUID stored in that tree.
// Using the uuid as the target argument for the config operations would be
// reasonable, and similar in spirit to the link configuration operations.
//
// On the other hand, the neighbors are discovered on a configured link, but the
// data is otherwise completely independent of the configuration. Furthermore,
// the questions answered by the neighbor information have to do with the
// physical connections between the Oxide rack and the upstream, datacenter
// switch. Accordingly, it seems more appropriate to use the physical
// rack/switch/port triple to identify the port of interest for the neighbors
// query.
//
// For consistency across the lldp operations, all use rack/switch/port rather
// than the uuid.
// XXX: Is this the right call? The other options being: uuid for all
// operations, or uuid for config and r/s/p for neighbors.
Comment on lines +21 to +37
Copy link
Contributor

Choose a reason for hiding this comment

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

Is there a reason LLDP configuration should be a part of the switch-port-settings object, aside from everything else also being there? I think it can be argued that we could migrate it out and make the CREATE operation consistent with the other paths that have been defined for the GET and UPDATE methods.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I could go back and look at the git history to be sure, but I think they've been there for as long as we've have switch port settings in the database. These are settings that belong to a specific port on the switch, so I'm not sure where else they would go? The settings themselves have their own table - the switch-port-settings just has a link to that table.

If you have something specific in mind, I'd be happy to tackle that as follow-on work. This is already a pretty chunky PR and doesn't include any database changes, so I'd rather not weigh it down with a db restructure as well.

impl DataStore {
/// Look up the settings id for this port in the switch_port table by its
/// rack/switch/port triple, and then use that id to look up the lldp
/// config id in the switch_port_settings_link_config table.
async fn lldp_config_id_get(
&self,
opctx: &OpContext,
rack_id: Uuid,
switch_location: Name,
port_name: Name,
) -> LookupResult<Uuid> {
use db::schema::switch_port;
use db::schema::switch_port::dsl as switch_port_dsl;
use db::schema::switch_port_settings_link_config;
use db::schema::switch_port_settings_link_config::dsl as config_dsl;

let conn = self.pool_connection_authorized(opctx).await?;

let port_settings_id: Uuid = switch_port_dsl::switch_port
.filter(switch_port::rack_id.eq(rack_id))
.filter(
switch_port::switch_location.eq(switch_location.to_string()),
)
.filter(switch_port::port_name.eq(port_name.to_string()))
.select(switch_port::port_settings_id)
.limit(1)
.first_async::<Option<Uuid>>(&*conn)
.await
.map_err(|_| {
Error::not_found_by_name(ResourceType::SwitchPort, &port_name)
})?
.ok_or(Error::invalid_value(
"settings",
"switch port not yet configured".to_string(),
))?;

let lldp_id: Uuid = config_dsl::switch_port_settings_link_config
.filter(
switch_port_settings_link_config::port_settings_id
.eq(port_settings_id),
)
.select(switch_port_settings_link_config::lldp_link_config_id)
.limit(1)
.first_async::<Option<Uuid>>(&*conn)
.await
.map_err(|_| {
Error::not_found_by_id(
ResourceType::SwitchPortSettings,
&port_settings_id,
)
})?
.ok_or(Error::invalid_value(
"settings",
"lldp not configured for this port".to_string(),
))?;
Ok(lldp_id)
}

/// Fetch the current LLDP configuration settings for the link identified
/// using the rack/switch/port triple.
pub async fn lldp_config_get(
&self,
opctx: &OpContext,
rack_id: Uuid,
switch_location: Name,
port_name: Name,
) -> LookupResult<external::LldpLinkConfig> {
use db::schema::lldp_link_config;
use db::schema::lldp_link_config::dsl;

let id = self
.lldp_config_id_get(opctx, rack_id, switch_location, port_name)
.await?;

let conn = self.pool_connection_authorized(opctx).await?;
dsl::lldp_link_config
.filter(lldp_link_config::id.eq(id))
.select(LldpLinkConfig::as_select())
.limit(1)
.first_async::<LldpLinkConfig>(&*conn)
.await
.map(|config| config.into())
.map_err(|e| {
let msg = "failed to lookup lldp config by id";
error!(opctx.log, "{msg}"; "error" => ?e);

match e {
diesel::result::Error::NotFound => Error::not_found_by_id(
ResourceType::LldpLinkConfig,
&id,
),
_ => Error::internal_error(msg),
}
})
}

/// Update the current LLDP configuration settings for the link identified
/// using the rack/switch/port triple. n.b.: each link is given an empty
/// configuration structure at link creation time, so there are no
/// lldp config create/delete operations.
pub async fn lldp_config_update(
&self,
opctx: &OpContext,
rack_id: Uuid,
switch_location: Name,
port_name: Name,
config: external::LldpLinkConfig,
) -> UpdateResult<()> {
use db::schema::lldp_link_config::dsl;

let id = self
.lldp_config_id_get(opctx, rack_id, switch_location, port_name)
.await?;
if id != config.id {
return Err(external::Error::invalid_request(&format!(
"id ({}) doesn't match provided config ({})",
id, config.id
)));
}

diesel::update(dsl::lldp_link_config)
.filter(dsl::time_deleted.is_null())
.filter(dsl::id.eq(id))
.set((
dsl::time_modified.eq(Utc::now()),
dsl::enabled.eq( config.enabled),
dsl::link_name.eq( config.link_name.clone()),
dsl::link_description.eq( config.link_description.clone()),
dsl::chassis_id.eq( config.chassis_id.clone()),
dsl::system_name.eq( config.system_name.clone()),
dsl::system_description.eq( config.system_description.clone()),
dsl::management_ip.eq( config.management_ip.map(|a| IpNetwork::from(a)))))
.execute_async(&*self.pool_connection_authorized(opctx).await?)
.await
.map_err(|err| {
error!(opctx.log, "lldp link config update failed"; "error" => ?err);
public_error_from_diesel(err, ErrorHandler::Server)
})?;
Ok(())
}
}
1 change: 1 addition & 0 deletions nexus/db-queries/src/db/datastore/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ pub mod instance;
mod inventory;
mod ip_pool;
mod ipv4_nat_entry;
mod lldp;
mod migration;
mod network_interface;
mod oximeter;
Expand Down
3 changes: 3 additions & 0 deletions nexus/external-api/output/nexus_tags.txt
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,9 @@ networking_bgp_status GET /v1/system/networking/bgp-stat
networking_loopback_address_create POST /v1/system/networking/loopback-address
networking_loopback_address_delete DELETE /v1/system/networking/loopback-address/{rack_id}/{switch_location}/{address}/{subnet_mask}
networking_loopback_address_list GET /v1/system/networking/loopback-address
networking_switch_port_lldp_config_update POST /v1/system/hardware/switch-port/{port}/lldp/config
networking_switch_port_lldp_config_view GET /v1/system/hardware/switch-port/{port}/lldp/config
networking_switch_port_lldp_neighbors GET /v1/system/hardware/switch-port/{port}/lldp/neighbors
networking_switch_port_settings_create POST /v1/system/networking/switch-port-settings
networking_switch_port_settings_delete DELETE /v1/system/networking/switch-port-settings
networking_switch_port_settings_list GET /v1/system/networking/switch-port-settings
Expand Down
Loading
Loading