diff --git a/run_cgw.sh b/run_cgw.sh index 62464fb..c37a424 100755 --- a/run_cgw.sh +++ b/run_cgw.sh @@ -111,6 +111,7 @@ docker run \ -e CGW_DB_PASSWORD \ -e CGW_REDIS_HOST \ -e CGW_REDIS_PORT \ + -e CGW_FEATURE_TOPOMAP_DISABLE \ -e CGW_METRICS_PORT \ -e CGW_ALLOW_CERT_MISMATCH \ -d -t --network=host --name $2 $1 ucentral-cgw diff --git a/src/cgw_connection_processor.rs b/src/cgw_connection_processor.rs index dfc5365..efc4837 100644 --- a/src/cgw_connection_processor.rs +++ b/src/cgw_connection_processor.rs @@ -69,16 +69,18 @@ pub struct CGWConnectionProcessor { pub addr: SocketAddr, pub idx: i64, pub group_id: i32, + pub feature_topomap_enabled: bool, } impl CGWConnectionProcessor { pub fn new(server: Arc, conn_idx: i64, addr: SocketAddr) -> Self { let conn_processor: CGWConnectionProcessor = CGWConnectionProcessor { - cgw_server: server, + cgw_server: server.clone(), serial: MacAddress::default(), addr, idx: conn_idx, group_id: 0, + feature_topomap_enabled: server.feature_topomap_enabled, }; conn_processor @@ -277,9 +279,11 @@ impl CGWConnectionProcessor { cgw_ucentral_event_parse(&device_type, &payload, timestamp.timestamp()) { if let CGWUCentralEventType::State(_) = evt.evt_type { - let topo_map = CGWUCentralTopologyMap::get_ref(); - topo_map.process_state_message(&device_type, evt).await; - topo_map.debug_dump_map().await; + if self.feature_topomap_enabled { + let topo_map = CGWUCentralTopologyMap::get_ref(); + topo_map.process_state_message(&device_type, evt).await; + topo_map.debug_dump_map().await; + } } else if let CGWUCentralEventType::Reply(content) = evt.evt_type { if *fsm_state != CGWUCentralMessageProcessorState::ResultPending { error!( @@ -298,11 +302,13 @@ impl CGWConnectionProcessor { *fsm_state = CGWUCentralMessageProcessorState::Idle; debug!("Got reply event for pending request id: {}", pending_req_id); } else if let CGWUCentralEventType::RealtimeEvent(_) = evt.evt_type { - let topo_map = CGWUCentralTopologyMap::get_ref(); - topo_map - .process_device_topology_event(&device_type, evt) - .await; - topo_map.debug_dump_map().await; + if self.feature_topomap_enabled { + let topo_map = CGWUCentralTopologyMap::get_ref(); + topo_map + .process_device_topology_event(&device_type, evt) + .await; + topo_map.debug_dump_map().await; + } } } diff --git a/src/cgw_connection_server.rs b/src/cgw_connection_server.rs index ed03ac1..288ebf6 100644 --- a/src/cgw_connection_server.rs +++ b/src/cgw_connection_server.rs @@ -152,6 +152,10 @@ pub struct CGWConnectionServer { // Internal CGW Devices cache // Key: device MAC, Value: Device devices_cache: Arc>, + + // User-supplied arguments can disable state/realtime events + // processing by underlying connections processors. + pub feature_topomap_enabled: bool, } enum CGWNBApiParsedMsgType { @@ -282,6 +286,7 @@ impl CGWConnectionServer { mbox_relayed_messages_handle: nb_api_tx, mbox_relay_msg_runtime_handle: relay_msg_mbox_runtime_handle, devices_cache: Arc::new(RwLock::new(CGWDevicesCache::new())), + feature_topomap_enabled: app_args.feature_topomap_enabled, }); let server_clone = server.clone(); @@ -1308,8 +1313,10 @@ impl CGWConnectionServer { ); } - let topo_map = CGWUCentralTopologyMap::get_ref(); - topo_map.insert_device(&device_mac).await; + if self.feature_topomap_enabled { + let topo_map = CGWUCentralTopologyMap::get_ref(); + topo_map.insert_device(&device_mac).await; + } connmap_w_lock.insert(device_mac, conn_processor_mbox_tx); @@ -1340,8 +1347,10 @@ impl CGWConnectionServer { } } - let topo_map = CGWUCentralTopologyMap::get_ref(); - topo_map.remove_device(&device_mac).await; + if self.feature_topomap_enabled { + let topo_map = CGWUCentralTopologyMap::get_ref(); + topo_map.remove_device(&device_mac).await; + } CGWMetrics::get_ref().change_counter( CGWMetricsCounterType::ConnectionsNum, diff --git a/src/main.rs b/src/main.rs index 7ce7ae7..55d4b47 100644 --- a/src/main.rs +++ b/src/main.rs @@ -95,6 +95,7 @@ const CGW_DEFAULT_REDIS_HOST: &str = "localhost"; const CGW_DEFAULT_REDIS_PORT: u16 = 6379; const CGW_DEFAULT_ALLOW_CERT_MISMATCH: &str = "no"; const CGW_DEFAULT_METRICS_PORT: u16 = 8080; +const CGW_DEFAULT_TOPOMAP_STATE: bool = true; /// CGW server pub struct AppArgs { @@ -158,6 +159,9 @@ pub struct AppArgs { /// PORT to connect to Metrics metrics_port: u16, + + /// Topomap featue status (enabled/disabled) + feature_topomap_enabled: bool, } impl AppArgs { @@ -393,6 +397,11 @@ impl AppArgs { Err(_) => CGW_DEFAULT_METRICS_PORT, }; + let feature_topomap_enabled: bool = match env::var("CGW_FEATURE_TOPOMAP_DISABLE") { + Ok(_) => false, + Err(_) => CGW_DEFAULT_TOPOMAP_STATE, + }; + Ok(AppArgs { log_level, cgw_id, @@ -419,6 +428,7 @@ impl AppArgs { redis_port, allow_mismatch, metrics_port, + feature_topomap_enabled, }) } } @@ -627,6 +637,10 @@ async fn main() -> Result<()> { // Configure logger setup_logger(args.log_level); + if !args.feature_topomap_enabled { + warn!("CGW_FEATURE_TOPOMAP_DISABLE is set, TOPO MAP feature will be disabled (realtime events / state processing)"); + } + info!( "Starting CGW application, rev tag: {}", env::var("CGW_CONTAINER_BUILD_REV").unwrap_or("".to_string())