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.

3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ default-members = [
"ddm-admin-client",
"ddm-api",
"ddm-types",
"ddm-types/versions",
"dropshot-apis",
"bfd",
"util",
Expand All @@ -33,6 +34,7 @@ members = [
"ddm-admin-client",
"ddm-api",
"ddm-types",
"ddm-types/versions",
"dropshot-apis",
"bfd",
"package",
Expand Down Expand Up @@ -114,6 +116,7 @@ proptest = "1.4"
serial_test = "3.2"
ddm-api = { path = "ddm-api" }
ddm-types = { path = "ddm-types" }
ddm-types-versions = { path = "ddm-types/versions" }
gateway-client = { git = "https://github.com/oxidecomputer/omicron", branch = "main" }

[workspace.dependencies.opte-ioctl]
Expand Down
2 changes: 1 addition & 1 deletion ddm-api/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ version = "0.1.0"
edition = "2024"

[dependencies]
ddm-types.workspace = true
ddm-types-versions.workspace = true
dropshot.workspace = true
dropshot-api-manager-types.workspace = true
mg-common.workspace = true
Expand Down
33 changes: 7 additions & 26 deletions ddm-api/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@
// 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 ddm_types::db::PeerInfo;
use ddm_types::db::TunnelRoute;
use ddm_types::exchange::PathVector;
use ddm_types_versions::latest;
use dropshot::HttpError;
use dropshot::HttpResponseOk;
use dropshot::HttpResponseUpdatedNoContent;
Expand All @@ -14,13 +12,7 @@ use dropshot::TypedBody;
use dropshot_api_manager_types::api_versions;
use mg_common::net::TunnelOrigin;
use oxnet::Ipv6Net;
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};
use std::collections::{BTreeMap, HashMap, HashSet};
use std::net::Ipv6Addr;
use uuid::Uuid;

pub type PrefixMap = BTreeMap<Ipv6Addr, HashSet<PathVector>>;
use std::collections::{HashMap, HashSet};

api_versions!([
// WHEN CHANGING THE API (part 1 of 2):
Expand Down Expand Up @@ -56,12 +48,12 @@ pub trait DdmAdminApi {
#[endpoint { method = GET, path = "/peers" }]
async fn get_peers(
ctx: RequestContext<Self::Context>,
) -> Result<HttpResponseOk<HashMap<u32, PeerInfo>>, HttpError>;
) -> Result<HttpResponseOk<HashMap<u32, latest::db::PeerInfo>>, HttpError>;

#[endpoint { method = DELETE, path = "/peers/{addr}" }]
async fn expire_peer(
ctx: RequestContext<Self::Context>,
params: Path<ExpirePathParams>,
params: Path<latest::admin::ExpirePathParams>,
) -> Result<HttpResponseUpdatedNoContent, HttpError>;

#[endpoint { method = GET, path = "/originated" }]
Expand All @@ -77,12 +69,12 @@ pub trait DdmAdminApi {
#[endpoint { method = GET, path = "/prefixes" }]
async fn get_prefixes(
ctx: RequestContext<Self::Context>,
) -> Result<HttpResponseOk<PrefixMap>, HttpError>;
) -> Result<HttpResponseOk<latest::admin::PrefixMap>, HttpError>;

#[endpoint { method = GET, path = "/tunnel_endpoints" }]
async fn get_tunnel_endpoints(
ctx: RequestContext<Self::Context>,
) -> Result<HttpResponseOk<HashSet<TunnelRoute>>, HttpError>;
) -> Result<HttpResponseOk<HashSet<latest::db::TunnelRoute>>, HttpError>;

#[endpoint { method = PUT, path = "/prefix" }]
async fn advertise_prefixes(
Expand Down Expand Up @@ -116,22 +108,11 @@ pub trait DdmAdminApi {
#[endpoint { method = POST, path = "/enable-stats" }]
async fn enable_stats(
ctx: RequestContext<Self::Context>,
request: TypedBody<EnableStatsRequest>,
request: TypedBody<latest::admin::EnableStatsRequest>,
) -> Result<HttpResponseUpdatedNoContent, HttpError>;

#[endpoint { method = POST, path = "/disable-stats" }]
async fn disable_stats(
ctx: RequestContext<Self::Context>,
) -> Result<HttpResponseUpdatedNoContent, HttpError>;
}

#[derive(Debug, Clone, Deserialize, Serialize, JsonSchema)]
pub struct ExpirePathParams {
pub addr: Ipv6Addr,
}

#[derive(Clone, Debug, Serialize, Deserialize, JsonSchema, PartialEq)]
pub struct EnableStatsRequest {
pub sled_id: Uuid,
pub rack_id: Uuid,
}
6 changes: 1 addition & 5 deletions ddm-types/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,4 @@ version = "0.1.0"
edition = "2024"

[dependencies]
mg-common.workspace = true
oxnet.workspace = true
schemars.workspace = true
serde.workspace = true
serde_repr.workspace = true
ddm-types-versions.workspace = true
5 changes: 5 additions & 0 deletions ddm-types/src/admin.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// This Source Code Form is subject to the terms of the Mozilla Public
// 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/.

pub use ddm_types_versions::latest::admin::*;
87 changes: 1 addition & 86 deletions ddm-types/src/db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,89 +2,4 @@
// 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 std::net::Ipv6Addr;

use mg_common::net::TunnelOrigin;
use schemars::{JsonSchema, JsonSchema_repr};
use serde::{Deserialize, Serialize};
use serde_repr::{Deserialize_repr, Serialize_repr};

#[derive(
Debug, Copy, Clone, PartialEq, Eq, Deserialize, Serialize, JsonSchema,
)]
pub enum PeerStatus {
NoContact,
Active,
Expired,
}

#[derive(Clone, Debug, Serialize, Deserialize, JsonSchema, PartialEq)]
pub struct PeerInfo {
pub status: PeerStatus,
pub addr: Ipv6Addr,
pub host: String,
pub kind: RouterKind,
}

#[derive(
Debug,
PartialEq,
Eq,
Clone,
Copy,
Serialize_repr,
Deserialize_repr,
JsonSchema_repr,
)]
#[repr(u8)]
pub enum RouterKind {
Server,
Transit,
}

