Skip to content

Commit 8f39f04

Browse files
committed
Changes to the interactive queue and geotiming queue
1 parent 38a030f commit 8f39f04

File tree

4 files changed

+38
-14
lines changed

4 files changed

+38
-14
lines changed

bgpsim/src/event/rand_queue.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ impl<P: Prefix> PartialEq for SimpleTimingModel<P> {
167167
}
168168
}
169169

170-
/// Timing model based on geological information. This timing model uses seconds as time unit.
170+
/// Timing model based on geographical information. This timing model uses seconds as time unit.
171171
///
172172
/// The delay of a message from `a` to `b` is computed as follows: First, we compute the message's
173173
/// path through the network (based on the current IGP table). For each traversed link, we add the
@@ -315,7 +315,9 @@ impl<P: Prefix> GeoTimingModel<P> {
315315

316316
/// Set the distance between two nodes in light seconds
317317
pub fn set_distance(&mut self, src: RouterId, dst: RouterId, dist: f64) {
318-
let dist = NotNan::new(dist).unwrap();
318+
let mut dist = NotNan::new(dist).unwrap();
319+
// dist is in light seconds (c [m/s] * [s]), need to normalize for the speed of light
320+
dist /= GEO_TIMING_MODEL_F_LIGHT_SPEED;
319321
self.distances.insert((src, dst), dist);
320322
self.distances.insert((dst, src), dist);
321323
}
@@ -443,6 +445,9 @@ impl<P: Prefix> EventQueue<P> for GeoTimingModel<P> {
443445
} => {
444446
// compute the next time
445447
let key = (src, dst);
448+
// add any existing propagation delay introduced from external queues
449+
// TODO: check that putting this here is correct (I think that normally this is always 0 and not really used)
450+
next_time += *t;
446451
// compute the propagation time
447452
next_time += self.propagation_time(src, dst, &mut rng);
448453
// compute the processing time
@@ -540,6 +545,7 @@ impl<P: Prefix> EventQueue<P> for GeoTimingModel<P> {
540545
);
541546
}
542547
}
548+
// TODO: add external routers to this
543549
}
544550

545551
unsafe fn clone_events(&self, conquered: Self) -> Self {

bgpsim/src/formatter.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ use itertools::{join, Itertools};
2121

2222
use crate::{
2323
bgp::{BgpEvent, BgpRibEntry, BgpRoute},
24+
builder::GaoRexfordPeerType,
2425
config::{Config, ConfigExpr, ConfigExprKey, ConfigModifier, ConfigPatch, RouteMapEdit},
2526
event::{BasicEventQueue, Event, FmtPriority},
2627
forwarding_state::{ForwardingState, TO_DST},
@@ -1143,6 +1144,20 @@ impl<'n, P: Prefix, Q, Ospf: OspfImpl<Process = LocalOspfProcess>> NetworkFormat
11431144
}
11441145
}
11451146

1147+
//
1148+
// Gao-Rexford
1149+
//
1150+
impl<'n, P: Prefix, Q, Ospf: OspfImpl> NetworkFormatter<'n, P, Q, Ospf> for GaoRexfordPeerType {
1151+
fn fmt(&self, _: &'n Network<P, Q, Ospf>) -> String {
1152+
match self {
1153+
GaoRexfordPeerType::Peer => "Peer".to_string(),
1154+
GaoRexfordPeerType::Provider => "Provider".to_string(),
1155+
GaoRexfordPeerType::Customer => "Customer".to_string(),
1156+
GaoRexfordPeerType::Ignore => "Ignore".to_string(),
1157+
}
1158+
}
1159+
}
1160+
11461161
#[cfg(test)]
11471162
mod test {
11481163
use crate::prelude::*;

bgpsim/src/interactive.rs

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -79,12 +79,13 @@ where
7979
///
8080
/// If the closure is called *before* the event is processed:
8181
/// - The third argument will be `None`
82-
/// - The event is still present in the network's queue
82+
/// - The event is still present in the network's queue (and therefore unfiltered)
8383
///
8484
/// If the closure is called *after* the event is processed:
8585
/// - The third argument will contain a `Some((StepUpdate, Vec<Event>))` tuple, where the second element
8686
/// contains a list of events that were generated by the event that was just processed.
8787
/// - These events have not been enqueued yet
88+
/// - The second argument will be the popped (filtered) event
8889
fn simulate_hooked(
8990
&mut self,
9091
f: impl FnMut(
@@ -263,7 +264,7 @@ impl<P: Prefix, Q: EventQueue<P>, Ospf: OspfImpl> InteractiveNetwork<P, Q, Ospf>
263264
let mut remaining_iter = self.stop_after;
264265
'timeout: loop {
265266
// While there are events in the queue
266-
while let Some(event) = self.queue().peek() {
267+
'queue: while let Some(event) = self.queue().peek() {
267268
// Ensure the convergence limit is not overstepped
268269
if let Some(rem) = remaining_iter {
269270
if rem == 0 {
@@ -276,18 +277,20 @@ impl<P: Prefix, Q: EventQueue<P>, Ospf: OspfImpl> InteractiveNetwork<P, Q, Ospf>
276277
// Straddle the trigger_event function with the pre- and post-event hooks
277278
f(self, event, None);
278279
// Safety: This is safe because we trigger the next event in the queue and
279-
// we still push all resulting events to the queue. The extracted events are
280-
// all immutable and won't be modified.
281-
// Since the closure's reference to the network is immutable as well, this unwrap
282-
// is always safe
283-
let event = self.queue_mut().pop().unwrap();
284-
let event_clone = event.clone();
285-
let result = unsafe { self.trigger_event(event)? };
286-
f(self, &event_clone, Some(&result));
280+
// we still push all resulting events to the queue. The extracted events as well as the
281+
// reference to the network are all immutable in this closure and won't be modified.
282+
//
283+
// The check below however is still needed, because `EventQueue::peek()` is allowed
284+
// to return an event that is actually not returned by `EventQueue::pop()`
285+
let Some(popped_event) = self.queue_mut().pop() else {
286+
break 'queue;
287+
};
288+
let result = unsafe { self.trigger_event(popped_event.clone())? };
289+
f(self, &popped_event, Some(&result));
287290

288291
self.enqueue_events(result.1);
289292

290-
if matches!(event_clone, Event::Ospf { .. }) {
293+
if matches!(popped_event, Event::Ospf { .. }) {
291294
// OSPF event received! Check the BGP session state
292295
self.refresh_bgp_sessions()?;
293296
}

bgpsim/src/network.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ use std::collections::{HashMap, HashSet};
4141

4242
static DEFAULT_STOP_AFTER: usize = 1_000_000;
4343
/// The AS number assigned to internal routers.
44-
pub const INTERNAL_AS: AsId = AsId(65535);
44+
pub const INTERNAL_AS: AsId = AsId(10);
4545

4646
/// # Network struct
4747
/// The struct contains all information about the underlying physical network (Links), a manages

0 commit comments

Comments
 (0)