mirror of
				https://github.com/Telecominfraproject/wlan-cloud-opensync-controller.git
				synced 2025-11-03 20:17:53 +00:00 
			
		
		
		
	[WIFI-7323] push new config to AP only if the cloud config is more recent than what was previouly pushed
This commit is contained in:
		@@ -582,7 +582,8 @@ public class OpensyncExternalIntegrationCloud implements OpensyncExternalIntegra
 | 
				
			|||||||
            protocolStatusData.setBandPlan("FCC");
 | 
					            protocolStatusData.setBandPlan("FCC");
 | 
				
			||||||
            protocolStatusData.setBaseMacAddress(MacAddress.valueOf(connectNodeInfo.macAddress));
 | 
					            protocolStatusData.setBaseMacAddress(MacAddress.valueOf(connectNodeInfo.macAddress));
 | 
				
			||||||
            protocolStatusData.setCloudCfgDataVersion(42L);
 | 
					            protocolStatusData.setCloudCfgDataVersion(42L);
 | 
				
			||||||
            protocolStatusData.setReportedCfgDataVersion(42L);
 | 
					            //this will be set later in the flow - after the config is successfully pushed to the AP
 | 
				
			||||||
 | 
					            //protocolStatusData.setReportedCfgDataVersion(42L);
 | 
				
			||||||
            CountryCode countryCode = Location.getCountryCode(locationServiceInterface.getOrNull(ce.getLocationId()));
 | 
					            CountryCode countryCode = Location.getCountryCode(locationServiceInterface.getOrNull(ce.getLocationId()));
 | 
				
			||||||
            if (countryCode != null)
 | 
					            if (countryCode != null)
 | 
				
			||||||
                protocolStatusData.setCountryCode(countryCode.getName());
 | 
					                protocolStatusData.setCountryCode(countryCode.getName());
 | 
				
			||||||
