Skip to content

Commit b1ed9ad

Browse files
authored
consolidate ddm protocol types into a dedicated crate (#770)
The frozen DDMv2 protocol types (UpdateV2, PullResponseV2, UnderlayUpdateV2, TunnelUpdateV2, PathVectorV2, TunnelOriginV2, IpPrefix, Ipv4Prefix, Ipv6Prefix) were scattered across ddm-api-types, mg-common, and ddm/src/exchange/mod.rs. Collect them all into a single dedicated module with a module-level comment making the freeze guarantee impossible to miss. Add an expectorate snapshot test over the JSON schema for the two top-level message types (UpdateV2, PullResponseV2) so that any accidental change to the frozen wire format fails loudly. Also remove the DDMv1 conversion helpers (UpdateV1 and its From impls) that are no longer needed.
1 parent 6542c37 commit b1ed9ad

21 files changed

Lines changed: 1035 additions & 508 deletions

File tree

Cargo.lock

Lines changed: 13 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ default-members = [
99
"ddm-api",
1010
"ddm-api-types",
1111
"ddm-api-types/versions",
12+
"ddm-protocol",
1213
"dropshot-apis",
1314
"bfd",
1415
"util",
@@ -38,6 +39,7 @@ members = [
3839
"ddm-api",
3940
"ddm-api-types",
4041
"ddm-api-types/versions",
42+
"ddm-protocol",
4143
"dropshot-apis",
4244
"bfd",
4345
"package",
@@ -72,6 +74,7 @@ rdb = { path = "rdb", features = ["clap"] }
7274
ddm-api = { path = "ddm-api" }
7375
ddm-api-types = { path = "ddm-api-types" }
7476
ddm-api-types-versions = { path = "ddm-api-types/versions" }
77+
ddm-protocol = { path = "ddm-protocol" }
7578

7679
# External
7780
slog = { version = "2.8.2", features = ["max_level_trace", "release_max_level_debug"] }
@@ -87,7 +90,8 @@ thiserror = "2.0"
8790
dropshot = { version = "0.17.0", features = [ "usdt-probes" ] }
8891
dropshot-api-manager = "0.7.2"
8992
dropshot-api-manager-types = "0.7.2"
90-
schemars = { version = "0.8", features = [ "uuid1", "chrono" ] }
93+
expectorate = "1.2.0"
94+
schemars = { version = "0.8.22", features = [ "uuid1", "chrono" ] }
9195
tokio = { version = "1.49", features = ["full"] }
9296
serde_repr = "0.1"
9397
anyhow = "1.0.102"

ddm-api-types/versions/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,4 @@ schemars.workspace = true
99
serde.workspace = true
1010
serde_repr.workspace = true
1111
uuid.workspace = true
12+
ddm-protocol.workspace = true

ddm-api-types/versions/src/initial/exchange.rs

Lines changed: 1 addition & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -2,50 +2,4 @@
22
// License, v. 2.0. If a copy of the MPL was not distributed with this
33
// file, You can obtain one at https://mozilla.org/MPL/2.0/.
44

5-
use crate::v1::net::Ipv6Prefix;
6-
use oxnet::Ipv6Net;
7-
use schemars::JsonSchema;
8-
use serde::{Deserialize, Serialize};
9-
10-
#[derive(
11-
Debug, Clone, PartialEq, Eq, Hash, Deserialize, Serialize, JsonSchema,
12-
)]
13-
pub struct PathVector {
14-
pub destination: Ipv6Net,
15-
pub path: Vec<String>,
16-
}
17-
18-
/// THIS TYPE IS FOR DDM PROTOCOL VERSION 2. IT SHALL NEVER CHANGE. THIS TYPE
19-
/// CAN BE REMOVED WHEN DDMV2 CLIENTS AND SERVERS NO LONGER EXIST BUT ITS
20-
/// DEFINITION SHALL NEVER CHANGE.
21-
#[derive(
22-
Debug, Clone, PartialEq, Eq, Hash, Deserialize, Serialize, JsonSchema,
23-
)]
24-
pub struct PathVectorV2 {
25-
pub destination: Ipv6Prefix,
26-
pub path: Vec<String>,
27-
}
28-
29-
impl From<PathVectorV2> for PathVector {
30-
fn from(value: PathVectorV2) -> Self {
31-
PathVector {
32-
destination: Ipv6Net::new_unchecked(
33-
value.destination.addr,
34-
value.destination.len,
35-
),
36-
path: value.path,
37-
}
38-
}
39-
}
40-
41-
impl From<PathVector> for PathVectorV2 {
42-
fn from(value: PathVector) -> Self {
43-
PathVectorV2 {
44-
destination: Ipv6Prefix {
45-
addr: value.destination.addr(),
46-
len: value.destination.width(),
47-
},
48-
path: value.path,
49-
}
50-
}
51-
}
5+
pub use ddm_protocol::v3::PathVector;

ddm-api-types/versions/src/initial/net.rs

Lines changed: 1 addition & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -2,42 +2,4 @@
22
// License, v. 2.0. If a copy of the MPL was not distributed with this
33
// file, You can obtain one at https://mozilla.org/MPL/2.0/.
44

5-
use oxnet::IpNet;
6-
use schemars::JsonSchema;
7-
use serde::{Deserialize, Serialize};
8-
use std::net::{Ipv4Addr, Ipv6Addr};
9-
10-
#[derive(
11-
Debug, Copy, Clone, PartialEq, Eq, Hash, Serialize, Deserialize, JsonSchema,
12-
)]
13-
pub struct TunnelOrigin {
14-
pub overlay_prefix: IpNet,
15-
pub boundary_addr: Ipv6Addr,
16-
pub vni: u32,
17-
#[serde(default)]
18-
pub metric: u64,
19-
}
20-
21-
#[derive(
22-
Debug, Copy, Clone, PartialEq, Eq, Hash, Serialize, Deserialize, JsonSchema,
23-
)]
24-
pub struct Ipv6Prefix {
25-
pub addr: Ipv6Addr,
26-
pub len: u8,
27-
}
28-
29-
#[derive(
30-
Debug, Copy, Clone, PartialEq, Eq, Hash, Serialize, Deserialize, JsonSchema,
31-
)]
32-
pub struct Ipv4Prefix {
33-
pub addr: Ipv4Addr,
34-
pub len: u8,
35-
}
36-
37-
#[derive(
38-
Debug, Copy, Clone, PartialEq, Eq, Hash, Serialize, Deserialize, JsonSchema,
39-
)]
40-
pub enum IpPrefix {
41-
V4(Ipv4Prefix),
42-
V6(Ipv6Prefix),
43-
}
5+
pub use ddm_protocol::v3::TunnelOrigin;

ddm-api-types/versions/src/latest.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,8 @@ pub mod db {
2020

2121
pub mod exchange {
2222
pub use crate::v1::exchange::PathVector;
23-
pub use crate::v1::exchange::PathVectorV2;
2423
}
2524

2625
pub mod net {
27-
pub use crate::v1::net::IpPrefix;
28-
pub use crate::v1::net::Ipv4Prefix;
29-
pub use crate::v1::net::Ipv6Prefix;
3026
pub use crate::v1::net::TunnelOrigin;
3127
}

ddm-protocol/Cargo.toml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
[package]
2+
name = "ddm-protocol"
3+
version = "0.1.0"
4+
edition = "2024"
5+
6+
[dependencies]
7+
oxnet.workspace = true
8+
schemars.workspace = true
9+
serde.workspace = true
10+
11+
[dev-dependencies]
12+
expectorate.workspace = true
13+
serde_json.workspace = true

0 commit comments

Comments
 (0)