Net

Struct Net 

Source
pub struct Net {
    pub graph: Graph,
    /* private fields */
}
Expand description

The runtime state of a flow-based network.

A Net is created from a Graph and tracks:

  • All packets and their locations
  • All epochs and their states
  • Which epochs are startable

All mutations must go through Net::do_action to ensure proper event tracking.

Fields§

§graph: Graph

The graph topology this network is running on.

Implementations§

Source§

impl Net

Source

pub fn new(graph: Graph) -> Self

Creates a new Net from a Graph.

Initializes packet location tracking for all edges and input ports.

Source

pub fn do_action(&mut self, action: &NetAction) -> NetActionResponse

Perform an action on the network.

This is the primary way to mutate the network state. All actions produce a response containing either success data and events, or an error.

§Example
use netrun_sim::net::{Net, NetAction, NetActionResponse, NetActionResponseData};
use netrun_sim::graph::{Graph, Node, Port, PortSlotSpec};
use std::collections::HashMap;

let node = Node {
    name: "A".to_string(),
    in_ports: HashMap::new(),
    out_ports: HashMap::new(),
    in_salvo_conditions: HashMap::new(),
    out_salvo_conditions: HashMap::new(),
};
let graph = Graph::new(vec![node], vec![]);
let mut net = Net::new(graph);

// Create a packet outside the network
let response = net.do_action(&NetAction::CreatePacket(None));
match response {
    NetActionResponse::Success(NetActionResponseData::Packet(id), events) => {
        println!("Created packet {}", id);
    }
    _ => panic!("Expected success"),
}
Source

pub fn packet_count_at(&self, location: &PacketLocation) -> usize

Get the number of packets at a given location.

Source

pub fn get_packets_at_location( &self, location: &PacketLocation, ) -> Vec<PacketID>

Get all packets at a given location.

Source

pub fn get_epoch(&self, epoch_id: &EpochID) -> Option<&Epoch>

Get an epoch by ID.

Source

pub fn get_startable_epochs(&self) -> Vec<EpochID>

Get all startable epoch IDs.

Source

pub fn get_packet(&self, packet_id: &PacketID) -> Option<&Packet>

Get a packet by ID.

Trait Implementations§

Source§

impl Debug for Net

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl Freeze for Net

§

impl RefUnwindSafe for Net

§

impl Send for Net

§

impl Sync for Net

§

impl Unpin for Net

§

impl UnwindSafe for Net

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> 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, 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