Refine ClientCount based on MQTT events

This commit is contained in:
Mike Hansen
2020-06-29 18:14:20 -04:00
parent 8ebbfd2f93
commit 9274badad7

View File

@@ -3,6 +3,7 @@ package com.telecominfraproject.wlan.opensync.external.integration;
import java.net.InetAddress; import java.net.InetAddress;
import java.net.UnknownHostException; import java.net.UnknownHostException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap; import java.util.HashMap;
import java.util.HashSet; import java.util.HashSet;
import java.util.List; import java.util.List;
@@ -1155,12 +1156,14 @@ public class OpensyncExternalIntegrationCloud implements OpensyncExternalIntegra
} }
} }
LOG.debug("ApClientMetrics Report {}", cMetrics); LOG.debug("ApClientMetrics Report {}", cMetrics);
} }
updateClientConnectionDetails(customerId, equipmentId, clReport,
getRadioTypeFromOpensyncRadioBand(clReport.getBand()));
} }
} }
@@ -1226,65 +1229,82 @@ public class OpensyncExternalIntegrationCloud implements OpensyncExternalIntegra
} }
private void handleClientSessionUpdate(int customerId, long equipmentId, String apId, long locationId, int channel, private void handleClientSessionUpdate(int customerId, long equipmentId, String apId, long locationId, int channel,
RadioBandType band, long timestamp, sts.OpensyncStats.Client client, String nodeId, MacAddress macAddress, RadioBandType band, long timestamp, sts.OpensyncStats.Client client, String nodeId, MacAddress bssidAddress,
String ssid) { String ssid) {
try
LOG.debug("Client numConnected {} connectOffsetMs {} numDisconnected {} disconnectOffsetMs {} durationMs {}", {
client.getConnectCount(), client.getConnectOffsetMs(), client.getDisconnectCount(), LOG.info("handleClientSessionUpdate for {} on BSSID {}", client.getMacAddress(),
client.getDisconnectOffsetMs(), client.getDurationMs()); bssidAddress.getAddressAsString());
com.telecominfraproject.wlan.client.models.Client clientInstance = clientServiceInterface.getOrNull(customerId, com.telecominfraproject.wlan.client.models.Client clientInstance = clientServiceInterface
new MacAddress(client.getMacAddress())); .getOrNull(customerId, new MacAddress(client.getMacAddress()));
if (clientInstance == null) { if (!client.getConnected()) {
clientInstance = new com.telecominfraproject.wlan.client.models.Client(); if (clientInstance != null) {
clientInstance.setCustomerId(customerId); clientServiceInterface.delete(customerId, clientInstance.getMacAddress());
clientInstance.setMacAddress(new MacAddress(client.getMacAddress())); }
clientInstance.setDetails(new ClientInfoDetails()); } else {
clientInstance = clientServiceInterface.create(clientInstance); if (clientInstance == null) {
} clientInstance = new com.telecominfraproject.wlan.client.models.Client();
ClientInfoDetails clientDetails = (ClientInfoDetails) clientInstance.getDetails(); clientInstance.setCustomerId(customerId);
clientDetails.setHostName(nodeId); clientInstance.setMacAddress(new MacAddress(client.getMacAddress()));
clientInstance.setDetails(clientDetails); clientInstance.setDetails(new ClientInfoDetails());
clientInstance = clientServiceInterface.update(clientInstance); clientInstance = clientServiceInterface.create(clientInstance);
}
try { ClientInfoDetails clientDetails = (ClientInfoDetails) clientInstance.getDetails();
clientDetails.setHostName(nodeId);
ClientSession clientSession = clientServiceInterface.getSessionOrNull(customerId, equipmentId, clientInstance.setDetails(clientDetails);
clientInstance.getMacAddress()); clientInstance = clientServiceInterface.update(clientInstance);
if (clientSession == null) {
LOG.debug("No session found for Client {}, creating new one.", client.getMacAddress());
clientSession = new ClientSession();
clientSession.setCustomerId(customerId);
clientSession.setEquipmentId(equipmentId);
clientSession.setLocationId(locationId);
clientSession.setMacAddress(new MacAddress(client.getMacAddress()));
clientSession.setDetails(new ClientSessionDetails());
clientSession = clientServiceInterface.updateSession(clientSession);
} }
ClientSessionDetails clientSessionDetails = clientSession.getDetails(); ClientSession clientSession = clientServiceInterface.getSessionOrNull(customerId, equipmentId,
clientSessionDetails.setRadioType(getRadioTypeFromOpensyncRadioBand(band)); bssidAddress);
clientSessionDetails.setSessionId(clientSession.getMacAddress().getAddressAsLong()); // For this session if we have a disconnected client, remove, else
clientSessionDetails.setSsid(ssid); // update
clientSessionDetails.setAssociationStatus(0); if (!client.getConnected()) {
clientSessionDetails.setAssocTimestamp(timestamp - client.getConnectOffsetMs()); if (clientSession != null) {
clientSessionDetails.setAuthTimestamp(timestamp - client.getConnectOffsetMs()); clientSession = clientServiceInterface.deleteSession(customerId, equipmentId,
clientSessionDetails.setFirstDataRcvdTimestamp(timestamp); clientSession.getMacAddress());
clientSessionDetails.setFirstDataSentTimestamp(timestamp); LOG.debug("Client session {} deleted due to disconnect", clientSession);
clientSessionDetails.setLastRxTimestamp(timestamp); }
clientSessionDetails.setHostname(nodeId); } else {
if (clientSession == null) {
LOG.debug("No session found for Client {}, creating new one.", client.getMacAddress());
clientSession = new ClientSession();
clientSession.setCustomerId(customerId);
clientSession.setEquipmentId(equipmentId);
clientSession.setLocationId(locationId);
clientSession.setMacAddress(new MacAddress(client.getMacAddress()));
ClientDhcpDetails dhcpDetails = new ClientDhcpDetails(clientSessionDetails.getSessionId()); ClientSessionDetails clientSessionDetails = new ClientSessionDetails();
clientSessionDetails.setDhcpDetails(dhcpDetails); clientSessionDetails.setAssocTimestamp(timestamp - client.getConnectOffsetMs());
clientSessionDetails.setAuthTimestamp(timestamp - client.getConnectOffsetMs());
clientSessionDetails.setMetricDetails(calculateClientSessionMetricDetails(client)); clientSessionDetails.setFirstDataSentTimestamp(timestamp - client.getDurationMs());
clientSession.setDetails(clientSessionDetails); clientSessionDetails.setFirstDataRcvdTimestamp(timestamp - client.getDurationMs());
clientSession.setDetails(clientSessionDetails);
clientSession = clientServiceInterface.updateSession(clientSession); clientSession = clientServiceInterface.updateSession(clientSession);
}
ClientSessionDetails clientSessionDetails = clientSession.getDetails();
clientSessionDetails.setRadioType(getRadioTypeFromOpensyncRadioBand(band));
clientSessionDetails.setSessionId(clientSession.getMacAddress().getAddressAsLong());
clientSessionDetails.setSsid(ssid);
clientSessionDetails.setAssociationStatus(0);
clientSessionDetails.setLastRxTimestamp(timestamp);
clientSessionDetails.setHostname(bssidAddress.getAddressAsString());
clientSessionDetails.setMetricDetails(calculateClientSessionMetricDetails(client));
clientSession.setDetails(clientSessionDetails);
clientSession = clientServiceInterface.updateSession(clientSession);
LOG.info("CreatedOrUpdated clientSession {}", clientSession);
}
LOG.debug("CreatedOrUpdated clientSession {}", clientSession);
} catch (Exception e) { } catch (Exception e) {
LOG.error("Error while attempting to create ClientSession and Info", e); LOG.error("Error while attempting to create ClientSession and Info", e);
} }
@@ -1388,16 +1408,22 @@ public class OpensyncExternalIntegrationCloud implements OpensyncExternalIntegra
} }
} }
} }
LOG.debug("Client Report Date is {}", new Date(clientReport.getTimestampMs()));
int numConnectedClients = 0;
for (Client client : clientReport.getClientListList()) { for (Client client : clientReport.getClientListList()) {
if (!client.hasConnected() || !client.getConnected()) {
handleClientSessionUpdate(customerId, equipmentId, apId, locationId, clientReport.getChannel(),
clientReport.getBand(), clientReport.getTimestampMs(), client, report.getNodeID(),
ssidStatistics.getBssid(), ssidStatistics.getSsid());
continue;
}
numConnectedClients += 1;
if (client.hasSsid() && client.getSsid() != null && !client.getSsid().equals("")) { if (client.hasSsid() && client.getSsid() != null && !client.getSsid().equals("")) {
ssid = client.getSsid(); ssid = client.getSsid();
} }
LOG.debug("Client {} connected {} connectedCount {}", client.getMacAddress(), client.getConnected(),
client.getConnectCount());
if (client.hasStats()) { if (client.hasStats()) {
clientMacs.add(client.getMacAddress()); clientMacs.add(client.getMacAddress());
sts.OpensyncStats.Client.Stats clientStats = client.getStats(); sts.OpensyncStats.Client.Stats clientStats = client.getStats();
@@ -1448,7 +1474,7 @@ public class OpensyncExternalIntegrationCloud implements OpensyncExternalIntegra
ssidStatistics.setNumRcvFrameForTx(txFrames); ssidStatistics.setNumRcvFrameForTx(txFrames);
ssidStatistics.setNumTxBytesSucc(txBytes - txErrors - txRetries); ssidStatistics.setNumTxBytesSucc(txBytes - txErrors - txRetries);
ssidStatistics.setNumRxRetry(rxRetries); ssidStatistics.setNumRxRetry(rxRetries);
ssidStatistics.setNumClient(clientMacs.size()); ssidStatistics.setNumClient(numConnectedClients);
ssidStatistics.setSsid(ssid); ssidStatistics.setSsid(ssid);
if (radioType != null) { if (radioType != null) {
@@ -1461,48 +1487,48 @@ public class OpensyncExternalIntegrationCloud implements OpensyncExternalIntegra
} }
if (statusDetails != null && indexOfBssid >= 0) { if (statusDetails != null && indexOfBssid >= 0) {
statusDetails.getActiveBSSIDs().get(indexOfBssid).setNumDevicesConnected(ssidStatistics.getNumClient()); statusDetails.getActiveBSSIDs().get(indexOfBssid).setNumDevicesConnected(numConnectedClients);
activeBssidsStatus.setDetails(statusDetails); activeBssidsStatus.setDetails(statusDetails);
activeBssidsStatus = statusServiceInterface.update(activeBssidsStatus); activeBssidsStatus = statusServiceInterface.update(activeBssidsStatus);
LOG.debug("update activeBSSIDs {}", activeBssidsStatus); LOG.debug("update activeBSSIDs {}", activeBssidsStatus);
} }
updateClientConnectionDetails(customerId, equipmentId, clientReport, radioType);
} }
LOG.debug("ApSsidMetrics {}", apSsidMetrics); LOG.debug("ApSsidMetrics {}", apSsidMetrics);
} }
private void updateClientConnectionDetails(int customerId, long equipmentId, ClientReport clientReport, private void updateClientConnectionDetails(int customerId, long equipmentId, ClientReport clientReport,
RadioType radioType) { RadioType radioType) {
// update client status for radio type // update client status for radio type
Status clientConnectionDetails = statusServiceInterface.getOrNull(customerId, equipmentId, Status clientConnectionStatus = statusServiceInterface.getOrNull(customerId, equipmentId,
StatusDataType.CLIENT_DETAILS); StatusDataType.CLIENT_DETAILS);
if (clientConnectionDetails == null) { if (clientConnectionStatus == null) {
clientConnectionDetails = new Status(); clientConnectionStatus = new Status();
clientConnectionDetails.setCustomerId(customerId); clientConnectionStatus.setCustomerId(customerId);
clientConnectionDetails.setEquipmentId(equipmentId); clientConnectionStatus.setEquipmentId(equipmentId);
clientConnectionDetails.setStatusDataType(StatusDataType.CLIENT_DETAILS); clientConnectionStatus.setStatusDataType(StatusDataType.CLIENT_DETAILS);
clientConnectionDetails.setDetails(new ClientConnectionDetails()); clientConnectionStatus.setDetails(new ClientConnectionDetails());
} }
ClientConnectionDetails connectionDetails = (ClientConnectionDetails)clientConnectionDetails.getDetails(); ClientConnectionDetails connectionDetails = (ClientConnectionDetails) clientConnectionStatus.getDetails();
Map<RadioType,Integer> clientsPerRadio = connectionDetails.getNumClientsPerRadio(); Map<RadioType, Integer> clientsPerRadio = connectionDetails.getNumClientsPerRadio();
if (clientsPerRadio == null) {
clientsPerRadio = new HashMap<RadioType,Integer>(); int clientCount = 0;
for (Client client : clientReport.getClientListList()) {
if (client.getConnected()) {
clientCount += 1;
}
} }
clientsPerRadio.put(radioType, clientReport.getClientListCount()); clientsPerRadio.put(radioType, clientCount);
connectionDetails.setNumClientsPerRadio(clientsPerRadio); connectionDetails.setNumClientsPerRadio(clientsPerRadio);
clientConnectionDetails.setDetails(connectionDetails); clientConnectionStatus.setDetails(connectionDetails);
clientConnectionDetails = statusServiceInterface.update(clientConnectionDetails); clientConnectionStatus = statusServiceInterface.update(clientConnectionStatus);
LOG.debug("update client connection details {}", clientConnectionDetails); LOG.info("Sending ClientConnectionDetails {}", clientConnectionStatus);
} }
int getNegativeSignedIntFromUnsigned(int unsignedValue) { int getNegativeSignedIntFromUnsigned(int unsignedValue) {