impl std::fmt::Display for RouterKind {
fn fmt(
&self,
f: &mut std::fmt::Formatter<'_>,
) -> Result<(), std::fmt::Error> {
match self {
Self::Server => write!(f, "server"),
Self::Transit => write!(f, "transit"),
}
}
}

impl std::str::FromStr for RouterKind {
type Err = &'static str;
fn from_str(s: &str) -> Result<Self, Self::Err> {
match s {
"server" => Ok(Self::Server),
"transit" => Ok(Self::Transit),
_ => Err(r#"Router kind must be "server" or "transit""#),
}
}
}

#[derive(
Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize, JsonSchema,
)]
pub struct TunnelRoute {
pub origin: TunnelOrigin,

// The nexthop is only used to associate the route with a peer allowing us
// to remove the route if the peer expires. It does not influence what goes
// into the underlaying underlay routing platform. Tunnel routes only
// influence the state of the underlying encapsulation service.
pub nexthop: Ipv6Addr,
}

impl From<TunnelRoute> for TunnelOrigin {
fn from(x: TunnelRoute) -> Self {
Self {
overlay_prefix: x.origin.overlay_prefix,
boundary_addr: x.origin.boundary_addr,
vni: x.origin.vni,
metric: x.origin.metric,
}
}
}
pub use ddm_types_versions::latest::db::*;
48 changes: 1 addition & 47 deletions ddm-types/src/exchange.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,50 +2,4 @@
// 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 mg_common::net::Ipv6Prefix;
use oxnet::Ipv6Net;
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};

#[derive(
Debug, Clone, PartialEq, Eq, Hash, Deserialize, Serialize, JsonSchema,
)]
pub struct PathVector {
pub destination: Ipv6Net,
pub path: Vec<String>,
}

/// THIS TYPE IS FOR DDM PROTOCOL VERSION 2. IT SHALL NEVER CHANGE. THIS TYPE
/// CAN BE REMOVED WHEN DDMV2 CLIENTS AND SERVERS NO LONGER EXIST BUT ITS
/// DEFINITION SHALL NEVER CHANGE.
#[derive(
Debug, Clone, PartialEq, Eq, Hash, Deserialize, Serialize, JsonSchema,
)]
pub struct PathVectorV2 {
pub destination: Ipv6Prefix,
pub path: Vec<String>,
}

impl From<PathVectorV2> for PathVector {
fn from(value: PathVectorV2) -> Self {
PathVector {
destination: Ipv6Net::new_unchecked(
value.destination.addr,
value.destination.len,
),
path: value.path,
}
}
}

impl From<PathVector> for PathVectorV2 {
fn from(value: PathVector) -> Self {
PathVectorV2 {
destination: Ipv6Prefix {
addr: value.destination.addr(),
len: value.destination.width(),
},
path: value.path,
}
}
}
pub use ddm_types_versions::latest::exchange::*;
1 change: 1 addition & 0 deletions ddm-types/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +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/.

pub mod admin;
pub mod db;
pub mod exchange;
12 changes: 12 additions & 0 deletions ddm-types/versions/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
[package]
name = "ddm-types-versions"
version = "0.1.0"
edition = "2024"

[dependencies]
mg-common.workspace = true
oxnet.workspace = true
schemars.workspace = true
serde.workspace = true
serde_repr.workspace = true
uuid.workspace = true
25 changes: 25 additions & 0 deletions ddm-types/versions/src/initial/admin.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// This Source Code Form is subject to the terms of the Mozilla Public
// 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 std::collections::{BTreeMap, HashSet};
use std::net::Ipv6Addr;

use schemars::JsonSchema;
use serde::{Deserialize, Serialize};
use uuid::Uuid;

use super::exchange::PathVector;

pub type PrefixMap = BTreeMap<Ipv6Addr, HashSet<PathVector>>;

#[derive(Debug, Clone, Deserialize, Serialize, JsonSchema)]
pub struct ExpirePathParams {
pub addr: Ipv6Addr,
}

#[derive(Clone, Debug, Serialize, Deserialize, JsonSchema, PartialEq)]
pub struct EnableStatsRequest {
pub sled_id: Uuid,
pub rack_id: Uuid,
}
Loading