mirror of
https://github.com/logos-blockchain/logos-blockchain-simulations.git
synced 2026-01-03 21:53:09 +00:00
feat: add more regions
This commit is contained in:
parent
a42dc4b4bf
commit
0deedd68b3
@ -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),
|
||||
),
|
||||
(
|
||||
|
||||
@ -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<S: serde::Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
|
||||
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::<Vec<NodeId>>();
|
||||
|
||||
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,
|
||||
|
||||
@ -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!(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -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 {
|
||||
|
||||
@ -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 {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user