From aa600ca3726d1891e371796ba47bf99f3aa6e2ad Mon Sep 17 00:00:00 2001 From: Joe Grund Date: Mon, 29 Jun 2020 13:23:18 -0400 Subject: [PATCH] Create Rust iml-state-machine WIP Signed-off-by: Joe Grund --- Cargo.lock | 24 ++++++++++ Cargo.toml | 1 + iml-state-machine/Cargo.toml | 9 ++++ iml-state-machine/README.md | 27 +++++++++++ iml-state-machine/src/lnet.rs | 88 +++++++++++++++++++++++++++++++++++ iml-state-machine/src/main.rs | 9 ++++ 6 files changed, 158 insertions(+) create mode 100644 iml-state-machine/Cargo.toml create mode 100644 iml-state-machine/README.md create mode 100644 iml-state-machine/src/lnet.rs create mode 100644 iml-state-machine/src/main.rs diff --git a/Cargo.lock b/Cargo.lock index f0b36c6b15..e7922bf704 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -813,6 +813,12 @@ version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4443176a9f2c162692bd3d352d745ef9413eec5782a80d8fd6f8a1ac692a07f7" +[[package]] +name = "fixedbitset" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "37ab347416e802de484e4d03c7316c48f1ecb56574dfd4a46a80f173ce1de04d" + [[package]] name = "fnv" version = "1.0.7" @@ -1608,6 +1614,14 @@ dependencies = [ "wbem-client", ] +[[package]] +name = "iml-state-machine" +version = "0.1.0" +dependencies = [ + "futures", + "petgraph", +] + [[package]] name = "iml-stats" version = "0.3.0" @@ -2442,6 +2456,16 @@ version = "2.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d4fd5641d01c8f18a23da7b6fe29298ff4b55afcccdf78973b24cf3175fee32e" +[[package]] +name = "petgraph" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "467d164a6de56270bd7c4d070df81d07beace25012d5103ced4e9ff08d6afdb7" +dependencies = [ + "fixedbitset", + "indexmap", +] + [[package]] name = "phf" version = "0.7.24" diff --git a/Cargo.toml b/Cargo.toml index 853ed035d7..7f60f2f449 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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', diff --git a/iml-state-machine/Cargo.toml b/iml-state-machine/Cargo.toml new file mode 100644 index 0000000000..3a6a4e54a7 --- /dev/null +++ b/iml-state-machine/Cargo.toml @@ -0,0 +1,9 @@ +[package] +name = "iml-state-machine" +version = "0.1.0" +authors = ["IML Team "] +edition = "2018" + +[dependencies] +futures = "0.3" +petgraph = "0.5" \ No newline at end of file diff --git a/iml-state-machine/README.md b/iml-state-machine/README.md new file mode 100644 index 0000000000..d34fe2fcfd --- /dev/null +++ b/iml-state-machine/README.md @@ -0,0 +1,27 @@ +# IML State Machine Model + +``` + ┌────────────────────────────────────────────┐ + │ │ + │ Client mount │ + │ │ + │ │ + └────────────────────────────────────────────┘ + │ + │ + │ + │ + │ + ┌───────Depends on─────┴────────Depends On─────────┐ + │ │ + │ │ + │ │ + │ │ + ▼ ▼ +┌────────────────────────────────────────────┐ ┌────────────────────────────────────────────┐ +│ │ │ │ +│ LNet │ │ Filesystem │ +│ │ │ │ +│ │ │ │ +└────────────────────────────────────────────┘ └────────────────────────────────────────────┘ +``` diff --git a/iml-state-machine/src/lnet.rs b/iml-state-machine/src/lnet.rs new file mode 100644 index 0000000000..db76238b82 --- /dev/null +++ b/iml-state-machine/src/lnet.rs @@ -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> + Send>>; + +type Transition = Box BoxedFuture + Send + Sync>; + +fn mk_transition(f: fn() -> Fut) -> Transition +where + Fut: Future> + Send + 'static, +{ + Box::new(move || f().boxed()) +} + +fn build_graph() -> DiGraph:: { + let mut deps = DiGraph::::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 + +} diff --git a/iml-state-machine/src/main.rs b/iml-state-machine/src/main.rs new file mode 100644 index 0000000000..0f4e65ceb2 --- /dev/null +++ b/iml-state-machine/src/main.rs @@ -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!"); +}