Skip to content
This repository has been archived by the owner on Jul 25, 2022. It is now read-only.

Commit

Permalink
Create Rust iml-state-machine
Browse files Browse the repository at this point in the history
WIP

Signed-off-by: Joe Grund <[email protected]>
  • Loading branch information
jgrund committed Jun 29, 2020
1 parent 00356a3 commit aa600ca
Show file tree
Hide file tree
Showing 6 changed files with 158 additions and 0 deletions.
24 changes: 24 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ members = [
'iml-services/iml-service-queue',
'iml-services/iml-stats',
'iml-sfa',
'iml-state-machine',
'iml-system-test-utils',
'iml-systemd',
'iml-timer',
Expand Down
9 changes: 9 additions & 0 deletions iml-state-machine/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[package]
name = "iml-state-machine"
version = "0.1.0"
authors = ["IML Team <[email protected]>"]
edition = "2018"

[dependencies]
futures = "0.3"
petgraph = "0.5"
27 changes: 27 additions & 0 deletions iml-state-machine/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# IML State Machine Model

```
┌────────────────────────────────────────────┐
│ │
│ Client mount │
│ │
│ │
└────────────────────────────────────────────┘
┌───────Depends on─────┴────────Depends On─────────┐
│ │
│ │
│ │
│ │
▼ ▼
┌────────────────────────────────────────────┐ ┌────────────────────────────────────────────┐
│ │ │ │
│ LNet │ │ Filesystem │
│ │ │ │
│ │ │ │
└────────────────────────────────────────────┘ └────────────────────────────────────────────┘
```
88 changes: 88 additions & 0 deletions iml-state-machine/src/lnet.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
// Copyright (c) 2020 DDN. All rights reserved.
// Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file.

use futures::{Future, FutureExt};
use petgraph::graph::DiGraph;
use std::{ io, pin::Pin};

pub enum LnetStates {
Unconfigured,
Unloaded,
Down,
Up,
}

impl Default for LnetStates {
fn default() -> Self {
Self::Unconfigured
}
}

impl LnetStates {
fn step(self, next: &Self) {
match (self, next) {
(Self::Unconfigured, Self::Unloaded) => {}
(Self::Unloaded, Self::Down) => {}
(Self::Down, Self::Up) => {}
(Self::Up, Self::Down) => {}
(Self::Down, Self::Unloaded) => {}
(Self::Unloaded, Self::Unconfigured) => {}
_ => {}
};
}
}

async fn configure() -> Result<(), io::Error> {
Ok(())
}

async fn load() -> Result<(), io::Error> {
Ok(())
}

async fn start() -> Result<(), io::Error> {
Ok(())
}

async fn stop() -> Result<(), io::Error> {
Ok(())
}

async fn unload() -> Result<(), io::Error> {
Ok(())
}

async fn unconfigure() -> Result<(), io::Error> {
Ok(())
}

type BoxedFuture = Pin<Box<dyn Future<Output = Result<(), io::Error>> + Send>>;

type Transition = Box<dyn Fn() -> BoxedFuture + Send + Sync>;

fn mk_transition<Fut>(f: fn() -> Fut) -> Transition
where
Fut: Future<Output = Result<(), io::Error>> + Send + 'static,
{
Box::new(move || f().boxed())
}

fn build_graph() -> DiGraph::<LnetStates, Transition> {
let mut deps = DiGraph::<LnetStates, Transition>::new();

let unconfigured = deps.add_node(LnetStates::Unconfigured);
let unloaded = deps.add_node(LnetStates::Unloaded);
let down = deps.add_node(LnetStates::Down);
let up = deps.add_node(LnetStates::Up);

deps.add_edge(unconfigured, unloaded, mk_transition(configure));
deps.add_edge(unloaded, down, mk_transition(load));
deps.add_edge(down, up, mk_transition(start));
deps.add_edge(up, down, mk_transition(stop));
deps.add_edge(down, unloaded, mk_transition(unload));
deps.add_edge(unloaded, unconfigured, mk_transition(unconfigure));

deps

}
9 changes: 9 additions & 0 deletions iml-state-machine/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// Copyright (c) 2020 DDN. All rights reserved.
// Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file.

mod lnet;

fn main() {
println!("Hello, world!");
}

0 comments on commit aa600ca

Please sign in to comment.