Skip to content

Commit

Permalink
feat: use periodic process for router
Browse files Browse the repository at this point in the history
  • Loading branch information
dadada committed Jan 15, 2025
1 parent ac19a48 commit 204eb75
Show file tree
Hide file tree
Showing 10 changed files with 135 additions and 75 deletions.
3 changes: 3 additions & 0 deletions a653rs-router-linux/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ impl Partition<Hypervisor> for RouterPartition {
Name::from_str(NAME).unwrap(),
cfg.interfaces,
cfg.ports,
cfg.period,
cfg.time_capacity,
cfg.stack_size,
entry_point,
)
Expand Down Expand Up @@ -73,6 +75,7 @@ extern "C" fn entry_point() {
}
#[cfg(not(feature = "log"))]
let _res = res;
Hypervisor::periodic_wait().unwrap();
}
}

Expand Down
6 changes: 6 additions & 0 deletions a653rs-router-tests/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
pub mod test_data {
pub const CFG: &str = r##"
period:
secs: 1
nanos: 0
time_capacity:
secs: 0
nanos: 300000
stack_size: 10000
virtual_links:
1:
Expand Down
2 changes: 2 additions & 0 deletions a653rs-router-tests/tests/partition.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ impl Partition<DummyHypervisor> for RouterPartition {
Name::from_str(NAME).unwrap(),
cfg.interfaces,
cfg.ports,
cfg.period,
cfg.time_capacity,
cfg.stack_size,
entry_point,
)
Expand Down
2 changes: 2 additions & 0 deletions a653rs-router-zynq7000/src/partition.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ impl Partition<XngHypervisor> for RouterPartition {
Name::from_str(NAME).unwrap(),
cfg.interfaces,
cfg.ports,
cfg.period,
cfg.time_capacity,
cfg.stack_size,
entry_point,
)
Expand Down
156 changes: 86 additions & 70 deletions a653rs-router/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,12 @@ pub struct RouterConfig<const IN: usize, const OUT: usize, const IFS: usize, con
/// Stack size limit
pub stack_size: StackSize,

/// Period for running the router process.
pub period: Duration,

/// Maximum duration for which the router process may execute.
pub time_capacity: Duration,

/// Forwarding table
#[cfg_attr(feature = "serde", serde(default))]
pub virtual_links: VirtualLinksConfig<IN, OUT>,
Expand Down Expand Up @@ -209,22 +215,28 @@ impl PortConfig {
impl<const IN: usize, const OUT: usize, const IFS: usize, const PORTS: usize>
RouterConfig<IN, OUT, IFS, PORTS>
{
fn new(stack_size: usize) -> Self {
fn new(stack_size: usize, period: Duration, time_capacity: Duration) -> Self {
Self {
stack_size: stack_size as u32,
time_capacity,
period,
virtual_links: Default::default(),
interfaces: Default::default(),
ports: Default::default(),
}
}

/// Creates a new builder for a configuration.
pub fn builder(stack_size: usize) -> RouterConfigBuilder<IN, OUT, IFS, PORTS> {
pub fn builder(
stack_size: usize,
period: Duration,
time_capacity: Duration,
) -> RouterConfigBuilder<IN, OUT, IFS, PORTS> {
sealed::greater_than_zero::<IN>();
sealed::greater_than_zero::<OUT>();
sealed::greater_than_zero::<IFS>();
sealed::greater_than_zero::<PORTS>();
RouterConfigBuilder::new(stack_size)
RouterConfigBuilder::new(stack_size, period, time_capacity)
}
}

Expand Down Expand Up @@ -331,9 +343,9 @@ impl<const IN: usize, const OUT: usize, const IFS: usize, const PORTS: usize>
RouterConfigBuilder<IN, OUT, IFS, PORTS>
{
/// Creates a new builder for a configuration with a given `stack_size`.
pub fn new(stack_size: usize) -> Self {
pub fn new(stack_size: usize, period: Duration, time_capacity: Duration) -> Self {
Self {
cfg: RouterConfig::new(stack_size),
cfg: RouterConfig::new(stack_size, period, time_capacity),
}
}

Expand Down Expand Up @@ -489,70 +501,74 @@ mod tests {

#[test]
fn build_config() {
_ = RouterConfig::<8, 8, 8, 8>::builder(10_000)
.interface(
"eth0",
InterfaceConfig::new("NodeA", "NodeB", DataRate::b(10_000_000), 1_500),
)
.unwrap()
.interface(
"eth1",
InterfaceConfig::new("NodeA", "NodeB", DataRate::b(10_000_000), 1_500),
)
.unwrap()
.port(
"Advisory_1",
PortConfig::queuing_in(QueuingDiscipline::Fifo, 10, 1_0000),
)
.unwrap()
.port(
"Advisory_2",
PortConfig::queuing_in(QueuingDiscipline::Fifo, 10, 1_0000),
)
.unwrap()
.port(
"FCC_1",
PortConfig::queuing_in(QueuingDiscipline::Fifo, 10, 1_0000),
)
.unwrap()
.port(
"FCC_2",
PortConfig::queuing_out(QueuingDiscipline::Fifo, 10, 1_0000),
)
.unwrap()
.port(
"FCC_3",
PortConfig::queuing_out(QueuingDiscipline::Fifo, 10, 1_0000),
)
.unwrap()
// VL 1
.virtual_link(1, "Advisory_1")
.unwrap()
.destination(1, "eth0")
.unwrap()
.destination(1, "FCC_1")
.unwrap()
.schedule(1, Duration::from_millis(10))
.unwrap()
// VL2
.virtual_link(2, "Advisory_2")
.unwrap()
.destination(2, "eth0")
.unwrap()
.destination(2, "FCC_2")
.unwrap()
.schedule(2, Duration::from_millis(20))
.unwrap()
// VL3
.virtual_link(3, "eth0")
.unwrap()
.destination(3, "FCC_3")
.unwrap()
.destination(3, "eth1")
.unwrap()
.schedule(3, Duration::from_millis(40))
.unwrap()
.build()
.unwrap();
_ = RouterConfig::<8, 8, 8, 8>::builder(
10_000,
Duration::from_millis(500),
Duration::from_millis(10),
)
.interface(
"eth0",
InterfaceConfig::new("NodeA", "NodeB", DataRate::b(10_000_000), 1_500),
)
.unwrap()
.interface(
"eth1",
InterfaceConfig::new("NodeA", "NodeB", DataRate::b(10_000_000), 1_500),
)
.unwrap()
.port(
"Advisory_1",
PortConfig::queuing_in(QueuingDiscipline::Fifo, 10, 1_0000),
)
.unwrap()
.port(
"Advisory_2",
PortConfig::queuing_in(QueuingDiscipline::Fifo, 10, 1_0000),
)
.unwrap()
.port(
"FCC_1",
PortConfig::queuing_in(QueuingDiscipline::Fifo, 10, 1_0000),
)
.unwrap()
.port(
"FCC_2",
PortConfig::queuing_out(QueuingDiscipline::Fifo, 10, 1_0000),
)
.unwrap()
.port(
"FCC_3",
PortConfig::queuing_out(QueuingDiscipline::Fifo, 10, 1_0000),
)
.unwrap()
// VL 1
.virtual_link(1, "Advisory_1")
.unwrap()
.destination(1, "eth0")
.unwrap()
.destination(1, "FCC_1")
.unwrap()
.schedule(1, Duration::from_millis(10))
.unwrap()
// VL2
.virtual_link(2, "Advisory_2")
.unwrap()
.destination(2, "eth0")
.unwrap()
.destination(2, "FCC_2")
.unwrap()
.schedule(2, Duration::from_millis(20))
.unwrap()
// VL3
.virtual_link(3, "eth0")
.unwrap()
.destination(3, "FCC_3")
.unwrap()
.destination(3, "eth1")
.unwrap()
.schedule(3, Duration::from_millis(40))
.unwrap()
.build()
.unwrap();
}
}
14 changes: 12 additions & 2 deletions a653rs-router/src/partition.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,18 +53,28 @@ where
/// # Errors
/// Returns an error describing what kind of resource failed to initialize.
/// Enable the `log` feature for more debug information.
#[allow(clippy::too_many_arguments)]
pub fn create<C: CreateNetworkInterfaceId<P>>(
ctx: &mut StartContext<I>,
name: Name,
interfaces: InterfacesConfig<IFS>,
ports: PortsConfig<PS>,
period: Duration,
time_capacity: Duration,
stack_size: StackSize,
entry_point: extern "C" fn(),
) -> Result<Self, Error> {
Ok(Self {
resources: RouterResources::<I, P, IFS, PS>::create::<C>(ctx, interfaces, ports)?,
process: RouterProcess::create(ctx, name, stack_size, entry_point)
.map_err(Error::Process)?,
process: RouterProcess::create(
ctx,
name,
period,
time_capacity,
stack_size,
entry_point,
)
.map_err(Error::Process)?,
})
}

Expand Down
9 changes: 6 additions & 3 deletions a653rs-router/src/process.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
use a653rs::prelude::SystemTime::Infinite;
use a653rs::prelude::SystemTime;
use a653rs::prelude::{Error as ApexError, Name, Process, StartContext};
use a653rs::{bindings::*, prelude::ProcessAttribute};
use core::fmt::Debug;
use core::time::Duration;

/// Router process
#[derive(Debug)]
Expand All @@ -28,13 +29,15 @@ impl<H: ApexProcessP4> RouterProcess<H> {
pub fn create(
ctx: &mut StartContext<H>,
name: Name,
period: Duration,
time_capacity: Duration,
stack_size: StackSize,
entry_point: extern "C" fn(),
) -> Result<Self, ProcessError> {
Ok(Self {
inner: ctx.create_process(ProcessAttribute {
period: Infinite,
time_capacity: Infinite,
period: SystemTime::Normal(period),
time_capacity: SystemTime::Normal(time_capacity),
entry_point,
stack_size,
base_priority: 1,
Expand Down
6 changes: 6 additions & 0 deletions examples/config/echo-local/router.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
period:
secs: 1
nanos: 0
time_capacity:
secs: 0
nanos: 300000
stack_size: 20000
virtual_links:
1:
Expand Down
6 changes: 6 additions & 0 deletions examples/config/echo-remote/client/router.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
period:
secs: 1
nanos: 0
time_capacity:
secs: 0
nanos: 300000
stack_size: 20000
virtual_links:
1:
Expand Down
6 changes: 6 additions & 0 deletions examples/config/echo-remote/server/router.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
period:
secs: 1
nanos: 0
time_capacity:
secs: 0
nanos: 300000
stack_size: 20000
virtual_links:
1:
Expand Down

0 comments on commit 204eb75

Please sign in to comment.