This repository has been archived by the owner on Jul 25, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
WIP Signed-off-by: Joe Grund <[email protected]>
- Loading branch information
Showing
6 changed files
with
158 additions
and
0 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 │ | ||
│ │ │ │ | ||
│ │ │ │ | ||
└────────────────────────────────────────────┘ └────────────────────────────────────────────┘ | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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!"); | ||
} |