Skip to content

Commit

Permalink
Merge pull request #60 from Telecominfraproject/feat/allow_disabling_…
Browse files Browse the repository at this point in the history
…topomap_processign

CGW: Allow disabling topomap handling through env var
  • Loading branch information
Cahb authored Jul 2, 2024
2 parents 760bb4c + 58e59cc commit 7fa2658
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 13 deletions.
1 change: 1 addition & 0 deletions run_cgw.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
24 changes: 15 additions & 9 deletions src/cgw_connection_processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<CGWConnectionServer>, 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
Expand Down Expand Up @@ -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!(
Expand All @@ -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;
}
}
}

Expand Down
17 changes: 13 additions & 4 deletions src/cgw_connection_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,10 @@ pub struct CGWConnectionServer {
// Internal CGW Devices cache
// Key: device MAC, Value: Device
devices_cache: Arc<RwLock<CGWDevicesCache>>,

// User-supplied arguments can disable state/realtime events
// processing by underlying connections processors.
pub feature_topomap_enabled: bool,
}

enum CGWNBApiParsedMsgType {
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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,
Expand Down
14 changes: 14 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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,
Expand All @@ -419,6 +428,7 @@ impl AppArgs {
redis_port,
allow_mismatch,
metrics_port,
feature_topomap_enabled,
})
}
}
Expand Down Expand Up @@ -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("<CGW-unknown-tag>".to_string())
Expand Down

0 comments on commit 7fa2658

Please sign in to comment.