From ea6e5cf7612294be2fab994d89637f29877d389b Mon Sep 17 00:00:00 2001 From: Mike Hansen Date: Mon, 15 Mar 2021 11:49:08 -0400 Subject: [PATCH] WIFI-1698: Services - RadSEC certificates WIFI-1717: Gateway: Handle table state changes for APC_State --- .../OpensyncExternalIntegrationCloud.java | 77 +++++++++++++------ .../integration/utils/MqttStatsPublisher.java | 5 ++ .../opensync/ovsdb/dao/OvsdbRadSecConfig.java | 23 +++++- .../opensync/ovsdb/dao/OvsdbSsidConfig.java | 32 +++++--- 4 files changed, 101 insertions(+), 36 deletions(-) diff --git a/opensync-ext-cloud/src/main/java/com/telecominfraproject/wlan/opensync/external/integration/OpensyncExternalIntegrationCloud.java b/opensync-ext-cloud/src/main/java/com/telecominfraproject/wlan/opensync/external/integration/OpensyncExternalIntegrationCloud.java index e5659cb..882d6ba 100644 --- a/opensync-ext-cloud/src/main/java/com/telecominfraproject/wlan/opensync/external/integration/OpensyncExternalIntegrationCloud.java +++ b/opensync-ext-cloud/src/main/java/com/telecominfraproject/wlan/opensync/external/integration/OpensyncExternalIntegrationCloud.java @@ -103,6 +103,9 @@ import com.telecominfraproject.wlan.status.models.Status; import com.telecominfraproject.wlan.status.models.StatusCode; import com.telecominfraproject.wlan.status.models.StatusDataType; import com.telecominfraproject.wlan.status.network.models.NetworkAdminStatusData; +import com.telecominfraproject.wlan.systemevent.equipment.realtime.ApcElectionEvent; +import com.telecominfraproject.wlan.systemevent.equipment.realtime.RealTimeEventType; +import com.telecominfraproject.wlan.systemevent.equipment.realtime.ApcElectionEvent.ApcMode; import sts.OpensyncStats.Report; import traffic.NetworkMetadata.FlowReport; @@ -2393,7 +2396,8 @@ public class OpensyncExternalIntegrationCloud implements OpensyncExternalIntegra public void apcStateDbTableUpdate(Map apcStateAttributes, String apId, RowUpdateOperation rowUpdateOperation) { - LOG.info("apcStateDbTableUpdate {} operations on AP {} with values {} ", rowUpdateOperation, apId, apcStateAttributes); + LOG.info("apcStateDbTableUpdate {} operations on AP {} with values {} ", rowUpdateOperation, apId, + apcStateAttributes); OvsdbSession ovsdbSession = ovsdbSessionMapInterface.getSession(apId); @@ -2418,7 +2422,27 @@ public class OpensyncExternalIntegrationCloud implements OpensyncExternalIntegra return; } + ApcElectionEvent electionEvent = new ApcElectionEvent(RealTimeEventType.APC_Election_event, customerId, + customerId, equipmentId, System.currentTimeMillis()); + if (rowUpdateOperation.equals(RowUpdateOperation.DELETE)) { + try { + electionEvent.setApcBackupDesignatedRouterIpAddress( + InetAddress.getByName(apcStateAttributes.get("backupDesignatedRouterIp"))); + } catch (UnknownHostException e) { + LOG.error("UnknownHost for backupDesignatedRouterIp", e); + } + try { + electionEvent.setApcDesignatedRouterIpAddress( + InetAddress.getByName(apcStateAttributes.get("designatedRouterIp"))); + } catch (UnknownHostException e) { + LOG.error("UnknownHost for designatedRouterIp", e); + } + electionEvent.setApcMode(ApcMode.valueOf(apcStateAttributes.get("mode"))); + electionEvent.setEnabled(Boolean.valueOf(apcStateAttributes.get("enabled"))); + electionEvent.setLocationId(ce.getLocationId()); + + electionEvent.setRadiusProxyAddress(null); Status protocolStatus; EquipmentProtocolStatusData protocolStatusData; protocolStatus = statusServiceInterface.getOrNull(customerId, equipmentId, StatusDataType.PROTOCOL); @@ -2428,10 +2452,10 @@ public class OpensyncExternalIntegrationCloud implements OpensyncExternalIntegra protocolStatusData.setIsApcConnected(false); protocolStatusData.setReportedApcAddress(null); protocolStatusData.setRadiusProxyAddress(null); - protocolStatus.setDetails(protocolStatusData); protocolStatus = statusServiceInterface.update(protocolStatus); + electionEvent.setLocalIpAddress(protocolStatusData.getReportedIpV4Addr()); LOG.info("apcStateDbTableUpdate for {} protocolStatus {}", rowUpdateOperation, protocolStatus); } } else { @@ -2442,34 +2466,43 @@ public class OpensyncExternalIntegrationCloud implements OpensyncExternalIntegra if (protocolStatus != null) { protocolStatusData = (EquipmentProtocolStatusData) protocolStatus.getDetails(); protocolStatusData.setLastApcUpdate(System.currentTimeMillis()); - - if (apcStateAttributes.containsKey("mode")) { - String mode = apcStateAttributes.get("mode"); - if (mode.equals("DR")) { - String drAddr = apcStateAttributes.get("designatedRouterIp"); - protocolStatusData.setReportedApcAddress(InetAddress.getByName(drAddr)); - protocolStatusData.setRadiusProxyAddress(InetAddress.getByName(drAddr)); - protocolStatusData - .setIsApcConnected((drAddr == null || drAddr.equals("0.0.0.0")) ? false : true); - } else if (mode.equals("BDR")) { - String bdrAddr = apcStateAttributes.get("backupDesignatedRouterIp"); - protocolStatusData.setReportedApcAddress(InetAddress.getByName(bdrAddr)); - protocolStatusData.setRadiusProxyAddress(InetAddress.getByName(bdrAddr)); - protocolStatusData - .setIsApcConnected((bdrAddr == null || bdrAddr.equals("0.0.0.0")) ? false : true); - } else if (mode.equals("SR")) { - // TODO: do we set for this scenario? - } else if (mode.equals("NC")) { - protocolStatusData.setIsApcConnected(false); - } + String mode = apcStateAttributes.get("mode"); + String drAddr = apcStateAttributes.get("designatedRouterIp"); + String bdrAddr = apcStateAttributes.get("backupDesignatedRouterIp"); + if (mode.equals("DR")) { + protocolStatusData.setReportedApcAddress(InetAddress.getByName(drAddr)); + protocolStatusData.setRadiusProxyAddress(InetAddress.getByName(drAddr)); + protocolStatusData + .setIsApcConnected((drAddr == null || drAddr.equals("0.0.0.0")) ? false : true); + } else if (mode.equals("BDR")) { + protocolStatusData.setReportedApcAddress(InetAddress.getByName(bdrAddr)); + protocolStatusData.setRadiusProxyAddress(InetAddress.getByName(bdrAddr)); + protocolStatusData + .setIsApcConnected((bdrAddr == null || bdrAddr.equals("0.0.0.0")) ? false : true); + } else if (mode.equals("SR")) { + // TODO: do we set for this scenario? + } else if (mode.equals("NC")) { + protocolStatusData.setIsApcConnected(false); } protocolStatus.setDetails(protocolStatusData); protocolStatus = statusServiceInterface.update(protocolStatus); + + electionEvent.setApcDesignatedRouterIpAddress( + InetAddress.getByName(drAddr)); + electionEvent.setApcBackupDesignatedRouterIpAddress( + InetAddress.getByName(bdrAddr)); + electionEvent.setLocalIpAddress(protocolStatusData.getReportedIpV4Addr()); + electionEvent.setApcMode(ApcMode.valueOf(apcStateAttributes.get("mode"))); + electionEvent.setEnabled(Boolean.valueOf(apcStateAttributes.get("enabled"))); + electionEvent.setLocationId(ce.getLocationId()); LOG.info("apcStateDbTableUpdate for {} protocolStatus {}", rowUpdateOperation, protocolStatus); } } catch (UnknownHostException e) { LOG.error("Unknown host for radius proxy.", e); } } + + mqttMessageProcessor.publishSystemEventFromTableStateMonitor(electionEvent); + } } diff --git a/opensync-ext-cloud/src/main/java/com/telecominfraproject/wlan/opensync/external/integration/utils/MqttStatsPublisher.java b/opensync-ext-cloud/src/main/java/com/telecominfraproject/wlan/opensync/external/integration/utils/MqttStatsPublisher.java index 4e87037..15985f7 100644 --- a/opensync-ext-cloud/src/main/java/com/telecominfraproject/wlan/opensync/external/integration/utils/MqttStatsPublisher.java +++ b/opensync-ext-cloud/src/main/java/com/telecominfraproject/wlan/opensync/external/integration/utils/MqttStatsPublisher.java @@ -72,6 +72,7 @@ import com.telecominfraproject.wlan.status.models.Status; import com.telecominfraproject.wlan.status.models.StatusCode; import com.telecominfraproject.wlan.status.models.StatusDataType; import com.telecominfraproject.wlan.status.network.models.NetworkAdminStatusData; +import com.telecominfraproject.wlan.systemevent.models.SystemEvent; import sts.OpensyncStats; import sts.OpensyncStats.AssocType; @@ -269,6 +270,10 @@ public class MqttStatsPublisher { } + public void publishSystemEventFromTableStateMonitor(SystemEvent event) { + cloudEventDispatcherInterface.publishEvent(event); + } + void publishEvents(Report report, int customerId, long equipmentId, String apId, long locationId) { realtimeEventPublisher.publishSipCallEvents(customerId, equipmentId, locationId, report.getVideoVoiceReportList()); diff --git a/opensync-gateway/src/main/java/com/telecominfraproject/wlan/opensync/ovsdb/dao/OvsdbRadSecConfig.java b/opensync-gateway/src/main/java/com/telecominfraproject/wlan/opensync/ovsdb/dao/OvsdbRadSecConfig.java index 310b569..743055b 100644 --- a/opensync-gateway/src/main/java/com/telecominfraproject/wlan/opensync/ovsdb/dao/OvsdbRadSecConfig.java +++ b/opensync-gateway/src/main/java/com/telecominfraproject/wlan/opensync/ovsdb/dao/OvsdbRadSecConfig.java @@ -69,14 +69,13 @@ public class OvsdbRadSecConfig extends OvsdbDaoBase { private void configureRadiusServers(OvsdbClient ovsdbClient, OpensyncAPConfig apConfig, List operations) throws OvsdbClientException, InterruptedException, ExecutionException, TimeoutException { + for (RadSecConfiguration rsc : ((ApNetworkConfiguration) apConfig.getApProfile().getDetails()) .getRadSecConfigurations()) { Map updateColumns = new HashMap<>(); updateColumns.put("server", new Atom<>(rsc.getServer().getHostAddress())); - updateColumns.put("client_cert", new Atom<>(externalFileStoreURL + rsc.getClientCert().getApExportUrl())); + getCertificateUrls(rsc, updateColumns); updateColumns.put("radius_config_name", new Atom<>(rsc.getName())); - updateColumns.put("client_key", new Atom<>(externalFileStoreURL + rsc.getClientKey().getApExportUrl())); - updateColumns.put("ca_cert", new Atom<>(externalFileStoreURL + rsc.getCaCert().getApExportUrl())); updateColumns.put("passphrase", new Atom<>(rsc.getPassphrase())); Row row = new Row(updateColumns); operations.add(new Insert(radiusConfigDbTable, row)); @@ -92,6 +91,24 @@ public class OvsdbRadSecConfig extends OvsdbDaoBase { } } + private void getCertificateUrls(RadSecConfiguration rsc, Map updateColumns) { + String clientCertFilestoreUrl = externalFileStoreURL + rsc.getClientCert().getApExportUrl(); + String clientKeyFilestoreUrl = externalFileStoreURL + rsc.getClientKey().getApExportUrl(); + String caCertFilestoreUrl = externalFileStoreURL + rsc.getCaCert().getApExportUrl(); + if (!clientCertFilestoreUrl.contains("filestore")) { + clientCertFilestoreUrl = externalFileStoreURL + "/filestore/" + rsc.getClientCert().getApExportUrl(); + } + if (!clientKeyFilestoreUrl.contains("filestore")) { + clientKeyFilestoreUrl = externalFileStoreURL + "/filestore/" + rsc.getClientKey().getApExportUrl(); + } + if (!caCertFilestoreUrl.contains("filestore")) { + caCertFilestoreUrl = externalFileStoreURL + "/filestore/" + rsc.getCaCert().getApExportUrl(); + } + updateColumns.put("client_cert", new Atom<>(clientCertFilestoreUrl)); + updateColumns.put("client_key", new Atom<>(clientKeyFilestoreUrl)); + updateColumns.put("ca_cert", new Atom<>(caCertFilestoreUrl)); + } + private void configureRealmForRadiusServers(OvsdbClient ovsdbClient, OpensyncAPConfig apConfig) throws OvsdbClientException, InterruptedException, ExecutionException, TimeoutException { List operations; diff --git a/opensync-gateway/src/main/java/com/telecominfraproject/wlan/opensync/ovsdb/dao/OvsdbSsidConfig.java b/opensync-gateway/src/main/java/com/telecominfraproject/wlan/opensync/ovsdb/dao/OvsdbSsidConfig.java index 8e7f5d5..5babefe 100644 --- a/opensync-gateway/src/main/java/com/telecominfraproject/wlan/opensync/ovsdb/dao/OvsdbSsidConfig.java +++ b/opensync-gateway/src/main/java/com/telecominfraproject/wlan/opensync/ovsdb/dao/OvsdbSsidConfig.java @@ -699,8 +699,21 @@ public class OvsdbSsidConfig extends OvsdbDaoBase { captiveMap.put("login_success_text", captiveProfileDetails.getSuccessPageMarkdownText()); captiveMap.put("authentication", getCaptiveAuthentication(captiveProfileDetails.getAuthenticationType())); - if (!externalFileStoreURL.endsWith("/filestore/")) { - externalFileStoreURL = externalFileStoreURL + "/filestore/"; + if (captiveProfileDetails.getLogoFile() != null) { + String splashLogoUrl = externalFileStoreURL + captiveProfileDetails.getLogoFile().getApExportUrl(); + if (!splashLogoUrl.contains("filestore")) { + splashLogoUrl = externalFileStoreURL + "/filestore/" + captiveProfileDetails.getLogoFile().getApExportUrl(); + } + captiveMap.put("splash_page_logo", + splashLogoUrl); + } + if (captiveProfileDetails.getBackgroundFile() != null) { + String splashBackgroundUrl = externalFileStoreURL + captiveProfileDetails.getBackgroundFile().getApExportUrl(); + if (!splashBackgroundUrl.contains("filestore")) { + splashBackgroundUrl = externalFileStoreURL + "/filestore/" + captiveProfileDetails.getBackgroundFile().getApExportUrl(); + } + captiveMap.put("splash_page_background_logo", + splashBackgroundUrl); } if (captiveProfileDetails.getAuthenticationType() .equals(CaptivePortalAuthenticationType.username)) { @@ -711,16 +724,13 @@ public class OvsdbSsidConfig extends OvsdbDaoBase { mfi.setFileCategory(FileCategory.UsernamePasswordList); mfi.setFileType(FileType.TEXT); mfi.setApExportUrl(userFilepath.getFileName().toString()); - captiveMap.put("username_password_file", externalFileStoreURL + mfi.getApExportUrl()); - } - if (captiveProfileDetails.getLogoFile() != null) { - captiveMap.put("splash_page_logo", - externalFileStoreURL + captiveProfileDetails.getLogoFile().getApExportUrl()); - } - if (captiveProfileDetails.getBackgroundFile() != null) { - captiveMap.put("splash_page_background_logo", - externalFileStoreURL + captiveProfileDetails.getBackgroundFile().getApExportUrl()); + String usernamePasswordFileUrl = externalFileStoreURL + mfi.getApExportUrl(); + if (!usernamePasswordFileUrl.contains("filestore")) { + usernamePasswordFileUrl = externalFileStoreURL + "/filestore/" + mfi.getApExportUrl(); + } + captiveMap.put("username_password_file", usernamePasswordFileUrl); } + LOG.debug("captiveMap {}", captiveMap); walledGardenAllowlist.addAll(captiveProfileDetails.getWalledGardenAllowlist());