pub struct Packet { /* private fields */ }
Expand description
Holds networking information and payload data that assists in sending managed-process bytes between different sockets and hosts over the simulation network.
The Packet
is designed to separate the IP layer header from the transport layer data, to make
it easier to support new transport protocols in the future. Thus, the Packet
has a Header
to
store IP header information, and a Data
to store transport-specific data (e.g., A TCP header
and payload for TCP, or a UDP header and payload for UDP).
The Packet
is designed to be read-only after creation to simplify implementation and to reduce
the need for mutable borrows.
§Deprecation
As an exception to the read-only design, some legacy TCP data is mutable to support the legacy C
TCP stack. When the legacy TCP stack and the Packet
’s C interface is removed, mutability will
also be removed.
Implementations§
Source§impl Packet
impl Packet
Sourcepub fn new_ipv4_tcp(
header: TcpHeader,
payload: Payload,
priority: FifoPacketPriority,
) -> Self
pub fn new_ipv4_tcp( header: TcpHeader, payload: Payload, priority: FifoPacketPriority, ) -> Self
Creates a new IPv4 TCP packet using the provided data.
Sourcepub fn new_ipv4_udp(
src: SocketAddrV4,
dst: SocketAddrV4,
payload: Bytes,
priority: FifoPacketPriority,
) -> Self
pub fn new_ipv4_udp( src: SocketAddrV4, dst: SocketAddrV4, payload: Bytes, priority: FifoPacketPriority, ) -> Self
Creates a new IPv4 UDP packet using the provided data.
Sourcepub fn ipv4_tcp_header(&self) -> Option<TcpHeader>
pub fn ipv4_tcp_header(&self) -> Option<TcpHeader>
If the packet is an IPv4 TCP packet, returns a copy of the TCP header in a format defined by
the Rust TCP stack. Otherwise, returns None
.
Panics
This function panics if the packet was created with packet_new_tcp()
in the legacy C API.
Sourcepub fn payload(&self) -> Vec<Bytes>
pub fn payload(&self) -> Vec<Bytes>
Returns the packet’s payload that was provided at packet creation time. This function
allocates a new Vec
, but is zero-copy with respect to the payload Bytes
.
This function may return a non-empty vector of zero-length Bytes
object(s) if zero-length
Bytes
object(s) were provided at creation time. Thus, it may be helpful to check if the
packet has useful payload using payload_len()
before calling this function.
Sourcepub fn len(&self) -> usize
pub fn len(&self) -> usize
Returns the total simulated length of the packet, which is the sum of the emulated IP and transport header lengths and the payload length.
Sourcepub fn payload_len(&self) -> usize
pub fn payload_len(&self) -> usize
Returns the total number of payload bytes stored in the packet, which excludes IP and transport header lengths.
Sourcepub fn add_status(&self, status: PacketStatus)
pub fn add_status(&self, status: PacketStatus)
Appends the provided packet status to the list of the packet’s status checkpoints.
This function has no effect unless log::Level::Trace
is enabled.
Sourcepub fn src_ipv4_address(&self) -> SocketAddrV4
pub fn src_ipv4_address(&self) -> SocketAddrV4
Returns the packet’s IPv4 source address and source port.
Panics
This function panics if the source address is not an IPv4 address.
Sourcepub fn dst_ipv4_address(&self) -> SocketAddrV4
pub fn dst_ipv4_address(&self) -> SocketAddrV4
Returns the packet’s IPv4 destination address and destination port.
Panics
This function panics if the destination address is not an IPv4 address.
Sourcepub fn priority(&self) -> FifoPacketPriority
pub fn priority(&self) -> FifoPacketPriority
Returns the priority set at packet creation time.
Sourcepub fn iana_protocol(&self) -> IanaProtocol
pub fn iana_protocol(&self) -> IanaProtocol
Returns the packet’s iana-assigned protocol type.
Trait Implementations§
Source§impl PacketDisplay for Packet
impl PacketDisplay for Packet
Auto Trait Implementations§
impl !Freeze for Packet
impl !RefUnwindSafe for Packet
impl Send for Packet
impl Sync for Packet
impl Unpin for Packet
impl UnwindSafe for Packet
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more