11use std:: {
22 borrow:: Cow ,
33 collections:: HashMap ,
4+ path:: PathBuf ,
45 process:: { ExitCode , Stdio , Termination } ,
56 sync:: { atomic:: AtomicBool , Arc } ,
67} ;
@@ -14,18 +15,15 @@ use nix::sys::signal::{self, Signal};
1415use nix:: unistd:: Pid ;
1516use once_cell:: sync:: OnceCell ;
1617use paste:: paste;
18+ use rattan_core:: devices:: bandwidth:: queue:: {
19+ CoDelQueueConfig , DropHeadQueueConfig , DropTailQueueConfig , InfiniteQueueConfig ,
20+ } ;
1721use rattan_core:: devices:: bandwidth:: BwDeviceConfig ;
1822use rattan_core:: devices:: StdPacket ;
1923use rattan_core:: env:: { StdNetEnvConfig , StdNetEnvMode } ;
2024use rattan_core:: metal:: io:: af_packet:: AfPacketDriver ;
2125use rattan_core:: netem_trace:: { Bandwidth , Delay } ;
2226use rattan_core:: radix:: RattanRadix ;
23- use rattan_core:: {
24- config:: RattanGeneralConfig ,
25- devices:: bandwidth:: queue:: {
26- CoDelQueueConfig , DropHeadQueueConfig , DropTailQueueConfig , InfiniteQueueConfig ,
27- } ,
28- } ;
2927use rattan_core:: {
3028 config:: {
3129 BwDeviceBuildConfig , BwReplayDeviceBuildConfig , BwReplayQueueConfig ,
@@ -70,15 +68,6 @@ pub struct Arguments {
7068 #[ command( subcommand) ]
7169 subcommand : Option < CliCommand > ,
7270
73- #[ cfg( feature = "http" ) ]
74- /// Enable HTTP control server
75- #[ arg( long) ]
76- http : bool ,
77- #[ cfg( feature = "http" ) ]
78- /// HTTP control server port (default: 8086)
79- #[ arg( short, long, value_name = "Port" ) ]
80- port : Option < u16 > ,
81-
8271 /// Uplink packet loss
8372 #[ arg( long, global = true , value_name = "Loss" ) ]
8473 uplink_loss : Option < f64 > ,
@@ -131,6 +120,19 @@ pub struct Arguments {
131120 #[ arg( long, global = true , value_name = "JSON" , requires = "downlink-queue" ) ]
132121 downlink_queue_args : Option < String > ,
133122
123+ #[ cfg( feature = "http" ) ]
124+ /// Enable HTTP control server (overwrite config)
125+ #[ arg( long) ]
126+ http : bool ,
127+ #[ cfg( feature = "http" ) ]
128+ /// HTTP control server port (overwrite config) (default: 8086)
129+ #[ arg( short, long, value_name = "Port" ) ]
130+ port : Option < u16 > ,
131+
132+ /// The file to store compressed packet log (overwrite config) (default: None)
133+ #[ arg( long, value_name = "Packet Log File" ) ]
134+ packet_log : Option < PathBuf > ,
135+
134136 /// Enable logging to file
135137 #[ arg( long) ]
136138 file_log : bool ,
@@ -371,7 +373,7 @@ fn main() -> ExitCode {
371373
372374 // Main CLI
373375 let main_cli = || -> rattan_core:: error:: Result < ( ) > {
374- let config = match opts. config {
376+ let mut config = match opts. config {
375377 Some ( ref config_file) => {
376378 info ! ( "Loading config from {}" , config_file) ;
377379 if !std:: path:: Path :: new ( config_file) . exists ( ) {
@@ -386,16 +388,6 @@ fn main() -> ExitCode {
386388 config
387389 }
388390 None => {
389- #[ cfg( feature = "http" ) ]
390- let mut http_config = HttpConfig {
391- enable : opts. http ,
392- ..Default :: default ( )
393- } ;
394- #[ cfg( feature = "http" ) ]
395- if let Some ( port) = opts. port {
396- http_config. port = port;
397- }
398-
399391 let mut devices_config = HashMap :: < String , DeviceBuildConfig < StdPacket > > :: new ( ) ;
400392 let mut links_config = HashMap :: < String , String > :: new ( ) ;
401393 let mut uplink_count = 0 ;
@@ -582,19 +574,31 @@ fn main() -> ExitCode {
582574 server_cores : vec ! [ 3 ] ,
583575 ..Default :: default ( )
584576 } ,
585- #[ cfg( feature = "http" ) ]
586- http : http_config,
587577 devices : devices_config,
588578 links : links_config,
589579 resource : RattanResourceConfig {
590580 memory : None ,
591581 cpu : Some ( vec ! [ 2 ] ) ,
592582 } ,
593- general : RattanGeneralConfig :: new ( ) ,
583+ .. Default :: default ( )
594584 }
595585 }
596586 } ;
587+
588+ // Overwrite config with CLI options
589+ #[ cfg( feature = "http" ) ]
590+ if opts. http {
591+ config. http . enable = true ;
592+ }
593+ #[ cfg( feature = "http" ) ]
594+ if let Some ( port) = opts. port {
595+ config. http . port = port;
596+ }
597+ if let Some ( packet_log) = opts. packet_log {
598+ config. general . packet_log = Some ( packet_log) ;
599+ }
597600 debug ! ( ?config) ;
601+
598602 if config. devices . is_empty ( ) {
599603 warn ! ( "No devices specified in config" ) ;
600604 }
0 commit comments