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: GraphThe graph topology this network is running on.
Implementations§
Source§impl Net
impl Net
Sourcepub fn new(graph: Graph) -> Self
pub fn new(graph: Graph) -> Self
Creates a new Net from a Graph.
Initializes packet location tracking for all edges and input ports.
Sourcepub fn do_action(&mut self, action: &NetAction) -> NetActionResponse
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"),
}Sourcepub fn packet_count_at(&self, location: &PacketLocation) -> usize
pub fn packet_count_at(&self, location: &PacketLocation) -> usize
Get the number of packets at a given location.
Sourcepub fn get_packets_at_location(
&self,
location: &PacketLocation,
) -> Vec<PacketID> ⓘ
pub fn get_packets_at_location( &self, location: &PacketLocation, ) -> Vec<PacketID> ⓘ
Get all packets at a given location.
Sourcepub fn get_startable_epochs(&self) -> Vec<EpochID> ⓘ
pub fn get_startable_epochs(&self) -> Vec<EpochID> ⓘ
Get all startable epoch IDs.
Sourcepub fn get_packet(&self, packet_id: &PacketID) -> Option<&Packet>
pub fn get_packet(&self, packet_id: &PacketID) -> Option<&Packet>
Get a packet by ID.
Trait Implementations§
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> 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
Mutably borrows from an owned value. Read more