pub struct NetworkEngine { /* private fields */ }Expand description
The guest-visible network state of one record or replay run.
Implementations§
Source§impl NetworkEngine
impl NetworkEngine
Sourcepub fn new_record(epoch: DateTime<Utc>) -> Self
pub fn new_record(epoch: DateTime<Utc>) -> Self
Start recording; epoch is the run’s configured epoch.
Sourcepub fn new_replay(trace: NetworkTraceV2) -> Self
pub fn new_replay(trace: NetworkTraceV2) -> Self
Replay trace, which must already have passed validation.
pub fn is_record(&self) -> bool
Sourcepub fn is_channel(&self, id: OpenFileId) -> bool
pub fn is_channel(&self, id: OpenFileId) -> bool
Whether the guest connected id as a network channel.
Sourcepub fn record_connect(
&mut self,
id: OpenFileId,
peer: NetworkAddressV1,
local: Option<NetworkAddressV1>,
errno: i32,
nonblocking: bool,
) -> Result<i32, NetworkEngineError>
pub fn record_connect( &mut self, id: OpenFileId, peer: NetworkAddressV1, local: Option<NetworkAddressV1>, errno: i32, nonblocking: bool, ) -> Result<i32, NetworkEngineError>
Record a connect the runtime performed on the host. errno is 0 on
success, and local is the host-assigned local address.
Sourcepub fn replay_connect(
&mut self,
id: OpenFileId,
peer: &NetworkAddressV1,
nonblocking: bool,
) -> Result<i32, NetworkEngineError>
pub fn replay_connect( &mut self, id: OpenFileId, peer: &NetworkAddressV1, nonblocking: bool, ) -> Result<i32, NetworkEngineError>
Replay the recorded connect of id, which must target the recorded peer.
Sourcepub fn addresses(
&self,
id: OpenFileId,
) -> Option<(Option<&NetworkAddressV1>, &NetworkAddressV1)>
pub fn addresses( &self, id: OpenFileId, ) -> Option<(Option<&NetworkAddressV1>, &NetworkAddressV1)>
The local and peer addresses of a connected channel, for
getsockname and getpeername.
Sourcepub fn needs_pull(&self, id: OpenFileId) -> bool
pub fn needs_pull(&self, id: OpenFileId) -> bool
Whether the recorder should pull more input for id from the host.
Sourcepub fn record_arrival(
&mut self,
id: OpenFileId,
now: LogicalTime,
arrival: NetworkArrival,
) -> Result<(), NetworkEngineError>
pub fn record_arrival( &mut self, id: OpenFileId, now: LogicalTime, arrival: NetworkArrival, ) -> Result<(), NetworkEngineError>
Record what the runtime pulled from the host for id at global time
now, and make it visible to the guest at once.
Sourcepub fn recv(
&mut self,
id: OpenFileId,
now: LogicalTime,
max_len: usize,
target: usize,
peek: bool,
) -> Result<NetworkRecvOutcome, NetworkEngineError>
pub fn recv( &mut self, id: OpenFileId, now: LogicalTime, max_len: usize, target: usize, peek: bool, ) -> Result<NetworkRecvOutcome, NetworkEngineError>
A guest receive of at most max_len bytes at global time now.
target is the byte count that completes a blocking receive:
min(SO_RCVLOWAT, max_len), or max_len under MSG_WAITALL. A
nonblocking receive, or one whose timeout expired, passes 1. With
peek the bytes stay queued.
Sourcepub fn readiness(
&mut self,
id: OpenFileId,
now: LogicalTime,
lowat: usize,
) -> Result<i16, NetworkEngineError>
pub fn readiness( &mut self, id: OpenFileId, now: LogicalTime, lowat: usize, ) -> Result<i16, NetworkEngineError>
The poll events id reports at global time now, before masking
with the requested events. Mirrors Linux tcp_poll; lowat is the
socket’s SO_RCVLOWAT, which the guest may set before it connects.
Sourcepub fn take_error(
&mut self,
id: OpenFileId,
now: LogicalTime,
) -> Result<i32, NetworkEngineError>
pub fn take_error( &mut self, id: OpenFileId, now: LogicalTime, ) -> Result<i32, NetworkEngineError>
Consume and return the pending socket error at global time now, as
SO_ERROR does; 0 when there is none. Inputs due by now are
released first, so the first observer of a recorded error sees it
whichever operation it uses.
Sourcepub fn send_failure(
&mut self,
id: OpenFileId,
now: LogicalTime,
) -> Result<Option<i32>, NetworkEngineError>
pub fn send_failure( &mut self, id: OpenFileId, now: LogicalTime, ) -> Result<Option<i32>, NetworkEngineError>
The errno a guest send at global time now fails with before
transmitting anything, or None when the send may proceed. Inputs due
by now are released first. A pending error is consumed first;
otherwise a socket shut down for writing fails with EPIPE.
Sourcepub fn record_send(
&mut self,
id: OpenFileId,
sent: &[u8],
at: Option<SendMark>,
now: LogicalTime,
waits: u64,
) -> Result<SendMark, NetworkEngineError>
pub fn record_send( &mut self, id: OpenFileId, sent: &[u8], at: Option<SendMark>, now: LogicalTime, waits: u64, ) -> Result<SendMark, NetworkEngineError>
Record the bytes a host send accepted at now and return where they
left the stream. Empty sent records nothing and returns the current
mark, which a blocking send takes before its first wait. at is the
mark of a send that then waited for buffer space; any output event on
the channel in the meantime, accepted or refused, is refused, because
replay would order the two the other way. waits counts the send’s
waits since it started or since its previous accepted chunk; when it
is nonzero the fragment records that count and now, so that replay
accepts it only after waiting as long.
Sourcepub fn record_refused_send(
&mut self,
id: OpenFileId,
) -> Result<(), NetworkEngineError>
pub fn record_refused_send( &mut self, id: OpenFileId, ) -> Result<(), NetworkEngineError>
Record a nonblocking send that the host refused with EAGAIN, as an
empty fragment at the current stream offset.
Sourcepub fn replay_send(
&mut self,
id: OpenFileId,
bytes: &[u8],
nonblocking: bool,
now: LogicalTime,
waits: u64,
) -> Result<ReplaySendOutcome, NetworkEngineError>
pub fn replay_send( &mut self, id: OpenFileId, bytes: &[u8], nonblocking: bool, now: LogicalTime, waits: u64, ) -> Result<ReplaySendOutcome, NetworkEngineError>
Match a guest send at now against the recording and return how
many bytes it transmits: the bytes left in the current recorded
fragment, at most bytes.len(). A recorded short write therefore
replays as the same short write. ReplaySendOutcome::WouldBlock is
a nonblocking send that the recording refused with EAGAIN; a
blocking send at that point diverged.
A fragment that the recording accepted only after its send waited is
due once this send has waited waits times as many and now has
reached the recorded acceptance time; before that the send gets
ReplaySendOutcome::NotYet and waits again. The check and the
consumption happen in this one call, so nothing can run between them.
Sourcepub fn shutdown(
&mut self,
id: OpenFileId,
how: i32,
) -> Result<i32, NetworkEngineError>
pub fn shutdown( &mut self, id: OpenFileId, how: i32, ) -> Result<i32, NetworkEngineError>
Apply shutdown(how); returns 0 or the errno the guest sees.
Sourcepub fn apply(
&mut self,
now: LogicalTime,
request: NetworkRequest,
) -> Result<NetworkReply, NetworkEngineError>
pub fn apply( &mut self, now: LogicalTime, request: NetworkRequest, ) -> Result<NetworkReply, NetworkEngineError>
Perform request at global time now.
Sourcepub fn finish_replay(self) -> Result<(), NetworkEngineError>
pub fn finish_replay(self) -> Result<(), NetworkEngineError>
End a replay: fail if the guest left part of the recording unused, by never connecting a recorded socket, by sending fewer bytes than the recording holds, or by never making a recorded refused send. Inputs the guest never read are not checked: when an input is released depends on the schedule, so a replay may end before a final input the recording happened to observe.
Sourcepub fn finish(self) -> Result<NetworkTraceV2, NetworkEngineError>
pub fn finish(self) -> Result<NetworkTraceV2, NetworkEngineError>
The trace of a record run. Fails if the run was a replay or the recording does not validate.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for NetworkEngine
impl RefUnwindSafe for NetworkEngine
impl Send for NetworkEngine
impl Sync for NetworkEngine
impl Unpin for NetworkEngine
impl UnsafeUnpin for NetworkEngine
impl UnwindSafe for NetworkEngine
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
§impl<T> Conv for T
impl<T> Conv for T
§impl<T> FmtForward for T
impl<T> FmtForward for T
§fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
self to use its Binary implementation when Debug-formatted.§fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
self to use its Display implementation when
Debug-formatted.§fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
self to use its LowerExp implementation when
Debug-formatted.§fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
self to use its LowerHex implementation when
Debug-formatted.§fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
self to use its Octal implementation when Debug-formatted.§fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
self to use its Pointer implementation when
Debug-formatted.§fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
self to use its UpperExp implementation when
Debug-formatted.§fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
self to use its UpperHex implementation when
Debug-formatted.§fn fmt_list(self) -> FmtList<Self>where
&'a Self: for<'a> IntoIterator,
fn fmt_list(self) -> FmtList<Self>where
&'a Self: for<'a> IntoIterator,
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
§impl<T> Pipe for Twhere
T: ?Sized,
impl<T> Pipe for Twhere
T: ?Sized,
§fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
§fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
self and passes that borrow into the pipe function. Read more§fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
self and passes that borrow into the pipe function. Read more§fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
§fn pipe_borrow_mut<'a, B, R>(
&'a mut self,
func: impl FnOnce(&'a mut B) -> R,
) -> R
fn pipe_borrow_mut<'a, B, R>( &'a mut self, func: impl FnOnce(&'a mut B) -> R, ) -> R
§fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
self, then passes self.as_ref() into the pipe function.§fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
self, then passes self.as_mut() into the pipe
function.§fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
self, then passes self.deref() into the pipe function.§impl<T> Tap for T
impl<T> Tap for T
§fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
Borrow<B> of a value. Read more§fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
BorrowMut<B> of a value. Read more§fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
AsRef<R> view of a value. Read more§fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
AsMut<R> view of a value. Read more§fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
Deref::Target of a value. Read more§fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
Deref::Target of a value. Read more§fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
.tap() only in debug builds, and is erased in release builds.§fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
.tap_mut() only in debug builds, and is erased in release
builds.§fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
.tap_borrow() only in debug builds, and is erased in release
builds.§fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
.tap_borrow_mut() only in debug builds, and is erased in release
builds.§fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
.tap_ref() only in debug builds, and is erased in release
builds.§fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
.tap_ref_mut() only in debug builds, and is erased in release
builds.§fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
.tap_deref() only in debug builds, and is erased in release
builds.