From 512605f63e9f59486b322e409ba5491fa9395676 Mon Sep 17 00:00:00 2001 From: Sviatoslav Boichuk Date: Tue, 30 Jul 2024 15:16:32 +0300 Subject: [PATCH] Do not process lldp & link state data if topology map is disabled --- src/cgw_connection_processor.rs | 9 +++++--- src/cgw_connection_server.rs | 4 ++-- src/cgw_ucentral_ap_parser.rs | 36 ++++++++++++++++++++----------- src/cgw_ucentral_parser.rs | 9 ++++++-- src/cgw_ucentral_switch_parser.rs | 5 +++-- utils/docker/docker-compose.yml | 19 ++++++---------- 6 files changed, 48 insertions(+), 34 deletions(-) diff --git a/src/cgw_connection_processor.rs b/src/cgw_connection_processor.rs index 8a0d62c..9d7abef 100644 --- a/src/cgw_connection_processor.rs +++ b/src/cgw_connection_processor.rs @@ -277,9 +277,12 @@ impl CGWConnectionProcessor { return Ok(CGWConnectionState::ClosedGracefully); } Text(payload) => { - if let Ok(evt) = - cgw_ucentral_event_parse(&device_type, &payload, timestamp.timestamp()) - { + if let Ok(evt) = cgw_ucentral_event_parse( + &device_type, + self.feature_topomap_enabled, + &payload, + timestamp.timestamp(), + ) { kafaka_msg = payload.clone(); if let CGWUCentralEventType::State(_) = evt.evt_type { if let Some(decompressed) = evt.decompressed.clone() { diff --git a/src/cgw_connection_server.rs b/src/cgw_connection_server.rs index 59f591c..082cd06 100644 --- a/src/cgw_connection_server.rs +++ b/src/cgw_connection_server.rs @@ -1449,7 +1449,7 @@ mod tests { #[test] fn can_parse_connect_event() -> Result<()> { let msg = get_connect_json_msg(); - let event: CGWUCentralEvent = cgw_ucentral_ap_parse_message(msg, 0)?; + let event: CGWUCentralEvent = cgw_ucentral_ap_parse_message(false, msg, 0)?; match event.evt_type { CGWUCentralEventType::Connect(_) => { @@ -1467,7 +1467,7 @@ mod tests { fn can_parse_log_event() -> Result<()> { let msg = get_log_json_msg(); - let event: CGWUCentralEvent = cgw_ucentral_ap_parse_message(msg, 0)?; + let event: CGWUCentralEvent = cgw_ucentral_ap_parse_message(false, msg, 0)?; match event.evt_type { CGWUCentralEventType::Log(_) => { diff --git a/src/cgw_ucentral_ap_parser.rs b/src/cgw_ucentral_ap_parser.rs index 7bd966b..8005c88 100644 --- a/src/cgw_ucentral_ap_parser.rs +++ b/src/cgw_ucentral_ap_parser.rs @@ -304,7 +304,11 @@ fn parse_link_state_data( } } -fn parse_state_event_data(map: CGWUCentralJRPCMessage, timestamp: i64) -> Result { +fn parse_state_event_data( + feature_topomap_enabled: bool, + map: CGWUCentralJRPCMessage, + timestamp: i64, +) -> Result { if !map.contains_key("params") { return Err(Error::UCentralParser( "Invalid state event received: params is missing", @@ -350,7 +354,7 @@ fn parse_state_event_data(map: CGWUCentralJRPCMessage, timestamp: i64) -> Result let mut lldp_links: Vec = Vec::new(); let mut clients_links: Vec = Vec::new(); - if state_map.contains_key("lldp-peers") { + if state_map.contains_key("lldp-peers") && feature_topomap_enabled { if let Value::Object(v) = &state_map["lldp-peers"] { parse_lldp_data(v, &mut lldp_links)?; } @@ -359,21 +363,23 @@ fn parse_state_event_data(map: CGWUCentralJRPCMessage, timestamp: i64) -> Result let mut upstream_ifaces: Vec = Vec::new(); let mut downstream_ifaces: Vec = Vec::new(); - if state_map.contains_key("link-state") { + if state_map.contains_key("link-state") && feature_topomap_enabled { if let Value::Object(obj) = &state_map["link-state"] { parse_link_state_data(obj, &mut upstream_ifaces, &mut downstream_ifaces); } } if let Value::Array(arr) = &state_map["interfaces"] { - for interface in arr { - if let Value::Object(iface) = interface { - parse_interface_data( - iface, - &mut clients_links, - &upstream_ifaces, - timestamp, - )?; + if feature_topomap_enabled { + for interface in arr { + if let Value::Object(iface) = interface { + parse_interface_data( + iface, + &mut clients_links, + &upstream_ifaces, + timestamp, + )?; + } } } } @@ -770,7 +776,11 @@ fn parse_realtime_event_data( } } -pub fn cgw_ucentral_ap_parse_message(message: &str, timestamp: i64) -> Result { +pub fn cgw_ucentral_ap_parse_message( + feature_topomap_enabled: bool, + message: &str, + timestamp: i64, +) -> Result { let map: CGWUCentralJRPCMessage = match serde_json::from_str(message) { Ok(m) => m, Err(e) => { @@ -835,7 +845,7 @@ pub fn cgw_ucentral_ap_parse_message(message: &str, timestamp: i64) -> Result Result Result { match device_type { - CGWDeviceType::CGWDeviceAP => cgw_ucentral_ap_parse_message(message, timestamp), - CGWDeviceType::CGWDeviceSwitch => cgw_ucentral_switch_parse_message(message, timestamp), + CGWDeviceType::CGWDeviceAP => { + cgw_ucentral_ap_parse_message(feature_topomap_enabled, message, timestamp) + } + CGWDeviceType::CGWDeviceSwitch => { + cgw_ucentral_switch_parse_message(feature_topomap_enabled, message, timestamp) + } } } diff --git a/src/cgw_ucentral_switch_parser.rs b/src/cgw_ucentral_switch_parser.rs index c015a5b..62a4bf5 100644 --- a/src/cgw_ucentral_switch_parser.rs +++ b/src/cgw_ucentral_switch_parser.rs @@ -124,6 +124,7 @@ fn parse_fdb_data( } pub fn cgw_ucentral_switch_parse_message( + feature_topomap_enabled: bool, message: &str, timestamp: i64, ) -> Result { @@ -195,11 +196,11 @@ pub fn cgw_ucentral_switch_parse_message( } } - if state_map.contains_key("lldp-peers") { + if state_map.contains_key("lldp-peers") && feature_topomap_enabled { parse_lldp_data(&state_map["lldp-peers"], &mut lldp_links, &upstream_port)?; } - if state_map.contains_key("mac-forwarding-table") { + if state_map.contains_key("mac-forwarding-table") && feature_topomap_enabled { parse_fdb_data( &state_map["mac-forwarding-table"], &mut clients_links, diff --git a/utils/docker/docker-compose.yml b/utils/docker/docker-compose.yml index ad6183b..654b513 100644 --- a/utils/docker/docker-compose.yml +++ b/utils/docker/docker-compose.yml @@ -32,18 +32,13 @@ services: image: "postgres:latest" ports: - "5432:5432" - command: - - "postgres" - - "-c" - - "max_connections=400" - - "-c" - - "shared_buffers=20MB" - - "-c" - - "ssl=on" - - "-c" - - "ssl_cert_file=/var/lib/postgresql/certs/server.crt" - - "-c" - - "ssl_key_file=/var/lib/postgresql/certs/server.key" + user: postgres + command: > + bash -c " + chown 999:999 /var/lib/postgresql/certs/server.key && + chmod 600 /var/lib/postgresql/certs/server.key && + postgres -c max_connections=400 -c shared_buffers=20MB -c ssl=on -c ssl_cert_file=/var/lib/postgresql/certs/server.crt -c ssl_key_file=/var/lib/postgresql/certs/server.key + " env_file: - postgresql.env restart: always