use scion_proto::{address::IsdAsn, packet::ScionPacketRaw};
use snap_dataplane::dispatcher::Dispatcher;
use crate::{
network::{scion::routing::ScionNetworkTime, simulator::NetworkSimulator},
state::SharedPocketScionState,
};
pub(crate) struct AsNetSimDispatcher {
local_as: IsdAsn,
app_state: SharedPocketScionState,
}
impl AsNetSimDispatcher {
pub(crate) fn new(local_as: IsdAsn, app_state: SharedPocketScionState) -> Self {
Self {
local_as,
app_state,
}
}
}
impl Dispatcher for AsNetSimDispatcher {
fn try_dispatch(&self, packet: ScionPacketRaw) {
let network_time = ScionNetworkTime::now();
let state_guard = self.app_state.system_state.read().unwrap();
NetworkSimulator::new(&state_guard.sim_receivers, state_guard.topology.as_ref()).dispatch(
self.local_as,
network_time,
packet,
);
}
}
pub(crate) struct NetSimDispatcher {
app_state: SharedPocketScionState,
}
impl NetSimDispatcher {
pub(crate) fn new(app_state: SharedPocketScionState) -> Self {
Self { app_state }
}
}
impl Dispatcher for NetSimDispatcher {
fn try_dispatch(&self, packet: ScionPacketRaw) {
let network_time = ScionNetworkTime::now();
let state_guard = self.app_state.system_state.read().unwrap();
NetworkSimulator::new(&state_guard.sim_receivers, state_guard.topology.as_ref()).dispatch(
packet.headers.address.ia.source,
network_time,
packet,
);
}
}