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
10 changes: 9 additions & 1 deletion Cargo.lock

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

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ members = [
"lldpd-client",
"lldpd-common",
"lldpd-types",
"lldpd-types/versions",
"lldpd",
"protocol",
"xtask",
Expand All @@ -21,6 +22,7 @@ lldpd-api = { path = "lldpd-api" }
lldpd-client = { path = "lldpd-client" }
lldpd-common = { path = "lldpd-common" }
lldpd-types = { path = "lldpd-types" }
lldpd-types-versions = { path = "lldpd-types/versions" }
protocol = { path = "protocol" }

# oxide dependencies from github
Expand Down
2 changes: 1 addition & 1 deletion lldpd-api/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ license = "MPL-2.0"
[dependencies]
dropshot.workspace = true
dropshot-api-manager-types.workspace = true
lldpd-types.workspace = true
lldpd-types-versions.workspace = true
protocol.workspace = true
schemars.workspace = true
serde.workspace = true
125 changes: 40 additions & 85 deletions lldpd-api/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,14 @@
//
// Copyright 2025 Oxide Computer Company

use std::net::IpAddr;

use dropshot::{
EmptyScanParams, HttpError, HttpResponseCreated, HttpResponseDeleted,
HttpResponseOk, HttpResponseUpdatedNoContent, PaginationParams, Path,
Query, RequestContext, ResultsPage, TypedBody,
};
use dropshot_api_manager_types::api_versions;
use lldpd_types::{
build_info::BuildInfo,
interfaces::{Interface, InterfaceAdd},
neighbor::{Neighbor, NeighborId},
};
use protocol::types::{ChassisId, PortId, SystemCapabilities};
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};
use lldpd_types_versions::latest;
use protocol::types::{ChassisId, PortId};

api_versions!([
// WHEN CHANGING THE API (part 1 of 2):
Expand Down Expand Up @@ -109,7 +101,7 @@ pub trait LldpdApi {
}]
async fn sys_add_system_capability(
rqctx: RequestContext<Self::Context>,
path: Path<SystemCapabilityPathParams>,
path: Path<latest::system_info::SystemCapabilityPathParams>,
) -> Result<HttpResponseUpdatedNoContent, HttpError>;

/// Remove a capability from the set of those advertised on all interfaces
Expand All @@ -119,7 +111,7 @@ pub trait LldpdApi {
}]
async fn sys_del_system_capability(
rqctx: RequestContext<Self::Context>,
path: Path<SystemCapabilityPathParams>,
path: Path<latest::system_info::SystemCapabilityPathParams>,
) -> Result<HttpResponseDeleted, HttpError>;

/// Add a capability to the set of those advertised as enabled on all interfaces
Expand All @@ -129,7 +121,7 @@ pub trait LldpdApi {
}]
async fn sys_enable_system_capability(
rqctx: RequestContext<Self::Context>,
path: Path<SystemCapabilityPathParams>,
path: Path<latest::system_info::SystemCapabilityPathParams>,
) -> Result<HttpResponseUpdatedNoContent, HttpError>;

/// Remove a capability from the set of those advertised as enabled on all interfaces
Expand All @@ -139,7 +131,7 @@ pub trait LldpdApi {
}]
async fn sys_disable_system_capability(
rqctx: RequestContext<Self::Context>,
path: Path<SystemCapabilityPathParams>,
path: Path<latest::system_info::SystemCapabilityPathParams>,
) -> Result<HttpResponseDeleted, HttpError>;

/// Add a management address to the set of those advertised on all interfaces
Expand All @@ -149,7 +141,7 @@ pub trait LldpdApi {
}]
async fn sys_add_management_addr(
rqctx: RequestContext<Self::Context>,
path: Path<SystemAddressPathParams>,
path: Path<latest::system_info::SystemAddressPathParams>,
) -> Result<HttpResponseUpdatedNoContent, HttpError>;

/// Remove a management address from the set of those advertised on all interfaces
Expand All @@ -159,7 +151,7 @@ pub trait LldpdApi {
}]
async fn sys_del_management_addr(
rqctx: RequestContext<Self::Context>,
path: Path<SystemAddressPathParams>,
path: Path<latest::system_info::SystemAddressPathParams>,
) -> Result<HttpResponseDeleted, HttpError>;

/// Remove all management addresses from the set of those advertised on all
Expand All @@ -178,8 +170,8 @@ pub trait LldpdApi {
}]
async fn interface_add(
rqctx: RequestContext<Self::Context>,
path: Path<InterfacePathParams>,
params: TypedBody<InterfaceAdd>,
path: Path<latest::interfaces::InterfacePathParams>,
params: TypedBody<latest::interfaces::InterfaceAdd>,
) -> Result<HttpResponseCreated<()>, HttpError>;

