From be5df9ead1669c55052b1600d41c98d5d98ffc5e Mon Sep 17 00:00:00 2001 From: Youngjoon Lee <5462944+youngjoon-lee@users.noreply.github.com> Date: Fri, 20 Dec 2024 16:22:47 +0900 Subject: [PATCH 1/4] Fix netrunner tests (#61) --- .github/workflows/ci.yaml | 7 +++---- simlib/netrunner/src/network/mod.rs | 2 +- simlib/netrunner/src/network/regions.rs | 3 +-- simlib/netrunner/src/node/dummy_streaming.rs | 14 +++++++++++++- simlib/netrunner/src/node/mod.rs | 10 ++++++++-- simlib/netrunner/src/streaming/io.rs | 11 +++++------ .../netrunner/src/streaming/runtime_subscriber.rs | 10 ++++------ .../netrunner/src/streaming/settings_subscriber.rs | 4 +--- 8 files changed, 36 insertions(+), 25 deletions(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 7e98e87..1b1fbbe 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -20,7 +20,6 @@ jobs: - name: Build working-directory: simlib run: cargo build -v - # TODO: uncomment this after fixing tests - # - name: Unit tests - # working-directory: simlib - # run: cargo test -v + - name: Unit tests + working-directory: simlib + run: cargo test -v diff --git a/simlib/netrunner/src/network/mod.rs b/simlib/netrunner/src/network/mod.rs index 1fec225..e88d821 100644 --- a/simlib/netrunner/src/network/mod.rs +++ b/simlib/netrunner/src/network/mod.rs @@ -524,7 +524,7 @@ mod tests { impl PayloadSize for () { fn size_bytes(&self) -> u32 { - todo!() + 0 } } diff --git a/simlib/netrunner/src/network/regions.rs b/simlib/netrunner/src/network/regions.rs index 328deb4..185375b 100644 --- a/simlib/netrunner/src/network/regions.rs +++ b/simlib/netrunner/src/network/regions.rs @@ -156,7 +156,6 @@ pub fn create_regions( mod tests { use std::collections::HashMap; - use consensus_engine::NodeId; use rand::rngs::mock::StepRng; use crate::{ @@ -164,7 +163,7 @@ mod tests { regions::{create_regions, Region}, NetworkSettings, }, - node::NodeIdExt, + node::{NodeId, NodeIdExt}, }; #[test] diff --git a/simlib/netrunner/src/node/dummy_streaming.rs b/simlib/netrunner/src/node/dummy_streaming.rs index cdbf93b..3fce774 100644 --- a/simlib/netrunner/src/node/dummy_streaming.rs +++ b/simlib/netrunner/src/node/dummy_streaming.rs @@ -1,6 +1,8 @@ use serde::{Deserialize, Serialize}; use std::time::Duration; +use crate::warding::WardCondition; + use super::{Node, NodeId}; #[derive(Debug, Default, Copy, Clone, Serialize, Deserialize)] @@ -40,6 +42,16 @@ impl Node for DummyStreamingNode { } fn step(&mut self, _: Duration) { - todo!() + self.state.counter += 1; + } + + fn analyze(&self, ward: &mut crate::warding::WardCondition) -> bool { + match ward { + WardCondition::Max(ward) => self.state.counter >= ward.max_count, + WardCondition::Sum(condition) => { + *condition.step_result.borrow_mut() += self.state.counter; + false + } + } } } diff --git a/simlib/netrunner/src/node/mod.rs b/simlib/netrunner/src/node/mod.rs index c5b1c0e..b107275 100644 --- a/simlib/netrunner/src/node/mod.rs +++ b/simlib/netrunner/src/node/mod.rs @@ -163,8 +163,14 @@ impl Node for usize { self.add_assign(1); } - fn analyze(&self, _: &mut WardCondition) -> bool { - todo!() + fn analyze(&self, ward: &mut WardCondition) -> bool { + match ward { + WardCondition::Max(ward) => *self >= ward.max_count, + WardCondition::Sum(condition) => { + *condition.step_result.borrow_mut() += *self; + false + } + } } } diff --git a/simlib/netrunner/src/streaming/io.rs b/simlib/netrunner/src/streaming/io.rs index 9332731..b79d2f6 100644 --- a/simlib/netrunner/src/streaming/io.rs +++ b/simlib/netrunner/src/streaming/io.rs @@ -117,8 +117,6 @@ where mod tests { use std::{collections::HashMap, time::Duration}; - use consensus_engine::View; - use crate::{ network::{ behaviour::NetworkBehaviour, @@ -135,12 +133,13 @@ mod tests { }; use super::*; + #[derive(Debug, Clone, Serialize)] - struct IORecord { - states: HashMap, + struct IORecord { + states: HashMap, } - impl TryFrom<&SimulationState> for IORecord { + impl TryFrom<&SimulationState> for IORecord { type Error = anyhow::Error; fn try_from(value: &SimulationState) -> Result { @@ -148,7 +147,7 @@ mod tests { Ok(Self { states: nodes .iter() - .map(|node| (node.id(), node.current_view())) + .map(|node| (node.id(), node.state().clone())) .collect(), }) } diff --git a/simlib/netrunner/src/streaming/runtime_subscriber.rs b/simlib/netrunner/src/streaming/runtime_subscriber.rs index 3f45c56..2b54fc2 100644 --- a/simlib/netrunner/src/streaming/runtime_subscriber.rs +++ b/simlib/netrunner/src/streaming/runtime_subscriber.rs @@ -103,8 +103,6 @@ where mod tests { use std::{collections::HashMap, time::Duration}; - use consensus_engine::View; - use crate::{ network::{ behaviour::NetworkBehaviour, @@ -122,11 +120,11 @@ mod tests { use super::*; #[derive(Debug, Clone, Serialize)] - struct RuntimeRecord { - states: HashMap, + struct RuntimeRecord { + states: HashMap, } - impl TryFrom<&SimulationState> for RuntimeRecord { + impl TryFrom<&SimulationState> for RuntimeRecord { type Error = anyhow::Error; fn try_from(value: &SimulationState) -> Result { @@ -135,7 +133,7 @@ mod tests { .nodes .read() .iter() - .map(|node| (node.id(), node.current_view())) + .map(|node| (node.id(), node.state().clone())) .collect(), }) } diff --git a/simlib/netrunner/src/streaming/settings_subscriber.rs b/simlib/netrunner/src/streaming/settings_subscriber.rs index 59105ce..1dd4ec9 100644 --- a/simlib/netrunner/src/streaming/settings_subscriber.rs +++ b/simlib/netrunner/src/streaming/settings_subscriber.rs @@ -102,9 +102,7 @@ where #[cfg(test)] mod tests { use std::collections::HashSet; - use std::{collections::HashMap, time::Duration}; - - type View = usize; + use std::time::Duration; use crate::{ network::{ From a42dc4b4bf6a3aa11bed8735f9647dfd9cadb824 Mon Sep 17 00:00:00 2001 From: Youngjoon Lee <5462944+youngjoon-lee@users.noreply.github.com> Date: Thu, 2 Jan 2025 22:26:48 +0900 Subject: [PATCH 2/4] feat(blend): calculate topology diameter (#66) --- simlib/blendnet-sims/src/main.rs | 22 +- .../blendnet-sims/src/node/blend/topology.rs | 216 ++++++++++++------ 2 files changed, 162 insertions(+), 76 deletions(-) diff --git a/simlib/blendnet-sims/src/main.rs b/simlib/blendnet-sims/src/main.rs index a6d131d..f825a5e 100644 --- a/simlib/blendnet-sims/src/main.rs +++ b/simlib/blendnet-sims/src/main.rs @@ -1,3 +1,4 @@ +use std::collections::HashMap; // std use std::fs::File; use std::path::{Path, PathBuf}; @@ -16,7 +17,7 @@ use netrunner::node::{NodeId, NodeIdExt}; use netrunner::output_processors::Record; use netrunner::runner::{BoxedNode, SimulationRunnerHandle}; use netrunner::streaming::{io::IOSubscriber, naive::NaiveSubscriber, StreamType}; -use node::blend::topology::build_topology; +use node::blend::topology::Topology; use nomos_blend::cover_traffic::CoverTrafficSettings; use nomos_blend::message_blend::{ CryptographicProcessorSettings, MessageBlendSettings, TemporalSchedulerSettings, @@ -26,7 +27,7 @@ use rand::seq::SliceRandom; use rand::{RngCore, SeedableRng}; use rand_chacha::ChaCha12Rng; use serde::de::DeserializeOwned; -use serde::Serialize; +use serde::{Deserialize, Serialize}; // internal use crate::node::blend::BlendNode; use crate::settings::SimSettings; @@ -89,7 +90,8 @@ impl SimulationApp { let network = Arc::new(Mutex::new(Network::::new(regions_data, seed))); - let topology = build_topology(&node_ids, settings.connected_peers_count, &mut rng); + let topology = Topology::new(&node_ids, settings.connected_peers_count, &mut rng); + log_topology(&topology); let nodes: Vec<_> = node_ids .iter() @@ -243,6 +245,20 @@ fn load_json_from_file(path: &Path) -> anyhow::Result { Ok(serde_json::from_reader(f)?) } +fn log_topology(topology: &Topology) { + let log = TopologyLog { + topology: topology.to_node_indices(), + diameter: topology.diameter(), + }; + tracing::info!("Topology: {}", serde_json::to_string(&log).unwrap()); +} + +#[derive(Debug, Serialize, Deserialize)] +struct TopologyLog { + topology: HashMap>, + diameter: usize, +} + fn main() -> anyhow::Result<()> { let app: SimulationApp = SimulationApp::parse(); let maybe_guard = log::config_tracing(app.log_format, &app.log_to, app.with_metrics); diff --git a/simlib/blendnet-sims/src/node/blend/topology.rs b/simlib/blendnet-sims/src/node/blend/topology.rs index f01e890..d86d40e 100644 --- a/simlib/blendnet-sims/src/node/blend/topology.rs +++ b/simlib/blendnet-sims/src/node/blend/topology.rs @@ -1,91 +1,149 @@ use std::collections::{HashMap, HashSet}; -use netrunner::node::NodeId; +use netrunner::node::{NodeId, NodeIdExt}; use rand::{seq::SliceRandom, RngCore}; -pub type Topology = HashMap>; +#[derive(Clone)] +pub struct Topology(HashMap>); -/// Builds a topology with the given nodes and peering degree -/// by ensuring that all nodes are connected (no partition) -/// and all nodes have the same number of connections (only if possible). -pub fn build_topology(nodes: &[NodeId], peering_degree: usize, mut rng: R) -> Topology { - tracing::info!("Building topology: peering_degree:{}", peering_degree); - loop { - let mut topology = nodes - .iter() - .map(|&node| (node, HashSet::new())) - .collect::>(); - - for node in nodes.iter() { - // Collect peer candidates - let mut others = nodes +impl Topology { + /// Builds a topology with the given nodes and peering degree + /// by ensuring that all nodes are connected (no partition) + /// and all nodes have the same number of connections (only if possible). + pub fn new(nodes: &[NodeId], peering_degree: usize, mut rng: R) -> Self { + tracing::info!("Building topology: peering_degree:{}", peering_degree); + loop { + let mut topology = nodes .iter() - .filter(|&other| { - // Check if the other node is not already connected to the current node - // and the other node has not reached the peering degree. - other != node - && !topology.get(node).unwrap().contains(other) - && topology.get(other).unwrap().len() < peering_degree - }) - .copied() - .collect::>(); + .map(|&node| (node, HashSet::new())) + .collect::>(); - // How many more connections the current node needs - let num_needs = peering_degree - topology.get(node).unwrap().len(); - // Sample peers as many as possible and connect them to the current node - let k = std::cmp::min(num_needs, others.len()); - others.as_mut_slice().shuffle(&mut rng); - others.into_iter().take(k).for_each(|peer| { - topology.get_mut(node).unwrap().insert(peer); - topology.get_mut(&peer).unwrap().insert(*node); - }); - } + for node in nodes.iter() { + // Collect peer candidates + let mut others = nodes + .iter() + .filter(|&other| { + // Check if the other node is not already connected to the current node + // and the other node has not reached the peering degree. + other != node + && !topology.get(node).unwrap().contains(other) + && topology.get(other).unwrap().len() < peering_degree + }) + .copied() + .collect::>(); - // Check constraints: - // - All nodes are connected (no partition) - // - All nodes have the same number of connections (if possible) - let can_have_equal_conns = (nodes.len() * peering_degree) % 2 == 0; - if check_all_connected(&topology) - && (!can_have_equal_conns || check_equal_conns(&topology, peering_degree)) - { - return topology; + // How many more connections the current node needs + let num_needs = peering_degree - topology.get(node).unwrap().len(); + // Sample peers as many as possible and connect them to the current node + let k = std::cmp::min(num_needs, others.len()); + others.as_mut_slice().shuffle(&mut rng); + others.into_iter().take(k).for_each(|peer| { + topology.get_mut(node).unwrap().insert(peer); + topology.get_mut(&peer).unwrap().insert(*node); + }); + } + + // Check constraints: + // - All nodes are connected (no partition) + // - All nodes have the same number of connections (if possible) + let topology = Self(topology); + let can_have_equal_conns = (nodes.len() * peering_degree) % 2 == 0; + if topology.check_all_connected() + && (!can_have_equal_conns || topology.check_equal_conns(peering_degree)) + { + return topology; + } + tracing::info!("Topology doesn't meet constraints. Retrying..."); } - tracing::info!("Topology doesn't meet constraints. Retrying..."); } -} -/// Checks if all nodes are connected (no partition) in the topology. -fn check_all_connected(topology: &Topology) -> bool { - let visited = dfs(topology, *topology.keys().next().unwrap()); - visited.len() == topology.len() -} + /// Checks if all nodes are connected (no partition) in the topology. + fn check_all_connected(&self) -> bool { + let visited = self.dfs(*self.0.keys().next().unwrap()); + visited.len() == self.0.len() + } -/// Depth-first search to visit nodes in the topology. -fn dfs(topology: &Topology, start_node: NodeId) -> HashSet { - let mut visited: HashSet = HashSet::new(); - let mut stack: Vec = Vec::new(); - stack.push(start_node); - while let Some(node) = stack.pop() { - visited.insert(node); - for peer in topology.get(&node).unwrap().iter() { - if !visited.contains(peer) { - stack.push(*peer); + /// Depth-first search to visit nodes in the topology. + fn dfs(&self, start_node: NodeId) -> HashSet { + let mut visited: HashSet = HashSet::new(); + let mut stack: Vec = Vec::new(); + stack.push(start_node); + while let Some(node) = stack.pop() { + visited.insert(node); + for peer in self.0.get(&node).unwrap().iter() { + if !visited.contains(peer) { + stack.push(*peer); + } } } + visited } - visited -} -/// Checks if all nodes have the same number of connections. -fn check_equal_conns(topology: &Topology, peering_degree: usize) -> bool { - topology - .iter() - .all(|(_, peers)| peers.len() == peering_degree) + /// Checks if all nodes have the same number of connections. + fn check_equal_conns(&self, peering_degree: usize) -> bool { + self.0 + .iter() + .all(|(_, peers)| peers.len() == peering_degree) + } + + /// Calculate the diameter (longest path length) of the topology. + pub fn diameter(&self) -> usize { + // Calculate a diameter from each node and take the maximum + self.0 + .keys() + .map(|&node| self.diameter_from(node)) + .fold(0, usize::max) + } + + /// Calculate a diameter (longest path length) of the topology from the start_node. + fn diameter_from(&self, start_node: NodeId) -> usize { + // start_node is visited at the beginning + let mut visited: HashSet = HashSet::from([start_node]); + + // Count the number of hops to visit all nodes + let mut hop_count = 0; + let mut next_hop: HashSet = self.0.get(&start_node).unwrap().clone(); + while !next_hop.is_empty() { + // First, visit all nodes in the next hop and increase the hop count + next_hop.iter().for_each(|&node| { + assert!(visited.insert(node)); + }); + hop_count += 1; + // Then, build the new next hop by collecting all peers of the current next hop + // except peers already visited + next_hop = next_hop + .iter() + .flat_map(|node| self.0.get(node).unwrap()) + .filter(|&peer| !visited.contains(peer)) + .copied() + .collect(); + } + hop_count + } + + pub fn get(&self, node: &NodeId) -> Option<&HashSet> { + self.0.get(node) + } + + /// Converts all [`NodeId`]s in the topology to their indices. + pub fn to_node_indices(&self) -> HashMap> { + self.0 + .iter() + .map(|(node, peers)| { + ( + node.index(), + peers.iter().map(|peer| peer.index()).collect(), + ) + }) + .collect() + } } #[cfg(test)] mod tests { use netrunner::node::NodeIdExt; + use rand::SeedableRng; + use rand_chacha::ChaCha8Rng; use super::*; @@ -97,9 +155,9 @@ mod tests { let peering_degree = 4; let mut rng = rand::rngs::OsRng; - let topology = build_topology(&nodes, peering_degree, &mut rng); - assert_eq!(topology.len(), nodes.len()); - for (node, peers) in topology.iter() { + let topology = Topology::new(&nodes, peering_degree, &mut rng); + assert_eq!(topology.0.len(), nodes.len()); + for (node, peers) in topology.0.iter() { assert!(peers.len() == peering_degree); for peer in peers.iter() { assert!(topology.get(peer).unwrap().contains(node)); @@ -115,13 +173,25 @@ mod tests { let peering_degree = 3; let mut rng = rand::rngs::OsRng; - let topology = build_topology(&nodes, peering_degree, &mut rng); - assert_eq!(topology.len(), nodes.len()); - for (node, peers) in topology.iter() { + let topology = Topology::new(&nodes, peering_degree, &mut rng); + assert_eq!(topology.0.len(), nodes.len()); + for (node, peers) in topology.0.iter() { assert!(peers.len() <= peering_degree); for peer in peers.iter() { assert!(topology.get(peer).unwrap().contains(node)); } } } + + #[test] + fn test_diameter() { + let nodes = (0..100).map(NodeId::from_index).collect::>(); + let peering_degree = 4; + let mut rng = ChaCha8Rng::seed_from_u64(0); + let topology = Topology::new(&nodes, peering_degree, &mut rng); + let diameter = topology.diameter(); + println!("diameter: {}", diameter); + assert!(diameter > 0); + assert!(diameter <= nodes.len()); + } } From 0deedd68b3635c159b5621e79c63c1164562fddb Mon Sep 17 00:00:00 2001 From: Youngjoon Lee <5462944+youngjoon-lee@users.noreply.github.com> Date: Mon, 3 Feb 2025 17:47:29 +0900 Subject: [PATCH 3/4] feat: add more regions --- simlib/netrunner/src/network/mod.rs | 6 +-- simlib/netrunner/src/network/regions.rs | 40 ++++++++++++---- simlib/netrunner/src/streaming/io.rs | 48 ++++++++----------- .../src/streaming/runtime_subscriber.rs | 31 ++---------- .../src/streaming/settings_subscriber.rs | 31 ++---------- 5 files changed, 61 insertions(+), 95 deletions(-) diff --git a/simlib/netrunner/src/network/mod.rs b/simlib/netrunner/src/network/mod.rs index e88d821..aed8c2d 100644 --- a/simlib/netrunner/src/network/mod.rs +++ b/simlib/netrunner/src/network/mod.rs @@ -618,16 +618,16 @@ mod tests { let node_c = NodeId::from_index(2); let regions = HashMap::from([ - (Region::Asia, vec![node_a, node_b]), + (Region::EastAsia, vec![node_a, node_b]), (Region::Europe, vec![node_c]), ]); let behaviour = HashMap::from([ ( - NetworkBehaviourKey::new(Region::Asia, Region::Asia), + NetworkBehaviourKey::new(Region::EastAsia, Region::EastAsia), NetworkBehaviour::new(Duration::from_millis(100), 0.0), ), ( - NetworkBehaviourKey::new(Region::Asia, Region::Europe), + NetworkBehaviourKey::new(Region::EastAsia, Region::Europe), NetworkBehaviour::new(Duration::from_millis(500), 0.0), ), ( diff --git a/simlib/netrunner/src/network/regions.rs b/simlib/netrunner/src/network/regions.rs index 185375b..45d1ff1 100644 --- a/simlib/netrunner/src/network/regions.rs +++ b/simlib/netrunner/src/network/regions.rs @@ -10,9 +10,13 @@ use super::{NetworkBehaviourKey, NetworkSettings}; #[derive(Debug, Copy, Clone, Eq, PartialEq, Hash)] pub enum Region { - NorthAmerica, + NorthAmericaWest, + NorthAmericaCentral, + NorthAmericaEast, Europe, - Asia, + NorthernEurope, + EastAsia, + SoutheastAsia, Africa, SouthAmerica, Australia, @@ -21,9 +25,13 @@ pub enum Region { impl core::fmt::Display for Region { fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { let s = match self { - Self::NorthAmerica => "NorthAmerica", + Self::NorthAmericaWest => "NorthAmericaWest", + Self::NorthAmericaCentral => "NorthAmericaCentral", + Self::NorthAmericaEast => "NorthAmericaEast", Self::Europe => "Europe", - Self::Asia => "Asia", + Self::NorthernEurope => "NorthernEurope", + Self::EastAsia => "EastAsia", + Self::SoutheastAsia => "SoutheastAsia", Self::Africa => "Africa", Self::SouthAmerica => "SouthAmerica", Self::Australia => "Australia", @@ -42,9 +50,13 @@ impl FromStr for Region { .replace(['-', '_', ' '], "") .as_str() { - "northamerica" | "na" => Ok(Self::NorthAmerica), + "northamericawest" | "naw" => Ok(Self::NorthAmericaWest), + "northamericacentral" | "nac" => Ok(Self::NorthAmericaCentral), + "northamericaeast" | "nae" => Ok(Self::NorthAmericaEast), "europe" | "eu" => Ok(Self::Europe), - "asia" | "as" => Ok(Self::Asia), + "northerneurope" | "neu" => Ok(Self::NorthernEurope), + "eastasia" | "eas" => Ok(Self::EastAsia), + "southeastasia" | "seas" => Ok(Self::SoutheastAsia), "africa" | "af" => Ok(Self::Africa), "southamerica" | "sa" => Ok(Self::SouthAmerica), "australia" | "au" => Ok(Self::Australia), @@ -56,9 +68,13 @@ impl FromStr for Region { impl Serialize for Region { fn serialize(&self, serializer: S) -> Result { let s = match self { - Self::NorthAmerica => "North America", + Self::NorthAmericaWest => "North America West", + Self::NorthAmericaCentral => "North America Central", + Self::NorthAmericaEast => "North America East", Self::Europe => "Europe", - Self::Asia => "Asia", + Self::NorthernEurope => "Northern Europe", + Self::EastAsia => "EastAsia", + Self::SoutheastAsia => "Southeast Asia", Self::Africa => "Africa", Self::SouthAmerica => "South America", Self::Australia => "Australia", @@ -207,9 +223,13 @@ mod tests { .collect::>(); let available_regions = [ - Region::NorthAmerica, + Region::NorthAmericaWest, + Region::NorthAmericaCentral, + Region::NorthAmericaEast, Region::Europe, - Region::Asia, + Region::NorthernEurope, + Region::EastAsia, + Region::SoutheastAsia, Region::Africa, Region::SouthAmerica, Region::Australia, diff --git a/simlib/netrunner/src/streaming/io.rs b/simlib/netrunner/src/streaming/io.rs index b79d2f6..d0b0ec6 100644 --- a/simlib/netrunner/src/streaming/io.rs +++ b/simlib/netrunner/src/streaming/io.rs @@ -114,7 +114,7 @@ where } #[cfg(test)] -mod tests { +pub(crate) mod tests { use std::{collections::HashMap, time::Duration}; use crate::{ @@ -174,43 +174,19 @@ mod tests { RegionsData { regions: (0..6) .map(|idx| { - let region = match idx % 6 { - 0 => Region::Europe, - 1 => Region::NorthAmerica, - 2 => Region::SouthAmerica, - 3 => Region::Asia, - 4 => Region::Africa, - 5 => Region::Australia, - _ => unreachable!(), - }; + let region = region_from_index(idx); (region, vec![NodeId::from_index(idx)]) }) .collect(), node_region: (0..6) .map(|idx| { - let region = match idx % 6 { - 0 => Region::Europe, - 1 => Region::NorthAmerica, - 2 => Region::SouthAmerica, - 3 => Region::Asia, - 4 => Region::Africa, - 5 => Region::Australia, - _ => unreachable!(), - }; + let region = region_from_index(idx); (NodeId::from_index(idx), region) }) .collect(), region_network_behaviour: (0..6) .map(|idx| { - let region = match idx % 6 { - 0 => Region::Europe, - 1 => Region::NorthAmerica, - 2 => Region::SouthAmerica, - 3 => Region::Asia, - 4 => Region::Africa, - 5 => Region::Australia, - _ => unreachable!(), - }; + let region = region_from_index(idx); ( NetworkBehaviourKey::new(region, region), NetworkBehaviour { @@ -231,4 +207,20 @@ mod tests { .stop_after(Duration::from_millis(100)) .unwrap(); } + + pub(crate) fn region_from_index(idx: usize) -> Region { + match idx % 10 { + 0 => Region::Europe, + 1 => Region::NorthernEurope, + 2 => Region::NorthAmericaWest, + 3 => Region::NorthAmericaCentral, + 4 => Region::NorthAmericaEast, + 5 => Region::SouthAmerica, + 6 => Region::EastAsia, + 7 => Region::SoutheastAsia, + 8 => Region::Africa, + 9 => Region::Australia, + _ => unreachable!(), + } + } } diff --git a/simlib/netrunner/src/streaming/runtime_subscriber.rs b/simlib/netrunner/src/streaming/runtime_subscriber.rs index 2b54fc2..59d8809 100644 --- a/simlib/netrunner/src/streaming/runtime_subscriber.rs +++ b/simlib/netrunner/src/streaming/runtime_subscriber.rs @@ -115,6 +115,7 @@ mod tests { }, output_processors::OutData, runner::SimulationRunner, + streaming::io::tests::region_from_index, warding::SimulationState, }; @@ -160,43 +161,19 @@ mod tests { RegionsData { regions: (0..6) .map(|idx| { - let region = match idx % 6 { - 0 => Region::Europe, - 1 => Region::NorthAmerica, - 2 => Region::SouthAmerica, - 3 => Region::Asia, - 4 => Region::Africa, - 5 => Region::Australia, - _ => unreachable!(), - }; + let region = region_from_index(idx); (region, vec![NodeId::from_index(idx)]) }) .collect(), node_region: (0..6) .map(|idx| { - let region = match idx % 6 { - 0 => Region::Europe, - 1 => Region::NorthAmerica, - 2 => Region::SouthAmerica, - 3 => Region::Asia, - 4 => Region::Africa, - 5 => Region::Australia, - _ => unreachable!(), - }; + let region = region_from_index(idx); (NodeId::from_index(idx), region) }) .collect(), region_network_behaviour: (0..6) .map(|idx| { - let region = match idx % 6 { - 0 => Region::Europe, - 1 => Region::NorthAmerica, - 2 => Region::SouthAmerica, - 3 => Region::Asia, - 4 => Region::Africa, - 5 => Region::Australia, - _ => unreachable!(), - }; + let region = region_from_index(idx); ( NetworkBehaviourKey::new(region, region), NetworkBehaviour { diff --git a/simlib/netrunner/src/streaming/settings_subscriber.rs b/simlib/netrunner/src/streaming/settings_subscriber.rs index 1dd4ec9..e2f6f3d 100644 --- a/simlib/netrunner/src/streaming/settings_subscriber.rs +++ b/simlib/netrunner/src/streaming/settings_subscriber.rs @@ -116,6 +116,7 @@ mod tests { }, output_processors::OutData, runner::SimulationRunner, + streaming::io::tests::region_from_index, warding::SimulationState, }; @@ -156,43 +157,19 @@ mod tests { RegionsData { regions: (0..6) .map(|idx| { - let region = match idx % 6 { - 0 => Region::Europe, - 1 => Region::NorthAmerica, - 2 => Region::SouthAmerica, - 3 => Region::Asia, - 4 => Region::Africa, - 5 => Region::Australia, - _ => unreachable!(), - }; + let region = region_from_index(idx); (region, vec![NodeId::from_index(idx)]) }) .collect(), node_region: (0..6) .map(|idx| { - let region = match idx % 6 { - 0 => Region::Europe, - 1 => Region::NorthAmerica, - 2 => Region::SouthAmerica, - 3 => Region::Asia, - 4 => Region::Africa, - 5 => Region::Australia, - _ => unreachable!(), - }; + let region = region_from_index(idx); (NodeId::from_index(idx), region) }) .collect(), region_network_behaviour: (0..6) .map(|idx| { - let region = match idx % 6 { - 0 => Region::Europe, - 1 => Region::NorthAmerica, - 2 => Region::SouthAmerica, - 3 => Region::Asia, - 4 => Region::Africa, - 5 => Region::Australia, - _ => unreachable!(), - }; + let region = region_from_index(idx); ( NetworkBehaviourKey::new(region, region), NetworkBehaviour { From f9192f084dc14a52bc644c6171ef614d61599967 Mon Sep 17 00:00:00 2001 From: Youngjoon Lee <5462944+youngjoon-lee@users.noreply.github.com> Date: Mon, 3 Feb 2025 18:04:39 +0900 Subject: [PATCH 4/4] update conf --- simlib/blendnet-sims/config/blendnet.json | 84 +++++++++++++++++++---- 1 file changed, 72 insertions(+), 12 deletions(-) diff --git a/simlib/blendnet-sims/config/blendnet.json b/simlib/blendnet-sims/config/blendnet.json index 9179c44..166755a 100644 --- a/simlib/blendnet-sims/config/blendnet.json +++ b/simlib/blendnet-sims/config/blendnet.json @@ -1,26 +1,86 @@ { "network_settings": { "network_behaviors": { - "north america:north america": "50ms", - "north america:europe": "100ms", - "north america:asia": "120ms", + "north america west:north america west": "40ms", + "north america west:north america east": "70ms", + "north america west:north america central": "50ms", + "north america west:europe": "150ms", + "north america west:northern europe": "170ms", + "north america west:east asia": "180ms", + "north america west:southeast asia": "200ms", + "north america west:australia": "250ms", + "north america east:north america west": "70ms", + "north america east:north america east": "40ms", + "north america east:north america central": "50ms", + "north america east:europe": "130ms", + "north america east:northern europe": "140ms", + "north america east:east asia": "250ms", + "north america east:southeast asia": "300ms", + "north america east:australia": "230ms", + "north america central:north america west": "50ms", + "north america central:north america east": "50ms", + "north america central:north america central": "20ms", + "north america central:europe": "140ms", + "north america central:northern europe": "150ms", + "north america central:east asia": "200ms", + "north america central:southeast asia": "280ms", + "north america central:australia": "220ms", + "europe:north america west": "150ms", + "europe:north america east": "130ms", + "europe:north america central": "140ms", "europe:europe": "50ms", - "europe:asia": "100ms", - "europe:north america": "120ms", - "asia:north america": "100ms", - "asia:europe": "120ms", - "asia:asia": "40ms" + "europe:northern europe": "60ms", + "europe:east asia": "300ms", + "europe:southeast asia": "300ms", + "europe:australia": "300ms", + "northern europe:north america west": "170ms", + "northern europe:north america east": "140ms", + "northern europe:north america central": "150ms", + "northern europe:europe": "60ms", + "northern europe:northern europe": "30ms", + "northern europe:east asia": "400ms", + "northern europe:southeast asia": "320ms", + "northern europe:australia": "300ms", + "east asia:north america west": "180ms", + "east asia:north america east": "250ms", + "east asia:north america central": "200ms", + "east asia:europe": "300ms", + "east asia:northern europe": "400ms", + "east asia:east asia": "50ms", + "east asia:southeast asia": "90ms", + "east asia:australia": "150ms", + "southeast asia:north america west": "200ms", + "southeast asia:north america east": "300ms", + "southeast asia:north america central": "280ms", + "southeast asia:europe": "300ms", + "southeast asia:northern europe": "320ms", + "southeast asia:east asia": "90ms", + "southeast asia:southeast asia": "40ms", + "southeast asia:australia": "150ms", + "australia:north america west": "250ms", + "australia:north america east": "230ms", + "australia:north america central": "220ms", + "australia:europe": "300ms", + "australia:northern europe": "300ms", + "australia:east asia": "150ms", + "australia:southeast asia": "150ms", + "australia:australia": "50ms" }, "regions": { - "north america": 0.4, - "europe": 0.4, - "asia": 0.3 + "north america west": 0.06, + "north america east": 0.15, + "north america central": 0.02, + "europe": 0.47, + "northern europe": 0.10, + "east asia": 0.10, + "southeast asia": 0.07, + "australia": 0.03 } }, "node_settings": { "timeout": "1000ms" }, - "step_time": "40ms", + "step_time": "20ms", "runner_settings": "Sync", "stream_settings": { "path": "test.json"