Struct Packet

Source
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

Source

pub fn new_ipv4_tcp( header: TcpHeader, payload: Payload, priority: FifoPacketPriority, ) -> Self

Creates a new IPv4 TCP packet using the provided data.

Source

pub fn new_ipv4_udp( src: SocketAddrV4, dst: SocketAddrV4, payload: Bytes, priority: FifoPacketPriority, ) -> Self

Creates a new IPv4 UDP packet using the provided data.

Source

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.

Source

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.

Source

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.

Source

pub fn payload_len(&self) -> usize

Returns the total number of payload bytes stored in the packet, which excludes IP and transport header lengths.

Source

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.

Source

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.

Source

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.

Source

pub fn priority(&self) -> FifoPacketPriority

Returns the priority set at packet creation time.

Source

pub fn iana_protocol(&self) -> IanaProtocol

Returns the packet’s iana-assigned protocol type.

Trait Implementations§

Source§

impl Clone for Packet

Source§

fn clone(&self) -> Packet

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Packet

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl From<Packet> for PacketRc

Source§

fn from(packet: Packet) -> Self

Converts to this type from the input type.
Source§

impl PacketDisplay for Packet

Source§

fn display_bytes(&self, writer: impl Write) -> Result<()>

Write the packet bytes.

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dst: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
Source§

impl<T> DynClone for T
where T: Clone,

Source§

fn __clone_box(&self, _: Private) -> *mut ()

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> NoTypeInference for T

Source§

type This = T

Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> Host for T
where T: Debug + Send,

Source§

impl<T> Host for T
where T: Debug + Send + 'static,

Source§

impl<T> Host for T
where T: Host + Host,