Skip to content

Commit

Permalink
Add trigger_event functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
tiborschneider committed Nov 20, 2024
1 parent 06fb416 commit cf0ddf8
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 1 deletion.
2 changes: 1 addition & 1 deletion bgpsim/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "bgpsim"
version = "0.17.8"
version = "0.17.9"
edition = "2021"
license-file = "LICENSE"
description = "A network control-plane simulator"
Expand Down
41 changes: 41 additions & 0 deletions bgpsim/src/interactive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,24 @@ where

/// Get a reference to the queue
fn queue_mut(&mut self) -> &mut Q;

/// 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.
#[allow(clippy::type_complexity)]
unsafe fn trigger_event(
&mut self,
event: Event<P, Q::Priority>,
) -> Result<(StepUpdate<P>, Vec<Event<P, Q::Priority>>), NetworkError>;

/// 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.
unsafe fn enqueue_event(&mut self, event: Event<P, Q::Priority>);
}

impl<P: Prefix, Q: EventQueue<P>, Ospf: OspfImpl> InteractiveNetwork<P, Q, Ospf>
Expand Down Expand Up @@ -233,6 +251,29 @@ impl<P: Prefix, Q: EventQueue<P>, Ospf: OspfImpl> InteractiveNetwork<P, Q, Ospf>
Ok(false)
}
}

unsafe fn trigger_event(
&mut self,
event: Event<P, Q::Priority>,
) -> Result<(StepUpdate<P>, Vec<Event<P, Q::Priority>>), NetworkError> {
// log the job
log::trace!("{}", event.fmt(self));
// execute the event
let (step_update, events) = match self
.routers
.get_mut(&event.router())
.ok_or(NetworkError::DeviceNotFound(event.router()))?
{
NetworkDevice::InternalRouter(r) => r.handle_event(event.clone()),
NetworkDevice::ExternalRouter(r) => r.handle_event(event.clone()),
}?;

Ok((step_update, events))
}

unsafe fn enqueue_event(&mut self, event: Event<P, Q::Priority>) {
self.enqueue_events(vec![event]);
}
}

/// Builder interface to partially clone the source network while moving values from the conquered
Expand Down

0 comments on commit cf0ddf8

Please sign in to comment.