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 f2fa3ad..61c1210 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 @@ -3,14 +3,12 @@ package com.telecominfraproject.wlan.opensync.external.integration; import java.net.InetAddress; import java.net.UnknownHostException; import java.util.ArrayList; -import java.util.Date; import java.util.HashMap; import java.util.HashSet; import java.util.List; import java.util.Map; import java.util.Optional; import java.util.Set; -import java.util.function.Predicate; import java.util.stream.Collectors; import javax.annotation.PostConstruct; @@ -25,35 +23,19 @@ import org.springframework.stereotype.Component; import com.google.common.collect.ImmutableSet; import com.google.common.collect.Lists; -import com.google.protobuf.Descriptors; -import com.google.protobuf.InvalidProtocolBufferException; -import com.google.protobuf.util.JsonFormat; -import com.google.protobuf.util.JsonFormat.TypeRegistry; -import com.telecominfraproject.wlan.alarm.AlarmServiceInterface; import com.telecominfraproject.wlan.client.ClientServiceInterface; import com.telecominfraproject.wlan.client.info.models.ClientInfoDetails; import com.telecominfraproject.wlan.client.session.models.AssociationState; import com.telecominfraproject.wlan.client.session.models.ClientDhcpDetails; -import com.telecominfraproject.wlan.client.session.models.ClientEapDetails; -import com.telecominfraproject.wlan.client.session.models.ClientFailureDetails; import com.telecominfraproject.wlan.client.session.models.ClientSession; 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.entity.CountryCode; import com.telecominfraproject.wlan.core.model.equipment.AutoOrManualValue; -import com.telecominfraproject.wlan.core.model.equipment.ChannelBandwidth; -import com.telecominfraproject.wlan.core.model.equipment.DetectedAuthMode; import com.telecominfraproject.wlan.core.model.equipment.EquipmentType; import com.telecominfraproject.wlan.core.model.equipment.MacAddress; -import com.telecominfraproject.wlan.core.model.equipment.NeighborScanPacketType; -import com.telecominfraproject.wlan.core.model.equipment.NetworkType; import com.telecominfraproject.wlan.core.model.equipment.RadioType; -import com.telecominfraproject.wlan.core.model.equipment.SecurityType; -import com.telecominfraproject.wlan.core.model.equipment.WiFiSessionUtility; import com.telecominfraproject.wlan.core.model.pagination.PaginationContext; import com.telecominfraproject.wlan.core.model.pagination.PaginationResponse; -import com.telecominfraproject.wlan.core.model.utils.DecibelUtils; import com.telecominfraproject.wlan.customer.models.Customer; import com.telecominfraproject.wlan.customer.models.EquipmentAutoProvisioningSettings; import com.telecominfraproject.wlan.customer.service.CustomerServiceInterface; @@ -90,27 +72,10 @@ import com.telecominfraproject.wlan.profile.models.ProfileContainer; import com.telecominfraproject.wlan.profile.models.ProfileType; import com.telecominfraproject.wlan.profile.network.models.ApNetworkConfiguration; import com.telecominfraproject.wlan.profile.network.models.RadioProfileConfiguration; -import com.telecominfraproject.wlan.profile.ssid.models.RadioBasedSsidConfiguration; import com.telecominfraproject.wlan.profile.ssid.models.SsidConfiguration; import com.telecominfraproject.wlan.profile.ssid.models.SsidConfiguration.SecureMode; import com.telecominfraproject.wlan.routing.RoutingServiceInterface; import com.telecominfraproject.wlan.routing.models.EquipmentRoutingRecord; -import com.telecominfraproject.wlan.servicemetric.apnode.models.ApNodeMetrics; -import com.telecominfraproject.wlan.servicemetric.apnode.models.ApPerformance; -import com.telecominfraproject.wlan.servicemetric.apnode.models.DnsProbeMetric; -import com.telecominfraproject.wlan.servicemetric.apnode.models.EthernetLinkState; -import com.telecominfraproject.wlan.servicemetric.apnode.models.NetworkProbeMetrics; -import com.telecominfraproject.wlan.servicemetric.apnode.models.RadioStatistics; -import com.telecominfraproject.wlan.servicemetric.apnode.models.RadioUtilization; -import com.telecominfraproject.wlan.servicemetric.apnode.models.StateUpDownError; -import com.telecominfraproject.wlan.servicemetric.apssid.models.ApSsidMetrics; -import com.telecominfraproject.wlan.servicemetric.apssid.models.SsidStatistics; -import com.telecominfraproject.wlan.servicemetric.channelinfo.models.ChannelInfo; -import com.telecominfraproject.wlan.servicemetric.channelinfo.models.ChannelInfoReports; -import com.telecominfraproject.wlan.servicemetric.client.models.ClientMetrics; -import com.telecominfraproject.wlan.servicemetric.models.ServiceMetric; -import com.telecominfraproject.wlan.servicemetric.neighbourscan.models.NeighbourReport; -import com.telecominfraproject.wlan.servicemetric.neighbourscan.models.NeighbourScanReports; import com.telecominfraproject.wlan.status.StatusServiceInterface; import com.telecominfraproject.wlan.status.equipment.models.EquipmentAdminStatusData; import com.telecominfraproject.wlan.status.equipment.models.EquipmentLANStatusData; @@ -123,44 +88,13 @@ import com.telecominfraproject.wlan.status.equipment.models.VLANStatusData; import com.telecominfraproject.wlan.status.equipment.report.models.ActiveBSSID; import com.telecominfraproject.wlan.status.equipment.report.models.ActiveBSSIDs; import com.telecominfraproject.wlan.status.equipment.report.models.ClientConnectionDetails; -import com.telecominfraproject.wlan.status.equipment.report.models.EquipmentCapacityDetails; -import com.telecominfraproject.wlan.status.equipment.report.models.OperatingSystemPerformance; -import com.telecominfraproject.wlan.status.equipment.report.models.RadioUtilizationReport; 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 sts.OpensyncStats; -import sts.OpensyncStats.AssocType; -import sts.OpensyncStats.Client; -import sts.OpensyncStats.ClientReport; -import sts.OpensyncStats.DNSProbeMetric; -import sts.OpensyncStats.Device; -import sts.OpensyncStats.Device.RadioTemp; -import sts.OpensyncStats.EventReport.ClientAssocEvent; -import sts.OpensyncStats.EventReport.ClientAuthEvent; -import sts.OpensyncStats.EventReport.ClientDisconnectEvent; -import sts.OpensyncStats.EventReport.ClientFailureEvent; -import sts.OpensyncStats.EventReport.ClientFirstDataEvent; -import sts.OpensyncStats.EventReport.ClientIdEvent; -import sts.OpensyncStats.EventReport.ClientIpEvent; -import sts.OpensyncStats.EventReport.ClientTimeoutEvent; -import sts.OpensyncStats.FrameType; -import sts.OpensyncStats.Neighbor; -import sts.OpensyncStats.Neighbor.NeighborBss; -import sts.OpensyncStats.NetworkProbe; -import sts.OpensyncStats.RADIUSMetrics; -import sts.OpensyncStats.RadioBandType; import sts.OpensyncStats.Report; -import sts.OpensyncStats.Survey; -import sts.OpensyncStats.Survey.SurveySample; -import sts.OpensyncStats.SurveyType; -import sts.OpensyncStats.UCCReport; -import sts.OpensyncStats.VLANMetrics; -import traffic.NetworkMetadata; import traffic.NetworkMetadata.FlowReport; -import wc.stats.IpDnsTelemetry; import wc.stats.IpDnsTelemetry.WCStatsReport; @org.springframework.context.annotation.Profile("opensync_cloud_config") @@ -169,8 +103,6 @@ public class OpensyncExternalIntegrationCloud implements OpensyncExternalIntegra private static final Logger LOG = LoggerFactory.getLogger(OpensyncExternalIntegrationCloud.class); - @Autowired - private AlarmServiceInterface alarmServiceInterface; @Autowired private CustomerServiceInterface customerServiceInterface; @Autowired @@ -178,8 +110,6 @@ public class OpensyncExternalIntegrationCloud implements OpensyncExternalIntegra @Autowired private OvsdbSessionMapInterface ovsdbSessionMapInterface; @Autowired - private CloudEventDispatcherInterface equipmentMetricsCollectorInterface; - @Autowired private EquipmentServiceInterface equipmentServiceInterface; @Autowired private RoutingServiceInterface routingServiceInterface; @@ -191,6 +121,8 @@ public class OpensyncExternalIntegrationCloud implements OpensyncExternalIntegra private ClientServiceInterface clientServiceInterface; @Autowired private FirmwareServiceInterface firmwareServiceInterface; + @Autowired + private OpensyncExternalIntegrationMqttMessageProcessor mqttMessageProcessor; @Autowired private OpensyncCloudGatewayController gatewayController; @@ -275,7 +207,8 @@ public class OpensyncExternalIntegrationCloud implements OpensyncExternalIntegra + autoProvisionedCustomerId); } -// String dbUrlString = customer.getDetails().getClientFingerPrintsDbUrl(); + // String dbUrlString = + // customer.getDetails().getClientFingerPrintsDbUrl(); ce = new Equipment(); ce.setEquipmentType(EquipmentType.AP); ce.setInventoryId(apId); @@ -809,6 +742,8 @@ public class OpensyncExternalIntegrationCloud implements OpensyncExternalIntegra Set radiusSet = new HashSet<>(); Set captiveProfileIds = new HashSet<>(); + Set bonjourGatewayProfileIds = new HashSet<>(); + for (Profile ssidProfile : ret.getSsidProfile()) { radiusSet.addAll(profileContainer.getChildrenOfType(ssidProfile.getId(), ProfileType.radius)); @@ -817,10 +752,15 @@ public class OpensyncExternalIntegrationCloud implements OpensyncExternalIntegra if (captivePortId != null) { captiveProfileIds.add(captivePortId); } + Long bonjourGatewayProfileId = ((SsidConfiguration)ssidProfile.getDetails()).getBonjourGatewayProfileId(); + if (bonjourGatewayProfileId != null) { + bonjourGatewayProfileIds.add(bonjourGatewayProfileId); + } } } ret.setRadiusProfiles(new ArrayList<>(radiusSet)); ret.setCaptiveProfiles(profileServiceInterface.get(captiveProfileIds)); + ret.setBonjourGatewayProfiles(profileServiceInterface.get(bonjourGatewayProfileIds)); List blockedClients = clientServiceInterface .getBlockedClients(customerId); @@ -842,1859 +782,20 @@ public class OpensyncExternalIntegrationCloud implements OpensyncExternalIntegra return ret; } - /** - * @param topic - * @return apId extracted from the topic name, or null if it cannot be - * extracted - */ - public static String extractApIdFromTopic(String topic) { - // Topic is formatted as - // "/ap/"+clientCn+"_"+ret.serialNumber+"/opensync" - if (topic == null) { - return null; - } - - String[] parts = topic.split("/"); - if (parts.length < 3) { - return null; - } - - // apId is the third element in the topic - return parts[2]; - } - - /** - * @param topic - * @return customerId looked up from the topic name, or -1 if it cannot be - * extracted - */ - public int extractCustomerIdFromTopic(String topic) { - - String apId = extractApIdFromTopic(topic); - if (apId == null) { - return -1; - } - - OvsdbSession ovsdbSession = ovsdbSessionMapInterface.getSession(apId); - - if (ovsdbSession != null) { - return ovsdbSession.getCustomerId(); - } - - return -1; - - } - - public long extractEquipmentIdFromTopic(String topic) { - - String apId = extractApIdFromTopic(topic); - if (apId == null) { - return -1; - } - - OvsdbSession ovsdbSession = ovsdbSessionMapInterface.getSession(apId); - - if (ovsdbSession != null) { - return ovsdbSession.getEquipmentId(); - } - - return -1; - - } - @Override public void processMqttMessage(String topic, Report report) { - LOG.info("Received report on topic {} for ap {}", topic, report.getNodeID()); - int customerId = extractCustomerIdFromTopic(topic); - String apId = extractApIdFromTopic(topic); - long equipmentId = extractEquipmentIdFromTopic(topic); - if ((equipmentId <= 0) || (customerId <= 0)) { - LOG.warn("Cannot determine equipment ids from topic {} - customerId {} equipmentId {}", topic, customerId, - equipmentId); - return; - } - - gatewayController.updateActiveCustomer(customerId); - - Equipment ce = getCustomerEquipment(apId); - if (ce == null) { - LOG.warn("Cannot read equipment {}", apId); - return; - } - - long locationId = ce.getLocationId(); - - if (LOG.isTraceEnabled()) { - // prepare a JSONPrinter to format protobuf messages as - // json - List protobufDescriptors = new ArrayList<>(); - protobufDescriptors.addAll(OpensyncStats.getDescriptor().getMessageTypes()); - TypeRegistry oldRegistry = TypeRegistry.newBuilder().add(protobufDescriptors).build(); - JsonFormat.Printer jsonPrinter = JsonFormat.printer().preservingProtoFieldNames() - .includingDefaultValueFields().usingTypeRegistry(oldRegistry); - - try { - LOG.trace("MQTT OpensyncStats.report = {}", jsonPrinter.print(report)); - - } catch (InvalidProtocolBufferException e1) { - LOG.error("Couldn't parse OpensyncStats.report.", e1); - } - } - - List metricRecordList = new ArrayList<>(); - - try { - populateApClientMetrics(metricRecordList, report, customerId, equipmentId, locationId); - populateApNodeMetrics(metricRecordList, report, customerId, equipmentId, locationId); - populateNeighbourScanReports(metricRecordList, report, customerId, equipmentId, locationId); - populateChannelInfoReports(metricRecordList, report, customerId, equipmentId, locationId); - populateApSsidMetrics(metricRecordList, report, customerId, equipmentId, apId, locationId); - // TODO: uncomment when AP support present - populateUccReport(metricRecordList, report, customerId, equipmentId, apId, locationId); - processEventReport(report, customerId, equipmentId, apId, locationId); - // handleRssiMetrics(metricRecordList, report, customerId, - // equipmentId, locationId); - - } catch (Exception e) { - LOG.error("Exception when processing populateApSsidMetrics", e); - } - - if (!metricRecordList.isEmpty()) { - LOG.debug("Publishing Metrics {}", metricRecordList); - equipmentMetricsCollectorInterface.publishMetrics(metricRecordList); - } - + mqttMessageProcessor.processMqttMessage(topic, report); } - private void processEventReport(Report report, int customerId, long equipmentId, String apId, long locationId) { - - LOG.debug("Processing EventReport List {}", report.getEventReportList()); - - report.getEventReportList().stream().forEach(e -> { - LOG.info("Received EventReport {}", e); - - if (e.hasClientAssocEvent()) { - - - ClientAssocEvent clientAssocEvent = e.getClientAssocEvent(); - - if (clientAssocEvent.hasStaMac()) { - com.telecominfraproject.wlan.client.models.Client client = clientServiceInterface - .getOrNull(customerId, new MacAddress(clientAssocEvent.getStaMac())); - if (client == null) { - client = new com.telecominfraproject.wlan.client.models.Client(); - - client.setCustomerId(customerId); - client.setMacAddress(new MacAddress(clientAssocEvent.getStaMac())); - - client.setDetails(new ClientInfoDetails()); - - client = clientServiceInterface.create(client); - - } - - ClientSession clientSession = clientServiceInterface.getSessionOrNull(customerId, equipmentId, - new MacAddress(clientAssocEvent.getStaMac())); - - if (clientSession == null) { - clientSession = new ClientSession(); - } - clientSession.setCustomerId(customerId); - clientSession.setEquipmentId(equipmentId); - clientSession.setLocationId(locationId); - clientSession.setMacAddress(new MacAddress(clientAssocEvent.getStaMac())); - - ClientSessionDetails clientSessionDetails = new ClientSessionDetails(); - if (clientAssocEvent.hasUsing11K()) { - clientSessionDetails.setIs11KUsed(clientAssocEvent.getUsing11K()); - } - if (clientAssocEvent.hasUsing11R()) { - clientSessionDetails.setIs11RUsed(clientAssocEvent.getUsing11R()); - } - if (clientAssocEvent.hasUsing11V()) { - clientSessionDetails.setIs11VUsed(clientAssocEvent.getUsing11V()); - } - if (clientAssocEvent.hasAssocType()) { - clientSessionDetails - .setIsReassociation(clientAssocEvent.getAssocType().equals(AssocType.REASSOC)); - } - if (clientAssocEvent.hasBand()) { - clientSessionDetails - .setRadioType(getRadioTypeFromOpensyncRadioBand(clientAssocEvent.getBand())); - } - if (clientAssocEvent.hasRssi()) { - clientSessionDetails.setAssocRssi(clientAssocEvent.getRssi()); - } - if (clientAssocEvent.hasSessionId()) { - clientSessionDetails.setSessionId(clientAssocEvent.getSessionId()); - } - if (clientAssocEvent.hasSsid()) { - clientSessionDetails.setSsid(clientAssocEvent.getSsid()); - } - if (clientAssocEvent.hasStatus()) { - clientSessionDetails.setAssociationStatus(clientAssocEvent.getStatus()); - clientSessionDetails.setAssociationState(AssociationState._802_11_Associated); - } - - if (clientSession.getDetails() == null) { - clientSession.setDetails(clientSessionDetails); - } else { - clientSession.getDetails().mergeSession(clientSessionDetails); - } - - clientSession = clientServiceInterface.updateSession(clientSession); - - } else { - LOG.info("Cannot update client or client session when no client mac address is present"); - } - - - } - - if (e.hasClientAuthEvent()) { - - - ClientAuthEvent clientAuthEvent = e.getClientAuthEvent(); - - - if (clientAuthEvent.hasStaMac()) { - - com.telecominfraproject.wlan.client.models.Client client = clientServiceInterface - .getOrNull(customerId, new MacAddress(clientAuthEvent.getStaMac())); - if (client == null) { - client = new com.telecominfraproject.wlan.client.models.Client(); - - client.setCustomerId(customerId); - client.setMacAddress(new MacAddress(clientAuthEvent.getStaMac())); - - client.setDetails(new ClientInfoDetails()); - - client = clientServiceInterface.create(client); - - } - - ClientSession clientSession = clientServiceInterface.getSessionOrNull(customerId, equipmentId, - new MacAddress(clientAuthEvent.getStaMac())); - - if (clientSession == null) { - clientSession = new ClientSession(); - } - - clientSession.setCustomerId(customerId); - clientSession.setEquipmentId(equipmentId); - clientSession.setLocationId(locationId); - clientSession.setMacAddress(new MacAddress(clientAuthEvent.getStaMac())); - - ClientSessionDetails clientSessionDetails = new ClientSessionDetails(); - - if (clientAuthEvent.hasSessionId()) { - clientSessionDetails.setSessionId(clientAuthEvent.getSessionId()); - } - if (clientAuthEvent.hasBand()) { - clientSessionDetails.setRadioType(getRadioTypeFromOpensyncRadioBand(clientAuthEvent.getBand())); - } - if (clientAuthEvent.hasSsid()) { - clientSessionDetails.setSsid(clientAuthEvent.getSsid()); - } - if (clientAuthEvent.hasAuthStatus()) { - clientSessionDetails.setAssociationState(AssociationState._802_11_Authenticated); - } - - - if (clientSession.getDetails() == null) { - clientSession.setDetails(clientSessionDetails); - } else { - clientSession.getDetails().mergeSession(clientSessionDetails); - } - - clientSession = clientServiceInterface.updateSession(clientSession); - - - } else { - LOG.info("Cannot update client or client session when no client mac address is present"); - } - - - } - - if (e.hasClientDisconnectEvent()) { - ClientDisconnectEvent clientDisconnectEvent = e.getClientDisconnectEvent(); - - if (clientDisconnectEvent.hasStaMac()) { - - com.telecominfraproject.wlan.client.models.Client client = clientServiceInterface - .getOrNull(customerId, new MacAddress(clientDisconnectEvent.getStaMac())); - if (client == null) { - client = new com.telecominfraproject.wlan.client.models.Client(); - - client.setCustomerId(customerId); - client.setMacAddress(new MacAddress(clientDisconnectEvent.getStaMac())); - - client.setDetails(new ClientInfoDetails()); - - client = clientServiceInterface.create(client); - - } - - ClientSession clientSession = clientServiceInterface.getSessionOrNull(customerId, equipmentId, - new MacAddress(clientDisconnectEvent.getStaMac())); - - if (clientSession == null) { - clientSession = new ClientSession(); - } - - clientSession.setCustomerId(customerId); - clientSession.setEquipmentId(equipmentId); - clientSession.setLocationId(locationId); - clientSession.setMacAddress(new MacAddress(clientDisconnectEvent.getStaMac())); - - ClientSessionDetails clientSessionDetails = new ClientSessionDetails(); - - if (clientDisconnectEvent.hasBand()) { - clientSessionDetails - .setRadioType(getRadioTypeFromOpensyncRadioBand(clientDisconnectEvent.getBand())); - } - if (clientDisconnectEvent.hasDevType()) { - } - if (clientDisconnectEvent.hasFrType()) { - if (clientDisconnectEvent.getFrType().equals(FrameType.FT_DEAUTH)) { - } - if (clientDisconnectEvent.getFrType().equals(FrameType.FT_DISASSOC)) { - } - } - if (clientDisconnectEvent.hasRssi()) { - clientSessionDetails.setAssocRssi(clientDisconnectEvent.getRssi()); - } - - if (clientDisconnectEvent.hasSessionId()) { - clientSessionDetails.setSessionId(clientDisconnectEvent.getSessionId()); - } - - if (clientDisconnectEvent.hasLrcvUpTsInUs()) { - clientSessionDetails.setLastRxTimestamp(clientDisconnectEvent.getLrcvUpTsInUs()); - } - - if (clientDisconnectEvent.hasLsentUpTsInUs()) { - clientSessionDetails.setLastTxTimestamp(clientDisconnectEvent.getLsentUpTsInUs()); - } - - if (clientDisconnectEvent.hasInternalRc()) { - clientSessionDetails - .setDisconnectByClientInternalReasonCode(clientDisconnectEvent.getInternalRc()); - } - if (clientDisconnectEvent.hasReason()) { - clientSessionDetails.setDisconnectByClientReasonCode(clientDisconnectEvent.getReason()); - - } - clientSessionDetails.setAssociationState(AssociationState.Disconnected); - - - if (clientSession.getDetails() == null) { - clientSession.setDetails(clientSessionDetails); - } else { - clientSession.getDetails().mergeSession(clientSessionDetails); - } - - clientSession = clientServiceInterface.updateSession(clientSession); - - - } else { - LOG.info("Cannot update client or client session when no client mac address is present"); - } - - } - - if (e.hasClientFailureEvent()) { - - ClientFailureEvent clientFailureEvent = e.getClientFailureEvent(); - - - if (clientFailureEvent.hasStaMac()) { - - com.telecominfraproject.wlan.client.models.Client client = clientServiceInterface - .getOrNull(customerId, new MacAddress(clientFailureEvent.getStaMac())); - if (client == null) { - client = new com.telecominfraproject.wlan.client.models.Client(); - - client.setCustomerId(customerId); - client.setMacAddress(new MacAddress(clientFailureEvent.getStaMac())); - - client.setDetails(new ClientInfoDetails()); - - client = clientServiceInterface.create(client); - - } - - ClientSession clientSession = clientServiceInterface.getSessionOrNull(customerId, equipmentId, - new MacAddress(clientFailureEvent.getStaMac())); - - if (clientSession == null) { - clientSession = new ClientSession(); - } - - clientSession.setCustomerId(customerId); - clientSession.setEquipmentId(equipmentId); - clientSession.setLocationId(locationId); - clientSession.setMacAddress(new MacAddress(clientFailureEvent.getStaMac())); - - - ClientSessionDetails clientSessionDetails = new ClientSessionDetails(); - - if (clientFailureEvent.hasSsid()) { - clientSessionDetails.setSsid(clientFailureEvent.getSsid()); - } - - if (clientFailureEvent.hasSessionId()) { - clientSessionDetails.setSessionId(clientFailureEvent.getSessionId()); - } - ClientFailureDetails clientFailureDetails = new ClientFailureDetails(); - if (clientFailureEvent.hasReasonStr()) { - clientFailureDetails.setReason(clientFailureEvent.getReasonStr()); - } - if (clientFailureEvent.hasReasonCode()) { - clientFailureDetails.setReasonCode(clientFailureEvent.getReasonCode()); - } - clientSessionDetails.setLastFailureDetails(clientFailureDetails); - - if (clientSession.getDetails() == null) { - clientSession.setDetails(clientSessionDetails); - } else { - clientSession.getDetails().mergeSession(clientSessionDetails); - } - - clientSession = clientServiceInterface.updateSession(clientSession); - - } else { - LOG.info("Cannot update client or client session when no client mac address is present"); - } - - } - - if (e.hasClientFirstDataEvent()) { - - - ClientFirstDataEvent clientFirstDataEvent = e.getClientFirstDataEvent(); - - - if (clientFirstDataEvent.hasStaMac()) { - - com.telecominfraproject.wlan.client.models.Client client = clientServiceInterface - .getOrNull(customerId, new MacAddress(clientFirstDataEvent.getStaMac())); - if (client == null) { - client = new com.telecominfraproject.wlan.client.models.Client(); - - client.setCustomerId(customerId); - client.setMacAddress(new MacAddress(clientFirstDataEvent.getStaMac())); - - client.setDetails(new ClientInfoDetails()); - - client = clientServiceInterface.create(client); - - } - - ClientSession clientSession = clientServiceInterface.getSessionOrNull(customerId, equipmentId, - new MacAddress(clientFirstDataEvent.getStaMac())); - - if (clientSession == null) { - clientSession = new ClientSession(); - } - - clientSession.setCustomerId(customerId); - clientSession.setEquipmentId(equipmentId); - clientSession.setLocationId(locationId); - clientSession.setMacAddress(new MacAddress(clientFirstDataEvent.getStaMac())); - - - ClientSessionDetails clientSessionDetails = new ClientSessionDetails(); - - - if (clientFirstDataEvent.hasFdataRxUpTsInUs()) { - clientSessionDetails.setFirstDataRcvdTimestamp(clientFirstDataEvent.getFdataRxUpTsInUs()); - } - - if (clientFirstDataEvent.hasFdataTxUpTsInUs()) { - clientSessionDetails.setFirstDataSentTimestamp(clientFirstDataEvent.getFdataTxUpTsInUs()); - } - - if (clientFirstDataEvent.hasSessionId()) { - clientSessionDetails.setSessionId(clientFirstDataEvent.getSessionId()); - } - clientSessionDetails.setAssociationState(AssociationState.Active_Data); - - if (clientSession.getDetails() == null) { - clientSession.setDetails(clientSessionDetails); - } else { - clientSession.getDetails().mergeSession(clientSessionDetails); - } - - clientSession = clientServiceInterface.updateSession(clientSession); - - } else { - LOG.info("Cannot update client or client session when no client mac address is present"); - } - - - } - - if (e.hasClientIdEvent()) { - - ClientIdEvent clientIdEvent = e.getClientIdEvent(); - - if (clientIdEvent.hasCltMac()) { - - com.telecominfraproject.wlan.client.models.Client client = clientServiceInterface - .getOrNull(customerId, new MacAddress(clientIdEvent.getCltMac())); - if (client == null) { - client = new com.telecominfraproject.wlan.client.models.Client(); - - client.setCustomerId(customerId); - client.setMacAddress(new MacAddress(clientIdEvent.getCltMac())); - - client.setDetails(new ClientInfoDetails()); - - client = clientServiceInterface.create(client); - - } - - ClientSession clientSession = clientServiceInterface.getSessionOrNull(customerId, equipmentId, - new MacAddress(clientIdEvent.getCltMac())); - - if (clientSession == null) { - clientSession = new ClientSession(); - } - - clientSession.setCustomerId(customerId); - clientSession.setEquipmentId(equipmentId); - clientSession.setLocationId(locationId); - clientSession.setMacAddress(new MacAddress(clientIdEvent.getCltMac())); - - - ClientSessionDetails clientSessionDetails = new ClientSessionDetails(); - - if (clientIdEvent.hasSessionId()) { - clientSessionDetails.setSessionId(clientIdEvent.getSessionId()); - } - - if (clientSession.getDetails() == null) { - clientSession.setDetails(clientSessionDetails); - } else { - clientSession.getDetails().mergeSession(clientSessionDetails); - } - - clientSession = clientServiceInterface.updateSession(clientSession); - - } else { - LOG.info("Cannot update client or client session when no client mac address is present"); - } - - - } - - if (e.hasClientIpEvent()) { - - ClientIpEvent clientIpEvent = e.getClientIpEvent(); - - if (clientIpEvent.hasStaMac()) { - - com.telecominfraproject.wlan.client.models.Client client = clientServiceInterface - .getOrNull(customerId, new MacAddress(clientIpEvent.getStaMac())); - if (client == null) { - client = new com.telecominfraproject.wlan.client.models.Client(); - - client.setCustomerId(customerId); - client.setMacAddress(new MacAddress(clientIpEvent.getStaMac())); - - client.setDetails(new ClientInfoDetails()); - - client = clientServiceInterface.create(client); - - } - - ClientSession clientSession = clientServiceInterface.getSessionOrNull(customerId, equipmentId, - new MacAddress(clientIpEvent.getStaMac())); - - if (clientSession == null) { - clientSession = new ClientSession(); - } - - clientSession.setCustomerId(customerId); - clientSession.setEquipmentId(equipmentId); - clientSession.setLocationId(locationId); - clientSession.setMacAddress(new MacAddress(clientIpEvent.getStaMac())); - - ClientSessionDetails clientSessionDetails = new ClientSessionDetails(); - - if (clientIpEvent.hasSessionId()) { - clientSessionDetails.setSessionId(clientIpEvent.getSessionId()); - } - - try { - clientSessionDetails - .setIpAddress(InetAddress.getByAddress(clientIpEvent.getIpAddr().toByteArray())); - } catch (UnknownHostException e1) { - // TODO Auto-generated catch block - e1.printStackTrace(); - } - - if (clientSession.getDetails() == null) { - clientSession.setDetails(clientSessionDetails); - } else { - clientSession.getDetails().mergeSession(clientSessionDetails); - } - - clientSession = clientServiceInterface.updateSession(clientSession); - - } else { - LOG.info("Cannot update client or client session when no client mac address is present"); - } - - - } - - if (e.hasClientTimeoutEvent()) { - - ClientTimeoutEvent clientTimeoutEvent = e.getClientTimeoutEvent(); - - - if (clientTimeoutEvent.hasStaMac()) { - - com.telecominfraproject.wlan.client.models.Client client = clientServiceInterface - .getOrNull(customerId, new MacAddress(clientTimeoutEvent.getStaMac())); - if (client == null) { - client = new com.telecominfraproject.wlan.client.models.Client(); - - client.setCustomerId(customerId); - client.setMacAddress(new MacAddress(clientTimeoutEvent.getStaMac())); - - client.setDetails(new ClientInfoDetails()); - - client = clientServiceInterface.create(client); - - } - - ClientSession clientSession = clientServiceInterface.getSessionOrNull(customerId, equipmentId, - new MacAddress(clientTimeoutEvent.getStaMac())); - - if (clientSession == null) { - clientSession = new ClientSession(); - } - - clientSession.setCustomerId(customerId); - clientSession.setEquipmentId(equipmentId); - clientSession.setLocationId(locationId); - clientSession.setMacAddress(new MacAddress(clientTimeoutEvent.getStaMac())); - - ClientSessionDetails clientSessionDetails = new ClientSessionDetails(); - - if (clientTimeoutEvent.hasSessionId()) { - clientSessionDetails.setSessionId(clientTimeoutEvent.getSessionId()); - } - - if (clientTimeoutEvent.hasLastRcvUpTsInUs()) { - clientSessionDetails.setLastRxTimestamp(clientTimeoutEvent.getLastRcvUpTsInUs()); - } - - if (clientTimeoutEvent.hasLastSentUpTsInUs()) { - clientSessionDetails.setLastTxTimestamp(clientTimeoutEvent.getLastSentUpTsInUs()); - } - - if (clientSession.getDetails() == null) { - clientSession.setDetails(clientSessionDetails); - } else { - clientSession.getDetails().mergeSession(clientSessionDetails); - } - - clientSession = clientServiceInterface.updateSession(clientSession); - - } else { - LOG.info("Cannot update client or client session when no client mac address is present"); - } - - - } - - - }); - - } - - private void populateUccReport(List metricRecordList, Report report, int customerId, - long equipmentId, String apId, long locationId) { - - // This feature is used identify the ongoing UCC (Unified Communications - // and Collaboration) technology and Video sessions. - - if (report.getUccReportCount() < 1) { - LOG.debug("No UCC metrics in this message"); - return; - } - - for (UCCReport uccReport : report.getUccReportList()) { - if (uccReport.hasSipCallReport()) { - LOG.debug("SIP Call Report {}", uccReport.getSipCallReport()); - } - } - - - } - - private void populateApNodeMetrics(List metricRecordList, Report report, int customerId, - long equipmentId, long locationId) { - LOG.debug("populateApNodeMetrics for Customer {} Equipment {}", customerId, equipmentId); - ApNodeMetrics apNodeMetrics = new ApNodeMetrics(); - ServiceMetric smr = new ServiceMetric(customerId, equipmentId); - - smr.setLocationId(locationId); - - metricRecordList.add(smr); - smr.setDetails(apNodeMetrics); - - for (Device deviceReport : report.getDeviceList()) { - - int avgRadioTemp = 0; - - ApPerformance apPerformance = new ApPerformance(); - apNodeMetrics.setApPerformance(apPerformance); - - smr.setCreatedTimestamp(deviceReport.getTimestampMs()); - - if (deviceReport.getRadioTempCount() > 0) { - float cpuTemperature = 0; - int numSamples = 0; - for (RadioTemp r : deviceReport.getRadioTempList()) { - if (r.hasValue()) { - cpuTemperature += r.getValue(); - numSamples++; - } - } - - if (numSamples > 0) { - avgRadioTemp = Math.round((cpuTemperature / numSamples)); - apPerformance.setCpuTemperature(avgRadioTemp); - } - } - - if (deviceReport.hasCpuUtil() && deviceReport.getCpuUtil().hasCpuUtil()) { - Integer cpuUtilization = deviceReport.getCpuUtil().getCpuUtil(); - apPerformance.setCpuUtilized(new byte[] { cpuUtilization.byteValue() }); - } - - apPerformance.setEthLinkState(EthernetLinkState.UP1000_FULL_DUPLEX); - - if (deviceReport.hasMemUtil() && deviceReport.getMemUtil().hasMemTotal() - && deviceReport.getMemUtil().hasMemUsed()) { - apPerformance.setFreeMemory( - deviceReport.getMemUtil().getMemTotal() - deviceReport.getMemUtil().getMemUsed()); - } - apPerformance.setUpTime((long) deviceReport.getUptime()); - - updateDeviceStatusForReport(customerId, equipmentId, deviceReport, avgRadioTemp); - - } - - // statusList.add(status); - - // Main Network dashboard shows Traffic and Capacity values that - // are calculated from - // ApNodeMetric properties getPeriodLengthSec, getRxBytes2G, - // getTxBytes2G, getRxBytes5G, getTxBytes5G - - // go over all the clients to aggregate per-client tx/rx stats - - // we want to do this - // only once per batch of ApNodeMetrics - so we do not repeat - // values over and over again - - for (ClientReport clReport : report.getClientsList()) { - - long rxBytes = 0; - long txBytes = 0; - - long txFrames = 0; - long rxFrames = 0; - int txRetries = 0; - int rxRetries = 0; - int rxErrors = 0; - int rssi = 0; - Long uRssi = null; - - Set clientMacs = new HashSet<>(); - - for (Client cl : clReport.getClientListList()) { - - if (!cl.hasConnected() || (cl.getConnected() != true)) { - // this client is not currently connected, skip it - // TODO: how come AP reports disconencted clients? What - // if it is a busy coffe shop with thousands of peopele - // per day, when do clients disappear from the reports? - continue; - } - - if (cl.hasMacAddress()) { - clientMacs.add(cl.getMacAddress()); - } - - if (cl.getStats().hasTxBytes()) { - txBytes += cl.getStats().getTxBytes(); - } - if (cl.getStats().hasRxBytes()) { - rxBytes += cl.getStats().getRxBytes(); - } - if (cl.getStats().hasRssi()) { - rssi = cl.getStats().getRssi(); - } - if (cl.getStats().hasTxFrames()) { - txFrames += cl.getStats().getTxFrames(); - } - if (cl.getStats().hasRxFrames()) { - rxFrames += cl.getStats().getRxFrames(); - } - if (cl.getStats().hasTxRetries()) { - txRetries += cl.getStats().getTxRetries(); - } - if (cl.getStats().hasRxRetries()) { - rxRetries += cl.getStats().getRxRetries(); - } - if (cl.getStats().hasTxErrors()) { - cl.getStats().getTxErrors(); - } - if (cl.getStats().hasRxErrors()) { - rxErrors += cl.getStats().getRxErrors(); - } - if (cl.getStats().hasTxRate()) { - cl.getStats().getTxRate(); - } - if (cl.getStats().hasRxRate()) { - cl.getStats().getRxRate(); - } - - } - - RadioType radioType = getRadioTypeFromOpensyncRadioBand(clReport.getBand()); - RadioStatistics radioStats = apNodeMetrics.getRadioStats(radioType); - if (radioStats == null) { - radioStats = new RadioStatistics(); - } - - radioStats.setNumTxRetryAttemps(txRetries); - radioStats.setNumTxFramesTransmitted(txFrames); - radioStats.setNumTxRetryAttemps(txRetries); - radioStats.setCurChannel(clReport.getChannel()); - if (clReport.getClientListCount() > 0) { - // radioStats.setRxLastRssi(getNegativeSignedIntFromUnsigned(rssi) - // / clReport.getClientListCount()); - radioStats.setRxLastRssi(rssi); - } - radioStats.setRxDataBytes(rxBytes); - radioStats.setNumRxDataFrames(rxFrames); - radioStats.setNumRxErr(rxErrors); - radioStats.setNumRxRetry(rxRetries); - - apNodeMetrics.setRadioStats(radioType, radioStats); - - apNodeMetrics.setRxBytes(radioType, rxBytes); - apNodeMetrics.setTxBytes(radioType, txBytes); - - List clientMacList = new ArrayList<>(); - clientMacs.forEach(macStr -> { - try { - clientMacList.add(new MacAddress(macStr)); - } catch (RuntimeException e) { - LOG.warn("Cannot parse mac address from MQTT ClientReport {} ", macStr); - } - }); - - apNodeMetrics.setClientMacAddresses(radioType, clientMacList); - - // TODO: Radio Utilization will be calculated when the survey is - // enabled - - apNodeMetrics.setRadioUtilization(radioType, new ArrayList()); - - } - - // Status radioUtilizationStatus = - // statusServiceInterface.getOrNull(customerId, equipmentId, - // StatusDataType.RADIO_UTILIZATION); - // - // if (radioUtilizationStatus != null) { - // RadioUtilizationReport radioUtilizationReport = - // (RadioUtilizationReport) radioUtilizationStatus - // .getDetails(); - // } - - apNodeMetrics.setPeriodLengthSec(60); - - // Now try to populate metrics for calculation of radio capacity - // see - // com.telecominfraproject.wlan.metrics.streaming.spark.equipmentreport.CapacityDStreamsConfig.toAggregatedStats(int, - // long, ApNodeMetric data) - // result.stats2g = - // toAggregatedRadioStats(data.getNoiseFloor2G(),data.getRadioUtilization2G()); - // result.stats5g = - // toAggregatedRadioStats(data.getNoiseFloor5G(),data.getRadioUtilization5G()); - // RadioUtilization - // private Integer assocClientTx; - // private Integer unassocClientTx; - // private Integer assocClientRx; - // private Integer unassocClientRx; - // private Integer nonWifi; - // private Integer timestampSeconds; - Map avgNoiseFloor = new HashMap<>(); - new HashMap<>(); - Map capacityDetails = new HashMap<>(); - RadioUtilizationReport radioUtilizationReport = new RadioUtilizationReport(); - - // populate it from report.survey - for (Survey survey : report.getSurveyList()) { - - int oBSS = 0; - int iBSS = 0; - int totalBusy = 0; - int durationMs = 0; - RadioType radioType = RadioType.UNSUPPORTED; - - List noiseList = new ArrayList<>(); - for (SurveySample surveySample : survey.getSurveyListList()) { - if (surveySample.getDurationMs() == 0) { - continue; - } - - iBSS += surveySample.getBusySelf() + surveySample.getBusyTx(); - oBSS += surveySample.getBusyRx(); - totalBusy += surveySample.getBusy(); - durationMs += surveySample.getDurationMs(); - noiseList.add(getNegativeSignedIntFrom8BitUnsigned(surveySample.getNoise())); - RadioUtilization radioUtil = new RadioUtilization(); - radioUtil.setTimestampSeconds((int) ((survey.getTimestampMs() + surveySample.getOffsetMs()) / 1000)); - radioUtil.setAssocClientTx((100 * surveySample.getBusyTx()) / surveySample.getDurationMs()); - radioUtil.setAssocClientRx((100 * surveySample.getBusyRx()) / surveySample.getDurationMs()); - // TODO not totally correct, NonWifi = totalBusy - iBSS - oBSS - radioUtil.setNonWifi( - (100 * (surveySample.getBusy() - surveySample.getBusyTx() - surveySample.getBusyRx())) - / surveySample.getDurationMs()); - - switch (survey.getBand()) { - case BAND2G: - radioType = RadioType.is2dot4GHz; - break; - case BAND5G: - radioType = RadioType.is5GHz; - break; - case BAND5GL: - radioType = RadioType.is5GHzL; - break; - case BAND5GU: - radioType = RadioType.is5GHzU; - break; - } - - if (radioType != RadioType.UNSUPPORTED) { - - if (!apNodeMetrics.getRadioUtilizationPerRadio().containsKey(radioType)) { - List radioUtilizationList = new ArrayList<>(); - radioUtilizationList.add(radioUtil); - apNodeMetrics.getRadioUtilizationPerRadio().put(radioType, radioUtilizationList); - } else { - apNodeMetrics.getRadioUtilizationPerRadio().get(radioType).add(radioUtil); - } - } - } - - if ((survey.getSurveyListCount() > 0) && (radioType != RadioType.UNSUPPORTED)) { - int noiseAvg = (int) Math.round(DecibelUtils.getAverageDecibel(toIntArray(noiseList))); - avgNoiseFloor.put(radioType, noiseAvg); - apNodeMetrics.setNoiseFloor(radioType, noiseAvg); - } - Double totalUtilization = (100D * totalBusy) / durationMs; - Double totalNonWifi = (100D * (totalBusy - iBSS - oBSS)) / durationMs; - - EquipmentCapacityDetails cap = new EquipmentCapacityDetails(); - cap.setUnavailableCapacity(totalNonWifi.intValue()); - int avaiCapacity = 100 - totalNonWifi.intValue(); - cap.setAvailableCapacity(avaiCapacity); - cap.setUsedCapacity(totalUtilization.intValue()); - cap.setUnusedCapacity(avaiCapacity - totalUtilization.intValue()); - cap.setTotalCapacity(100); - - if (radioType != RadioType.UNSUPPORTED) { - apNodeMetrics.setChannelUtilization(radioType, totalUtilization.intValue()); - capacityDetails.put(radioType, cap); - } - } - - new RadioStatistics(); - - populateNetworkProbeMetrics(report, apNodeMetrics); - - radioUtilizationReport.setAvgNoiseFloor(avgNoiseFloor); - radioUtilizationReport.setCapacityDetails(capacityDetails); - - updateDeviceStatusRadioUtilizationReport(customerId, equipmentId, radioUtilizationReport); - } - - private void updateDeviceStatusRadioUtilizationReport(int customerId, long equipmentId, - RadioUtilizationReport radioUtilizationReport) { - LOG.debug( - "Processing updateDeviceStatusRadioUtilizationReport for equipmentId {} with RadioUtilizationReport {}", - equipmentId, radioUtilizationReport); - - Status radioUtilizationStatus = statusServiceInterface.getOrNull(customerId, equipmentId, - StatusDataType.RADIO_UTILIZATION); - - if (radioUtilizationStatus == null) { - LOG.debug("Create new radioUtilizationStatus"); - radioUtilizationStatus = new Status(); - radioUtilizationStatus.setCustomerId(customerId); - radioUtilizationStatus.setEquipmentId(equipmentId); - radioUtilizationStatus.setStatusDataType(StatusDataType.RADIO_UTILIZATION); - } - - radioUtilizationStatus.setDetails(radioUtilizationReport); - - statusServiceInterface.update(radioUtilizationStatus); - } - - void populateNetworkProbeMetrics(Report report, ApNodeMetrics apNodeMetrics) { - List networkProbeMetricsList = new ArrayList<>(); - - for (NetworkProbe networkProbe : report.getNetworkProbeList()) { - - NetworkProbeMetrics networkProbeMetrics = new NetworkProbeMetrics(); - - List dnsProbeResults = new ArrayList<>(); - if (networkProbe.hasDnsProbe()) { - - DNSProbeMetric dnsProbeMetricFromAp = networkProbe.getDnsProbe(); - - DnsProbeMetric dnsProbeMetric = new DnsProbeMetric(); - - if (dnsProbeMetricFromAp.hasLatency()) { - networkProbeMetrics.setDnsLatencyMs(dnsProbeMetricFromAp.getLatency()); - dnsProbeMetric.setDnsLatencyMs(dnsProbeMetricFromAp.getLatency()); - } - - if (dnsProbeMetricFromAp.hasState()) { - switch (dnsProbeMetricFromAp.getState()) { - case SUD_down: - networkProbeMetrics.setDnsState(StateUpDownError.disabled); - dnsProbeMetric.setDnsState(StateUpDownError.disabled); - break; - case SUD_up: - networkProbeMetrics.setDnsState(StateUpDownError.enabled); - dnsProbeMetric.setDnsState(StateUpDownError.enabled); - break; - case SUD_error: - networkProbeMetrics.setDnsState(StateUpDownError.error); - dnsProbeMetric.setDnsState(StateUpDownError.error); - break; - default: - networkProbeMetrics.setDnsState(StateUpDownError.UNSUPPORTED); - dnsProbeMetric.setDnsState(StateUpDownError.UNSUPPORTED); - } - } - - if (dnsProbeMetricFromAp.hasServerIP()) { - InetAddress ipAddress; - try { - ipAddress = InetAddress.getByName(dnsProbeMetricFromAp.getServerIP()); - dnsProbeMetric.setDnsServerIp(ipAddress); - - } catch (UnknownHostException e) { - LOG.error("Could not get DNS Server IP from network_probe metrics", e); - } - } - - dnsProbeResults.add(dnsProbeMetric); - - } - - networkProbeMetrics.setDnsProbeResults(dnsProbeResults); - - for (RADIUSMetrics radiusMetrics : networkProbe.getRadiusProbeList()) { - if (networkProbe.hasVlanProbe()) { - if (networkProbe.getVlanProbe().hasObsV200RadiusLatency()) { - networkProbeMetrics.setRadiusLatencyInMs(networkProbe.getVlanProbe().getObsV200RadiusLatency()); - } - if (networkProbe.getVlanProbe().hasObsV200RadiusState()) { - switch (networkProbe.getVlanProbe().getObsV200RadiusState()) { - case SUD_down: - networkProbeMetrics.setRadiusState(StateUpDownError.disabled); - break; - case SUD_up: - networkProbeMetrics.setRadiusState(StateUpDownError.enabled); - break; - case SUD_error: - networkProbeMetrics.setRadiusState(StateUpDownError.error); - break; - default: - networkProbeMetrics.setRadiusState(StateUpDownError.UNSUPPORTED); - } - } - } else { - // take the average if we don't have from the VLAN Probe - if (radiusMetrics.hasLatencyAve()) { - networkProbeMetrics.setRadiusLatencyInMs(radiusMetrics.getLatencyAve()); - } - } - } - if (networkProbe.hasVlanProbe()) { - VLANMetrics vlanMetrics = networkProbe.getVlanProbe(); - - if (vlanMetrics.hasVlanIF()) { - networkProbeMetrics.setVlanIF(vlanMetrics.getVlanIF()); - } - if (vlanMetrics.hasDhcpLatency()) { - networkProbeMetrics.setDhcpLatencyMs(vlanMetrics.getDhcpLatency()); - } - if (vlanMetrics.hasDhcpState()) { - switch (vlanMetrics.getDhcpState()) { - case SUD_down: - networkProbeMetrics.setDhcpState(StateUpDownError.disabled); - break; - case SUD_up: - networkProbeMetrics.setDhcpState(StateUpDownError.enabled); - break; - case SUD_error: - networkProbeMetrics.setDhcpState(StateUpDownError.error); - break; - default: - networkProbeMetrics.setDhcpState(StateUpDownError.UNSUPPORTED); - } - } - - } - - networkProbeMetricsList.add(networkProbeMetrics); - - } - - apNodeMetrics.setNetworkProbeMetrics(networkProbeMetricsList); - } - - private void updateDeviceStatusForReport(int customerId, long equipmentId, Device deviceReport, int avgRadioTemp) { - Status status = new Status(); - status.setCustomerId(customerId); - status.setEquipmentId(equipmentId); - OperatingSystemPerformance eqOsPerformance = new OperatingSystemPerformance(); - eqOsPerformance.setUptimeInSeconds(deviceReport.getUptime()); - eqOsPerformance.setAvgCpuTemperature(avgRadioTemp); - eqOsPerformance.setAvgCpuUtilization(deviceReport.getCpuUtil().getCpuUtil()); - eqOsPerformance - .setAvgFreeMemoryKb(deviceReport.getMemUtil().getMemTotal() - deviceReport.getMemUtil().getMemUsed()); - eqOsPerformance.setTotalAvailableMemoryKb(deviceReport.getMemUtil().getMemTotal()); - status.setDetails(eqOsPerformance); - status = statusServiceInterface.update(status); - LOG.debug("updated status {}", status); - } - - private void populateApClientMetrics(List metricRecordList, Report report, int customerId, - long equipmentId, long locationId) { - LOG.debug("populateApClientMetrics {} for Customer {} Equipment {}", report.getClientsList(), customerId, - equipmentId); - - for (ClientReport clReport : report.getClientsList()) { - for (Client cl : clReport.getClientListList()) { - - if (cl.getMacAddress() == null) { - LOG.debug( - "No mac address for Client {}, cannot set device mac address for client in ClientMetrics.", - cl); - continue; - } - - LOG.debug("Processing ClientReport from AP {}", cl.getMacAddress()); - - ServiceMetric smr = new ServiceMetric(customerId, equipmentId, new MacAddress(cl.getMacAddress())); - smr.setLocationId(locationId); - metricRecordList.add(smr); - - smr.setCreatedTimestamp(clReport.getTimestampMs()); - smr.setClientMac(new MacAddress(cl.getMacAddress()).getAddressAsLong()); - - // clReport.getChannel(); - ClientMetrics cMetrics = new ClientMetrics(); - smr.setDetails(cMetrics); - - Integer periodLengthSec = 60; // matches what's configured by - // OvsdbDao.configureStats(OvsdbClient) - cMetrics.setPeriodLengthSec(periodLengthSec); - - cMetrics.setRadioType(getRadioTypeFromOpensyncRadioBand(clReport.getBand())); - // we'll report each device as having a single (very long) - // session - long sessionId = WiFiSessionUtility.encodeWiFiAssociationId(clReport.getTimestampMs() / 1000L, - MacAddress.convertMacStringToLongValue(cl.getMacAddress())); - - LOG.debug("populateApClientMetrics Session Id {}", sessionId); - cMetrics.setSessionId(sessionId); - - if (cl.hasStats()) { - if (cl.getStats().hasRssi()) { - int rssi = cl.getStats().getRssi(); - cMetrics.setRssi(rssi); - } - - // populate Rx stats - if (cl.getStats().hasRxBytes()) { - cMetrics.setRxBytes(cl.getStats().getRxBytes()); - } - - if (cl.getStats().hasRxRate()) { - cMetrics.setAverageRxRate(cl.getStats().getRxRate() / 1000); - } - - if (cl.getStats().hasRxErrors()) { - cMetrics.setNumRxNoFcsErr((int) cl.getStats().getRxErrors()); - } - - if (cl.getStats().hasRxFrames()) { - cMetrics.setNumRxFramesReceived(cl.getStats().getRxFrames()); - // cMetrics.setNumRxPackets(cl.getStats().getRxFrames()); - } - - if (cl.getStats().hasRxRetries()) { - cMetrics.setNumRxRetry((int) cl.getStats().getRxRetries()); - } - - // populate Tx stats - if (cl.getStats().hasTxBytes()) { - cMetrics.setNumTxBytes(cl.getStats().getTxBytes()); - } - - if (cl.getStats().hasTxRate()) { - cMetrics.setAverageTxRate(cl.getStats().getTxRate() / 1000); - } - - if (cl.getStats().hasTxRate() && cl.getStats().hasRxRate()) { - cMetrics.setRates(new byte[] { Double.valueOf(cl.getStats().getTxRate() / 1000).byteValue(), - Double.valueOf(cl.getStats().getRxRate() / 1000).byteValue() }); - } - - if (cl.getStats().hasTxErrors()) { - cMetrics.setNumTxDropped((int) cl.getStats().getTxErrors()); - } - - if (cl.getStats().hasRxFrames()) { - cMetrics.setNumTxFramesTransmitted(cl.getStats().getTxFrames()); - } - - if (cl.getStats().hasTxRetries()) { - cMetrics.setNumTxDataRetries((int) cl.getStats().getTxRetries()); - } - } - - LOG.debug("ApClientMetrics Report {}", cMetrics); - - } - - } - - } - - private void populateNeighbourScanReports(List metricRecordList, Report report, int customerId, - long equipmentId, long locationId) { - LOG.debug("populateNeighbourScanReports for Customer {} Equipment {}", customerId, equipmentId); - - for (Neighbor neighbor : report.getNeighborsList()) { - - ServiceMetric smr = new ServiceMetric(customerId, equipmentId); - smr.setLocationId(locationId); - - metricRecordList.add(smr); - NeighbourScanReports neighbourScanReports = new NeighbourScanReports(); - smr.setDetails(neighbourScanReports); - smr.setCreatedTimestamp(neighbor.getTimestampMs()); - - List neighbourReports = new ArrayList<>(); - neighbourScanReports.setNeighbourReports(neighbourReports); - - for (NeighborBss nBss : neighbor.getBssListList()) { - NeighbourReport nr = new NeighbourReport(); - neighbourReports.add(nr); - - if (neighbor.getBand() == RadioBandType.BAND2G) { - nr.setAcMode(false); - nr.setbMode(false); - nr.setnMode(true); - nr.setRadioType(RadioType.is2dot4GHz); - } else if (neighbor.getBand() == RadioBandType.BAND5G) { - nr.setAcMode(true); - nr.setbMode(false); - nr.setnMode(false); - nr.setRadioType(RadioType.is5GHz); - } else if (neighbor.getBand() == RadioBandType.BAND5GL) { - nr.setAcMode(true); - nr.setbMode(false); - nr.setnMode(false); - nr.setRadioType(RadioType.is5GHzL); - } else if (neighbor.getBand() == RadioBandType.BAND5GU) { - nr.setAcMode(true); - nr.setbMode(false); - nr.setnMode(false); - nr.setRadioType(RadioType.is5GHzU); - } - - nr.setChannel(nBss.getChannel()); - nr.setMacAddress(new MacAddress(nBss.getBssid())); - nr.setNetworkType(NetworkType.AP); - nr.setPacketType(NeighborScanPacketType.BEACON); - nr.setPrivacy(((nBss.getSsid() == null) || nBss.getSsid().isEmpty()) ? true : false); - // nr.setRate(rate); - // we can only get Rssi as an unsigned int from opensync, so - // some shifting - int rssi = nBss.getRssi(); - nr.setRssi(rssi); - // nr.setScanTimeInSeconds(scanTimeInSeconds); - nr.setSecureMode(DetectedAuthMode.WPA); - // nr.setSignal(signal); - nr.setSsid(nBss.getSsid()); - } - - } - } - - private void handleClientSessionMetricsUpdate(int customerId, long equipmentId, long locationId, - RadioType radioType, long timestamp, sts.OpensyncStats.Client client) { - try - - { - LOG.info("handleClientSessionUpdate for customerId {} equipmentId {} locationId {} client {} ", customerId, - equipmentId, locationId, client); - - com.telecominfraproject.wlan.client.models.Client clientInstance = clientServiceInterface - .getOrNull(customerId, new MacAddress(client.getMacAddress())); - - boolean isReassociation = true; - if (clientInstance == null) { - clientInstance = new com.telecominfraproject.wlan.client.models.Client(); - clientInstance.setCustomerId(customerId); - clientInstance.setMacAddress(new MacAddress(client.getMacAddress())); - clientInstance.setDetails(new ClientInfoDetails()); - clientInstance = clientServiceInterface.create(clientInstance); - - isReassociation = false; - } - - LOG.info("Client {}", clientInstance); - - ClientSession clientSession = clientServiceInterface.getSessionOrNull(customerId, equipmentId, - clientInstance.getMacAddress()); - - if (clientSession == null) { - - clientSession = new ClientSession(); - clientSession.setCustomerId(customerId); - clientSession.setEquipmentId(equipmentId); - clientSession.setLocationId(locationId); - clientSession.setMacAddress(clientInstance.getMacAddress()); - ClientSessionDetails clientSessionDetails = new ClientSessionDetails(); - clientSessionDetails.setSsid(client.getSsid()); - clientSessionDetails.setRadioType(radioType); - clientSessionDetails.setSessionId(clientInstance.getMacAddress().getAddressAsLong()); - clientSession.setDetails(new ClientSessionDetails()); - clientSession = clientServiceInterface.updateSession(clientSession); - } - - ClientSessionDetails latestClientSessionDetails = clientSession.getDetails(); - latestClientSessionDetails.setIsReassociation(isReassociation); - latestClientSessionDetails.setSsid(client.getSsid()); - latestClientSessionDetails.setRadioType(radioType); - latestClientSessionDetails.setSessionId(clientInstance.getMacAddress().getAddressAsLong()); - latestClientSessionDetails.setLastEventTimestamp(timestamp); - latestClientSessionDetails.setFirstDataSentTimestamp(timestamp - client.getDurationMs()); - latestClientSessionDetails.setFirstDataRcvdTimestamp(timestamp - client.getDurationMs()); - latestClientSessionDetails.setAssociationState(AssociationState.Active_Data); - int rssi = client.getStats().getRssi(); - latestClientSessionDetails.setAssocRssi(rssi); - latestClientSessionDetails.setLastRxTimestamp(timestamp); - latestClientSessionDetails.setLastTxTimestamp(timestamp); - - Equipment ce = equipmentServiceInterface.get(equipmentId); - ProfileContainer profileContainer = new ProfileContainer( - profileServiceInterface.getProfileWithChildren(ce.getProfileId())); - - List ssidConfigList = new ArrayList<>(); - ssidConfigList = profileContainer.getChildrenOfType(ce.getProfileId(), ProfileType.ssid).stream() - .filter(new Predicate() { - - @Override - public boolean test(Profile t) { - - SsidConfiguration ssidConfig = (SsidConfiguration) t.getDetails(); - return ssidConfig.getSsid().equals(client.getSsid()) - && ssidConfig.getAppliedRadios().contains(radioType); - } - - }).collect(Collectors.toList()); - - if (!ssidConfigList.isEmpty()) { - - Profile ssidProfile = ssidConfigList.iterator().next(); - SsidConfiguration ssidConfig = (SsidConfiguration) ssidProfile.getDetails(); - if (ssidConfig.getSecureMode().equals(SecureMode.open)) { - latestClientSessionDetails.setSecurityType(SecurityType.OPEN); - } else if (ssidConfig.getSecureMode().equals(SecureMode.wpaPSK) - || ssidConfig.getSecureMode().equals(SecureMode.wpa2PSK) - || ssidConfig.getSecureMode().equals(SecureMode.wpa2OnlyPSK)) { - latestClientSessionDetails.setSecurityType(SecurityType.PSK); - } else if (ssidConfig.getSecureMode().equals(SecureMode.wpa2Radius) - || ssidConfig.getSecureMode().equals(SecureMode.wpaRadius) - || ssidConfig.getSecureMode().equals(SecureMode.wpa2OnlyRadius)) { - latestClientSessionDetails.setSecurityType(SecurityType.RADIUS); - latestClientSessionDetails.setEapDetails(new ClientEapDetails()); - } else if (ssidConfig.getSecureMode().equals(SecureMode.wpaEAP) - || ssidConfig.getSecureMode().equals(SecureMode.wpa2EAP) - || ssidConfig.getSecureMode().equals(SecureMode.wpa2OnlyEAP)) { - latestClientSessionDetails.setSecurityType(SecurityType.RADIUS); - - latestClientSessionDetails.setEapDetails(new ClientEapDetails()); - } else { - latestClientSessionDetails.setSecurityType(SecurityType.UNSUPPORTED); - } - - if (ssidConfig.getVlanId() > 1) { - latestClientSessionDetails.setDynamicVlan(ssidConfig.getVlanId()); - } - - - RadioBasedSsidConfiguration radioConfig = ssidConfig.getRadioBasedConfigs().get(radioType); - latestClientSessionDetails - .setIs11KUsed(radioConfig.getEnable80211k() != null ? radioConfig.getEnable80211k() : false); - latestClientSessionDetails - .setIs11RUsed(radioConfig.getEnable80211r() != null ? radioConfig.getEnable80211r() : false); - latestClientSessionDetails - .setIs11VUsed(radioConfig.getEnable80211v() != null ? radioConfig.getEnable80211v() : false); - - } - - latestClientSessionDetails.setMetricDetails(calculateClientSessionMetricDetails(client, timestamp)); - - clientSession.getDetails().mergeSession(latestClientSessionDetails); - clientSession.setLastModifiedTimestamp(timestamp); - - clientSession = clientServiceInterface.updateSession(clientSession); - - LOG.debug("Updated client session {}", clientSession); - - } catch (Exception e) { - LOG.error("Error while attempting to create ClientSession and Info", e); - } - } - - private RadioType getRadioTypeFromOpensyncRadioBand(RadioBandType band) { - RadioType radioType = null; - switch (band) { - case BAND2G: - radioType = RadioType.is2dot4GHz; - break; - case BAND5G: - radioType = RadioType.is5GHz; - break; - case BAND5GU: - radioType = RadioType.is5GHzU; - break; - case BAND5GL: - radioType = RadioType.is5GHzL; - break; - default: - radioType = RadioType.UNSUPPORTED; - } - return radioType; - } - - private ClientSessionMetricDetails calculateClientSessionMetricDetails(sts.OpensyncStats.Client client, - long timestamp) { - - LOG.debug("calculateClientSessionMetricDetails for Client {} at timestamp {}", client.getMacAddress(), - timestamp); - - ClientSessionMetricDetails metricDetails = new ClientSessionMetricDetails(); - - int rssi = client.getStats().getRssi(); - metricDetails.setRssi(rssi); - metricDetails.setRxBytes(client.getStats().getRxBytes()); - metricDetails.setTxBytes(client.getStats().getTxBytes()); - metricDetails.setTotalTxPackets(client.getStats().getTxFrames()); - metricDetails.setTotalRxPackets(client.getStats().getRxFrames()); - metricDetails.setTxDataFrames((int) client.getStats().getTxFrames()); - metricDetails.setRxDataFrames((int) client.getStats().getRxFrames()); - // values reported in Kbps, convert to Mbps - metricDetails.setRxMbps((float) (client.getStats().getRxRate() / 1000)); - metricDetails.setTxMbps((float) (client.getStats().getTxRate() / 1000)); - // Throughput, do rate / duration - if (client.getDurationMs() > 0) { - metricDetails.setRxRateKbps((long) client.getStats().getRxRate() / client.getDurationMs()); - metricDetails.setTxRateKbps((long) client.getStats().getTxRate() / client.getDurationMs()); - } else { - LOG.info("Cannot calculate tx/rx throughput for Client {} based on duration of {} Ms", - client.getMacAddress(), client.getDurationMs()); - } - metricDetails.setLastMetricTimestamp(timestamp); - - return metricDetails; - } - - private void populateApSsidMetrics(List metricRecordList, Report report, int customerId, - long equipmentId, String apId, long locationId) { - - LOG.debug("populateApSsidMetrics for Customer {} Equipment {}", customerId, equipmentId); - ServiceMetric smr = new ServiceMetric(customerId, equipmentId); - smr.setLocationId(locationId); - ApSsidMetrics apSsidMetrics = new ApSsidMetrics(); - - - smr.setDetails(apSsidMetrics); - metricRecordList.add(smr); - - - for (ClientReport clientReport : report.getClientsList()) { - - LOG.debug("ClientReport for channel {} RadioBand {}", clientReport.getChannel(), clientReport.getBand()); - - if (smr.getCreatedTimestamp() < clientReport.getTimestampMs()) { - smr.setCreatedTimestamp(clientReport.getTimestampMs()); - } - - long txBytes = 0L; - long rxBytes = 0L; - long txFrames = 0L; - long rxFrames = 0L; - - int txErrors = 0; - int rxErrors = 0; - - int txRetries = 0; - int rxRetries = 0; - - int lastRssi = 0; - String ssid = null; - - Set clientMacs = new HashSet<>(); - - RadioType radioType = getRadioTypeFromOpensyncRadioBand(clientReport.getBand()); - - SsidStatistics ssidStatistics = new SsidStatistics(); - // GET the Radio IF MAC (BSSID) from the activeBSSIDs - - Status activeBssidsStatus = statusServiceInterface.getOrNull(customerId, equipmentId, - StatusDataType.ACTIVE_BSSIDS); - ActiveBSSIDs statusDetails = null; - if (activeBssidsStatus != null) { - statusDetails = (ActiveBSSIDs) activeBssidsStatus.getDetails(); - for (ActiveBSSID activeBSSID : ((ActiveBSSIDs) activeBssidsStatus.getDetails()).getActiveBSSIDs()) { - if (activeBSSID.getRadioType().equals(radioType)) { - ssidStatistics.setBssid(new MacAddress(activeBSSID.getBssid())); - // ssid value, in case not in stats, else will take - // stats value after - ssid = activeBSSID.getSsid(); - statusDetails.getActiveBSSIDs().indexOf(activeBSSID); - } - } - } - LOG.debug("Client Report Date is {}", new Date(clientReport.getTimestampMs())); - int numConnectedClients = 0; - for (Client client : clientReport.getClientListList()) { - if (client.hasStats()) { - - - if (client.hasSsid()) { - ssid = client.getSsid(); - } - - if (client.hasMacAddress()) { - clientMacs.add(client.getMacAddress()); - - } else { - continue; // cannot have a session without a MAC address - } - - rxBytes += client.getStats().getRxBytes(); - txBytes += client.getStats().getTxBytes(); - txFrames += client.getStats().getRxFrames(); - rxFrames += client.getStats().getTxFrames(); - rxRetries += client.getStats().getRxRetries(); - txRetries += client.getStats().getTxRetries(); - rxErrors += client.getStats().getRxErrors(); - txErrors += client.getStats().getTxErrors(); - lastRssi = client.getStats().getRssi(); - - try { - - if (client.hasConnected() && client.getConnected()) { - // update metrics for connected client - numConnectedClients += 1; - handleClientSessionMetricsUpdate(customerId, equipmentId, locationId, radioType, - clientReport.getTimestampMs(), client); - } else { - // Make sure, if we have a session for this client, - // it - // shows disconnected. - // update any metrics that need update if the - // disconnect occured during this window - if (client.hasMacAddress()) { - ClientSession session = clientServiceInterface.getSessionOrNull(customerId, equipmentId, - new MacAddress(client.getMacAddress())); - - if (session != null) { - if (session.getDetails().getAssociationState() != null && !session.getDetails() - .getAssociationState().equals(AssociationState.Disconnected)) { - - ClientSessionDetails latestSessionDetails = new ClientSessionDetails(); - latestSessionDetails.setAssociationState(AssociationState.Disconnected); - latestSessionDetails.setLastEventTimestamp(clientReport.getTimestampMs()); - latestSessionDetails - .setDisconnectByClientTimestamp(client.hasDisconnectOffsetMs() - ? clientReport.getTimestampMs() - client.getDisconnectOffsetMs() - : clientReport.getTimestampMs()); - if (client.hasSsid()) { - latestSessionDetails.setSsid(client.getSsid()); - } - - // could still be values from before - // disconnect occured. - latestSessionDetails.setMetricDetails(calculateClientSessionMetricDetails( - client, clientReport.getTimestampMs())); - - session.getDetails().mergeSession(latestSessionDetails); - - clientServiceInterface.updateSession(session); - - } - } - - } - - continue; // not connected - } - - - } catch (Exception e) { - LOG.debug("Unabled to update client {} session {}", client, e); - } - - } - - } - - // 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); - ssidStatistics.setNumTxDataRetries(txRetries); - ssidStatistics.setNumRcvFrameForTx(txFrames); - ssidStatistics.setNumTxBytesSucc(txBytes - txErrors - txRetries); - ssidStatistics.setNumRxRetry(rxRetries); - ssidStatistics.setNumClient(numConnectedClients); - ssidStatistics.setSsid(ssid); - - if (radioType != null) { - List ssidStatsList = apSsidMetrics.getSsidStats().get(radioType); - if (ssidStatsList == null) { - ssidStatsList = new ArrayList<>(); - } - ssidStatsList.add(ssidStatistics); - apSsidMetrics.getSsidStats().put(radioType, ssidStatsList); - } - - } - - LOG.debug("ApSsidMetrics {}", apSsidMetrics); - - } - - int getNegativeSignedIntFrom8BitUnsigned(int unsignedValue) { - byte b = (byte) Integer.parseInt(Integer.toHexString(unsignedValue), 16); - return b; - } - - private void populateChannelInfoReports(List metricRecordList, Report report, int customerId, - long equipmentId, long locationId) { - - LOG.debug("populateChannelInfoReports for Customer {} Equipment {}", customerId, equipmentId); - - for (Survey survey : report.getSurveyList()) { - - ServiceMetric smr = new ServiceMetric(); - smr.setCustomerId(customerId); - smr.setEquipmentId(equipmentId); - smr.setLocationId(locationId); - - ChannelInfoReports channelInfoReports = new ChannelInfoReports(); - Map> channelInfoMap = channelInfoReports - .getChannelInformationReportsPerRadio(); - - RadioType radioType = null; - - if (survey.hasBand()) { - radioType = getRadioTypeFromOpensyncRadioBand(survey.getBand()); - } else { - continue; - } - - - ChannelBandwidth channelBandwidth = ((ApElementConfiguration) equipmentServiceInterface.get(equipmentId) - .getDetails()).getRadioMap().get(radioType).getChannelBandwidth(); - - Map> sampleByChannelMap = new HashMap<>(); - - survey.getSurveyListList().stream().filter(new Predicate() { - - @Override - public boolean test(SurveySample t) { - if (survey.getSurveyType().equals(SurveyType.ON_CHANNEL)) { - return t.hasDurationMs() && t.getDurationMs() > 0 && t.hasChannel() && t.hasBusy() - && t.hasBusyTx() && t.hasNoise(); - } else { - return t.hasDurationMs() && t.hasChannel(); - } - } - - }).forEach(s -> { - List surveySampleList; - if (sampleByChannelMap.get(s.getChannel()) == null) { - surveySampleList = new ArrayList<>(); - } else { - surveySampleList = sampleByChannelMap.get(s.getChannel()); - } - surveySampleList.add(s); - sampleByChannelMap.put(s.getChannel(), surveySampleList); - }); - - for (List surveySampleList : sampleByChannelMap.values()) { - ChannelInfo channelInfo = createChannelInfo(equipmentId, radioType, surveySampleList, channelBandwidth); - List channelInfoList = channelInfoReports.getRadioInfo(radioType); - if (channelInfoList == null) { - channelInfoList = new ArrayList<>(); - } - channelInfoList.add(channelInfo); - channelInfoMap.put(radioType, channelInfoList); - channelInfoReports.setChannelInformationReportsPerRadio(channelInfoMap); - } - - - channelInfoReports.setChannelInformationReportsPerRadio(channelInfoMap); - smr.setDetails(channelInfoReports); - smr.setCreatedTimestamp(survey.getTimestampMs()); - metricRecordList.add(smr); - - LOG.debug("ChannelInfoReports {}", channelInfoReports); - - } - - - } - - private ChannelInfo createChannelInfo(long equipmentId, RadioType radioType, List surveySampleList, - ChannelBandwidth channelBandwidth) { - int busyTx = 0; /* Tx */ - int busySelf = 0; /* Rx_self (derived from succesful Rx frames) */ - int busy = 0; /* Busy = Rx + Tx + Interference */ - ChannelInfo channelInfo = new ChannelInfo(); - - int[] noiseArray = new int[surveySampleList.size()]; - int index = 0; - for (SurveySample sample : surveySampleList) { - LOG.debug("createChannelInfo::SurveySample {}", sample); - busyTx += sample.getBusyTx(); - busySelf += sample.getBusySelf(); - busy += sample.getBusy(); - channelInfo.setChanNumber(sample.getChannel()); - noiseArray[index++] = getNegativeSignedIntFrom8BitUnsigned(sample.getNoise()); - } - - int iBSS = busyTx + busySelf; - - int totalWifi = busy - iBSS; - - channelInfo.setTotalUtilization(busy); - channelInfo.setWifiUtilization(totalWifi); - channelInfo.setBandwidth(channelBandwidth); - if (surveySampleList.size() > 0) { - channelInfo.setNoiseFloor((int) Math.round(DecibelUtils.getAverageDecibel(noiseArray))); - } - return channelInfo; - } @Override public void processMqttMessage(String topic, FlowReport flowReport) { - - LOG.info("Received report on topic {}", topic); - int customerId = extractCustomerIdFromTopic(topic); - - long equipmentId = extractEquipmentIdFromTopic(topic); - if ((equipmentId <= 0) || (customerId <= 0)) { - LOG.warn("Cannot determine equipment ids from topic {} - customerId {} equipmentId {}", topic, customerId, - equipmentId); - return; - } - - String apId = extractApIdFromTopic(topic); - - if (apId == null) { - LOG.warn("Cannot determine AP id from topic {} - customerId {} equipmentId {} apId {}", topic, customerId, - equipmentId, apId); - return; - } - - if (LOG.isTraceEnabled()) { - // prepare a JSONPrinter to format protobuf messages as - // json - List protobufDescriptors = new ArrayList<>(); - protobufDescriptors.addAll(NetworkMetadata.getDescriptor().getMessageTypes()); - TypeRegistry oldRegistry = TypeRegistry.newBuilder().add(protobufDescriptors).build(); - JsonFormat.Printer jsonPrinter = JsonFormat.printer().preservingProtoFieldNames() - .includingDefaultValueFields().usingTypeRegistry(oldRegistry); - - try { - LOG.trace("MQTT NetworkMetadata.flowReport = {}", jsonPrinter.print(flowReport)); - - } catch (InvalidProtocolBufferException e1) { - LOG.error("Couldn't parse NetworkMetadata.flowReport.", e1); - } - } - + mqttMessageProcessor.processMqttMessage(topic, flowReport); } @Override public void processMqttMessage(String topic, WCStatsReport wcStatsReport) { - LOG.debug("Received WCStatsReport {}", wcStatsReport.toString()); - - LOG.info("Received report on topic {}", topic); - int customerId = extractCustomerIdFromTopic(topic); - - long equipmentId = extractEquipmentIdFromTopic(topic); - if ((equipmentId <= 0) || (customerId <= 0)) { - LOG.warn("Cannot determine equipment ids from topic {} - customerId {} equipmentId {}", topic, customerId, - equipmentId); - return; - } - - String apId = extractApIdFromTopic(topic); - - if (apId == null) { - LOG.warn("Cannot determine AP id from topic {} - customerId {} equipmentId {} apId {}", topic, customerId, - equipmentId, apId); - return; - } - - if (LOG.isTraceEnabled()) { - // prepare a JSONPrinter to format protobuf messages as - // json - List protobufDescriptors = new ArrayList<>(); - protobufDescriptors.addAll(IpDnsTelemetry.getDescriptor().getMessageTypes()); - TypeRegistry oldRegistry = TypeRegistry.newBuilder().add(protobufDescriptors).build(); - JsonFormat.Printer jsonPrinter = JsonFormat.printer().preservingProtoFieldNames() - .includingDefaultValueFields().usingTypeRegistry(oldRegistry); - - try { - LOG.trace("MQTT IpDnsTelemetry.wcStatsReport = {}", jsonPrinter.print(wcStatsReport)); - - } catch (InvalidProtocolBufferException e1) { - LOG.error("Couldn't parse IpDnsTelemetry.wcStatsReport.", e1); - } - } - + mqttMessageProcessor.processMqttMessage(topic, wcStatsReport); } @Override @@ -2756,14 +857,7 @@ public class OpensyncExternalIntegrationCloud implements OpensyncExternalIntegra RadioType radioType = null; Optional radioConfiguration = ((ApElementConfiguration) apNode.getDetails()) - .getRadioMap().values().stream().filter(new Predicate() { - - @Override - public boolean test(ElementRadioConfiguration t) { - return (t.getActiveChannel() == channel); - } - - }).findFirst(); + .getRadioMap().values().stream().filter(t -> (t.getActiveChannel() == channel)).findFirst(); if (radioConfiguration.isPresent()) { radioType = radioConfiguration.get().getRadioType(); @@ -2980,7 +1074,7 @@ public class OpensyncExternalIntegrationCloud implements OpensyncExternalIntegra currentActiveBSSIDs = new ArrayList<>(); } else { currentActiveBSSIDs = currentActiveBSSIDs.stream() - .filter(p -> !(p.getRadioType().equals(freqBand) && p.getSsid().equals(ssid))) + .filter(p -> (!p.getRadioType().equals(freqBand) || !p.getSsid().equals(ssid))) .collect(Collectors.toList()); LOG.debug( "Processing Wifi_VIF_State table update for AP {}, activeBSSIDs bssidList without current radio freq {} and ssid {}", @@ -3503,7 +1597,7 @@ public class OpensyncExternalIntegrationCloud implements OpensyncExternalIntegra ClientSessionDetails clientSessionDetails = session.getDetails(); - if (clientSessionDetails.getAssociationState() != null + if ((clientSessionDetails.getAssociationState() != null) && !clientSessionDetails.getAssociationState().equals(AssociationState.Disconnected)) { clientSessionDetails.setDisconnectByClientTimestamp(System.currentTimeMillis()); clientSessionDetails.setAssociationState(AssociationState.Disconnected); @@ -3521,19 +1615,6 @@ public class OpensyncExternalIntegrationCloud implements OpensyncExternalIntegra } - private static int[] toIntArray(List values) { - if (values != null) { - int returnValue[] = new int[values.size()]; - int index = 0; - - for (Integer value : values) { - returnValue[index++] = value; - } - - return returnValue; - } - return null; - } @Override public void dhcpLeasedIpDbTableUpdate(List> dhcpAttributes, String apId, 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 new file mode 100644 index 0000000..4466d7e --- /dev/null +++ b/opensync-ext-cloud/src/main/java/com/telecominfraproject/wlan/opensync/external/integration/OpensyncExternalIntegrationMqttMessageProcessor.java @@ -0,0 +1,1981 @@ +package com.telecominfraproject.wlan.opensync.external.integration; + +import java.net.InetAddress; +import java.net.UnknownHostException; +import java.util.ArrayList; +import java.util.Date; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.stream.Collectors; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +import com.google.protobuf.Descriptors; +import com.google.protobuf.InvalidProtocolBufferException; +import com.google.protobuf.util.JsonFormat; +import com.google.protobuf.util.JsonFormat.TypeRegistry; +import com.telecominfraproject.wlan.client.ClientServiceInterface; +import com.telecominfraproject.wlan.client.info.models.ClientInfoDetails; +import com.telecominfraproject.wlan.client.session.models.AssociationState; +import com.telecominfraproject.wlan.client.session.models.ClientEapDetails; +import com.telecominfraproject.wlan.client.session.models.ClientFailureDetails; +import com.telecominfraproject.wlan.client.session.models.ClientSession; +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.DetectedAuthMode; +import com.telecominfraproject.wlan.core.model.equipment.MacAddress; +import com.telecominfraproject.wlan.core.model.equipment.NeighborScanPacketType; +import com.telecominfraproject.wlan.core.model.equipment.NetworkType; +import com.telecominfraproject.wlan.core.model.equipment.RadioType; +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.profile.ProfileServiceInterface; +import com.telecominfraproject.wlan.profile.models.Profile; +import com.telecominfraproject.wlan.profile.models.ProfileContainer; +import com.telecominfraproject.wlan.profile.models.ProfileType; +import com.telecominfraproject.wlan.profile.ssid.models.RadioBasedSsidConfiguration; +import com.telecominfraproject.wlan.profile.ssid.models.SsidConfiguration; +import com.telecominfraproject.wlan.profile.ssid.models.SsidConfiguration.SecureMode; +import com.telecominfraproject.wlan.servicemetric.apnode.models.ApNodeMetrics; +import com.telecominfraproject.wlan.servicemetric.apnode.models.ApPerformance; +import com.telecominfraproject.wlan.servicemetric.apnode.models.DnsProbeMetric; +import com.telecominfraproject.wlan.servicemetric.apnode.models.EthernetLinkState; +import com.telecominfraproject.wlan.servicemetric.apnode.models.NetworkProbeMetrics; +import com.telecominfraproject.wlan.servicemetric.apnode.models.RadioStatistics; +import com.telecominfraproject.wlan.servicemetric.apnode.models.RadioUtilization; +import com.telecominfraproject.wlan.servicemetric.apnode.models.StateUpDownError; +import com.telecominfraproject.wlan.servicemetric.apssid.models.ApSsidMetrics; +import com.telecominfraproject.wlan.servicemetric.apssid.models.SsidStatistics; +import com.telecominfraproject.wlan.servicemetric.channelinfo.models.ChannelInfo; +import com.telecominfraproject.wlan.servicemetric.channelinfo.models.ChannelInfoReports; +import com.telecominfraproject.wlan.servicemetric.client.models.ClientMetrics; +import com.telecominfraproject.wlan.servicemetric.models.ServiceMetric; +import com.telecominfraproject.wlan.servicemetric.neighbourscan.models.NeighbourReport; +import com.telecominfraproject.wlan.servicemetric.neighbourscan.models.NeighbourScanReports; +import com.telecominfraproject.wlan.status.StatusServiceInterface; +import com.telecominfraproject.wlan.status.equipment.report.models.ActiveBSSID; +import com.telecominfraproject.wlan.status.equipment.report.models.ActiveBSSIDs; +import com.telecominfraproject.wlan.status.equipment.report.models.EquipmentCapacityDetails; +import com.telecominfraproject.wlan.status.equipment.report.models.OperatingSystemPerformance; +import com.telecominfraproject.wlan.status.equipment.report.models.RadioUtilizationReport; +import com.telecominfraproject.wlan.status.models.Status; +import com.telecominfraproject.wlan.status.models.StatusDataType; + +import sts.OpensyncStats; +import sts.OpensyncStats.AssocType; +import sts.OpensyncStats.Client; +import sts.OpensyncStats.ClientReport; +import sts.OpensyncStats.DNSProbeMetric; +import sts.OpensyncStats.Device; +import sts.OpensyncStats.Device.RadioTemp; +import sts.OpensyncStats.EventReport.ClientAssocEvent; +import sts.OpensyncStats.EventReport.ClientAuthEvent; +import sts.OpensyncStats.EventReport.ClientDisconnectEvent; +import sts.OpensyncStats.EventReport.ClientFailureEvent; +import sts.OpensyncStats.EventReport.ClientFirstDataEvent; +import sts.OpensyncStats.EventReport.ClientIdEvent; +import sts.OpensyncStats.EventReport.ClientIpEvent; +import sts.OpensyncStats.EventReport.ClientTimeoutEvent; +import sts.OpensyncStats.FrameType; +import sts.OpensyncStats.Neighbor; +import sts.OpensyncStats.Neighbor.NeighborBss; +import sts.OpensyncStats.NetworkProbe; +import sts.OpensyncStats.RADIUSMetrics; +import sts.OpensyncStats.RadioBandType; +import sts.OpensyncStats.Report; +import sts.OpensyncStats.Survey; +import sts.OpensyncStats.Survey.SurveySample; +import sts.OpensyncStats.SurveyType; +import sts.OpensyncStats.UCCReport; +import sts.OpensyncStats.VLANMetrics; +import traffic.NetworkMetadata; +import traffic.NetworkMetadata.FlowReport; +import wc.stats.IpDnsTelemetry; +import wc.stats.IpDnsTelemetry.WCStatsReport; + +@org.springframework.context.annotation.Profile("opensync_cloud_config") +@Component +public class OpensyncExternalIntegrationMqttMessageProcessor { + + private static final Logger LOG = LoggerFactory.getLogger(OpensyncExternalIntegrationMqttMessageProcessor.class); + + @Autowired + private EquipmentServiceInterface equipmentServiceInterface; + @Autowired + private OvsdbSessionMapInterface ovsdbSessionMapInterface; + @Autowired + private ProfileServiceInterface profileServiceInterface; + @Autowired + private StatusServiceInterface statusServiceInterface; + @Autowired + private ClientServiceInterface clientServiceInterface; + @Autowired + private CloudEventDispatcherInterface equipmentMetricsCollectorInterface; + + void processMqttMessage(String topic, WCStatsReport wcStatsReport) { + LOG.debug("Received WCStatsReport {}", wcStatsReport.toString()); + + LOG.info("Received report on topic {}", topic); + int customerId = extractCustomerIdFromTopic(topic); + + long equipmentId = extractEquipmentIdFromTopic(topic); + if ((equipmentId <= 0) || (customerId <= 0)) { + LOG.warn("Cannot determine equipment ids from topic {} - customerId {} equipmentId {}", topic, customerId, + equipmentId); + return; + } + + String apId = extractApIdFromTopic(topic); + + if (apId == null) { + LOG.warn("Cannot determine AP id from topic {} - customerId {} equipmentId {} apId {}", topic, customerId, + equipmentId, apId); + return; + } + + if (LOG.isTraceEnabled()) { + // prepare a JSONPrinter to format protobuf messages as + // json + List protobufDescriptors = new ArrayList<>(); + protobufDescriptors.addAll(IpDnsTelemetry.getDescriptor().getMessageTypes()); + TypeRegistry oldRegistry = TypeRegistry.newBuilder().add(protobufDescriptors).build(); + JsonFormat.Printer jsonPrinter = JsonFormat.printer().preservingProtoFieldNames() + .includingDefaultValueFields().usingTypeRegistry(oldRegistry); + + try { + LOG.trace("MQTT IpDnsTelemetry.wcStatsReport = {}", jsonPrinter.print(wcStatsReport)); + + } catch (InvalidProtocolBufferException e1) { + LOG.error("Couldn't parse IpDnsTelemetry.wcStatsReport.", e1); + } + } + + } + + void processMqttMessage(String topic, Report report) { + LOG.info("Received report on topic {} for ap {}", topic, report.getNodeID()); + int customerId = extractCustomerIdFromTopic(topic); + String apId = extractApIdFromTopic(topic); + long equipmentId = extractEquipmentIdFromTopic(topic); + if ((equipmentId <= 0) || (customerId <= 0)) { + LOG.warn("Cannot determine equipment ids from topic {} - customerId {} equipmentId {}", topic, customerId, + equipmentId); + return; + } + + // gatewayController.updateActiveCustomer(customerId); + + Equipment ce = equipmentServiceInterface.getOrNull(equipmentId); + if (ce == null) { + LOG.warn("Cannot read equipment {}", apId); + return; + } + + long locationId = ce.getLocationId(); + + if (LOG.isTraceEnabled()) { + // prepare a JSONPrinter to format protobuf messages as + // json + List protobufDescriptors = new ArrayList<>(); + protobufDescriptors.addAll(OpensyncStats.getDescriptor().getMessageTypes()); + TypeRegistry oldRegistry = TypeRegistry.newBuilder().add(protobufDescriptors).build(); + JsonFormat.Printer jsonPrinter = JsonFormat.printer().preservingProtoFieldNames() + .includingDefaultValueFields().usingTypeRegistry(oldRegistry); + + try { + LOG.trace("MQTT OpensyncStats.report = {}", jsonPrinter.print(report)); + + } catch (InvalidProtocolBufferException e1) { + LOG.error("Couldn't parse OpensyncStats.report.", e1); + } + } + + List metricRecordList = new ArrayList<>(); + + try { + populateApClientMetrics(metricRecordList, report, customerId, equipmentId, locationId); + populateApNodeMetrics(metricRecordList, report, customerId, equipmentId, locationId); + populateNeighbourScanReports(metricRecordList, report, customerId, equipmentId, locationId); + populateChannelInfoReports(metricRecordList, report, customerId, equipmentId, locationId); + populateApSsidMetrics(metricRecordList, report, customerId, equipmentId, apId, locationId); + // TODO: uncomment when AP support present + populateUccReport(metricRecordList, report, customerId, equipmentId, apId, locationId); + processEventReport(report, customerId, equipmentId, apId, locationId); + // handleRssiMetrics(metricRecordList, report, customerId, + // equipmentId, locationId); + + } catch (Exception e) { + LOG.error("Exception when processing populateApSsidMetrics", e); + } + + if (!metricRecordList.isEmpty()) { + LOG.debug("Publishing Metrics {}", metricRecordList); + equipmentMetricsCollectorInterface.publishMetrics(metricRecordList); + } + + } + + void processMqttMessage(String topic, FlowReport flowReport) { + + LOG.info("Received report on topic {}", topic); + int customerId = extractCustomerIdFromTopic(topic); + + long equipmentId = extractEquipmentIdFromTopic(topic); + if ((equipmentId <= 0) || (customerId <= 0)) { + LOG.warn("Cannot determine equipment ids from topic {} - customerId {} equipmentId {}", topic, customerId, + equipmentId); + return; + } + + String apId = extractApIdFromTopic(topic); + + if (apId == null) { + LOG.warn("Cannot determine AP id from topic {} - customerId {} equipmentId {} apId {}", topic, customerId, + equipmentId, apId); + return; + } + + if (LOG.isTraceEnabled()) { + // prepare a JSONPrinter to format protobuf messages as + // json + List protobufDescriptors = new ArrayList<>(); + protobufDescriptors.addAll(NetworkMetadata.getDescriptor().getMessageTypes()); + TypeRegistry oldRegistry = TypeRegistry.newBuilder().add(protobufDescriptors).build(); + JsonFormat.Printer jsonPrinter = JsonFormat.printer().preservingProtoFieldNames() + .includingDefaultValueFields().usingTypeRegistry(oldRegistry); + + try { + LOG.trace("MQTT NetworkMetadata.flowReport = {}", jsonPrinter.print(flowReport)); + + } catch (InvalidProtocolBufferException e1) { + LOG.error("Couldn't parse NetworkMetadata.flowReport.", e1); + } + } + + } + + + void processEventReport(Report report, int customerId, long equipmentId, String apId, long locationId) { + + LOG.debug("Processing EventReport List {}", report.getEventReportList()); + + report.getEventReportList().stream().forEach(e -> { + LOG.info("Received EventReport {}", e); + + if (e.hasClientAssocEvent()) { + + + ClientAssocEvent clientAssocEvent = e.getClientAssocEvent(); + + if (clientAssocEvent.hasStaMac()) { + com.telecominfraproject.wlan.client.models.Client client = clientServiceInterface + .getOrNull(customerId, new MacAddress(clientAssocEvent.getStaMac())); + if (client == null) { + client = new com.telecominfraproject.wlan.client.models.Client(); + + client.setCustomerId(customerId); + client.setMacAddress(new MacAddress(clientAssocEvent.getStaMac())); + + client.setDetails(new ClientInfoDetails()); + + client = clientServiceInterface.create(client); + + } + + ClientSession clientSession = clientServiceInterface.getSessionOrNull(customerId, equipmentId, + new MacAddress(clientAssocEvent.getStaMac())); + + if (clientSession == null) { + clientSession = new ClientSession(); + } + clientSession.setCustomerId(customerId); + clientSession.setEquipmentId(equipmentId); + clientSession.setLocationId(locationId); + clientSession.setMacAddress(new MacAddress(clientAssocEvent.getStaMac())); + + ClientSessionDetails clientSessionDetails = new ClientSessionDetails(); + if (clientAssocEvent.hasUsing11K()) { + clientSessionDetails.setIs11KUsed(clientAssocEvent.getUsing11K()); + } + if (clientAssocEvent.hasUsing11R()) { + clientSessionDetails.setIs11RUsed(clientAssocEvent.getUsing11R()); + } + if (clientAssocEvent.hasUsing11V()) { + clientSessionDetails.setIs11VUsed(clientAssocEvent.getUsing11V()); + } + if (clientAssocEvent.hasAssocType()) { + clientSessionDetails + .setIsReassociation(clientAssocEvent.getAssocType().equals(AssocType.REASSOC)); + } + if (clientAssocEvent.hasBand()) { + clientSessionDetails + .setRadioType(getRadioTypeFromOpensyncRadioBand(clientAssocEvent.getBand())); + } + if (clientAssocEvent.hasRssi()) { + clientSessionDetails.setAssocRssi(clientAssocEvent.getRssi()); + } + if (clientAssocEvent.hasSessionId()) { + clientSessionDetails.setSessionId(clientAssocEvent.getSessionId()); + } + if (clientAssocEvent.hasSsid()) { + clientSessionDetails.setSsid(clientAssocEvent.getSsid()); + } + if (clientAssocEvent.hasStatus()) { + clientSessionDetails.setAssociationStatus(clientAssocEvent.getStatus()); + clientSessionDetails.setAssociationState(AssociationState._802_11_Associated); + } + + if (clientSession.getDetails() == null) { + clientSession.setDetails(clientSessionDetails); + } else { + clientSession.getDetails().mergeSession(clientSessionDetails); + } + + clientSession = clientServiceInterface.updateSession(clientSession); + + } else { + LOG.info("Cannot update client or client session when no client mac address is present"); + } + + + } + + if (e.hasClientAuthEvent()) { + + + ClientAuthEvent clientAuthEvent = e.getClientAuthEvent(); + + + if (clientAuthEvent.hasStaMac()) { + + com.telecominfraproject.wlan.client.models.Client client = clientServiceInterface + .getOrNull(customerId, new MacAddress(clientAuthEvent.getStaMac())); + if (client == null) { + client = new com.telecominfraproject.wlan.client.models.Client(); + + client.setCustomerId(customerId); + client.setMacAddress(new MacAddress(clientAuthEvent.getStaMac())); + + client.setDetails(new ClientInfoDetails()); + + client = clientServiceInterface.create(client); + + } + + ClientSession clientSession = clientServiceInterface.getSessionOrNull(customerId, equipmentId, + new MacAddress(clientAuthEvent.getStaMac())); + + if (clientSession == null) { + clientSession = new ClientSession(); + } + + clientSession.setCustomerId(customerId); + clientSession.setEquipmentId(equipmentId); + clientSession.setLocationId(locationId); + clientSession.setMacAddress(new MacAddress(clientAuthEvent.getStaMac())); + + ClientSessionDetails clientSessionDetails = new ClientSessionDetails(); + + if (clientAuthEvent.hasSessionId()) { + clientSessionDetails.setSessionId(clientAuthEvent.getSessionId()); + } + if (clientAuthEvent.hasBand()) { + clientSessionDetails.setRadioType(getRadioTypeFromOpensyncRadioBand(clientAuthEvent.getBand())); + } + if (clientAuthEvent.hasSsid()) { + clientSessionDetails.setSsid(clientAuthEvent.getSsid()); + } + if (clientAuthEvent.hasAuthStatus()) { + clientSessionDetails.setAssociationState(AssociationState._802_11_Authenticated); + } + + + if (clientSession.getDetails() == null) { + clientSession.setDetails(clientSessionDetails); + } else { + clientSession.getDetails().mergeSession(clientSessionDetails); + } + + clientSession = clientServiceInterface.updateSession(clientSession); + + + } else { + LOG.info("Cannot update client or client session when no client mac address is present"); + } + + + } + + if (e.hasClientDisconnectEvent()) { + ClientDisconnectEvent clientDisconnectEvent = e.getClientDisconnectEvent(); + + if (clientDisconnectEvent.hasStaMac()) { + + com.telecominfraproject.wlan.client.models.Client client = clientServiceInterface + .getOrNull(customerId, new MacAddress(clientDisconnectEvent.getStaMac())); + if (client == null) { + client = new com.telecominfraproject.wlan.client.models.Client(); + + client.setCustomerId(customerId); + client.setMacAddress(new MacAddress(clientDisconnectEvent.getStaMac())); + + client.setDetails(new ClientInfoDetails()); + + client = clientServiceInterface.create(client); + + } + + ClientSession clientSession = clientServiceInterface.getSessionOrNull(customerId, equipmentId, + new MacAddress(clientDisconnectEvent.getStaMac())); + + if (clientSession == null) { + clientSession = new ClientSession(); + } + + clientSession.setCustomerId(customerId); + clientSession.setEquipmentId(equipmentId); + clientSession.setLocationId(locationId); + clientSession.setMacAddress(new MacAddress(clientDisconnectEvent.getStaMac())); + + ClientSessionDetails clientSessionDetails = new ClientSessionDetails(); + + if (clientDisconnectEvent.hasBand()) { + clientSessionDetails + .setRadioType(getRadioTypeFromOpensyncRadioBand(clientDisconnectEvent.getBand())); + } + if (clientDisconnectEvent.hasDevType()) { + } + if (clientDisconnectEvent.hasFrType()) { + if (clientDisconnectEvent.getFrType().equals(FrameType.FT_DEAUTH)) { + } + if (clientDisconnectEvent.getFrType().equals(FrameType.FT_DISASSOC)) { + } + } + if (clientDisconnectEvent.hasRssi()) { + clientSessionDetails.setAssocRssi(clientDisconnectEvent.getRssi()); + } + + if (clientDisconnectEvent.hasSessionId()) { + clientSessionDetails.setSessionId(clientDisconnectEvent.getSessionId()); + } + + if (clientDisconnectEvent.hasLrcvUpTsInUs()) { + clientSessionDetails.setLastRxTimestamp(clientDisconnectEvent.getLrcvUpTsInUs()); + } + + if (clientDisconnectEvent.hasLsentUpTsInUs()) { + clientSessionDetails.setLastTxTimestamp(clientDisconnectEvent.getLsentUpTsInUs()); + } + + if (clientDisconnectEvent.hasInternalRc()) { + clientSessionDetails + .setDisconnectByClientInternalReasonCode(clientDisconnectEvent.getInternalRc()); + } + if (clientDisconnectEvent.hasReason()) { + clientSessionDetails.setDisconnectByClientReasonCode(clientDisconnectEvent.getReason()); + + } + clientSessionDetails.setAssociationState(AssociationState.Disconnected); + + + if (clientSession.getDetails() == null) { + clientSession.setDetails(clientSessionDetails); + } else { + clientSession.getDetails().mergeSession(clientSessionDetails); + } + + clientSession = clientServiceInterface.updateSession(clientSession); + + + } else { + LOG.info("Cannot update client or client session when no client mac address is present"); + } + + } + + if (e.hasClientFailureEvent()) { + + ClientFailureEvent clientFailureEvent = e.getClientFailureEvent(); + + + if (clientFailureEvent.hasStaMac()) { + + com.telecominfraproject.wlan.client.models.Client client = clientServiceInterface + .getOrNull(customerId, new MacAddress(clientFailureEvent.getStaMac())); + if (client == null) { + client = new com.telecominfraproject.wlan.client.models.Client(); + + client.setCustomerId(customerId); + client.setMacAddress(new MacAddress(clientFailureEvent.getStaMac())); + + client.setDetails(new ClientInfoDetails()); + + client = clientServiceInterface.create(client); + + } + + ClientSession clientSession = clientServiceInterface.getSessionOrNull(customerId, equipmentId, + new MacAddress(clientFailureEvent.getStaMac())); + + if (clientSession == null) { + clientSession = new ClientSession(); + } + + clientSession.setCustomerId(customerId); + clientSession.setEquipmentId(equipmentId); + clientSession.setLocationId(locationId); + clientSession.setMacAddress(new MacAddress(clientFailureEvent.getStaMac())); + + + ClientSessionDetails clientSessionDetails = new ClientSessionDetails(); + + if (clientFailureEvent.hasSsid()) { + clientSessionDetails.setSsid(clientFailureEvent.getSsid()); + } + + if (clientFailureEvent.hasSessionId()) { + clientSessionDetails.setSessionId(clientFailureEvent.getSessionId()); + } + ClientFailureDetails clientFailureDetails = new ClientFailureDetails(); + if (clientFailureEvent.hasReasonStr()) { + clientFailureDetails.setReason(clientFailureEvent.getReasonStr()); + } + if (clientFailureEvent.hasReasonCode()) { + clientFailureDetails.setReasonCode(clientFailureEvent.getReasonCode()); + } + clientSessionDetails.setLastFailureDetails(clientFailureDetails); + + if (clientSession.getDetails() == null) { + clientSession.setDetails(clientSessionDetails); + } else { + clientSession.getDetails().mergeSession(clientSessionDetails); + } + + clientSession = clientServiceInterface.updateSession(clientSession); + + } else { + LOG.info("Cannot update client or client session when no client mac address is present"); + } + + } + + if (e.hasClientFirstDataEvent()) { + + + ClientFirstDataEvent clientFirstDataEvent = e.getClientFirstDataEvent(); + + + if (clientFirstDataEvent.hasStaMac()) { + + com.telecominfraproject.wlan.client.models.Client client = clientServiceInterface + .getOrNull(customerId, new MacAddress(clientFirstDataEvent.getStaMac())); + if (client == null) { + client = new com.telecominfraproject.wlan.client.models.Client(); + + client.setCustomerId(customerId); + client.setMacAddress(new MacAddress(clientFirstDataEvent.getStaMac())); + + client.setDetails(new ClientInfoDetails()); + + client = clientServiceInterface.create(client); + + } + + ClientSession clientSession = clientServiceInterface.getSessionOrNull(customerId, equipmentId, + new MacAddress(clientFirstDataEvent.getStaMac())); + + if (clientSession == null) { + clientSession = new ClientSession(); + } + + clientSession.setCustomerId(customerId); + clientSession.setEquipmentId(equipmentId); + clientSession.setLocationId(locationId); + clientSession.setMacAddress(new MacAddress(clientFirstDataEvent.getStaMac())); + + + ClientSessionDetails clientSessionDetails = new ClientSessionDetails(); + + + if (clientFirstDataEvent.hasFdataRxUpTsInUs()) { + clientSessionDetails.setFirstDataRcvdTimestamp(clientFirstDataEvent.getFdataRxUpTsInUs()); + } + + if (clientFirstDataEvent.hasFdataTxUpTsInUs()) { + clientSessionDetails.setFirstDataSentTimestamp(clientFirstDataEvent.getFdataTxUpTsInUs()); + } + + if (clientFirstDataEvent.hasSessionId()) { + clientSessionDetails.setSessionId(clientFirstDataEvent.getSessionId()); + } + clientSessionDetails.setAssociationState(AssociationState.Active_Data); + + if (clientSession.getDetails() == null) { + clientSession.setDetails(clientSessionDetails); + } else { + clientSession.getDetails().mergeSession(clientSessionDetails); + } + + clientSession = clientServiceInterface.updateSession(clientSession); + + } else { + LOG.info("Cannot update client or client session when no client mac address is present"); + } + + + } + + if (e.hasClientIdEvent()) { + + ClientIdEvent clientIdEvent = e.getClientIdEvent(); + + if (clientIdEvent.hasCltMac()) { + + com.telecominfraproject.wlan.client.models.Client client = clientServiceInterface + .getOrNull(customerId, new MacAddress(clientIdEvent.getCltMac())); + if (client == null) { + client = new com.telecominfraproject.wlan.client.models.Client(); + + client.setCustomerId(customerId); + client.setMacAddress(new MacAddress(clientIdEvent.getCltMac())); + + client.setDetails(new ClientInfoDetails()); + + client = clientServiceInterface.create(client); + + } + + ClientSession clientSession = clientServiceInterface.getSessionOrNull(customerId, equipmentId, + new MacAddress(clientIdEvent.getCltMac())); + + if (clientSession == null) { + clientSession = new ClientSession(); + } + + clientSession.setCustomerId(customerId); + clientSession.setEquipmentId(equipmentId); + clientSession.setLocationId(locationId); + clientSession.setMacAddress(new MacAddress(clientIdEvent.getCltMac())); + + + ClientSessionDetails clientSessionDetails = new ClientSessionDetails(); + + if (clientIdEvent.hasSessionId()) { + clientSessionDetails.setSessionId(clientIdEvent.getSessionId()); + } + + if (clientSession.getDetails() == null) { + clientSession.setDetails(clientSessionDetails); + } else { + clientSession.getDetails().mergeSession(clientSessionDetails); + } + + clientSession = clientServiceInterface.updateSession(clientSession); + + } else { + LOG.info("Cannot update client or client session when no client mac address is present"); + } + + + } + + if (e.hasClientIpEvent()) { + + ClientIpEvent clientIpEvent = e.getClientIpEvent(); + + if (clientIpEvent.hasStaMac()) { + + com.telecominfraproject.wlan.client.models.Client client = clientServiceInterface + .getOrNull(customerId, new MacAddress(clientIpEvent.getStaMac())); + if (client == null) { + client = new com.telecominfraproject.wlan.client.models.Client(); + + client.setCustomerId(customerId); + client.setMacAddress(new MacAddress(clientIpEvent.getStaMac())); + + client.setDetails(new ClientInfoDetails()); + + client = clientServiceInterface.create(client); + + } + + ClientSession clientSession = clientServiceInterface.getSessionOrNull(customerId, equipmentId, + new MacAddress(clientIpEvent.getStaMac())); + + if (clientSession == null) { + clientSession = new ClientSession(); + } + + clientSession.setCustomerId(customerId); + clientSession.setEquipmentId(equipmentId); + clientSession.setLocationId(locationId); + clientSession.setMacAddress(new MacAddress(clientIpEvent.getStaMac())); + + ClientSessionDetails clientSessionDetails = new ClientSessionDetails(); + + if (clientIpEvent.hasSessionId()) { + clientSessionDetails.setSessionId(clientIpEvent.getSessionId()); + } + + try { + clientSessionDetails + .setIpAddress(InetAddress.getByAddress(clientIpEvent.getIpAddr().toByteArray())); + } catch (UnknownHostException e1) { + // TODO Auto-generated catch block + e1.printStackTrace(); + } + + if (clientSession.getDetails() == null) { + clientSession.setDetails(clientSessionDetails); + } else { + clientSession.getDetails().mergeSession(clientSessionDetails); + } + + clientSession = clientServiceInterface.updateSession(clientSession); + + } else { + LOG.info("Cannot update client or client session when no client mac address is present"); + } + + + } + + if (e.hasClientTimeoutEvent()) { + + ClientTimeoutEvent clientTimeoutEvent = e.getClientTimeoutEvent(); + + + if (clientTimeoutEvent.hasStaMac()) { + + com.telecominfraproject.wlan.client.models.Client client = clientServiceInterface + .getOrNull(customerId, new MacAddress(clientTimeoutEvent.getStaMac())); + if (client == null) { + client = new com.telecominfraproject.wlan.client.models.Client(); + + client.setCustomerId(customerId); + client.setMacAddress(new MacAddress(clientTimeoutEvent.getStaMac())); + + client.setDetails(new ClientInfoDetails()); + + client = clientServiceInterface.create(client); + + } + + ClientSession clientSession = clientServiceInterface.getSessionOrNull(customerId, equipmentId, + new MacAddress(clientTimeoutEvent.getStaMac())); + + if (clientSession == null) { + clientSession = new ClientSession(); + } + + clientSession.setCustomerId(customerId); + clientSession.setEquipmentId(equipmentId); + clientSession.setLocationId(locationId); + clientSession.setMacAddress(new MacAddress(clientTimeoutEvent.getStaMac())); + + ClientSessionDetails clientSessionDetails = new ClientSessionDetails(); + + if (clientTimeoutEvent.hasSessionId()) { + clientSessionDetails.setSessionId(clientTimeoutEvent.getSessionId()); + } + + if (clientTimeoutEvent.hasLastRcvUpTsInUs()) { + clientSessionDetails.setLastRxTimestamp(clientTimeoutEvent.getLastRcvUpTsInUs()); + } + + if (clientTimeoutEvent.hasLastSentUpTsInUs()) { + clientSessionDetails.setLastTxTimestamp(clientTimeoutEvent.getLastSentUpTsInUs()); + } + + if (clientSession.getDetails() == null) { + clientSession.setDetails(clientSessionDetails); + } else { + clientSession.getDetails().mergeSession(clientSessionDetails); + } + + clientSession = clientServiceInterface.updateSession(clientSession); + + } else { + LOG.info("Cannot update client or client session when no client mac address is present"); + } + + + } + + + }); + + } + + void populateUccReport(List metricRecordList, Report report, int customerId, long equipmentId, + String apId, long locationId) { + + // This feature is used identify the ongoing UCC (Unified Communications + // and Collaboration) technology and Video sessions. + + if (report.getUccReportCount() < 1) { + LOG.debug("No UCC metrics in this message"); + return; + } + + for (UCCReport uccReport : report.getUccReportList()) { + if (uccReport.hasSipCallReport()) { + LOG.debug("SIP Call Report {}", uccReport.getSipCallReport()); + } + } + + + } + + void populateApNodeMetrics(List metricRecordList, Report report, int customerId, long equipmentId, + long locationId) { + LOG.debug("populateApNodeMetrics for Customer {} Equipment {}", customerId, equipmentId); + ApNodeMetrics apNodeMetrics = new ApNodeMetrics(); + ServiceMetric smr = new ServiceMetric(customerId, equipmentId); + + smr.setLocationId(locationId); + + metricRecordList.add(smr); + smr.setDetails(apNodeMetrics); + + for (Device deviceReport : report.getDeviceList()) { + + int avgRadioTemp = 0; + + ApPerformance apPerformance = new ApPerformance(); + apNodeMetrics.setApPerformance(apPerformance); + + smr.setCreatedTimestamp(deviceReport.getTimestampMs()); + + if (deviceReport.getRadioTempCount() > 0) { + float cpuTemperature = 0; + int numSamples = 0; + for (RadioTemp r : deviceReport.getRadioTempList()) { + if (r.hasValue()) { + cpuTemperature += r.getValue(); + numSamples++; + } + } + + if (numSamples > 0) { + avgRadioTemp = Math.round((cpuTemperature / numSamples)); + apPerformance.setCpuTemperature(avgRadioTemp); + } + } + + if (deviceReport.hasCpuUtil() && deviceReport.getCpuUtil().hasCpuUtil()) { + Integer cpuUtilization = deviceReport.getCpuUtil().getCpuUtil(); + apPerformance.setCpuUtilized(new byte[] { cpuUtilization.byteValue() }); + } + + apPerformance.setEthLinkState(EthernetLinkState.UP1000_FULL_DUPLEX); + + if (deviceReport.hasMemUtil() && deviceReport.getMemUtil().hasMemTotal() + && deviceReport.getMemUtil().hasMemUsed()) { + apPerformance.setFreeMemory( + deviceReport.getMemUtil().getMemTotal() - deviceReport.getMemUtil().getMemUsed()); + } + apPerformance.setUpTime((long) deviceReport.getUptime()); + + updateDeviceStatusForReport(customerId, equipmentId, deviceReport, avgRadioTemp); + + } + + // statusList.add(status); + + // Main Network dashboard shows Traffic and Capacity values that + // are calculated from + // ApNodeMetric properties getPeriodLengthSec, getRxBytes2G, + // getTxBytes2G, getRxBytes5G, getTxBytes5G + + // go over all the clients to aggregate per-client tx/rx stats - + // we want to do this + // only once per batch of ApNodeMetrics - so we do not repeat + // values over and over again + + for (ClientReport clReport : report.getClientsList()) { + + long rxBytes = 0; + long txBytes = 0; + + long txFrames = 0; + long rxFrames = 0; + int txRetries = 0; + int rxRetries = 0; + int rxErrors = 0; + int rssi = 0; + Set clientMacs = new HashSet<>(); + + for (Client cl : clReport.getClientListList()) { + + if (!cl.hasConnected() || (cl.getConnected() != true)) { + // this client is not currently connected, skip it + // TODO: how come AP reports disconencted clients? What + // if it is a busy coffe shop with thousands of peopele + // per day, when do clients disappear from the reports? + continue; + } + + if (cl.hasMacAddress()) { + clientMacs.add(cl.getMacAddress()); + } + + if (cl.getStats().hasTxBytes()) { + txBytes += cl.getStats().getTxBytes(); + } + if (cl.getStats().hasRxBytes()) { + rxBytes += cl.getStats().getRxBytes(); + } + if (cl.getStats().hasRssi()) { + rssi = cl.getStats().getRssi(); + } + if (cl.getStats().hasTxFrames()) { + txFrames += cl.getStats().getTxFrames(); + } + if (cl.getStats().hasRxFrames()) { + rxFrames += cl.getStats().getRxFrames(); + } + if (cl.getStats().hasTxRetries()) { + txRetries += cl.getStats().getTxRetries(); + } + if (cl.getStats().hasRxRetries()) { + rxRetries += cl.getStats().getRxRetries(); + } + if (cl.getStats().hasTxErrors()) { + cl.getStats().getTxErrors(); + } + if (cl.getStats().hasRxErrors()) { + rxErrors += cl.getStats().getRxErrors(); + } + if (cl.getStats().hasTxRate()) { + cl.getStats().getTxRate(); + } + if (cl.getStats().hasRxRate()) { + cl.getStats().getRxRate(); + } + + } + + RadioType radioType = getRadioTypeFromOpensyncRadioBand(clReport.getBand()); + RadioStatistics radioStats = apNodeMetrics.getRadioStats(radioType); + if (radioStats == null) { + radioStats = new RadioStatistics(); + } + + radioStats.setNumTxRetryAttemps(txRetries); + radioStats.setNumTxFramesTransmitted(txFrames); + radioStats.setNumTxRetryAttemps(txRetries); + radioStats.setCurChannel(clReport.getChannel()); + if (clReport.getClientListCount() > 0) { + // radioStats.setRxLastRssi(getNegativeSignedIntFromUnsigned(rssi) + // / clReport.getClientListCount()); + radioStats.setRxLastRssi(rssi); + } + radioStats.setRxDataBytes(rxBytes); + radioStats.setNumRxDataFrames(rxFrames); + radioStats.setNumRxErr(rxErrors); + radioStats.setNumRxRetry(rxRetries); + + apNodeMetrics.setRadioStats(radioType, radioStats); + + apNodeMetrics.setRxBytes(radioType, rxBytes); + apNodeMetrics.setTxBytes(radioType, txBytes); + + List clientMacList = new ArrayList<>(); + clientMacs.forEach(macStr -> { + try { + clientMacList.add(new MacAddress(macStr)); + } catch (RuntimeException e) { + LOG.warn("Cannot parse mac address from MQTT ClientReport {} ", macStr); + } + }); + + apNodeMetrics.setClientMacAddresses(radioType, clientMacList); + + // TODO: Radio Utilization will be calculated when the survey is + // enabled + + apNodeMetrics.setRadioUtilization(radioType, new ArrayList()); + + } + + // Status radioUtilizationStatus = + // statusServiceInterface.getOrNull(customerId, equipmentId, + // StatusDataType.RADIO_UTILIZATION); + // + // if (radioUtilizationStatus != null) { + // RadioUtilizationReport radioUtilizationReport = + // (RadioUtilizationReport) radioUtilizationStatus + // .getDetails(); + // } + + apNodeMetrics.setPeriodLengthSec(60); + + // Now try to populate metrics for calculation of radio capacity + // see + // com.telecominfraproject.wlan.metrics.streaming.spark.equipmentreport.CapacityDStreamsConfig.toAggregatedStats(int, + // long, ApNodeMetric data) + // result.stats2g = + // toAggregatedRadioStats(data.getNoiseFloor2G(),data.getRadioUtilization2G()); + // result.stats5g = + // toAggregatedRadioStats(data.getNoiseFloor5G(),data.getRadioUtilization5G()); + // RadioUtilization + // private Integer assocClientTx; + // private Integer unassocClientTx; + // private Integer assocClientRx; + // private Integer unassocClientRx; + // private Integer nonWifi; + // private Integer timestampSeconds; + Map avgNoiseFloor = new HashMap<>(); + new HashMap<>(); + Map capacityDetails = new HashMap<>(); + RadioUtilizationReport radioUtilizationReport = new RadioUtilizationReport(); + + // populate it from report.survey + for (Survey survey : report.getSurveyList()) { + + int oBSS = 0; + int iBSS = 0; + int totalBusy = 0; + int durationMs = 0; + RadioType radioType = RadioType.UNSUPPORTED; + + List noiseList = new ArrayList<>(); + for (SurveySample surveySample : survey.getSurveyListList()) { + if (surveySample.getDurationMs() == 0) { + continue; + } + + iBSS += surveySample.getBusySelf() + surveySample.getBusyTx(); + oBSS += surveySample.getBusyRx(); + totalBusy += surveySample.getBusy(); + durationMs += surveySample.getDurationMs(); + noiseList.add(getNegativeSignedIntFrom8BitUnsigned(surveySample.getNoise())); + RadioUtilization radioUtil = new RadioUtilization(); + radioUtil.setTimestampSeconds((int) ((survey.getTimestampMs() + surveySample.getOffsetMs()) / 1000)); + radioUtil.setAssocClientTx((100 * surveySample.getBusyTx()) / surveySample.getDurationMs()); + radioUtil.setAssocClientRx((100 * surveySample.getBusyRx()) / surveySample.getDurationMs()); + // TODO not totally correct, NonWifi = totalBusy - iBSS - oBSS + radioUtil.setNonWifi( + (100 * (surveySample.getBusy() - surveySample.getBusyTx() - surveySample.getBusyRx())) + / surveySample.getDurationMs()); + + switch (survey.getBand()) { + case BAND2G: + radioType = RadioType.is2dot4GHz; + break; + case BAND5G: + radioType = RadioType.is5GHz; + break; + case BAND5GL: + radioType = RadioType.is5GHzL; + break; + case BAND5GU: + radioType = RadioType.is5GHzU; + break; + } + + if (radioType != RadioType.UNSUPPORTED) { + + if (!apNodeMetrics.getRadioUtilizationPerRadio().containsKey(radioType)) { + List radioUtilizationList = new ArrayList<>(); + radioUtilizationList.add(radioUtil); + apNodeMetrics.getRadioUtilizationPerRadio().put(radioType, radioUtilizationList); + } else { + apNodeMetrics.getRadioUtilizationPerRadio().get(radioType).add(radioUtil); + } + } + } + + if ((survey.getSurveyListCount() > 0) && (radioType != RadioType.UNSUPPORTED)) { + int noiseAvg = (int) Math.round(DecibelUtils.getAverageDecibel(toIntArray(noiseList))); + avgNoiseFloor.put(radioType, noiseAvg); + apNodeMetrics.setNoiseFloor(radioType, noiseAvg); + } + Double totalUtilization = (100D * totalBusy) / durationMs; + Double totalNonWifi = (100D * (totalBusy - iBSS - oBSS)) / durationMs; + + EquipmentCapacityDetails cap = new EquipmentCapacityDetails(); + cap.setUnavailableCapacity(totalNonWifi.intValue()); + int avaiCapacity = 100 - totalNonWifi.intValue(); + cap.setAvailableCapacity(avaiCapacity); + cap.setUsedCapacity(totalUtilization.intValue()); + cap.setUnusedCapacity(avaiCapacity - totalUtilization.intValue()); + cap.setTotalCapacity(100); + + if (radioType != RadioType.UNSUPPORTED) { + apNodeMetrics.setChannelUtilization(radioType, totalUtilization.intValue()); + capacityDetails.put(radioType, cap); + } + } + + new RadioStatistics(); + + populateNetworkProbeMetrics(report, apNodeMetrics); + + radioUtilizationReport.setAvgNoiseFloor(avgNoiseFloor); + radioUtilizationReport.setCapacityDetails(capacityDetails); + + updateDeviceStatusRadioUtilizationReport(customerId, equipmentId, radioUtilizationReport); + } + + void updateDeviceStatusRadioUtilizationReport(int customerId, long equipmentId, + RadioUtilizationReport radioUtilizationReport) { + LOG.debug( + "Processing updateDeviceStatusRadioUtilizationReport for equipmentId {} with RadioUtilizationReport {}", + equipmentId, radioUtilizationReport); + + Status radioUtilizationStatus = statusServiceInterface.getOrNull(customerId, equipmentId, + StatusDataType.RADIO_UTILIZATION); + + if (radioUtilizationStatus == null) { + LOG.debug("Create new radioUtilizationStatus"); + radioUtilizationStatus = new Status(); + radioUtilizationStatus.setCustomerId(customerId); + radioUtilizationStatus.setEquipmentId(equipmentId); + radioUtilizationStatus.setStatusDataType(StatusDataType.RADIO_UTILIZATION); + } + + radioUtilizationStatus.setDetails(radioUtilizationReport); + + statusServiceInterface.update(radioUtilizationStatus); + } + + void populateNetworkProbeMetrics(Report report, ApNodeMetrics apNodeMetrics) { + List networkProbeMetricsList = new ArrayList<>(); + + for (NetworkProbe networkProbe : report.getNetworkProbeList()) { + + NetworkProbeMetrics networkProbeMetrics = new NetworkProbeMetrics(); + + List dnsProbeResults = new ArrayList<>(); + if (networkProbe.hasDnsProbe()) { + + DNSProbeMetric dnsProbeMetricFromAp = networkProbe.getDnsProbe(); + + DnsProbeMetric dnsProbeMetric = new DnsProbeMetric(); + + if (dnsProbeMetricFromAp.hasLatency()) { + networkProbeMetrics.setDnsLatencyMs(dnsProbeMetricFromAp.getLatency()); + dnsProbeMetric.setDnsLatencyMs(dnsProbeMetricFromAp.getLatency()); + } + + if (dnsProbeMetricFromAp.hasState()) { + switch (dnsProbeMetricFromAp.getState()) { + case SUD_down: + networkProbeMetrics.setDnsState(StateUpDownError.disabled); + dnsProbeMetric.setDnsState(StateUpDownError.disabled); + break; + case SUD_up: + networkProbeMetrics.setDnsState(StateUpDownError.enabled); + dnsProbeMetric.setDnsState(StateUpDownError.enabled); + break; + case SUD_error: + networkProbeMetrics.setDnsState(StateUpDownError.error); + dnsProbeMetric.setDnsState(StateUpDownError.error); + break; + default: + networkProbeMetrics.setDnsState(StateUpDownError.UNSUPPORTED); + dnsProbeMetric.setDnsState(StateUpDownError.UNSUPPORTED); + } + } + + if (dnsProbeMetricFromAp.hasServerIP()) { + InetAddress ipAddress; + try { + ipAddress = InetAddress.getByName(dnsProbeMetricFromAp.getServerIP()); + dnsProbeMetric.setDnsServerIp(ipAddress); + + } catch (UnknownHostException e) { + LOG.error("Could not get DNS Server IP from network_probe metrics", e); + } + } + + dnsProbeResults.add(dnsProbeMetric); + + } + + networkProbeMetrics.setDnsProbeResults(dnsProbeResults); + + for (RADIUSMetrics radiusMetrics : networkProbe.getRadiusProbeList()) { + if (networkProbe.hasVlanProbe()) { + if (networkProbe.getVlanProbe().hasObsV200RadiusLatency()) { + networkProbeMetrics.setRadiusLatencyInMs(networkProbe.getVlanProbe().getObsV200RadiusLatency()); + } + if (networkProbe.getVlanProbe().hasObsV200RadiusState()) { + switch (networkProbe.getVlanProbe().getObsV200RadiusState()) { + case SUD_down: + networkProbeMetrics.setRadiusState(StateUpDownError.disabled); + break; + case SUD_up: + networkProbeMetrics.setRadiusState(StateUpDownError.enabled); + break; + case SUD_error: + networkProbeMetrics.setRadiusState(StateUpDownError.error); + break; + default: + networkProbeMetrics.setRadiusState(StateUpDownError.UNSUPPORTED); + } + } + } else { + // take the average if we don't have from the VLAN Probe + if (radiusMetrics.hasLatencyAve()) { + networkProbeMetrics.setRadiusLatencyInMs(radiusMetrics.getLatencyAve()); + } + } + } + if (networkProbe.hasVlanProbe()) { + VLANMetrics vlanMetrics = networkProbe.getVlanProbe(); + + if (vlanMetrics.hasVlanIF()) { + networkProbeMetrics.setVlanIF(vlanMetrics.getVlanIF()); + } + if (vlanMetrics.hasDhcpLatency()) { + networkProbeMetrics.setDhcpLatencyMs(vlanMetrics.getDhcpLatency()); + } + if (vlanMetrics.hasDhcpState()) { + switch (vlanMetrics.getDhcpState()) { + case SUD_down: + networkProbeMetrics.setDhcpState(StateUpDownError.disabled); + break; + case SUD_up: + networkProbeMetrics.setDhcpState(StateUpDownError.enabled); + break; + case SUD_error: + networkProbeMetrics.setDhcpState(StateUpDownError.error); + break; + default: + networkProbeMetrics.setDhcpState(StateUpDownError.UNSUPPORTED); + } + } + + } + + networkProbeMetricsList.add(networkProbeMetrics); + + } + + apNodeMetrics.setNetworkProbeMetrics(networkProbeMetricsList); + } + + void updateDeviceStatusForReport(int customerId, long equipmentId, Device deviceReport, int avgRadioTemp) { + Status status = new Status(); + status.setCustomerId(customerId); + status.setEquipmentId(equipmentId); + OperatingSystemPerformance eqOsPerformance = new OperatingSystemPerformance(); + eqOsPerformance.setUptimeInSeconds(deviceReport.getUptime()); + eqOsPerformance.setAvgCpuTemperature(avgRadioTemp); + eqOsPerformance.setAvgCpuUtilization(deviceReport.getCpuUtil().getCpuUtil()); + eqOsPerformance + .setAvgFreeMemoryKb(deviceReport.getMemUtil().getMemTotal() - deviceReport.getMemUtil().getMemUsed()); + eqOsPerformance.setTotalAvailableMemoryKb(deviceReport.getMemUtil().getMemTotal()); + status.setDetails(eqOsPerformance); + status = statusServiceInterface.update(status); + LOG.debug("updated status {}", status); + } + + void populateApClientMetrics(List metricRecordList, Report report, int customerId, long equipmentId, + long locationId) { + LOG.debug("populateApClientMetrics {} for Customer {} Equipment {}", report.getClientsList(), customerId, + equipmentId); + + for (ClientReport clReport : report.getClientsList()) { + for (Client cl : clReport.getClientListList()) { + + if (cl.getMacAddress() == null) { + LOG.debug( + "No mac address for Client {}, cannot set device mac address for client in ClientMetrics.", + cl); + continue; + } + + LOG.debug("Processing ClientReport from AP {}", cl.getMacAddress()); + + ServiceMetric smr = new ServiceMetric(customerId, equipmentId, new MacAddress(cl.getMacAddress())); + smr.setLocationId(locationId); + metricRecordList.add(smr); + + smr.setCreatedTimestamp(clReport.getTimestampMs()); + smr.setClientMac(new MacAddress(cl.getMacAddress()).getAddressAsLong()); + + // clReport.getChannel(); + ClientMetrics cMetrics = new ClientMetrics(); + smr.setDetails(cMetrics); + + Integer periodLengthSec = 60; // matches what's configured by + // OvsdbDao.configureStats(OvsdbClient) + cMetrics.setPeriodLengthSec(periodLengthSec); + + cMetrics.setRadioType(getRadioTypeFromOpensyncRadioBand(clReport.getBand())); + // we'll report each device as having a single (very long) + // session + long sessionId = WiFiSessionUtility.encodeWiFiAssociationId(clReport.getTimestampMs() / 1000L, + MacAddress.convertMacStringToLongValue(cl.getMacAddress())); + + LOG.debug("populateApClientMetrics Session Id {}", sessionId); + cMetrics.setSessionId(sessionId); + + if (cl.hasStats()) { + if (cl.getStats().hasRssi()) { + int rssi = cl.getStats().getRssi(); + cMetrics.setRssi(rssi); + } + + // populate Rx stats + if (cl.getStats().hasRxBytes()) { + cMetrics.setRxBytes(cl.getStats().getRxBytes()); + } + + if (cl.getStats().hasRxRate()) { + cMetrics.setAverageRxRate(cl.getStats().getRxRate() / 1000); + } + + if (cl.getStats().hasRxErrors()) { + cMetrics.setNumRxNoFcsErr((int) cl.getStats().getRxErrors()); + } + + if (cl.getStats().hasRxFrames()) { + cMetrics.setNumRxFramesReceived(cl.getStats().getRxFrames()); + // cMetrics.setNumRxPackets(cl.getStats().getRxFrames()); + } + + if (cl.getStats().hasRxRetries()) { + cMetrics.setNumRxRetry((int) cl.getStats().getRxRetries()); + } + + // populate Tx stats + if (cl.getStats().hasTxBytes()) { + cMetrics.setNumTxBytes(cl.getStats().getTxBytes()); + } + + if (cl.getStats().hasTxRate()) { + cMetrics.setAverageTxRate(cl.getStats().getTxRate() / 1000); + } + + if (cl.getStats().hasTxRate() && cl.getStats().hasRxRate()) { + cMetrics.setRates(new byte[] { Double.valueOf(cl.getStats().getTxRate() / 1000).byteValue(), + Double.valueOf(cl.getStats().getRxRate() / 1000).byteValue() }); + } + + if (cl.getStats().hasTxErrors()) { + cMetrics.setNumTxDropped((int) cl.getStats().getTxErrors()); + } + + if (cl.getStats().hasRxFrames()) { + cMetrics.setNumTxFramesTransmitted(cl.getStats().getTxFrames()); + } + + if (cl.getStats().hasTxRetries()) { + cMetrics.setNumTxDataRetries((int) cl.getStats().getTxRetries()); + } + } + + LOG.debug("ApClientMetrics Report {}", cMetrics); + + } + + } + + } + + void populateNeighbourScanReports(List metricRecordList, Report report, int customerId, + long equipmentId, long locationId) { + LOG.debug("populateNeighbourScanReports for Customer {} Equipment {}", customerId, equipmentId); + + for (Neighbor neighbor : report.getNeighborsList()) { + + ServiceMetric smr = new ServiceMetric(customerId, equipmentId); + smr.setLocationId(locationId); + + metricRecordList.add(smr); + NeighbourScanReports neighbourScanReports = new NeighbourScanReports(); + smr.setDetails(neighbourScanReports); + smr.setCreatedTimestamp(neighbor.getTimestampMs()); + + List neighbourReports = new ArrayList<>(); + neighbourScanReports.setNeighbourReports(neighbourReports); + + for (NeighborBss nBss : neighbor.getBssListList()) { + NeighbourReport nr = new NeighbourReport(); + neighbourReports.add(nr); + + if (neighbor.getBand() == RadioBandType.BAND2G) { + nr.setAcMode(false); + nr.setbMode(false); + nr.setnMode(true); + nr.setRadioType(RadioType.is2dot4GHz); + } else if (neighbor.getBand() == RadioBandType.BAND5G) { + nr.setAcMode(true); + nr.setbMode(false); + nr.setnMode(false); + nr.setRadioType(RadioType.is5GHz); + } else if (neighbor.getBand() == RadioBandType.BAND5GL) { + nr.setAcMode(true); + nr.setbMode(false); + nr.setnMode(false); + nr.setRadioType(RadioType.is5GHzL); + } else if (neighbor.getBand() == RadioBandType.BAND5GU) { + nr.setAcMode(true); + nr.setbMode(false); + nr.setnMode(false); + nr.setRadioType(RadioType.is5GHzU); + } + + nr.setChannel(nBss.getChannel()); + nr.setMacAddress(new MacAddress(nBss.getBssid())); + nr.setNetworkType(NetworkType.AP); + nr.setPacketType(NeighborScanPacketType.BEACON); + nr.setPrivacy(((nBss.getSsid() == null) || nBss.getSsid().isEmpty()) ? true : false); + // nr.setRate(rate); + // we can only get Rssi as an unsigned int from opensync, so + // some shifting + int rssi = nBss.getRssi(); + nr.setRssi(rssi); + // nr.setScanTimeInSeconds(scanTimeInSeconds); + nr.setSecureMode(DetectedAuthMode.WPA); + // nr.setSignal(signal); + nr.setSsid(nBss.getSsid()); + } + + } + } + + void handleClientSessionMetricsUpdate(int customerId, long equipmentId, long locationId, RadioType radioType, + long timestamp, sts.OpensyncStats.Client client) { + try + + { + LOG.info("handleClientSessionUpdate for customerId {} equipmentId {} locationId {} client {} ", customerId, + equipmentId, locationId, client.getMacAddress()); + + com.telecominfraproject.wlan.client.models.Client clientInstance = clientServiceInterface + .getOrNull(customerId, new MacAddress(client.getMacAddress())); + + boolean isReassociation = true; + if (clientInstance == null) { + clientInstance = new com.telecominfraproject.wlan.client.models.Client(); + clientInstance.setCustomerId(customerId); + clientInstance.setMacAddress(new MacAddress(client.getMacAddress())); + clientInstance.setDetails(new ClientInfoDetails()); + clientInstance = clientServiceInterface.create(clientInstance); + + isReassociation = false; + } + + LOG.info("Client {}", clientInstance); + + ClientSession clientSession = clientServiceInterface.getSessionOrNull(customerId, equipmentId, + clientInstance.getMacAddress()); + + if (clientSession == null) { + + clientSession = new ClientSession(); + clientSession.setCustomerId(customerId); + clientSession.setEquipmentId(equipmentId); + clientSession.setLocationId(locationId); + clientSession.setMacAddress(clientInstance.getMacAddress()); + ClientSessionDetails clientSessionDetails = new ClientSessionDetails(); + clientSessionDetails.setSsid(client.getSsid()); + clientSessionDetails.setRadioType(radioType); + clientSessionDetails.setSessionId(clientInstance.getMacAddress().getAddressAsLong()); + clientSession.setDetails(new ClientSessionDetails()); + clientSession = clientServiceInterface.updateSession(clientSession); + } + + ClientSessionDetails latestClientSessionDetails = clientSession.getDetails(); + latestClientSessionDetails.setIsReassociation(isReassociation); + latestClientSessionDetails.setSsid(client.getSsid()); + latestClientSessionDetails.setRadioType(radioType); + latestClientSessionDetails.setSessionId(clientInstance.getMacAddress().getAddressAsLong()); + latestClientSessionDetails.setLastEventTimestamp(timestamp); + latestClientSessionDetails.setFirstDataSentTimestamp(timestamp - client.getDurationMs()); + latestClientSessionDetails.setFirstDataRcvdTimestamp(timestamp - client.getDurationMs()); + latestClientSessionDetails.setAssociationState(AssociationState.Active_Data); + int rssi = client.getStats().getRssi(); + latestClientSessionDetails.setAssocRssi(rssi); + latestClientSessionDetails.setLastRxTimestamp(timestamp); + latestClientSessionDetails.setLastTxTimestamp(timestamp); + + Equipment ce = equipmentServiceInterface.get(equipmentId); + ProfileContainer profileContainer = new ProfileContainer( + profileServiceInterface.getProfileWithChildren(ce.getProfileId())); + + List ssidConfigList = new ArrayList<>(); + ssidConfigList = profileContainer.getChildrenOfType(ce.getProfileId(), ProfileType.ssid).stream() + .filter(t -> { + + SsidConfiguration ssidConfig = (SsidConfiguration) t.getDetails(); + return ssidConfig.getSsid().equals(client.getSsid()) + && ssidConfig.getAppliedRadios().contains(radioType); + }).collect(Collectors.toList()); + + if (!ssidConfigList.isEmpty()) { + + Profile ssidProfile = ssidConfigList.iterator().next(); + SsidConfiguration ssidConfig = (SsidConfiguration) ssidProfile.getDetails(); + if (ssidConfig.getSecureMode().equals(SecureMode.open)) { + latestClientSessionDetails.setSecurityType(SecurityType.OPEN); + } else if (ssidConfig.getSecureMode().equals(SecureMode.wpaPSK) + || ssidConfig.getSecureMode().equals(SecureMode.wpa2PSK) + || ssidConfig.getSecureMode().equals(SecureMode.wpa2OnlyPSK)) { + latestClientSessionDetails.setSecurityType(SecurityType.PSK); + } else if (ssidConfig.getSecureMode().equals(SecureMode.wpa2Radius) + || ssidConfig.getSecureMode().equals(SecureMode.wpaRadius) + || ssidConfig.getSecureMode().equals(SecureMode.wpa2OnlyRadius)) { + latestClientSessionDetails.setSecurityType(SecurityType.RADIUS); + latestClientSessionDetails.setEapDetails(new ClientEapDetails()); + } else if (ssidConfig.getSecureMode().equals(SecureMode.wpaEAP) + || ssidConfig.getSecureMode().equals(SecureMode.wpa2EAP) + || ssidConfig.getSecureMode().equals(SecureMode.wpa2OnlyEAP)) { + latestClientSessionDetails.setSecurityType(SecurityType.RADIUS); + + latestClientSessionDetails.setEapDetails(new ClientEapDetails()); + } else { + latestClientSessionDetails.setSecurityType(SecurityType.UNSUPPORTED); + } + + if (ssidConfig.getVlanId() > 1) { + latestClientSessionDetails.setDynamicVlan(ssidConfig.getVlanId()); + } + + + RadioBasedSsidConfiguration radioConfig = ssidConfig.getRadioBasedConfigs().get(radioType); + latestClientSessionDetails + .setIs11KUsed(radioConfig.getEnable80211k() != null ? radioConfig.getEnable80211k() : false); + latestClientSessionDetails + .setIs11RUsed(radioConfig.getEnable80211r() != null ? radioConfig.getEnable80211r() : false); + latestClientSessionDetails + .setIs11VUsed(radioConfig.getEnable80211v() != null ? radioConfig.getEnable80211v() : false); + + } + + latestClientSessionDetails.setMetricDetails(calculateClientSessionMetricDetails(client, timestamp)); + + clientSession.getDetails().mergeSession(latestClientSessionDetails); + clientSession.setLastModifiedTimestamp(timestamp); + + clientSession = clientServiceInterface.updateSession(clientSession); + + LOG.debug("Updated client session {}", clientSession); + + } catch (Exception e) { + LOG.error("Error while attempting to create ClientSession and Info", e); + } + } + + ClientSessionMetricDetails calculateClientSessionMetricDetails(sts.OpensyncStats.Client client, long timestamp) { + + LOG.debug("calculateClientSessionMetricDetails for Client {} at timestamp {}", client.getMacAddress(), + timestamp); + + ClientSessionMetricDetails metricDetails = new ClientSessionMetricDetails(); + + int rssi = client.getStats().getRssi(); + metricDetails.setRssi(rssi); + metricDetails.setRxBytes(client.getStats().getRxBytes()); + metricDetails.setTxBytes(client.getStats().getTxBytes()); + metricDetails.setTotalTxPackets(client.getStats().getTxFrames()); + metricDetails.setTotalRxPackets(client.getStats().getRxFrames()); + metricDetails.setTxDataFrames((int) client.getStats().getTxFrames()); + metricDetails.setRxDataFrames((int) client.getStats().getRxFrames()); + // values reported in Kbps, convert to Mbps + metricDetails.setRxMbps((float) (client.getStats().getRxRate() / 1000)); + metricDetails.setTxMbps((float) (client.getStats().getTxRate() / 1000)); + // Throughput, do rate / duration + if (client.getDurationMs() > 0) { + metricDetails.setRxRateKbps((long) client.getStats().getRxRate() / client.getDurationMs()); + metricDetails.setTxRateKbps((long) client.getStats().getTxRate() / client.getDurationMs()); + } else { + LOG.info("Cannot calculate tx/rx throughput for Client {} based on duration of {} Ms", + client.getMacAddress(), client.getDurationMs()); + } + metricDetails.setLastMetricTimestamp(timestamp); + + return metricDetails; + } + + void populateApSsidMetrics(List metricRecordList, Report report, int customerId, long equipmentId, + String apId, long locationId) { + + LOG.debug("populateApSsidMetrics for Customer {} Equipment {}", customerId, equipmentId); + ServiceMetric smr = new ServiceMetric(customerId, equipmentId); + smr.setLocationId(locationId); + ApSsidMetrics apSsidMetrics = new ApSsidMetrics(); + + + smr.setDetails(apSsidMetrics); + metricRecordList.add(smr); + + + for (ClientReport clientReport : report.getClientsList()) { + + LOG.debug("ClientReport for channel {} RadioBand {}", clientReport.getChannel(), clientReport.getBand()); + + if (smr.getCreatedTimestamp() < clientReport.getTimestampMs()) { + smr.setCreatedTimestamp(clientReport.getTimestampMs()); + } + + long txBytes = 0L; + long rxBytes = 0L; + long txFrames = 0L; + long rxFrames = 0L; + + int txErrors = 0; + int rxErrors = 0; + + int txRetries = 0; + int rxRetries = 0; + + int lastRssi = 0; + String ssid = null; + + Set clientMacs = new HashSet<>(); + + RadioType radioType = getRadioTypeFromOpensyncRadioBand(clientReport.getBand()); + + SsidStatistics ssidStatistics = new SsidStatistics(); + // GET the Radio IF MAC (BSSID) from the activeBSSIDs + + Status activeBssidsStatus = statusServiceInterface.getOrNull(customerId, equipmentId, + StatusDataType.ACTIVE_BSSIDS); + ActiveBSSIDs statusDetails = null; + if (activeBssidsStatus != null) { + statusDetails = (ActiveBSSIDs) activeBssidsStatus.getDetails(); + for (ActiveBSSID activeBSSID : ((ActiveBSSIDs) activeBssidsStatus.getDetails()).getActiveBSSIDs()) { + if (activeBSSID.getRadioType().equals(radioType)) { + ssidStatistics.setBssid(new MacAddress(activeBSSID.getBssid())); + // ssid value, in case not in stats, else will take + // stats value after + ssid = activeBSSID.getSsid(); + statusDetails.getActiveBSSIDs().indexOf(activeBSSID); + } + } + } + LOG.debug("Client Report Date is {}", new Date(clientReport.getTimestampMs())); + int numConnectedClients = 0; + for (Client client : clientReport.getClientListList()) { + if (client.hasStats()) { + + + if (client.hasSsid()) { + ssid = client.getSsid(); + } + + if (client.hasMacAddress()) { + clientMacs.add(client.getMacAddress()); + + } else { + continue; // cannot have a session without a MAC address + } + + rxBytes += client.getStats().getRxBytes(); + txBytes += client.getStats().getTxBytes(); + txFrames += client.getStats().getRxFrames(); + rxFrames += client.getStats().getTxFrames(); + rxRetries += client.getStats().getRxRetries(); + txRetries += client.getStats().getTxRetries(); + rxErrors += client.getStats().getRxErrors(); + txErrors += client.getStats().getTxErrors(); + lastRssi = client.getStats().getRssi(); + + try { + + if (client.hasConnected() && client.getConnected() && client.hasMacAddress()) { + // update metrics for connected client + numConnectedClients += 1; + handleClientSessionMetricsUpdate(customerId, equipmentId, locationId, radioType, + clientReport.getTimestampMs(), client); + } else { + // Make sure, if we have a session for this client, + // it + // shows disconnected. + // update any metrics that need update if the + // disconnect occured during this window + if (client.hasMacAddress()) { + ClientSession session = clientServiceInterface.getSessionOrNull(customerId, equipmentId, + new MacAddress(client.getMacAddress())); + + if (session != null) { + if ((session.getDetails().getAssociationState() != null) && !session.getDetails() + .getAssociationState().equals(AssociationState.Disconnected)) { + + ClientSessionDetails latestSessionDetails = new ClientSessionDetails(); + latestSessionDetails.setAssociationState(AssociationState.Disconnected); + latestSessionDetails.setLastEventTimestamp(clientReport.getTimestampMs()); + latestSessionDetails + .setDisconnectByClientTimestamp(client.hasDisconnectOffsetMs() + ? clientReport.getTimestampMs() - client.getDisconnectOffsetMs() + : clientReport.getTimestampMs()); + if (client.hasSsid()) { + latestSessionDetails.setSsid(client.getSsid()); + } + + // could still be values from before + // disconnect occured. + latestSessionDetails.setMetricDetails(calculateClientSessionMetricDetails( + client, clientReport.getTimestampMs())); + + session.getDetails().mergeSession(latestSessionDetails); + + clientServiceInterface.updateSession(session); + + } + } + + } + + continue; // not connected + } + + + } catch (Exception e) { + LOG.debug("Unabled to update client {} session {}", client, e); + } + + } + + } + + // 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); + ssidStatistics.setNumTxDataRetries(txRetries); + ssidStatistics.setNumRcvFrameForTx(txFrames); + ssidStatistics.setNumTxBytesSucc(txBytes - txErrors - txRetries); + ssidStatistics.setNumRxRetry(rxRetries); + ssidStatistics.setNumClient(numConnectedClients); + ssidStatistics.setSsid(ssid); + + if (radioType != null) { + List ssidStatsList = apSsidMetrics.getSsidStats().get(radioType); + if (ssidStatsList == null) { + ssidStatsList = new ArrayList<>(); + } + ssidStatsList.add(ssidStatistics); + apSsidMetrics.getSsidStats().put(radioType, ssidStatsList); + } + + } + + LOG.debug("ApSsidMetrics {}", apSsidMetrics); + + } + + ChannelInfo createChannelInfo(long equipmentId, RadioType radioType, List surveySampleList, + ChannelBandwidth channelBandwidth) { + int busyTx = 0; /* Tx */ + int busySelf = 0; /* Rx_self (derived from succesful Rx frames) */ + int busy = 0; /* Busy = Rx + Tx + Interference */ + ChannelInfo channelInfo = new ChannelInfo(); + + int[] noiseArray = new int[surveySampleList.size()]; + int index = 0; + for (SurveySample sample : surveySampleList) { + LOG.debug("createChannelInfo::SurveySample {}", sample); + busyTx += sample.getBusyTx(); + busySelf += sample.getBusySelf(); + busy += sample.getBusy(); + channelInfo.setChanNumber(sample.getChannel()); + noiseArray[index++] = getNegativeSignedIntFrom8BitUnsigned(sample.getNoise()); + } + + int iBSS = busyTx + busySelf; + + int totalWifi = busy - iBSS; + + channelInfo.setTotalUtilization(busy); + channelInfo.setWifiUtilization(totalWifi); + channelInfo.setBandwidth(channelBandwidth); + if (surveySampleList.size() > 0) { + channelInfo.setNoiseFloor((int) Math.round(DecibelUtils.getAverageDecibel(noiseArray))); + } + return channelInfo; + } + + void populateChannelInfoReports(List metricRecordList, Report report, int customerId, + long equipmentId, long locationId) { + + LOG.debug("populateChannelInfoReports for Customer {} Equipment {}", customerId, equipmentId); + + for (Survey survey : report.getSurveyList()) { + + ServiceMetric smr = new ServiceMetric(); + smr.setCustomerId(customerId); + smr.setEquipmentId(equipmentId); + smr.setLocationId(locationId); + + ChannelInfoReports channelInfoReports = new ChannelInfoReports(); + Map> channelInfoMap = channelInfoReports + .getChannelInformationReportsPerRadio(); + + RadioType radioType = null; + + if (survey.hasBand()) { + radioType = getRadioTypeFromOpensyncRadioBand(survey.getBand()); + } else { + continue; + } + + + ChannelBandwidth channelBandwidth = ((ApElementConfiguration) equipmentServiceInterface.get(equipmentId) + .getDetails()).getRadioMap().get(radioType).getChannelBandwidth(); + + Map> sampleByChannelMap = new HashMap<>(); + + survey.getSurveyListList().stream().filter(t -> { + if (survey.getSurveyType().equals(SurveyType.ON_CHANNEL)) { + return t.hasDurationMs() && (t.getDurationMs() > 0) && t.hasChannel() && t.hasBusy() + && t.hasBusyTx() && t.hasNoise(); + } else { + return t.hasDurationMs() && t.hasChannel(); + } + }).forEach(s -> { + List surveySampleList; + if (sampleByChannelMap.get(s.getChannel()) == null) { + surveySampleList = new ArrayList<>(); + } else { + surveySampleList = sampleByChannelMap.get(s.getChannel()); + } + surveySampleList.add(s); + sampleByChannelMap.put(s.getChannel(), surveySampleList); + }); + + for (List surveySampleList : sampleByChannelMap.values()) { + ChannelInfo channelInfo = createChannelInfo(equipmentId, radioType, surveySampleList, channelBandwidth); + List channelInfoList = channelInfoReports.getRadioInfo(radioType); + if (channelInfoList == null) { + channelInfoList = new ArrayList<>(); + } + channelInfoList.add(channelInfo); + channelInfoMap.put(radioType, channelInfoList); + channelInfoReports.setChannelInformationReportsPerRadio(channelInfoMap); + } + + + channelInfoReports.setChannelInformationReportsPerRadio(channelInfoMap); + smr.setDetails(channelInfoReports); + smr.setCreatedTimestamp(survey.getTimestampMs()); + metricRecordList.add(smr); + + LOG.debug("ChannelInfoReports {}", channelInfoReports); + + } + + + } + + RadioType getRadioTypeFromOpensyncRadioBand(RadioBandType band) { + RadioType radioType = null; + switch (band) { + case BAND2G: + radioType = RadioType.is2dot4GHz; + break; + case BAND5G: + radioType = RadioType.is5GHz; + break; + case BAND5GU: + radioType = RadioType.is5GHzU; + break; + case BAND5GL: + radioType = RadioType.is5GHzL; + break; + default: + radioType = RadioType.UNSUPPORTED; + } + return radioType; + } + + int getNegativeSignedIntFrom8BitUnsigned(int unsignedValue) { + byte b = (byte) Integer.parseInt(Integer.toHexString(unsignedValue), 16); + return b; + } + + /** + * @param topic + * @return apId extracted from the topic name, or null if it cannot be + * extracted + */ + static String extractApIdFromTopic(String topic) { + // Topic is formatted as + // "/ap/"+clientCn+"_"+ret.serialNumber+"/opensync" + if (topic == null) { + return null; + } + + String[] parts = topic.split("/"); + if (parts.length < 3) { + return null; + } + + // apId is the third element in the topic + return parts[2]; + } + + /** + * @param topic + * @return customerId looked up from the topic name, or -1 if it cannot be + * extracted + */ + int extractCustomerIdFromTopic(String topic) { + + String apId = extractApIdFromTopic(topic); + if (apId == null) { + return -1; + } + + OvsdbSession ovsdbSession = ovsdbSessionMapInterface.getSession(apId); + + if (ovsdbSession != null) { + return ovsdbSession.getCustomerId(); + } + + return -1; + + } + + long extractEquipmentIdFromTopic(String topic) { + + String apId = extractApIdFromTopic(topic); + if (apId == null) { + return -1; + } + + OvsdbSession ovsdbSession = ovsdbSessionMapInterface.getSession(apId); + + if (ovsdbSession != null) { + return ovsdbSession.getEquipmentId(); + } + + return -1; + + } + + static int[] toIntArray(List values) { + if (values != null) { + int returnValue[] = new int[values.size()]; + int index = 0; + + for (Integer value : values) { + returnValue[index++] = value; + } + + return returnValue; + } + return null; + } + +} 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 1f3b216..8802691 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 @@ -4,8 +4,6 @@ import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; import static org.junit.jupiter.api.Assertions.assertEquals; -import java.math.BigInteger; -import java.net.InetAddress; import java.util.ArrayList; import java.util.HashMap; import java.util.List; @@ -18,6 +16,7 @@ import org.junit.Ignore; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.Answers; +import org.mockito.ArgumentMatchers; import org.mockito.Mockito; import org.mockito.MockitoSession; import org.mockito.quality.Strictness; @@ -70,8 +69,6 @@ import com.telecominfraproject.wlan.profile.models.Profile; import com.telecominfraproject.wlan.profile.network.models.ApNetworkConfiguration; import com.telecominfraproject.wlan.profile.ssid.models.SsidConfiguration; import com.telecominfraproject.wlan.routing.RoutingServiceInterface; -import com.telecominfraproject.wlan.servicemetric.apnode.models.ApNodeMetrics; -import com.telecominfraproject.wlan.servicemetric.apnode.models.StateUpDownError; import com.telecominfraproject.wlan.status.StatusServiceInterface; import com.telecominfraproject.wlan.status.equipment.models.EquipmentProtocolStatusData; import com.telecominfraproject.wlan.status.equipment.models.EquipmentUpgradeStatusData; @@ -85,15 +82,10 @@ import com.vmware.ovsdb.protocol.operation.notation.Uuid; import sts.OpensyncStats.AssocType; import sts.OpensyncStats.Client; import sts.OpensyncStats.ClientReport; -import sts.OpensyncStats.DNSProbeMetric; import sts.OpensyncStats.EventReport; import sts.OpensyncStats.EventType; -import sts.OpensyncStats.NetworkProbe; -import sts.OpensyncStats.RADIUSMetrics; import sts.OpensyncStats.RadioBandType; import sts.OpensyncStats.Report; -import sts.OpensyncStats.StateUpDown; -import sts.OpensyncStats.VLANMetrics; @RunWith(SpringRunner.class) @ActiveProfiles(profiles = { "integration_test", }) @@ -128,14 +120,18 @@ public class OpensyncExternalIntegrationCloudTest { FirmwareServiceInterface firmwareServiceInterface; @MockBean(answer = Answers.RETURNS_MOCKS) OpensyncCloudGatewayController gatewayController; + @MockBean + OpensyncExternalIntegrationMqttMessageProcessor opensyncExternalIntegrationMqttProcessor; @Autowired OpensyncExternalIntegrationCloud opensyncExternalIntegrationCloud; + MockitoSession mockito; @Configuration static class Config { + @Bean public OpensyncExternalIntegrationCloud opensyncExternalIntegrationCloud() { return new OpensyncExternalIntegrationCloud(); @@ -167,7 +163,8 @@ public class OpensyncExternalIntegrationCloudTest { Equipment equipment = new Equipment(); equipment.setDetails(ApElementConfiguration.createWithDefaults()); - Mockito.when(equipmentServiceInterface.getByInventoryIdOrNull(Mockito.eq("Test_Client_21P10C68818122"))) + Mockito.when( + equipmentServiceInterface.getByInventoryIdOrNull(ArgumentMatchers.eq("Test_Client_21P10C68818122"))) .thenReturn(equipment); assertNotNull(opensyncExternalIntegrationCloud.getCustomerEquipment("Test_Client_21P10C68818122")); assertNull(opensyncExternalIntegrationCloud.getCustomerEquipment("Test_Client_21P10C68818133")); @@ -193,7 +190,7 @@ public class OpensyncExternalIntegrationCloudTest { customer.setDetails(customerDetails); - Mockito.when(customerServiceInterface.getOrNull(Mockito.anyInt())).thenReturn(customer); + Mockito.when(customerServiceInterface.getOrNull(ArgumentMatchers.anyInt())).thenReturn(customer); Profile apProfile = new Profile(); apProfile.setDetails(ApNetworkConfiguration.createWithDefaults()); @@ -202,14 +199,16 @@ public class OpensyncExternalIntegrationCloudTest { ssidProfile.setDetails(SsidConfiguration.createWithDefaults()); apProfile.setChildProfileIds(ImmutableSet.of(ssidProfile.getId())); - Mockito.when(profileServiceInterface.create(Mockito.any(Profile.class))).thenAnswer(i -> i.getArguments()[0]); + Mockito.when(profileServiceInterface.create(ArgumentMatchers.any(Profile.class))) + .thenAnswer(i -> i.getArguments()[0]); // .thenReturn(ssidProfile); - Mockito.when(profileServiceInterface.update(Mockito.any(Profile.class))).thenAnswer(i -> i.getArguments()[0]); + Mockito.when(profileServiceInterface.update(ArgumentMatchers.any(Profile.class))) + .thenAnswer(i -> i.getArguments()[0]); Status fwStatus = new Status(); fwStatus.setDetails(new EquipmentUpgradeStatusData()); - Mockito.when(statusServiceInterface.getOrNull(Mockito.anyInt(), Mockito.anyLong(), - Mockito.eq(StatusDataType.FIRMWARE))).thenReturn(fwStatus); + Mockito.when(statusServiceInterface.getOrNull(ArgumentMatchers.anyInt(), ArgumentMatchers.anyLong(), + ArgumentMatchers.eq(StatusDataType.FIRMWARE))).thenReturn(fwStatus); Mockito.when(firmwareServiceInterface.getDefaultCustomerTrackSetting()) .thenReturn(new CustomerFirmwareTrackSettings()); @@ -217,7 +216,7 @@ public class OpensyncExternalIntegrationCloudTest { fwTrackRecord.setSettings(new CustomerFirmwareTrackSettings()); fwTrackRecord.setTrackRecordId(3); fwTrackRecord.setCustomerId(2); - Mockito.when(firmwareServiceInterface.getCustomerFirmwareTrackRecord(Mockito.anyInt())) + Mockito.when(firmwareServiceInterface.getCustomerFirmwareTrackRecord(ArgumentMatchers.anyInt())) .thenReturn(fwTrackRecord); Equipment equipment = new Equipment(); @@ -230,12 +229,13 @@ public class OpensyncExternalIntegrationCloudTest { equipment.setDetails(ApElementConfiguration.createWithDefaults()); Mockito.when(equipmentServiceInterface.get(1L)).thenReturn(equipment); - Mockito.when(equipmentServiceInterface.getByInventoryIdOrNull(Mockito.eq("Test_Client_21P10C68818122"))) + Mockito.when( + equipmentServiceInterface.getByInventoryIdOrNull(ArgumentMatchers.eq("Test_Client_21P10C68818122"))) .thenReturn(equipment); - Mockito.when(equipmentServiceInterface.create(Mockito.any(Equipment.class))) + Mockito.when(equipmentServiceInterface.create(ArgumentMatchers.any(Equipment.class))) .thenAnswer(i -> i.getArguments()[0]); - Mockito.when(equipmentServiceInterface.update(Mockito.any(Equipment.class))) + Mockito.when(equipmentServiceInterface.update(ArgumentMatchers.any(Equipment.class))) .thenAnswer(i -> i.getArguments()[0]); OvsdbSession session = Mockito.mock(OvsdbSession.class); @@ -270,7 +270,7 @@ public class OpensyncExternalIntegrationCloudTest { customer.setDetails(customerDetails); - Mockito.when(customerServiceInterface.getOrNull(Mockito.anyInt())).thenReturn(customer); + Mockito.when(customerServiceInterface.getOrNull(ArgumentMatchers.anyInt())).thenReturn(customer); Profile apProfile = new Profile(); apProfile.setDetails(ApNetworkConfiguration.createWithDefaults()); @@ -280,9 +280,9 @@ public class OpensyncExternalIntegrationCloudTest { apProfile.setChildProfileIds(ImmutableSet.of(ssidProfile.getId())); - Mockito.when(profileServiceInterface.create(Mockito.any(Profile.class))).thenReturn(apProfile) + Mockito.when(profileServiceInterface.create(ArgumentMatchers.any(Profile.class))).thenReturn(apProfile) .thenReturn(ssidProfile); - Mockito.when(profileServiceInterface.update(Mockito.any(Profile.class))).thenReturn(apProfile); + Mockito.when(profileServiceInterface.update(ArgumentMatchers.any(Profile.class))).thenReturn(apProfile); Equipment equipment = new Equipment(); equipment.setCustomerId(2); @@ -295,17 +295,18 @@ public class OpensyncExternalIntegrationCloudTest { Mockito.when(equipmentServiceInterface.get(1L)).thenReturn(equipment); - Mockito.when(equipmentServiceInterface.create(Mockito.any(Equipment.class))) + Mockito.when(equipmentServiceInterface.create(ArgumentMatchers.any(Equipment.class))) .thenAnswer(i -> i.getArguments()[0]); - Mockito.when(equipmentServiceInterface.update(Mockito.any(Equipment.class))) + Mockito.when(equipmentServiceInterface.update(ArgumentMatchers.any(Equipment.class))) .thenAnswer(i -> i.getArguments()[0]); - Mockito.when(equipmentServiceInterface.getByInventoryIdOrNull(Mockito.eq("Test_Client_21P10C68818122"))) + Mockito.when( + equipmentServiceInterface.getByInventoryIdOrNull(ArgumentMatchers.eq("Test_Client_21P10C68818122"))) .thenReturn(null); Status fwStatus = new Status(); fwStatus.setDetails(new EquipmentUpgradeStatusData()); - Mockito.when(statusServiceInterface.getOrNull(Mockito.anyInt(), Mockito.anyLong(), - Mockito.eq(StatusDataType.FIRMWARE))).thenReturn(fwStatus); + Mockito.when(statusServiceInterface.getOrNull(ArgumentMatchers.anyInt(), ArgumentMatchers.anyLong(), + ArgumentMatchers.eq(StatusDataType.FIRMWARE))).thenReturn(fwStatus); Mockito.when(firmwareServiceInterface.getDefaultCustomerTrackSetting()) .thenReturn(new CustomerFirmwareTrackSettings()); @@ -313,7 +314,7 @@ public class OpensyncExternalIntegrationCloudTest { fwTrackRecord.setSettings(new CustomerFirmwareTrackSettings()); fwTrackRecord.setTrackRecordId(3); fwTrackRecord.setCustomerId(2); - Mockito.when(firmwareServiceInterface.getCustomerFirmwareTrackRecord(Mockito.anyInt())) + Mockito.when(firmwareServiceInterface.getCustomerFirmwareTrackRecord(ArgumentMatchers.anyInt())) .thenReturn(fwTrackRecord); OvsdbSession session = Mockito.mock(OvsdbSession.class); @@ -323,10 +324,10 @@ public class OpensyncExternalIntegrationCloudTest { // Mockito.when(locationServiceInterface.get(Mockito.anyLong())).thenReturn(value); opensyncExternalIntegrationCloud.apConnected("Test_Client_21P10C68818122", createConnectNodeInfo()); - Mockito.verify(customerServiceInterface).getOrNull(Mockito.anyInt()); + Mockito.verify(customerServiceInterface).getOrNull(ArgumentMatchers.anyInt()); Mockito.verify(equipmentServiceInterface).getByInventoryIdOrNull("Test_Client_21P10C68818122"); Mockito.verify(firmwareServiceInterface).getDefaultCustomerTrackSetting(); - Mockito.verify(locationServiceInterface).get(Mockito.anyLong()); + Mockito.verify(locationServiceInterface).get(ArgumentMatchers.anyLong()); } @@ -339,9 +340,11 @@ public class OpensyncExternalIntegrationCloudTest { ssidProfile.setDetails(SsidConfiguration.createWithDefaults()); apProfile.setChildProfileIds(ImmutableSet.of(ssidProfile.getId())); - Mockito.when(profileServiceInterface.create(Mockito.any(Profile.class))).thenAnswer(i -> i.getArguments()[0]); + Mockito.when(profileServiceInterface.create(ArgumentMatchers.any(Profile.class))) + .thenAnswer(i -> i.getArguments()[0]); // .thenReturn(ssidProfile); - Mockito.when(profileServiceInterface.update(Mockito.any(Profile.class))).thenAnswer(i -> i.getArguments()[0]); + Mockito.when(profileServiceInterface.update(ArgumentMatchers.any(Profile.class))) + .thenAnswer(i -> i.getArguments()[0]); Location location = new Location(); location.setId(8L); @@ -349,7 +352,7 @@ public class OpensyncExternalIntegrationCloudTest { location.setDetails(LocationDetails.createWithDefaults()); location.setName("Location-UT"); location.setLocationType(LocationType.BUILDING); - + Equipment equipment = new Equipment(); equipment.setCustomerId(2); equipment.setEquipmentType(EquipmentType.AP); @@ -360,8 +363,8 @@ public class OpensyncExternalIntegrationCloudTest { equipment.setDetails(ApElementConfiguration.createWithDefaults()); Status fwStatus = new Status(); fwStatus.setDetails(new EquipmentUpgradeStatusData()); - Mockito.when(statusServiceInterface.getOrNull(Mockito.anyInt(), Mockito.anyLong(), - Mockito.eq(StatusDataType.FIRMWARE))).thenReturn(fwStatus); + Mockito.when(statusServiceInterface.getOrNull(ArgumentMatchers.anyInt(), ArgumentMatchers.anyLong(), + ArgumentMatchers.eq(StatusDataType.FIRMWARE))).thenReturn(fwStatus); Mockito.when(firmwareServiceInterface.getDefaultCustomerTrackSetting()) .thenReturn(new CustomerFirmwareTrackSettings()); @@ -369,17 +372,18 @@ public class OpensyncExternalIntegrationCloudTest { fwTrackRecord.setSettings(new CustomerFirmwareTrackSettings()); fwTrackRecord.setTrackRecordId(3); fwTrackRecord.setCustomerId(2); - Mockito.when(firmwareServiceInterface.getCustomerFirmwareTrackRecord(Mockito.anyInt())) + Mockito.when(firmwareServiceInterface.getCustomerFirmwareTrackRecord(ArgumentMatchers.anyInt())) .thenReturn(fwTrackRecord); Mockito.when(equipmentServiceInterface.get(1L)).thenReturn(equipment); - Mockito.when(equipmentServiceInterface.create(Mockito.any(Equipment.class))) + Mockito.when(equipmentServiceInterface.create(ArgumentMatchers.any(Equipment.class))) .thenAnswer(i -> i.getArguments()[0]); - Mockito.when(equipmentServiceInterface.update(Mockito.any(Equipment.class))) + Mockito.when(equipmentServiceInterface.update(ArgumentMatchers.any(Equipment.class))) .thenAnswer(i -> i.getArguments()[0]); - Mockito.when(equipmentServiceInterface.getByInventoryIdOrNull(Mockito.eq("Test_Client_21P10C68818122"))) + Mockito.when( + equipmentServiceInterface.getByInventoryIdOrNull(ArgumentMatchers.eq("Test_Client_21P10C68818122"))) .thenReturn(equipment); - + Customer customer = new Customer(); customer.setId(2); CustomerDetails customerDetails = new CustomerDetails(); @@ -388,7 +392,7 @@ public class OpensyncExternalIntegrationCloudTest { customerDetails.setAutoProvisioning(autoprovSettings); customer.setDetails(customerDetails); - Mockito.when(customerServiceInterface.getOrNull(Mockito.anyInt())).thenReturn(customer); + Mockito.when(customerServiceInterface.getOrNull(ArgumentMatchers.anyInt())).thenReturn(customer); opensyncExternalIntegrationCloud.apConnected("Test_Client_21P10C68818122", createConnectNodeInfo()); @@ -410,12 +414,12 @@ public class OpensyncExternalIntegrationCloudTest { customerDetails.setAutoProvisioning(autoprovSettings); customer.setDetails(customerDetails); - Mockito.when(customerServiceInterface.getOrNull(Mockito.anyInt())).thenReturn(customer); + Mockito.when(customerServiceInterface.getOrNull(ArgumentMatchers.anyInt())).thenReturn(customer); Equipment equipment = new Equipment(); equipment.setDetails(ApElementConfiguration.createWithDefaults()); - Mockito.when(equipmentServiceInterface.getByInventoryIdOrNull(Mockito.any())).thenReturn(equipment); + Mockito.when(equipmentServiceInterface.getByInventoryIdOrNull(ArgumentMatchers.any())).thenReturn(equipment); Profile apProfile = new Profile(); apProfile.setDetails(ApNetworkConfiguration.createWithDefaults()); @@ -424,7 +428,8 @@ public class OpensyncExternalIntegrationCloudTest { ssidProfile.setDetails(SsidConfiguration.createWithDefaults()); List profileWithChildren = ImmutableList.of(apProfile, ssidProfile); - Mockito.when(profileServiceInterface.getProfileWithChildren(Mockito.anyLong())).thenReturn(profileWithChildren); + Mockito.when(profileServiceInterface.getProfileWithChildren(ArgumentMatchers.anyLong())) + .thenReturn(profileWithChildren); assertNotNull(opensyncExternalIntegrationCloud.getApConfig("Test_Client_21P10C68818122")); @@ -441,7 +446,7 @@ public class OpensyncExternalIntegrationCloudTest { customerDetails.setAutoProvisioning(autoprovSettings); customer.setDetails(customerDetails); - Mockito.when(customerServiceInterface.getOrNull(Mockito.anyInt())).thenReturn(customer); + Mockito.when(customerServiceInterface.getOrNull(ArgumentMatchers.anyInt())).thenReturn(customer); assertNull(opensyncExternalIntegrationCloud.getApConfig("Test_Client_21P10C68818122")); @@ -452,31 +457,8 @@ public class OpensyncExternalIntegrationCloudTest { String topic = "/ap/Test_Client_21P10C68818122/opensync"; - assertEquals("Test_Client_21P10C68818122", OpensyncExternalIntegrationCloud.extractApIdFromTopic(topic)); - - } - - @Test - public void testExtractCustomerIdFromTopic() { - String topic = "/ap/Test_Client_21P10C68818122/opensync"; - OvsdbSession session = Mockito.mock(OvsdbSession.class); - Mockito.when(session.getCustomerId()).thenReturn(2); - - Mockito.when(ovsdbSessionMapInterface.getSession("Test_Client_21P10C68818122")).thenReturn(session); - - assertEquals(2, opensyncExternalIntegrationCloud.extractCustomerIdFromTopic(topic)); - } - - @Test - public void testExtractEquipmentIdFromTopic() { - - String topic = "/ap/Test_Client_21P10C68818122/opensync"; - OvsdbSession session = Mockito.mock(OvsdbSession.class); - Mockito.when(session.getEquipmentId()).thenReturn(1L); - - Mockito.when(ovsdbSessionMapInterface.getSession("Test_Client_21P10C68818122")).thenReturn(session); - - assertEquals(1L, opensyncExternalIntegrationCloud.extractEquipmentIdFromTopic(topic)); + assertEquals("Test_Client_21P10C68818122", + OpensyncExternalIntegrationMqttMessageProcessor.extractApIdFromTopic(topic)); } @@ -484,16 +466,11 @@ public class OpensyncExternalIntegrationCloudTest { public void testProcessMqttMessageStringReport() { Report report = Report.newBuilder().setNodeID("21P10C68818122") - .addAllClients(getOpensyncStatsClientReportsList()).addAllEventReport(getOpensyncStatsEventReportsList()).build(); + .addAllClients(getOpensyncStatsClientReportsList()) + .addAllEventReport(getOpensyncStatsEventReportsList()).build(); String topic = "/ap/Test_Client_21P10C68818122/opensync"; - OvsdbSession session = Mockito.mock(OvsdbSession.class); - Mockito.when(session.getEquipmentId()).thenReturn(1L); - Mockito.when(session.getCustomerId()).thenReturn(2); - - Mockito.when(ovsdbSessionMapInterface.getSession("Test_Client_21P10C68818122")).thenReturn(session); - Status bssidStatus = new Status(); bssidStatus.setStatusDataType(StatusDataType.ACTIVE_BSSIDS); bssidStatus.setCustomerId(2); @@ -502,20 +479,21 @@ public class OpensyncExternalIntegrationCloudTest { activeBssidsDetails.setActiveBSSIDs(getActiveBssidList()); bssidStatus.setDetails(activeBssidsDetails); - Mockito.when(statusServiceInterface.getOrNull(Mockito.anyInt(), Mockito.anyLong(), - Mockito.eq(StatusDataType.ACTIVE_BSSIDS))).thenReturn(bssidStatus); + Mockito.when(statusServiceInterface.getOrNull(ArgumentMatchers.anyInt(), ArgumentMatchers.anyLong(), + ArgumentMatchers.eq(StatusDataType.ACTIVE_BSSIDS))).thenReturn(bssidStatus); - Mockito.when(statusServiceInterface.update(Mockito.any(Status.class))).thenReturn(bssidStatus); + Mockito.when(statusServiceInterface.update(ArgumentMatchers.any(Status.class))).thenReturn(bssidStatus); com.telecominfraproject.wlan.client.models.Client clientInstance = new com.telecominfraproject.wlan.client.models.Client(); clientInstance.setMacAddress(new MacAddress("7C:AB:60:E6:EA:4D")); clientInstance.setDetails(new ClientInfoDetails()); com.telecominfraproject.wlan.client.models.Client clientInstance2 = new com.telecominfraproject.wlan.client.models.Client(); clientInstance2.setMacAddress(new MacAddress("C0:9A:D0:76:A9:69")); clientInstance2.setDetails(new ClientInfoDetails()); - Mockito.when(clientServiceInterface.getOrNull(Mockito.anyInt(), Mockito.any(MacAddress.class))) - .thenReturn(clientInstance).thenReturn(clientInstance2); Mockito.when( - clientServiceInterface.update(Mockito.any(com.telecominfraproject.wlan.client.models.Client.class))) + clientServiceInterface.getOrNull(ArgumentMatchers.anyInt(), ArgumentMatchers.any(MacAddress.class))) + .thenReturn(clientInstance).thenReturn(clientInstance2); + Mockito.when(clientServiceInterface + .update(ArgumentMatchers.any(com.telecominfraproject.wlan.client.models.Client.class))) .thenReturn(clientInstance).thenReturn(clientInstance2); ClientSession clientSession = new ClientSession(); @@ -524,20 +502,15 @@ public class OpensyncExternalIntegrationCloudTest { ClientSession clientSession2 = new ClientSession(); clientSession2.setMacAddress(new MacAddress("C0:9A:D0:76:A9:69")); clientSession2.setDetails(new ClientSessionDetails()); - Mockito.when(clientServiceInterface.getSessionOrNull(Mockito.anyInt(), Mockito.anyLong(), - Mockito.any(MacAddress.class))).thenReturn(clientSession).thenReturn(clientSession2); + Mockito.when(clientServiceInterface.getSessionOrNull(ArgumentMatchers.anyInt(), ArgumentMatchers.anyLong(), + ArgumentMatchers.any(MacAddress.class))).thenReturn(clientSession).thenReturn(clientSession2); - Mockito.when(clientServiceInterface.updateSession(Mockito.any(ClientSession.class))).thenReturn(clientSession) - .thenReturn(clientSession2); + Mockito.when(clientServiceInterface.updateSession(ArgumentMatchers.any(ClientSession.class))) + .thenReturn(clientSession).thenReturn(clientSession2); opensyncExternalIntegrationCloud.processMqttMessage(topic, report); - Mockito.verify(clientServiceInterface, Mockito.times(4)).getOrNull(Mockito.anyInt(), - Mockito.any(MacAddress.class)); - Mockito.verify(clientServiceInterface, Mockito.times(4)).getSessionOrNull(Mockito.anyInt(), Mockito.anyLong(), - Mockito.any(MacAddress.class)); - Mockito.verify(statusServiceInterface, Mockito.times(3)).getOrNull(Mockito.anyInt(), Mockito.anyLong(), - Mockito.eq(StatusDataType.ACTIVE_BSSIDS)); + Mockito.verify(opensyncExternalIntegrationMqttProcessor, Mockito.times(1)).processMqttMessage(topic, report); } @@ -756,8 +729,8 @@ public class OpensyncExternalIntegrationCloudTest { activeBssidsDetails.setActiveBSSIDs(getActiveBssidList()); bssidStatus.setDetails(activeBssidsDetails); - Mockito.when(statusServiceInterface.getOrNull(Mockito.anyInt(), Mockito.anyLong(), - Mockito.eq(StatusDataType.ACTIVE_BSSIDS))).thenReturn(bssidStatus); + Mockito.when(statusServiceInterface.getOrNull(ArgumentMatchers.anyInt(), ArgumentMatchers.anyLong(), + ArgumentMatchers.eq(StatusDataType.ACTIVE_BSSIDS))).thenReturn(bssidStatus); opensyncExternalIntegrationCloud.wifiVIFStateDbTableDelete(ImmutableList.of(new OpensyncAPVIFState()), "apId"); } @@ -768,39 +741,6 @@ public class OpensyncExternalIntegrationCloudTest { opensyncExternalIntegrationCloud.wifiAssociatedClientsDbTableDelete("7C:AB:60:E6:EA:4D", "apId"); } - @Test - public void testpopulateNetworkProbeMetrics() throws Exception { - - InetAddress ip = InetAddress.getByName("192.168.1.1"); - - DNSProbeMetric dnsProbeMetric = DNSProbeMetric.getDefaultInstance().toBuilder().setLatency(10) - .setState(StateUpDown.SUD_up).setServerIP(ip.toString()).build(); - RADIUSMetrics radiusProbeMetric = RADIUSMetrics.getDefaultInstance().toBuilder().setLatencyAve(10).build(); - VLANMetrics vlanMetrics = VLANMetrics.getDefaultInstance().toBuilder().setDhcpLatency(10) - .setDhcpState(StateUpDown.SUD_up).setVlanIF("vlan-1").setObsV200RadiusLatency(15) - .setObsV200RadiusState(StateUpDown.SUD_up).build(); - NetworkProbe networkProbe = NetworkProbe.getDefaultInstance().toBuilder().setVlanProbe(vlanMetrics) - .setDnsProbe(dnsProbeMetric).addRadiusProbe(radiusProbeMetric).build(); - - Report report = Report.getDefaultInstance().toBuilder().setNodeID("21P10C68818122") - .addNetworkProbe(networkProbe).build(); - - ApNodeMetrics apNodeMetrics = new ApNodeMetrics(); - - opensyncExternalIntegrationCloud.populateNetworkProbeMetrics(report, apNodeMetrics); - - assertNotNull(apNodeMetrics.getNetworkProbeMetrics()); - - assert (apNodeMetrics.getNetworkProbeMetrics().get(0).getDhcpLatencyMs() == 10); - assert (apNodeMetrics.getNetworkProbeMetrics().get(0).getDnsLatencyMs() == 10); - assert (apNodeMetrics.getNetworkProbeMetrics().get(0).getRadiusState().equals(StateUpDownError.enabled)); - assert (apNodeMetrics.getNetworkProbeMetrics().get(0).getDhcpState().equals(StateUpDownError.enabled)); - assert (apNodeMetrics.getNetworkProbeMetrics().get(0).getDnsState().equals(StateUpDownError.enabled)); - assert (apNodeMetrics.getNetworkProbeMetrics().get(0).getRadiusLatencyInMs() == 15); - assert (apNodeMetrics.getNetworkProbeMetrics().get(0).getVlanIF().equals("vlan-1")); - - } - // Helper methods private List getActiveBssidList() { ActiveBSSID activeBssid = new ActiveBSSID(); @@ -819,17 +759,18 @@ public class OpensyncExternalIntegrationCloudTest { activeBssid3.setNumDevicesConnected(1); activeBssid3.setRadioType(RadioType.is5GHzU); - List bssidList = new ArrayList(); + List bssidList = new ArrayList<>(); bssidList.add(activeBssid); bssidList.add(activeBssid2); bssidList.add(activeBssid3); return bssidList; } - - + + private List getOpensyncStatsEventReportsList() { - sts.OpensyncStats.EventReport.ClientAssocEvent.Builder clientAssocBuilder = EventReport.ClientAssocEvent.getDefaultInstance().toBuilder(); + sts.OpensyncStats.EventReport.ClientAssocEvent.Builder clientAssocBuilder = EventReport.ClientAssocEvent + .getDefaultInstance().toBuilder(); clientAssocBuilder.setAssocType(AssocType.ASSOC); clientAssocBuilder.setBand(RadioBandType.BAND5GU); clientAssocBuilder.setRssi(-65); @@ -839,8 +780,9 @@ public class OpensyncExternalIntegrationCloudTest { clientAssocBuilder.setInternalSc(1); clientAssocBuilder.setSsid("ssid-3"); clientAssocBuilder.setStatus(1); - - sts.OpensyncStats.EventReport.ClientAssocEvent.Builder clientAssocBuilder2 = EventReport.ClientAssocEvent.getDefaultInstance().toBuilder(); + + sts.OpensyncStats.EventReport.ClientAssocEvent.Builder clientAssocBuilder2 = EventReport.ClientAssocEvent + .getDefaultInstance().toBuilder(); clientAssocBuilder2.setAssocType(AssocType.ASSOC); clientAssocBuilder2.setBand(RadioBandType.BAND2G); clientAssocBuilder2.setRssi(-65); @@ -856,24 +798,25 @@ public class OpensyncExternalIntegrationCloudTest { EventReport.Builder eventReportBuilder = EventReport.getDefaultInstance().toBuilder(); eventReportBuilder.setClientAssocEvent(clientAssocBuilder.build()); eventReportBuilder.setEventType(EventType.CLIENT_ASSOC); - + eventReportList.add(eventReportBuilder.build()); - + eventReportBuilder = EventReport.getDefaultInstance().toBuilder(); eventReportBuilder.setClientAssocEvent(clientAssocBuilder2.build()); eventReportBuilder.setEventType(EventType.CLIENT_ASSOC); - + eventReportList.add(eventReportBuilder.build()); return eventReportList; - - } + + } private List getOpensyncStatsClientReportsList() { int rssi = Long.valueOf(4294967239L).intValue(); Client.Stats clientStats = Client.Stats.getDefaultInstance().toBuilder().setRssi(rssi).setRxBytes(225554786) - .setRxRate(24000.0).setTxBytes(1208133026).setTxRate(433300.0).setRssi(758722570).setRxFrames(10000).setTxFrames(10000).setTxRate(24000.0).build(); + .setRxRate(24000.0).setTxBytes(1208133026).setTxRate(433300.0).setRssi(758722570).setRxFrames(10000) + .setTxFrames(10000).setTxRate(24000.0).build(); Client client2g = Client.getDefaultInstance().toBuilder().setMacAddress("7C:AB:60:E6:EA:4D").setSsid("ssid-1") .setConnected(true).setDurationMs(59977).setStats(clientStats).build(); Client client5gu = Client.getDefaultInstance().toBuilder().setMacAddress("C0:9A:D0:76:A9:69").setSsid("ssid-3") @@ -885,8 +828,8 @@ public class OpensyncExternalIntegrationCloudTest { .setChannel(36).addAllClientList(new ArrayList()).build(); ClientReport clientReport5gu = ClientReport.getDefaultInstance().toBuilder().setBand(RadioBandType.BAND5GU) .setChannel(157).addAllClientList(ImmutableList.of(client5gu)).build(); - - List clients = new ArrayList(); + + List clients = new ArrayList<>(); clients.add(clientReport2g); clients.add(clientReport5gl); clients.add(clientReport5gu); 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 new file mode 100644 index 0000000..e5bcbe3 --- /dev/null +++ b/opensync-ext-cloud/src/test/java/com/telecominfraproject/wlan/opensync/external/integration/OpensyncExternalIntegrationMqttMessageProcessorTest.java @@ -0,0 +1,370 @@ +package com.telecominfraproject.wlan.opensync.external.integration; + +import static org.junit.Assert.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertEquals; + +import java.net.InetAddress; +import java.util.ArrayList; +import java.util.List; + +import org.junit.After; +import org.junit.Before; +import org.junit.Ignore; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Answers; +import org.mockito.ArgumentMatchers; +import org.mockito.Mockito; +import org.mockito.MockitoSession; +import org.mockito.quality.Strictness; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; +import org.springframework.boot.test.mock.mockito.MockBean; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.Import; +import org.springframework.test.context.ActiveProfiles; +import org.springframework.test.context.junit4.SpringRunner; + +import com.google.common.collect.ImmutableList; +import com.google.protobuf.ByteString; +import com.telecominfraproject.wlan.alarm.AlarmServiceInterface; +import com.telecominfraproject.wlan.client.ClientServiceInterface; +import com.telecominfraproject.wlan.client.info.models.ClientInfoDetails; +import com.telecominfraproject.wlan.client.session.models.ClientSession; +import com.telecominfraproject.wlan.client.session.models.ClientSessionDetails; +import com.telecominfraproject.wlan.cloudeventdispatcher.CloudEventDispatcherInterface; +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.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.routing.RoutingServiceInterface; +import com.telecominfraproject.wlan.servicemetric.apnode.models.ApNodeMetrics; +import com.telecominfraproject.wlan.servicemetric.apnode.models.StateUpDownError; +import com.telecominfraproject.wlan.status.StatusServiceInterface; +import com.telecominfraproject.wlan.status.equipment.report.models.ActiveBSSID; +import com.telecominfraproject.wlan.status.equipment.report.models.ActiveBSSIDs; +import com.telecominfraproject.wlan.status.models.Status; +import com.telecominfraproject.wlan.status.models.StatusDataType; + +import sts.OpensyncStats.AssocType; +import sts.OpensyncStats.Client; +import sts.OpensyncStats.ClientReport; +import sts.OpensyncStats.DNSProbeMetric; +import sts.OpensyncStats.EventReport; +import sts.OpensyncStats.EventType; +import sts.OpensyncStats.NetworkProbe; +import sts.OpensyncStats.RADIUSMetrics; +import sts.OpensyncStats.RadioBandType; +import sts.OpensyncStats.Report; +import sts.OpensyncStats.StateUpDown; +import sts.OpensyncStats.VLANMetrics; + +@RunWith(SpringRunner.class) +@ActiveProfiles(profiles = { "integration_test", }) +@SpringBootTest(webEnvironment = WebEnvironment.NONE, classes = OpensyncExternalIntegrationMqttMessageProcessorTest.class) +@Import(value = { AlarmServiceInterface.class, OpensyncExternalIntegrationCloud.class, + OpensyncExternalIntegrationMqttMessageProcessorTest.Config.class, + +}) +public class OpensyncExternalIntegrationMqttMessageProcessorTest { + + @MockBean + AlarmServiceInterface alarmServiceInterface; + @MockBean + CustomerServiceInterface customerServiceInterface; + @MockBean + LocationServiceInterface locationServiceInterface; + @MockBean(answer = Answers.RETURNS_MOCKS) + OvsdbSessionMapInterface ovsdbSessionMapInterface; + @MockBean + CloudEventDispatcherInterface equipmentMetricsCollectorInterface; + @MockBean + EquipmentServiceInterface equipmentServiceInterface; + @MockBean + RoutingServiceInterface routingServiceInterface; + @MockBean + ProfileServiceInterface profileServiceInterface; + @MockBean + StatusServiceInterface statusServiceInterface; + @MockBean + ClientServiceInterface clientServiceInterface; + @MockBean + FirmwareServiceInterface firmwareServiceInterface; + @MockBean(answer = Answers.RETURNS_MOCKS) + OpensyncCloudGatewayController gatewayController; + + @Autowired + OpensyncExternalIntegrationMqttMessageProcessor opensyncExternalIntegrationMqttProcessor; + + MockitoSession mockito; + + @Configuration + static class Config { + + @Bean + public OpensyncExternalIntegrationMqttMessageProcessor opensyncExternalIntegrationMqttMessageProcessor() { + return new OpensyncExternalIntegrationMqttMessageProcessor(); + } + + } + + @Before + public void setUp() throws Exception { + + mockito = Mockito.mockitoSession().initMocks(this).strictness(Strictness.STRICT_STUBS).startMocking(); + + } + + @After + public void tearDown() throws Exception { + mockito.finishMocking(); + + } + + + @Test + public void testExtractApIdFromTopic() { + + String topic = "/ap/Test_Client_21P10C68818122/opensync"; + + assertEquals("Test_Client_21P10C68818122", + OpensyncExternalIntegrationMqttMessageProcessor.extractApIdFromTopic(topic)); + + } + + @Test + public void testExtractCustomerIdFromTopic() { + String topic = "/ap/Test_Client_21P10C68818122/opensync"; + OvsdbSession session = Mockito.mock(OvsdbSession.class); + Mockito.when(session.getCustomerId()).thenReturn(2); + + Mockito.when(ovsdbSessionMapInterface.getSession("Test_Client_21P10C68818122")).thenReturn(session); + + assertEquals(2, opensyncExternalIntegrationMqttProcessor.extractCustomerIdFromTopic(topic)); + } + + @Test + public void testExtractEquipmentIdFromTopic() { + + String topic = "/ap/Test_Client_21P10C68818122/opensync"; + OvsdbSession session = Mockito.mock(OvsdbSession.class); + Mockito.when(session.getEquipmentId()).thenReturn(1L); + + Mockito.when(ovsdbSessionMapInterface.getSession("Test_Client_21P10C68818122")).thenReturn(session); + + assertEquals(1L, opensyncExternalIntegrationMqttProcessor.extractEquipmentIdFromTopic(topic)); + + } + + @Test + public void testProcessMqttMessageStringReport() { + + Report report = Report.newBuilder().setNodeID("21P10C68818122") + .addAllClients(getOpensyncStatsClientReportsList()) + .addAllEventReport(getOpensyncStatsEventReportsList()).build(); + + String topic = "/ap/Test_Client_21P10C68818122/opensync"; + + OvsdbSession session = Mockito.mock(OvsdbSession.class); + Mockito.when(session.getEquipmentId()).thenReturn(1L); + Mockito.when(session.getCustomerId()).thenReturn(2); + + Mockito.when(ovsdbSessionMapInterface.getSession("Test_Client_21P10C68818122")).thenReturn(session); + + Status bssidStatus = new Status(); + bssidStatus.setStatusDataType(StatusDataType.ACTIVE_BSSIDS); + bssidStatus.setCustomerId(2); + + ActiveBSSIDs activeBssidsDetails = new ActiveBSSIDs(); + activeBssidsDetails.setActiveBSSIDs(getActiveBssidList()); + bssidStatus.setDetails(activeBssidsDetails); + + Mockito.when(statusServiceInterface.getOrNull(ArgumentMatchers.anyInt(), ArgumentMatchers.anyLong(), + ArgumentMatchers.eq(StatusDataType.ACTIVE_BSSIDS))).thenReturn(bssidStatus); + + Mockito.when(statusServiceInterface.update(ArgumentMatchers.any(Status.class))).thenReturn(bssidStatus); + com.telecominfraproject.wlan.client.models.Client clientInstance = new com.telecominfraproject.wlan.client.models.Client(); + clientInstance.setMacAddress(new MacAddress("7C:AB:60:E6:EA:4D")); + clientInstance.setDetails(new ClientInfoDetails()); + com.telecominfraproject.wlan.client.models.Client clientInstance2 = new com.telecominfraproject.wlan.client.models.Client(); + clientInstance2.setMacAddress(new MacAddress("C0:9A:D0:76:A9:69")); + clientInstance2.setDetails(new ClientInfoDetails()); + Mockito.when( + clientServiceInterface.getOrNull(ArgumentMatchers.anyInt(), ArgumentMatchers.any(MacAddress.class))) + .thenReturn(clientInstance).thenReturn(clientInstance2); + Mockito.when(clientServiceInterface + .update(ArgumentMatchers.any(com.telecominfraproject.wlan.client.models.Client.class))) + .thenReturn(clientInstance).thenReturn(clientInstance2); + + ClientSession clientSession = new ClientSession(); + clientSession.setMacAddress(new MacAddress("7C:AB:60:E6:EA:4D")); + clientSession.setDetails(new ClientSessionDetails()); + ClientSession clientSession2 = new ClientSession(); + clientSession2.setMacAddress(new MacAddress("C0:9A:D0:76:A9:69")); + clientSession2.setDetails(new ClientSessionDetails()); + Mockito.when(clientServiceInterface.getSessionOrNull(ArgumentMatchers.anyInt(), ArgumentMatchers.anyLong(), + ArgumentMatchers.any(MacAddress.class))).thenReturn(clientSession).thenReturn(clientSession2); + + Mockito.when(clientServiceInterface.updateSession(ArgumentMatchers.any(ClientSession.class))) + .thenReturn(clientSession).thenReturn(clientSession2); + + opensyncExternalIntegrationMqttProcessor.processMqttMessage(topic, report); + + // Mockito.verify(clientServiceInterface, + // Mockito.times(4)).getOrNull(Mockito.anyInt(), + // Mockito.any(MacAddress.class)); + // Mockito.verify(clientServiceInterface, + // Mockito.times(4)).getSessionOrNull(Mockito.anyInt(), + // Mockito.anyLong(), + // Mockito.any(MacAddress.class)); + // Mockito.verify(statusServiceInterface, + // Mockito.times(3)).getOrNull(Mockito.anyInt(), Mockito.anyLong(), + // Mockito.eq(StatusDataType.ACTIVE_BSSIDS)); + + } + + @Ignore + public void testProcessMqttMessageStringFlowReport() { + // TODO: implement me when support flow reports + } + + @Ignore + public void testProcessMqttMessageStringWCStatsReport() { + // TODO: implement me when wcs stats reports supported + } + + @Test + public void testpopulateNetworkProbeMetrics() throws Exception { + + InetAddress ip = InetAddress.getLocalHost(); + + DNSProbeMetric dnsProbeMetric = DNSProbeMetric.getDefaultInstance().toBuilder().setLatency(10) + .setState(StateUpDown.SUD_up).setServerIP(ip.getHostName()).build(); + RADIUSMetrics radiusProbeMetric = RADIUSMetrics.getDefaultInstance().toBuilder().setLatencyAve(10).build(); + VLANMetrics vlanMetrics = VLANMetrics.getDefaultInstance().toBuilder().setDhcpLatency(10) + .setDhcpState(StateUpDown.SUD_up).setVlanIF("vlan-1").setObsV200RadiusLatency(15) + .setObsV200RadiusState(StateUpDown.SUD_up).build(); + NetworkProbe networkProbe = NetworkProbe.getDefaultInstance().toBuilder().setVlanProbe(vlanMetrics) + .setDnsProbe(dnsProbeMetric).addRadiusProbe(radiusProbeMetric).build(); + + Report report = Report.getDefaultInstance().toBuilder().setNodeID("21P10C68818122") + .addNetworkProbe(networkProbe).build(); + + ApNodeMetrics apNodeMetrics = new ApNodeMetrics(); + + opensyncExternalIntegrationMqttProcessor.populateNetworkProbeMetrics(report, apNodeMetrics); + + assertNotNull(apNodeMetrics.getNetworkProbeMetrics()); + + assert (apNodeMetrics.getNetworkProbeMetrics().get(0).getDhcpLatencyMs() == 10); + assert (apNodeMetrics.getNetworkProbeMetrics().get(0).getDnsLatencyMs() == 10); + assert (apNodeMetrics.getNetworkProbeMetrics().get(0).getRadiusState().equals(StateUpDownError.enabled)); + assert (apNodeMetrics.getNetworkProbeMetrics().get(0).getDhcpState().equals(StateUpDownError.enabled)); + assert (apNodeMetrics.getNetworkProbeMetrics().get(0).getDnsState().equals(StateUpDownError.enabled)); + assert (apNodeMetrics.getNetworkProbeMetrics().get(0).getRadiusLatencyInMs() == 15); + assert (apNodeMetrics.getNetworkProbeMetrics().get(0).getVlanIF().equals("vlan-1")); + + } + + // Helper methods + private List getActiveBssidList() { + ActiveBSSID activeBssid = new ActiveBSSID(); + activeBssid.setBssid("24:f5:a2:ef:2e:54"); + activeBssid.setSsid("ssid-1"); + activeBssid.setNumDevicesConnected(1); + activeBssid.setRadioType(RadioType.is2dot4GHz); + ActiveBSSID activeBssid2 = new ActiveBSSID(); + activeBssid2.setBssid("24:f5:a2:ef:2e:55"); + activeBssid2.setSsid("ssid-2"); + activeBssid2.setNumDevicesConnected(1); + activeBssid2.setRadioType(RadioType.is5GHzL); + ActiveBSSID activeBssid3 = new ActiveBSSID(); + activeBssid3.setBssid("24:f5:a2:ef:2e:56"); + activeBssid3.setSsid("ssid-3"); + activeBssid3.setNumDevicesConnected(1); + activeBssid3.setRadioType(RadioType.is5GHzU); + + List bssidList = new ArrayList<>(); + bssidList.add(activeBssid); + bssidList.add(activeBssid2); + bssidList.add(activeBssid3); + return bssidList; + } + + + private List getOpensyncStatsEventReportsList() { + + sts.OpensyncStats.EventReport.ClientAssocEvent.Builder clientAssocBuilder = EventReport.ClientAssocEvent + .getDefaultInstance().toBuilder(); + clientAssocBuilder.setAssocType(AssocType.ASSOC); + clientAssocBuilder.setBand(RadioBandType.BAND5GU); + clientAssocBuilder.setRssi(-65); + clientAssocBuilder.setStaMac("C0:9A:D0:76:A9:69"); + clientAssocBuilder.setStaMacBytes(ByteString.copyFrom("C0:9A:D0:76:A9:69".getBytes())); + clientAssocBuilder.setSessionId(1000L); + clientAssocBuilder.setInternalSc(1); + clientAssocBuilder.setSsid("ssid-3"); + clientAssocBuilder.setStatus(1); + + sts.OpensyncStats.EventReport.ClientAssocEvent.Builder clientAssocBuilder2 = EventReport.ClientAssocEvent + .getDefaultInstance().toBuilder(); + clientAssocBuilder2.setAssocType(AssocType.ASSOC); + clientAssocBuilder2.setBand(RadioBandType.BAND2G); + clientAssocBuilder2.setRssi(-65); + clientAssocBuilder2.setStaMac("7C:AB:60:E6:EA:4D"); + clientAssocBuilder2.setStaMacBytes(ByteString.copyFrom("7C:AB:60:E6:EA:4D".getBytes())); + clientAssocBuilder2.setSessionId(1000L); + clientAssocBuilder2.setInternalSc(1); + clientAssocBuilder2.setSsid("ssid-1"); + clientAssocBuilder2.setStatus(1); + + List eventReportList = new ArrayList<>(); + + EventReport.Builder eventReportBuilder = EventReport.getDefaultInstance().toBuilder(); + eventReportBuilder.setClientAssocEvent(clientAssocBuilder.build()); + eventReportBuilder.setEventType(EventType.CLIENT_ASSOC); + + eventReportList.add(eventReportBuilder.build()); + + eventReportBuilder = EventReport.getDefaultInstance().toBuilder(); + eventReportBuilder.setClientAssocEvent(clientAssocBuilder2.build()); + eventReportBuilder.setEventType(EventType.CLIENT_ASSOC); + + eventReportList.add(eventReportBuilder.build()); + + return eventReportList; + + } + + private List getOpensyncStatsClientReportsList() { + int rssi = Long.valueOf(4294967239L).intValue(); + + Client.Stats clientStats = Client.Stats.getDefaultInstance().toBuilder().setRssi(rssi).setRxBytes(225554786) + .setRxRate(24000.0).setTxBytes(1208133026).setTxRate(433300.0).setRssi(758722570).setRxFrames(10000) + .setTxFrames(10000).setTxRate(24000.0).build(); + Client client2g = Client.getDefaultInstance().toBuilder().setMacAddress("7C:AB:60:E6:EA:4D").setSsid("ssid-1") + .setConnected(true).setDurationMs(59977).setStats(clientStats).build(); + Client client5gu = Client.getDefaultInstance().toBuilder().setMacAddress("C0:9A:D0:76:A9:69").setSsid("ssid-3") + .setConnected(true).setDurationMs(298127).setStats(clientStats).build(); + + ClientReport clientReport2g = ClientReport.getDefaultInstance().toBuilder().setBand(RadioBandType.BAND2G) + .setChannel(6).addAllClientList(ImmutableList.of(client2g)).build(); + ClientReport clientReport5gl = ClientReport.getDefaultInstance().toBuilder().setBand(RadioBandType.BAND5GL) + .setChannel(36).addAllClientList(new ArrayList()).build(); + ClientReport clientReport5gu = ClientReport.getDefaultInstance().toBuilder().setBand(RadioBandType.BAND5GU) + .setChannel(157).addAllClientList(ImmutableList.of(client5gu)).build(); + + List clients = new ArrayList<>(); + clients.add(clientReport2g); + clients.add(clientReport5gl); + clients.add(clientReport5gu); + return clients; + } + +} diff --git a/opensync-ext-interface/src/main/java/com/telecominfraproject/wlan/opensync/external/integration/models/OpensyncAPConfig.java b/opensync-ext-interface/src/main/java/com/telecominfraproject/wlan/opensync/external/integration/models/OpensyncAPConfig.java index 4739b51..8e812f5 100644 --- a/opensync-ext-interface/src/main/java/com/telecominfraproject/wlan/opensync/external/integration/models/OpensyncAPConfig.java +++ b/opensync-ext-interface/src/main/java/com/telecominfraproject/wlan/opensync/external/integration/models/OpensyncAPConfig.java @@ -25,207 +25,223 @@ import com.telecominfraproject.wlan.routing.models.EquipmentRoutingRecord; public class OpensyncAPConfig extends BaseJsonModel { - private static final long serialVersionUID = 3917975477206236668L; + private static final long serialVersionUID = 3917975477206236668L; - private Equipment customerEquipment; - private Profile apProfile; - private List ssidProfile; - private List radiusProfiles; - private Location equipmentLocation; - private EquipmentRoutingRecord equipmentRouting; - private EquipmentGatewayRecord equipmentGateway; - private List captiveProfiles; - private List blockedClients; + private Equipment customerEquipment; + private Profile apProfile; + private List ssidProfile; + private List radiusProfiles; + private Location equipmentLocation; + private EquipmentRoutingRecord equipmentRouting; + private EquipmentGatewayRecord equipmentGateway; + private List captiveProfiles; + private List bonjourGatewayProfiles; + private List blockedClients; - // Handle Legacy Config Support - public void setRadioConfig(OpensyncAPRadioConfig radioConfig) { + // Handle Legacy Config Support + public void setRadioConfig(OpensyncAPRadioConfig radioConfig) { - if (customerEquipment == null) { - customerEquipment = new Equipment(); - customerEquipment.setId(0); - customerEquipment.setEquipmentType(EquipmentType.AP); - customerEquipment.setDetails(ApElementConfiguration.createWithDefaults()); - ApElementConfiguration apConfig = (ApElementConfiguration) customerEquipment.getDetails(); - apConfig.getRadioMap().get(RadioType.is2dot4GHz).setChannelNumber(radioConfig.getRadioChannel24G()); - apConfig.getRadioMap().get(RadioType.is5GHzL).setChannelNumber(radioConfig.getRadioChannel5LG()); - apConfig.getRadioMap().get(RadioType.is5GHzU).setChannelNumber(radioConfig.getRadioChannel5HG()); - customerEquipment.setDetails(apConfig); - } + if (customerEquipment == null) { + customerEquipment = new Equipment(); + customerEquipment.setId(0); + customerEquipment.setEquipmentType(EquipmentType.AP); + customerEquipment.setDetails(ApElementConfiguration.createWithDefaults()); + ApElementConfiguration apConfig = (ApElementConfiguration) customerEquipment.getDetails(); + apConfig.getRadioMap().get(RadioType.is2dot4GHz).setChannelNumber(radioConfig.getRadioChannel24G()); + apConfig.getRadioMap().get(RadioType.is5GHzL).setChannelNumber(radioConfig.getRadioChannel5LG()); + apConfig.getRadioMap().get(RadioType.is5GHzU).setChannelNumber(radioConfig.getRadioChannel5HG()); + customerEquipment.setDetails(apConfig); + } - if (equipmentLocation == null) { - equipmentLocation = new Location(); - equipmentLocation.setId(1); - equipmentLocation.setDetails(LocationDetails.createWithDefaults()); - ((LocationDetails) equipmentLocation.getDetails()) - .setCountryCode(CountryCode.getByName(radioConfig.getCountry().toLowerCase())); - customerEquipment.setLocationId(equipmentLocation.getId()); - } + if (equipmentLocation == null) { + equipmentLocation = new Location(); + equipmentLocation.setId(1); + equipmentLocation.setDetails(LocationDetails.createWithDefaults()); + ((LocationDetails) equipmentLocation.getDetails()) + .setCountryCode(CountryCode.getByName(radioConfig.getCountry().toLowerCase())); + customerEquipment.setLocationId(equipmentLocation.getId()); + } - } + } - // Handle Legacy Config Support - public void setSsidConfigs(List ssidConfigs) { + // Handle Legacy Config Support + public void setSsidConfigs(List ssidConfigs) { - if (apProfile == null) { - apProfile = new Profile(); - apProfile.setName("GeneratedApProfile"); - apProfile.setId(2); - apProfile.setDetails(ApNetworkConfiguration.createWithDefaults()); - } + if (apProfile == null) { + apProfile = new Profile(); + apProfile.setName("GeneratedApProfile"); + apProfile.setId(2); + apProfile.setDetails(ApNetworkConfiguration.createWithDefaults()); + } - long ssidProfileId = 3; - for (OpensyncAPSsidConfig ssidConfig : ssidConfigs) { + long ssidProfileId = 3; + for (OpensyncAPSsidConfig ssidConfig : ssidConfigs) { - Profile profile = new Profile(); - profile.setProfileType(ProfileType.ssid); - profile.setName(ssidConfig.getSsid()); - SsidConfiguration cfg = SsidConfiguration.createWithDefaults(); - Set appliedRadios = new HashSet(); - appliedRadios.add(ssidConfig.getRadioType()); - cfg.setAppliedRadios(appliedRadios); - cfg.setSsid(ssidConfig.getSsid()); - if (ssidConfig.getEncryption().equals("WPA-PSK") && ssidConfig.getMode().equals("1")) - cfg.setSecureMode(SecureMode.wpaPSK); - else - cfg.setSecureMode(SecureMode.wpa2PSK); - cfg.setBroadcastSsid(ssidConfig.isBroadcast() ? StateSetting.enabled : StateSetting.disabled); + Profile profile = new Profile(); + profile.setProfileType(ProfileType.ssid); + profile.setName(ssidConfig.getSsid()); + SsidConfiguration cfg = SsidConfiguration.createWithDefaults(); + Set appliedRadios = new HashSet(); + appliedRadios.add(ssidConfig.getRadioType()); + cfg.setAppliedRadios(appliedRadios); + cfg.setSsid(ssidConfig.getSsid()); + if (ssidConfig.getEncryption().equals("WPA-PSK") && ssidConfig.getMode().equals("1")) + cfg.setSecureMode(SecureMode.wpaPSK); + else + cfg.setSecureMode(SecureMode.wpa2PSK); + cfg.setBroadcastSsid(ssidConfig.isBroadcast() ? StateSetting.enabled : StateSetting.disabled); - profile.setDetails(cfg); - profile.setId(ssidProfileId); - if (this.ssidProfile == null) - this.ssidProfile = new ArrayList(); - this.ssidProfile.add(profile); - apProfile.getChildProfileIds().add(ssidProfileId); - ssidProfileId++; + profile.setDetails(cfg); + profile.setId(ssidProfileId); + if (this.ssidProfile == null) + this.ssidProfile = new ArrayList(); + this.ssidProfile.add(profile); + apProfile.getChildProfileIds().add(ssidProfileId); + ssidProfileId++; - } + } - if (customerEquipment != null) { - customerEquipment.setProfileId(apProfile.getId()); - } + if (customerEquipment != null) { + customerEquipment.setProfileId(apProfile.getId()); + } - } + } - public EquipmentGatewayRecord getEquipmentGateway() { - return equipmentGateway; - } + public EquipmentGatewayRecord getEquipmentGateway() { + return equipmentGateway; + } - public void setEquipmentGateway(EquipmentGatewayRecord equipmentGateway) { - this.equipmentGateway = equipmentGateway; - } + public void setEquipmentGateway(EquipmentGatewayRecord equipmentGateway) { + this.equipmentGateway = equipmentGateway; + } - public EquipmentRoutingRecord getEquipmentRouting() { - return equipmentRouting; - } + public EquipmentRoutingRecord getEquipmentRouting() { + return equipmentRouting; + } - public void setEquipmentRouting(EquipmentRoutingRecord equipmentRouting) { - this.equipmentRouting = equipmentRouting; - } + public void setEquipmentRouting(EquipmentRoutingRecord equipmentRouting) { + this.equipmentRouting = equipmentRouting; + } - public Equipment getCustomerEquipment() { - return customerEquipment; - } + public Equipment getCustomerEquipment() { + return customerEquipment; + } - public void setCustomerEquipment(Equipment customerEquipment) { - this.customerEquipment = customerEquipment; - } + public void setCustomerEquipment(Equipment customerEquipment) { + this.customerEquipment = customerEquipment; + } - public Profile getApProfile() { - return apProfile; - } + public Profile getApProfile() { + return apProfile; + } - public void setApProfile(Profile apProfile) { - this.apProfile = apProfile; - } + public void setApProfile(Profile apProfile) { + this.apProfile = apProfile; + } - public List getSsidProfile() { - return ssidProfile; - } + public List getSsidProfile() { + return ssidProfile; + } - public void setSsidProfile(List ssidProfile) { - this.ssidProfile = ssidProfile; - } + public void setSsidProfile(List ssidProfile) { + this.ssidProfile = ssidProfile; + } - public Location getEquipmentLocation() { - return equipmentLocation; - } + public List getBonjourGatewayProfiles() { + return bonjourGatewayProfiles; + } - public void setEquipmentLocation(Location equipmentLocation) { - this.equipmentLocation = equipmentLocation; - } + public void setBonjourGatewayProfiles(List bonjourGatewayProfiles) { + this.bonjourGatewayProfiles = bonjourGatewayProfiles; + } - public String getCountryCode() { - return Location.getCountryCode(this.equipmentLocation).toString(); - } + public Location getEquipmentLocation() { + return equipmentLocation; + } - public static long getSerialversionuid() { - return serialVersionUID; - } + public void setEquipmentLocation(Location equipmentLocation) { + this.equipmentLocation = equipmentLocation; + } - @Override - public OpensyncAPConfig clone() { - OpensyncAPConfig ret = (OpensyncAPConfig) super.clone(); + public String getCountryCode() { + return Location.getCountryCode(this.equipmentLocation).toString(); + } - if (customerEquipment != null) - ret.customerEquipment = customerEquipment.clone(); - if (equipmentLocation != null) - ret.equipmentLocation = equipmentLocation.clone(); - if (ssidProfile != null) { - List ssidList = new ArrayList(); - for (Profile profile : ssidProfile) { - ssidList.add(profile.clone()); - } - ret.ssidProfile = ssidList; - } - if (apProfile != null) - ret.apProfile = apProfile.clone(); - if (equipmentRouting != null) - ret.equipmentRouting = equipmentRouting.clone(); - if (equipmentGateway != null) - ret.equipmentGateway = equipmentGateway.clone(); - if (radiusProfiles != null) { + public static long getSerialversionuid() { + return serialVersionUID; + } + + @Override + public OpensyncAPConfig clone() { + OpensyncAPConfig ret = (OpensyncAPConfig) super.clone(); + + if (customerEquipment != null) + ret.customerEquipment = customerEquipment.clone(); + if (equipmentLocation != null) + ret.equipmentLocation = equipmentLocation.clone(); + if (ssidProfile != null) { + List ssidList = new ArrayList(); + for (Profile profile : ssidProfile) { + ssidList.add(profile.clone()); + } + ret.ssidProfile = ssidList; + } + if (bonjourGatewayProfiles != null) { + List bonjourGatewayProfilesList = new ArrayList(); + for (Profile profile : bonjourGatewayProfiles) { + bonjourGatewayProfilesList.add(profile.clone()); + } + ret.bonjourGatewayProfiles = bonjourGatewayProfilesList; + } + if (apProfile != null) + ret.apProfile = apProfile.clone(); + if (equipmentRouting != null) + ret.equipmentRouting = equipmentRouting.clone(); + if (equipmentGateway != null) + ret.equipmentGateway = equipmentGateway.clone(); + if (radiusProfiles != null) { ret.radiusProfiles = new ArrayList<>(); - for (Profile cpConfig : this.radiusProfiles) { - ret.radiusProfiles.add(cpConfig); + for (Profile radiusProfile : this.radiusProfiles) { + ret.radiusProfiles.add(radiusProfile); } } - if (captiveProfiles != null) { - ret.captiveProfiles = new ArrayList<>(); - for (Profile cpConfig : this.captiveProfiles) { + if (captiveProfiles != null) { + ret.captiveProfiles = new ArrayList<>(); + for (Profile cpConfig : this.captiveProfiles) { ret.captiveProfiles.add(cpConfig); } } - if (blockedClients != null) { - ret.blockedClients = new ArrayList(); - for (MacAddress blockedClient : this.blockedClients) { + if (blockedClients != null) { + ret.blockedClients = new ArrayList(); + for (MacAddress blockedClient : this.blockedClients) { ret.blockedClients.add(blockedClient); } } - return ret; - } + return ret; + } - public List getRadiusProfiles() { - return radiusProfiles; - } + public List getRadiusProfiles() { + return radiusProfiles; + } - public void setRadiusProfiles(List radiusProfiles) { - this.radiusProfiles = radiusProfiles; - } - - public List getCaptiveProfiles() { - return captiveProfiles; - } + public void setRadiusProfiles(List radiusProfiles) { + this.radiusProfiles = radiusProfiles; + } - public void setCaptiveProfiles(List captiveProfiles) { - this.captiveProfiles = captiveProfiles; - } - - public List getBlockedClients() { - return blockedClients; - } + public List getCaptiveProfiles() { + return captiveProfiles; + } - public void setBlockedClients(List blockedClients) { - this.blockedClients = blockedClients; - } + public void setCaptiveProfiles(List captiveProfiles) { + this.captiveProfiles = captiveProfiles; + } + + public List getBlockedClients() { + return blockedClients; + } + + public void setBlockedClients(List blockedClients) { + this.blockedClients = blockedClients; + } } diff --git a/opensync-ext-static/src/main/java/com/telecominfraproject/wlan/opensync/external/integration/OpensyncExternalIntegrationSimple.java b/opensync-ext-static/src/main/java/com/telecominfraproject/wlan/opensync/external/integration/OpensyncExternalIntegrationSimple.java index 562b040..34b49e6 100644 --- a/opensync-ext-static/src/main/java/com/telecominfraproject/wlan/opensync/external/integration/OpensyncExternalIntegrationSimple.java +++ b/opensync-ext-static/src/main/java/com/telecominfraproject/wlan/opensync/external/integration/OpensyncExternalIntegrationSimple.java @@ -47,7 +47,10 @@ public class OpensyncExternalIntegrationSimple implements OpensyncExternalIntegr @Value("${tip.wlan.ovsdb.captiveProfileFileName:/app/config/ProfileCaptive.json}") private String captiveProfileFileName; - + + @Value("${tip.wlan.ovsdb.bonjourProfileFileName:/app/config/ProfileBonjour.json}") + private String bonjourProfileFileName; + @Value("${tip.wlan.ovsdb.locationFileName:/app/config/LocationBuildingExample.json}") private String locationFileName; @@ -101,6 +104,15 @@ public class OpensyncExternalIntegrationSimple implements OpensyncExternalIntegr } else { LOG.info("Captive file is not provided"); } + + List bonjourProfiles = null; + File bonjourFile = new File(bonjourProfileFileName); + if (bonjourFile.exists()) { + bonjourProfiles = com.telecominfraproject.wlan.profile.models.Profile + .listFromFile(bonjourProfileFileName, com.telecominfraproject.wlan.profile.models.Profile.class); + } else { + LOG.info("Bonjour file is not provided"); + } equipment.setProfileId(apProfile.getId()); @@ -115,6 +127,7 @@ public class OpensyncExternalIntegrationSimple implements OpensyncExternalIntegr ret.setRadiusProfiles(radiusProfiles); ret.setEquipmentLocation(location); ret.setCaptiveProfiles(captiveProfiles); + ret.setBonjourGatewayProfiles(bonjourProfiles); } catch (IOException e) { LOG.error("Cannot read config file", e); diff --git a/opensync-ext-static/src/main/resources/ProfileBonjour.json b/opensync-ext-static/src/main/resources/ProfileBonjour.json new file mode 100644 index 0000000..117b1f7 --- /dev/null +++ b/opensync-ext-static/src/main/resources/ProfileBonjour.json @@ -0,0 +1,29 @@ +[ +{ + "model_type": "Profile", + "id": 100, + "customerId": 2, + "profileType": "bonjour", + "name": "Bonjour-gateway", + "details": { + "model_type": "BonjourGatewayProfile", + "profileDescription": "Bonjour Gateway Configuration for Design Testing", + "profileType": "bonjour", + "bonjourServices": [ + { + "model_type": "BonjourServiceSet", + "vlanId": 1, + "supportAllServices": false, + "serviceNames": [ + "AirPort", + "SFTP", + "SSH" + ] + } + ] + }, + "createdTimestamp": 1599234550774, + "lastModifiedTimestamp": 1599234550774, + "childProfileIds": [] +} +] \ No newline at end of file diff --git a/opensync-gateway-static-docker/src/main/docker-opensync-gateway-and-mqtt/app/opensync/ProfileBonjour.json b/opensync-gateway-static-docker/src/main/docker-opensync-gateway-and-mqtt/app/opensync/ProfileBonjour.json new file mode 100644 index 0000000..117b1f7 --- /dev/null +++ b/opensync-gateway-static-docker/src/main/docker-opensync-gateway-and-mqtt/app/opensync/ProfileBonjour.json @@ -0,0 +1,29 @@ +[ +{ + "model_type": "Profile", + "id": 100, + "customerId": 2, + "profileType": "bonjour", + "name": "Bonjour-gateway", + "details": { + "model_type": "BonjourGatewayProfile", + "profileDescription": "Bonjour Gateway Configuration for Design Testing", + "profileType": "bonjour", + "bonjourServices": [ + { + "model_type": "BonjourServiceSet", + "vlanId": 1, + "supportAllServices": false, + "serviceNames": [ + "AirPort", + "SFTP", + "SSH" + ] + } + ] + }, + "createdTimestamp": 1599234550774, + "lastModifiedTimestamp": 1599234550774, + "childProfileIds": [] +} +] \ No newline at end of file diff --git a/opensync-gateway-static-docker/src/main/docker-opensync-gateway-and-mqtt/app/run.sh b/opensync-gateway-static-docker/src/main/docker-opensync-gateway-and-mqtt/app/run.sh index b7bb2f0..ee2a1b3 100755 --- a/opensync-gateway-static-docker/src/main/docker-opensync-gateway-and-mqtt/app/run.sh +++ b/opensync-gateway-static-docker/src/main/docker-opensync-gateway-and-mqtt/app/run.sh @@ -133,6 +133,7 @@ OVSDB_PROPS="$OVSDB_PROPS -Dtip.wlan.ovsdb.ssidProfileFileName=$OVSDB_SSIDPROFIL OVSDB_PROPS="$OVSDB_PROPS -Dtip.wlan.ovsdb.radiusProfileFileName=$OVSDB_RADIUSPROFILE_CONFIG_FILE" OVSDB_PROPS="$OVSDB_PROPS -Dtip.wlan.ovsdb.locationFileName=$OVSDB_LOCATION_CONFIG_FILE" OVSDB_PROPS="$OVSDB_PROPS -Dtip.wlan.ovsdb.captiveProfileFileName=$OVSDB_CAPTIVEPROFILE_CONFIG_FILE" +OVSDB_PROPS="$OVSDB_PROPS -Dtip.wlan.ovsdb.bonjourProfileFileName=$OVSDB_BONJOURPROFILE_CONFIG_FILE" OVSDB_PROPS="$OVSDB_PROPS -Dtip.wlan.ovsdb.wifi-iface.default_bridge=$OVSDB_IF_DEFAULT_BRIDGE" OVSDB_PROPS="$OVSDB_PROPS -Dtip.wlan.ovsdb.wifi-iface.default_wan_type=$OVSDB_DEVICE_DEFAULT_WAN_TYPE" OVSDB_PROPS="$OVSDB_PROPS -Dtip.wlan.ovsdb.wifi-iface.default_wan_name=$OVSDB_DEVICE_DEFAULT_WAN_NAME" diff --git a/opensync-gateway-static-docker/src/main/docker/app/opensync/ProfileBonjour.json b/opensync-gateway-static-docker/src/main/docker/app/opensync/ProfileBonjour.json new file mode 100644 index 0000000..117b1f7 --- /dev/null +++ b/opensync-gateway-static-docker/src/main/docker/app/opensync/ProfileBonjour.json @@ -0,0 +1,29 @@ +[ +{ + "model_type": "Profile", + "id": 100, + "customerId": 2, + "profileType": "bonjour", + "name": "Bonjour-gateway", + "details": { + "model_type": "BonjourGatewayProfile", + "profileDescription": "Bonjour Gateway Configuration for Design Testing", + "profileType": "bonjour", + "bonjourServices": [ + { + "model_type": "BonjourServiceSet", + "vlanId": 1, + "supportAllServices": false, + "serviceNames": [ + "AirPort", + "SFTP", + "SSH" + ] + } + ] + }, + "createdTimestamp": 1599234550774, + "lastModifiedTimestamp": 1599234550774, + "childProfileIds": [] +} +] \ No newline at end of file diff --git a/opensync-gateway-static-docker/src/main/docker/app/run.sh b/opensync-gateway-static-docker/src/main/docker/app/run.sh index cb4a579..880a040 100755 --- a/opensync-gateway-static-docker/src/main/docker/app/run.sh +++ b/opensync-gateway-static-docker/src/main/docker/app/run.sh @@ -24,6 +24,7 @@ OVSDB_PROPS+=" -Dtip.wlan.ovsdb.apProfileFileName=$OVSDB_APPROFILE_CONFIG_FILE" OVSDB_PROPS+=" -Dtip.wlan.ovsdb.ssidProfileFileName=$OVSDB_SSIDPROFILE_CONFIG_FILE" OVSDB_PROPS+=" -Dtip.wlan.ovsdb.radiusProfileFileName=$OVSDB_RADIUSPROFILE_CONFIG_FILE" OVSDB_PROPS+=" -Dtip.wlan.ovsdb.captiveProfileFileName=$OVSDB_CAPTIVEPROFILE_CONFIG_FILE" +OVSDB_PROPS+=" -Dtip.wlan.ovsdb.bonjourProfileFileName=$OVSDB_BONJOURPROFILE_CONFIG_FILE" OVSDB_PROPS+=" -Dtip.wlan.ovsdb.locationFileName=$OVSDB_LOCATION_CONFIG_FILE" OVSDB_PROPS+=" -Dtip.wlan.ovsdb.wifi-iface.default_bridge=$OVSDB_IF_DEFAULT_BRIDGE" OVSDB_PROPS+=" -Dtip.wlan.ovsdb.wifi-iface.default_wan_type=$OVSDB_DEVICE_DEFAULT_WAN_TYPE"