mirror of
https://github.com/Telecominfraproject/wlan-cloud-opensync-controller.git
synced 2025-11-20 20:05:05 +00:00
Refine ClientCount based on MQTT events
This commit is contained in:
@@ -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;
|
||||||
@@ -1156,11 +1157,13 @@ public class OpensyncExternalIntegrationCloud implements OpensyncExternalIntegra
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
LOG.debug("ApClientMetrics Report {}", cMetrics);
|
LOG.debug("ApClientMetrics Report {}", cMetrics);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
updateClientConnectionDetails(customerId, equipmentId, clReport,
|
||||||
|
getRadioTypeFromOpensyncRadioBand(clReport.getBand()));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -1226,15 +1229,21 @@ 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 (!client.getConnected()) {
|
||||||
|
if (clientInstance != null) {
|
||||||
|
clientServiceInterface.delete(customerId, clientInstance.getMacAddress());
|
||||||
|
}
|
||||||
|
} else {
|
||||||
if (clientInstance == null) {
|
if (clientInstance == null) {
|
||||||
clientInstance = new com.telecominfraproject.wlan.client.models.Client();
|
clientInstance = new com.telecominfraproject.wlan.client.models.Client();
|
||||||
clientInstance.setCustomerId(customerId);
|
clientInstance.setCustomerId(customerId);
|
||||||
@@ -1246,11 +1255,19 @@ public class OpensyncExternalIntegrationCloud implements OpensyncExternalIntegra
|
|||||||
clientDetails.setHostName(nodeId);
|
clientDetails.setHostName(nodeId);
|
||||||
clientInstance.setDetails(clientDetails);
|
clientInstance.setDetails(clientDetails);
|
||||||
clientInstance = clientServiceInterface.update(clientInstance);
|
clientInstance = clientServiceInterface.update(clientInstance);
|
||||||
|
}
|
||||||
try {
|
|
||||||
|
|
||||||
ClientSession clientSession = clientServiceInterface.getSessionOrNull(customerId, equipmentId,
|
ClientSession clientSession = clientServiceInterface.getSessionOrNull(customerId, equipmentId,
|
||||||
clientInstance.getMacAddress());
|
bssidAddress);
|
||||||
|
// For this session if we have a disconnected client, remove, else
|
||||||
|
// update
|
||||||
|
if (!client.getConnected()) {
|
||||||
|
if (clientSession != null) {
|
||||||
|
clientSession = clientServiceInterface.deleteSession(customerId, equipmentId,
|
||||||
|
clientSession.getMacAddress());
|
||||||
|
LOG.debug("Client session {} deleted due to disconnect", clientSession);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
if (clientSession == null) {
|
if (clientSession == null) {
|
||||||
LOG.debug("No session found for Client {}, creating new one.", client.getMacAddress());
|
LOG.debug("No session found for Client {}, creating new one.", client.getMacAddress());
|
||||||
clientSession = new ClientSession();
|
clientSession = new ClientSession();
|
||||||
@@ -1258,7 +1275,14 @@ public class OpensyncExternalIntegrationCloud implements OpensyncExternalIntegra
|
|||||||
clientSession.setEquipmentId(equipmentId);
|
clientSession.setEquipmentId(equipmentId);
|
||||||
clientSession.setLocationId(locationId);
|
clientSession.setLocationId(locationId);
|
||||||
clientSession.setMacAddress(new MacAddress(client.getMacAddress()));
|
clientSession.setMacAddress(new MacAddress(client.getMacAddress()));
|
||||||
clientSession.setDetails(new ClientSessionDetails());
|
|
||||||
|
ClientSessionDetails clientSessionDetails = new ClientSessionDetails();
|
||||||
|
clientSessionDetails.setAssocTimestamp(timestamp - client.getConnectOffsetMs());
|
||||||
|
clientSessionDetails.setAuthTimestamp(timestamp - client.getConnectOffsetMs());
|
||||||
|
|
||||||
|
clientSessionDetails.setFirstDataSentTimestamp(timestamp - client.getDurationMs());
|
||||||
|
clientSessionDetails.setFirstDataRcvdTimestamp(timestamp - client.getDurationMs());
|
||||||
|
clientSession.setDetails(clientSessionDetails);
|
||||||
|
|
||||||
clientSession = clientServiceInterface.updateSession(clientSession);
|
clientSession = clientServiceInterface.updateSession(clientSession);
|
||||||
}
|
}
|
||||||
@@ -1268,22 +1292,18 @@ public class OpensyncExternalIntegrationCloud implements OpensyncExternalIntegra
|
|||||||
clientSessionDetails.setSessionId(clientSession.getMacAddress().getAddressAsLong());
|
clientSessionDetails.setSessionId(clientSession.getMacAddress().getAddressAsLong());
|
||||||
clientSessionDetails.setSsid(ssid);
|
clientSessionDetails.setSsid(ssid);
|
||||||
clientSessionDetails.setAssociationStatus(0);
|
clientSessionDetails.setAssociationStatus(0);
|
||||||
clientSessionDetails.setAssocTimestamp(timestamp - client.getConnectOffsetMs());
|
|
||||||
clientSessionDetails.setAuthTimestamp(timestamp - client.getConnectOffsetMs());
|
|
||||||
clientSessionDetails.setFirstDataRcvdTimestamp(timestamp);
|
|
||||||
clientSessionDetails.setFirstDataSentTimestamp(timestamp);
|
|
||||||
clientSessionDetails.setLastRxTimestamp(timestamp);
|
clientSessionDetails.setLastRxTimestamp(timestamp);
|
||||||
clientSessionDetails.setHostname(nodeId);
|
|
||||||
|
|
||||||
ClientDhcpDetails dhcpDetails = new ClientDhcpDetails(clientSessionDetails.getSessionId());
|
clientSessionDetails.setHostname(bssidAddress.getAddressAsString());
|
||||||
clientSessionDetails.setDhcpDetails(dhcpDetails);
|
|
||||||
|
|
||||||
clientSessionDetails.setMetricDetails(calculateClientSessionMetricDetails(client));
|
clientSessionDetails.setMetricDetails(calculateClientSessionMetricDetails(client));
|
||||||
clientSession.setDetails(clientSessionDetails);
|
clientSession.setDetails(clientSessionDetails);
|
||||||
|
|
||||||
clientSession = clientServiceInterface.updateSession(clientSession);
|
clientSession = clientServiceInterface.updateSession(clientSession);
|
||||||
|
|
||||||
LOG.debug("CreatedOrUpdated clientSession {}", clientSession);
|
LOG.info("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) {
|
||||||
|
|||||||
Reference in New Issue
Block a user