Commit eda2a361 authored by Nawasan Wisitsingkhon's avatar Nawasan Wisitsingkhon

add cli/feature: run multiple port

parent 3963dd58
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(author, version, about, long_about = None)] #[command(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