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 43cb881..5fa72dc 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 @@ -4,6 +4,7 @@ import java.net.Inet4Address; import java.net.InetAddress; import java.net.UnknownHostException; import java.util.ArrayList; +import java.util.EnumMap; import java.util.HashMap; import java.util.HashSet; import java.util.List; @@ -315,7 +316,8 @@ public class OpensyncExternalIntegrationCloud implements OpensyncExternalIntegra if (apElementConfig == null) { apElementConfig = ApElementConfiguration.createWithDefaults(); ce.setDetails(apElementConfig); - needToUpdateEquipment = true; + ce = equipmentServiceInterface.update(ce); + apElementConfig = (ApElementConfiguration) ce.getDetails(); } if (apElementConfig.getDeviceName() == null @@ -333,76 +335,60 @@ public class OpensyncExternalIntegrationCloud implements OpensyncExternalIntegra Map advancedRadioMap = apElementConfig.getAdvancedRadioMap(); Map radioMap = apElementConfig.getRadioMap(); - if (advancedRadioMap == null) { - advancedRadioMap = new HashMap<>(); + if (apElementConfig.getAdvancedRadioMap() == null) { + advancedRadioMap = new EnumMap<>(RadioType.class); apElementConfig.setAdvancedRadioMap(advancedRadioMap); needToUpdateEquipment = true; } if (radioMap == null) { - radioMap = new HashMap<>(); + radioMap = new EnumMap<>(RadioType.class); apElementConfig.setRadioMap(radioMap); needToUpdateEquipment = true; } Set radiosFromAp = new HashSet<>(); + connectNodeInfo.wifiRadioStates.keySet().forEach(k -> { + radiosFromAp.add(OvsdbToWlanCloudTypeMappingUtility.getRadioTypeForOvsdbRadioFreqBand(k)); + }); // add missing radio configs from the AP into the DB - for (String radio : connectNodeInfo.wifiRadioStates.keySet()) { - RadioType radioType = RadioType.UNSUPPORTED; - if (radio.equals("2.4G")) { - radioType = RadioType.is2dot4GHz; - } else if (radio.equals("5G")) { - radioType = RadioType.is5GHz; - } else if (radio.equals("5GL")) { - radioType = RadioType.is5GHzL; - } else if (radio.equals("5GU")) { - radioType = RadioType.is5GHzU; + for (RadioType radio : radiosFromAp) { + if (!advancedRadioMap.containsKey(radio) || advancedRadioMap.get(radio) == null) { + advancedRadioMap.put(radio, RadioConfiguration.createWithDefaults(radio)); + needToUpdateEquipment = true; } - - if (!radioType.equals(RadioType.UNSUPPORTED)) { - - radiosFromAp.add(radioType); - - RadioConfiguration advancedRadioConfiguration = advancedRadioMap.get(radioType); - ElementRadioConfiguration radioConfiguration = radioMap.get(radioType); - - if (advancedRadioConfiguration == null) { - advancedRadioConfiguration = RadioConfiguration.createWithDefaults(radioType); - advancedRadioMap.put(radioType, advancedRadioConfiguration); - needToUpdateEquipment = true; - } - - if (radioConfiguration == null) { - radioConfiguration = ElementRadioConfiguration.createWithDefaults(radioType); - radioMap.put(radioType, radioConfiguration); - needToUpdateEquipment = true; - } - + if (!radioMap.containsKey(radio) || radioMap.get(radio) == null) { + radioMap.putIfAbsent(radio, ElementRadioConfiguration.createWithDefaults(radio)); + needToUpdateEquipment = true; } } // remove radio configs from the DB that are no longer // present in the AP but still exist in DB - for (RadioType radioType : RadioType.validValues()) { - - RadioConfiguration advancedRadioConfiguration = advancedRadioMap.get(radioType); - - if (advancedRadioConfiguration != null || !radiosFromAp.contains(radioType)) { - advancedRadioMap.remove(radioType); + for (RadioType radio : advancedRadioMap.keySet()) { + if (!radiosFromAp.contains(radio)) { + advancedRadioMap.remove(radio); needToUpdateEquipment = true; } - - ElementRadioConfiguration radioConfiguration = radioMap.get(radioType); - if (radioConfiguration != null || !radiosFromAp.contains(radioType)) { - radioMap.remove(radioType); + } + for (RadioType radio : radioMap.keySet()) { + if (!radiosFromAp.contains(radio)) { + radioMap.remove(radio); needToUpdateEquipment = true; } - } if (needToUpdateEquipment) { + + apElementConfig.setAdvancedRadioMap(advancedRadioMap); + apElementConfig.setRadioMap(radioMap); + ce.setDetails(apElementConfig); + ce = equipmentServiceInterface.update(ce); + apElementConfig = (ApElementConfiguration) ce.getDetails(); + LOG.info("Equipment {} values for RadioMap {} AdvancedRadioMap {}", ce.getName(), + apElementConfig.getRadioMap(), apElementConfig.getAdvancedRadioMap()); } } @@ -947,7 +933,6 @@ public class OpensyncExternalIntegrationCloud implements OpensyncExternalIntegra throw new IllegalStateException("AP is not connected " + apId); } int customerId = ovsdbSession.getCustomerId(); - Equipment equipmentConfig = equipmentServiceInterface.getByInventoryIdOrNull(apId); if (equipmentConfig == null) { throw new IllegalStateException("Cannot retrieve configuration for " + apId); @@ -1075,7 +1060,7 @@ public class OpensyncExternalIntegrationCloud implements OpensyncExternalIntegra return; } - Equipment apNode = equipmentServiceInterface.getByInventoryIdOrNull(apId); + Equipment apNode = equipmentServiceInterface.getOrNull(equipmentId); if (apNode == null) { LOG.debug("wifiVIFStateDbTableUpdate::Cannot get EquipmentId for AP {}", apId); return; // we don't have the required info to get the @@ -1120,6 +1105,11 @@ public class OpensyncExternalIntegrationCloud implements OpensyncExternalIntegra RadioType radioType = null; Map rfElementMap = rfConfig.getRfConfigMap(); Map elementRadioMap = apElementConfig.getRadioMap(); + + if (apElementConfig.getAdvancedRadioMap().isEmpty()) { + LOG.warn("No AdvancedRadioMap for ap {} {}", apId, apElementConfig); + continue; + } for (RadioType rType : elementRadioMap.keySet()) { boolean autoChannelSelection = rfElementMap.get(rType).getAutoChannelSelection(); if (elementRadioMap.get(rType).getActiveChannel(autoChannelSelection) == channel) { @@ -1134,11 +1124,12 @@ public class OpensyncExternalIntegrationCloud implements OpensyncExternalIntegra Status activeBssidsStatus = statusServiceInterface.getOrNull(customerId, equipmentId, StatusDataType.ACTIVE_BSSIDS); + if (activeBssidsStatus != null) { + ActiveBSSIDs bssidStatusDetails = (ActiveBSSIDs) activeBssidsStatus.getDetails(); - ActiveBSSIDs bssidStatusDetails = (ActiveBSSIDs) activeBssidsStatus.getDetails(); - - if (activeBssidsStatus != null && bssidStatusDetails != null && bssidStatusDetails.getActiveBSSIDs() != null) { - updateClientDetailsStatus(customerId, equipmentId, bssidStatusDetails); + if (bssidStatusDetails != null && bssidStatusDetails.getActiveBSSIDs() != null) { + updateClientDetailsStatus(customerId, equipmentId, bssidStatusDetails); + } } LOG.info("Finished wifiVIFStateDbTableUpdate updated {}", activeBssidsStatus); @@ -1167,7 +1158,10 @@ public class OpensyncExternalIntegrationCloud implements OpensyncExternalIntegra Map clientsPerRadioType = new HashMap<>(); for (ActiveBSSID bssid : statusDetails.getActiveBSSIDs()) { - + if (bssid.getRadioType() == null) { + LOG.info("No radio type for BSSID, ignore"); + continue; + } if (!clientsPerRadioType.containsKey(bssid.getRadioType())) { clientsPerRadioType.put(bssid.getRadioType(), 0); } 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 f11e1f0..51b1a50 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 @@ -1805,16 +1805,10 @@ public class MqttStatsPublisher { Status activeBssidsStatus = statusServiceInterface.getOrNull(customerId, equipmentId, StatusDataType.ACTIVE_BSSIDS); - ActiveBSSIDs statusDetails = null; - if (activeBssidsStatus != null) { - statusDetails = (ActiveBSSIDs) activeBssidsStatus.getDetails(); + if (activeBssidsStatus != null && activeBssidsStatus.getDetails() != null && ((ActiveBSSIDs) activeBssidsStatus.getDetails()).getActiveBSSIDs() != null) { for (ActiveBSSID activeBSSID : ((ActiveBSSIDs) activeBssidsStatus.getDetails()).getActiveBSSIDs()) { if (activeBSSID.getRadioType().equals(radioType)) { ssidStatistics.setBssid(MacAddress.valueOf(activeBSSID.getBssid())); - // ssid value, in case not in stats, else will take - // stats value after - ssid = activeBSSID.getSsid(); - statusDetails.getActiveBSSIDs().indexOf(activeBSSID); } } } @@ -1905,8 +1899,6 @@ public class MqttStatsPublisher { } - // we can only get Rssi as an unsigned int from opensync, so some - // shifting ssidStatistics.setRxLastRssi(lastRssi); ssidStatistics.setNumRxData(Long.valueOf(rxFrames).intValue()); ssidStatistics.setRxBytes(rxBytes - rxErrors - rxRetries); diff --git a/opensync-ext-cloud/src/test/java/com/telecominfraproject/wlan/opensync/external/integration/OpensyncExternalIntegrationCloudTest.java b/opensync-ext-cloud/src/test/java/com/telecominfraproject/wlan/opensync/external/integration/OpensyncExternalIntegrationCloudTest.java index e97a098..ff2c9bd 100644 --- a/opensync-ext-cloud/src/test/java/com/telecominfraproject/wlan/opensync/external/integration/OpensyncExternalIntegrationCloudTest.java +++ b/opensync-ext-cloud/src/test/java/com/telecominfraproject/wlan/opensync/external/integration/OpensyncExternalIntegrationCloudTest.java @@ -588,7 +588,7 @@ public class OpensyncExternalIntegrationCloudTest { equipment.setProfileId(1); equipment.setDetails(ApElementConfiguration.createWithDefaults()); - Mockito.when(equipmentServiceInterface.getByInventoryIdOrNull(apId)).thenReturn(equipment); + Mockito.when(equipmentServiceInterface.getOrNull(1L)).thenReturn(equipment); Mockito.when(equipmentServiceInterface.get(equipment.getId())).thenReturn(equipment); Mockito.when(equipmentServiceInterface.update(equipment)).thenReturn(equipment); @@ -620,7 +620,7 @@ public class OpensyncExternalIntegrationCloudTest { Mockito.verify(session).getCustomerId(); Mockito.verify(session).getEquipmentId(); Mockito.verify(ovsdbSessionMapInterface).getSession(apId); - Mockito.verify(equipmentServiceInterface).getByInventoryIdOrNull(apId); + Mockito.verify(equipmentServiceInterface).getOrNull(1L); Mockito.verify(statusServiceInterface).getOrNull(2, 1L, StatusDataType.CLIENT_DETAILS); Mockito.verify(statusServiceInterface).getOrNull(2, 1L, StatusDataType.ACTIVE_BSSIDS); diff --git a/opensync-gateway/src/main/java/com/telecominfraproject/wlan/opensync/ovsdb/TipWlanOvsdbClient.java b/opensync-gateway/src/main/java/com/telecominfraproject/wlan/opensync/ovsdb/TipWlanOvsdbClient.java index 1799d24..c496910 100644 --- a/opensync-gateway/src/main/java/com/telecominfraproject/wlan/opensync/ovsdb/TipWlanOvsdbClient.java +++ b/opensync-gateway/src/main/java/com/telecominfraproject/wlan/opensync/ovsdb/TipWlanOvsdbClient.java @@ -133,17 +133,10 @@ public class TipWlanOvsdbClient implements OvsdbClientInterface { @Override public void disconnected(OvsdbClient ovsdbClient) { - String remoteHost = ovsdbClient.getConnectionInfo().getRemoteAddress().getHostAddress(); - int localPort = ovsdbClient.getConnectionInfo().getLocalPort(); - String subjectDn = null; - try { - subjectDn = ((X509Certificate) ovsdbClient.getConnectionInfo().getRemoteCertificate()) - .getSubjectDN().getName(); - } catch (Exception e) { - // do nothing - } - String clientCn = SslUtil.extractCN(subjectDn); + String remoteHost; + int localPort; + String clientCn; // disconnected - deregister ovsdbClient from our // connectedClients table @@ -153,22 +146,40 @@ public class TipWlanOvsdbClient implements OvsdbClientInterface { // so we are doing a reverse lookup here, and then if we find // the key we will // remove the entry from the connectedClients. - String key = ovsdbSessionMapInterface.lookupClientId(ovsdbClient); + String key; - if (key != null) { + try { + remoteHost = ovsdbClient.getConnectionInfo().getRemoteAddress().getHostAddress(); + localPort = ovsdbClient.getConnectionInfo().getLocalPort(); + String subjectDn = null; try { - extIntegrationInterface.apDisconnected(key); - ovsdbSessionMapInterface.removeSession(key); + subjectDn = ((X509Certificate) ovsdbClient.getConnectionInfo().getRemoteCertificate()) + .getSubjectDN().getName(); } catch (Exception e) { - LOG.debug("Unable to process ap disconnect. {}", e.getMessage()); - } finally { - ovsdbClient.shutdown(); + // do nothing + } + clientCn = SslUtil.extractCN(subjectDn); + key = ovsdbSessionMapInterface.lookupClientId(ovsdbClient); + if (key != null) { + try { + extIntegrationInterface.apDisconnected(key); + ovsdbSessionMapInterface.removeSession(key); + } catch (Exception e) { + LOG.debug("Unable to process ap disconnect. {}", e.getMessage()); + } + } + LOG.info("ovsdbClient disconnected from {} on port {} clientCn {} AP {} ", remoteHost, localPort, + clientCn, key); + LOG.info("ovsdbClient connectedClients = {}", ovsdbSessionMapInterface.getNumSessions()); + } finally { + try { + ovsdbClient.shutdown(); + } catch (Exception e) { + LOG.info("Caught Exception shutting down ovsdb client, may have already been disconnected {}", + e); } - } - LOG.info("ovsdbClient disconnected from {} on port {} clientCn {} AP {} ", remoteHost, localPort, - clientCn, key); - LOG.info("ovsdbClient connectedClients = {}", ovsdbSessionMapInterface.getNumSessions()); + } } @@ -191,36 +202,36 @@ public class TipWlanOvsdbClient implements OvsdbClientInterface { String apId = alterClientCnIfRequired(clientCn, connectNodeInfo); LOG.debug("Client {} connect for AP {}", clientCn, apId); - + ovsdbDao.removeAllPasspointConfigs(ovsdbClient); - ovsdbDao.removeAllSsids(ovsdbClient); // always - ovsdbDao.removeAllInetConfigs(ovsdbClient); + ovsdbDao.removeAllSsids(ovsdbClient); // always + ovsdbDao.removeAllInetConfigs(ovsdbClient); ovsdbDao.removeWifiRrm(ovsdbClient); ovsdbDao.removeAllStatsConfigs(ovsdbClient); // always - + extIntegrationInterface.clearEquipmentStatus(apId); - + OpensyncAPConfig opensyncAPConfig = extIntegrationInterface.getApConfig(apId); if (opensyncAPConfig != null) { - + ovsdbDao.configureWifiRadios(ovsdbClient, opensyncAPConfig); ovsdbDao.configureWifiRrm(ovsdbClient, opensyncAPConfig); - ovsdbDao.configureGreTunnels(ovsdbClient, opensyncAPConfig); + ovsdbDao.configureGreTunnels(ovsdbClient, opensyncAPConfig); ovsdbDao.createVlanNetworkInterfaces(ovsdbClient, opensyncAPConfig); - + ovsdbDao.configureSsids(ovsdbClient, opensyncAPConfig); if (opensyncAPConfig.getHotspotConfig() != null) { ovsdbDao.configureHotspots(ovsdbClient, opensyncAPConfig); } - + ovsdbDao.configureInterfaces(ovsdbClient); ovsdbDao.configureStatsFromProfile(ovsdbClient, opensyncAPConfig); if (ovsdbDao.getDeviceStatsReportingInterval(ovsdbClient) != collectionIntervalSecDeviceStats) { ovsdbDao.updateDeviceStatsReportingInterval(ovsdbClient, collectionIntervalSecDeviceStats); } - + } else { LOG.info("No Configuration available for {}", apId); } @@ -267,27 +278,25 @@ public class TipWlanOvsdbClient implements OvsdbClientInterface { LOG.warn("AP with id " + apId + " does not have a config to apply."); return; } - + ovsdbDao.removeAllPasspointConfigs(ovsdbClient); - ovsdbDao.removeAllSsids(ovsdbClient); // always - ovsdbDao.removeAllInetConfigs(ovsdbClient); + ovsdbDao.removeAllSsids(ovsdbClient); // always + ovsdbDao.removeAllInetConfigs(ovsdbClient); ovsdbDao.removeWifiRrm(ovsdbClient); ovsdbDao.removeAllStatsConfigs(ovsdbClient); // always - extIntegrationInterface.clearEquipmentStatus(apId); - - + ovsdbDao.configureWifiRadios(ovsdbClient, opensyncAPConfig); ovsdbDao.configureWifiRrm(ovsdbClient, opensyncAPConfig); - ovsdbDao.configureGreTunnels(ovsdbClient, opensyncAPConfig); + ovsdbDao.configureGreTunnels(ovsdbClient, opensyncAPConfig); ovsdbDao.createVlanNetworkInterfaces(ovsdbClient, opensyncAPConfig); - + ovsdbDao.configureSsids(ovsdbClient, opensyncAPConfig); if (opensyncAPConfig.getHotspotConfig() != null) { ovsdbDao.configureHotspots(ovsdbClient, opensyncAPConfig); } - + ovsdbDao.configureInterfaces(ovsdbClient); ovsdbDao.configureStatsFromProfile(ovsdbClient, opensyncAPConfig); @@ -425,16 +434,19 @@ public class TipWlanOvsdbClient implements OvsdbClientInterface { } if (!insert.isEmpty()) { - extIntegrationInterface.dhcpLeasedIpDbTableUpdate(insert, key, RowUpdateOperation.INSERT); + extIntegrationInterface.dhcpLeasedIpDbTableUpdate(insert, key, + RowUpdateOperation.INSERT); } if (!delete.isEmpty()) { - extIntegrationInterface.dhcpLeasedIpDbTableUpdate(delete, key, RowUpdateOperation.DELETE); + extIntegrationInterface.dhcpLeasedIpDbTableUpdate(delete, key, + RowUpdateOperation.DELETE); } if (!update.isEmpty()) { - extIntegrationInterface.dhcpLeasedIpDbTableUpdate(update, key, RowUpdateOperation.MODIFY); + extIntegrationInterface.dhcpLeasedIpDbTableUpdate(update, key, + RowUpdateOperation.MODIFY); } } catch (Exception e) { @@ -504,16 +516,19 @@ public class TipWlanOvsdbClient implements OvsdbClientInterface { } if (!insert.isEmpty()) { - extIntegrationInterface.commandStateDbTableUpdate(insert, key, RowUpdateOperation.INSERT); + extIntegrationInterface.commandStateDbTableUpdate(insert, key, + RowUpdateOperation.INSERT); } if (!delete.isEmpty()) { - extIntegrationInterface.commandStateDbTableUpdate(delete, key, RowUpdateOperation.DELETE); + extIntegrationInterface.commandStateDbTableUpdate(delete, key, + RowUpdateOperation.DELETE); } if (!update.isEmpty()) { - extIntegrationInterface.commandStateDbTableUpdate(update, key, RowUpdateOperation.MODIFY); + extIntegrationInterface.commandStateDbTableUpdate(update, key, + RowUpdateOperation.MODIFY); } } catch (Exception e) { @@ -529,27 +544,28 @@ public class TipWlanOvsdbClient implements OvsdbClientInterface { } private void monitorAwlanNodeDbTable(OvsdbClient ovsdbClient, String key) throws OvsdbClientException { - CompletableFuture awCf = ovsdbClient.monitor(OvsdbDao.ovsdbName, - OvsdbDao.awlanNodeDbTable + "_" + key, - new MonitorRequests(ImmutableMap.of(OvsdbDao.awlanNodeDbTable, new MonitorRequest(new MonitorSelect(true, true, true, true)))), + CompletableFuture awCf = ovsdbClient.monitor( + OvsdbDao.ovsdbName, OvsdbDao.awlanNodeDbTable + "_" + key, new MonitorRequests(ImmutableMap + .of(OvsdbDao.awlanNodeDbTable, new MonitorRequest(new MonitorSelect(true, true, true, true)))), new MonitorCallback() { @Override public void update(TableUpdates tableUpdates) { try { - LOG.info(OvsdbDao.awlanNodeDbTable + "_" + key + " monitor callback received {}", tableUpdates); + LOG.info(OvsdbDao.awlanNodeDbTable + "_" + key + " monitor callback received {}", + tableUpdates); extIntegrationInterface.awlanNodeDbTableUpdate( ovsdbDao.getOpensyncAWLANNode(tableUpdates, key, ovsdbClient), key); } catch (Exception e) { - LOG.error("awlanNodeDbTableUpdate failed",e); + LOG.error("awlanNodeDbTableUpdate failed", e); } } }); - extIntegrationInterface.awlanNodeDbTableUpdate( - ovsdbDao.getOpensyncAWLANNode(awCf.join(), key, ovsdbClient), key); + extIntegrationInterface.awlanNodeDbTableUpdate(ovsdbDao.getOpensyncAWLANNode(awCf.join(), key, ovsdbClient), + key); } private void monitorWifiAssociatedClientsDbTable(OvsdbClient ovsdbClient, String key) throws OvsdbClientException { @@ -558,47 +574,49 @@ public class TipWlanOvsdbClient implements OvsdbClientInterface { new MonitorRequests(ImmutableMap.of(OvsdbDao.wifiAssociatedClientsDbTable, new MonitorRequest())), new MonitorCallback() { - @Override - public void update(TableUpdates tableUpdates) { + @Override + public void update(TableUpdates tableUpdates) { - try { - LOG.info(OvsdbDao.wifiAssociatedClientsDbTable + "_" + key + " monitor callback received {}", - tableUpdates); + try { + LOG.info( + OvsdbDao.wifiAssociatedClientsDbTable + "_" + key + " monitor callback received {}", + tableUpdates); - List associatedClients = new ArrayList<>(); + List associatedClients = new ArrayList<>(); - for (TableUpdate tableUpdate : tableUpdates.getTableUpdates().values()) { + for (TableUpdate tableUpdate : tableUpdates.getTableUpdates().values()) { + + for (RowUpdate rowUpdate : tableUpdate.getRowUpdates().values()) { + if ((rowUpdate.getOld() != null) && (rowUpdate.getNew() == null)) { + Row row = rowUpdate.getOld(); + String deletedClientMac = row.getStringColumn("mac"); + // take care of the deletes as we go + // through + // the updates, as we want to delete + // before + // adding anyway. + extIntegrationInterface.wifiAssociatedClientsDbTableDelete(deletedClientMac, + key); + } else { + associatedClients.addAll( + ovsdbDao.getOpensyncWifiAssociatedClients(rowUpdate, key, ovsdbClient)); + } + } - for (RowUpdate rowUpdate : tableUpdate.getRowUpdates().values()) { - if ((rowUpdate.getOld() != null) && (rowUpdate.getNew() == null)) { - Row row = rowUpdate.getOld(); - String deletedClientMac = row.getStringColumn("mac"); - // take care of the deletes as we go through - // the updates, as we want to delete before - // adding anyway. - extIntegrationInterface.wifiAssociatedClientsDbTableDelete(deletedClientMac, key); - } else { - associatedClients.addAll( - ovsdbDao.getOpensyncWifiAssociatedClients(rowUpdate, key, ovsdbClient)); } + + // now address the update/add + extIntegrationInterface.wifiAssociatedClientsDbTableUpdate(associatedClients, key); + } catch (Exception e) { + LOG.error("wifiAssociatedClientsDbTableUpdate failed", e); } } - // now address the update/add - extIntegrationInterface.wifiAssociatedClientsDbTableUpdate(associatedClients, key); - } catch (Exception e) { - LOG.error("wifiAssociatedClientsDbTableUpdate failed", e); - } - - } - - }); - - - - extIntegrationInterface.wifiAssociatedClientsDbTableUpdate(ovsdbDao.getInitialOpensyncWifiAssociatedClients(acCf.join(), key, ovsdbClient), key); + }); + extIntegrationInterface.wifiAssociatedClientsDbTableUpdate( + ovsdbDao.getInitialOpensyncWifiAssociatedClients(acCf.join(), key, ovsdbClient), key); } @@ -624,11 +642,11 @@ public class TipWlanOvsdbClient implements OvsdbClientInterface { for (RowUpdate rowUpdate : tableUpdate.getRowUpdates().values()) { if (rowUpdate.getNew() == null) { - inetStateDelete.addAll( - ovsdbDao.getOpensyncApInetStateForRowUpdate(rowUpdate, key, ovsdbClient)); + inetStateDelete.addAll(ovsdbDao.getOpensyncApInetStateForRowUpdate(rowUpdate, + key, ovsdbClient)); } else { - inetStateInsertOrUpdate.addAll( - ovsdbDao.getOpensyncApInetStateForRowUpdate(rowUpdate, key, ovsdbClient)); + inetStateInsertOrUpdate.addAll(ovsdbDao + .getOpensyncApInetStateForRowUpdate(rowUpdate, key, ovsdbClient)); } } @@ -640,14 +658,15 @@ public class TipWlanOvsdbClient implements OvsdbClientInterface { // now process updates and mutations extIntegrationInterface.wifiInetStateDbTableUpdate(inetStateInsertOrUpdate, key); } catch (Exception e) { - LOG.error("wifiInetStateDbTableUpdate failed",e); + LOG.error("wifiInetStateDbTableUpdate failed", e); } } }); - - extIntegrationInterface.wifiInetStateDbTableUpdate(ovsdbDao.getInitialOpensyncApInetStateForRowUpdate(isCf.join(), key, ovsdbClient), key); + + extIntegrationInterface.wifiInetStateDbTableUpdate( + ovsdbDao.getInitialOpensyncApInetStateForRowUpdate(isCf.join(), key, ovsdbClient), key); } @@ -655,7 +674,8 @@ public class TipWlanOvsdbClient implements OvsdbClientInterface { CompletableFuture rsCf = ovsdbClient.monitor(OvsdbDao.ovsdbName, OvsdbDao.wifiRadioStateDbTable + "_" + key, - new MonitorRequests(ImmutableMap.of(OvsdbDao.wifiRadioStateDbTable, new MonitorRequest(new MonitorSelect(true, true, true, true)))), + new MonitorRequests(ImmutableMap.of(OvsdbDao.wifiRadioStateDbTable, + new MonitorRequest(new MonitorSelect(true, true, true, true)))), new MonitorCallback() { @Override @@ -667,78 +687,82 @@ public class TipWlanOvsdbClient implements OvsdbClientInterface { extIntegrationInterface.wifiRadioStatusDbTableUpdate( ovsdbDao.getOpensyncAPRadioState(tableUpdates, key, ovsdbClient), key); } catch (Exception e) { - LOG.error("wifiRadioStatusDbTableUpdate failed",e); + LOG.error("wifiRadioStatusDbTableUpdate failed", e); } } }); - extIntegrationInterface.wifiRadioStatusDbTableUpdate( - ovsdbDao.getOpensyncAPRadioState(rsCf.join(), key, ovsdbClient), key); + extIntegrationInterface + .wifiRadioStatusDbTableUpdate(ovsdbDao.getOpensyncAPRadioState(rsCf.join(), key, ovsdbClient), key); } private void monitorWifiVifStateDbTable(OvsdbClient ovsdbClient, String key) throws OvsdbClientException { - CompletableFuture vsCf = ovsdbClient.monitor(OvsdbDao.ovsdbName, - OvsdbDao.wifiVifStateDbTable + "_" + key, - new MonitorRequests(ImmutableMap.of(OvsdbDao.wifiVifStateDbTable, new MonitorRequest(new MonitorSelect(true, true, true, true)))), - new MonitorCallback() { + CompletableFuture vsCf = ovsdbClient + .monitor(OvsdbDao.ovsdbName, OvsdbDao.wifiVifStateDbTable + "_" + key, + new MonitorRequests(ImmutableMap.of(OvsdbDao.wifiVifStateDbTable, + new MonitorRequest(new MonitorSelect(false, true, true, true)))), + new MonitorCallback() { - @Override - public void update(TableUpdates tableUpdates) { - try { - LOG.info(OvsdbDao.wifiVifStateDbTable + "_" + key + " monitor callback received {}", - tableUpdates); + @Override + public void update(TableUpdates tableUpdates) { + try { + LOG.info(OvsdbDao.wifiVifStateDbTable + "_" + key + " monitor callback received {}", + tableUpdates); - List vifsToDelete = new ArrayList<>(); - List vifsToInsertOrUpdate = new ArrayList<>(); - for (TableUpdate tableUpdate : tableUpdates.getTableUpdates().values()) { + List vifsToDelete = new ArrayList<>(); + List vifsToInsertOrUpdate = new ArrayList<>(); + for (TableUpdate tableUpdate : tableUpdates.getTableUpdates().values()) { - for (RowUpdate rowUpdate : tableUpdate.getRowUpdates().values()) { + for (RowUpdate rowUpdate : tableUpdate.getRowUpdates().values()) { - if (rowUpdate.getNew() == null) { - // this is a deletion - vifsToDelete.addAll( - ovsdbDao.getOpensyncApVifStateForRowUpdate(rowUpdate, key, ovsdbClient)); + if (rowUpdate.getNew() == null) { + // this is a deletion + vifsToDelete.addAll(ovsdbDao.getOpensyncApVifStateForRowUpdate( + rowUpdate, key, ovsdbClient)); - } else { - // either an insert or - // mutuate/update - vifsToInsertOrUpdate.addAll( - ovsdbDao.getOpensyncApVifStateForRowUpdate(rowUpdate, key, ovsdbClient)); + } else { + // either an insert or + // mutuate/update + vifsToInsertOrUpdate.addAll(ovsdbDao.getOpensyncApVifStateForRowUpdate( + rowUpdate, key, ovsdbClient)); + + } + + } + + // delete first, if required + if (!vifsToDelete.isEmpty()) { + extIntegrationInterface.wifiVIFStateDbTableDelete(vifsToDelete, key); + } + if (!vifsToInsertOrUpdate.isEmpty()) { + extIntegrationInterface.wifiVIFStateDbTableUpdate(vifsToInsertOrUpdate, + key); + } + + } + } catch (Exception e) { + LOG.error("wifiVIFStateDbTableUpdate failed", e); + } } - } - - // delete first, if required - if (!vifsToDelete.isEmpty()) { - extIntegrationInterface.wifiVIFStateDbTableDelete(vifsToDelete, key); - } - if (!vifsToInsertOrUpdate.isEmpty()) { - extIntegrationInterface.wifiVIFStateDbTableUpdate(vifsToInsertOrUpdate, key); - } - - } - } catch (Exception e) { - LOG.error("wifiVIFStateDbTableUpdate failed", e); - } - - } - - }); - extIntegrationInterface.wifiVIFStateDbTableUpdate(ovsdbDao.getInitialOpensyncApVifStateForTableUpdates(vsCf.join(), key, ovsdbClient),key); + }); + vsCf.join(); } @Override public String closeSession(String apId) { OvsdbSession session = ovsdbSessionMapInterface.getSession(apId); - try { - session.getOvsdbClient().shutdown(); - } catch (Exception e) { - LOG.error("Failed to close session to " + apId + " " + e.getLocalizedMessage()); - return "Failed to close session to " + apId + " " + e.getLocalizedMessage(); + if (session != null) { + try { + session.getOvsdbClient().shutdown(); + } catch (Exception e) { + LOG.error("Failed to close session to " + apId + " " + e.getLocalizedMessage()); + return "Failed to close session to " + apId + " " + e.getLocalizedMessage(); + } } LOG.debug("Closed session to " + apId); return "Closed session to " + apId; @@ -896,18 +920,21 @@ public class TipWlanOvsdbClient implements OvsdbClientInterface { return key; } - public String processNewChannelsRequest(String apId, Map backupChannelMap, Map primaryChannelMap) { + public String processNewChannelsRequest(String apId, Map backupChannelMap, + Map primaryChannelMap) { LOG.info("TipWlanOvsdbClient::processNewChannelsRequest for AP {}", apId); try { OvsdbSession session = ovsdbSessionMapInterface.getSession(apId); OvsdbClient ovsdbClient = session.getOvsdbClient(); ovsdbDao.processNewChannelsRequest(ovsdbClient, backupChannelMap, primaryChannelMap); - LOG.info("TipWlanOvsdbClient::processNewChannelsRequest change backup and/or primary channels for AP {}", apId); + LOG.info("TipWlanOvsdbClient::processNewChannelsRequest change backup and/or primary channels for AP {}", + apId); return " change backup and/or primary channels for AP " + apId; } catch (Exception e) { - LOG.error("TipWlanOvsdbClient::processNewChannelsRequest failed to change backup and/or primary channels for AP {}", apId, - e); + LOG.error( + "TipWlanOvsdbClient::processNewChannelsRequest failed to change backup and/or primary channels for AP {}", + apId, e); return "failed to change backup and/or primary channels for AP " + apId; } } diff --git a/opensync-gateway/src/main/java/com/telecominfraproject/wlan/opensync/ovsdb/dao/OvsdbDao.java b/opensync-gateway/src/main/java/com/telecominfraproject/wlan/opensync/ovsdb/dao/OvsdbDao.java index c1742bd..66d31a5 100644 --- a/opensync-gateway/src/main/java/com/telecominfraproject/wlan/opensync/ovsdb/dao/OvsdbDao.java +++ b/opensync-gateway/src/main/java/com/telecominfraproject/wlan/opensync/ovsdb/dao/OvsdbDao.java @@ -3089,13 +3089,13 @@ public class OvsdbDao { rrmEnabled = opensyncApConfig.getEquipmentLocation().getDetails().isRrmEnabled(); } List macBlockList = opensyncApConfig.getBlockedClients(); - LOG.debug("configureSsids with blockList {}", macBlockList); + LOG.debug("configureSsids {} with blockList {}", opensyncApConfig.getSsidProfile(), macBlockList); List enabledRadiosFromAp = new ArrayList<>(); getEnabledRadios(ovsdbClient, enabledRadiosFromAp); for (Profile ssidProfile : opensyncApConfig.getSsidProfile()) { - + SsidConfiguration ssidConfig = (SsidConfiguration) ssidProfile.getDetails(); ApElementConfiguration apElementConfig = (ApElementConfiguration) opensyncApConfig.getCustomerEquipment() .getDetails(); @@ -3198,15 +3198,21 @@ public class OvsdbDao { } } - RadioConfiguration radioConfiguration = apElementConfig.getAdvancedRadioMap().get(radioType); - if (radioConfiguration == null) { - continue; // don't have a radio of this kind in the map - } RfElementConfiguration rfElementConfig = rfConfig.getRfConfig(radioType); - int dtimPeriod = radioConfiguration.getDtimPeriod(); int rtsCtsThreshold = rfElementConfig.getRtsCtsThreshold(); - int fragThresholdBytes = radioConfiguration.getFragmentationThresholdBytes(); RadioMode radioMode = rfElementConfig.getRadioMode(); + + int dtimPeriod = 2; + int fragThresholdBytes = 2346; + boolean uapsdEnabled = true; + boolean apBridge = true; + RadioConfiguration radioConfiguration = apElementConfig.getAdvancedRadioMap().get(radioType); + if (radioConfiguration != null) { + dtimPeriod = radioConfiguration.getDtimPeriod(); + uapsdEnabled = radioConfiguration.getUapsdState() == StateSetting.enabled; + apBridge = radioConfiguration.getStationIsolation() == StateSetting.disabled; // stationIsolation + fragThresholdBytes = radioConfiguration.getFragmentationThresholdBytes(); + } String minHwMode = "11n"; // min_hw_mode is 11ac, wifi 5, we can // also take ++ (11ax) but 2.4GHz only // Wifi4 -- @@ -3217,9 +3223,7 @@ public class OvsdbDao { minHwMode = "11x"; } - boolean uapsdEnabled = radioConfiguration.getUapsdState() == StateSetting.enabled; - boolean apBridge = radioConfiguration.getStationIsolation() == StateSetting.disabled; // stationIsolation // off by default boolean enable80211r = false; int mobilityDomain = 0; @@ -5656,7 +5660,8 @@ public class OvsdbDao { } } - public void processNewChannelsRequest(OvsdbClient ovsdbClient, Map backupChannelMap, Map primaryChannelMap) { + public void processNewChannelsRequest(OvsdbClient ovsdbClient, Map backupChannelMap, + Map primaryChannelMap) { LOG.info("OvsdbDao::processNewChannelsRequest backup {} primary {}", backupChannelMap, primaryChannelMap); try { @@ -5689,7 +5694,6 @@ public class OvsdbDao { LOG.info("Op Result {}", res); } - LOG.info("Updated ovsdb config for primary and backup channels."); } catch (ExecutionException e) { LOG.error("Error in processNewChannelsRequest", e); @@ -5699,8 +5703,6 @@ public class OvsdbDao { } } - - public AutoOrManualValue getSourcedValue(SourceType source, int profileValue, int equipmentValue) { if (source == SourceType.profile) {