Skip to content

Commit 8a49211

Browse files
committed
add request/response sequence numbers
as per [this comment][1] from @jgallagher. this is similar to the control-plane-agent protocol. wow, it's almost like we're reimplementing TCP (but without flow control because thats hard). [1]: #370 (comment)
1 parent dec98f3 commit 8a49211

File tree

2 files changed

+205
-88
lines changed

2 files changed

+205
-88
lines changed

gateway-messages/src/ereport.rs

+51-19
Original file line numberDiff line numberDiff line change
@@ -82,29 +82,54 @@ pub enum EreportRequest {
8282
// `version_byte_values` test below!
8383
}
8484

85+
/// An ereport request ID (sequence number)
86+
///
87+
/// This is an arbitrary 8-bit value sent in the request packet. The SP is
88+
/// expected to include this value in the header for the response packet.
89+
#[derive(
90+
Clone,
91+
Copy,
92+
Debug,
93+
PartialEq,
94+
Eq,
95+
Ord,
96+
PartialOrd,
97+
Serialize,
98+
Deserialize,
99+
SerializedSize,
100+
)]
101+
#[repr(transparent)]
102+
pub struct RequestIdV0(pub u8);
103+
104+
impl RequestIdV0 {
105+
pub fn increment(&mut self) {
106+
self.0 = self.0.wrapping_add(1);
107+
}
108+
}
109+
85110
/// A request for ereports aggregated by the SP's snitch task, version 0.
86111
///
87112
/// ```text
88113
/// 0 1 2 3
89114
/// +--------+--------+--------+--------+
90-
/// | version|-------C| limit | |
91-
/// +--------+--------+--------+ |
115+
/// | version|-------C| limit | req ID |
116+
/// +--------+--------+--------+--------+
92117
/// | |
93118
/// + +
94119
/// | |
95120
/// + restart ID (128 bits) +
96121
/// | |
97-
/// + +--------+
98-
/// | | |
99-
/// +--------+--------+--------+ +
122+
/// + +
123+
/// | |
124+
/// +--------+--------+--------+--------+
100125
/// | first ENA desired in response |
101-
/// + (64 bits) +--------+
102-
/// | | |
103-
/// +--------+--------+--------+ +
126+
/// + (64 bits) +
127+
/// | |
128+
/// +--------+--------+--------+--------+
104129
/// | last ENA written to database | only present when C bit set
105-
/// + (64 bits) +--------+
106-
/// | |
107-
/// +--------+--------+--------+
130+
/// + (64 bits) +
131+
/// | |
132+
/// +--------+--------+--------+--------+
108133
/// ```
109134
///
110135
/// See [RFD 545 §4.4.3.1] for details.
@@ -118,6 +143,10 @@ pub struct RequestV0 {
118143
/// Maximum number of ereports to include in the response packet.
119144
pub limit: u8,
120145

146+
/// Message ID of this request. The SP must include this value in the
147+
/// response header for the response to this request.
148+
pub request_id: RequestIdV0,
149+
121150
/// The restart ID of the SP's snitch task which the control plane believes
122151
/// is current.
123152
///
@@ -167,6 +196,7 @@ bitflags::bitflags! {
167196
impl RequestV0 {
168197
pub const fn new(
169198
restart_id: RestartId,
199+
request_id: RequestIdV0,
170200
start_ena: Ena,
171201
limit: u8,
172202
committed_ena: Option<Ena>,
@@ -175,7 +205,7 @@ impl RequestV0 {
175205
Some(ena) => (ena, RequestFlagsV0::COMMIT),
176206
None => (Ena(0), RequestFlagsV0::empty()),
177207
};
178-
Self { flags, limit, restart_id, start_ena, committed_ena }
208+
Self { flags, limit, request_id, restart_id, start_ena, committed_ena }
179209
}
180210

181211
/// Returns the "committed ENA" field if this packet contains one.
@@ -214,31 +244,31 @@ pub enum EreportResponseHeader {
214244
/// ```text
215245
/// 0 1 2 3
216246
/// +--------+--------+--------+--------+
217-
/// | version| |
218-
/// +--------+ +
247+
/// | version| req ID | |
248+
/// +--------+--------+ +
219249
/// | |
220250
/// + +
221251
/// | restart ID (128 bits) |
222252
/// + +
223253
/// | |
224-
/// + +--------+
225-
/// | | 0xBF | beginning of CBOR metadata map
254+
/// + +--------+--------+
255+
/// | | 0xBF | beginning of CBOR metadata map
226256
/// +--------+--------+--------+--------+
227257
/// ... metadata k/v pairs ... | 0xFF | metadata-only packets may end here
228258
/// +--------+--------+--------+--------+
229259
/// | start ENA (64 bits) |
230260
/// +--------+--------+--------+--------+
231-
/// | 0x9F | ... ereports ...
261+
/// | 0x9F | ... ereports ...| 0xFF |
232262
/// +--------+ +--------+
233-
/// ... ereports ... | 0xFF |
234-
/// +--------+
235263
/// ```
236264
/// See [RFD 545 §4.4.4] for details.
237265
/// [RFD 545 §4.4.4]: https://rfd.shared.oxide.computer/rfd/0545#_readresponse
238266
#[derive(
239267
Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize, SerializedSize,
240268
)]
241269
pub struct ResponseHeaderV0 {
270+
/// The request ID of the request that this message is a response to.
271+
pub request_id: RequestIdV0,
242272
/// The reporter restart ID of the SP's snitch task when this response was
243273
/// produced.
244274
pub restart_id: RestartId,
@@ -276,6 +306,7 @@ mod tests {
276306
&mut buf,
277307
&EreportRequest::V0(RequestV0::new(
278308
RestartId(1),
309+
RequestIdV0(1),
279310
Ena(2),
280311
3,
281312
Some(Ena(4)),
@@ -288,6 +319,7 @@ mod tests {
288319
&mut buf,
289320
&EreportResponseHeader::V0(ResponseHeaderV0 {
290321
restart_id: RestartId(1),
322+
request_id: RequestIdV0(1),
291323
}),
292324
);
293325
assert_eq!(bytes[0], 0, "ResponseHeader v0 version byte should be 0");

0 commit comments

Comments
 (0)