Adding initial auto-provisioning to LinkSys AP

This commit is contained in:
Mike Hansen
2020-05-14 11:33:27 -04:00
parent 26f0321b8e
commit 36500319f4

View File

@@ -3,6 +3,7 @@ package com.telecominfraproject.wlan.opensync.external.integration;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
@@ -20,9 +21,9 @@ import org.springframework.stereotype.Component;
import com.telecominfraproject.wlan.cloudeventdispatcher.CloudEventDispatcherInterface;
import com.telecominfraproject.wlan.core.model.entity.CountryCode;
import com.telecominfraproject.wlan.core.model.equipment.EquipmentType;
import com.telecominfraproject.wlan.core.model.equipment.MacAddress;
import com.telecominfraproject.wlan.core.model.equipment.RadioType;
import com.telecominfraproject.wlan.customer.models.Customer;
import com.telecominfraproject.wlan.customer.service.CustomerServiceInterface;
import com.telecominfraproject.wlan.equipment.EquipmentServiceInterface;
import com.telecominfraproject.wlan.equipment.models.ApElementConfiguration;
@@ -43,6 +44,7 @@ import com.telecominfraproject.wlan.opensync.external.integration.models.Opensyn
import com.telecominfraproject.wlan.opensync.external.integration.models.OpensyncWifiAssociatedClients;
import com.telecominfraproject.wlan.profile.ProfileServiceInterface;
import com.telecominfraproject.wlan.profile.models.ProfileType;
import com.telecominfraproject.wlan.profile.network.models.ApNetworkConfiguration;
import com.telecominfraproject.wlan.profile.ssid.models.SsidConfiguration;
import com.telecominfraproject.wlan.profile.ssid.models.SsidConfiguration.SecureMode;
import com.telecominfraproject.wlan.routing.RoutingServiceInterface;
@@ -91,8 +93,12 @@ public class OpensyncExternalIntegrationCloud implements OpensyncExternalIntegra
@Value("${connectus.ovsdb.autoProvisionedCustomerId:2}")
private int autoProvisionedCustomerId;
@Value("${connectus.ovsdb.autoProvisionedLocationId:5}")
@Value("${connectus.ovsdb.autoProvisionedLocationId:8}")
private int autoProvisionedLocationId;
@Value("${connectus.ovsdb.autoProvisionedProfileId:2}")
private int autoProvisionedProfileId;
@Value("${connectus.ovsdb.autoProvisionedSsid:Connectus-cloud}")
private String autoProvisionedSsid;
@Autowired
private CacheManager cacheManagerShortLived;
@@ -128,14 +134,7 @@ public class OpensyncExternalIntegrationCloud implements OpensyncExternalIntegra
public void apConnected(String apId, ConnectNodeInfo connectNodeInfo) {
LOG.info("AP {} got connected to the gateway", apId);
Customer customer = null;
try {
customer = customerServiceInterface.get(autoProvisionedCustomerId);
LOG.debug("Got Customer {} for apId {}", customer.toPrettyString(), apId);
} catch (Exception e) {
LOG.error("Caught exception getting customer for Id {} for apId {}", autoProvisionedCustomerId, apId, e);
}
LOG.debug("ConnectNodeInfo {}", connectNodeInfo);
Equipment ce = null;
try {
@@ -145,11 +144,52 @@ public class OpensyncExternalIntegrationCloud implements OpensyncExternalIntegra
LOG.error("Caught exception getting equipment for Id {} for apId {}", apId, apId, e);
}
List<Location> locationList = locationServiceInterface.getAllForCustomer(ce.getCustomerId());
for (Location location : locationList) {
LOG.debug("Location {} for Customer {}", location.toPrettyString(), ce.getCustomerId());
try {
if (ce == null) {
ce = new Equipment();
ce.setCustomerId(autoProvisionedCustomerId);
ce.setInventoryId(apId);
ce.setEquipmentType(EquipmentType.AP);
ce.setSerial(connectNodeInfo.serialNumber);
ce.setDetails(ApElementConfiguration.createWithDefaults());
ce.setLocationId(autoProvisionedLocationId);
ce.setProfileId(autoProvisionedProfileId);
ce = equipmentServiceInterface.create(ce);
}
com.telecominfraproject.wlan.profile.models.Profile apProfile = profileServiceInterface
.getOrNull(ce.getProfileId());
if (apProfile == null) {
com.telecominfraproject.wlan.profile.models.Profile profileSsid = new com.telecominfraproject.wlan.profile.models.Profile();
profileSsid.setCustomerId(ce.getCustomerId());
profileSsid.setProfileType(ProfileType.ssid);
profileSsid.setName(autoProvisionedSsid);
SsidConfiguration ssidConfig = SsidConfiguration.createWithDefaults();
Set<RadioType> appliedRadios = new HashSet<RadioType>();
appliedRadios.add(RadioType.is2dot4GHz);
appliedRadios.add(RadioType.is5GHzL);
appliedRadios.add(RadioType.is5GHzU);
ssidConfig.setAppliedRadios(appliedRadios);
profileSsid.setDetails(ssidConfig);
profileSsid = profileServiceInterface.create(profileSsid);
apProfile = new com.telecominfraproject.wlan.profile.models.Profile();
apProfile.setCustomerId(ce.getCustomerId());
apProfile.setName("autoprovisionedApProfile");
apProfile.setProfileType(ProfileType.equipment_ap);
apProfile.setDetails(ApNetworkConfiguration.createWithDefaults());
apProfile.getChildProfileIds().add(apProfile.getId());
apProfile = profileServiceInterface.create(apProfile);
}
ce.setProfileId(apProfile.getId());
ce = equipmentServiceInterface.update(ce);
// register equipment routing record
EquipmentRoutingRecord equipmentRoutingRecord = new EquipmentRoutingRecord();
equipmentRoutingRecord.setGatewayId(gatewayController.getRegisteredGwId());
@@ -157,13 +197,16 @@ public class OpensyncExternalIntegrationCloud implements OpensyncExternalIntegra
equipmentRoutingRecord.setEquipmentId(ce.getId());
equipmentRoutingRecord = routingServiceInterface.create(equipmentRoutingRecord);
try {
OvsdbSession ovsdbSession = ovsdbSessionMapInterface.getSession(apId);
ovsdbSession.setRoutingId(equipmentRoutingRecord.getId());
ovsdbSession.setEquipmentId(ce.getId());
ovsdbSession.setCustomerId(ce.getCustomerId());
LOG.debug("Equipment {}", Equipment.toPrettyJsonString(ce));
} catch (Exception e) {
LOG.error("Caught exception getting ovsdbSession for apId {}", apId, e);
// TODO Auto-generated catch block
e.printStackTrace();
}
}
@@ -200,14 +243,16 @@ public class OpensyncExternalIntegrationCloud implements OpensyncExternalIntegra
if (ovsdbSession == null) {
throw new IllegalStateException("AP is not connected " + apId);
}
Equipment resolvedEqCfg = equipmentServiceInterface.getByInventoryIdOrNull(apId);
if (resolvedEqCfg == null) {
Equipment equipmentConfig = getCustomerEquipment(apId);
if (equipmentConfig == null) {
throw new IllegalStateException("Cannot retrieve configuration for " + apId);
}
ret = new OpensyncAPConfig();
Location eqLocation = locationServiceInterface.get(resolvedEqCfg.getLocationId());
Location eqLocation = locationServiceInterface.get(equipmentConfig.getLocationId());
// extract country, radio channels from resolvedEqCfg
String country = "CA";
@@ -220,10 +265,11 @@ public class OpensyncExternalIntegrationCloud implements OpensyncExternalIntegra
int radioChannel5LG = 44;
int radioChannel5HG = 108;
ApElementConfiguration apElementConfiguration = (ApElementConfiguration) resolvedEqCfg.getDetails();
ApElementConfiguration apElementConfiguration = (ApElementConfiguration) equipmentConfig.getDetails();
Map<RadioType, ElementRadioConfiguration> erc = apElementConfiguration.getRadioMap();
if (erc != null) {
ElementRadioConfiguration erc24 = erc.get(RadioType.is2dot4GHz);
ElementRadioConfiguration erc5gl = erc.get(RadioType.is5GHzL);
ElementRadioConfiguration erc5gh = erc.get(RadioType.is5GHzU);
@@ -239,8 +285,13 @@ public class OpensyncExternalIntegrationCloud implements OpensyncExternalIntegra
if (erc5gh != null) {
radioChannel5HG = erc5gh.getChannelNumber();
}
}
LOG.debug("Channel erc24 {}", radioChannel24G);
LOG.debug("Channel erc5gl {}", radioChannel5LG);
LOG.debug("Channel erc5gh {}", radioChannel5HG);
OpensyncAPRadioConfig radioConfig = new OpensyncAPRadioConfig();
radioConfig.setCountry(country);
radioConfig.setRadioChannel24G(radioChannel24G);
@@ -253,9 +304,11 @@ public class OpensyncExternalIntegrationCloud implements OpensyncExternalIntegra
List<OpensyncAPSsidConfig> ssidConfigs = new ArrayList<>();
com.telecominfraproject.wlan.profile.models.Profile apProfile = profileServiceInterface
.get(resolvedEqCfg.getProfileId());
.getOrNull(equipmentConfig.getProfileId());
if (apProfile != null) {
Set<Long> childProfileIds = apProfile.getChildProfileIds();
for (Long id : childProfileIds) {
com.telecominfraproject.wlan.profile.models.Profile profile = profileServiceInterface.get(id);
if (profile.getProfileType().equals(ProfileType.ssid)) {
@@ -294,6 +347,7 @@ public class OpensyncExternalIntegrationCloud implements OpensyncExternalIntegra
}
}
}
ret.setSsidConfigs(ssidConfigs);
@@ -530,8 +584,8 @@ public class OpensyncExternalIntegrationCloud implements OpensyncExternalIntegra
// durationMs += surveySample.getDurationMs();
RadioUtilization radioUtil = new RadioUtilization();
radioUtil
.setTimestampSeconds((int) ((survey.getTimestampMs() + surveySample.getOffsetMs()) / 1000));
radioUtil.setTimestampSeconds(
(int) ((survey.getTimestampMs() + surveySample.getOffsetMs()) / 1000));
radioUtil.setAssocClientTx(100 * surveySample.getBusyTx() / surveySample.getDurationMs());
radioUtil.setAssocClientRx(100 * surveySample.getBusyRx() / surveySample.getDurationMs());
radioUtil.setNonWifi(
@@ -564,8 +618,6 @@ public class OpensyncExternalIntegrationCloud implements OpensyncExternalIntegra
}
}
private void populateApClientMetrics(List<SingleMetricRecord> metricRecordList, Report report, int customerId,
@@ -749,20 +801,6 @@ public class OpensyncExternalIntegrationCloud implements OpensyncExternalIntegra
}
osNode = opensyncNodeMap.get(apId);
List<OpensyncAPVIFState> vifStates = osNode.getVifStates();
LOG.debug(
"BSSID SSID AUTH MODE RADIO DEVICES");
for (OpensyncAPVIFState vif : vifStates) {
String ssid = vif.getSsid();
int channel = vif.getChannel();
int devices = vif.getAssociatedClients().size();
String bssid = osNode.getRadioForChannel(channel).getMac();
String freqBand = osNode.getRadioForChannel(channel).getFreqBand();
String encryption = vif.getSecurity().get("encryption");
LOG.debug("{} {} {} {} {}", bssid, ssid, encryption, freqBand, devices);
}
}