diff --git a/opensync-ext-cloud/src/main/java/com/telecominfraproject/wlan/opensync/external/integration/OpensyncExternalIntegrationMqttMessageProcessor.java b/opensync-ext-cloud/src/main/java/com/telecominfraproject/wlan/opensync/external/integration/OpensyncExternalIntegrationMqttMessageProcessor.java index 4103cb6..3b62770 100644 --- a/opensync-ext-cloud/src/main/java/com/telecominfraproject/wlan/opensync/external/integration/OpensyncExternalIntegrationMqttMessageProcessor.java +++ b/opensync-ext-cloud/src/main/java/com/telecominfraproject/wlan/opensync/external/integration/OpensyncExternalIntegrationMqttMessageProcessor.java @@ -30,6 +30,7 @@ import com.telecominfraproject.wlan.client.session.models.ClientSessionDetails; import com.telecominfraproject.wlan.client.session.models.ClientSessionMetricDetails; import com.telecominfraproject.wlan.cloudeventdispatcher.CloudEventDispatcherInterface; import com.telecominfraproject.wlan.core.model.equipment.ChannelBandwidth; +import com.telecominfraproject.wlan.core.model.equipment.ChannelHopReason; import com.telecominfraproject.wlan.core.model.equipment.DetectedAuthMode; import com.telecominfraproject.wlan.core.model.equipment.MacAddress; import com.telecominfraproject.wlan.core.model.equipment.NeighborScanPacketType; @@ -39,6 +40,7 @@ import com.telecominfraproject.wlan.core.model.equipment.SecurityType; import com.telecominfraproject.wlan.core.model.equipment.WiFiSessionUtility; import com.telecominfraproject.wlan.core.model.utils.DecibelUtils; import com.telecominfraproject.wlan.equipment.EquipmentServiceInterface; +import com.telecominfraproject.wlan.equipment.models.ApElementConfiguration; import com.telecominfraproject.wlan.equipment.models.Equipment; import com.telecominfraproject.wlan.opensync.ovsdb.dao.utilities.OvsdbToWlanCloudTypeMappingUtility; import com.telecominfraproject.wlan.profile.ProfileServiceInterface; @@ -76,6 +78,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.equipment.realtime.RealTimeChannelHopEvent; import com.telecominfraproject.wlan.systemevent.equipment.realtime.RealTimeEventType; import com.telecominfraproject.wlan.systemevent.equipment.realtime.RealTimeSipCallReportEvent; import com.telecominfraproject.wlan.systemevent.equipment.realtime.RealTimeSipCallStartEvent; @@ -92,6 +95,7 @@ import sts.OpensyncStats.AssocType; import sts.OpensyncStats.CallReport; import sts.OpensyncStats.CallStart; import sts.OpensyncStats.CallStop; +import sts.OpensyncStats.ChannelSwitchReason; import sts.OpensyncStats.Client; import sts.OpensyncStats.ClientReport; import sts.OpensyncStats.DNSProbeMetric; @@ -150,7 +154,7 @@ public class OpensyncExternalIntegrationMqttMessageProcessor { void processMqttMessage(String topic, WCStatsReport wcStatsReport) { LOG.info("Received WCStatsReport {}", wcStatsReport.toString()); - LOG.info("Received report on topic {}", topic); + LOG.debug("Received report on topic {}", topic); int customerId = extractCustomerIdFromTopic(topic); long equipmentId = extractEquipmentIdFromTopic(topic); @@ -245,7 +249,7 @@ public class OpensyncExternalIntegrationMqttMessageProcessor { } if (!metricRecordList.isEmpty()) { - LOG.info("Publishing Metrics {}", metricRecordList); + LOG.debug("Publishing Metrics {}", metricRecordList); equipmentMetricsCollectorInterface.publishMetrics(metricRecordList); } @@ -296,7 +300,7 @@ public class OpensyncExternalIntegrationMqttMessageProcessor { for (sts.OpensyncStats.EventReport.ClientSession apEventClientSession : e.getClientSessionList()) { - LOG.info("Processing EventReport::ClientSession {}", apEventClientSession); + LOG.debug("Processing EventReport::ClientSession {}", apEventClientSession); processClientConnectEvent(customerId, equipmentId, locationId, e, apEventClientSession); @@ -318,10 +322,74 @@ public class OpensyncExternalIntegrationMqttMessageProcessor { } + publishChannelHopEvents(customerId, equipmentId, e); + }); } + private void publishChannelHopEvents(int customerId, long equipmentId, EventReport e) { + + LOG.info("publishChannelHopEvents for customerId {} equipmentId {}"); + + List events = new ArrayList<>(); + + for (sts.OpensyncStats.EventReport.ChannelSwitchEvent channelSwitchEvent : e.getChannelSwitchList()) { + Equipment equipment = equipmentServiceInterface.getOrNull(equipmentId); + if (equipment == null) + continue; + RadioType radioType = null; + Long timestamp = null; + ChannelHopReason reason = null; + Integer channel = null; + if (channelSwitchEvent.hasBand()) { + radioType = OvsdbToWlanCloudTypeMappingUtility + .getRadioTypeFromOpensyncStatsRadioBandType(channelSwitchEvent.getBand()); + } + if (RadioType.isUnsupported(radioType)) { + LOG.warn("publishChannelHopEvents:RadioType {} is unsupported, cannot send RealTimeChannelHopEvent for {}", radioType, channelSwitchEvent); + continue; + } + if (channelSwitchEvent.hasTimestampMs()) { + timestamp = channelSwitchEvent.getTimestampMs(); + } + if (timestamp == null) { + LOG.warn("publishChannelHopEvents:timestamp is null, cannot send RealTimeChannelHopEvent for {}", channelSwitchEvent); + continue; + } + + if (channelSwitchEvent.hasReason()) { + if (channelSwitchEvent.getReason().equals(ChannelSwitchReason.high_interference)) reason = ChannelHopReason.HighInterference; + else if (channelSwitchEvent.getReason().equals(ChannelSwitchReason.radar_detected)) reason = ChannelHopReason.RadarDetected; + } + if (ChannelHopReason.isUnsupported(reason)) { + LOG.warn("publishChannelHopEvents:reason {} is unsupported, cannot send RealTimeChannelHopEvent for {}", channelSwitchEvent.getReason(), channelSwitchEvent); + continue; + } + if (channelSwitchEvent.hasChannel()) { + channel = channelSwitchEvent.getChannel(); + } + if (channel == null) { + LOG.warn("publishChannelHopEvents:channel is null, cannot send RealTimeChannelHopEvent for {}", channelSwitchEvent); + continue; + } + + RealTimeChannelHopEvent channelHopEvent = new RealTimeChannelHopEvent(RealTimeEventType.Channel_Hop, customerId, equipmentId, radioType, channel, ((ApElementConfiguration)equipment.getDetails()).getRadioMap().get(radioType).getChannelNumber(), reason, timestamp); + + events.add(channelHopEvent); + + LOG.debug("publishChannelHopEvents:Adding ChannelHopEvent to bulk list {}", channelHopEvent); + } + + + if (events.size() > 0) { + LOG.info("publishChannelHopEvents:publishEventsBulk: {}", events); + equipmentMetricsCollectorInterface.publishEventsBulk(events); + } else { + LOG.info("publishChannelHopEvents:No ChannelHopEvents in report"); + } + } + protected void processClientConnectEvent(int customerId, long equipmentId, long locationId, EventReport e, sts.OpensyncStats.EventReport.ClientSession apEventClientSession) { for (ClientConnectEvent clientConnectEvent : apEventClientSession.getClientConnectEventList()) { @@ -533,7 +601,7 @@ public class OpensyncExternalIntegrationMqttMessageProcessor { clientSession = clientServiceInterface.updateSession(clientSession); } else { - LOG.info("Cannot update client or client session when no client mac address is present"); + LOG.warn("Cannot update client or client session when no client mac address is present"); } } } @@ -593,7 +661,7 @@ public class OpensyncExternalIntegrationMqttMessageProcessor { clientSession = clientServiceInterface.updateSession(clientSession); } else { - LOG.info("Cannot update client or client session when no client mac address is present"); + LOG.warn("Cannot update client or client session when no client mac address is present"); } } } @@ -666,7 +734,7 @@ public class OpensyncExternalIntegrationMqttMessageProcessor { clientSession = clientServiceInterface.updateSession(clientSession); } else { - LOG.info("Cannot update client or client session when no client mac address is present"); + LOG.warn("Cannot update client or client session when no client mac address is present"); } } } @@ -728,7 +796,7 @@ public class OpensyncExternalIntegrationMqttMessageProcessor { clientSession = clientServiceInterface.updateSession(clientSession); } else { - LOG.info("Cannot update client or client session when no client mac address is present"); + LOG.warn("Cannot update client or client session when no client mac address is present"); } } } @@ -787,7 +855,7 @@ public class OpensyncExternalIntegrationMqttMessageProcessor { clientSession = clientServiceInterface.updateSession(clientSession); } else { - LOG.info("Cannot update client or client session when no client mac address is present"); + LOG.warn("Cannot update client or client session when no client mac address is present"); } } } @@ -836,7 +904,7 @@ public class OpensyncExternalIntegrationMqttMessageProcessor { clientSession = clientServiceInterface.updateSession(clientSession); } else { - LOG.info("Cannot update client or client session when no client mac address is present"); + LOG.warn("Cannot update client or client session when no client mac address is present"); } } } @@ -893,7 +961,7 @@ public class OpensyncExternalIntegrationMqttMessageProcessor { clientSession = clientServiceInterface.updateSession(clientSession); } else { - LOG.info("Cannot update client or client session when no clientmac address is present"); + LOG.warn("Cannot update client or client session when no clientmac address is present"); } } } @@ -960,7 +1028,7 @@ public class OpensyncExternalIntegrationMqttMessageProcessor { clientSession = clientServiceInterface.updateSession(clientSession); } else { - LOG.info("Cannot update client or client session when no client mac address is present"); + LOG.warn("Cannot update client or client session when no client mac address is present"); } } } @@ -978,7 +1046,7 @@ public class OpensyncExternalIntegrationMqttMessageProcessor { eventTimestamp = videoVoiceReport.getTimestampMs(); } - LOG.info("Received VideoVoiceReport {} for SIP call", videoVoiceReport); + LOG.debug("Received VideoVoiceReport {} for SIP call", videoVoiceReport); processRealTImeSipCallReportEvent(customerId, equipmentId, eventTimestamp, eventsList, videoVoiceReport); @@ -1601,7 +1669,7 @@ public class OpensyncExternalIntegrationMqttMessageProcessor { NetworkAdminStatusData statusData = (NetworkAdminStatusData) networkAdminStatus.getDetails(); if (n.getDnsState() == null) { - LOG.info("No DnsState present in networkProbeMetrics, DnsState and CloudLinkStatus set to 'normal"); + LOG.debug("No DnsState present in networkProbeMetrics, DnsState and CloudLinkStatus set to 'normal"); statusData.setDnsStatus(StatusCode.normal); statusData.setCloudLinkStatus(StatusCode.normal); } else { @@ -1609,13 +1677,13 @@ public class OpensyncExternalIntegrationMqttMessageProcessor { statusData.setCloudLinkStatus(stateUpDownErrorToStatusCode(n.getDnsState())); } if (n.getDhcpState() == null) { - LOG.info("No DhcpState present in networkProbeMetrics, set to 'normal"); + LOG.debug("No DhcpState present in networkProbeMetrics, set to 'normal"); statusData.setDhcpStatus(StatusCode.normal); } else { statusData.setDhcpStatus(stateUpDownErrorToStatusCode(n.getDhcpState())); } if (n.getRadiusState() == null) { - LOG.info("No RadiusState present in networkProbeMetrics, set to 'normal"); + LOG.debug("No RadiusState present in networkProbeMetrics, set to 'normal"); statusData.setRadiusStatus(StatusCode.normal); } else { statusData.setRadiusStatus(stateUpDownErrorToStatusCode(n.getRadiusState())); @@ -1625,7 +1693,7 @@ public class OpensyncExternalIntegrationMqttMessageProcessor { networkAdminStatus = statusServiceInterface.update(networkAdminStatus); - LOG.info("Updated NetworkAdminStatus {}", networkAdminStatus); + LOG.debug("Updated NetworkAdminStatus {}", networkAdminStatus); }); @@ -1658,7 +1726,7 @@ public class OpensyncExternalIntegrationMqttMessageProcessor { StatusDataType.RADIO_UTILIZATION); if (radioUtilizationStatus == null) { - LOG.info("Create new radioUtilizationStatus"); + LOG.debug("Create new radioUtilizationStatus"); radioUtilizationStatus = new Status(); radioUtilizationStatus.setCustomerId(customerId); radioUtilizationStatus.setEquipmentId(equipmentId); @@ -1769,7 +1837,7 @@ public class OpensyncExternalIntegrationMqttMessageProcessor { eqOsPerformance.setTotalAvailableMemoryKb(deviceReport.getMemUtil().getMemTotal()); status.setDetails(eqOsPerformance); status = statusServiceInterface.update(status); - LOG.info("updated status {}", status); + LOG.debug("updated status {}", status); } void populateApClientMetrics(List metricRecordList, Report report, int customerId, long equipmentId, @@ -1780,12 +1848,12 @@ public class OpensyncExternalIntegrationMqttMessageProcessor { for (Client cl : clReport.getClientListList()) { if (cl.getMacAddress() == null) { - LOG.info("No mac address for Client {}, cannot set device mac address for client in ClientMetrics.", + LOG.debug("No mac address for Client {}, cannot set device mac address for client in ClientMetrics.", cl); continue; } - LOG.info("Processing ClientReport from AP {}", cl.getMacAddress()); + LOG.debug("Processing ClientReport from AP {}", cl.getMacAddress()); ServiceMetric smr = new ServiceMetric(customerId, equipmentId, new MacAddress(cl.getMacAddress())); smr.setLocationId(locationId); @@ -1809,7 +1877,7 @@ public class OpensyncExternalIntegrationMqttMessageProcessor { long sessionId = WiFiSessionUtility.encodeWiFiAssociationId(clReport.getTimestampMs() / 1000L, MacAddress.convertMacStringToLongValue(cl.getMacAddress())); - LOG.info("populateApClientMetrics Session Id {}", sessionId); + LOG.debug("populateApClientMetrics Session Id {}", sessionId); cMetrics.setSessionId(sessionId); if (cl.hasStats()) { @@ -1867,7 +1935,7 @@ public class OpensyncExternalIntegrationMqttMessageProcessor { } } - LOG.info("ApClientMetrics Report {}", cMetrics); + LOG.debug("ApClientMetrics Report {}", cMetrics); } @@ -1951,18 +2019,18 @@ public class OpensyncExternalIntegrationMqttMessageProcessor { boolean isReassociation = true; if (clientInstance == null) { - LOG.info("Cannot get client instance for {}", client.getMacAddress()); + LOG.debug("Cannot get client instance for {}", client.getMacAddress()); return null; } - LOG.info("Client {}", clientInstance); + LOG.debug("Client {}", clientInstance); ClientSession clientSession = clientServiceInterface.getSessionOrNull(customerId, equipmentId, clientInstance.getMacAddress()); if (clientSession == null) { - LOG.info("Cannot get client session for {}", clientInstance.getMacAddress()); + LOG.warn("Cannot get client session for {}", clientInstance.getMacAddress()); return null; } @@ -2037,7 +2105,7 @@ public class OpensyncExternalIntegrationMqttMessageProcessor { clientSession = clientServiceInterface.updateSession(clientSession); - LOG.info("Updated client session {}", clientSession); + LOG.debug("Updated client session {}", clientSession); return clientSession; } catch (Exception e) { @@ -2054,7 +2122,7 @@ public class OpensyncExternalIntegrationMqttMessageProcessor { ClientSessionMetricDetails metricDetails = new ClientSessionMetricDetails(); if (LOG.isDebugEnabled()) - LOG.info("Stats: {} DurationMs {}", client.getStats(), client.getDurationMs()); + LOG.debug("Stats: {} DurationMs {}", client.getStats(), client.getDurationMs()); int rssi = client.getStats().getRssi(); metricDetails.setRssi(rssi); metricDetails.setRxBytes(client.getStats().getRxBytes()); @@ -2072,7 +2140,7 @@ public class OpensyncExternalIntegrationMqttMessageProcessor { metricDetails.setRxRateKbps((long) client.getStats().getRxRate()); metricDetails.setTxRateKbps((long) client.getStats().getTxRate()); if (LOG.isDebugEnabled()) - LOG.info("RxRateKbps {} TxRateKbps {}", metricDetails.getRxRateKbps(), metricDetails.getTxRateKbps()); + LOG.debug("RxRateKbps {} TxRateKbps {}", metricDetails.getRxRateKbps(), metricDetails.getTxRateKbps()); // Throughput, do rate / duration if (client.getDurationMs() > 1000) { @@ -2085,15 +2153,15 @@ public class OpensyncExternalIntegrationMqttMessageProcessor { float txBytesToMb = txBytesFv / 125000F; if (LOG.isDebugEnabled()) - LOG.info("rxBytesToMb {} txBytesToMb {} ", rxBytesToMb, txBytesToMb); + LOG.debug("rxBytesToMb {} txBytesToMb {} ", rxBytesToMb, txBytesToMb); metricDetails.setRxMbps(rxBytesToMb / durationSec); metricDetails.setTxMbps(txBytesToMb / durationSec); if (LOG.isDebugEnabled()) - LOG.info("RxMbps {} TxMbps {} ", metricDetails.getRxMbps(), metricDetails.getTxMbps()); + LOG.debug("RxMbps {} TxMbps {} ", metricDetails.getRxMbps(), metricDetails.getTxMbps()); } else { - LOG.info("Cannot calculate tx/rx throughput for Client {} based on duration of {} Ms", + LOG.warn("Cannot calculate tx/rx throughput for Client {} based on duration of {} Ms", client.getMacAddress(), client.getDurationMs()); } metricDetails.setLastMetricTimestamp(timestamp); @@ -2114,7 +2182,7 @@ public class OpensyncExternalIntegrationMqttMessageProcessor { for (ClientReport clientReport : report.getClientsList()) { - LOG.info("ClientReport for channel {} RadioBand {}", clientReport.getChannel(), clientReport.getBand()); + LOG.debug("ClientReport for channel {} RadioBand {}", clientReport.getChannel(), clientReport.getBand()); if (smr.getCreatedTimestamp() < clientReport.getTimestampMs()) { smr.setCreatedTimestamp(clientReport.getTimestampMs()); @@ -2157,7 +2225,7 @@ public class OpensyncExternalIntegrationMqttMessageProcessor { } } } - LOG.info("Client Report Date is {}", new Date(clientReport.getTimestampMs())); + LOG.debug("Client Report Date is {}", new Date(clientReport.getTimestampMs())); int numConnectedClients = 0; for (Client client : clientReport.getClientListList()) { if (client.hasStats()) { @@ -2237,7 +2305,7 @@ public class OpensyncExternalIntegrationMqttMessageProcessor { } } catch (Exception e) { - LOG.info("Unabled to update client {} session {}", client, e); + LOG.error("Unabled to update client {}", client, e); } } @@ -2267,7 +2335,7 @@ public class OpensyncExternalIntegrationMqttMessageProcessor { } - LOG.info("ApSsidMetrics {}", apSsidMetrics); + LOG.debug("ApSsidMetrics {}", apSsidMetrics); } @@ -2313,8 +2381,18 @@ public class OpensyncExternalIntegrationMqttMessageProcessor { ProfileContainer profileContainer = new ProfileContainer( profileServiceInterface.getProfileWithChildren(profileId)); - RfConfiguration rfConfig = (RfConfiguration) profileContainer.getChildOfTypeOrNull(profileId, ProfileType.rf) + + Profile rfProfile = profileContainer.getChildOfTypeOrNull(profileId, ProfileType.rf); + RfConfiguration rfConfig = null; + if (rfProfile != null) { + rfConfig = (RfConfiguration) profileContainer.getChildOfTypeOrNull(profileId, ProfileType.rf) .getDetails(); + } + + if (rfConfig == null) { + LOG.warn("Cannot get RfConfiguration for customerId {} equipmentId {}", customerId,equipmentId); + return; + } for (Survey survey : report.getSurveyList()) { @@ -2374,7 +2452,7 @@ public class OpensyncExternalIntegrationMqttMessageProcessor { smr.setCreatedTimestamp(survey.getTimestampMs()); metricRecordList.add(smr); - LOG.info("ChannelInfoReports {}", channelInfoReports); + LOG.debug("ChannelInfoReports {}", channelInfoReports); } diff --git a/opensync-ext-cloud/src/test/java/com/telecominfraproject/wlan/opensync/external/integration/OpensyncExternalIntegrationMqttMessageProcessorTest.java b/opensync-ext-cloud/src/test/java/com/telecominfraproject/wlan/opensync/external/integration/OpensyncExternalIntegrationMqttMessageProcessorTest.java index 6075ea2..2ab0ca1 100644 --- a/opensync-ext-cloud/src/test/java/com/telecominfraproject/wlan/opensync/external/integration/OpensyncExternalIntegrationMqttMessageProcessorTest.java +++ b/opensync-ext-cloud/src/test/java/com/telecominfraproject/wlan/opensync/external/integration/OpensyncExternalIntegrationMqttMessageProcessorTest.java @@ -39,10 +39,15 @@ import com.telecominfraproject.wlan.core.model.equipment.MacAddress; import com.telecominfraproject.wlan.core.model.equipment.RadioType; import com.telecominfraproject.wlan.customer.service.CustomerServiceInterface; import com.telecominfraproject.wlan.equipment.EquipmentServiceInterface; +import com.telecominfraproject.wlan.equipment.models.ApElementConfiguration; +import com.telecominfraproject.wlan.equipment.models.Equipment; import com.telecominfraproject.wlan.firmware.FirmwareServiceInterface; import com.telecominfraproject.wlan.location.service.LocationServiceInterface; import com.telecominfraproject.wlan.opensync.external.integration.controller.OpensyncCloudGatewayController; import com.telecominfraproject.wlan.profile.ProfileServiceInterface; +import com.telecominfraproject.wlan.profile.models.ProfileContainer; +import com.telecominfraproject.wlan.profile.models.ProfileType; +import com.telecominfraproject.wlan.profile.rf.models.RfConfiguration; import com.telecominfraproject.wlan.routing.RoutingServiceInterface; import com.telecominfraproject.wlan.servicemetric.apnode.models.ApNodeMetrics; import com.telecominfraproject.wlan.servicemetric.apnode.models.StateUpDownError; @@ -53,17 +58,19 @@ import com.telecominfraproject.wlan.status.models.Status; import com.telecominfraproject.wlan.status.models.StatusDataType; import sts.OpensyncStats.AssocType; +import sts.OpensyncStats.ChannelSwitchReason; import sts.OpensyncStats.Client; import sts.OpensyncStats.ClientReport; import sts.OpensyncStats.DNSProbeMetric; import sts.OpensyncStats.EventReport; +import sts.OpensyncStats.EventReport.ChannelSwitchEvent; +import sts.OpensyncStats.EventReport.ClientAssocEvent; import sts.OpensyncStats.NetworkProbe; import sts.OpensyncStats.RADIUSMetrics; import sts.OpensyncStats.RadioBandType; import sts.OpensyncStats.Report; import sts.OpensyncStats.StateUpDown; import sts.OpensyncStats.VLANMetrics; -import sts.OpensyncStats.EventReport.ClientAssocEvent; @RunWith(SpringRunner.class) @ActiveProfiles(profiles = { "integration_test", }) @@ -164,6 +171,20 @@ public class OpensyncExternalIntegrationMqttMessageProcessorTest { @Test public void testProcessMqttMessageStringReport() { + Equipment equipment = new Equipment(); + + equipment.setDetails(ApElementConfiguration.createWithDefaults()); + + equipment.setId(1L); + + Mockito.when( + equipmentServiceInterface.getByInventoryIdOrNull(ArgumentMatchers.eq("Test_Client_21P10C68818122"))) + .thenReturn(equipment); + + equipment.setProfileId(0L); + + Mockito.when(equipmentServiceInterface.getOrNull(1L)).thenReturn(equipment); + Mockito.when(equipmentServiceInterface.get(1L)).thenReturn(equipment); Report report = Report.newBuilder().setNodeID("21P10C68818122") .addAllClients(getOpensyncStatsClientReportsList()) @@ -341,8 +362,15 @@ public class OpensyncExternalIntegrationMqttMessageProcessorTest { clientSessionBuilder.addAllClientAssocEvent(clientAssocEventList); List clientSessionList = new ArrayList<>(); clientSessionList.add(clientSessionBuilder.build()); + + sts.OpensyncStats.EventReport.ChannelSwitchEvent.Builder channelSwitchEventBuilder = sts.OpensyncStats.EventReport.ChannelSwitchEvent.getDefaultInstance().toBuilder(); + channelSwitchEventBuilder.setBand(RadioBandType.BAND5GL).setChannel(40).setReason(ChannelSwitchReason.high_interference).setTimestampMs(System.currentTimeMillis()); + List channelSwitchEventList = new ArrayList<>(); + channelSwitchEventList.add(channelSwitchEventBuilder.build()); + eventReportBuilder.addAllClientSession(clientSessionList); + eventReportBuilder.addAllChannelSwitch(channelSwitchEventList); eventReportList.add(eventReportBuilder.build()); 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 3edf2f8..27ab85d 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 @@ -684,13 +684,17 @@ public class OvsdbDao { CompletableFuture fResult = ovsdbClient.transact(ovsdbName, operations); OperationResult[] result = fResult.get(ovsdbTimeoutSec, TimeUnit.SECONDS); - if (LOG.isDebugEnabled()) { LOG.debug("Updated {}:", wifiStatsConfigDbTable); for (OperationResult res : result) { LOG.debug("Op Result {}", res); + if (res instanceof InsertResult) { + LOG.info("updateDeviceStatsReportingInterval insert new row result {}", ((InsertResult)res)); + // for insert, make sure it is actually in the table + confirmRowExistsInTable(ovsdbClient, ((InsertResult) res).getUuid(), wifiStatsConfigDbTable); + } } - } + } catch (OvsdbClientException | TimeoutException | ExecutionException | InterruptedException e) { throw new RuntimeException(e); @@ -722,8 +726,11 @@ public class OvsdbDao { if (LOG.isDebugEnabled()) { for (OperationResult res : result) { - - if (res instanceof ErrorResult) { + if (res instanceof InsertResult) { + LOG.info("enableNetworkProbeForSyntheticClient insert new row result {}", ((InsertResult)res)); + // for insert, make sure it is actually in the table + confirmRowExistsInTable(ovsdbClient, ((InsertResult) res).getUuid(), wifiStatsConfigDbTable); + } else if (res instanceof ErrorResult) { LOG.error("Could not update {}:", wifiStatsConfigDbTable); LOG.error("Error: {} Details: {}", ((ErrorResult) res).getError(), ((ErrorResult) res).getDetails()); @@ -1709,67 +1716,6 @@ public class OvsdbDao { } } - public void removeAllGreTunnels(OvsdbClient ovsdbClient, OpensyncAPConfig opensyncAPConfig) { - try { - List operations = new ArrayList<>(); - List conditions = new ArrayList<>(); - if (opensyncAPConfig == null || opensyncAPConfig.getApProfile() == null) { - conditions.add(new Condition("if_type", Function.EQUALS, new Atom<>("gre"))); - operations.add(new Delete(wifiInetConfigDbTable, conditions)); - CompletableFuture fResult = ovsdbClient.transact(ovsdbName, operations); - OperationResult[] result = fResult.get(ovsdbTimeoutSec, TimeUnit.SECONDS); - if (LOG.isDebugEnabled()) { - - for (OperationResult res : result) { - LOG.debug("removeAllGreTunnels Op Result {}", res); - } - } - } else { - - ApNetworkConfiguration profileDetails = (ApNetworkConfiguration) opensyncAPConfig.getApProfile() - .getDetails(); - String greTunnelName = profileDetails.getGreTunnelName(); - - conditions.add(new Condition("if_type", Function.EQUALS, new Atom<>("gre"))); - operations.add(new Select(wifiInetConfigDbTable, conditions)); - - CompletableFuture fResult = ovsdbClient.transact(ovsdbName, operations); - OperationResult[] result = fResult.get(ovsdbTimeoutSec, TimeUnit.SECONDS); - - if (((SelectResult) result[0]).getRows().isEmpty()) { - LOG.debug("No Gre Tunnels present"); - return; - } else { - operations.clear(); - for (Row row : ((SelectResult) result[0]).getRows()) { - String ifName = row.getStringColumn("if_name"); - if (greTunnelName != null && !greTunnelName.equals(ifName)) { - List deleteCondition = new ArrayList<>(); - deleteCondition.add(new Condition("if_name", Function.EQUALS, new Atom<>(ifName))); - operations.add(new Delete(wifiInetConfigDbTable, deleteCondition)); - } - } - - } - - ovsdbClient.transact(ovsdbName, operations); - fResult.get(ovsdbTimeoutSec, TimeUnit.SECONDS); - - if (LOG.isDebugEnabled()) { - - for (OperationResult res : result) { - LOG.debug("removeAllGreTunnels Op Result {}", res); - } - } - - } - } catch (OvsdbClientException | InterruptedException | ExecutionException | TimeoutException e) { - LOG.error("Could not delete GreTunnel Configs", e); - throw new RuntimeException(e); - } - - } - public void removeAllInetConfigs(OvsdbClient ovsdbClient) { try { Collection provisionedWifiInetConfigs = getProvisionedWifiInetConfigs(ovsdbClient) @@ -1789,13 +1735,31 @@ public class OvsdbDao { CompletableFuture fResult = ovsdbClient.transact(ovsdbName, operations); OperationResult[] result = fResult.get(ovsdbTimeoutSec, TimeUnit.SECONDS); - if (LOG.isDebugEnabled()) { - LOG.debug("Removed all existing vif, vlan, and gre interface configs from {}:", wifiInetConfigDbTable); + LOG.info("Removed all existing vif, vlan, and gre interface configs from {}:", wifiInetConfigDbTable); + + for (OperationResult res : result) { + LOG.info("Op Result {}", res); + } + + provisionedWifiInetConfigs = getProvisionedWifiInetConfigs(ovsdbClient) + .values(); + + for (WifiInetConfigInfo inetConfigInfo : provisionedWifiInetConfigs) { + if (inetConfigInfo.ifType.equals("vif") || inetConfigInfo.ifType.equals("gre")) { + throw new RuntimeException("Failed to remove all vif and gre interface configurations from Wifi_Inet_Config dbTable, still has " + provisionedWifiInetConfigs.stream().filter(new Predicate() { + + @Override + public boolean test(WifiInetConfigInfo t) { + if ((t.ifType.equals("vif")) || (t.ifType.equals("gre"))) return true; + return false; + } + + }).collect(Collectors.toList()) ); - for (OperationResult res : result) { - LOG.debug("Op Result {}", res); } } + + } catch (OvsdbClientException | TimeoutException | ExecutionException | InterruptedException e) { LOG.error("Error in removeAllInetConfigs", e); @@ -1822,6 +1786,11 @@ public class OvsdbDao { LOG.debug("Op Result {}", res); } } + Map provisionedVifConfigs = getProvisionedWifiVifConfigs(ovsdbClient); + // this should be empty + if (!provisionedVifConfigs.isEmpty()) { + throw new RuntimeException("Failed to remove all vif configurations from Wifi_VIF_Config dbTable, still has " + provisionedVifConfigs.values() ); + }; LOG.info("Removed all ssids"); @@ -2684,7 +2653,7 @@ public class OvsdbDao { throw new IllegalStateException("Wifi_VIF_Config entry was not created successfully"); } - confirmVifConfigRow(ovsdbClient, vifConfigUuid); + confirmRowExistsInTable(ovsdbClient, vifConfigUuid, wifiVifConfigDbTable); LOG.info("configureSingleSsid:Provisioned SSID {} on interface {} / {}", ssid, vifInterfaceName, radioFreqBand); @@ -2697,25 +2666,25 @@ public class OvsdbDao { } } - - private void confirmVifConfigRow(OvsdbClient ovsdbClient, Uuid vifConfigUuid) { + + private void confirmRowExistsInTable(OvsdbClient ovsdbClient, Uuid rowUuid, String table) { try { List conditions = new ArrayList<>(); - conditions.add(new Condition("_uuid", Function.EQUALS, new Atom<>(vifConfigUuid))); + conditions.add(new Condition("_uuid", Function.EQUALS, new Atom<>(rowUuid))); List operations = new ArrayList<>(); - operations.add(new Select(wifiVifConfigDbTable, conditions)); + operations.add(new Select(table, conditions)); CompletableFuture fResult = ovsdbClient.transact(ovsdbName, operations); OperationResult[] result = fResult.get(ovsdbTimeoutSec, TimeUnit.SECONDS); for (OperationResult res : result) { if (res instanceof SelectResult) { - LOG.info("Select Result for confirmVifConfigRow with Uuid {} {}", vifConfigUuid, + LOG.info("Select Result for confirmRowExistsInTable {} with Uuid {} {}", table, rowUuid, ((SelectResult) res).getRows()); } } } catch (OvsdbClientException | InterruptedException | ExecutionException | TimeoutException e) { - LOG.error("Unable to confirm creation of VifConfig row for Uuid {}", vifConfigUuid, e); + LOG.error("Unable to confirm existence of row in table {} for Uuid {}", table, rowUuid, e); throw new RuntimeException(e); } } @@ -3541,7 +3510,15 @@ public class OvsdbDao { LOG.debug("Updated Inet {}", ifName); for (OperationResult res : result) { - LOG.debug("Op Result {}", res); + + if (res instanceof InsertResult) { + LOG.info("configureInetInterface insert new row result {}", ((InsertResult)res)); + // for insert, make sure it is actually in the table + confirmRowExistsInTable(ovsdbClient, ((InsertResult) res).getUuid(), wifiInetConfigDbTable); + } else if (res instanceof UpdateResult) { + LOG.info("configureInetInterface update new row result {}", ((UpdateResult)res)); + } + } } catch (OvsdbClientException | TimeoutException | ExecutionException | InterruptedException e) { @@ -3789,8 +3766,6 @@ public class OvsdbDao { operations.add(newHs20Config); - // } - } CompletableFuture fResult = ovsdbClient.transact(ovsdbName, operations); @@ -3798,6 +3773,11 @@ public class OvsdbDao { for (OperationResult res : result) { LOG.debug("provisionHotspot20Config Op Result {}", res); + if (res instanceof InsertResult) { + LOG.info("provisionHotspot20Config insert new row result {}", ((InsertResult)res)); + // for insert, make sure it is actually in the table + confirmRowExistsInTable(ovsdbClient, ((InsertResult) res).getUuid(), hotspot20ConfigDbTable); + } } } @@ -3871,6 +3851,14 @@ public class OvsdbDao { for (OperationResult res : result) { LOG.debug("provisionHotspot20OsuProviders Op Result {}", res); + if (res instanceof InsertResult) { + LOG.info("provisionHotspot20OsuProviders insert new row result {}", ((InsertResult)res)); + // for insert, make sure it is actually in the table + confirmRowExistsInTable(ovsdbClient, ((InsertResult) res).getUuid(), hotspot20OsuProvidersDbTable); + } else if (res instanceof UpdateResult) { + LOG.info("provisionHotspot20OsuProviders update row result {}", ((UpdateResult)res)); + + } } } @@ -4075,6 +4063,14 @@ public class OvsdbDao { for (OperationResult res : result) { LOG.debug("provisionHotspot20Config Op Result {}", res); + if (res instanceof InsertResult) { + LOG.info("provisionHotspot20Config insert new row result {}", ((InsertResult)res)); + // for insert, make sure it is actually in the table + confirmRowExistsInTable(ovsdbClient, ((InsertResult) res).getUuid(), hotspot20IconConfigDbTable); + } else if (res instanceof UpdateResult) { + LOG.info("provisionHotspot20Config update row result {}", ((UpdateResult)res)); + + } } } @@ -4596,11 +4592,15 @@ public class OvsdbDao { CompletableFuture fResult = ovsdbClient.transact(ovsdbName, operations); OperationResult[] result = fResult.get(ovsdbTimeoutSec, TimeUnit.SECONDS); - if (LOG.isDebugEnabled()) { - for (OperationResult res : result) { + if (res instanceof InsertResult) { + LOG.info("provisionVideoVoiceStats insert new row result {}", ((InsertResult)res)); + // for insert, make sure it is actually in the table + confirmRowExistsInTable(ovsdbClient, ((InsertResult) res).getUuid(), wifiStatsConfigDbTable); + } else if (res instanceof UpdateResult) { + LOG.info("provisionVideoVoiceStats update row result {}", ((UpdateResult)res)); - if (res instanceof ErrorResult) { + }else if (res instanceof ErrorResult) { LOG.error("Could not update {}:", wifiStatsConfigDbTable); LOG.error("Error: {} Details: {}", ((ErrorResult) res).getError(), ((ErrorResult) res).getDetails()); @@ -4609,7 +4609,7 @@ public class OvsdbDao { LOG.debug("Op Result {}", res); } } - } + } catch (OvsdbClientException | TimeoutException | ExecutionException | InterruptedException e) { throw new RuntimeException(e); @@ -4643,8 +4643,13 @@ public class OvsdbDao { if (LOG.isDebugEnabled()) { for (OperationResult res : result) { - - if (res instanceof ErrorResult) { + if (res instanceof InsertResult) { + LOG.info("provisionEventReporting insert new row result {}", ((InsertResult)res)); + // for insert, make sure it is actually in the table + confirmRowExistsInTable(ovsdbClient, ((InsertResult) res).getUuid(), wifiStatsConfigDbTable); + } else if (res instanceof UpdateResult) { + LOG.info("provisionEventReporting update row result {}", ((UpdateResult)res)); + } else if (res instanceof ErrorResult) { LOG.error("Could not update {}:", wifiStatsConfigDbTable); LOG.error("Error: {} Details: {}", ((ErrorResult) res).getError(), ((ErrorResult) res).getDetails()); @@ -4779,13 +4784,12 @@ public class OvsdbDao { CompletableFuture fResult = ovsdbClient.transact(ovsdbName, operations); OperationResult[] result = fResult.get(ovsdbTimeoutSec, TimeUnit.SECONDS); - if (LOG.isDebugEnabled()) { - LOG.debug("Removed all existing config from {}:", wifiStatsConfigDbTable); + LOG.info("Removed all existing config from {}:", wifiStatsConfigDbTable); for (OperationResult res : result) { LOG.debug("Op Result {}", res); } - } + } catch (OvsdbClientException | TimeoutException | ExecutionException | InterruptedException e) { LOG.error("Error in removeAllStatsConfigs", e); @@ -4967,6 +4971,15 @@ public class OvsdbDao { for (OperationResult res : result) { LOG.debug("Op Result {}", res); + + if (res instanceof InsertResult) { + LOG.info("configureWifiRrm insert new row result {}", ((InsertResult)res)); + // for insert, make sure it is actually in the table + confirmRowExistsInTable(ovsdbClient, ((InsertResult) res).getUuid(), wifiRrmConfigDbTable); + } else if (res instanceof UpdateResult) { + LOG.info("configureWifiRrm update row result {}", ((UpdateResult)res)); + } + } } @@ -4983,8 +4996,7 @@ public class OvsdbDao { for (OperationResult res : result) { if (res instanceof UpdateResult) { - - LOG.info("Delete Result {}", (UpdateResult) res); + LOG.info("removeWifiRrm result {}", (UpdateResult) res); } } diff --git a/opensync-gateway/src/test/java/com/telecominfraproject/wlan/opensync/ovsdb/dao/OvsdbDaoTest.java b/opensync-gateway/src/test/java/com/telecominfraproject/wlan/opensync/ovsdb/dao/OvsdbDaoTest.java index 26ee67d..0b32fd9 100644 --- a/opensync-gateway/src/test/java/com/telecominfraproject/wlan/opensync/ovsdb/dao/OvsdbDaoTest.java +++ b/opensync-gateway/src/test/java/com/telecominfraproject/wlan/opensync/ovsdb/dao/OvsdbDaoTest.java @@ -142,48 +142,6 @@ public class OvsdbDaoTest { mockito.finishMocking(); } - @Test - public void testRemoveAllGreTunnels() throws Exception { - List rows = new ArrayList<>(); - OperationResult[] operationResult = new OperationResult[] { new SelectResult(rows) }; - Mockito.when(ovsdbClient.transact(Mockito.eq(OvsdbDao.ovsdbName), Mockito.anyList())) - .thenReturn(selectionFutureResult); - Mockito.when(selectionFutureResult.get(30, TimeUnit.SECONDS)).thenReturn(operationResult); - Profile apProfile = new Profile(); - apProfile.setCustomerId(2); - apProfile.setId(1L); - apProfile.setName("ApProfile"); - apProfile.setProfileType(ProfileType.equipment_ap); - ApNetworkConfiguration tunnelProfileDetails = ApNetworkConfiguration.createWithDefaults(); - - tunnelProfileDetails.setGreLocalInetAddr(InetAddress.getByName("10.0.10.10")); - tunnelProfileDetails.setGreRemoteInetAddr(InetAddress.getByName("192.168.0.10")); - tunnelProfileDetails.setGreTunnelName("gre1"); - tunnelProfileDetails.setGreParentIfName("wan"); - apProfile.setDetails(tunnelProfileDetails); - OpensyncAPConfig apConfig = Mockito.mock(OpensyncAPConfig.class); - Mockito.when(apConfig.getApProfile()).thenReturn(apProfile); - ovsdbDao.removeAllGreTunnels(ovsdbClient, apConfig); - - Mockito.verify(apConfig, Mockito.times(2)).getApProfile(); - Mockito.verify(ovsdbClient, Mockito.times(1)).transact(Mockito.eq(OvsdbDao.ovsdbName), Mockito.anyList()); - - } - - @Test - public void testRemoveAllGreTunnelsNoProfile() throws Exception { - List rows = new ArrayList<>(); - OperationResult[] operationResult = new OperationResult[] { new SelectResult(rows) }; - Mockito.when(ovsdbClient.transact(Mockito.eq(OvsdbDao.ovsdbName), Mockito.anyList())) - .thenReturn(selectionFutureResult); - Mockito.when(selectionFutureResult.get(30, TimeUnit.SECONDS)).thenReturn(operationResult); - - ovsdbDao.removeAllGreTunnels(ovsdbClient, null); - - Mockito.verify(ovsdbClient, Mockito.times(1)).transact(Mockito.eq(OvsdbDao.ovsdbName), Mockito.anyList()); - - } - @Test public void testConfigureGreTunnels() throws Exception { List rows = new ArrayList<>(); @@ -339,7 +297,7 @@ public class OvsdbDaoTest { ovsdbDao.configureHotspots(ovsdbClient, apConfig); - Mockito.verify(futureResult, Mockito.times(11)).get(Mockito.anyLong(), Mockito.eq(TimeUnit.SECONDS)); + Mockito.verify(futureResult, Mockito.times(13)).get(Mockito.anyLong(), Mockito.eq(TimeUnit.SECONDS)); }