update clap to v3: net-sharper
This commit is contained in:
parent
d8be0d9430
commit
12e24a90a0
@ -10,9 +10,9 @@ homepage = "https://solana.com/"
|
|||||||
publish = false
|
publish = false
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
clap = "2.33.1"
|
|
||||||
rand = "0.7.0"
|
rand = "0.7.0"
|
||||||
serde = "1.0.136"
|
clap = { version = "3.1.5", features = ["cargo"] }
|
||||||
|
serde = { version = "1.0.136", features = ["derive"] }
|
||||||
serde_json = "1.0.79"
|
serde_json = "1.0.79"
|
||||||
solana-logger = { path = "../logger", version = "=1.11.0" }
|
solana-logger = { path = "../logger", version = "=1.11.0" }
|
||||||
|
|
||||||
|
@ -1,9 +1,6 @@
|
|||||||
#![allow(clippy::integer_arithmetic)]
|
#![allow(clippy::integer_arithmetic)]
|
||||||
use {
|
use {
|
||||||
clap::{
|
clap::{crate_description, crate_name, crate_version, Arg, ArgMatches, Command},
|
||||||
crate_description, crate_name, crate_version, value_t, value_t_or_exit, App, Arg,
|
|
||||||
ArgMatches, SubCommand,
|
|
||||||
},
|
|
||||||
rand::{thread_rng, Rng},
|
rand::{thread_rng, Rng},
|
||||||
serde::{Deserialize, Serialize},
|
serde::{Deserialize, Serialize},
|
||||||
std::{fs, io, path::PathBuf},
|
std::{fs, io, path::PathBuf},
|
||||||
@ -369,13 +366,13 @@ fn partition_id_to_tos(partition: usize) -> u8 {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn shape_network(matches: &ArgMatches) {
|
fn shape_network(matches: &ArgMatches) {
|
||||||
let config_path = PathBuf::from(value_t_or_exit!(matches, "file", String));
|
let config_path = PathBuf::from(matches.value_of_t_or_exit::<String>("file"));
|
||||||
let config = fs::read_to_string(&config_path).expect("Unable to read config file");
|
let config = fs::read_to_string(&config_path).expect("Unable to read config file");
|
||||||
let topology: NetworkTopology =
|
let topology: NetworkTopology =
|
||||||
serde_json::from_str(&config).expect("Failed to parse log as JSON");
|
serde_json::from_str(&config).expect("Failed to parse log as JSON");
|
||||||
let interface = value_t_or_exit!(matches, "iface", String);
|
let interface: String = matches.value_of_t_or_exit("iface");
|
||||||
let network_size = value_t_or_exit!(matches, "size", u64);
|
let network_size: u64 = matches.value_of_t_or_exit("size");
|
||||||
let my_index = value_t_or_exit!(matches, "position", u64);
|
let my_index: u64 = matches.value_of_t_or_exit("position");
|
||||||
if !shape_network_steps(&topology, &interface, network_size, my_index) {
|
if !shape_network_steps(&topology, &interface, network_size, my_index) {
|
||||||
delete_ifb(interface.as_str());
|
delete_ifb(interface.as_str());
|
||||||
flush_iptables_rule();
|
flush_iptables_rule();
|
||||||
@ -471,9 +468,9 @@ fn configure(matches: &ArgMatches) {
|
|||||||
let config = if !matches.is_present("random") {
|
let config = if !matches.is_present("random") {
|
||||||
NetworkTopology::new_from_stdin()
|
NetworkTopology::new_from_stdin()
|
||||||
} else {
|
} else {
|
||||||
let max_partitions = value_t!(matches, "max-partitions", usize).unwrap_or(4);
|
let max_partitions: usize = matches.value_of_t("max-partitions").unwrap_or(4);
|
||||||
let max_drop = value_t!(matches, "max-drop", u8).unwrap_or(100);
|
let max_drop: u8 = matches.value_of_t("max-drop").unwrap_or(100);
|
||||||
let max_delay = value_t!(matches, "max-delay", u32).unwrap_or(50);
|
let max_delay: u32 = matches.value_of_t("max-delay").unwrap_or(50);
|
||||||
NetworkTopology::new_random(max_partitions, max_drop, max_delay)
|
NetworkTopology::new_random(max_partitions, max_drop, max_delay)
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -487,15 +484,15 @@ fn configure(matches: &ArgMatches) {
|
|||||||
fn main() {
|
fn main() {
|
||||||
solana_logger::setup();
|
solana_logger::setup();
|
||||||
|
|
||||||
let matches = App::new(crate_name!())
|
let matches = Command::new(crate_name!())
|
||||||
.about(crate_description!())
|
.about(crate_description!())
|
||||||
.version(crate_version!())
|
.version(crate_version!())
|
||||||
.subcommand(
|
.subcommand(
|
||||||
SubCommand::with_name("shape")
|
Command::new("shape")
|
||||||
.about("Shape the network using config file")
|
.about("Shape the network using config file")
|
||||||
.arg(
|
.arg(
|
||||||
Arg::with_name("file")
|
Arg::new("file")
|
||||||
.short("f")
|
.short('f')
|
||||||
.long("file")
|
.long("file")
|
||||||
.value_name("config file")
|
.value_name("config file")
|
||||||
.takes_value(true)
|
.takes_value(true)
|
||||||
@ -503,8 +500,8 @@ fn main() {
|
|||||||
.help("Location of the network config file"),
|
.help("Location of the network config file"),
|
||||||
)
|
)
|
||||||
.arg(
|
.arg(
|
||||||
Arg::with_name("size")
|
Arg::new("size")
|
||||||
.short("s")
|
.short('s')
|
||||||
.long("size")
|
.long("size")
|
||||||
.value_name("network size")
|
.value_name("network size")
|
||||||
.takes_value(true)
|
.takes_value(true)
|
||||||
@ -512,8 +509,8 @@ fn main() {
|
|||||||
.help("Number of nodes in the network"),
|
.help("Number of nodes in the network"),
|
||||||
)
|
)
|
||||||
.arg(
|
.arg(
|
||||||
Arg::with_name("iface")
|
Arg::new("iface")
|
||||||
.short("i")
|
.short('i')
|
||||||
.long("iface")
|
.long("iface")
|
||||||
.value_name("network interface name")
|
.value_name("network interface name")
|
||||||
.takes_value(true)
|
.takes_value(true)
|
||||||
@ -521,8 +518,8 @@ fn main() {
|
|||||||
.help("Name of network interface"),
|
.help("Name of network interface"),
|
||||||
)
|
)
|
||||||
.arg(
|
.arg(
|
||||||
Arg::with_name("position")
|
Arg::new("position")
|
||||||
.short("p")
|
.short('p')
|
||||||
.long("position")
|
.long("position")
|
||||||
.value_name("position of node")
|
.value_name("position of node")
|
||||||
.takes_value(true)
|
.takes_value(true)
|
||||||
@ -531,11 +528,11 @@ fn main() {
|
|||||||
),
|
),
|
||||||
)
|
)
|
||||||
.subcommand(
|
.subcommand(
|
||||||
SubCommand::with_name("cleanup")
|
Command::new("cleanup")
|
||||||
.about("Remove the network filters using config file")
|
.about("Remove the network filters using config file")
|
||||||
.arg(
|
.arg(
|
||||||
Arg::with_name("file")
|
Arg::new("file")
|
||||||
.short("f")
|
.short('f')
|
||||||
.long("file")
|
.long("file")
|
||||||
.value_name("config file")
|
.value_name("config file")
|
||||||
.takes_value(true)
|
.takes_value(true)
|
||||||
@ -543,8 +540,8 @@ fn main() {
|
|||||||
.help("Location of the network config file"),
|
.help("Location of the network config file"),
|
||||||
)
|
)
|
||||||
.arg(
|
.arg(
|
||||||
Arg::with_name("size")
|
Arg::new("size")
|
||||||
.short("s")
|
.short('s')
|
||||||
.long("size")
|
.long("size")
|
||||||
.value_name("network size")
|
.value_name("network size")
|
||||||
.takes_value(true)
|
.takes_value(true)
|
||||||
@ -552,8 +549,8 @@ fn main() {
|
|||||||
.help("Number of nodes in the network"),
|
.help("Number of nodes in the network"),
|
||||||
)
|
)
|
||||||
.arg(
|
.arg(
|
||||||
Arg::with_name("iface")
|
Arg::new("iface")
|
||||||
.short("i")
|
.short('i')
|
||||||
.long("iface")
|
.long("iface")
|
||||||
.value_name("network interface name")
|
.value_name("network interface name")
|
||||||
.takes_value(true)
|
.takes_value(true)
|
||||||
@ -561,8 +558,8 @@ fn main() {
|
|||||||
.help("Name of network interface"),
|
.help("Name of network interface"),
|
||||||
)
|
)
|
||||||
.arg(
|
.arg(
|
||||||
Arg::with_name("position")
|
Arg::new("position")
|
||||||
.short("p")
|
.short('p')
|
||||||
.long("position")
|
.long("position")
|
||||||
.value_name("position of node")
|
.value_name("position of node")
|
||||||
.takes_value(true)
|
.takes_value(true)
|
||||||
@ -571,18 +568,18 @@ fn main() {
|
|||||||
),
|
),
|
||||||
)
|
)
|
||||||
.subcommand(
|
.subcommand(
|
||||||
SubCommand::with_name("configure")
|
Command::new("configure")
|
||||||
.about("Generate a config file")
|
.about("Generate a config file")
|
||||||
.arg(
|
.arg(
|
||||||
Arg::with_name("random")
|
Arg::new("random")
|
||||||
.short("r")
|
.short('r')
|
||||||
.long("random")
|
.long("random")
|
||||||
.required(false)
|
.required(false)
|
||||||
.help("Generate a random config file"),
|
.help("Generate a random config file"),
|
||||||
)
|
)
|
||||||
.arg(
|
.arg(
|
||||||
Arg::with_name("max-partitions")
|
Arg::new("max-partitions")
|
||||||
.short("p")
|
.short('p')
|
||||||
.long("max-partitions")
|
.long("max-partitions")
|
||||||
.value_name("count")
|
.value_name("count")
|
||||||
.takes_value(true)
|
.takes_value(true)
|
||||||
@ -590,8 +587,8 @@ fn main() {
|
|||||||
.help("Maximum number of partitions. Used only with random configuration generation"),
|
.help("Maximum number of partitions. Used only with random configuration generation"),
|
||||||
)
|
)
|
||||||
.arg(
|
.arg(
|
||||||
Arg::with_name("max-drop")
|
Arg::new("max-drop")
|
||||||
.short("d")
|
.short('d')
|
||||||
.long("max-drop")
|
.long("max-drop")
|
||||||
.value_name("percentage")
|
.value_name("percentage")
|
||||||
.takes_value(true)
|
.takes_value(true)
|
||||||
@ -599,8 +596,8 @@ fn main() {
|
|||||||
.help("Maximum amount of packet drop. Used only with random configuration generation"),
|
.help("Maximum amount of packet drop. Used only with random configuration generation"),
|
||||||
)
|
)
|
||||||
.arg(
|
.arg(
|
||||||
Arg::with_name("max-delay")
|
Arg::new("max-delay")
|
||||||
.short("y")
|
.short('y')
|
||||||
.long("max-delay")
|
.long("max-delay")
|
||||||
.value_name("ms")
|
.value_name("ms")
|
||||||
.takes_value(true)
|
.takes_value(true)
|
||||||
@ -611,13 +608,13 @@ fn main() {
|
|||||||
.get_matches();
|
.get_matches();
|
||||||
|
|
||||||
match matches.subcommand() {
|
match matches.subcommand() {
|
||||||
("shape", Some(args_matches)) => shape_network(args_matches),
|
Some(("shape", args_matches)) => shape_network(args_matches),
|
||||||
("cleanup", Some(args_matches)) => {
|
Some(("cleanup", args_matches)) => {
|
||||||
let interfaces = value_t_or_exit!(args_matches, "iface", String);
|
let interfaces: String = args_matches.value_of_t_or_exit("iface");
|
||||||
let iface = parse_interface(&interfaces);
|
let iface = parse_interface(&interfaces);
|
||||||
cleanup_network(iface)
|
cleanup_network(iface)
|
||||||
}
|
}
|
||||||
("configure", Some(args_matches)) => configure(args_matches),
|
Some(("configure", args_matches)) => configure(args_matches),
|
||||||
_ => {}
|
_ => {}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user