-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: get netgen bin setup ready for cli handling
Introduce clap to netgen for CLI args handling add default configs for plugins add startup config for holo Signed-off-by: Paul Wekesa <paul1tw1@gmail.com>
- Loading branch information
Showing
11 changed files
with
375 additions
and
59 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
! | ||
interfaces interface eth-sw1 | ||
type iana-if-type:ethernetCsmacd | ||
! | ||
ipv4 vrrp vrrp-instance 1 | ||
log-state-change true | ||
preempt enabled false | ||
advertise-interval-sec 1 | ||
priority 10 | ||
! | ||
virtual-ipv4-addresses virtual-ipv4-address 10.0.1.5 | ||
! | ||
interfaces interface lo | ||
type iana-if-type:softwareLoopback | ||
ipv4 | ||
! | ||
ipv4 address 1.1.1.1 | ||
prefix-length 32 | ||
! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
! | ||
interfaces interface eth-sw1 | ||
type iana-if-type:ethernetCsmacd | ||
! | ||
ipv4 vrrp vrrp-instance 1 | ||
log-state-change true | ||
preempt enabled false | ||
advertise-interval-sec 1 | ||
priority 20 | ||
! | ||
virtual-ipv4-addresses virtual-ipv4-address 10.0.1.5 | ||
! | ||
interfaces interface lo | ||
type iana-if-type:softwareLoopback | ||
ipv4 | ||
! | ||
ipv4 address 2.2.2.2 | ||
prefix-length 32 | ||
! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
! | ||
interfaces interface eth-sw1 | ||
type iana-if-type:ethernetCsmacd | ||
! | ||
ipv4 vrrp vrrp-instance 1 | ||
log-state-change true | ||
preempt enabled false | ||
advertise-interval-sec 1 | ||
priority 30 | ||
! | ||
virtual-ipv4-addresses virtual-ipv4-address 10.0.1.5 | ||
! | ||
interfaces interface lo | ||
type iana-if-type:softwareLoopback | ||
ipv4 | ||
! | ||
ipv4 address 3.3.3.3 | ||
prefix-length 32 | ||
! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,56 @@ | ||
#![feature(let_chains)] | ||
use netgen::plugins::Config; | ||
use netgen::topology::Topology; | ||
use netgen::{error::Error, Result}; | ||
|
||
use std::fs::File; | ||
|
||
use clap::{command, Arg}; | ||
|
||
#[tokio::main] | ||
async fn main() { | ||
let mut topology: Topology = Topology::new(); | ||
if let Ok(mut config_file) = File::open("./assets/config.yml") | ||
&& let Ok(mut topo_file) = File::open("./assets/sample-top.yml") | ||
{ | ||
// load the base configuration | ||
let config = match Config::from_yaml_file(&mut config_file) { | ||
Ok(config) => Some(config), | ||
Err(_err) => None, | ||
}; | ||
|
||
// load the topology configuration | ||
topology = Topology::from_yaml_file(&mut topo_file, config).unwrap(); | ||
} | ||
async fn main() -> Result<()> { | ||
let matches = command!("netgen") | ||
.arg( | ||
Arg::new("Config File") | ||
.short('c') | ||
.long("config") | ||
.value_name("yaml-file") | ||
.help("the file with plugin configs"), | ||
) | ||
.arg( | ||
Arg::new("Topo File") | ||
.short('t') | ||
.long("topo") | ||
.value_name("yaml-file") | ||
.help("file with the topology"), | ||
) | ||
.get_matches(); | ||
let config = match matches.get_one::<String>("Config File") { | ||
Some(config_file) => { | ||
let mut config_file = File::open(config_file).unwrap(); | ||
Config::from_yaml_file(Some(&mut config_file))? | ||
} | ||
None => Config::from_yaml_file(None)?, | ||
}; | ||
|
||
let topo_file = match matches.get_one::<String>("Topo File") { | ||
Some(topo_file) => topo_file, | ||
None => { | ||
return Err(Error::GeneralError(String::from( | ||
"topolofy file not configured", | ||
))) | ||
} | ||
}; | ||
|
||
let mut topo_file = File::open(topo_file).unwrap(); | ||
let mut topology = Topology::from_yaml_file(&mut topo_file, config).unwrap(); | ||
|
||
// "powers on" all the devices and sets up all the required links | ||
topology.power_on().await.unwrap(); | ||
topology.power_on().await?; | ||
|
||
// runs the plugins in the routers. | ||
// and initiates their startup-config (if present) | ||
topology.run().await?; | ||
|
||
Ok(()) | ||
} |
Oops, something went wrong.