|
| 1 | +use std::fmt::Display; |
| 2 | + |
| 3 | +use clap::{Parser, ValueEnum}; |
| 4 | + |
| 5 | +#[derive(Debug, Clone, ValueEnum, PartialEq, Eq)] |
| 6 | +pub enum Mode { |
| 7 | + /// All nodes broadcast messages |
| 8 | + #[value(name = "all")] |
| 9 | + AllBroadcast, |
| 10 | + /// Only the node specified by --broadcaster broadcasts messages |
| 11 | + #[value(name = "one")] |
| 12 | + OneBroadcast, |
| 13 | + /// Nodes take turns broadcasting in round-robin fashion |
| 14 | + #[value(name = "rr")] |
| 15 | + RoundRobin, |
| 16 | + /// Only the node specified by --broadcaster broadcasts messages, |
| 17 | + /// Every explore_run_duration_seconds + explore_cool_down_duration_seconds seconds |
| 18 | + /// a new combination of MPS and message size is explored. |
| 19 | + /// Increases the throughput with each new trial. |
| 20 | + /// Configurations are filtered by minimum throughput and minimum message size. |
| 21 | + #[value(name = "explore")] |
| 22 | + Explore, |
| 23 | +} |
| 24 | + |
| 25 | +#[derive(Debug, Clone, ValueEnum, PartialEq, Eq)] |
| 26 | +pub enum NetworkProtocol { |
| 27 | + /// Use gossipsub for broadcasting (default) |
| 28 | + #[value(name = "gossipsub")] |
| 29 | + Gossipsub, |
| 30 | + /// Use SQMR for point-to-point communication |
| 31 | + #[value(name = "sqmr")] |
| 32 | + Sqmr, |
| 33 | + /// Use Reversed SQMR where receivers initiate requests to broadcasters |
| 34 | + #[value(name = "reversed-sqmr")] |
| 35 | + ReveresedSqmr, |
| 36 | +} |
| 37 | + |
| 38 | +impl Display for Mode { |
| 39 | + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { |
| 40 | + write!(f, "{}", self.to_possible_value().unwrap().get_name()) |
| 41 | + } |
| 42 | +} |
| 43 | + |
| 44 | +impl Display for NetworkProtocol { |
| 45 | + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { |
| 46 | + write!(f, "{}", self.to_possible_value().unwrap().get_name()) |
| 47 | + } |
| 48 | +} |
| 49 | + |
| 50 | +#[derive(Parser, Debug, Clone)] |
| 51 | +#[command(version, about, long_about = None)] |
| 52 | +pub struct Args { |
| 53 | + /// ID for Prometheus logging |
| 54 | + #[arg(short, long, env)] |
| 55 | + pub id: u64, |
| 56 | + |
| 57 | + /// Total number of nodes in the network |
| 58 | + #[arg(long, env)] |
| 59 | + pub num_nodes: u64, |
| 60 | + |
| 61 | + /// The port to run the Prometheus metrics server on |
| 62 | + #[arg(long, env)] |
| 63 | + pub metric_port: u16, |
| 64 | + |
| 65 | + /// The port to run the P2P network on |
| 66 | + #[arg(short, env, long)] |
| 67 | + pub p2p_port: u16, |
| 68 | + |
| 69 | + /// The addresses of the bootstrap peers (can specify multiple) |
| 70 | + #[arg(long, env, value_delimiter = ',')] |
| 71 | + pub bootstrap: Vec<String>, |
| 72 | + |
| 73 | + /// Set the verbosity level of the logger, the higher the more verbose |
| 74 | + #[arg(short, long, env)] |
| 75 | + pub verbosity: u8, |
| 76 | + |
| 77 | + /// Buffer size for the broadcast topic |
| 78 | + #[arg(long, env)] |
| 79 | + pub buffer_size: usize, |
| 80 | + |
| 81 | + /// The mode to use for the stress test. |
| 82 | + #[arg(long, env)] |
| 83 | + pub mode: Mode, |
| 84 | + |
| 85 | + /// The network protocol to use for communication (default: gossipsub) |
| 86 | + #[arg(long, env)] |
| 87 | + pub network_protocol: NetworkProtocol, |
| 88 | + |
| 89 | + /// Which node ID should do the broadcasting - for OneBroadcast and Explore modes |
| 90 | + #[arg(long, env, required_if_eq_any([("mode", "one"), ("mode", "explore")]))] |
| 91 | + pub broadcaster: Option<u64>, |
| 92 | + |
| 93 | + /// Duration each node broadcasts before switching (in seconds) - for RoundRobin mode |
| 94 | + #[arg(long, env, required_if_eq("mode", "rr"))] |
| 95 | + pub round_duration_seconds: Option<u64>, |
| 96 | + |
| 97 | + /// Size of StressTestMessage |
| 98 | + #[arg(long, env, required_if_eq_any([("mode", "one"), ("mode", "all"), ("mode", "rr")]))] |
| 99 | + pub message_size_bytes: Option<usize>, |
| 100 | + |
| 101 | + /// The time to sleep between broadcasts of StressTestMessage in milliseconds |
| 102 | + #[arg(long, env, required_if_eq_any([("mode", "one"), ("mode", "all"), ("mode", "rr")]))] |
| 103 | + pub heartbeat_millis: Option<u64>, |
| 104 | + |
| 105 | + /// Cool down duration between configuration changes in seconds - for Explore mode |
| 106 | + #[arg(long, env, required_if_eq("mode", "explore"))] |
| 107 | + pub explore_cool_down_duration_seconds: Option<u64>, |
| 108 | + |
| 109 | + /// Duration to run each configuration in seconds - for Explore mode |
| 110 | + #[arg(long, env, required_if_eq("mode", "explore"))] |
| 111 | + pub explore_run_duration_seconds: Option<u64>, |
| 112 | + |
| 113 | + /// Minimum throughput in bytes per second - for Explore mode |
| 114 | + #[arg(long, env, required_if_eq("mode", "explore"))] |
| 115 | + pub explore_min_throughput_byte_per_seconds: Option<f64>, |
| 116 | + |
| 117 | + /// Minimum message size in bytes - for Explore mode |
| 118 | + #[arg(long, env, required_if_eq("mode", "explore"))] |
| 119 | + pub explore_min_message_size_bytes: Option<usize>, |
| 120 | + |
| 121 | + /// The timeout in seconds for the node. |
| 122 | + /// When the node runs for longer than this, it will be killed. |
| 123 | + #[arg(long, env)] |
| 124 | + pub timeout: u64, |
| 125 | +} |
0 commit comments