From 0e80415e52119a6c79b8c8eb1d896fbd471e814c Mon Sep 17 00:00:00 2001 From: Mike Hansen Date: Wed, 28 Oct 2020 15:19:29 -0400 Subject: [PATCH] WIFI-1007: AP is reported as WiFi clients --- .../OpensyncExternalIntegrationCloud.java | 3664 +++++++++-------- .../models/OpensyncAPInetState.java | 279 +- .../opensync/ovsdb/TipWlanOvsdbClient.java | 20 +- .../wlan/opensync/ovsdb/dao/OvsdbDao.java | 315 +- .../wlan/opensync/ovsdb/dao/OvsdbDaoTest.java | 142 - .../resources/Wifi_Inet_State-home-ap-24.json | 110 - .../Wifi_Inet_State-home-ap-l50.json | 109 - .../Wifi_Inet_State-home-ap-u50.json | 109 - .../Wifi_Radio_State-home-ap-24.json | 110 - .../Wifi_Radio_State-home-ap-l50.json | 109 - .../Wifi_Radio_State-home-ap-u50.json | 109 - .../resources/Wifi_VIF_State-home-ap-24.json | 110 - .../resources/Wifi_VIF_State-home-ap-l50.json | 109 - .../resources/Wifi_VIF_State-home-ap-u50.json | 96 - 14 files changed, 2275 insertions(+), 3116 deletions(-) delete mode 100644 opensync-gateway/src/test/resources/Wifi_Inet_State-home-ap-24.json delete mode 100644 opensync-gateway/src/test/resources/Wifi_Inet_State-home-ap-l50.json delete mode 100644 opensync-gateway/src/test/resources/Wifi_Inet_State-home-ap-u50.json delete mode 100644 opensync-gateway/src/test/resources/Wifi_Radio_State-home-ap-24.json delete mode 100644 opensync-gateway/src/test/resources/Wifi_Radio_State-home-ap-l50.json delete mode 100644 opensync-gateway/src/test/resources/Wifi_Radio_State-home-ap-u50.json delete mode 100644 opensync-gateway/src/test/resources/Wifi_VIF_State-home-ap-24.json delete mode 100644 opensync-gateway/src/test/resources/Wifi_VIF_State-home-ap-l50.json delete mode 100644 opensync-gateway/src/test/resources/Wifi_VIF_State-home-ap-u50.json 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 3c28e89..d429e97 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 @@ -108,1945 +108,2039 @@ import wc.stats.IpDnsTelemetry.WCStatsReport; @Component public class OpensyncExternalIntegrationCloud implements OpensyncExternalIntegrationInterface { - private static final Logger LOG = LoggerFactory.getLogger(OpensyncExternalIntegrationCloud.class); - - @Autowired - private CustomerServiceInterface customerServiceInterface; - @Autowired - private LocationServiceInterface locationServiceInterface; - @Autowired - private OvsdbSessionMapInterface ovsdbSessionMapInterface; - @Autowired - private EquipmentServiceInterface equipmentServiceInterface; - @Autowired - private RoutingServiceInterface routingServiceInterface; - @Autowired - private ProfileServiceInterface profileServiceInterface; - @Autowired - private StatusServiceInterface statusServiceInterface; - @Autowired - private ClientServiceInterface clientServiceInterface; - @Autowired - private FirmwareServiceInterface firmwareServiceInterface; - @Autowired - private OpensyncExternalIntegrationMqttMessageProcessor mqttMessageProcessor; - - @Autowired - private OpensyncCloudGatewayController gatewayController; - - @Value("${tip.wlan.ovsdb.autoProvisionedCustomerId:1970}") - private int autoProvisionedCustomerId; - @Value("${tip.wlan.ovsdb.autoProvisionedLocationId:8}") - private int autoProvisionedLocationId; - @Value("${tip.wlan.ovsdb.autoProvisionedProfileId:1}") - private int autoProvisionedProfileId; - @Value("${tip.wlan.ovsdb.autoProvisionedSsid:DefaultSsid-}") - private String autoProvisionedSsid; - @Value("${tip.wlan.ovsdb.autoprovisionedSsidKey:12345678}") - private String autoprovisionedSsidKey; - @Value("${tip.wlan.ovsdb.isAutoconfigEnabled:true}") - private boolean isAutoconfigEnabled; - @Value("${tip.wlan.ovsdb.defaultFwVersion:r10947-65030d81f3}") - private String defaultFwVersion; - - @Autowired - private CacheManager cacheManagerShortLived; - private Cache cloudEquipmentRecordCache; - - @PostConstruct - private void postCreate() { - LOG.info("Using Cloud integration"); - cloudEquipmentRecordCache = cacheManagerShortLived.getCache("equipment_record_cache"); - } - - public Equipment getCustomerEquipment(String apId) { - Equipment ce = null; - - try { - ce = cloudEquipmentRecordCache.get(apId, () -> equipmentServiceInterface.getByInventoryIdOrNull(apId)); - } catch (Exception e) { - LOG.error("Could not get customer equipment for {}", apId, e); - } - - return ce; - } - - - @Override - public void apConnected(String apId, ConnectNodeInfo connectNodeInfo) { - - Equipment ce = getCustomerEquipment(apId); - - try { - if (ce == null) { - - Customer customer = customerServiceInterface.getOrNull(autoProvisionedCustomerId); - if (customer == null) { - LOG.error("Cannot auto-provision equipment because customer with id {} is not found", - autoProvisionedCustomerId); - throw new IllegalStateException("Cannot auto-provision equipment because customer is not found : " - + autoProvisionedCustomerId); - } - - if ((customer.getDetails() != null) && (customer.getDetails().getAutoProvisioning() != null) - && !customer.getDetails().getAutoProvisioning().isEnabled()) { - LOG.error( - "Cannot auto-provision equipment because customer with id {} explicitly turned that feature off", - autoProvisionedCustomerId); - throw new IllegalStateException( - "Cannot auto-provision equipment because customer explicitly turned that feature off : " - + autoProvisionedCustomerId); - } - - // String dbUrlString = - // customer.getDetails().getClientFingerPrintsDbUrl(); - ce = new Equipment(); - ce.setEquipmentType(EquipmentType.AP); - ce.setInventoryId(apId); - try { - ce.setBaseMacAddress(new MacAddress(connectNodeInfo.macAddress)); - } catch (RuntimeException e) { - LOG.warn("Auto-provisioning: cannot parse equipment mac address {}", connectNodeInfo.macAddress); - } - - long locationId = autoProvisionedLocationId; - if ((customer.getDetails() != null) && (customer.getDetails().getAutoProvisioning() != null) - && customer.getDetails().getAutoProvisioning().isEnabled()) { - locationId = customer.getDetails().getAutoProvisioning().getLocationId(); - } - - try { - Location location = locationServiceInterface.get(locationId); - ce.setLocationId(location.getId()); - } catch (Exception e) { - LOG.error("Cannot auto-provision equipment because customer location with id {} cannot be found", - locationId); - throw new IllegalStateException( - "Cannot auto-provision equipment because customer location cannot be found : " - + locationId); - - } - - ce.setSerial(connectNodeInfo.serialNumber); - ce.setDetails(ApElementConfiguration.createWithDefaults()); - ce.setCustomerId(autoProvisionedCustomerId); - ce.setName(apId); - - ApElementConfiguration apElementConfig = (ApElementConfiguration) ce.getDetails(); - apElementConfig.setDeviceName(ce.getName()); - apElementConfig.setEquipmentModel(connectNodeInfo.model); - Map advancedRadioMap = new HashMap<>(); - Map radioMap = new HashMap<>(); - for (String radio : connectNodeInfo.wifiRadioStates.keySet()) { - RadioConfiguration advancedRadioConfiguration = null; - ElementRadioConfiguration radioConfiguration = null; - RadioType radioType = RadioType.UNSUPPORTED; - if (radio.equals("2.4G")) { - radioType = RadioType.is2dot4GHz; - } else if (radio.equals("5G")) { - radioType = RadioType.is5GHz; - } else if (radio.equals("5GL")) { - radioType = RadioType.is5GHzL; - } else if (radio.equals("5GU")) { - radioType = RadioType.is5GHzU; - } - if (!radioType.equals(RadioType.UNSUPPORTED)) { - advancedRadioConfiguration = RadioConfiguration.createWithDefaults(radioType); - - advancedRadioMap.put(radioType, advancedRadioConfiguration); - radioConfiguration = ElementRadioConfiguration.createWithDefaults(radioType); - radioMap.put(radioType, radioConfiguration); - } - } - - apElementConfig.setRadioMap(radioMap); - apElementConfig.setAdvancedRadioMap(advancedRadioMap); - - ce.setDetails(apElementConfig); - - Long profileId = null; - if ((customer.getDetails() != null) && (customer.getDetails().getAutoProvisioning() != null) - && customer.getDetails().getAutoProvisioning().isEnabled() - && (customer.getDetails().getAutoProvisioning().getEquipmentProfileIdPerModel() != null)) { - - // try to find auto-provisioning profile for the current - // equipment model - profileId = customer.getDetails().getAutoProvisioning().getEquipmentProfileIdPerModel() - .get(ce.getDetails().getEquipmentModel()); - if (profileId == null) { - // could not find profile for the equipment model, - // lets try to find a default profile - profileId = customer.getDetails().getAutoProvisioning().getEquipmentProfileIdPerModel() - .get(EquipmentAutoProvisioningSettings.DEFAULT_MODEL_NAME); - } - } - - if (profileId == null) { - // create default apProfile if cannot find applicable - // one: - Profile apProfile = createDefaultApProfile(ce, connectNodeInfo); - profileId = apProfile.getId(); - } - - ce.setProfileId(profileId); - - ce = equipmentServiceInterface.create(ce); - - // update the cache right away, no need to wait until the - // entry expires - cloudEquipmentRecordCache.put(ce.getInventoryId(), ce); - - } else { - // equipment already exists - - MacAddress reportedMacAddress = null; - try { - reportedMacAddress = new MacAddress(connectNodeInfo.macAddress); - } catch (RuntimeException e) { - LOG.warn("AP connect: cannot parse equipment mac address {}", connectNodeInfo.macAddress); - } - - if (reportedMacAddress != null) { - // check if reported mac address matches what is in the - // db - if (!reportedMacAddress.equals(ce.getBaseMacAddress())) { - // need to update base mac address on equipment in - // DB - ce = equipmentServiceInterface.get(ce.getId()); - ce.setBaseMacAddress(reportedMacAddress); - ce = equipmentServiceInterface.update(ce); - - // update the cache right away, no need to wait - // until the entry expires - cloudEquipmentRecordCache.put(ce.getInventoryId(), ce); - } - } - - } - - EquipmentRoutingRecord equipmentRoutingRecord = gatewayController.registerCustomerEquipment(ce.getName(), - ce.getCustomerId(), ce.getId()); - - updateApStatus(ce, connectNodeInfo); - - OvsdbSession ovsdbSession = ovsdbSessionMapInterface.getSession(apId); - ovsdbSession.setRoutingId(equipmentRoutingRecord.getId()); - ovsdbSession.setEquipmentId(ce.getId()); - ovsdbSession.setCustomerId(ce.getCustomerId()); - - LOG.debug("Equipment {}", ce); - LOG.info("AP {} got connected to the gateway", apId); - LOG.info("ConnectNodeInfo {}", connectNodeInfo); - - if (connectNodeInfo.versionMatrix.containsKey(OvsdbStringConstants.FW_IMAGE_ACTIVE_KEY)) { - reconcileFwVersionToTrack(ce, - connectNodeInfo.versionMatrix.get(OvsdbStringConstants.FW_IMAGE_ACTIVE_KEY), - connectNodeInfo.model); - } else { - LOG.info("Cloud based firmware upgrade is not supported for this AP"); - } - - } catch (Exception e) { - LOG.error("Could not process connection from AP {}", apId, e); - throw e; - } - - } - - private Profile createDefaultApProfile(Equipment ce, ConnectNodeInfo connectNodeInfo) { - Profile apProfile = new Profile(); - apProfile.setCustomerId(ce.getCustomerId()); - apProfile.setName("DefaultApProfile for " + ce.getName()); - apProfile.setDetails(ApNetworkConfiguration.createWithDefaults()); - apProfile = profileServiceInterface.create(apProfile); - - ApNetworkConfiguration apNetworkConfig = (ApNetworkConfiguration) apProfile.getDetails(); - Map radioProfileMap = new HashMap<>(); - - for (String radioBand : connectNodeInfo.wifiRadioStates.keySet()) { - - RadioType radioType = OvsdbToWlanCloudTypeMappingUtility.getRadioTypeForOvsdbRadioFreqBand(radioBand); - if (!radioType.equals(RadioType.UNSUPPORTED)) { - radioProfileMap.put(radioType, RadioProfileConfiguration.createWithDefaults(radioType)); - } - - } - - apNetworkConfig.setRadioMap(radioProfileMap); - - apProfile.setDetails(apNetworkConfig); - - apProfile = profileServiceInterface.update(apProfile); - - apNetworkConfig = (ApNetworkConfiguration) apProfile.getDetails(); - - Set radioTypes = radioProfileMap.keySet(); - - for (RadioType radioType : radioTypes) { - // SSID Profile init - Profile ssidProfile = new Profile(); - ssidProfile.setCustomerId(ce.getCustomerId()); - ssidProfile.setName(autoProvisionedSsid + radioType.name() + " for " + ce.getName()); - SsidConfiguration ssidConfig = SsidConfiguration.createWithDefaults(); - - ssidConfig.setSsid(ssidProfile.getName()); - ssidConfig.setSsidAdminState(StateSetting.enabled); - ssidConfig.setBroadcastSsid(StateSetting.enabled); - ssidConfig.setSecureMode(SecureMode.wpa2PSK); - ssidConfig.setKeyStr(autoprovisionedSsidKey); - - Set appliedRadios = new HashSet<>(); - appliedRadios.add(radioType); - ssidConfig.setAppliedRadios(appliedRadios); - ssidProfile.setDetails(ssidConfig); - ssidProfile = profileServiceInterface.create(ssidProfile); - - apProfile.getChildProfileIds().add(ssidProfile.getId()); - } - - // RF Profile Init - Profile rfProfile = new Profile(); - rfProfile.setCustomerId(ce.getCustomerId()); - rfProfile.setName("DefaultRf for " + ce.getName()); - RfConfiguration rfConfig = RfConfiguration.createWithDefaults(); - - // Override default values - for (RadioType radioType : radioTypes) { - rfConfig.getRfConfig(radioType).setRf(rfProfile.getName()); - } - - rfProfile.setDetails(rfConfig); - rfProfile = profileServiceInterface.create(rfProfile); - - apProfile.getChildProfileIds().add(rfProfile.getId()); - - - // Update AP profile with SSID and RF child profiles - apProfile = profileServiceInterface.update(apProfile); - - return apProfile; - } - - private void updateApStatus(Equipment ce, ConnectNodeInfo connectNodeInfo) { - - try { - - Status statusRecord = statusServiceInterface.getOrNull(ce.getCustomerId(), ce.getId(), - StatusDataType.EQUIPMENT_ADMIN); - if (statusRecord == null) { - statusRecord = new Status(); - statusRecord.setCustomerId(ce.getCustomerId()); - statusRecord.setEquipmentId(ce.getId()); - EquipmentAdminStatusData statusData = new EquipmentAdminStatusData(); - statusRecord.setDetails(statusData); - } - - ((EquipmentAdminStatusData) statusRecord.getDetails()).setStatusCode(StatusCode.normal); - // Update the equipment admin status - statusRecord = statusServiceInterface.update(statusRecord); - - // update LAN status - nothing to do here for now - statusRecord = statusServiceInterface.getOrNull(ce.getCustomerId(), ce.getId(), StatusDataType.LANINFO); - if (statusRecord == null) { - statusRecord = new Status(); - statusRecord.setCustomerId(ce.getCustomerId()); - statusRecord.setEquipmentId(ce.getId()); - - EquipmentLANStatusData statusData = new EquipmentLANStatusData(); - statusRecord.setDetails(statusData); - } - - Map vlanStatusDataMap = new HashMap<>(); - ((EquipmentLANStatusData) statusRecord.getDetails()).setVlanStatusDataMap(vlanStatusDataMap); - - statusServiceInterface.update(statusRecord); - - // update protocol status - statusRecord = statusServiceInterface.getOrNull(ce.getCustomerId(), ce.getId(), StatusDataType.PROTOCOL); - if (statusRecord == null) { - statusRecord = new Status(); - statusRecord.setCustomerId(ce.getCustomerId()); - statusRecord.setEquipmentId(ce.getId()); - - EquipmentProtocolStatusData statusData = new EquipmentProtocolStatusData(); - statusRecord.setDetails(statusData); - } - - EquipmentProtocolStatusData protocolStatusData = (EquipmentProtocolStatusData) statusRecord.getDetails(); - protocolStatusData.setPoweredOn(true); - protocolStatusData.setCloudProtocolVersion("1100"); - protocolStatusData.setProtocolState(EquipmentProtocolState.ready); - protocolStatusData.setBandPlan("FCC"); - protocolStatusData.setBaseMacAddress(MacAddress.valueOf(connectNodeInfo.macAddress)); - protocolStatusData.setCloudCfgDataVersion(42L); - protocolStatusData.setReportedCfgDataVersion(42L); - protocolStatusData.setCountryCode("CA"); - protocolStatusData.setReportedCC(CountryCode.ca); - protocolStatusData.setReportedHwVersion(connectNodeInfo.platformVersion); - if (connectNodeInfo.versionMatrix.containsKey(OvsdbStringConstants.FW_IMAGE_ACTIVE_KEY)) { - protocolStatusData.setReportedSwVersion( - connectNodeInfo.versionMatrix.get(OvsdbStringConstants.FW_IMAGE_ACTIVE_KEY)); - } else if (connectNodeInfo.versionMatrix.containsKey(OvsdbStringConstants.FW_IMAGE_NAME_KEY)) { - protocolStatusData.setReportedSwVersion( - connectNodeInfo.versionMatrix.get(OvsdbStringConstants.FW_IMAGE_NAME_KEY)); - } else { - protocolStatusData.setReportedSwVersion("Unknown"); - } - if (connectNodeInfo.versionMatrix.containsKey(OvsdbStringConstants.FW_IMAGE_INACTIVE_KEY)) { - protocolStatusData.setReportedSwAltVersion( - connectNodeInfo.versionMatrix.get(OvsdbStringConstants.FW_IMAGE_INACTIVE_KEY)); - } else if (connectNodeInfo.versionMatrix.containsKey(OvsdbStringConstants.FW_IMAGE_NAME_KEY)) { - protocolStatusData.setReportedSwVersion( - connectNodeInfo.versionMatrix.get(OvsdbStringConstants.FW_IMAGE_NAME_KEY)); - } else { - protocolStatusData.setReportedSwVersion("Unknown"); - } - try { - protocolStatusData.setReportedIpV4Addr(InetAddress.getByName(connectNodeInfo.ipV4Address)); - } catch (UnknownHostException e) { - // do nothing here - } - if ((connectNodeInfo.macAddress != null) && (MacAddress.valueOf(connectNodeInfo.macAddress) != null)) { - protocolStatusData.setReportedMacAddr(MacAddress.valueOf(connectNodeInfo.macAddress)); - } - protocolStatusData.setReportedSku(connectNodeInfo.skuNumber); - protocolStatusData.setSerialNumber(connectNodeInfo.serialNumber); - protocolStatusData.setSystemName(connectNodeInfo.model); - statusRecord.setDetails(protocolStatusData); - statusServiceInterface.update(statusRecord); - - statusRecord = statusServiceInterface.getOrNull(ce.getCustomerId(), ce.getId(), StatusDataType.FIRMWARE); - if (statusRecord == null) { - statusRecord = new Status(); - statusRecord.setCustomerId(ce.getCustomerId()); - statusRecord.setEquipmentId(ce.getId()); - EquipmentUpgradeStatusData statusData = new EquipmentUpgradeStatusData(); - statusRecord.setDetails(statusData); - } - - EquipmentUpgradeStatusData fwUpgradeStatusData = (EquipmentUpgradeStatusData) statusRecord.getDetails(); - if (connectNodeInfo.versionMatrix.containsKey(OvsdbStringConstants.FW_IMAGE_ACTIVE_KEY)) { - fwUpgradeStatusData.setActiveSwVersion( - connectNodeInfo.versionMatrix.get(OvsdbStringConstants.FW_IMAGE_ACTIVE_KEY)); - } else if (connectNodeInfo.versionMatrix.containsKey(OvsdbStringConstants.FW_IMAGE_NAME_KEY)) { - fwUpgradeStatusData - .setActiveSwVersion(connectNodeInfo.versionMatrix.get(OvsdbStringConstants.FW_IMAGE_NAME_KEY)); - } else { - fwUpgradeStatusData.setActiveSwVersion("Unknown"); - } - if (connectNodeInfo.versionMatrix.containsKey(OvsdbStringConstants.FW_IMAGE_INACTIVE_KEY)) { - fwUpgradeStatusData.setAlternateSwVersion( - connectNodeInfo.versionMatrix.get(OvsdbStringConstants.FW_IMAGE_INACTIVE_KEY)); - } else if (connectNodeInfo.versionMatrix.containsKey(OvsdbStringConstants.FW_IMAGE_NAME_KEY)) { - fwUpgradeStatusData.setAlternateSwVersion( - connectNodeInfo.versionMatrix.get(OvsdbStringConstants.FW_IMAGE_NAME_KEY)); - } else { - fwUpgradeStatusData.setAlternateSwVersion("Unknown"); - } - - if (fwUpgradeStatusData.getUpgradeState() == null) { - fwUpgradeStatusData.setUpgradeState(EquipmentUpgradeState.undefined); - fwUpgradeStatusData.setUpgradeStartTime(null); - - } - - statusRecord.setDetails(fwUpgradeStatusData); - statusServiceInterface.update(statusRecord); - - Status networkAdminStatusRec = statusServiceInterface.getOrNull(ce.getCustomerId(), ce.getId(), - StatusDataType.NETWORK_ADMIN); - if (networkAdminStatusRec == null) { - networkAdminStatusRec = new Status(); - networkAdminStatusRec.setCustomerId(ce.getCustomerId()); - networkAdminStatusRec.setEquipmentId(ce.getId()); - NetworkAdminStatusData statusData = new NetworkAdminStatusData(); - networkAdminStatusRec.setDetails(statusData); - } - - NetworkAdminStatusData netAdminStatusData = (NetworkAdminStatusData) networkAdminStatusRec.getDetails(); - netAdminStatusData.setDhcpStatus(StatusCode.normal); - netAdminStatusData.setCloudLinkStatus(StatusCode.normal); - netAdminStatusData.setDnsStatus(StatusCode.normal); - - networkAdminStatusRec.setDetails(netAdminStatusData); - - networkAdminStatusRec = statusServiceInterface.update(networkAdminStatusRec); - - } catch (Exception e) { - LOG.debug("Exception in updateApStatus", e); - } - - } - - private void reconcileFwVersionToTrack(Equipment ce, String reportedFwVersionFromAp, String model) { - - LOG.debug("reconcileFwVersionToTrack for AP {} with active firmware version {} model {}", ce.getInventoryId(), - reportedFwVersionFromAp, model); - Status statusRecord = statusServiceInterface.getOrNull(ce.getCustomerId(), ce.getId(), StatusDataType.FIRMWARE); - - EquipmentUpgradeStatusData fwUpgradeStatusData = (EquipmentUpgradeStatusData) statusRecord.getDetails(); - - // default track settings for firmware - CustomerFirmwareTrackSettings trackSettings = firmwareServiceInterface.getDefaultCustomerTrackSetting(); - - // check for updated/modified track settings for this customer - CustomerFirmwareTrackRecord custFwTrackRecord = firmwareServiceInterface - .getCustomerFirmwareTrackRecord(ce.getCustomerId()); - - long trackRecordId = -1; - if (custFwTrackRecord != null) { - trackSettings = custFwTrackRecord.getSettings(); - trackRecordId = custFwTrackRecord.getTrackRecordId(); - } - // determine if AP requires FW upgrade before cloud - // connection/provision - if (trackSettings.getAutoUpgradeDeprecatedOnBind().equals(TrackFlag.ALWAYS) - || trackSettings.getAutoUpgradeUnknownOnBind().equals(TrackFlag.ALWAYS)) { - - LOG.debug("reconcileFwVersionToTrack for AP {} track flag for auto-upgrade {}", ce.getInventoryId(), - trackSettings.getAutoUpgradeDeprecatedOnBind()); - - // check the reported fw version for the AP, if it is < than - // the default version for the cloud, then download and - // flash the firmware before proceeding. - // then return; - FirmwareTrackRecord fwTrackRecord = null; - if (trackRecordId == -1) { - // take the default - fwTrackRecord = firmwareServiceInterface.getFirmwareTrackByName(FirmwareTrackRecord.DEFAULT_TRACK_NAME); - - } else { - // there must be a customer one - fwTrackRecord = firmwareServiceInterface.getFirmwareTrackById(trackRecordId); - } - - if (fwTrackRecord != null) { - - LOG.debug("reconcileFwVersionToTrack for AP {} firmwareTrackRecord {}", ce.getInventoryId(), - fwTrackRecord); - - List fwTrackAssignmentDetails = firmwareServiceInterface - .getFirmwareTrackAssignments(fwTrackRecord.getTrackName()); - - String targetFwVersionNameForTrack = null; - - if (fwTrackAssignmentDetails != null) { - for (FirmwareTrackAssignmentDetails details : fwTrackAssignmentDetails) { - if (model.equalsIgnoreCase(details.getModelId())) { - targetFwVersionNameForTrack = details.getVersionName(); - break; - } - } - } - - if (targetFwVersionNameForTrack == null) { - LOG.info("No target FW version for this track {}", fwTrackRecord); - - } else { - LOG.debug("reconcileFwVersionToTrack for AP {} targetFwVersion for track {}", ce.getInventoryId(), - targetFwVersionNameForTrack); - - if (reportedFwVersionFromAp != null) { - if (!targetFwVersionNameForTrack.equals(reportedFwVersionFromAp)) { - LOG.debug( - "reconcileFwVersionToTrack for AP {} targetFwVersion {} doesn't match reported fw version {}, triggering download and flash", - ce.getInventoryId(), targetFwVersionNameForTrack, reportedFwVersionFromAp); - - fwUpgradeStatusData.setTargetSwVersion(targetFwVersionNameForTrack); - fwUpgradeStatusData.setUpgradeState(EquipmentUpgradeState.out_of_date); - statusRecord.setDetails(fwUpgradeStatusData); - statusRecord = statusServiceInterface.update(statusRecord); - triggerFwDownload(ce, fwUpgradeStatusData, trackSettings); - } else if (targetFwVersionNameForTrack.equals(reportedFwVersionFromAp)) { - LOG.debug("reconcileFwVersionToTrack for AP {} targetFwVersion {} is active", - ce.getInventoryId(), targetFwVersionNameForTrack); - - fwUpgradeStatusData.setUpgradeState(EquipmentUpgradeState.up_to_date); - fwUpgradeStatusData.setActiveSwVersion(targetFwVersionNameForTrack); - fwUpgradeStatusData.setAlternateSwVersion(targetFwVersionNameForTrack); - fwUpgradeStatusData.setTargetSwVersion(targetFwVersionNameForTrack); - - statusRecord.setDetails(fwUpgradeStatusData); - statusRecord = statusServiceInterface.update(statusRecord); - - } - } - - } - - } - - } else - - { - LOG.debug("Automatic firmware upgrade is not configured for track {}", trackSettings); - } - } - - private void triggerFwDownload(Equipment ce, EquipmentUpgradeStatusData fwUpgradeStatusData, - CustomerFirmwareTrackSettings trackSettings) { - LOG.debug("triggerFwDownloadAndFlash Automatic firmware upgrade is configured for track {}.", trackSettings); - - try { - FirmwareVersion fwVersion = firmwareServiceInterface - .getFirmwareVersionByName(fwUpgradeStatusData.getTargetSwVersion()); - - if (fwVersion != null) { - OvsdbSession ovsdbSession = ovsdbSessionMapInterface.getSession(ce.getInventoryId()); - if (ovsdbSession == null) { - throw new IllegalStateException("AP is not connected " + ce.getInventoryId()); - } - - CEGWFirmwareDownloadRequest fwDownloadRequest = new CEGWFirmwareDownloadRequest(ce.getInventoryId(), - ce.getId(), fwVersion.getVersionName(), fwVersion.getFilename(), - fwVersion.getValidationMethod(), fwVersion.getValidationCode()); - List commands = new ArrayList<>(); - commands.add(fwDownloadRequest); - - gatewayController.updateActiveCustomer(ce.getCustomerId()); - ListOfEquipmentCommandResponses responses = gatewayController.sendCommands(commands); - LOG.debug("FW Download Response {}", responses); - - } - } catch (Exception e) { - LOG.error("Cannot trigger FW download {}", e); - } - } - - @Override - public void apDisconnected(String apId) { - LOG.info("AP {} got disconnected from the gateway", apId); - try { - - OvsdbSession ovsdbSession = ovsdbSessionMapInterface.getSession(apId); - - if (ovsdbSession != null) { - // if (ovsdbSession.getCustomerId() > 0 && - // ovsdbSession.getEquipmentId() > 0L) { - // List statusForDisconnectedAp = - // statusServiceInterface.delete(ovsdbSession.getCustomerId(), - // ovsdbSession.getEquipmentId()); - // LOG.info("Deleted status records {} for AP {}", - // statusForDisconnectedAp, apId); - // } - if (ovsdbSession.getRoutingId() > 0L) { - try { - routingServiceInterface.delete(ovsdbSession.getRoutingId()); - } catch (Exception e) { - LOG.warn("Unable to delete routing service Id {} for ap {}. {}", ovsdbSession.getRoutingId(), - apId, e); - } - } - } else { - LOG.warn("Cannot find ap {} in inventory", apId); - } - } catch (Exception e) { - LOG.error("Exception when registering ap routing {}", apId, e); - } - - } - - @Override - public OpensyncAPConfig getApConfig(String apId) { - LOG.info("Retrieving config for AP {} ", apId); - OpensyncAPConfig ret = null; - - try { - - OvsdbSession ovsdbSession = ovsdbSessionMapInterface.getSession(apId); - if (ovsdbSession == null) { - throw new IllegalStateException("AP is not connected " + apId); - } - int customerId = ovsdbSession.getCustomerId(); - Customer customer = customerServiceInterface.getOrNull(customerId); - if ((customer != null) && (customer.getDetails() != null) - && (customer.getDetails().getAutoProvisioning() != null) - && customer.getDetails().getAutoProvisioning().isEnabled()) { - Equipment equipmentConfig = getCustomerEquipment(apId); - - if (equipmentConfig == null) { - throw new IllegalStateException("Cannot retrieve configuration for " + apId); - } - - ret = new OpensyncAPConfig(); - - ret.setCustomerEquipment(equipmentConfig); - - Location eqLocation = locationServiceInterface.get(equipmentConfig.getLocationId()); - - ret.setEquipmentLocation(eqLocation); - - ProfileContainer profileContainer = new ProfileContainer( - profileServiceInterface.getProfileWithChildren(equipmentConfig.getProfileId())); - - ret.setApProfile(profileContainer.getOrNull(equipmentConfig.getProfileId())); - - ret.setRfProfile(profileContainer.getChildOfTypeOrNull(equipmentConfig.getProfileId(), ProfileType.rf)); - - ret.setSsidProfile( - profileContainer.getChildrenOfType(equipmentConfig.getProfileId(), ProfileType.ssid)); - - ret.setMetricsProfiles( - profileContainer.getChildrenOfType(equipmentConfig.getProfileId(), ProfileType.metrics)); - - Set radiusSet = new HashSet<>(); - Set captiveProfileIds = new HashSet<>(); - Set bonjourGatewayProfileIds = new HashSet<>(); - - OpensyncAPHotspot20Config hotspotConfig = new OpensyncAPHotspot20Config(); - - Set hotspot20ProfileSet = new HashSet<>(); - Set hotspot20OperatorSet = new HashSet<>(); - Set hotspot20VenueSet = new HashSet<>(); - Set hotspot20ProviderSet = new HashSet<>(); - - for (Profile ssidProfile : ret.getSsidProfile()) { - - hotspot20ProfileSet - .addAll(profileContainer.getChildrenOfType(ssidProfile.getId(), ProfileType.hotspot_2pt0)); - - - radiusSet.addAll(profileContainer.getChildrenOfType(ret.getApProfile().getId(), ProfileType.radius)); - if (ssidProfile.getDetails() != null) { - Long captivePortId = ((SsidConfiguration) ssidProfile.getDetails()).getCaptivePortalId(); - if (captivePortId != null) { - captiveProfileIds.add(captivePortId); - } - Long bonjourGatewayProfileId = ((SsidConfiguration) ssidProfile.getDetails()) - .getBonjourGatewayProfileId(); - if (bonjourGatewayProfileId != null) { - bonjourGatewayProfileIds.add(bonjourGatewayProfileId); - } - } - } - - - - if (hotspot20ProfileSet.size() > 0) { - for (Profile hotspot20Profile : hotspot20ProfileSet) { - hotspot20OperatorSet.addAll(profileContainer.getChildrenOfType(hotspot20Profile.getId(), ProfileType.operator)); - hotspot20VenueSet.addAll(profileContainer.getChildrenOfType(hotspot20Profile.getId(), ProfileType.venue)); - hotspot20ProviderSet.addAll(profileContainer.getChildrenOfType(hotspot20Profile.getId(), ProfileType.id_provider)); - } - hotspotConfig.setHotspot20OperatorSet(hotspot20OperatorSet); - hotspotConfig.setHotspot20ProfileSet(hotspot20ProfileSet); - hotspotConfig.setHotspot20ProviderSet(hotspot20ProviderSet); - hotspotConfig.setHotspot20VenueSet(hotspot20VenueSet); - - ret.setHotspotConfig(hotspotConfig); - } - - ret.setRadiusProfiles(new ArrayList<>(radiusSet)); - ret.setCaptiveProfiles(profileServiceInterface.get(captiveProfileIds)); - ret.setBonjourGatewayProfiles(profileServiceInterface.get(bonjourGatewayProfileIds)); - - List blockedClients = clientServiceInterface - .getBlockedClients(customerId); - List blockList = Lists.newArrayList(); - if ((blockedClients != null) && !blockedClients.isEmpty()) { - blockedClients.forEach(client -> blockList.add(client.getMacAddress())); - } - ret.setBlockedClients(blockList); - - LOG.debug("ApConfig {}", ret); - } else { - LOG.info("Autoconfig is not enabled for this AP {}", apId); - } - - } catch (Exception e) { - LOG.error("Cannot read config for AP {}", apId, e); - } - - return ret; - } - - @Override - public void processMqttMessage(String topic, Report report) { - mqttMessageProcessor.processMqttMessage(topic, report); - } + private static final Logger LOG = LoggerFactory.getLogger(OpensyncExternalIntegrationCloud.class); + + @Autowired + private CustomerServiceInterface customerServiceInterface; + @Autowired + private LocationServiceInterface locationServiceInterface; + @Autowired + private OvsdbSessionMapInterface ovsdbSessionMapInterface; + @Autowired + private EquipmentServiceInterface equipmentServiceInterface; + @Autowired + private RoutingServiceInterface routingServiceInterface; + @Autowired + private ProfileServiceInterface profileServiceInterface; + @Autowired + private StatusServiceInterface statusServiceInterface; + @Autowired + private ClientServiceInterface clientServiceInterface; + @Autowired + private FirmwareServiceInterface firmwareServiceInterface; + @Autowired + private OpensyncExternalIntegrationMqttMessageProcessor mqttMessageProcessor; + + @Autowired + private OpensyncCloudGatewayController gatewayController; + + @Value("${tip.wlan.ovsdb.autoProvisionedCustomerId:1970}") + private int autoProvisionedCustomerId; + @Value("${tip.wlan.ovsdb.autoProvisionedLocationId:8}") + private int autoProvisionedLocationId; + @Value("${tip.wlan.ovsdb.autoProvisionedProfileId:1}") + private int autoProvisionedProfileId; + @Value("${tip.wlan.ovsdb.autoProvisionedSsid:DefaultSsid-}") + private String autoProvisionedSsid; + @Value("${tip.wlan.ovsdb.autoprovisionedSsidKey:12345678}") + private String autoprovisionedSsidKey; + @Value("${tip.wlan.ovsdb.isAutoconfigEnabled:true}") + private boolean isAutoconfigEnabled; + @Value("${tip.wlan.ovsdb.defaultFwVersion:r10947-65030d81f3}") + private String defaultFwVersion; + + @Autowired + private CacheManager cacheManagerShortLived; + private Cache cloudEquipmentRecordCache; + + @PostConstruct + private void postCreate() { + LOG.info("Using Cloud integration"); + cloudEquipmentRecordCache = cacheManagerShortLived.getCache("equipment_record_cache"); + } + + public Equipment getCustomerEquipment(String apId) { + Equipment ce = null; + + try { + ce = cloudEquipmentRecordCache.get(apId, () -> equipmentServiceInterface.getByInventoryIdOrNull(apId)); + } catch (Exception e) { + LOG.error("Could not get customer equipment for {}", apId, e); + } + + return ce; + } + + @Override + public void apConnected(String apId, ConnectNodeInfo connectNodeInfo) { + + Equipment ce = getCustomerEquipment(apId); + + try { + if (ce == null) { + + Customer customer = customerServiceInterface.getOrNull(autoProvisionedCustomerId); + if (customer == null) { + LOG.error("Cannot auto-provision equipment because customer with id {} is not found", + autoProvisionedCustomerId); + throw new IllegalStateException("Cannot auto-provision equipment because customer is not found : " + + autoProvisionedCustomerId); + } + + if ((customer.getDetails() != null) && (customer.getDetails().getAutoProvisioning() != null) + && !customer.getDetails().getAutoProvisioning().isEnabled()) { + LOG.error( + "Cannot auto-provision equipment because customer with id {} explicitly turned that feature off", + autoProvisionedCustomerId); + throw new IllegalStateException( + "Cannot auto-provision equipment because customer explicitly turned that feature off : " + + autoProvisionedCustomerId); + } + + // String dbUrlString = + // customer.getDetails().getClientFingerPrintsDbUrl(); + ce = new Equipment(); + ce.setEquipmentType(EquipmentType.AP); + ce.setInventoryId(apId); + try { + ce.setBaseMacAddress(new MacAddress(connectNodeInfo.macAddress)); + } catch (RuntimeException e) { + LOG.warn("Auto-provisioning: cannot parse equipment mac address {}", connectNodeInfo.macAddress); + } + + long locationId = autoProvisionedLocationId; + if ((customer.getDetails() != null) && (customer.getDetails().getAutoProvisioning() != null) + && customer.getDetails().getAutoProvisioning().isEnabled()) { + locationId = customer.getDetails().getAutoProvisioning().getLocationId(); + } + + try { + Location location = locationServiceInterface.get(locationId); + ce.setLocationId(location.getId()); + } catch (Exception e) { + LOG.error("Cannot auto-provision equipment because customer location with id {} cannot be found", + locationId); + throw new IllegalStateException( + "Cannot auto-provision equipment because customer location cannot be found : " + + locationId); + + } + + ce.setSerial(connectNodeInfo.serialNumber); + ce.setDetails(ApElementConfiguration.createWithDefaults()); + ce.setCustomerId(autoProvisionedCustomerId); + ce.setName(apId); + + ApElementConfiguration apElementConfig = (ApElementConfiguration) ce.getDetails(); + apElementConfig.setDeviceName(ce.getName()); + apElementConfig.setEquipmentModel(connectNodeInfo.model); + Map advancedRadioMap = new HashMap<>(); + Map radioMap = new HashMap<>(); + for (String radio : connectNodeInfo.wifiRadioStates.keySet()) { + RadioConfiguration advancedRadioConfiguration = null; + ElementRadioConfiguration radioConfiguration = null; + RadioType radioType = RadioType.UNSUPPORTED; + if (radio.equals("2.4G")) { + radioType = RadioType.is2dot4GHz; + } else if (radio.equals("5G")) { + radioType = RadioType.is5GHz; + } else if (radio.equals("5GL")) { + radioType = RadioType.is5GHzL; + } else if (radio.equals("5GU")) { + radioType = RadioType.is5GHzU; + } + if (!radioType.equals(RadioType.UNSUPPORTED)) { + advancedRadioConfiguration = RadioConfiguration.createWithDefaults(radioType); + + advancedRadioMap.put(radioType, advancedRadioConfiguration); + radioConfiguration = ElementRadioConfiguration.createWithDefaults(radioType); + radioMap.put(radioType, radioConfiguration); + } + } + + apElementConfig.setRadioMap(radioMap); + apElementConfig.setAdvancedRadioMap(advancedRadioMap); + + ce.setDetails(apElementConfig); + + Long profileId = null; + if ((customer.getDetails() != null) && (customer.getDetails().getAutoProvisioning() != null) + && customer.getDetails().getAutoProvisioning().isEnabled() + && (customer.getDetails().getAutoProvisioning().getEquipmentProfileIdPerModel() != null)) { + + // try to find auto-provisioning profile for the current + // equipment model + profileId = customer.getDetails().getAutoProvisioning().getEquipmentProfileIdPerModel() + .get(ce.getDetails().getEquipmentModel()); + if (profileId == null) { + // could not find profile for the equipment model, + // lets try to find a default profile + profileId = customer.getDetails().getAutoProvisioning().getEquipmentProfileIdPerModel() + .get(EquipmentAutoProvisioningSettings.DEFAULT_MODEL_NAME); + } + } + + if (profileId == null) { + // create default apProfile if cannot find applicable + // one: + Profile apProfile = createDefaultApProfile(ce, connectNodeInfo); + profileId = apProfile.getId(); + } + + ce.setProfileId(profileId); + + ce = equipmentServiceInterface.create(ce); + + // update the cache right away, no need to wait until the + // entry expires + cloudEquipmentRecordCache.put(ce.getInventoryId(), ce); + + } else { + // equipment already exists + + MacAddress reportedMacAddress = null; + try { + reportedMacAddress = new MacAddress(connectNodeInfo.macAddress); + } catch (RuntimeException e) { + LOG.warn("AP connect: cannot parse equipment mac address {}", connectNodeInfo.macAddress); + } + + if (reportedMacAddress != null) { + // check if reported mac address matches what is in the + // db + if (!reportedMacAddress.equals(ce.getBaseMacAddress())) { + // need to update base mac address on equipment in + // DB + ce = equipmentServiceInterface.get(ce.getId()); + ce.setBaseMacAddress(reportedMacAddress); + ce = equipmentServiceInterface.update(ce); + + // update the cache right away, no need to wait + // until the entry expires + cloudEquipmentRecordCache.put(ce.getInventoryId(), ce); + } + } + + } + + EquipmentRoutingRecord equipmentRoutingRecord = gatewayController.registerCustomerEquipment(ce.getName(), + ce.getCustomerId(), ce.getId()); + + updateApStatus(ce, connectNodeInfo); + + OvsdbSession ovsdbSession = ovsdbSessionMapInterface.getSession(apId); + ovsdbSession.setRoutingId(equipmentRoutingRecord.getId()); + ovsdbSession.setEquipmentId(ce.getId()); + ovsdbSession.setCustomerId(ce.getCustomerId()); + + LOG.debug("Equipment {}", ce); + LOG.info("AP {} got connected to the gateway", apId); + LOG.info("ConnectNodeInfo {}", connectNodeInfo); + + if (connectNodeInfo.versionMatrix.containsKey(OvsdbStringConstants.FW_IMAGE_ACTIVE_KEY)) { + reconcileFwVersionToTrack(ce, + connectNodeInfo.versionMatrix.get(OvsdbStringConstants.FW_IMAGE_ACTIVE_KEY), + connectNodeInfo.model); + } else { + LOG.info("Cloud based firmware upgrade is not supported for this AP"); + } + + } catch (Exception e) { + LOG.error("Could not process connection from AP {}", apId, e); + throw e; + } + + } + + private Profile createDefaultApProfile(Equipment ce, ConnectNodeInfo connectNodeInfo) { + Profile apProfile = new Profile(); + apProfile.setCustomerId(ce.getCustomerId()); + apProfile.setName("DefaultApProfile for " + ce.getName()); + apProfile.setDetails(ApNetworkConfiguration.createWithDefaults()); + apProfile = profileServiceInterface.create(apProfile); + + ApNetworkConfiguration apNetworkConfig = (ApNetworkConfiguration) apProfile.getDetails(); + Map radioProfileMap = new HashMap<>(); + + for (String radioBand : connectNodeInfo.wifiRadioStates.keySet()) { + + RadioType radioType = OvsdbToWlanCloudTypeMappingUtility.getRadioTypeForOvsdbRadioFreqBand(radioBand); + if (!radioType.equals(RadioType.UNSUPPORTED)) { + radioProfileMap.put(radioType, RadioProfileConfiguration.createWithDefaults(radioType)); + } + + } + + apNetworkConfig.setRadioMap(radioProfileMap); + + apProfile.setDetails(apNetworkConfig); + + apProfile = profileServiceInterface.update(apProfile); + + apNetworkConfig = (ApNetworkConfiguration) apProfile.getDetails(); + + Set radioTypes = radioProfileMap.keySet(); + + for (RadioType radioType : radioTypes) { + // SSID Profile init + Profile ssidProfile = new Profile(); + ssidProfile.setCustomerId(ce.getCustomerId()); + ssidProfile.setName(autoProvisionedSsid + radioType.name() + " for " + ce.getName()); + SsidConfiguration ssidConfig = SsidConfiguration.createWithDefaults(); + + ssidConfig.setSsid(ssidProfile.getName()); + ssidConfig.setSsidAdminState(StateSetting.enabled); + ssidConfig.setBroadcastSsid(StateSetting.enabled); + ssidConfig.setSecureMode(SecureMode.wpa2PSK); + ssidConfig.setKeyStr(autoprovisionedSsidKey); + + Set appliedRadios = new HashSet<>(); + appliedRadios.add(radioType); + ssidConfig.setAppliedRadios(appliedRadios); + ssidProfile.setDetails(ssidConfig); + ssidProfile = profileServiceInterface.create(ssidProfile); + + apProfile.getChildProfileIds().add(ssidProfile.getId()); + } + + // RF Profile Init + Profile rfProfile = new Profile(); + rfProfile.setCustomerId(ce.getCustomerId()); + rfProfile.setName("DefaultRf for " + ce.getName()); + RfConfiguration rfConfig = RfConfiguration.createWithDefaults(); + + // Override default values + for (RadioType radioType : radioTypes) { + rfConfig.getRfConfig(radioType).setRf(rfProfile.getName()); + } + + rfProfile.setDetails(rfConfig); + rfProfile = profileServiceInterface.create(rfProfile); + + apProfile.getChildProfileIds().add(rfProfile.getId()); + + // Update AP profile with SSID and RF child profiles + apProfile = profileServiceInterface.update(apProfile); + + return apProfile; + } + + private void updateApStatus(Equipment ce, ConnectNodeInfo connectNodeInfo) { + + try { + + Status statusRecord = statusServiceInterface.getOrNull(ce.getCustomerId(), ce.getId(), + StatusDataType.EQUIPMENT_ADMIN); + if (statusRecord == null) { + statusRecord = new Status(); + statusRecord.setCustomerId(ce.getCustomerId()); + statusRecord.setEquipmentId(ce.getId()); + EquipmentAdminStatusData statusData = new EquipmentAdminStatusData(); + statusRecord.setDetails(statusData); + } + + ((EquipmentAdminStatusData) statusRecord.getDetails()).setStatusCode(StatusCode.normal); + // Update the equipment admin status + statusRecord = statusServiceInterface.update(statusRecord); + + // update LAN status - nothing to do here for now + statusRecord = statusServiceInterface.getOrNull(ce.getCustomerId(), ce.getId(), StatusDataType.LANINFO); + if (statusRecord == null) { + statusRecord = new Status(); + statusRecord.setCustomerId(ce.getCustomerId()); + statusRecord.setEquipmentId(ce.getId()); + + EquipmentLANStatusData statusData = new EquipmentLANStatusData(); + statusRecord.setDetails(statusData); + } + + Map vlanStatusDataMap = new HashMap<>(); + ((EquipmentLANStatusData) statusRecord.getDetails()).setVlanStatusDataMap(vlanStatusDataMap); + + statusServiceInterface.update(statusRecord); + + // update protocol status + statusRecord = statusServiceInterface.getOrNull(ce.getCustomerId(), ce.getId(), StatusDataType.PROTOCOL); + if (statusRecord == null) { + statusRecord = new Status(); + statusRecord.setCustomerId(ce.getCustomerId()); + statusRecord.setEquipmentId(ce.getId()); + + EquipmentProtocolStatusData statusData = new EquipmentProtocolStatusData(); + statusRecord.setDetails(statusData); + } + + EquipmentProtocolStatusData protocolStatusData = (EquipmentProtocolStatusData) statusRecord.getDetails(); + protocolStatusData.setPoweredOn(true); + protocolStatusData.setCloudProtocolVersion("1100"); + protocolStatusData.setProtocolState(EquipmentProtocolState.ready); + protocolStatusData.setBandPlan("FCC"); + protocolStatusData.setBaseMacAddress(MacAddress.valueOf(connectNodeInfo.macAddress)); + protocolStatusData.setCloudCfgDataVersion(42L); + protocolStatusData.setReportedCfgDataVersion(42L); + protocolStatusData.setCountryCode("CA"); + protocolStatusData.setReportedCC(CountryCode.ca); + protocolStatusData.setReportedHwVersion(connectNodeInfo.platformVersion); + if (connectNodeInfo.versionMatrix.containsKey(OvsdbStringConstants.FW_IMAGE_ACTIVE_KEY)) { + protocolStatusData.setReportedSwVersion( + connectNodeInfo.versionMatrix.get(OvsdbStringConstants.FW_IMAGE_ACTIVE_KEY)); + } else if (connectNodeInfo.versionMatrix.containsKey(OvsdbStringConstants.FW_IMAGE_NAME_KEY)) { + protocolStatusData.setReportedSwVersion( + connectNodeInfo.versionMatrix.get(OvsdbStringConstants.FW_IMAGE_NAME_KEY)); + } else { + protocolStatusData.setReportedSwVersion("Unknown"); + } + if (connectNodeInfo.versionMatrix.containsKey(OvsdbStringConstants.FW_IMAGE_INACTIVE_KEY)) { + protocolStatusData.setReportedSwAltVersion( + connectNodeInfo.versionMatrix.get(OvsdbStringConstants.FW_IMAGE_INACTIVE_KEY)); + } else if (connectNodeInfo.versionMatrix.containsKey(OvsdbStringConstants.FW_IMAGE_NAME_KEY)) { + protocolStatusData.setReportedSwVersion( + connectNodeInfo.versionMatrix.get(OvsdbStringConstants.FW_IMAGE_NAME_KEY)); + } else { + protocolStatusData.setReportedSwVersion("Unknown"); + } + try { + protocolStatusData.setReportedIpV4Addr(InetAddress.getByName(connectNodeInfo.ipV4Address)); + } catch (UnknownHostException e) { + // do nothing here + } + if ((connectNodeInfo.macAddress != null) && (MacAddress.valueOf(connectNodeInfo.macAddress) != null)) { + protocolStatusData.setReportedMacAddr(MacAddress.valueOf(connectNodeInfo.macAddress)); + } + protocolStatusData.setReportedSku(connectNodeInfo.skuNumber); + protocolStatusData.setSerialNumber(connectNodeInfo.serialNumber); + protocolStatusData.setSystemName(connectNodeInfo.model); + statusRecord.setDetails(protocolStatusData); + statusServiceInterface.update(statusRecord); + + statusRecord = statusServiceInterface.getOrNull(ce.getCustomerId(), ce.getId(), StatusDataType.FIRMWARE); + if (statusRecord == null) { + statusRecord = new Status(); + statusRecord.setCustomerId(ce.getCustomerId()); + statusRecord.setEquipmentId(ce.getId()); + EquipmentUpgradeStatusData statusData = new EquipmentUpgradeStatusData(); + statusRecord.setDetails(statusData); + } + + EquipmentUpgradeStatusData fwUpgradeStatusData = (EquipmentUpgradeStatusData) statusRecord.getDetails(); + if (connectNodeInfo.versionMatrix.containsKey(OvsdbStringConstants.FW_IMAGE_ACTIVE_KEY)) { + fwUpgradeStatusData.setActiveSwVersion( + connectNodeInfo.versionMatrix.get(OvsdbStringConstants.FW_IMAGE_ACTIVE_KEY)); + } else if (connectNodeInfo.versionMatrix.containsKey(OvsdbStringConstants.FW_IMAGE_NAME_KEY)) { + fwUpgradeStatusData + .setActiveSwVersion(connectNodeInfo.versionMatrix.get(OvsdbStringConstants.FW_IMAGE_NAME_KEY)); + } else { + fwUpgradeStatusData.setActiveSwVersion("Unknown"); + } + if (connectNodeInfo.versionMatrix.containsKey(OvsdbStringConstants.FW_IMAGE_INACTIVE_KEY)) { + fwUpgradeStatusData.setAlternateSwVersion( + connectNodeInfo.versionMatrix.get(OvsdbStringConstants.FW_IMAGE_INACTIVE_KEY)); + } else if (connectNodeInfo.versionMatrix.containsKey(OvsdbStringConstants.FW_IMAGE_NAME_KEY)) { + fwUpgradeStatusData.setAlternateSwVersion( + connectNodeInfo.versionMatrix.get(OvsdbStringConstants.FW_IMAGE_NAME_KEY)); + } else { + fwUpgradeStatusData.setAlternateSwVersion("Unknown"); + } + + if (fwUpgradeStatusData.getUpgradeState() == null) { + fwUpgradeStatusData.setUpgradeState(EquipmentUpgradeState.undefined); + fwUpgradeStatusData.setUpgradeStartTime(null); + + } + + statusRecord.setDetails(fwUpgradeStatusData); + statusServiceInterface.update(statusRecord); + + Status networkAdminStatusRec = statusServiceInterface.getOrNull(ce.getCustomerId(), ce.getId(), + StatusDataType.NETWORK_ADMIN); + if (networkAdminStatusRec == null) { + networkAdminStatusRec = new Status(); + networkAdminStatusRec.setCustomerId(ce.getCustomerId()); + networkAdminStatusRec.setEquipmentId(ce.getId()); + NetworkAdminStatusData statusData = new NetworkAdminStatusData(); + networkAdminStatusRec.setDetails(statusData); + } + + NetworkAdminStatusData netAdminStatusData = (NetworkAdminStatusData) networkAdminStatusRec.getDetails(); + netAdminStatusData.setDhcpStatus(StatusCode.normal); + netAdminStatusData.setCloudLinkStatus(StatusCode.normal); + netAdminStatusData.setDnsStatus(StatusCode.normal); + + networkAdminStatusRec.setDetails(netAdminStatusData); + + networkAdminStatusRec = statusServiceInterface.update(networkAdminStatusRec); + + } catch (Exception e) { + LOG.debug("Exception in updateApStatus", e); + } + + } + + private void reconcileFwVersionToTrack(Equipment ce, String reportedFwVersionFromAp, String model) { + + LOG.debug("reconcileFwVersionToTrack for AP {} with active firmware version {} model {}", ce.getInventoryId(), + reportedFwVersionFromAp, model); + Status statusRecord = statusServiceInterface.getOrNull(ce.getCustomerId(), ce.getId(), StatusDataType.FIRMWARE); + + EquipmentUpgradeStatusData fwUpgradeStatusData = (EquipmentUpgradeStatusData) statusRecord.getDetails(); + + // default track settings for firmware + CustomerFirmwareTrackSettings trackSettings = firmwareServiceInterface.getDefaultCustomerTrackSetting(); + + // check for updated/modified track settings for this customer + CustomerFirmwareTrackRecord custFwTrackRecord = firmwareServiceInterface + .getCustomerFirmwareTrackRecord(ce.getCustomerId()); + + long trackRecordId = -1; + if (custFwTrackRecord != null) { + trackSettings = custFwTrackRecord.getSettings(); + trackRecordId = custFwTrackRecord.getTrackRecordId(); + } + // determine if AP requires FW upgrade before cloud + // connection/provision + if (trackSettings.getAutoUpgradeDeprecatedOnBind().equals(TrackFlag.ALWAYS) + || trackSettings.getAutoUpgradeUnknownOnBind().equals(TrackFlag.ALWAYS)) { + + LOG.debug("reconcileFwVersionToTrack for AP {} track flag for auto-upgrade {}", ce.getInventoryId(), + trackSettings.getAutoUpgradeDeprecatedOnBind()); + + // check the reported fw version for the AP, if it is < than + // the default version for the cloud, then download and + // flash the firmware before proceeding. + // then return; + FirmwareTrackRecord fwTrackRecord = null; + if (trackRecordId == -1) { + // take the default + fwTrackRecord = firmwareServiceInterface.getFirmwareTrackByName(FirmwareTrackRecord.DEFAULT_TRACK_NAME); + + } else { + // there must be a customer one + fwTrackRecord = firmwareServiceInterface.getFirmwareTrackById(trackRecordId); + } + + if (fwTrackRecord != null) { + + LOG.debug("reconcileFwVersionToTrack for AP {} firmwareTrackRecord {}", ce.getInventoryId(), + fwTrackRecord); + + List fwTrackAssignmentDetails = firmwareServiceInterface + .getFirmwareTrackAssignments(fwTrackRecord.getTrackName()); + + String targetFwVersionNameForTrack = null; + + if (fwTrackAssignmentDetails != null) { + for (FirmwareTrackAssignmentDetails details : fwTrackAssignmentDetails) { + if (model.equalsIgnoreCase(details.getModelId())) { + targetFwVersionNameForTrack = details.getVersionName(); + break; + } + } + } + + if (targetFwVersionNameForTrack == null) { + LOG.info("No target FW version for this track {}", fwTrackRecord); + + } else { + LOG.debug("reconcileFwVersionToTrack for AP {} targetFwVersion for track {}", ce.getInventoryId(), + targetFwVersionNameForTrack); + + if (reportedFwVersionFromAp != null) { + if (!targetFwVersionNameForTrack.equals(reportedFwVersionFromAp)) { + LOG.debug( + "reconcileFwVersionToTrack for AP {} targetFwVersion {} doesn't match reported fw version {}, triggering download and flash", + ce.getInventoryId(), targetFwVersionNameForTrack, reportedFwVersionFromAp); + + fwUpgradeStatusData.setTargetSwVersion(targetFwVersionNameForTrack); + fwUpgradeStatusData.setUpgradeState(EquipmentUpgradeState.out_of_date); + statusRecord.setDetails(fwUpgradeStatusData); + statusRecord = statusServiceInterface.update(statusRecord); + triggerFwDownload(ce, fwUpgradeStatusData, trackSettings); + } else if (targetFwVersionNameForTrack.equals(reportedFwVersionFromAp)) { + LOG.debug("reconcileFwVersionToTrack for AP {} targetFwVersion {} is active", + ce.getInventoryId(), targetFwVersionNameForTrack); + + fwUpgradeStatusData.setUpgradeState(EquipmentUpgradeState.up_to_date); + fwUpgradeStatusData.setActiveSwVersion(targetFwVersionNameForTrack); + fwUpgradeStatusData.setAlternateSwVersion(targetFwVersionNameForTrack); + fwUpgradeStatusData.setTargetSwVersion(targetFwVersionNameForTrack); + + statusRecord.setDetails(fwUpgradeStatusData); + statusRecord = statusServiceInterface.update(statusRecord); + + } + } + + } + + } + + } else + + { + LOG.debug("Automatic firmware upgrade is not configured for track {}", trackSettings); + } + } + + private void triggerFwDownload(Equipment ce, EquipmentUpgradeStatusData fwUpgradeStatusData, + CustomerFirmwareTrackSettings trackSettings) { + LOG.debug("triggerFwDownloadAndFlash Automatic firmware upgrade is configured for track {}.", trackSettings); + + try { + FirmwareVersion fwVersion = firmwareServiceInterface + .getFirmwareVersionByName(fwUpgradeStatusData.getTargetSwVersion()); + + if (fwVersion != null) { + OvsdbSession ovsdbSession = ovsdbSessionMapInterface.getSession(ce.getInventoryId()); + if (ovsdbSession == null) { + throw new IllegalStateException("AP is not connected " + ce.getInventoryId()); + } + + CEGWFirmwareDownloadRequest fwDownloadRequest = new CEGWFirmwareDownloadRequest(ce.getInventoryId(), + ce.getId(), fwVersion.getVersionName(), fwVersion.getFilename(), + fwVersion.getValidationMethod(), fwVersion.getValidationCode()); + List commands = new ArrayList<>(); + commands.add(fwDownloadRequest); + + gatewayController.updateActiveCustomer(ce.getCustomerId()); + ListOfEquipmentCommandResponses responses = gatewayController.sendCommands(commands); + LOG.debug("FW Download Response {}", responses); + + } + } catch (Exception e) { + LOG.error("Cannot trigger FW download {}", e); + } + } + + @Override + public void apDisconnected(String apId) { + LOG.info("AP {} got disconnected from the gateway", apId); + try { + + OvsdbSession ovsdbSession = ovsdbSessionMapInterface.getSession(apId); + + if (ovsdbSession != null) { + // if (ovsdbSession.getCustomerId() > 0 && + // ovsdbSession.getEquipmentId() > 0L) { + // List statusForDisconnectedAp = + // statusServiceInterface.delete(ovsdbSession.getCustomerId(), + // ovsdbSession.getEquipmentId()); + // LOG.info("Deleted status records {} for AP {}", + // statusForDisconnectedAp, apId); + // } + if (ovsdbSession.getRoutingId() > 0L) { + try { + routingServiceInterface.delete(ovsdbSession.getRoutingId()); + } catch (Exception e) { + LOG.warn("Unable to delete routing service Id {} for ap {}. {}", ovsdbSession.getRoutingId(), + apId, e); + } + } + } else { + LOG.warn("Cannot find ap {} in inventory", apId); + } + } catch (Exception e) { + LOG.error("Exception when registering ap routing {}", apId, e); + } + + } + + @Override + public OpensyncAPConfig getApConfig(String apId) { + LOG.info("Retrieving config for AP {} ", apId); + OpensyncAPConfig ret = null; + + try { + + OvsdbSession ovsdbSession = ovsdbSessionMapInterface.getSession(apId); + if (ovsdbSession == null) { + throw new IllegalStateException("AP is not connected " + apId); + } + int customerId = ovsdbSession.getCustomerId(); + Customer customer = customerServiceInterface.getOrNull(customerId); + if ((customer != null) && (customer.getDetails() != null) + && (customer.getDetails().getAutoProvisioning() != null) + && customer.getDetails().getAutoProvisioning().isEnabled()) { + Equipment equipmentConfig = getCustomerEquipment(apId); + + if (equipmentConfig == null) { + throw new IllegalStateException("Cannot retrieve configuration for " + apId); + } + + ret = new OpensyncAPConfig(); + + ret.setCustomerEquipment(equipmentConfig); + + Location eqLocation = locationServiceInterface.get(equipmentConfig.getLocationId()); + + ret.setEquipmentLocation(eqLocation); + + ProfileContainer profileContainer = new ProfileContainer( + profileServiceInterface.getProfileWithChildren(equipmentConfig.getProfileId())); + + ret.setApProfile(profileContainer.getOrNull(equipmentConfig.getProfileId())); + + ret.setRfProfile(profileContainer.getChildOfTypeOrNull(equipmentConfig.getProfileId(), ProfileType.rf)); + + ret.setSsidProfile( + profileContainer.getChildrenOfType(equipmentConfig.getProfileId(), ProfileType.ssid)); + + ret.setMetricsProfiles( + profileContainer.getChildrenOfType(equipmentConfig.getProfileId(), ProfileType.metrics)); + + Set radiusSet = new HashSet<>(); + Set captiveProfileIds = new HashSet<>(); + Set bonjourGatewayProfileIds = new HashSet<>(); + + OpensyncAPHotspot20Config hotspotConfig = new OpensyncAPHotspot20Config(); + + Set hotspot20ProfileSet = new HashSet<>(); + Set hotspot20OperatorSet = new HashSet<>(); + Set hotspot20VenueSet = new HashSet<>(); + Set hotspot20ProviderSet = new HashSet<>(); + + for (Profile ssidProfile : ret.getSsidProfile()) { + + hotspot20ProfileSet + .addAll(profileContainer.getChildrenOfType(ssidProfile.getId(), ProfileType.hotspot_2pt0)); + + radiusSet + .addAll(profileContainer.getChildrenOfType(ret.getApProfile().getId(), ProfileType.radius)); + if (ssidProfile.getDetails() != null) { + Long captivePortId = ((SsidConfiguration) ssidProfile.getDetails()).getCaptivePortalId(); + if (captivePortId != null) { + captiveProfileIds.add(captivePortId); + } + Long bonjourGatewayProfileId = ((SsidConfiguration) ssidProfile.getDetails()) + .getBonjourGatewayProfileId(); + if (bonjourGatewayProfileId != null) { + bonjourGatewayProfileIds.add(bonjourGatewayProfileId); + } + } + } + + if (hotspot20ProfileSet.size() > 0) { + for (Profile hotspot20Profile : hotspot20ProfileSet) { + hotspot20OperatorSet.addAll( + profileContainer.getChildrenOfType(hotspot20Profile.getId(), ProfileType.operator)); + hotspot20VenueSet.addAll( + profileContainer.getChildrenOfType(hotspot20Profile.getId(), ProfileType.venue)); + hotspot20ProviderSet.addAll( + profileContainer.getChildrenOfType(hotspot20Profile.getId(), ProfileType.id_provider)); + } + hotspotConfig.setHotspot20OperatorSet(hotspot20OperatorSet); + hotspotConfig.setHotspot20ProfileSet(hotspot20ProfileSet); + hotspotConfig.setHotspot20ProviderSet(hotspot20ProviderSet); + hotspotConfig.setHotspot20VenueSet(hotspot20VenueSet); + + ret.setHotspotConfig(hotspotConfig); + } + + ret.setRadiusProfiles(new ArrayList<>(radiusSet)); + ret.setCaptiveProfiles(profileServiceInterface.get(captiveProfileIds)); + ret.setBonjourGatewayProfiles(profileServiceInterface.get(bonjourGatewayProfileIds)); + + List blockedClients = clientServiceInterface + .getBlockedClients(customerId); + List blockList = Lists.newArrayList(); + if ((blockedClients != null) && !blockedClients.isEmpty()) { + blockedClients.forEach(client -> blockList.add(client.getMacAddress())); + } + ret.setBlockedClients(blockList); + + LOG.debug("ApConfig {}", ret); + } else { + LOG.info("Autoconfig is not enabled for this AP {}", apId); + } + + } catch (Exception e) { + LOG.error("Cannot read config for AP {}", apId, e); + } + + return ret; + } + + @Override + public void processMqttMessage(String topic, Report report) { + mqttMessageProcessor.processMqttMessage(topic, report); + } + + @Override + public void processMqttMessage(String topic, FlowReport flowReport) { + mqttMessageProcessor.processMqttMessage(topic, flowReport); + } + + @Override + public void processMqttMessage(String topic, WCStatsReport wcStatsReport) { + mqttMessageProcessor.processMqttMessage(topic, wcStatsReport); + } + + @Override + public void wifiVIFStateDbTableUpdate(List vifStateTables, String apId) { + LOG.debug("Received Wifi_VIF_State table update for AP {}", apId); + + OvsdbSession ovsdbSession = ovsdbSessionMapInterface.getSession(apId); + + if (ovsdbSession == null) { + LOG.debug("wifiVIFStateDbTableUpdate::Cannot get Session for AP {}", apId); + return; + } + + int customerId = ovsdbSession.getCustomerId(); + long equipmentId = ovsdbSession.getEquipmentId(); + + if ((customerId < 0) || (equipmentId < 0)) { + LOG.debug("wifiVIFStateDbTableUpdate::Cannot get valid CustomerId {} or EquipmentId {} for AP {}", + customerId, equipmentId, apId); + return; + } + + Equipment apNode = equipmentServiceInterface.getByInventoryIdOrNull(apId); + if (apNode == null) { + LOG.debug("wifiVIFStateDbTableUpdate::Cannot get EquipmentId for AP {}", apId); + return; // we don't have the required info to get the + // radio type yet + } + ApElementConfiguration apElementConfig = (ApElementConfiguration) apNode.getDetails(); + + ProfileContainer profileContainer = new ProfileContainer( + profileServiceInterface.getProfileWithChildren(apNode.getProfileId())); + RfConfiguration rfConfig = (RfConfiguration) profileContainer + .getChildOfTypeOrNull(apNode.getProfileId(), ProfileType.rf).getDetails(); + + for (OpensyncAPVIFState vifState : vifStateTables) { + + LOG.debug("Processing vifState for interface {} on AP {}", vifState.getIfName(), apId); + + String bssid = vifState.getMac(); + + if ((bssid == null) || bssid.equals("")) { + LOG.warn("BSSID from AP {} for vif {} is null or empty", apId, vifState.getIfName()); + continue; + } + String ssid = vifState.getSsid(); + + if ((ssid == null) || ssid.equals("")) { + LOG.warn("SSID from AP {} interface {} is null or empty", apId, vifState.getIfName()); + continue; + } + + int numClients = vifState.getAssociatedClients().size(); + + int channel = vifState.getChannel(); + + if ((channel < 1)) { + LOG.warn("Channel from AP {} interface {} is null or empty", apId, vifState.getIfName()); + continue; + } + + LOG.debug("Values from Vif State Mac (BSSID) {} SSID {} AssociatedClients {} Channel {}", bssid, ssid, + vifState.getAssociatedClients()); + + RadioType radioType = null; + Map rfElementMap = rfConfig.getRfConfigMap(); + Map elementRadioMap = apElementConfig.getRadioMap(); + for (RadioType rType : elementRadioMap.keySet()) { + boolean autoChannelSelection = rfElementMap.get(rType).getAutoChannelSelection(); + if (elementRadioMap.get(rType).getActiveChannel(autoChannelSelection) == channel) { + radioType = rType; + break; + } + } + updateActiveBssids(customerId, equipmentId, apId, ssid, radioType, bssid, numClients); - @Override - public void processMqttMessage(String topic, FlowReport flowReport) { - mqttMessageProcessor.processMqttMessage(topic, flowReport); - } + } - @Override - public void processMqttMessage(String topic, WCStatsReport wcStatsReport) { - mqttMessageProcessor.processMqttMessage(topic, wcStatsReport); - } - - @Override - public void wifiVIFStateDbTableUpdate(List vifStateTables, String apId) { - LOG.debug("Received Wifi_VIF_State table update for AP {}", apId); - - OvsdbSession ovsdbSession = ovsdbSessionMapInterface.getSession(apId); - - if (ovsdbSession == null) { - LOG.debug("wifiVIFStateDbTableUpdate::Cannot get Session for AP {}", apId); - return; - } - - int customerId = ovsdbSession.getCustomerId(); - long equipmentId = ovsdbSession.getEquipmentId(); - - if ((customerId < 0) || (equipmentId < 0)) { - LOG.debug("wifiVIFStateDbTableUpdate::Cannot get valid CustomerId {} or EquipmentId {} for AP {}", - customerId, equipmentId, apId); - return; - } - - Equipment apNode = equipmentServiceInterface.getByInventoryIdOrNull(apId); - if (apNode == null) { - LOG.debug("wifiVIFStateDbTableUpdate::Cannot get EquipmentId for AP {}", apId); - return; // we don't have the required info to get the - // radio type yet - } - ApElementConfiguration apElementConfig = (ApElementConfiguration) apNode.getDetails(); - - ProfileContainer profileContainer = new ProfileContainer( - profileServiceInterface.getProfileWithChildren(apNode.getProfileId())); - RfConfiguration rfConfig = (RfConfiguration) profileContainer.getChildOfTypeOrNull(apNode.getProfileId(), ProfileType.rf) - .getDetails(); - - for (OpensyncAPVIFState vifState : vifStateTables) { - - LOG.debug("Processing vifState for interface {} on AP {}", vifState.getIfName(), apId); - - String bssid = vifState.getMac(); - - if ((bssid == null) || bssid.equals("")) { - LOG.warn("BSSID from AP {} for vif {} is null or empty", apId, vifState.getIfName()); - continue; - } - String ssid = vifState.getSsid(); - - if ((ssid == null) || ssid.equals("")) { - LOG.warn("SSID from AP {} interface {} is null or empty", apId, vifState.getIfName()); - continue; - } - - int numClients = vifState.getAssociatedClients().size(); - - int channel = vifState.getChannel(); - - if ((channel < 1)) { - LOG.warn("Channel from AP {} interface {} is null or empty", apId, vifState.getIfName()); - continue; - } - - LOG.debug("Values from Vif State Mac (BSSID) {} SSID {} AssociatedClients {} Channel {}", bssid, ssid, - vifState.getAssociatedClients()); - - RadioType radioType = null; - Map rfElementMap = rfConfig.getRfConfigMap(); - Map elementRadioMap = apElementConfig.getRadioMap(); - for (RadioType rType : elementRadioMap.keySet()) { - boolean autoChannelSelection = rfElementMap.get(rType).getAutoChannelSelection(); - if (elementRadioMap.get(rType).getActiveChannel(autoChannelSelection) == channel) { - radioType = rType; - break; - } - } + Status activeBssidsStatus = statusServiceInterface.getOrNull(customerId, equipmentId, + StatusDataType.ACTIVE_BSSIDS); + if (activeBssidsStatus != null) { + updateClientDetailsStatus(customerId, equipmentId, (ActiveBSSIDs) activeBssidsStatus.getDetails()); + } - updateActiveBssids(customerId, equipmentId, apId, ssid, radioType, bssid, numClients); + LOG.info("Finished wifiVIFStateDbTableUpdate updated {}", activeBssidsStatus); - } + } + + private void updateClientDetailsStatus(int customerId, long equipmentId, ActiveBSSIDs statusDetails) { + Status clientDetailsStatus = statusServiceInterface.getOrNull(customerId, equipmentId, + StatusDataType.CLIENT_DETAILS); + + LOG.debug("Processing updateClientDetailsStatus Status for ActiveBSSIDs {}", statusDetails); + + if (clientDetailsStatus == null) { + clientDetailsStatus = new Status(); + clientDetailsStatus.setCustomerId(customerId); + clientDetailsStatus.setEquipmentId(equipmentId); + clientDetailsStatus.setStatusDataType(StatusDataType.CLIENT_DETAILS); + clientDetailsStatus.setDetails(new ClientConnectionDetails()); + clientDetailsStatus = statusServiceInterface.update(clientDetailsStatus); + + LOG.debug("Processing updateClientDetailsStatus, new ClientDetailsStatus {}", clientDetailsStatus); + } + + ClientConnectionDetails clientConnectionDetails = (ClientConnectionDetails) clientDetailsStatus.getDetails(); + + Map clientsPerRadioType = new HashMap<>(); + + for (ActiveBSSID bssid : statusDetails.getActiveBSSIDs()) { + + if (!clientsPerRadioType.containsKey(bssid.getRadioType())) { + clientsPerRadioType.put(bssid.getRadioType(), 0); + } + int numConnectedForBssid = bssid.getNumDevicesConnected(); + int currentNumberOfClients = clientsPerRadioType.get(bssid.getRadioType()); + clientsPerRadioType.put(bssid.getRadioType(), currentNumberOfClients + numConnectedForBssid); + LOG.debug("Processing updateClientDetailsStatus. Upgrade numClients for RadioType {} from {} to {}", + bssid.getRadioType(), currentNumberOfClients, clientsPerRadioType.get(bssid.getRadioType())); + } - Status activeBssidsStatus = statusServiceInterface.getOrNull(customerId, equipmentId, - StatusDataType.ACTIVE_BSSIDS); - if (activeBssidsStatus != null) { - updateClientDetailsStatus(customerId, equipmentId, (ActiveBSSIDs) activeBssidsStatus.getDetails()); - } + clientConnectionDetails.setNumClientsPerRadio(clientsPerRadioType); + clientDetailsStatus.setDetails(clientConnectionDetails); + clientDetailsStatus = statusServiceInterface.update(clientDetailsStatus); + if (LOG.isTraceEnabled()) { + LOG.trace("Processing updateClientDetailsStatus. Updated clientConnectionDetails to {}", + clientDetailsStatus.toPrettyString()); + } - LOG.info("Finished wifiVIFStateDbTableUpdate updated {}", activeBssidsStatus); + LOG.info("Finished updateClientDetailsStatus updated {}", clientDetailsStatus); - } + } - private void updateClientDetailsStatus(int customerId, long equipmentId, ActiveBSSIDs statusDetails) { - Status clientDetailsStatus = statusServiceInterface.getOrNull(customerId, equipmentId, - StatusDataType.CLIENT_DETAILS); - - LOG.debug("Processing updateClientDetailsStatus Status for ActiveBSSIDs {}", statusDetails); - - if (clientDetailsStatus == null) { - clientDetailsStatus = new Status(); - clientDetailsStatus.setCustomerId(customerId); - clientDetailsStatus.setEquipmentId(equipmentId); - clientDetailsStatus.setStatusDataType(StatusDataType.CLIENT_DETAILS); - clientDetailsStatus.setDetails(new ClientConnectionDetails()); - clientDetailsStatus = statusServiceInterface.update(clientDetailsStatus); - - LOG.debug("Processing updateClientDetailsStatus, new ClientDetailsStatus {}", clientDetailsStatus); - } - - ClientConnectionDetails clientConnectionDetails = (ClientConnectionDetails) clientDetailsStatus.getDetails(); - - Map clientsPerRadioType = new HashMap<>(); - - for (ActiveBSSID bssid : statusDetails.getActiveBSSIDs()) { - - if (!clientsPerRadioType.containsKey(bssid.getRadioType())) { - clientsPerRadioType.put(bssid.getRadioType(), 0); - } - int numConnectedForBssid = bssid.getNumDevicesConnected(); - int currentNumberOfClients = clientsPerRadioType.get(bssid.getRadioType()); - clientsPerRadioType.put(bssid.getRadioType(), currentNumberOfClients + numConnectedForBssid); - LOG.debug("Processing updateClientDetailsStatus. Upgrade numClients for RadioType {} from {} to {}", - bssid.getRadioType(), currentNumberOfClients, clientsPerRadioType.get(bssid.getRadioType())); - } - - clientConnectionDetails.setNumClientsPerRadio(clientsPerRadioType); - clientDetailsStatus.setDetails(clientConnectionDetails); - clientDetailsStatus = statusServiceInterface.update(clientDetailsStatus); + @Override + public void wifiRadioStatusDbTableUpdate(List radioStateTables, String apId) { + LOG.debug("Received Wifi_Radio_State table update for AP {}", apId); + OvsdbSession ovsdbSession = ovsdbSessionMapInterface.getSession(apId); - if (LOG.isTraceEnabled()) { - LOG.trace("Processing updateClientDetailsStatus. Updated clientConnectionDetails to {}", - clientDetailsStatus.toPrettyString()); - } + if (ovsdbSession == null) { + LOG.debug("wifiRadioStatusDbTableUpdate::Cannot get Session for AP {}", apId); + return; + } - LOG.info("Finished updateClientDetailsStatus updated {}", clientDetailsStatus); + int customerId = ovsdbSession.getCustomerId(); + long equipmentId = ovsdbSession.getEquipmentId(); - } + if ((customerId < 0) || (equipmentId < 0)) { + LOG.debug("wifiRadioStatusDbTableUpdate::Cannot get valid CustomerId {} or EquipmentId {} for AP {}", + customerId, equipmentId, apId); + return; + } - @Override - public void wifiRadioStatusDbTableUpdate(List radioStateTables, String apId) { - LOG.debug("Received Wifi_Radio_State table update for AP {}", apId); - OvsdbSession ovsdbSession = ovsdbSessionMapInterface.getSession(apId); + Equipment ce = equipmentServiceInterface.getByInventoryIdOrNull(apId); + if (ce == null) { + LOG.debug("wifiRadioStatusDbTableUpdate::Cannot get Equipment for AP {}", apId); + return; + } - if (ovsdbSession == null) { - LOG.debug("wifiRadioStatusDbTableUpdate::Cannot get Session for AP {}", apId); - return; - } + ApElementConfiguration apElementConfiguration = ((ApElementConfiguration) ce.getDetails()); - int customerId = ovsdbSession.getCustomerId(); - long equipmentId = ovsdbSession.getEquipmentId(); + Status protocolStatus = null; + EquipmentProtocolStatusData protocolStatusData = null; + + for (OpensyncAPRadioState radioState : radioStateTables) { + LOG.debug("Processing Wifi_Radio_State table update for AP {} {}", apId, radioState); - if ((customerId < 0) || (equipmentId < 0)) { - LOG.debug("wifiRadioStatusDbTableUpdate::Cannot get valid CustomerId {} or EquipmentId {} for AP {}", - customerId, equipmentId, apId); - return; - } + if (radioState.getFreqBand().equals(RadioType.UNSUPPORTED)) { + LOG.debug("Could not get radio configuration for AP {}", apId); + continue; + } - Equipment ce = equipmentServiceInterface.getByInventoryIdOrNull(apId); - if (ce == null) { - LOG.debug("wifiRadioStatusDbTableUpdate::Cannot get Equipment for AP {}", apId); - return; - } + if (radioState.getAllowedChannels() != null) { + apElementConfiguration.getRadioMap().get(radioState.getFreqBand()) + .setAllowedChannels(new ArrayList<>(radioState.getAllowedChannels())); - ApElementConfiguration apElementConfiguration = ((ApElementConfiguration) ce.getDetails()); + LOG.debug("Updated AllowedChannels from Wifi_Radio_State table change for AP {}", apId); - Status protocolStatus = null; - EquipmentProtocolStatusData protocolStatusData = null; + } - for (OpensyncAPRadioState radioState : radioStateTables) { - LOG.debug("Processing Wifi_Radio_State table update for AP {} {}", apId, radioState); + if (radioState.getTxPower() > 0) { + SourceType txPowerSource = apElementConfiguration.getRadioMap().get(radioState.getFreqBand()) + .getEirpTxPower().getSource(); + // Preserve the source while updating the value + if (txPowerSource == SourceType.auto) { + apElementConfiguration.getRadioMap().get(radioState.getFreqBand()) + .setEirpTxPower(SourceSelectionValue.createAutomaticInstance(radioState.getTxPower())); + } else if (txPowerSource == SourceType.profile) { + apElementConfiguration.getRadioMap().get(radioState.getFreqBand()) + .setEirpTxPower(SourceSelectionValue.createProfileInstance(radioState.getTxPower())); + } else { + apElementConfiguration.getRadioMap().get(radioState.getFreqBand()) + .setEirpTxPower(SourceSelectionValue.createManualInstance(radioState.getTxPower())); + } + + LOG.debug("Updated TxPower from Wifi_Radio_State table change for AP {}", apId); + } + + StateSetting state = StateSetting.disabled; + if (radioState.isEnabled()) { + state = StateSetting.enabled; + } + + if (!apElementConfiguration.getAdvancedRadioMap().get(radioState.getFreqBand()).getRadioAdminState() + .equals(state)) { + // only update if changed + apElementConfiguration.getAdvancedRadioMap().get(radioState.getFreqBand()).setRadioAdminState(state); + + LOG.debug("Updated RadioAdminState from Wifi_Radio_State table change for AP {}", apId); + + } + + protocolStatus = statusServiceInterface.getOrNull(customerId, equipmentId, StatusDataType.PROTOCOL); + + if (protocolStatus != null) { + + protocolStatusData = (EquipmentProtocolStatusData) protocolStatus.getDetails(); + if (!protocolStatusData.getReportedCC() + .equals(CountryCode.valueOf(radioState.getCountry().toLowerCase()))) { + protocolStatusData.setReportedCC(CountryCode.valueOf(radioState.getCountry().toLowerCase())); + protocolStatus.setDetails(protocolStatusData); + + } else { + protocolStatus = null; + } - if (radioState.getFreqBand().equals(RadioType.UNSUPPORTED)) { - LOG.debug("Could not get radio configuration for AP {}", apId); - continue; - } + } - if (radioState.getAllowedChannels() != null) { - apElementConfiguration.getRadioMap().get(radioState.getFreqBand()) - .setAllowedChannels(new ArrayList<>(radioState.getAllowedChannels())); + } - LOG.debug("Updated AllowedChannels from Wifi_Radio_State table change for AP {}", apId); + if (protocolStatus != null) { + statusServiceInterface.update(protocolStatus); + } - } + ce = equipmentServiceInterface.getByInventoryIdOrNull(apId); + if (ce == null) { + LOG.debug("wifiRadioStatusDbTableUpdate::Cannot get Equipment for AP {}", apId); + return; + } + + try { - if (radioState.getTxPower() > 0) { - SourceType txPowerSource = apElementConfiguration.getRadioMap().get(radioState.getFreqBand()) - .getEirpTxPower().getSource(); - // Preserve the source while updating the value - if (txPowerSource == SourceType.auto) { - apElementConfiguration.getRadioMap().get(radioState.getFreqBand()) - .setEirpTxPower(SourceSelectionValue.createAutomaticInstance(radioState.getTxPower())); - } else if (txPowerSource == SourceType.profile) { - apElementConfiguration.getRadioMap().get(radioState.getFreqBand()) - .setEirpTxPower(SourceSelectionValue.createProfileInstance(radioState.getTxPower())); - } else { - apElementConfiguration.getRadioMap().get(radioState.getFreqBand()) - .setEirpTxPower(SourceSelectionValue.createManualInstance(radioState.getTxPower())); - } + if (!apElementConfiguration.equals((ce.getDetails()))) { - LOG.debug("Updated TxPower from Wifi_Radio_State table change for AP {}", apId); - } + ((ApElementConfiguration) ce.getDetails()).setRadioMap(apElementConfiguration.getRadioMap()); + ((ApElementConfiguration) ce.getDetails()) + .setAdvancedRadioMap(apElementConfiguration.getAdvancedRadioMap()); + + apElementConfiguration = (ApElementConfiguration) ce.getDetails(); + ce = equipmentServiceInterface.update(ce); + } + } catch (DsConcurrentModificationException e) { + LOG.debug("Equipment reference changed, update instance and retry.", e.getMessage()); + ce = equipmentServiceInterface.getByInventoryIdOrNull(apId); + ce.setDetails(apElementConfiguration); + ce = equipmentServiceInterface.update(ce); + } + LOG.info("Finished wifiRadioStateDbTableUpdate"); - StateSetting state = StateSetting.disabled; - if (radioState.isEnabled()) { - state = StateSetting.enabled; - } + } - if (!apElementConfiguration.getAdvancedRadioMap().get(radioState.getFreqBand()).getRadioAdminState() - .equals(state)) { - // only update if changed - apElementConfiguration.getAdvancedRadioMap().get(radioState.getFreqBand()).setRadioAdminState(state); + private void updateActiveBssids(int customerId, long equipmentId, Object apId, String ssid, RadioType freqBand, + String macAddress, int numClients) { + Status activeBssidsStatus = statusServiceInterface.getOrNull(customerId, equipmentId, + StatusDataType.ACTIVE_BSSIDS); + + if (activeBssidsStatus == null) { + activeBssidsStatus = new Status(); + activeBssidsStatus.setCustomerId(customerId); + activeBssidsStatus.setEquipmentId(equipmentId); + activeBssidsStatus.setStatusDataType(StatusDataType.ACTIVE_BSSIDS); + + ActiveBSSIDs statusDetails = new ActiveBSSIDs(); + statusDetails.setActiveBSSIDs(new ArrayList()); + + activeBssidsStatus.setDetails(statusDetails); + + activeBssidsStatus = statusServiceInterface.update(activeBssidsStatus); + LOG.debug("Processing Wifi_VIF_State table update for AP {}, created new ACTIVE_BSSID Status {}", apId, + activeBssidsStatus); + + } + + ActiveBSSIDs statusDetails = (ActiveBSSIDs) activeBssidsStatus.getDetails(); + + LOG.debug("Processing Wifi_VIF_State table update for AP {}, activeBSSIDs StatusDetails before update {}", apId, + statusDetails); + + List currentActiveBSSIDs = statusDetails.getActiveBSSIDs(); + if (currentActiveBSSIDs == null) { + currentActiveBSSIDs = new ArrayList<>(); + } else { + currentActiveBSSIDs = currentActiveBSSIDs.stream() + .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 {}", + apId, currentActiveBSSIDs, ssid); + } + + ActiveBSSID activeBssid = new ActiveBSSID(); + activeBssid.setBssid(macAddress); + activeBssid.setSsid(ssid); + activeBssid.setRadioType(freqBand); + activeBssid.setNumDevicesConnected(numClients); + currentActiveBSSIDs.add(activeBssid); + + statusDetails.setActiveBSSIDs(currentActiveBSSIDs); + activeBssidsStatus.setDetails(statusDetails); + + activeBssidsStatus = statusServiceInterface.update(activeBssidsStatus); + + if (LOG.isTraceEnabled()) { + LOG.trace("Processing Wifi_VIF_State table update for AP {}, updated ACTIVE_BSSID Status {}", apId, + activeBssidsStatus.toPrettyString()); + } + } + + @Override + public void wifiInetStateDbTableUpdate(List inetStateTables, String apId) { + + LOG.debug("Received Wifi_Inet_State table update for AP {}", apId); + + OvsdbSession ovsdbSession = ovsdbSessionMapInterface.getSession(apId); + + if (ovsdbSession == null) { + LOG.debug("wifiInetStateDbTableUpdate::Cannot get Session for AP {}", apId); + return; + } + + int customerId = ovsdbSession.getCustomerId(); + long equipmentId = ovsdbSession.getEquipmentId(); + + if ((customerId < 0) || (equipmentId < 0)) { + LOG.debug("wifiInetStateDbTableUpdate::Cannot get valid CustomerId {} or EquipmentId {} for AP {}", + customerId, equipmentId, apId); + return; + } + + Equipment ce = equipmentServiceInterface.getOrNull(equipmentId); + + if (ce == null) { + LOG.debug("wifiInetStateDbTableUpdate Cannot get customer Equipment for {}", apId); + return; + } + + Status lanStatus = statusServiceInterface.getOrNull(customerId, equipmentId, StatusDataType.LANINFO); + if (lanStatus == null) { + lanStatus = new Status(); + lanStatus.setCustomerId(customerId); + lanStatus.setEquipmentId(equipmentId); + lanStatus.setStatusDataType(StatusDataType.LANINFO); + lanStatus.setDetails(new EquipmentLANStatusData()); + lanStatus = statusServiceInterface.update(lanStatus); + } + + EquipmentLANStatusData lanStatusData = (EquipmentLANStatusData) lanStatus.getDetails(); + for (OpensyncAPInetState inetState : inetStateTables) { + + if (inetState.getVlanId() > 1) { + + if (!lanStatusData.getVlanStatusDataMap().containsKey(inetState.getVlanId())) { + lanStatusData.getVlanStatusDataMap().put(inetState.getVlanId(), new VLANStatusData()); + } - LOG.debug("Updated RadioAdminState from Wifi_Radio_State table change for AP {}", apId); + try { + lanStatusData.getVlanStatusDataMap().get(inetState.getVlanId()) + .setGateway(InetAddress.getByName(inetState.getGateway())); - } + String primaryDns = inetState.getDns().get("primary"); + if (primaryDns != null) { + lanStatusData.getVlanStatusDataMap().get(inetState.getVlanId()) + .setDnsServer1(InetAddress.getByName(primaryDns)); + } + lanStatusData.getVlanStatusDataMap().get(inetState.getVlanId()) + .setSubnetMask(InetAddress.getByName(inetState.getNetmask())); + + String dhcpOption = inetState.getDhcpd().get("dhcp_option"); + if (dhcpOption != null) { + String dhcpServer = dhcpOption.split(",")[1]; + if (dhcpServer != null) { + lanStatusData.getVlanStatusDataMap().get(inetState.getVlanId()) + .setDhcpServer(InetAddress.getByName(dhcpServer)); + } + } + String inetAddr = inetState.getInetAddr(); + if (inetAddr != null) { + lanStatusData.getVlanStatusDataMap().get(inetState.getVlanId()) + .setIpBase(InetAddress.getByName(inetAddr)); + } + + } catch (UnknownHostException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } - protocolStatus = statusServiceInterface.getOrNull(customerId, equipmentId, StatusDataType.PROTOCOL); + lanStatus.setDetails(lanStatusData); + lanStatus = statusServiceInterface.update(lanStatus); - if (protocolStatus != null) { + } + } - protocolStatusData = (EquipmentProtocolStatusData) protocolStatus.getDetails(); - if (!protocolStatusData.getReportedCC() - .equals(CountryCode.valueOf(radioState.getCountry().toLowerCase()))) { - protocolStatusData.setReportedCC(CountryCode.valueOf(radioState.getCountry().toLowerCase())); - protocolStatus.setDetails(protocolStatusData); + } - } else { - protocolStatus = null; - } + @Override + public void wifiInetStateDbTableDelete(List inetStateTables, String apId) { - } + LOG.debug("Received Wifi_Inet_State table delete for AP {}", apId); + } - } + @Override + public void wifiAssociatedClientsDbTableUpdate(List wifiAssociatedClients, + String apId) { + OvsdbSession ovsdbSession = ovsdbSessionMapInterface.getSession(apId); - if (protocolStatus != null) { - statusServiceInterface.update(protocolStatus); - } + if (ovsdbSession == null) { + LOG.debug("wifiAssociatedClientsDbTableUpdate::Cannot get Session for AP {}", apId); + return; + } - ce = equipmentServiceInterface.getByInventoryIdOrNull(apId); - if (ce == null) { - LOG.debug("wifiRadioStatusDbTableUpdate::Cannot get Equipment for AP {}", apId); - return; - } + int customerId = ovsdbSession.getCustomerId(); + long equipmentId = ovsdbSession.getEquipmentId(); - try { + if ((customerId < 0) || (equipmentId < 0)) { + LOG.debug("wifiAssociatedClientsDbTableUpdate::Cannot get valid CustomerId {} or EquipmentId {} for AP {}", + customerId, equipmentId, apId); + return; + } + + Equipment ce = equipmentServiceInterface.getOrNull(equipmentId); + + if (ce == null) { + LOG.debug("wifiAssociatedClientsDbTableUpdate Cannot get customer Equipment for {}", apId); + return; + } + + if ((wifiAssociatedClients == null) || wifiAssociatedClients.isEmpty()) { + return; + } + + for (OpensyncWifiAssociatedClients opensyncWifiAssociatedClients : wifiAssociatedClients) { + com.telecominfraproject.wlan.client.models.Client clientInstance = clientServiceInterface + .getOrNull(customerId, new MacAddress(opensyncWifiAssociatedClients.getMac())); + + boolean isReassociation = true; + if (clientInstance == null) { + clientInstance = new com.telecominfraproject.wlan.client.models.Client(); - if (!apElementConfiguration.equals((ce.getDetails()))) { + clientInstance.setCustomerId(customerId); + clientInstance.setMacAddress(new MacAddress(opensyncWifiAssociatedClients.getMac())); + clientInstance.setDetails(new ClientInfoDetails()); + clientInstance = clientServiceInterface.create(clientInstance); - ((ApElementConfiguration) ce.getDetails()).setRadioMap(apElementConfiguration.getRadioMap()); - ((ApElementConfiguration) ce.getDetails()) - .setAdvancedRadioMap(apElementConfiguration.getAdvancedRadioMap()); + isReassociation = false; - apElementConfiguration = (ApElementConfiguration) ce.getDetails(); - ce = equipmentServiceInterface.update(ce); - } - } catch (DsConcurrentModificationException e) { - LOG.debug("Equipment reference changed, update instance and retry.", e.getMessage()); - ce = equipmentServiceInterface.getByInventoryIdOrNull(apId); - ce.setDetails(apElementConfiguration); - ce = equipmentServiceInterface.update(ce); - } - LOG.info("Finished wifiRadioStateDbTableUpdate"); + } + ClientInfoDetails clientDetails = (ClientInfoDetails) clientInstance.getDetails(); - } + clientInstance.setDetails(clientDetails); - private void updateActiveBssids(int customerId, long equipmentId, Object apId, String ssid, RadioType freqBand, - String macAddress, int numClients) { - Status activeBssidsStatus = statusServiceInterface.getOrNull(customerId, equipmentId, - StatusDataType.ACTIVE_BSSIDS); + clientInstance = clientServiceInterface.update(clientInstance); - if (activeBssidsStatus == null) { - activeBssidsStatus = new Status(); - activeBssidsStatus.setCustomerId(customerId); - activeBssidsStatus.setEquipmentId(equipmentId); - activeBssidsStatus.setStatusDataType(StatusDataType.ACTIVE_BSSIDS); + ClientSession clientSession = clientServiceInterface.getSessionOrNull(customerId, equipmentId, + clientInstance.getMacAddress()); - ActiveBSSIDs statusDetails = new ActiveBSSIDs(); - statusDetails.setActiveBSSIDs(new ArrayList()); + if (clientSession == null) { + clientSession = new ClientSession(); + clientSession.setCustomerId(customerId); + clientSession.setEquipmentId(equipmentId); + clientSession.setMacAddress(clientInstance.getMacAddress()); + clientSession.setLocationId(ce.getLocationId()); + ClientSessionDetails clientSessionDetails = new ClientSessionDetails(); + clientSessionDetails.setIsReassociation(isReassociation); + clientSessionDetails.setSessionId(clientInstance.getMacAddress().getAddressAsLong()); + clientSession.setDetails(clientSessionDetails); - activeBssidsStatus.setDetails(statusDetails); + clientSession = clientServiceInterface.updateSession(clientSession); + } - activeBssidsStatus = statusServiceInterface.update(activeBssidsStatus); - LOG.debug("Processing Wifi_VIF_State table update for AP {}, created new ACTIVE_BSSID Status {}", apId, - activeBssidsStatus); + ClientSessionDetails clientSessionDetails = clientSession.getDetails(); + clientSessionDetails.setAssociationState(AssociationState._802_11_Associated); + clientSessionDetails.setAssocTimestamp(System.currentTimeMillis()); + clientSessionDetails.setSessionId(clientInstance.getMacAddress().getAddressAsLong()); + clientSession.getDetails().mergeSession(clientSessionDetails); - } + clientSession = clientServiceInterface.updateSession(clientSession); - ActiveBSSIDs statusDetails = (ActiveBSSIDs) activeBssidsStatus.getDetails(); + } - LOG.debug("Processing Wifi_VIF_State table update for AP {}, activeBSSIDs StatusDetails before update {}", apId, - statusDetails); + } - List currentActiveBSSIDs = statusDetails.getActiveBSSIDs(); - if (currentActiveBSSIDs == null) { - currentActiveBSSIDs = new ArrayList<>(); - } else { - currentActiveBSSIDs = currentActiveBSSIDs.stream() - .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 {}", - apId, currentActiveBSSIDs, ssid); - } + @Override + public void awlanNodeDbTableUpdate(OpensyncAWLANNode opensyncAPState, String apId) { + LOG.debug("AP {} table AWLAN_Node updated {}", apId, opensyncAPState); + OvsdbSession ovsdbSession = ovsdbSessionMapInterface.getSession(apId); - ActiveBSSID activeBssid = new ActiveBSSID(); - activeBssid.setBssid(macAddress); - activeBssid.setSsid(ssid); - activeBssid.setRadioType(freqBand); - activeBssid.setNumDevicesConnected(numClients); - currentActiveBSSIDs.add(activeBssid); + if (ovsdbSession == null) { + LOG.debug("awlanNodeDbTableUpdate::Cannot get Session for AP {}", apId); + return; + } + int customerId = ovsdbSession.getCustomerId(); + long equipmentId = ovsdbSession.getEquipmentId(); - statusDetails.setActiveBSSIDs(currentActiveBSSIDs); - activeBssidsStatus.setDetails(statusDetails); + if ((customerId < 0) || (equipmentId < 0)) { + LOG.debug("awlanNodeDbTableUpdate::Cannot get valid CustomerId {} or EquipmentId {} for AP {}", customerId, + equipmentId, apId); + return; + } + + int upgradeStatusFromAp = opensyncAPState.getUpgradeStatus(); + EquipmentUpgradeState fwUpgradeState = null; + FailureReason fwUpgradeFailureReason = null; + + if (opensyncAPState.getFirmwareUrl().equals(OvsdbStringConstants.OVSDB_AWLAN_AP_FACTORY_RESET) + || opensyncAPState.getFirmwareUrl().equals(OvsdbStringConstants.OVSDB_AWLAN_AP_FACTORY_RESET) + || opensyncAPState.getFirmwareUrl().equals(OvsdbStringConstants.OVSDB_AWLAN_AP_FACTORY_RESET) + || opensyncAPState.getFirmwareUrl().equals("")) { + + fwUpgradeState = EquipmentUpgradeState.undefined; + + } else { + fwUpgradeState = OvsdbToWlanCloudTypeMappingUtility + .getCloudEquipmentUpgradeStateFromOpensyncUpgradeStatus(upgradeStatusFromAp); + + if (upgradeStatusFromAp < 0) { + fwUpgradeFailureReason = OvsdbToWlanCloudTypeMappingUtility + .getCloudEquipmentUpgradeFailureReasonFromOpensyncUpgradeStatus(upgradeStatusFromAp); + } + } + + Status protocolStatus = statusServiceInterface.getOrNull(customerId, equipmentId, StatusDataType.PROTOCOL); + if (protocolStatus == null) { + protocolStatus = new Status(); + protocolStatus.setCustomerId(customerId); + protocolStatus.setEquipmentId(equipmentId); + protocolStatus.setStatusDataType(StatusDataType.PROTOCOL); + EquipmentProtocolStatusData protocolStatusData = new EquipmentProtocolStatusData(); + protocolStatus.setDetails(protocolStatusData); + + protocolStatus = statusServiceInterface.update(protocolStatus); + + } + + String reportedFwImageName = null; + String reportedAltFwImageName = null; + + if (opensyncAPState.getVersionMatrix().containsKey(OvsdbStringConstants.FW_IMAGE_ACTIVE_KEY)) { + reportedFwImageName = opensyncAPState.getVersionMatrix().get(OvsdbStringConstants.FW_IMAGE_ACTIVE_KEY); + } else { + reportedFwImageName = opensyncAPState.getVersionMatrix().get(OvsdbStringConstants.FW_IMAGE_NAME_KEY); + + } + + if (opensyncAPState.getVersionMatrix().containsKey(OvsdbStringConstants.FW_IMAGE_INACTIVE_KEY)) { + reportedAltFwImageName = opensyncAPState.getVersionMatrix().get(OvsdbStringConstants.FW_IMAGE_INACTIVE_KEY); + } else { + reportedAltFwImageName = opensyncAPState.getVersionMatrix().get(OvsdbStringConstants.FW_IMAGE_NAME_KEY); + + } + + EquipmentProtocolStatusData protocolStatusData = (EquipmentProtocolStatusData) protocolStatus.getDetails(); + protocolStatusData.setReportedSku(opensyncAPState.getSkuNumber()); + if (reportedFwImageName != null) { + protocolStatusData.setReportedSwVersion(reportedFwImageName); + } + protocolStatusData.setReportedSwAltVersion(reportedAltFwImageName); + protocolStatusData.setReportedHwVersion(opensyncAPState.getPlatformVersion()); + protocolStatusData.setSystemName(opensyncAPState.getModel()); + + List updates = new ArrayList<>(); + + // only post update if there is a change + if (!((EquipmentProtocolStatusData) statusServiceInterface + .getOrNull(customerId, equipmentId, StatusDataType.PROTOCOL).getDetails()).equals(protocolStatusData)) { + protocolStatus.setDetails(protocolStatusData); + updates.add(protocolStatus); + } + + Status firmwareStatus = statusServiceInterface.getOrNull(customerId, equipmentId, StatusDataType.FIRMWARE); + if (firmwareStatus == null) { + firmwareStatus = new Status(); + firmwareStatus.setCustomerId(customerId); + firmwareStatus.setEquipmentId(equipmentId); + firmwareStatus.setStatusDataType(StatusDataType.FIRMWARE); + firmwareStatus.setDetails(new EquipmentUpgradeStatusData()); + firmwareStatus = statusServiceInterface.update(firmwareStatus); + + } + + Equipment ce = getCustomerEquipment(apId); + if (ce != null) { + ce.getDetails(); + + if (fwUpgradeState.equals(EquipmentUpgradeState.up_to_date)) { + LOG.info("Firmware load is up to date."); + + EquipmentUpgradeStatusData firmwareStatusData = (EquipmentUpgradeStatusData) firmwareStatus + .getDetails(); + if (reportedFwImageName != null) { + if (!firmwareStatusData.getActiveSwVersion().equals(reportedFwImageName) + || !firmwareStatusData.getUpgradeState().equals(fwUpgradeState) + || !firmwareStatusData.getAlternateSwVersion().equals(reportedAltFwImageName)) { + firmwareStatusData.setActiveSwVersion(reportedFwImageName); + firmwareStatusData.setAlternateSwVersion(reportedAltFwImageName); + firmwareStatusData.setUpgradeState(fwUpgradeState, fwUpgradeFailureReason); + firmwareStatus.setDetails(firmwareStatusData); + updates.add(firmwareStatus); + } + + } + + if (!updates.isEmpty()) { // may be some updates from protocol + // status + updates = statusServiceInterface.update(updates); + } + + } else if (fwUpgradeState.equals(EquipmentUpgradeState.download_complete) + || fwUpgradeState.equals(EquipmentUpgradeState.apply_complete) + || fwUpgradeState.equals(EquipmentUpgradeState.apply_initiated) + || fwUpgradeState.equals(EquipmentUpgradeState.applying) + || fwUpgradeState.equals(EquipmentUpgradeState.downloading) + || fwUpgradeState.equals(EquipmentUpgradeState.download_initiated) + || fwUpgradeState.equals(EquipmentUpgradeState.reboot_initiated) + || fwUpgradeState.equals(EquipmentUpgradeState.rebooting)) { + + LOG.info("Firmware upgrade is in state {}", fwUpgradeState); + + EquipmentUpgradeStatusData firmwareStatusData = (EquipmentUpgradeStatusData) firmwareStatus + .getDetails(); + if (reportedFwImageName != null) { + if (!firmwareStatusData.getActiveSwVersion().equals(reportedFwImageName) + || !firmwareStatusData.getUpgradeState().equals(fwUpgradeState) + || !firmwareStatusData.getAlternateSwVersion().equals(reportedAltFwImageName)) { + firmwareStatusData.setActiveSwVersion(reportedFwImageName); + firmwareStatusData.setAlternateSwVersion(reportedAltFwImageName); + firmwareStatusData.setUpgradeState(fwUpgradeState, fwUpgradeFailureReason); + if (fwUpgradeState.equals(EquipmentUpgradeState.apply_initiated)) { + firmwareStatusData.setUpgradeStartTime(System.currentTimeMillis()); + } else if (fwUpgradeState.equals(EquipmentUpgradeState.reboot_initiated) + || fwUpgradeState.equals(EquipmentUpgradeState.rebooting)) { + firmwareStatusData.setRebooted(true); + } + firmwareStatus.setDetails(firmwareStatusData); + updates.add(firmwareStatus); + } + } + + if (!updates.isEmpty()) {// may be some updates from protocol + // status + updates = statusServiceInterface.update(updates); + } + + // no other action here, these are just transient states + + } else if (fwUpgradeState.equals(EquipmentUpgradeState.apply_failed) + || fwUpgradeState.equals(EquipmentUpgradeState.download_failed) + || fwUpgradeState.equals(EquipmentUpgradeState.reboot_failed)) { + LOG.warn("Firmware upgrade is in a failed state {} due to {}", fwUpgradeState, fwUpgradeFailureReason); + + EquipmentUpgradeStatusData firmwareStatusData = (EquipmentUpgradeStatusData) firmwareStatus + .getDetails(); + if (reportedFwImageName != null) { + if (!firmwareStatusData.getActiveSwVersion().equals(reportedFwImageName) + || !firmwareStatusData.getAlternateSwVersion().equals(reportedAltFwImageName) + || !firmwareStatusData.getUpgradeState().equals(fwUpgradeState) + || !firmwareStatusData.getReason().equals(fwUpgradeFailureReason)) { + firmwareStatusData.setActiveSwVersion(reportedFwImageName); + firmwareStatusData.setAlternateSwVersion(reportedAltFwImageName); + firmwareStatusData.setUpgradeState(fwUpgradeState, fwUpgradeFailureReason); + firmwareStatus.setDetails(firmwareStatusData); + updates.add(firmwareStatus); + updates = statusServiceInterface.update(updates); + reconcileFwVersionToTrack(ce, reportedFwImageName, opensyncAPState.getModel()); + } else { + if (!updates.isEmpty()) { + updates = statusServiceInterface.update(updates); + } + } + + } else { + if (!updates.isEmpty()) {// may be some updates from + // protocol + // status + updates = statusServiceInterface.update(updates); + } + } + + } else { + LOG.info("Firmware upgrade state is {}", fwUpgradeState); + EquipmentUpgradeStatusData firmwareStatusData = (EquipmentUpgradeStatusData) firmwareStatus + .getDetails(); + if (reportedFwImageName != null) { + if (!firmwareStatusData.getActiveSwVersion().equals(reportedFwImageName) + || !firmwareStatusData.getUpgradeState().equals(fwUpgradeState) + || !firmwareStatusData.getAlternateSwVersion().equals(reportedAltFwImageName)) { + firmwareStatusData.setActiveSwVersion(reportedFwImageName); + firmwareStatusData.setAlternateSwVersion(reportedAltFwImageName); + firmwareStatusData.setUpgradeState(fwUpgradeState, fwUpgradeFailureReason); + firmwareStatus.setDetails(firmwareStatusData); + updates.add(firmwareStatus); + updates = statusServiceInterface.update(updates); + } else { + if (!updates.isEmpty()) {// may be some updates from + // protocol + // status + updates = statusServiceInterface.update(updates); + } + } + } else { + if (!updates.isEmpty()) {// may be some updates from + // protocol + // status + updates = statusServiceInterface.update(updates); + } + + } + } + } + + } + + @Override + public void wifiVIFStateDbTableDelete(List vifStateTables, String apId) { + + LOG.info("wifiVIFStateDbTableDelete for AP {} rows {}", apId, vifStateTables); + OvsdbSession ovsdbSession = ovsdbSessionMapInterface.getSession(apId); + + if (ovsdbSession == null) { + LOG.debug("wifiVIFStateDbTableDelete::Cannot get Session for AP {}", apId); + return; + } + + int customerId = ovsdbSession.getCustomerId(); + long equipmentId = ovsdbSession.getEquipmentId(); + + if ((customerId < 0) || (equipmentId < 0)) { + LOG.debug("wifiVIFStateDbTableDelete::Cannot get valid CustomerId {} or EquipmentId {} for AP {}", + customerId, equipmentId, apId); + return; + } + + if (equipmentId < 0L) { + LOG.debug("wifiVIFStateDbTableDelete Cannot get equipmentId {} for session {}", equipmentId); + return; + } + + Status activeBssidsStatus = statusServiceInterface.getOrNull(customerId, equipmentId, + StatusDataType.ACTIVE_BSSIDS); + + if (activeBssidsStatus == null) { + return; // nothing to delete + + } + + ActiveBSSIDs statusDetails = (ActiveBSSIDs) activeBssidsStatus.getDetails(); + + List bssidList = statusDetails.getActiveBSSIDs(); + List toBeDeleted = new ArrayList<>(); + Equipment ce = equipmentServiceInterface.getOrNull(equipmentId); + List clientSessionsForCustomerAndEquipment = new ArrayList<>(); + if (ce != null) { + PaginationResponse clientSessions = clientServiceInterface.getSessionsForCustomer(customerId, + ImmutableSet.of(equipmentId), ImmutableSet.of(ce.getLocationId()), null, + new PaginationContext()); + clientSessionsForCustomerAndEquipment.addAll(clientSessions.getItems()); + } + for (OpensyncAPVIFState vifState : vifStateTables) { + + if (bssidList != null) { + for (ActiveBSSID activeBSSID : bssidList) { + if (activeBSSID.getBssid().equals(vifState.getMac()) + && activeBSSID.getSsid().equals(vifState.getSsid())) { + toBeDeleted.add(activeBSSID); + + } + } + } + + } + + bssidList.removeAll(toBeDeleted); + + statusDetails.setActiveBSSIDs(bssidList); + + activeBssidsStatus.setDetails(statusDetails); + + activeBssidsStatus = statusServiceInterface.update(activeBssidsStatus); + + LOG.debug("wifiVIFStateDbTableDelete Updated activeBSSIDs {}", activeBssidsStatus); + + } + + @Override + public void wifiAssociatedClientsDbTableDelete(String deletedClientMac, String apId) { - activeBssidsStatus = statusServiceInterface.update(activeBssidsStatus); + OvsdbSession ovsdbSession = ovsdbSessionMapInterface.getSession(apId); - if (LOG.isTraceEnabled()) { - LOG.trace("Processing Wifi_VIF_State table update for AP {}, updated ACTIVE_BSSID Status {}", apId, - activeBssidsStatus.toPrettyString()); - } - } + if (ovsdbSession == null) { + LOG.debug("wifiAssociatedClientsDbTableDelete::Cannot get Session for AP {}", apId); + return; + } - @Override - public void wifiInetStateDbTableUpdate(List inetStateTables, String apId) { + int customerId = ovsdbSession.getCustomerId(); + long equipmentId = ovsdbSession.getEquipmentId(); - LOG.debug("Received Wifi_Inet_State table update for AP {}", apId); + if ((customerId < 0) || (equipmentId < 0)) { + LOG.debug("wifiAssociatedClientsDbTableDelete::Cannot get valid CustomerId {} or EquipmentId {} for AP {}", + customerId, equipmentId, apId); + return; + } + Set macAddressSet = new HashSet<>(); + macAddressSet.add(new MacAddress(deletedClientMac)); + List clientSessionList = clientServiceInterface.getSessions(customerId, macAddressSet); - } + for (ClientSession session : clientSessionList) { - @Override - public void wifiInetStateDbTableDelete(List inetStateTables, String apId) { + ClientSessionDetails clientSessionDetails = session.getDetails(); - LOG.debug("Received Wifi_Inet_State table delete for AP {}", apId); + if ((clientSessionDetails.getAssociationState() != null) + && !clientSessionDetails.getAssociationState().equals(AssociationState.Disconnected)) { + clientSessionDetails.setDisconnectByClientTimestamp(System.currentTimeMillis()); + clientSessionDetails.setAssociationState(AssociationState.Disconnected); + session.setDetails(clientSessionDetails); + session = clientServiceInterface.updateSession(session); - } + if (LOG.isTraceEnabled()) { + LOG.trace("wifiAssociatedClientsDbTableDelete Updated client session, set to disconnected {}", + session.toPrettyString()); + } + } - @Override - public void wifiAssociatedClientsDbTableUpdate(List wifiAssociatedClients, - String apId) { + } - OvsdbSession ovsdbSession = ovsdbSessionMapInterface.getSession(apId); + } - if (ovsdbSession == null) { - LOG.debug("wifiAssociatedClientsDbTableUpdate::Cannot get Session for AP {}", apId); - return; - } + @Override + public void dhcpLeasedIpDbTableUpdate(List> dhcpAttributes, String apId, + RowUpdateOperation rowUpdateOperation) { - int customerId = ovsdbSession.getCustomerId(); - long equipmentId = ovsdbSession.getEquipmentId(); + LOG.info("dhcpLeasedIpDbTableUpdate {} operations on AP {} ", rowUpdateOperation, apId); - if ((customerId < 0) || (equipmentId < 0)) { - LOG.debug("wifiAssociatedClientsDbTableUpdate::Cannot get valid CustomerId {} or EquipmentId {} for AP {}", - customerId, equipmentId, apId); - return; - } + OvsdbSession ovsdbSession = ovsdbSessionMapInterface.getSession(apId); - Equipment ce = equipmentServiceInterface.getOrNull(equipmentId); + if (ovsdbSession == null) { + LOG.debug("updateDhcpIpClientFingerprints::Cannot get Session for AP {}", apId); + return; + } - if (ce == null) { - LOG.debug("wifiAssociatedClientsDbTableUpdate Cannot get customer Equipment for {}", apId); - return; - } + int customerId = ovsdbSession.getCustomerId(); + long equipmentId = ovsdbSession.getEquipmentId(); - if ((wifiAssociatedClients == null) || wifiAssociatedClients.isEmpty()) { - return; - } + if ((customerId < 0) || (equipmentId < 0)) { + LOG.debug("updateDhcpIpClientFingerprints::Cannot get valid CustomerId {} or EquipmentId {} for AP {}", + customerId, equipmentId, apId); + return; + } - for (OpensyncWifiAssociatedClients opensyncWifiAssociatedClients : wifiAssociatedClients) { - com.telecominfraproject.wlan.client.models.Client clientInstance = clientServiceInterface - .getOrNull(customerId, new MacAddress(opensyncWifiAssociatedClients.getMac())); + Equipment ce = getCustomerEquipment(apId); - boolean isReassociation = true; - if (clientInstance == null) { - clientInstance = new com.telecominfraproject.wlan.client.models.Client(); + if (ce == null) { + LOG.debug("updateDhcpIpClientFingerprints::Cannot get Equipment for AP {}", apId); + return; + } - clientInstance.setCustomerId(customerId); - clientInstance.setMacAddress(new MacAddress(opensyncWifiAssociatedClients.getMac())); - clientInstance.setDetails(new ClientInfoDetails()); - clientInstance = clientServiceInterface.create(clientInstance); + long locationId = ce.getLocationId(); - isReassociation = false; + //         "hwaddr": + //         "inet_addr": + //         "hostname": + //         "fingerprint": + //         "vendor_class": + //         "lease_time": + //         "subnet_mask": + //         "gateway": + //         "dhcp_server": + //         "primary_dns": + //         "secondary_dns": + //         "db_status": + //         "device_name": + //         "device_type": + //         "manuf_id": - } - ClientInfoDetails clientDetails = (ClientInfoDetails) clientInstance.getDetails(); + if (rowUpdateOperation.equals(RowUpdateOperation.INSERT)) { - clientInstance.setDetails(clientDetails); + List clientSessionList = new ArrayList<>(); + for (Map dhcpLeasedIps : dhcpAttributes) { + if (!dhcpLeasedIps.containsKey("hwaddr")) { - clientInstance = clientServiceInterface.update(clientInstance); + LOG.info("Cannot insert a client {} that has no hwaddr.", dhcpLeasedIps); + continue; - ClientSession clientSession = clientServiceInterface.getSessionOrNull(customerId, equipmentId, - clientInstance.getMacAddress()); + } - if (clientSession == null) { - clientSession = new ClientSession(); - clientSession.setCustomerId(customerId); - clientSession.setEquipmentId(equipmentId); - clientSession.setMacAddress(clientInstance.getMacAddress()); - clientSession.setLocationId(ce.getLocationId()); - ClientSessionDetails clientSessionDetails = new ClientSessionDetails(); - clientSessionDetails.setIsReassociation(isReassociation); - clientSessionDetails.setSessionId(clientInstance.getMacAddress().getAddressAsLong()); - clientSession.setDetails(clientSessionDetails); + MacAddress clientMacAddress = new MacAddress(dhcpLeasedIps.get("hwaddr")); + if (clientMacAddress.equals(equipmentServiceInterface.get(equipmentId).getBaseMacAddress())) { + LOG.info("Not a client device {} ", dhcpLeasedIps); + com.telecominfraproject.wlan.client.models.Client client = clientServiceInterface.getOrNull(customerId, + clientMacAddress); + if (client != null) { - clientSession = clientServiceInterface.updateSession(clientSession); - } + // In case somehow this equipment has accidentally been tagged as a client, remove + + ClientSession clientSession = clientServiceInterface.getSessionOrNull(customerId, equipmentId, clientMacAddress); + + if (clientSession != null) { + LOG.info("Deleting invalid client session {}", clientServiceInterface.deleteSession(customerId, equipmentId, clientMacAddress)); + } + + LOG.info("Deleting invalid client {}", clientServiceInterface.delete(customerId, clientMacAddress)); - ClientSessionDetails clientSessionDetails = clientSession.getDetails(); - clientSessionDetails.setAssociationState(AssociationState._802_11_Associated); - clientSessionDetails.setAssocTimestamp(System.currentTimeMillis()); - clientSessionDetails.setSessionId(clientInstance.getMacAddress().getAddressAsLong()); - clientSession.getDetails().mergeSession(clientSessionDetails); + + } + continue; + } + com.telecominfraproject.wlan.client.models.Client client = clientServiceInterface.getOrNull(customerId, + clientMacAddress); + if (client != null) { + LOG.info("Client {} already exists on the cloud, update client values", dhcpLeasedIps); - clientSession = clientServiceInterface.updateSession(clientSession); + ClientInfoDetails clientDetails = (ClientInfoDetails) client.getDetails(); + if (dhcpLeasedIps.containsKey("hostname")) { - } + clientDetails.setHostName(dhcpLeasedIps.get("hostname")); - } + } - @Override - public void awlanNodeDbTableUpdate(OpensyncAWLANNode opensyncAPState, String apId) { + if (dhcpLeasedIps.containsKey("fingerprint")) { - LOG.debug("AP {} table AWLAN_Node updated {}", apId, opensyncAPState); - OvsdbSession ovsdbSession = ovsdbSessionMapInterface.getSession(apId); + clientDetails.setApFingerprint(dhcpLeasedIps.get("fingerprint")); + } - if (ovsdbSession == null) { - LOG.debug("awlanNodeDbTableUpdate::Cannot get Session for AP {}", apId); - return; - } + if (dhcpLeasedIps.containsKey("device_type")) { - int customerId = ovsdbSession.getCustomerId(); - long equipmentId = ovsdbSession.getEquipmentId(); + DhcpFpDeviceType dhcpFpDeviceType = DhcpFpDeviceType + .getByName(dhcpLeasedIps.get("device_type")); + ClientType clientType = OvsdbToWlanCloudTypeMappingUtility + .getClientTypeForDhcpFpDeviceType(dhcpFpDeviceType); - if ((customerId < 0) || (equipmentId < 0)) { - LOG.debug("awlanNodeDbTableUpdate::Cannot get valid CustomerId {} or EquipmentId {} for AP {}", customerId, - equipmentId, apId); - return; - } - - int upgradeStatusFromAp = opensyncAPState.getUpgradeStatus(); - EquipmentUpgradeState fwUpgradeState = null; - FailureReason fwUpgradeFailureReason = null; - - if (opensyncAPState.getFirmwareUrl().equals(OvsdbStringConstants.OVSDB_AWLAN_AP_FACTORY_RESET) - || opensyncAPState.getFirmwareUrl().equals(OvsdbStringConstants.OVSDB_AWLAN_AP_FACTORY_RESET) - || opensyncAPState.getFirmwareUrl().equals(OvsdbStringConstants.OVSDB_AWLAN_AP_FACTORY_RESET) - || opensyncAPState.getFirmwareUrl().equals("")) { - - fwUpgradeState = EquipmentUpgradeState.undefined; - - } else { - fwUpgradeState = OvsdbToWlanCloudTypeMappingUtility - .getCloudEquipmentUpgradeStateFromOpensyncUpgradeStatus(upgradeStatusFromAp); - - if (upgradeStatusFromAp < 0) { - fwUpgradeFailureReason = OvsdbToWlanCloudTypeMappingUtility - .getCloudEquipmentUpgradeFailureReasonFromOpensyncUpgradeStatus(upgradeStatusFromAp); - } - } - - - Status protocolStatus = statusServiceInterface.getOrNull(customerId, equipmentId, StatusDataType.PROTOCOL); - if (protocolStatus == null) { - protocolStatus = new Status(); - protocolStatus.setCustomerId(customerId); - protocolStatus.setEquipmentId(equipmentId); - protocolStatus.setStatusDataType(StatusDataType.PROTOCOL); - EquipmentProtocolStatusData protocolStatusData = new EquipmentProtocolStatusData(); - protocolStatus.setDetails(protocolStatusData); - - protocolStatus = statusServiceInterface.update(protocolStatus); - - } - - String reportedFwImageName = null; - String reportedAltFwImageName = null; - - if (opensyncAPState.getVersionMatrix().containsKey(OvsdbStringConstants.FW_IMAGE_ACTIVE_KEY)) { - reportedFwImageName = opensyncAPState.getVersionMatrix().get(OvsdbStringConstants.FW_IMAGE_ACTIVE_KEY); - } else { - reportedFwImageName = opensyncAPState.getVersionMatrix().get(OvsdbStringConstants.FW_IMAGE_NAME_KEY); - - } - - if (opensyncAPState.getVersionMatrix().containsKey(OvsdbStringConstants.FW_IMAGE_INACTIVE_KEY)) { - reportedAltFwImageName = opensyncAPState.getVersionMatrix().get(OvsdbStringConstants.FW_IMAGE_INACTIVE_KEY); - } else { - reportedAltFwImageName = opensyncAPState.getVersionMatrix().get(OvsdbStringConstants.FW_IMAGE_NAME_KEY); - - } - - EquipmentProtocolStatusData protocolStatusData = (EquipmentProtocolStatusData) protocolStatus.getDetails(); - protocolStatusData.setReportedSku(opensyncAPState.getSkuNumber()); - if (reportedFwImageName != null) { - protocolStatusData.setReportedSwVersion(reportedFwImageName); - } - protocolStatusData.setReportedSwAltVersion(reportedAltFwImageName); - protocolStatusData.setReportedHwVersion(opensyncAPState.getPlatformVersion()); - protocolStatusData.setSystemName(opensyncAPState.getModel()); - - List updates = new ArrayList<>(); - - // only post update if there is a change - if (!((EquipmentProtocolStatusData) statusServiceInterface - .getOrNull(customerId, equipmentId, StatusDataType.PROTOCOL).getDetails()).equals(protocolStatusData)) { - protocolStatus.setDetails(protocolStatusData); - updates.add(protocolStatus); - } - - Status firmwareStatus = statusServiceInterface.getOrNull(customerId, equipmentId, StatusDataType.FIRMWARE); - if (firmwareStatus == null) { - firmwareStatus = new Status(); - firmwareStatus.setCustomerId(customerId); - firmwareStatus.setEquipmentId(equipmentId); - firmwareStatus.setStatusDataType(StatusDataType.FIRMWARE); - firmwareStatus.setDetails(new EquipmentUpgradeStatusData()); - firmwareStatus = statusServiceInterface.update(firmwareStatus); - - } - - Equipment ce = getCustomerEquipment(apId); - if (ce != null) { - ce.getDetails(); - - if (fwUpgradeState.equals(EquipmentUpgradeState.up_to_date)) { - LOG.info("Firmware load is up to date."); - - EquipmentUpgradeStatusData firmwareStatusData = (EquipmentUpgradeStatusData) firmwareStatus - .getDetails(); - if (reportedFwImageName != null) { - if (!firmwareStatusData.getActiveSwVersion().equals(reportedFwImageName) - || !firmwareStatusData.getUpgradeState().equals(fwUpgradeState) - || !firmwareStatusData.getAlternateSwVersion().equals(reportedAltFwImageName)) { - firmwareStatusData.setActiveSwVersion(reportedFwImageName); - firmwareStatusData.setAlternateSwVersion(reportedAltFwImageName); - firmwareStatusData.setUpgradeState(fwUpgradeState, fwUpgradeFailureReason); - firmwareStatus.setDetails(firmwareStatusData); - updates.add(firmwareStatus); - } - - } - - if (!updates.isEmpty()) { // may be some updates from protocol - // status - updates = statusServiceInterface.update(updates); - } - - } else if (fwUpgradeState.equals(EquipmentUpgradeState.download_complete) - || fwUpgradeState.equals(EquipmentUpgradeState.apply_complete) - || fwUpgradeState.equals(EquipmentUpgradeState.apply_initiated) - || fwUpgradeState.equals(EquipmentUpgradeState.applying) - || fwUpgradeState.equals(EquipmentUpgradeState.downloading) - || fwUpgradeState.equals(EquipmentUpgradeState.download_initiated) - || fwUpgradeState.equals(EquipmentUpgradeState.reboot_initiated) - || fwUpgradeState.equals(EquipmentUpgradeState.rebooting)) { - - LOG.info("Firmware upgrade is in state {}", fwUpgradeState); - - EquipmentUpgradeStatusData firmwareStatusData = (EquipmentUpgradeStatusData) firmwareStatus - .getDetails(); - if (reportedFwImageName != null) { - if (!firmwareStatusData.getActiveSwVersion().equals(reportedFwImageName) - || !firmwareStatusData.getUpgradeState().equals(fwUpgradeState) - || !firmwareStatusData.getAlternateSwVersion().equals(reportedAltFwImageName)) { - firmwareStatusData.setActiveSwVersion(reportedFwImageName); - firmwareStatusData.setAlternateSwVersion(reportedAltFwImageName); - firmwareStatusData.setUpgradeState(fwUpgradeState, fwUpgradeFailureReason); - if (fwUpgradeState.equals(EquipmentUpgradeState.apply_initiated)) { - firmwareStatusData.setUpgradeStartTime(System.currentTimeMillis()); - } else if (fwUpgradeState.equals(EquipmentUpgradeState.reboot_initiated) - || fwUpgradeState.equals(EquipmentUpgradeState.rebooting)) { - firmwareStatusData.setRebooted(true); - } - firmwareStatus.setDetails(firmwareStatusData); - updates.add(firmwareStatus); - } - } - - if (!updates.isEmpty()) {// may be some updates from protocol - // status - updates = statusServiceInterface.update(updates); - } - - // no other action here, these are just transient states - - } else if (fwUpgradeState.equals(EquipmentUpgradeState.apply_failed) - || fwUpgradeState.equals(EquipmentUpgradeState.download_failed) - || fwUpgradeState.equals(EquipmentUpgradeState.reboot_failed)) { - LOG.warn("Firmware upgrade is in a failed state {} due to {}", fwUpgradeState, fwUpgradeFailureReason); - - EquipmentUpgradeStatusData firmwareStatusData = (EquipmentUpgradeStatusData) firmwareStatus - .getDetails(); - if (reportedFwImageName != null) { - if (!firmwareStatusData.getActiveSwVersion().equals(reportedFwImageName) - || !firmwareStatusData.getAlternateSwVersion().equals(reportedAltFwImageName) - || !firmwareStatusData.getUpgradeState().equals(fwUpgradeState) - || !firmwareStatusData.getReason().equals(fwUpgradeFailureReason)) { - firmwareStatusData.setActiveSwVersion(reportedFwImageName); - firmwareStatusData.setAlternateSwVersion(reportedAltFwImageName); - firmwareStatusData.setUpgradeState(fwUpgradeState, fwUpgradeFailureReason); - firmwareStatus.setDetails(firmwareStatusData); - updates.add(firmwareStatus); - updates = statusServiceInterface.update(updates); - reconcileFwVersionToTrack(ce, reportedFwImageName, opensyncAPState.getModel()); - } else { - if (!updates.isEmpty()) { - updates = statusServiceInterface.update(updates); - } - } - - } else { - if (!updates.isEmpty()) {// may be some updates from - // protocol - // status - updates = statusServiceInterface.update(updates); - } - } - - } else { - LOG.info("Firmware upgrade state is {}", fwUpgradeState); - EquipmentUpgradeStatusData firmwareStatusData = (EquipmentUpgradeStatusData) firmwareStatus - .getDetails(); - if (reportedFwImageName != null) { - if (!firmwareStatusData.getActiveSwVersion().equals(reportedFwImageName) - || !firmwareStatusData.getUpgradeState().equals(fwUpgradeState) - || !firmwareStatusData.getAlternateSwVersion().equals(reportedAltFwImageName)) { - firmwareStatusData.setActiveSwVersion(reportedFwImageName); - firmwareStatusData.setAlternateSwVersion(reportedAltFwImageName); - firmwareStatusData.setUpgradeState(fwUpgradeState, fwUpgradeFailureReason); - firmwareStatus.setDetails(firmwareStatusData); - updates.add(firmwareStatus); - updates = statusServiceInterface.update(updates); - } else { - if (!updates.isEmpty()) {// may be some updates from - // protocol - // status - updates = statusServiceInterface.update(updates); - } - } - } else { - if (!updates.isEmpty()) {// may be some updates from - // protocol - // status - updates = statusServiceInterface.update(updates); - } - - } - } - } - - } - - @Override - public void wifiVIFStateDbTableDelete(List vifStateTables, String apId) { - - LOG.info("wifiVIFStateDbTableDelete for AP {} rows {}", apId, vifStateTables); - OvsdbSession ovsdbSession = ovsdbSessionMapInterface.getSession(apId); - - if (ovsdbSession == null) { - LOG.debug("wifiVIFStateDbTableDelete::Cannot get Session for AP {}", apId); - return; - } - - int customerId = ovsdbSession.getCustomerId(); - long equipmentId = ovsdbSession.getEquipmentId(); - - if ((customerId < 0) || (equipmentId < 0)) { - LOG.debug("wifiVIFStateDbTableDelete::Cannot get valid CustomerId {} or EquipmentId {} for AP {}", - customerId, equipmentId, apId); - return; - } - - if (equipmentId < 0L) { - LOG.debug("wifiVIFStateDbTableDelete Cannot get equipmentId {} for session {}", equipmentId); - return; - } - - Status activeBssidsStatus = statusServiceInterface.getOrNull(customerId, equipmentId, - StatusDataType.ACTIVE_BSSIDS); - - if (activeBssidsStatus == null) { - return; // nothing to delete - - } - - ActiveBSSIDs statusDetails = (ActiveBSSIDs) activeBssidsStatus.getDetails(); - - List bssidList = statusDetails.getActiveBSSIDs(); - List toBeDeleted = new ArrayList<>(); - Equipment ce = equipmentServiceInterface.getOrNull(equipmentId); - List clientSessionsForCustomerAndEquipment = new ArrayList<>(); - if (ce != null) { - PaginationResponse clientSessions = clientServiceInterface.getSessionsForCustomer(customerId, - ImmutableSet.of(equipmentId), ImmutableSet.of(ce.getLocationId()), null, - new PaginationContext()); - clientSessionsForCustomerAndEquipment.addAll(clientSessions.getItems()); - } - for (OpensyncAPVIFState vifState : vifStateTables) { - - if (bssidList != null) { - for (ActiveBSSID activeBSSID : bssidList) { - if (activeBSSID.getBssid().equals(vifState.getMac()) - && activeBSSID.getSsid().equals(vifState.getSsid())) { - toBeDeleted.add(activeBSSID); + LOG.debug("Translate from ovsdb {} to cloud {}", dhcpFpDeviceType, clientType); - } - } - } + clientDetails.setClientType(clientType.getId()); - } + } + client.setDetails(clientDetails); - bssidList.removeAll(toBeDeleted); + client = clientServiceInterface.update(client); - statusDetails.setActiveBSSIDs(bssidList); + LOG.info("Updated Client {}.", client); - activeBssidsStatus.setDetails(statusDetails); + // In this case, we might have a session, as the client + // already exists on the cloud, update if required + ClientSession session = updateClientSession(customerId, equipmentId, locationId, dhcpLeasedIps, + clientMacAddress); + if (session != null) { + clientSessionList.add(session); - activeBssidsStatus = statusServiceInterface.update(activeBssidsStatus); + } - LOG.debug("wifiVIFStateDbTableDelete Updated activeBSSIDs {}", activeBssidsStatus); + } else { - } + client = new com.telecominfraproject.wlan.client.models.Client(); - @Override - public void wifiAssociatedClientsDbTableDelete(String deletedClientMac, String apId) { + client.setCustomerId(customerId); + client.setMacAddress(clientMacAddress); - OvsdbSession ovsdbSession = ovsdbSessionMapInterface.getSession(apId); + ClientInfoDetails clientDetails = new ClientInfoDetails(); - if (ovsdbSession == null) { - LOG.debug("wifiAssociatedClientsDbTableDelete::Cannot get Session for AP {}", apId); - return; - } + if (dhcpLeasedIps.containsKey("hostname")) { - int customerId = ovsdbSession.getCustomerId(); - long equipmentId = ovsdbSession.getEquipmentId(); + clientDetails.setHostName(dhcpLeasedIps.get("hostname")); - if ((customerId < 0) || (equipmentId < 0)) { - LOG.debug("wifiAssociatedClientsDbTableDelete::Cannot get valid CustomerId {} or EquipmentId {} for AP {}", - customerId, equipmentId, apId); - return; - } + } - Set macAddressSet = new HashSet<>(); - macAddressSet.add(new MacAddress(deletedClientMac)); - List clientSessionList = clientServiceInterface.getSessions(customerId, macAddressSet); + if (dhcpLeasedIps.containsKey("fingerprint")) { - for (ClientSession session : clientSessionList) { + clientDetails.setApFingerprint(dhcpLeasedIps.get("fingerprint")); + } - ClientSessionDetails clientSessionDetails = session.getDetails(); + if (dhcpLeasedIps.containsKey("device_type")) { + DhcpFpDeviceType dhcpFpDeviceType = DhcpFpDeviceType + .getByName(dhcpLeasedIps.get("device_type")); + ClientType clientType = OvsdbToWlanCloudTypeMappingUtility + .getClientTypeForDhcpFpDeviceType(dhcpFpDeviceType); - if ((clientSessionDetails.getAssociationState() != null) - && !clientSessionDetails.getAssociationState().equals(AssociationState.Disconnected)) { - clientSessionDetails.setDisconnectByClientTimestamp(System.currentTimeMillis()); - clientSessionDetails.setAssociationState(AssociationState.Disconnected); + LOG.debug("Translate from ovsdb {} to cloud {}", dhcpFpDeviceType, clientType); - session.setDetails(clientSessionDetails); - session = clientServiceInterface.updateSession(session); + clientDetails.setClientType(clientType.getId()); - if (LOG.isTraceEnabled()) { - LOG.trace("wifiAssociatedClientsDbTableDelete Updated client session, set to disconnected {}", - session.toPrettyString()); - } - } + } - } + client.setDetails(clientDetails); - } + client = clientServiceInterface.create(client); + LOG.info("Created Client {}.", client); + } - @Override - public void dhcpLeasedIpDbTableUpdate(List> dhcpAttributes, String apId, - RowUpdateOperation rowUpdateOperation) { + } - LOG.info("dhcpLeasedIpDbTableUpdate {} operations on AP {} ", rowUpdateOperation, apId); + if (!clientSessionList.isEmpty()) { + LOG.info("Updating client sessions {}", clientSessionList); + clientSessionList = clientServiceInterface.updateSessions(clientSessionList); + LOG.info("Updated client sessions {}", clientSessionList); + } - OvsdbSession ovsdbSession = ovsdbSessionMapInterface.getSession(apId); + } else if (rowUpdateOperation.equals(RowUpdateOperation.MODIFY) + || rowUpdateOperation.equals(RowUpdateOperation.INIT)) { - if (ovsdbSession == null) { - LOG.debug("updateDhcpIpClientFingerprints::Cannot get Session for AP {}", apId); - return; - } + List clientSessionList = new ArrayList<>(); - int customerId = ovsdbSession.getCustomerId(); - long equipmentId = ovsdbSession.getEquipmentId(); + for (Map dhcpLeasedIps : dhcpAttributes) { - if ((customerId < 0) || (equipmentId < 0)) { - LOG.debug("updateDhcpIpClientFingerprints::Cannot get valid CustomerId {} or EquipmentId {} for AP {}", - customerId, equipmentId, apId); - return; - } + if (!dhcpLeasedIps.containsKey("hwaddr")) { + LOG.info("Cannot update a client {} that has no hwaddr.", dhcpLeasedIps); + continue; - Equipment ce = getCustomerEquipment(apId); + } - if (ce == null) { - LOG.debug("updateDhcpIpClientFingerprints::Cannot get Equipment for AP {}", apId); - return; - } + MacAddress clientMacAddress = new MacAddress(dhcpLeasedIps.get("hwaddr")); + + if (clientMacAddress.equals(equipmentServiceInterface.get(equipmentId).getBaseMacAddress())) { - long locationId = ce.getLocationId(); + LOG.info("Not a client device {} ", dhcpLeasedIps); + com.telecominfraproject.wlan.client.models.Client client = clientServiceInterface.getOrNull(customerId, + clientMacAddress); + if (client != null) { - //         "hwaddr": - //         "inet_addr": - //         "hostname": - //         "fingerprint": - //         "vendor_class": - //         "lease_time": - //         "subnet_mask": - //         "gateway": - //         "dhcp_server": - //         "primary_dns": - //         "secondary_dns": - //         "db_status": - //         "device_name": - //         "device_type": - //         "manuf_id": + // In case somehow this equipment has accidentally been tagged as a client, remove + + ClientSession clientSession = clientServiceInterface.getSessionOrNull(customerId, equipmentId, clientMacAddress); + + if (clientSession != null) { + LOG.info("Deleting invalid client session {}", clientServiceInterface.deleteSession(customerId, equipmentId, clientMacAddress)); + } + + LOG.info("Deleting invalid client {}", clientServiceInterface.delete(customerId, clientMacAddress)); - if (rowUpdateOperation.equals(RowUpdateOperation.INSERT)) { + + } + continue; + + } + + com.telecominfraproject.wlan.client.models.Client client = clientServiceInterface.getOrNull(customerId, + clientMacAddress); + if (client == null) { + LOG.info("Client {} does not exist on the cloud. Creating...", dhcpLeasedIps); + client = new com.telecominfraproject.wlan.client.models.Client(); + client.setCustomerId(customerId); + client.setMacAddress(clientMacAddress); + ClientInfoDetails clientDetails = new ClientInfoDetails(); + client.setDetails(clientDetails); - List clientSessionList = new ArrayList<>(); - for (Map dhcpLeasedIps : dhcpAttributes) { - if (!dhcpLeasedIps.containsKey("hwaddr")) { + client = clientServiceInterface.create(client); + } - LOG.info("Cannot insert a client {} that has no hwaddr.", dhcpLeasedIps); - continue; + ClientInfoDetails clientDetails = (ClientInfoDetails) client.getDetails(); + if (dhcpLeasedIps.containsKey("hostname")) { - } + clientDetails.setHostName(dhcpLeasedIps.get("hostname")); - MacAddress clientMacAddress = new MacAddress(dhcpLeasedIps.get("hwaddr")); - com.telecominfraproject.wlan.client.models.Client client = clientServiceInterface.getOrNull(customerId, - clientMacAddress); - if (client != null) { - LOG.info("Client {} already exists on the cloud, update client values", dhcpLeasedIps); + } - ClientInfoDetails clientDetails = (ClientInfoDetails) client.getDetails(); - if (dhcpLeasedIps.containsKey("hostname")) { + if (dhcpLeasedIps.containsKey("fingerprint")) { - clientDetails.setHostName(dhcpLeasedIps.get("hostname")); + clientDetails.setApFingerprint(dhcpLeasedIps.get("fingerprint")); + } - } + if (dhcpLeasedIps.containsKey("device_type")) { - if (dhcpLeasedIps.containsKey("fingerprint")) { + DhcpFpDeviceType dhcpFpDeviceType = DhcpFpDeviceType.getByName(dhcpLeasedIps.get("device_type")); + ClientType clientType = OvsdbToWlanCloudTypeMappingUtility + .getClientTypeForDhcpFpDeviceType(dhcpFpDeviceType); - clientDetails.setApFingerprint(dhcpLeasedIps.get("fingerprint")); - } + LOG.debug("Translate from ovsdb {} to cloud {}", dhcpFpDeviceType, clientType); - if (dhcpLeasedIps.containsKey("device_type")) { + clientDetails.setClientType(clientType.getId()); + } - DhcpFpDeviceType dhcpFpDeviceType = DhcpFpDeviceType - .getByName(dhcpLeasedIps.get("device_type")); - ClientType clientType = OvsdbToWlanCloudTypeMappingUtility - .getClientTypeForDhcpFpDeviceType(dhcpFpDeviceType); + client.setDetails(clientDetails); - LOG.debug("Translate from ovsdb {} to cloud {}", dhcpFpDeviceType, clientType); + client = clientServiceInterface.update(client); - clientDetails.setClientType(clientType.getId()); + LOG.info("Updated Client {}.", client); - } + // check if there is a session for this client - client.setDetails(clientDetails); + ClientSession session = updateClientSession(customerId, equipmentId, locationId, dhcpLeasedIps, + clientMacAddress); + if (session != null) { + clientSessionList.add(session); - client = clientServiceInterface.update(client); + } - LOG.info("Updated Client {}.", client); + } - // In this case, we might have a session, as the client - // already exists on the cloud, update if required - ClientSession session = updateClientSession(customerId, equipmentId, locationId, dhcpLeasedIps, - clientMacAddress); - if (session != null) { - clientSessionList.add(session); + if (!clientSessionList.isEmpty()) { + LOG.info("Updating client sessions {}", clientSessionList); + clientSessionList = clientServiceInterface.updateSessions(clientSessionList); + LOG.info("Updated client sessions {}", clientSessionList); + } - } - - - } else { - - client = new com.telecominfraproject.wlan.client.models.Client(); - - client.setCustomerId(customerId); - client.setMacAddress(clientMacAddress); - - ClientInfoDetails clientDetails = new ClientInfoDetails(); - - if (dhcpLeasedIps.containsKey("hostname")) { - - clientDetails.setHostName(dhcpLeasedIps.get("hostname")); - - } - - if (dhcpLeasedIps.containsKey("fingerprint")) { - - clientDetails.setApFingerprint(dhcpLeasedIps.get("fingerprint")); - } - - if (dhcpLeasedIps.containsKey("device_type")) { - - - DhcpFpDeviceType dhcpFpDeviceType = DhcpFpDeviceType - .getByName(dhcpLeasedIps.get("device_type")); - ClientType clientType = OvsdbToWlanCloudTypeMappingUtility - .getClientTypeForDhcpFpDeviceType(dhcpFpDeviceType); - - LOG.debug("Translate from ovsdb {} to cloud {}", dhcpFpDeviceType, clientType); - - clientDetails.setClientType(clientType.getId()); - - } - - client.setDetails(clientDetails); - - client = clientServiceInterface.create(client); - - LOG.info("Created Client {}.", client); - } - - - } - - if (!clientSessionList.isEmpty()) { - LOG.info("Updating client sessions {}", clientSessionList); - clientSessionList = clientServiceInterface.updateSessions(clientSessionList); - LOG.info("Updated client sessions {}", clientSessionList); - } - - - } else if (rowUpdateOperation.equals(RowUpdateOperation.MODIFY) - || rowUpdateOperation.equals(RowUpdateOperation.INIT)) { - - List clientSessionList = new ArrayList<>(); - - for (Map dhcpLeasedIps : dhcpAttributes) { - - if (!dhcpLeasedIps.containsKey("hwaddr")) { - - LOG.info("Cannot update a client {} that has no hwaddr.", dhcpLeasedIps); - continue; - - } - - MacAddress clientMacAddress = new MacAddress(dhcpLeasedIps.get("hwaddr")); - com.telecominfraproject.wlan.client.models.Client client = clientServiceInterface.getOrNull(customerId, - clientMacAddress); - if (client == null) { - LOG.info("Client {} does not exist on the cloud. Creating...", dhcpLeasedIps); - client = new com.telecominfraproject.wlan.client.models.Client(); - client.setCustomerId(customerId); - client.setMacAddress(clientMacAddress); - ClientInfoDetails clientDetails = new ClientInfoDetails(); - - client.setDetails(clientDetails); - - client = clientServiceInterface.create(client); - - } - - ClientInfoDetails clientDetails = (ClientInfoDetails) client.getDetails(); - if (dhcpLeasedIps.containsKey("hostname")) { - - clientDetails.setHostName(dhcpLeasedIps.get("hostname")); - - } - - if (dhcpLeasedIps.containsKey("fingerprint")) { - - clientDetails.setApFingerprint(dhcpLeasedIps.get("fingerprint")); - } - - if (dhcpLeasedIps.containsKey("device_type")) { - - - DhcpFpDeviceType dhcpFpDeviceType = DhcpFpDeviceType.getByName(dhcpLeasedIps.get("device_type")); - ClientType clientType = OvsdbToWlanCloudTypeMappingUtility - .getClientTypeForDhcpFpDeviceType(dhcpFpDeviceType); - - LOG.debug("Translate from ovsdb {} to cloud {}", dhcpFpDeviceType, clientType); - - clientDetails.setClientType(clientType.getId()); - - } - - client.setDetails(clientDetails); - - client = clientServiceInterface.update(client); - - LOG.info("Updated Client {}.", client); - - // check if there is a session for this client - - ClientSession session = updateClientSession(customerId, equipmentId, locationId, dhcpLeasedIps, - clientMacAddress); - if (session != null) { - clientSessionList.add(session); - - } - - } - - if (!clientSessionList.isEmpty()) { - LOG.info("Updating client sessions {}", clientSessionList); - clientSessionList = clientServiceInterface.updateSessions(clientSessionList); - LOG.info("Updated client sessions {}", clientSessionList); - } - - } else if (rowUpdateOperation.equals(RowUpdateOperation.DELETE)) { - // Client should not be 'deleted' from Cloud - LOG.debug("Recieved deletions, not removing client(s) from cloud", dhcpAttributes); - } - - - } - - protected ClientSession updateClientSession(int customerId, long equipmentId, long locationId, - Map dhcpLeasedIps, MacAddress clientMacAddress) { - ClientSession session = clientServiceInterface.getSessionOrNull(customerId, equipmentId, clientMacAddress); - - //         "hwaddr": -- - //         "inet_addr": -- - //         "hostname": -- - //         "fingerprint": -- - //         "vendor_class": -- - //         "lease_time": -- - //         "subnet_mask": -- - //         "gateway": -- - //         "dhcp_server": -- - //         "primary_dns": -- - //         "secondary_dns": -- - //         "db_status": - //         "device_name": - //         "device_type": - //         "manuf_id": - - - if (session == null) { - session = new ClientSession(); - } - session.setCustomerId(customerId); - session.setEquipmentId(equipmentId); - session.setLocationId(locationId); - session.setMacAddress(clientMacAddress); - session.setDetails(new ClientSessionDetails()); - - ClientSessionDetails clientSessionDetails = new ClientSessionDetails(); - - if (dhcpLeasedIps.containsKey("fingerprint")) { - - clientSessionDetails.setApFingerprint(dhcpLeasedIps.get("fingerprint")); - } - - if (dhcpLeasedIps.containsKey("inet_addr")) { - - try { - clientSessionDetails.setIpAddress(InetAddress.getByName(dhcpLeasedIps.get("inet_addr"))); - } catch (UnknownHostException e) { - LOG.error("Invalid Client IP", e); - } - - } - - - if (dhcpLeasedIps.containsKey("hostname")) { - - clientSessionDetails.setHostname(dhcpLeasedIps.get("hostname")); - - } - - - ClientDhcpDetails clientDhcpDetails = new ClientDhcpDetails(clientSessionDetails.getSessionId()); - - if (dhcpLeasedIps.containsKey("dhcp_server")) { - try { - clientDhcpDetails.setDhcpServerIp(InetAddress.getByName(dhcpLeasedIps.get("dhcp_server"))); - } catch (UnknownHostException e) { - LOG.error("Invalid DhcpServer", e); - } - } - - if (dhcpLeasedIps.containsKey("lease_time")) { - Integer leaseTime = Integer.valueOf(dhcpLeasedIps.get("lease_time")); - clientDhcpDetails.setLeaseTimeInSeconds(leaseTime); - } - - if (dhcpLeasedIps.containsKey("gateway")) { - try { - clientDhcpDetails.setGatewayIp(InetAddress.getByName(dhcpLeasedIps.get("gateway"))); - } catch (UnknownHostException e) { - LOG.error("Invalid Gateway IP", e); - - try { - clientDhcpDetails.setGatewayIp(InetAddress.getByAddress(dhcpLeasedIps.get("gateway").getBytes())); - } catch (UnknownHostException e1) { - // TODO Auto-generated catch block - LOG.error("Invalid Gateway Address", e); - } - - } - } - - if (dhcpLeasedIps.containsKey("subnet_mask")) { - try { - clientDhcpDetails.setSubnetMask(InetAddress.getByName(dhcpLeasedIps.get("subnet_mask"))); - } catch (UnknownHostException e) { - LOG.error("Invalid Subnet Mask", e); - try { - clientDhcpDetails - .setGatewayIp(InetAddress.getByAddress(dhcpLeasedIps.get("subnet_mask").getBytes())); - } catch (UnknownHostException e1) { - // TODO Auto-generated catch block - LOG.error("Invalid Subnet Mask Address", e); - } - } - } - - if (dhcpLeasedIps.containsKey("primary_dns")) { - try { - clientDhcpDetails.setPrimaryDns(InetAddress.getByName(dhcpLeasedIps.get("primary_dns"))); - } catch (UnknownHostException e) { - LOG.error("Invalid Primary DNS", e); - try { - clientDhcpDetails - .setGatewayIp(InetAddress.getByAddress(dhcpLeasedIps.get("primary_dns").getBytes())); - } catch (UnknownHostException e1) { - // TODO Auto-generated catch block - LOG.error("Invalid Primary DNS Address", e); - } - - } - } - - if (dhcpLeasedIps.containsKey("secondary_dns")) { - try { - clientDhcpDetails.setSecondaryDns(InetAddress.getByName(dhcpLeasedIps.get("secondary_dns"))); - } catch (UnknownHostException e) { - LOG.error("Invalid Secondary DNS", e); - try { - clientDhcpDetails - .setGatewayIp(InetAddress.getByAddress(dhcpLeasedIps.get("secondary_dns").getBytes())); - } catch (UnknownHostException e1) { - // TODO Auto-generated catch block - LOG.error("Invalid Seconary DNS Address", e); - } - } - } - - - if (dhcpLeasedIps.containsKey("device_name")) { - clientSessionDetails.setClassificationName(dhcpLeasedIps.get("device_name")); - } - - clientSessionDetails.setDhcpDetails(clientDhcpDetails); - - session.getDetails().mergeSession(clientSessionDetails); - - - return session; - } - - @Override - public void commandStateDbTableUpdate(List> commandStateAttributes, String apId, - RowUpdateOperation rowUpdateOperation) { - LOG.info("Received Command_State row(s) {} rowUpdateOperation {} for ap {}", commandStateAttributes, - rowUpdateOperation, apId); - - // TODO: will handle changes from Command_State table - } + } else if (rowUpdateOperation.equals(RowUpdateOperation.DELETE)) { + // Client should not be 'deleted' from Cloud + LOG.debug("Recieved deletions, not removing client(s) from cloud", dhcpAttributes); + } + } + + protected ClientSession updateClientSession(int customerId, long equipmentId, long locationId, + Map dhcpLeasedIps, MacAddress clientMacAddress) { + ClientSession session = clientServiceInterface.getSessionOrNull(customerId, equipmentId, clientMacAddress); + + //         "hwaddr": -- + //         "inet_addr": -- + //         "hostname": -- + //         "fingerprint": -- + //         "vendor_class": -- + //         "lease_time": -- + //         "subnet_mask": -- + //         "gateway": -- + //         "dhcp_server": -- + //         "primary_dns": -- + //         "secondary_dns": -- + //         "db_status": + //         "device_name": + //         "device_type": + //         "manuf_id": + + if (session == null) { + session = new ClientSession(); + } + session.setCustomerId(customerId); + session.setEquipmentId(equipmentId); + session.setLocationId(locationId); + session.setMacAddress(clientMacAddress); + session.setDetails(new ClientSessionDetails()); + + ClientSessionDetails clientSessionDetails = new ClientSessionDetails(); + + if (dhcpLeasedIps.containsKey("fingerprint")) { + + clientSessionDetails.setApFingerprint(dhcpLeasedIps.get("fingerprint")); + } + + if (dhcpLeasedIps.containsKey("inet_addr")) { + + try { + clientSessionDetails.setIpAddress(InetAddress.getByName(dhcpLeasedIps.get("inet_addr"))); + } catch (UnknownHostException e) { + LOG.error("Invalid Client IP", e); + } + + } + + if (dhcpLeasedIps.containsKey("hostname")) { + + clientSessionDetails.setHostname(dhcpLeasedIps.get("hostname")); + + } + + ClientDhcpDetails clientDhcpDetails = new ClientDhcpDetails(clientSessionDetails.getSessionId()); + + if (dhcpLeasedIps.containsKey("dhcp_server")) { + try { + clientDhcpDetails.setDhcpServerIp(InetAddress.getByName(dhcpLeasedIps.get("dhcp_server"))); + } catch (UnknownHostException e) { + LOG.error("Invalid DhcpServer", e); + } + } + + if (dhcpLeasedIps.containsKey("lease_time")) { + Integer leaseTime = Integer.valueOf(dhcpLeasedIps.get("lease_time")); + clientDhcpDetails.setLeaseTimeInSeconds(leaseTime); + } + + if (dhcpLeasedIps.containsKey("gateway")) { + try { + clientDhcpDetails.setGatewayIp(InetAddress.getByName(dhcpLeasedIps.get("gateway"))); + } catch (UnknownHostException e) { + LOG.error("Invalid Gateway IP", e); + + try { + clientDhcpDetails.setGatewayIp(InetAddress.getByAddress(dhcpLeasedIps.get("gateway").getBytes())); + } catch (UnknownHostException e1) { + // TODO Auto-generated catch block + LOG.error("Invalid Gateway Address", e); + } + + } + } + + if (dhcpLeasedIps.containsKey("subnet_mask")) { + try { + clientDhcpDetails.setSubnetMask(InetAddress.getByName(dhcpLeasedIps.get("subnet_mask"))); + } catch (UnknownHostException e) { + LOG.error("Invalid Subnet Mask", e); + try { + clientDhcpDetails + .setGatewayIp(InetAddress.getByAddress(dhcpLeasedIps.get("subnet_mask").getBytes())); + } catch (UnknownHostException e1) { + // TODO Auto-generated catch block + LOG.error("Invalid Subnet Mask Address", e); + } + } + } + + if (dhcpLeasedIps.containsKey("primary_dns")) { + try { + clientDhcpDetails.setPrimaryDns(InetAddress.getByName(dhcpLeasedIps.get("primary_dns"))); + } catch (UnknownHostException e) { + LOG.error("Invalid Primary DNS", e); + try { + clientDhcpDetails + .setGatewayIp(InetAddress.getByAddress(dhcpLeasedIps.get("primary_dns").getBytes())); + } catch (UnknownHostException e1) { + // TODO Auto-generated catch block + LOG.error("Invalid Primary DNS Address", e); + } + + } + } + + if (dhcpLeasedIps.containsKey("secondary_dns")) { + try { + clientDhcpDetails.setSecondaryDns(InetAddress.getByName(dhcpLeasedIps.get("secondary_dns"))); + } catch (UnknownHostException e) { + LOG.error("Invalid Secondary DNS", e); + try { + clientDhcpDetails + .setGatewayIp(InetAddress.getByAddress(dhcpLeasedIps.get("secondary_dns").getBytes())); + } catch (UnknownHostException e1) { + // TODO Auto-generated catch block + LOG.error("Invalid Seconary DNS Address", e); + } + } + } + + if (dhcpLeasedIps.containsKey("device_name")) { + clientSessionDetails.setClassificationName(dhcpLeasedIps.get("device_name")); + } + + clientSessionDetails.setDhcpDetails(clientDhcpDetails); + + session.getDetails().mergeSession(clientSessionDetails); + + return session; + } + + @Override + public void commandStateDbTableUpdate(List> commandStateAttributes, String apId, + RowUpdateOperation rowUpdateOperation) { + LOG.info("Received Command_State row(s) {} rowUpdateOperation {} for ap {}", commandStateAttributes, + rowUpdateOperation, apId); + + // TODO: will handle changes from Command_State table + } } diff --git a/opensync-ext-interface/src/main/java/com/telecominfraproject/wlan/opensync/external/integration/models/OpensyncAPInetState.java b/opensync-ext-interface/src/main/java/com/telecominfraproject/wlan/opensync/external/integration/models/OpensyncAPInetState.java index 2779d2e..6be5b8a 100644 --- a/opensync-ext-interface/src/main/java/com/telecominfraproject/wlan/opensync/external/integration/models/OpensyncAPInetState.java +++ b/opensync-ext-interface/src/main/java/com/telecominfraproject/wlan/opensync/external/integration/models/OpensyncAPInetState.java @@ -6,13 +6,12 @@ import java.util.Map; import com.telecominfraproject.wlan.core.model.json.BaseJsonModel; import com.vmware.ovsdb.protocol.operation.notation.Uuid; -public class OpensyncAPInetState extends BaseJsonModel { - +public class OpensyncAPInetState extends BaseJsonModel { private static final long serialVersionUID = 1707053648715030173L; - + public String ifName; - public String dhcpd; + public Map dhcpd; public String unpnpMode; public String ifType; public String softwdsMacAddr; @@ -37,175 +36,423 @@ public class OpensyncAPInetState extends BaseJsonModel { public String inetConfig; public Uuid _uuid; public Uuid version; + public String greLocalInetAddr; + public String greRemoteMacAddr; - - - public OpensyncAPInetState() { - super(); - dns = new HashMap<>(); - dhcpc = new HashMap<>(); - } - public String getIfName() { + super(); + dns = new HashMap<>(); + dhcpc = new HashMap<>(); + } + + public String getIfName() { return ifName; } + public void setIfName(String ifName) { this.ifName = ifName; } - public String getDhcpd() { + + public Map getDhcpd() { return dhcpd; } - public void setDhcpd(String dhcpd) { + + public void setDhcpd(Map dhcpd) { this.dhcpd = dhcpd; } + public String getUnpnpMode() { return unpnpMode; } + public void setUnpnpMode(String unpnpMode) { this.unpnpMode = unpnpMode; } + public String getIfType() { return ifType; } + public void setIfType(String ifType) { this.ifType = ifType; } + public String getSoftwdsMacAddr() { return softwdsMacAddr; } + public void setSoftwdsMacAddr(String softwdsMacAddr) { this.softwdsMacAddr = softwdsMacAddr; } + public boolean isEnabled() { return enabled; } + public void setEnabled(boolean enabled) { this.enabled = enabled; } + public boolean isSofwdsWrap() { return sofwdsWrap; } + public void setSofwdsWrap(boolean sofwdsWrap) { this.sofwdsWrap = sofwdsWrap; } + public int getVlanId() { return vlanId; } + public void setVlanId(int vlanId) { this.vlanId = vlanId; } + public String getNetmask() { return netmask; } + public void setNetmask(String netmask) { this.netmask = netmask; } + public boolean isNat() { return nat; } + public void setNat(boolean nat) { this.nat = nat; } + public String getGreRemoteInetAddr() { return greRemoteInetAddr; } + public void setGreRemoteInetAddr(String greRemoteInetAddr) { this.greRemoteInetAddr = greRemoteInetAddr; } + public String getIfUuid() { return ifUuid; } + public void setIfUuid(String ifUuid) { this.ifUuid = ifUuid; } + public String getInetAddr() { return inetAddr; } + public void setInetAddr(String inetAddr) { this.inetAddr = inetAddr; } + public String getHwAddr() { return hwAddr; } + public void setHwAddr(String hwAddr) { this.hwAddr = hwAddr; } + public int getMtw() { return mtw; } + public void setMtw(int mtw) { this.mtw = mtw; } + public boolean isNetwork() { return network; } + public void setNetwork(boolean network) { this.network = network; } + public Map getDns() { return dns; } + public void setDns(Map dns) { this.dns = dns; } + public String getParentIfName() { return parentIfName; } + public void setParentIfName(String parentIfName) { this.parentIfName = parentIfName; } + public String getGreIfName() { return greIfName; } + public void setGreIfName(String greIfName) { this.greIfName = greIfName; } + public String getBroadcast() { return broadcast; } + public void setBroadcast(String broadcast) { this.broadcast = broadcast; } + public Map getDhcpc() { return dhcpc; } + public void setDhcpc(Map dhcpc) { this.dhcpc = dhcpc; } + public String getGateway() { return gateway; } + public void setGateway(String gateway) { this.gateway = gateway; } + public String getIpAssignScheme() { return ipAssignScheme; } + public void setIpAssignScheme(String ipAssignScheme) { this.ipAssignScheme = ipAssignScheme; } + public String getInetConfig() { return inetConfig; } + public void setInetConfig(String inetConfig) { this.inetConfig = inetConfig; } + public static long getSerialversionuid() { return serialVersionUID; } + public Uuid get_uuid() { return _uuid; } + public void set_uuid(Uuid _uuid) { this._uuid = _uuid; } + public Uuid getVersion() { return version; } + public void setVersion(Uuid version) { this.version = version; } - - + + public void setGreLocalInetAddr(String greLocalInetAddr) { + this.greLocalInetAddr = greLocalInetAddr; + + } + + public String getGreLocalInetAddr() { + return greLocalInetAddr; + } + + public void setGreRemoteMacAddr(String greRemoteMacAddr) { + this.greRemoteMacAddr = greRemoteMacAddr; + } + + public String getGreRemoteMacAddr(){ + return this.greRemoteMacAddr; + } + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((_uuid == null) ? 0 : _uuid.hashCode()); + result = prime * result + ((broadcast == null) ? 0 : broadcast.hashCode()); + result = prime * result + ((dhcpc == null) ? 0 : dhcpc.hashCode()); + result = prime * result + ((dhcpd == null) ? 0 : dhcpd.hashCode()); + result = prime * result + ((dns == null) ? 0 : dns.hashCode()); + result = prime * result + (enabled ? 1231 : 1237); + result = prime * result + ((gateway == null) ? 0 : gateway.hashCode()); + result = prime * result + ((greIfName == null) ? 0 : greIfName.hashCode()); + result = prime * result + ((greLocalInetAddr == null) ? 0 : greLocalInetAddr.hashCode()); + result = prime * result + ((greRemoteInetAddr == null) ? 0 : greRemoteInetAddr.hashCode()); + result = prime * result + ((hwAddr == null) ? 0 : hwAddr.hashCode()); + result = prime * result + ((ifName == null) ? 0 : ifName.hashCode()); + result = prime * result + ((ifType == null) ? 0 : ifType.hashCode()); + result = prime * result + ((ifUuid == null) ? 0 : ifUuid.hashCode()); + result = prime * result + ((inetAddr == null) ? 0 : inetAddr.hashCode()); + result = prime * result + ((inetConfig == null) ? 0 : inetConfig.hashCode()); + result = prime * result + ((ipAssignScheme == null) ? 0 : ipAssignScheme.hashCode()); + result = prime * result + mtw; + result = prime * result + (nat ? 1231 : 1237); + result = prime * result + ((netmask == null) ? 0 : netmask.hashCode()); + result = prime * result + (network ? 1231 : 1237); + result = prime * result + ((parentIfName == null) ? 0 : parentIfName.hashCode()); + result = prime * result + ((greRemoteMacAddr == null) ? 0 : greRemoteMacAddr.hashCode()); + result = prime * result + ((softwdsMacAddr == null) ? 0 : softwdsMacAddr.hashCode()); + result = prime * result + (sofwdsWrap ? 1231 : 1237); + result = prime * result + ((unpnpMode == null) ? 0 : unpnpMode.hashCode()); + result = prime * result + ((version == null) ? 0 : version.hashCode()); + result = prime * result + vlanId; + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + OpensyncAPInetState other = (OpensyncAPInetState) obj; + if (_uuid == null) { + if (other._uuid != null) + return false; + } else if (!_uuid.equals(other._uuid)) + return false; + if (broadcast == null) { + if (other.broadcast != null) + return false; + } else if (!broadcast.equals(other.broadcast)) + return false; + if (dhcpc == null) { + if (other.dhcpc != null) + return false; + } else if (!dhcpc.equals(other.dhcpc)) + return false; + if (dhcpd == null) { + if (other.dhcpd != null) + return false; + } else if (!dhcpd.equals(other.dhcpd)) + return false; + if (dns == null) { + if (other.dns != null) + return false; + } else if (!dns.equals(other.dns)) + return false; + if (enabled != other.enabled) + return false; + if (gateway == null) { + if (other.gateway != null) + return false; + } else if (!gateway.equals(other.gateway)) + return false; + if (greIfName == null) { + if (other.greIfName != null) + return false; + } else if (!greIfName.equals(other.greIfName)) + return false; + if (greLocalInetAddr == null) { + if (other.greLocalInetAddr != null) + return false; + } else if (!greLocalInetAddr.equals(other.greLocalInetAddr)) + return false; + if (greRemoteInetAddr == null) { + if (other.greRemoteInetAddr != null) + return false; + } else if (!greRemoteInetAddr.equals(other.greRemoteInetAddr)) + return false; + if (hwAddr == null) { + if (other.hwAddr != null) + return false; + } else if (!hwAddr.equals(other.hwAddr)) + return false; + if (ifName == null) { + if (other.ifName != null) + return false; + } else if (!ifName.equals(other.ifName)) + return false; + if (ifType == null) { + if (other.ifType != null) + return false; + } else if (!ifType.equals(other.ifType)) + return false; + if (ifUuid == null) { + if (other.ifUuid != null) + return false; + } else if (!ifUuid.equals(other.ifUuid)) + return false; + if (inetAddr == null) { + if (other.inetAddr != null) + return false; + } else if (!inetAddr.equals(other.inetAddr)) + return false; + if (inetConfig == null) { + if (other.inetConfig != null) + return false; + } else if (!inetConfig.equals(other.inetConfig)) + return false; + if (ipAssignScheme == null) { + if (other.ipAssignScheme != null) + return false; + } else if (!ipAssignScheme.equals(other.ipAssignScheme)) + return false; + if (mtw != other.mtw) + return false; + if (nat != other.nat) + return false; + if (netmask == null) { + if (other.netmask != null) + return false; + } else if (!netmask.equals(other.netmask)) + return false; + if (network != other.network) + return false; + if (parentIfName == null) { + if (other.parentIfName != null) + return false; + } else if (!parentIfName.equals(other.parentIfName)) + return false; + if (greRemoteMacAddr == null) { + if (other.greRemoteMacAddr != null) + return false; + } else if (!greRemoteMacAddr.equals(other.greRemoteMacAddr)) + return false; + if (softwdsMacAddr == null) { + if (other.softwdsMacAddr != null) + return false; + } else if (!softwdsMacAddr.equals(other.softwdsMacAddr)) + return false; + if (sofwdsWrap != other.sofwdsWrap) + return false; + if (unpnpMode == null) { + if (other.unpnpMode != null) + return false; + } else if (!unpnpMode.equals(other.unpnpMode)) + return false; + if (version == null) { + if (other.version != null) + return false; + } else if (!version.equals(other.version)) + return false; + if (vlanId != other.vlanId) + return false; + return true; + } + + @Override + public String toString() { + return "OpensyncAPInetState [ifName=" + ifName + ", dhcpd=" + dhcpd + ", unpnpMode=" + unpnpMode + ", ifType=" + + ifType + ", softwdsMacAddr=" + softwdsMacAddr + ", enabled=" + enabled + ", sofwdsWrap=" + sofwdsWrap + + ", vlanId=" + vlanId + ", netmask=" + netmask + ", nat=" + nat + ", greRemoteInetAddr=" + + greRemoteInetAddr + ", ifUuid=" + ifUuid + ", inetAddr=" + inetAddr + ", hwAddr=" + hwAddr + ", mtw=" + + mtw + ", network=" + network + ", dns=" + dns + ", parentIfName=" + parentIfName + ", greIfName=" + + greIfName + ", broadcast=" + broadcast + ", dhcpc=" + dhcpc + ", gateway=" + gateway + + ", ipAssignScheme=" + ipAssignScheme + ", inetConfig=" + inetConfig + ", _uuid=" + _uuid + + ", version=" + version + ", greLocalInetAddr=" + greLocalInetAddr + ", greRemoteMacAddr=" + + greRemoteMacAddr + "]"; + } } diff --git a/opensync-gateway/src/main/java/com/telecominfraproject/wlan/opensync/ovsdb/TipWlanOvsdbClient.java b/opensync-gateway/src/main/java/com/telecominfraproject/wlan/opensync/ovsdb/TipWlanOvsdbClient.java index 489a049..9e3053e 100644 --- a/opensync-gateway/src/main/java/com/telecominfraproject/wlan/opensync/ovsdb/TipWlanOvsdbClient.java +++ b/opensync-gateway/src/main/java/com/telecominfraproject/wlan/opensync/ovsdb/TipWlanOvsdbClient.java @@ -196,11 +196,11 @@ public class TipWlanOvsdbClient implements OvsdbClientInterface { OpensyncAPConfig opensyncAPConfig = extIntegrationInterface.getApConfig(apId); - try { - ovsdbDao.provisionBridgePortInterface(ovsdbClient); - } catch (Exception e) { - LOG.warn("Could not provision Bridge->Port->Interface mapping.", e); - } +// try { +// ovsdbDao.provisionBridgePortInterface(ovsdbClient); +// } catch (Exception e) { +// LOG.warn("Could not provision Bridge->Port->Interface mapping.", e); +// } ovsdbDao.removeAllStatsConfigs(ovsdbClient); // always ovsdbDao.removeAllSsids(ovsdbClient); // always ovsdbDao.removeWifiRrm(ovsdbClient); @@ -360,7 +360,7 @@ public class TipWlanOvsdbClient implements OvsdbClientInterface { CompletableFuture awCf = ovsdbClient.monitor(OvsdbDao.ovsdbName, OvsdbDao.dhcpLeasedIpDbTable + "_" + key, - new MonitorRequests(ImmutableMap.of(OvsdbDao.dhcpLeasedIpDbTable, new MonitorRequest())), + new MonitorRequests(ImmutableMap.of(OvsdbDao.dhcpLeasedIpDbTable, new MonitorRequest(new MonitorSelect(true, true, true, true)))), new MonitorCallback() { @Override @@ -581,7 +581,7 @@ public class TipWlanOvsdbClient implements OvsdbClientInterface { CompletableFuture isCf = ovsdbClient .monitor(OvsdbDao.ovsdbName, OvsdbDao.wifiInetStateDbTable + "_" + key, new MonitorRequests(ImmutableMap.of(OvsdbDao.wifiInetStateDbTable, - new MonitorRequest(new MonitorSelect(false, true, true, true)))), + new MonitorRequest(new MonitorSelect(true, true, true, true)))), new MonitorCallback() { @Override @@ -729,14 +729,10 @@ public class TipWlanOvsdbClient implements OvsdbClientInterface { @Override public String processFirmwareFlash(String apId, String firmwareVersion, String username) { OvsdbSession session = ovsdbSessionMapInterface.getSession(apId); - OvsdbClient ovsdbClient = session.getOvsdbClient(); try { ovsdbDao.configureFirmwareFlash(session.getOvsdbClient(), apId, firmwareVersion, username); } catch (Exception e) { - LOG.error("Failed to flash firmware for " + apId + " " + e.getLocalizedMessage()); - monitorOvsdbStateTables(ovsdbClient, apId); // turn back on so we - // can go forward and - // recover + LOG.error("Failed to flash firmware for " + apId + " " + e.getLocalizedMessage()); return "Failed to flash firmware for " + apId + " " + e.getLocalizedMessage(); } diff --git a/opensync-gateway/src/main/java/com/telecominfraproject/wlan/opensync/ovsdb/dao/OvsdbDao.java b/opensync-gateway/src/main/java/com/telecominfraproject/wlan/opensync/ovsdb/dao/OvsdbDao.java index dd00d4b..0039198 100644 --- a/opensync-gateway/src/main/java/com/telecominfraproject/wlan/opensync/ovsdb/dao/OvsdbDao.java +++ b/opensync-gateway/src/main/java/com/telecominfraproject/wlan/opensync/ovsdb/dao/OvsdbDao.java @@ -1,5 +1,8 @@ package com.telecominfraproject.wlan.opensync.ovsdb.dao; +import java.net.Inet4Address; +import java.net.InetAddress; +import java.net.UnknownHostException; import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; @@ -1836,26 +1839,13 @@ public class OvsdbDao { List operations = new ArrayList<>(); - operations.add(new Delete(wifiVifConfigDbTable)); - - CompletableFuture fResult = ovsdbClient.transact(ovsdbName, operations); - OperationResult[] result = fResult.get(ovsdbTimeoutSec, TimeUnit.SECONDS); - - if (LOG.isDebugEnabled()) { - LOG.debug("Removed all existing SSIDs from {}:", wifiVifConfigDbTable); - - for (OperationResult res : result) { - LOG.debug("Op Result {}", res); - } - } - operations = new ArrayList<>(); List conditions = new ArrayList<>(); conditions.add(new Condition("if_type", Function.EQUALS, new Atom<>("vif"))); operations.add(new Delete(wifiInetConfigDbTable, conditions)); - fResult = ovsdbClient.transact(ovsdbName, operations); - result = fResult.get(ovsdbTimeoutSec, TimeUnit.SECONDS); + CompletableFuture fResult = ovsdbClient.transact(ovsdbName, operations); + OperationResult[] result = fResult.get(ovsdbTimeoutSec, TimeUnit.SECONDS); if (LOG.isDebugEnabled()) { LOG.debug("Removed all existing vif interfaces configs from {}:", wifiInetConfigDbTable); @@ -1865,9 +1855,23 @@ public class OvsdbDao { } } + operations = new ArrayList<>(); + operations.add(new Delete(wifiVifConfigDbTable)); + + fResult = ovsdbClient.transact(ovsdbName, operations); + result = fResult.get(ovsdbTimeoutSec, TimeUnit.SECONDS); + + if (LOG.isDebugEnabled()) { + LOG.debug("Removed all existing SSIDs from {}:", wifiVifConfigDbTable); + + for (OperationResult res : result) { + LOG.debug("Op Result {}", res); + } + } + operations = new ArrayList<>(); conditions = new ArrayList<>(); - conditions.add(new Condition("if_type", Function.EQUALS, new Atom<>("vlan"))); + conditions.add(new Condition("vlan_id", Function.GREATER_THAN, new Atom<>(1))); operations.add(new Delete(wifiInetConfigDbTable, conditions)); fResult = ovsdbClient.transact(ovsdbName, operations); @@ -2223,6 +2227,8 @@ public class OvsdbDao { OvsdbClient ovsdbClient) { List ret = new ArrayList<>(); + LOG.info("OvsdbDao::getOpensyncApInetStateForRowUpdate {} for apId {}", rowUpdate, apId); + try { Row row = rowUpdate.getNew(); @@ -2249,6 +2255,44 @@ public class OvsdbDao { && map.get("if_type").getClass().equals(com.vmware.ovsdb.protocol.operation.notation.Atom.class)) { tableState.setIfType(row.getStringColumn("if_type")); } + + if (map.containsKey("dhcpc")) { + tableState.setDhcpc(row.getMapColumn("dhcpc")); + } + if (map.containsKey("dhcpd")) { + tableState.setDhcpd(row.getMapColumn("dhcpd")); + } + if (map.containsKey("dns")) { + tableState.setDns(row.getMapColumn("dns")); + } + if (map.get("inet_addr") != null && map.get("inet_addr").getClass() + .equals(com.vmware.ovsdb.protocol.operation.notation.Atom.class)) { + tableState.setInetAddr(row.getStringColumn("inet_addr")); + } + if (map.containsKey("netmask")) { + tableState.setNetmask(getSingleValueFromSet(row, "netmask")); + } + if (map.get("vlan_id") != null + && map.get("vlan_id").getClass().equals(com.vmware.ovsdb.protocol.operation.notation.Atom.class)) { + tableState.setVlanId(row.getIntegerColumn("vlan_id").intValue()); + } + if (map.get("gre_ifname") != null && map.get("gre_ifname").getClass() + .equals(com.vmware.ovsdb.protocol.operation.notation.Atom.class)) { + tableState.setGreIfName(row.getStringColumn("gre_ifname")); + } + if (map.get("gre_remote_inet_addr") != null && map.get("gre_remote_inet_addr").getClass() + .equals(com.vmware.ovsdb.protocol.operation.notation.Atom.class)) { + tableState.setGreRemoteInetAddr(row.getStringColumn("gre_remote_inet_addr")); + } + if (map.get("gre_local_inet_addr") != null && map.get("gre_local_inet_addr").getClass() + .equals(com.vmware.ovsdb.protocol.operation.notation.Atom.class)) { + tableState.setGreLocalInetAddr(row.getStringColumn("gre_local_inet_addr")); + } + if (map.get("gre_remote_mac_addr") != null && map.get("gre_remote_mac_addr").getClass() + .equals(com.vmware.ovsdb.protocol.operation.notation.Atom.class)) { + tableState.setGreRemoteMacAddr(row.getStringColumn("gre_remote_mac_addr")); + } + if ((map.get("ip_assign_scheme") != null) && map.get("ip_assign_scheme").getClass() .equals(com.vmware.ovsdb.protocol.operation.notation.Atom.class)) { tableState.setIpAssignScheme(row.getStringColumn("ip_assign_scheme")); @@ -2561,14 +2605,15 @@ public class OvsdbDao { } } - private void configureSingleSsid(OvsdbClient ovsdbClient, String ifName, String ssid, boolean ssidBroadcast, - Map security, String radioFreqBand, int vlanId, boolean rrmEnabled, boolean enable80211r, - int mobilityDomain, boolean enable80211v, boolean enable80211k, String minHwMode, boolean enabled, - int keyRefresh, boolean uapsdEnabled, boolean apBridge, NetworkForwardMode networkForwardMode, - String gateway, String inet, Map dns, String ipAssignScheme, List macBlockList, - boolean rateLimitEnable, int ssidDlLimit, int ssidUlLimit, int clientDlLimit, int clientUlLimit, - int rtsCtsThreshold, int fragThresholdBytes, int dtimPeriod, Map captiveMap, - List walledGardenAllowlist, Map> bonjourServiceMap) { + private void configureSingleSsid(OvsdbClient ovsdbClient, String vifInterfaceName, String ssid, + boolean ssidBroadcast, Map security, String radioFreqBand, int vlanId, boolean rrmEnabled, + boolean enable80211r, int mobilityDomain, boolean enable80211v, boolean enable80211k, String minHwMode, + boolean enabled, int keyRefresh, boolean uapsdEnabled, boolean apBridge, + NetworkForwardMode networkForwardMode, String gateway, String inet, Map dns, + String ipAssignScheme, List macBlockList, boolean rateLimitEnable, int ssidDlLimit, + int ssidUlLimit, int clientDlLimit, int clientUlLimit, int rtsCtsThreshold, int fragThresholdBytes, + int dtimPeriod, Map captiveMap, List walledGardenAllowlist, + Map> bonjourServiceMap) { List operations = new ArrayList<>(); Map updateColumns = new HashMap<>(); @@ -2576,9 +2621,9 @@ public class OvsdbDao { try { // If we are doing a NAT SSID, no bridge, else yes - String bridge = defaultWanInterfaceName; + String bridgeInterfaceName = defaultWanInterfaceName; if (networkForwardMode == NetworkForwardMode.NAT) { - bridge = defaultLanInterfaceName; + bridgeInterfaceName = defaultLanInterfaceName; } if (vlanId > 1) { @@ -2586,26 +2631,20 @@ public class OvsdbDao { // question Map wifiInetConfigInfoMap = getProvisionedWifiInetConfigs(ovsdbClient); - String vlanIfName = bridge + "_" + vlanId; + String vlanIfName = bridgeInterfaceName + "_" + vlanId; if (!wifiInetConfigInfoMap.containsKey(vlanIfName)) { // we need to make a VLAN, before we do anything else - createInetConfigForVlan(ovsdbClient, bridge, (networkForwardMode == NetworkForwardMode.NAT), - vlanIfName, vlanId, gateway, inet, ipAssignScheme, dns, false); + createInetConfigForVlan(ovsdbClient, bridgeInterfaceName, vlanIfName, vlanId, false); } else { - createInetConfigForVlan(ovsdbClient, bridge, (networkForwardMode == NetworkForwardMode.NAT), - vlanIfName, vlanId, gateway, inet, ipAssignScheme, dns, true); + createInetConfigForVlan(ovsdbClient, bridgeInterfaceName, vlanIfName, vlanId, true); } - bridge = vlanIfName; - updateColumns.put("vlan_id", new Atom<>(vlanId)); - updateColumns.put("mode", new Atom<>("ap")); - } else { - updateColumns.put("mode", new Atom<>("ap")); - updateColumns.put("vlan_id", new com.vmware.ovsdb.protocol.operation.notation.Set()); } + updateColumns.put("mode", new Atom<>("ap")); + // TODO: remove when captive portal support available in AP load DatabaseSchema dbSchema = ovsdbClient.getSchema(ovsdbName).join(); TableSchema tableSchema = dbSchema.getTables().get(wifiVifConfigDbTable); @@ -2632,7 +2671,7 @@ public class OvsdbDao { LOG.debug("SSID {} Bonjour Services per vlan {}", ssid, bonjourServiceMap); } - updateColumns.put("bridge", new Atom<>(bridge)); + updateColumns.put("bridge", new Atom<>(bridgeInterfaceName)); if (enable80211v) { updateColumns.put("btm", new Atom<>(1)); @@ -2647,7 +2686,7 @@ public class OvsdbDao { updateColumns.put("ft_psk", new Atom<>(0)); updateColumns.put("ft_mobility_domain", new com.vmware.ovsdb.protocol.operation.notation.Set()); } - updateColumns.put("if_name", new Atom<>(ifName)); + updateColumns.put("if_name", new Atom<>(vifInterfaceName)); updateColumns.put("rrm", new Atom<>(rrmEnabled ? 1 : 0)); updateColumns.put("ssid", new Atom<>(ssid)); updateColumns.put("ssid_broadcast", new Atom<>(ssidBroadcast ? "enabled" : "disabled")); @@ -2687,14 +2726,13 @@ public class OvsdbDao { updateColumns.put("custom_options", customMap); updateBlockList(updateColumns, macBlockList); - Row row = new Row(updateColumns); operations.add(new Insert(wifiVifConfigDbTable, row)); CompletableFuture fResult = ovsdbClient.transact(ovsdbName, operations); OperationResult[] result = fResult.get(ovsdbTimeoutSec, TimeUnit.SECONDS); - LOG.debug("Provisioned SSID {} on {}", ssid, ifName); + LOG.debug("Provisioned SSID {} on {}", ssid, vifInterfaceName); Uuid vifConfigUuid = null; for (OperationResult res : result) { @@ -2713,19 +2751,14 @@ public class OvsdbDao { updateVifConfigsSetForRadio(ovsdbClient, ssid, radioFreqBand, operations, updateColumns, vifConfigUuid); Map inetConfigs = getProvisionedWifiInetConfigs(ovsdbClient); - boolean isNAT = inetConfigs.get(bridge).nat; - ipAssignScheme = inetConfigs.get(bridge).ipAssignScheme; - if (inetConfigs.containsKey(ifName)) { - updateWifiInetConfig(ovsdbClient, vlanId, ifName, enabled, isNAT, "vif", bridge, gateway, inet, dns, - ipAssignScheme, vifConfigUuid); + if (inetConfigs.containsKey(vifInterfaceName)) { + configureInetInterface(ovsdbClient, vifInterfaceName, enabled, "vif", true); } else { - LOG.debug("No corresponding WifiInetConfig for this Interface"); - insertWifiInetConfigForVif(ovsdbClient, vlanId, ifName, enabled, isNAT, "vif", bridge, gateway, inet, - dns, ipAssignScheme, vifConfigUuid); + configureInetInterface(ovsdbClient, vifInterfaceName, enabled, "vif", false); } - LOG.info("Provisioned SSID {} on interface {} / {}", ssid, ifName, radioFreqBand); + LOG.info("Provisioned SSID {} on interface {} / {}", ssid, vifInterfaceName, radioFreqBand); } catch (OvsdbClientException | TimeoutException | ExecutionException | InterruptedException e) { LOG.error("Error in configureSingleSsid", e); @@ -2937,25 +2970,26 @@ public class OvsdbDao { boolean ssidBroadcast = ssidConfig.getBroadcastSsid() == StateSetting.enabled; - String ipAssignScheme = null; + String ipAssignScheme = apElementConfig.getGettingIP().toString(); // the following 5 attributes only applicable to static config, // else they are // ignored String gateway = null; String inet = null; Map dns = null; - if (apElementConfig.getStaticIP() != null) { - ipAssignScheme = "static"; - inet = apElementConfig.getStaticIP().getHostAddress(); - gateway = apElementConfig.getStaticIpGw().getHostAddress(); - dns = new HashMap<>(); - dns.put(apElementConfig.getStaticDnsIp1().getHostName(), - apElementConfig.getStaticDnsIp1().getHostAddress()); - dns.put(apElementConfig.getStaticDnsIp2().getHostName(), - apElementConfig.getStaticDnsIp2().getHostAddress()); - } else if (apElementConfig.getGettingIP().equals(GettingIP.dhcp) - || apElementConfig.getGettingDNS().equals(GettingDNS.dhcp)) { - ipAssignScheme = "dhcp"; + if (ipAssignScheme.equals("manual")) { + if (apElementConfig.getStaticIP() != null) { + ipAssignScheme = "static"; + inet = apElementConfig.getStaticIP().getHostAddress(); + gateway = apElementConfig.getStaticIpGw().getHostAddress(); + dns = new HashMap<>(); + dns.put(apElementConfig.getStaticDnsIp1().getHostName(), + apElementConfig.getStaticDnsIp1().getHostAddress()); + dns.put(apElementConfig.getStaticDnsIp2().getHostName(), + apElementConfig.getStaticDnsIp2().getHostAddress()); + } else { + ipAssignScheme = "none"; + } } RadioConfiguration radioConfiguration = apElementConfig.getAdvancedRadioMap().get(radioType); @@ -3113,13 +3147,10 @@ public class OvsdbDao { } - private void createInetConfigForVlan(OvsdbClient ovsdbClient, String parentIfName, boolean isNAT, String vlanIfName, - int vlanId, String gateway, String inet, String ipAssignScheme, Map dns, boolean isUpdate) { + private void createInetConfigForVlan(OvsdbClient ovsdbClient, String parentIfName, String vlanIfName, int vlanId, + boolean isUpdate) { try { - Map wifiInetConfigsMap = getProvisionedWifiInetConfigs(ovsdbClient); - WifiInetConfigInfo parentWifiInetConfig = wifiInetConfigsMap.get(parentIfName); - List operations = new ArrayList<>(); Map tableColumns = new HashMap<>(); @@ -3127,37 +3158,14 @@ public class OvsdbDao { tableColumns.put("vlan_id", new Atom<>(vlanId)); tableColumns.put("if_name", new Atom<>(vlanIfName)); tableColumns.put("parent_ifname", new Atom<>(parentIfName)); - tableColumns.put("NAT", new Atom<>(isNAT)); tableColumns.put("enabled", new Atom<>(true)); tableColumns.put("network", new Atom<>(true)); - tableColumns.put("mtu", new Atom<>(1500)); - tableColumns.put("dhcp_sniff", new Atom<>(true)); - if (parentWifiInetConfig != null) { - tableColumns.put("ip_assign_scheme", new Atom<>(parentWifiInetConfig.ipAssignScheme)); - if (parentWifiInetConfig.ipAssignScheme.equals("static")) { - tableColumns.put("dns", - com.vmware.ovsdb.protocol.operation.notation.Map.of(parentWifiInetConfig.dns)); - tableColumns.put("dhcpd", - com.vmware.ovsdb.protocol.operation.notation.Map.of(parentWifiInetConfig.dhcpd)); - if (parentWifiInetConfig.gateway != null) { - tableColumns.put("gateway", new Atom<>(parentWifiInetConfig.gateway)); - } - if (parentWifiInetConfig.netmask != null) { - tableColumns.put("netmask", new Atom<>(parentWifiInetConfig.netmask)); - } - if (parentWifiInetConfig.inetAddr != null) { - String[] inetAddrOctets = parentWifiInetConfig.inetAddr.split("\\."); - if (inetAddrOctets.length == 4) { - // change the subnet octet to be the vlan - tableColumns.put("inet_addr", new Atom<>(inetAddrOctets[0] + "." + inetAddrOctets[1] + "." - + vlanId + "." + inetAddrOctets[3])); - } - } - - } + if (parentIfName.equals(defaultLanInterfaceName)) { + tableColumns.put("ip_assign_scheme", new Atom<>("static")); } else { - tableColumns.put("ip_assign_scheme", new Atom<>(ipAssignScheme)); + tableColumns.put("ip_assign_scheme", new Atom<>("dhcp")); } + tableColumns.put("dhcp_sniff", new Atom<>(true)); Row row = new Row(tableColumns); operations.clear(); @@ -3328,114 +3336,41 @@ public class OvsdbDao { return externalFileStoreURL + FILESTORE + "/" + fileInfo.getApExportUrl(); } - private void updateWifiInetConfig(OvsdbClient ovsdbClient, int vlanId, String ifName, boolean enabled, - boolean isNAT, String ifType, String gateway, String inet, String parentIfName, Map dns, - String ipAssignScheme, Uuid vifConfigUuid) { - - List operations = new ArrayList<>(); - Map updateColumns = new HashMap<>(); - List conditions = new ArrayList<>(); - conditions.add(new Condition("if_name", Function.EQUALS, new Atom<>(ifName))); + private void configureInetInterface(OvsdbClient ovsdbClient, String ifName, boolean enabled, String ifType, + boolean isUpdate) { try { -// /usr/plume/tools/ovsh i Wifi_Inet_Config NAT:=false enabled:=true if_name:=home-ap-24 if_type:=vif ip_assign_scheme:=none network:=true - /// usr/plume/tools/ovsh i Wifi_Inet_Config NAT:=false enabled:=true - /// if_name:=home-ap-24 if_type:=vif ip_assign_scheme:=none - /// network:=true - // dhcpd - updateColumns.put("if_name", new Atom<>(ifName)); - updateColumns.put("if_type", new Atom<>(ifType)); - updateColumns.put("if_uuid", new Atom<>(vifConfigUuid.toString())); - updateColumns.put("enabled", new Atom<>(enabled)); - updateColumns.put("NAT", new Atom<>(isNAT)); -// updateColumns.put("parent_ifname", new Atom<>(parentIfName)); - // mtu // specified in interface, should take that value when - // implemented -// updateColumns.put("mtu", new Atom<>(1500)); - updateColumns.put("network", new Atom<>(true)); - - updateColumns.put("ip_assign_scheme", new Atom<>(ipAssignScheme)); - updateColumns.put("dhcp_sniff", new Atom<>(true)); - -// if (ipAssignScheme.equals("static")) { -// updateColumns.put("dns", com.vmware.ovsdb.protocol.operation.notation.Map.of(dns)); -// updateColumns.put("inet_addr", new Atom<>(inet)); -// updateColumns.put("gateway", new Atom<>(gateway)); -// // netmask -// // broadcast -// } - - Row row = new Row(updateColumns); - operations.add(new Update(wifiInetConfigDbTable, conditions, row)); + List operations = new ArrayList<>(); + Map tableColumns = new HashMap<>(); + tableColumns.put("if_type", new Atom<>(ifType)); + tableColumns.put("enabled", new Atom<>(enabled)); + tableColumns.put("network", new Atom<>(true)); + tableColumns.put("if_name", new Atom<>(ifName)); + tableColumns.put("dhcp_sniff", new Atom<>(true)); + tableColumns.put("ip_assign_scheme", new Atom<>("dhcp")); + tableColumns.put("NAT", new Atom<>(false)); + + Row row = new Row(tableColumns); + if (isUpdate) { + List conditions = new ArrayList<>(); + conditions.add(new Condition("if_name", Function.EQUALS, new Atom<>(ifName))); + operations.add(new Update(wifiInetConfigDbTable, conditions, row)); + } else { + operations.add(new Insert(wifiInetConfigDbTable, row)); + } CompletableFuture fResult = ovsdbClient.transact(ovsdbName, operations); OperationResult[] result = fResult.get(ovsdbTimeoutSec, TimeUnit.SECONDS); - LOG.debug("Provisioned WifiInetConfig {}", ifName); + LOG.debug("Updated Inet {}", ifName); for (OperationResult res : result) { LOG.debug("Op Result {}", res); } } catch (OvsdbClientException | TimeoutException | ExecutionException | InterruptedException e) { - LOG.error("Error in configureWifiInet", e); - throw new RuntimeException(e); - } - - } - - private void insertWifiInetConfigForVif(OvsdbClient ovsdbClient, int vlanId, String ifName, boolean enabled, - boolean isNAT, String ifType, String gateway, String inet, String parentIfName, Map dns, - String ipAssignScheme, Uuid vifConfigUuid) { - - List operations = new ArrayList<>(); - Map insertColumns = new HashMap<>(); - - try { - /// usr/plume/tools/ovsh i Wifi_Inet_Config NAT:=false enabled:=true - /// if_name:=home-ap-24 if_type:=vif ip_assign_scheme:=none - /// network:=true - // dhcpd - insertColumns.put("if_name", new Atom<>(ifName)); - insertColumns.put("if_type", new Atom<>(ifType)); - insertColumns.put("if_uuid", new Atom<>(vifConfigUuid.toString())); - insertColumns.put("enabled", new Atom<>(enabled)); - insertColumns.put("NAT", new Atom<>(isNAT)); -// insertColumns.put("parent_ifname", new Atom<>(parentIfName)); - - // mtu // specified in interface, should take that value when - // implemented -// insertColumns.put("mtu", new Atom<>(1500)); - insertColumns.put("network", new Atom<>(true)); - insertColumns.put("dhcp_sniff", new Atom<>(true)); - - insertColumns.put("ip_assign_scheme", new Atom<>(ipAssignScheme)); - -// if (ipAssignScheme.equals("static")) { -// -// if (inet != null) { -// insertColumns.put("inet_addr", new Atom<>(inet)); -// } -// insertColumns.put("netmask", new Atom<>("255.255.255.0")); -// // netmask -// // broadcast -// } - - Row row = new Row(insertColumns); - operations.add(new Insert(wifiInetConfigDbTable, row)); - - CompletableFuture fResult = ovsdbClient.transact(ovsdbName, operations); - OperationResult[] result = fResult.get(ovsdbTimeoutSec, TimeUnit.SECONDS); - - LOG.debug("Provisioned WifiInetConfig {}", ifName); - - for (OperationResult res : result) { - LOG.debug("Op Result {}", res); - } - - } catch (OvsdbClientException | TimeoutException | ExecutionException | InterruptedException e) { - LOG.error("Error in configureWifiInet", e); + LOG.error("Error in updateWifiInetConfig", e); throw new RuntimeException(e); } diff --git a/opensync-gateway/src/test/java/com/telecominfraproject/wlan/opensync/ovsdb/dao/OvsdbDaoTest.java b/opensync-gateway/src/test/java/com/telecominfraproject/wlan/opensync/ovsdb/dao/OvsdbDaoTest.java index bc80a99..472dce7 100644 --- a/opensync-gateway/src/test/java/com/telecominfraproject/wlan/opensync/ovsdb/dao/OvsdbDaoTest.java +++ b/opensync-gateway/src/test/java/com/telecominfraproject/wlan/opensync/ovsdb/dao/OvsdbDaoTest.java @@ -3,7 +3,6 @@ package com.telecominfraproject.wlan.opensync.ovsdb.dao; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; -import java.io.File; import java.util.HashMap; import java.util.List; import java.util.UUID; @@ -27,21 +26,11 @@ 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 org.springframework.util.ResourceUtils; -import com.fasterxml.jackson.databind.JsonNode; -import com.github.fge.jackson.JsonLoader; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; import com.telecominfraproject.wlan.opensync.external.integration.models.ConnectNodeInfo; -import com.telecominfraproject.wlan.opensync.external.integration.models.OpensyncAPInetState; -import com.telecominfraproject.wlan.opensync.external.integration.models.OpensyncAPRadioState; -import com.telecominfraproject.wlan.opensync.external.integration.models.OpensyncAPVIFState; import com.vmware.ovsdb.exception.OvsdbClientException; -import com.vmware.ovsdb.jsonrpc.v1.util.JsonUtil; -import com.vmware.ovsdb.protocol.methods.RowUpdate; -import com.vmware.ovsdb.protocol.methods.TableUpdate; -import com.vmware.ovsdb.protocol.methods.TableUpdates; import com.vmware.ovsdb.protocol.operation.notation.Atom; import com.vmware.ovsdb.protocol.operation.notation.Row; import com.vmware.ovsdb.protocol.operation.notation.Uuid; @@ -387,94 +376,6 @@ public class OvsdbDaoTest { } - @Test - public void testOvsdbDaoGetOpensyncAPVIFState() throws Exception { - - String path = "src/test/resources/Wifi_VIF_State-home-ap-24.json"; - - File file = new File(path); - String absolutePath = file.getAbsolutePath(); - File jsonFile = ResourceUtils.getFile(absolutePath); - - JsonNode jn = JsonLoader.fromFile(jsonFile); - Row row = JsonUtil.deserializeNoException(jn.toString(), Row.class); - RowUpdate rowUpdate = new RowUpdate(); - rowUpdate.setNew(row); - - path = "src/test/resources/Wifi_VIF_State-home-ap-l50.json"; - file = new File(path); - absolutePath = file.getAbsolutePath(); - jsonFile = ResourceUtils.getFile(absolutePath); - jn = JsonLoader.fromFile(jsonFile); - Row row1 = JsonUtil.deserializeNoException(jn.toString(), Row.class); - - RowUpdate rowUpdate1 = new RowUpdate(); - rowUpdate1.setNew(row1); - - path = "src/test/resources/Wifi_VIF_State-home-ap-u50.json"; - file = new File(path); - absolutePath = file.getAbsolutePath(); - jsonFile = ResourceUtils.getFile(absolutePath); - jn = JsonLoader.fromFile(jsonFile); - Row row2 = JsonUtil.deserializeNoException(jn.toString(), Row.class); - - RowUpdate rowUpdate2 = new RowUpdate(); - rowUpdate2.setNew(row2); - - List vifStateList = ovsdbDao.getOpensyncApVifStateForRowUpdate(rowUpdate, "SomeAPId", ovsdbClient); - assert (vifStateList.size() == 1); - vifStateList.addAll(ovsdbDao.getOpensyncApVifStateForRowUpdate(rowUpdate1, "SomeAPId", ovsdbClient)); - assert (vifStateList.size() == 2); - vifStateList.addAll(ovsdbDao.getOpensyncApVifStateForRowUpdate(rowUpdate2, "SomeAPId", ovsdbClient)); - assert (vifStateList.size() == 3); - - - } - - @Test - public void testOvsdbDaoGetOpensyncAPRadioState() throws Exception { - - String path = "src/test/resources/Wifi_Radio_State-home-ap-24.json"; - - File file = new File(path); - String absolutePath = file.getAbsolutePath(); - File jsonFile = ResourceUtils.getFile(absolutePath); - - JsonNode jn = JsonLoader.fromFile(jsonFile); - Row row = JsonUtil.deserializeNoException(jn.toString(), Row.class); - RowUpdate rowUpdate = new RowUpdate(); - rowUpdate.setNew(row); - - path = "src/test/resources/Wifi_Radio_State-home-ap-l50.json"; - file = new File(path); - absolutePath = file.getAbsolutePath(); - jsonFile = ResourceUtils.getFile(absolutePath); - jn = JsonLoader.fromFile(jsonFile); - Row row1 = JsonUtil.deserializeNoException(jn.toString(), Row.class); - - RowUpdate rowUpdate1 = new RowUpdate(); - rowUpdate1.setNew(row1); - - path = "src/test/resources/Wifi_Radio_State-home-ap-u50.json"; - file = new File(path); - absolutePath = file.getAbsolutePath(); - jsonFile = ResourceUtils.getFile(absolutePath); - jn = JsonLoader.fromFile(jsonFile); - Row row2 = JsonUtil.deserializeNoException(jn.toString(), Row.class); - - RowUpdate rowUpdate2 = new RowUpdate(); - rowUpdate2.setNew(row2); - - TableUpdate tableUpdate = new TableUpdate(ImmutableMap.of(row.getUuidColumn("_uuid").getUuid(), rowUpdate, - row1.getUuidColumn("_uuid").getUuid(), rowUpdate1, row2.getUuidColumn("_uuid").getUuid(), rowUpdate2)); - TableUpdates tableUpdates = new TableUpdates(ImmutableMap.of(OvsdbDao.wifiRadioStateDbTable, tableUpdate)); - - List radioStateList = ovsdbDao.getOpensyncAPRadioState(tableUpdates, "SomeAPId", - ovsdbClient); - assert (radioStateList.size() == 3); - - } - @Test public void testObsdbDaoEnableNetworkProbe() throws Exception { @@ -521,48 +422,5 @@ public class OvsdbDaoTest { } - @Test - public void testOvsdbDaoGetOpensyncAPInetState() throws Exception { - - String path = "src/test/resources/Wifi_Inet_State-home-ap-24.json"; - - File file = new File(path); - String absolutePath = file.getAbsolutePath(); - File jsonFile = ResourceUtils.getFile(absolutePath); - - JsonNode jn = JsonLoader.fromFile(jsonFile); - Row row = JsonUtil.deserializeNoException(jn.toString(), Row.class); - RowUpdate rowUpdate = new RowUpdate(); - rowUpdate.setNew(row); - - path = "src/test/resources/Wifi_Inet_State-home-ap-l50.json"; - file = new File(path); - absolutePath = file.getAbsolutePath(); - jsonFile = ResourceUtils.getFile(absolutePath); - jn = JsonLoader.fromFile(jsonFile); - Row row1 = JsonUtil.deserializeNoException(jn.toString(), Row.class); - - RowUpdate rowUpdate1 = new RowUpdate(); - rowUpdate1.setNew(row1); - - path = "src/test/resources/Wifi_Inet_State-home-ap-u50.json"; - file = new File(path); - absolutePath = file.getAbsolutePath(); - jsonFile = ResourceUtils.getFile(absolutePath); - jn = JsonLoader.fromFile(jsonFile); - Row row2 = JsonUtil.deserializeNoException(jn.toString(), Row.class); - - RowUpdate rowUpdate2 = new RowUpdate(); - rowUpdate2.setNew(row2); - - List inetStateList = ovsdbDao.getOpensyncApInetStateForRowUpdate(rowUpdate, "SomeAPId", ovsdbClient); - assert (inetStateList.size() == 1); - inetStateList.addAll(ovsdbDao.getOpensyncApInetStateForRowUpdate(rowUpdate1, "SomeAPId", ovsdbClient)); - assert (inetStateList.size() == 2); - inetStateList.addAll(ovsdbDao.getOpensyncApInetStateForRowUpdate(rowUpdate2, "SomeAPId", ovsdbClient)); - assert (inetStateList.size() == 3); - - - } } diff --git a/opensync-gateway/src/test/resources/Wifi_Inet_State-home-ap-24.json b/opensync-gateway/src/test/resources/Wifi_Inet_State-home-ap-24.json deleted file mode 100644 index e5d84a7..0000000 --- a/opensync-gateway/src/test/resources/Wifi_Inet_State-home-ap-24.json +++ /dev/null @@ -1,110 +0,0 @@ -{ - "vif_radio_idx": [ - "set", - [ - ] - ], - "if_name": "home-ap-24", - "state": [ - "set", - [ - ] - ], - "mac": "24:f5:a2:ef:2e:54", - "ssid": "TipWlan-cloud-3-radios", - "uapsd_enable": true, - "ap_bridge": false, - "wps_pbc": [ - "set", - [ - ] - ], - "mac_list": [ - "set", - [ - ] - ], - "associated_clients": [ - "set", - [ - ] - ], - "btm": 1, - "_uuid": [ - "uuid", - "a007d865-fe4b-4265-a9a1-69d4b309e939" - ], - "ssid_broadcast": "enabled", - "wps": [ - "set", - [ - ] - ], - "mcast2ucast": [ - "set", - [ - ] - ], - "mode": "ap", - "mac_list_type": "none", - "wps_pbc_key_id": "", - "ft_psk": 0, - "channel": [ - "set", - [ - ] - ], - "parent": [ - "set", - [ - ] - ], - "multi_ap": [ - "set", - [ - ] - ], - "ap_vlan_sta_addr": [ - "set", - [ - ] - ], - "security": [ - "map", - [ - [ - "encryption", - "OPEN" - ] - ] - ], - "wds": [ - "set", - [ - ] - ], - "enabled": true, - "vlan_id": 1, - "min_hw_mode": "11n", - "vif_config": [ - "uuid", - "fc3de7db-ee6c-452c-859c-1be81b0b5b24" - ], - "_version": [ - "uuid", - "a96bff45-29bd-423b-9014-10a418683e5d" - ], - "bridge": "lan", - "group_rekey": 0, - "ft_mobility_domain": [ - "set", - [ - ] - ], - "dynamic_beacon": [ - "set", - [ - ] - ], - "rrm": 1 -} diff --git a/opensync-gateway/src/test/resources/Wifi_Inet_State-home-ap-l50.json b/opensync-gateway/src/test/resources/Wifi_Inet_State-home-ap-l50.json deleted file mode 100644 index 6000fce..0000000 --- a/opensync-gateway/src/test/resources/Wifi_Inet_State-home-ap-l50.json +++ /dev/null @@ -1,109 +0,0 @@ -{ - "vif_radio_idx": [ - "set", - [ - ] - ], - "if_name": "home-ap-l50", - "state": [ - "set", - [ - ] - ], - "mac": "24:f5:a2:ef:2e:55", - "ssid": "TipWlan-cloud-3-radios", - "uapsd_enable": true, - "ap_bridge": false, - "wps_pbc": [ - "set", - [ - ] - ], - "mac_list": [ - "set", - [ - ] - ], - "associated_clients": [ - "uuid", - "073c3961-33fe-4054-abc6-ae2e8b91c914" - ], - "btm": 1, - "_uuid": [ - "uuid", - "7ebfab8d-0962-4af3-a45b-b5a9d68c86c8" - ], - "ssid_broadcast": "enabled", - "wps": [ - "set", - [ - ] - ], - "mcast2ucast": [ - "set", - [ - ] - ], - "mode": "ap", - "mac_list_type": "none", - "wps_pbc_key_id": "", - "ft_psk": 0, - "channel": [ - "set", - [ - ] - ], - "parent": [ - "set", - [ - ] - ], - "multi_ap": [ - "set", - [ - ] - ], - "ap_vlan_sta_addr": [ - "set", - [ - ] - ], - "security": [ - "map", - [ - [ - "encryption", - "OPEN" - ] - ] - ], - "wds": [ - "set", - [ - ] - ], - "enabled": true, - "vlan_id": 1, - "min_hw_mode": "11ac", - "vif_config": [ - "uuid", - "54c01e8b-4d67-456e-ab18-cbc89c784c2a" - ], - "_version": [ - "uuid", - "faec64fb-fbc1-417a-9ff4-f30ff2c5be94" - ], - "bridge": "lan", - "group_rekey": 0, - "ft_mobility_domain": [ - "set", - [ - ] - ], - "dynamic_beacon": [ - "set", - [ - ] - ], - "rrm": 1 -} diff --git a/opensync-gateway/src/test/resources/Wifi_Inet_State-home-ap-u50.json b/opensync-gateway/src/test/resources/Wifi_Inet_State-home-ap-u50.json deleted file mode 100644 index c530284..0000000 --- a/opensync-gateway/src/test/resources/Wifi_Inet_State-home-ap-u50.json +++ /dev/null @@ -1,109 +0,0 @@ -{ - "vif_radio_idx": [ - "set", - [ - ] - ], - "if_name": "home-ap-u50", - "state": [ - "set", - [ - ] - ], - "mac": "26:f5:a2:ef:2e:56", - "ssid": "TipWlan-cloud-3-radios", - "uapsd_enable": true, - "ap_bridge": false, - "wps_pbc": [ - "set", - [ - ] - ], - "mac_list": [ - "set", - [ - ] - ], - "associated_clients": [ - "uuid", - "c9f5a30d-7ccf-406f-a0d8-f108b377584e" - ], - "btm": 1, - "_uuid": [ - "uuid", - "009e6ee9-d687-4201-9c55-f42d26cbd7b5" - ], - "ssid_broadcast": "enabled", - "wps": [ - "set", - [ - ] - ], - "mcast2ucast": [ - "set", - [ - ] - ], - "mode": "ap", - "mac_list_type": "none", - "wps_pbc_key_id": "", - "ft_psk": 0, - "channel": [ - "set", - [ - ] - ], - "parent": [ - "set", - [ - ] - ], - "multi_ap": [ - "set", - [ - ] - ], - "ap_vlan_sta_addr": [ - "set", - [ - ] - ], - "security": [ - "map", - [ - [ - "encryption", - "OPEN" - ] - ] - ], - "wds": [ - "set", - [ - ] - ], - "enabled": true, - "vlan_id": 1, - "min_hw_mode": "11ac", - "vif_config": [ - "uuid", - "4aeefd3b-b86f-45e4-a9a1-c734363be9c8" - ], - "_version": [ - "uuid", - "e70c7842-6257-46d1-94d3-350a55733fc4" - ], - "bridge": "lan", - "group_rekey": 0, - "ft_mobility_domain": [ - "set", - [ - ] - ], - "dynamic_beacon": [ - "set", - [ - ] - ], - "rrm": 1 -} diff --git a/opensync-gateway/src/test/resources/Wifi_Radio_State-home-ap-24.json b/opensync-gateway/src/test/resources/Wifi_Radio_State-home-ap-24.json deleted file mode 100644 index e5d84a7..0000000 --- a/opensync-gateway/src/test/resources/Wifi_Radio_State-home-ap-24.json +++ /dev/null @@ -1,110 +0,0 @@ -{ - "vif_radio_idx": [ - "set", - [ - ] - ], - "if_name": "home-ap-24", - "state": [ - "set", - [ - ] - ], - "mac": "24:f5:a2:ef:2e:54", - "ssid": "TipWlan-cloud-3-radios", - "uapsd_enable": true, - "ap_bridge": false, - "wps_pbc": [ - "set", - [ - ] - ], - "mac_list": [ - "set", - [ - ] - ], - "associated_clients": [ - "set", - [ - ] - ], - "btm": 1, - "_uuid": [ - "uuid", - "a007d865-fe4b-4265-a9a1-69d4b309e939" - ], - "ssid_broadcast": "enabled", - "wps": [ - "set", - [ - ] - ], - "mcast2ucast": [ - "set", - [ - ] - ], - "mode": "ap", - "mac_list_type": "none", - "wps_pbc_key_id": "", - "ft_psk": 0, - "channel": [ - "set", - [ - ] - ], - "parent": [ - "set", - [ - ] - ], - "multi_ap": [ - "set", - [ - ] - ], - "ap_vlan_sta_addr": [ - "set", - [ - ] - ], - "security": [ - "map", - [ - [ - "encryption", - "OPEN" - ] - ] - ], - "wds": [ - "set", - [ - ] - ], - "enabled": true, - "vlan_id": 1, - "min_hw_mode": "11n", - "vif_config": [ - "uuid", - "fc3de7db-ee6c-452c-859c-1be81b0b5b24" - ], - "_version": [ - "uuid", - "a96bff45-29bd-423b-9014-10a418683e5d" - ], - "bridge": "lan", - "group_rekey": 0, - "ft_mobility_domain": [ - "set", - [ - ] - ], - "dynamic_beacon": [ - "set", - [ - ] - ], - "rrm": 1 -} diff --git a/opensync-gateway/src/test/resources/Wifi_Radio_State-home-ap-l50.json b/opensync-gateway/src/test/resources/Wifi_Radio_State-home-ap-l50.json deleted file mode 100644 index 6000fce..0000000 --- a/opensync-gateway/src/test/resources/Wifi_Radio_State-home-ap-l50.json +++ /dev/null @@ -1,109 +0,0 @@ -{ - "vif_radio_idx": [ - "set", - [ - ] - ], - "if_name": "home-ap-l50", - "state": [ - "set", - [ - ] - ], - "mac": "24:f5:a2:ef:2e:55", - "ssid": "TipWlan-cloud-3-radios", - "uapsd_enable": true, - "ap_bridge": false, - "wps_pbc": [ - "set", - [ - ] - ], - "mac_list": [ - "set", - [ - ] - ], - "associated_clients": [ - "uuid", - "073c3961-33fe-4054-abc6-ae2e8b91c914" - ], - "btm": 1, - "_uuid": [ - "uuid", - "7ebfab8d-0962-4af3-a45b-b5a9d68c86c8" - ], - "ssid_broadcast": "enabled", - "wps": [ - "set", - [ - ] - ], - "mcast2ucast": [ - "set", - [ - ] - ], - "mode": "ap", - "mac_list_type": "none", - "wps_pbc_key_id": "", - "ft_psk": 0, - "channel": [ - "set", - [ - ] - ], - "parent": [ - "set", - [ - ] - ], - "multi_ap": [ - "set", - [ - ] - ], - "ap_vlan_sta_addr": [ - "set", - [ - ] - ], - "security": [ - "map", - [ - [ - "encryption", - "OPEN" - ] - ] - ], - "wds": [ - "set", - [ - ] - ], - "enabled": true, - "vlan_id": 1, - "min_hw_mode": "11ac", - "vif_config": [ - "uuid", - "54c01e8b-4d67-456e-ab18-cbc89c784c2a" - ], - "_version": [ - "uuid", - "faec64fb-fbc1-417a-9ff4-f30ff2c5be94" - ], - "bridge": "lan", - "group_rekey": 0, - "ft_mobility_domain": [ - "set", - [ - ] - ], - "dynamic_beacon": [ - "set", - [ - ] - ], - "rrm": 1 -} diff --git a/opensync-gateway/src/test/resources/Wifi_Radio_State-home-ap-u50.json b/opensync-gateway/src/test/resources/Wifi_Radio_State-home-ap-u50.json deleted file mode 100644 index c530284..0000000 --- a/opensync-gateway/src/test/resources/Wifi_Radio_State-home-ap-u50.json +++ /dev/null @@ -1,109 +0,0 @@ -{ - "vif_radio_idx": [ - "set", - [ - ] - ], - "if_name": "home-ap-u50", - "state": [ - "set", - [ - ] - ], - "mac": "26:f5:a2:ef:2e:56", - "ssid": "TipWlan-cloud-3-radios", - "uapsd_enable": true, - "ap_bridge": false, - "wps_pbc": [ - "set", - [ - ] - ], - "mac_list": [ - "set", - [ - ] - ], - "associated_clients": [ - "uuid", - "c9f5a30d-7ccf-406f-a0d8-f108b377584e" - ], - "btm": 1, - "_uuid": [ - "uuid", - "009e6ee9-d687-4201-9c55-f42d26cbd7b5" - ], - "ssid_broadcast": "enabled", - "wps": [ - "set", - [ - ] - ], - "mcast2ucast": [ - "set", - [ - ] - ], - "mode": "ap", - "mac_list_type": "none", - "wps_pbc_key_id": "", - "ft_psk": 0, - "channel": [ - "set", - [ - ] - ], - "parent": [ - "set", - [ - ] - ], - "multi_ap": [ - "set", - [ - ] - ], - "ap_vlan_sta_addr": [ - "set", - [ - ] - ], - "security": [ - "map", - [ - [ - "encryption", - "OPEN" - ] - ] - ], - "wds": [ - "set", - [ - ] - ], - "enabled": true, - "vlan_id": 1, - "min_hw_mode": "11ac", - "vif_config": [ - "uuid", - "4aeefd3b-b86f-45e4-a9a1-c734363be9c8" - ], - "_version": [ - "uuid", - "e70c7842-6257-46d1-94d3-350a55733fc4" - ], - "bridge": "lan", - "group_rekey": 0, - "ft_mobility_domain": [ - "set", - [ - ] - ], - "dynamic_beacon": [ - "set", - [ - ] - ], - "rrm": 1 -} diff --git a/opensync-gateway/src/test/resources/Wifi_VIF_State-home-ap-24.json b/opensync-gateway/src/test/resources/Wifi_VIF_State-home-ap-24.json deleted file mode 100644 index e5d84a7..0000000 --- a/opensync-gateway/src/test/resources/Wifi_VIF_State-home-ap-24.json +++ /dev/null @@ -1,110 +0,0 @@ -{ - "vif_radio_idx": [ - "set", - [ - ] - ], - "if_name": "home-ap-24", - "state": [ - "set", - [ - ] - ], - "mac": "24:f5:a2:ef:2e:54", - "ssid": "TipWlan-cloud-3-radios", - "uapsd_enable": true, - "ap_bridge": false, - "wps_pbc": [ - "set", - [ - ] - ], - "mac_list": [ - "set", - [ - ] - ], - "associated_clients": [ - "set", - [ - ] - ], - "btm": 1, - "_uuid": [ - "uuid", - "a007d865-fe4b-4265-a9a1-69d4b309e939" - ], - "ssid_broadcast": "enabled", - "wps": [ - "set", - [ - ] - ], - "mcast2ucast": [ - "set", - [ - ] - ], - "mode": "ap", - "mac_list_type": "none", - "wps_pbc_key_id": "", - "ft_psk": 0, - "channel": [ - "set", - [ - ] - ], - "parent": [ - "set", - [ - ] - ], - "multi_ap": [ - "set", - [ - ] - ], - "ap_vlan_sta_addr": [ - "set", - [ - ] - ], - "security": [ - "map", - [ - [ - "encryption", - "OPEN" - ] - ] - ], - "wds": [ - "set", - [ - ] - ], - "enabled": true, - "vlan_id": 1, - "min_hw_mode": "11n", - "vif_config": [ - "uuid", - "fc3de7db-ee6c-452c-859c-1be81b0b5b24" - ], - "_version": [ - "uuid", - "a96bff45-29bd-423b-9014-10a418683e5d" - ], - "bridge": "lan", - "group_rekey": 0, - "ft_mobility_domain": [ - "set", - [ - ] - ], - "dynamic_beacon": [ - "set", - [ - ] - ], - "rrm": 1 -} diff --git a/opensync-gateway/src/test/resources/Wifi_VIF_State-home-ap-l50.json b/opensync-gateway/src/test/resources/Wifi_VIF_State-home-ap-l50.json deleted file mode 100644 index 6000fce..0000000 --- a/opensync-gateway/src/test/resources/Wifi_VIF_State-home-ap-l50.json +++ /dev/null @@ -1,109 +0,0 @@ -{ - "vif_radio_idx": [ - "set", - [ - ] - ], - "if_name": "home-ap-l50", - "state": [ - "set", - [ - ] - ], - "mac": "24:f5:a2:ef:2e:55", - "ssid": "TipWlan-cloud-3-radios", - "uapsd_enable": true, - "ap_bridge": false, - "wps_pbc": [ - "set", - [ - ] - ], - "mac_list": [ - "set", - [ - ] - ], - "associated_clients": [ - "uuid", - "073c3961-33fe-4054-abc6-ae2e8b91c914" - ], - "btm": 1, - "_uuid": [ - "uuid", - "7ebfab8d-0962-4af3-a45b-b5a9d68c86c8" - ], - "ssid_broadcast": "enabled", - "wps": [ - "set", - [ - ] - ], - "mcast2ucast": [ - "set", - [ - ] - ], - "mode": "ap", - "mac_list_type": "none", - "wps_pbc_key_id": "", - "ft_psk": 0, - "channel": [ - "set", - [ - ] - ], - "parent": [ - "set", - [ - ] - ], - "multi_ap": [ - "set", - [ - ] - ], - "ap_vlan_sta_addr": [ - "set", - [ - ] - ], - "security": [ - "map", - [ - [ - "encryption", - "OPEN" - ] - ] - ], - "wds": [ - "set", - [ - ] - ], - "enabled": true, - "vlan_id": 1, - "min_hw_mode": "11ac", - "vif_config": [ - "uuid", - "54c01e8b-4d67-456e-ab18-cbc89c784c2a" - ], - "_version": [ - "uuid", - "faec64fb-fbc1-417a-9ff4-f30ff2c5be94" - ], - "bridge": "lan", - "group_rekey": 0, - "ft_mobility_domain": [ - "set", - [ - ] - ], - "dynamic_beacon": [ - "set", - [ - ] - ], - "rrm": 1 -} diff --git a/opensync-gateway/src/test/resources/Wifi_VIF_State-home-ap-u50.json b/opensync-gateway/src/test/resources/Wifi_VIF_State-home-ap-u50.json deleted file mode 100644 index c2b73e6..0000000 --- a/opensync-gateway/src/test/resources/Wifi_VIF_State-home-ap-u50.json +++ /dev/null @@ -1,96 +0,0 @@ -{ - "vif_radio_idx": [ - "set", - [] - ], - "if_name": "home-ap-u50", - "state": [ - "set", - [] - ], - "mac": "26:f5:a2:ef:2e:56", - "ssid": "TipWlan-cloud-3-radios", - "uapsd_enable": true, - "ap_bridge": false, - "wps_pbc": [ - "set", - [] - ], - "mac_list": [ - "set", - [] - ], - "associated_clients": [ - "uuid", - "c9f5a30d-7ccf-406f-a0d8-f108b377584e" - ], - "btm": 1, - "_uuid": [ - "uuid", - "009e6ee9-d687-4201-9c55-f42d26cbd7b5" - ], - "ssid_broadcast": "enabled", - "wps": [ - "set", - [] - ], - "mcast2ucast": [ - "set", - [] - ], - "mode": "ap", - "mac_list_type": "none", - "wps_pbc_key_id": "", - "ft_psk": 0, - "channel": [ - "set", - [] - ], - "parent": [ - "set", - [] - ], - "multi_ap": [ - "set", - [] - ], - "ap_vlan_sta_addr": [ - "set", - [] - ], - "security": [ - "map", - [ - [ - "encryption", - "OPEN" - ] - ] - ], - "wds": [ - "set", - [] - ], - "enabled": true, - "vlan_id": 1, - "min_hw_mode": "11ac", - "vif_config": [ - "uuid", - "4aeefd3b-b86f-45e4-a9a1-c734363be9c8" - ], - "_version": [ - "uuid", - "e70c7842-6257-46d1-94d3-350a55733fc4" - ], - "bridge": "lan", - "group_rekey": 0, - "ft_mobility_domain": [ - "set", - [] - ], - "dynamic_beacon": [ - "set", - [] - ], - "rrm": 1 -} \ No newline at end of file