Skip to content
This repository was archived by the owner on Jan 22, 2025. It is now read-only.

Commit 66e30e6

Browse files
committed
Fix Cleanup
1 parent 7c964d5 commit 66e30e6

File tree

1 file changed

+11
-73
lines changed

1 file changed

+11
-73
lines changed

net-shaper/src/main.rs

Lines changed: 11 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -306,22 +306,6 @@ fn insert_tc_ifb_netem(class: &str, handle: &str, filter: &str) -> bool {
306306
run("tc", &args, "Failed to add tc child", "tc add child", false)
307307
}
308308

309-
fn delete_tc_ifb_netem(interface: &str, class: &str, handle: &str, filter: &str) {
310-
let mut filters: Vec<&str> = filter.split(' ').collect();
311-
let mut args = vec![
312-
"qdisc", "delete", "dev", interface, "parent", class, "handle", handle, "netem",
313-
];
314-
args.append(&mut filters);
315-
// tc qdisc delete dev <if> parent <class> handle <handle>: netem <filters>
316-
run(
317-
"tc",
318-
&args,
319-
"Failed to delete child qdisc",
320-
"tc delete child qdisc",
321-
true,
322-
);
323-
}
324-
325309
fn insert_tos_ifb_filter(class: &str, tos: &str) -> bool {
326310
// tc filter add dev ifb0 protocol ip parent 1: prio 1 u32 match ip tos <tos> 0xff flowid <class>
327311
run(
@@ -336,20 +320,6 @@ fn insert_tos_ifb_filter(class: &str, tos: &str) -> bool {
336320
)
337321
}
338322

339-
fn delete_tos_filter(interface: &str, class: &str, tos: &str) {
340-
// tc filter delete dev <if> protocol ip parent 1: prio 10 u32 match ip tos <tos> 0xff flowid <class>
341-
run(
342-
"tc",
343-
&[
344-
"filter", "delete", "dev", interface, "protocol", "ip", "parent", "1:", "prio", "1",
345-
"u32", "match", "ip", "tos", tos, "0xff", "flowid", class,
346-
],
347-
"Failed to delete tos filter",
348-
"tc delete filter",
349-
true,
350-
);
351-
}
352-
353323
fn insert_default_ifb_filter(class: &str) -> bool {
354324
// tc filter add dev ifb0 parent 1: protocol all prio 2 u32 match u32 0 0 flowid 1:<class>
355325
run(
@@ -486,45 +456,14 @@ fn shape_network_steps(
486456
true
487457
}
488458

489-
fn cleanup_network(matches: &ArgMatches) {
490-
let config_path = PathBuf::from(value_t_or_exit!(matches, "file", String));
491-
let config = fs::read_to_string(&config_path).expect("Unable to read config file");
492-
let topology: NetworkTopology =
493-
serde_json::from_str(&config).expect("Failed to parse log as JSON");
494-
495-
if !topology.verify() {
496-
panic!("Failed to verify the configuration file");
459+
fn parse_interface(interfaces: &str) -> &str {
460+
for line in interfaces.lines() {
461+
if line != "ifb0" {
462+
return line;
463+
}
497464
}
498465

499-
let network_size = value_t_or_exit!(matches, "size", u64);
500-
let my_index = value_t_or_exit!(matches, "position", u64);
501-
let interface = value_t_or_exit!(matches, "iface", String);
502-
503-
assert!(my_index < network_size);
504-
505-
println!(
506-
"cleanup: my_index: {}, network_size: {}, partitions: {:?}",
507-
my_index, network_size, topology.partitions
508-
);
509-
let my_partition = identify_my_partition(&topology.partitions, my_index + 1, network_size);
510-
println!("My cleanup partition is {}", my_partition);
511-
512-
topology.interconnects.iter().for_each(|i| {
513-
if i.b as usize == my_partition {
514-
let handle = (i.a + 1).to_string();
515-
// First valid class is 1:1
516-
let class = format!("1:{}", i.a + 1);
517-
let tos_string = i.a.to_string();
518-
delete_tos_filter(interface.as_str(), class.as_str(), tos_string.as_str());
519-
delete_tc_ifb_netem(
520-
interface.as_str(),
521-
class.as_str(),
522-
handle.as_str(),
523-
i.config.as_str(),
524-
);
525-
}
526-
});
527-
force_cleanup_network(&interface);
466+
panic!("No valid interfaces");
528467
}
529468

530469
fn force_cleanup_network(interface: &str) {
@@ -638,10 +577,6 @@ fn main() {
638577
.help("Position of current node in the network"),
639578
),
640579
)
641-
.subcommand(
642-
SubCommand::with_name("force_cleanup")
643-
.about("Remove the network filters")
644-
)
645580
.subcommand(
646581
SubCommand::with_name("configure")
647582
.about("Generate a config file")
@@ -684,8 +619,11 @@ fn main() {
684619

685620
match matches.subcommand() {
686621
("shape", Some(args_matches)) => shape_network(args_matches),
687-
("cleanup", Some(args_matches)) => cleanup_network(args_matches),
688-
("force_cleanup", Some(args_matches)) => force_cleanup_network(&value_t_or_exit!(args_matches, "iface", String)),
622+
("cleanup", Some(args_matches)) => {
623+
let interfaces = value_t_or_exit!(args_matches, "iface", String);
624+
let iface = parse_interface(&interfaces);
625+
force_cleanup_network(iface)
626+
}
689627
("configure", Some(args_matches)) => configure(args_matches),
690628
_ => {}
691629
};

0 commit comments

Comments
 (0)