Skip to content
This repository has been archived by the owner on Jan 28, 2021. It is now read-only.

Commit

Permalink
fixup! dist/tools/vaina: add VAINA client
Browse files Browse the repository at this point in the history
  • Loading branch information
jeandudey committed May 11, 2020
1 parent 9036a7e commit d5e1045
Showing 1 changed file with 55 additions and 0 deletions.
55 changes: 55 additions & 0 deletions dist/tools/vaina/src/nib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
use std::ffi::OsString;
use std::net::Ipv6Addr;

use clap::{value_t, ArgMatches};

use crate::client::VainaClient;
use crate::msg::Message;
use crate::Error;

/// Router Client Set sub command
pub fn handle_matches(matches: &ArgMatches) -> Result<(), Error> {
match matches.subcommand() {
("add", Some(add_matches)) => add(add_matches)?,
("del", Some(del_matches)) => del(del_matches)?,
_ => println!("{}", matches.usage()),
};

Ok(())
}

fn add(matches: &ArgMatches) -> Result<(), Error> {
let prefix = value_t!(matches, "prefix", u8).unwrap_or_else(|e| e.exit());
let ip = value_t!(matches, "IP", Ipv6Addr).unwrap_or_else(|e| e.exit());
let interface = value_t!(matches, "interface", String).unwrap_or_else(|e| e.exit());
let interface = OsString::from(interface);

let mut client = VainaClient::new(&interface)?;

let msg = Message::NibAdd {
seqno: client.craft_seqno(),
prefix,
ip,
};
client.send_message(&msg)?;

Ok(())
}

fn del(matches: &ArgMatches) -> Result<(), Error> {
let prefix = value_t!(matches, "prefix", u8).unwrap_or_else(|e| e.exit());
let ip = value_t!(matches, "IP", Ipv6Addr).unwrap_or_else(|e| e.exit());
let interface = value_t!(matches, "interface", String).unwrap_or_else(|e| e.exit());
let interface = OsString::from(interface);

let mut client = VainaClient::new(&interface)?;

let msg = Message::NibDel {
seqno: client.craft_seqno(),
prefix,
ip,
};
client.send_message(&msg)?;

Ok(())
}

0 comments on commit d5e1045

Please sign in to comment.