Skip to content

Commit

Permalink
Merge pull request #12 from BugenZhao/bz-dump-targets
Browse files Browse the repository at this point in the history
tr: allow dumping targets
  • Loading branch information
BugenZhao authored Dec 11, 2020
2 parents 905f579 + 32c89aa commit 9aaa6b0
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "flashroute_rs"
version = "0.1.0"
version = "0.1.2"
authors = [
"Bugen Zhao <[email protected]>",
"Zhengdong Wang <[email protected]>",
Expand Down
2 changes: 2 additions & 0 deletions src/opt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ pub struct Opt {
pub salt: u16,
#[structopt(long)]
pub dry_run: bool,
#[structopt(long)]
pub dump_targets: Option<PathBuf>,
#[structopt(short = "D", long)]
pub debug: bool,

Expand Down
16 changes: 16 additions & 0 deletions src/tracerouter.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
use std::{
io::Write,
net::Ipv4Addr,
path::PathBuf,
sync::{
atomic::{AtomicBool, AtomicU64, Ordering},
Arc,
Expand Down Expand Up @@ -56,6 +58,11 @@ impl Tracerouter {
log::info!("Initializing targets...");
let targets = Self::generate_targets()?;

if let Some(path) = OPT.dump_targets.clone() {
log::info!("Dumping targets...");
Self::dump_targets(&targets, &path)?;
}

Ok(Self {
targets: Arc::new(targets),
..Self::default()
Expand Down Expand Up @@ -129,6 +136,15 @@ impl Tracerouter {
}
}
}

fn dump_targets(targets: &DcbMap, path: &PathBuf) -> Result<()> {
let mut file = std::fs::File::create(path)?;
for DstCtrlBlock { addr, .. } in targets.values() {
file.write_fmt(format_args!("{}\n", addr.to_string()))?;
}

Ok(())
}
}

impl Tracerouter {
Expand Down

0 comments on commit 9aaa6b0

Please sign in to comment.