@@ -2432,6 +2433,83 @@ public class OpensyncExternalIntegrationCloud implements OpensyncExternalIntegra
 | 
				
			|||||||
        // TODO: will handle changes from Command_State table
 | 
					        // TODO: will handle changes from Command_State table
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    @Override
 | 
				
			||||||
 | 
					    public long getConfigVersionFromStatus(String apId) {
 | 
				
			||||||
 | 
					        long ret = 0;
 | 
				
			||||||
 | 
					        
 | 
				
			||||||
 | 
					        OvsdbSession ovsdbSession = ovsdbSessionMapInterface.getSession(apId);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        if (ovsdbSession == null) {
 | 
				
			||||||
 | 
					            LOG.debug("getConfigVersionFromStatus::Cannot get Session for AP {}", apId);
 | 
				
			||||||
 | 
					            return ret;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        long equipmentId = ovsdbSession.getEquipmentId();
 | 
				
			||||||
 | 
					        Equipment ce = equipmentServiceInterface.getOrNull(equipmentId);
 | 
				
			||||||
 | 
					        if (ce == null) {
 | 
				
			||||||
 | 
					            LOG.debug("getConfigVersionFromStatus Cannot get customer Equipment for {}", apId);
 | 
				
			||||||
 | 
					            return ret;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        int customerId = ce.getCustomerId();
 | 
				
			||||||
 | 
					        if ((customerId < 0) || (equipmentId < 0)) {
 | 
				
			||||||
 | 
					            LOG.debug("getConfigVersionFromStatus::Cannot get valid CustomerId {} or EquipmentId {} for AP {}", customerId, equipmentId, apId);
 | 
				
			||||||
 | 
					            return ret;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        
 | 
				
			||||||
 | 
					        Status protocolStatus = statusServiceInterface.getOrNull(customerId, equipmentId, StatusDataType.PROTOCOL);
 | 
				
			||||||
 | 
					        if(protocolStatus != null) {
 | 
				
			||||||
 | 
					            EquipmentProtocolStatusData epsd = (EquipmentProtocolStatusData) protocolStatus.getDetails();
 | 
				
			||||||
 | 
					            if(epsd!=null && epsd.getReportedCfgDataVersion()!=null) {
 | 
				
			||||||
 | 
					                ret = epsd.getReportedCfgDataVersion();
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        return ret;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    
 | 
				
			||||||
 | 
					    @Override
 | 
				
			||||||
 | 
					    public void updateConfigVersionInStatus(String apId, long configVersionFromProfiles) {
 | 
				
			||||||
 | 
					        OvsdbSession ovsdbSession = ovsdbSessionMapInterface.getSession(apId);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        if (ovsdbSession == null) {
 | 
				
			||||||
 | 
					            LOG.debug("updateConfigVersionInStatus::Cannot get Session for AP {}", apId);
 | 
				
			||||||
 | 
					            return;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        long equipmentId = ovsdbSession.getEquipmentId();
 | 
				
			||||||
 | 
					        Equipment ce = equipmentServiceInterface.getOrNull(equipmentId);
 | 
				
			||||||
 | 
					        if (ce == null) {
 | 
				
			||||||
 | 
					            LOG.debug("updateConfigVersionInStatus Cannot get customer Equipment for {}", apId);
 | 
				
			||||||
 | 
					            return;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        int customerId = ce.getCustomerId();
 | 
				
			||||||
 | 
					        if ((customerId < 0) || (equipmentId < 0)) {
 | 
				
			||||||
 | 
					            LOG.debug("updateConfigVersionInStatus::Cannot get valid CustomerId {} or EquipmentId {} for AP {}", customerId, equipmentId, apId);
 | 
				
			||||||
 | 
					            return;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        
 | 
				
			||||||
 | 
					        Status protocolStatus = statusServiceInterface.getOrNull(customerId, equipmentId, StatusDataType.PROTOCOL);
 | 
				
			||||||
 | 
					        if(protocolStatus == null) {
 | 
				
			||||||
 | 
					            protocolStatus = new Status();
 | 
				
			||||||
 | 
					            protocolStatus.setCustomerId(customerId);
 | 
				
			||||||
 | 
					            protocolStatus.setEquipmentId(equipmentId);
 | 
				
			||||||
 | 
					            protocolStatus.setCreatedTimestamp(System.currentTimeMillis());
 | 
				
			||||||
 | 
					            protocolStatus.setLastModifiedTimestamp(protocolStatus.getCreatedTimestamp());
 | 
				
			||||||
 | 
					            protocolStatus.setDetails(new EquipmentProtocolStatusData());
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        EquipmentProtocolStatusData epsd = (EquipmentProtocolStatusData) protocolStatus.getDetails();
 | 
				
			||||||
 | 
					        if(epsd==null) {
 | 
				
			||||||
 | 
					            epsd = new EquipmentProtocolStatusData();
 | 
				
			||||||
 | 
					            protocolStatus.setDetails(epsd);
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        
 | 
				
			||||||
 | 
					        epsd.setReportedCfgDataVersion(configVersionFromProfiles);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        statusServiceInterface.update(protocolStatus);
 | 
				
			||||||
 | 
					        
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    
 | 
				
			||||||
    /**
 | 
					    /**
 | 
				
			||||||
     * Clear the EquipmentStatus for this AP, and set all client sessions to
 | 
					     * Clear the EquipmentStatus for this AP, and set all client sessions to
 | 
				
			||||||
     * disconnected. Done as part of a reconfiguration/configuration change
 | 
					     * disconnected. Done as part of a reconfiguration/configuration change
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -56,4 +56,8 @@ public interface OpensyncExternalIntegrationInterface {
 | 
				
			|||||||
    void clearEquipmentStatus(String apId);
 | 
					    void clearEquipmentStatus(String apId);
 | 
				
			||||||
    
 | 
					    
 | 
				
			||||||
    void processMqttMessage(String topic, Report report);
 | 
					    void processMqttMessage(String topic, Report report);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    long getConfigVersionFromStatus(String apId);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    void updateConfigVersionInStatus(String apId, long configVersionFromProfiles);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -7,6 +7,8 @@ import java.util.Objects;
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
public class ConnectNodeInfo implements Cloneable {
 | 
					public class ConnectNodeInfo implements Cloneable {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public static String CONFIG_VERSION_PROPERTY_NAME = "tip/reportedCfgDataVersion";
 | 
				
			||||||
 | 
					    
 | 
				
			||||||
    public Map<String, String> mqttSettings = new HashMap<>();
 | 
					    public Map<String, String> mqttSettings = new HashMap<>();
 | 
				
			||||||
    public Map<String, String> versionMatrix = new HashMap<>();
 | 
					    public Map<String, String> versionMatrix = new HashMap<>();
 | 
				
			||||||
    public Map<String, String> wifiRadioStates = new HashMap<>();
 | 
					    public Map<String, String> wifiRadioStates = new HashMap<>();
 | 
				
			||||||
@@ -35,6 +37,18 @@ public class ConnectNodeInfo implements Cloneable {
 | 
				
			|||||||
    public String manufacturerDate;
 | 
					    public String manufacturerDate;
 | 
				
			||||||
    public String certificationRegion;
 | 
					    public String certificationRegion;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public long getConfigVersion() {
 | 
				
			||||||
 | 
					        
 | 
				
			||||||
 | 
					        long ret = 0;
 | 
				
			||||||
 | 
					        try {
 | 
				
			||||||
 | 
					            ret = Long.parseLong(versionMatrix.get(CONFIG_VERSION_PROPERTY_NAME));
 | 
				
			||||||
 | 
					        } catch(Exception e) {
 | 
				
			||||||
 | 
					            //do nothing
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        return ret;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    
 | 
				
			||||||
    @Override
 | 
					    @Override
 | 
				
			||||||
    public ConnectNodeInfo clone() {
 | 
					    public ConnectNodeInfo clone() {
 | 
				
			||||||
        try {
 | 
					        try {
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,6 +1,7 @@
 | 
				
			|||||||
package com.telecominfraproject.wlan.opensync.external.integration.models;
 | 
					package com.telecominfraproject.wlan.opensync.external.integration.models;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import java.util.ArrayList;
 | 
					import java.util.ArrayList;
 | 
				
			||||||
 | 
					import java.util.Collection;
 | 
				
			||||||
import java.util.HashSet;
 | 
					import java.util.HashSet;
 | 
				
			||||||
import java.util.List;
 | 
					import java.util.List;
 | 
				
			||||||
import java.util.Objects;
 | 
					import java.util.Objects;
 | 
				
			||||||
@@ -44,9 +45,67 @@ public class OpensyncAPConfig extends OpensyncAPBase {
 | 
				
			|||||||
    private EquipmentGatewayRecord equipmentGateway;
 | 
					    private EquipmentGatewayRecord equipmentGateway;
 | 
				
			||||||
    private List<Profile> captiveProfiles;
 | 
					    private List<Profile> captiveProfiles;
 | 
				
			||||||
    private List<Profile> bonjourGatewayProfiles;
 | 
					    private List<Profile> bonjourGatewayProfiles;
 | 
				
			||||||
 | 
					    
 | 
				
			||||||
 | 
					    private long configVersion;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    private List<MacAddress> blockedClients;
 | 
					    private List<MacAddress> blockedClients;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public long getConfigVersion() {
 | 
				
			||||||
 | 
					        //go through all child objects and get the most recent lastModifiedTimestamp from them
 | 
				
			||||||
 | 
					        configVersion = 0;
 | 
				
			||||||
 | 
					        
 | 
				
			||||||
 | 
					        if(customerEquipment!=null && customerEquipment.getLastModifiedTimestamp()> configVersion) {
 | 
				
			||||||
 | 
					            configVersion = customerEquipment.getLastModifiedTimestamp();
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        
 | 
				
			||||||
 | 
					        if(hotspotConfig!=null) {
 | 
				
			||||||
 | 
					            configVersion = getLatestLastMod(configVersion, hotspotConfig.getHotspot20OperatorSet());
 | 
				
			||||||
 | 
					            configVersion = getLatestLastMod(configVersion, hotspotConfig.getHotspot20ProfileSet());
 | 
				
			||||||
 | 
					            configVersion = getLatestLastMod(configVersion, hotspotConfig.getHotspot20ProviderSet());
 | 
				
			||||||
 | 
					            configVersion = getLatestLastMod(configVersion, hotspotConfig.getHotspot20VenueSet());
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        configVersion = getLatestLastMod(configVersion, apProfile);
 | 
				
			||||||
 | 
					        configVersion = getLatestLastMod(configVersion, rfProfile);
 | 
				
			||||||
 | 
					        configVersion = getLatestLastMod(configVersion, ssidProfile);
 | 
				
			||||||
 | 
					        configVersion = getLatestLastMod(configVersion, metricsProfile);
 | 
				
			||||||
 | 
					        configVersion = getLatestLastMod(configVersion, radiusProfiles);
 | 
				
			||||||
 | 
					        configVersion = getLatestLastMod(configVersion, wiredEthernetPortProfile);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        if(equipmentLocation!=null && equipmentLocation.getLastModifiedTimestamp()> configVersion) {
 | 
				
			||||||
 | 
					            configVersion = equipmentLocation.getLastModifiedTimestamp();
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        configVersion = getLatestLastMod(configVersion, captiveProfiles);
 | 
				
			||||||
 | 
					        configVersion = getLatestLastMod(configVersion, bonjourGatewayProfiles);
 | 
				
			||||||
 | 
					        
 | 
				
			||||||
 | 
					        return configVersion;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    
 | 
				
			||||||
 | 
					    private long getLatestLastMod(long incomingLastMod, Collection<Profile> profiles) {
 | 
				
			||||||
 | 
					        
 | 
				
			||||||
 | 
					        if(profiles!=null) {
 | 
				
			||||||
 | 
					            for(Profile p: profiles) {
 | 
				
			||||||
 | 
					                if(incomingLastMod < p.getLastModifiedTimestamp()) {
 | 
				
			||||||
 | 
					                    incomingLastMod = p.getLastModifiedTimestamp();
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        
 | 
				
			||||||
 | 
					        return incomingLastMod;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    private long getLatestLastMod(long incomingLastMod, Profile profile) {
 | 
				
			||||||
 | 
					        
 | 
				
			||||||
 | 
					        if(profile!=null) {
 | 
				
			||||||
 | 
					            if(incomingLastMod < profile.getLastModifiedTimestamp()) {
 | 
				
			||||||
 | 
					                incomingLastMod = profile.getLastModifiedTimestamp();
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        
 | 
				
			||||||
 | 
					        return incomingLastMod;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    @Override
 | 
					    @Override
 | 
				
			||||||
    public OpensyncAPConfig clone() {
 | 
					    public OpensyncAPConfig clone() {
 | 
				
			||||||
        OpensyncAPConfig ret = (OpensyncAPConfig) super.clone();
 | 
					        OpensyncAPConfig ret = (OpensyncAPConfig) super.clone();
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -212,4 +212,14 @@ public class OpensyncExternalIntegrationSimple implements OpensyncExternalIntegr
 | 
				
			|||||||
        LOG.info("nodeStateDbTableUpdate for AP {}", apId);
 | 
					        LOG.info("nodeStateDbTableUpdate for AP {}", apId);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    @Override
 | 
				
			||||||
 | 
					    public long getConfigVersionFromStatus(String inventoryId) {
 | 
				
			||||||
 | 
					        //0 means always push config to ap, do not do the version check for the configuration before pushing it
 | 
				
			||||||
 | 
					        return 0;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    
 | 
				
			||||||
 | 
					    @Override
 | 
				
			||||||
 | 
					    public void updateConfigVersionInStatus(String apId, long configVersionFromProfiles) {
 | 
				
			||||||
 | 
					        // do nothing here
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -72,6 +72,12 @@ public class TipWlanOvsdbClient implements OvsdbClientInterface {
 | 
				
			|||||||
    @org.springframework.beans.factory.annotation.Value("${tip.wlan.defaultCommandDurationSec:3600}")
 | 
					    @org.springframework.beans.factory.annotation.Value("${tip.wlan.defaultCommandDurationSec:3600}")
 | 
				
			||||||
    private long defaultCommandDurationSec;
 | 
					    private long defaultCommandDurationSec;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    @org.springframework.beans.factory.annotation.Value("${tip.wlan.checkConfigVersionFromStatus:true}")
 | 
				
			||||||
 | 
					    private boolean checkBeforePushConfigVersionFromStatus;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    @org.springframework.beans.factory.annotation.Value("${tip.wlan.checkConfigVersionFromAp:true}")
 | 
				
			||||||
 | 
					    private boolean checkBeforePushConfigVersionFromAp;
 | 
				
			||||||
 | 
					    
 | 
				
			||||||
    @Autowired
 | 
					    @Autowired
 | 
				
			||||||
    private SslContext sslContext;
 | 
					    private SslContext sslContext;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -242,15 +248,69 @@ public class TipWlanOvsdbClient implements OvsdbClientInterface {
 | 
				
			|||||||
        
 | 
					        
 | 
				
			||||||
        OpensyncAPConfig opensyncAPConfig = extIntegrationInterface.getApConfig(apId);
 | 
					        OpensyncAPConfig opensyncAPConfig = extIntegrationInterface.getApConfig(apId);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        //get last known configVersion from the AP
 | 
				
			||||||
 | 
					        long configVersionFromAp = checkBeforePushConfigVersionFromAp ? connectNodeInfo.getConfigVersion() : 0;
 | 
				
			||||||
 | 
					        
 | 
				
			||||||
 | 
					        //get last known configVersion from the EquipmentProtocolStatusData        
 | 
				
			||||||
 | 
					        long configVersionFromStatus = checkBeforePushConfigVersionFromStatus ? extIntegrationInterface.getConfigVersionFromStatus(apId) : 0;
 | 
				
			||||||
 | 
					        
 | 
				
			||||||
 | 
					        //get current configVersion from the profiles and equipment
 | 
				
			||||||
 | 
					        long configVersionFromProfiles = opensyncAPConfig.getConfigVersion();
 | 
				
			||||||
 | 
					        
 | 
				
			||||||
 | 
					        boolean needToPushConfigToAP = needToPushToAp(configVersionFromAp, configVersionFromStatus, configVersionFromProfiles);
 | 
				
			||||||
 | 
					        
 | 
				
			||||||
 | 
					        if(needToPushConfigToAP) {
 | 
				
			||||||
 | 
					            pushConfigToAp(ovsdbClient, opensyncAPConfig, apId, configVersionFromProfiles);
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        
 | 
				
			||||||
 | 
					        LOG.debug("Client connect Done");
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    private boolean needToPushToAp(long configVersionFromAp, long configVersionFromStatus, long configVersionFromProfiles) {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        boolean ret = false;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        if(configVersionFromAp == 0) {
 | 
				
			||||||
 | 
					            LOG.debug("do not know what is on AP, let's push new config");
 | 
				
			||||||
 | 
					            ret = true;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        
 | 
				
			||||||
 | 
					        if(checkBeforePushConfigVersionFromAp && configVersionFromAp < configVersionFromProfiles ) {
 | 
				
			||||||
 | 
					            LOG.debug("our profiles are more recent than what was pushed  to AP previously, let's push new config");
 | 
				
			||||||
 | 
					            ret = true;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        if(checkBeforePushConfigVersionFromStatus && configVersionFromStatus < configVersionFromProfiles) {
 | 
				
			||||||
 | 
					           LOG.debug("our profiles are more recent than the version stored in the protocol status, let's push new config");
 | 
				
			||||||
 | 
					           ret = true;
 | 
				
			||||||
 | 
					       }
 | 
				
			||||||
 | 
					        
 | 
				
			||||||
 | 
					       if(!checkBeforePushConfigVersionFromAp && !checkBeforePushConfigVersionFromStatus) {
 | 
				
			||||||
 | 
					           LOG.debug("we do not do any checks for config versions - let's push new config");
 | 
				
			||||||
 | 
					           ret = true;
 | 
				
			||||||
 | 
					       }
 | 
				
			||||||
 | 
					       
 | 
				
			||||||
 | 
					       if(!ret) {
 | 
				
			||||||
 | 
					           LOG.debug("no need to push new config to AP");
 | 
				
			||||||
 | 
					       }
 | 
				
			||||||
 | 
					       
 | 
				
			||||||
 | 
					       return ret;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    
 | 
				
			||||||
 | 
					    private void pushConfigToAp(OvsdbClient ovsdbClient, OpensyncAPConfig opensyncAPConfig, String apInventoryId, long configVersionFromProfiles) {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        ovsdbDao.removeAllPasspointConfigs(ovsdbClient);
 | 
					        ovsdbDao.removeAllPasspointConfigs(ovsdbClient);
 | 
				
			||||||
        ovsdbDao.removeAllSsids(ovsdbClient); // always
 | 
					        ovsdbDao.removeAllSsids(ovsdbClient); // always
 | 
				
			||||||
        ovsdbDao.removeAllInetConfigs(ovsdbClient);
 | 
					        ovsdbDao.removeAllInetConfigs(ovsdbClient);
 | 
				
			||||||
        ovsdbDao.resetWiredPorts(ovsdbClient, opensyncAPConfig); 
 | 
					        if(opensyncAPConfig!=null) {
 | 
				
			||||||
 | 
					            ovsdbDao.resetWiredPorts(ovsdbClient, opensyncAPConfig); // need to run this first before remove Status
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
        ovsdbDao.removeWifiRrm(ovsdbClient);
 | 
					        ovsdbDao.removeWifiRrm(ovsdbClient);
 | 
				
			||||||
        ovsdbDao.removeRadsecRadiusAndRealmConfigs(ovsdbClient);
 | 
					        ovsdbDao.removeRadsecRadiusAndRealmConfigs(ovsdbClient);
 | 
				
			||||||
        ovsdbDao.removeAllStatsConfigs(ovsdbClient); // always
 | 
					        ovsdbDao.removeAllStatsConfigs(ovsdbClient); // always
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        extIntegrationInterface.clearEquipmentStatus(apId);
 | 
					        extIntegrationInterface.clearEquipmentStatus(apInventoryId);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        if (opensyncAPConfig != null) {
 | 
					        if (opensyncAPConfig != null) {
 | 
				
			||||||
            ovsdbDao.configureNode(ovsdbClient, opensyncAPConfig);
 | 
					            ovsdbDao.configureNode(ovsdbClient, opensyncAPConfig);
 | 
				
			||||||
@@ -275,12 +335,17 @@ public class TipWlanOvsdbClient implements OvsdbClientInterface {
 | 
				
			|||||||
            ovsdbDao.updateEventReportingInterval(ovsdbClient, collectionIntervalSecEvent);
 | 
					            ovsdbDao.updateEventReportingInterval(ovsdbClient, collectionIntervalSecEvent);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        } else {
 | 
					        } else {
 | 
				
			||||||
            LOG.info("No Configuration available for {}", apId);
 | 
					            LOG.info("No Configuration available for {}", apInventoryId);
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					        
 | 
				
			||||||
 | 
					        //after a successful config push let's update the configVersion on the AP and in the EquipmentProtocolStatusData
 | 
				
			||||||
 | 
					        if(checkBeforePushConfigVersionFromStatus) {
 | 
				
			||||||
 | 
					            extIntegrationInterface.updateConfigVersionInStatus(apInventoryId, configVersionFromProfiles);
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        ovsdbDao.updateConfigVersionInNode(ovsdbClient, configVersionFromProfiles);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        LOG.debug("Client connect Done");
 | 
					 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					    
 | 
				
			||||||
    @Override
 | 
					    @Override
 | 
				
			||||||
    public Set<String> getConnectedClientIds() {
 | 
					    public Set<String> getConnectedClientIds() {
 | 
				
			||||||
        return ovsdbSessionMapInterface.getConnectedClientIds();
 | 
					        return ovsdbSessionMapInterface.getConnectedClientIds();
 | 
				
			||||||
@@ -327,36 +392,20 @@ public class TipWlanOvsdbClient implements OvsdbClientInterface {
 | 
				
			|||||||
            return;
 | 
					            return;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        ovsdbDao.removeAllPasspointConfigs(ovsdbClient);
 | 
					        //get last known configVersion from the AP
 | 
				
			||||||
        ovsdbDao.removeAllSsids(ovsdbClient); // always
 | 
					        long configVersionFromAp = checkBeforePushConfigVersionFromAp ? ovsdbDao.getConfigVersionFromNode(ovsdbClient) : 0;
 | 
				
			||||||
        ovsdbDao.removeAllInetConfigs(ovsdbClient);
 | 
					 | 
				
			||||||
        ovsdbDao.resetWiredPorts(ovsdbClient, opensyncAPConfig); // need to run this first before remove Status
 | 
					 | 
				
			||||||
        ovsdbDao.removeWifiRrm(ovsdbClient);
 | 
					 | 
				
			||||||
        ovsdbDao.removeRadsecRadiusAndRealmConfigs(ovsdbClient);
 | 
					 | 
				
			||||||
        ovsdbDao.removeAllStatsConfigs(ovsdbClient);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        extIntegrationInterface.clearEquipmentStatus(apId);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        ovsdbDao.configureNode(ovsdbClient, opensyncAPConfig);
 | 
					 | 
				
			||||||
        ovsdbDao.configureWifiRrm(ovsdbClient, opensyncAPConfig);
 | 
					 | 
				
			||||||
        ovsdbDao.configureGreTunnels(ovsdbClient, opensyncAPConfig);
 | 
					 | 
				
			||||||
        ovsdbDao.createVlanNetworkInterfaces(ovsdbClient, opensyncAPConfig);
 | 
					 | 
				
			||||||
        ovsdbDao.configureWiredPort(ovsdbClient, opensyncAPConfig);
 | 
					 | 
				
			||||||
        ovsdbDao.configureRadsecRadiusAndRealm(ovsdbClient, opensyncAPConfig);
 | 
					 | 
				
			||||||
        ovsdbDao.configureSsids(ovsdbClient, opensyncAPConfig);
 | 
					 | 
				
			||||||
        if (opensyncAPConfig.getHotspotConfig() != null) {
 | 
					 | 
				
			||||||
            ovsdbDao.configureHotspots(ovsdbClient, opensyncAPConfig);
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        ovsdbDao.configureInterfaces(ovsdbClient);
 | 
					 | 
				
			||||||
        ovsdbDao.configureWifiRadios(ovsdbClient, opensyncAPConfig);
 | 
					 | 
				
			||||||
        
 | 
					        
 | 
				
			||||||
        ovsdbDao.configureStatsFromProfile(ovsdbClient, opensyncAPConfig);
 | 
					        //get last known configVersion from the EquipmentProtocolStatusData        
 | 
				
			||||||
        if (ovsdbDao.getDeviceStatsReportingInterval(ovsdbClient) != collectionIntervalSecDeviceStats) {
 | 
					        long configVersionFromStatus = checkBeforePushConfigVersionFromStatus ? extIntegrationInterface.getConfigVersionFromStatus(apId) : 0;
 | 
				
			||||||
            ovsdbDao.updateDeviceStatsReportingInterval(ovsdbClient, collectionIntervalSecDeviceStats);
 | 
					        
 | 
				
			||||||
 | 
					        //get current configVersion from the profiles and equipment
 | 
				
			||||||
 | 
					        long configVersionFromProfiles = opensyncAPConfig.getConfigVersion();
 | 
				
			||||||
 | 
					        
 | 
				
			||||||
 | 
					        boolean needToPushConfigToAP = needToPushToAp(configVersionFromAp, configVersionFromStatus, configVersionFromProfiles);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        if(needToPushConfigToAP) {
 | 
				
			||||||
 | 
					            pushConfigToAp(ovsdbClient, opensyncAPConfig, apId, configVersionFromProfiles);
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        ovsdbDao.enableNetworkProbeForSyntheticClient(ovsdbClient);
 | 
					 | 
				
			||||||
        ovsdbDao.updateEventReportingInterval(ovsdbClient, collectionIntervalSecEvent);
 | 
					 | 
				
			||||||
        
 | 
					        
 | 
				
			||||||
        LOG.debug("Finished processConfigChanged for {}", apId);
 | 
					        LOG.debug("Finished processConfigChanged for {}", apId);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
@@ -693,7 +742,7 @@ public class TipWlanOvsdbClient implements OvsdbClientInterface {
 | 
				
			|||||||
    private void monitorWifiVifStateDbTable(OvsdbClient ovsdbClient, String key) throws OvsdbClientException {
 | 
					    private void monitorWifiVifStateDbTable(OvsdbClient ovsdbClient, String key) throws OvsdbClientException {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        CompletableFuture<TableUpdates> vsCf = ovsdbClient.monitor(OvsdbDao.ovsdbName, OvsdbDao.wifiVifStateDbTable + "_" + key,
 | 
					        CompletableFuture<TableUpdates> vsCf = ovsdbClient.monitor(OvsdbDao.ovsdbName, OvsdbDao.wifiVifStateDbTable + "_" + key,
 | 
				
			||||||
                new MonitorRequests(ImmutableMap.of(OvsdbDao.wifiVifStateDbTable, new MonitorRequest(new MonitorSelect(false, true, true, true)))),
 | 
					                new MonitorRequests(ImmutableMap.of(OvsdbDao.wifiVifStateDbTable, new MonitorRequest(new MonitorSelect(true, true, true, true)))),
 | 
				
			||||||
                tableUpdates -> {
 | 
					                tableUpdates -> {
 | 
				
			||||||
                    try {
 | 
					                    try {
 | 
				
			||||||
                        LOG.info(OvsdbDao.wifiVifStateDbTable + "_" + key + " monitor callback received {}", tableUpdates);
 | 
					                        LOG.info(OvsdbDao.wifiVifStateDbTable + "_" + key + " monitor callback received {}", tableUpdates);
 | 
				
			||||||
@@ -731,7 +780,19 @@ public class TipWlanOvsdbClient implements OvsdbClientInterface {
 | 
				
			|||||||
                    }
 | 
					                    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                });
 | 
					                });
 | 
				
			||||||
        vsCf.join();
 | 
					
 | 
				
			||||||
 | 
					        try {
 | 
				
			||||||
 | 
					            List<OpensyncAPVIFState> vifsToInsert = new ArrayList<>();
 | 
				
			||||||
 | 
					            TableUpdates initialTableUpdates = vsCf.join();
 | 
				
			||||||
 | 
					            for (TableUpdate tableUpdate : initialTableUpdates.getTableUpdates().values()) {
 | 
				
			||||||
 | 
					                for (RowUpdate rowUpdate : tableUpdate.getRowUpdates().values()) {
 | 
				
			||||||
 | 
					                    vifsToInsert.addAll(ovsdbDao.getOpensyncApVifStateForRowUpdate(rowUpdate, key, ovsdbClient));
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					            extIntegrationInterface.wifiVIFStateDbTableUpdate(vifsToInsert, key);
 | 
				
			||||||
 | 
					        } catch (Exception e) {
 | 
				
			||||||
 | 
					            LOG.error("initial wifiVIFStateDbTableUpdate failed", e);
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -259,4 +259,12 @@ public class OvsdbDao extends OvsdbDaoBase {
 | 
				
			|||||||
        ovsdbNodeConfig.configureDynamicRadiusProxyToAPC(ovsdbClient, opensyncAPConfig);
 | 
					        ovsdbNodeConfig.configureDynamicRadiusProxyToAPC(ovsdbClient, opensyncAPConfig);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public long getConfigVersionFromNode(OvsdbClient ovsdbClient) {
 | 
				
			||||||
 | 
					        return ovsdbNode.getConfigVersionFromNode(ovsdbClient);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public void updateConfigVersionInNode(OvsdbClient ovsdbClient, long configVersionFromProfiles) {
 | 
				
			||||||
 | 
					        ovsdbNode.updateConfigVersionInNode(ovsdbClient, configVersionFromProfiles);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -417,4 +417,96 @@ public class OvsdbNode extends OvsdbDaoBase {
 | 
				
			|||||||
        return ret;
 | 
					        return ret;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public long getConfigVersionFromNode(OvsdbClient ovsdbClient) {
 | 
				
			||||||
 | 
					        
 | 
				
			||||||
 | 
					        long ret = 0;
 | 
				
			||||||
 | 
					        
 | 
				
			||||||
 | 
					        Map<String, String> versionMatrix = getVersionMatrixFromNode(ovsdbClient);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        try {
 | 
				
			||||||
 | 
					            ret = Long.parseLong(versionMatrix.get(ConnectNodeInfo.CONFIG_VERSION_PROPERTY_NAME));
 | 
				
			||||||
 | 
					        } catch(Exception e) {
 | 
				
			||||||
 | 
					            //do nothing
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        
 | 
				
			||||||
 | 
					        LOG.debug("getConfigVersionFromNode {}", ret);
 | 
				
			||||||
 | 
					        
 | 
				
			||||||
 | 
					        return ret;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public Map<String, String> getVersionMatrixFromNode(OvsdbClient ovsdbClient) {
 | 
				
			||||||
 | 
					        
 | 
				
			||||||
 | 
					        Map<String, String> ret = new HashMap<>();
 | 
				
			||||||
 | 
					        
 | 
				
			||||||
 | 
					        try {
 | 
				
			||||||
 | 
					            List<Operation> operations = new ArrayList<>();
 | 
				
			||||||
 | 
					            List<Condition> conditions = new ArrayList<>();
 | 
				
			||||||
 | 
					            List<String> columns = new ArrayList<>();
 | 
				
			||||||
 | 
					            columns.add("version_matrix");
 | 
				
			||||||
 | 
					            columns.add("id");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            operations.add(new Select(awlanNodeDbTable, conditions, columns));
 | 
				
			||||||
 | 
					            CompletableFuture<OperationResult[]> fResult = ovsdbClient.transact(ovsdbName, operations);
 | 
				
			||||||
 | 
					            OperationResult[] result = fResult.get(ovsdbTimeoutSec, TimeUnit.SECONDS);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            if (LOG.isDebugEnabled()) {
 | 
				
			||||||
 | 
					                LOG.debug("Select from {}:", awlanNodeDbTable);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                for (OperationResult res : result) {
 | 
				
			||||||
 | 
					                    LOG.debug("Op Result {}", res);
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            Row row = null;
 | 
				
			||||||
 | 
					            if ((result != null) && (result.length > 0) && (result[0] instanceof SelectResult) && !((SelectResult) result[0]).getRows().isEmpty()) {
 | 
				
			||||||
 | 
					                row = ((SelectResult) result[0]).getRows().iterator().next();
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            if( row != null ) {
 | 
				
			||||||
 | 
					                ret = row.getMapColumn("version_matrix");
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        } catch (OvsdbClientException | TimeoutException | ExecutionException | InterruptedException e) {
 | 
				
			||||||
 | 
					            throw new RuntimeException(e);
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        
 | 
				
			||||||
 | 
					        LOG.debug("getVersionMatrixFromNode {}", ret);
 | 
				
			||||||
 | 
					        
 | 
				
			||||||
 | 
					        return ret;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    public void updateConfigVersionInNode(OvsdbClient ovsdbClient, long configVersionFromProfiles) {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        try {
 | 
				
			||||||
 | 
					            //get original version_matrix map value
 | 
				
			||||||
 | 
					            Map<String, String> versionMatrix = getVersionMatrixFromNode(ovsdbClient);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            //update our config version in version_matrix map
 | 
				
			||||||
 | 
					            versionMatrix.put(ConnectNodeInfo.CONFIG_VERSION_PROPERTY_NAME, Long.toString(configVersionFromProfiles));
 | 
				
			||||||
 | 
					            
 | 
				
			||||||
 | 
					            //update the version_matrix column
 | 
				
			||||||
 | 
					            List<Operation> operations = new ArrayList<>();
 | 
				
			||||||
 | 
					            Map<String, Value> updateColumns = new HashMap<>();
 | 
				
			||||||
 | 
					            
 | 
				
			||||||
 | 
					            @SuppressWarnings("unchecked")
 | 
				
			||||||
 | 
					            com.vmware.ovsdb.protocol.operation.notation.Map<String, String> ovsdbVersionMatrix =
 | 
				
			||||||
 | 
					                    com.vmware.ovsdb.protocol.operation.notation.Map.of(versionMatrix);
 | 
				
			||||||
 | 
					            updateColumns.put("version_matrix", ovsdbVersionMatrix);
 | 
				
			||||||
 | 
					            
 | 
				
			||||||
 | 
					            Row row = new Row(updateColumns);
 | 
				
			||||||
 | 
					            operations.add(new Update(awlanNodeDbTable, row));
 | 
				
			||||||
 | 
					            CompletableFuture<OperationResult[]> fResult = ovsdbClient.transact(ovsdbName, operations);
 | 
				
			||||||
 | 
					            OperationResult[] result = fResult.get(ovsdbTimeoutSec, TimeUnit.SECONDS);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            for (OperationResult r : result) {
 | 
				
			||||||
 | 
					                LOG.debug("Op Result {}", r);
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					    
 | 
				
			||||||
 | 
					            LOG.debug("updateConfigVersionInNode {}", configVersionFromProfiles);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        } catch (OvsdbClientException | TimeoutException | ExecutionException | InterruptedException  e) {
 | 
				
			||||||
 | 
					            throw new RuntimeException(e);
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -123,7 +123,6 @@ public class OpensyncGatewayTipWlanOvsdbClientTest {
 | 
				
			|||||||
        Mockito.when(ovsdbSessionMapInterface.getSession("Test_Client_21P10C68818122")).thenReturn(ovsdbSession);
 | 
					        Mockito.when(ovsdbSessionMapInterface.getSession("Test_Client_21P10C68818122")).thenReturn(ovsdbSession);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        OpensyncAPConfig apConfig = Mockito.mock(OpensyncAPConfig.class, Mockito.RETURNS_DEEP_STUBS);
 | 
					        OpensyncAPConfig apConfig = Mockito.mock(OpensyncAPConfig.class, Mockito.RETURNS_DEEP_STUBS);
 | 
				
			||||||
 | 
					 | 
				
			||||||
        Mockito.when(apConfig.getApProfile().getDetails()).thenReturn(Mockito.mock(ApNetworkConfiguration.class));
 | 
					        Mockito.when(apConfig.getApProfile().getDetails()).thenReturn(Mockito.mock(ApNetworkConfiguration.class));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        Mockito.when(opensyncExternalIntegrationInterface.getApConfig(Mockito.anyString())).thenReturn(apConfig);
 | 
					        Mockito.when(opensyncExternalIntegrationInterface.getApConfig(Mockito.anyString())).thenReturn(apConfig);
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user