#[endpoint {
Expand All @@ -188,7 +180,7 @@ pub trait LldpdApi {
}]
async fn interface_del(
rqctx: RequestContext<Self::Context>,
path: Path<InterfacePathParams>,
path: Path<latest::interfaces::InterfacePathParams>,
) -> Result<HttpResponseDeleted, HttpError>;

#[endpoint {
Expand All @@ -197,24 +189,24 @@ pub trait LldpdApi {
}]
async fn interface_get(
rqctx: RequestContext<Self::Context>,
path: Path<InterfacePathParams>,
) -> Result<HttpResponseOk<Interface>, HttpError>;
path: Path<latest::interfaces::InterfacePathParams>,
) -> Result<HttpResponseOk<latest::interfaces::Interface>, HttpError>;

#[endpoint {
method = GET,
path = "/interface",
}]
async fn interface_list(
rqctx: RequestContext<Self::Context>,
) -> Result<HttpResponseOk<Vec<Interface>>, HttpError>;
) -> Result<HttpResponseOk<Vec<latest::interfaces::Interface>>, HttpError>;

#[endpoint {
method = POST,
path = "/interface/{iface}/disabled",
}]
async fn interface_set_disabled(
rqctx: RequestContext<Self::Context>,
path: Path<InterfacePathParams>,
path: Path<latest::interfaces::InterfacePathParams>,
body: TypedBody<bool>,
) -> Result<HttpResponseUpdatedNoContent, HttpError>;

Expand All @@ -224,7 +216,7 @@ pub trait LldpdApi {
}]
async fn interface_set_chassis_id(
rqctx: RequestContext<Self::Context>,
path: Path<InterfacePathParams>,
path: Path<latest::interfaces::InterfacePathParams>,
body: TypedBody<ChassisId>,
) -> Result<HttpResponseUpdatedNoContent, HttpError>;

Expand All @@ -234,7 +226,7 @@ pub trait LldpdApi {
}]
async fn interface_del_chassis_id(
rqctx: RequestContext<Self::Context>,
path: Path<InterfacePathParams>,
path: Path<latest::interfaces::InterfacePathParams>,
) -> Result<HttpResponseDeleted, HttpError>;

#[endpoint {
Expand All @@ -243,7 +235,7 @@ pub trait LldpdApi {
}]
async fn interface_set_port_id(
rqctx: RequestContext<Self::Context>,
path: Path<InterfacePathParams>,
path: Path<latest::interfaces::InterfacePathParams>,
body: TypedBody<PortId>,
) -> Result<HttpResponseUpdatedNoContent, HttpError>;

Expand All @@ -253,7 +245,7 @@ pub trait LldpdApi {
}]
async fn interface_set_port_description(
rqctx: RequestContext<Self::Context>,
path: Path<InterfacePathParams>,
path: Path<latest::interfaces::InterfacePathParams>,
body: TypedBody<String>,
) -> Result<HttpResponseUpdatedNoContent, HttpError>;

Expand All @@ -263,7 +255,7 @@ pub trait LldpdApi {
}]
async fn interface_del_port_description(
rqctx: RequestContext<Self::Context>,
path: Path<InterfacePathParams>,
path: Path<latest::interfaces::InterfacePathParams>,
) -> Result<HttpResponseDeleted, HttpError>;

#[endpoint {
Expand All @@ -272,7 +264,7 @@ pub trait LldpdApi {
}]
async fn interface_set_system_name(
rqctx: RequestContext<Self::Context>,
path: Path<InterfacePathParams>,
path: Path<latest::interfaces::InterfacePathParams>,
body: TypedBody<String>,
) -> Result<HttpResponseUpdatedNoContent, HttpError>;

Expand All @@ -282,7 +274,7 @@ pub trait LldpdApi {
}]
async fn interface_del_system_name(
rqctx: RequestContext<Self::Context>,
path: Path<InterfacePathParams>,
path: Path<latest::interfaces::InterfacePathParams>,
) -> Result<HttpResponseDeleted, HttpError>;

#[endpoint {
Expand All @@ -291,7 +283,7 @@ pub trait LldpdApi {
}]
async fn interface_set_system_description(
rqctx: RequestContext<Self::Context>,
path: Path<InterfacePathParams>,
path: Path<latest::interfaces::InterfacePathParams>,
body: TypedBody<String>,
) -> Result<HttpResponseUpdatedNoContent, HttpError>;
#[endpoint {
Expand All @@ -300,7 +292,7 @@ pub trait LldpdApi {
}]
async fn interface_del_system_description(
rqctx: RequestContext<Self::Context>,
path: Path<InterfacePathParams>,
path: Path<latest::interfaces::InterfacePathParams>,
) -> Result<HttpResponseDeleted, HttpError>;

