Skip to content

Commit 9aaa6b0

Browse files
authored
Merge pull request #12 from BugenZhao/bz-dump-targets
tr: allow dumping targets
2 parents 905f579 + 32c89aa commit 9aaa6b0

File tree

4 files changed

+20
-2
lines changed

4 files changed

+20
-2
lines changed

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "flashroute_rs"
3-
version = "0.1.0"
3+
version = "0.1.2"
44
authors = [
55
"Bugen Zhao <[email protected]>",
66
"Zhengdong Wang <[email protected]>",

src/opt.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@ pub struct Opt {
5555
pub salt: u16,
5656
#[structopt(long)]
5757
pub dry_run: bool,
58+
#[structopt(long)]
59+
pub dump_targets: Option<PathBuf>,
5860
#[structopt(short = "D", long)]
5961
pub debug: bool,
6062

src/tracerouter.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
use std::{
2+
io::Write,
23
net::Ipv4Addr,
4+
path::PathBuf,
35
sync::{
46
atomic::{AtomicBool, AtomicU64, Ordering},
57
Arc,
@@ -56,6 +58,11 @@ impl Tracerouter {
5658
log::info!("Initializing targets...");
5759
let targets = Self::generate_targets()?;
5860

61+
if let Some(path) = OPT.dump_targets.clone() {
62+
log::info!("Dumping targets...");
63+
Self::dump_targets(&targets, &path)?;
64+
}
65+
5966
Ok(Self {
6067
targets: Arc::new(targets),
6168
..Self::default()
@@ -129,6 +136,15 @@ impl Tracerouter {
129136
}
130137
}
131138
}
139+
140+
fn dump_targets(targets: &DcbMap, path: &PathBuf) -> Result<()> {
141+
let mut file = std::fs::File::create(path)?;
142+
for DstCtrlBlock { addr, .. } in targets.values() {
143+
file.write_fmt(format_args!("{}\n", addr.to_string()))?;
144+
}
145+
146+
Ok(())
147+
}
132148
}
133149

134150
impl Tracerouter {

0 commit comments

Comments
 (0)