Commit cf57e8b5 authored by Nawasan Wisitsingkhon's avatar Nawasan Wisitsingkhon

Merge branch 'cli/multiport' into cli/update

parents 6da350d0 eda2a361
use clap::{command, Parser, Subcommand};
use crate::{ use crate::{
example::{Controller10, Controller13}, example::{Controller10, Controller13},
openflow::{ofp10::ControllerFrame10, ofp13::ControllerFrame13}, openflow::{ofp10::ControllerFrame10, ofp13::ControllerFrame13},
}; };
use clap::{command, Parser, Subcommand};
use std::thread;
#[derive(Parser)] #[derive(Parser)]
#[command(name = "tenjin",author, version, about, long_about = None)] #[command(name = "tenjin",author, version, about, long_about = None)]
...@@ -18,8 +18,8 @@ enum Commands { ...@@ -18,8 +18,8 @@ enum Commands {
Run { Run {
#[command(subcommand)] #[command(subcommand)]
controller: Option<Controllers>, controller: Option<Controllers>,
#[arg(default_value_t = 6633, short = 'p', long)] #[arg(default_values_t = [6633,6653], short = 'p', long, value_delimiter = ',')]
port: u16, port: Vec<u16>,
#[arg( #[arg(
default_value = "127.0.0.1", default_value = "127.0.0.1",
short = 'l', short = 'l',
...@@ -47,14 +47,26 @@ pub fn system() { ...@@ -47,14 +47,26 @@ pub fn system() {
port, port,
listen, listen,
} => { } => {
let addr = format!("{}:{}", listen.as_str(), port.to_string()); // creat runner function to run inside thread spawn
match controller { let runner = match controller {
Some(controller) => match controller { Some(controller) => match controller {
Controllers::Ctrl13 => Controller13::new().listener(&addr), Controllers::Ctrl13 => |addr: &str| Controller13::new().listener(addr),
Controllers::Ctrl10 => Controller10::new().listener(&addr), Controllers::Ctrl10 => |addr: &str| Controller10::new().listener(addr),
}, },
// Set Default Controller at here // Set Default Controller at here
None => Controller13::new().listener(&addr), None => |addr: &str| Controller13::new().listener(addr),
};
// spawn and run threads
let mut thread_list = Vec::new();
for p in port.iter() {
let addr = format!("{}:{}", listen, p);
let t = thread::spawn(move || {
runner(&addr);
});
thread_list.push(t);
}
for th in thread_list {
let _ = th.join();
} }
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment