Skip to content

Commit 63e3178

Browse files
authored
[mg-admin] migrate to API trait (#546)
Part of oxidecomputer/omicron#8922.
1 parent 9fc074d commit 63e3178

File tree

12 files changed

+722
-298
lines changed

12 files changed

+722
-298
lines changed

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: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ default-members = [
1414
"tests",
1515
"rdb",
1616
"bgp",
17+
"mg-api",
1718
"mg-admin-client",
1819
"mgadm",
1920
"mgd",
@@ -35,6 +36,7 @@ members = [
3536
"mg-ddm-verify",
3637
"tests",
3738
"bgp",
39+
"mg-api",
3840
"mg-admin-client",
3941
"mgadm",
4042
"rdb",
@@ -85,6 +87,7 @@ http-body-util = "0.1"
8587
humantime = "2.1"
8688
rand = "0.8.5"
8789
backoff = "0.4"
90+
mg-api = { path = "mg-api" }
8891
mg-common = { path = "mg-common" }
8992
chrono = { version = "0.4.41", features = ["serde"] }
9093
oxide-tokio-rt = "0.1.2"

bgp/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ pub mod dispatcher;
1212
pub mod error;
1313
pub mod fanout;
1414
pub mod messages;
15+
pub mod params;
1516
pub mod policy;
1617
pub mod router;
1718
pub mod session;

mgd/src/bgp_param.rs renamed to bgp/src/params.rs

Lines changed: 14 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,12 @@
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 bgp::config::PeerConfig;
6-
use bgp::session::{FsmStateKind, MessageHistory};
5+
use crate::config::PeerConfig;
6+
use crate::session::FsmStateKind;
77
use rdb::{ImportExportPolicy, Path, PolicyAction, Prefix4};
88
use schemars::JsonSchema;
99
use serde::{Deserialize, Serialize};
1010
use std::collections::{BTreeSet, HashMap};
11-
use std::num::NonZeroU8;
1211
use std::time::Duration;
1312
use std::{
1413
collections::BTreeMap,
@@ -30,32 +29,13 @@ pub struct Router {
3029
pub graceful_shutdown: bool,
3130
}
3231

33-
#[derive(Debug, Deserialize, Serialize, JsonSchema)]
34-
pub struct DeleteRouterRequest {
35-
/// Autonomous system number for the router to remove
36-
pub asn: u32,
37-
}
38-
39-
#[derive(Debug, Deserialize, Serialize, JsonSchema, Clone)]
40-
pub struct NeighborSelector {
41-
pub asn: u32,
42-
pub addr: IpAddr,
43-
}
44-
4532
#[derive(Debug, Deserialize, Serialize, JsonSchema, Clone)]
4633
pub enum NeighborResetOp {
4734
Hard,
4835
SoftInbound,
4936
SoftOutbound,
5037
}
5138

52-
#[derive(Debug, Deserialize, Serialize, JsonSchema, Clone)]
53-
pub struct NeighborResetRequest {
54-
pub asn: u32,
55-
pub addr: IpAddr,
56-
pub op: NeighborResetOp,
57-
}
58-
5939
#[derive(Debug, Deserialize, Serialize, JsonSchema, Clone, PartialEq)]
6040
pub struct Neighbor {
6141
pub asn: u32,
@@ -154,12 +134,6 @@ impl Neighbor {
154134
}
155135
}
156136

157-
#[derive(Debug, Deserialize, Serialize, JsonSchema)]
158-
pub struct DeleteNeighborRequest {
159-
pub asn: u32,
160-
pub addr: IpAddr,
161-
}
162-
163137
#[derive(Debug, Deserialize, Serialize, JsonSchema)]
164138
pub struct AddExportPolicyRequest {
165139
/// ASN of the router to apply the export policy to.
@@ -196,12 +170,6 @@ pub struct Withdraw4Request {
196170
pub prefixes: Vec<Prefix4>,
197171
}
198172

199-
#[derive(Debug, Deserialize, Serialize, JsonSchema)]
200-
pub struct AsnSelector {
201-
/// ASN of the router to get imported prefixes from.
202-
pub asn: u32,
203-
}
204-
205173
#[derive(Debug, Deserialize, Serialize, JsonSchema)]
206174
pub struct GracefulShutdownRequest {
207175
/// ASN of the router to gracefully shut down.
@@ -216,18 +184,6 @@ pub struct GetOriginated4Request {
216184
pub asn: u32,
217185
}
218186

219-
#[derive(Debug, Deserialize, Serialize, JsonSchema)]
220-
pub struct BestpathFanoutRequest {
221-
/// Maximum number of equal-cost paths for ECMP forwarding
222-
pub fanout: NonZeroU8,
223-
}
224-
225-
#[derive(Debug, Deserialize, Serialize, JsonSchema)]
226-
pub struct BestpathFanoutResponse {
227-
/// Current maximum number of equal-cost paths for ECMP forwarding
228-
pub fanout: NonZeroU8,
229-
}
230-
231187
#[derive(Debug, Deserialize, Serialize, JsonSchema)]
232188
pub struct GetRoutersRequest {}
233189

@@ -263,6 +219,18 @@ pub struct PeerInfo {
263219
pub timers: PeerTimers,
264220
}
265221

222+
#[derive(Debug, Deserialize, Serialize, JsonSchema, Clone)]
223+
pub struct CheckerSource {
224+
pub asn: u32,
225+
pub code: String,
226+
}
227+
228+
#[derive(Debug, Deserialize, Serialize, JsonSchema, Clone)]
229+
pub struct ShaperSource {
230+
pub asn: u32,
231+
pub code: String,
232+
}
233+
266234
/// Apply changes to an ASN.
267235
#[derive(Debug, Deserialize, Serialize, JsonSchema, Clone)]
268236
pub struct ApplyRequest {
@@ -314,31 +282,9 @@ pub struct BgpPeerConfig {
314282
pub vlan_id: Option<u16>,
315283
}
316284

317-
#[derive(Debug, Deserialize, JsonSchema, Clone)]
318-
pub struct MessageHistoryRequest {
319-
pub asn: u32,
320-
}
321-
322-
#[derive(Debug, Serialize, JsonSchema, Clone)]
323-
pub struct MessageHistoryResponse {
324-
pub by_peer: HashMap<IpAddr, MessageHistory>,
325-
}
326-
327285
#[derive(Debug, Deserialize, Serialize, JsonSchema, Clone)]
328286
pub struct Rib(BTreeMap<String, BTreeSet<Path>>);
329287

330-
#[derive(Debug, Deserialize, Serialize, JsonSchema, Clone)]
331-
pub struct CheckerSource {
332-
pub asn: u32,
333-
pub code: String,
334-
}
335-
336-
#[derive(Debug, Deserialize, Serialize, JsonSchema, Clone)]
337-
pub struct ShaperSource {
338-
pub asn: u32,
339-
pub code: String,
340-
}
341-
342288
pub enum PolicySource {
343289
Checker(String),
344290
Shaper(String),

mg-api/Cargo.toml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
[package]
2+
name = "mg-api"
3+
version = "0.1.0"
4+
edition = "2024"
5+
6+
[dependencies]
7+
bfd = { path = "../bfd" }
8+
bgp = { path = "../bgp" }
9+
dropshot.workspace = true
10+
rdb = { path = "../rdb" }
11+
schemars.workspace = true
12+
serde.workspace = true

0 commit comments

Comments
 (0)