Skip to main content

InteractiveNetwork

Trait InteractiveNetwork 

Source
pub trait InteractiveNetwork<P, Q, Ospf>
where P: Prefix, Q: EventQueue<P>, Ospf: OspfImpl,
{
Show 13 methods // Required methods fn auto_simulation(&mut self); fn manual_simulation(&mut self); fn auto_simulation_enabled(&self) -> bool; fn with_manual_simulation<F>(self, f: F) -> Self where F: FnOnce(&mut Self); fn simulate(&mut self) -> Result<(), NetworkError>; fn simulate_hooked( &mut self, f: impl FnMut(&Self, &Event<P, Q::Priority>, Option<&(StepUpdate<P>, Vec<Event<P, Q::Priority>>)>), ) -> Result<(), NetworkError>; fn trigger_timeout(&mut self) -> Result<Option<RouterId>, NetworkError>; fn trigger_timeout_at( &mut self, router: RouterId, ) -> Result<bool, NetworkError>; fn simulate_step( &mut self, ) -> Result<Option<(StepUpdate<P>, Event<P, Q::Priority>)>, NetworkError>; fn queue(&self) -> &Q; fn queue_mut(&mut self) -> &mut Q; unsafe fn trigger_event( &mut self, event: Event<P, Q::Priority>, ) -> Result<(StepUpdate<P>, Vec<Event<P, Q::Priority>>), NetworkError>; unsafe fn enqueue_event(&mut self, event: Event<P, Q::Priority>);
}
Expand description

Trait that allows you to interact with the simulator on a per message level. It exposes an interface to simulate a single event, inspect the queue of the network, and even reorder events.

Required Methods§

Source

fn auto_simulation(&mut self)

Setup the network to automatically simulate each change of the network. This is the default behavior. Disable auto-simulation by using InteractiveNetwork::manual_simulation.

Source

fn manual_simulation(&mut self)

Setup the network to not to automatically simulate each change of the network. Upon any change of the network (configuration change, external update of any routing input, or a link failure), the event queue will be filled with the initial message(s), but it will not execute them. Enable auto-simulation by using InteractiveNetwork::auto_simulation. Use either Network::simulate to run the entire queue after updating the messages, or use InteractiveNetwork::simulate_step to execute a single event on the queue.

Source

fn auto_simulation_enabled(&self) -> bool

Returns true if auto-simulation is enabled.

Source

fn with_manual_simulation<F>(self, f: F) -> Self
where F: FnOnce(&mut Self),

Calls the function f with argument to a mutable network. During this call, the network will have automatic simulation disabled. It will be re-enabled once the function exits.

Note, that this function takes ownership of self and returns it afterwards. This is to prohibit you to call with_manual_simulation multiple times.

Source

fn simulate(&mut self) -> Result<(), NetworkError>

Simulate the network behavior, given the current event queue. This function will execute all events (that may trigger new events), until either the event queue is empt (i.e., the network has converged), or until the maximum allowed events have been processed (which can be set by self.set_msg_limit).

Source

fn simulate_hooked( &mut self, f: impl FnMut(&Self, &Event<P, Q::Priority>, Option<&(StepUpdate<P>, Vec<Event<P, Q::Priority>>)>), ) -> Result<(), NetworkError>

Similarly to the Network::simulate function, this function will execute all events in the queue. This function provides a hook in the form of a closure that is called before and after each event is processed.

The closure always provides immutable access to both the network and the currently processed event. In order to determine whether it was called before or after the event was popped from the queue and processed we need to look at the value of the third argument.

If the closure is called before the event is processed:

  • The third argument will be None
  • The event is still present in the network’s queue

If the closure is called after the event is processed:

  • The third argument will contain a Some((StepUpdate, Vec<Event>)) tuple, where the second element contains a list of events that were generated by the event that was just processed.
  • These events have not been enqueued yet
Source

fn trigger_timeout(&mut self) -> Result<Option<RouterId>, NetworkError>

Trigger the timeout event on any router. The router is picked randomly if the feature rand is enabled. The function returns the router on which the timeout was triggered, or None if no router is waiting for a timeout event.

After calling this function, the queue might contain new events. Run net.simulate() to execute them.

Timeout might cause OSPF events to be generated at internal routers.

Source

fn trigger_timeout_at(&mut self, router: RouterId) -> Result<bool, NetworkError>

Trigger the timeout event on router. If the router is not waiting for a timeout event, the function returns Ok(false). Otherwise, the timeout is triggered, and Ok(true) is returned.

After calling this function, the queue might contain new events. Run net.simulate() to execute them.

Timeout might cause OSPF events to be generated at internal routers.

Source

fn simulate_step( &mut self, ) -> Result<Option<(StepUpdate<P>, Event<P, Q::Priority>)>, NetworkError>

Simulate the next event on the queue. In comparison to Network::simulate, this function will not execute any subsequent event. This function returns the change in forwarding behavior caused by this step, as well as the event that was processed. If this function returns Ok(None), then no event was enqueued.

Source

fn queue(&self) -> &Q

Get a reference to the queue

Source

fn queue_mut(&mut self) -> &mut Q

Get a reference to the queue

Source

unsafe fn trigger_event( &mut self, event: Event<P, Q::Priority>, ) -> Result<(StepUpdate<P>, Vec<Event<P, Q::Priority>>), NetworkError>

Manually trigger the given event, returning the result of that event. No new events will be enqueued.

§Safety

The network will be in an inconsistent state. Make sure to deal with that properly.

Source

unsafe fn enqueue_event(&mut self, event: Event<P, Q::Priority>)

Manually enqueue a specific event. The event will be executed automatically if the network is the automatic simulation state.

§Safety

The network will be in an inconsistent state. Make sure to deal with that properly.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§

Source§

impl<P: Prefix, Q: EventQueue<P>, Ospf: OspfImpl> InteractiveNetwork<P, Q, Ospf> for Network<P, Q, Ospf>