#[endpoint {
Expand All @@ -309,7 +301,7 @@ pub trait LldpdApi {
}]
async fn interface_add_system_capability(
rqctx: RequestContext<Self::Context>,
path: Path<InterfaceCapabilityPathParams>,
path: Path<latest::interfaces::InterfaceCapabilityPathParams>,
) -> Result<HttpResponseUpdatedNoContent, HttpError>;

#[endpoint {
Expand All @@ -318,7 +310,7 @@ pub trait LldpdApi {
}]
async fn interface_del_system_capability(
rqctx: RequestContext<Self::Context>,
path: Path<InterfaceCapabilityPathParams>,
path: Path<latest::interfaces::InterfaceCapabilityPathParams>,
) -> Result<HttpResponseDeleted, HttpError>;

#[endpoint {
Expand All @@ -327,7 +319,7 @@ pub trait LldpdApi {
}]
async fn interface_enable_system_capability(
rqctx: RequestContext<Self::Context>,
path: Path<InterfaceCapabilityPathParams>,
path: Path<latest::interfaces::InterfaceCapabilityPathParams>,
) -> Result<HttpResponseUpdatedNoContent, HttpError>;

#[endpoint {
Expand All @@ -336,7 +328,7 @@ pub trait LldpdApi {
}]
async fn interface_disable_system_capability(
rqctx: RequestContext<Self::Context>,
path: Path<InterfaceCapabilityPathParams>,
path: Path<latest::interfaces::InterfaceCapabilityPathParams>,
) -> Result<HttpResponseDeleted, HttpError>;

#[endpoint {
Expand All @@ -345,7 +337,7 @@ pub trait LldpdApi {
}]
async fn interface_add_management_addr(
rqctx: RequestContext<Self::Context>,
path: Path<InterfaceAddressPathParams>,
path: Path<latest::interfaces::InterfaceAddressPathParams>,
) -> Result<HttpResponseUpdatedNoContent, HttpError>;

#[endpoint {
Expand All @@ -354,7 +346,7 @@ pub trait LldpdApi {
}]
async fn interface_del_management_addr(
rqctx: RequestContext<Self::Context>,
path: Path<InterfaceAddressPathParams>,
path: Path<latest::interfaces::InterfaceAddressPathParams>,
) -> Result<HttpResponseDeleted, HttpError>;

#[endpoint {
Expand All @@ -363,7 +355,7 @@ pub trait LldpdApi {
}]
async fn interface_clear_management_addr(
rqctx: RequestContext<Self::Context>,
path: Path<InterfacePathParams>,
path: Path<latest::interfaces::InterfacePathParams>,
) -> Result<HttpResponseDeleted, HttpError>;

/// Return a list of the active neighbors
Expand All @@ -373,9 +365,14 @@ pub trait LldpdApi {
}]
async fn get_neighbors(
rqctx: RequestContext<Self::Context>,
path: Path<InterfacePathParams>,
query: Query<PaginationParams<EmptyScanParams, NeighborToken>>,
) -> Result<HttpResponseOk<ResultsPage<Neighbor>>, HttpError>;
path: Path<latest::interfaces::InterfacePathParams>,
query: Query<
PaginationParams<EmptyScanParams, latest::neighbor::NeighborToken>,
>,
) -> Result<
HttpResponseOk<ResultsPage<latest::neighbor::Neighbor>>,
HttpError,
>;

/// Return detailed build information about the `dpd` server itself.
#[endpoint {
Expand All @@ -384,47 +381,5 @@ pub trait LldpdApi {
}]
async fn build_info(
_rqctx: RequestContext<Self::Context>,
) -> Result<HttpResponseOk<BuildInfo>, HttpError>;
}

#[derive(Deserialize, Serialize, JsonSchema)]
pub struct SystemCapabilityPathParams {
pub capability: SystemCapabilities,
}

#[derive(Deserialize, Serialize, JsonSchema)]
pub struct SystemAddressPathParams {
pub address: IpAddr,
}

#[derive(Deserialize, Serialize, JsonSchema)]
pub struct InterfacePathParams {
/// The switch port on which to operate.
pub iface: String,
}

#[derive(Deserialize, Serialize, JsonSchema)]
pub struct InterfaceCapabilityPathParams {
/// The switch port on which to operate.
pub iface: String,
pub capability: SystemCapabilities,
}

#[derive(Deserialize, Serialize, JsonSchema)]
pub struct InterfaceAddressPathParams {
/// The switch port on which to operate.
pub iface: String,
/// Management Address to advertise on this port
// TODO-completeness: this should allow non-IP addresses to be specified (as
// per the standard) and should include an optional interface number.
pub address: IpAddr,
}

/**
* Represents a cursor into a paginated request for the contents of the neighbor
* list.
*/
#[derive(Deserialize, Serialize, JsonSchema)]
pub struct NeighborToken {
pub id: NeighborId,
) -> Result<HttpResponseOk<latest::build_info::BuildInfo>, HttpError>;
}
Loading